Search in sources :

Example 6 with TimeFormatInfo

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");
}
Also used : Time(java.sql.Time) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BigDecimal(java.math.BigDecimal) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Timestamp(java.sql.Timestamp) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) IOException(java.io.IOException) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) Date(java.sql.Date) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) Consumer(java.util.function.Consumer) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) Row(org.apache.flink.types.Row) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) Assert.assertEquals(org.junit.Assert.assertEquals) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with TimeFormatInfo

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);
}
Also used : DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Row(org.apache.flink.types.Row) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) Test(org.junit.Test)

Example 8 with TimeFormatInfo

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);
}
Also used : Time(java.sql.Time) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BigDecimal(java.math.BigDecimal) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Timestamp(java.sql.Timestamp) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) IOException(java.io.IOException) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) Date(java.sql.Date) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) Consumer(java.util.function.Consumer) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) Row(org.apache.flink.types.Row) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) Assert.assertEquals(org.junit.Assert.assertEquals) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Test(org.junit.Test)

Example 9 with TimeFormatInfo

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);
}
Also used : Time(java.sql.Time) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BigDecimal(java.math.BigDecimal) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Timestamp(java.sql.Timestamp) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) Date(java.sql.Date) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) Consumer(java.util.function.Consumer) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) Row(org.apache.flink.types.Row) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) Assert.assertEquals(org.junit.Assert.assertEquals) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Test(org.junit.Test)

Example 10 with TimeFormatInfo

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");
}
Also used : Time(java.sql.Time) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BigDecimal(java.math.BigDecimal) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) Timestamp(java.sql.Timestamp) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) Date(java.sql.Date) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) Consumer(java.util.function.Consumer) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) Row(org.apache.flink.types.Row) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) Assert.assertEquals(org.junit.Assert.assertEquals) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

DateFormatInfo (org.apache.inlong.sort.formats.common.DateFormatInfo)12 TimeFormatInfo (org.apache.inlong.sort.formats.common.TimeFormatInfo)12 TimestampFormatInfo (org.apache.inlong.sort.formats.common.TimestampFormatInfo)12 Row (org.apache.flink.types.Row)10 BasicFormatInfo (org.apache.inlong.sort.formats.common.BasicFormatInfo)10 BooleanFormatInfo (org.apache.inlong.sort.formats.common.BooleanFormatInfo)10 ByteFormatInfo (org.apache.inlong.sort.formats.common.ByteFormatInfo)10 DecimalFormatInfo (org.apache.inlong.sort.formats.common.DecimalFormatInfo)10 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)10 FloatFormatInfo (org.apache.inlong.sort.formats.common.FloatFormatInfo)10 FormatInfo (org.apache.inlong.sort.formats.common.FormatInfo)10 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)10 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)10 RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)10 ShortFormatInfo (org.apache.inlong.sort.formats.common.ShortFormatInfo)10 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)10 Test (org.junit.Test)10 Date (java.sql.Date)9 Time (java.sql.Time)9 Timestamp (java.sql.Timestamp)9