You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "writer-jill (via GitHub)" <gi...@apache.org> on 2023/08/07 13:59:45 UTC

Re: [PR] document expression aggregator (druid)

writer-jill commented on code in PR #14497:
URL: https://github.com/apache/druid/pull/14497#discussion_r1285898341


##########
docs/querying/aggregations.md:
##########
@@ -50,94 +56,121 @@ query time.
 
 ### Sum aggregators
 
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "longSum", "doubleSum", or "floatSum". | Yes |
+| `name` | Output name for the summed value. | Yes |
+| `fieldName` | Name of the input column to sum over. At most one of `fieldName` or `expression` must be defined. | No |
+| `expression` | Alternative to `fieldName`, an inline [expression](./math-expr.md) can be specified instead. At most one of `fieldName` or `expression` can be defined. | No |

Review Comment:
   ```suggestion
   | `expression` | You can specify an inline [expression](./math-expr.md) as an alternative to `fieldName`. You must define `fieldName` or `expression`. | No |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -50,94 +56,121 @@ query time.
 
 ### Sum aggregators
 
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "longSum", "doubleSum", or "floatSum". | Yes |
+| `name` | Output name for the summed value. | Yes |
+| `fieldName` | Name of the input column to sum over. At most one of `fieldName` or `expression` must be defined. | No |

Review Comment:
   ```suggestion
   | `fieldName` | Name of the input column to sum over. You must define `fieldName` or `expression`. | No |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -50,94 +56,121 @@ query time.
 
 ### Sum aggregators
 
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "longSum", "doubleSum", or "floatSum". | Yes |
+| `name` | Output name for the summed value. | Yes |
+| `fieldName` | Name of the input column to sum over. At most one of `fieldName` or `expression` must be defined. | No |
+| `expression` | Alternative to `fieldName`, an inline [expression](./math-expr.md) can be specified instead. At most one of `fieldName` or `expression` can be defined. | No |
+
 #### `longSum` aggregator
 
 Computes the sum of values as a 64-bit, signed integer.
 
+Example:
 ```json
-{ "type" : "longSum", "name" : <output_name>, "fieldName" : <metric_name> }
+{ "type" : "longSum", "name" : "sumLong", "fieldName" : "aLong" }
 ```
 
-The `longSum` aggregator takes the following properties:
-* `name`: Output name for the summed value
-* `fieldName`: Name of the metric column to sum over
-
 #### `doubleSum` aggregator
 
 Computes and stores the sum of values as a 64-bit floating point value. Similar to `longSum`.
 
+Example:
 ```json
-{ "type" : "doubleSum", "name" : <output_name>, "fieldName" : <metric_name> }
+{ "type" : "doubleSum", "name" : "sumDouble", "fieldName" : "aDouble" }
 ```
 
 #### `floatSum` aggregator
 
 Computes and stores the sum of values as a 32-bit floating point value. Similar to `longSum` and `doubleSum`.
 
+Example:
 ```json
-{ "type" : "floatSum", "name" : <output_name>, "fieldName" : <metric_name> }
+{ "type" : "floatSum", "name" : "sumFloat", "fieldName" : "aFloat" }
 ```
 
 ### Min and max aggregators
 
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "doubleMin", "doubleMax", "floatMin", "floatMax", "longMin", or "longMax". | Yes |
+| `name` | Output name for the min or max value. | Yes |
+| `fieldName` | Name of the input column to compute the minimum or maximum value over. At most one of `fieldName` or `expression` can be defined. | No |
+| `expression` | Alternative to `fieldName`, an inline [expression](./math-expr.md) can be specified instead. At most one of `fieldName` or `expression` can be defined. | No |

