Search in sources :

Example 21 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class ProcedureNamespace method validateImpl.

// ~ Methods ----------------------------------------------------------------
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 SqlUserDefinedTableFunction) {
        assert type.getSqlTypeName() == SqlTypeName.CURSOR : "User-defined table function should have CURSOR type, not " + type;
        final SqlUserDefinedTableFunction udf = (SqlUserDefinedTableFunction) operator;
        return udf.getRowType(validator.typeFactory, callBinding.operands());
    } else if (operator instanceof SqlUserDefinedTableMacro) {
        assert type.getSqlTypeName() == SqlTypeName.CURSOR : "User-defined table macro should have CURSOR type, not " + type;
        final SqlUserDefinedTableMacro udf = (SqlUserDefinedTableMacro) operator;
        return udf.getTable(validator.typeFactory, callBinding.operands()).getRowType(validator.typeFactory);
    }
    return type;
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 22 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class RelOptUtil method isDistinctFromInternal.

private static RexNode isDistinctFromInternal(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg) {
    SqlOperator nullOp;
    SqlOperator eqOp;
    if (neg) {
        nullOp = SqlStdOperatorTable.IS_NULL;
        eqOp = SqlStdOperatorTable.EQUALS;
    } else {
        nullOp = SqlStdOperatorTable.IS_NOT_NULL;
        eqOp = SqlStdOperatorTable.NOT_EQUALS;
    }
    // By the time the ELSE is reached, x and y are known to be not null;
    // therefore the whole CASE is not null.
    RexNode[] whenThenElse = { // when x is null
    rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, x), // then return y is [not] null
    rexBuilder.makeCall(nullOp, y), // when y is null
    rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, y), // then return x is [not] null
    rexBuilder.makeCall(nullOp, x), // else return x compared to y
    rexBuilder.makeCall(eqOp, rexBuilder.makeNotNull(x), rexBuilder.makeNotNull(y)) };
    return rexBuilder.makeCall(SqlStdOperatorTable.CASE, whenThenElse);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) RexNode(org.apache.calcite.rex.RexNode)

Example 23 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class VisitorDataContext method removeCast.

private static RexNode removeCast(RexNode inputRef) {
    if (inputRef instanceof RexCall) {
        final RexCall castedRef = (RexCall) inputRef;
        final SqlOperator operator = castedRef.getOperator();
        if (operator instanceof SqlCastFunction) {
            inputRef = castedRef.getOperands().get(0);
        }
    }
    return inputRef;
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SqlCastFunction(org.apache.calcite.sql.fun.SqlCastFunction) SqlOperator(org.apache.calcite.sql.SqlOperator)

Example 24 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class ReflectiveSqlOperatorTable method lookupOperatorOverloads.

// implement SqlOperatorTable
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) {
    // NOTE jvs 3-Mar-2005:  ignore category until someone cares
    String simpleName;
    if (opName.names.size() > 1) {
        if (opName.names.get(opName.names.size() - 2).equals(IS_NAME)) {
            // per SQL99 Part 2 Section 10.4 Syntax Rule 7.b.ii.1
            simpleName = Util.last(opName.names);
        } else {
            return;
        }
    } else {
        simpleName = opName.getSimple();
    }
    // Always look up built-in operators case-insensitively. Even in sessions
    // with unquotedCasing=UNCHANGED and caseSensitive=true.
    final Collection<SqlOperator> list = operators.get(new Key(simpleName, syntax));
    if (list.isEmpty()) {
        return;
    }
    for (SqlOperator op : list) {
        if (op.getSyntax() == syntax) {
            operatorList.add(op);
        } else if (syntax == SqlSyntax.FUNCTION && op instanceof SqlFunction) {
            // this special case is needed for operators like CAST,
            // which are treated as functions but have special syntax
            operatorList.add(op);
        }
    }
    // Shouldn't it be covered by search above?
    switch(syntax) {
        case BINARY:
        case PREFIX:
        case POSTFIX:
            for (SqlOperator extra : operators.get(new Key(simpleName, syntax))) {
                // REVIEW: should only search operators added during this method?
                if (extra != null && !operatorList.contains(extra)) {
                    operatorList.add(extra);
                }
            }
            break;
    }
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 25 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class RexProgramTest method testSimplifyNot.

@Test
public void testSimplifyNot() {
    final RelDataType booleanNullableType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN), true);
    final RexNode booleanInput = rexBuilder.makeInputRef(booleanNullableType, 0);
    final RexNode isFalse = rexBuilder.makeCall(SqlStdOperatorTable.IS_FALSE, booleanInput);
    final RexCall result = (RexCall) simplify(isFalse);
    assertThat(result.getType().isNullable(), is(false));
    assertThat(result.getOperator(), is((SqlOperator) SqlStdOperatorTable.IS_FALSE));
    assertThat(result.getOperands().size(), is(1));
    assertThat(result.getOperands().get(0), is(booleanInput));
    // Make sure that IS_FALSE(IS_FALSE(nullable boolean)) != IS_TRUE(nullable boolean)
    // IS_FALSE(IS_FALSE(null)) = IS_FALSE(false) = true
    // IS_TRUE(null) = false
    final RexNode isFalseIsFalse = rexBuilder.makeCall(SqlStdOperatorTable.IS_FALSE, isFalse);
    final RexCall result2 = (RexCall) simplify(isFalseIsFalse);
    assertThat(result2.getType().isNullable(), is(false));
    assertThat(result2.getOperator(), is((SqlOperator) SqlStdOperatorTable.IS_NOT_FALSE));
    assertThat(result2.getOperands().size(), is(1));
    assertThat(result2.getOperands().get(0), is(booleanInput));
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SqlOperator(org.apache.calcite.sql.SqlOperator) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Aggregations

SqlOperator (org.apache.calcite.sql.SqlOperator)129 ArrayList (java.util.ArrayList)44 RexNode (org.apache.calcite.rex.RexNode)41 RelDataType (org.apache.calcite.rel.type.RelDataType)25 SqlCall (org.apache.calcite.sql.SqlCall)24 RexCall (org.apache.calcite.rex.RexCall)21 SqlNode (org.apache.calcite.sql.SqlNode)21 SqlKind (org.apache.calcite.sql.SqlKind)15 List (java.util.List)13 SqlFunction (org.apache.calcite.sql.SqlFunction)13 RelNode (org.apache.calcite.rel.RelNode)12 RexBuilder (org.apache.calcite.rex.RexBuilder)11 RexInputRef (org.apache.calcite.rex.RexInputRef)11 Test (org.junit.Test)11 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)10 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)10 NlsString (org.apache.calcite.util.NlsString)10 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)9 SqlOperator (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator)9 RexLiteral (org.apache.calcite.rex.RexLiteral)9