Support compute incremental stats statement.

This commit is contained in:
林枸 2025-05-15 10:09:38 +08:00 committed by Shaojin Wen
parent 8333677a98
commit 6c2012851c
5 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,39 @@
package com.alibaba.druid.sql.ast;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLComputeIncrementalStatsStatement extends SQLStatementImpl {
private SQLExpr name;
private SQLExpr partition;
public SQLExpr getName() {
return name;
}
public void setName(SQLExpr name) {
if (name != null) {
name.setParent(this);
}
this.name = name;
}
public SQLExpr getPartition() {
return partition;
}
public void setPartition(SQLExpr partition) {
if (partition != null) {
partition.setParent(this);
}
this.partition = partition;
}
@Override
protected void accept0(SQLASTVisitor v) {
if (v.visit(this)) {
acceptChild(v, name);
acceptChild(v, partition);
}
v.endVisit(this);
}
}

View File

@ -688,6 +688,12 @@ public class SQLStatementParser extends SQLParser {
continue;
}
if (lexer.token == COMPUTE) {
SQLStatement stmt = parseCompute();
statementList.add(stmt);
continue;
}
int size = statementList.size();
if (parseStatementListDialect(statementList)) {
if (parent != null) {
@ -7805,6 +7811,18 @@ public class SQLStatementParser extends SQLParser {
}
return stmt;
}
public SQLComputeIncrementalStatsStatement parseCompute() {
accept(COMPUTE);
acceptIdentifier("INCREMENTAL");
acceptIdentifier("STATS");
SQLComputeIncrementalStatsStatement stmt = new SQLComputeIncrementalStatsStatement();
stmt.setName(this.exprParser.expr());
if (lexer.nextIf(PARTITION)) {
stmt.setPartition(this.exprParser.expr());
}
return stmt;
}
public SQLStartTransactionStatement parseStart() {
acceptIdentifier("START");
acceptIdentifier("TRANSACTION");

View File

@ -12327,6 +12327,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
}
return false;
}
public boolean visit(SQLComputeIncrementalStatsStatement x) {
print0(ucase ? "COMPUTE INCREMENTAL STATS " : "compute incremental stats ");
x.getName().accept(this);
if (x.getPartition() != null) {
print0(ucase ? " PARTITION " : " partition ");
x.getPartition().accept(this);
}
return false;
}
@Override
public boolean visit(SQLExceptionStatement.Item x) {
print0(ucase ? "WHEN " : "when ");

View File

@ -2735,6 +2735,13 @@ public interface SQLASTVisitor {
default void endVisit(SQLTypeExpr x) {
}
default boolean visit(SQLComputeIncrementalStatsStatement x) {
return true;
}
default void endVisit(SQLComputeIncrementalStatsStatement x) {
}
static SQLASTVisitor ofMethodInvoke(Consumer<SQLMethodInvokeExpr> p) {
return ofMethodInvoke(null, p);
}

View File

@ -1,3 +1,11 @@
COMPUTE INCREMENTAL STATS test.test
--------------------
COMPUTE INCREMENTAL STATS test.test
------------------------------------------------------------------------------------------------------------------------
COMPUTE INCREMENTAL STATS test.test PARTITION p1
--------------------
COMPUTE INCREMENTAL STATS test.test PARTITION p1
------------------------------------------------------------------------------------------------------------------------
SELECT
straight_join o.org_new_no AS org_new_no --AD店铺代号机构最新编码
,