/** date by timestamp. */ @SuppressWarnings("deprecation") @Test public void date_by_timestamp() { ValueSerde serde = TimestampValueSerdeFactory.DATE; TimestampObjectInspector inspector = (TimestampObjectInspector) serde.getInspector(); DateOption option = new DateOption(new Date(2014, 7, 1)); Timestamp value = new Timestamp(2014 - 1900, 7 - 1, 1, 0, 0, 0, 0); assertThat(inspector.copyObject(option), is((Object) option)); assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option)))); assertThat(inspector.copyObject(null), is(nullValue())); assertThat(inspector.getPrimitiveJavaObject(option), is(value)); assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue())); assertThat(inspector.getPrimitiveWritableObject(option), is(new TimestampWritable(value))); assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue())); ValueDriver driver = serde.getDriver(inspector); DateOption copy = new DateOption(); driver.set(copy, option); assertThat(copy, is(option)); driver.set(copy, null); assertThat(copy.isNull(), is(true)); }
@SuppressWarnings("deprecation") private void fill0(DateOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { int value = dateFormat.parse(lineBuffer); if (value < 0) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException( createStatusInLine(Reason.INVALID_CELL_FORMAT, dateFormat.getPattern()), null); } option.modify(value); } else { option.setNull(); } }
@Override public void emit(DateOption option) throws IOException { startCell(); if (emitNull(option)) { return; } int days = option.get().getElapsedDays(); emitDate(days); }
/** date by string. */ @Test public void date_by_string() { ValueSerde serde = StringValueSerdeFactory.DATE; StringObjectInspector inspector = (StringObjectInspector) serde.getInspector(); DateOption option = new DateOption(new Date(2014, 7, 1)); String value = "2014-07-01"; assertThat(inspector.copyObject(option), is((Object) option)); assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option)))); assertThat(inspector.copyObject(null), is(nullValue())); assertThat(inspector.getPrimitiveJavaObject(option), is(value)); assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue())); assertThat(inspector.getPrimitiveWritableObject(option), is(new Text(value))); assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue())); ValueDriver driver = serde.getDriver(inspector); DateOption copy = new DateOption(); driver.set(copy, option); assertThat(copy, is(option)); driver.set(copy, null); assertThat(copy.isNull(), is(true)); }