Search in sources :

Example 1 with CategorizedExpressions

use of org.apache.flink.table.operations.utils.OperationExpressionsUtils.CategorizedExpressions in project flink by apache.

the class TableImpl method select.

@Override
public Table select(Expression... fields) {
    List<Expression> expressionsWithResolvedCalls = preprocessExpressions(fields);
    CategorizedExpressions extracted = OperationExpressionsUtils.extractAggregationsAndProperties(expressionsWithResolvedCalls);
    if (!extracted.getWindowProperties().isEmpty()) {
        throw new ValidationException("Window properties can only be used on windowed tables.");
    }
    if (!extracted.getAggregations().isEmpty()) {
        QueryOperation aggregate = operationTreeBuilder.aggregate(Collections.emptyList(), extracted.getAggregations(), operationTree);
        return createTable(operationTreeBuilder.project(extracted.getProjections(), aggregate, false));
    } else {
        return createTable(operationTreeBuilder.project(expressionsWithResolvedCalls, operationTree, false));
    }
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) Expression(org.apache.flink.table.expressions.Expression) CategorizedExpressions(org.apache.flink.table.operations.utils.OperationExpressionsUtils.CategorizedExpressions) QueryOperation(org.apache.flink.table.operations.QueryOperation)

Example 2 with CategorizedExpressions

use of org.apache.flink.table.operations.utils.OperationExpressionsUtils.CategorizedExpressions in project flink by apache.

the class TableImpl method addColumnsOperation.

private Table addColumnsOperation(boolean replaceIfExist, List<Expression> fields) {
    List<Expression> expressionsWithResolvedCalls = preprocessExpressions(fields);
    CategorizedExpressions extracted = OperationExpressionsUtils.extractAggregationsAndProperties(expressionsWithResolvedCalls);
    List<Expression> aggNames = extracted.getAggregations();
    if (!aggNames.isEmpty()) {
        throw new ValidationException("The added field expression cannot be an aggregation, found: " + aggNames.get(0));
    }
    return createTable(operationTreeBuilder.addColumns(replaceIfExist, expressionsWithResolvedCalls, operationTree));
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) Expression(org.apache.flink.table.expressions.Expression) CategorizedExpressions(org.apache.flink.table.operations.utils.OperationExpressionsUtils.CategorizedExpressions)

Aggregations

ValidationException (org.apache.flink.table.api.ValidationException)2 Expression (org.apache.flink.table.expressions.Expression)2 UnresolvedReferenceExpression (org.apache.flink.table.expressions.UnresolvedReferenceExpression)2 CategorizedExpressions (org.apache.flink.table.operations.utils.OperationExpressionsUtils.CategorizedExpressions)2 QueryOperation (org.apache.flink.table.operations.QueryOperation)1