Skip to content
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-13814][hive] HiveTableSink should strip quotes from partition … #9502

Closed
wants to merge 2 commits into from

Conversation

lirui-apache
Copy link
Contributor

…values

What is the purpose of the change

Strip quotes from partition value in order to get proper string values.

Brief change log

  • Strip quotes when we get partition spec from the planner
  • Added test to verify string partition values are properly handled
  • Migrated some existing tests to TableEnvHiveConnectorTest since the planner has now supported PartitionableTableSink

Verifying this change

Added test case

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? NA

@flinkbot
Copy link
Collaborator

flinkbot commented Aug 22, 2019

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 6901271 (Fri Aug 30 22:22:15 UTC 2019)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

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 for a full explanation of the review process.


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 Bot commands
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

@flinkbot
Copy link
Collaborator

flinkbot commented Aug 22, 2019

CI report:

@lirui-apache
Copy link
Contributor Author

cc @xuefuz @bowenli86 @zjuwangg

@@ -170,7 +171,7 @@ public void setStaticPartition(Map<String, String> partitionSpec) {
staticPartitionSpec = new LinkedHashMap<>();
for (String partitionCol : getPartitionFieldNames()) {
if (partitionSpec.containsKey(partitionCol)) {
staticPartitionSpec.put(partitionCol, partitionSpec.get(partitionCol));
staticPartitionSpec.put(partitionCol, PlanUtils.stripQuotes(partitionSpec.get(partitionCol)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, partitionSpec is a map of strings, and the value should probably have been unquoted before getting here. I'm wondering if the fix should be at a lower level than here. Otherwise, similar fix will be needed wherever such partition spec is used.

@lirui-apache
Copy link
Contributor Author

PR updated to get unquoted partition values in RichSqlInsert, so that we don't have to do it in HiveTableSink.
@danny0405 better if you can also take a look. Thanks.

@@ -75,7 +77,8 @@ public SqlNodeList getStaticPartitions() {
}
for (SqlNode node : this.staticPartitions.getList()) {
SqlProperty sqlProperty = (SqlProperty) node;
String value = SqlLiteral.value(sqlProperty.getValue()).toString();
Comparable comparable = SqlLiteral.value(sqlProperty.getValue());
String value = comparable instanceof NlsString ? ((NlsString) comparable).getValue() : comparable.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the RichSqlInsert change.

hiveShell.insertInto("db1", "src").addRow(1).addRow(2).commit();
hiveShell.execute("create table db1.dest (x int) partitioned by (p1 string, p2 double)");
TableEnvironment tableEnv = getTableEnvWithHiveCatalog();
tableEnv.sqlUpdate("insert into db1.dest partition (p1='1''1', p2=1.1) select x from db1.src");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what this means and why a user might do this: p1='1''1'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, a little confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this may not be common use case, but theoretically a string partition column can take any valid values including those with single quotes. And Hive also supports this.

@lirui-apache
Copy link
Contributor Author

@xuefuz Do you have any further comments?

@xuefuz
Copy link
Contributor

xuefuz commented Aug 29, 2019

No. It looks good to me. Thanks.

@bowenli86
Copy link
Member

LGTM, merging

@bowenli86
Copy link
Member

The following test is failing on my machine:

[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   TableEnvHiveConnectorTest.testStaticPartition:203->verifyHiveQueryResult:253 expected:<[2	1'1	1.1, 1	1'1	1.1]> but was:<[2	'1''1'	1.1, 1	'1''1'	1.1]>
[INFO]
[ERROR] Tests run: 235, Failures: 1, Errors: 0, Skipped: 0

@lirui-apache
Copy link
Contributor Author

@bowenli86 I can't reproduce the error you mentioned. Rebase to trigger travis again.

@lirui-apache
Copy link
Contributor Author

Seems the latest Travis build passed.
@bowenli86 Could you please retry the failed test on your side, and make sure the sql-parser is built with this PR?

@asfgit asfgit closed this in 07dfffe Aug 30, 2019
@lirui-apache lirui-apache deleted the FLINK-13814 branch September 2, 2019 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants