Search in sources :

Example 16 with SqlNode

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

the class SqlCastFunction method inferReturnType.

// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    assert opBinding.getOperandCount() == 2;
    RelDataType ret = opBinding.getOperandType(1);
    RelDataType firstType = opBinding.getOperandType(0);
    ret = opBinding.getTypeFactory().createTypeWithNullability(ret, firstType.isNullable());
    if (opBinding instanceof SqlCallBinding) {
        SqlCallBinding callBinding = (SqlCallBinding) opBinding;
        SqlNode operand0 = callBinding.operand(0);
        // to them using the type they are casted to.
        if (((operand0 instanceof SqlLiteral) && (((SqlLiteral) operand0).getValue() == null)) || (operand0 instanceof SqlDynamicParam)) {
            final SqlValidatorImpl validator = (SqlValidatorImpl) callBinding.getValidator();
            validator.setValidatedNodeType(operand0, ret);
        }
    }
    return ret;
}
Also used : SqlValidatorImpl(org.apache.calcite.sql.validate.SqlValidatorImpl) SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlNode(org.apache.calcite.sql.SqlNode)

Example 17 with SqlNode

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

the class SqlMultisetValueConstructor method unparse.

public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
    // "MULTISET" or "ARRAY"
    writer.keyword(getName());
    final SqlWriter.Frame frame = writer.startList("[", "]");
    for (SqlNode operand : call.getOperandList()) {
        writer.sep(",");
        operand.unparse(writer, leftPrec, rightPrec);
    }
    writer.endList(frame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 18 with SqlNode

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

the class SqlNullifFunction method rewriteCall.

// ~ Methods ----------------------------------------------------------------
// override SqlOperator
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
    List<SqlNode> operands = call.getOperandList();
    SqlParserPos pos = call.getParserPosition();
    checkOperandCount(validator, getOperandTypeChecker(), call);
    assert operands.size() == 2;
    SqlNodeList whenList = new SqlNodeList(pos);
    SqlNodeList thenList = new SqlNodeList(pos);
    whenList.add(operands.get(1));
    thenList.add(SqlLiteral.createNull(SqlParserPos.ZERO));
    return SqlCase.createSwitched(pos, operands.get(0), whenList, thenList, SqlNode.clone(operands.get(0)));
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlNode(org.apache.calcite.sql.SqlNode)

Example 19 with SqlNode

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

the class SqlColumnListConstructor method unparse.

// ~ Methods ----------------------------------------------------------------
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
    writer.keyword("ROW");
    final SqlWriter.Frame frame = writer.startList("(", ")");
    for (SqlNode operand : call.getOperandList()) {
        writer.sep(",");
        operand.unparse(writer, leftPrec, rightPrec);
    }
    writer.endList(frame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 20 with SqlNode

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

the class SqlDatePartFunction method rewriteCall.

// ~ Methods ----------------------------------------------------------------
@Override
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
    final List<SqlNode> operands = call.getOperandList();
    final SqlParserPos pos = call.getParserPosition();
    return SqlStdOperatorTable.EXTRACT.createCall(pos, new SqlIntervalQualifier(timeUnit, null, SqlParserPos.ZERO), operands.get(0));
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlNode (org.apache.calcite.sql.SqlNode)510 RelDataType (org.apache.calcite.rel.type.RelDataType)141 SqlNodeList (org.apache.calcite.sql.SqlNodeList)98 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)84 SqlCall (org.apache.calcite.sql.SqlCall)81 ArrayList (java.util.ArrayList)78 RelNode (org.apache.calcite.rel.RelNode)60 Test (org.junit.Test)59 BitString (org.apache.calcite.util.BitString)46 SqlSelect (org.apache.calcite.sql.SqlSelect)45 SqlWriter (org.apache.calcite.sql.SqlWriter)42 RexNode (org.apache.calcite.rex.RexNode)40 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)33 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)25 SqlLiteral (org.apache.calcite.sql.SqlLiteral)23 SqlOperator (org.apache.calcite.sql.SqlOperator)23 SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)22 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)21 ImmutableList (com.google.common.collect.ImmutableList)20 SqlValidator (org.apache.calcite.sql.validate.SqlValidator)20