lincoln-lil commented on code in PR #21704:
URL: https://github.com/apache/flink/pull/21704#discussion_r1089940415
##########
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:
I was going to add an assertion here, just a protection for the following
lines
##########
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:
ok
##########
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 also remember discussing this case with you a long time ago, but I didn't
find any record of it in the commit history
--
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]