use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlItemOperator method reduceExpr.
@Override
public ReduceResult reduceExpr(int ordinal, TokenSequence list) {
SqlNode left = list.node(ordinal - 1);
SqlNode right = list.node(ordinal + 1);
return new ReduceResult(ordinal - 1, ordinal + 2, createCall(SqlParserPos.sum(Arrays.asList(left.getParserPosition(), right.getParserPosition(), list.pos(ordinal))), left, right));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlItemOperator method checkOperandTypes.
@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
final SqlNode left = callBinding.operand(0);
final SqlNode right = callBinding.operand(1);
if (!ARRAY_OR_MAP.checkSingleOperandType(callBinding, left, 0, throwOnFailure)) {
return false;
}
final RelDataType operandType = callBinding.getOperandType(0);
final SqlSingleOperandTypeChecker checker = getChecker(operandType);
return checker.checkSingleOperandType(callBinding, right, 0, throwOnFailure);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlLikeOperator method reduceExpr.
public ReduceResult reduceExpr(final int opOrdinal, TokenSequence list) {
// Example:
// a LIKE b || c ESCAPE d || e AND f
// | | | | | |
// exp0 exp1 exp2
SqlNode exp0 = list.node(opOrdinal - 1);
SqlOperator op = list.op(opOrdinal);
assert op instanceof SqlLikeOperator;
SqlNode exp1 = SqlParserUtil.toTreeEx(list, opOrdinal + 1, getRightPrec(), SqlKind.ESCAPE);
SqlNode exp2 = null;
if ((opOrdinal + 2) < list.size()) {
if (list.isOp(opOrdinal + 2)) {
final SqlOperator op2 = list.op(opOrdinal + 2);
if (op2.getKind() == SqlKind.ESCAPE) {
exp2 = SqlParserUtil.toTreeEx(list, opOrdinal + 3, getRightPrec(), SqlKind.ESCAPE);
}
}
}
final SqlNode[] operands;
int end;
if (exp2 != null) {
operands = new SqlNode[] { exp0, exp1, exp2 };
end = opOrdinal + 4;
} else {
operands = new SqlNode[] { exp0, exp1 };
end = opOrdinal + 2;
}
SqlCall call = createCall(SqlParserPos.ZERO, operands);
return new ReduceResult(opOrdinal - 1, end, call);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlBetweenOperator method reduceExpr.
public ReduceResult reduceExpr(int opOrdinal, TokenSequence list) {
SqlOperator op = list.op(opOrdinal);
assert op == this;
// Break the expression up into expressions. For example, a simple
// expression breaks down as follows:
//
// opOrdinal endExp1
// | |
// a + b BETWEEN c + d AND e + f
// |_____| |_____| |_____|
// exp0 exp1 exp2
// Create the expression between 'BETWEEN' and 'AND'.
SqlNode exp1 = SqlParserUtil.toTreeEx(list, opOrdinal + 1, 0, SqlKind.AND);
if ((opOrdinal + 2) >= list.size()) {
SqlParserPos lastPos = list.pos(list.size() - 1);
final int line = lastPos.getEndLineNum();
final int col = lastPos.getEndColumnNum() + 1;
SqlParserPos errPos = new SqlParserPos(line, col, line, col);
throw SqlUtil.newContextException(errPos, RESOURCE.betweenWithoutAnd());
}
if (!list.isOp(opOrdinal + 2) || list.op(opOrdinal + 2).getKind() != SqlKind.AND) {
SqlParserPos errPos = list.pos(opOrdinal + 2);
throw SqlUtil.newContextException(errPos, RESOURCE.betweenWithoutAnd());
}
// Create the expression after 'AND', but stopping if we encounter an
// operator of lower precedence.
//
// For example,
// a BETWEEN b AND c + d OR e
// becomes
// (a BETWEEN b AND c + d) OR e
// because OR has lower precedence than BETWEEN.
SqlNode exp2 = SqlParserUtil.toTreeEx(list, opOrdinal + 3, getRightPrec(), SqlKind.OTHER);
// Create the call.
SqlNode exp0 = list.node(opOrdinal - 1);
SqlCall newExp = createCall(list.pos(opOrdinal), exp0, exp1, exp2);
// Replace all of the matched nodes with the single reduced node.
return new ReduceResult(opOrdinal - 1, opOrdinal + 4, newExp);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlCastFunction method checkOperandTypes.
/**
* Makes sure that the number and types of arguments are allowable.
* Operators (such as "ROW" and "AS") which do not check their arguments can
* override this method.
*/
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
final SqlNode left = callBinding.operand(0);
final SqlNode right = callBinding.operand(1);
if (SqlUtil.isNullLiteral(left, false) || left instanceof SqlDynamicParam) {
return true;
}
RelDataType validatedNodeType = callBinding.getValidator().getValidatedNodeType(left);
RelDataType returnType = callBinding.getValidator().deriveType(callBinding.getScope(), right);
if (!SqlTypeUtil.canCastFrom(returnType, validatedNodeType, true)) {
if (throwOnFailure) {
throw callBinding.newError(RESOURCE.cannotCastValue(validatedNodeType.toString(), returnType.toString()));
}
return false;
}
if (SqlTypeUtil.areCharacterSetsMismatched(validatedNodeType, returnType)) {
if (throwOnFailure) {
// set mismatch.
throw callBinding.newError(RESOURCE.cannotCastValue(validatedNodeType.getFullTypeString(), returnType.getFullTypeString()));
}
return false;
}
return true;
}
Aggregations