LadyForest commented on code in PR #24510:
URL: https://github.com/apache/flink/pull/24510#discussion_r1554809993


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/LogicalUnnestRule.scala:
##########
@@ -20,12 +20,13 @@ package org.apache.flink.table.planner.plan.rules.logical
 import org.apache.flink.table.functions.BuiltInFunctionDefinitions
 import org.apache.flink.table.planner.calcite.FlinkTypeFactory
 import org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction
+import org.apache.flink.table.planner.plan.utils.UnnestConversionUtil
 import org.apache.flink.table.planner.utils.ShortcutUtils
 import org.apache.flink.table.runtime.functions.table.UnnestRowsFunction
 import org.apache.flink.table.types.logical.utils.LogicalTypeUtils.toRowType
 
 import com.google.common.collect.ImmutableList
-import org.apache.calcite.plan.{RelOptRule, RelOptRuleCall, RelOptRuleOperand}
+import org.apache.calcite.plan.{RelOptCluster, RelOptRule, RelOptRuleCall, 
RelOptRuleOperand, RelTraitSet}

Review Comment:
   Please remove the following unused import since a base trait has been 
extracted
   
   ```scalca
   import org.apache.flink.table.functions.BuiltInFunctionDefinitions
   import org.apache.flink.table.planner.calcite.FlinkTypeFactory
   import org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction
   import org.apache.flink.table.planner.utils.ShortcutUtils
   import org.apache.flink.table.runtime.functions.table.UnnestRowsFunction
   import org.apache.flink.table.types.logical.utils.LogicalTypeUtils.toRowType
   import org.apache.calcite.plan.hep.HepRelVertex
   import org.apache.calcite.rel.RelNode
   import java.util.Collections
   import org.apache.calcite.plan.{RelOptCluster, RelTraitSet}
   ```



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/utils/UnnestConversionUtil.scala:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.planner.plan.utils
+
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction
+import org.apache.flink.table.planner.utils.ShortcutUtils
+import org.apache.flink.table.runtime.functions.table.UnnestRowsFunction
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils.toRowType
+
+import com.google.common.collect.ImmutableList
+import org.apache.calcite.plan.{RelOptCluster, RelTraitSet}
+import org.apache.calcite.plan.hep.HepRelVertex
+import org.apache.calcite.rel.RelNode
+import org.apache.calcite.rel.core.Uncollect
+import org.apache.calcite.rel.logical._
+
+import java.util.Collections
+
+/** Unnest conversion utils. */
+trait UnnestConversionUtil {

Review Comment:
   Nit: Naming a trait with "Util" indicates a more procedural or imperative 
style rather than a pure functional or object-oriented approach. What about 
`UnnestConverter`?



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/utils/UnnestConversionUtil.scala:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.planner.plan.utils
+
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction
+import org.apache.flink.table.planner.utils.ShortcutUtils
+import org.apache.flink.table.runtime.functions.table.UnnestRowsFunction
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils.toRowType
+
+import com.google.common.collect.ImmutableList
+import org.apache.calcite.plan.{RelOptCluster, RelTraitSet}

Review Comment:
   Please remove unused import



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/LogicalUnnestRule.scala:
##########
@@ -73,59 +75,13 @@ class LogicalUnnestRule(operand: RelOptRuleOperand, 
description: String)
     val outer = getRel(correlate.getLeft)
     val array = getRel(correlate.getRight)
 
-    def convert(relNode: RelNode): RelNode = {
-      relNode match {
-        case rs: HepRelVertex =>
-          convert(getRel(rs))
-
-        case f: LogicalProject =>
-          f.copy(f.getTraitSet, ImmutableList.of(convert(getRel(f.getInput))))
-
-        case f: LogicalFilter =>
-          f.copy(f.getTraitSet, ImmutableList.of(convert(getRel(f.getInput))))
-
-        case uc: Uncollect =>
-          // convert Uncollect into TableFunctionScan
-          val cluster = correlate.getCluster
-          val typeFactory = ShortcutUtils.unwrapTypeFactory(cluster)
-          val relDataType = uc.getInput.getRowType.getFieldList.get(0).getValue
-          val logicalType = FlinkTypeFactory.toLogicalType(relDataType)
-
-          val sqlFunction =
-            BridgingSqlFunction.of(cluster, 
BuiltInFunctionDefinitions.INTERNAL_UNNEST_ROWS)
-
-          val rexCall = cluster.getRexBuilder.makeCall(
-            typeFactory.createFieldTypeFromLogicalType(
-              toRowType(UnnestRowsFunction.getUnnestedType(logicalType))),
-            sqlFunction,
-            getRel(uc.getInput).asInstanceOf[LogicalProject].getProjects
-          )
-
-          new LogicalTableFunctionScan(
-            cluster,
-            correlate.getTraitSet,
-            Collections.emptyList(),
-            rexCall,
-            null,
-            rexCall.getType,
-            null)
-      }
-    }
-
     // convert unnest into table function scan
-    val tableFunctionScan = convert(array)
+    val tableFunctionScan = convert(array, correlate.getCluster, 
correlate.getTraitSet)

Review Comment:
   Nit: I think we can remain the signature of `convert` unchanged. WDYT?



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/UncollectToTableFunctionScanRule.scala:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.planner.plan.rules.logical
+
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction
+import org.apache.flink.table.planner.plan.utils.UnnestConversionUtil
+import org.apache.flink.table.planner.utils.ShortcutUtils
+import org.apache.flink.table.runtime.functions.table.UnnestRowsFunction
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils.toRowType
+
+import com.google.common.collect.ImmutableList
+import org.apache.calcite.plan.{RelOptRule, RelOptRuleCall, RelOptRuleOperand}
+import org.apache.calcite.plan.RelOptRule._
+import org.apache.calcite.plan.hep.HepRelVertex
+import org.apache.calcite.rel.RelNode
+import org.apache.calcite.rel.core.Uncollect
+import org.apache.calcite.rel.logical._
+
+import java.util.Collections
+
+/** Planner rule that converts Uncollect values to TableFunctionScan. */

Review Comment:
   ```suggestion
   /**
    * Planner rule that converts [[Uncollect]] values to
    * [[org.apache.calcite.rel.core.TableFunctionScan]].
    */
   ```



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