Skip to content

Completion Rule Examples

The following rules are evaluated and applied when a query goes into any completion state: done, cancel, or error.

Setting a Query Tag

The following completion rule, completion_tag_short_query, sets a query tag Subsecond Query when queries run by non-superuser roles complete in less than 1 second.

if (w.roles !== 'superuser' &&
   w.duration <1000) {
	w.tags = 'Subsecond Query';
}

Log a Warning Message for the ybdadmin User

This completion rule, completion_warn_ybdadmin_user, tracks all of the queries run by the ybdadmin account and logs a warning message.

Rule Preview:
if (w.user === 'ybdadmin) {
	log.warn('Running as ybdadmin!');
}

For every query run by the ybdadmin account, the administrator sees the warning:

Running as ybdadmin!

Parent topic:Rule Examples