Review Comment:
   ```suggestion
   | `expression` | You can specify an inline [expression](./math-expr.md) as an alternative to `fieldName`. You must define `fieldName` or `expression`. | No |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -50,94 +56,121 @@ query time.
 
 ### Sum aggregators
 
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "longSum", "doubleSum", or "floatSum". | Yes |
+| `name` | Output name for the summed value. | Yes |
+| `fieldName` | Name of the input column to sum over. At most one of `fieldName` or `expression` must be defined. | No |
+| `expression` | Alternative to `fieldName`, an inline [expression](./math-expr.md) can be specified instead. At most one of `fieldName` or `expression` can be defined. | No |
+
 #### `longSum` aggregator
 
 Computes the sum of values as a 64-bit, signed integer.
 
+Example:
 ```json
-{ "type" : "longSum", "name" : <output_name>, "fieldName" : <metric_name> }
+{ "type" : "longSum", "name" : "sumLong", "fieldName" : "aLong" }
 ```
 
-The `longSum` aggregator takes the following properties:
-* `name`: Output name for the summed value
-* `fieldName`: Name of the metric column to sum over
-
 #### `doubleSum` aggregator
 
 Computes and stores the sum of values as a 64-bit floating point value. Similar to `longSum`.
 
+Example:
 ```json
-{ "type" : "doubleSum", "name" : <output_name>, "fieldName" : <metric_name> }
+{ "type" : "doubleSum", "name" : "sumDouble", "fieldName" : "aDouble" }
 ```
 
 #### `floatSum` aggregator
 
 Computes and stores the sum of values as a 32-bit floating point value. Similar to `longSum` and `doubleSum`.
 
+Example:
 ```json
-{ "type" : "floatSum", "name" : <output_name>, "fieldName" : <metric_name> }
+{ "type" : "floatSum", "name" : "sumFloat", "fieldName" : "aFloat" }
 ```
 
 ### Min and max aggregators
 
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "doubleMin", "doubleMax", "floatMin", "floatMax", "longMin", or "longMax". | Yes |
+| `name` | Output name for the min or max value. | Yes |
+| `fieldName` | Name of the input column to compute the minimum or maximum value over. At most one of `fieldName` or `expression` can be defined. | No |

Review Comment:
   ```suggestion
   | `fieldName` | Name of the input column to compute the minimum or maximum value over. You must specify `fieldName` or `expression`. | No |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -261,88 +314,73 @@ Queries with first or last aggregators on a segment created with rollup return t
 
 Returns any value including null. This aggregator can simplify and optimize the performance by returning the first encountered value (including null)
 
-#### `doubleAny` aggregator
+#### Numeric any aggregators
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "doubleAny", "floatAny", or "longAny". | Yes |
+| `name` | Output name for the value. | Yes |
+| `fieldName` | Name of the input column to compute the value over. | Yes |
+
+##### `doubleAny` aggregator
 
 `doubleAny` returns any double metric value.
 
+Example:
 ```json
 {
   "type" : "doubleAny",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>
+  "name" : "anyDouble",
+  "fieldName" : "aDouble"
 }
 ```
 
-#### `floatAny` aggregator
+##### `floatAny` aggregator
 
 `floatAny` returns any float metric value.
 
+Example:
 ```json
 {
   "type" : "floatAny",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>
+  "name" : "anyFloat",
+  "fieldName" : "aFloat"
 }
 ```
 
-#### `longAny` aggregator
+##### `longAny` aggregator
 
 `longAny` returns any long metric value.
 
+Example:
 ```json
 {
   "type" : "longAny",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
+  "name" : "anyLong",
+  "fieldName" : "aLong"
 }
 ```
 
 #### `stringAny` aggregator
 
-`stringAny` returns any string metric value.
-
-```json
-{
-  "type" : "stringAny",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "maxStringBytes" : <integer> # (optional, defaults to 1024),
-}
-```
-
-### JavaScript aggregator
-
-Computes an arbitrary JavaScript function over a set of columns (both metrics and dimensions are allowed). Your
-JavaScript functions are expected to return floating-point values.
-
-```json
-{ "type": "javascript",
-  "name": "<output_name>",
-  "fieldNames"  : [ <column1>, <column2>, ... ],
-  "fnAggregate" : "function(current, column1, column2, ...) {
-                     <updates partial aggregate (current) based on the current row values>
-                     return <updated partial aggregate>
-                   }",
-  "fnCombine"   : "function(partialA, partialB) { return <combined partial results>; }",
-  "fnReset"     : "function()                   { return <initial value>; }"
-}
-```
+`stringAny` returns any string value present in the input.
 
