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/01/21 21:33:48 UTC
[incubator-pinot] 01/01: Make PQL use LIMIT N if TOP N is not set
This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch pql_set_top_with_limit_if_not_present
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit 836e331ef9c0e39f85d87519a1947347e20886be
Author: Xiang Fu <fx...@gmail.com>
AuthorDate: Tue Jan 21 13:33:27 2020 -0800
Make PQL use LIMIT N if TOP N is not set
---
.../pinot/pql/parsers/pql2/ast/SelectAstNode.java | 4 ++++
.../apache/pinot/pql/parsers/Pql2CompilerTest.java | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/SelectAstNode.java b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/SelectAstNode.java
index ff03fb7..228dd27 100644
--- a/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/SelectAstNode.java
+++ b/pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/SelectAstNode.java
@@ -136,10 +136,14 @@ public class SelectAstNode extends BaseAstNode {
}
// If there is a topN clause, set it on the group by
+ // if topN is not present, set it with LIMIT;
+ // if Limit is not present, set it with DEFAULT.
GroupBy groupBy = brokerRequest.getGroupBy();
if (groupBy != null) {
if (_topN != -1) {
groupBy.setTopN(_topN);
+ } else if (_recordLimit != -1) {
+ groupBy.setTopN(_recordLimit);
} else {
// Pinot quirk: default to top 10
groupBy.setTopN(DEFAULT_RECORD_LIMIT);
diff --git a/pinot-common/src/test/java/org/apache/pinot/pql/parsers/Pql2CompilerTest.java b/pinot-common/src/test/java/org/apache/pinot/pql/parsers/Pql2CompilerTest.java
index e633d0f..84b7cfa 100644
--- a/pinot-common/src/test/java/org/apache/pinot/pql/parsers/Pql2CompilerTest.java
+++ b/pinot-common/src/test/java/org/apache/pinot/pql/parsers/Pql2CompilerTest.java
@@ -183,6 +183,25 @@ public class Pql2CompilerTest {
}
@Test
+ public void testGroupByTopLimitBehavior() {
+ boolean previousFailOnConversionErrorValue = Pql2Compiler.FAIL_ON_CONVERSION_ERROR;
+ Pql2Compiler.FAIL_ON_CONVERSION_ERROR = false;
+ BrokerRequest brokerRequest =
+ COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA top 200");
+ Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 200);
+ brokerRequest =
+ COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA limit 300");
+ Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 300);
+ brokerRequest =
+ COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA");
+ Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 10);
+ brokerRequest =
+ COMPILER.compileToBrokerRequest("select count(*) from myTable group by dimA top 200 LIMIT 300");
+ Assert.assertEquals(brokerRequest.getGroupBy().getTopN(), 200);
+ Pql2Compiler.FAIL_ON_CONVERSION_ERROR = previousFailOnConversionErrorValue;
+ }
+
+ @Test
public void testRejectInvalidLexerToken() {
assertCompilationFails("select foo from bar where baz ?= 2");
assertCompilationFails("select foo from bar where baz =! 2");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org