wuchong commented on a change in pull request #8203: 
[Flink-12208][table-planner-blink] Support translation from StreamExecSort / 
TemporalSort / SortLimit/ Limit to StreamTransformation.
URL: https://github.com/apache/flink/pull/8203#discussion_r277502857
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/stream/StreamExecSort.scala
 ##########
 @@ -75,4 +87,47 @@ class StreamExecSort(
       .item("orderBy", RelExplainUtil.collationToString(sortCollation, 
getRowType))
   }
 
+  //~ ExecNode methods 
-----------------------------------------------------------
+
+  /**
+    * Returns an array of this node's inputs. If there are no inputs,
+    * returns an empty list, not null.
+    *
+    * @return Array of this node's inputs
+    */
+  override def getInputNodes: util.List[ExecNode[StreamTableEnvironment, _]] = 
{
+    List(getInput.asInstanceOf[ExecNode[StreamTableEnvironment, _]])
+  }
+
+  /**
+    * Internal method, translates this node into a Flink operator.
+    *
+    * @param tableEnv The [[StreamTableEnvironment]] of the translated Table.
+    */
+  override protected def translateToPlanInternal(
+      tableEnv: StreamTableEnvironment): StreamTransformation[BaseRow] = {
+    val conf = tableEnv.getConfig
+    if 
(!conf.getConf.getBoolean(TableConfigOptions.SQL_EXEC_SORT_NON_TEMPORAL_ENABLED))
 {
+      throw new TableException("Sort on a non-time-attribute field is not 
supported.")
+    }
+
+    val inputType = FlinkTypeFactory.toInternalRowType(getInput.getRowType)
+    val (keys, orders, nullsIsLast) = 
SortUtil.getKeysAndOrders(sortCollation.getFieldCollations)
+    // sort code gen
+    val keyTypes = keys.map(inputType.getTypeAt)
+    val rowComparator = ComparatorCodeGenerator.gen(conf, 
"StreamExecSortComparator",
+      keys, keyTypes, orders, nullsIsLast)
+    val sortOperator = new StreamSortOperator(inputType.toTypeInfo, 
rowComparator)
+    val input = getInputNodes.get(0).translateToPlan(tableEnv)
+      .asInstanceOf[StreamTransformation[BaseRow]]
+    val outputRowTypeInfo = 
FlinkTypeFactory.toInternalRowType(getRowType).toTypeInfo
+    // sets parallelism to 1 since StreamExecSort could only work in global 
mode.
+    new OneInputTransformation(
+      input,
+      s"Sort(${RelExplainUtil.collationToString(sortCollation, getRowType)})",
+      sortOperator,
+      outputRowTypeInfo,
+      1)
 
 Review comment:
   Force maxParallelism to `1` too? 
   
   `ret.setMaxParallelism(1)`

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