[ 
https://issues.apache.org/jira/browse/FLINK-8868?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16585940#comment-16585940
 ] 

ASF GitHub Bot commented on FLINK-8868:
---------------------------------------

pnowojski commented on a change in pull request #6574: [FLINK-8868] [table] 
Support Table Function as Table Source for Stream Sql
URL: https://github.com/apache/flink/pull/6574#discussion_r211264292
 
 

 ##########
 File path: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/SourceFunctionCodeGenerator.scala
 ##########
 @@ -0,0 +1,101 @@
+/*
+ * 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.codegen
+
+import org.apache.flink.api.common.typeinfo.TypeInformation
+import org.apache.flink.api.java.typeutils.RowTypeInfo
+import org.apache.flink.configuration.Configuration
+import org.apache.flink.table.api.TableConfig
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction
+import 
org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext
+import org.apache.flink.table.codegen.CodeGenUtils.newName
+import org.apache.flink.util.Collector
+
+/**
+  * A code generator for generating Flink [[RichSourceFunction]].
+  *
+  * @param config configuration that determines runtime behavior
+  */
+class SourceFunctionCodeGenerator[T](
+  config: TableConfig,
+  outputType: TypeInformation[T])
+  extends CodeGenerator(config, false, new RowTypeInfo(), None, None) {
+
+  def generateSourceFunction(
+    name: String,
+    generatedFunc: GeneratedExpression)
+  : GeneratedFunction[RichSourceFunction[T], T] = {
+
+    val funcName = newName(name)
+    val collectorName = newName("TableFunctionSourceCollector")
+    val configName = classOf[Configuration].getCanonicalName
+
+    val functionCode =
+      s"""
+         |public class $funcName extends 
${classOf[RichSourceFunction[_]].getCanonicalName} {
+         |
+         |  ${reuseMemberCode()}
+         |
+         |  private ${collectorName} collectorProxy;
+         |
+         |  @Override
+         |  public void open(${configName} parameters) throws Exception {
+         |    ${reuseInitCode()}
+         |    ${reuseOpenCode()}
+         |    collectorProxy = new ${collectorName}();
+         |  }
+         |
+         |  @Override
+         |  public void close() throws Exception {
+         |    ${reuseCloseCode()}
+         |  }
+         |
+         |  void run(${classOf[SourceContext[_]].getCanonicalName} ctx) throws 
Exception {
+         |    collectorProxy.setContext(ctx);
+         |    ${generatedFunc.resultTerm}.setCollector(collectorProxy);
+         |    ${generatedFunc.code}
+         |  }
+         |
+         |  void cancel() {
+         |
+         |  }
+         |
+         |  class ${collectorName} implements 
${classOf[Collector[_]].getCanonicalName} {
 
 Review comment:
   Isn't this duplicated with 
`org.apache.flink.table.plan.nodes.CommonCorrelate#generateCollector`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Support Table Function as Table for Stream Sql
> ----------------------------------------------
>
>                 Key: FLINK-8868
>                 URL: https://issues.apache.org/jira/browse/FLINK-8868
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table API & SQL
>            Reporter: Ruidong Li
>            Assignee: Ruidong Li
>            Priority: Major
>              Labels: pull-request-available
>
> for stream sql:
> support SQL like:  SELECT * FROM Lateral TABLE(tf("a"))
> for batch sql:
> udtf might produce infinite recors, it need to be discussed



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to