|
53 | 53 | import org.apache.spark.sql.SparkSession;
|
54 | 54 | import org.apache.spark.sql.types.DataTypes;
|
55 | 55 | import org.junit.jupiter.api.AfterAll;
|
| 56 | +import org.junit.jupiter.api.Assertions; |
56 | 57 | import org.junit.jupiter.api.BeforeAll;
|
57 | 58 | import org.junit.jupiter.api.BeforeEach;
|
58 | 59 | import org.junit.jupiter.api.Test;
|
|
77 | 78 | import io.delta.standalone.expressions.EqualTo;
|
78 | 79 | import io.delta.standalone.expressions.Expression;
|
79 | 80 | import io.delta.standalone.expressions.Literal;
|
| 81 | +import io.delta.standalone.internal.exception.DeltaErrors; |
80 | 82 | import io.delta.standalone.types.IntegerType;
|
81 | 83 | import io.delta.standalone.types.StringType;
|
82 | 84 |
|
@@ -431,6 +433,46 @@ public void testGetTargetCommitIdentifierWithNullSourceIdentifier() throws Excep
|
431 | 433 | assertFalse(unmappedTargetId.isPresent());
|
432 | 434 | }
|
433 | 435 |
|
| 436 | + @Test |
| 437 | + public void testTimestampNtz() { |
| 438 | + InternalSchema schema1 = getInternalSchemaWithTimestampNtz(); |
| 439 | + List<InternalField> fields2 = new ArrayList<>(schema1.getFields()); |
| 440 | + fields2.add( |
| 441 | + InternalField.builder() |
| 442 | + .name("float_field") |
| 443 | + .schema( |
| 444 | + InternalSchema.builder() |
| 445 | + .name("float") |
| 446 | + .dataType(InternalType.FLOAT) |
| 447 | + .isNullable(true) |
| 448 | + .build()) |
| 449 | + .build()); |
| 450 | + InternalSchema schema2 = getInternalSchema().toBuilder().fields(fields2).build(); |
| 451 | + InternalTable table1 = getInternalTable(tableName, basePath, schema1, null, LAST_COMMIT_TIME); |
| 452 | + InternalTable table2 = getInternalTable(tableName, basePath, schema2, null, LAST_COMMIT_TIME); |
| 453 | + |
| 454 | + InternalDataFile dataFile1 = getDataFile(1, Collections.emptyList(), basePath); |
| 455 | + InternalDataFile dataFile2 = getDataFile(2, Collections.emptyList(), basePath); |
| 456 | + InternalDataFile dataFile3 = getDataFile(3, Collections.emptyList(), basePath); |
| 457 | + |
| 458 | + InternalSnapshot snapshot1 = buildSnapshot(table1, "0", dataFile1, dataFile2); |
| 459 | + InternalSnapshot snapshot2 = buildSnapshot(table2, "1", dataFile2, dataFile3); |
| 460 | + |
| 461 | + TableFormatSync.getInstance() |
| 462 | + .syncSnapshot(Collections.singletonList(conversionTarget), snapshot1); |
| 463 | + // Delta standalone library can't read versions (3,7) and needs delta kernel dependency. |
| 464 | + Assertions.assertThrows( |
| 465 | + DeltaErrors.InvalidProtocolVersionException.class, |
| 466 | + () -> |
| 467 | + validateDeltaTable(basePath, new HashSet<>(Arrays.asList(dataFile1, dataFile2)), null)); |
| 468 | + TableFormatSync.getInstance() |
| 469 | + .syncSnapshot(Collections.singletonList(conversionTarget), snapshot2); |
| 470 | + Assertions.assertThrows( |
| 471 | + DeltaErrors.InvalidProtocolVersionException.class, |
| 472 | + () -> |
| 473 | + validateDeltaTable(basePath, new HashSet<>(Arrays.asList(dataFile1, dataFile2)), null)); |
| 474 | + } |
| 475 | + |
434 | 476 | private static Stream<Arguments> timestampPartitionTestingArgs() {
|
435 | 477 | return Stream.of(
|
436 | 478 | Arguments.of(PartitionTransformType.YEAR),
|
@@ -563,6 +605,25 @@ private InternalSchema getInternalSchema() {
|
563 | 605 | .build();
|
564 | 606 | }
|
565 | 607 |
|
| 608 | + private InternalSchema getInternalSchemaWithTimestampNtz() { |
| 609 | + Map<InternalSchema.MetadataKey, Object> timestampMetadata = new HashMap<>(); |
| 610 | + timestampMetadata.put( |
| 611 | + InternalSchema.MetadataKey.TIMESTAMP_PRECISION, InternalSchema.MetadataValue.MICROS); |
| 612 | + List<InternalField> fields = new ArrayList<>(getInternalSchema().getFields()); |
| 613 | + fields.add( |
| 614 | + InternalField.builder() |
| 615 | + .name("timestamp_ntz_field") |
| 616 | + .schema( |
| 617 | + InternalSchema.builder() |
| 618 | + .name("time_ntz") |
| 619 | + .dataType(InternalType.TIMESTAMP_NTZ) |
| 620 | + .isNullable(true) |
| 621 | + .metadata(timestampMetadata) |
| 622 | + .build()) |
| 623 | + .build()); |
| 624 | + return getInternalSchema().toBuilder().fields(fields).build(); |
| 625 | + } |
| 626 | + |
566 | 627 | private static SparkSession buildSparkSession() {
|
567 | 628 | SparkConf sparkConf =
|
568 | 629 | new SparkConf()
|
|
0 commit comments