Search in sources :

Example 56 with SqlFunction

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

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 57 with SqlFunction

use of org.apache.calcite.sql.SqlFunction in project ignite-3 by apache.

the class RelJson method toJson.

private Object toJson(RexNode node) {
    // removes calls to SEARCH and the included Sarg and converts them to comparisons
    node = RexUtil.expandSearch(Commons.cluster().getRexBuilder(), null, node);
    Map<String, Object> map;
    switch(node.getKind()) {
        case FIELD_ACCESS:
            map = map();
            RexFieldAccess fieldAccess = (RexFieldAccess) node;
            map.put("field", fieldAccess.getField().getName());
            map.put("expr", toJson(fieldAccess.getReferenceExpr()));
            return map;
        case LITERAL:
            RexLiteral literal = (RexLiteral) node;
            Object value = literal.getValue3();
            map = map();
            map.put("literal", toJson(value));
            map.put("type", toJson(node.getType()));
            return map;
        case INPUT_REF:
            map = map();
            map.put("input", ((RexSlot) node).getIndex());
            map.put("name", ((RexVariable) node).getName());
            return map;
        case DYNAMIC_PARAM:
            map = map();
            map.put("input", ((RexDynamicParam) node).getIndex());
            map.put("name", ((RexVariable) node).getName());
            map.put("type", toJson(node.getType()));
            map.put("dynamic", true);
            return map;
        case LOCAL_REF:
            map = map();
            map.put("input", ((RexSlot) node).getIndex());
            map.put("name", ((RexVariable) node).getName());
            map.put("type", toJson(node.getType()));
            return map;
        case CORREL_VARIABLE:
            map = map();
            map.put("correl", ((RexVariable) node).getName());
            map.put("type", toJson(node.getType()));
            return map;
        default:
            if (node instanceof RexCall) {
                RexCall call = (RexCall) node;
                map = map();
                map.put("op", toJson(call.getOperator()));
                List<Object> list = list();
                for (RexNode operand : call.getOperands()) {
                    list.add(toJson(operand));
                }
                map.put("operands", list);
                if (node.getKind() == SqlKind.CAST) {
                    map.put("type", toJson(node.getType()));
                }
                if (call.getOperator() instanceof SqlFunction) {
                    if (((SqlFunction) call.getOperator()).getFunctionType().isUserDefined()) {
                        SqlOperator op = call.getOperator();
                        map.put("class", op.getClass().getName());
                        map.put("type", toJson(node.getType()));
                        map.put("deterministic", op.isDeterministic());
                        map.put("dynamic", op.isDynamicFunction());
                    }
                }
                if (call instanceof RexOver) {
                    RexOver over = (RexOver) call;
                    map.put("distinct", over.isDistinct());
                    map.put("type", toJson(node.getType()));
                    map.put("window", toJson(over.getWindow()));
                }
                return map;
            }
            throw new UnsupportedOperationException("unknown rex " + node);
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) RexOver(org.apache.calcite.rex.RexOver) RexLiteral(org.apache.calcite.rex.RexLiteral) SqlOperator(org.apache.calcite.sql.SqlOperator) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) RexNode(org.apache.calcite.rex.RexNode) 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