mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for SchemaStat
This commit is contained in:
@@ -8,7 +8,6 @@ import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class PGSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
@@ -24,6 +23,15 @@ public class PGSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
private SQLOrderBy orderBy;
|
||||
private FetchClause fetch;
|
||||
private ForClause forClause;
|
||||
private IntoClause into;
|
||||
|
||||
public IntoClause getInto() {
|
||||
return into;
|
||||
}
|
||||
|
||||
public void setInto(IntoClause into) {
|
||||
this.into = into;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
@@ -35,6 +43,7 @@ public class PGSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
acceptChild(visitor, this.with);
|
||||
acceptChild(visitor, this.distinctOn);
|
||||
acceptChild(visitor, this.selectList);
|
||||
acceptChild(visitor, this.into);
|
||||
acceptChild(visitor, this.from);
|
||||
acceptChild(visitor, this.where);
|
||||
acceptChild(visitor, this.groupBy);
|
||||
@@ -284,4 +293,39 @@ public class PGSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntoClause extends PGSQLObjectImpl {
|
||||
public static enum Option {
|
||||
TEMPORARY, TEMP, UNLOGGED
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExpr table;
|
||||
private Option option;
|
||||
|
||||
public Option getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
public void setOption(Option option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public SQLExpr getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public void setTable(SQLExpr table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(PGASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, table);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithQuery;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
@@ -76,6 +77,31 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
parseSelectList(queryBlock);
|
||||
|
||||
if (lexer.token() == Token.INTO) {
|
||||
IntoClause into = new IntoClause();
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.TEMPORARY) {
|
||||
lexer.nextToken();
|
||||
into.setOption(IntoClause.Option.TEMPORARY);
|
||||
} else if (lexer.token() == Token.TEMP) {
|
||||
lexer.nextToken();
|
||||
into.setOption(IntoClause.Option.TEMP);
|
||||
} else if (lexer.token() == Token.UNLOGGED) {
|
||||
lexer.nextToken();
|
||||
into.setOption(IntoClause.Option.UNLOGGED);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLExpr name = this.createExprParser().name();
|
||||
into.setTable(name);
|
||||
|
||||
queryBlock.setInto(into);
|
||||
}
|
||||
|
||||
parseFrom(queryBlock);
|
||||
|
||||
|
||||
@@ -23,4 +23,8 @@ public interface PGASTVisitor extends SQLASTVisitor {
|
||||
void endVisit(PGSelectQueryBlock.WithClause x);
|
||||
|
||||
boolean visit(PGSelectQueryBlock.WithClause x);
|
||||
|
||||
void endVisit(PGSelectQueryBlock.IntoClause x);
|
||||
|
||||
boolean visit(PGSelectQueryBlock.IntoClause x);
|
||||
}
|
||||
|
||||
+12
@@ -2,6 +2,7 @@ package com.alibaba.druid.sql.dialect.postgresql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.FetchClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.ForClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WindowClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithQuery;
|
||||
@@ -64,5 +65,16 @@ public class PGASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(IntoClause x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IntoClause x) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.FetchClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.ForClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WindowClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithQuery;
|
||||
@@ -157,6 +158,11 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements
|
||||
}
|
||||
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (x.getInto() != null) {
|
||||
println();
|
||||
x.getInto().accept(this);
|
||||
}
|
||||
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
@@ -210,4 +216,20 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(IntoClause x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IntoClause x) {
|
||||
print("INTO ");
|
||||
if (x.getOption() != null) {
|
||||
print(x.getOption().name());
|
||||
print(" ");
|
||||
}
|
||||
x.getTable().accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -2,10 +2,12 @@ package com.alibaba.druid.sql.dialect.postgresql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.FetchClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.ForClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WindowClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSelectQueryBlock.WithQuery;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
|
||||
public class PGSchemaStatVisitor extends SchemaStatVisitor implements
|
||||
PGASTVisitor {
|
||||
@@ -63,4 +65,22 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(IntoClause x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IntoClause x) {
|
||||
String ident = x.getTable().toString();
|
||||
|
||||
TableStat stat = tableStats.get(ident);
|
||||
if (stat == null) {
|
||||
stat = new TableStat();
|
||||
tableStats.put(new TableStat.Name(ident), stat);
|
||||
}
|
||||
stat.incrementInsertCount();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user