Search in sources :

Example 1 with DataTypeQueryable

use of org.apache.flink.table.types.DataTypeQueryable in project flink by apache.

the class FieldInfoUtils method getFieldNames.

/**
 * Returns field names for a given {@link TypeInformation}. If the input {@link TypeInformation}
 * is not a composite type, the result field name should not exist in the existingNames.
 *
 * @param inputType The TypeInformation extract the field names.
 * @param existingNames The existing field names for non-composite types that can not be used.
 * @param <A> The type of the TypeInformation.
 * @return An array holding the field names
 */
public static <A> String[] getFieldNames(TypeInformation<A> inputType, List<String> existingNames) {
    validateInputTypeInfo(inputType);
    List<String> fieldNames = null;
    // type originated from Table API
    if (inputType instanceof DataTypeQueryable) {
        final DataType dataType = ((DataTypeQueryable) inputType).getDataType();
        final LogicalType type = dataType.getLogicalType();
        if (isCompositeType(type)) {
            fieldNames = LogicalTypeChecks.getFieldNames(type);
        }
    } else // type originated from other API
    if (inputType instanceof CompositeType) {
        fieldNames = Arrays.asList(((CompositeType<A>) inputType).getFieldNames());
    }
    // atomic in any case
    if (fieldNames == null) {
        fieldNames = Collections.singletonList(getAtomicName(existingNames));
    }
    if (fieldNames.contains("*")) {
        throw new TableException("Field name can not be '*'.");
    }
    return fieldNames.toArray(new String[0]);
}
Also used : TableException(org.apache.flink.table.api.TableException) DataTypeQueryable(org.apache.flink.table.types.DataTypeQueryable) DataType(org.apache.flink.table.types.DataType) AtomicDataType(org.apache.flink.table.types.AtomicDataType) TypeConversions.fromLegacyInfoToDataType(org.apache.flink.table.types.utils.TypeConversions.fromLegacyInfoToDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) CompositeType(org.apache.flink.api.common.typeutils.CompositeType) LogicalTypeChecks.isCompositeType(org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isCompositeType)

Example 2 with DataTypeQueryable

use of org.apache.flink.table.types.DataTypeQueryable in project flink by apache.

the class FieldInfoUtils method isIndexedComposite.

private static boolean isIndexedComposite(TypeInformation<?> inputType) {
    // type originated from Table API
    if (inputType instanceof DataTypeQueryable) {
        final DataType dataType = ((DataTypeQueryable) inputType).getDataType();
        final LogicalType type = dataType.getLogicalType();
        // every composite in Table API is indexed
        return isCompositeType(type);
    }
    // type originated from other API
    return inputType instanceof TupleTypeInfoBase;
}
Also used : DataTypeQueryable(org.apache.flink.table.types.DataTypeQueryable) TupleTypeInfoBase(org.apache.flink.api.java.typeutils.TupleTypeInfoBase) DataType(org.apache.flink.table.types.DataType) AtomicDataType(org.apache.flink.table.types.AtomicDataType) TypeConversions.fromLegacyInfoToDataType(org.apache.flink.table.types.utils.TypeConversions.fromLegacyInfoToDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Aggregations

AtomicDataType (org.apache.flink.table.types.AtomicDataType)2 DataType (org.apache.flink.table.types.DataType)2 DataTypeQueryable (org.apache.flink.table.types.DataTypeQueryable)2 LogicalType (org.apache.flink.table.types.logical.LogicalType)2 TypeConversions.fromLegacyInfoToDataType (org.apache.flink.table.types.utils.TypeConversions.fromLegacyInfoToDataType)2 CompositeType (org.apache.flink.api.common.typeutils.CompositeType)1 TupleTypeInfoBase (org.apache.flink.api.java.typeutils.TupleTypeInfoBase)1 TableException (org.apache.flink.table.api.TableException)1 LogicalTypeChecks.isCompositeType (org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isCompositeType)1