org.apache.flink.api.common.typeutils.base.SqlTimestampSerializer Java Examples

The following examples show how to use org.apache.flink.api.common.typeutils.base.SqlTimestampSerializer. 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: BinaryRowTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateAndTimeAsGenericObject() {
	BinaryRow row = new BinaryRow(7);
	BinaryRowWriter writer = new BinaryRowWriter(row);

	LocalDate localDate = LocalDate.of(2019, 7, 16);
	LocalTime localTime = LocalTime.of(17, 31);
	LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);

	writer.writeInt(0, 0);
	writer.writeGeneric(1, new BinaryGeneric<>(new Date(123), SqlDateSerializer.INSTANCE));
	writer.writeGeneric(2, new BinaryGeneric<>(new Time(456), SqlTimeSerializer.INSTANCE));
	writer.writeGeneric(3, new BinaryGeneric<>(new Timestamp(789), SqlTimestampSerializer.INSTANCE));
	writer.writeGeneric(4, new BinaryGeneric<>(localDate, LocalDateSerializer.INSTANCE));
	writer.writeGeneric(5, new BinaryGeneric<>(localTime, LocalTimeSerializer.INSTANCE));
	writer.writeGeneric(6, new BinaryGeneric<>(localDateTime, LocalDateTimeSerializer.INSTANCE));
	writer.complete();

	assertEquals(new Date(123), BinaryGeneric.getJavaObjectFromBinaryGeneric(
		row.getGeneric(1), SqlDateSerializer.INSTANCE));
	assertEquals(new Time(456), BinaryGeneric.getJavaObjectFromBinaryGeneric(
		row.getGeneric(2), SqlTimeSerializer.INSTANCE));
	assertEquals(new Timestamp(789), BinaryGeneric.getJavaObjectFromBinaryGeneric(
		row.getGeneric(3), SqlTimestampSerializer.INSTANCE));
	assertEquals(localDate, BinaryGeneric.getJavaObjectFromBinaryGeneric(
		row.getGeneric(4), LocalDateSerializer.INSTANCE));
	assertEquals(localTime, BinaryGeneric.getJavaObjectFromBinaryGeneric(
		row.getGeneric(5), LocalTimeSerializer.INSTANCE));
	assertEquals(localDateTime, BinaryGeneric.getJavaObjectFromBinaryGeneric(
		row.getGeneric(6), LocalDateTimeSerializer.INSTANCE));
}
 
Example #2
Source File: LegacyTimestampTypeInfo.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public LegacyTimestampTypeInfo(int precision) {
	super(
		Timestamp.class,
		SqlTimestampSerializer.INSTANCE,
		(Class) SqlTimestampComparator.class);
	this.precision = precision;
}
 
Example #3
Source File: TimeIndicatorTypeInfo.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected TimeIndicatorTypeInfo(boolean isEventTime) {
	super(Timestamp.class, SqlTimestampSerializer.INSTANCE, (Class) SqlTimestampComparator.class);
	this.isEventTime = isEventTime;
}
 
Example #4
Source File: BinaryRowDataTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testDateAndTimeAsGenericObject() {
	BinaryRowData row = new BinaryRowData(7);
	BinaryRowWriter writer = new BinaryRowWriter(row);

	LocalDate localDate = LocalDate.of(2019, 7, 16);
	LocalTime localTime = LocalTime.of(17, 31);
	LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);

	writer.writeInt(0, 0);
	writer.writeRawValue(
		1,
		RawValueData.fromObject(new Date(123)),
		new RawValueDataSerializer<>(SqlDateSerializer.INSTANCE));
	writer.writeRawValue(
		2,
		RawValueData.fromObject(new Time(456)),
		new RawValueDataSerializer<>(SqlTimeSerializer.INSTANCE));
	writer.writeRawValue(
		3,
		RawValueData.fromObject(new Timestamp(789)),
		new RawValueDataSerializer<>(SqlTimestampSerializer.INSTANCE));
	writer.writeRawValue(
		4,
		RawValueData.fromObject(localDate),
		new RawValueDataSerializer<>(LocalDateSerializer.INSTANCE));
	writer.writeRawValue(
		5,
		RawValueData.fromObject(localTime),
		new RawValueDataSerializer<>(LocalTimeSerializer.INSTANCE));
	writer.writeRawValue(
		6,
		RawValueData.fromObject(localDateTime),
		new RawValueDataSerializer<>(LocalDateTimeSerializer.INSTANCE));
	writer.complete();

	assertEquals(new Date(123), row.<Date>getRawValue(1).toObject(SqlDateSerializer.INSTANCE));
	assertEquals(new Time(456), row.<Time>getRawValue(2).toObject(SqlTimeSerializer.INSTANCE));
	assertEquals(new Timestamp(789), row.<Timestamp>getRawValue(3).toObject(SqlTimestampSerializer.INSTANCE));
	assertEquals(localDate, row.<LocalDate>getRawValue(4).toObject(LocalDateSerializer.INSTANCE));
	assertEquals(localTime, row.<LocalTime>getRawValue(5).toObject(LocalTimeSerializer.INSTANCE));
	assertEquals(localDateTime, row.<LocalDateTime>getRawValue(6).toObject(LocalDateTimeSerializer.INSTANCE));
}
 
Example #5
Source File: TimeIndicatorTypeInfo.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected TimeIndicatorTypeInfo(boolean isEventTime) {
	super(Timestamp.class, SqlTimestampSerializer.INSTANCE, (Class) SqlTimestampComparator.class);
	this.isEventTime = isEventTime;
}