-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-3978] Fix use of partition path field as hive partition field in flink #5434
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...k-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/utils/TestHiveSyncContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hudi.sink.utils; | ||
|
|
||
| import org.apache.flink.configuration.Configuration; | ||
|
|
||
| import org.apache.hudi.configuration.FlinkOptions; | ||
| import org.apache.hudi.hive.HiveSyncConfig; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * Test cases for {@link HiveSyncContext}. | ||
| */ | ||
| public class TestHiveSyncContext { | ||
| /** | ||
| * Test that the file ids generated by the task can finally shuffled to itself. | ||
| */ | ||
| @Test | ||
| public void testBuildSyncConfig() throws Exception { | ||
| Configuration configuration1 = new Configuration(); | ||
| Configuration configuration2 = new Configuration(); | ||
| String hiveSyncPartitionField = "hiveSyncPartitionField"; | ||
| String partitionPathField = "partitionPathField"; | ||
|
|
||
| configuration1.setString(FlinkOptions.HIVE_SYNC_PARTITION_FIELDS, hiveSyncPartitionField); | ||
| configuration1.setString(FlinkOptions.PARTITION_PATH_FIELD, partitionPathField); | ||
|
|
||
| configuration2.setString(FlinkOptions.PARTITION_PATH_FIELD, partitionPathField); | ||
|
|
||
| Class<?> threadClazz = Class.forName("org.apache.hudi.sink.utils.HiveSyncContext"); | ||
| Method buildSyncConfigMethod = threadClazz.getDeclaredMethod("buildSyncConfig", Configuration.class); | ||
| buildSyncConfigMethod.setAccessible(true); | ||
|
|
||
| HiveSyncConfig hiveSyncConfig1 = HiveSyncContext.buildSyncConfig(configuration1); | ||
| HiveSyncConfig hiveSyncConfig2 = HiveSyncContext.buildSyncConfig(configuration2); | ||
|
|
||
| assertTrue(hiveSyncConfig1.partitionFields.get(0).equals(hiveSyncPartitionField)); | ||
| assertTrue(hiveSyncConfig2.partitionFields.get(0).equals(partitionPathField)); | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In HiveSyncContext, we already assign the partition fields to to hive sync partition fields, see:
hudi/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/utils/HiveSyncContext.java
Line 86 in 762623a
so what's the problem here ? BTW, this is a common util which you should not modify directly.
Uh oh!
There was an error while loading. Please reload this page.
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.
In HiveSyncContext this PARTITION_PATH_FIELD assign to hive sync partition fields .I think these two params
PARTITION_PATH_FIELDandHIVE_SYNC_PARTITION_FIELDShave different meanings in hudi.
PARTITION_PATH_FIELDis for hudi KeyGenerator to get a partitionPathHIVE_SYNC_PARTITION_FIELDSis use for hive to set a partition field.This function extractPartitionKeys should get the hive partition fields key rather than a hudi partition path field. Sometimes confuse the values will cause some errors
In this case we use TimestampBasedAvroKeyGenerator and set hudi partition path field is same as hive partition fields . There will be some promblems, see:
PARTITION_PATH_FIELD=datetime HIVE_SYNC_PARTITION_FIELDS=datetimeIn hudi: we will get the 1596074902000L value and converted to a string hudi partition path like 2020-07-30.
In hive: We will get the table like :
This partition value datetime=2020-07-30 also will be add to hive. We can't get the datetime value from this hive table, and the table partition is also broken. This datetime value is conflicting
When we set PARTITION PATH_FIELD value is different with HIVE_SYNC PARTITION FIELDS value like this.
PARTITION_PATH_FIELD=datetime HIVE_SYNC_PARTITION_FIELDS=inc_dayWe can get this table like :
In this time we can normal get the datetime value, and the inc_day as a partition field is also work.
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.
Got you, then in
HiveSyncContext, you can take the optionHIVE_SYNC_PARTITION_FIELDSinstead, and write a new tool method(you should not modify the existing method directly), if user does not configure theHIVE_SYNC_PARTITION_FIELDS, fallback to hudi table's partition path (the current code does so).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.
You also need to write a test case i guess. A unit test for HiveSyncContext is okey i think.