private static void check(boolean condition, ShowStats node, String message) { if (!condition) { throw new SemanticException(NOT_SUPPORTED, node, message); } }
@Override protected Void visitFieldReference(FieldReference node, Void context) { throw new SemanticException(EXPRESSION_NOT_CONSTANT, expression, "Constant expression cannot contain column references"); } }
public static SemanticException notSupportedException(Node node, String notSupportedFeatureDescription) { throw new SemanticException(NOT_SUPPORTED, node, notSupportedFeatureDescription + " is not supported"); } }
public static SemanticException notSupportedException(Node node, String notSupportedFeatureDescription) { throw new SemanticException(NOT_SUPPORTED, node, notSupportedFeatureDescription + " is not supported"); } }
@Override protected Scope visitUse(Use node, Optional<Scope> scope) { throw new SemanticException(NOT_SUPPORTED, node, "USE statement is not supported"); }
/** * Use {@link #missingAttributeException(Expression, QualifiedName)} instead. */ @Deprecated public static SemanticException missingAttributeException(Expression node) { throw new SemanticException(MISSING_ATTRIBUTE, node, "Column '%s' cannot be resolved", node); }
@Override protected Type visitExpression(Expression node, StackableAstVisitorContext<Context> context) { throw new SemanticException(NOT_SUPPORTED, node, "not yet implemented: " + node.getClass().getName()); }
@Override protected Type visitNode(Node node, StackableAstVisitorContext<Context> context) { throw new SemanticException(NOT_SUPPORTED, node, "not yet implemented: " + node.getClass().getName()); }
private void verifyNoOrderByReferencesToOutputColumns(Node node, SemanticErrorCode errorCode, String errorString) { getReferencesToScope(node, analysis, orderByScope.get()) .findFirst() .ifPresent(expression -> { throw new SemanticException(errorCode, expression, errorString); }); } }
private static void validateParameters(Statement node, List<Expression> parameterValues) { int parameterCount = getParameterCount(node); if (parameterValues.size() != parameterCount) { throw new SemanticException(INVALID_PARAMETER_USAGE, node, "Incorrect number of parameters: expected %s but found %s", parameterCount, parameterValues.size()); } for (Expression expression : parameterValues) { verifyExpressionIsConstant(emptySet(), expression); } }
private TableHandle getTableHandle(ShowStats node, QualifiedName table) { QualifiedObjectName qualifiedTableName = createQualifiedObjectName(session, node, table); return metadata.getTableHandle(session, qualifiedTableName) .orElseThrow(() -> new SemanticException(MISSING_TABLE, node, "Table %s not found", table)); }
private static Privilege parsePrivilege(Revoke statement, String privilegeString) { for (Privilege privilege : Privilege.values()) { if (privilege.name().equalsIgnoreCase(privilegeString)) { return privilege; } } throw new SemanticException(INVALID_PRIVILEGE, statement, "Unknown privilege: '%s'", privilegeString); } }
private void coerceType(Expression expression, Type actualType, Type expectedType, String message) { if (!actualType.equals(expectedType)) { if (!typeManager.canCoerce(actualType, expectedType)) { throw new SemanticException(TYPE_MISMATCH, expression, message + " must evaluate to a %s (actual: %s)", expectedType, actualType); } addOrReplaceExpressionCoercion(expression, actualType, expectedType); } }
private void analyzeGroupingOperations(QuerySpecification node, List<Expression> outputExpressions, List<Expression> orderByExpressions) { List<GroupingOperation> groupingOperations = extractExpressions(Iterables.concat(outputExpressions, orderByExpressions), GroupingOperation.class); boolean isGroupingOperationPresent = !groupingOperations.isEmpty(); if (isGroupingOperationPresent && !node.getGroupBy().isPresent()) { throw new SemanticException( INVALID_PROCEDURE_ARGUMENTS, node, "A GROUPING() operation can only be used with a corresponding GROUPING SET/CUBE/ROLLUP/GROUP BY clause"); } analysis.setGroupingOperations(node, groupingOperations); }
@Override protected Scope visitExcept(Except node, Optional<Scope> scope) { if (!node.isDistinct()) { throw new SemanticException(NOT_SUPPORTED, node, "EXCEPT ALL not yet implemented"); } return visitSetOperation(node, scope); }
private void analyze(Expression expression) { Visitor visitor = new Visitor(); if (!visitor.process(expression, null)) { throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, expression, "'%s' must be an aggregate expression or appear in GROUP BY clause", expression); } }
@Override protected Void visitDereferenceExpression(DereferenceExpression node, Void context) { if (columnReferences.contains(NodeRef.<Expression>of(node))) { throw new SemanticException(EXPRESSION_NOT_CONSTANT, expression, "Constant expression cannot contain column references"); } process(node.getBase(), context); return null; }
private Query parseView(String view, QualifiedObjectName name, Node node) { try { Statement statement = sqlParser.createStatement(view, createParsingOptions(session)); return (Query) statement; } catch (ParsingException e) { throw new SemanticException(VIEW_PARSE_ERROR, node, "Failed parsing stored view '%s': %s", name, e.getMessage()); } }
@Override protected Void visitFunctionCall(FunctionCall functionCall, Analysis analysis) { requireNonNull(analysis, "analysis is null"); Signature signature = analysis.getFunctionSignature(functionCall); if (signature != null && signature.getKind() == WINDOW && !functionCall.getWindow().isPresent()) { throw new SemanticException(WINDOW_REQUIRES_OVER, functionCall, "Window function %s requires an OVER clause", signature.getName()); } return super.visitFunctionCall(functionCall, analysis); } }
private Query parseView(String view, QualifiedObjectName name, Node node) { try { return (Query) sqlParser.createStatement(view, createParsingOptions(session)); } catch (ParsingException e) { throw new SemanticException(VIEW_PARSE_ERROR, node, "Failed parsing stored view '%s': %s", name, e.getMessage()); } }