Java Code Examples for org.apache.calcite.sql.SqlCallBinding#newError()
The following examples show how to use
org.apache.calcite.sql.SqlCallBinding#newError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlJsonObjectFunction.java From Bats with Apache License 2.0 | 6 votes |
@Override public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) { final int count = callBinding.getOperandCount(); for (int i = 1; i < count; i += 2) { RelDataType nameType = callBinding.getOperandType(i); if (!SqlTypeUtil.inCharFamily(nameType)) { if (throwOnFailure) { throw callBinding.newError(RESOURCE.expectedCharacter()); } return false; } if (nameType.isNullable()) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.operand(i).toString())); } return false; } } return true; }
Example 2
Source File: SqlJsonObjectFunction.java From calcite with Apache License 2.0 | 6 votes |
@Override public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) { final int count = callBinding.getOperandCount(); for (int i = 1; i < count; i += 2) { RelDataType nameType = callBinding.getOperandType(i); if (!SqlTypeUtil.inCharFamily(nameType)) { if (throwOnFailure) { throw callBinding.newError(RESOURCE.expectedCharacter()); } return false; } if (nameType.isNullable()) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.operand(i).toString())); } return false; } } return true; }
Example 3
Source File: SqlCastFunction.java From Bats with Apache License 2.0 | 5 votes |
/** * 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) { // Include full type string to indicate character // set mismatch. throw callBinding.newError( RESOURCE.cannotCastValue(validatedNodeType.getFullTypeString(), returnType.getFullTypeString())); } return false; } return true; }
Example 4
Source File: SqlJsonValueFunction.java From Bats with Apache License 2.0 | 5 votes |
private boolean canCastFrom(SqlCallBinding callBinding, boolean throwOnFailure, RelDataType inType, RelDataType outType) { if (SqlTypeUtil.canCastFrom(outType, inType, true)) { return true; } if (throwOnFailure) { throw callBinding.newError( RESOURCE.cannotCastValue(inType.toString(), outType.toString())); } return false; }
Example 5
Source File: LiteralOperandTypeChecker.java From Bats with Apache License 2.0 | 5 votes |
public boolean checkSingleOperandType( SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) { Util.discard(iFormalOperand); if (SqlUtil.isNullLiteral(node, true)) { if (allowNull) { return true; } if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.getOperator().getName())); } return false; } if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustBeLiteral( callBinding.getOperator().getName())); } return false; } return true; }
Example 6
Source File: SqlCastFunction.java From calcite with Apache License 2.0 | 5 votes |
/** * 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) { // Include full type string to indicate character // set mismatch. throw callBinding.newError( RESOURCE.cannotCastValue(validatedNodeType.getFullTypeString(), returnType.getFullTypeString())); } return false; } return true; }
Example 7
Source File: LiteralOperandTypeChecker.java From calcite with Apache License 2.0 | 5 votes |
public boolean checkSingleOperandType( SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) { Util.discard(iFormalOperand); if (SqlUtil.isNullLiteral(node, true)) { if (allowNull) { return true; } if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.getOperator().getName())); } return false; } if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustBeLiteral( callBinding.getOperator().getName())); } return false; } return true; }
Example 8
Source File: MultisetOperandTypeChecker.java From Bats with Apache License 2.0 | 4 votes |
public boolean checkOperandTypes( SqlCallBinding callBinding, boolean throwOnFailure) { final SqlNode op0 = callBinding.operand(0); if (!OperandTypes.MULTISET.checkSingleOperandType( callBinding, op0, 0, throwOnFailure)) { return false; } final SqlNode op1 = callBinding.operand(1); if (!OperandTypes.MULTISET.checkSingleOperandType( callBinding, op1, 0, throwOnFailure)) { return false; } // TODO: this won't work if element types are of ROW types and there is // a mismatch. RelDataType biggest = callBinding.getTypeFactory().leastRestrictive( ImmutableList.of( callBinding.getValidator() .deriveType(callBinding.getScope(), op0) .getComponentType(), callBinding.getValidator() .deriveType(callBinding.getScope(), op1) .getComponentType())); if (null == biggest) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.typeNotComparable( op0.getParserPosition().toString(), op1.getParserPosition().toString())); } return false; } return true; }
Example 9
Source File: MultisetOperandTypeChecker.java From calcite with Apache License 2.0 | 4 votes |
public boolean checkOperandTypes( SqlCallBinding callBinding, boolean throwOnFailure) { final SqlNode op0 = callBinding.operand(0); if (!OperandTypes.MULTISET.checkSingleOperandType( callBinding, op0, 0, throwOnFailure)) { return false; } final SqlNode op1 = callBinding.operand(1); if (!OperandTypes.MULTISET.checkSingleOperandType( callBinding, op1, 0, throwOnFailure)) { return false; } // TODO: this won't work if element types are of ROW types and there is // a mismatch. RelDataType biggest = callBinding.getTypeFactory().leastRestrictive( ImmutableList.of( callBinding.getValidator() .deriveType(callBinding.getScope(), op0) .getComponentType(), callBinding.getValidator() .deriveType(callBinding.getScope(), op1) .getComponentType())); if (null == biggest) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.typeNotComparable( op0.getParserPosition().toString(), op1.getParserPosition().toString())); } return false; } return true; }