Skip to content

Commit

Permalink
[Refactor] Add DML Statement Analyzer to unify some dml analyze logic…
Browse files Browse the repository at this point in the history
…al (#53974)
  • Loading branch information
HangyuanLiu authored Dec 16, 2024
1 parent aa3928e commit a852995
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 22 deletions.
40 changes: 21 additions & 19 deletions fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public Void visitSubmitTaskStatement(SubmitTaskStmt statement, ConnectContext co
taskStmt = queryStatement;
} else if (statement.getInsertStmt() != null) {
InsertStmt insertStmt = statement.getInsertStmt();
InsertAnalyzer.analyze(insertStmt, context);
Analyzer.analyze(insertStmt, context);
taskStmt = insertStmt;
} else if (statement.getDataCacheSelectStmt() != null) {
DataCacheStmtAnalyzer.analyze(statement.getDataCacheSelectStmt(), context);
Expand Down Expand Up @@ -392,12 +392,6 @@ public Void visitShowResourceStatement(ShowResourcesStmt stmt, ConnectContext se
return null;
}

@Override
public Void visitInsertStatement(InsertStmt statement, ConnectContext session) {
InsertAnalyzer.analyze(statement, session);
return null;
}

@Override
public Void visitShowStatement(ShowStmt statement, ConnectContext session) {
ShowStmtAnalyzer.analyze(statement, session);
Expand Down Expand Up @@ -446,18 +440,6 @@ public Void visitQueryStatement(QueryStatement stmt, ConnectContext session) {
return null;
}

@Override
public Void visitUpdateStatement(UpdateStmt node, ConnectContext context) {
UpdateAnalyzer.analyze(node, context);
return null;
}

@Override
public Void visitDeleteStatement(DeleteStmt node, ConnectContext context) {
DeleteAnalyzer.analyze(node, context);
return null;
}

@Override
public Void visitCreateMaterializedViewStatement(CreateMaterializedViewStatement statement,
ConnectContext context) {
Expand Down Expand Up @@ -631,6 +613,26 @@ public Void visitAlterCatalogStatement(AlterCatalogStmt statement, ConnectContex
return null;
}

// ------------------------------------------- DML Statement -------------------------------------------------------

@Override
public Void visitInsertStatement(InsertStmt statement, ConnectContext context) {
DMLStmtAnalyzer.analyze(statement, context);
return null;
}

@Override
public Void visitUpdateStatement(UpdateStmt statement, ConnectContext context) {
DMLStmtAnalyzer.analyze(statement, context);
return null;
}

@Override
public Void visitDeleteStatement(DeleteStmt statement, ConnectContext context) {
DMLStmtAnalyzer.analyze(statement, context);
return null;
}

// ------------------------------------------- Cluster Management Statement ----------------------------------------

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.starrocks.sql.analyzer;

import com.starrocks.qe.ConnectContext;
import com.starrocks.sql.ast.AstVisitor;
import com.starrocks.sql.ast.DeleteStmt;
import com.starrocks.sql.ast.DmlStmt;
import com.starrocks.sql.ast.InsertStmt;
import com.starrocks.sql.ast.UpdateStmt;

public class DMLStmtAnalyzer {
public static void analyze(DmlStmt stmt, ConnectContext context) {
new DMLStmtAnalyzer.DMLStmtAnalyzerVisitor().analyze(stmt, context);
}

static class DMLStmtAnalyzerVisitor implements AstVisitor<Void, ConnectContext> {
public void analyze(DmlStmt dmlStmt, ConnectContext context) {
dmlStmt.getTableName().normalization(context);
visit(dmlStmt, context);
}

@Override
public Void visitInsertStatement(InsertStmt stmt, ConnectContext context) {
InsertAnalyzer.analyze(stmt, context);
return null;
}

@Override
public Void visitUpdateStatement(UpdateStmt stmt, ConnectContext context) {
UpdateAnalyzer.analyze(stmt, context);
return null;
}

@Override
public Void visitDeleteStatement(DeleteStmt stmt, ConnectContext context) {
DeleteAnalyzer.analyze(stmt, context);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public static void analyze(DeleteStmt deleteStatement, ConnectContext session) {
analyzeProperties(deleteStatement, session);

TableName tableName = deleteStatement.getTableName();
tableName.normalization(session);
MetaUtils.checkNotSupportCatalog(tableName.getCatalog(), "DELETE");
Database db = GlobalStateMgr.getCurrentState().getMetadataMgr()
.getDb(tableName.getCatalog(), tableName.getDb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static void analyze(CreatePipeStmt stmt, ConnectContext context) {
stmt.setTargetTable(insertStmt.getTableName());
String insertSql = stmt.getOrigStmt().originStmt.substring(stmt.getInsertSqlStartIndex());
stmt.setInsertSql(insertSql);
InsertAnalyzer.analyze(insertStmt, context);
Analyzer.analyze(insertStmt, context);

analyzePipeName(stmt.getPipeName(), insertStmt.getTableName().getDb());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static void analyze(UpdateStmt updateStmt, ConnectContext session) {
analyzeProperties(updateStmt, session);

TableName tableName = updateStmt.getTableName();
tableName.normalization(session);
Database db = GlobalStateMgr.getCurrentState().getMetadataMgr()
.getDb(tableName.getCatalog(), tableName.getDb());
if (db == null) {
Expand Down

0 comments on commit a852995

Please sign in to comment.