Search in sources :

Example 61 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class OperationTreeBuilder method map.

public QueryOperation map(Expression mapFunction, QueryOperation child) {
    Expression resolvedMapFunction = mapFunction.accept(lookupResolver);
    if (!isFunctionOfKind(resolvedMapFunction, FunctionKind.SCALAR)) {
        throw new ValidationException("Only a scalar function can be used in the map operator.");
    }
    Expression expandedFields = unresolvedCall(BuiltInFunctionDefinitions.FLATTEN, resolvedMapFunction);
    return project(Collections.singletonList(expandedFields), child, false);
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) Expression(org.apache.flink.table.expressions.Expression) UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression)

Example 62 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class SortOperationFactory method createLimitWithFetch.

/**
 * Creates a valid {@link SortQueryOperation} with fetch (possibly merged into a preceding
 * {@link SortQueryOperation}).
 *
 * @param fetch fetch to limit
 * @param child relational expression on top of which to apply the sort operation
 * @param postResolverFactory factory for creating resolved expressions
 * @return valid sort operation with applied offset
 */
QueryOperation createLimitWithFetch(int fetch, QueryOperation child, PostResolverFactory postResolverFactory) {
    SortQueryOperation previousSort = validateAndGetChildSort(child, postResolverFactory);
    if (fetch < 0) {
        throw new ValidationException("Fetch should be greater or equal 0");
    }
    int offset = Math.max(previousSort.getOffset(), 0);
    return new SortQueryOperation(previousSort.getOrder(), previousSort.getChild(), offset, fetch);
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) SortQueryOperation(org.apache.flink.table.operations.SortQueryOperation)

Example 63 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class AggregateOperationFactory method validateAndCreateSessionWindow.

private ResolvedGroupWindow validateAndCreateSessionWindow(SessionWithGapOnTimeWithAlias window, String windowName, FieldReferenceExpression timeField) {
    ValueLiteralExpression windowGap = getAsValueLiteral(window.getGap(), "A session window expects a gap value literal.");
    final LogicalType windowGapType = windowGap.getOutputDataType().getLogicalType();
    if (!windowGapType.is(INTERVAL_DAY_TIME)) {
        throw new ValidationException("A session window expects a gap literal of a day-time interval type.");
    }
    return ResolvedGroupWindow.sessionWindow(windowName, timeField, windowGap);
}
Also used : ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) ValidationException(org.apache.flink.table.api.ValidationException) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Example 64 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class AggregateOperationFactory method createResolvedWindow.

/**
 * Converts an API class to a resolved window for planning with expressions already resolved. It
 * performs following validations:
 *
 * <ul>
 *   <li>The alias is represented with an unresolved reference
 *   <li>The time attribute is a single field reference of a {@link
 *       TimeIndicatorTypeInfo}(stream), {@link SqlTimeTypeInfo}(batch), or {@link
 *       BasicTypeInfo#LONG_TYPE_INFO}(batch) type
 *   <li>The size & slide are value literals of either {@link BasicTypeInfo#LONG_TYPE_INFO}, or
 *       {@link TimeIntervalTypeInfo} type
 *   <li>The size & slide are of the same type
 *   <li>The gap is a value literal of a {@link TimeIntervalTypeInfo} type
 * </ul>
 *
 * @param window window to resolve
 * @param resolver resolver to resolve potential unresolved field references
 * @return window with expressions resolved
 */
ResolvedGroupWindow createResolvedWindow(GroupWindow window, ExpressionResolver resolver) {
    Expression alias = window.getAlias();
    if (!(alias instanceof UnresolvedReferenceExpression)) {
        throw new ValidationException("Only unresolved reference supported for alias of a group window.");
    }
    final String windowName = ((UnresolvedReferenceExpression) alias).getName();
    FieldReferenceExpression timeField = getValidatedTimeAttribute(window, resolver);
    if (window instanceof TumbleWithSizeOnTimeWithAlias) {
        return validateAndCreateTumbleWindow((TumbleWithSizeOnTimeWithAlias) window, windowName, timeField);
    } else if (window instanceof SlideWithSizeAndSlideOnTimeWithAlias) {
        return validateAndCreateSlideWindow((SlideWithSizeAndSlideOnTimeWithAlias) window, windowName, timeField);
    } else if (window instanceof SessionWithGapOnTimeWithAlias) {
        return validateAndCreateSessionWindow((SessionWithGapOnTimeWithAlias) window, windowName, timeField);
    } else {
        throw new TableException("Unknown window type: " + window);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) TumbleWithSizeOnTimeWithAlias(org.apache.flink.table.api.TumbleWithSizeOnTimeWithAlias) SlideWithSizeAndSlideOnTimeWithAlias(org.apache.flink.table.api.SlideWithSizeAndSlideOnTimeWithAlias) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) SessionWithGapOnTimeWithAlias(org.apache.flink.table.api.SessionWithGapOnTimeWithAlias)

Example 65 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class FieldInfoUtils method extractFieldInfoFromAtomicType.

private static List<FieldInfo> extractFieldInfoFromAtomicType(TypeInformation<?> atomicType, Expression[] exprs) {
    List<FieldInfo> fields = new ArrayList<>(exprs.length);
    boolean alreadyReferenced = false;
    for (int i = 0; i < exprs.length; i++) {
        Expression expr = exprs[i];
        if (expr instanceof UnresolvedReferenceExpression) {
            if (alreadyReferenced) {
                throw new ValidationException("Too many fields referenced from an atomic type.");
            }
            alreadyReferenced = true;
            String name = ((UnresolvedReferenceExpression) expr).getName();
            fields.add(new FieldInfo(name, i, fromLegacyInfoToDataType(atomicType)));
        } else if (isRowTimeExpression(expr)) {
            UnresolvedReferenceExpression reference = getChildAsReference(expr);
            fields.add(createTimeAttributeField(reference, TimestampKind.ROWTIME, null));
        } else if (isProcTimeExpression(expr)) {
            UnresolvedReferenceExpression reference = getChildAsReference(expr);
            fields.add(createTimeAttributeField(reference, TimestampKind.PROCTIME, null));
        } else {
            throw new ValidationException("Field reference expression expected.");
        }
    }
    return fields;
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) Expression(org.apache.flink.table.expressions.Expression) UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) ArrayList(java.util.ArrayList) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression)

Aggregations

ValidationException (org.apache.flink.table.api.ValidationException)143 DataType (org.apache.flink.table.types.DataType)25 Test (org.junit.Test)23 HashMap (java.util.HashMap)21 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)19 LogicalType (org.apache.flink.table.types.logical.LogicalType)18 TableException (org.apache.flink.table.api.TableException)17 List (java.util.List)14 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)14 QueryOperation (org.apache.flink.table.operations.QueryOperation)14 LinkedHashMap (java.util.LinkedHashMap)13 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)13 CatalogTable (org.apache.flink.table.catalog.CatalogTable)12 Expression (org.apache.flink.table.expressions.Expression)12 TableSchema (org.apache.flink.table.api.TableSchema)11 Catalog (org.apache.flink.table.catalog.Catalog)11 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Internal (org.apache.flink.annotation.Internal)10