org.apache.calcite.runtime.CalciteException Java Examples
The following examples show how to use
org.apache.calcite.runtime.CalciteException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 6 votes |
@Test 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")); } }
Example #2
Source File: SqlValidatorFeatureTest.java From calcite with Apache License 2.0 | 6 votes |
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()); } }
Example #3
Source File: Util.java From calcite with Apache License 2.0 | 6 votes |
/** * Retrieves messages in a exception and writes them to a string. In the * string returned, each message will appear on a different line. * * @return a non-null string containing all messages of the exception */ @Deprecated // to be removed before 2.0 public static String getMessages(Throwable t) { StringBuilder sb = new StringBuilder(); for (Throwable curr = t; curr != null; curr = curr.getCause()) { String msg = ((curr instanceof CalciteException) || (curr instanceof SQLException)) ? curr.getMessage() : curr.toString(); if (sb.length() > 0) { sb.append("\n"); } sb.append(msg); } return sb.toString(); }
Example #4
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 6 votes |
@Test 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")); } }
Example #5
Source File: SqlAdvisorValidator.java From calcite with Apache License 2.0 | 6 votes |
/** * Calls the parent class method and mask Farrago exception thrown. */ public RelDataType deriveType( SqlValidatorScope scope, SqlNode operand) { // REVIEW Do not mask Error (indicates a serious system problem) or // UnsupportedOperationException (a bug). I have to mask // UnsupportedOperationException because // SqlValidatorImpl.getValidatedNodeType throws it for an unrecognized // identifier node I have to mask Error as well because // AbstractNamespace.getRowType called in super.deriveType can do a // Util.permAssert that throws Error try { return super.deriveType(scope, operand); } catch (CalciteException | UnsupportedOperationException | Error e) { return unknownType; } }
Example #6
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 6 votes |
@Test 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")); } }
Example #7
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testMinusAny() { // null parameters assertThat(SqlFunctions.minusAny(null, null), nullValue()); assertThat(SqlFunctions.minusAny(null, 1), nullValue()); assertThat(SqlFunctions.minusAny(1, null), nullValue()); // 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")); } }
Example #8
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testMultiplyAny() { // null parameters assertThat(SqlFunctions.multiplyAny(null, null), nullValue()); assertThat(SqlFunctions.multiplyAny(null, 1), nullValue()); assertThat(SqlFunctions.multiplyAny(1, null), nullValue()); // 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")); } }
Example #9
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testPlusAny() { // null parameters assertThat(SqlFunctions.plusAny(null, null), nullValue()); assertThat(SqlFunctions.plusAny(null, 1), nullValue()); assertThat(SqlFunctions.plusAny(1, null), nullValue()); // 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")); } }
Example #10
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testGeWithAny() { // Non-numeric same type "greater or equal" check assertThat(SqlFunctions.geAny("banana", "apple"), is(true)); assertThat(SqlFunctions.geAny("apple", "apple"), is(true)); // Numeric types "greater or equal" check assertThat(SqlFunctions.geAny(2, 1L), is(true)); assertThat(SqlFunctions.geAny(1, 1L), is(true)); assertThat(SqlFunctions.geAny(2, 1.0D), is(true)); assertThat(SqlFunctions.geAny(1, 1.0D), is(true)); assertThat(SqlFunctions.geAny(2L, 1.0D), is(true)); assertThat(SqlFunctions.geAny(1L, 1.0D), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(2L), 1), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(1L), 1), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(2L), 1L), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(1L), 1L), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(2L), 1.0D), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(1L), 1.0D), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(2L), new BigDecimal(1.0D)), is(true)); assertThat(SqlFunctions.geAny(new BigDecimal(1L), new BigDecimal(1.0D)), is(true)); // Non-numeric different type but both implements Comparable // "greater or equal" check try { assertThat(SqlFunctions.geAny("2", 2L), is(false)); 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")); } }
Example #11
Source File: SqlJsonFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void assertJsonPretty() { assertJsonPretty( JsonFunctions.JsonValueContext.withJavaObj(new HashMap<>()), is("{ }")); assertJsonPretty( JsonFunctions.JsonValueContext.withJavaObj(Longs.asList(1, 2)), is("[ 1, 2 ]")); Object input = new Object() { private final Object self = this; }; CalciteException expected = new CalciteException( "Cannot serialize object to JSON: '" + input + "'", null); assertJsonPrettyFailed( JsonFunctions.JsonValueContext.withJavaObj(input), errorMatches(expected)); }
Example #12
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testLeWithAny() { // Non-numeric same type "less or equal" check assertThat(SqlFunctions.leAny("apple", "banana"), is(true)); assertThat(SqlFunctions.leAny("apple", "apple"), is(true)); // Numeric types "less or equal" check assertThat(SqlFunctions.leAny(1, 2L), is(true)); assertThat(SqlFunctions.leAny(1, 1L), is(true)); assertThat(SqlFunctions.leAny(1, 2.0D), is(true)); assertThat(SqlFunctions.leAny(1, 1.0D), is(true)); assertThat(SqlFunctions.leAny(1L, 2.0D), is(true)); assertThat(SqlFunctions.leAny(1L, 1.0D), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), 2), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), 1), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), 2L), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), 1L), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), 2.0D), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), 1.0D), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), new BigDecimal(2.0D)), is(true)); assertThat(SqlFunctions.leAny(new BigDecimal(1L), new BigDecimal(1.0D)), is(true)); // Non-numeric different type but both implements Comparable // "less or equal" check try { assertThat(SqlFunctions.leAny("2", 2L), is(false)); 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")); } }
Example #13
Source File: SqlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testDivideAny() { // null parameters assertThat(SqlFunctions.divideAny(null, null), nullValue()); assertThat(SqlFunctions.divideAny(null, 1), nullValue()); assertThat(SqlFunctions.divideAny(1, null), nullValue()); // 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")); } }
Example #14
Source File: SqlXmlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testExistsNode() { assertExistsNode(null, "", null, nullValue()); assertExistsNode("", null, null, nullValue()); String xpath = "<"; String namespace = "a"; String message = "Invalid input for EXISTSNODE xpath: '" + xpath + "', namespace: '" + namespace + "'"; CalciteException expected = new CalciteException(message, null); assertExistsNodeFailed("", xpath, namespace, Matchers.expectThrowable(expected)); }
Example #15
Source File: SqlXmlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testExtractXml() { assertExtractXml(null, "", null, nullValue()); assertExtractXml("", null, null, nullValue()); String xpath = "<"; String namespace = "a"; String message = "Invalid input for EXTRACT xpath: '" + xpath + "', namespace: '" + namespace + "'"; CalciteException expected = new CalciteException(message, null); assertExtractXmlFailed("", xpath, namespace, Matchers.expectThrowable(expected)); }
Example #16
Source File: SqlXmlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testXmlTransform() { assertXmlTransform(null, "", nullValue()); assertXmlTransform("", null, nullValue()); String xslt = "<"; String message = "Illegal xslt specified : '" + xslt + "'"; CalciteException expected = new CalciteException(message, null); assertXmlTransformFailed("", xslt, Matchers.expectThrowable(expected)); }
Example #17
Source File: SqlXmlFunctionsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testExtractValue() { assertExtractValue("<a>ccc<b>ddd</b></a>", "/a", is("ccc")); String input = "<a>ccc<b>ddd</b></a>"; String message = "Invalid input for EXTRACTVALUE: xml: '" + input + "', xpath expression: '#'"; CalciteException expected = new CalciteException(message, null); assertExtractValueFailed(input, "#", Matchers.expectThrowable(expected)); }
Example #18
Source File: SqlValidatorImpl.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, List<RelDataType> argTypes, List<String> argNames) { // For builtins, we can give a better error message final List<SqlOperator> overloads = new ArrayList<>(); opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null, SqlSyntax.FUNCTION, overloads); if (overloads.size() == 1) { SqlFunction fun = (SqlFunction) overloads.get(0); if ((fun.getSqlIdentifier() == null) && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) { final int expectedArgCount = fun.getOperandCountRange().getMin(); throw newValidationError(call, RESOURCE.invalidArgCount(call.getOperator().getName(), expectedArgCount)); } } AssignableOperandTypeChecker typeChecking = new AssignableOperandTypeChecker(argTypes, argNames); String signature = typeChecking.getAllowedSignatures( unresolvedFunction, unresolvedFunction.getName()); throw newValidationError(call, RESOURCE.validatorUnknownFunction(signature)); }
Example #19
Source File: SqlUtil.java From calcite with Apache License 2.0 | 5 votes |
/** * Wraps an exception with context. */ public static CalciteException newContextException( final SqlParserPos pos, Resources.ExInst<?> e, String inputText) { CalciteContextException ex = newContextException(pos, e); ex.setOriginalStatement(inputText); return ex; }
Example #20
Source File: SqlCallBinding.java From calcite with Apache License 2.0 | 5 votes |
/** * Constructs a new validation signature error for the call. * * @return signature exception */ public CalciteException newValidationSignatureError() { return validator.newValidationError(call, RESOURCE.canNotApplyOp2Type(getOperator().getName(), call.getCallSignature(validator, scope), getOperator().getAllowedSignatures())); }
Example #21
Source File: SqlAdvisorValidator.java From calcite with Apache License 2.0 | 5 votes |
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); } }
Example #22
Source File: SqlAdvisorValidator.java From calcite with Apache License 2.0 | 5 votes |
/** * Calls the parent class method and masks Farrago exception thrown. */ protected void validateHavingClause(SqlSelect select) { try { super.validateHavingClause(select); } catch (CalciteException e) { Util.swallow(e, TRACER); } }
Example #23
Source File: SqlAdvisorValidator.java From calcite with Apache License 2.0 | 5 votes |
/** * Calls the parent class method and masks Farrago exception thrown. */ protected void validateWhereClause(SqlSelect select) { try { super.validateWhereClause(select); } catch (CalciteException e) { Util.swallow(e, TRACER); } }
Example #24
Source File: SqlAdvisorValidator.java From calcite with Apache License 2.0 | 5 votes |
protected void validateFrom( SqlNode node, RelDataType targetRowType, SqlValidatorScope scope) { try { super.validateFrom(node, targetRowType, scope); } catch (CalciteException e) { Util.swallow(e, TRACER); } }
Example #25
Source File: SqlAdvisorValidator.java From calcite with Apache License 2.0 | 5 votes |
/** * Registers the identifier and its scope into a map keyed by ParserPosition. */ public void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope) { registerId(id, scope); try { super.validateIdentifier(id, scope); } catch (CalciteException e) { Util.swallow(e, TRACER); } }
Example #26
Source File: ExplicitOperatorBinding.java From calcite with Apache License 2.0 | 5 votes |
public CalciteException newError( Resources.ExInst<SqlValidatorException> e) { if (delegate != null) { return delegate.newError(e); } else { return SqlUtil.newContextException(SqlParserPos.ZERO, e); } }
Example #27
Source File: SqlValidatorImpl.java From flink with Apache License 2.0 | 5 votes |
public CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, List<RelDataType> argTypes, List<String> argNames) { // For builtins, we can give a better error message final List<SqlOperator> overloads = new ArrayList<>(); opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null, SqlSyntax.FUNCTION, overloads, catalogReader.nameMatcher()); if (overloads.size() == 1) { SqlFunction fun = (SqlFunction) overloads.get(0); if ((fun.getSqlIdentifier() == null) && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) { final int expectedArgCount = fun.getOperandCountRange().getMin(); throw newValidationError(call, RESOURCE.invalidArgCount(call.getOperator().getName(), expectedArgCount)); } } AssignableOperandTypeChecker typeChecking = new AssignableOperandTypeChecker(argTypes, argNames); String signature = typeChecking.getAllowedSignatures( unresolvedFunction, unresolvedFunction.getName()); throw newValidationError(call, RESOURCE.validatorUnknownFunction(signature)); }
Example #28
Source File: RexCallBinding.java From calcite with Apache License 2.0 | 4 votes |
public CalciteException newError( Resources.ExInst<SqlValidatorException> e) { return SqlUtil.newContextException(SqlParserPos.ZERO, e); }
Example #29
Source File: SqlCallBinding.java From calcite with Apache License 2.0 | 4 votes |
public CalciteException newError( Resources.ExInst<SqlValidatorException> e) { return validator.newValidationError(call, e); }
Example #30
Source File: Aggregate.java From calcite with Apache License 2.0 | 4 votes |
public CalciteException newError( Resources.ExInst<SqlValidatorException> e) { return SqlUtil.newContextException(SqlParserPos.ZERO, e); }