Search in sources :

Example 11 with TimestampFormatInfo

use of org.apache.inlong.sort.formats.common.TimestampFormatInfo 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 12 with TimestampFormatInfo

use of org.apache.inlong.sort.formats.common.TimestampFormatInfo 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)

Example 13 with TimestampFormatInfo

use of org.apache.inlong.sort.formats.common.TimestampFormatInfo in project incubator-inlong by apache.

the class CsvDeserializationSchemaTest method testNormal.

@Test
public void testNormal() throws Exception {
    Consumer<CsvDeserializationSchema.Builder> config = builder -> {
    };
    testBasicDeserialization(config, StringFormatInfo.INSTANCE, "hello", "hello");
    testBasicDeserialization(config, BooleanFormatInfo.INSTANCE, true, "true");
    testBasicDeserialization(config, ByteFormatInfo.INSTANCE, (byte) 124, "124");
    testBasicDeserialization(config, ShortFormatInfo.INSTANCE, (short) 10000, "10000");
    testBasicDeserialization(config, IntFormatInfo.INSTANCE, 1234567, "1234567");
    testBasicDeserialization(config, LongFormatInfo.INSTANCE, 12345678910L, "12345678910");
    testBasicDeserialization(config, FloatFormatInfo.INSTANCE, 0.33333334f, "0.33333334");
    testBasicDeserialization(config, DoubleFormatInfo.INSTANCE, 0.33333333332, "0.33333333332");
    testBasicDeserialization(config, DecimalFormatInfo.INSTANCE, new BigDecimal("1234.0000000000000000000000001"), "1234.0000000000000000000000001");
    testBasicDeserialization(config, new DateFormatInfo("dd/MM/yyyy"), Date.valueOf("2020-03-22"), "22/03/2020");
    testBasicDeserialization(config, new TimeFormatInfo("ss/mm/hh"), Time.valueOf("11:12:13"), "13/12/11");
    testBasicDeserialization(config, new TimestampFormatInfo("dd/MM/yyyy hh:mm:ss"), Timestamp.valueOf("2020-03-22 11:12:13"), "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 14 with TimestampFormatInfo

use of org.apache.inlong.sort.formats.common.TimestampFormatInfo in project incubator-inlong by apache.

the class FieldMappingTransformerTest method testTransformWithDt.

@Test
public void testTransformWithDt() throws Exception {
    final FieldInfo fieldInfo = new FieldInfo("id", new LongFormatInfo());
    final FieldInfo dtFieldInfo = new BuiltInFieldInfo("dt", new TimestampFormatInfo(), BuiltInField.DATA_TIME);
    final SourceInfo sourceInfo = new TestingSourceInfo(new FieldInfo[] { fieldInfo, dtFieldInfo });
    final SinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { fieldInfo, dtFieldInfo });
    final long dataFlowId = 1L;
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(dataFlowId, sourceInfo, sinkInfo);
    final FieldMappingTransformer transformer = new FieldMappingTransformer(new Configuration());
    transformer.addDataFlow(dataFlowInfo);
    // should be 3 fields (1 origin fields + time + attr)
    final Row sourceRow = new Row(1 + SOURCE_FIELD_SKIP_STEP);
    final long dt = System.currentTimeMillis();
    sourceRow.setField(0, dt);
    sourceRow.setField(1, "attr");
    sourceRow.setField(2, 9527L);
    final Record sourceRecord = new Record(dataFlowId, dt, sourceRow);
    final Record sinkRecord = transformer.transform(sourceRecord);
    assertEquals(dataFlowId, sinkRecord.getDataflowId());
    assertEquals(2, sinkRecord.getRow().getArity());
    assertEquals(9527L, sinkRecord.getRow().getField(0));
    assertEquals(new Timestamp(dt), sinkRecord.getRow().getField(1));
}
Also used : TestingSourceInfo(org.apache.inlong.sort.util.TestingUtils.TestingSourceInfo) SourceInfo(org.apache.inlong.sort.protocol.source.SourceInfo) TestingSourceInfo(org.apache.inlong.sort.util.TestingUtils.TestingSourceInfo) Configuration(org.apache.inlong.sort.configuration.Configuration) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) SinkInfo(org.apache.inlong.sort.protocol.sink.SinkInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Timestamp(java.sql.Timestamp) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 15 with TimestampFormatInfo

use of org.apache.inlong.sort.formats.common.TimestampFormatInfo in project incubator-inlong by apache.

the class TableFormatUtils method deriveLogicalType.

/**
 * Derive the LogicalType for the given FormatInfo.
 */
public static LogicalType deriveLogicalType(FormatInfo formatInfo) {
    if (formatInfo instanceof StringFormatInfo) {
        return new VarCharType();
    } else if (formatInfo instanceof BooleanFormatInfo) {
        return new BooleanType();
    } else if (formatInfo instanceof ByteFormatInfo) {
        return new TinyIntType();
    } else if (formatInfo instanceof ShortFormatInfo) {
        return new SmallIntType();
    } else if (formatInfo instanceof IntFormatInfo) {
        return new IntType();
    } else if (formatInfo instanceof LongFormatInfo) {
        return new BigIntType();
    } else if (formatInfo instanceof FloatFormatInfo) {
        return new FloatType();
    } else if (formatInfo instanceof DoubleFormatInfo) {
        return new DoubleType();
    } else if (formatInfo instanceof DecimalFormatInfo) {
        return new DecimalType();
    } else if (formatInfo instanceof TimeFormatInfo) {
        return new TimeType();
    } else if (formatInfo instanceof DateFormatInfo) {
        return new DateType();
    } else if (formatInfo instanceof TimestampFormatInfo) {
        return new TimestampType(DEFAULT_PRECISION_FOR_TIMESTAMP);
    } else if (formatInfo instanceof LocalZonedTimestampFormatInfo) {
        return new LocalZonedTimestampType();
    } else if (formatInfo instanceof ArrayFormatInfo) {
        FormatInfo elementFormatInfo = ((ArrayFormatInfo) formatInfo).getElementFormatInfo();
        return new ArrayType(deriveLogicalType(elementFormatInfo));
    } else if (formatInfo instanceof MapFormatInfo) {
        MapFormatInfo mapFormatInfo = (MapFormatInfo) formatInfo;
        FormatInfo keyFormatInfo = mapFormatInfo.getKeyFormatInfo();
        FormatInfo valueFormatInfo = mapFormatInfo.getValueFormatInfo();
        return new MapType(deriveLogicalType(keyFormatInfo), deriveLogicalType(valueFormatInfo));
    } else if (formatInfo instanceof RowFormatInfo) {
        RowFormatInfo rowFormatInfo = (RowFormatInfo) formatInfo;
        FormatInfo[] formatInfos = rowFormatInfo.getFieldFormatInfos();
        int formatInfosSize = formatInfos.length;
        LogicalType[] logicalTypes = new LogicalType[formatInfosSize];
        for (int i = 0; i < formatInfosSize; ++i) {
            logicalTypes[i] = deriveLogicalType(formatInfos[i]);
        }
        return RowType.of(logicalTypes, rowFormatInfo.getFieldNames());
    } else if (formatInfo instanceof BinaryFormatInfo) {
        return new BinaryType();
    } else if (formatInfo instanceof NullFormatInfo) {
        return new NullType();
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) BigIntType(org.apache.flink.table.types.logical.BigIntType) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) MapType(org.apache.flink.table.types.logical.MapType) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) FloatType(org.apache.flink.table.types.logical.FloatType) TimeType(org.apache.flink.table.types.logical.TimeType) ArrayType(org.apache.flink.table.types.logical.ArrayType) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) VarCharType(org.apache.flink.table.types.logical.VarCharType) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) DateType(org.apache.flink.table.types.logical.DateType) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) BinaryType(org.apache.flink.table.types.logical.BinaryType) BooleanType(org.apache.flink.table.types.logical.BooleanType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) DoubleType(org.apache.flink.table.types.logical.DoubleType) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) DecimalType(org.apache.flink.table.types.logical.DecimalType) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) NullType(org.apache.flink.table.types.logical.NullType) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo)

Aggregations

TimestampFormatInfo (org.apache.inlong.sort.formats.common.TimestampFormatInfo)16 Row (org.apache.flink.types.Row)12 DateFormatInfo (org.apache.inlong.sort.formats.common.DateFormatInfo)12 TimeFormatInfo (org.apache.inlong.sort.formats.common.TimeFormatInfo)12 Test (org.junit.Test)12 Timestamp (java.sql.Timestamp)11 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)11 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)11 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 RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)10 ShortFormatInfo (org.apache.inlong.sort.formats.common.ShortFormatInfo)10 Date (java.sql.Date)9 Time (java.sql.Time)9