godfreyhe commented on code in PR #21704:
URL: https://github.com/apache/flink/pull/21704#discussion_r1089919390
##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/stream/sql/agg/AggregateTest.scala:
##########
@@ -395,4 +395,48 @@ class AggregateTest extends TableTestBase {
def testApproximateCountDistinct(): Unit = {
util.verifyExecPlan("SELECT APPROX_COUNT_DISTINCT(b) FROM MyTable")
}
+
+ @Test
+ def testCountStart(): Unit = {
+ util.tableEnv.executeSql("""
+ |CREATE TABLE src (
+ | id VARCHAR,
+ | cnt BIGINT
+ |) WITH (
+ | 'connector' = 'values'
+ |)
+ |""".stripMargin)
+ util.verifyExecPlan("SELECT COUNT(*) FROM src")
+ }
+
+ @Test
+ def testCountStartWithMetadata(): Unit = {
Review Comment:
please add a case about all columns are metadata
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/PushProjectIntoTableSourceScanRule.java:
##########
@@ -139,10 +139,23 @@ public void onMatch(RelOptRuleCall call) {
final FlinkTypeFactory typeFactory = unwrapTypeFactory(scan);
final ResolvedSchema schema =
sourceTable.contextResolvedTable().getResolvedSchema();
final RowType producedType = createProducedType(schema,
sourceTable.tableSource());
- final NestedSchema projectedSchema =
+ NestedSchema projectedSchema =
NestedProjectionUtil.build(
getProjections(project, scan),
typeFactory.buildRelNodeRowType(producedType));
+ // we can not perform an empty column query to the table scan, just
choose the first column
+ // in such case
+ if (projectedSchema.columns().isEmpty()) {
+ if (scan.getRowType().getFieldCount() == 0) {
+ return;
+ }
+ RexInputRef firstFieldRef = RexInputRef.of(0, scan.getRowType());
+ projectedSchema =
Review Comment:
I clearly remember this case is handled before, maybe the code is removed in
some refactor/bugfix changes
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/PushProjectIntoTableSourceScanRule.java:
##########
@@ -139,10 +139,23 @@ public void onMatch(RelOptRuleCall call) {
final FlinkTypeFactory typeFactory = unwrapTypeFactory(scan);
final ResolvedSchema schema =
sourceTable.contextResolvedTable().getResolvedSchema();
final RowType producedType = createProducedType(schema,
sourceTable.tableSource());
- final NestedSchema projectedSchema =
+ NestedSchema projectedSchema =
NestedProjectionUtil.build(
getProjections(project, scan),
typeFactory.buildRelNodeRowType(producedType));
+ // we can not perform an empty column query to the table scan, just
choose the first column
+ // in such case
+ if (projectedSchema.columns().isEmpty()) {
+ if (scan.getRowType().getFieldCount() == 0) {
+ return;
Review Comment:
is this case valid ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]