Skip to content

Commit 680f8ab

Browse files
committed
Add unittest for timestamp identity transform
1 parent 3f5bfac commit 680f8ab

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

velox/connectors/hive/iceberg/tests/IcebergPartitionIdGeneratorTest.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,70 @@ TEST_F(IcebergPartitionIdGeneratorTest, partitionNameWithIdentityTransforms) {
130130
verifyPartitionComponents(partitionName, expectedComponents);
131131
}
132132

133+
TEST_F(
134+
IcebergPartitionIdGeneratorTest,
135+
partitionNameWithTimestampIdentitySpecialValues) {
136+
std::vector<Timestamp> timestamps = {
137+
Timestamp(253402300800, 100000000), // +10000-01-01T00:00:00.1.
138+
Timestamp(-62170000000, 0), // -0001-11-29T19:33:20.
139+
Timestamp(-62135577748, 999000000), // 0001-01-01T05:17:32.999.
140+
Timestamp(0, 0), // 1970-01-01T00:00.
141+
Timestamp(1609459200, 999000000), // 2021-01-01T00:00.
142+
Timestamp(1640995200, 500000000), // 2022-01-01T00:00:00.5.
143+
Timestamp(1672531200, 123000000), // 2023-01-01T00:00:00.123.
144+
Timestamp(-1, 999000000), // 1969-12-31T23:59:59.999.
145+
Timestamp(1, 1000000), // 1970-01-01T00:00:01.001.
146+
Timestamp(-62167219199, 0), // 0000-01-01T00:00:01.
147+
Timestamp(-377716279140, 321000000), // -10000-01-01T01:01:00.321.
148+
Timestamp(253402304660, 321000000), // +10000-01-01T01:01:00.321.
149+
Timestamp(951782400, 0), // 2000-02-29T00:00:00 (leap year).
150+
Timestamp(4107456000, 0), // 2100-02-28T00:00:00 (not leap year).
151+
Timestamp(86400, 0), // 1970-01-02T00:00:00.
152+
Timestamp(-86400, 0), // 1969-12-31T00:00:00.
153+
Timestamp(1672531200, 456000000), // 2023-01-01T00:00:00.456.
154+
Timestamp(1672531200, 789000000), // 2023-01-01T00:00:00.789.
155+
};
156+
157+
std::vector<std::string> expectedPartitionNames = {
158+
"c_timestamp=%2B10000-01-01T00%3A00%3A00.1",
159+
"c_timestamp=-0001-11-29T19%3A33%3A20",
160+
"c_timestamp=0001-01-01T05%3A17%3A32.999",
161+
"c_timestamp=1970-01-01T00%3A00",
162+
"c_timestamp=2021-01-01T00%3A00%3A00.999",
163+
"c_timestamp=2022-01-01T00%3A00%3A00.5",
164+
"c_timestamp=2023-01-01T00%3A00%3A00.123",
165+
"c_timestamp=1969-12-31T23%3A59%3A59.999",
166+
"c_timestamp=1970-01-01T00%3A00%3A01.001",
167+
"c_timestamp=0000-01-01T00%3A00%3A01",
168+
"c_timestamp=-10000-08-24T19%3A21%3A00.321",
169+
"c_timestamp=%2B10000-01-01T01%3A04%3A20.321",
170+
"c_timestamp=2000-02-29T00%3A00",
171+
"c_timestamp=2100-02-28T00%3A00",
172+
"c_timestamp=1970-01-02T00%3A00",
173+
"c_timestamp=1969-12-31T00%3A00",
174+
"c_timestamp=2023-01-01T00%3A00%3A00.456",
175+
"c_timestamp=2023-01-01T00%3A00%3A00.789",
176+
};
177+
178+
auto timestampVector = makeFlatVector<Timestamp>(timestamps);
179+
std::vector<std::string> columnNames = {"c_timestamp"};
180+
std::vector<VectorPtr> columns = {timestampVector};
181+
std::vector<TypePtr> types = {TIMESTAMP()};
182+
auto rowVector = createRowVector(columnNames, columns);
183+
184+
std::vector<TransformType> transformTypes = {TransformType::kIdentity};
185+
auto transforms = createColumnTransforms(columnNames, types, transformTypes);
186+
auto generator = createGenerator(transforms);
187+
raw_vector<uint64_t> partitionIds(timestamps.size());
188+
generator->run(rowVector, partitionIds);
189+
190+
for (size_t i = 0; i < timestamps.size(); ++i) {
191+
std::string partitionName =
192+
generator->partitionName(partitionIds[i], "null");
193+
ASSERT_EQ(partitionName, expectedPartitionNames[i]);
194+
}
195+
}
196+
133197
TEST_F(IcebergPartitionIdGeneratorTest, partitionNameWithMixedTransforms) {
134198
auto intVector = makeFlatVector<int32_t>(1, [](auto) { return 42; });
135199
auto bigintVector =

velox/connectors/hive/iceberg/tests/IcebergTransformUnitTest.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ TEST_F(IcebergTransformUnitTest, testTransformOnTimestamp) {
510510
{"year(c_timestamp)",
511511
"month(c_timestamp)",
512512
"day(c_timestamp)",
513-
"hour(c_timestamp)"},
513+
"hour(c_timestamp)",
514+
"c_timestamp"},
514515
rowType_);
515516

516517
auto& yearTransform = partitionSpec->fields[0];
@@ -560,6 +561,19 @@ TEST_F(IcebergTransformUnitTest, testTransformOnTimestamp) {
560561
Timestamp(1609459200, 0),
561562
Timestamp(1612224000, 0)},
562563
{0, 8760, 447072, 447840});
564+
565+
auto& identityTransform = partitionSpec->fields[4];
566+
EXPECT_EQ(identityTransform.transformType, TransformType::kIdentity);
567+
testTransform<Timestamp, Timestamp>(
568+
identityTransform,
569+
{Timestamp(0, 0),
570+
Timestamp(31536000, 0),
571+
Timestamp(1609459200, 0),
572+
Timestamp(1612224000, 0)},
573+
{Timestamp(0, 0),
574+
Timestamp(31536000, 0),
575+
Timestamp(1609459200, 0),
576+
Timestamp(1612224000, 0)});
563577
}
564578

565579
TEST_F(IcebergTransformUnitTest, testTransformsWithNulls) {

0 commit comments

Comments
 (0)