sunjincheng121 commented on a change in pull request #8472:
[FLINK-12327][python] Adds support to submit Python Table API job in CliFrontend
URL: https://github.com/apache/flink/pull/8472#discussion_r286394165
##########
File path:
flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
##########
@@ -771,22 +774,32 @@ PackagedProgram buildProgram(ProgramOptions options)
throws FileNotFoundExceptio
String jarFilePath = options.getJarFilePath();
List<URL> classpaths = options.getClasspaths();
- if (jarFilePath == null) {
- throw new IllegalArgumentException("The program JAR
file was not specified.");
+ // the job is not a specified a jar file or a Python job.
+ if (!(options.getJarFilePath() != null || options.isPython())) {
+ throw new IllegalArgumentException("The program should
be specified a JAR file " +
+ "or a python file(or module)");
}
- File jarFile = new File(jarFilePath);
+ File jarFile = null;
+ // If the job is specified a jar file
+ if (options.getJarFilePath() != null) {
+ jarFile = new File(jarFilePath);
- // Check if JAR file exists
- if (!jarFile.exists()) {
- throw new FileNotFoundException("JAR file does not
exist: " + jarFile);
- }
- else if (!jarFile.isFile()) {
- throw new FileNotFoundException("JAR file is not a
file: " + jarFile);
+ // Check if JAR file exists
+ if (!jarFile.exists()) {
+ throw new FileNotFoundException("JAR file does
not exist: " + jarFile);
+ }
+ else if (!jarFile.isFile()) {
+ throw new FileNotFoundException("JAR file is
not a file: " + jarFile);
+ }
}
// Get assembler class
String entryPointClass = options.getEntryPointClassName();
+ // If the job is a python job, the entry point class is
PythonDriver.
+ if (entryPointClass == null && options.isPython()) {
+ entryPointClass = PythonDriver.class.getCanonicalName();
+ }
Review comment:
We can improve the code a bit, and reduce the check times such as
`options.isPython()`, `options.getJarFilePath() != null`, so, the example code
as follows:
```
File jarFile = null;
String entryPointClass;
if (!options.isPython()) {
// Java program should be specified a JAR file
if (options.getJarFilePath() == null) {
throw new IllegalArgumentException("Java
program should be specified a JAR file.");
}
// get assembler class
entryPointClass = options.getEntryPointClassName();
} else {
// the job is a python job, the entry point class is PythonDriver.
entryPointClass = PythonDriver.class.getCanonicalName();
}
if (options.getJarFilePath() == null) {
// the job is specified a jar file
jarFile = new File(jarFilePath);
// Check if JAR file exists
if (!jarFile.exists()) {
throw new FileNotFoundException("JAR
file does not exist: " + jarFile);
} else if (!jarFile.isFile()) {
throw new FileNotFoundException("JAR
file is not a file: " + jarFile);
}
}
}
```
What do you think?
----------------------------------------------------------------
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