This is an automated email from the ASF dual-hosted git repository.
xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new c52014a721e Register time-series plan node types and validate worker
expressions (#20371)
c52014a721e is described below
commit c52014a721e778773661f559be16b1cfc201d26d
Author: Xiang Fu <[email protected]>
AuthorDate: Wed Nov 25 23:38:56 2026 -0800
Register time-series plan node types and validate worker expressions
(#20371)
---
.../m3ql/plan/M3TimeSeriesPlanNodeProvider.java | 32 ++++++++++++++++++++
....tsdb.spi.plan.serde.TimeSeriesPlanNodeProvider | 19 ++++++++++++
.../PhysicalTimeSeriesServerPlanVisitor.java | 27 ++++++++++++++---
.../PhysicalTimeSeriesServerPlanVisitorTest.java | 26 ++++++++++++++++
.../spi/plan/serde/TimeSeriesPlanNodeProvider.java | 30 +++++++++++++++++++
.../tsdb/spi/plan/serde/TimeSeriesPlanSerde.java | 35 +++++++++++++++-------
.../spi/plan/serde/TimeSeriesPlanSerdeTest.java | 12 ++++++++
7 files changed, 166 insertions(+), 15 deletions(-)
diff --git
a/pinot-plugins/pinot-timeseries-lang/pinot-timeseries-m3ql/src/main/java/org/apache/pinot/tsdb/m3ql/plan/M3TimeSeriesPlanNodeProvider.java
b/pinot-plugins/pinot-timeseries-lang/pinot-timeseries-m3ql/src/main/java/org/apache/pinot/tsdb/m3ql/plan/M3TimeSeriesPlanNodeProvider.java
new file mode 100644
index 00000000000..3d1646a4ce6
--- /dev/null
+++
b/pinot-plugins/pinot-timeseries-lang/pinot-timeseries-m3ql/src/main/java/org/apache/pinot/tsdb/m3ql/plan/M3TimeSeriesPlanNodeProvider.java
@@ -0,0 +1,32 @@
+/**
+ * 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.tsdb.m3ql.plan;
+
+import java.util.Set;
+import org.apache.pinot.tsdb.spi.plan.BaseTimeSeriesPlanNode;
+import org.apache.pinot.tsdb.spi.plan.serde.TimeSeriesPlanNodeProvider;
+
+
+/// Declares the immutable set of M3QL operators that may be dispatched to a
worker.
+public class M3TimeSeriesPlanNodeProvider implements
TimeSeriesPlanNodeProvider {
+ @Override
+ public Set<Class<? extends BaseTimeSeriesPlanNode>> getPlanNodeTypes() {
+ return Set.of(KeepLastValuePlanNode.class, TransformNullPlanNode.class);
+ }
+}
diff --git
a/pinot-plugins/pinot-timeseries-lang/pinot-timeseries-m3ql/src/main/resources/META-INF/services/org.apache.pinot.tsdb.spi.plan.serde.TimeSeriesPlanNodeProvider
b/pinot-plugins/pinot-timeseries-lang/pinot-timeseries-m3ql/src/main/resources/META-INF/services/org.apache.pinot.tsdb.spi.plan.serde.TimeSeriesPlanNodeProvider
new file mode 100644
index 00000000000..30fe65a3f8e
--- /dev/null
+++
b/pinot-plugins/pinot-timeseries-lang/pinot-timeseries-m3ql/src/main/resources/META-INF/services/org.apache.pinot.tsdb.spi.plan.serde.TimeSeriesPlanNodeProvider
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.pinot.tsdb.m3ql.plan.M3TimeSeriesPlanNodeProvider
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitor.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitor.java
index e873fd950f0..52a12b83401 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitor.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitor.java
@@ -26,10 +26,14 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
+import org.apache.pinot.common.function.TransformFunctionType;
import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.common.request.Expression;
import org.apache.pinot.common.request.context.ExpressionContext;
import org.apache.pinot.common.request.context.FilterContext;
+import org.apache.pinot.common.request.context.FunctionContext;
import org.apache.pinot.common.request.context.RequestContextUtils;
+import org.apache.pinot.common.utils.request.RequestUtils;
import
org.apache.pinot.core.query.aggregation.function.TimeSeriesAggregationFunction;
import org.apache.pinot.core.query.executor.QueryExecutor;
import org.apache.pinot.core.query.request.ServerQueryRequest;
@@ -100,16 +104,18 @@ public class PhysicalTimeSeriesServerPlanVisitor {
/// Create a transform expression, and link it with an aggregation function.
@VisibleForTesting
QueryContext compileQueryContext(LeafTimeSeriesPlanNode leafNode,
TimeSeriesExecutionContext context) {
- FilterContext filterContext =
- RequestContextUtils.getFilter(CalciteSqlParser.compileToExpression(
- leafNode.getEffectiveFilter(context.getInitialTimeBuckets())));
+ TimeBuckets timeBuckets = context.getInitialTimeBuckets();
+ Expression filter =
CalciteSqlParser.compileToExpression(leafNode.getEffectiveFilter(timeBuckets));
+ rejectScriptFunctions(RequestContextUtils.getExpression(filter));
+ FilterContext filterContext = RequestContextUtils.getFilter(filter);
List<ExpressionContext> groupByExpressions =
leafNode.getGroupByExpressions().stream()
.map(RequestContextUtils::getExpression).collect(Collectors.toList());
- TimeBuckets timeBuckets = context.getInitialTimeBuckets();
+
groupByExpressions.forEach(PhysicalTimeSeriesServerPlanVisitor::rejectScriptFunctions);
ExpressionContext rawTimeValuesInLong =
RequestContextUtils.getExpression(leafNode.getTimeColumn());
ExpressionContext aggregation =
TimeSeriesAggregationFunction.create(context.getLanguage(),
leafNode.getValueExpression(), rawTimeValuesInLong,
leafNode.getTimeUnit(),
leafNode.getOffsetSeconds() == null ? 0 : leafNode.getOffsetSeconds(),
timeBuckets, leafNode.getAggInfo());
+ rejectScriptFunctions(aggregation);
Map<String, String> queryOptions = new
HashMap<>(Optional.ofNullable(leafNode.getQueryOptions())
.orElseGet(Map::of));
queryOptions.put(QueryOptionKey.TIMEOUT_MS, Long.toString(Math.max(0L,
context.getRemainingTimeMs())));
@@ -124,6 +130,19 @@ public class PhysicalTimeSeriesServerPlanVisitor {
.build();
}
+ // Worker plans do not pass through the broker's SQL query script checks.
+ private static void rejectScriptFunctions(ExpressionContext expression) {
+ FunctionContext function = expression.getFunction();
+ if (function == null) {
+ return;
+ }
+ String canonicalName =
RequestUtils.canonicalizeFunctionName(function.getFunctionName());
+ if (TransformFunctionType.GROOVY.getName().equals(canonicalName)) {
+ throw new IllegalArgumentException("Groovy functions are not supported
in time-series worker plans");
+ }
+
function.getArguments().forEach(PhysicalTimeSeriesServerPlanVisitor::rejectScriptFunctions);
+ }
+
Map<String, String>
getServerQueryRequestMetadataMap(TimeSeriesExecutionContext context) {
Map<String, String> result = new HashMap<>();
result.put(MetadataKeys.BROKER_ID,
context.getMetadataMap().get(MetadataKeys.BROKER_ID));
diff --git
a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitorTest.java
b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitorTest.java
index bb109fdf33d..0b109fdb151 100644
---
a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitorTest.java
+++
b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/timeseries/PhysicalTimeSeriesServerPlanVisitorTest.java
@@ -36,12 +36,14 @@ import
org.apache.pinot.tsdb.spi.plan.LeafTimeSeriesPlanNode;
import org.apache.pinot.tsdb.spi.series.SimpleTimeSeriesBuilderFactory;
import org.apache.pinot.tsdb.spi.series.TimeSeriesBuilderFactoryProvider;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
public class PhysicalTimeSeriesServerPlanVisitorTest {
@@ -55,6 +57,30 @@ public class PhysicalTimeSeriesServerPlanVisitorTest {
TimeSeriesBuilderFactoryProvider.registerSeriesBuilderFactory(LANGUAGE,
new SimpleTimeSeriesBuilderFactory());
}
+ @DataProvider
+ public Object[][] leafScriptExpressions() {
+ String marker = "abs(Groovy())";
+ return new Object[][] {
+ {marker, "", "orderCount", "cityName"},
+ {"orderTime", marker + " > 0", "orderCount", "cityName"},
+ {"orderTime", "", marker, "cityName"},
+ {"orderTime", "", "orderCount", marker}
+ };
+ }
+
+ @Test(dataProvider = "leafScriptExpressions")
+ public void testRejectsScriptFunctions(String time, String filter, String
value, String groupBy) {
+ PhysicalTimeSeriesServerPlanVisitor visitor = new
PhysicalTimeSeriesServerPlanVisitor(
+ mock(QueryExecutor.class), mock(ExecutorService.class),
mock(ServerMetrics.class));
+ LeafTimeSeriesPlanNode leaf = new LeafTimeSeriesPlanNode("leaf",
List.of(), "orderTable", time, TimeUnit.SECONDS,
+ 0L, filter, value, new AggInfo("SUM", false, Map.of()),
List.of(groupBy), SERIES_LIMIT, QUERY_OPTIONS);
+ TimeSeriesExecutionContext context = new
TimeSeriesExecutionContext(LANGUAGE,
+ TimeBuckets.ofSeconds(1000L, Duration.ofSeconds(10), 100),
DUMMY_DEADLINE_MS, Map.of(), Map.of(), Map.of());
+
+ assertEquals(expectThrows(IllegalArgumentException.class, () ->
visitor.compileQueryContext(leaf, context))
+ .getMessage(), "Groovy functions are not supported in time-series
worker plans");
+ }
+
@Test
public void testCompileQueryContext() {
final String planId = "id";
diff --git
a/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanNodeProvider.java
b/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanNodeProvider.java
new file mode 100644
index 00000000000..f10490a9723
--- /dev/null
+++
b/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanNodeProvider.java
@@ -0,0 +1,30 @@
+/**
+ * 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.tsdb.spi.plan.serde;
+
+import java.util.Set;
+import org.apache.pinot.tsdb.spi.plan.BaseTimeSeriesPlanNode;
+
+
+/// Declares the plan node classes a language plugin allows workers to
deserialize. Register the provider through
+/// [java.util.ServiceLoader] on the worker classpath. The serde reads the
types once, using each class name as its
+/// wire identifier. The built-in leaf node is always available.
+public interface TimeSeriesPlanNodeProvider {
+ Set<Class<? extends BaseTimeSeriesPlanNode>> getPlanNodeTypes();
+}
diff --git
a/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerde.java
b/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerde.java
index e20ba13bc06..e5ae73f4832 100644
---
a/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerde.java
+++
b/pinot-timeseries/pinot-timeseries-spi/src/main/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerde.java
@@ -24,8 +24,15 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.pinot.spi.annotations.InterfaceStability;
import org.apache.pinot.tsdb.spi.plan.BaseTimeSeriesPlanNode;
+import org.apache.pinot.tsdb.spi.plan.LeafTimeSeriesPlanNode;
/// We have implemented a custom serialization/deserialization mechanism for
time series plans. This allows users to use
@@ -38,7 +45,16 @@ import org.apache.pinot.tsdb.spi.plan.BaseTimeSeriesPlanNode;
public class TimeSeriesPlanSerde {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private static final Map<String, Class<? extends BaseTimeSeriesPlanNode>>
PLAN_NODE_TYPES;
+
static {
+ Set<Class<? extends BaseTimeSeriesPlanNode>> types = new HashSet<>();
+ types.add(LeafTimeSeriesPlanNode.class);
+ for (TimeSeriesPlanNodeProvider provider :
ServiceLoader.load(TimeSeriesPlanNodeProvider.class,
+ TimeSeriesPlanSerde.class.getClassLoader())) {
+ types.addAll(provider.getPlanNodeTypes());
+ }
+ PLAN_NODE_TYPES =
types.stream().collect(Collectors.toUnmodifiableMap(Class::getName,
Function.identity()));
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
}
@@ -74,17 +90,14 @@ public class TimeSeriesPlanSerde {
}
objectNode.putIfAbsent("inputs", OBJECT_MAPPER.createArrayNode());
}
- BaseTimeSeriesPlanNode planNode = null;
- try {
- String klassName = jsonNode.get("klass").asText();
- Class<BaseTimeSeriesPlanNode> klass = (Class<BaseTimeSeriesPlanNode>)
Class.forName(klassName);
- planNode = OBJECT_MAPPER.readValue(jsonNode.toString(), klass);
- } finally {
- if (planNode != null && inputs instanceof ArrayNode) {
- ArrayNode childArray = (ArrayNode) inputs;
- for (JsonNode childJsonNode : childArray) {
- planNode.addInputNode(create(childJsonNode));
- }
+ Class<? extends BaseTimeSeriesPlanNode> type =
PLAN_NODE_TYPES.get(jsonNode.path("klass").asText());
+ if (type == null) {
+ throw new ClassNotFoundException("Unregistered time-series plan node
type");
+ }
+ BaseTimeSeriesPlanNode planNode = OBJECT_MAPPER.treeToValue(jsonNode,
type);
+ if (inputs instanceof ArrayNode) {
+ for (JsonNode child : inputs) {
+ planNode.addInputNode(create(child));
}
}
return planNode;
diff --git
a/pinot-timeseries/pinot-timeseries-spi/src/test/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerdeTest.java
b/pinot-timeseries/pinot-timeseries-spi/src/test/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerdeTest.java
index 5bd1cb3ec8a..d81fa40597b 100644
---
a/pinot-timeseries/pinot-timeseries-spi/src/test/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerdeTest.java
+++
b/pinot-timeseries/pinot-timeseries-spi/src/test/java/org/apache/pinot/tsdb/spi/plan/serde/TimeSeriesPlanSerdeTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.pinot.tsdb.spi.plan.serde;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -31,12 +33,22 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
public class TimeSeriesPlanSerdeTest {
private static final int SERIES_LIMIT = 1000;
private static final Map<String, String> QUERY_OPTIONS =
Map.of("numGroupsLimit", "1000");
+ @Test
+ public void testRejectUnregisteredNodeType() {
+ ObjectNode unknown = JsonNodeFactory.instance.objectNode().put("klass",
Object.class.getName());
+ ObjectNode parent = JsonNodeFactory.instance.objectNode().put("klass",
LeafTimeSeriesPlanNode.class.getName());
+ parent.putArray("inputs").add(unknown);
+ expectThrows(ClassNotFoundException.class, () ->
TimeSeriesPlanSerde.create(unknown));
+ expectThrows(ClassNotFoundException.class, () ->
TimeSeriesPlanSerde.create(parent));
+ }
+
@Test
public void testSerdeForScanFilterProjectNode() {
Map<String, String> aggParams = new HashMap<>();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]