Skip to content

Commit

Permalink
[CALCITE-5270] JDBC adapter should not generate 'FILTER (WHERE)' in F…
Browse files Browse the repository at this point in the history
…irebolt dialect

Close #2896
  • Loading branch information
thomasbanghart authored and julianhyde committed Sep 9, 2022
1 parent 89c940c commit 1167b12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public FireboltSqlDialect(Context context) {
SqlParserPos.ZERO);
}

@Override public boolean supportsAggregateFunctionFilter() {
return false;
}

@Override public boolean supportsFunction(SqlOperator operator,
RelDataType type, final List<RelDataType> paramTypes) {
switch (operator.kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,36 +266,42 @@ private static String toSql(RelNode root, SqlDialect dialect,
sql(query).ok(expected);
}

@Test void testAggregateFilterWhereToSqlFromProductTable() {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-4321">[CALCITE-4321]
* JDBC adapter omits FILTER (WHERE ...) expressions when generating SQL</a>
* and
* <a href="https://issues.apache.org/jira/browse/CALCITE-5270">[CALCITE-5270]
* JDBC adapter should not generate FILTER (WHERE) in Firebolt dialect</a>. */
@Test void testAggregateFilterWhere() {
String query = "select\n"
+ " sum(\"shelf_width\") filter (where \"net_weight\" > 0),\n"
+ " sum(\"shelf_width\")\n"
+ "from \"foodmart\".\"product\"\n"
+ "where \"product_id\" > 0\n"
+ "group by \"product_id\"";
final String expected = "SELECT"
final String expectedDefault = "SELECT"
+ " SUM(\"shelf_width\") FILTER (WHERE \"net_weight\" > 0 IS TRUE),"
+ " SUM(\"shelf_width\")\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_id\" > 0\n"
+ "GROUP BY \"product_id\"";
sql(query).ok(expected);
}

@Test void testAggregateFilterWhereToBigQuerySqlFromProductTable() {
String query = "select\n"
+ " sum(\"shelf_width\") filter (where \"net_weight\" > 0),\n"
+ " sum(\"shelf_width\")\n"
+ "from \"foodmart\".\"product\"\n"
+ "where \"product_id\" > 0\n"
+ "group by \"product_id\"";
final String expected = "SELECT SUM(CASE WHEN net_weight > 0 IS TRUE"
final String expectedBigQuery = "SELECT"
+ " SUM(CASE WHEN net_weight > 0 IS TRUE"
+ " THEN shelf_width ELSE NULL END), "
+ "SUM(shelf_width)\n"
+ "FROM foodmart.product\n"
+ "WHERE product_id > 0\n"
+ "GROUP BY product_id";
sql(query).withBigQuery().ok(expected);
final String expectedFirebolt = "SELECT"
+ " SUM(CASE WHEN \"net_weight\" > 0 IS TRUE"
+ " THEN \"shelf_width\" ELSE NULL END), "
+ "SUM(\"shelf_width\")\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_id\" > 0\n"
+ "GROUP BY \"product_id\"";
sql(query).ok(expectedDefault)
.withBigQuery().ok(expectedBigQuery)
.withFirebolt().ok(expectedFirebolt);
}

@Test void testPivotToSqlFromProductTable() {
Expand Down

0 comments on commit 1167b12

Please sign in to comment.