List of usage examples for java.time LocalTime get
@Override public int get(TemporalField field)
From source file:Main.java
public static void main(String[] args) { LocalTime l = LocalTime.now(); System.out.println(l.get(ChronoField.MINUTE_OF_HOUR)); }
From source file:org.apache.nifi.processors.orc.PutORCTest.java
@Test public void testWriteORCWithAvroLogicalTypes() throws IOException, InitializationException { final String avroSchema = IOUtils.toString( new FileInputStream("src/test/resources/user_logical_types.avsc"), StandardCharsets.UTF_8); schema = new Schema.Parser().parse(avroSchema); Calendar now = Calendar.getInstance(); LocalTime nowTime = LocalTime.now(); LocalDateTime nowDateTime = LocalDateTime.now(); LocalDate epoch = LocalDate.ofEpochDay(0); LocalDate nowDate = LocalDate.now(); final int timeMillis = nowTime.get(ChronoField.MILLI_OF_DAY); final Timestamp timestampMillis = Timestamp.valueOf(nowDateTime); final Date dt = Date.valueOf(nowDate); final double dec = 1234.56; configure(proc, 10, (numUsers, readerFactory) -> { for (int i = 0; i < numUsers; i++) { readerFactory.addRecord(i, timeMillis, timestampMillis, dt, dec); }//from w w w.j av a2 s. c o m return null; }); final String filename = "testORCWithDefaults-" + System.currentTimeMillis(); final Map<String, String> flowFileAttributes = new HashMap<>(); flowFileAttributes.put(CoreAttributes.FILENAME.key(), filename); testRunner.setProperty(PutORC.HIVE_TABLE_NAME, "myTable"); testRunner.enqueue("trigger", flowFileAttributes); testRunner.run(); testRunner.assertAllFlowFilesTransferred(PutORC.REL_SUCCESS, 1); final Path orcFile = new Path(DIRECTORY + "/" + filename); // verify the successful flow file has the expected attributes final MockFlowFile mockFlowFile = testRunner.getFlowFilesForRelationship(PutORC.REL_SUCCESS).get(0); mockFlowFile.assertAttributeEquals(PutORC.ABSOLUTE_HDFS_PATH_ATTRIBUTE, orcFile.getParent().toString()); mockFlowFile.assertAttributeEquals(CoreAttributes.FILENAME.key(), filename); mockFlowFile.assertAttributeEquals(PutORC.RECORD_COUNT_ATTR, "10"); // DDL will be created with field names normalized (lowercased, e.g.) for Hive by default mockFlowFile.assertAttributeEquals(PutORC.HIVE_DDL_ATTRIBUTE, "CREATE EXTERNAL TABLE IF NOT EXISTS `myTable` (`id` INT, `timemillis` INT, `timestampmillis` TIMESTAMP, `dt` DATE, `dec` DOUBLE) STORED AS ORC"); // verify we generated a provenance event final List<ProvenanceEventRecord> provEvents = testRunner.getProvenanceEvents(); assertEquals(1, provEvents.size()); // verify it was a SEND event with the correct URI final ProvenanceEventRecord provEvent = provEvents.get(0); assertEquals(ProvenanceEventType.SEND, provEvent.getEventType()); // If it runs with a real HDFS, the protocol will be "hdfs://", but with a local filesystem, just assert the filename. Assert.assertTrue(provEvent.getTransitUri().endsWith(DIRECTORY + "/" + filename)); // verify the content of the ORC file by reading it back in verifyORCUsers(orcFile, 10, (x, currUser) -> { assertEquals((int) currUser, ((IntWritable) x.get(0)).get()); assertEquals(timeMillis, ((IntWritable) x.get(1)).get()); assertEquals(timestampMillis, ((TimestampWritableV2) x.get(2)).getTimestamp().toSqlTimestamp()); final DateFormat noTimeOfDayDateFormat = new SimpleDateFormat("yyyy-MM-dd"); noTimeOfDayDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); assertEquals(noTimeOfDayDateFormat.format(dt), ((DateWritableV2) x.get(3)).get().toString()); assertEquals(dec, ((DoubleWritable) x.get(4)).get(), Double.MIN_VALUE); return null; }); // verify we don't have the temp dot file after success final File tempOrcFile = new File(DIRECTORY + "/." + filename); Assert.assertFalse(tempOrcFile.exists()); // verify we DO have the CRC file after success final File crcAvroORCFile = new File(DIRECTORY + "/." + filename + ".crc"); Assert.assertTrue(crcAvroORCFile.exists()); }