use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class RexSimplify method simplifyIs2.
private RexNode simplifyIs2(SqlKind kind, RexNode a) {
switch(kind) {
case IS_NULL:
// x IS NULL ==> FALSE (if x is not nullable)
if (!a.getType().isNullable()) {
return rexBuilder.makeLiteral(false);
}
break;
case IS_NOT_NULL:
// x IS NOT NULL ==> TRUE (if x is not nullable)
RexNode simplified = simplifyIsNotNull(a);
if (simplified != null) {
return simplified;
}
break;
case IS_TRUE:
case IS_NOT_FALSE:
// x IS NOT FALSE ==> x (if x is not nullable)
if (!a.getType().isNullable()) {
return simplify(a);
}
break;
case IS_FALSE:
case IS_NOT_TRUE:
// x IS FALSE ==> NOT x (if x is not nullable)
if (!a.getType().isNullable()) {
return simplify(rexBuilder.makeCall(SqlStdOperatorTable.NOT, a));
}
break;
}
switch(a.getKind()) {
case NOT:
// (NOT x) IS TRUE ==> x IS FALSE
// Similarly for IS NOT TRUE, IS FALSE, etc.
//
// Note that
// (NOT x) IS TRUE !=> x IS FALSE
// because of null values.
final SqlOperator notKind = RexUtil.op(kind.negateNullSafe());
final RexNode arg = ((RexCall) a).operands.get(0);
return simplify(rexBuilder.makeCall(notKind, arg));
}
RexNode a2 = simplify(a);
if (a != a2) {
return rexBuilder.makeCall(RexUtil.op(kind), ImmutableList.of(a2));
}
// cannot be simplified
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class RexSqlReflectiveConvertletTable method get.
// ~ Methods ----------------------------------------------------------------
public RexSqlConvertlet get(RexCall call) {
RexSqlConvertlet convertlet;
final SqlOperator op = call.getOperator();
// Is there a convertlet for this operator
// (e.g. SqlStdOperatorTable.plusOperator)?
convertlet = (RexSqlConvertlet) map.get(op);
if (convertlet != null) {
return convertlet;
}
// Is there a convertlet for this class of operator
// (e.g. SqlBinaryOperator)?
Class<? extends Object> clazz = op.getClass();
while (clazz != null) {
convertlet = (RexSqlConvertlet) map.get(clazz);
if (convertlet != null) {
return convertlet;
}
clazz = clazz.getSuperclass();
}
// Is there a convertlet for this class of expression
// (e.g. SqlCall)?
clazz = call.getClass();
while (clazz != null) {
convertlet = (RexSqlConvertlet) map.get(clazz);
if (convertlet != null) {
return convertlet;
}
clazz = clazz.getSuperclass();
}
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class RexSqlStandardConvertletTable method convertCall.
// ~ Methods ----------------------------------------------------------------
/**
* Converts a call to an operator into a {@link SqlCall} to the same
* operator.
*
* <p>Called automatically via reflection.
*
* @param converter Converter
* @param call Call
* @return Sql call
*/
public SqlNode convertCall(RexToSqlNodeConverter converter, RexCall call) {
if (get(call) == null) {
return null;
}
final SqlOperator op = call.getOperator();
final List<RexNode> operands = call.getOperands();
final SqlNode[] exprs = convertExpressionList(converter, operands);
if (exprs == null) {
return null;
}
return new SqlBasicCall(op, exprs, SqlParserPos.ZERO);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class LookupOperatorOverloadsTest method test.
@Test
public void test() throws SQLException {
final String schemaName = "MySchema";
final String funcName = "MyFUNC";
final String anotherName = "AnotherFunc";
try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add(schemaName, new AbstractSchema());
final TableFunction table = TableFunctionImpl.create(Smalls.MAZE_METHOD);
schema.add(funcName, table);
schema.add(anotherName, table);
final TableFunction table2 = TableFunctionImpl.create(Smalls.MAZE3_METHOD);
schema.add(funcName, table2);
final CalciteServerStatement statement = connection.createStatement().unwrap(CalciteServerStatement.class);
final CalcitePrepare.Context prepareContext = statement.createPrepareContext();
final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
CalciteCatalogReader reader = new CalciteCatalogReader(prepareContext.getRootSchema(), ImmutableList.<String>of(), typeFactory, prepareContext.config());
final List<SqlOperator> operatorList = new ArrayList<>();
SqlIdentifier myFuncIdentifier = new SqlIdentifier(Lists.newArrayList(schemaName, funcName), null, SqlParserPos.ZERO, null);
reader.lookupOperatorOverloads(myFuncIdentifier, SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION, SqlSyntax.FUNCTION, operatorList);
checkFunctionType(2, funcName, operatorList);
operatorList.clear();
reader.lookupOperatorOverloads(myFuncIdentifier, SqlFunctionCategory.USER_DEFINED_FUNCTION, SqlSyntax.FUNCTION, operatorList);
checkFunctionType(0, null, operatorList);
operatorList.clear();
SqlIdentifier anotherFuncIdentifier = new SqlIdentifier(Lists.newArrayList(schemaName, anotherName), null, SqlParserPos.ZERO, null);
reader.lookupOperatorOverloads(anotherFuncIdentifier, SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION, SqlSyntax.FUNCTION, operatorList);
checkFunctionType(1, anotherName, operatorList);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class LookupOperatorOverloadsTest method checkFunctionType.
private void checkFunctionType(int size, String name, List<SqlOperator> operatorList) {
assertThat(size, is(operatorList.size()));
for (SqlOperator op : operatorList) {
assertThat(op, instanceOf(SqlUserDefinedTableFunction.class));
assertThat(name, is(op.getName()));
}
}
Aggregations