Repository: apache/amoro
Pull request #3094 (2024-08-12 12:38:13)

[AMORO-3091] Support TIMESTAMP in `MixedDataFiles.fromPartitionString()`
fix issues [3091](https://github.com/apache/amoro/issues/3091)
support TIMESTAMP in `MixedDataFiles.fromPartitionString()`

lurnagao-dahua: > Thank you for your First Contribution,We have a set of template standards when we submit PR, and I revised some of the descriptions.and you should run spotless format the code. cc @lurnagao-dahua ![image](https://private-user-images.githubusercontent.com/28348735/357250756-6ea11085-b293-4b4e-a92a-5749a865c1ef.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM1MTY5MTgsIm5iZiI6MTcyMzUxNjYxOCwicGF0aCI6Ii8yODM0ODczNS8zNTcyNTA3NTYtNmVhMTEwODUtYjI5My00YjRlLWE5MmEtNTc0OWE4NjVjMWVmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEzVDAyMzY1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBjZTY4NDRiOTQ2Y2M1YjZiMTlkN2M0NWUzNWQxNjgxZWM5Mzg0MWFhYjkzZGJhNGU0ZjFhMTA1NDc4NjU0YjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.X8aKTO_ZsNthaGSkr-uAq_GQpVEsHUv7sjflNispp1s)

Thank you for your guidance!
I have run `mvn spotless:check` and `mvn spotless:apply`

Patch:
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);


Test patch:
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);
+  }
 }