-**Example**
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "stringAny". | Yes |
+| `name` | Output name for the value. | Yes |
+| `fieldName` | Name of the input column to compute the value over. | Yes |
+| `maxStringBytes` | Maximum size of string values to accumulate when computing the first or last value per group. Values longer than this will be truncated. | No, defaults to 1024 |

Review Comment:
   ```suggestion
   | `maxStringBytes` | Maximum size of string values to accumulate when computing the first or last value per group. Values longer than this will be truncated. | No. Defaults to 1024. |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -422,6 +460,117 @@ It is not possible to determine a priori how well this aggregator will behave fo
 
 For these reasons, we have deprecated this aggregator and recommend using the DataSketches Quantiles aggregator instead for new and existing use cases, although we will continue to support Approximate Histogram for backwards compatibility.
 
+
+## Expression aggregations
+
+### Expression aggregator
+
+Aggregator applicable only at query time. Aggregates results using [Druid expressions](./math-expr.md) functions to facilitate building custom functions.
+
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "expression". | Yes |
+| `name` | The aggregator output name. | Yes |
+| `fields` | The list of aggregator input columns. | Yes |
+| `accumulatorIdentifier` | The variable which identifies the accumulator value in the `fold` and `combine` expressions. | No (default `__acc`)|

Review Comment:
   ```suggestion
   | `accumulatorIdentifier` | The variable which identifies the accumulator value in the `fold` and `combine` expressions. | No. Default is `__acc`|
   ```



##########
docs/querying/aggregations.md:
##########
@@ -147,111 +180,131 @@ The string-typed aggregators, `stringFirst` and `stringLast`, are supported for
 
 Queries with first or last aggregators on a segment created with rollup return the rolled up value, not the first or last value from the raw ingested data.
 
-#### `doubleFirst` aggregator
+#### Numeric first and last aggregators
 
-`doubleFirst` computes the metric value with the minimum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "doubleFirst", "doubleLast", "floatFirst", "floatLast", "longFirst", "longLast". | Yes |
+| `name` | Output name for the first or last value. | Yes |
+| `fieldName` | Name of the input column to compute the first or last value over. | Yes |
+| `timeColumn` | Name of the input column to use for time values. Must be a LONG typed column. | No, defaults to `__time` |
 
+##### `doubleFirst` aggregator
+
+`doubleFirst` computes the input value with the minimum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
+
+Example:
 ```json
 {
   "type" : "doubleFirst",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "timeColumn" : <time_column_name> # (optional, defaults to __time)
+  "name" : "firstDouble",
+  "fieldName" : "aDouble"
 }
 ```
 
-#### `doubleLast` aggregator
+##### `doubleLast` aggregator
 
-`doubleLast` computes the metric value with the maximum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
+`doubleLast` computes the input value with the maximum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
 
+Example:
 ```json
 {
   "type" : "doubleLast",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "timeColumn" : <time_column_name> # (optional, defaults to __time)
+  "name" : "lastDouble",
+  "fieldName" : "aDouble",
+  "timeColumn" : "longTime"
 }
 ```
 
-#### `floatFirst` aggregator
+##### `floatFirst` aggregator
 
-`floatFirst` computes the metric value with the minimum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
+`floatFirst` computes the input value with the minimum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
 
+Example:
 ```json
 {
   "type" : "floatFirst",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "timeColumn" : <time_column_name> # (optional, defaults to __time)
+  "name" : "firstFloat",
+  "fieldName" : "aFloat"
 }
 ```
 
-#### `floatLast` aggregator
+##### `floatLast` aggregator
 
 `floatLast` computes the metric value with the maximum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
 
+Example:
 ```json
 {
   "type" : "floatLast",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "timeColumn" : <time_column_name> # (optional, defaults to __time)
+  "name" : "lastFloat",
+  "fieldName" : "aFloat"
 }
 ```
 
-#### `longFirst` aggregator
+##### `longFirst` aggregator
 
 `longFirst` computes the metric value with the minimum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
 
+Example:
 ```json
 {
   "type" : "longFirst",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "timeColumn" : <time_column_name> # (optional, defaults to __time)
+  "name" : "firstLong",
+  "fieldName" : "aLong"
 }
 ```
 
-#### `longLast` aggregator
+##### `longLast` aggregator
 
 `longLast` computes the metric value with the maximum value for time column or 0 in default mode, or `null` in SQL-compatible mode if no row exists.
 
+Example:
 ```json
 {
   "type" : "longLast",
-  "name" : <output_name>,
-  "fieldName" : <metric_name>,
-  "timeColumn" : <time_column_name> # (optional, defaults to __time)
+  "name" : "lastLong",
+  "fieldName" : "aLong",
+  "timeColumn" : "longTime"
 }
 ```
 
+#### String first and last aggregators
+
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "stringFirst", "stringLast". | Yes |
+| `name` | Output name for the first or last value. | Yes |
+| `fieldName` | Name of the input column to compute the first or last value over. | Yes |
+| `timeColumn` | Name of the input column to use for time values. Must be a LONG typed column. | No, defaults to `__time` |

Review Comment:
   ```suggestion
   | `timeColumn` | Name of the input column to use for time values. Must be a LONG typed column. | No. Defaults to `__time` |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -422,6 +460,117 @@ It is not possible to determine a priori how well this aggregator will behave fo
 
 For these reasons, we have deprecated this aggregator and recommend using the DataSketches Quantiles aggregator instead for new and existing use cases, although we will continue to support Approximate Histogram for backwards compatibility.
 
