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/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new edf0c01be0 Fix NonAggregationGroupByToDistinctQueryRewriter (#9605)
edf0c01be0 is described below
commit edf0c01be06158c920f4803f16b41df1c531f786
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Mon Oct 17 14:02:33 2022 -0700
Fix NonAggregationGroupByToDistinctQueryRewriter (#9605)
---
...nAggregationGroupByToDistinctQueryRewriter.java | 70 +++++----
.../pinot/sql/parsers/CalciteSqlCompilerTest.java | 39 +++--
...regationGroupByToDistinctQueryRewriterTest.java | 160 ++++-----------------
.../tests/OfflineClusterIntegrationTest.java | 12 +-
pinot-tools/src/test/resources/queries.raw | 2 +-
5 files changed, 89 insertions(+), 194 deletions(-)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriter.java
b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriter.java
index eb26df6517..958387d051 100644
---
a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriter.java
+++
b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriter.java
@@ -18,58 +18,72 @@
*/
package org.apache.pinot.sql.parsers.rewriter;
-import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
import org.apache.pinot.common.request.Expression;
+import org.apache.pinot.common.request.Function;
import org.apache.pinot.common.request.PinotQuery;
import org.apache.pinot.common.utils.request.RequestUtils;
import org.apache.pinot.sql.parsers.CalciteSqlParser;
import org.apache.pinot.sql.parsers.SqlCompilationException;
+/**
+ * Rewrite non-aggregation group-by query to distinct query.
+ * The query can be rewritten only if select expression set and group-by
expression set are the same.
+ *
+ * E.g.
+ * SELECT col1, col2 FROM foo GROUP BY col1, col2 --> SELECT DISTINCT col1,
col2 FROM foo
+ * SELECT col1 + col2 FROM foo GROUP BY col1 + col2 --> SELECT DISTINCT col1 +
col2 FROM foo
+ * SELECT col1 AS c1 FROM foo GROUP BY col1 --> SELECT DISTINCT col1 AS c1
FROM foo
+ * SELECT col1, col1 AS c1, col2 FROM foo GROUP BY col1, col2 --> SELECT
DISTINCT col1, col1 AS ci, col2 FROM foo
+ *
+ * Unsupported queries:
+ * SELECT col1 FROM foo GROUP BY col1, col2 (not equivalent to SELECT DISTINCT
col1 FROM foo)
+ * SELECT col1 + col2 FROM foo GROUP BY col1, col2 (not equivalent to SELECT
col1 + col2 FROM foo)
+ */
public class NonAggregationGroupByToDistinctQueryRewriter implements
QueryRewriter {
- /**
- * Rewrite non-aggregate group by query to distinct query.
- * E.g.
- * ```
- * SELECT col1+col2*5 FROM foo GROUP BY col1, col2 => SELECT distinct
col1+col2*5 FROM foo
- * SELECT col1, col2 FROM foo GROUP BY col1, col2 => SELECT distinct col1,
col2 FROM foo
- * ```
- * @param pinotQuery
- */
+
@Override
public PinotQuery rewrite(PinotQuery pinotQuery) {
- boolean hasAggregation = false;
+ if (pinotQuery.getGroupByListSize() == 0) {
+ return pinotQuery;
+ }
for (Expression select : pinotQuery.getSelectList()) {
if (CalciteSqlParser.isAggregateExpression(select)) {
- hasAggregation = true;
+ return pinotQuery;
}
}
if (pinotQuery.getOrderByList() != null) {
for (Expression orderBy : pinotQuery.getOrderByList()) {
if (CalciteSqlParser.isAggregateExpression(orderBy)) {
- hasAggregation = true;
+ return pinotQuery;
}
}
}
- if (!hasAggregation && pinotQuery.getGroupByListSize() > 0) {
- Set<String> selectIdentifiers =
CalciteSqlParser.extractIdentifiers(pinotQuery.getSelectList(), true);
- Set<String> groupByIdentifiers =
CalciteSqlParser.extractIdentifiers(pinotQuery.getGroupByList(), true);
- if (groupByIdentifiers.containsAll(selectIdentifiers)) {
- Expression distinctExpression =
RequestUtils.getFunctionExpression("distinct");
- for (Expression select : pinotQuery.getSelectList()) {
- distinctExpression.getFunctionCall().addToOperands(select);
- }
- pinotQuery.setSelectList(Arrays.asList(distinctExpression));
- pinotQuery.setGroupByList(Collections.emptyList());
+
+ // This rewriter is applied after AliasApplier, so all the alias in
group-by are already replaced with expressions
+ Set<Expression> selectExpressions = new HashSet<>();
+ for (Expression select : pinotQuery.getSelectList()) {
+ Function function = select.getFunctionCall();
+ if (function != null && function.getOperator().equals("as")) {
+ selectExpressions.add(function.getOperands().get(0));
} else {
- selectIdentifiers.removeAll(groupByIdentifiers);
- throw new SqlCompilationException(String.format(
- "For non-aggregation group by query, all the identifiers in select
clause should be in groupBys. Found "
- + "identifier: %s",
Arrays.toString(selectIdentifiers.toArray(new String[0]))));
+ selectExpressions.add(select);
}
}
- return pinotQuery;
+ Set<Expression> groupByExpressions = new
HashSet<>(pinotQuery.getGroupByList());
+ if (selectExpressions.equals(groupByExpressions)) {
+ Expression distinct = RequestUtils.getFunctionExpression("distinct");
+ distinct.getFunctionCall().setOperands(pinotQuery.getSelectList());
+ pinotQuery.setSelectList(Collections.singletonList(distinct));
+ pinotQuery.setGroupByList(null);
+ return pinotQuery;
+ } else {
+ throw new SqlCompilationException(String.format(
+ "For non-aggregation group-by query, select expression set and
group-by expression set should be the same. "
+ + "Found select: %s, group-by: %s", selectExpressions,
groupByExpressions));
+ }
}
}
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 901cc4860a..2c1e9d26e3 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
@@ -1812,7 +1812,7 @@ public class CalciteSqlCompilerTest {
}
@Test
- public void testOrdinalsQueryRewriteWithDistinctOrderby() {
+ public void testOrdinalsQueryRewriteWithDistinctOrderBy() {
String query =
"SELECT baseballStats.playerName AS playerName FROM baseballStats
GROUP BY baseballStats.playerName ORDER BY "
+ "1 ASC";
@@ -1820,7 +1820,7 @@ public class CalciteSqlCompilerTest {
Assert.assertEquals(
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(0)
.getIdentifier().getName(), "baseballStats.playerName");
- Assert.assertTrue(pinotQuery.getGroupByList().isEmpty());
+ Assert.assertNull(pinotQuery.getGroupByList());
Assert.assertEquals(
pinotQuery.getOrderByList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
"baseballStats.playerName");
@@ -1937,19 +1937,16 @@ public class CalciteSqlCompilerTest {
Assert.assertEquals(encodedBase64, "aGVsbG8h");
Assert.assertEquals(decodedBase64, "hello!");
- query =
- "select toBase64(toUtf8(upper('hello!'))),
fromUtf8(fromBase64(toBase64(toUtf8(upper('hello!'))))) from "
- + "mytable";
+ query = "select toBase64(toUtf8(upper('hello!'))),
fromUtf8(fromBase64(toBase64(toUtf8(upper('hello!'))))) from "
+ + "mytable";
pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
encodedBase64 =
pinotQuery.getSelectList().get(0).getLiteral().getStringValue();
decodedBase64 =
pinotQuery.getSelectList().get(1).getLiteral().getStringValue();
Assert.assertEquals(encodedBase64, "SEVMTE8h");
Assert.assertEquals(decodedBase64, "HELLO!");
- query =
- "select
reverse(fromUtf8(fromBase64(toBase64(toUtf8(upper('hello!')))))) from mytable
where fromUtf8"
- + "(fromBase64(toBase64(toUtf8(upper('hello!')))))"
- + " = bar";
+ query = "select
reverse(fromUtf8(fromBase64(toBase64(toUtf8(upper('hello!')))))) from mytable
where "
+ + "fromUtf8(fromBase64(toBase64(toUtf8(upper('hello!'))))) = bar";
pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
String arg1 =
pinotQuery.getSelectList().get(0).getLiteral().getStringValue();
String leftOp =
@@ -2217,7 +2214,7 @@ public class CalciteSqlCompilerTest {
Assert.assertEquals(
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getIdentifier().getName(),
"col2");
- query = "SELECT col1+col2*5 FROM foo GROUP BY col1, col2";
+ query = "SELECT col1+col2*5 FROM foo GROUP BY col1+col2*5";
pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
Assert.assertEquals(pinotQuery.getSelectListSize(), 1);
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator().toUpperCase(),
"DISTINCT");
@@ -2237,7 +2234,7 @@ public class CalciteSqlCompilerTest {
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
.getFunctionCall().getOperands().get(1).getLiteral().getLongValue(), 5L);
- query = "SELECT col1+col2*5 AS col3 FROM foo GROUP BY col1, col2";
+ query = "SELECT col1+col2*5 AS col3 FROM foo GROUP BY col3";
pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
Assert.assertEquals(pinotQuery.getSelectListSize(), 1);
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator().toUpperCase(),
"DISTINCT");
@@ -2265,17 +2262,16 @@ public class CalciteSqlCompilerTest {
5L);
}
- @Test(expectedExceptions = SqlCompilationException.class)
+ @Test
public void testInvalidNonAggregationGroupBy() {
- // Not support Aggregation functions in case statements.
- try {
- CalciteSqlParser.compileToPinotQuery("SELECT col1+col2 FROM foo GROUP BY
col1");
- } catch (SqlCompilationException e) {
- Assert.assertEquals(e.getMessage(),
- "For non-aggregation group by query, all the identifiers in select
clause should be in groupBys. Found "
- + "identifier: [col2]");
- throw e;
- }
+ Assert.assertThrows(SqlCompilationException.class,
+ () -> CalciteSqlParser.compileToPinotQuery("SELECT col1 FROM foo GROUP
BY col1, col2"));
+ Assert.assertThrows(SqlCompilationException.class,
+ () -> CalciteSqlParser.compileToPinotQuery("SELECT col1, col2 FROM foo
GROUP BY col1"));
+ Assert.assertThrows(SqlCompilationException.class,
+ () -> CalciteSqlParser.compileToPinotQuery("SELECT col1 + col2 FROM
foo GROUP BY col1"));
+ Assert.assertThrows(SqlCompilationException.class,
+ () -> CalciteSqlParser.compileToPinotQuery("SELECT col1+col2 FROM foo
GROUP BY col1,col2"));
}
@Test
@@ -2681,7 +2677,6 @@ public class CalciteSqlCompilerTest {
Assert.assertEquals(sqlNodeAndOptions.getSqlType(), PinotSqlType.DML);
}
-
@Test
public void shouldParseBasicAtTimeZoneExtension() {
// Given:
diff --git
a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriterTest.java
b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriterTest.java
index 295f4502ea..b97df8dfc2 100644
---
a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriterTest.java
+++
b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/NonAggregationGroupByToDistinctQueryRewriterTest.java
@@ -18,155 +18,45 @@
*/
package org.apache.pinot.sql.parsers.rewriter;
-import org.apache.pinot.common.request.PinotQuery;
import org.apache.pinot.sql.parsers.CalciteSqlParser;
-import org.testng.Assert;
+import org.apache.pinot.sql.parsers.SqlCompilationException;
import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertThrows;
-public class NonAggregationGroupByToDistinctQueryRewriterTest {
+public class NonAggregationGroupByToDistinctQueryRewriterTest {
private static final QueryRewriter QUERY_REWRITER = new
NonAggregationGroupByToDistinctQueryRewriter();
@Test
- public void testQuery1() {
- final PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery("SELECT
A FROM myTable GROUP BY A");
- QUERY_REWRITER.rewrite(pinotQuery);
-
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
"distinct");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
"A");
- }
-
- @Test
- // SELECT col1+col2*5 FROM foo GROUP BY col1, col2 => SELECT distinct
col1+col2*5 FROM foo
- public void testQuery2() {
- final PinotQuery pinotQuery =
- CalciteSqlParser.compileToPinotQuery("SELECT col1+col2*5 FROM foo
GROUP BY col1, col2");
- QUERY_REWRITER.rewrite(pinotQuery);
-
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
"distinct");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(0)
- .getIdentifier().getName(), "col1");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
- .getFunctionCall().getOperands().get(0).getIdentifier().getName(),
"col2");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
-
.getFunctionCall().getOperands().get(1).getLiteral().getLongValue(), 5L);
+ public void testQueryRewrite() {
+ testQueryRewrite("SELECT A FROM myTable GROUP BY A", "SELECT DISTINCT A
FROM myTable");
+ testQueryRewrite("SELECT col1, col2 FROM foo GROUP BY col1, col2", "SELECT
DISTINCT col1, col2 FROM foo");
+ testQueryRewrite("SELECT col1+col2*5 FROM foo GROUP BY col1+col2*5",
"SELECT DISTINCT col1+col2*5 FROM foo");
+ testQueryRewrite("SELECT col1 as col2, col1 as col3 FROM foo GROUP BY
col1",
+ "SELECT DISTINCT col1 as col2, col1 as col3 FROM foo");
+ testQueryRewrite("SELECT col1 as a, col2 as b, concat(col3, col4, '') as c
FROM foo GROUP BY a,b,c",
+ "SELECT DISTINCT col1 as a, col2 as b, concat(col3, col4, '') as c
FROM foo");
+ testQueryRewrite(
+ "SELECT col1 as a, col2 as b, concat(col3, col4, '') as c FROM foo
GROUP BY col1, col2, CONCAT(col3,col4,'')",
+ "SELECT DISTINCT col1 as a, col2 as b, concat(col3, col4, '') as c
FROM foo");
}
- @Test
- // SELECT col1, col2 FROM foo GROUP BY col1, col2 => SELECT distinct col1,
col2 FROM foo
- public void testQuery3() {
- final PinotQuery pinotQuery =
- CalciteSqlParser.compileToPinotQuery("SELECT col1, col2 FROM foo GROUP
BY col1, col2 ");
- QUERY_REWRITER.rewrite(pinotQuery);
-
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
"distinct");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
"col1");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getIdentifier().getName(),
"col2");
+ private void testQueryRewrite(String original, String expected) {
+
assertEquals(QUERY_REWRITER.rewrite(CalciteSqlParser.compileToPinotQuery(original)),
+ CalciteSqlParser.compileToPinotQuery(expected));
}
@Test
- // SELECT col1 as col2 FROM foo GROUP BY col1 => SELECT distinct col1 as
col2 FROM foo
- public void testQuery4() {
- final PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery("SELECT
col1 as col2 FROM foo GROUP BY col1");
- QUERY_REWRITER.rewrite(pinotQuery);
-
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
"distinct");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(0)
- .getIdentifier().getName(), "col1");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "col2");
+ public void testUnsupportedQueries() {
+ testUnsupportedQuery("SELECT col1 FROM foo GROUP BY col1, col2");
+ testUnsupportedQuery("SELECT col1, col2 FROM foo GROUP BY col1");
+ testUnsupportedQuery("SELECT col1 + col2 FROM foo GROUP BY col1, col2");
}
- @Test
- // SELECT col1 as a, col2 as b, concat(col3, col4, '') as c FROM foo GROUP
BY a,b,c => SELECT DISTINCT col1 as a,
- // col2 as b, concat(col3, col4, '') as c FROM foo
- public void testQuery5() {
- final PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(
- "SELECT col1 as a, col2 as b, concat(col3, col4, '') as c FROM foo
GROUP BY a,b,c");
- QUERY_REWRITER.rewrite(pinotQuery);
-
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
"distinct");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(0)
- .getIdentifier().getName(), "col1");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "a");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getFunctionCall().getOperands().get(0)
- .getIdentifier().getName(), "col2");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "b");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
- .getFunctionCall().getOperator(), "concat");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
- .getFunctionCall().getOperands().get(0).getIdentifier().getName(),
"col3");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
- .getFunctionCall().getOperands().get(1).getIdentifier().getName(),
"col4");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
-
.getFunctionCall().getOperands().get(2).getLiteral().getStringValue(), "");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "c");
- }
-
- @Test
- // SELECT col1 as a, col2 as b, concat(col3, col4, '') as c FROM foo GROUP
BY col1, col2, col3, col4 => SELECT
- // DISTINCT col1 as a, col2 as b, concat(col3, col4, '') as c FROM foo
- public void testQuery6() {
- final PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(
- "SELECT col1 as a, col2 as b, concat(col3, col4, '') as c FROM foo
GROUP BY col1, col2, col3, col4");
- QUERY_REWRITER.rewrite(pinotQuery);
-
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
"distinct");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(0)
- .getIdentifier().getName(), "col1");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "a");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getFunctionCall().getOperands().get(0)
- .getIdentifier().getName(), "col2");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(1).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "b");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperator(),
"as");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
- .getFunctionCall().getOperator(), "concat");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
- .getFunctionCall().getOperands().get(0).getIdentifier().getName(),
"col3");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
- .getFunctionCall().getOperands().get(1).getIdentifier().getName(),
"col4");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(0)
-
.getFunctionCall().getOperands().get(2).getLiteral().getStringValue(), "");
- Assert.assertEquals(
-
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(2).getFunctionCall().getOperands().get(1)
- .getIdentifier().getName(), "c");
+ private void testUnsupportedQuery(String query) {
+ assertThrows(SqlCompilationException.class,
+ () ->
QUERY_REWRITER.rewrite(CalciteSqlParser.compileToPinotQuery(query)));
}
}
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 1fdd46d5b5..a404c10ad8 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
@@ -2299,16 +2299,12 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
h2Query = "SELECT Carrier, DestAirportID, DestCityName FROM mytable GROUP
BY Carrier, DestAirportID, DestCityName";
testQuery(pinotQuery, h2Query);
- pinotQuery = "SELECT ArrTime-DepTime FROM mytable GROUP BY ArrTime,
DepTime LIMIT 1000000";
- h2Query = "SELECT ArrTime-DepTime FROM mytable GROUP BY ArrTime, DepTime";
+ pinotQuery = "SELECT ArrTime-DepTime FROM mytable GROUP BY ArrTime-DepTime
LIMIT 1000000";
+ h2Query = "SELECT ArrTime-DepTime FROM mytable GROUP BY ArrTime-DepTime";
testQuery(pinotQuery, h2Query);
- pinotQuery = "SELECT ArrTime-DepTime,ArrTime/3,DepTime*2 FROM mytable
GROUP BY ArrTime, DepTime LIMIT 1000000";
- h2Query = "SELECT ArrTime-DepTime,ArrTime/3,DepTime*2 FROM mytable GROUP
BY ArrTime, DepTime";
- testQuery(pinotQuery, h2Query);
-
- pinotQuery = "SELECT ArrTime+DepTime FROM mytable GROUP BY ArrTime +
DepTime LIMIT 1000000";
- h2Query = "SELECT ArrTime+DepTime FROM mytable GROUP BY ArrTime + DepTime";
+ pinotQuery = "SELECT ArrTime+DepTime AS A FROM mytable GROUP BY A LIMIT
1000000";
+ h2Query = "SELECT ArrTime+DepTime AS A FROM mytable GROUP BY A";
testQuery(pinotQuery, h2Query);
}
diff --git a/pinot-tools/src/test/resources/queries.raw
b/pinot-tools/src/test/resources/queries.raw
index f700404fc3..584ebc28ce 100644
--- a/pinot-tools/src/test/resources/queries.raw
+++ b/pinot-tools/src/test/resources/queries.raw
@@ -15,4 +15,4 @@ SELECT C1, C2 FROM Foo WHERE C3 > 100 ORDER BY C1, C2 DESC
LIMIT 10000
SELECT C1, C2 FROM Foo WHERE C3 > 100 ORDER BY C1 ASC, C2 DESC
SELECT C1, C2 FROM Foo WHERE C3 > 100 ORDER BY C1 ASC, C2 DESC LIMIT 10000
SELECT C1, C2 FROM Foo WHERE (C3 IN (100) OR C3 NOT IN (200)) GROUP BY C1, C2
LIMIT 10000
-SELECT C1, C2 FROM Foo WHERE (C12 IN (100) OR C13 NOT IN (200)) GROUP BY C1,
C2, C8 LIMIT 10000
\ No newline at end of file
+SELECT C1, C2 FROM Foo WHERE (C12 IN (100) OR C13 NOT IN (200)) GROUP BY C1,
C2 LIMIT 10000
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]