You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/02/14 03:27:21 UTC
[shardingsphere] branch master updated: Optimize sql parser code style (#15394)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 77be1a3 Optimize sql parser code style (#15394)
77be1a3 is described below
commit 77be1a3ddcd6c8526ac2a83316b169b24d9533f8
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Mon Feb 14 11:26:22 2022 +0800
Optimize sql parser code style (#15394)
* Optimize sql parser code style
---
.../impl/OracleDMLStatementSQLVisitor.java | 6 ++---
.../impl/SQLServerStatementSQLVisitor.java | 28 +++++++++++++---------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
index 56e3b2f..babcc3f 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
@@ -22,7 +22,6 @@ import org.antlr.v4.runtime.misc.Interval;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.operation.SQLStatementVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DMLSQLVisitor;
-import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AliasContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AssignmentValueContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AssignmentValuesContext;
@@ -46,6 +45,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprCo
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExpressionListContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ForUpdateClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ForUpdateClauseListContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ForUpdateClauseOptionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FromClauseListContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FromClauseOptionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.GroupByClauseContext;
@@ -1008,7 +1008,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
private List<SimpleTableSegment> generateTablesFromforUpdateClauseOption(final ForUpdateClauseListContext ctx) {
List<SimpleTableSegment> result = new LinkedList<>();
- for (OracleStatementParser.ForUpdateClauseOptionContext each : ctx.forUpdateClauseOption()) {
+ for (ForUpdateClauseOptionContext each : ctx.forUpdateClauseOption()) {
if (null != each.tableName()) {
result.add((SimpleTableSegment) visit(each.tableName()));
}
@@ -1018,7 +1018,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
private List<ColumnSegment> generateColumnsFromforUpdateClauseOption(final ForUpdateClauseListContext ctx) {
List<ColumnSegment> result = new LinkedList<>();
- for (OracleStatementParser.ForUpdateClauseOptionContext each : ctx.forUpdateClauseOption()) {
+ for (ForUpdateClauseOptionContext each : ctx.forUpdateClauseOption()) {
if (null != each.columnName()) {
result.add((ColumnSegment) visit(each.columnName()));
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
index f7df82b..3840cf7 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
@@ -25,7 +25,7 @@ import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementBaseVisitor;
-import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AggregationClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AggregationFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AliasContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AssignmentContext;
@@ -53,6 +53,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Exp
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.FromClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.FunctionCallContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.GroupByClauseContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.HavingClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.HexadecimalLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.IdentifierContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.IndexNameContext;
@@ -67,6 +68,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Mul
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.MultipleTablesClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.NullValueLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.NumberLiteralsContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OrderByClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OrderByItemContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OutputClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OutputTableNameContext;
@@ -76,9 +78,12 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Own
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ParameterMarkerContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.PredicateContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ProjectionContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ProjectionsContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.QualifiedShorthandContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.RegularFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SchemaNameContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SelectClauseContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SelectContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SetAssignmentsClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SimpleExprContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SingleTableClauseContext;
@@ -89,6 +94,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Tab
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableNameContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableNamesContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableReferenceContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableReferencesContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TopContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UnreservedWordContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UpdateContext;
@@ -644,7 +650,7 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
}
@Override
- public ASTNode visitSelect(final SQLServerStatementParser.SelectContext ctx) {
+ public ASTNode visitSelect(final SelectContext ctx) {
// TODO :Unsupported for withClause.
SQLServerSelectStatement result = (SQLServerSelectStatement) visit(ctx.aggregationClause());
result.setParameterCount(getCurrentParameterIndex());
@@ -652,13 +658,13 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
}
@Override
- public ASTNode visitAggregationClause(final SQLServerStatementParser.AggregationClauseContext ctx) {
+ public ASTNode visitAggregationClause(final AggregationClauseContext ctx) {
// TODO :Unsupported for union | except | intersect SQL.
return visit(ctx.selectClause(0));
}
@Override
- public ASTNode visitSelectClause(final SQLServerStatementParser.SelectClauseContext ctx) {
+ public ASTNode visitSelectClause(final SelectClauseContext ctx) {
SQLServerSelectStatement result = new SQLServerSelectStatement();
result.setProjections((ProjectionsSegment) visit(ctx.projections()));
if (null != ctx.duplicateSpecification()) {
@@ -684,12 +690,12 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
}
@Override
- public ASTNode visitHavingClause(final SQLServerStatementParser.HavingClauseContext ctx) {
+ public ASTNode visitHavingClause(final HavingClauseContext ctx) {
ExpressionSegment expr = (ExpressionSegment) visit(ctx.expr());
return new HavingSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), expr);
}
- private SQLServerSelectStatement visitOrderBy(final SQLServerSelectStatement selectStatement, final SQLServerStatementParser.OrderByClauseContext ctx) {
+ private SQLServerSelectStatement visitOrderBy(final SQLServerSelectStatement selectStatement, final OrderByClauseContext ctx) {
Collection<OrderByItemSegment> items = new LinkedList<>();
int orderByStartIndex = ctx.start.getStartIndex();
int orderByStopIndex = ctx.start.getStartIndex();
@@ -727,17 +733,17 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
return selectStatement;
}
- private boolean isDistinct(final SQLServerStatementParser.SelectClauseContext ctx) {
+ private boolean isDistinct(final SelectClauseContext ctx) {
return ((BooleanLiteralValue) visit(ctx.duplicateSpecification())).getValue();
}
@Override
- public ASTNode visitProjections(final SQLServerStatementParser.ProjectionsContext ctx) {
+ public ASTNode visitProjections(final ProjectionsContext ctx) {
Collection<ProjectionSegment> projections = new LinkedList<>();
if (null != ctx.unqualifiedShorthand()) {
projections.add(new ShorthandProjectionSegment(ctx.unqualifiedShorthand().getStart().getStartIndex(), ctx.unqualifiedShorthand().getStop().getStopIndex()));
}
- for (SQLServerStatementParser.ProjectionContext each : ctx.projection()) {
+ for (ProjectionContext each : ctx.projection()) {
projections.add((ProjectionSegment) visit(each));
}
ProjectionsSegment result = new ProjectionsSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
@@ -746,7 +752,7 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
}
@Override
- public ASTNode visitTableReferences(final SQLServerStatementParser.TableReferencesContext ctx) {
+ public ASTNode visitTableReferences(final TableReferencesContext ctx) {
TableSegment result = (TableSegment) visit(ctx.tableReference(0));
if (ctx.tableReference().size() > 1) {
for (int i = 1; i < ctx.tableReference().size(); i++) {
@@ -756,7 +762,7 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
return result;
}
- private JoinTableSegment generateJoinTableSourceFromTableReference(final SQLServerStatementParser.TableReferenceContext ctx, final TableSegment tableSegment) {
+ private JoinTableSegment generateJoinTableSourceFromTableReference(final TableReferenceContext ctx, final TableSegment tableSegment) {
JoinTableSegment result = new JoinTableSegment();
result.setStartIndex(tableSegment.getStartIndex());
result.setStopIndex(ctx.stop.getStopIndex());