org.embulk.spi.time.Timestamp Java Examples
The following examples show how to use
org.embulk.spi.time.Timestamp.
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: ColumnVisitorImpl.java From embulk-filter-column with MIT License | 6 votes |
@Override public void timestampColumn(Column outputColumn) { Column inputColumn = outputInputColumnMap.get(outputColumn); if (inputColumn == null || pageReader.isNull(inputColumn)) { Timestamp defaultValue = (Timestamp) outputDefaultMap.get(outputColumn); if (defaultValue == null) { pageBuilder.setNull(outputColumn); } else { pageBuilder.setTimestamp(outputColumn, defaultValue); } } else { pageBuilder.setTimestamp(outputColumn, pageReader.getTimestamp(inputColumn)); } }
Example #2
Source File: ColumnVisitorImpl.java From embulk-parser-jsonl with MIT License | 6 votes |
@Override public void timestampColumn(Column column) { if (isNil(value)) { pageBuilder.setNull(column); } else { try { Timestamp timestamp = ColumnCaster.asTimestamp(value, timestampParsers[column.getIndex()]); pageBuilder.setTimestamp(column, timestamp); } catch (MessageTypeException e) { throw new JsonRecordValidateException(String.format("failed to get \"%s\" as Timestamp", value), e); } } }
Example #3
Source File: ColumnCaster.java From embulk-parser-jsonl with MIT License | 6 votes |
public static Timestamp asTimestamp(Value value, TimestampParser parser) throws DataException { if (value.isBooleanValue()) { return BooleanCast.asTimestamp(value.asBooleanValue().getBoolean()); } else if (value.isIntegerValue()) { return LongCast.asTimestamp(value.asIntegerValue().asLong()); } else if (value.isFloatValue()) { return DoubleCast.asTimestamp(value.asFloatValue().toDouble()); } else if (value.isStringValue()) { return StringCast.asTimestamp(value.asStringValue().asString(), parser); } else { return JsonCast.asTimestamp(value); } }
Example #4
Source File: TestColumnVisitorImpl.java From embulk-filter-column with MIT License | 5 votes |
@Test public void visit_Columns_WithDrop() { PluginTask task = taskFromYamlString( "type: column", "columns:", " - {name: timestamp}", " - {name: string}", " - {name: boolean}", " - {name: long}", " - {name: double}", " - {name: json}"); Schema inputSchema = Schema.builder() .add("timestamp", TIMESTAMP) .add("string", STRING) .add("boolean", BOOLEAN) .add("long", LONG) .add("double", DOUBLE) .add("json", JSON) .add("remove_me", STRING) .build(); List<Object[]> records = filter(task, inputSchema, Timestamp.ofEpochSecond(0), "string", Boolean.valueOf(true), Long.valueOf(0), Double.valueOf(0.5), ValueFactory.newString("json"), "remove_me", Timestamp.ofEpochSecond(0), "string", Boolean.valueOf(true), Long.valueOf(0), Double.valueOf(0.5), ValueFactory.newString("json"), "remove_me"); assertEquals(2, records.size()); Object[] record; { record = records.get(0); assertEquals(6, record.length); assertEquals(Timestamp.ofEpochSecond(0), record[0]); assertEquals("string", record[1]); assertEquals(Boolean.valueOf(true), record[2]); assertEquals(Long.valueOf(0), record[3]); assertEquals(Double.valueOf(0.5), record[4]); assertEquals(ValueFactory.newString("json"), record[5]); } }
Example #5
Source File: EmbulkWriteSupport.java From embulk-output-parquet with MIT License | 5 votes |
@Override public void timestampColumn(Column column) { if (!record.isNull(column)) { Timestamp t = record.getTimestamp(column); String formatted = timestampFormatters[column.getIndex()].format(t); consumer.addBinary(Binary.fromString(formatted)); } }
Example #6
Source File: TestStringCast.java From embulk-parser-jsonl with MIT License | 5 votes |
@Test public void asTimestamp() { Timestamp expected = Timestamp.ofEpochSecond(1463084053, 123456000); TimestampParser parser = new TimestampParser(jruby, "%Y-%m-%d %H:%M:%S.%N", DateTimeZone.UTC); assertEquals(expected, StringCast.asTimestamp("2016-05-12 20:14:13.123456", parser)); try { StringCast.asTimestamp("foo", parser); fail(); } catch (Throwable t) { assertTrue(t instanceof DataException); } }
Example #7
Source File: StringCast.java From embulk-parser-jsonl with MIT License | 5 votes |
public static Timestamp asTimestamp(String value, TimestampParser parser) throws DataException { try { return parser.parse(value); } catch (TimestampParseException ex) { throw new DataException(buildErrorMessage("timestamp", value), ex); } }
Example #8
Source File: TestColumnVisitorImpl.java From embulk-filter-column with MIT License | 5 votes |
@Test public void visit_AddColumns_WithDefault() { PluginTask task = taskFromYamlString( "type: column", "add_columns:", " - {name: timestamp, type: timestamp, default: 2015-07-13, format: \"%Y-%m-%d\", timezone: UTC}", " - {name: string, type: string, default: string}", " - {name: boolean, type: boolean, default: true}", " - {name: long, type: long, default: 0}", " - {name: double, type: double, default: 0.5}", " - {name: json, type: json, default: \"{\\\"foo\\\":\\\"bar\\\"}\" }"); Schema inputSchema = Schema.builder() .add("keep_me", STRING) .build(); List<Object[]> records = filter(task, inputSchema, "keep_me", "keep_me"); assertEquals(2, records.size()); Object[] record; { record = records.get(0); assertEquals(7, record.length); assertEquals("keep_me", record[0]); assertEquals(Timestamp.ofEpochSecond(1436745600), record[1]); assertEquals("string", record[2]); assertEquals(Boolean.valueOf(true), record[3]); assertEquals(Long.valueOf(0), record[4]); assertEquals(Double.valueOf(0.5), record[5]); assertEquals("{\"foo\":\"bar\"}", record[6].toString()); } }
Example #9
Source File: TestColumnVisitorImpl.java From embulk-filter-column with MIT License | 5 votes |
@Test public void visit_DropColumns() { PluginTask task = taskFromYamlString( "type: column", "drop_columns:", " - {name: timestamp}", " - {name: string}", " - {name: boolean}", " - {name: long}", " - {name: double}", " - {name: json}"); Schema inputSchema = Schema.builder() .add("timestamp", TIMESTAMP) .add("string", STRING) .add("boolean", BOOLEAN) .add("long", LONG) .add("double", DOUBLE) .add("json", JSON) .add("keep_me", STRING) .build(); List<Object[]> records = filter(task, inputSchema, Timestamp.ofEpochSecond(1436745600), "string", Boolean.valueOf(true), Long.valueOf(0), Double.valueOf(0.5), ValueFactory.newString("json"), "keep_me", null, null, null, null, null, null, "keep_me"); assertEquals(2, records.size()); Object[] record; { record = records.get(0); assertEquals(1, record.length); assertEquals("keep_me", record[0]); } { record = records.get(1); assertEquals(1, record.length); assertEquals("keep_me", record[0]); } }
Example #10
Source File: JsonCast.java From embulk-parser-jsonl with MIT License | 4 votes |
public static Timestamp asTimestamp(Value value) throws DataException { throw new DataException(buildErrorMessage("timestamp", value)); }
Example #11
Source File: BooleanCast.java From embulk-parser-jsonl with MIT License | 4 votes |
public static Timestamp asTimestamp(boolean value) throws DataException { throw new DataException(buildErrorMessage("timestamp", value)); }
Example #12
Source File: DoubleCast.java From embulk-parser-jsonl with MIT License | 4 votes |
public static Timestamp asTimestamp(double value) throws DataException { long epochSecond = (long) value; long nanoAdjustMent = (long) ((value - epochSecond) * 1000000000); return Timestamp.ofEpochSecond(epochSecond, nanoAdjustMent); }
Example #13
Source File: LongCast.java From embulk-parser-jsonl with MIT License | 4 votes |
public static Timestamp asTimestamp(long value) throws DataException { return Timestamp.ofEpochSecond(value); }
Example #14
Source File: TestLongCast.java From embulk-parser-jsonl with MIT License | 4 votes |
@Test public void asTimestamp() { Timestamp expected = Timestamp.ofEpochSecond(1); assertEquals(expected, LongCast.asTimestamp(1)); }
Example #15
Source File: TestDoubleCast.java From embulk-parser-jsonl with MIT License | 4 votes |
@Test public void asTimestamp() { Timestamp expected = Timestamp.ofEpochSecond(1, 500000000); assertEquals(expected, DoubleCast.asTimestamp(1.5)); }
Example #16
Source File: TestColumnCaster.java From embulk-parser-jsonl with MIT License | 4 votes |
@Test public void asTimestampFromFloat() { Timestamp expected = Timestamp.ofEpochSecond(1463084053, 500000000); assertEquals(expected, ColumnCaster.asTimestamp(ValueFactory.newFloat(1463084053.5), parser)); }
Example #17
Source File: TestColumnCaster.java From embulk-parser-jsonl with MIT License | 4 votes |
@Test public void asTimestampFromString() { Timestamp expected = Timestamp.ofEpochSecond(1463084053, 500000000); assertEquals(expected, ColumnCaster.asTimestamp(ValueFactory.newString("2016-05-12 20:14:13.5"), parser)); }
Example #18
Source File: TestColumnVisitorImpl.java From embulk-filter-column with MIT License | 4 votes |
@Test public void visit_Columns_WithDefault() { PluginTask task = taskFromYamlString( "type: column", "columns:", " - {name: timestamp, type: timestamp, default: 2015-07-13, format: \"%Y-%m-%d\", timezone: UTC}", " - {name: string, type: string, default: string}", " - {name: boolean, type: boolean, default: true}", " - {name: long, type: long, default: 0}", " - {name: double, type: double, default: 0.5}", " - {name: json, type: json, default: \"{\\\"foo\\\":\\\"bar\\\"}\" }"); Schema inputSchema = Schema.builder() .add("timestamp", TIMESTAMP) .add("string", STRING) .add("boolean", BOOLEAN) .add("long", LONG) .add("double", DOUBLE) .add("json", JSON) .add("remove_me", STRING) .build(); List<Object[]> records = filter(task, inputSchema, Timestamp.ofEpochSecond(1436745600), "string", Boolean.valueOf(true), Long.valueOf(0), Double.valueOf(0.5), ValueFactory.newString("json"), "remove_me", null, null, null, null, null, null, "remove_me"); assertEquals(2, records.size()); Object[] record; { record = records.get(0); assertEquals(6, record.length); assertEquals(Timestamp.ofEpochSecond(1436745600), record[0]); assertEquals("string", record[1]); assertEquals(Boolean.valueOf(true), record[2]); assertEquals(Long.valueOf(0), record[3]); assertEquals(Double.valueOf(0.5), record[4]); assertEquals(ValueFactory.newString("json"), record[5]); } { record = records.get(1); assertEquals(6, record.length); assertEquals(Timestamp.ofEpochSecond(1436745600), record[0]); assertEquals("string", record[1]); assertEquals(Boolean.valueOf(true), record[2]); assertEquals(Long.valueOf(0), record[3]); assertEquals(Double.valueOf(0.5), record[4]); assertEquals("{\"foo\":\"bar\"}", record[5].toString()); } }