SELECT
queries, so we will focus on the syntax for this.
Here’s the basic syntax of a Clickhouse SELECT
query. Some parts that we don’t recommend or don’t support are omitted.
SELECT FROM WHERE GROUP BY HAVING ORDER BY LIMIT
query.
DateTime64
- represents a date and time with a precision of nanoseconds. All datetimes in Laminar are in UTC.String
- represents a string.UUID
- represents a universally unique identifier. This is used for most identifier columns.Float64
- represents a floating point number.UInt64
- represents a 64-bit unsigned integer.UInt8
- unsigned 8-bit integer. Used for enum values.'value'::type
syntax, for example:
start_time
, so adding a start_time
filter will speed up the query and prevent it from failing because of running out of memory.
This is relevant to both the spans
table and the traces
aggregation view on it.
start_time
filter.
spans
table with the traces
table to get the trace duration.
traces
table for each trace_id.
toStartOfInterval(value, interval_specifier)
.
date_trunc
function, notice how this is similar.
toStartOfInterval
is more flexible, because you can specify any interval, not just the ones supported by date_trunc
.
For example, you can group spans within last day to 15-minute intervals.
toStartOfSecond(value)
- truncates to the start of the secondtoStartOfMinute(value)
- truncates to the start of the minutetoStartOfTenMinutes(value)
- truncates to the start of the minutetoStartOfHour(value)
- truncates to the start of the hourtoStartOfDay(value)
- truncates to the start of the daytoStartOfWeek(value)
- truncates to the start of the weektoStartOfMonth(value)
- truncates to the start of the monthtoStartOfQuarter(value)
- truncates to the start of the monthtoStartOfYear(value)
- truncates to the start of the yearattributes
on spans
table, contain JSON values stored as strings.
Clickhouse provides a wide variety of functions to work with JSONs. See the full reference in Clickhouse documentation.
Generally, there are two families of functions to work with JSONs:
JSON*
functions - comprehensive set of functions that work on the JSON stringssimpleJSON*
functions - simpler subset that works much faster, and under a few assumptions.simpleJSON*
functions, especially if you know the data type of the value you want to extract.key
. If you know the data type of the value, you can use the simpleJSONExtract*
functions.
For example,
simpleJSONHas
functions.
The query below will return the number of LLM spans that have a gen_ai.request.structured_output_schema
key in the attributes
column,
i.e. the number of LLM spans that have a structured output schema defined at request time.
simpleJSONExtract*
functions repeatedly to extract the nested value.
Suppose you pass a structured output schema to the LLM, and the schema always has a description
key.
JSON*
functions.
Here’s a quick list of things, you can do with JSON*
functions:
JSONExtractRaw(input, -1)
to get the last input messageJSONExtractRaw(input, -1, 'content')
to get the last input message contentObject.keys
or dict.keys
, e.g. JSONExtractKeys(attributes)
Object.entries
or dict.items
, e.g. JSONExtractKeysAndValues(attributes)
JSONLength(input)
to get the number of input messages