use of org.apache.inlong.sort.formats.common.TimeFormatInfo in project incubator-inlong by apache.
the class KvDeserializationSchemaTest method testNormal.
@Test
public void testNormal() throws Exception {
Consumer<KvDeserializationSchema.Builder> config = builder -> {
};
testBasicDeserialization(config, StringFormatInfo.INSTANCE, "hello", "f=hello");
testBasicDeserialization(config, BooleanFormatInfo.INSTANCE, true, "f=true");
testBasicDeserialization(config, ByteFormatInfo.INSTANCE, (byte) 124, "f=124");
testBasicDeserialization(config, ShortFormatInfo.INSTANCE, (short) 10000, "f=10000");
testBasicDeserialization(config, IntFormatInfo.INSTANCE, 1234567, "f=1234567");
testBasicDeserialization(config, LongFormatInfo.INSTANCE, 12345678910L, "f=12345678910");
testBasicDeserialization(config, FloatFormatInfo.INSTANCE, 0.33333334f, "f=0.33333334");
testBasicDeserialization(config, DoubleFormatInfo.INSTANCE, 0.33333333332, "f=0.33333333332");
testBasicDeserialization(config, DecimalFormatInfo.INSTANCE, new BigDecimal("1234.0000000000000000000000001"), "f=1234.0000000000000000000000001");
testBasicDeserialization(config, new DateFormatInfo("dd/MM/yyyy"), Date.valueOf("2020-03-22"), "f=22/03/2020");
testBasicDeserialization(config, new TimeFormatInfo("ss/mm/hh"), Time.valueOf("11:12:13"), "f=13/12/11");
testBasicDeserialization(config, new TimestampFormatInfo("dd/MM/yyyy hh:mm:ss"), Timestamp.valueOf("2020-03-22 11:12:13"), "f=22/03/2020 11:12:13");
}
use of org.apache.inlong.sort.formats.common.TimeFormatInfo in project incubator-inlong by apache.
the class CustomDateFormatSerializationSchemaWrapperTest method testFromDateAndTimeToString.
@Test
public void testFromDateAndTimeToString() throws IOException, ClassNotFoundException {
FieldInfo[] fieldInfos = new FieldInfo[] { new FieldInfo("f1", new DateFormatInfo()), new FieldInfo("f2", new TimeFormatInfo()), new FieldInfo("f3", new TimestampFormatInfo()), new FieldInfo("f4", IntFormatInfo.INSTANCE) };
SerializationSchema<Row> stringSchema = SerializationSchemaFactory.build(fieldInfos, null);
CustomDateFormatSerializationSchemaWrapper schemaWrapper = new CustomDateFormatSerializationSchemaWrapper(stringSchema, extractFormatInfos(fieldInfos));
Row testRow = Row.of(Date.valueOf("2022-02-15"), Time.valueOf("15:52:30"), Timestamp.valueOf("2022-02-15 15:52:30"), 1);
Row resultRow = schemaWrapper.fromDateAndTimeToString(testRow);
assertTrue(resultRow.getField(0) instanceof String);
assertTrue(resultRow.getField(1) instanceof String);
assertTrue(resultRow.getField(2) instanceof String);
Row expectedRow = Row.of("2022-02-15", "15:52:30", "2022-02-15 15:52:30", 1);
assertEquals(expectedRow, resultRow);
}
use of org.apache.inlong.sort.formats.common.TimeFormatInfo in project incubator-inlong by apache.
the class KvDeserializationSchemaTest method testNullIteral.
@Test
public void testNullIteral() throws Exception {
String nullLiteral = "n/a";
String nullField = "f=n/a";
Consumer<KvDeserializationSchema.Builder> config = builder -> builder.setNullLiteral(nullLiteral);
testBasicDeserialization(config, StringFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, BooleanFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, ByteFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, ShortFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, IntFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, LongFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, FloatFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, DoubleFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, DecimalFormatInfo.INSTANCE, null, nullField);
testBasicDeserialization(config, new DateFormatInfo("dd/MM/yyyy"), null, nullField);
testBasicDeserialization(config, new TimeFormatInfo("ss/mm/hh"), null, nullField);
testBasicDeserialization(config, new TimestampFormatInfo("dd/MM/yyyy hh:mm:ss"), null, nullField);
}
use of org.apache.inlong.sort.formats.common.TimeFormatInfo in project incubator-inlong by apache.
the class KvSerializationSchemaTest method testNullIteral.
@Test
public void testNullIteral() {
String nullLiteral = "n/a";
String nullField = "f=n/a";
Consumer<KvSerializationSchema.Builder> config = builder -> builder.setNullLiteral(nullLiteral);
testBasicSerialization(config, StringFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, BooleanFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, ByteFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, ShortFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, IntFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, LongFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, FloatFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, DoubleFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, DecimalFormatInfo.INSTANCE, null, nullField);
testBasicSerialization(config, new DateFormatInfo("dd/MM/yyyy"), null, nullField);
testBasicSerialization(config, new TimeFormatInfo("ss/mm/hh"), null, nullField);
testBasicSerialization(config, new TimestampFormatInfo("dd/MM/yyyy hh:mm:ss"), null, nullField);
}
use of org.apache.inlong.sort.formats.common.TimeFormatInfo in project incubator-inlong by apache.
the class KvSerializationSchemaTest method testNormal.
@Test
public void testNormal() {
Consumer<KvSerializationSchema.Builder> config = builder -> {
};
testBasicSerialization(config, StringFormatInfo.INSTANCE, "hello", "f=hello");
testBasicSerialization(config, BooleanFormatInfo.INSTANCE, true, "f=true");
testBasicSerialization(config, ByteFormatInfo.INSTANCE, (byte) 124, "f=124");
testBasicSerialization(config, ShortFormatInfo.INSTANCE, (short) 10000, "f=10000");
testBasicSerialization(config, IntFormatInfo.INSTANCE, 1234567, "f=1234567");
testBasicSerialization(config, LongFormatInfo.INSTANCE, 12345678910L, "f=12345678910");
testBasicSerialization(config, FloatFormatInfo.INSTANCE, 0.33333334f, "f=0.33333334");
testBasicSerialization(config, DoubleFormatInfo.INSTANCE, 0.33333333332, "f=0.33333333332");
testBasicSerialization(config, DecimalFormatInfo.INSTANCE, new BigDecimal("1234.0000000000000000000000001"), "f=1234.0000000000000000000000001");
testBasicSerialization(config, new DateFormatInfo("dd/MM/yyyy"), Date.valueOf("2020-03-22"), "f=22/03/2020");
testBasicSerialization(config, new TimeFormatInfo("ss/mm/hh"), Time.valueOf("11:12:13"), "f=13/12/11");
testBasicSerialization(config, new TimestampFormatInfo("dd/MM/yyyy hh:mm:ss"), Timestamp.valueOf("2020-03-22 11:12:13"), "f=22/03/2020 11:12:13");
}
Aggregations