Search in sources :

Example 1 with SqlValidatorException

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);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlCall(org.apache.calcite.sql.SqlCall) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) Resources(org.apache.calcite.runtime.Resources) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException)

Example 2 with SqlValidatorException

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;
        }
    };
}
Also used : Function(com.google.common.base.Function) StringWriter(java.io.StringWriter) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CalciteException(org.apache.calcite.runtime.CalciteException) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException) Nullable(javax.annotation.Nullable) InvocationTargetException(java.lang.reflect.InvocationTargetException) CalciteException(org.apache.calcite.runtime.CalciteException) SQLException(java.sql.SQLException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException) ExecutionException(java.util.concurrent.ExecutionException) PrintWriter(java.io.PrintWriter)

Example 3 with SqlValidatorException

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);
}
Also used : CalciteContextException(org.apache.calcite.runtime.CalciteContextException) TimeString(org.apache.calcite.util.TimeString) HazelcastResources(com.hazelcast.jet.sql.impl.validate.HazelcastResources) Resources(org.apache.calcite.runtime.Resources) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException)

Aggregations

SqlValidatorException (org.apache.calcite.sql.validate.SqlValidatorException)3 Resources (org.apache.calcite.runtime.Resources)2 Function (com.google.common.base.Function)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 HazelcastResources (com.hazelcast.jet.sql.impl.validate.HazelcastResources)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nullable (javax.annotation.Nullable)1 CalciteContextException (org.apache.calcite.runtime.CalciteContextException)1 CalciteException (org.apache.calcite.runtime.CalciteException)1 SqlCall (org.apache.calcite.sql.SqlCall)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1 SqlValidator (org.apache.calcite.sql.validate.SqlValidator)1 TimeString (org.apache.calcite.util.TimeString)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1