Commit 2d049d65 authored by terrymanu's avatar terrymanu
Browse files

for #2084, StarSelectItemSegment => ShorthandSelectItemSegment

parent 18544d71
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.shardingsphere.core.parse.antlr.extractor.api.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.dml.item.StarSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ShorthandSelectItemSegment;

/**
 * Shorthand select item extractor.
@@ -32,14 +32,14 @@ import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.StarSelec
public final class ShorthandSelectItemExtractor implements OptionalSQLSegmentExtractor {
    
    @Override
    public Optional<StarSelectItemSegment> extract(final ParserRuleContext expressionNode) {
    public Optional<ShorthandSelectItemSegment> extract(final ParserRuleContext expressionNode) {
        Optional<ParserRuleContext> unqualifiedShorthandNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.UNQUALIFIED_SHORTHAND);
        if (unqualifiedShorthandNode.isPresent()) {
            return Optional.of(new StarSelectItemSegment(unqualifiedShorthandNode.get().getStart().getStartIndex()));
            return Optional.of(new ShorthandSelectItemSegment(unqualifiedShorthandNode.get().getStart().getStartIndex()));
        }
        Optional<ParserRuleContext> qualifiedShorthandNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.QUALIFIED_SHORTHAND);
        if (qualifiedShorthandNode.isPresent()) {
            StarSelectItemSegment result = new StarSelectItemSegment(qualifiedShorthandNode.get().getStart().getStartIndex());
            ShorthandSelectItemSegment result = new ShorthandSelectItemSegment(qualifiedShorthandNode.get().getStart().getStartIndex());
            result.setOwner(qualifiedShorthandNode.get().getChild(0).getText());
            return Optional.of(result);
        }
+4 −4
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.Aggregati
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.AggregationSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ColumnSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ExpressionSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.StarSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ShorthandSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.antlr.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.parse.antlr.sql.token.AggregationDistinctToken;
@@ -57,8 +57,8 @@ public final class SelectItemFiller implements SQLSegmentFiller {
            return;
        }
        SelectStatement selectStatement = (SelectStatement) sqlStatement;
        if (sqlSegment instanceof StarSelectItemSegment) {
            fillStarSelectItemSegment((StarSelectItemSegment) sqlSegment, selectStatement);
        if (sqlSegment instanceof ShorthandSelectItemSegment) {
            fillShorthandSelectItemSegment((ShorthandSelectItemSegment) sqlSegment, selectStatement);
            return;
        }
        if (sqlSegment instanceof ColumnSelectItemSegment) {
@@ -78,7 +78,7 @@ public final class SelectItemFiller implements SQLSegmentFiller {
        }
    }
    
    private void fillStarSelectItemSegment(final StarSelectItemSegment selectItemSegment, final SelectStatement selectStatement) {
    private void fillShorthandSelectItemSegment(final ShorthandSelectItemSegment selectItemSegment, final SelectStatement selectStatement) {
        selectStatement.setContainStar(true);
        Optional<String> owner = selectItemSegment.getOwner();
        selectStatement.getItems().add(new StarSelectItem(owner.orNull()));
+2 −2
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.Aggregati
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ColumnSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ExpressionSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.SelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.StarSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.item.ShorthandSelectItemSegment;
import org.apache.shardingsphere.core.parse.antlr.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.antlr.sql.statement.dml.SelectStatement;
import org.apache.shardingsphere.core.parse.old.parser.constant.DerivedAlias;
@@ -73,7 +73,7 @@ public final class SelectItemsFiller implements SQLSegmentFiller<SelectItemsSegm
        Set<String> distinctColumnNames = new LinkedHashSet<>();
        DistinctSelectItem distinctSelectItem = null;
        int offset = 0;
        if (firstSelectItemSegment instanceof StarSelectItemSegment) {
        if (firstSelectItemSegment instanceof ShorthandSelectItemSegment) {
            selectItemFiller.fill(firstSelectItemSegment, selectStatement);
            selectStatement.getItems().add(new DistinctSelectItem(distinctColumnNames, Optional.<String>absent()));
        } else if (firstSelectItemSegment instanceof ColumnSelectItemSegment) {
+2 −2
Original line number Diff line number Diff line
@@ -24,13 +24,13 @@ import org.apache.shardingsphere.core.parse.antlr.sql.OwnerAvailable;
import org.apache.shardingsphere.core.parse.util.SQLUtil;

/**
 * Star select item segment.
 * Shorthand select item segment.
 *
 * @author zhangliang
 */
@RequiredArgsConstructor
@Getter
public final class StarSelectItemSegment implements SelectItemSegment, OwnerAvailable {
public final class ShorthandSelectItemSegment implements SelectItemSegment, OwnerAvailable {
    
    private final int startIndex;