xiangfu0 commented on a change in pull request #7678:
URL: https://github.com/apache/pinot/pull/7678#discussion_r743357353



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
##########
@@ -82,6 +82,7 @@ private TransformFunctionFactory() {
           put(canonicalize(TransformFunctionType.LN.getName().toLowerCase()), 
LnTransformFunction.class);
           
put(canonicalize(TransformFunctionType.SQRT.getName().toLowerCase()), 
SqrtTransformFunction.class);
 
+          put(canonicalize(TransformFunctionType.AS.getName().toLowerCase()), 
AsTransformFunction.class);

Review comment:
       no, this is used universally can not be changed

##########
File path: 
pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriterTest.java
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.sql.parsers.rewriter;
+
+import org.apache.pinot.common.request.PinotQuery;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class NonAggregationGroupByToDistinctQueryRewriterTest {
+
+  private static final QueryRewriter QUERY_REWRITER = new 
NonAggregationGroupByToDistinctQueryRewriter();
+
+  @Test
+  public void testQuery1() {
+    final PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery("SELECT 
A FROM myTable GROUP BY A");
+    QUERY_REWRITER.rewrite(pinotQuery);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "DISTINCT");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "A");
+  }
+
+  @Test
+  // SELECT col1+col2*5 FROM foo GROUP BY col1, col2 => SELECT distinct 
col1+col2*5 FROM foo
+  public void testQuery2() {
+    final PinotQuery pinotQuery =
+        CalciteSqlParser.compileToPinotQuery("SELECT col1+col2*5 FROM foo 
GROUP BY col1, col2");
+    QUERY_REWRITER.rewrite(pinotQuery);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "DISTINCT");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(0)
+            .getIdentifier().getName(), "col1");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
+            .getFunctionCall().getOperands().get(0).getIdentifier().getName(), 
"col2");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
+            
.getFunctionCall().getOperands().get(1).getLiteral().getLongValue(), 5L);
+  }
+
+  @Test
+  // SELECT col1, col2 FROM foo GROUP BY col1, col2 => SELECT distinct col1, 
col2 FROM foo
+  public void testQuery3() {
+    final PinotQuery pinotQuery =
+        CalciteSqlParser.compileToPinotQuery("SELECT col1, col2 FROM foo GROUP 
BY col1, col2 ");
+    QUERY_REWRITER.rewrite(pinotQuery);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "DISTINCT");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "col1");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getIdentifier().getName(),
 "col2");
+  }
+
+  @Test
+  // SELECT col1 as col2 FROM foo GROUP BY col1 => SELECT distinct col1 as 
col2 FROM foo

Review comment:
       added.




-- 
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-unsubscr...@pinot.apache.org

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