snuyanzin commented on code in PR #29967:
URL: https://github.com/apache/flink/pull/29967#discussion_r4641942082


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/DeduplicateTypeStrategyUtils.java:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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 org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+import org.apache.flink.table.types.utils.DataTypeUtils;
+import org.apache.flink.types.ColumnList;
+import org.apache.flink.util.TimeUtils;
+
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** Argument validation and output type helpers shared by the deduplication 
PTFs. */
+@Internal
+public final class DeduplicateTypeStrategyUtils {
+
+    /** Which record of a key is kept. */
+    @Internal
+    public enum Keep {
+        FIRST("first"),
+        LAST("last");
+
+        private final String value;
+
+        Keep(final String value) {
+            this.value = value;
+        }
+
+        /** Returns the mode for an argument value, or empty if the value 
names no mode. */
+        public static Optional<Keep> fromValue(final String value) {
+            return Arrays.stream(values()).filter(keep -> 
keep.value.equals(value)).findFirst();
+        }
+    }
+
+    /** Returns the {@code keep} argument, or {@link Keep#FIRST} when it is 
omitted. */
+    public static Keep keep(final CallContext callContext, final int argPos) {
+        return callContext
+                .getArgumentValue(argPos, String.class)
+                .map(
+                        value ->
+                                Keep.fromValue(value)
+                                        .orElseThrow(
+                                                () ->
+                                                        new 
IllegalStateException(
+                                                                "Validated 
keep argument expected.")))
+                .orElse(Keep.FIRST);
+    }
+
+    /**
+     * Returns the positions of the {@code sequence_by} columns, in the listed 
order, within the
+     * output row without the PARTITION BY columns.
+     */
+    public static int[] sequenceByOutputIndices(
+            final CallContext callContext, final TableSemantics 
tableSemantics, final int argPos) {
+        final List<String> fieldNames = 
DataType.getFieldNames(tableSemantics.dataType());
+        final List<Integer> outputIndices =
+                
Arrays.stream(ChangelogTypeStrategyUtils.computeOutputIndices(tableSemantics))
+                        .boxed()
+                        .collect(Collectors.toList());

Review Comment:
   i guess it will be slow with growing amount of indexes
   why don't we use map here?



-- 
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]

Reply via email to