KurtYoung commented on a change in pull request #8156: 
[FLINK-12168][table-planner-blink] Support e2e limit, sortLimit, rank, union in 
blink batch
URL: https://github.com/apache/flink/pull/8156#discussion_r275146297
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/batch/BatchExecRank.scala
 ##########
 @@ -103,4 +111,67 @@ class BatchExecRank(
     val costFactory = planner.getCostFactory.asInstanceOf[FlinkCostFactory]
     costFactory.makeCost(rowCount, cpuCost, 0, 0, memCost)
   }
+
+  override def getDamBehavior: DamBehavior = DamBehavior.PIPELINED
+
+  override def getInputNodes: util.List[ExecNode[BatchTableEnvironment, _]] =
+    List(getInput.asInstanceOf[ExecNode[BatchTableEnvironment, _]])
+
+  override def translateToPlanInternal(
+      tableEnv: BatchTableEnvironment): StreamTransformation[BaseRow] = {
+    val input = getInputNodes.get(0).translateToPlan(tableEnv)
+        .asInstanceOf[StreamTransformation[BaseRow]]
+    val outputType = FlinkTypeFactory.toInternalRowType(getRowType)
+    val partitionBySortingKeys = partitionKey.toArray
+    // The collation for the partition-by fields is inessential here, we only 
use the
+    // comparator to distinguish different groups.
+    // (order[is_asc], null_is_last)
+    val partitionBySortCollation = partitionBySortingKeys.map(_ => (true, 
true))
+
+    val inputRowType = FlinkTypeFactory.toInternalRowType(getInput.getRowType)
+    val partitionByCodeGen = new SortCodeGenerator(
+      tableEnv.getConfig,
+      partitionBySortingKeys,
+      partitionBySortingKeys.map(inputRowType.getTypeAt),
+      partitionBySortCollation.map(_._1),
+      partitionBySortCollation.map(_._2))
+
+
+    // The collation for the order-by fields is inessential here, we only use 
the
+    // comparator to distinguish order-by fields change.
+    // (order[is_asc], null_is_last)
+    val orderByCollation = orderKey.getFieldCollations.map(_ => (true, 
true)).toArray
+    val orderByKeys = orderKey.getFieldCollations.map(_.getFieldIndex).toArray
+
+    val orderBySortCodeGen = new SortCodeGenerator(
+      tableEnv.getConfig,
+      orderByKeys,
+      orderByKeys.map(inputRowType.getTypeAt),
+      orderByCollation.map(_._1),
+      orderByCollation.map(_._2))
+
+
+    //operator needn't cache data
+    val operator = new RankOperator(
+      partitionByCodeGen.generateRecordComparator("PartitionByComparator"),
 
 Review comment:
   Looks like we need a dedicated RecordComparatorCodegen, always codegen 
through SortCodeGenerator seems too heavy for this.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to