Search in sources :

Example 1 with SqlTableFunction

use of org.apache.calcite.sql.SqlTableFunction in project flink by apache.

the class ProcedureNamespace method validateImpl.

public RelDataType validateImpl(RelDataType targetRowType) {
    validator.inferUnknownTypes(validator.unknownType, scope, call);
    final RelDataType type = validator.deriveTypeImpl(scope, call);
    final SqlOperator operator = call.getOperator();
    final SqlCallBinding callBinding = new SqlCallBinding(validator, scope, call);
    if (operator instanceof SqlTableFunction) {
        final SqlTableFunction tableFunction = (SqlTableFunction) operator;
        if (type.getSqlTypeName() != SqlTypeName.CURSOR) {
            throw new IllegalArgumentException("Table function should have CURSOR " + "type, not " + type);
        }
        final SqlReturnTypeInference rowTypeInference = tableFunction.getRowTypeInference();
        RelDataType retType = rowTypeInference.inferReturnType(callBinding);
        return validator.getTypeFactory().createTypeWithNullability(retType, false);
    }
    // special handling of collection tables TABLE(function(...))
    if (SqlUtil.stripAs(enclosingNode).getKind() == SqlKind.COLLECTION_TABLE) {
        return toStruct(type, getNode());
    }
    return type;
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) SqlReturnTypeInference(org.apache.calcite.sql.type.SqlReturnTypeInference) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlTableFunction(org.apache.calcite.sql.SqlTableFunction)

Example 2 with SqlTableFunction

use of org.apache.calcite.sql.SqlTableFunction in project flink by apache.

the class SqlValidatorImpl method validateExpr.

/**
 * Validates an expression.
 *
 * @param expr Expression
 * @param scope Scope in which expression occurs
 */
private void validateExpr(SqlNode expr, SqlValidatorScope scope) {
    if (expr instanceof SqlCall) {
        final SqlOperator op = ((SqlCall) expr).getOperator();
        if (op.isAggregator() && op.requiresOver()) {
            throw newValidationError(expr, RESOURCE.absentOverClause());
        }
        if (op instanceof SqlTableFunction) {
            throw RESOURCE.cannotCallTableFunctionHere(op.getName()).ex();
        }
    }
    // Call on the expression to validate itself.
    expr.validateExpr(this, scope);
    // Perform any validation specific to the scope. For example, an
    // aggregating scope requires that expressions are valid aggregations.
    scope.validateExpr(expr);
}
Also used : SqlCall(org.apache.calcite.sql.SqlCall) SqlOperator(org.apache.calcite.sql.SqlOperator) SqlTableFunction(org.apache.calcite.sql.SqlTableFunction)

Aggregations

SqlOperator (org.apache.calcite.sql.SqlOperator)2 SqlTableFunction (org.apache.calcite.sql.SqlTableFunction)2 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SqlCall (org.apache.calcite.sql.SqlCall)1 SqlCallBinding (org.apache.calcite.sql.SqlCallBinding)1 SqlReturnTypeInference (org.apache.calcite.sql.type.SqlReturnTypeInference)1