diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/TableNameOrAliasExtractor.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/OwnerNameExtractor.java similarity index 69% rename from sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/TableNameOrAliasExtractor.java rename to sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/OwnerNameExtractor.java index 46e3b0ffce186..15c16d4c540b5 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/TableNameOrAliasExtractor.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/OwnerNameExtractor.java @@ -23,23 +23,23 @@ import org.apache.shardingsphere.core.parse.antlr.extractor.OptionalSQLSegmentExtractor; import org.apache.shardingsphere.core.parse.antlr.extractor.util.ExtractorUtils; import org.apache.shardingsphere.core.parse.antlr.extractor.util.RuleName; -import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.TableNameOrAliasSegment; +import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.OwnerSegment; import org.apache.shardingsphere.core.parse.util.SQLUtil; /** - * Table name or alias extractor. + * Owner name extractor. * * @author zhangliang */ -public final class TableNameOrAliasExtractor implements OptionalSQLSegmentExtractor { +public final class OwnerNameExtractor implements OptionalSQLSegmentExtractor { @Override - public Optional extract(final ParserRuleContext ancestorNode) { - Optional tableNameOrAliasNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.TABLE_NAME_OR_ALIAS); - if (!tableNameOrAliasNode.isPresent()) { + public Optional extract(final ParserRuleContext ancestorNode) { + Optional ownerNameNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.OWNER_NAME); + if (!ownerNameNode.isPresent()) { return Optional.absent(); } - String name = tableNameOrAliasNode.get().getText(); - return Optional.of(new TableNameOrAliasSegment(tableNameOrAliasNode.get().getStart().getStartIndex(), SQLUtil.getExactlyValue(name), QuoteCharacter.getQuoteCharacter(name))); + String name = ownerNameNode.get().getText(); + return Optional.of(new OwnerSegment(ownerNameNode.get().getStart().getStartIndex(), SQLUtil.getExactlyValue(name), QuoteCharacter.getQuoteCharacter(name))); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/TableNamesOrAliasesExtractor.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/OwnerNamesExtractor.java similarity index 67% rename from sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/TableNamesOrAliasesExtractor.java rename to sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/OwnerNamesExtractor.java index e643c66dbb2ac..82ef8c59f5a6d 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/TableNamesOrAliasesExtractor.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/OwnerNamesExtractor.java @@ -22,27 +22,27 @@ import org.apache.shardingsphere.core.parse.antlr.extractor.CollectionSQLSegmentExtractor; import org.apache.shardingsphere.core.parse.antlr.extractor.util.ExtractorUtils; import org.apache.shardingsphere.core.parse.antlr.extractor.util.RuleName; -import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.TableNameOrAliasSegment; +import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.OwnerSegment; import java.util.Collection; import java.util.LinkedList; /** - * Table names or aliases extractor. + * Owner names extractor. * * @author zhangliang */ -public final class TableNamesOrAliasesExtractor implements CollectionSQLSegmentExtractor { +public final class OwnerNamesExtractor implements CollectionSQLSegmentExtractor { - private final TableNameOrAliasExtractor tableNameOrAliasExtractor = new TableNameOrAliasExtractor(); + private final OwnerNameExtractor ownerNameExtractor = new OwnerNameExtractor(); @Override - public Collection extract(final ParserRuleContext ancestorNode) { - Collection result = new LinkedList<>(); - for (ParserRuleContext each : ExtractorUtils.getAllDescendantNodes(ancestorNode, RuleName.TABLE_NAME_OR_ALIAS)) { - Optional tableNameOrAliasSegment = tableNameOrAliasExtractor.extract(each); - if (tableNameOrAliasSegment.isPresent()) { - result.add(tableNameOrAliasSegment.get()); + public Collection extract(final ParserRuleContext ancestorNode) { + Collection result = new LinkedList<>(); + for (ParserRuleContext each : ExtractorUtils.getAllDescendantNodes(ancestorNode, RuleName.OWNER_NAME)) { + Optional ownerSegment = ownerNameExtractor.extract(each); + if (ownerSegment.isPresent()) { + result.add(ownerSegment.get()); } } return result; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java index 76dfaa031a15c..68c99b19c1112 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java @@ -29,7 +29,7 @@ public enum RuleName { TABLE_NAME("TableName"), - TABLE_NAME_OR_ALIAS("TableNameOrAlias"), + OWNER_NAME("OwnerName"), COLUMN_DEFINITION("ColumnDefinition"), diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/segment/impl/TableNameOrAliasFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/segment/impl/OwnerFiller.java similarity index 74% rename from sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/segment/impl/TableNameOrAliasFiller.java rename to sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/segment/impl/OwnerFiller.java index b49b2ede8d8cd..175d851031a71 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/segment/impl/TableNameOrAliasFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/segment/impl/OwnerFiller.java @@ -19,19 +19,19 @@ import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData; import org.apache.shardingsphere.core.parse.antlr.filler.sharding.SQLSegmentShardingFiller; -import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.TableNameOrAliasSegment; +import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.OwnerSegment; import org.apache.shardingsphere.core.parse.parser.sql.SQLStatement; import org.apache.shardingsphere.core.rule.ShardingRule; /** - * Table name or alias filler. + * Owner filler. * * @author zhangliang */ -public final class TableNameOrAliasFiller implements SQLSegmentShardingFiller { +public final class OwnerFiller implements SQLSegmentShardingFiller { @Override - public void fill(final TableNameOrAliasSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { - sqlStatement.getTables().getTableNameOrAliasSegment().add(sqlSegment); + public void fill(final OwnerSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + sqlStatement.getTables().getOwnerSegments().add(sqlSegment); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/segment/table/TableNameOrAliasSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/segment/table/OwnerSegment.java similarity index 93% rename from sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/segment/table/TableNameOrAliasSegment.java rename to sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/segment/table/OwnerSegment.java index 0c0fff00cd615..76400a937eba3 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/segment/table/TableNameOrAliasSegment.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/segment/table/OwnerSegment.java @@ -23,13 +23,13 @@ import org.apache.shardingsphere.core.parse.antlr.sql.segment.SQLSegment; /** - * Table name or alias segment. + * Owner segment. * * @author zhangliang */ @RequiredArgsConstructor @Getter -public class TableNameOrAliasSegment implements SQLSegment { +public class OwnerSegment implements SQLSegment { private final int startIndex; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/parser/context/table/Tables.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/parser/context/table/Tables.java index 7050bf6384b2f..3e00c63878077 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/parser/context/table/Tables.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/parser/context/table/Tables.java @@ -21,7 +21,7 @@ import com.google.common.base.Preconditions; import lombok.Getter; import lombok.ToString; -import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.TableNameOrAliasSegment; +import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.OwnerSegment; import java.util.ArrayList; import java.util.Collection; @@ -42,7 +42,7 @@ public final class Tables { private final List tables = new ArrayList<>(); @Getter - private final Collection tableNameOrAliasSegment = new LinkedList<>(); + private final Collection ownerSegments = new LinkedList<>(); /** * Add table. diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/common/extractor-rule-definition.xml b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/common/extractor-rule-definition.xml index d6c902ba55ea9..35ced3ce27fd9 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/common/extractor-rule-definition.xml +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/common/extractor-rule-definition.xml @@ -19,7 +19,7 @@ - + diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/sharding/common/filler-rule-definition.xml b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/sharding/common/filler-rule-definition.xml index eb3ab8ff97b02..9a57ebdbb8b95 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/sharding/common/filler-rule-definition.xml +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/sharding/common/filler-rule-definition.xml @@ -18,7 +18,7 @@ - + diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 index b5ba01f546284..b3c0836e3bb53 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 @@ -41,10 +41,6 @@ tableName : (schemaName DOT_)? uid ; -tableNameOrAlias - : uid - ; - ownerName : uid ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/MySQLDQLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/MySQLDQLStatement.g4 index 8019a893c5c04..6ab2934f5351d 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/MySQLDQLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/MySQLDQLStatement.g4 @@ -44,7 +44,7 @@ selectExprs ; selectExpr - : (columnName | expr) AS? alias? | tableNameOrAlias DOT_ASTERISK_ + : (columnName | expr) AS? alias? | ownerName DOT_ASTERISK_ ; fromClause diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/java/org/apache/shardingsphere/core/parse/optimizer/MySQLSelectOptimizer.java b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/java/org/apache/shardingsphere/core/parse/optimizer/MySQLSelectOptimizer.java index 385853d55250f..0bc3cc189eff3 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/java/org/apache/shardingsphere/core/parse/optimizer/MySQLSelectOptimizer.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/java/org/apache/shardingsphere/core/parse/optimizer/MySQLSelectOptimizer.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.core.constant.AggregationType; import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData; import org.apache.shardingsphere.core.parse.antlr.optimizer.SQLStatementOptimizer; -import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.TableNameOrAliasSegment; +import org.apache.shardingsphere.core.parse.antlr.sql.segment.table.OwnerSegment; import org.apache.shardingsphere.core.parse.parser.constant.DerivedColumn; import org.apache.shardingsphere.core.parse.parser.context.condition.OrCondition; import org.apache.shardingsphere.core.parse.parser.context.orderby.OrderItem; @@ -52,16 +52,16 @@ public final class MySQLSelectOptimizer implements SQLStatementOptimizer { @Override public void optimize(final SQLStatement sqlStatement, final ShardingTableMetaData shardingTableMetaData) { - addTableTokensIfIsNotAlias(sqlStatement); + addTableTokensIfOwnerIsNotAlias(sqlStatement); appendDerivedColumns((SelectStatement) sqlStatement, shardingTableMetaData); appendDerivedOrderBy((SelectStatement) sqlStatement); postExtractInternal(sqlStatement); } - private void addTableTokensIfIsNotAlias(final SQLStatement sqlStatement) { + private void addTableTokensIfOwnerIsNotAlias(final SQLStatement sqlStatement) { List toBeAdded = new LinkedList<>(); final Collection tableNames = sqlStatement.getTables().getTableNames(); - for (TableNameOrAliasSegment each : sqlStatement.getTables().getTableNameOrAliasSegment()) { + for (OwnerSegment each : sqlStatement.getTables().getOwnerSegments()) { if (!isAlias(tableNames, each)) { toBeAdded.add(new TableToken(each.getStartIndex(), each.getName(), each.getQuoteCharacter(), 0)); } @@ -69,9 +69,9 @@ private void addTableTokensIfIsNotAlias(final SQLStatement sqlStatement) { sqlStatement.getSQLTokens().addAll(toBeAdded); } - private boolean isAlias(final Collection tableNames, final TableNameOrAliasSegment tableNameOrAliasSegment) { + private boolean isAlias(final Collection tableNames, final OwnerSegment ownerSegment) { for (String each : tableNames) { - if (each.equalsIgnoreCase(tableNameOrAliasSegment.getName())) { + if (each.equalsIgnoreCase(ownerSegment.getName())) { return false; } }