| 43 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 44 | |
| 45 | public class TestConvert implements TestConf { |
| 46 | |
| 47 | public static final TimeZone DEFAULT_TIME_ZONE = TimeZone.getDefault(); |
| 48 | |
| 49 | Path workDir = new Path(System.getProperty("test.tmp.dir")); |
| 50 | FileSystem fs; |
| 51 | Path testFilePath; |
| 52 | |
| 53 | @BeforeEach |
| 54 | public void openFileSystem () throws Exception { |
| 55 | fs = FileSystem.getLocal(conf); |
| 56 | testFilePath = new Path(workDir + File.separator + "TestConvert.testConvert.orc"); |
| 57 | fs.delete(testFilePath, false); |
| 58 | } |
| 59 | |
| 60 | @BeforeAll |
| 61 | public static void changeDefaultTimeZone() { |
| 62 | TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); |
| 63 | } |
| 64 | |
| 65 | @AfterAll |
| 66 | public static void resetDefaultTimeZone() { |
| 67 | TimeZone.setDefault(DEFAULT_TIME_ZONE); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testConvertCustomTimestampFromCsv() throws IOException, ParseException { |
| 72 | Path csvFile = new Path(workDir + File.separator + "test.csv"); |
| 73 | FSDataOutputStream stream = fs.create(csvFile, true); |
| 74 | String[] timeValues = new String[] {"0001-01-01 00:00:00.000", "2021-12-01 18:36:00.800"}; |
| 75 | stream.writeBytes(String.join("\n", timeValues)); |
| 76 | stream.close(); |
| 77 | String schema = "struct<d:timestamp>"; |
| 78 | String timestampFormat = "yyyy-MM-dd HH:mm:ss.SSS"; |
| 79 | TypeDescription readSchema = TypeDescription.fromString(schema); |
| 80 | |
| 81 | ConvertTool.main(conf, new String[]{"--schema", schema, "-o", testFilePath.toString(), |
| 82 | "-t", timestampFormat, csvFile.toString()}); |
| 83 | |
| 84 | assertTrue(fs.exists(testFilePath)); |
| 85 | |
| 86 | Reader reader = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf)); |
| 87 | VectorizedRowBatch batch = readSchema.createRowBatch(); |
| 88 | RecordReader rowIterator = reader.rows(reader.options().schema(readSchema)); |
| 89 | TimestampColumnVector tcv = (TimestampColumnVector) batch.cols[0]; |
| 90 | |
| 91 | while (rowIterator.nextBatch(batch)) { |
| 92 | for (int row = 0; row < batch.size; ++row) { |
| 93 | Timestamp timestamp = Timestamp.valueOf(timeValues[row]); |
| 94 | assertEquals(timestamp.getTime(), tcv.time[row]); |
| 95 | assertEquals(timestamp.getNanos(), tcv.nanos[row]); |
| 96 | } |
| 97 | } |
| 98 | rowIterator.close(); |
| 99 | } |
| 100 | |
| 101 | } |
nothing calls this directly
no outgoing calls
no test coverage detected