-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core][bug] Fix the incorrect partition key format generated from the…
… DATE type.
- Loading branch information
yuan
committed
Apr 9, 2023
1 parent
fb9babb
commit d953639
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
paimon-core/src/test/java/org/apache/paimon/utils/RowDataPartitionComputerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.apache.paimon.utils; | ||
|
||
import org.apache.paimon.data.BinaryRow; | ||
import org.apache.paimon.data.BinaryRowWriter; | ||
import org.apache.paimon.types.DataType; | ||
import org.apache.paimon.types.DateType; | ||
import org.apache.paimon.types.IntType; | ||
import org.apache.paimon.types.RowType; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.LinkedHashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** Tests for {@link RowDataPartitionComputer}. */ | ||
public class RowDataPartitionComputerTest { | ||
|
||
@Test | ||
public void testGeneratePartitionValues() { | ||
RowDataPartitionComputer partitionComputer = | ||
FileStorePathFactory.getPartitionComputer( | ||
RowType.of( | ||
new DataType[] {new DateType(), new IntType()}, | ||
new String[] {"dt", "hour"}), | ||
FileStorePathFactory.PARTITION_DEFAULT_NAME.defaultValue()); | ||
BinaryRow binaryRow = buildPartitionBinaryRow(LocalDate.now(), LocalTime.now().getHour()); | ||
LinkedHashMap<String, String> map = partitionComputer.generatePartValues(binaryRow); | ||
|
||
assertEquals(map.get("dt"), LocalDate.now().toString()); | ||
assertEquals(map.get("hour"), String.valueOf(LocalTime.now().getHour())); | ||
} | ||
|
||
public BinaryRow buildPartitionBinaryRow(LocalDate dt, Integer hour) { | ||
BinaryRow partition = new BinaryRow(2); | ||
BinaryRowWriter writer = new BinaryRowWriter(partition); | ||
if (dt != null) { | ||
writer.writeInt(0, (int) dt.toEpochDay()); | ||
} else { | ||
writer.setNullAt(0); | ||
} | ||
if (hour != null) { | ||
writer.writeInt(1, hour); | ||
} else { | ||
writer.setNullAt(1); | ||
} | ||
writer.complete(); | ||
return partition; | ||
} | ||
} |