@Override public String getMessage() { // The superclass' message is the textual context information // for this exception, so we add in the underlying cause to the message return super.getMessage() + ": " + getCause().getMessage(); } }
/** * Creates a new CalciteException object. * * @param message error message * @param cause underlying cause */ public CalciteException( String message, Throwable cause) { super(message, cause); // TODO: Force the caller to pass in a Logger as a trace argument for // better context. Need to extend ResGen for this. LOGGER.trace("CalciteException", this); LOGGER.error(toString()); } }
null, errorMatches( new CalciteException("Empty result of JSON_VALUE function is not " + "allowed", null))); assertJsonValueAny( null, errorMatches( new CalciteException("Empty result of JSON_VALUE function is not " + "allowed", null))); assertJsonValueAny( null, errorMatches( new CalciteException("Strict jsonpath mode requires scalar value, " + "and the actual value is: '[]'", null)));
protected void validateFeature( Feature feature, SqlParserPos context) { if (feature.equals(disabledFeature)) { CalciteException ex = new CalciteException( FEATURE_DISABLED, null); if (context == null) { throw ex; } throw new CalciteContextException( "location", ex, context.getLineNum(), context.getColumnNum(), context.getEndLineNum(), context.getEndColumnNum()); } } }
@Override public String getMessage() { // The superclass' message is the textual context information // for this exception, so we add in the underlying cause to the message return super.getMessage() + ": " + getCause().getMessage(); } }
protected void validateFeature( Feature feature, SqlParserPos context) { if (feature.equals(disabledFeature)) { CalciteException ex = new CalciteException( FEATURE_DISABLED, null); if (context == null) { throw ex; } throw new CalciteContextException( "location", ex, context.getLineNum(), context.getColumnNum(), context.getEndLineNum(), context.getEndColumnNum()); } } }
/** * Creates a new CalciteException object. * * @param message error message * @param cause underlying cause */ public CalciteException( String message, Throwable cause) { super(message, cause); // TODO: Force the caller to pass in a Logger as a trace argument for // better context. Need to extend ResGen for this. LOGGER.trace("CalciteException", this); LOGGER.error(toString()); } }
@Test public void testLtWithAny() { // Non-numeric same type "less then" check assertThat(SqlFunctions.ltAny("apple", "banana"), is(true)); // Numeric types "less than" check assertThat(SqlFunctions.ltAny(1, 2L), is(true)); assertThat(SqlFunctions.ltAny(1, 2.0D), is(true)); assertThat(SqlFunctions.ltAny(1L, 2.0D), is(true)); assertThat(SqlFunctions.ltAny(new BigDecimal(1L), 2), is(true)); assertThat(SqlFunctions.ltAny(new BigDecimal(1L), 2L), is(true)); assertThat(SqlFunctions.ltAny(new BigDecimal(1L), 2.0D), is(true)); assertThat(SqlFunctions.ltAny(new BigDecimal(1L), new BigDecimal(2.0D)), is(true)); // Non-numeric different type but both implements Comparable // "less than" check try { assertThat(SqlFunctions.ltAny("1", 2L), is(false)); fail("'lt' on non-numeric different type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for comparison: class java.lang.String < " + "class java.lang.Long")); } }
SqlJsonQueryEmptyOrErrorBehavior.NULL, errorMatches( new CalciteException("Empty result of JSON_QUERY function is not " + "allowed", null))); SqlJsonQueryEmptyOrErrorBehavior.NULL, errorMatches( new CalciteException("Empty result of JSON_QUERY function is not " + "allowed", null))); assertJsonQuery( SqlJsonQueryEmptyOrErrorBehavior.ERROR, errorMatches( new CalciteException("Strict jsonpath mode requires array or " + "object value, and the actual value is: 'bar'", null)));
@Test public void testGtWithAny() { // Non-numeric same type "greater then" check assertThat(SqlFunctions.gtAny("banana", "apple"), is(true)); // Numeric types "greater than" check assertThat(SqlFunctions.gtAny(2, 1L), is(true)); assertThat(SqlFunctions.gtAny(2, 1.0D), is(true)); assertThat(SqlFunctions.gtAny(2L, 1.0D), is(true)); assertThat(SqlFunctions.gtAny(new BigDecimal(2L), 1), is(true)); assertThat(SqlFunctions.gtAny(new BigDecimal(2L), 1L), is(true)); assertThat(SqlFunctions.gtAny(new BigDecimal(2L), 1.0D), is(true)); assertThat(SqlFunctions.gtAny(new BigDecimal(2L), new BigDecimal(1.0D)), is(true)); // Non-numeric different type but both implements Comparable // "greater than" check try { assertThat(SqlFunctions.gtAny("2", 1L), is(false)); fail("'gt' on non-numeric different type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for comparison: class java.lang.String > " + "class java.lang.Long")); } }
@Test public void testPlusAny() { // null parameters assertNull(SqlFunctions.plusAny(null, null)); assertNull(SqlFunctions.plusAny(null, 1)); assertNull(SqlFunctions.plusAny(1, null)); // Numeric types assertThat(SqlFunctions.plusAny(2, 1L), is((Object) new BigDecimal(3))); assertThat(SqlFunctions.plusAny(2, 1.0D), is((Object) new BigDecimal(3))); assertThat(SqlFunctions.plusAny(2L, 1.0D), is((Object) new BigDecimal(3))); assertThat(SqlFunctions.plusAny(new BigDecimal(2L), 1), is((Object) new BigDecimal(3))); assertThat(SqlFunctions.plusAny(new BigDecimal(2L), 1L), is((Object) new BigDecimal(3))); assertThat(SqlFunctions.plusAny(new BigDecimal(2L), 1.0D), is((Object) new BigDecimal(3))); assertThat(SqlFunctions.plusAny(new BigDecimal(2L), new BigDecimal(1.0D)), is((Object) new BigDecimal(3))); // Non-numeric type try { SqlFunctions.plusAny("2", 2L); fail("'plus' on non-numeric type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for arithmetic: class java.lang.String + " + "class java.lang.Long")); } }
@Test public void testMinusAny() { // null parameters assertNull(SqlFunctions.minusAny(null, null)); assertNull(SqlFunctions.minusAny(null, 1)); assertNull(SqlFunctions.minusAny(1, null)); // Numeric types assertThat(SqlFunctions.minusAny(2, 1L), is((Object) new BigDecimal(1))); assertThat(SqlFunctions.minusAny(2, 1.0D), is((Object) new BigDecimal(1))); assertThat(SqlFunctions.minusAny(2L, 1.0D), is((Object) new BigDecimal(1))); assertThat(SqlFunctions.minusAny(new BigDecimal(2L), 1), is((Object) new BigDecimal(1))); assertThat(SqlFunctions.minusAny(new BigDecimal(2L), 1L), is((Object) new BigDecimal(1))); assertThat(SqlFunctions.minusAny(new BigDecimal(2L), 1.0D), is((Object) new BigDecimal(1))); assertThat(SqlFunctions.minusAny(new BigDecimal(2L), new BigDecimal(1.0D)), is((Object) new BigDecimal(1))); // Non-numeric type try { SqlFunctions.minusAny("2", 2L); fail("'minus' on non-numeric type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for arithmetic: class java.lang.String - " + "class java.lang.Long")); } }
@Test public void testMultiplyAny() { // null parameters assertNull(SqlFunctions.multiplyAny(null, null)); assertNull(SqlFunctions.multiplyAny(null, 1)); assertNull(SqlFunctions.multiplyAny(1, null)); // Numeric types assertThat(SqlFunctions.multiplyAny(2, 1L), is((Object) new BigDecimal(2))); assertThat(SqlFunctions.multiplyAny(2, 1.0D), is((Object) new BigDecimal(2))); assertThat(SqlFunctions.multiplyAny(2L, 1.0D), is((Object) new BigDecimal(2))); assertThat(SqlFunctions.multiplyAny(new BigDecimal(2L), 1), is((Object) new BigDecimal(2))); assertThat(SqlFunctions.multiplyAny(new BigDecimal(2L), 1L), is((Object) new BigDecimal(2))); assertThat(SqlFunctions.multiplyAny(new BigDecimal(2L), 1.0D), is((Object) new BigDecimal(2))); assertThat(SqlFunctions.multiplyAny(new BigDecimal(2L), new BigDecimal(1.0D)), is((Object) new BigDecimal(2))); // Non-numeric type try { SqlFunctions.multiplyAny("2", 2L); fail("'multiply' on non-numeric type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for arithmetic: class java.lang.String * " + "class java.lang.Long")); } }
@Test public void testDivideAny() { // null parameters assertNull(SqlFunctions.divideAny(null, null)); assertNull(SqlFunctions.divideAny(null, 1)); assertNull(SqlFunctions.divideAny(1, null)); // Numeric types assertThat(SqlFunctions.divideAny(5, 2L), is((Object) new BigDecimal("2.5"))); assertThat(SqlFunctions.divideAny(5, 2.0D), is((Object) new BigDecimal("2.5"))); assertThat(SqlFunctions.divideAny(5L, 2.0D), is((Object) new BigDecimal("2.5"))); assertThat(SqlFunctions.divideAny(new BigDecimal(5L), 2), is((Object) new BigDecimal(2.5))); assertThat(SqlFunctions.divideAny(new BigDecimal(5L), 2L), is((Object) new BigDecimal(2.5))); assertThat(SqlFunctions.divideAny(new BigDecimal(5L), 2.0D), is((Object) new BigDecimal(2.5))); assertThat(SqlFunctions.divideAny(new BigDecimal(5L), new BigDecimal(2.0D)), is((Object) new BigDecimal(2.5))); // Non-numeric type try { SqlFunctions.divideAny("5", 2L); fail("'divide' on non-numeric type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for arithmetic: class java.lang.String / " + "class java.lang.Long")); } }
fail("'le' on non-numeric different type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for comparison: class java.lang.String <= " + "class java.lang.Long"));
fail("'ge' on non-numeric different type is not possible"); } catch (CalciteException e) { assertThat(e.getMessage(), is("Invalid types for comparison: class java.lang.String >= " + "class java.lang.Long"));
@Test public void testAggregateFilterFails() { // Equivalent SQL: // SELECT deptno, SUM(sal) FILTER (WHERE comm) AS c // FROM emp // 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")); } }
@Test public void testAggregateFilterFails() { // Equivalent SQL: // SELECT deptno, SUM(sal) FILTER (WHERE comm) AS c // FROM emp // GROUP BY deptno try { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .aggregate( builder.groupKey(builder.field("DEPTNO")), builder.sum(builder.field("SAL")) .filter(builder.field("COMM")) .as("C")) .build(); fail("expected error, got " + root); } catch (CalciteException e) { assertThat(e.getMessage(), is("FILTER expression must be of type BOOLEAN")); } }