This is an automated email from the ASF dual-hosted git repository.
jackie 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 2e834cf Support escaping single quote for SQL literal (#5501)
2e834cf is described below
commit 2e834cf0efc553f729e2f7aeec43725fb68da421
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Mon Jun 8 11:43:39 2020 -0700
Support escaping single quote for SQL literal (#5501)
Currently there is no way to escape single quote for SQL literal
Support escaping single quote by using the SQL convention of double single
quote "''"
This is especially useful for DistinctCountThetaSketch because it stores
expression as literal
E.g. DistinctCountThetaSketch(..., 'foo=''bar''', ...)
---
.../java/org/apache/pinot/common/utils/request/RequestUtils.java | 7 ++++---
.../java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
b/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
index cc4b9c1..994b979 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
@@ -121,7 +121,7 @@ public class RequestUtils {
literal.setDoubleValue(node.bigDecimalValue().doubleValue());
}
} else {
- literal.setStringValue(node.toString().replaceAll("^\'|\'$", ""));
+ literal.setStringValue(node.toString().replaceAll("^'|'$",
"").replace("''", "'"));
}
expression.setLiteral(literal);
return expression;
@@ -176,10 +176,11 @@ public class RequestUtils {
if (object instanceof String) {
return RequestUtils.getLiteralExpression((String) object);
}
- if(object instanceof SqlLiteral) {
+ if (object instanceof SqlLiteral) {
return RequestUtils.getLiteralExpression((SqlLiteral) object);
}
- throw new SqlCompilationException(new
IllegalArgumentException("Unsupported Literal value type - " +
object.getClass()));
+ throw new SqlCompilationException(
+ new IllegalArgumentException("Unsupported Literal value type - " +
object.getClass()));
}
public static Expression getFunctionExpression(String operator) {
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 aec7917..f76eb94 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
@@ -55,7 +55,7 @@ public class CalciteSqlCompilerTest {
CalciteSqlParser.compileToPinotQuery("select * from vegetables where
origin = 'Martha''s Vineyard'");
Assert.assertEquals(
pinotQuery.getFilterExpression().getFunctionCall().getOperands().get(1).getLiteral().getStringValue(),
- "Martha''s Vineyard");
+ "Martha's Vineyard");
pinotQuery = CalciteSqlParser.compileToPinotQuery("select * from
vegetables where origin = 'Martha\"\"s Vineyard'");
Assert.assertEquals(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]