Query Engines
Query

Query

The Vizzly frontend builds queries which are sent to your custom query engine through the runQueriesCallback async function passed into the Vizzly Dashboard react component.

The async runQueriesCallback function accepts a list of queries to be executed, and should be returned as an array of results where the index of each result in the array corresponds to the query at the same index in the array of queries.

Format

export namespace Query {
  // A dimension can be thought of as a
  // field to "group by" in a SQL statement.
  export type Dimension = Field;
 
  // Field ID provided in your data set.
  export type Field = string;
 
  export type Limit = number;
 
  export type Offset = number;
 
  export type Aggregate =
    | "countDistinct"
    | "count"
    | "mean"
    | "sum"
    | "min"
    | "max"
    | "none";
 
  export type Measure = {
    field: Field;
    aggregate: Aggregate;
  };
 
  export type Order = {
    field: Field;
    direction: "asc" | "desc";
    aggregate: Aggregate;
  };
 
  export type Operator =
    | ">"
    | "<"
    | "="
    | '!='
    | ">="
    | "<="
    | "is_one_of"
    | "is_not_one_of"
    | "starts_with"
    | "ends_with"
    | "contains_substring"
    | "does_not_contain_substring";
 
  export type Filter = {
    field: Field;
    op: Operator;
    value: any;
  };
 
  export namespace TimeDimension {
    export type Truncate =
      | "second"
      | "minute"
      | "hour"
      | "day"
      | "month"
      | "year";
  }
 
  export type TimeDimension = {
    field: Field;
    truncate: TimeDimension.Truncate;
  };
}
 
export type Query = {
  dataSetId: string;
  measure: Array<Query.Measure>;
  dimension: Array<Query.Dimension>;
  timeDimension: Query.TimeDimension | null;
 
  /*
    The following filter structure
    [
      [<< filter 1>>, << filter 2 >>],
      [<< filter 3>>, << filter 4 >>],
    ]
    would be read as;
    accept data records where (filter 1 and filter 2 are truthy), or (filter 3 and filter 4 are truthy)
  */
  filter: Array<Array<Query.Filter>>;
  order: Array<Query.Order>;
  limit?: Query.Limit;
  offset?: Query.Offset;
};

Client side caching

By default, Vizzly checks a local cache to ensure duplicate queries aren't sent to your servers in quick succession.

Last updated on January 27, 2023