Middleware for annotating (adding type information to) the results of a query, under the :cols
column.
Middleware for annotating (adding type information to) the results of a query, under the `:cols` column.
(add-column-info qp)
Middleware for adding type information about the columns in the query results (the :cols
key).
Middleware for adding type information about the columns in the query results (the `:cols` key).
(aggregation-name ag-clause & [{:keys [top-level?]}])
Inputs: [ag-clause :- mbql.s/Aggregation & [{:keys [top-level?]}]] Returns: su/NonBlankString
Return an appropriate field and display name for an :aggregation
subclause (an aggregation or
expression). Takes an options map as schema won't support passing keypairs directly as a varargs. {:top-level? true}
will cause a name to be generated that will appear in the results, other names with a leading __ will be
trimmed on some backends.
Inputs: [ag-clause :- mbql.s/Aggregation & [{:keys [top-level?]}]] Returns: su/NonBlankString Return an appropriate field *and* display name for an `:aggregation` subclause (an aggregation or expression). Takes an options map as schema won't support passing keypairs directly as a varargs. `{:top-level? true}` will cause a name to be generated that will appear in the results, other names with a leading __ will be trimmed on some backends.
(cols-for-mbql-query inner-query)
Inputs: [inner-query :- su/Map]
Return results metadata about the expected columns in an 'inner' MBQL query.
Inputs: [inner-query :- su/Map] Return results metadata about the expected columns in an 'inner' MBQL query.
(result-rows-maps->vectors qp)
For drivers that return query result rows as a sequence of maps rather than a sequence of vectors, determine appropriate column sort order and convert rows to sequences (the expected MBQL result format).
Certain databases like MongoDB and Druid always return result rows as maps, rather than something sequential (e.g.
vectors). Rather than require those drivers to duplicate the logic in this and other QP middleware namespaces for
determining expected column sort order, drivers have the option of leaving the :rows
as a sequence of maps, and
this middleware will handle things for them.
Because the order of :columns
is determined by this middleware, it adds :columns
to the results as well as the
updated :rows
; drivers relying on this middleware should return a map containing only :rows
.
IMPORTANT NOTES:
Determining correct sort order only works for MBQL queries. For native queries, the sort order is the result of
calling keys
on the first row. It is reccomended that you utilize Flatland ordered-map
when possible to
preserve key ordering in maps.
For obvious reasons, drivers that returns rows as maps cannot support duplicate column names. Thus it is expected
that drivers that use functionality provided by this middleware return deduplicated column names, e.g. :sum
and
:sum_2
for queries with multiple :sum
aggregations.
Call mbql.u/pre-alias-and-uniquify-aggregations
on your query before processing it tp add appropriate aliases to
aggregations. Currently this assumes you are passing annotate/aggregation-name
as the function to generate
aggregation names; if your driver is doing something drastically different, you may need to tweak the keys in the
result row maps so they match up with the keys generated by that function.
For nested Fields, this namespace assumes result row maps will come back flattened, and Field name keys will
come back qualified by names of their ancestors, e.g. parent.child
, grandparent.parent.child
, etc. This is done
to remove any ambiguity between nested columns with the same name (e.g. a document with both user.id
and
venue.id
). Be sure to follow this convention if your driver supports nested Fields (e.g., MongoDB).
For drivers that return query result rows as a sequence of maps rather than a sequence of vectors, determine appropriate column sort order and convert rows to sequences (the expected MBQL result format). Certain databases like MongoDB and Druid always return result rows as maps, rather than something sequential (e.g. vectors). Rather than require those drivers to duplicate the logic in this and other QP middleware namespaces for determining expected column sort order, drivers have the option of leaving the `:rows` as a sequence of maps, and this middleware will handle things for them. Because the order of `:columns` is determined by this middleware, it adds `:columns` to the results as well as the updated `:rows`; drivers relying on this middleware should return a map containing only `:rows`. IMPORTANT NOTES: * Determining correct sort order only works for MBQL queries. For native queries, the sort order is the result of calling `keys` on the first row. It is reccomended that you utilize Flatland `ordered-map` when possible to preserve key ordering in maps. * For obvious reasons, drivers that returns rows as maps cannot support duplicate column names. Thus it is expected that drivers that use functionality provided by this middleware return deduplicated column names, e.g. `:sum` and `:sum_2` for queries with multiple `:sum` aggregations. Call `mbql.u/pre-alias-and-uniquify-aggregations` on your query before processing it tp add appropriate aliases to aggregations. Currently this assumes you are passing `annotate/aggregation-name` as the function to generate aggregation names; if your driver is doing something drastically different, you may need to tweak the keys in the result row maps so they match up with the keys generated by that function. * For *nested* Fields, this namespace assumes result row maps will come back flattened, and Field name keys will come back qualified by names of their ancestors, e.g. `parent.child`, `grandparent.parent.child`, etc. This is done to remove any ambiguity between nested columns with the same name (e.g. a document with both `user.id` and `venue.id`). Be sure to follow this convention if your driver supports nested Fields (e.g., MongoDB).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close