Skip to content

Commit

Permalink
[Improve] add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
liunaijie committed Oct 24, 2023
1 parent 5745e1f commit c55da0f
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import java.io.File;
import java.net.URL;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_DEFAULT;

Expand Down Expand Up @@ -70,6 +72,37 @@ public void testParquetRead2() throws Exception {
parquetReadStrategy.read(path, testCollector);
}

@Test
public void testParquetRead3() throws Exception {
URL resource = ParquetReadStrategyTest.class.getResource("/timestamp_as_int64.parquet");
Assertions.assertNotNull(resource);
String path = Paths.get(resource.toURI()).toString();
ParquetReadStrategy parquetReadStrategy = new ParquetReadStrategy();
LocalConf localConf = new LocalConf(FS_DEFAULT_NAME_DEFAULT);
parquetReadStrategy.init(localConf);
SeaTunnelRowType seaTunnelRowTypeInfo =
parquetReadStrategy.getSeaTunnelRowTypeInfo(localConf, path);
Assertions.assertNotNull(seaTunnelRowTypeInfo);
System.out.println(seaTunnelRowTypeInfo);
int index = seaTunnelRowTypeInfo.indexOf("c_timestamp");
TimeZone tz1 = TimeZone.getTimeZone("Asia/Shanghai");
TimeZone.setDefault(tz1);
TestCollector testCollector = new TestCollector();
parquetReadStrategy.read(path, testCollector);
LocalDateTime time1 = (LocalDateTime) testCollector.getRows().get(0).getField(index);

TimeZone tz2 = TimeZone.getTimeZone("UTC");
TimeZone.setDefault(tz2);
TestCollector testCollector2 = new TestCollector();
parquetReadStrategy.read(path, testCollector2);
LocalDateTime time2 = (LocalDateTime) testCollector2.getRows().get(0).getField(index);

Assertions.assertTrue(time1.isAfter(time2));
Assertions.assertEquals(
time1.atZone(tz1.toZoneId()).withZoneSameInstant(tz2.toZoneId()).toLocalDateTime(),
time2);
}

@Test
public void testParquetReadProjection1() throws Exception {
URL resource = ParquetReadStrategyTest.class.getResource("/timestamp_as_int96.parquet");
Expand Down

0 comments on commit c55da0f

Please sign in to comment.