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

haibow pushed a commit to branch release-0.4.0-rc2
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit f26f19b674604dbd7afce9e81954198b245e4338
Author: Xiang Fu <fx19880...@gmail.com>
AuthorDate: Wed May 27 21:55:14 2020 -0700

    Single Quote String Literal for function invoker results (#5456)
---
 .../org/apache/pinot/sql/parsers/CalciteSqlParser.java     |  3 +++
 .../apache/pinot/sql/parsers/CalciteSqlCompilerTest.java   |  6 +++---
 .../integration/tests/OfflineClusterIntegrationTest.java   | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

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 45b3274..2aec8ec 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
@@ -676,6 +676,9 @@ public class CalciteSqlParser {
       try {
         FunctionInvoker invoker = new FunctionInvoker(functionInfo);
         Object result = invoker.process(arguments);
+        if (result instanceof String) {
+          result = String.format("'%s'", result);
+        }
         return RequestUtils.getLiteralExpression(result);
       } catch (Exception e) {
         throw new SqlCompilationException(new 
IllegalArgumentException("Unsupported function - " + funcName, e));
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 ac0a5cf..aec7917 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
@@ -1534,7 +1534,7 @@ public class CalciteSqlCompilerTest {
     Function greaterThan = pinotQuery.getFilterExpression().getFunctionCall();
     String today = 
greaterThan.getOperands().get(1).getLiteral().getStringValue();
     String expectedTodayStr =
-        
Instant.now().atZone(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd
 z"));
+        "'" + 
Instant.now().atZone(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd
 z")) + "'";
     Assert.assertEquals(today, expectedTodayStr);
   }
 
@@ -1557,7 +1557,7 @@ public class CalciteSqlCompilerTest {
     Assert.assertTrue(expression.getLiteral() != null);
     String today = expression.getLiteral().getStringValue();
     String expectedTodayStr =
-        
Instant.now().atZone(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd
 z"));
+        "'" + 
Instant.now().atZone(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd
 z")) + "'";
     Assert.assertEquals(today, expectedTodayStr);
     expression = 
CalciteSqlParser.compileToExpression("toDateTime(playerName)");
     Assert.assertTrue(expression.getFunctionCall() != null);
@@ -1575,7 +1575,7 @@ public class CalciteSqlCompilerTest {
     Assert.assertTrue(expression.getFunctionCall() != null);
     expression = 
CalciteSqlParser.invokeCompileTimeFunctionExpression(expression);
     Assert.assertTrue(expression.getLiteral() != null);
-    Assert.assertEquals(expression.getLiteral().getFieldValue(), "emaNreyalp");
+    Assert.assertEquals(expression.getLiteral().getFieldValue(), 
"'emaNreyalp'");
     expression = CalciteSqlParser.compileToExpression("count(*)");
     Assert.assertTrue(expression.getFunctionCall() != null);
     expression = 
CalciteSqlParser.invokeCompileTimeFunctionExpression(expression);
diff --git 
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
 
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
index f433a3e..223602c 100644
--- 
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
+++ 
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
@@ -24,6 +24,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.collect.ImmutableList;
 import java.io.File;
 import java.io.IOException;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -309,6 +312,17 @@ public class OfflineClusterIntegrationTest extends 
BaseClusterIntegrationTestSet
   }
 
   @Test
+  public void testTimeFunc()
+      throws Exception {
+    String sqlQuery = "SELECT toDateTime(now(), 'yyyy-MM-dd z') FROM mytable";
+    JsonNode response = postSqlQuery(sqlQuery, _brokerBaseApiUrl);
+    String todayStr = 
response.get("resultTable").get("rows").get(0).get(0).asText();
+    String expectedTodayStr =
+        
Instant.now().atZone(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd
 z"));
+    Assert.assertEquals(todayStr, expectedTodayStr);
+  }
+
+  @Test
   public void testRangeIndexTriggering()
       throws Exception {
     long numTotalDocs = getCountStarResult();


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

Reply via email to