raminqaf commented on code in PR #28120:
URL: https://github.com/apache/flink/pull/28120#discussion_r3196245007
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/ToChangelogTypeStrategy.java:
##########
@@ -96,10 +97,14 @@ public List<Signature> getExpectedSignatures(final
FunctionDefinition definition
final String opColumnName = resolveOpColumnName(callContext);
final List<Field> inputFields =
DataType.getFields(semantics.dataType());
+ // Excludes partition keys when set semantics; the framework
prepends them so
+ // including them again here would duplicate the columns.
Review Comment:
nit: not really needed since the java docs of the method explain already
what it does
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/ChangelogTypeStrategyUtils.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.types.inference.strategies;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.DataTypes.Field;
+import org.apache.flink.table.functions.TableSemantics;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.IntStream;
+
+/** Shared helpers for changelog-style PTFs ({@code TO_CHANGELOG}, {@code
FROM_CHANGELOG}). */
+@Internal
+public final class ChangelogTypeStrategyUtils {
+
+ /**
+ * Returns the input column indices that pass through to the function's
output, excluding: -
+ * Partition keys, if present (the PTF framework prepends them when the
input has set semantics)
+ * - The operation column {@code opColumnName} when non-null and present.
+ */
+ public static int[] computeOutputIndices(
+ final TableSemantics tableSemantics, final @Nullable String
opColumnName) {
Review Comment:
I would rather create an override of the method one for TO_CHANGELOG and one
for FROM_CHANGELOG.
```suggestion
public static int[] computeOutputIndices(
final TableSemantics tableSemantics, final @Nullable String
opColumnName) {
// ...
}
public static int[] computeOutputIndices(final TableSemantics
tableSemantics) {
// ....
}
```
Alternatively, it is good to explain why opColumnName is nullable.
##########
flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/ToChangelogTest.xml:
##########
@@ -35,42 +35,42 @@ ProcessTableFunction(invocation=[TO_CHANGELOG(TABLE(#0),
DEFAULT(), DEFAULT(), D
]]>
</Resource>
</TestCase>
- <TestCase name="testRetractSource">
+ <TestCase name="testRetractPartitionBy">
<Resource name="sql">
- <![CDATA[SELECT * FROM TO_CHANGELOG(input => TABLE retract_source)]]>
+ <![CDATA[SELECT * FROM TO_CHANGELOG(input => TABLE retract_source
PARTITION BY id)]]>
</Resource>
<Resource name="ast">
<![CDATA[
-LogicalProject(op=[$0], id=[$1], name=[$2])
-+- LogicalTableFunctionScan(invocation=[TO_CHANGELOG(TABLE(#0), DEFAULT(),
DEFAULT(), DEFAULT(), DEFAULT())], rowType=[RecordType(VARCHAR(2147483647) op,
INTEGER id, VARCHAR(2147483647) name)])
+LogicalProject(id=[$0], op=[$1], name=[$2])
Review Comment:
Just to point out:
- If we use `PARTITION BY id` the LogicalProject would be id, op, ...
- If we avoid `PARTITION BY` clause the LogicalProject would be op, id,...
is this intended?
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/ptf/ToChangelogFunction.java:
##########
@@ -70,6 +75,14 @@ public ToChangelogFunction(final SpecializedContext context)
{
final Map<String, String> opMapping =
callContext.getArgumentValue(2, Map.class).orElse(null);
this.rawOpMap = buildOpMap(opMapping);
+
+ // Drop partition keys when set semantics: the framework prepends them
automatically.
+ // For row semantics, partitionByColumns is empty and this is a no-op
identity projection.
+ final TableSemantics tableSemantics =
+ callContext
+ .getTableSemantics(0)
+ .orElseThrow(() -> new IllegalStateException("Table
argument expected."));
Review Comment:
Needed? Should be caught in the TypeStrategy as Validation error during
planning
--
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]