Search in sources :

Example 1 with CalciteException

use of org.apache.calcite.runtime.CalciteException in project calcite by apache.

the class RelBuilderTest method testAggregateFilterFails.

@Test
public void testAggregateFilterFails() {
    // GROUP BY deptno
    try {
        final RelBuilder builder = RelBuilder.create(config().build());
        RelNode root = builder.scan("EMP").aggregate(builder.groupKey(builder.field("DEPTNO")), builder.aggregateCall(SqlStdOperatorTable.SUM, false, false, builder.field("COMM"), "C", builder.field("SAL"))).build();
        fail("expected error, got " + root);
    } catch (CalciteException e) {
        assertThat(e.getMessage(), is("FILTER expression must be of type BOOLEAN"));
    }
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) CalciteException(org.apache.calcite.runtime.CalciteException) Test(org.junit.Test)

Example 2 with CalciteException

use of org.apache.calcite.runtime.CalciteException 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 CalciteException

use of org.apache.calcite.runtime.CalciteException in project calcite by apache.

the class SqlAdvisorValidator method validateOver.

protected void validateOver(SqlCall call, SqlValidatorScope scope) {
    try {
        final OverScope overScope = (OverScope) getOverScope(call);
        final SqlNode relation = call.operand(0);
        validateFrom(relation, unknownType, scope);
        final SqlNode window = call.operand(1);
        SqlValidatorScope opScope = scopes.get(relation);
        if (opScope == null) {
            opScope = overScope;
        }
        validateWindow(window, opScope, null);
    } catch (CalciteException e) {
        Util.swallow(e, TRACER);
    }
}
Also used : SqlValidatorScope(org.apache.calcite.sql.validate.SqlValidatorScope) OverScope(org.apache.calcite.sql.validate.OverScope) CalciteException(org.apache.calcite.runtime.CalciteException) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

CalciteException (org.apache.calcite.runtime.CalciteException)3 Function (com.google.common.base.Function)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)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 RelNode (org.apache.calcite.rel.RelNode)1 SqlNode (org.apache.calcite.sql.SqlNode)1 OverScope (org.apache.calcite.sql.validate.OverScope)1 SqlValidatorException (org.apache.calcite.sql.validate.SqlValidatorException)1 SqlValidatorScope (org.apache.calcite.sql.validate.SqlValidatorScope)1 RelBuilder (org.apache.calcite.tools.RelBuilder)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1