You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2020/05/27 09:47:14 UTC

[incubator-pinot] branch master updated: Make Literal transformer return string literals (#5453)

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/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 008be2d  Make Literal transformer return string literals (#5453)
008be2d is described below

commit 008be2db874dd1c0d7877ce712842abd818d89d1
Author: Xiang Fu <fx...@gmail.com>
AuthorDate: Wed May 27 02:47:03 2020 -0700

    Make Literal transformer return string literals (#5453)
---
 .../pql/parsers/PinotQuery2BrokerRequestConverter.java      |  2 +-
 .../apache/pinot/sql/parsers/CalciteSqlCompilerTest.java    | 13 +++++++++++++
 .../transform/function/LiteralTransformFunction.java        | 12 +++++++++---
 3 files changed, 23 insertions(+), 4 deletions(-)

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 1ce9a06..f4a9639 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
@@ -128,7 +128,7 @@ public class PinotQuery2BrokerRequestConverter {
           if (selection == null) {
             selection = new Selection();
           }
-          selection.addToSelectionColumns(expression.getLiteral().getStringValue());
+          selection.addToSelectionColumns(expression.getLiteral().getFieldValue().toString());
           break;
         case IDENTIFIER:
           if (selection == null) {
diff --git a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java
index a037b3f..ac0a5cf 100644
--- a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java
+++ b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java
@@ -36,6 +36,7 @@ import org.apache.pinot.common.request.ExpressionType;
 import org.apache.pinot.common.request.FilterOperator;
 import org.apache.pinot.common.request.Function;
 import org.apache.pinot.common.request.Identifier;
+import org.apache.pinot.common.request.Literal;
 import org.apache.pinot.common.request.PinotQuery;
 import org.apache.pinot.pql.parsers.PinotQuery2BrokerRequestConverter;
 import org.apache.pinot.pql.parsers.Pql2Compiler;
@@ -293,6 +294,18 @@ public class CalciteSqlCompilerTest {
   }
 
   @Test
+  public void testBrokerConverterWithLiteral() {
+    PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery("select now() from mytable");
+    Literal literal = pinotQuery.getSelectList().get(0).getLiteral();
+    Assert.assertNotNull(literal);
+    PinotQuery2BrokerRequestConverter converter = new PinotQuery2BrokerRequestConverter();
+    BrokerRequest tempBrokerRequest = converter.convert(pinotQuery);
+    Assert.assertEquals(tempBrokerRequest.getQuerySource().getTableName(), "mytable");
+    Assert.assertEquals(tempBrokerRequest.getSelections().getSelectionColumns().get(0),
+        literal.getFieldValue().toString());
+  }
+
+  @Test
   public void testSelectAs() {
     PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(
         "select sum(A) as sum_A, count(B) as count_B  from vegetables where g IN (12, 13, 15.2, 17)");
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/LiteralTransformFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/LiteralTransformFunction.java
index 24a2374..4317a2b 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/LiteralTransformFunction.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/LiteralTransformFunction.java
@@ -18,11 +18,13 @@
  */
 package org.apache.pinot.core.operator.transform.function;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import org.apache.pinot.core.common.DataSource;
 import org.apache.pinot.core.operator.blocks.ProjectionBlock;
 import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
 import org.apache.pinot.core.segment.index.readers.Dictionary;
 
 
@@ -32,6 +34,7 @@ import org.apache.pinot.core.segment.index.readers.Dictionary;
  */
 public class LiteralTransformFunction implements TransformFunction {
   private final String _literal;
+  private String[] _result;
 
   public LiteralTransformFunction(String literal) {
     _literal = literal;
@@ -48,12 +51,11 @@ public class LiteralTransformFunction implements TransformFunction {
 
   @Override
   public void init(List<TransformFunction> arguments, Map<String, DataSource> dataSourceMap) {
-    throw new UnsupportedOperationException();
   }
 
   @Override
   public TransformResultMetadata getResultMetadata() {
-    throw new UnsupportedOperationException();
+    return BaseTransformFunction.STRING_SV_NO_DICTIONARY_METADATA;
   }
 
   @Override
@@ -93,7 +95,11 @@ public class LiteralTransformFunction implements TransformFunction {
 
   @Override
   public String[] transformToStringValuesSV(ProjectionBlock projectionBlock) {
-    throw new UnsupportedOperationException();
+    if (_result == null) {
+      _result = new String[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+      Arrays.fill(_result, _literal);
+    }
+    return _result;
   }
 
   @Override


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