Search in sources :

Example 16 with SqlFunction

use of org.apache.calcite.sql.SqlFunction in project calcite by apache.

the class SqlValidatorImpl method deriveConstructorType.

@Override
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
    SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
    assert sqlIdentifier != null;
    RelDataType type = catalogReader.getNamedType(sqlIdentifier);
    if (type == null) {
        // TODO jvs 12-Feb-2005:  proper type name formatting
        throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
    }
    if (resolvedConstructor == null) {
        if (call.operandCount() > 0) {
            // no user-defined constructor could be found
            throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
        }
    } else {
        SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
        RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
        assert type == returnType;
    }
    if (config.identifierExpansion()) {
        if (resolvedConstructor != null) {
            ((SqlBasicCall) call).setOperator(resolvedConstructor);
        } else {
            // fake a fully-qualified call to the default constructor
            ((SqlBasicCall) call).setOperator(new SqlFunction(requireNonNull(type.getSqlIdentifier(), () -> "sqlIdentifier of " + type), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
        }
    }
    return type;
}
Also used : SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlCall(org.apache.calcite.sql.SqlCall) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 17 with SqlFunction

use of org.apache.calcite.sql.SqlFunction in project calcite by apache.

the class DocumentationTest method addOperators.

private void addOperators(Map<String, PatternOp> map, String prefix, List<SqlOperator> operatorList) {
    for (SqlOperator op : operatorList) {
        final String name = op.getName().equals("TRANSLATE3") ? "TRANSLATE" : op.getName();
        if (op instanceof SqlSpecialOperator || !name.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
            continue;
        }
        final String regex;
        if (op instanceof SqlOverlapsOperator) {
            regex = "[ ]*<td>period1 " + name + " period2</td>";
        } else if (op instanceof SqlFunction && (op.getOperandTypeChecker() == null || op.getOperandTypeChecker().getOperandCountRange().getMin() != 0)) {
            regex = prefix + "\\| .*" + name + "\\(.*";
        } else {
            regex = prefix + "\\| .*" + name + ".*";
        }
        map.put(regex, new PatternOp(Pattern.compile(regex), name));
    }
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlOverlapsOperator(org.apache.calcite.sql.fun.SqlOverlapsOperator) SqlSpecialOperator(org.apache.calcite.sql.SqlSpecialOperator) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 18 with SqlFunction

use of org.apache.calcite.sql.SqlFunction in project flink-mirror by flink-ci.

the class SqlValidatorImpl method validateCall.

public void validateCall(SqlCall call, SqlValidatorScope scope) {
    final SqlOperator operator = call.getOperator();
    if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !this.config.sqlConformance().allowNiladicParentheses()) {
        // SqlIdentifier.)
        throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null);
    }
    SqlValidatorScope operandScope = scope.getOperandScope(call);
    if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) {
        throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
    }
    // Delegate validation to the operator.
    operator.validateCall(call, this, scope, operandScope);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 19 with SqlFunction

use of org.apache.calcite.sql.SqlFunction in project flink-mirror by flink-ci.

the class SqlValidatorImpl method deriveConstructorType.

public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
    SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
    assert sqlIdentifier != null;
    RelDataType type = catalogReader.getNamedType(sqlIdentifier);
    if (type == null) {
        // TODO jvs 12-Feb-2005:  proper type name formatting
        throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
    }
    if (resolvedConstructor == null) {
        if (call.operandCount() > 0) {
            // no user-defined constructor could be found
            throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
        }
    } else {
        SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
        RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
        assert type == returnType;
    }
    if (config.identifierExpansion()) {
        if (resolvedConstructor != null) {
            ((SqlBasicCall) call).setOperator(resolvedConstructor);
        } else {
            // fake a fully-qualified call to the default constructor
            ((SqlBasicCall) call).setOperator(new SqlFunction(type.getSqlIdentifier(), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
        }
    }
    return type;
}
Also used : SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlCall(org.apache.calcite.sql.SqlCall) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 20 with SqlFunction

use of org.apache.calcite.sql.SqlFunction in project Mycat2 by MyCATApache.

the class CheckingUserDefinedAndConvertFunctionVisitor method visitCall.

@Override
public Void visitCall(RexCall call) {
    SqlOperator operator = call.getOperator();
    String name = operator.getName();
    if (operator instanceof SqlFunction) {
        containsUsedDefinedFunction |= Information_Functions.containsKey(name, false);
    }
    if (operator == MycatSessionValueFunction.BIGINT_TYPE_INSTANCE || operator == MycatSessionValueFunction.STRING_TYPE_INSTANCE) {
        containsUsedDefinedFunction = true;
    }
    return super.visitCall(call);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlFunction(org.apache.calcite.sql.SqlFunction)

Aggregations

SqlFunction (org.apache.calcite.sql.SqlFunction)57 SqlOperator (org.apache.calcite.sql.SqlOperator)26 ArrayList (java.util.ArrayList)13 RoundOperatorConversion (org.apache.druid.sql.calcite.expression.builtin.RoundOperatorConversion)12 Test (org.junit.Test)12 RexNode (org.apache.calcite.rex.RexNode)8 SqlCall (org.apache.calcite.sql.SqlCall)8 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)8 AssignableOperandTypeChecker (org.apache.calcite.sql.type.AssignableOperandTypeChecker)6 BitString (org.apache.calcite.util.BitString)6 ImmutableList (com.google.common.collect.ImmutableList)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)5 RexCall (org.apache.calcite.rex.RexCall)4 RexLiteral (org.apache.calcite.rex.RexLiteral)4 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)4 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)4 BigDecimal (java.math.BigDecimal)3 TimeUnitRange (org.apache.calcite.avatica.util.TimeUnitRange)3 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)3