You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/01/19 15:33:46 UTC

[GitHub] [flink] matriv commented on a change in pull request #18401: [FLINK-25677][table-planner] Update ReplicateRows to the new type inference

matriv commented on a change in pull request #18401:
URL: https://github.com/apache/flink/pull/18401#discussion_r787869160



##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/InternalReplicateRowsTypeStrategy.java
##########
@@ -0,0 +1,42 @@
+/*
+ * 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;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.inference.TypeStrategy;
+
+import java.util.Optional;
+
+/** Type strategy for {@link BuiltInFunctionDefinitions#INTERNAL_REPLICATE_ROWS}. */
+@Internal
+class InternalReplicateRowsTypeStrategy implements TypeStrategy {
+
+    @Override
+    public Optional<DataType> inferType(CallContext callContext) {
+        return Optional.of(
+                DataTypes.ROW(
+                        callContext.getArgumentDataTypes().stream()
+                                .skip(1)

Review comment:
       This is the noOfRows, right?

##########
File path: flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/utils/SetOpRewriteUtil.scala
##########
@@ -76,47 +69,24 @@ object SetOpRewriteUtil {
     * and the rest are the row fields.
     */
   def replicateRows(
-      builder: RelBuilder, outputType: RelDataType, fields: util.List[Integer]): RelNode = {
-    // construct LogicalTableFunctionScan
-    val logicalType = toLogicalRowType(outputType)
-    val fieldNames = outputType.getFieldNames.toSeq.toArray
-    val fieldTypes = logicalType.getChildren.map(fromLogicalTypeToTypeInfo).toArray
-    val tf = new ReplicateRows(fieldTypes)
-    val resultType = fromLegacyInfoToDataType(new RowTypeInfo(fieldTypes, fieldNames))
-    val function = new TypedFlinkTableFunction(tf, fieldNames, resultType)
-    val typeFactory = builder.getTypeFactory.asInstanceOf[FlinkTypeFactory]
-    val sqlFunction = new TableSqlFunction(
-      FunctionIdentifier.of(generateInlineFunctionName(tf)),
-      tf.toString,
-      tf,
-      resultType,
-      typeFactory,
-      function)
+      relBuilder: RelBuilder,
+      outputRelDataType: RelDataType,
+      fields: util.List[Integer]): RelNode = {
+    val cluster = relBuilder.getCluster
+
+    val sqlFunction = BridgingSqlFunction.of(
+      relBuilder.getCluster,
+      BuiltInFunctionDefinitions.INTERNAL_REPLICATE_ROWS)
 
-    val cluster = builder.peek().getCluster
-    // TODO use relBuilder.functionScan() once we remove TableSqlFunction
-    val scan = LogicalTableFunctionScan.create(
-      cluster,
-      new util.ArrayList[RelNode](),
-      builder.getRexBuilder
-        .makeCall(
-          function.getRowType(typeFactory),
-          sqlFunction,
-          builder.fields(Util.range(fields.size() + 1))),
-      function.getElementType(null),
-      UserDefinedFunctionUtils.buildRelDataType(
-        builder.getTypeFactory,
-        logicalType,
-        fieldNames,
-        fieldNames.indices.toArray),
-      null)
-    builder.push(scan)
+    relBuilder
+      .functionScan(sqlFunction, 0, relBuilder.fields(Util.range(fields.size() + 1)))

Review comment:
       Could you please explain this for my knowledge?




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org