Jackie-Jiang commented on a change in pull request #6891:
URL: https://github.com/apache/incubator-pinot/pull/6891#discussion_r628407710



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/reduce/BrokerReduceService.java
##########
@@ -91,7 +91,8 @@ private static void updateAlias(QueryContext queryContext, 
BrokerResponseNative
     if (resultTable == null) {
       return;
     }
-    Map<ExpressionContext, String> aliasMap = queryContext.getAliasMap();
+    // Use list to support multiple alias for the same column.
+    Map<ExpressionContext, List<String>> aliasMap = queryContext.getAliasMap();

Review comment:
       Even with a list, we still cannot handle cases such as `SELECT colA, 
colA AS a, colA AS b FROM myTable`. We might need to think of a different way 
to store the alias if we do want to support it. One possible solution would be 
keep a list of aliasNames for the select expressions.

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/reduce/BrokerReduceService.java
##########
@@ -104,9 +105,10 @@ private static void updateAlias(QueryContext queryContext, 
BrokerResponseNative
       return;
     }
     for (int i = 0; i < numSelectExpressions; i++) {
-      String alias = aliasMap.get(selectExpressions.get(i));
-      if (alias != null) {
-        columnNames[i] = alias;
+      List<String> alias = aliasMap.get(selectExpressions.get(i));
+      if (alias != null && alias.size() > 0) {
+        columnNames[i] = alias.get(0);
+        alias.remove(0);

Review comment:
       We should avoid modifying the query context in case it is used somewhere 
else

##########
File path: 
pinot-core/src/test/java/org/apache/pinot/queries/AliasQueriesTest.java
##########
@@ -0,0 +1,249 @@
+/**
+ * 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.queries;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.common.response.broker.BrokerResponseNative;
+import org.apache.pinot.common.response.broker.ResultTable;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import 
org.apache.pinot.segment.local.indexsegment.immutable.ImmutableSegmentLoader;
+import 
org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.segment.local.segment.readers.GenericRowRecordReader;
+import org.apache.pinot.segment.spi.ImmutableSegment;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.utils.BigDecimalUtils;
+import org.apache.pinot.spi.utils.ReadMode;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+@SuppressWarnings("rawtypes")
+public class AliasQueriesTest extends BaseQueriesTest {

Review comment:
       Can we add these test queries into one of the integration test? I feel 
adding a separate queries test might be too much




-- 
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.

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



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

Reply via email to