+
+## Expression aggregations
+
+### Expression aggregator
+
+Aggregator applicable only at query time. Aggregates results using [Druid expressions](./math-expr.md) functions to facilitate building custom functions.
+
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "expression". | Yes |
+| `name` | The aggregator output name. | Yes |
+| `fields` | The list of aggregator input columns. | Yes |
+| `accumulatorIdentifier` | The variable which identifies the accumulator value in the `fold` and `combine` expressions. | No (default `__acc`)|
+| `fold` | The expression to accumulate values from `fields`. The result of the expression will be stored in `accumulatorIdentifier` and available to the next computation. | Yes |
+| `combine` | The expression to combine the results of various `fold` expressions of each segment when merging results. The input is available to the expression as a variable identified by the `name`. | No (default to `fold` expression if and only if the expression has a single input in `fields`)|

Review Comment:
   ```suggestion
   | `combine` | The expression to combine the results of various `fold` expressions of each segment when merging results. The input is available to the expression as a variable identified by the `name`. | No. Default is `fold` expression if the expression has a single input in `fields`)|
   ```



##########
docs/querying/aggregations.md:
##########
@@ -430,17 +579,30 @@ A filtered aggregator wraps any given aggregator, but only aggregates the values
 
 This makes it possible to compute the results of a filtered and an unfiltered aggregation simultaneously, without having to issue multiple queries, and use both results as part of post-aggregations.
 
-*Note:* If only the filtered results are required, consider putting the filter on the query itself, which will be much faster since it does not require scanning all the data.
+If only the filtered results are required, consider putting the filter on the query itself, which will be much faster since it does not require scanning all the data.

Review Comment:
   ```suggestion
   If only the filtered results are required, consider putting the filter on the query itself. This will be much faster because it does not require scanning all the data.
   ```



##########
docs/querying/aggregations.md:
##########
@@ -422,6 +460,117 @@ It is not possible to determine a priori how well this aggregator will behave fo
 
 For these reasons, we have deprecated this aggregator and recommend using the DataSketches Quantiles aggregator instead for new and existing use cases, although we will continue to support Approximate Histogram for backwards compatibility.
 
