use of org.apache.calcite.sql.validate.SqlValidatorException in project hazelcast by hazelcast.
the class HazelcastCallBinding method newValidationSignatureError.
@Override
public CalciteException newValidationSignatureError() {
SqlOperator operator = getOperator();
SqlValidator validator = getValidator();
SqlCall call = getCall();
String operandTypes = getOperandTypes(validator, call, getScope());
Resources.ExInst<SqlValidatorException> error;
String operatorName = '\'' + operator.getName() + '\'';
switch(operator.getSyntax()) {
case FUNCTION:
case FUNCTION_STAR:
case FUNCTION_ID:
error = RESOURCES.invalidFunctionOperands(operatorName, operandTypes);
break;
default:
error = RESOURCES.invalidOperatorOperands(operatorName, operandTypes);
}
return validator.newValidationError(call, error);
}
use of org.apache.calcite.sql.validate.SqlValidatorException in project calcite by apache.
the class CalciteAssert method checkValidationException.
static Function<Throwable, Void> checkValidationException(final String expected) {
return new Function<Throwable, Void>() {
@Nullable
@Override
public Void apply(@Nullable Throwable throwable) {
assertNotNull("Nothing was thrown", throwable);
Exception exception = containsCorrectException(throwable);
assertTrue("Expected to fail at validation, but did not", exception != null);
if (expected != null) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
exception.printStackTrace(printWriter);
printWriter.flush();
String stack = stringWriter.toString();
assertTrue(stack, stack.contains(expected));
}
return null;
}
private boolean isCorrectException(Throwable throwable) {
return throwable instanceof SqlValidatorException || throwable instanceof CalciteException;
}
private Exception containsCorrectException(Throwable root) {
Throwable currentCause = root;
while (currentCause != null) {
if (isCorrectException(currentCause)) {
return (Exception) currentCause;
}
currentCause = currentCause.getCause();
}
return null;
}
};
}
use of org.apache.calcite.sql.validate.SqlValidatorException in project hazelcast by hazelcast.
the class HazelcastSqlToRelConverter method literalConversionException.
private static QueryException literalConversionException(SqlValidator validator, SqlCall call, Literal literal, QueryDataType toType, Exception e) {
String literalValue = literal.getStringValue();
if (SqlTypeName.CHAR_TYPES.contains(literal.getTypeName())) {
literalValue = "'" + literalValue + "'";
}
Resources.ExInst<SqlValidatorException> contextError = HazelcastResources.RESOURCES.cannotCastLiteralValue(literalValue, toType.getTypeFamily().getPublicType().toString(), e.getMessage());
CalciteContextException calciteContextError = validator.newValidationError(call, contextError);
throw QueryException.error(SqlErrorCode.PARSING, calciteContextError.getMessage(), e);
}
Aggregations