Search in sources :

Example 1 with LogicalTypeMerging

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

the class ValuesOperationFactory method create.

/**
 * Creates a valid {@link ValuesQueryOperation} operation.
 *
 * <p>It derives a row type based on {@link LogicalTypeMerging}. It flattens any row
 * constructors. It does not flatten ROWs which are a result of e.g. a function call.
 *
 * <p>The resulting schema can be provided manually. If it is not, the schema will be
 * automatically derived from the types of the expressions.
 */
QueryOperation create(@Nullable ResolvedSchema expectedSchema, List<ResolvedExpression> resolvedExpressions, ExpressionResolver.PostResolverFactory postResolverFactory) {
    List<List<ResolvedExpression>> resolvedRows = unwrapFromRowConstructor(resolvedExpressions);
    if (expectedSchema != null) {
        verifyAllSameSize(resolvedRows, expectedSchema.getColumnCount());
    }
    ResolvedSchema schema = Optional.ofNullable(expectedSchema).orElseGet(() -> extractSchema(resolvedRows));
    List<List<ResolvedExpression>> castedExpressions = resolvedRows.stream().map(row -> convertTopLevelExpressionToExpectedRowType(postResolverFactory, schema.getColumnDataTypes(), row)).collect(Collectors.toList());
    return new ValuesQueryOperation(castedExpressions, schema);
}
Also used : IntStream(java.util.stream.IntStream) DataType(org.apache.flink.table.types.DataType) QueryOperation(org.apache.flink.table.operations.QueryOperation) ApiExpressionUtils.valueLiteral(org.apache.flink.table.expressions.ApiExpressionUtils.valueLiteral) KeyValueDataType(org.apache.flink.table.types.KeyValueDataType) CallExpression(org.apache.flink.table.expressions.CallExpression) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) LogicalTypeMerging(org.apache.flink.table.types.logical.utils.LogicalTypeMerging) Expression(org.apache.flink.table.expressions.Expression) ExpressionDefaultVisitor(org.apache.flink.table.expressions.ExpressionDefaultVisitor) ArrayList(java.util.ArrayList) NULL(org.apache.flink.table.types.logical.LogicalTypeRoot.NULL) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) FieldsDataType(org.apache.flink.table.types.FieldsDataType) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) MAP(org.apache.flink.table.types.logical.LogicalTypeRoot.MAP) LogicalTypeCasts.supportsExplicitCast(org.apache.flink.table.types.logical.utils.LogicalTypeCasts.supportsExplicitCast) ValuesQueryOperation(org.apache.flink.table.operations.ValuesQueryOperation) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) ROW(org.apache.flink.table.types.logical.LogicalTypeRoot.ROW) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) BuiltInFunctionDefinitions(org.apache.flink.table.functions.BuiltInFunctionDefinitions) TableException(org.apache.flink.table.api.TableException) Set(java.util.Set) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) Collectors(java.util.stream.Collectors) List(java.util.List) CollectionDataType(org.apache.flink.table.types.CollectionDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) ARRAY(org.apache.flink.table.types.logical.LogicalTypeRoot.ARRAY) ValidationException(org.apache.flink.table.api.ValidationException) Optional(java.util.Optional) Internal(org.apache.flink.annotation.Internal) TypeConversions(org.apache.flink.table.types.utils.TypeConversions) Collections(java.util.Collections) ValuesQueryOperation(org.apache.flink.table.operations.ValuesQueryOperation) ArrayList(java.util.ArrayList) List(java.util.List) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Nullable (javax.annotation.Nullable)1 Internal (org.apache.flink.annotation.Internal)1 TableException (org.apache.flink.table.api.TableException)1 ValidationException (org.apache.flink.table.api.ValidationException)1 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)1 ApiExpressionUtils.valueLiteral (org.apache.flink.table.expressions.ApiExpressionUtils.valueLiteral)1 CallExpression (org.apache.flink.table.expressions.CallExpression)1 Expression (org.apache.flink.table.expressions.Expression)1 ExpressionDefaultVisitor (org.apache.flink.table.expressions.ExpressionDefaultVisitor)1 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)1 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)1 ExpressionResolver (org.apache.flink.table.expressions.resolver.ExpressionResolver)1