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;
}
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);
}
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;
}
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;
}
}
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));
}
Aggregations