Oiliúint
Modúl
Gain insights from your data by using Kusto Query Language - Training
Learn how to write advanced queries in Kusto Query Language (KQL) by using the aggregation functions, the render operator, and variables.
Ní thacaítear leis an mbrabhsálaí seo a thuilleadh.
Uasghrádú go Microsoft Edge chun leas a bhaint as na gnéithe is déanaí, nuashonruithe slándála, agus tacaíocht theicniúil.
reduce
functionApplies to: Databricks SQL
Databricks Runtime
Aggregates elements in an array using a custom aggregator. This function is a synonym for aggregate
function.
reduce(expr, start, merge [, finish] )
expr
: An ARRAY
expression.start
: An initial value of any type.merge
: A lambda function used to aggregate the current element.finish
: An optional lambda function used to finalize the aggregation.The result type matches the result type of the finish
lambda function if exists or start
.
Applies an expression to an initial state and all elements in the array, and reduces this to a single state. The final state is converted into the final result by applying a finish
function.
The merge
function takes two parameters. The first is the accumulator, and the second is the element to be aggregated.
The accumulator and the result must be of the type of start
.
The optional finish
function takes one parameter and returns the final result.
> SELECT reduce(array(1, 2, 3), 0, (acc, x) -> acc + x);
6
> SELECT reduce(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);
60
> SELECT reduce(array(1, 2, 3, 4),
named_struct('sum', 0, 'cnt', 0),
(acc, x) -> named_struct('sum', acc.sum + x, 'cnt', acc.cnt + 1),
acc -> acc.sum / acc.cnt) AS avg
1.5
Oiliúint
Modúl
Gain insights from your data by using Kusto Query Language - Training
Learn how to write advanced queries in Kusto Query Language (KQL) by using the aggregation functions, the render operator, and variables.
Doiciméadúchán
filter function - Azure Databricks - Databricks SQL
Learn the syntax of the filter function of the SQL language in Databricks SQL and Databricks Runtime.
exists function - Azure Databricks - Databricks SQL
Learn the syntax of the exists function of the SQL language in Databricks SQL and Databricks Runtime.
Lambda functions - Azure Databricks - Databricks SQL
Learn about lambda function in Databricks SQL and Databricks Runtime. A lambda function is a parameterized expression that can be passed to a function to control its behavior.