beyond1920 commented on a change in pull request #8035:
[FLINK-11975][table-planner-blink] Support to run a sql query : 'SELECT * FROM
(VALUES (1, 2, 3)) T(a, b, c)'
URL: https://github.com/apache/flink/pull/8035#discussion_r268554887
##########
File path:
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/batch/BatchExecSink.scala
##########
@@ -36,10 +46,99 @@ class BatchExecSink[T](
sink: TableSink[T],
sinkName: String)
extends Sink(cluster, traitSet, inputRel, sink, sinkName)
- with BatchPhysicalRel {
+ with BatchPhysicalRel
+ with BatchExecNode[Any] {
override def copy(traitSet: RelTraitSet, inputs: util.List[RelNode]):
RelNode = {
new BatchExecSink(cluster, traitSet, inputs.get(0), sink, sinkName)
}
+ /**
+ * Returns [[DamBehavior]] of this node.
+ */
+ override def getDamBehavior: DamBehavior = DamBehavior.PIPELINED
+
+ /**
+ * 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[BatchTableEnvironment, _]] = {
+ List(getInput.asInstanceOf[ExecNode[BatchTableEnvironment, _]])
+ }
+
+ /**
+ * Internal method, translates this node into a Flink operator.
+ *
+ * @param tableEnv The [[BatchTableEnvironment]] of the translated Table.
+ */
+ override protected def translateToPlanInternal(
+ tableEnv: BatchTableEnvironment): StreamTransformation[Any] = {
+ val convertTransformation = sink match {
+ case _: BatchTableSink[T] =>
+ translate(withChangeFlag = false, tableEnv)
+ case streamTableSink: DataStreamTableSink[T] =>
+ translate(withChangeFlag = streamTableSink.withChangeFlag, tableEnv)
+ case _ =>
+ throw new TableException("Only Support BatchTableSink or
BatchCompatibleStreamTableSink")
+ }
+ // In case of table to bounded stream through
BatchTableEnvironment#toBoundedStream, we insert a
+ // DataStreamTableSink then wrap it as a LogicalSink, there is no real
batch table sink, so
+ // we do not need to invoke TableSink#emitBoundedStream and set resource,
just a translation to
+ // StreamTransformation is ok.
+ val resultTransformation = if (sink.isInstanceOf[DataStreamTableSink[T]]) {
+ convertTransformation
+ } else {
+ val stream = new DataStream(tableEnv.streamEnv, convertTransformation)
+ emitBoundedStreamSink(stream, tableEnv).getTransformation
+ }
+ resultTransformation.asInstanceOf[StreamTransformation[Any]]
+ }
+
+ private def emitBoundedStreamSink(
+ boundedStream: DataStream[T],
+ tableEnv: BatchTableEnvironment): DataStreamSink[_] = {
+ val config = tableEnv.getConfig
+ sink match {
+ case sinkBatch: BatchTableSink[T] =>
+ sinkBatch.emitBoundedStream(boundedStream, config,
tableEnv.streamEnv.getConfig)
+
+ case _ => throw new TableException("BatchTableSink or
CompatibleStreamTableSink " +
+ "required to emit batch exec Table")
+ }
+ }
+
+ /**
+ * Translates a logical [[RelNode]] into a [[StreamTransformation]].
+ * Converts to target type if necessary.
+ *
+ * @return The [[StreamTransformation]] that corresponds to the translated
[[Table]].
+ */
+ private def translate(
Review comment:
done
----------------------------------------------------------------
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