Test over an orc file that does not store time zone information in the footer and it was written from a time zone that does not observe DST.
| 40 | * and it was written from a time zone that does not observe DST. |
| 41 | */ |
| 42 | public class TestOrcNoTimezone implements TestConf { |
| 43 | FileSystem fs; |
| 44 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); |
| 45 | static TimeZone defaultTimeZone = TimeZone.getDefault(); |
| 46 | |
| 47 | @BeforeEach |
| 48 | public void openFileSystem() throws Exception { |
| 49 | fs = FileSystem.getLocal(conf); |
| 50 | } |
| 51 | |
| 52 | @AfterEach |
| 53 | public void restoreTimeZone() { |
| 54 | TimeZone.setDefault(defaultTimeZone); |
| 55 | } |
| 56 | |
| 57 | @ParameterizedTest |
| 58 | @ValueSource(strings = {"GMT-12:00", "UTC", "GMT+8:00"}) |
| 59 | public void testReadOldTimestampFormat(String readerTimeZone) throws Exception { |
| 60 | TimeZone.setDefault(TimeZone.getTimeZone(readerTimeZone)); |
| 61 | Path oldFilePath = new Path(getClass().getClassLoader(). |
| 62 | getSystemResource("orc-file-no-timezone.orc").getPath()); |
| 63 | Reader reader = OrcFile.createReader(oldFilePath, |
| 64 | OrcFile.readerOptions(conf).filesystem(fs).useUTCTimestamp(true)); |
| 65 | formatter.setTimeZone(TimeZone.getTimeZone("UTC")); |
| 66 | TypeDescription schema = reader.getSchema(); |
| 67 | VectorizedRowBatch batch = schema.createRowBatch(10); |
| 68 | TimestampColumnVector ts = (TimestampColumnVector) batch.cols[0]; |
| 69 | |
| 70 | boolean[] include = new boolean[schema.getMaximumId() + 1]; |
| 71 | include[schema.getChildren().get(0).getId()] = true; |
| 72 | RecordReader rows = reader.rows |
| 73 | (reader.options().include(include)); |
| 74 | assertTrue(rows.nextBatch(batch)); |
| 75 | Timestamp timestamp = ts.asScratchTimestamp(0); |
| 76 | assertEquals( |
| 77 | Timestamp.valueOf("2014-01-01 12:34:56.0").toString(), |
| 78 | formatter.format(timestamp), |
| 79 | "For timezone : " + TimeZone.getTimeZone(readerTimeZone)); |
| 80 | |
| 81 | // check the contents of second row |
| 82 | rows.seekToRow(1); |
| 83 | assertTrue(rows.nextBatch(batch)); |
| 84 | assertEquals(1, batch.size); |
| 85 | timestamp = ts.asScratchTimestamp(0); |
| 86 | assertEquals( |
| 87 | Timestamp.valueOf("2014-06-06 12:34:56.0").toString(), |
| 88 | formatter.format(timestamp), |
| 89 | "For timezone : " + TimeZone.getTimeZone(readerTimeZone)); |
| 90 | |
| 91 | // handle the close up |
| 92 | assertFalse(rows.nextBatch(batch)); |
| 93 | rows.close(); |
| 94 | } |
| 95 | } |
nothing calls this directly
no outgoing calls
no test coverage detected