Using BQL, function calls can have different formats.
For a function with only one argument, it can be called as:
{"function_name": "field_name"}
For functions with more than one argument, the "function" and "args"
keywords must be used:
{
"function": "function_name",
"args": [
"field_name_1",
"field_name_2"
]
}
Function arguments are generally taken as field names, with few exceptions.
Literal numerical values, boolean values, and NULL are recognized. Literal
string can be specified with:
{"literal": "a string"}
The Mathematical Functions output a numerical value or null.
addsubmuldivExample:
{
"function": "sub",
"args": [
"search_console.period_1.count_clicks",
"search_console.period_0.count_clicks"
]
}
All BQL Date Functions take one input parameter.
first_day_of_weekfirst_day_of_monthdateyearmonthyear_monthyear_week_number_starting_mondayyear_week_number_starting_sundayExample:
{"first_day_of_week": "search_console.period_0.date"}
countcount_truecount_falsecount_nullcount_distinctcount_distinct_approxConditional counts: these are shortcuts to applying count_true to the corresponding boolean function.
count_eqcount_gtcount_gtecount_ltcount_ltehttp_code_familyhttp_code_qualityBQL supports retrieving any kind of field as a JSON-formatted string.
to_json_stringfirsteqneltltegtgteandornotexistsnot_existsif: returns one of two values according to a boolean condition.
The two possible return values must be the same type.
Example:
{
"function": "if",
"args": [
{
"function": "exists",
"args": [
"segments.pagetype.depth_2"
]
},
"segments.pagetype.depth_2",
{"literal": "#empty"}
]
}
if_not_exists: returns the first field’s value if it exists, the second field’s value otherwise.
The two possible return values must be the same type.
This is a shortcut for the previous example:
{
"function": "if_not_exists",
"args": [
"segments.pagetype.depth_2",
{"literal": "#empty"}
]
}
concat: concatenates strings. Any non-existing value results in NULL.
Example:
JSON
{
"function": "concat",
"args": [
"segments.pagetype.depth_1",
{"literal": "/"},
"segments.pagetype.depth_2"
]
}