Search in sources :

Example 1 with LocalZonedTimestampFormatInfo

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

the class TableFormatUtils method deriveFormatInfo.

/**
 * Derive the format information for the given type.
 *
 * @param logicalType The type whose format is derived.
 * @return The format information for the given type.
 */
public static FormatInfo deriveFormatInfo(LogicalType logicalType) {
    if (logicalType instanceof VarCharType) {
        return StringFormatInfo.INSTANCE;
    } else if (logicalType instanceof BooleanType) {
        return BooleanFormatInfo.INSTANCE;
    } else if (logicalType instanceof TinyIntType) {
        return ByteFormatInfo.INSTANCE;
    } else if (logicalType instanceof SmallIntType) {
        return ShortFormatInfo.INSTANCE;
    } else if (logicalType instanceof IntType) {
        return IntFormatInfo.INSTANCE;
    } else if (logicalType instanceof BigIntType) {
        return LongFormatInfo.INSTANCE;
    } else if (logicalType instanceof FloatType) {
        return FloatFormatInfo.INSTANCE;
    } else if (logicalType instanceof DoubleType) {
        return DoubleFormatInfo.INSTANCE;
    } else if (logicalType instanceof DecimalType) {
        return DecimalFormatInfo.INSTANCE;
    } else if (logicalType instanceof DateType) {
        return new DateFormatInfo();
    } else if (logicalType instanceof TimeType) {
        return new TimeFormatInfo();
    } else if (logicalType instanceof TimestampType) {
        return new TimestampFormatInfo();
    } else if (logicalType instanceof LocalZonedTimestampType) {
        return new LocalZonedTimestampFormatInfo();
    } else if (logicalType instanceof ArrayType) {
        ArrayType arrayType = (ArrayType) logicalType;
        LogicalType elementType = arrayType.getElementType();
        FormatInfo elementFormatInfo = deriveFormatInfo(elementType);
        return new ArrayFormatInfo(elementFormatInfo);
    } else if (logicalType instanceof MapType) {
        MapType mapType = (MapType) logicalType;
        LogicalType keyType = mapType.getKeyType();
        LogicalType valueType = mapType.getValueType();
        FormatInfo keyFormatInfo = deriveFormatInfo(keyType);
        FormatInfo valueFormatInfo = deriveFormatInfo(valueType);
        return new MapFormatInfo(keyFormatInfo, valueFormatInfo);
    } else if (logicalType instanceof RowType) {
        RowType rowType = (RowType) logicalType;
        List<RowType.RowField> rowFields = rowType.getFields();
        String[] fieldNames = new String[rowFields.size()];
        FormatInfo[] fieldFormatInfos = new FormatInfo[rowFields.size()];
        for (int i = 0; i < rowFields.size(); ++i) {
            RowType.RowField rowField = rowFields.get(i);
            fieldNames[i] = rowField.getName();
            fieldFormatInfos[i] = deriveFormatInfo(rowField.getType());
        }
        return new RowFormatInfo(fieldNames, fieldFormatInfos);
    } else if (logicalType instanceof BinaryType) {
        return BinaryFormatInfo.INSTANCE;
    } else if (logicalType instanceof NullType) {
        return NullFormatInfo.INSTANCE;
    } 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) LogicalType(org.apache.flink.table.types.logical.LogicalType) RowType(org.apache.flink.table.types.logical.RowType) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) 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) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) List(java.util.List) VarCharType(org.apache.flink.table.types.logical.VarCharType) DateType(org.apache.flink.table.types.logical.DateType) 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) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) DoubleType(org.apache.flink.table.types.logical.DoubleType) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) DecimalType(org.apache.flink.table.types.logical.DecimalType) 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)

Example 2 with LocalZonedTimestampFormatInfo

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

ArrayType (org.apache.flink.table.types.logical.ArrayType)2 BigIntType (org.apache.flink.table.types.logical.BigIntType)2 BinaryType (org.apache.flink.table.types.logical.BinaryType)2 BooleanType (org.apache.flink.table.types.logical.BooleanType)2 DateType (org.apache.flink.table.types.logical.DateType)2 DecimalType (org.apache.flink.table.types.logical.DecimalType)2 DoubleType (org.apache.flink.table.types.logical.DoubleType)2 FloatType (org.apache.flink.table.types.logical.FloatType)2 IntType (org.apache.flink.table.types.logical.IntType)2 LocalZonedTimestampType (org.apache.flink.table.types.logical.LocalZonedTimestampType)2 MapType (org.apache.flink.table.types.logical.MapType)2 NullType (org.apache.flink.table.types.logical.NullType)2 SmallIntType (org.apache.flink.table.types.logical.SmallIntType)2 TimeType (org.apache.flink.table.types.logical.TimeType)2 TimestampType (org.apache.flink.table.types.logical.TimestampType)2 TinyIntType (org.apache.flink.table.types.logical.TinyIntType)2 VarCharType (org.apache.flink.table.types.logical.VarCharType)2 ArrayFormatInfo (org.apache.inlong.sort.formats.common.ArrayFormatInfo)2 BasicFormatInfo (org.apache.inlong.sort.formats.common.BasicFormatInfo)2 BinaryFormatInfo (org.apache.inlong.sort.formats.common.BinaryFormatInfo)2