Enable search for metrics.

This commit is contained in:
Mike Cao 2024-03-05 00:45:55 -08:00
parent bbd7c4b6ea
commit b0bfd0b5ab
7 changed files with 74 additions and 30 deletions

View file

@ -92,12 +92,14 @@ function getTimestampDiffQuery(field1: string, field2: string): string {
}
}
function mapFilter(column: string, operator: string, name: string, type = 'varchar') {
switch (operator) {
function mapFilter(column: string, filter: string, name: string, type = 'varchar') {
switch (filter) {
case OPERATORS.equals:
return `${column} = {{${name}::${type}}}`;
case OPERATORS.notEquals:
return `${column} != {{${name}::${type}}}`;
case OPERATORS.contains:
return `${column} like {{${name}::${type}}}`;
default:
return '';
}
@ -106,11 +108,11 @@ function mapFilter(column: string, operator: string, name: string, type = 'varch
function getFilterQuery(filters: QueryFilters = {}, options: QueryOptions = {}): string {
const query = Object.keys(filters).reduce((arr, name) => {
const value = filters[name];
const operator = value?.filter ?? OPERATORS.equals;
const column = FILTER_COLUMNS[name] ?? options?.columns?.[name];
const filter = value?.filter ?? OPERATORS.equals;
const column = value?.column ?? FILTER_COLUMNS[name] ?? options?.columns?.[name];
if (value !== undefined && column) {
arr.push(`and ${mapFilter(column, operator, name)}`);
if (value !== undefined && column !== undefined) {
arr.push(`and ${mapFilter(column, filter, name)}`);
if (name === 'referrer') {
arr.push(