-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support writing timestamp with time zone
type on partitioned column in Delta
#18353
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -52,6 +52,7 @@ | |||||||||||
import io.trino.spi.type.MapType; | ||||||||||||
import io.trino.spi.type.RowType; | ||||||||||||
import io.trino.spi.type.TimestampType; | ||||||||||||
import io.trino.spi.type.TimestampWithTimeZoneType; | ||||||||||||
import io.trino.spi.type.Type; | ||||||||||||
import io.trino.spi.type.VarcharType; | ||||||||||||
import org.apache.hadoop.conf.Configuration; | ||||||||||||
|
@@ -86,6 +87,7 @@ | |||||||||||
import java.util.Optional; | ||||||||||||
import java.util.Properties; | ||||||||||||
|
||||||||||||
import static com.google.common.base.Preconditions.checkArgument; | ||||||||||||
import static com.google.common.base.Verify.verify; | ||||||||||||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||||||||||||
import static com.google.common.io.BaseEncoding.base16; | ||||||||||||
|
@@ -113,11 +115,13 @@ | |||||||||||
import static io.trino.spi.type.BigintType.BIGINT; | ||||||||||||
import static io.trino.spi.type.BooleanType.BOOLEAN; | ||||||||||||
import static io.trino.spi.type.Chars.padSpaces; | ||||||||||||
import static io.trino.spi.type.DateTimeEncoding.unpackMillisUtc; | ||||||||||||
import static io.trino.spi.type.DateType.DATE; | ||||||||||||
import static io.trino.spi.type.DoubleType.DOUBLE; | ||||||||||||
import static io.trino.spi.type.IntegerType.INTEGER; | ||||||||||||
import static io.trino.spi.type.RealType.REAL; | ||||||||||||
import static io.trino.spi.type.SmallintType.SMALLINT; | ||||||||||||
import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; | ||||||||||||
import static io.trino.spi.type.Timestamps.MICROSECONDS_PER_MILLISECOND; | ||||||||||||
import static io.trino.spi.type.Timestamps.MICROSECONDS_PER_SECOND; | ||||||||||||
import static io.trino.spi.type.Timestamps.MILLISECONDS_PER_SECOND; | ||||||||||||
|
@@ -334,6 +338,10 @@ public static Object getField(DateTimeZone localZone, Type type, Block block, in | |||||||||||
if (type instanceof TimestampType timestampType) { | ||||||||||||
return getHiveTimestamp(localZone, timestampType, block, position); | ||||||||||||
} | ||||||||||||
if (type instanceof TimestampWithTimeZoneType) { | ||||||||||||
checkArgument(type.equals(TIMESTAMP_TZ_MILLIS)); | ||||||||||||
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 good functionally from my perspective. Code wise, I'm concerned about mixing Delta Lake specific code within Do you see anything against having 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. Agreed. We call here from trino/plugin/trino-hive/src/main/java/io/trino/plugin/hive/util/HiveWriteUtils.java Lines 285 to 289 in 431f3e0
in delta context the value gets used to
so the logic could indeed be Delta-specific. AFAIAC, this can go follow-up 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 will send a follow-up PR. |
||||||||||||
return getHiveTimestampTz(block, position); | ||||||||||||
} | ||||||||||||
if (type instanceof DecimalType decimalType) { | ||||||||||||
return getHiveDecimal(decimalType, block, position); | ||||||||||||
} | ||||||||||||
|
@@ -780,4 +788,10 @@ private static Timestamp getHiveTimestamp(DateTimeZone localZone, TimestampType | |||||||||||
int nanosOfSecond = microsOfSecond * NANOSECONDS_PER_MICROSECOND + nanosOfMicro; | ||||||||||||
return Timestamp.ofEpochSecond(epochSeconds, nanosOfSecond); | ||||||||||||
} | ||||||||||||
|
||||||||||||
private static Timestamp getHiveTimestampTz(Block block, int position) | ||||||||||||
{ | ||||||||||||
long epochMillis = unpackMillisUtc(block.getLong(position, 0)); | ||||||||||||
return Timestamp.ofEpochMilli(epochMillis); | ||||||||||||
} | ||||||||||||
} |
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.
is "HIVE_DEFAULT_PARTITION" also the Delta's convention for paths for null part key?
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.
Yes, it's verified in a product test:
trino/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeDatabricksInsertCompatibility.java
Lines 132 to 134 in 68ad854