Java Code Examples for org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo#TIME
The following examples show how to use
org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo#TIME .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowCsvInputFormatTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSqlTimeFields() throws Exception { String fileContent = "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5\n" + "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5.3\n"; FileInputSplit split = createTempFile(fileContent); TypeInformation[] fieldTypes = new TypeInformation[]{ SqlTimeTypeInfo.DATE, SqlTimeTypeInfo.TIME, SqlTimeTypeInfo.TIMESTAMP, SqlTimeTypeInfo.TIMESTAMP}; RowCsvInputFormat format = new RowCsvInputFormat(PATH, fieldTypes); format.setFieldDelimiter("|"); format.configure(new Configuration()); format.open(split); Row result = new Row(4); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05"), result.getField(3)); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05.3"), result.getField(3)); result = format.nextRecord(result); assertNull(result); assertTrue(format.reachedEnd()); }
Example 2
Source File: RowCsvInputFormatTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSqlTimeFields() throws Exception { String fileContent = "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5\n" + "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5.3\n"; FileInputSplit split = createTempFile(fileContent); TypeInformation[] fieldTypes = new TypeInformation[]{ SqlTimeTypeInfo.DATE, SqlTimeTypeInfo.TIME, SqlTimeTypeInfo.TIMESTAMP, SqlTimeTypeInfo.TIMESTAMP}; RowCsvInputFormat format = new RowCsvInputFormat(PATH, fieldTypes); format.setFieldDelimiter("|"); format.configure(new Configuration()); format.open(split); Row result = new Row(4); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05"), result.getField(3)); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05.3"), result.getField(3)); result = format.nextRecord(result); assertNull(result); assertTrue(format.reachedEnd()); }
Example 3
Source File: RowCsvInputFormatTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSqlTimeFields() throws Exception { String fileContent = "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5\n" + "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5.3\n"; FileInputSplit split = createTempFile(fileContent); TypeInformation[] fieldTypes = new TypeInformation[]{ SqlTimeTypeInfo.DATE, SqlTimeTypeInfo.TIME, SqlTimeTypeInfo.TIMESTAMP, SqlTimeTypeInfo.TIMESTAMP}; RowCsvInputFormat.Builder builder = RowCsvInputFormat.builder(new RowTypeInfo(fieldTypes), PATH) .setFieldDelimiter('|'); RowCsvInputFormat format = builder.build(); format.configure(new Configuration()); format.open(split); Row result = new Row(4); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05"), result.getField(3)); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05.3"), result.getField(3)); result = format.nextRecord(result); assertNull(result); assertTrue(format.reachedEnd()); }
Example 4
Source File: RowCsvInputFormatTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSqlTimeFields() throws Exception { String fileContent = "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5\n" + "1990-10-14|02:42:25|1990-10-14 02:42:25.123|1990-1-4 2:2:5.3\n"; FileInputSplit split = createTempFile(fileContent); TypeInformation[] fieldTypes = new TypeInformation[]{ SqlTimeTypeInfo.DATE, SqlTimeTypeInfo.TIME, SqlTimeTypeInfo.TIMESTAMP, SqlTimeTypeInfo.TIMESTAMP}; RowCsvInputFormat format = new RowCsvInputFormat(PATH, fieldTypes); format.setFieldDelimiter("|"); format.configure(new Configuration()); format.open(split); Row result = new Row(4); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05"), result.getField(3)); result = format.nextRecord(result); assertNotNull(result); assertEquals(Date.valueOf("1990-10-14"), result.getField(0)); assertEquals(Time.valueOf("02:42:25"), result.getField(1)); assertEquals(Timestamp.valueOf("1990-10-14 02:42:25.123"), result.getField(2)); assertEquals(Timestamp.valueOf("1990-01-04 02:02:05.3"), result.getField(3)); result = format.nextRecord(result); assertNull(result); assertTrue(format.reachedEnd()); }