@Override protected RelationType visitQuerySpecification(QuerySpecification node, AnalysisContext parentContext) { // TODO: extract candidate names from SELECT, WHERE, HAVING, GROUP BY and ORDER BY expressions // to pass down to analyzeFrom AnalysisContext context = new AnalysisContext(parentContext); RelationType tupleDescriptor = analyzeFrom(node, context); node.getWhere().ifPresent(where -> analyzeWhere(node, tupleDescriptor, context, where)); List<FieldOrExpression> outputExpressions = analyzeSelect(node, tupleDescriptor, context); List<List<FieldOrExpression>> groupByExpressions = analyzeGroupBy(node, tupleDescriptor, context, outputExpressions); List<FieldOrExpression> orderByExpressions = analyzeOrderBy(node, tupleDescriptor, context, outputExpressions); analyzeHaving(node, tupleDescriptor, context); analyzeAggregations(node, tupleDescriptor, groupByExpressions, outputExpressions, orderByExpressions, context, analysis.getColumnReferences()); analyzeWindowFunctions(node, outputExpressions, orderByExpressions); RelationType descriptor = computeOutputDescriptor(node, tupleDescriptor); analysis.setOutputDescriptor(node, descriptor); return descriptor; }
@Override protected RelationType visitDelete(Delete node, AnalysisContext context) { Table table = node.getTable(); QualifiedObjectName tableName = createQualifiedObjectName(session, table, table.getName()); if (metadata.getView(session, tableName).isPresent()) { throw new SemanticException(NOT_SUPPORTED, node, "Deleting from views is not supported"); } // Analyzer checks for select permissions but DELETE has a separate permission, so disable access checks // TODO: we shouldn't need to create a new analyzer. The access control should be carried in the context object StatementAnalyzer analyzer = new StatementAnalyzer( analysis, metadata, sqlParser, new AllowAllAccessControl(), session, experimentalSyntaxEnabled, queryExplainer); RelationType descriptor = analyzer.process(table, context); node.getWhere().ifPresent(where -> analyzer.analyzeWhere(node, descriptor, context, where)); analysis.setUpdateType("DELETE"); analysis.setStatement(node); accessControl.checkCanDeleteFromTable(session.getRequiredTransactionId(), session.getIdentity(), tableName); return new RelationType(Field.newUnqualified("rows", BIGINT)); }