You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "gortiz (via GitHub)" <gi...@apache.org> on 2026/09/14 12:06:17 UTC
[PR] Support generateArray in the multi-stage engine [pinot]
gortiz opened a new pull request, #19552:
URL: https://github.com/apache/pinot/pull/19552
## Problem
`generateArray` resolves only in the single-stage engine, where `TransformFunctionFactory` special-cases it by name. The multi-stage engine offers the typed `generate{Int,Long,Float,Double}Array` scalars instead, but folding a call to any of them throws:
```
ClassCastException: class [J cannot be cast to class [Ljava.lang.Object;
at PinotEvaluateLiteralRule.evaluateLiteralOnlyFunction(PinotEvaluateLiteralRule.java:241)
```
`PinotEvaluateLiteralRule` reads an array result by casting it to `Object[]`, with a special case for `double[]` only, so every other primitive array fails. `generateDoubleArray` is the only one of the four usable today.
The generators also mishandle their own arguments. A literal call is evaluated on the broker while planning, so these are broker-side failures:
| Call | Today |
|---|---|
| `generateLongArray(0, 10, 0)` | `ArithmeticException: / by zero` |
| `generateLongArray(10, 0, 1)` | `NegativeArraySizeException: -9` |
| `generateLongArray(0, Long.MAX_VALUE, 1)` | silently empty — the length is truncated by an `(int)` cast |
| `generateLongArray(0, 1000000000, 1)` | 8 GB allocation, no bound of any kind |
| `generateLongArray(7, 7, 1)` | rejected, though a zero span is a valid single element sequence |
## Changes
**`PinotEvaluateLiteralRule`** — read array elements with `java.lang.reflect.Array`, which handles primitive and object arrays uniformly, replacing the `Object[]` cast and its `double[]` special case. This fixes constant folding for any scalar function returning a primitive array, not only these.
**`GenerateArrayScalarFunction`** (new) — registers `generateArray` for the multi-stage engine as a `PinotScalarFunction`, which can dispatch on argument *types*; the method level `@ScalarFunction` annotation dispatches on argument *count* alone, so one name cannot cover four element types. The element type is the widest of the arguments:
```sql
generateArray(0, 6, 2) -- ARRAY(0, 2, 4, 6)
generateArray(1633078800000, 1633080600000, 1800000) -- ARRAY(...:BIGINT, ...:BIGINT)
generateArray(0, 1, 0.5) -- ARRAY(0.0E0:DOUBLE, ...)
```
This follows the existing scalar-for-MSE / transform-for-SSE pattern (`ArrayLengthScalarFunction`). The single-stage transform function is kept, since it infers the element type from literals in a way the scalar registry cannot express, but it now delegates to `ArrayFunctions` so the two engines cannot disagree on the sequence or on which arguments are rejected.
**`ArrayFunctions`** — validate the increment, bound the length at 100 000 elements, add `(start, end)` overloads defaulting the increment to `1` (or `-1` when counting down), and index each element from `start` instead of accumulating, so a floating point sequence does not drift. The length is checked on the step count rather than the length so a span of `Long.MAX_VALUE` cannot overflow into a small positive size.
## Why
A dense time grid to `UNNEST` and left join a sparse series onto is how gap filling is expressed relationally in the multi-stage engine. Without a series generator the grid has to be faked, typically with an unrelated table and `ROW_NUMBER`, which needs a table with enough rows and hides the bucket count in a `LIMIT` — get it wrong and the result is silently truncated rather than an error:
```sql
-- before
WITH someRows AS (SELECT 1 FROM some_other_table LIMIT 6),
timeBuckets AS (SELECT ROW_NUMBER() OVER () * 1800000 + 1633078800000 - 1800000 AS ts FROM someRows)
...
-- after
SELECT ts FROM UNNEST(generateArray(1633078800000, 1633089600000, 1800000)) AS grid(ts)
```
## Backward compatibility
Single-stage behaviour changes in three ways, all of them fixes: a zero span now yields `[start]` instead of throwing; the two argument form now counts down when `end < start` instead of erroring; and a bad increment raises `IllegalArgumentException` rather than `IllegalStateException`, since validation moved into `ArrayFunctions`. The existing test is updated accordingly. The length bound is new — a call generating more than 100 000 elements now fails with a clear message instead of allocating.
## Testing
| Suite | Tests |
|---|---|
| `ResourceBasedQueriesTest`, full suite | 3710, 0 failures |
| `QueryCompilationTest` + `UnnestSqlPlannerTest` | 257 |
| `GenerateArrayTransformFunctionTest` + `ArrayFunctionsTest` (pinot-core) | 52 |
| `GenerateArrayFunctionsTest` + `ArrayFunctionsTest` (pinot-common) | 14 |
New coverage:
- `GenerateArrayFunctionsTest` — sequence semantics, every rejected argument shape, timestamps past 2^53, and the absence of floating point drift.
- `QueryCompilationTest` — the folded array literal, the element type dispatch, and the planning time rejections.
- `GenerateArray.json` — end to end through `ResourceBasedQueriesTest`, including the full gap fill query (grid × keys, `LEFT JOIN`, `LAST_VALUE ... IGNORE NULLS`) returning the carried forward rows.
The new end-to-end cases set `ignoreLiteMode` and `ignoreV2Optimizer`: both planners reject `UNNEST` outright with `Unexpected relNode type: Uncollect`, independently of this change.
## Note on `all-functions.yaml`
Only the five affected entries are updated. The snapshot cannot be regenerated wholesale at the moment: `NotUdf` looks up `LogicalFunctions.not(boolean)` while the method takes a `Boolean`, so `ServiceLoader.load(Udf.class)` throws and `UdfTest` cannot run at all. The file is already stale as a result — 488 entries against 564 registered functions, with entries such as `and.scalar` still `null`. The five entries here were rendered with the same mapper the generator uses and verified against the live registries. The `NotUdf` mismatch looks worth a separate fix.
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Support generateArray in the multi-stage engine [pinot]
Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz merged PR #19552:
URL: https://github.com/apache/pinot/pull/19552
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Support generateArray in the multi-stage engine [pinot]
Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz commented on code in PR #19552:
URL: https://github.com/apache/pinot/pull/19552#discussion_r4280856950
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
+ List.of(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.REAL, SqlTypeName.DOUBLE);
+
+ /// Element type to the [ArrayFunctions] method generating it, by argument count.
+ private static final Map<ColumnDataType, Map<Integer, FunctionInfo>> FUNCTION_INFO_MAP =
+ new EnumMap<>(ColumnDataType.class);
+
+ static {
+ register(ColumnDataType.INT, "generateIntArray", int.class);
+ register(ColumnDataType.LONG, "generateLongArray", long.class);
+ register(ColumnDataType.FLOAT, "generateFloatArray", float.class);
+ register(ColumnDataType.DOUBLE, "generateDoubleArray", double.class);
+ }
+
+ private static void register(ColumnDataType elementType, String methodName, Class<?> argumentClass) {
+ try {
+ FUNCTION_INFO_MAP.put(elementType, Map.of(2,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass)), 3,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass, argumentClass))));
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to find the " + methodName + " implementation of " + NAME, e);
+ }
+ }
+
+ /// Marks the function as not deterministic so that neither engine folds a call on literal arguments into an array
+ /// literal at the broker. Folding would serialize the whole sequence, up to the maximum length [ArrayFunctions]
+ /// allows, into the query plan sent to every server, while evaluating it on the server only needs the three
+ /// arguments. The function is still [FunctionVolatility#IMMUTABLE]: the same arguments always generate the same
+ /// sequence, so it stays usable in ingestion transforms.
+ private static FunctionInfo functionInfo(Method method) {
+ return new FunctionInfo(method, ArrayFunctions.class, false, false, FunctionVolatility.IMMUTABLE);
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public PinotSqlFunction toPinotSqlFunction() {
+ // The third operand is the increment, which defaults to 1 (or -1 when counting down) when omitted.
+ return new PinotSqlFunction(NAME, GenerateArrayScalarFunction::inferReturnType,
+ OperandTypes.family(List.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC), i -> i == 2));
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(ColumnDataType[] argumentTypes) {
+ ColumnDataType elementType = getElementType(argumentTypes);
+ return elementType != null ? getFunctionInfo(elementType, argumentTypes.length) : null;
+ }
+
+ /// The element type of the sequence generated from arguments of these types: `INT`, `LONG`, `FLOAT` or `DOUBLE`,
+ /// whichever is the widest of the argument types. Returns `null` if a sequence cannot be generated from one of them.
+ ///
+ /// The single-stage `GenerateArrayTransformFunction` uses this too. It also evaluates the multi-stage leaf stage
+ /// projections, so it must generate the same element type as the type the multi-stage planner inferred.
+ @Nullable
+ public static ColumnDataType getElementType(ColumnDataType[] argumentTypes) {
+ int width = 0;
+ for (ColumnDataType argumentType : argumentTypes) {
+ int argumentWidth = width(argumentType);
+ if (argumentWidth < 0) {
+ return null;
+ }
+ width = Math.max(width, argumentWidth);
+ }
+ return ELEMENT_TYPES.get(width);
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(int numArguments) {
+ // Reached only when the argument types are unknown. LONG is the type the time grids this mainly generates use.
+ return getFunctionInfo(ColumnDataType.LONG, numArguments);
+ }
+
+ @Nullable
+ private static FunctionInfo getFunctionInfo(ColumnDataType elementType, int numArguments) {
+ return FUNCTION_INFO_MAP.get(elementType).get(numArguments);
+ }
+
+ private static RelDataType inferReturnType(SqlOperatorBinding binding) {
+ int width = 0;
+ for (RelDataType operandType : binding.collectOperandTypes()) {
+ width = Math.max(width, width(operandType.getSqlTypeName()));
+ }
+ RelDataTypeFactory typeFactory = binding.getTypeFactory();
+ return typeFactory.createArrayType(typeFactory.createSqlType(ELEMENT_TYPE_NAMES.get(width)), -1);
Review Comment:
Good catch. The inferred array type now allows null when any operand does, so Calcite keeps the `COALESCE` fallback. `QueryCompilationTest` checks the type and the plan, and `GenerateArray.json` runs your query end to end.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
+ List.of(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.REAL, SqlTypeName.DOUBLE);
+
+ /// Element type to the [ArrayFunctions] method generating it, by argument count.
+ private static final Map<ColumnDataType, Map<Integer, FunctionInfo>> FUNCTION_INFO_MAP =
+ new EnumMap<>(ColumnDataType.class);
+
+ static {
+ register(ColumnDataType.INT, "generateIntArray", int.class);
+ register(ColumnDataType.LONG, "generateLongArray", long.class);
+ register(ColumnDataType.FLOAT, "generateFloatArray", float.class);
+ register(ColumnDataType.DOUBLE, "generateDoubleArray", double.class);
+ }
+
+ private static void register(ColumnDataType elementType, String methodName, Class<?> argumentClass) {
+ try {
+ FUNCTION_INFO_MAP.put(elementType, Map.of(2,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass)), 3,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass, argumentClass))));
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to find the " + methodName + " implementation of " + NAME, e);
+ }
+ }
+
+ /// Marks the function as not deterministic so that neither engine folds a call on literal arguments into an array
+ /// literal at the broker. Folding would serialize the whole sequence, up to the maximum length [ArrayFunctions]
+ /// allows, into the query plan sent to every server, while evaluating it on the server only needs the three
+ /// arguments. The function is still [FunctionVolatility#IMMUTABLE]: the same arguments always generate the same
+ /// sequence, so it stays usable in ingestion transforms.
+ private static FunctionInfo functionInfo(Method method) {
+ return new FunctionInfo(method, ArrayFunctions.class, false, false, FunctionVolatility.IMMUTABLE);
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public PinotSqlFunction toPinotSqlFunction() {
+ // The third operand is the increment, which defaults to 1 (or -1 when counting down) when omitted.
+ return new PinotSqlFunction(NAME, GenerateArrayScalarFunction::inferReturnType,
+ OperandTypes.family(List.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC), i -> i == 2));
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(ColumnDataType[] argumentTypes) {
+ ColumnDataType elementType = getElementType(argumentTypes);
+ return elementType != null ? getFunctionInfo(elementType, argumentTypes.length) : null;
+ }
+
+ /// The element type of the sequence generated from arguments of these types: `INT`, `LONG`, `FLOAT` or `DOUBLE`,
+ /// whichever is the widest of the argument types. Returns `null` if a sequence cannot be generated from one of them.
+ ///
+ /// The single-stage `GenerateArrayTransformFunction` uses this too. It also evaluates the multi-stage leaf stage
+ /// projections, so it must generate the same element type as the type the multi-stage planner inferred.
+ @Nullable
+ public static ColumnDataType getElementType(ColumnDataType[] argumentTypes) {
+ int width = 0;
+ for (ColumnDataType argumentType : argumentTypes) {
+ int argumentWidth = width(argumentType);
+ if (argumentWidth < 0) {
+ return null;
+ }
+ width = Math.max(width, argumentWidth);
+ }
+ return ELEMENT_TYPES.get(width);
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(int numArguments) {
+ // Reached only when the argument types are unknown. LONG is the type the time grids this mainly generates use.
+ return getFunctionInfo(ColumnDataType.LONG, numArguments);
+ }
+
+ @Nullable
+ private static FunctionInfo getFunctionInfo(ColumnDataType elementType, int numArguments) {
+ return FUNCTION_INFO_MAP.get(elementType).get(numArguments);
+ }
+
+ private static RelDataType inferReturnType(SqlOperatorBinding binding) {
+ int width = 0;
+ for (RelDataType operandType : binding.collectOperandTypes()) {
+ width = Math.max(width, width(operandType.getSqlTypeName()));
Review Comment:
Fixed. The return type inference now maps each operand the way `RelToPlanNodeConverter.convertToColumnDataType` does, so scale zero decimals become INT or LONG and the unsigned types become INT or LONG. Then it calls the same `getElementType` that execution uses. The converter is in `pinot-query-planner`, which `pinot-common` cannot depend on, so I mirrored its numeric cases and left a comment that points to it. There are new `QueryCompilationTest` cases, and `GenerateArray.json` runs your `DECIMAL(10, 0)` query.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
+ List.of(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.REAL, SqlTypeName.DOUBLE);
+
+ /// Element type to the [ArrayFunctions] method generating it, by argument count.
+ private static final Map<ColumnDataType, Map<Integer, FunctionInfo>> FUNCTION_INFO_MAP =
+ new EnumMap<>(ColumnDataType.class);
+
+ static {
+ register(ColumnDataType.INT, "generateIntArray", int.class);
+ register(ColumnDataType.LONG, "generateLongArray", long.class);
+ register(ColumnDataType.FLOAT, "generateFloatArray", float.class);
+ register(ColumnDataType.DOUBLE, "generateDoubleArray", double.class);
+ }
+
+ private static void register(ColumnDataType elementType, String methodName, Class<?> argumentClass) {
+ try {
+ FUNCTION_INFO_MAP.put(elementType, Map.of(2,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass)), 3,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass, argumentClass))));
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to find the " + methodName + " implementation of " + NAME, e);
+ }
+ }
+
+ /// Marks the function as not deterministic so that neither engine folds a call on literal arguments into an array
+ /// literal at the broker. Folding would serialize the whole sequence, up to the maximum length [ArrayFunctions]
+ /// allows, into the query plan sent to every server, while evaluating it on the server only needs the three
+ /// arguments. The function is still [FunctionVolatility#IMMUTABLE]: the same arguments always generate the same
+ /// sequence, so it stays usable in ingestion transforms.
+ private static FunctionInfo functionInfo(Method method) {
+ return new FunctionInfo(method, ArrayFunctions.class, false, false, FunctionVolatility.IMMUTABLE);
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public PinotSqlFunction toPinotSqlFunction() {
+ // The third operand is the increment, which defaults to 1 (or -1 when counting down) when omitted.
+ return new PinotSqlFunction(NAME, GenerateArrayScalarFunction::inferReturnType,
+ OperandTypes.family(List.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC), i -> i == 2));
Review Comment:
Fixed in `TransformFunctionFactory`. It uses `GenerateArrayTransformFunction` only when every argument is a literal. Any other call falls through to the scalar function through `ScalarTransformFunctionWrapper`, which generates one array per row.
Your example then hit a second problem. In the leaf stage, `intCol + 1` goes through the single-stage `plus`, which returns DOUBLE, so the call generates a `double[]` while the plan expects an INT_ARRAY. `TypeUtils.convert` already converts single values in this case, but for arrays it only asserted. It now converts between primitive numeric arrays the same way it converts single values. `ScalarTransformFunctionWrapperTest` and the new `TypeUtilsTest` cover both parts, and `GenerateArray.json` has a table-backed case with `generateArray(val, val + 2)`.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArrayFunctions.java:
##########
@@ -362,50 +368,130 @@ public static Object arrayValueConstructor(Object... arr) {
return arr;
}
+ /// Generates the sequence `start, start + inc, ...`, stopping at the last value that does not pass `end`. Both
+ /// bounds are inclusive when `end` lands exactly on a step, and `inc` may be negative to count down.
+ ///
+ /// The main use is building a dense time grid to `UNNEST` and left join a sparse time series onto, which is how gap
+ /// filling is expressed in the multi-stage engine:
+ /// ```sql
+ /// SELECT ts FROM UNNEST(generateArray(1633078800000, 1633089600000, 1800000)) AS grid(ts)
+ /// ```
+ /// `generateArray` selects the variant to call from its argument types; see
+ /// [org.apache.pinot.common.function.scalar.array.GenerateArrayScalarFunction].
+ ///
+ /// @throws IllegalArgumentException if `inc` is zero, if its sign does not lead from `start` to `end`, or if the
+ /// sequence would hold more than [#MAX_GENERATED_ARRAY_LENGTH] elements
@ScalarFunction
- public static int[] generateIntArray(int start, int end, int inc) {
- int size = (end - start) / inc + 1;
- int[] arr = new int[size];
-
- for (int i = 0, value = start; i < size; i++, value += inc) {
- arr[i] = value;
+ public static long[] generateLongArray(long start, long end, long inc) {
+ long[] arr = new long[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
+ /// Same as [#generateLongArray(long, long, long)] with a step of `1`, or `-1` when `end` is below `start`.
@ScalarFunction
- public static long[] generateLongArray(long start, long end, long inc) {
- int size = (int) ((end - start) / inc + 1);
- long[] arr = new long[size];
+ public static long[] generateLongArray(long start, long end) {
+ return generateLongArray(start, end, end < start ? -1 : 1);
+ }
- for (int i = 0; i < size; i++, start += inc) {
- arr[i] = start;
+ @ScalarFunction
+ public static int[] generateIntArray(int start, int end, int inc) {
+ int[] arr = new int[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
@ScalarFunction
- public static float[] generateFloatArray(float start, float end, float inc) {
- int size = (int) ((end - start) / inc + 1);
- float[] arr = new float[size];
+ public static int[] generateIntArray(int start, int end) {
+ return generateIntArray(start, end, end < start ? -1 : 1);
+ }
- for (int i = 0; i < size; i++, start += inc) {
- arr[i] = start;
+ @ScalarFunction
+ public static float[] generateFloatArray(float start, float end, float inc) {
+ float[] arr = new float[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
@ScalarFunction
- public static double[] generateDoubleArray(double start, double end, double inc) {
- int size = (int) ((end - start) / inc + 1);
- double[] arr = new double[size];
+ public static float[] generateFloatArray(float start, float end) {
+ return generateFloatArray(start, end, end < start ? -1 : 1);
+ }
- for (int i = 0; i < size; i++, start += inc) {
- arr[i] = start;
+ @ScalarFunction
+ public static double[] generateDoubleArray(double start, double end, double inc) {
+ double[] arr = new double[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
+ @ScalarFunction
+ public static double[] generateDoubleArray(double start, double end) {
+ return generateDoubleArray(start, end, end < start ? -1 : 1);
+ }
+
+ /// Length of the integral sequence `start, start + inc, ...` bounded by `end`, inclusive.
+ private static int generatedArrayLength(long start, long end, long inc) {
+ Preconditions.checkArgument(inc != 0, "Increment must not be zero");
+ long span;
+ try {
+ span = Math.subtractExact(end, start);
+ } catch (ArithmeticException e) {
+ // The span does not fit in a long, so the sequence is far past the length limit whatever the increment is.
+ throw new IllegalArgumentException(
+ String.format("Range from %s to %s is too wide to generate an array from", start, end));
+ }
+ checkIncrementLeadsToEnd(Long.signum(span), Long.signum(inc), start, end, inc);
+ return checkGeneratedArrayLength(span / inc);
+ }
+
+ /// Length of the `float` sequence `start, start + inc, ...` bounded by `end`, inclusive. The step count is computed
+ /// in `float` arithmetic, as the single-stage engine always did.
+ private static int generatedArrayLength(float start, float end, float inc) {
+ checkFloatingPointArguments(start, end, inc);
+ // TODO: decimal steps such as 0.1 are not exact in binary, so this can drop the end; see apache/pinot#19814
+ return checkGeneratedArrayLength((long) ((end - start) / inc + 1) - 1);
+ }
+
+ /// Length of the `double` sequence `start, start + inc, ...` bounded by `end`, inclusive.
+ private static int generatedArrayLength(double start, double end, double inc) {
+ checkFloatingPointArguments(start, end, inc);
+ // Adding 1 before truncating matches the length the single-stage engine always computed. It absorbs part of the
+ // rounding error of decimal steps, so 0.1 to 0.3 by 0.1 keeps its end.
+ // TODO: it does not absorb all of it, so 0.1 to 0.7 by 0.1 still drops its end; see apache/pinot#19814
+ // A span too wide for a long saturates the cast at Long.MAX_VALUE, which the length check below rejects.
+ return checkGeneratedArrayLength((long) ((end - start) / inc + 1) - 1);
+ }
+
+ private static void checkFloatingPointArguments(double start, double end, double inc) {
+ Preconditions.checkArgument(inc != 0 && !Double.isNaN(inc), "Increment must not be zero or NaN, got: %s", inc);
Review Comment:
Fixed. A non-finite increment is now rejected, and the tests cover double and float in both directions.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
Review Comment:
Done. `ELEMENT_TYPE_NAMES` is gone, and the return type comes from `ColumnDataType.toType`. Planning and execution now both pick the element type through `getElementType`.
##########
pinot-query-runtime/src/test/resources/queries/GenerateArray.json:
##########
@@ -0,0 +1,267 @@
+{
+ "generate_array_test": {
+ "tables": {
+ "sparse": {
+ "schema": [
+ {
+ "name": "eventTs",
+ "type": "LONG"
+ },
+ {
+ "name": "series",
+ "type": "STRING"
+ },
+ {
+ "name": "val",
+ "type": "INT"
+ }
+ ],
+ "inputs": [
+ [
+ 0,
+ "a",
+ 10
+ ],
+ [
+ 3,
+ "a",
+ 40
+ ],
+ [
+ 0,
+ "b",
+ 100
+ ]
+ ]
+ }
+ },
+ "queries": [
+ {
+ "description": "generateArray unnests into a dense grid, with the increment defaulting to 1",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(0, 4)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0
+ ],
+ [
+ 1
+ ],
+ [
+ 2
+ ],
+ [
+ 3
+ ],
+ [
+ 4
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "explicit increment",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(0, 10, 5)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0
+ ],
+ [
+ 5
+ ],
+ [
+ 10
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "negative increment counts down, and the end is not passed when it is not on a step",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(10, 1, -4)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket DESC",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 10
+ ],
+ [
+ 6
+ ],
+ [
+ 2
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "epoch millis bounds generate a LONG sequence rather than overflowing an INT one",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(1633078800000, 1633080600000, 1800000)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 1633078800000
+ ],
+ [
+ 1633080600000
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "a fractional increment makes the whole sequence DOUBLE",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(0, 1, 0.5)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0.0
+ ],
+ [
+ 0.5
+ ],
+ [
+ 1.0
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "WITH ORDINALITY numbers the generated buckets",
+ "sql": "SELECT grid.bucket, grid.pos FROM {sparse} CROSS JOIN UNNEST(generateArray(100, 300, 100)) WITH ORDINALITY AS grid(bucket, pos) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 100,
+ 1
+ ],
+ [
+ 200,
+ 2
+ ],
+ [
+ 300,
+ 3
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "gap fill: a generated grid crossed with the series keys, left joined to the sparse data and carried forward",
+ "sql": "SELECT grid.bucket, grid.series, COALESCE(LAST_VALUE(s.val) IGNORE NULLS OVER (PARTITION BY grid.series ORDER BY grid.bucket ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), 0) FROM (SELECT g.bucket, k.series FROM UNNEST(generateArray(0, 4)) AS g(bucket) CROSS JOIN (SELECT DISTINCT series FROM {sparse}) AS k) AS grid LEFT JOIN {sparse} s ON s.eventTs = grid.bucket AND s.series = grid.series ORDER BY grid.series, grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0,
+ "a",
+ 10
+ ],
+ [
+ 1,
+ "a",
+ 10
+ ],
+ [
+ 2,
+ "a",
+ 10
+ ],
+ [
+ 3,
+ "a",
+ 40
+ ],
+ [
+ 4,
+ "a",
+ 40
+ ],
+ [
+ 0,
+ "b",
+ 100
+ ],
+ [
+ 1,
+ "b",
+ 100
+ ],
+ [
+ 2,
+ "b",
+ 100
+ ],
+ [
+ 3,
+ "b",
+ 100
+ ],
+ [
+ 4,
+ "b",
+ 100
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ }
+ ]
+ },
+ "generate_array_unusable_arguments": {
Review Comment:
Done, the error cases are in the first group now. They need an empty `outputs`, because the runner does not allow a group that mixes queries with and without expected outputs.
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotEvaluateLiteralRule.java:
##########
@@ -230,17 +231,13 @@ private static RexNode evaluateLiteralOnlyFunction(RexCall rexCall, RexBuilder r
}
try {
if (rexNodeType instanceof ArraySqlType) {
- List<Object> resultValues = new ArrayList<>();
-
- // SQL FLOAT and DOUBLE literals are represented as Java double
- if (resultValue instanceof double[]) {
- for (double value: (double[]) resultValue) {
- resultValues.add(convertResultValue(value, rexNodeType.getComponentType()));
- }
- } else {
- for (Object value : (Object[]) resultValue) {
- resultValues.add(convertResultValue(value, rexNodeType.getComponentType()));
- }
+ // Scalar functions may return a primitive array (e.g. generateArray returns long[]), which cannot be cast to
Review Comment:
I'd rather keep it here, if that's fine with you. Without it, folding `generateIntArray`, `generateLongArray` or `generateFloatArray` on literals fails at planning time, so the MSE story of this PR would still be half broken for the typed functions. The change is small and `testPrimitiveArrayFunctionFoldsIntoAnArrayLiteral` covers it. If you feel strongly about it, I'll move it to its own PR.
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Support generateArray in the multi-stage engine [pinot]
Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #19552:
URL: https://github.com/apache/pinot/pull/19552#discussion_r4264346432
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
Review Comment:
Optional cleanup: remove the duplicate SQL type mapping
`ELEMENT_TYPE_NAMES` duplicates the mapping already provided by `ColumnDataType.toType()`. Return-type construction can use `ELEMENT_TYPES.get(width).toType(typeFactory)` instead, removing the parallel list and the requirement to keep its indices synchronized with `ELEMENT_TYPES`. While addressing the inference issue above, it would also help to consolidate argument normalization so planning and execution share the same policy.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
+ List.of(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.REAL, SqlTypeName.DOUBLE);
+
+ /// Element type to the [ArrayFunctions] method generating it, by argument count.
+ private static final Map<ColumnDataType, Map<Integer, FunctionInfo>> FUNCTION_INFO_MAP =
+ new EnumMap<>(ColumnDataType.class);
+
+ static {
+ register(ColumnDataType.INT, "generateIntArray", int.class);
+ register(ColumnDataType.LONG, "generateLongArray", long.class);
+ register(ColumnDataType.FLOAT, "generateFloatArray", float.class);
+ register(ColumnDataType.DOUBLE, "generateDoubleArray", double.class);
+ }
+
+ private static void register(ColumnDataType elementType, String methodName, Class<?> argumentClass) {
+ try {
+ FUNCTION_INFO_MAP.put(elementType, Map.of(2,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass)), 3,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass, argumentClass))));
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to find the " + methodName + " implementation of " + NAME, e);
+ }
+ }
+
+ /// Marks the function as not deterministic so that neither engine folds a call on literal arguments into an array
+ /// literal at the broker. Folding would serialize the whole sequence, up to the maximum length [ArrayFunctions]
+ /// allows, into the query plan sent to every server, while evaluating it on the server only needs the three
+ /// arguments. The function is still [FunctionVolatility#IMMUTABLE]: the same arguments always generate the same
+ /// sequence, so it stays usable in ingestion transforms.
+ private static FunctionInfo functionInfo(Method method) {
+ return new FunctionInfo(method, ArrayFunctions.class, false, false, FunctionVolatility.IMMUTABLE);
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public PinotSqlFunction toPinotSqlFunction() {
+ // The third operand is the increment, which defaults to 1 (or -1 when counting down) when omitted.
+ return new PinotSqlFunction(NAME, GenerateArrayScalarFunction::inferReturnType,
+ OperandTypes.family(List.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC), i -> i == 2));
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(ColumnDataType[] argumentTypes) {
+ ColumnDataType elementType = getElementType(argumentTypes);
+ return elementType != null ? getFunctionInfo(elementType, argumentTypes.length) : null;
+ }
+
+ /// The element type of the sequence generated from arguments of these types: `INT`, `LONG`, `FLOAT` or `DOUBLE`,
+ /// whichever is the widest of the argument types. Returns `null` if a sequence cannot be generated from one of them.
+ ///
+ /// The single-stage `GenerateArrayTransformFunction` uses this too. It also evaluates the multi-stage leaf stage
+ /// projections, so it must generate the same element type as the type the multi-stage planner inferred.
+ @Nullable
+ public static ColumnDataType getElementType(ColumnDataType[] argumentTypes) {
+ int width = 0;
+ for (ColumnDataType argumentType : argumentTypes) {
+ int argumentWidth = width(argumentType);
+ if (argumentWidth < 0) {
+ return null;
+ }
+ width = Math.max(width, argumentWidth);
+ }
+ return ELEMENT_TYPES.get(width);
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(int numArguments) {
+ // Reached only when the argument types are unknown. LONG is the type the time grids this mainly generates use.
+ return getFunctionInfo(ColumnDataType.LONG, numArguments);
+ }
+
+ @Nullable
+ private static FunctionInfo getFunctionInfo(ColumnDataType elementType, int numArguments) {
+ return FUNCTION_INFO_MAP.get(elementType).get(numArguments);
+ }
+
+ private static RelDataType inferReturnType(SqlOperatorBinding binding) {
+ int width = 0;
+ for (RelDataType operandType : binding.collectOperandTypes()) {
+ width = Math.max(width, width(operandType.getSqlTypeName()));
+ }
+ RelDataTypeFactory typeFactory = binding.getTypeFactory();
+ return typeFactory.createArrayType(typeFactory.createSqlType(ELEMENT_TYPE_NAMES.get(width)), -1);
Review Comment:
[P2] Preserve operand nullability in the inferred array type
`createArrayType()` produces a nonnullable array, but this function's `FunctionInfo` is null-intolerant, so execution returns null when any argument is null. For example, `SELECT g.x FROM UNNEST(COALESCE(generateArray(CAST(NULL AS INTEGER), 4), ARRAY[7])) AS g(x)` loses the fallback during planning: Calcite's `RelBuilder` simplifies `COALESCE` by dropping operands after the first nonnullable one. The resulting UNNEST emits no row instead of `7`. Please propagate operand nullability to the inferred array type and cover this through the query pipeline.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArrayFunctions.java:
##########
@@ -362,50 +368,130 @@ public static Object arrayValueConstructor(Object... arr) {
return arr;
}
+ /// Generates the sequence `start, start + inc, ...`, stopping at the last value that does not pass `end`. Both
+ /// bounds are inclusive when `end` lands exactly on a step, and `inc` may be negative to count down.
+ ///
+ /// The main use is building a dense time grid to `UNNEST` and left join a sparse time series onto, which is how gap
+ /// filling is expressed in the multi-stage engine:
+ /// ```sql
+ /// SELECT ts FROM UNNEST(generateArray(1633078800000, 1633089600000, 1800000)) AS grid(ts)
+ /// ```
+ /// `generateArray` selects the variant to call from its argument types; see
+ /// [org.apache.pinot.common.function.scalar.array.GenerateArrayScalarFunction].
+ ///
+ /// @throws IllegalArgumentException if `inc` is zero, if its sign does not lead from `start` to `end`, or if the
+ /// sequence would hold more than [#MAX_GENERATED_ARRAY_LENGTH] elements
@ScalarFunction
- public static int[] generateIntArray(int start, int end, int inc) {
- int size = (end - start) / inc + 1;
- int[] arr = new int[size];
-
- for (int i = 0, value = start; i < size; i++, value += inc) {
- arr[i] = value;
+ public static long[] generateLongArray(long start, long end, long inc) {
+ long[] arr = new long[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
+ /// Same as [#generateLongArray(long, long, long)] with a step of `1`, or `-1` when `end` is below `start`.
@ScalarFunction
- public static long[] generateLongArray(long start, long end, long inc) {
- int size = (int) ((end - start) / inc + 1);
- long[] arr = new long[size];
+ public static long[] generateLongArray(long start, long end) {
+ return generateLongArray(start, end, end < start ? -1 : 1);
+ }
- for (int i = 0; i < size; i++, start += inc) {
- arr[i] = start;
+ @ScalarFunction
+ public static int[] generateIntArray(int start, int end, int inc) {
+ int[] arr = new int[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
@ScalarFunction
- public static float[] generateFloatArray(float start, float end, float inc) {
- int size = (int) ((end - start) / inc + 1);
- float[] arr = new float[size];
+ public static int[] generateIntArray(int start, int end) {
+ return generateIntArray(start, end, end < start ? -1 : 1);
+ }
- for (int i = 0; i < size; i++, start += inc) {
- arr[i] = start;
+ @ScalarFunction
+ public static float[] generateFloatArray(float start, float end, float inc) {
+ float[] arr = new float[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
@ScalarFunction
- public static double[] generateDoubleArray(double start, double end, double inc) {
- int size = (int) ((end - start) / inc + 1);
- double[] arr = new double[size];
+ public static float[] generateFloatArray(float start, float end) {
+ return generateFloatArray(start, end, end < start ? -1 : 1);
+ }
- for (int i = 0; i < size; i++, start += inc) {
- arr[i] = start;
+ @ScalarFunction
+ public static double[] generateDoubleArray(double start, double end, double inc) {
+ double[] arr = new double[generatedArrayLength(start, end, inc)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = start + i * inc;
}
return arr;
}
+ @ScalarFunction
+ public static double[] generateDoubleArray(double start, double end) {
+ return generateDoubleArray(start, end, end < start ? -1 : 1);
+ }
+
+ /// Length of the integral sequence `start, start + inc, ...` bounded by `end`, inclusive.
+ private static int generatedArrayLength(long start, long end, long inc) {
+ Preconditions.checkArgument(inc != 0, "Increment must not be zero");
+ long span;
+ try {
+ span = Math.subtractExact(end, start);
+ } catch (ArithmeticException e) {
+ // The span does not fit in a long, so the sequence is far past the length limit whatever the increment is.
+ throw new IllegalArgumentException(
+ String.format("Range from %s to %s is too wide to generate an array from", start, end));
+ }
+ checkIncrementLeadsToEnd(Long.signum(span), Long.signum(inc), start, end, inc);
+ return checkGeneratedArrayLength(span / inc);
+ }
+
+ /// Length of the `float` sequence `start, start + inc, ...` bounded by `end`, inclusive. The step count is computed
+ /// in `float` arithmetic, as the single-stage engine always did.
+ private static int generatedArrayLength(float start, float end, float inc) {
+ checkFloatingPointArguments(start, end, inc);
+ // TODO: decimal steps such as 0.1 are not exact in binary, so this can drop the end; see apache/pinot#19814
+ return checkGeneratedArrayLength((long) ((end - start) / inc + 1) - 1);
+ }
+
+ /// Length of the `double` sequence `start, start + inc, ...` bounded by `end`, inclusive.
+ private static int generatedArrayLength(double start, double end, double inc) {
+ checkFloatingPointArguments(start, end, inc);
+ // Adding 1 before truncating matches the length the single-stage engine always computed. It absorbs part of the
+ // rounding error of decimal steps, so 0.1 to 0.3 by 0.1 keeps its end.
+ // TODO: it does not absorb all of it, so 0.1 to 0.7 by 0.1 still drops its end; see apache/pinot#19814
+ // A span too wide for a long saturates the cast at Long.MAX_VALUE, which the length check below rejects.
+ return checkGeneratedArrayLength((long) ((end - start) / inc + 1) - 1);
+ }
+
+ private static void checkFloatingPointArguments(double start, double end, double inc) {
+ Preconditions.checkArgument(inc != 0 && !Double.isNaN(inc), "Increment must not be zero or NaN, got: %s", inc);
Review Comment:
[P2] Reject infinite increments before using index multiplication
This accepts infinite increments. `generateDoubleArray(0, 1, Double.POSITIVE_INFINITY)` therefore allocates one element, but the new `start + i * inc` loop computes `0 * Infinity` at index zero and returns `[NaN]`; the previous implementation returned `[0.0]`. FLOAT and descending ranges with negative infinity have the same regression. Please reject nonfinite increments, or preserve the initial value without multiplying infinity by zero, and cover both floating-point variants.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
+ List.of(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.REAL, SqlTypeName.DOUBLE);
+
+ /// Element type to the [ArrayFunctions] method generating it, by argument count.
+ private static final Map<ColumnDataType, Map<Integer, FunctionInfo>> FUNCTION_INFO_MAP =
+ new EnumMap<>(ColumnDataType.class);
+
+ static {
+ register(ColumnDataType.INT, "generateIntArray", int.class);
+ register(ColumnDataType.LONG, "generateLongArray", long.class);
+ register(ColumnDataType.FLOAT, "generateFloatArray", float.class);
+ register(ColumnDataType.DOUBLE, "generateDoubleArray", double.class);
+ }
+
+ private static void register(ColumnDataType elementType, String methodName, Class<?> argumentClass) {
+ try {
+ FUNCTION_INFO_MAP.put(elementType, Map.of(2,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass)), 3,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass, argumentClass))));
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to find the " + methodName + " implementation of " + NAME, e);
+ }
+ }
+
+ /// Marks the function as not deterministic so that neither engine folds a call on literal arguments into an array
+ /// literal at the broker. Folding would serialize the whole sequence, up to the maximum length [ArrayFunctions]
+ /// allows, into the query plan sent to every server, while evaluating it on the server only needs the three
+ /// arguments. The function is still [FunctionVolatility#IMMUTABLE]: the same arguments always generate the same
+ /// sequence, so it stays usable in ingestion transforms.
+ private static FunctionInfo functionInfo(Method method) {
+ return new FunctionInfo(method, ArrayFunctions.class, false, false, FunctionVolatility.IMMUTABLE);
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public PinotSqlFunction toPinotSqlFunction() {
+ // The third operand is the increment, which defaults to 1 (or -1 when counting down) when omitted.
+ return new PinotSqlFunction(NAME, GenerateArrayScalarFunction::inferReturnType,
+ OperandTypes.family(List.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC), i -> i == 2));
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(ColumnDataType[] argumentTypes) {
+ ColumnDataType elementType = getElementType(argumentTypes);
+ return elementType != null ? getFunctionInfo(elementType, argumentTypes.length) : null;
+ }
+
+ /// The element type of the sequence generated from arguments of these types: `INT`, `LONG`, `FLOAT` or `DOUBLE`,
+ /// whichever is the widest of the argument types. Returns `null` if a sequence cannot be generated from one of them.
+ ///
+ /// The single-stage `GenerateArrayTransformFunction` uses this too. It also evaluates the multi-stage leaf stage
+ /// projections, so it must generate the same element type as the type the multi-stage planner inferred.
+ @Nullable
+ public static ColumnDataType getElementType(ColumnDataType[] argumentTypes) {
+ int width = 0;
+ for (ColumnDataType argumentType : argumentTypes) {
+ int argumentWidth = width(argumentType);
+ if (argumentWidth < 0) {
+ return null;
+ }
+ width = Math.max(width, argumentWidth);
+ }
+ return ELEMENT_TYPES.get(width);
+ }
+
+ @Nullable
+ @Override
+ public FunctionInfo getFunctionInfo(int numArguments) {
+ // Reached only when the argument types are unknown. LONG is the type the time grids this mainly generates use.
+ return getFunctionInfo(ColumnDataType.LONG, numArguments);
+ }
+
+ @Nullable
+ private static FunctionInfo getFunctionInfo(ColumnDataType elementType, int numArguments) {
+ return FUNCTION_INFO_MAP.get(elementType).get(numArguments);
+ }
+
+ private static RelDataType inferReturnType(SqlOperatorBinding binding) {
+ int width = 0;
+ for (RelDataType operandType : binding.collectOperandTypes()) {
+ width = Math.max(width, width(operandType.getSqlTypeName()));
Review Comment:
[P2] Align return-type inference with normalized argument types
`width(SqlTypeName)` treats every DECIMAL (and unsigned integer type) as DOUBLE, whereas `RelToPlanNodeConverter` normalizes scale-zero decimals and supported unsigned integers to INT/LONG. For `SELECT generateArray(CAST(0 AS DECIMAL(10,0)), 4)`, the outer call retains its inferred DOUBLE_ARRAY type after its argument becomes INT, so runtime dispatch generates `int[]`. `TypeUtils.convert()` does not widen primitive numeric arrays, and `DataBlockBuilder` then casts the value to `double[]`. Please infer from the full `RelDataType` using normalization consistent with runtime dispatch, and add a query regression case.
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotEvaluateLiteralRule.java:
##########
@@ -230,17 +231,13 @@ private static RexNode evaluateLiteralOnlyFunction(RexCall rexCall, RexBuilder r
}
try {
if (rexNodeType instanceof ArraySqlType) {
- List<Object> resultValues = new ArrayList<>();
-
- // SQL FLOAT and DOUBLE literals are represented as Java double
- if (resultValue instanceof double[]) {
- for (double value: (double[]) resultValue) {
- resultValues.add(convertResultValue(value, rexNodeType.getComponentType()));
- }
- } else {
- for (Object value : (Object[]) resultValue) {
- resultValues.add(convertResultValue(value, rexNodeType.getComponentType()));
- }
+ // Scalar functions may return a primitive array (e.g. generateArray returns long[]), which cannot be cast to
Review Comment:
Optional scope cleanup: consider splitting out the primitive-array folding fix
This is a useful fix for the existing typed generators, but the new `generateArray` explicitly disables constant folding, so its MSE support does not depend on this change. The reflective array handling and `testPrimitiveArrayFunctionFoldsIntoAnArrayLiteral` could move together into a separate focused PR. This is a scope suggestion, not a request to drop the fix.
##########
pinot-query-runtime/src/test/resources/queries/GenerateArray.json:
##########
@@ -0,0 +1,267 @@
+{
+ "generate_array_test": {
+ "tables": {
+ "sparse": {
+ "schema": [
+ {
+ "name": "eventTs",
+ "type": "LONG"
+ },
+ {
+ "name": "series",
+ "type": "STRING"
+ },
+ {
+ "name": "val",
+ "type": "INT"
+ }
+ ],
+ "inputs": [
+ [
+ 0,
+ "a",
+ 10
+ ],
+ [
+ 3,
+ "a",
+ 40
+ ],
+ [
+ 0,
+ "b",
+ 100
+ ]
+ ]
+ }
+ },
+ "queries": [
+ {
+ "description": "generateArray unnests into a dense grid, with the increment defaulting to 1",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(0, 4)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0
+ ],
+ [
+ 1
+ ],
+ [
+ 2
+ ],
+ [
+ 3
+ ],
+ [
+ 4
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "explicit increment",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(0, 10, 5)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0
+ ],
+ [
+ 5
+ ],
+ [
+ 10
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "negative increment counts down, and the end is not passed when it is not on a step",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(10, 1, -4)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket DESC",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 10
+ ],
+ [
+ 6
+ ],
+ [
+ 2
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "epoch millis bounds generate a LONG sequence rather than overflowing an INT one",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(1633078800000, 1633080600000, 1800000)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 1633078800000
+ ],
+ [
+ 1633080600000
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "a fractional increment makes the whole sequence DOUBLE",
+ "sql": "SELECT grid.bucket FROM {sparse} CROSS JOIN UNNEST(generateArray(0, 1, 0.5)) AS grid(bucket) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0.0
+ ],
+ [
+ 0.5
+ ],
+ [
+ 1.0
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "WITH ORDINALITY numbers the generated buckets",
+ "sql": "SELECT grid.bucket, grid.pos FROM {sparse} CROSS JOIN UNNEST(generateArray(100, 300, 100)) WITH ORDINALITY AS grid(bucket, pos) WHERE series = 'b' ORDER BY grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 100,
+ 1
+ ],
+ [
+ 200,
+ 2
+ ],
+ [
+ 300,
+ 3
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ },
+ {
+ "description": "gap fill: a generated grid crossed with the series keys, left joined to the sparse data and carried forward",
+ "sql": "SELECT grid.bucket, grid.series, COALESCE(LAST_VALUE(s.val) IGNORE NULLS OVER (PARTITION BY grid.series ORDER BY grid.bucket ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), 0) FROM (SELECT g.bucket, k.series FROM UNNEST(generateArray(0, 4)) AS g(bucket) CROSS JOIN (SELECT DISTINCT series FROM {sparse}) AS k) AS grid LEFT JOIN {sparse} s ON s.eventTs = grid.bucket AND s.series = grid.series ORDER BY grid.series, grid.bucket",
+ "keepOutputRowOrder": true,
+ "outputs": [
+ [
+ 0,
+ "a",
+ 10
+ ],
+ [
+ 1,
+ "a",
+ 10
+ ],
+ [
+ 2,
+ "a",
+ 10
+ ],
+ [
+ 3,
+ "a",
+ 40
+ ],
+ [
+ 4,
+ "a",
+ 40
+ ],
+ [
+ 0,
+ "b",
+ 100
+ ],
+ [
+ 1,
+ "b",
+ 100
+ ],
+ [
+ 2,
+ "b",
+ 100
+ ],
+ [
+ 3,
+ "b",
+ 100
+ ],
+ [
+ 4,
+ "b",
+ 100
+ ]
+ ],
+ "ignoreLiteMode": true,
+ "ignoreV2Optimizer": true
+ }
+ ]
+ },
+ "generate_array_unusable_arguments": {
Review Comment:
Optional cleanup: reuse the existing fixture for the error cases
This group repeats the first group's entire `sparse` schema and three input rows. Since `expectedException` is configured per query, the two error cases can go in the first group's `queries` array and this duplicate fixture can be removed without losing coverage.
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/array/GenerateArrayScalarFunction.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function.scalar.array;
+
+import java.lang.reflect.Method;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.PinotScalarFunction;
+import org.apache.pinot.common.function.scalar.ArrayFunctions;
+import org.apache.pinot.common.function.sql.PinotSqlFunction;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.spi.annotations.FunctionVolatility;
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+/// `generateArray(start, end[, inc])` in the multi-stage engine, generating the sequence `start, start + inc, ...`
+/// bounded by `end` inclusive. The single-stage engine resolves the same name through
+/// `GenerateArrayTransformFunction`; both delegate to [ArrayFunctions] so the two engines agree on the sequence and
+/// on which arguments are rejected.
+///
+/// The element type is the widest of the argument types rather than a fixed one, so `generateArray(0, 4)` generates
+/// `INT`s while `generateArray(1633078800000, 1633089600000, 1800000)` generates `LONG`s and `generateArray(0, 1,
+/// 0.25)` generates `DOUBLE`s. This class exists because that dispatch is on argument types, which the method level
+/// [ScalarFunction] annotation cannot express -- it dispatches on argument count alone.
+///
+/// This class is stateless and thread safe.
+@ScalarFunction
+public class GenerateArrayScalarFunction implements PinotScalarFunction {
+ public static final String NAME = "generateArray";
+
+ /// The element types a sequence can be generated as, narrowest first. The widest of the argument types wins, so a
+ /// single fractional or wide argument decides the whole sequence.
+ private static final List<ColumnDataType> ELEMENT_TYPES =
+ List.of(ColumnDataType.INT, ColumnDataType.LONG, ColumnDataType.FLOAT, ColumnDataType.DOUBLE);
+ private static final List<SqlTypeName> ELEMENT_TYPE_NAMES =
+ List.of(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.REAL, SqlTypeName.DOUBLE);
+
+ /// Element type to the [ArrayFunctions] method generating it, by argument count.
+ private static final Map<ColumnDataType, Map<Integer, FunctionInfo>> FUNCTION_INFO_MAP =
+ new EnumMap<>(ColumnDataType.class);
+
+ static {
+ register(ColumnDataType.INT, "generateIntArray", int.class);
+ register(ColumnDataType.LONG, "generateLongArray", long.class);
+ register(ColumnDataType.FLOAT, "generateFloatArray", float.class);
+ register(ColumnDataType.DOUBLE, "generateDoubleArray", double.class);
+ }
+
+ private static void register(ColumnDataType elementType, String methodName, Class<?> argumentClass) {
+ try {
+ FUNCTION_INFO_MAP.put(elementType, Map.of(2,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass)), 3,
+ functionInfo(ArrayFunctions.class.getMethod(methodName, argumentClass, argumentClass, argumentClass))));
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to find the " + methodName + " implementation of " + NAME, e);
+ }
+ }
+
+ /// Marks the function as not deterministic so that neither engine folds a call on literal arguments into an array
+ /// literal at the broker. Folding would serialize the whole sequence, up to the maximum length [ArrayFunctions]
+ /// allows, into the query plan sent to every server, while evaluating it on the server only needs the three
+ /// arguments. The function is still [FunctionVolatility#IMMUTABLE]: the same arguments always generate the same
+ /// sequence, so it stays usable in ingestion transforms.
+ private static FunctionInfo functionInfo(Method method) {
+ return new FunctionInfo(method, ArrayFunctions.class, false, false, FunctionVolatility.IMMUTABLE);
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public PinotSqlFunction toPinotSqlFunction() {
+ // The third operand is the increment, which defaults to 1 (or -1 when counting down) when omitted.
+ return new PinotSqlFunction(NAME, GenerateArrayScalarFunction::inferReturnType,
+ OperandTypes.family(List.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC), i -> i == 2));
Review Comment:
[P2] Handle nonliteral arguments in leaf-stage execution
The new signature accepts numeric expressions, but `SELECT generateArray(intCol, intCol + 1) FROM t` is pushed into the SSE leaf projection. `TransformFunctionFactory` unconditionally selects `GenerateArrayTransformFunction` for this name, whose constructor rejects column/function arguments because it only accepts literals. This makes a valid scalar call fail depending on its placement in the plan. Please route nonliteral calls through the scalar implementation, extend the transform to evaluate them, or prevent their leaf pushdown; a table-backed query would cover the gap.
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Support generateArray in the multi-stage engine [pinot]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #19552:
URL: https://github.com/apache/pinot/pull/19552#issuecomment-5664119895
## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/19552?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `85.57692%` with `15 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 57.85%. Comparing base ([`66fca21`](https://app.codecov.io/gh/apache/pinot/commit/66fca21494e2070fad854e10bf8a98e383e53174?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`125fa2a`](https://app.codecov.io/gh/apache/pinot/commit/125fa2adcaf3360f86f5571ac3282bc9fc7b5f37?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 6 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/pinot/pull/19552?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...tion/scalar/array/GenerateArrayScalarFunction.java](https://app.codecov.io/gh/apache/pinot/pull/19552?src=pr&el=tree&filepath=pinot-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcommon%2Ffunction%2Fscalar%2Farray%2FGenerateArrayScalarFunction.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vZnVuY3Rpb24vc2NhbGFyL2FycmF5L0dlbmVyYXRlQXJyYXlTY2FsYXJGdW5jdGlvbi5qYXZh) | 84.44% | [5 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/19552?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...sform/function/GenerateArrayTransformFunction.java](https://app.codecov.io/gh/apache/pinot/pull/19552?src=pr&el=tree&filepath=pinot-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcore%2Foperator%2Ftransform%2Ffunction%2FGenerateArrayTransformFunction.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9vcGVyYXRvci90cmFuc2Zvcm0vZnVuY3Rpb24vR2VuZXJhdGVBcnJheVRyYW5zZm9ybUZ1bmN0aW9uLmphdmE=) | 75.00% | [0 Missing and 5 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/19552?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...e/pinot/common/function/scalar/ArrayFunctions.java](https://app.codecov.io/gh/apache/pinot/pull/19552?src=pr&el=tree&filepath=pinot-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcommon%2Ffunction%2Fscalar%2FArrayFunctions.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vZnVuY3Rpb24vc2NhbGFyL0FycmF5RnVuY3Rpb25zLmphdmE=) | 91.17% | [2 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/19552?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (66fca21) and HEAD (125fa2a). Click for more details.
>
> <details><summary>HEAD has 24 uploads less than BASE</summary>
>
>| Flag | BASE (66fca21) | HEAD (125fa2a) |
>|------|------|------|
>|lane-a|2|0|
>|integration|4|0|
>|java-25|6|1|
>|integration2|2|0|
>|temurin|6|1|
>|lane-b|2|0|
>|unittests2|1|0|
>|unittests|2|1|
>|integration1|2|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #19552 +/- ##
============================================
- Coverage 67.71% 57.85% -9.86%
+ Complexity 1450 1 -1449
============================================
Files 3490 2686 -804
Lines 225032 164398 -60634
Branches 35527 26681 -8846
============================================
- Hits 152386 95117 -57269
- Misses 60613 61246 +633
+ Partials 12033 8035 -3998
```
| [Flag](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [integration](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration1](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration2](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-25](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.85% <85.57%> (-9.86%)` | :arrow_down: |
| [lane-a](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [lane-b](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [temurin](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.85% <85.57%> (-9.86%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.85% <85.57%> (-9.86%)` | :arrow_down: |
| [unittests1](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.85% <85.57%> (+0.02%)` | :arrow_up: |
| [unittests2](https://app.codecov.io/gh/apache/pinot/pull/19552/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/pinot/pull/19552?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Support generateArray in the multi-stage engine [pinot]
Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz commented on PR #19552:
URL: https://github.com/apache/pinot/pull/19552#issuecomment-6086855855
@xiangfu0 I changed the design after your approval, so could you take another look?
The PR no longer folds `generateArray` at the broker, in either engine. Folding put the whole sequence, up to 100,000 elements, into the plan that the broker sends to every server, while the servers only need the three arguments to generate it. The function now registers as not deterministic, but its volatility stays `IMMUTABLE`, so ingestion transforms still accept it. A consequence is that bad arguments fail at execution time again instead of at planning time, as on master.
Since an MSE leaf stage evaluates the call through `GenerateArrayTransformFunction`, the transform now picks the widest argument type, the same rule as the scalar function. In SSE this means mixed and `BIG_DECIMAL` arguments now work instead of failing. `FLOAT` arguments now return a `REAL` array.
I also went back to master's length formula for floating point sequences. The `floor` version dropped the end of `0.1..0.3 by 0.1`, which broke `ArrayTest` in CI. Master's formula still fails for some decimal steps, so I opened #19814 for that. I opened #19815 for the per-row evaluation that MSE now does when the call runs in an intermediate stage.
The new changes are all in 7e7e5aee83, and the PR description is updated.
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] Support generateArray in the multi-stage engine [pinot]
Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on PR #19552:
URL: https://github.com/apache/pinot/pull/19552#issuecomment-6193963575
Documentation follow-up merged: https://github.com/pinot-contrib/pinot-docs/pull/1110 — generateArray support in both engines, type/default-step/null semantics, argument and length validation, examples and function-index link.
--
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@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org