-
Notifications
You must be signed in to change notification settings - Fork 3k
Flink: Replace Row with RowData in flink write path. #1320
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,52 +85,51 @@ private interface PositionalGetter<T> { | |
| } | ||
|
|
||
| private static PositionalGetter<?> buildGetter(LogicalType logicalType, Type type) { | ||
| switch (type.typeId()) { | ||
| case STRING: | ||
| switch (logicalType.getTypeRoot()) { | ||
| case TINYINT: | ||
| return (row, pos) -> (int) row.getByte(pos); | ||
| case SMALLINT: | ||
| return (row, pos) -> (int) row.getShort(pos); | ||
| case CHAR: | ||
| case VARCHAR: | ||
| return (row, pos) -> row.getString(pos).toString(); | ||
|
|
||
| case FIXED: | ||
| case BINARY: | ||
| return (row, pos) -> ByteBuffer.wrap(row.getBinary(pos)); | ||
|
|
||
| case UUID: | ||
| return (row, pos) -> { | ||
| ByteBuffer bb = ByteBuffer.wrap(row.getBinary(pos)); | ||
| long mostSigBits = bb.getLong(); | ||
| long leastSigBits = bb.getLong(); | ||
| return new UUID(mostSigBits, leastSigBits); | ||
| }; | ||
| case VARBINARY: | ||
| if (Type.TypeID.UUID.equals(type.typeId())) { | ||
|
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. I think an identity check would be okay since this is an enum symbol, but either way is fine. |
||
| return (row, pos) -> { | ||
| ByteBuffer bb = ByteBuffer.wrap(row.getBinary(pos)); | ||
| long mostSigBits = bb.getLong(); | ||
| long leastSigBits = bb.getLong(); | ||
| return new UUID(mostSigBits, leastSigBits); | ||
|
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. Looks like another area where we should have a util method to convert (though it shouldn't block this commit).
Member
Author
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. It's true, we could have a separate pull request for this. |
||
| }; | ||
| } else { | ||
| return (row, pos) -> ByteBuffer.wrap(row.getBinary(pos)); | ||
| } | ||
|
|
||
| case DECIMAL: | ||
| DecimalType decimalType = (DecimalType) logicalType; | ||
| return (row, pos) -> row.getDecimal(pos, decimalType.getPrecision(), decimalType.getScale()).toBigDecimal(); | ||
|
|
||
| case TIME: | ||
| case TIME_WITHOUT_TIME_ZONE: | ||
| // Time in RowData is in milliseconds (Integer), while iceberg's time is microseconds (Long). | ||
| return (row, pos) -> ((long) row.getInt(pos)) * 1_000; | ||
|
|
||
| case TIMESTAMP: | ||
| switch (logicalType.getTypeRoot()) { | ||
| case TIMESTAMP_WITHOUT_TIME_ZONE: | ||
| TimestampType timestampType = (TimestampType) logicalType; | ||
| return (row, pos) -> { | ||
| LocalDateTime localDateTime = row.getTimestamp(pos, timestampType.getPrecision()).toLocalDateTime(); | ||
| return DateTimeUtil.microsFromTimestamp(localDateTime); | ||
| }; | ||
|
|
||
| case TIMESTAMP_WITH_LOCAL_TIME_ZONE: | ||
| LocalZonedTimestampType lzTs = (LocalZonedTimestampType) logicalType; | ||
| return (row, pos) -> { | ||
| TimestampData timestampData = row.getTimestamp(pos, lzTs.getPrecision()); | ||
| return timestampData.getMillisecond() * 1000 + timestampData.getNanoOfMillisecond() / 1000; | ||
| }; | ||
|
|
||
| default: | ||
| throw new IllegalArgumentException("Unhandled iceberg type: " + type + " corresponding flink type: " + | ||
| logicalType); | ||
| } | ||
| case TIMESTAMP_WITHOUT_TIME_ZONE: | ||
| TimestampType timestampType = (TimestampType) logicalType; | ||
| return (row, pos) -> { | ||
| LocalDateTime localDateTime = row.getTimestamp(pos, timestampType.getPrecision()).toLocalDateTime(); | ||
| return DateTimeUtil.microsFromTimestamp(localDateTime); | ||
|
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. Why not use the same logic here that is used in the other timestamp type? Both of the values are
Member
Author
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. Yeah, it could be the same to convert |
||
| }; | ||
|
|
||
| case TIMESTAMP_WITH_LOCAL_TIME_ZONE: | ||
| LocalZonedTimestampType lzTs = (LocalZonedTimestampType) logicalType; | ||
| return (row, pos) -> { | ||
| TimestampData timestampData = row.getTimestamp(pos, lzTs.getPrecision()); | ||
| return timestampData.getMillisecond() * 1000 + timestampData.getNanoOfMillisecond() / 1000; | ||
| }; | ||
|
|
||
| case STRUCT: | ||
| case ROW: | ||
| RowType rowType = (RowType) logicalType; | ||
| Types.StructType structType = (Types.StructType) type; | ||
|
|
||
|
|
||
This file was deleted.
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 changed the type from iceberg type to flink's logical type here, because the value of tinyint & smallint is a
byte&short, when cast to thebyteorshorttoIntegerhere, it will throw a cast failure exception. Using logical type here so that we could cast it to integer right way.