-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-28096][hive] Hive dialect support set variables #20000
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. I left some comments.
...rc/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSetProcessor.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSetProcessor.java
Outdated
Show resolved
Hide resolved
...-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java
Outdated
Show resolved
Hide resolved
...-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java
Outdated
Show resolved
Hide resolved
...-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java
Outdated
Show resolved
Hide resolved
...-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java
Outdated
Show resolved
Hide resolved
...-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParser.java
Outdated
Show resolved
Hide resolved
...s/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java
Show resolved
Hide resolved
if (!key.equals("silent")) { | ||
HiveParserSetProcessor.setVariable(hiveConf, hiveVariables, key, value); | ||
} | ||
return new NopOperation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd better to also set the config into table config because users may set some optimization options here.
import static org.apache.hadoop.hive.conf.SystemVariables.METACONF_PREFIX; | ||
import static org.apache.hadoop.hive.conf.SystemVariables.SYSTEM_PREFIX; | ||
|
||
/** Counterpart of hive's {@link org.apache.hadoop.hive.ql.processors.SetProcessor}. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I made a mistake. It's better use {@link SetProcessor}
The compile phase is failed. |
95d6432
to
432037b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for update. I left some comments. It looks good in general.
@@ -82,6 +88,7 @@ public class HiveParser extends ParserImpl { | |||
private static final Method getCurrentTSMethod = | |||
HiveReflectionUtils.tryGetMethod( | |||
SessionState.class, "getQueryCurrentTimestamp", new Class[0]); | |||
private static final String HIVE_VARIABLE_PREFIX = "__hive.variable__"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to move to HiveInternalOptions and describe this in the descriptions.
I think it's better to use __hive.variables__
? WDYT?
processSetCmd( | ||
hiveConf, statement.substring(commandTokens[0].length()).trim())); | ||
} else { | ||
throw new UnsupportedOperationException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It's better to tell users what is unsupported.
if (part[0].equals("silent")) { | ||
throw new UnsupportedOperationException("Unsupported command 'set silent'."); | ||
} | ||
HiveSetProcessor.setVariable(hiveConf, tableConfig, hiveVariables, part[0], part[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It better to let SessionContext to do the set.
String option = HiveSetProcessor.getVariable(hiveConf, hiveVariables, nwcmd); | ||
// for the variable | ||
throw new UnsupportedOperationException("Unsupported SET command which misses '='."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? I think we can remove it.
String options = | ||
HiveSetProcessor.dumpOptions( | ||
hiveConf.getChangedProperties(), hiveConf, hiveVariables); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove if we don't support this.
hiveConf.verifyAndSet(key, value); | ||
} | ||
|
||
public static String getVariable( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to support to show variables using SET
? If not, I think we can add this when needs.
assertThat(hiveCatalog.getHiveConf().get("yyy")).isEqualTo("5"); | ||
// test set hivevar: | ||
tableEnv.executeSql("set hivevar:a=1"); | ||
tableEnv.executeSql("set hiveconf:zzz=${hivevar:a}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should renew a sql parser to test whether the test config memorizes hive-vars.
For example,
tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
tableEnv.executeSql("show tables");
tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
79fbc1e
to
cbb3ce2
Compare
tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT); | ||
tableEnv.executeSql("show tables"); | ||
tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE); | ||
tableEnv.executeSql("set hiveconf:zzz1=${hivevar:a}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
set
statement to switch dialect? - Set a flink config under hive dialect and check it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1: We maynot use set
statement to switch dialect directly for the SetOperation
is executed in SqlClient.
2: The Flink's SetOperation
will be executed in SqlClient , so we can't set it in tableEnv. But the test set.q in flink-sql-client has covered the case that set flink config in HiveDialect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Do you have other concerns? @fsk119
What is the purpose of the change
To make Hive dialect support set variables.
Brief change log
Verifying this change
UT
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: noDocumentation