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 c139488 Support expression as the left-hand side for BETWEEN and IN
clause (#5502)
c139488 is described below
commit c139488a6c33e4328b13c24fbfd689848c816849
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Mon Jun 8 11:44:24 2020 -0700
Support expression as the left-hand side for BETWEEN and IN clause (#5502)
Add PQL compiler support for left-hand expression for BETWEEN and IN
---
.../parsers/pql2/ast/BetweenPredicateAstNode.java | 8 +--
.../pql/parsers/pql2/ast/InPredicateAstNode.java | 2 +
.../tests/OfflineClusterIntegrationTest.java | 63 +++++++++++-----------
3 files changed, 36 insertions(+), 37 deletions(-)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/BetweenPredicateAstNode.java
b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/BetweenPredicateAstNode.java
index 4f11372..8d216be 100644
---
a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/BetweenPredicateAstNode.java
+++
b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/BetweenPredicateAstNode.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import org.apache.pinot.common.request.Expression;
import org.apache.pinot.common.request.FilterOperator;
import org.apache.pinot.common.request.Function;
+import org.apache.pinot.common.request.transform.TransformExpressionTree;
import org.apache.pinot.common.utils.request.FilterQueryTree;
import org.apache.pinot.common.utils.request.HavingQueryTree;
import org.apache.pinot.common.utils.request.RequestUtils;
@@ -39,6 +40,7 @@ public class BetweenPredicateAstNode extends PredicateAstNode
{
_identifier = node.getName();
} else if (childNode instanceof FunctionCallAstNode) {
_function = (FunctionCallAstNode) childNode;
+ _identifier = TransformExpressionTree.getStandardExpression(childNode);
} else {
super.addChild(childNode);
}
@@ -102,8 +104,7 @@ public class BetweenPredicateAstNode extends
PredicateAstNode {
rangeFuncCall.addToOperands(RequestUtils.createLiteralExpression(right));
return betweenExpr;
} catch (ClassCastException e) {
- throw new Pql2CompilationException(
- "BETWEEN clause was expecting two literal AST nodes, got " +
getChildren());
+ throw new Pql2CompilationException("BETWEEN clause was expecting two
literal AST nodes, got " + getChildren());
}
} else {
throw new Pql2CompilationException("BETWEEN clause does not have two
children nodes");
@@ -123,8 +124,7 @@ public class BetweenPredicateAstNode extends
PredicateAstNode {
Collections.singletonList("[" + left.getValueAsString() + "\t\t" +
right.getValueAsString() + "]"),
FilterOperator.RANGE, null);
} catch (ClassCastException e) {
- throw new Pql2CompilationException(
- "BETWEEN clause was expecting two literal AST nodes, got " +
getChildren());
+ throw new Pql2CompilationException("BETWEEN clause was expecting two
literal AST nodes, got " + getChildren());
}
} else {
throw new Pql2CompilationException("BETWEEN clause does not have two
children nodes");
diff --git
a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/InPredicateAstNode.java
b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/InPredicateAstNode.java
index 82007c5..39a28c2 100644
---
a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/InPredicateAstNode.java
+++
b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/InPredicateAstNode.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.TreeSet;
import org.apache.pinot.common.request.Expression;
import org.apache.pinot.common.request.FilterOperator;
+import org.apache.pinot.common.request.transform.TransformExpressionTree;
import org.apache.pinot.common.utils.request.FilterQueryTree;
import org.apache.pinot.common.utils.request.HavingQueryTree;
import org.apache.pinot.common.utils.request.RequestUtils;
@@ -68,6 +69,7 @@ public class InPredicateAstNode extends PredicateAstNode {
} else if (childNode instanceof FunctionCallAstNode) {
if (_function == null && _identifier == null) {
_function = (FunctionCallAstNode) childNode;
+ _identifier = TransformExpressionTree.getStandardExpression(childNode);
} else if (_function != null) {
throw new Pql2CompilationException("IN predicate has more than one
function.");
} else {
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 223602c..beda97c 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
@@ -46,15 +46,11 @@ import org.apache.pinot.spi.utils.JsonUtils;
import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.apache.pinot.spi.utils.builder.TableNameBuilder;
import org.apache.pinot.util.TestUtils;
-import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
+import static org.testng.Assert.*;
/**
@@ -319,7 +315,7 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
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);
+ assertEquals(todayStr, expectedTodayStr);
}
@Test
@@ -677,26 +673,26 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
String pqlQuery = "SELECT DaysSinceEpoch,
timeConvert(DaysSinceEpoch,'DAYS','SECONDS') FROM mytable";
JsonNode response = postQuery(pqlQuery);
ArrayNode selectionResults = (ArrayNode)
response.get("selectionResults").get("results");
- Assert.assertNotNull(selectionResults);
- Assert.assertTrue(selectionResults.size() > 0);
+ assertNotNull(selectionResults);
+ assertTrue(selectionResults.size() > 0);
for (int i = 0; i < selectionResults.size(); i++) {
long daysSinceEpoch = selectionResults.get(i).get(0).asLong();
long secondsSinceEpoch = selectionResults.get(i).get(1).asLong();
- Assert.assertEquals(daysSinceEpoch * 24 * 60 * 60, secondsSinceEpoch);
+ assertEquals(daysSinceEpoch * 24 * 60 * 60, secondsSinceEpoch);
}
pqlQuery =
"SELECT DaysSinceEpoch, timeConvert(DaysSinceEpoch,'DAYS','SECONDS')
FROM mytable order by DaysSinceEpoch limit 10000";
response = postQuery(pqlQuery);
selectionResults = (ArrayNode)
response.get("selectionResults").get("results");
- Assert.assertNotNull(selectionResults);
- Assert.assertTrue(selectionResults.size() > 0);
+ assertNotNull(selectionResults);
+ assertTrue(selectionResults.size() > 0);
long prevValue = -1;
for (int i = 0; i < selectionResults.size(); i++) {
long daysSinceEpoch = selectionResults.get(i).get(0).asLong();
long secondsSinceEpoch = selectionResults.get(i).get(1).asLong();
- Assert.assertEquals(daysSinceEpoch * 24 * 60 * 60, secondsSinceEpoch);
- Assert.assertTrue(daysSinceEpoch >= prevValue);
+ assertEquals(daysSinceEpoch * 24 * 60 * 60, secondsSinceEpoch);
+ assertTrue(daysSinceEpoch >= prevValue);
prevValue = daysSinceEpoch;
}
@@ -704,14 +700,14 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
"SELECT DaysSinceEpoch, timeConvert(DaysSinceEpoch,'DAYS','SECONDS')
FROM mytable order by timeConvert(DaysSinceEpoch,'DAYS','SECONDS') DESC limit
10000";
response = postQuery(pqlQuery);
selectionResults = (ArrayNode)
response.get("selectionResults").get("results");
- Assert.assertNotNull(selectionResults);
- Assert.assertTrue(selectionResults.size() > 0);
+ assertNotNull(selectionResults);
+ assertTrue(selectionResults.size() > 0);
prevValue = Long.MAX_VALUE;
for (int i = 0; i < selectionResults.size(); i++) {
long daysSinceEpoch = selectionResults.get(i).get(0).asLong();
long secondsSinceEpoch = selectionResults.get(i).get(1).asLong();
- Assert.assertEquals(daysSinceEpoch * 24 * 60 * 60, secondsSinceEpoch);
- Assert.assertTrue(secondsSinceEpoch <= prevValue);
+ assertEquals(daysSinceEpoch * 24 * 60 * 60, secondsSinceEpoch);
+ assertTrue(secondsSinceEpoch <= prevValue);
prevValue = secondsSinceEpoch;
}
}
@@ -724,32 +720,33 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
String pqlQuery;
pqlQuery = "SELECT count(*) FROM mytable WHERE DaysSinceEpoch = " +
daysSinceEpoch;
- JsonNode response1 = postQuery(pqlQuery);
+ long expectedResult =
postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong();
+ System.out.println(expectedResult);
pqlQuery = "SELECT count(*) FROM mytable WHERE
timeConvert(DaysSinceEpoch,'DAYS','SECONDS') = " + secondsSinceEpoch;
- JsonNode response2 = postQuery(pqlQuery);
+
assertEquals(postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong(),
expectedResult);
pqlQuery = "SELECT count(*) FROM mytable WHERE DaysSinceEpoch = " +
daysSinceEpoch
+ " OR timeConvert(DaysSinceEpoch,'DAYS','SECONDS') = " +
secondsSinceEpoch;
- JsonNode response3 = postQuery(pqlQuery);
+
assertEquals(postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong(),
expectedResult);
pqlQuery = "SELECT count(*) FROM mytable WHERE DaysSinceEpoch = " +
daysSinceEpoch
+ " AND timeConvert(DaysSinceEpoch,'DAYS','SECONDS') = " +
secondsSinceEpoch;
- JsonNode response4 = postQuery(pqlQuery);
+
assertEquals(postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong(),
expectedResult);
pqlQuery =
"SELECT count(*) FROM mytable WHERE
DIV(timeConvert(DaysSinceEpoch,'DAYS','SECONDS'),1) = " + secondsSinceEpoch;
- JsonNode response5 = postQuery(pqlQuery);
-
- double val1 =
response1.get("aggregationResults").get(0).get("value").asDouble();
- double val2 =
response2.get("aggregationResults").get(0).get("value").asDouble();
- double val3 =
response3.get("aggregationResults").get(0).get("value").asDouble();
- double val4 =
response4.get("aggregationResults").get(0).get("value").asDouble();
- double val5 =
response5.get("aggregationResults").get(0).get("value").asDouble();
- Assert.assertEquals(val1, val2);
- Assert.assertEquals(val1, val3);
- Assert.assertEquals(val1, val4);
- Assert.assertEquals(val1, val5);
+
assertEquals(postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong(),
expectedResult);
+
+ pqlQuery = String
+ .format("SELECT count(*) FROM mytable WHERE
timeConvert(DaysSinceEpoch,'DAYS','SECONDS') IN (%d, %d)",
+ secondsSinceEpoch - 100, secondsSinceEpoch);
+
assertEquals(postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong(),
expectedResult);
+
+ pqlQuery = String
+ .format("SELECT count(*) FROM mytable WHERE
timeConvert(DaysSinceEpoch,'DAYS','SECONDS') BETWEEN %d AND %d",
+ secondsSinceEpoch - 100, secondsSinceEpoch);
+
assertEquals(postQuery(pqlQuery).get("aggregationResults").get(0).get("value").asLong(),
expectedResult);
}
@Test
@@ -772,7 +769,7 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
//System.out.println(response2);
double val1 =
response1.get("aggregationResults").get(0).get("value").asDouble();
double val2 =
response2.get("aggregationResults").get(0).get("value").asDouble();
- Assert.assertEquals(val1, val2);
+ assertEquals(val1, val2);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]