+
+## Expression aggregations
+
+### Expression aggregator
+
+Aggregator applicable only at query time. Aggregates results using [Druid expressions](./math-expr.md) functions to facilitate building custom functions.
+
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "expression". | Yes |
+| `name` | The aggregator output name. | Yes |
+| `fields` | The list of aggregator input columns. | Yes |
+| `accumulatorIdentifier` | The variable which identifies the accumulator value in the `fold` and `combine` expressions. | No (default `__acc`)|
+| `fold` | The expression to accumulate values from `fields`. The result of the expression will be stored in `accumulatorIdentifier` and available to the next computation. | Yes |

Review Comment:
   ```suggestion
   | `fold` | The expression to accumulate values from `fields`. The result of the expression is stored in `accumulatorIdentifier` and available to the next computation. | Yes |
   ```



##########
docs/querying/aggregations.md:
##########
@@ -422,6 +460,117 @@ It is not possible to determine a priori how well this aggregator will behave fo
 
 For these reasons, we have deprecated this aggregator and recommend using the DataSketches Quantiles aggregator instead for new and existing use cases, although we will continue to support Approximate Histogram for backwards compatibility.
 
+
+## Expression aggregations
+
+### Expression aggregator
+
+Aggregator applicable only at query time. Aggregates results using [Druid expressions](./math-expr.md) functions to facilitate building custom functions.
+
+| Property | Description | Required |
+| --- | --- | --- |
+| `type` | Must be "expression". | Yes |
+| `name` | The aggregator output name. | Yes |
+| `fields` | The list of aggregator input columns. | Yes |
+| `accumulatorIdentifier` | The variable which identifies the accumulator value in the `fold` and `combine` expressions. | No (default `__acc`)|
+| `fold` | The expression to accumulate values from `fields`. The result of the expression will be stored in `accumulatorIdentifier` and available to the next computation. | Yes |
+| `combine` | The expression to combine the results of various `fold` expressions of each segment when merging results. The input is available to the expression as a variable identified by the `name`. | No (default to `fold` expression if and only if the expression has a single input in `fields`)|
+| `compare` | The comparator expression which can only refer to two input variables, `o1` and `o2`, where `o1` and `o2` are the output of `fold` or `combine` expressions, and must adhere to the Java comparator contract. If not set, the aggregator will try to fall back to an output type appropriate comparator. | No |
+| `finalize` | The finalize expression which can only refer to a single input variable, `o`. This expression is used to perform any final transformation of the output of the `fold` or `combine` expressions. If not set, then the value is not transformed. | No |
+| `initialValue` | The initial value of the accumulator for the `fold` (and `combine`, if `InitialCombineValue` is null) expression. | Yes |
+| `initialCombineValue` | The initial value of the accumulator for the `combine` expression. | No (default `initialValue`) |
+| `isNullUnlessAggregated` | Indicates that the default output value should be `null` if the aggregator does not process any rows. If true, the value is `null`, if false, the result of running the expressions with initial values is used instead. | No (defaults to the value of `druid.generic.useDefaultValueForNull`)|
+| `shouldAggregateNullInputs` | Indicates if the `fold` expression should operate on any `null` input values. | No (defaults to `true`) |
+| `shouldCombineAggregateNullInputs` | Indicates if the `combine` expression should operate on any `null` input values. | No (defaults to the value of `shouldAggregateNullInputs`) |
+| `maxSizeBytes` | Maximum size in bytes that variably sized aggregator output types such as strings and arrays are allowed to grow to before the aggregation fails. | No (8192 bytes) |

Review Comment:
   ```suggestion
   | `maxSizeBytes` | Maximum size in bytes that variably sized aggregator output types such as strings and arrays are allowed to grow to before the aggregation fails. | No. Default is 8192 bytes. |
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org