Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Array functions
array
Introduced in: v1.1.0 Creates an array from the function arguments. The arguments should be constants and have types that share a common supertype. At least one argument must be passed, because otherwise it isn’t clear which type of array to create. This means that you can’t use this function to create an empty array. To do so, use theemptyArray* function.
Use the [ ] operator for the same functionality.
Syntax
x1— Constant value of any type T. If only this argument is provided, the array will be of type T. -[, x2, ..., xN]— Additional N constant values sharing a common supertype withx1
Array(T)
Examples
Valid usage
Query
Response
Query
Response
arrayAUCPR
Introduced in: v20.4.0 Calculates the area under the precision-recall (PR) curve. A precision-recall curve is created by plotting precision on the y-axis and recall on the x-axis across all thresholds. The resulting value ranges from 0 to 1, with a higher value indicating better model performance. The PR AUC is particularly useful for imbalanced datasets, providing a clearer comparison of performance compared to ROC AUC on those cases. For more details, please see here, here and here. SyntaxarrayPRAUC
Arguments
cores— Scores prediction model gives.Array((U)Int*)orArray(Float*)labels— Labels of samples, usually 1 for positive sample and 0 for negative sample.Array((U)Int*)orArray(Enum)partial_offsets—- Optional. An
Array(T)of three non-negative integers for calculating a partial area under the PR curve (equivalent to a vertical band of the PR space) instead of the whole AUC. This option is useful for distributed computation of the PR AUC. The array must contain the following elements [higher_partitions_tp,higher_partitions_fp,total_positives].higher_partitions_tp: The number of positive labels in the higher-scored partitions.higher_partitions_fp: The number of negative labels in the higher-scored partitions.total_positives: The total number of positive samples in the entire dataset.
When
arr_partial_offsets is used, the arr_scores and arr_labels should be only a partition of the entire dataset, containing an interval of scores.
The dataset should be divided into contiguous partitions, where each partition contains the subset of the data whose scores fall within a specific range.
For example:- One partition could contain all scores in the range [0, 0.5).
- Another partition could contain scores in the range [0.5, 1.0].
Float64
Examples
Usage example
Query
Response
arrayAll
Introduced in: v1.1.0 Returns1 if lambda func(x [, y1, y2, ... yN]) returns true for all elements. Otherwise, it returns 0.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)cond1_arr, ...— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
1 if the lambda function returns true for all elements, 0 otherwise UInt8
Examples
All elements match
Query
Response
Query
Response
arrayAutocorrelation
Introduced in: v26.4.0 Calculates the autocorrelation of an array. Ifmax_lag is provided, calculates correlation only for lags in range [0, max_lag).
If max_lag is not provided, calculates for all possible lags.
Syntax
arr— Array of numbers.Array(T)max_lag— Optional. Maximum number of lags to compute. Must be a non-negative integer.Integer
Array(Float64)
Examples
Linear
Query
Response
Query
Response
Query
Response
Query
Response
arrayAvg
Introduced in: v21.1.0 Returns the average of elements in the source array. If a lambda functionfunc is specified, returns the average of elements of the lambda results.
Syntax
func(x[, y1, ..., yN])— Optional. A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Float64
Examples
Basic example
Query
Response
Query
Response
arrayCompact
Introduced in: v20.1.0 Removes consecutive duplicate elements from an array, includingnull values. The order of values in the resulting array is determined by the order in the source array.
Syntax
arr— An array to remove duplicates from.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayConcat
Introduced in: v1.1.0 Combines arrays passed as arguments. Syntaxarr1 [, arr2, ... , arrN]— N number of arrays to concatenate.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayCount
Introduced in: v1.1.0 Returns the number of elements for whichfunc(arr1[i], ..., arrN[i]) returns true.
If func is not specified, it returns the number of non-zero elements in the array.
arrayCount is a higher-order function.
Syntax
func— Optional. Function to apply to each element of the array(s).Lambda functionarr1, ..., arrN— N arrays.Array(T)
func returns true. Otherwise, returns the number of non-zero elements in the array. UInt32
Examples
Usage example
Query
Response
arrayCumSum
Introduced in: v1.1.0 Returns an array of the partial (running) sums of the elements in the source array. If a lambda function is specified, the sum is computed from applying the lambda to the array elements at each position. Syntaxfunc— Optional. A lambda function to apply to the array elements at each position.Lambda functionarr1— The source array of numeric values.Array(T)[arr2, ..., arrN]— Optional. Additional arrays of the same size, passed as arguments to the lambda function if specified.Array(T)
Array(T)
Examples
Basic usage
Query
Response
Query
Response
arrayCumSumNonNegative
Introduced in: v18.12.0 Returns an array of the partial (running) sums of the elements in the source array, replacing any negative running sum with zero. If a lambda function is specified, the sum is computed from applying the lambda to the array elements at each position. Syntaxfunc— Optional. A lambda function to apply to the array elements at each position.Lambda functionarr1— The source array of numeric values.Array(T)[arr2, ..., arrN]— Optional. Additional arrays of the same size, passed as arguments to the lambda function if specified.Array(T)
Array(T)
Examples
Basic usage
Query
Response
Query
Response
arrayDifference
Introduced in: v1.1.0 Calculates an array of differences between adjacent array elements. The first element of the result array will be 0, the secondarr[1] - arr[0], the third arr[2] - arr[1], etc.
The type of elements in the result array are determined by the type inference rules for subtraction (e.g. UInt8 - UInt8 = Int16).
Syntax
arr— Array for which to calculate differences between adjacent elements.Array(T)
UInt*
Examples
Usage example
Query
Response
Query
Response
arrayDistinct
Introduced in: v1.1.0 Returns an array containing only the distinct elements of an array. Syntaxarr— Array for which to extract distinct elements.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayDotProduct
Introduced in: v23.5.0 Returns the dot product of two arrays.The sizes of the two vectors must be equal. Arrays and Tuples may also contain mixed element types.
v1— First vector.Array((U)Int* | Float* | Decimal)orTuple((U)Int* | Float* | Decimal)v2— Second vector.Array((U)Int* | Float* | Decimal)orTuple((U)Int* | Float* | Decimal)
The return type is determined by the type of the arguments. If Arrays or Tuples contain mixed element types then the result type is the supertype.
(U)Int* or Float* or Decimal
Examples
Array example
Query
Response
Query
Response
arrayElement
Introduced in: v1.1.0 Gets the element of the provided array with indexn where n can be any integer type.
If the index falls outside of the bounds of an array, it returns a default value (0 for numbers, an empty string for strings, etc.),
except for arguments of a non-constant array and a constant index 0. In this case there will be an error Array indices are 1-based.
Arrays in ClickHouse are one-indexed.
arr[-1] is the last item in the array.
Operator [n] provides the same functionality.
Syntax
Array(T)
Examples
Usage example
Query
Response
Query
Response
Query
Response
Query
Response
arrayElementOrNull
Introduced in: v1.1.0 Gets the element of the provided array with indexn where n can be any integer type.
If the index falls outside of the bounds of an array, NULL is returned instead of a default value.
Arrays in ClickHouse are one-indexed.
arr[-1] is the last item in the array.
Syntax
arrays— Arbitrary number of array arguments.Array
Array(T)
Examples
Usage example
Query
Response
Query
Response
Query
Response
arrayEnumerate
Introduced in: v1.1.0 Returns the array[1, 2, 3, ..., length (arr)]
This function is normally used with the ARRAY JOIN clause. It allows counting something just
once for each array after applying ARRAY JOIN.
This function can also be used in higher-order functions. For example, you can use it to get array indexes for elements that match a condition.
Syntax
arr— The array to enumerate.Array
[1, 2, 3, ..., length (arr)]. Array(UInt32)
Examples
Basic example with ARRAY JOIN
Query
Response
arrayEnumerateDense
Introduced in: v18.12.0 Returns an array of the same size as the source array, indicating where each element first appears in the source array. Syntaxarr— The array to enumerate.Array(T)
arr, indicating where each element first appears in the source array Array(T)
Examples
Usage example
Query
Response
arrayEnumerateDenseRanked
Introduced in: v20.1.0 Returns an array the same size as the source array, indicating where each element first appears in the source array. It allows for enumeration of a multidimensional array with the ability to specify how deep to look inside the array. Syntaxclear_depth— Enumerate elements at the specified level separately. Must be less than or equal tomax_arr_depth.UInt*arr— N-dimensional array to enumerate.Array(T)max_array_depth— The maximum effective depth. Must be less than or equal to the depth ofarr.UInt*
Array
Examples
Basic usage
Query
Response
Query
Response
Query
Response
arrayEnumerateUniq
Introduced in: v1.1.0 Returns an array the same size as the source array, indicating for each element what its position is among elements with the same value. This function is useful when usingARRAY JOIN and aggregation of array elements.
The function can take multiple arrays of the same size as arguments. In this case, uniqueness is considered for tuples of elements in the same positions in all the arrays.
Syntax
arr1— First array to process.Array(T)arr2, ...— Optional. Additional arrays of the same size for tuple uniqueness.Array(UInt32)
Array(T)
Examples
Basic usage
Query
Response
Query
Response
Query
Response
arrayEnumerateUniqRanked
Introduced in: v20.1.0 Returns an array (or multi-dimensional array) with the same dimensions as the source array, indicating for each element what it’s position is among elements with the same value. It allows for enumeration of a multi-dimensional array with the ability to specify how deep to look inside the array. Syntaxclear_depth— Enumerate elements at the specified level separately. Positive integer less than or equal tomax_arr_depth.UInt*arr— N-dimensional array to enumerate.Array(T)max_array_depth— The maximum effective depth. Positive integer less than or equal to the depth ofarr.UInt*
arr with each element showing the position of that element in relation to other elements of the same value. Array(T)
Examples
Example 1
Query
Response
Query
Response
Query
Response
Query
Response
arrayExcept
Introduced in: v25.9.0 Returns an array containing elements fromsource that are not present in except, preserving the original order.
This function performs a set difference operation between two arrays. For each element in source, it checks if the element exists in except (using exact comparison). If not, the element is included in the result.
The operation maintains these properties:
- Order of elements from
sourceis preserved - Duplicates in
sourceare preserved if they don’t exist inexcept - NULL is handled as a separate value
source— The source array containing elements to filter.Array(T)except— The array containing elements to exclude from the result.Array(T)
source that weren’t found in except. Array(T)
Examples
basic
Query
Response
Query
Response
Query
Response
Query
Response
arrayExists
Introduced in: v1.1.0 Returns1 if there is at least one element in a source array for which func(x[, y1, y2, ... yN]) returns true. Otherwise, it returns 0.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
1 if the lambda function returns true for at least one element, 0 otherwise UInt8
Examples
Usage example
Query
Response
arrayFill
Introduced in: v20.1.0 ThearrayFill function sequentially processes a source array from the first element
to the last, evaluating a lambda condition at each position using elements from
the source and condition arrays. When the lambda function evaluates to false at
position i, the function replaces that element with the element at position i-1
from the current state of the array. The first element is always preserved
regardless of any condition.
Syntax
func(x [, y1, ..., yN])— A lambda functionfunc(x [, y1, y2, ... yN]) → F(x [, y1, y2, ... yN])which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Lambda function[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Array(T)
Examples
Example with single array
Query
Response
Query
Response
arrayFilter
Introduced in: v1.1.0 Returns an array containing only the elements in the source array for which a lambda function returns true. Syntaxfunc(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Array(T)
Examples
Example 1
Query
Response
Query
Response
arrayFirst
Introduced in: v1.1.0 Returns the first element in the source array for whichfunc(x[, y1, y2, ... yN]) returns true, otherwise it returns a default value.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y). Lambda function. -source_arr— The source array to process.Array(T). -[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T).
λ is true, otherwise returns the default value of T.
Examples
Usage example
Query
Response
Query
Response
arrayFirstIndex
Introduced in: v1.1.0 Returns the index of the first element in the source array for whichfunc(x[, y1, y2, ... yN]) returns true, otherwise it returns ‘0’.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y). Lambda function. -source_arr— The source array to process.Array(T). -[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T).
func is true, otherwise returns 0 UInt32
Examples
Usage example
Query
Response
Query
Response
arrayFirstOrNull
Introduced in: v1.1.0 Returns the first element in the source array for whichfunc(x[, y1, y2, ... yN]) returns true, otherwise it returns NULL.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
func is true, otherwise returns NULL.
Examples
Usage example
Query
Response
Query
Response
arrayFlatten
Introduced in: v20.1.0 Converts an array of arrays to a flat array. Function:- Applies to any depth of nested arrays.
- Does not change arrays that are already flat.
flatten
Arguments
arr— A multidimensional array.Array(Array(T))
Array(T)
Examples
Usage example
Query
Response
arrayFold
Introduced in: v23.10.0 Applies a lambda function to one or more equally-sized arrays and collects the result in an accumulator. Syntaxλ(x, x1 [, x2, x3, ... xN])— A lambda functionλ(acc, x1 [, x2, x3, ... xN]) → F(acc, x1 [, x2, x3, ... xN])whereFis an operation applied toaccand array values fromxwith the result ofaccre-used.Lambda functionarr1 [, arr2, arr3, ... arrN]— N arrays over which to operate.Array(T)acc— Accumulator value with the same type as the return type of the Lambda function.
acc value.
Examples
Usage example
Query
Response
Query
Response
Query
Response
arrayIntersect
Introduced in: v1.1.0 Takes multiple arrays and returns an array with elements which are present in all source arrays. The result contains only unique values. SyntaxarrN— N arrays from which to make the new array.Array(T).
Array(T)
Examples
Usage example
Query
Response
arrayJaccardIndex
Introduced in: v23.7.0 Returns the Jaccard index of two arrays. Syntaxarr_x and arr_y Float64
Examples
Usage example
Query
Response
arrayJoin
Introduced in: v1.1.0 ThearrayJoin function takes a row that contains an array and unfolds it, generating multiple rows – one for each element in the array.
This is in contrast to Regular Functions in ClickHouse which map input values to output values within the same row,
and Aggregate Functions which take a group of rows and “compress” or “reduce” them into a single summary row
(or a single value within a summary row if used with GROUP BY).
All the values in the columns are simply copied, except the values in the column where this function is applied;
these are replaced with the corresponding array value.
Syntax
arr— An array to unfold.Array(T)
arr.
Examples
Basic usage
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
arrayLast
Introduced in: v1.1.0 Returns the last element in the source array for which a lambdafunc(x [, y1, y2, ... yN]) returns true, otherwise it returns a default value.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y). Lambda function. -source— The source array to process.Array(T). -[, cond1, ... , condN]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T).
func is true, otherwise returns the default value of T.
Examples
Usage example
Query
Response
Query
Response
arrayLastIndex
Introduced in: v1.1.0 Returns the index of the last element in the source array for whichfunc(x[, y1, y2, ... yN]) returns true, otherwise it returns ‘0’.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
func is true, otherwise returns 0 UInt32
Examples
Usage example
Query
Response
Query
Response
arrayLastOrNull
Introduced in: v1.1.0 Returns the last element in the source array for which a lambdafunc(x [, y1, y2, ... yN]) returns true, otherwise it returns NULL.
Syntax
func(x [, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y). Lambda function. -source_arr— The source array to process.Array(T). -[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T).
λ is not true, otherwise returns NULL.
Examples
Usage example
Query
Response
Query
Response
arrayLevenshteinDistance
Introduced in: v25.4.0 Calculates the Levenshtein distance for two arrays. SyntaxFloat64
Examples
Usage example
Query
Response
arrayLevenshteinDistanceWeighted
Introduced in: v25.4.0 Calculates Levenshtein distance for two arrays with custom weights for each element. The number of elements for the array and its weights should match. Syntaxfrom— first array.Array(T). -to— second array.Array(T). -from_weights— weights for the first array.Array((U)Int*|Float*)to_weights— weights for the second array.Array((U)Int*|Float*)
Float64
Examples
Usage example
Query
Response
arrayMap
Introduced in: v1.1.0 Returns an array obtained from the original arrays by applying a lambda function to each element. Syntaxfunc— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionarr— N arrays to process.Array(T)
Array(T)
Examples
Usage example
Query
Response
Query
Response
arrayMax
Introduced in: v21.1.0 Returns the maximum element in the source array. If a lambda functionfunc is specified, returns the maximum element of the lambda results.
Syntax
func(x[, y1, ..., yN])— Optional. A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Query
Response
Query
Response
arrayMin
Introduced in: v21.1.0 Returns the minimum element in the source array. If a lambda functionfunc is specified, returns the minimum element of the lambda results.
Syntax
func(x[, y1, ..., yN])— Optional. A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)cond1_arr, ...— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Query
Response
Query
Response
arrayNormalizedGini
Introduced in: v25.1.0 Calculates the normalized Gini coefficient. SyntaxTuple(Float64, Float64, Float64)
Examples
Usage example
Query
Response
arrayPartialReverseSort
Introduced in: v23.2.0 This function is the same asarrayReverseSort but with an additional limit argument allowing partial sorting.
Syntax
f(arr[, arr1, ... ,arrN])— The lambda function to apply to elements of arrayx.Lambda functionarr— Array to be sorted.Array(T)arr1, ... ,arrN— N additional arrays, in the case whenfaccepts multiple arguments.Array(T)limit— Index value up until which sorting will occur.(U)Int*
[1..limit] are sorted
in descending order. The remaining elements (limit..N] are in an unspecified order.
Examples
simple_int
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
arrayPartialShuffle
Introduced in: v23.2.0 Returns an array of the same size as the original array where elements in range[1..limit] are a random
subset of the original array. Remaining (limit..n] shall contain the elements not in [1..limit] range in undefined order.
Value of limit shall be in range [1..n]. Values outside of that range are equivalent to performing full arrayShuffle:
This function will not materialize constants.The value of
limit should be in the range [1..N]. Values outside of that range are equivalent to performing full arrayShuffle.arr— The array to shuffle.Array(T)seed— Optional. The seed to be used with random number generation. If not provided, a random one is used.(U)Int*limit— Optional. The number to limit element swaps to, in the range[1..N].(U)Int*
Array(T)
Examples
no_limit1
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
arrayPartialSort
Introduced in: v23.2.0 This function is the same asarraySort but with an additional limit argument allowing partial sorting.
Syntax
f(arr[, arr1, ... ,arrN])— The lambda function to apply to elements of arrayx.Lambda functionarr— Array to be sorted.Array(T)arr1, ... ,arrN— N additional arrays, in the case whenfaccepts multiple arguments.Array(T)limit— Index value up until which sorting will occur.(U)Int*
[1..limit] are sorted
in ascending order. The remaining elements (limit..N] are in an unspecified order.
Examples
simple_int
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
arrayPopBack
Introduced in: v1.1.0 Removes the last element from the array. Syntaxarr— The array for which to remove the last element from.Array(T)
arr but without the last element of arr Array(T)
Examples
Usage example
Query
Response
arrayPopFront
Introduced in: v1.1.0 Removes the first item from the array. Syntaxarr— The array for which to remove the first element from.Array(T)
arr but without the first element of arr Array(T)
Examples
Usage example
Query
Response
arrayProduct
Introduced in: v21.1.0 Returns the product of elements in the source array. If a lambda functionfunc is specified, returns the product of elements of the lambda results.
Syntax
func(x[, y1, ..., yN])— Optional. A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Float64
Examples
Basic example
Query
Response
Query
Response
arrayPushBack
Introduced in: v1.1.0 Adds one item to the end of the array. Syntaxarr— The array for which to add valuexto the end of.Array(T)x—- Single value to add to the end of the array.
Array(T).
- Only numbers can be added to an array with numbers, and only strings can be added to an array of strings.
- When adding numbers, ClickHouse automatically sets the type of
xfor the data type of the array. - Can be
NULL. The function adds aNULLelement to an array, and the type of array elements converts toNullable.
arr but with an additional value x at the end of the array Array(T)
Examples
Usage example
Query
Response
arrayPushFront
Introduced in: v1.1.0 Adds one element to the beginning of the array. Syntaxarr— The array for which to add valuexto the end of.Array(T). -x—- Single value to add to the start of the array.
Array(T).
- Only numbers can be added to an array with numbers, and only strings can be added to an array of strings.
- When adding numbers, ClickHouse automatically sets the type of
xfor the data type of the array. - Can be
NULL. The function adds aNULLelement to an array, and the type of array elements converts toNullable.
arr but with an additional value x at the beginning of the array Array(T)
Examples
Usage example
Query
Response
arrayROCAUC
Introduced in: v20.4.0 Calculates the area under the receiver operating characteristic (ROC) curve. A ROC curve is created by plotting True Positive Rate (TPR) on the y-axis and False Positive Rate (FPR) on the x-axis across all thresholds. The resulting value ranges from zero to one, with a higher value indicating better model performance. The ROC AUC (also known as simply AUC) is a concept in machine learning. For more details, please see here, here and here. SyntaxarrayAUC
Arguments
scores— Scores prediction model gives.Array((U)Int*)orArray(Float*)labels— Labels of samples, usually 1 for positive sample and 0 for negative sample.Array((U)Int*)orEnumscale— Optional. Decides whether to return the normalized area. If false, returns the area under the TP (true positives) x FP (false positives) curve instead. Default value: true.Boolpartial_offsets—- An array of four non-negative integers for calculating a partial area under the ROC curve (equivalent to a vertical band of the ROC space) instead of the whole AUC. This option is useful for distributed computation of the ROC AUC. The array must contain the following elements [
higher_partitions_tp,higher_partitions_fp,total_positives,total_negatives]. Array of non-negative Integers. Optional.higher_partitions_tp: The number of positive labels in the higher-scored partitions.higher_partitions_fp: The number of negative labels in the higher-scored partitions.total_positives: The total number of positive samples in the entire dataset.total_negatives: The total number of negative samples in the entire dataset.
When
arr_partial_offsets is used, the arr_scores and arr_labels should be only a partition of the entire dataset, containing an interval of scores.
The dataset should be divided into contiguous partitions, where each partition contains the subset of the data whose scores fall within a specific range.
For example:- One partition could contain all scores in the range [0, 0.5).
- Another partition could contain scores in the range [0.5, 1.0].
Float64
Examples
Usage example
Query
Response
arrayRandomSample
Introduced in: v23.10.0 Returns a subset withsamples-many random elements of an input array. If samples exceeds the size of the input array, the sample size is limited to the size of the array, i.e. all array elements are returned but their order is not guaranteed. The function can handle both flat arrays and nested arrays.
Syntax
arr— The input array or multidimensional array from which to sample elements.Array(T)samples— The number of elements to include in the random sample.(U)Int*
Array(T)
Examples
Usage example
Query
Response
Query
Response
arrayReduce
Introduced in: v1.1.0 Applies an aggregate function to array elements and returns its result. The name of the aggregation function is passed as a string in single quotes'max', 'sum'.
When using parametric aggregate functions, the parameter is indicated after the function name in parentheses 'uniqUpTo(6)'.
Syntax
agg_f— The name of an aggregate function which should be a constant.Stringarr1[, arr2, ... , arrN]— N arrays corresponding to the arguments ofagg_f.Array(T)
Query
Response
Query
Response
Query
Response
arrayReduceInRanges
Introduced in: v20.4.0 Applies an aggregate function to array elements in the given ranges and returns an array containing the result corresponding to each range. The function will return the same result as multiplearrayReduce(agg_func, arraySlice(arr1, index, length), ...).
Syntax
agg_f— The name of the aggregate function to use.Stringranges— The range over which to aggregate. An array of tuples,(i, r)containing the indexifrom which to begin from and the rangerover which to aggregate.Array(T)orTuple(T)arr1[, arr2, ... ,arrN]— N arrays as arguments to the aggregate function.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayRemove
Introduced in: v25.11.0 Removes all elements equal to a given value from an array. NULLs are treated as equal. Syntaxarray_remove
Arguments
arr— Array(T) -elem— T
Array(T)
Examples
Example 1
Query
Response
Query
Response
arrayResize
Introduced in: v1.1.0 Changes the length of the array. Syntaxarr— Array to resize.Array(T)size— -The new length of the array. Ifsizeis less than the original size of the array, the array is truncated from the right. Ifsizeis larger than the initial size of the array, the array is extended to the right withextendervalues or default values for the data type of the array items.extender— Value to use for extending the array. Can beNULL.
size. Array(T)
Examples
Example 1
Query
Response
Query
Response
arrayReverse
Introduced in: v1.1.0 Reverses the order of elements of a given array.Function
reverse(arr) performs the same functionality but works on other data-types
in addition to Arrays.arr— The array to reverse.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayReverseFill
Introduced in: v20.1.0 ThearrayReverseFill function sequentially processes a source array from the last
element to the first, evaluating a lambda condition at each position using elements
from the source and condition arrays. When the condition evaluates to false at
position i, the function replaces that element with the element at position i+1
from the current state of the array. The last element is always preserved
regardless of any condition.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T)[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Array(T)
Examples
Example with a single array
Query
Response
Query
Response
arrayReverseSort
Introduced in: v1.1.0 Sorts the elements of an array in descending order. If a functionf is specified, the provided array is sorted according to the result
of the function applied to the elements of the array, and then the sorted array is reversed.
If f accepts multiple arguments, the arrayReverseSort function is passed several arrays that
the arguments of func will correspond to.
If the array to sort contains -Inf, NULL, NaN, or Inf they will be sorted in the following order:
-InfInfNaNNULL
arrayReverseSort is a higher-order function.
Syntax
f(y1[, y2 ... yN])— The lambda function to apply to elements of arrayx. -arr— An array to be sorted.Array(T)-arr1, ..., yN— Optional. N additional arrays, in the case whenfaccepts multiple arguments.
x sorted in descending order if no lambda function is provided, otherwise
it returns an array sorted according to the logic of the provided lambda function, and then reversed. Array(T).
Examples
Example 1
Query
Response
Query
Response
arrayReverseSplit
Introduced in: v20.1.0 Split a source array into multiple arrays. Whenfunc(x[, y1, ..., yN]) returns something other than zero, the array will be split to the right of the element. The array will not be split after the last element.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Lambda function[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Array(Array(T))
Examples
Usage example
Query
Response
arrayRotateLeft
Introduced in: v23.8.0 Rotates an array to the left by the specified number of elements. Negative values ofn are treated as rotating to the right by the absolute value of the rotation.
Syntax
arr— The array for which to rotate the elements.Array(T). -n— Number of elements to rotate.(U)Int8/16/32/64.
Array(T)
Examples
Usage example
Query
Response
Query
Response
arrayRotateRight
Introduced in: v23.8.0 Rotates an array to the right by the specified number of elements. Negative values ofn are treated as rotating to the left by the absolute value of the rotation.
Syntax
arr— The array for which to rotate the elements.Array(T). -n— Number of elements to rotate.(U)Int8/16/32/64.
Array(T)
Examples
Usage example
Query
Response
Query
Response
arrayShiftLeft
Introduced in: v23.8.0 Shifts an array to the left by the specified number of elements. New elements are filled with the provided argument or the default value of the array element type. If the number of elements is negative, the array is shifted to the right. Syntaxarr— The array for which to shift the elements.Array(T). -n— Number of elements to shift.(U)Int8/16/32/64. -default— Optional. Default value for new elements.
Array(T)
Examples
Usage example
Query
Response
Query
Response
Query
Response
arrayShiftRight
Introduced in: v23.8.0 Shifts an array to the right by the specified number of elements. New elements are filled with the provided argument or the default value of the array element type. If the number of elements is negative, the array is shifted to the left. Syntaxarr— The array for which to shift the elements.Array(T)n— Number of elements to shift.(U)Int8/16/32/64default— Optional. Default value for new elements.
Array(T)
Examples
Usage example
Query
Response
Query
Response
Query
Response
arrayShingles
Introduced in: v24.1.0 Generates an array of shingles (similar to ngrams for strings), i.e. consecutive sub-arrays with a specified length of the input array. Syntaxarr— Array for which to generate an array of shingles.Array(T)l— The length of each shingle.(U)Int*
Array(T)
Examples
Usage example
Query
Response
arrayShuffle
Introduced in: v23.2.0 Returns an array of the same size as the original array containing the elements in shuffled order. Elements are reordered in such a way that each possible permutation of those elements has equal probability of appearance.This function will not materialize constants.
arr— The array to shuffle.Array(T)seed (optional)— Optional. The seed to be used with random number generation. If not provided a random one is used.(U)Int*
Array(T)
Examples
Example without seed (unstable results)
Query
Response
Query
Response
arraySimilarity
Introduced in: v25.4.0 Calculates the similarity of two arrays from0 to 1 based on weighted Levenshtein distance.
Syntax
from— first arrayArray(T)to— second arrayArray(T)from_weights— weights for the first array.Array((U)Int*|Float*)to_weights— weights for the second array.Array((U)Int*|Float*)
0 and 1 of the two arrays based on the weighted Levenshtein distance Float64
Examples
Usage example
Query
Response
arraySlice
Introduced in: v1.1.0 Returns a slice of the array, withNULL elements included.
Syntax
arr— Array to slice.Array(T)offset— Indent from the edge of the array. A positive value indicates an offset on the left, and a negative value is an indent on the right. Numbering of the array items begins with1.(U)Int*length— The length of the required slice. If you specify a negative value, the function returns an open slice[offset, array_length - length]. If you omit the value, the function returns the slice[offset, the_end_of_array].(U)Int*
length elements from the specified offset Array(T)
Examples
Usage example
Query
Response
arraySort
Introduced in: v1.1.0 Sorts the elements of the provided array in ascending order. If a lambda functionf is specified, sorting order is determined by the result of
the lambda applied to each element of the array.
If the lambda accepts multiple arguments, the arraySort function is passed several
arrays that the arguments of f will correspond to.
If the array to sort contains -Inf, NULL, NaN, or Inf they will be sorted in the following order:
-InfInfNaNNULL
arraySort is a higher-order function.
Syntax
f(y1[, y2 ... yN])— The lambda function to apply to elements of arrayx. -arr— An array to be sorted.Array(T)-arr1, ..., yN— Optional. N additional arrays, in the case whenfaccepts multiple arguments.
arr sorted in ascending order if no lambda function is provided, otherwise
it returns an array sorted according to the logic of the provided lambda function. Array(T).
Examples
Example 1
Query
Response
Query
Response
Query
Response
arraySplit
Introduced in: v20.1.0 Split a source array into multiple arrays. Whenfunc(x [, y1, ..., yN]) returns something other than zero, the array will be split to the left of the element. The array will not be split before the first element.
Syntax
func(x[, y1, ..., yN])— A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda function. -source_arr— The source array to splitArray(T). -[, cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T).
Array(Array(T))
Examples
Usage example
Query
Response
arraySum
Introduced in: v21.1.0 Returns the sum of elements in the source array. If a lambda functionfunc is specified, returns the sum of elements of the lambda results.
Syntax
func(x[, y1, ..., yN])— Optional. A lambda function which operates on elements of the source array (x) and condition arrays (y).Lambda functionsource_arr— The source array to process.Array(T), cond1_arr, ... , condN_arr]— Optional. N condition arrays providing additional arguments to the lambda function.Array(T)
Query
Response
Query
Response
arraySymmetricDifference
Introduced in: v25.4.0 Takes multiple arrays and returns an array with elements that are not present in all source arrays. The result contains only unique values.The symmetric difference of more than two sets is mathematically defined
as the set of all input elements which occur in an odd number of input sets.
In contrast, function
arraySymmetricDifference simply returns the set of input elements which do not occur in all input sets.arrN— N arrays from which to make the new array.Array(T).
Array(T)
Examples
Usage example
Query
Response
arrayTranspose
Introduced in: v26.4.0 Transposes a two-dimensional array. All inner arrays must have the same length. Syntaxarr— A two-dimensional array to transpose. All inner arrays must have the same length.Array(Array(T))
[i][j] of the result equals element [j][i] of the input. Array(Array(T))
Examples
Square matrix
Query
Response
Query
Response
Query
Response
arrayUnion
Introduced in: v24.10.0 Takes multiple arrays and returns an array which contains all elements that are present in one of the source arrays.The result contains only unique values. SyntaxarrN— N arrays from which to make the new array.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayUniq
Introduced in: v1.1.0 For a single argument passed, counts the number of different elements in the array. For multiple arguments passed, it counts the number of different tuples made of elements at matching positions across multiple arrays. For exampleSELECT arrayUniq([1,2], [3,4], [5,6]) will form the following tuples:
- Position 1: (1,3,5)
- Position 2: (2,4,6)
2.
All arrays passed must have the same length.
Syntax
arr1— Array for which to count the number of unique elements.Array(T)[, arr2, ..., arrN]— Optional. Additional arrays used to count the number of unique tuples of elements at corresponding positions in multiple arrays.Array(T)
UInt32
Examples
Single argument
Query
Response
Query
Response
arrayWithConstant
Introduced in: v20.1.0 Creates an array of lengthlength filled with the constant x.
Syntax
length— Number of elements in the array.(U)Int*x— The value of theNelements in the array, of any type.
N elements of value x. Array(T)
Examples
Usage example
Query
Response
arrayZip
Introduced in: v20.1.0 Combines multiple arrays into a single array. The resulting array contains the corresponding elements of the source arrays grouped into tuples in the listed order of arguments. Syntaxarr1, arr2, ... , arrN— N arrays to combine into a single array.Array(T)
Array(T)
Examples
Usage example
Query
Response
arrayZipUnaligned
Introduced in: v20.1.0 Combines multiple arrays into a single array, allowing for unaligned arrays (arrays of differing lengths). The resulting array contains the corresponding elements of the source arrays grouped into tuples in the listed order of arguments. Syntaxarr1, arr2, ..., arrN— N arrays to combine into a single array.Array(T)
Array(T) or Tuple(T1, T2, ...)
Examples
Usage example
Query
Response
countEqual
Introduced in: v1.1.0 Returns the number of elements in the array equal tox. Equivalent to arrayCount(elem -> elem = x, arr).
NULL elements are handled as separate values.
Syntax
arr— Array to search.Array(T)x— Value in the array to count. Any type.
x UInt64
Examples
Usage example
Query
Response
empty
Introduced in: v1.1.0 Checks whether the input array is empty. An array is considered empty if it does not contain any elements.Can be optimized by enabling the
optimize_functions_to_subcolumns setting. With optimize_functions_to_subcolumns = 1 the function reads only size0 subcolumn instead of reading and processing the whole array column. The query SELECT empty(arr) FROM TABLE; transforms to SELECT arr.size0 = 0 FROM TABLE;.arr— Input array.Array(T)
1 for an empty array or 0 for a non-empty array UInt8
Examples
Usage example
Query
Response
emptyArrayDate
Introduced in: v1.1.0 Returns an empty Date array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayDateTime
Introduced in: v1.1.0 Returns an empty DateTime array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayFloat32
Introduced in: v1.1.0 Returns an empty Float32 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayFloat64
Introduced in: v1.1.0 Returns an empty Float64 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayInt16
Introduced in: v1.1.0 Returns an empty Int16 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayInt32
Introduced in: v1.1.0 Returns an empty Int32 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayInt64
Introduced in: v1.1.0 Returns an empty Int64 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayInt8
Introduced in: v1.1.0 Returns an empty Int8 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayString
Introduced in: v1.1.0 Returns an empty String array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayToSingle
Introduced in: v1.1.0 Accepts an empty array and returns a one-element array that is equal to the default value. Syntaxarr— An empty array.Array(T)
Array(T)
Examples
Basic example
Query
Response
emptyArrayUInt16
Introduced in: v1.1.0 Returns an empty UInt16 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayUInt32
Introduced in: v1.1.0 Returns an empty UInt32 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayUInt64
Introduced in: v1.1.0 Returns an empty UInt64 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
emptyArrayUInt8
Introduced in: v1.1.0 Returns an empty UInt8 array Syntax- None.
Array(T)
Examples
Usage example
Query
Response
has
Introduced in: v1.1.0 Returns whether the array contains the specified element, the map contains the specified key, or the JSON object contains the specified path. For JSON, nested paths are supported using dot notation (e.g., ‘a.b.c’). When the first argument is a constant array and the second argument is a column or expression,has(constant_array, column) behaves like column IN (constant_array) and can use primary key and data-skipping indexes for optimization. For example, has([1, 10, 100], id) can leverage the primary key index if id is part of the PRIMARY KEY.
This optimization also applies when the column is wrapped in monotonic functions (e.g., has([...], toDate(ts))).
Syntax
haystack— The source array, map, or JSON.ArrayorMaporJSONneedle— The value to search for (element in array, key in map, or path string in JSON).
1 if the haystack contains the specified needle, otherwise 0. UInt8
Examples
Array basic usage
Query
Response
Query
Response
Query
Response
Query
Response
hasAll
Introduced in: v1.1.0 Checks whether one array is a subset of another.- An empty array is a subset of any array.
Nullis processed as a value.- The order of values in both the arrays does not matter.
set— Array of any type with a set of elements.Array(T)subset— Array of any type that shares a common supertype withsetcontaining elements that should be tested to be a subset ofset.Array(T)
1, ifsetcontains all of the elements fromsubset.0, otherwise.
NO_COMMON_TYPE exception if the set and subset elements do not share a common supertype.
Examples
Empty arrays
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
hasAny
Introduced in: v1.1.0 Checks whether two arrays have intersection by some elements.Nullis processed as a value.- The order of the values in both of the arrays does not matter.
arr_x— Array of any type with a set of elements.Array(T)arr_y— Array of any type that shares a common supertype with arrayarr_x.Array(T)
1, ifarr_xandarr_yhave one similar element at least.0, otherwise.
NO_COMMON_TYPE exception if any of the elements of the two arrays do not share a common supertype.
Examples
One array is empty
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
hasSubstr
Introduced in: v20.6.0 Checks whether all the elements of array2 appear in a array1 in the same exact order. Therefore, the function will return1, if and only if array1 = prefix + array2 + suffix.
In other words, the functions will check whether all the elements of array2 are contained in array1 like the hasAll function.
In addition, it will check that the elements are observed in the same order in both array1 and array2.
- The function will return
1if array2 is empty. Nullis processed as a value. In other wordshasSubstr([1, 2, NULL, 3, 4], [2,3])will return0. However,hasSubstr([1, 2, NULL, 3, 4], [2,NULL,3])will return1- The order of values in both the arrays does matter.
NO_COMMON_TYPE exception if any of the elements of the two arrays do not share a common supertype.
Syntax
arr1— Array of any type with a set of elements.Array(T)arr2— Array of any type with a set of elements.Array(T)
1 if array arr1 contains array arr2. Otherwise, returns 0. UInt8
Examples
Both arrays are empty
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
indexOf
Introduced in: v1.1.0 Returns the index of the first element with value ‘x’ (starting from 1) if it is in the array. If the array does not contain the searched-for value, the function returns0.
Elements set to NULL are handled as normal values.
Syntax
arr— An array to search in forx.Array(T)x— Value of the first matching element inarrfor which to return an index.UInt64
x in arr if it exists. Otherwise, returns 0. UInt64
Examples
Basic example
Query
Response
Query
Response
indexOfAssumeSorted
Introduced in: v24.12.0 Returns the index of the first element with value ‘x’ (starting from1) if it is in the array.
If the array does not contain the searched-for value, the function returns 0.
Unlike the
indexOf function, this function assumes that the array is sorted in
ascending order. If the array is not sorted, results are undefined.arr— A sorted array to search.Array(T)x— Value of the first matching element in sortedarrfor which to return an index.UInt64
x in arr if it exists. Otherwise, returns 0. UInt64
Examples
Basic example
Query
Response
kql_array_sort_asc
Introduced in: v23.10.0 Sorts one or more arrays in ascending order. The first array is sorted, and subsequent arrays are reordered to match the first array’s sorted order. Null values are placed at the end. This is a KQL (Kusto Query Language) compatibility function. Syntaxarray1— The array to sort.Array(T)array2— Optional. Additional arrays to reorder according to array1’s sort order.Array(T)nulls_last— Optional. A boolean indicating whether nulls should appear last. Default is true.UInt8
Tuple(Array, ...)
Examples
Basic usage
Query
Response
kql_array_sort_desc
Introduced in: v23.10.0 Sorts one or more arrays in descending order. The first array is sorted, and subsequent arrays are reordered to match the first array’s sorted order. Null values are placed at the end. This is a KQL (Kusto Query Language) compatibility function. Syntaxarray1— The array to sort.Array(T)array2— Optional additional arrays to reorder according to array1’s sort order.Array(T)nulls_last— Optional boolean indicating whether nulls should appear last. Default is true.UInt8
Tuple(Array, ...)
Examples
Basic usage
Query
Response
length
Introduced in: v1.1.0 Calculates the length of a string or array.- For String or FixedString arguments: calculates the number of bytes in the string.
- For Array arguments: calculates the number of elements in the array.
- If applied to a FixedString argument, the function is a constant expression.
OCTET_LENGTH
Arguments
x— Value for which to calculate the number of bytes (for String/FixedString) or elements (for Array).StringorFixedStringorArray(T)
x / the number of elements in array x UInt64
Examples
String example
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
notEmpty
Introduced in: v1.1.0 Checks whether the input array is non-empty. An array is considered non-empty if it contains at least one element.Can be optimized by enabling the
optimize_functions_to_subcolumns setting. With optimize_functions_to_subcolumns = 1 the function reads only size0 subcolumn instead of reading and processing the whole array column. The query SELECT notEmpty(arr) FROM table transforms to SELECT arr.size0 != 0 FROM TABLE.arr— Input array.Array(T)
1 for a non-empty array or 0 for an empty array UInt8
Examples
Usage example
Query
Response
range
Introduced in: v1.1.0 Returns an array of numbers fromstart to end - 1 by step.
The supported types are:
-
UInt8/16/32/64 -
Int8/16/32/64] -
All arguments
start,end,stepmust be one of the above supported types. Elements of the returned array will be a super type of the arguments. -
An exception is thrown if the function returns an array with a total length more than the number of elements specified by setting
function_range_max_elements_in_block. -
Returns
NULLif any argument has Nullable(nothing) type. An exception is thrown if any argument hasNULLvalue (Nullable(T) type).
start— Optional. The first element of the array. Required ifstepis used. Default value:0. -end— Required. The number before which the array is constructed. -step— Optional. Determines the incremental step between each element in the array. Default value:1.
start to end - 1 by step. Array(T)
Examples
Usage example
Query
Response
replicate
Introduced in: v1.1.0 Creates an array with a single value. Syntaxarr filled with value x. Array(T)
Examples
Usage example
Query
Response
reverse
Introduced in: v1.1.0 Reverses the order of the elements in the input array or the characters in the input string. SyntaxQuery
Response
Query
Response