You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/04/24 12:52:11 UTC

[GitHub] [flink] WeiZhong94 opened a new pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

WeiZhong94 opened a new pull request #11901:
URL: https://github.com/apache/flink/pull/11901


   ## What is the purpose of the change
   
   *This pull request support registering Python UDF in SQL Client.*
   
   
   ## Brief change log
   
     - *Let the Sql client environment file parser module support "from: python".*
     - *Add `flink-python` jar to the classpath of SQL Client.*
     - *If the environment file contains python UDF, add the `flink-python` jar to user jars.*
   
   
   ## Verifying this change
   
   This change is already covered by existing tests, such as *ExecutionContextTest*.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes)
     - If yes, how is the feature documented? (docs)
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/161830922) Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162159222",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162055839) Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264) 
   * f9050771eda446e3b745615362a175f54f6e7f9e Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/162159222) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] WeiZhong94 commented on a change in pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
WeiZhong94 commented on a change in pull request #11901:
URL: https://github.com/apache/flink/pull/11901#discussion_r415266948



##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -517,6 +526,7 @@ private void createTableEnvironment(
 			CatalogManager catalogManager,
 			ModuleManager moduleManager,
 			FunctionCatalog functionCatalog) {
+		config.addConfiguration(flinkConfig);

Review comment:
       The translation of Python physical nodes need to read the Python configurations in `flinkConfig`.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] WeiZhong94 commented on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
WeiZhong94 commented on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-619518917


   @dianfu Thanks for your review! I have addressed your comments in the latest commit.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] dianfu commented on a change in pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11901:
URL: https://github.com/apache/flink/pull/11901#discussion_r415228631



##########
File path: flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/ExecutionContextTest.java
##########
@@ -198,6 +201,22 @@ public void testFunctions() throws Exception {
 		assertArrayEquals(expected, actual);
 	}
 
