@Test public void testParametersNonPreparedStatement() { try { computeActual("SELECT ?, 1"); fail("parameters not in prepared statements should fail"); } catch (SemanticException e) { assertEquals(e.getCode(), INVALID_PARAMETER_USAGE); } catch (RuntimeException e) { assertEquals(e.getMessage(), "line 1:1: Incorrect number of parameters: expected 1 but found 0"); } }
@Override protected Void visitIdentifier(Identifier node, Void context) { throw new SemanticException(EXPRESSION_NOT_CONSTANT, expression, "Constant expression cannot contain column references"); }
public SemanticException(SemanticErrorCode code, Node node, String format, Object... args) { super(formatMessage(format, node, args)); requireNonNull(code, "code is null"); requireNonNull(node, "node is null"); this.code = code; this.node = node; }
private void assertFails(Session session, SemanticErrorCode error, String message, @Language("SQL") String query) { try { analyze(session, query); fail(format("Expected error %s, but analysis succeeded", error)); } catch (SemanticException e) { if (e.getCode() != error) { fail(format("Expected error %s, but found %s: %s", error, e.getCode(), e.getMessage()), e); } if (!e.getMessage().matches(message)) { fail(format("Expected error '%s', but got '%s'", message, e.getMessage()), e); } } }
private void assertFails(Session session, SemanticErrorCode error, Optional<NodeLocation> location, @Language("SQL") String query) { try { analyze(session, query); fail(format("Expected error %s, but analysis succeeded", error)); } catch (SemanticException e) { if (e.getCode() != error) { fail(format("Expected error %s, but found %s: %s", error, e.getCode(), e.getMessage()), e); } if (location.isPresent()) { NodeLocation expected = location.get(); NodeLocation actual = e.getNode().getLocation().get(); if (expected.getLineNumber() != actual.getLineNumber() || expected.getColumnNumber() != actual.getColumnNumber()) { fail(format( "Expected error '%s' to occur at line %s, offset %s, but was: line %s, offset %s", e.getCode(), expected.getLineNumber(), expected.getColumnNumber(), actual.getLineNumber(), actual.getColumnNumber())); } } } }
List<String> parts = propertyName.getParts(); if (parts.size() > 2) { throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", propertyName); accessControl.checkCanSetSystemSessionProperty(session.getIdentity(), parts.get(0)); propertyMetadata = metadata.getSessionPropertyManager().getSystemSessionPropertyMetadata(parts.get(0)) .orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName())); .orElseThrow(() -> new SemanticException(MISSING_CATALOG, statement, "Catalog %s does not exist", parts.get(0))); accessControl.checkCanSetCatalogSessionProperty(session.getRequiredTransactionId(), session.getIdentity(), parts.get(0), parts.get(1)); propertyMetadata = metadata.getSessionPropertyManager().getConnectorSessionPropertyMetadata(connectorId, parts.get(1)) .orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName())); format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getMessage()));
@Nullable private static ErrorLocation getErrorLocation(Throwable throwable) { // TODO: this is a big hack if (throwable instanceof ParsingException) { ParsingException e = (ParsingException) throwable; return new ErrorLocation(e.getLineNumber(), e.getColumnNumber()); } else if (throwable instanceof SemanticException) { SemanticException e = (SemanticException) throwable; if (e.getNode().getLocation().isPresent()) { NodeLocation nodeLocation = e.getNode().getLocation().get(); return new ErrorLocation(nodeLocation.getLineNumber(), nodeLocation.getColumnNumber()); } } return null; }
if (!e.getMessage().matches("\\Qline 1:55: '=' cannot be applied to row<HyperLogLog>('col0'), row<HyperLogLog>('col0')\\E")) { throw e;
public void assertInvalidFunction(String projection, SemanticErrorCode expectedErrorCode, String message) { try { evaluateInvalid(projection); fail(format("Expected to throw %s exception", expectedErrorCode)); } catch (SemanticException e) { try { assertEquals(e.getCode(), expectedErrorCode); assertEquals(e.getMessage(), message); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
QualifiedName propertyName = statement.getName(); if (propertyName.getParts().size() > 2) { throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", propertyName); format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getMessage()));
@Nullable private static ErrorLocation getErrorLocation(Throwable throwable) { // TODO: this is a big hack if (throwable instanceof ParsingException) { ParsingException e = (ParsingException) throwable; return new ErrorLocation(e.getLineNumber(), e.getColumnNumber()); } else if (throwable instanceof SemanticException) { SemanticException e = (SemanticException) throwable; if (e.getNode().getLocation().isPresent()) { NodeLocation nodeLocation = e.getNode().getLocation().get(); return new ErrorLocation(nodeLocation.getLineNumber(), nodeLocation.getColumnNumber()); } } return null; }
@Override protected Scope visitUse(Use node, Optional<Scope> scope) { throw new SemanticException(NOT_SUPPORTED, node, "USE statement is not supported"); }
private void assertFailsWithoutExperimentalSyntax(SemanticErrorCode error, @Language("SQL") String query) { try { analyzeWithoutExperimentalSyntax(query); fail(format("Expected error %s, but analysis succeeded", error)); } catch (SemanticException e) { if (e.getCode() != error) { fail(format("Expected error %s, but found %s: %s", error, e.getCode(), e.getMessage()), e); } } }
@Override public void assertInvalidFunction(String projection, SemanticErrorCode errorCode) { try { assertFunction(projection, UNKNOWN, null); fail("Expected error " + errorCode + " from " + projection); } catch (SemanticException e) { assertEquals(e.getCode(), errorCode); } }
public SemanticException(SemanticErrorCode code, Node node, String format, Object... args) { super(formatMessage(format, node, args)); requireNonNull(code, "code is null"); requireNonNull(node, "node is null"); this.code = code; this.node = node; }
private static void check(boolean condition, ShowStats node, String message) { if (!condition) { throw new SemanticException(NOT_SUPPORTED, node, message); } }
private void assertFails(Session session, SemanticErrorCode error, @Language("SQL") String query) { try { analyze(session, query); fail(format("Expected error %s, but analysis succeeded", error)); } catch (SemanticException e) { if (e.getCode() != error) { fail(format("Expected error %s, but found %s: %s", error, e.getCode(), e.getMessage()), e); } } }
public void assertInvalidFunction(String projection, SemanticErrorCode expectedErrorCode) { try { evaluateInvalid(projection); fail(format("Expected to throw %s exception", expectedErrorCode)); } catch (SemanticException e) { try { assertEquals(e.getCode(), expectedErrorCode); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public static SemanticException notSupportedException(Node node, String notSupportedFeatureDescription) { throw new SemanticException(NOT_SUPPORTED, node, notSupportedFeatureDescription + " is not supported"); } }
private void assertMissingInformationSchema(Session session, @Language("SQL") String query) { try { analyze(session, query); fail("expected exception"); } catch (SemanticException e) { assertEquals(e.getCode(), MISSING_SCHEMA); assertEquals(e.getMessage(), "Schema information_schema does not exist"); } }