This is an automated email from the ASF dual-hosted git repository.
jinsongzhou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git
The following commit(s) were added to refs/heads/master by this push:
new da62faf8d [AMORO-3091] Support TIMESTAMP in
`MixedDataFiles.fromPartitionString()` (#3094)
da62faf8d is described below
commit da62faf8d96b249c95e5d8e64d4fa78ce6399353
Author: liu yang <[email protected]>
AuthorDate: Tue Aug 13 17:58:34 2024 +0800
[AMORO-3091] Support TIMESTAMP in `MixedDataFiles.fromPartitionString()`
(#3094)
* support timestamp in fromPartitionString
* add ut
* remove excess spaces
---
.../org/apache/amoro/utils/MixedDataFiles.java | 6 ++++
.../org/apache/amoro/utils/TestMixedDataFiles.java | 37 ++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git
a/amoro-core/src/main/java/org/apache/amoro/utils/MixedDataFiles.java
b/amoro-core/src/main/java/org/apache/amoro/utils/MixedDataFiles.java
index 6073a835a..256727ff2 100644
--- a/amoro-core/src/main/java/org/apache/amoro/utils/MixedDataFiles.java
+++ b/amoro-core/src/main/java/org/apache/amoro/utils/MixedDataFiles.java
@@ -95,6 +95,12 @@ public class MixedDataFiles {
return new BigDecimal(asString);
case DATE:
return Literal.of(asString).to(Types.DateType.get()).value();
+ case TIMESTAMP:
+ if (((Types.TimestampType) type).shouldAdjustToUTC()) {
+ return
Literal.of(asString).to(Types.TimestampType.withZone()).value();
+ } else {
+ return
Literal.of(asString).to(Types.TimestampType.withoutZone()).value();
+ }
default:
throw new UnsupportedOperationException(
"Unsupported type for fromPartitionString: " + type);
diff --git
a/amoro-core/src/test/java/org/apache/amoro/utils/TestMixedDataFiles.java
b/amoro-core/src/test/java/org/apache/amoro/utils/TestMixedDataFiles.java
index 1fb08cf0f..1faef4be3 100644
--- a/amoro-core/src/test/java/org/apache/amoro/utils/TestMixedDataFiles.java
+++ b/amoro-core/src/test/java/org/apache/amoro/utils/TestMixedDataFiles.java
@@ -30,6 +30,7 @@ import org.junit.Assert;
import org.junit.Test;
import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
public class TestMixedDataFiles {
@@ -181,4 +182,40 @@ public class TestMixedDataFiles {
Assert.assertEquals(p1, p2);
}
+
+ @Test
+ public void testTimestampPartitionTZ() {
+ Schema schema = new Schema(Types.NestedField.required(1, "dt",
Types.TimestampType.withZone()));
+ PartitionSpec spec =
PartitionSpec.builderFor(schema).identity("dt").build();
+ PartitionKey partitionKey = new PartitionKey(spec, schema);
+ GenericRecord record = GenericRecord.create(schema);
+ InternalRecordWrapper internalRecordWrapper = new
InternalRecordWrapper(schema.asStruct());
+ partitionKey.partition(
+ internalRecordWrapper.wrap(
+ record.copy("dt",
OffsetDateTime.parse("2024-08-12T11:00:00+08:00"))));
+ String partitionPath = spec.partitionToPath(partitionKey);
+ StructLike partitionData = MixedDataFiles.data(spec, partitionPath);
+ StructLikeWrapper p1 = StructLikeWrapper.forType(spec.partitionType());
+ p1.set(partitionKey);
+ StructLikeWrapper p2 = StructLikeWrapper.forType(spec.partitionType());
+ p2.set(partitionData);
+ Assert.assertEquals(p1, p2);
+ }
+
+ @Test
+ public void testTimestampPartitionNTZ() {
+ PartitionSpec spec =
PartitionSpec.builderFor(SCHEMA).identity("dt").build();
+ PartitionKey partitionKey = new PartitionKey(spec, SCHEMA);
+ GenericRecord record = GenericRecord.create(SCHEMA);
+ InternalRecordWrapper internalRecordWrapper = new
InternalRecordWrapper(SCHEMA.asStruct());
+ partitionKey.partition(
+ internalRecordWrapper.wrap(record.copy("dt",
LocalDateTime.parse("2024-08-12T11:00:00"))));
+ String partitionPath = spec.partitionToPath(partitionKey);
+ StructLike partitionData = MixedDataFiles.data(spec, partitionPath);
+ StructLikeWrapper p1 = StructLikeWrapper.forType(spec.partitionType());
+ p1.set(partitionKey);
+ StructLikeWrapper p2 = StructLikeWrapper.forType(spec.partitionType());
+ p2.set(partitionData);
+ Assert.assertEquals(p1, p2);
+ }
}