+	@Test
+	public void testPythonFunction() throws Exception {

Review comment:
       The test case could be improved as following:
   ```
   PowerMockito.stub(PowerMockito.method(PythonFunctionFactory.class, "getPythonFunctionFactory", ReadableConfig.class)).toReturn(
   			(PythonFunctionFactory) (moduleName, objectName) -> new PythonScalarFunction(null, null, null, null, null, false, null));
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/161830922) Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162055839) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] WeiZhong94 commented on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
WeiZhong94 commented on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-619743899


   @dianfu Thanks for your review! I have addressed your comments.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "CANCELED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162159222",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162168156",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * f9050771eda446e3b745615362a175f54f6e7f9e Travis: [CANCELED](https://travis-ci.com/github/flink-ci/flink/builds/162159222) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289) 
   * 058bc95abecb6a4e9543c6a9912639f46b18184f Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/162168156) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] dianfu commented on a change in pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11901:
URL: https://github.com/apache/flink/pull/11901#discussion_r415188144



##########
File path: flink-table/flink-sql-client/bin/sql-client.sh
##########
@@ -58,18 +58,19 @@ log_setting=(-Dlog.file="$log" -Dlog4j.configuration=file:"$FLINK_CONF_DIR"/log4
 
 # get path of jar in /opt if it exist
 FLINK_SQL_CLIENT_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-sql-client.*.jar")
+FLINK_PYTHON_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-python.*.jar")

Review comment:
       I think we should check if the flink python jar already exists in the classpath just like how we did for the jar offlink-sql-client.

##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/descriptors/PythonFunctionValidator.java
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.descriptors;
+
+/**
+ * Validator of python function.
+ */
+public class PythonFunctionValidator implements DescriptorValidator {

Review comment:
       Annotate as `@Internal`

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +710,32 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {
+		return environment.getFunctions().values().stream().anyMatch(f ->
+			FunctionDescriptorValidator.FROM_VALUE_PYTHON.equals(
+				f.getDescriptor().toProperties().get(FunctionDescriptorValidator.FROM)));
+	}
+
+	private List<URL> addPythonFunctionDependency(List<URL> dependencies) {
+		List<URL> newDependencies = new ArrayList<>(dependencies);
+		URL location = PythonFunctionRunner.class.getProtectionDomain().getCodeSource().getLocation();

Review comment:
       Can we use reflection and then this module will not depend on flink-python any more?

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +710,32 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {
+		return environment.getFunctions().values().stream().anyMatch(f ->
+			FunctionDescriptorValidator.FROM_VALUE_PYTHON.equals(
+				f.getDescriptor().toProperties().get(FunctionDescriptorValidator.FROM)));
+	}
+
+	private List<URL> addPythonFunctionDependency(List<URL> dependencies) {

Review comment:
       rename to addPythonDependency

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -517,6 +526,7 @@ private void createTableEnvironment(
 			CatalogManager catalogManager,
 			ModuleManager moduleManager,
 			FunctionCatalog functionCatalog) {
+		config.addConfiguration(flinkConfig);

Review comment:
       What's the aim of this change?

##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/FunctionService.java
##########
@@ -87,11 +108,37 @@ public static UserDefinedFunction createFunction(
 			new FunctionDescriptorValidator().validate(properties);
 		}
 
-		// instantiate
-		Object instance = generateInstance(
-				HierarchyDescriptorValidator.EMPTY_PREFIX,
-				properties,
-				classLoader);
+		Object instance;
+		switch (properties.getString(FunctionDescriptorValidator.FROM)) {
+			case FunctionDescriptorValidator.FROM_VALUE_CLASS:
+				// instantiate
+				instance = generateInstance(
+					HierarchyDescriptorValidator.EMPTY_PREFIX,
+					properties,
+					classLoader);
+				break;
+			case FunctionDescriptorValidator.FROM_VALUE_PYTHON:
+				String fullyQualifiedName = properties.getString(PythonFunctionValidator.FULLY_QUALIFIED_NAME);
+				try {
+					Class pythonFunctionFactory = Class.forName(

Review comment:
       Many code here is duplicate with `FunctionDefinitionUtil.createPythonFunctionDefinition`. Could we abstract it a little to remove the duplication?

##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/descriptors/FunctionDescriptor.java
##########
@@ -29,13 +29,22 @@
 public class FunctionDescriptor implements Descriptor {
 	private String from;
 	private ClassInstance classInstance;
+	private String fullyQualifiedName;
 
 	/**
 	 * Creates a function from a class description.
 	 */
 	public FunctionDescriptor fromClass(ClassInstance classType) {
 		from = FunctionDescriptorValidator.FROM_VALUE_CLASS;
 		this.classInstance = classType;
+		this.fullyQualifiedName = null;
+		return this;
+	}
+
+	public FunctionDescriptor fromPython(String fullyQualifiedName) {
+		from = FunctionDescriptorValidator.FROM_VALUE_PYTHON;

Review comment:
       Add precondition check that `classInstance` should be null?

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +710,32 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {
+		return environment.getFunctions().values().stream().anyMatch(f ->
+			FunctionDescriptorValidator.FROM_VALUE_PYTHON.equals(
+				f.getDescriptor().toProperties().get(FunctionDescriptorValidator.FROM)));
+	}
+
+	private List<URL> addPythonFunctionDependency(List<URL> dependencies) {
+		List<URL> newDependencies = new ArrayList<>(dependencies);
+		URL location = PythonFunctionRunner.class.getProtectionDomain().getCodeSource().getLocation();
+		try {
+			if (Paths.get(location.toURI()).toFile().isFile()) {
+				newDependencies.add(location);
+			} else {
+				LOG.warn(
+					"Python UDF detected but flink-python jar not found. " +
+						"If you starts SQL-Client via `sql-client.sh`, " +
+						"please add the flink-python jar via `-j` command option manually.");
+			}
+		} catch (URISyntaxException e) {
+			LOG.warn("Python UDF detected but flink-python jar not found. " +

Review comment:
       Could we avoid this duplication lines?

##########
File path: flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/ExecutionContextTest.java
##########
@@ -198,6 +201,22 @@ public void testFunctions() throws Exception {
 		assertArrayEquals(expected, actual);
 	}
 
+	@Test
+	public void testPythonFunction() throws Exception {

Review comment:
       The test case could be improved as following:
   ```
   PowerMockito.stub(PowerMockito.method(PythonFunctionFactory.class, "getPythonFunctionFactory", ReadableConfig.class)).toReturn(
   			(PythonFunctionFactory) (moduleName, objectName) -> new PythonScalarFunction(null, null, null, null, null, false, null));
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/161830922) Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202) 
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/162055839) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162159222",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162168156",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 058bc95abecb6a4e9543c6a9912639f46b18184f Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162168156) Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162159222",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162055839) Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264) 
   * f9050771eda446e3b745615362a175f54f6e7f9e Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/162159222) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289) 
   * 058bc95abecb6a4e9543c6a9912639f46b18184f UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162159222",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162168156",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 058bc95abecb6a4e9543c6a9912639f46b18184f Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162168156) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618991436


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 (Fri Apr 24 12:55:20 UTC 2020)
   
   **Warnings:**
    * **1 pom.xml files were touched**: Check for build and licensing issues.
    * No documentation files were touched! Remember to keep the Flink docs up to date!
    * **This pull request references an unassigned [Jira ticket](https://issues.apache.org/jira/browse/FLINK-16971).** According to the [code contribution guide](https://flink.apache.org/contributing/contribute-code.html), tickets need to be assigned before starting with the implementation work.
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162055839) Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264) 
   * f9050771eda446e3b745615362a175f54f6e7f9e UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/161830922) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] dianfu commented on a change in pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11901:
