-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-3184] hudi-flink support timestamp-micros #4548
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
danny0405
merged 9 commits into
apache:master
from
AirToSupply:hudi_flink_support_timestamp_micro
Jan 12, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d9eb86
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 9a8dcb1
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 40bd35d
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply afe7fac
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply ed10ca7
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 83b5d6d
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 6e47470
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 17e6507
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 6b6822f
[HUDI-3184] hudi-flink support timestamp-micros
AirToSupply 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import org.apache.flink.table.types.logical.DecimalType; | ||
| import org.apache.flink.table.types.logical.LogicalType; | ||
| import org.apache.flink.table.types.logical.RowType; | ||
| import org.apache.flink.table.types.logical.TimestampType; | ||
| import org.apache.flink.table.types.logical.utils.LogicalTypeUtils; | ||
| import org.joda.time.DateTime; | ||
| import org.joda.time.DateTimeFieldType; | ||
|
|
@@ -45,6 +46,7 @@ | |
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.time.temporal.ChronoField; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -125,7 +127,7 @@ private static AvroToRowDataConverter createConverter(LogicalType type) { | |
| case TIME_WITHOUT_TIME_ZONE: | ||
| return AvroToRowDataConverters::convertToTime; | ||
| case TIMESTAMP_WITHOUT_TIME_ZONE: | ||
| return AvroToRowDataConverters::convertToTimestamp; | ||
| return createTimestampConverter(((TimestampType) type).getPrecision()); | ||
| case CHAR: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also instantiate the |
||
| case VARCHAR: | ||
| return avroObject -> StringData.fromString(avroObject.toString()); | ||
|
|
@@ -200,22 +202,36 @@ private static AvroToRowDataConverter createMapConverter(LogicalType type) { | |
| }; | ||
| } | ||
|
|
||
| private static TimestampData convertToTimestamp(Object object) { | ||
| final long millis; | ||
| if (object instanceof Long) { | ||
| millis = (Long) object; | ||
| } else if (object instanceof Instant) { | ||
| millis = ((Instant) object).toEpochMilli(); | ||
| private static AvroToRowDataConverter createTimestampConverter(int precision) { | ||
| final ChronoUnit chronoUnit; | ||
| if (precision <= 3) { | ||
| chronoUnit = ChronoUnit.MILLIS; | ||
| } else if (precision <= 6) { | ||
| chronoUnit = ChronoUnit.MICROS; | ||
| } else { | ||
| JodaConverter jodaConverter = JodaConverter.getConverter(); | ||
| if (jodaConverter != null) { | ||
| millis = jodaConverter.convertTimestamp(object); | ||
| throw new IllegalArgumentException( | ||
| "Avro does not support TIMESTAMP type with precision: " | ||
| + precision | ||
| + ", it only supports precision less than 6."); | ||
| } | ||
| return avroObject -> { | ||
| final Instant instant; | ||
| if (avroObject instanceof Long) { | ||
| instant = Instant.EPOCH.plus((Long) avroObject, chronoUnit); | ||
| } else if (avroObject instanceof Instant) { | ||
| instant = (Instant) avroObject; | ||
| } else { | ||
| throw new IllegalArgumentException( | ||
| "Unexpected object type for TIMESTAMP logical type. Received: " + object); | ||
| JodaConverter jodaConverter = JodaConverter.getConverter(); | ||
| if (jodaConverter != null) { | ||
| // joda time has only millisecond precision | ||
| instant = Instant.ofEpochMilli(jodaConverter.convertTimestamp(avroObject)); | ||
| } else { | ||
| throw new IllegalArgumentException( | ||
| "Unexpected object type for TIMESTAMP logical type. Received: " + avroObject); | ||
| } | ||
| } | ||
| } | ||
| return TimestampData.fromEpochMillis(millis); | ||
| return TimestampData.fromInstant(instant); | ||
| }; | ||
| } | ||
|
|
||
| private static int convertToDate(Object object) { | ||
|
|
@@ -272,10 +288,9 @@ private static byte[] convertToBytes(Object object) { | |
| static class JodaConverter { | ||
|
|
||
| private static JodaConverter instance; | ||
| private static boolean instantiated = false; | ||
|
|
||
| public static JodaConverter getConverter() { | ||
| if (instantiated) { | ||
| if (instance != null) { | ||
| return instance; | ||
| } | ||
|
|
||
|
|
@@ -287,8 +302,6 @@ public static JodaConverter getConverter() { | |
| instance = new JodaConverter(); | ||
| } catch (ClassNotFoundException e) { | ||
| instance = null; | ||
| } finally { | ||
| instantiated = true; | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
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
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
Oops, something went wrong.
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.
millionsOfDay => interval