use of org.apache.flink.table.types.DataType in project flink by apache.
the class SchemaTranslator method patchDataTypeFromDeclaredSchema.
private static DataType patchDataTypeFromDeclaredSchema(DataTypeFactory dataTypeFactory, DataType inputDataType, List<UnresolvedColumn> declaredColumns) {
final List<UnresolvedPhysicalColumn> physicalColumns = declaredColumns.stream().filter(SchemaTranslator::isPhysical).map(UnresolvedPhysicalColumn.class::cast).collect(Collectors.toList());
DataType patchedDataType = inputDataType;
for (UnresolvedPhysicalColumn physicalColumn : physicalColumns) {
patchedDataType = patchDataTypeFromColumn(dataTypeFactory, patchedDataType, physicalColumn);
}
return patchedDataType;
}
use of org.apache.flink.table.types.DataType in project flink by apache.
the class DecimalDivideTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType dividend = argumentDataTypes.get(0).getLogicalType();
final LogicalType divisor = argumentDataTypes.get(1).getLogicalType();
// a hack to make legacy types possible until we drop them
if (dividend instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(0));
}
if (divisor instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(1));
}
if (!isDecimalComputation(dividend, divisor)) {
return Optional.empty();
}
final DecimalType decimalType = LogicalTypeMerging.findDivisionDecimalType(getPrecision(dividend), getScale(dividend), getPrecision(divisor), getScale(divisor));
return Optional.of(fromLogicalToDataType(decimalType));
}
use of org.apache.flink.table.types.DataType in project flink by apache.
the class DecimalPlusTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType addend1 = argumentDataTypes.get(0).getLogicalType();
final LogicalType addend2 = argumentDataTypes.get(1).getLogicalType();
// a hack to make legacy types possible until we drop them
if (addend1 instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(0));
}
if (addend2 instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(1));
}
if (!isDecimalComputation(addend1, addend2)) {
return Optional.empty();
}
final DecimalType decimalType = LogicalTypeMerging.findAdditionDecimalType(getPrecision(addend1), getScale(addend1), getPrecision(addend2), getScale(addend2));
return Optional.of(fromLogicalToDataType(decimalType));
}
use of org.apache.flink.table.types.DataType in project flink by apache.
the class GetTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
DataType rowDataType = argumentDataTypes.get(0);
Optional<DataType> result = Optional.empty();
Optional<String> fieldName = callContext.getArgumentValue(1, String.class);
if (fieldName.isPresent()) {
result = DataTypeUtils.getField(rowDataType, fieldName.get());
}
Optional<Integer> fieldIndex = callContext.getArgumentValue(1, Integer.class);
if (fieldIndex.isPresent()) {
result = DataTypeUtils.getField(rowDataType, fieldIndex.get());
}
return result.map(type -> {
if (rowDataType.getLogicalType().isNullable()) {
return type.nullable();
} else {
return type;
}
});
}
use of org.apache.flink.table.types.DataType in project flink by apache.
the class MapInputTypeStrategy method inferInputTypes.
@Override
public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
if (argumentDataTypes.size() == 0) {
return Optional.empty();
}
List<LogicalType> keyTypes = new ArrayList<>();
List<LogicalType> valueTypes = new ArrayList<>();
for (int i = 0; i < argumentDataTypes.size(); i++) {
LogicalType logicalType = argumentDataTypes.get(i).getLogicalType();
if (i % 2 == 0) {
keyTypes.add(logicalType);
} else {
valueTypes.add(logicalType);
}
}
Optional<LogicalType> commonKeyType = LogicalTypeMerging.findCommonType(keyTypes);
Optional<LogicalType> commonValueType = LogicalTypeMerging.findCommonType(valueTypes);
if (!commonKeyType.isPresent() || !commonValueType.isPresent()) {
return Optional.empty();
}
DataType keyType = TypeConversions.fromLogicalToDataType(commonKeyType.get());
DataType valueType = TypeConversions.fromLogicalToDataType(commonValueType.get());
return Optional.of(IntStream.range(0, argumentDataTypes.size()).mapToObj(idx -> {
if (idx % 2 == 0) {
return keyType;
} else {
return valueType;
}
}).collect(Collectors.toList()));
}
Aggregations