Search in sources :

Example 21 with SqlNode

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

the class SqlExtendOperator method unparse.

@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
    final SqlOperator operator = call.getOperator();
    assert call.operandCount() == 2;
    final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.SIMPLE);
    call.operand(0).unparse(writer, leftPrec, operator.getLeftPrec());
    writer.setNeedWhitespace(true);
    writer.sep(operator.getName());
    final SqlNodeList list = call.operand(1);
    final SqlWriter.Frame frame2 = writer.startList("(", ")");
    for (Ord<SqlNode> node2 : Ord.zip(list)) {
        if (node2.i > 0 && node2.i % 2 == 0) {
            writer.sep(",");
        }
        node2.e.unparse(writer, 2, 3);
    }
    writer.endList(frame2);
    writer.endList(frame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlOperator(org.apache.calcite.sql.SqlOperator) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlNode(org.apache.calcite.sql.SqlNode)

Example 22 with SqlNode

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

the class SqlRollupOperator method unparseCube.

private static void unparseCube(SqlWriter writer, SqlCall call) {
    writer.keyword(call.getOperator().getName());
    final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")");
    for (SqlNode operand : call.getOperandList()) {
        writer.sep(",");
        if (operand.getKind() == SqlKind.ROW) {
            final SqlWriter.Frame frame2 = writer.startList(SqlWriter.FrameTypeEnum.SIMPLE, "(", ")");
            for (SqlNode operand2 : ((SqlCall) operand).getOperandList()) {
                writer.sep(",");
                operand2.unparse(writer, 0, 0);
            }
            writer.endList(frame2);
        } else if (operand instanceof SqlNodeList && ((SqlNodeList) operand).size() == 0) {
            writer.keyword("()");
        } else {
            operand.unparse(writer, 0, 0);
        }
    }
    writer.endList(frame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlCall(org.apache.calcite.sql.SqlCall) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlNode(org.apache.calcite.sql.SqlNode)

Example 23 with SqlNode

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

the class SqlSequenceValueOperator method validateCall.

@Override
public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) {
    List<SqlNode> operands = call.getOperandList();
    assert operands.size() == 1;
    assert operands.get(0) instanceof SqlIdentifier;
    SqlIdentifier id = (SqlIdentifier) operands.get(0);
    validator.validateSequenceValue(scope, id);
}
Also used : SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 24 with SqlNode

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

the class SqlSubstringFunction method checkOperandTypes.

public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    SqlValidator validator = callBinding.getValidator();
    SqlValidatorScope scope = callBinding.getScope();
    final List<SqlNode> operands = callBinding.operands();
    int n = operands.size();
    assert (3 == n) || (2 == n);
    if (!OperandTypes.STRING.checkSingleOperandType(callBinding, operands.get(0), 0, throwOnFailure)) {
        return false;
    }
    if (2 == n) {
        if (!OperandTypes.NUMERIC.checkSingleOperandType(callBinding, operands.get(1), 0, throwOnFailure)) {
            return false;
        }
    } else {
        RelDataType t1 = validator.deriveType(scope, operands.get(1));
        RelDataType t2 = validator.deriveType(scope, operands.get(2));
        if (SqlTypeUtil.inCharFamily(t1)) {
            if (!OperandTypes.STRING.checkSingleOperandType(callBinding, operands.get(1), 0, throwOnFailure)) {
                return false;
            }
            if (!OperandTypes.STRING.checkSingleOperandType(callBinding, operands.get(2), 0, throwOnFailure)) {
                return false;
            }
            if (!SqlTypeUtil.isCharTypeComparable(callBinding, operands, throwOnFailure)) {
                return false;
            }
        } else {
            if (!OperandTypes.NUMERIC.checkSingleOperandType(callBinding, operands.get(1), 0, throwOnFailure)) {
                return false;
            }
            if (!OperandTypes.NUMERIC.checkSingleOperandType(callBinding, operands.get(2), 0, throwOnFailure)) {
                return false;
            }
        }
        if (!SqlTypeUtil.inSameFamily(t1, t2)) {
            if (throwOnFailure) {
                throw callBinding.newValidationSignatureError();
            }
            return false;
        }
    }
    return true;
}
Also used : SqlValidatorScope(org.apache.calcite.sql.validate.SqlValidatorScope) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

Example 25 with SqlNode

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

the class SqlTranslate3Function method unparse.

// ~ Methods ----------------------------------------------------------------
@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
    final SqlWriter.Frame frame = writer.startFunCall("TRANSLATE");
    for (SqlNode sqlNode : call.getOperandList()) {
        writer.sep(",");
        sqlNode.unparse(writer, leftPrec, rightPrec);
    }
    writer.endFunCall(frame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) 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