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"));
}
}
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;
}
};
}
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);
}
}
Aggregations