Search in sources :

Example 61 with TableException

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

the class AggFunctionTestBase method accumulateValues.

protected ACC accumulateValues(List<T> values) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    AggregateFunction<T, ACC> aggregator = getAggregator();
    ACC accumulator = getAggregator().createAccumulator();
    Method accumulateFunc = getAccumulateFunc();
    for (T value : values) {
        if (accumulateFunc.getParameterCount() == 1) {
            accumulateFunc.invoke(aggregator, accumulator);
        } else if (accumulateFunc.getParameterCount() == 2) {
            accumulateFunc.invoke(aggregator, accumulator, value);
        } else {
            throw new TableException("Unsupported now");
        }
    }
    return accumulator;
}
Also used : TableException(org.apache.flink.table.api.TableException) Method(java.lang.reflect.Method)

Example 62 with TableException

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

the class AggFunctionTestBase method retractValues.

protected void retractValues(ACC accumulator, List<T> values) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    AggregateFunction<T, ACC> aggregator = getAggregator();
    Method retractFunc = getRetractFunc();
    for (T value : values) {
        if (retractFunc.getParameterCount() == 1) {
            retractFunc.invoke(aggregator, accumulator);
        } else if (retractFunc.getParameterCount() == 2) {
            retractFunc.invoke(aggregator, accumulator, value);
        } else {
            throw new TableException("Unsupported now");
        }
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) Method(java.lang.reflect.Method)

Example 63 with TableException

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

the class ProjectionOperationFactory method validateAndGetUniqueNames.

private String[] validateAndGetUniqueNames(List<ResolvedExpression> namedExpressions) {
    // we need to maintain field names order to match with types
    final Set<String> names = new LinkedHashSet<>();
    extractNames(namedExpressions).stream().map(name -> name.orElseThrow(() -> new TableException("Could not name a field in a projection."))).forEach(name -> {
        if (!names.add(name)) {
            throw new ValidationException("Ambiguous column name: " + name);
        }
    });
    return names.toArray(new String[0]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntStream(java.util.stream.IntStream) DataType(org.apache.flink.table.types.DataType) QueryOperation(org.apache.flink.table.operations.QueryOperation) CallExpression(org.apache.flink.table.expressions.CallExpression) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Expression(org.apache.flink.table.expressions.Expression) LocalReferenceExpression(org.apache.flink.table.expressions.LocalReferenceExpression) ResolvedExpressionDefaultVisitor(org.apache.flink.table.expressions.utils.ResolvedExpressionDefaultVisitor) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) TableReferenceExpression(org.apache.flink.table.expressions.TableReferenceExpression) GET(org.apache.flink.table.functions.BuiltInFunctionDefinitions.GET) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) LinkedHashSet(java.util.LinkedHashSet) CAST(org.apache.flink.table.functions.BuiltInFunctionDefinitions.CAST) AS(org.apache.flink.table.functions.BuiltInFunctionDefinitions.AS) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) BuiltInFunctionDefinitions(org.apache.flink.table.functions.BuiltInFunctionDefinitions) ProjectQueryOperation(org.apache.flink.table.operations.ProjectQueryOperation) TableException(org.apache.flink.table.api.TableException) Set(java.util.Set) INTEGER(org.apache.flink.table.types.logical.LogicalTypeRoot.INTEGER) OperationExpressionsUtils.extractName(org.apache.flink.table.operations.utils.OperationExpressionsUtils.extractName) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) Collectors(java.util.stream.Collectors) List(java.util.List) LogicalType(org.apache.flink.table.types.logical.LogicalType) ValidationException(org.apache.flink.table.api.ValidationException) OperationExpressionsUtils.extractNames(org.apache.flink.table.operations.utils.OperationExpressionsUtils.extractNames) Optional(java.util.Optional) Internal(org.apache.flink.annotation.Internal) TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException)

Example 64 with TableException

use of org.apache.flink.table.api.TableException 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 TableException

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

the class ParserImpl method parse.

/**
 * When parsing statement, it first uses {@link ExtendedParser} to parse statements. If {@link
 * ExtendedParser} fails to parse statement, it uses the {@link CalciteParser} to parse
 * statements.
 *
 * @param statement input statement.
 * @return parsed operations.
 */
@Override
public List<Operation> parse(String statement) {
    CalciteParser parser = calciteParserSupplier.get();
    FlinkPlannerImpl planner = validatorSupplier.get();
    Optional<Operation> command = EXTENDED_PARSER.parse(statement);
    if (command.isPresent()) {
        return Collections.singletonList(command.get());
    }
    // parse the sql query
    // use parseSqlList here because we need to support statement end with ';' in sql client.
    SqlNodeList sqlNodeList = parser.parseSqlList(statement);
    List<SqlNode> parsed = sqlNodeList.getList();
    Preconditions.checkArgument(parsed.size() == 1, "only single statement supported");
    return Collections.singletonList(SqlToOperationConverter.convert(planner, catalogManager, parsed.get(0)).orElseThrow(() -> new TableException("Unsupported query: " + statement)));
}
Also used : TableException(org.apache.flink.table.api.TableException) FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) SqlNodeList(org.apache.calcite.sql.SqlNodeList) Operation(org.apache.flink.table.operations.Operation) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

TableException (org.apache.flink.table.api.TableException)163 RowData (org.apache.flink.table.data.RowData)35 RowType (org.apache.flink.table.types.logical.RowType)35 Transformation (org.apache.flink.api.dag.Transformation)28 ArrayList (java.util.ArrayList)27 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)24 LogicalType (org.apache.flink.table.types.logical.LogicalType)24 List (java.util.List)22 DataType (org.apache.flink.table.types.DataType)19 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)18 ValidationException (org.apache.flink.table.api.ValidationException)17 IOException (java.io.IOException)13 AggregateCall (org.apache.calcite.rel.core.AggregateCall)13 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)13 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)13 Optional (java.util.Optional)11 Configuration (org.apache.flink.configuration.Configuration)11 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)11 Constructor (java.lang.reflect.Constructor)10 Arrays (java.util.Arrays)9