This is an automated email from the ASF dual-hosted git repository.

xiangfu 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 5e56b9a155 Make ExpressionContext using ArrayList for replacement 
(#8459)
5e56b9a155 is described below

commit 5e56b9a155b9f5d7ba3cd7214c15b3f1c697a351
Author: Xiang Fu <xiangfu.1...@gmail.com>
AuthorDate: Sun Apr 3 13:21:21 2022 -0700

    Make ExpressionContext using ArrayList for replacement (#8459)
---
 .../apache/pinot/common/request/context/RequestContextUtils.java | 8 ++++----
 .../pinot/pql/parsers/PinotQuery2BrokerRequestConverter.java     | 2 +-
 .../main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java | 3 ++-
 .../pinot/core/query/selection/SelectionOperatorUtils.java       | 2 +-
 .../apache/pinot/core/plan/maker/QueryOverrideWithHintsTest.java | 9 +++++++--
 .../java/org/apache/pinot/core/query/scheduler/TestHelper.java   | 3 ++-
 .../pinot/core/query/selection/SelectionOperatorServiceTest.java | 2 +-
 7 files changed, 18 insertions(+), 11 deletions(-)

diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/request/context/RequestContextUtils.java
 
b/pinot-common/src/main/java/org/apache/pinot/common/request/context/RequestContextUtils.java
index 6e022c4656..2fb53b0a6f 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/request/context/RequestContextUtils.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/request/context/RequestContextUtils.java
@@ -118,7 +118,7 @@ public class RequestContextUtils {
     if 
(functionName.equalsIgnoreCase(AggregationFunctionType.COUNT.getName())) {
       // NOTE: COUNT always take one single argument "*"
       return new FunctionContext(FunctionContext.Type.AGGREGATION, 
AggregationFunctionType.COUNT.getName(),
-          Collections.singletonList(ExpressionContext.forIdentifier("*")));
+          new 
ArrayList<>(Collections.singletonList(ExpressionContext.forIdentifier("*"))));
     }
     FunctionContext.Type functionType =
         AggregationFunctionType.isAggregationFunction(functionName) ? 
FunctionContext.Type.AGGREGATION
@@ -143,7 +143,7 @@ public class RequestContextUtils {
     if 
(functionName.equalsIgnoreCase(AggregationFunctionType.COUNT.getName())) {
       // NOTE: COUNT always take one single argument "*"
       return new FunctionContext(FunctionContext.Type.AGGREGATION, 
AggregationFunctionType.COUNT.getName(),
-          Collections.singletonList(ExpressionContext.forIdentifier("*")));
+          new 
ArrayList<>(Collections.singletonList(ExpressionContext.forIdentifier("*"))));
     }
     FunctionContext.Type functionType =
         AggregationFunctionType.isAggregationFunction(functionName) ? 
FunctionContext.Type.AGGREGATION
@@ -185,7 +185,7 @@ public class RequestContextUtils {
         return new FilterContext(FilterContext.Type.OR, children, null);
       case NOT:
         assert numOperands == 1;
-        return new FilterContext(FilterContext.Type.NOT, 
Collections.singletonList(getFilter(operands.get(0))), null);
+        return new FilterContext(FilterContext.Type.NOT, new 
ArrayList<>(Collections.singletonList(getFilter(operands.get(0)))), null);
       case EQUALS:
         return new FilterContext(FilterContext.Type.PREDICATE, null,
             new EqPredicate(getExpression(operands.get(0)), 
getStringValue(operands.get(1))));
@@ -286,7 +286,7 @@ public class RequestContextUtils {
         return new FilterContext(FilterContext.Type.OR, children, null);
       case NOT:
         assert numOperands == 1;
-        return new FilterContext(FilterContext.Type.NOT, 
Collections.singletonList(getFilter(operands.get(0))), null);
+        return new FilterContext(FilterContext.Type.NOT, new 
ArrayList<>(Collections.singletonList(getFilter(operands.get(0)))), null);
       case EQUALS:
         return new FilterContext(FilterContext.Type.PREDICATE, null,
             new EqPredicate(operands.get(0), getStringValue(operands.get(1))));
diff --git 
a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/PinotQuery2BrokerRequestConverter.java
 
b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/PinotQuery2BrokerRequestConverter.java
index 76a6217a23..41ab9b0bdf 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/PinotQuery2BrokerRequestConverter.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/PinotQuery2BrokerRequestConverter.java
@@ -199,7 +199,7 @@ public class PinotQuery2BrokerRequestConverter {
     String functionName = function.getOperator();
 
     if 
(functionName.equalsIgnoreCase(AggregationFunctionType.COUNT.getName())) {
-      args = Collections.singletonList("*");
+      args = new ArrayList<>(Collections.singletonList("*"));
     } else {
       // Need to de-dup columns for distinct.
       if 
(functionName.equalsIgnoreCase(AggregationFunctionType.DISTINCT.getName())) {
diff --git 
a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java 
b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
index 10e80ed21c..98c1e5fefa 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
@@ -292,7 +292,8 @@ public class CalciteSqlParser {
       Function function = expression.getFunctionCall();
       if (function != null) {
         if (excludeAs && function.getOperator().equals("as")) {
-          
identifiers.addAll(extractIdentifiers(Collections.singletonList(function.getOperands().get(0)),
 true));
+          identifiers.addAll(
+              extractIdentifiers(new 
ArrayList<>(Collections.singletonList(function.getOperands().get(0))), true));
         } else {
           identifiers.addAll(extractIdentifiers(function.getOperands(), 
excludeAs));
         }
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/query/selection/SelectionOperatorUtils.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/query/selection/SelectionOperatorUtils.java
index 98deee48c4..375e2bd79b 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/query/selection/SelectionOperatorUtils.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/query/selection/SelectionOperatorUtils.java
@@ -152,7 +152,7 @@ public class SelectionOperatorUtils {
       // NOTE: The data schema might be generated from 
DataTableBuilder.buildEmptyDataTable(), where for 'SELECT *' it
       //       contains a single column "*". In such case, return as is to 
build the empty selection result.
       if (numColumns == 1 && columnNames[0].equals("*")) {
-        return Collections.singletonList("*");
+        return new ArrayList<>(Collections.singletonList("*"));
       }
 
       // Directly return all columns for selection-only queries
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/plan/maker/QueryOverrideWithHintsTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/plan/maker/QueryOverrideWithHintsTest.java
index ccb3aec20c..594e175b65 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/plan/maker/QueryOverrideWithHintsTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/plan/maker/QueryOverrideWithHintsTest.java
@@ -199,7 +199,9 @@ public class QueryOverrideWithHintsTest {
 
   @Test
   public void testRewriteExpressionsWithHints() {
-    BrokerRequest brokerRequest = _sqlCompiler.compileToBrokerRequest("SELECT 
datetrunc('MONTH', ts) from myTable");
+    BrokerRequest brokerRequest =
+        _sqlCompiler.compileToBrokerRequest(
+            "SELECT datetrunc('MONTH', ts), count(*), sum(abc) from myTable 
group by datetrunc('MONTH', ts) ");
     Expression dateTruncFunctionExpr = 
RequestUtils.getFunctionExpression("datetrunc");
     dateTruncFunctionExpr.getFunctionCall().setOperands(new ArrayList<>(
         ImmutableList.of(RequestUtils.getLiteralExpression("MONTH"), 
RequestUtils.getIdentifierExpression("ts"))));
@@ -209,11 +211,14 @@ public class QueryOverrideWithHintsTest {
     QueryContext queryContext = 
BrokerRequestToQueryContextConverter.convert(brokerRequest);
     InstancePlanMakerImplV2.rewriteQueryContextWithHints(queryContext, 
_indexSegment);
     assertEquals(queryContext.getSelectExpressions().get(0).getIdentifier(), 
"$ts$MONTH");
+    assertEquals(queryContext.getGroupByExpressions().get(0).getIdentifier(), 
"$ts$MONTH");
   }
 
   @Test
   public void testNotRewriteExpressionsWithHints() {
-    BrokerRequest brokerRequest = _sqlCompiler.compileToBrokerRequest("SELECT 
datetrunc('DAY', ts) from myTable");
+    BrokerRequest brokerRequest =
+        _sqlCompiler.compileToBrokerRequest(
+            "SELECT datetrunc('DAY', ts), count(*), sum(abc) from myTable 
group by datetrunc('DAY', ts)");
     Expression dateTruncFunctionExpr = 
RequestUtils.getFunctionExpression("datetrunc");
     dateTruncFunctionExpr.getFunctionCall().setOperands(new ArrayList<>(
         ImmutableList.of(RequestUtils.getLiteralExpression("DAY"), 
RequestUtils.getIdentifierExpression("ts"))));
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/query/scheduler/TestHelper.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/query/scheduler/TestHelper.java
index 82e34c63d2..b3bbd8bbc0 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/query/scheduler/TestHelper.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/query/scheduler/TestHelper.java
@@ -18,6 +18,7 @@
  */
 package org.apache.pinot.core.query.scheduler;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import org.apache.pinot.common.metrics.ServerMetrics;
@@ -44,7 +45,7 @@ public class TestHelper {
     qs.setTableName(table);
     br.setQuerySource(qs);
     Selection selection = new Selection();
-    selection.setSelectionColumns(Collections.singletonList("*"));
+    selection.setSelectionColumns(new 
ArrayList<>(Collections.singletonList("*")));
     br.setSelections(selection);
     request.setQuery(br);
     return new ServerQueryRequest(request, metrics, queryArrivalTimeMs);
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/query/selection/SelectionOperatorServiceTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/query/selection/SelectionOperatorServiceTest.java
index cce9cb9eb4..62e8fb6b44 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/query/selection/SelectionOperatorServiceTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/query/selection/SelectionOperatorServiceTest.java
@@ -165,7 +165,7 @@ public class SelectionOperatorServiceTest {
     when(dataSchema.getColumnNames()).thenReturn(new String[]{"*"});
     selectionColumns = SelectionOperatorUtils
         
.getSelectionColumns(QueryContextConverterUtils.getQueryContextFromSQL("SELECT 
* FROM testTable"), dataSchema);
-    assertEquals(selectionColumns, Collections.singletonList("*"));
+    assertEquals(selectionColumns, new 
ArrayList<>(Collections.singletonList("*")));
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to