wuchong commented on code in PR #20413:
URL: https://github.com/apache/flink/pull/20413#discussion_r938805740
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java:
##########
@@ -1121,6 +1122,35 @@ public void testSetCommand() throws Exception {
assertThat(result.toString()).isEqualTo(String.format("[+I[%s]]",
path));
}
+ @Test
+ public void testAddCommand() {
+ TableEnvironmentInternal tableEnvInternal = (TableEnvironmentInternal)
tableEnv;
+ Parser parser = tableEnvInternal.getParser();
+
+ // test add jar
+ Operation operation = parser.parse("add jar test.jar").get(0);
+ assertThat(operation).isInstanceOf(AddJarOperation.class);
+ assertThat(((AddJarOperation)
operation).getPath()).isEqualTo("test.jar");
+ // test add jar with variable substitute
+ operation = parser.parse("add jar
\"${hiveconf:common-key}.jar\"").get(0);
+ assertThat(operation).isInstanceOf(AddJarOperation.class);
+ assertThat(((AddJarOperation)
operation).getPath()).isEqualTo("\"common-val.jar\"");
Review Comment:
Why use double quotes here? IIUC, this is invalid in ADD JAR command?
##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java:
##########
@@ -306,6 +313,20 @@ private String substituteVariables(HiveConf conf, String
statement) {
return new VariableSubstitution(() -> hiveVariables).substitute(conf,
statement);
}
+ private Operation processAddCmd(HiveConf hiveConf, String command) {
+ command = new VariableSubstitution(() ->
hiveVariables).substitute(hiveConf, command);
+ String[] tokens = command.split("\\s+");
+ if (tokens.length != 2
+ || SessionState.find_resource_type(tokens[0]) !=
SessionState.ResourceType.JAR) {
+ throw new UnsupportedOperationException(
+ "Only support add one jar in one single statement. Usage:
add "
Review Comment:
```suggestion
"Only support add one jar in one single statement.
Usage: ADD "
```
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java:
##########
@@ -1121,6 +1122,35 @@ public void testSetCommand() throws Exception {
assertThat(result.toString()).isEqualTo(String.format("[+I[%s]]",
path));
}
+ @Test
+ public void testAddCommand() {
+ TableEnvironmentInternal tableEnvInternal = (TableEnvironmentInternal)
tableEnv;
+ Parser parser = tableEnvInternal.getParser();
+
+ // test add jar
+ Operation operation = parser.parse("add jar test.jar").get(0);
+ assertThat(operation).isInstanceOf(AddJarOperation.class);
+ assertThat(((AddJarOperation)
operation).getPath()).isEqualTo("test.jar");
+ // test add jar with variable substitute
+ operation = parser.parse("add jar
\"${hiveconf:common-key}.jar\"").get(0);
+ assertThat(operation).isInstanceOf(AddJarOperation.class);
+ assertThat(((AddJarOperation)
operation).getPath()).isEqualTo("\"common-val.jar\"");
+
+ // test unsupported add command
+ assertThatThrownBy(() -> tableEnv.executeSql("add jar t1.jar t2.jar"))
+ .isInstanceOf(UnsupportedOperationException.class)
+ .hasMessage(
+ "Only support add one jar in one single statement.
Usage: add JAR <value>");
+ assertThatThrownBy(() -> tableEnv.executeSql("add File t1.txt"))
+ .isInstanceOf(UnsupportedOperationException.class)
+ .hasMessage(
+ "Only support add one jar in one single statement.
Usage: add JAR <value>");
+ assertThatThrownBy(() -> tableEnv.executeSql("add Archive t1.tgz"))
Review Comment:
throw a specific exception for the ADD FILE and ADD ARCHIVE is not supported
yet?
##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java:
##########
@@ -306,6 +313,20 @@ private String substituteVariables(HiveConf conf, String
statement) {
return new VariableSubstitution(() -> hiveVariables).substitute(conf,
statement);
}
+ private Operation processAddCmd(HiveConf hiveConf, String command) {
Review Comment:
Replace the command using `substituteVariables(..)` before this method? So
we don't need to pass `hiveConf` into this method.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]