URL: https://github.com/apache/flink/pull/11901#discussion_r415323127



##########
File path: flink-table/flink-sql-client/bin/sql-client.sh
##########
@@ -58,18 +58,25 @@ log_setting=(-Dlog.file="$log" -Dlog4j.configuration=file:"$FLINK_CONF_DIR"/log4
 
 # get path of jar in /opt if it exist
 FLINK_SQL_CLIENT_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-sql-client.*.jar")
+FLINK_PYTHON_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-python.*.jar")
 
 # check if SQL client is already in classpath and must not be shipped manually
-if [[ "$CC_CLASSPATH" =~ .*flink-sql-client.*.jar ]]; then
+if [[ "$CC_CLASSPATH" =~ .*flink-sql-client.*.jar && "$CC_CLASSPATH" =~ .*flink-python.*.jar ]]; then
 
     # start client without jar
     exec $JAVA_RUN $JVM_ARGS "${log_setting[@]}" -classpath "`manglePathList "$CC_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.table.client.SqlClient "$@"
 
 # check if SQL client jar is in /opt
 elif [ -n "$FLINK_SQL_CLIENT_JAR" ]; then

Review comment:
       In this case, maybe it's because `flink-sql-client` is in the classpath and `flink-python` is not.

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +709,33 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {
+		return environment.getFunctions().values().stream().anyMatch(f ->
+			FunctionDescriptorValidator.FROM_VALUE_PYTHON.equals(
+				f.getDescriptor().toProperties().get(FunctionDescriptorValidator.FROM)));
+	}
+
+	private List<URL> addPythonDependency(List<URL> dependencies) {
+		List<URL> newDependencies = new ArrayList<>(dependencies);
+		try {
+			URL location = Class.forName(
+				"org.apache.flink.python.PythonFunctionRunner",
+				false,
+				Thread.currentThread().getContextClassLoader())
+				.getProtectionDomain().getCodeSource().getLocation();
+			if (Paths.get(location.toURI()).toFile().isFile()) {
+				newDependencies.add(location);
+			} else {
+				throw new FlinkException("flink-python module detected but is not a jar file: " + location + ".");

Review comment:
       Should we use SqlExecutionException?

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +709,33 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {
+		return environment.getFunctions().values().stream().anyMatch(f ->
+			FunctionDescriptorValidator.FROM_VALUE_PYTHON.equals(
+				f.getDescriptor().toProperties().get(FunctionDescriptorValidator.FROM)));
+	}
+
+	private List<URL> addPythonDependency(List<URL> dependencies) {
+		List<URL> newDependencies = new ArrayList<>(dependencies);
+		try {
+			URL location = Class.forName(
+				"org.apache.flink.python.PythonFunctionRunner",
+				false,
+				Thread.currentThread().getContextClassLoader())
+				.getProtectionDomain().getCodeSource().getLocation();
+			if (Paths.get(location.toURI()).toFile().isFile()) {
+				newDependencies.add(location);
+			} else {
+				throw new FlinkException("flink-python module detected but is not a jar file: " + location + ".");
+			}
+		} catch (URISyntaxException | ClassNotFoundException | FlinkException e) {
+			LOG.warn("Python UDF detected but flink-python jar not found. " +

Review comment:
       Should we throw exception in this case?

##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/FunctionService.java
##########
@@ -87,11 +108,22 @@ public static UserDefinedFunction createFunction(
 			new FunctionDescriptorValidator().validate(properties);
 		}
 
-		// instantiate
-		Object instance = generateInstance(
-				HierarchyDescriptorValidator.EMPTY_PREFIX,
-				properties,
-				classLoader);
+		Object instance;
+		switch (properties.getString(FunctionDescriptorValidator.FROM)) {
+			case FunctionDescriptorValidator.FROM_VALUE_CLASS:
+				// instantiate
+				instance = generateInstance(
+					HierarchyDescriptorValidator.EMPTY_PREFIX,
+					properties,
+					classLoader);
+				break;
+			case FunctionDescriptorValidator.FROM_VALUE_PYTHON:
+				String fullyQualifiedName = properties.getString(PythonFunctionValidator.FULLY_QUALIFIED_NAME);
+				instance = PythonFunctionUtils.getPythonFunction(fullyQualifiedName, config);
+				break;
+			default:
+				throw new ValidationException("Unsupported function descriptor: " + properties);

Review comment:
       Use `String.format`

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +709,33 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {
+		return environment.getFunctions().values().stream().anyMatch(f ->
+			FunctionDescriptorValidator.FROM_VALUE_PYTHON.equals(
+				f.getDescriptor().toProperties().get(FunctionDescriptorValidator.FROM)));
+	}
+
+	private List<URL> addPythonDependency(List<URL> dependencies) {
+		List<URL> newDependencies = new ArrayList<>(dependencies);
+		try {
+			URL location = Class.forName(
+				"org.apache.flink.python.PythonFunctionRunner",
+				false,
+				Thread.currentThread().getContextClassLoader())
+				.getProtectionDomain().getCodeSource().getLocation();
+			if (Paths.get(location.toURI()).toFile().isFile()) {
+				newDependencies.add(location);
+			} else {
+				throw new FlinkException("flink-python module detected but is not a jar file: " + location + ".");

Review comment:
       Use `String.format` instead of +

##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/python/utils/PythonFunctionUtils.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.functions.python.utils;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.functions.python.PythonFunction;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Utilities for creating PythonFunction.
+ */
+@Internal
+public enum  PythonFunctionUtils {

Review comment:
       extra empty space before PythonFunctionUtils

##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/FunctionService.java
##########
@@ -87,11 +108,22 @@ public static UserDefinedFunction createFunction(
 			new FunctionDescriptorValidator().validate(properties);
 		}
 
-		// instantiate
-		Object instance = generateInstance(
-				HierarchyDescriptorValidator.EMPTY_PREFIX,
-				properties,
-				classLoader);
+		Object instance;
+		switch (properties.getString(FunctionDescriptorValidator.FROM)) {
+			case FunctionDescriptorValidator.FROM_VALUE_CLASS:
+				// instantiate
+				instance = generateInstance(
+					HierarchyDescriptorValidator.EMPTY_PREFIX,
+					properties,
+					classLoader);
+				break;
+			case FunctionDescriptorValidator.FROM_VALUE_PYTHON:
+				String fullyQualifiedName = properties.getString(PythonFunctionValidator.FULLY_QUALIFIED_NAME);
+				instance = PythonFunctionUtils.getPythonFunction(fullyQualifiedName, config);
+				break;
+			default:
+				throw new ValidationException("Unsupported function descriptor: " + properties);

Review comment:
       There is no need to make the `properties` in the exception. Just `properties.getString(FunctionDescriptorValidator.FROM)` is enough? What do you think?

##########
File path: flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -696,6 +709,33 @@ private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
 		}
 	}
 
+	private boolean hasPythonFunction(Environment environment) {

Review comment:
       minor: containsPythonFunction?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162055839) Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=264",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162055839",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=289",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162159222",
       "triggerID" : "f9050771eda446e3b745615362a175f54f6e7f9e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     }, {
       "hash" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/162168156",
       "triggerID" : "058bc95abecb6a4e9543c6a9912639f46b18184f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 058bc95abecb6a4e9543c6a9912639f46b18184f Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/162168156) Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=295) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #11901: [FLINK-16971][python][sql-client] Support Python UDF in SQL Client.

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #11901:
URL: https://github.com/apache/flink/pull/11901#issuecomment-618997437


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/161830922",
       "triggerID" : "d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "3aa5a671f3ffbc8d1729d95700b3b37bc3e15086",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d87aa0d87d7120cb4b193c99fa853eaa5e5bc3f6 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/161830922) Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=202) 
   * 3aa5a671f3ffbc8d1729d95700b3b37bc3e15086 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org