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-22207][connectors/hive]Hive Catalog retrieve Flink Properties … #15564

Merged
merged 1 commit into from
Apr 14, 2021

Conversation

hameizi
Copy link
Contributor

@hameizi hameizi commented Apr 12, 2021

What is the purpose of the change

Fix hive catalog handle propertie error "java.lang.IllegalStateException: Duplicate key". As said in FLINK-22207 like below.

If we use hive catalog and set flink propertie eg."url",and then when we add the other propertie like start with string "flink." like "flink.url" will show we the error "java.lang.IllegalStateException: Duplicate key" , and what's worse is because of this error we can`t drop or alter this tabel more.

I found in this method , "org.apache.flink.table.catalog.hive.HiveCatalog.retrieveFlinkProperties", replace all "flink." of propertie. So , the propertie of HiveCatalog "flink.url" and "flink.flink.url" both result to "url".

Brief change log

Hive Catalog retrieve Flink Properties error

Verifying this change

Manually verified.

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

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

Documentation

Does this pull request introduce a new feature? (yes / no)
If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@flinkbot
Copy link
Collaborator

flinkbot commented Apr 12, 2021

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 8eaeab3 (Fri May 28 09:06:10 UTC 2021)

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 Apr 12, 2021

CI report:

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

Copy link
Contributor

@KurtYoung KurtYoung left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, could you add a test case?

@hameizi
Copy link
Contributor Author

hameizi commented Apr 12, 2021

Thanks for the fix, could you add a test case?

hello , I test the bug in sql-client
Flink SQL> alter table clickhousetableflink_append_stream set ('url'='jdbc:clickhouse://host:port/default');
[INFO] Alter table succeeded!
Flink SQL> alter table clickhousetableflink_append_stream set ('flink.url'='jdbc:clickhouse://host:port/default?socket_timeout=300000');
[INFO] Alter table succeeded!
Flink SQL> drop table clickhousetableflink_append_stream;
[ERROR] Could not execute SQL statement. Reason:
java.lang.IllegalStateException: Duplicate key jdbc:clickhouse://host:port/default

After this fix is works fine

@KurtYoung
Copy link
Contributor

@hameizi I'm pretty sure you fixed the bug and the change also LGTM. But by adding a test case can help the project won't introduce the same bug by accident in the future.

@hameizi
Copy link
Contributor Author

hameizi commented Apr 13, 2021

@KurtYoung I add test case in new commit. Please review. Thanks

@@ -78,4 +80,17 @@ public void testCreateHiveTable() {
prop.keySet().stream()
.noneMatch(k -> k.startsWith(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX)));
}

@Test
public void testRetrieveFlinkProperties() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you choose another way to test this? Relying on private method is not a good practice.

Copy link
Contributor Author

@hameizi hameizi Apr 13, 2021

Choose a reason for hiding this comment

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

@KurtYoung Thanks for you review, i change the test case, please review it.

Copy link
Contributor

@KurtYoung KurtYoung left a comment

Choose a reason for hiding this comment

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

Please also fix the format error

Map<String, String> properties = new HashMap<>(new FileSystem().path("/test_path").toProperties());

properties.put(CatalogPropertiesUtil.IS_GENERIC, String.valueOf(true));
properties.put("url", "jdbc:clickhouse://host:port/default");
Copy link
Contributor

Choose a reason for hiding this comment

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

set this property to a different value and also verify you can get this property correctly?

CatalogTable source = new CatalogTableImpl(schema, properties, null);

hiveCatalog.createTable(
hiveObjectPath, source, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary wrap here

Copy link
Contributor Author

@hameizi hameizi Apr 13, 2021

Choose a reason for hiding this comment

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

Sorry, i can't understand this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like this?

hiveCatalog.createTable(
                hiveObjectPath, new CatalogTableImpl(schema, properties, null), false);

@@ -78,4 +99,23 @@ public void testCreateHiveTable() {
prop.keySet().stream()
.noneMatch(k -> k.startsWith(CatalogPropertiesUtil.FLINK_PROPERTY_PREFIX)));
}

@Test
public void testRetrieveFlinkProperties() throws TableAlreadyExistException, DatabaseNotExistException, TableNotExistException {
Copy link
Contributor

Choose a reason for hiding this comment

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

throws Exception is enough

@hameizi
Copy link
Contributor Author

hameizi commented Apr 13, 2021

@KurtYoung Hello, i push a new commit, thanks for your review.

hiveObjectPath, new CatalogTableImpl(schema, properties, null), false);

CatalogBaseTable hiveTable = hiveCatalog.getTable(hiveObjectPath);
assertEquals(hiveTable.getOptions().get("flink.url"), "jdbc:clickhouse://host:port/testUrl2");
Copy link
Contributor

Choose a reason for hiding this comment

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

check we can get "url" correctly

@KurtYoung
Copy link
Contributor

[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.4.2:check (spotless-check) on project flink-connector-hive_2.11: The following files had format violations:
[ERROR] src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogTest.java

@hameizi
Copy link
Contributor Author

hameizi commented Apr 14, 2021

@KurtYoung I fix in the new commit, please review thanks

Copy link
Contributor

@KurtYoung KurtYoung left a comment

Choose a reason for hiding this comment

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

LGTM

@KurtYoung
Copy link
Contributor

@hameizi If you want to fix this in 1.12.3, you can also create a PR against release-1.12 branch.

@hameizi
Copy link
Contributor Author

hameizi commented Apr 14, 2021

@hameizi If you want to fix this in 1.12.3, you can also create a PR against release-1.12 branch.

ok, thanks

@KurtYoung KurtYoung merged commit c29ee91 into apache:master Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants