Search in sources :

Example 1 with TimeType

use of org.apache.flink.table.types.logical.TimeType in project flink by apache.

the class LogicalTypeMerging method findCommonNullableType.

@SuppressWarnings("ConstantConditions")
@Nullable
private static LogicalType findCommonNullableType(List<LogicalType> normalizedTypes, boolean hasRawType, boolean hasNullType) {
    // all RAW types must be equal
    if (hasRawType) {
        return findExactlySameType(normalizedTypes);
    }
    LogicalType resultType = null;
    for (LogicalType type : normalizedTypes) {
        final LogicalTypeRoot typeRoot = type.getTypeRoot();
        // NULL does not affect the result of this loop
        if (typeRoot == NULL) {
            continue;
        }
        // result type candidate
        if (resultType == null) {
            resultType = type;
        }
        // find special patterns
        final LogicalType patternType = findCommonTypePattern(resultType, type);
        if (patternType != null) {
            resultType = patternType;
            continue;
        }
        // for types of family CONSTRUCTED
        if (typeRoot == ARRAY) {
            return findCommonArrayType(normalizedTypes);
        } else if (typeRoot == MULTISET) {
            return findCommonMultisetType(normalizedTypes);
        } else if (typeRoot == MAP) {
            return findCommonMapType(normalizedTypes);
        } else if (typeRoot == ROW) {
            return findCommonRowType(normalizedTypes);
        }
        // this simplifies the following lines as we compare same interval families for example
        if (!areSimilarTypes(resultType, type)) {
            return null;
        }
        // for types of family CHARACTER_STRING or BINARY_STRING
        if (type.is(CHARACTER_STRING) | type.is(BINARY_STRING)) {
            final int length = combineLength(resultType, type);
            if (resultType.isAnyOf(VARCHAR, VARBINARY)) {
                // variable length types remain variable length types
                resultType = createStringType(resultType.getTypeRoot(), length);
            } else if (getLength(resultType) != getLength(type)) {
                // padding/modification of strings
                if (resultType.is(CHAR)) {
                    resultType = createStringType(VARCHAR, length);
                } else if (resultType.is(BINARY)) {
                    resultType = createStringType(VARBINARY, length);
                }
            } else {
                // for same type with same length
                resultType = createStringType(typeRoot, length);
            }
        } else // for EXACT_NUMERIC types
        if (type.is(EXACT_NUMERIC)) {
            if (resultType.is(EXACT_NUMERIC)) {
                resultType = createCommonExactNumericType(resultType, type);
            } else if (resultType.is(APPROXIMATE_NUMERIC)) {
                // the result is already approximate
                if (typeRoot == DECIMAL) {
                    // in case of DECIMAL we enforce DOUBLE
                    resultType = new DoubleType();
                }
            } else {
                return null;
            }
        } else // for APPROXIMATE_NUMERIC types
        if (type.is(APPROXIMATE_NUMERIC)) {
            if (resultType.is(APPROXIMATE_NUMERIC)) {
                resultType = createCommonApproximateNumericType(resultType, type);
            } else if (resultType.is(EXACT_NUMERIC)) {
                // the result was exact so far
                if (typeRoot == DECIMAL) {
                    // in case of DECIMAL we enforce DOUBLE
                    resultType = new DoubleType();
                } else {
                    // enforce an approximate result
                    resultType = type;
                }
            } else {
                return null;
            }
        } else // for DATE
        if (type.is(DATE)) {
            if (resultType.is(DATE)) {
                // for enabling findCommonTypePattern
                resultType = new DateType();
            } else {
                return null;
            }
        } else // for TIME
        if (type.is(TIME)) {
            if (resultType.is(TIME)) {
                resultType = new TimeType(combinePrecision(resultType, type));
            } else {
                return null;
            }
        } else // for TIMESTAMP
        if (type.is(TIMESTAMP)) {
            if (resultType.is(TIMESTAMP)) {
                resultType = createCommonTimestampType(resultType, type);
            } else {
                return null;
            }
        } else // for day-time intervals
        if (typeRoot == INTERVAL_DAY_TIME) {
            resultType = createCommonDayTimeIntervalType((DayTimeIntervalType) resultType, (DayTimeIntervalType) type);
        } else // for year-month intervals
        if (typeRoot == INTERVAL_YEAR_MONTH) {
            resultType = createCommonYearMonthIntervalType((YearMonthIntervalType) resultType, (YearMonthIntervalType) type);
        } else // other types are handled by findCommonCastableType
        {
            return null;
        }
    }
    // NULL type only
    if (resultType == null && hasNullType) {
        return new NullType();
    }
    return resultType;
}
Also used : DoubleType(org.apache.flink.table.types.logical.DoubleType) LogicalType(org.apache.flink.table.types.logical.LogicalType) LogicalTypeRoot(org.apache.flink.table.types.logical.LogicalTypeRoot) NullType(org.apache.flink.table.types.logical.NullType) DateType(org.apache.flink.table.types.logical.DateType) TimeType(org.apache.flink.table.types.logical.TimeType) DayTimeIntervalType(org.apache.flink.table.types.logical.DayTimeIntervalType) Nullable(javax.annotation.Nullable)

Example 2 with TimeType

use of org.apache.flink.table.types.logical.TimeType in project flink by apache.

the class LogicalTypeJsonSerdeTest method testLogicalTypeSerde.

private static List<LogicalType> testLogicalTypeSerde() {
    final List<LogicalType> types = Arrays.asList(new BooleanType(), new TinyIntType(), new SmallIntType(), new IntType(), new BigIntType(), new FloatType(), new DoubleType(), new DecimalType(10), new DecimalType(15, 5), CharType.ofEmptyLiteral(), new CharType(), new CharType(5), VarCharType.ofEmptyLiteral(), new VarCharType(), new VarCharType(5), BinaryType.ofEmptyLiteral(), new BinaryType(), new BinaryType(100), VarBinaryType.ofEmptyLiteral(), new VarBinaryType(), new VarBinaryType(100), new DateType(), new TimeType(), new TimeType(3), new TimestampType(), new TimestampType(3), new LocalZonedTimestampType(false, TimestampKind.PROCTIME, 3), new TimestampType(false, TimestampKind.ROWTIME, 3), new ZonedTimestampType(), new ZonedTimestampType(3), new ZonedTimestampType(false, TimestampKind.ROWTIME, 3), new LocalZonedTimestampType(), new LocalZonedTimestampType(3), new LocalZonedTimestampType(false, TimestampKind.PROCTIME, 3), new LocalZonedTimestampType(false, TimestampKind.ROWTIME, 3), new DayTimeIntervalType(DayTimeIntervalType.DayTimeResolution.DAY_TO_HOUR), new DayTimeIntervalType(false, DayTimeIntervalType.DayTimeResolution.DAY_TO_HOUR, 3, 6), new YearMonthIntervalType(YearMonthIntervalType.YearMonthResolution.YEAR_TO_MONTH), new YearMonthIntervalType(false, YearMonthIntervalType.YearMonthResolution.MONTH, 2), new ZonedTimestampType(), new LocalZonedTimestampType(), new LocalZonedTimestampType(false, TimestampKind.PROCTIME, 3), new SymbolType<>(), new ArrayType(new IntType(false)), new ArrayType(new LocalZonedTimestampType(false, TimestampKind.ROWTIME, 3)), new ArrayType(new ZonedTimestampType(false, TimestampKind.ROWTIME, 3)), new ArrayType(new TimestampType()), new ArrayType(CharType.ofEmptyLiteral()), new ArrayType(VarCharType.ofEmptyLiteral()), new ArrayType(BinaryType.ofEmptyLiteral()), new ArrayType(VarBinaryType.ofEmptyLiteral()), new MapType(new BigIntType(), new IntType(false)), new MapType(new TimestampType(false, TimestampKind.ROWTIME, 3), new ZonedTimestampType()), new MapType(CharType.ofEmptyLiteral(), CharType.ofEmptyLiteral()), new MapType(VarCharType.ofEmptyLiteral(), VarCharType.ofEmptyLiteral()), new MapType(BinaryType.ofEmptyLiteral(), BinaryType.ofEmptyLiteral()), new MapType(VarBinaryType.ofEmptyLiteral(), VarBinaryType.ofEmptyLiteral()), new MultisetType(new IntType(false)), new MultisetType(new TimestampType()), new MultisetType(new TimestampType(true, TimestampKind.ROWTIME, 3)), new MultisetType(CharType.ofEmptyLiteral()), new MultisetType(VarCharType.ofEmptyLiteral()), new MultisetType(BinaryType.ofEmptyLiteral()), new MultisetType(VarBinaryType.ofEmptyLiteral()), RowType.of(new BigIntType(), new IntType(false), new VarCharType(200)), RowType.of(new LogicalType[] { new BigIntType(), new IntType(false), new VarCharType(200) }, new String[] { "f1", "f2", "f3" }), RowType.of(new TimestampType(false, TimestampKind.ROWTIME, 3), new TimestampType(false, TimestampKind.REGULAR, 3), new ZonedTimestampType(false, TimestampKind.ROWTIME, 3), new ZonedTimestampType(false, TimestampKind.REGULAR, 3), new LocalZonedTimestampType(false, TimestampKind.ROWTIME, 3), new LocalZonedTimestampType(false, TimestampKind.PROCTIME, 3), new LocalZonedTimestampType(false, TimestampKind.REGULAR, 3)), RowType.of(CharType.ofEmptyLiteral(), VarCharType.ofEmptyLiteral(), BinaryType.ofEmptyLiteral(), VarBinaryType.ofEmptyLiteral()), // registered structured type
    StructuredType.newBuilder(ObjectIdentifier.of("cat", "db", "structuredType"), PojoClass.class).attributes(Arrays.asList(new StructuredType.StructuredAttribute("f0", new IntType(true)), new StructuredType.StructuredAttribute("f1", new BigIntType(true)), new StructuredType.StructuredAttribute("f2", new VarCharType(200), "desc"))).comparison(StructuredType.StructuredComparison.FULL).setFinal(false).setInstantiable(false).superType(StructuredType.newBuilder(ObjectIdentifier.of("cat", "db", "structuredType2")).attributes(Collections.singletonList(new StructuredType.StructuredAttribute("f0", new BigIntType(false)))).build()).description("description for StructuredType").build(), // unregistered structured type
    StructuredType.newBuilder(PojoClass.class).attributes(Arrays.asList(new StructuredType.StructuredAttribute("f0", new IntType(true)), new StructuredType.StructuredAttribute("f1", new BigIntType(true)), new StructuredType.StructuredAttribute("f2", new VarCharType(200), "desc"))).build(), // registered distinct type
    DistinctType.newBuilder(ObjectIdentifier.of("cat", "db", "distinctType"), new VarCharType(5)).build(), DistinctType.newBuilder(ObjectIdentifier.of("cat", "db", "distinctType"), new VarCharType(false, 5)).build(), // custom RawType
    new RawType<>(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE), // external RawType
    new RawType<>(Row.class, ExternalSerializer.of(DataTypes.ROW(DataTypes.INT(), DataTypes.STRING()))));
    final List<LogicalType> mutableTypes = new ArrayList<>(types);
    // RawType for MapView
    addRawTypesForMapView(mutableTypes, new VarCharType(100), new VarCharType(100));
    addRawTypesForMapView(mutableTypes, new VarCharType(100), new BigIntType());
    addRawTypesForMapView(mutableTypes, new BigIntType(), new VarCharType(100));
    addRawTypesForMapView(mutableTypes, new BigIntType(), new BigIntType());
    // RawType for ListView
    addRawTypesForListView(mutableTypes, new VarCharType(100));
    addRawTypesForListView(mutableTypes, new BigIntType());
    // RawType for custom MapView
    mutableTypes.add(DataViewUtils.adjustDataViews(MapView.newMapViewDataType(DataTypes.STRING().toInternal(), DataTypes.STRING().bridgedTo(byte[].class)), false).getLogicalType());
    final List<LogicalType> allTypes = new ArrayList<>();
    // consider nullable
    for (LogicalType type : mutableTypes) {
        allTypes.add(type.copy(true));
        allTypes.add(type.copy(false));
    }
    // ignore nullable for NullType
    allTypes.add(new NullType());
    return allTypes;
}
Also used : LocalDateTime(java.time.LocalDateTime) VarBinaryType(org.apache.flink.table.types.logical.VarBinaryType) ArrayList(java.util.ArrayList) LogicalType(org.apache.flink.table.types.logical.LogicalType) BigIntType(org.apache.flink.table.types.logical.BigIntType) 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) StructuredType(org.apache.flink.table.types.logical.StructuredType) ArrayType(org.apache.flink.table.types.logical.ArrayType) PojoClass(org.apache.flink.table.planner.plan.nodes.exec.serde.DataTypeJsonSerdeTest.PojoClass) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) VarCharType(org.apache.flink.table.types.logical.VarCharType) DateType(org.apache.flink.table.types.logical.DateType) MultisetType(org.apache.flink.table.types.logical.MultisetType) BinaryType(org.apache.flink.table.types.logical.BinaryType) VarBinaryType(org.apache.flink.table.types.logical.VarBinaryType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) BooleanType(org.apache.flink.table.types.logical.BooleanType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) DayTimeIntervalType(org.apache.flink.table.types.logical.DayTimeIntervalType) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) DoubleType(org.apache.flink.table.types.logical.DoubleType) DecimalType(org.apache.flink.table.types.logical.DecimalType) CharType(org.apache.flink.table.types.logical.CharType) VarCharType(org.apache.flink.table.types.logical.VarCharType) Row(org.apache.flink.types.Row) NullType(org.apache.flink.table.types.logical.NullType) YearMonthIntervalType(org.apache.flink.table.types.logical.YearMonthIntervalType)

Example 3 with TimeType

use of org.apache.flink.table.types.logical.TimeType in project flink by apache.

the class ExpressionConverter method visit.

@Override
public RexNode visit(ValueLiteralExpression valueLiteral) {
    LogicalType type = fromDataTypeToLogicalType(valueLiteral.getOutputDataType());
    RexBuilder rexBuilder = relBuilder.getRexBuilder();
    FlinkTypeFactory typeFactory = (FlinkTypeFactory) relBuilder.getTypeFactory();
    RelDataType relDataType = typeFactory.createFieldTypeFromLogicalType(type);
    if (valueLiteral.isNull()) {
        return rexBuilder.makeNullLiteral(relDataType);
    }
    Object value = null;
    switch(type.getTypeRoot()) {
        case DECIMAL:
        case TINYINT:
        case SMALLINT:
        case INTEGER:
        case BIGINT:
        case FLOAT:
        case DOUBLE:
            value = extractValue(valueLiteral, BigDecimal.class);
            break;
        case VARCHAR:
        case CHAR:
            value = extractValue(valueLiteral, String.class);
            break;
        case BINARY:
        case VARBINARY:
            value = new ByteString(extractValue(valueLiteral, byte[].class));
            break;
        case INTERVAL_YEAR_MONTH:
            // convert to total months
            value = BigDecimal.valueOf(extractValue(valueLiteral, Period.class).toTotalMonths());
            break;
        case INTERVAL_DAY_TIME:
            // TODO planner supports only milliseconds precision
            // convert to total millis
            value = BigDecimal.valueOf(extractValue(valueLiteral, Duration.class).toMillis());
            break;
        case DATE:
            value = DateString.fromDaysSinceEpoch((int) extractValue(valueLiteral, LocalDate.class).toEpochDay());
            break;
        case TIME_WITHOUT_TIME_ZONE:
            // TODO type factory strips the precision, for literals we can be more lenient
            // already
            // Moreover conversion from long supports precision up to TIME(3) planner does not
            // support higher
            // precisions
            TimeType timeType = (TimeType) type;
            int precision = timeType.getPrecision();
            relDataType = typeFactory.createSqlType(SqlTypeName.TIME, Math.min(precision, 3));
            value = TimeString.fromMillisOfDay(extractValue(valueLiteral, LocalTime.class).get(ChronoField.MILLI_OF_DAY));
            break;
        case TIMESTAMP_WITHOUT_TIME_ZONE:
            LocalDateTime datetime = extractValue(valueLiteral, LocalDateTime.class);
            value = fromLocalDateTime(datetime);
            break;
        case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
            // normalize to UTC
            Instant instant = extractValue(valueLiteral, Instant.class);
            value = fromLocalDateTime(instant.atOffset(ZoneOffset.UTC).toLocalDateTime());
            break;
        default:
            value = extractValue(valueLiteral, Object.class);
            if (value instanceof TimePointUnit) {
                value = commonToCalcite((TimePointUnit) value);
            } else if (value instanceof TimeIntervalUnit) {
                value = commonToCalcite((TimeIntervalUnit) value);
            }
            break;
    }
    return rexBuilder.makeLiteral(value, relDataType, // RexBuilder#makeCast.
    true);
}
Also used : LocalDateTime(java.time.LocalDateTime) TimestampStringUtils.fromLocalDateTime(org.apache.flink.table.planner.utils.TimestampStringUtils.fromLocalDateTime) TimeIntervalUnit(org.apache.flink.table.expressions.TimeIntervalUnit) LocalTime(java.time.LocalTime) ByteString(org.apache.calcite.avatica.util.ByteString) Instant(java.time.Instant) LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter.fromDataTypeToLogicalType) LogicalType(org.apache.flink.table.types.logical.LogicalType) Period(java.time.Period) RelDataType(org.apache.calcite.rel.type.RelDataType) Duration(java.time.Duration) TimeString(org.apache.calcite.util.TimeString) DateString(org.apache.calcite.util.DateString) ByteString(org.apache.calcite.avatica.util.ByteString) BigDecimal(java.math.BigDecimal) TimeType(org.apache.flink.table.types.logical.TimeType) TimePointUnit(org.apache.flink.table.expressions.TimePointUnit) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RexBuilder(org.apache.calcite.rex.RexBuilder)

Example 4 with TimeType

use of org.apache.flink.table.types.logical.TimeType in project flink by apache.

the class ArrowReaderWriterTest method init.

@BeforeClass
public static void init() {
    fieldTypes.add(new TinyIntType());
    fieldTypes.add(new SmallIntType());
    fieldTypes.add(new IntType());
    fieldTypes.add(new BigIntType());
    fieldTypes.add(new BooleanType());
    fieldTypes.add(new FloatType());
    fieldTypes.add(new DoubleType());
    fieldTypes.add(new VarCharType());
    fieldTypes.add(new VarBinaryType());
    fieldTypes.add(new DecimalType(10, 3));
    fieldTypes.add(new DateType());
    fieldTypes.add(new TimeType(0));
    fieldTypes.add(new TimeType(2));
    fieldTypes.add(new TimeType(4));
    fieldTypes.add(new TimeType(8));
    fieldTypes.add(new LocalZonedTimestampType(0));
    fieldTypes.add(new LocalZonedTimestampType(2));
    fieldTypes.add(new LocalZonedTimestampType(4));
    fieldTypes.add(new LocalZonedTimestampType(8));
    fieldTypes.add(new TimestampType(0));
    fieldTypes.add(new TimestampType(2));
    fieldTypes.add(new TimestampType(4));
    fieldTypes.add(new TimestampType(8));
    fieldTypes.add(new ArrayType(new VarCharType()));
    rowFieldType = new RowType(Arrays.asList(new RowType.RowField("a", new IntType()), new RowType.RowField("b", new VarCharType()), new RowType.RowField("c", new ArrayType(new VarCharType())), new RowType.RowField("d", new TimestampType(2)), new RowType.RowField("e", new RowType(Arrays.asList(new RowType.RowField("e1", new IntType()), new RowType.RowField("e2", new VarCharType()))))));
    fieldTypes.add(rowFieldType);
    List<RowType.RowField> rowFields = new ArrayList<>();
    for (int i = 0; i < fieldTypes.size(); i++) {
        rowFields.add(new RowType.RowField("f" + i, fieldTypes.get(i)));
    }
    rowType = new RowType(rowFields);
    allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
Also used : VarBinaryType(org.apache.flink.table.types.logical.VarBinaryType) BooleanType(org.apache.flink.table.types.logical.BooleanType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) ArrayList(java.util.ArrayList) BigIntType(org.apache.flink.table.types.logical.BigIntType) RowType(org.apache.flink.table.types.logical.RowType) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) 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) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) DoubleType(org.apache.flink.table.types.logical.DoubleType) DecimalType(org.apache.flink.table.types.logical.DecimalType) TimestampType(org.apache.flink.table.types.logical.TimestampType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) VarCharType(org.apache.flink.table.types.logical.VarCharType) DateType(org.apache.flink.table.types.logical.DateType) BeforeClass(org.junit.BeforeClass)

Example 5 with TimeType

use of org.apache.flink.table.types.logical.TimeType in project flink by apache.

the class ArrowUtilsTest method init.

@BeforeClass
public static void init() {
    testFields = new ArrayList<>();
    testFields.add(Tuple5.of("f1", new TinyIntType(), new ArrowType.Int(8, true), TinyIntWriter.TinyIntWriterForRow.class, ArrowTinyIntColumnVector.class));
    testFields.add(Tuple5.of("f2", new SmallIntType(), new ArrowType.Int(8 * 2, true), SmallIntWriter.SmallIntWriterForRow.class, ArrowSmallIntColumnVector.class));
    testFields.add(Tuple5.of("f3", new IntType(), new ArrowType.Int(8 * 4, true), IntWriter.IntWriterForRow.class, ArrowIntColumnVector.class));
    testFields.add(Tuple5.of("f4", new BigIntType(), new ArrowType.Int(8 * 8, true), BigIntWriter.BigIntWriterForRow.class, ArrowBigIntColumnVector.class));
    testFields.add(Tuple5.of("f5", new BooleanType(), new ArrowType.Bool(), BooleanWriter.BooleanWriterForRow.class, ArrowBooleanColumnVector.class));
    testFields.add(Tuple5.of("f6", new FloatType(), new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), FloatWriter.FloatWriterForRow.class, ArrowFloatColumnVector.class));
    testFields.add(Tuple5.of("f7", new DoubleType(), new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), DoubleWriter.DoubleWriterForRow.class, ArrowDoubleColumnVector.class));
    testFields.add(Tuple5.of("f8", new VarCharType(), ArrowType.Utf8.INSTANCE, VarCharWriter.VarCharWriterForRow.class, ArrowVarCharColumnVector.class));
    testFields.add(Tuple5.of("f9", new VarBinaryType(), ArrowType.Binary.INSTANCE, VarBinaryWriter.VarBinaryWriterForRow.class, ArrowVarBinaryColumnVector.class));
    testFields.add(Tuple5.of("f10", new DecimalType(10, 3), new ArrowType.Decimal(10, 3), DecimalWriter.DecimalWriterForRow.class, ArrowDecimalColumnVector.class));
    testFields.add(Tuple5.of("f11", new DateType(), new ArrowType.Date(DateUnit.DAY), DateWriter.DateWriterForRow.class, ArrowDateColumnVector.class));
    testFields.add(Tuple5.of("f13", new TimeType(0), new ArrowType.Time(TimeUnit.SECOND, 32), TimeWriter.TimeWriterForRow.class, ArrowTimeColumnVector.class));
    testFields.add(Tuple5.of("f14", new TimeType(2), new ArrowType.Time(TimeUnit.MILLISECOND, 32), TimeWriter.TimeWriterForRow.class, ArrowTimeColumnVector.class));
    testFields.add(Tuple5.of("f15", new TimeType(4), new ArrowType.Time(TimeUnit.MICROSECOND, 64), TimeWriter.TimeWriterForRow.class, ArrowTimeColumnVector.class));
    testFields.add(Tuple5.of("f16", new TimeType(8), new ArrowType.Time(TimeUnit.NANOSECOND, 64), TimeWriter.TimeWriterForRow.class, ArrowTimeColumnVector.class));
    testFields.add(Tuple5.of("f17", new LocalZonedTimestampType(0), new ArrowType.Timestamp(TimeUnit.SECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f18", new LocalZonedTimestampType(2), new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f19", new LocalZonedTimestampType(4), new ArrowType.Timestamp(TimeUnit.MICROSECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f20", new LocalZonedTimestampType(8), new ArrowType.Timestamp(TimeUnit.NANOSECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f21", new TimestampType(0), new ArrowType.Timestamp(TimeUnit.SECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f22", new TimestampType(2), new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f23", new TimestampType(4), new ArrowType.Timestamp(TimeUnit.MICROSECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f24", new TimestampType(8), new ArrowType.Timestamp(TimeUnit.NANOSECOND, null), TimestampWriter.TimestampWriterForRow.class, ArrowTimestampColumnVector.class));
    testFields.add(Tuple5.of("f25", new ArrayType(new VarCharType()), ArrowType.List.INSTANCE, ArrayWriter.ArrayWriterForRow.class, ArrowArrayColumnVector.class));
    RowType rowFieldType = new RowType(Arrays.asList(new RowType.RowField("a", new IntType()), new RowType.RowField("b", new VarCharType()), new RowType.RowField("c", new ArrayType(new VarCharType())), new RowType.RowField("d", new TimestampType(2)), new RowType.RowField("e", new RowType((Arrays.asList(new RowType.RowField("e1", new IntType()), new RowType.RowField("e2", new VarCharType())))))));
    testFields.add(Tuple5.of("f26", rowFieldType, ArrowType.Struct.INSTANCE, RowWriter.RowWriterForRow.class, ArrowRowColumnVector.class));
    List<RowType.RowField> rowFields = new ArrayList<>();
    for (Tuple5<String, LogicalType, ArrowType, Class<?>, Class<?>> field : testFields) {
        rowFields.add(new RowType.RowField(field.f0, field.f1));
    }
    rowType = new RowType(rowFields);
    allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
Also used : ArrowArrayColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowArrayColumnVector) ArrayList(java.util.ArrayList) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) LogicalType(org.apache.flink.table.types.logical.LogicalType) FloatType(org.apache.flink.table.types.logical.FloatType) ArrayType(org.apache.flink.table.types.logical.ArrayType) DateType(org.apache.flink.table.types.logical.DateType) ArrowTimeColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowTimeColumnVector) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) DecimalType(org.apache.flink.table.types.logical.DecimalType) BeforeClass(org.junit.BeforeClass) ArrowTimestampColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowTimestampColumnVector) VarBinaryType(org.apache.flink.table.types.logical.VarBinaryType) ArrowTinyIntColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowTinyIntColumnVector) ArrowIntColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowIntColumnVector) BigIntType(org.apache.flink.table.types.logical.BigIntType) RowType(org.apache.flink.table.types.logical.RowType) ArrowBooleanColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowBooleanColumnVector) 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) TimeType(org.apache.flink.table.types.logical.TimeType) ArrowDoubleColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowDoubleColumnVector) ArrowDateColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowDateColumnVector) ArrowSmallIntColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowSmallIntColumnVector) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) ArrowVarBinaryColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowVarBinaryColumnVector) VarCharType(org.apache.flink.table.types.logical.VarCharType) ArrowDecimalColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowDecimalColumnVector) ArrowFloatColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowFloatColumnVector) BooleanType(org.apache.flink.table.types.logical.BooleanType) ArrowVarCharColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowVarCharColumnVector) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) DoubleType(org.apache.flink.table.types.logical.DoubleType) ArrowBigIntColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowBigIntColumnVector) ArrowRowColumnVector(org.apache.flink.table.runtime.arrow.vectors.ArrowRowColumnVector) BeforeClass(org.junit.BeforeClass)

Aggregations

TimeType (org.apache.flink.table.types.logical.TimeType)7 LogicalType (org.apache.flink.table.types.logical.LogicalType)6 ArrayList (java.util.ArrayList)5 DateType (org.apache.flink.table.types.logical.DateType)5 TimestampType (org.apache.flink.table.types.logical.TimestampType)5 ArrayType (org.apache.flink.table.types.logical.ArrayType)4 BigIntType (org.apache.flink.table.types.logical.BigIntType)4 DecimalType (org.apache.flink.table.types.logical.DecimalType)4 DoubleType (org.apache.flink.table.types.logical.DoubleType)4 FloatType (org.apache.flink.table.types.logical.FloatType)4 IntType (org.apache.flink.table.types.logical.IntType)4 LocalZonedTimestampType (org.apache.flink.table.types.logical.LocalZonedTimestampType)4 SmallIntType (org.apache.flink.table.types.logical.SmallIntType)4 LocalDateTime (java.time.LocalDateTime)3 BooleanType (org.apache.flink.table.types.logical.BooleanType)3 RowType (org.apache.flink.table.types.logical.RowType)3 TinyIntType (org.apache.flink.table.types.logical.TinyIntType)3 LocalTime (java.time.LocalTime)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2