|
33 | 33 | import org.apache.calcite.rel.rules.FilterMergeRule; |
34 | 34 | import org.apache.calcite.runtime.CalciteContextException; |
35 | 35 | import org.apache.calcite.schema.SchemaPlus; |
| 36 | +import org.apache.calcite.sql.SqlBasicCall; |
| 37 | +import org.apache.calcite.sql.SqlCall; |
36 | 38 | import org.apache.calcite.sql.SqlIdentifier; |
37 | 39 | import org.apache.calcite.sql.SqlNode; |
38 | | -import org.apache.calcite.sql.dialect.MysqlSqlDialect; |
| 40 | +import org.apache.calcite.sql.dialect.SparkSqlDialect; |
| 41 | +import org.apache.calcite.sql.fun.SqlCountAggFunction; |
| 42 | +import org.apache.calcite.sql.fun.SqlStdOperatorTable; |
39 | 43 | import org.apache.calcite.sql.parser.SqlParser; |
40 | 44 | import org.apache.calcite.sql.util.SqlShuttle; |
41 | 45 | import org.apache.calcite.sql.validate.SqlValidator; |
@@ -82,7 +86,7 @@ public class QueryService { |
82 | 86 | private DataSourceService dataSourceService; |
83 | 87 | private Settings settings; |
84 | 88 | private static final PplRelToSqlNodeConverter rel2sql = |
85 | | - new PplRelToSqlNodeConverter(MysqlSqlDialect.DEFAULT); |
| 89 | + new PplRelToSqlNodeConverter(SparkSqlDialect.DEFAULT); |
86 | 90 |
|
87 | 91 | @Getter(lazy = true) |
88 | 92 | private final CalciteRelNodeVisitor relNodeVisitor = new CalciteRelNodeVisitor(dataSourceService); |
@@ -336,6 +340,23 @@ public SqlNode visit(SqlIdentifier id) { |
336 | 340 | } |
337 | 341 | return id; |
338 | 342 | } |
| 343 | + |
| 344 | + @Override |
| 345 | + public @org.checkerframework.checker.nullness.qual.Nullable SqlNode visit( |
| 346 | + SqlCall call) { |
| 347 | + if (call.getOperator() instanceof SqlCountAggFunction |
| 348 | + && call.getOperandList().isEmpty()) { |
| 349 | + // Convert COUNT() to COUNT(*) so that SqlCall.isCountStar() resolves to True |
| 350 | + // This is useful when deriving the return types in SqlCountAggFunction#deriveType |
| 351 | + call = |
| 352 | + new SqlBasicCall( |
| 353 | + SqlStdOperatorTable.COUNT, |
| 354 | + List.of(SqlIdentifier.STAR), |
| 355 | + call.getParserPosition(), |
| 356 | + call.getFunctionQuantifier()); |
| 357 | + } |
| 358 | + return super.visit(call); |
| 359 | + } |
339 | 360 | }); |
340 | 361 |
|
341 | 362 | SqlValidator validator = context.getValidator(); |
|
0 commit comments