Skip to content

Commit

Permalink
Merge d01fc8d into b623737
Browse files Browse the repository at this point in the history
  • Loading branch information
jingshanglu committed Sep 25, 2020
2 parents b623737 + d01fc8d commit be24c71
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
Expand Up @@ -322,7 +322,7 @@ columnDefinition
storageOption
: dataTypeGenericOption
| AUTO_INCREMENT
| DEFAULT (literals | expr)
| DEFAULT expr
| COLUMN_FORMAT (FIXED | DYNAMIC | DEFAULT)
| STORAGE (DISK | MEMORY | DEFAULT)
;
Expand Down Expand Up @@ -414,7 +414,7 @@ alterSpecification
| DROP CHECK ignoredIdentifier_
| ALTER CHECK ignoredIdentifier_ NOT? ENFORCED
| ALGORITHM EQ_? (DEFAULT | INSTANT | INPLACE | COPY)
| ALTER COLUMN? columnName (SET DEFAULT (literals | LP_ expr RP_) | DROP DEFAULT)
| ALTER COLUMN? columnName (SET DEFAULT expr | DROP DEFAULT)
| ALTER INDEX indexName (VISIBLE | INVISIBLE)
| changeColumnSpecification
| modifyColumnSpecification
Expand Down Expand Up @@ -549,7 +549,7 @@ partitionLessThanValue_
;

partitionValueList_
: literals (COMMA_ literals)*
: expr (COMMA_ expr)*
;

partitionDefinitionOption_
Expand Down
Expand Up @@ -34,14 +34,13 @@ FILESIZE_LITERAL
IDENTIFIER_
: [A-Za-z_$0-9]*?[A-Za-z_$]+?[A-Za-z_$0-9]*
| BQ_ ~'`'+ BQ_
| (DQ_ ( '\\'. | '""' | ~('"'| '\\') )* DQ_)
;

Y_N_
: SQ_ ('Y' | 'N') SQ_
;

STRING_
STRING_
: (DQ_ ( '\\'. | '""' | ~('"'| '\\') )* DQ_)
| (SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_)
;
Expand Down
Expand Up @@ -19,7 +19,6 @@

import lombok.AccessLevel;
import lombok.Getter;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
Expand Down Expand Up @@ -386,7 +385,7 @@ private BetweenExpression createBetweenSegment(final PredicateContext ctx) {
@Override
public final ASTNode visitBitExpr(final BitExprContext ctx) {
if (null != ctx.simpleExpr()) {
return createExpressionSegment(visit(ctx.simpleExpr()), ctx);
return visit(ctx.simpleExpr());
}
ExpressionSegment left = (ExpressionSegment) visit(ctx.getChild(0));
ExpressionSegment right = (ExpressionSegment) visit(ctx.getChild(2));
Expand All @@ -396,7 +395,8 @@ public final ASTNode visitBitExpr(final BitExprContext ctx) {
return result;
}

private ASTNode createExpressionSegment(final ASTNode astNode, final ParserRuleContext context) {
private ExpressionSegment createLiteralExpression(final LiteralsContext context) {
ASTNode astNode = visit(context);
if (astNode instanceof StringLiteralValue) {
return new LiteralExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((StringLiteralValue) astNode).getValue());
}
Expand All @@ -406,28 +406,24 @@ private ASTNode createExpressionSegment(final ASTNode astNode, final ParserRuleC
if (astNode instanceof BooleanLiteralValue) {
return new LiteralExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((BooleanLiteralValue) astNode).getValue());
}
if (astNode instanceof ParameterMarkerValue) {
return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue());
}
if (astNode instanceof SubquerySegment) {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), ((OtherLiteralValue) astNode).getValue());
}
return astNode;
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(),
context.start.getInputStream().getText(new Interval(context.start.getStartIndex(), context.stop.getStopIndex())));
}

@Override
public final ASTNode visitSimpleExpr(final SimpleExprContext ctx) {
if (null != ctx.subquery()) {
return new SubquerySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (MySQLSelectStatement) visit(ctx.subquery()));
SubquerySegment subquerySegment = new SubquerySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (MySQLSelectStatement) visit(ctx.subquery()));
return new SubqueryExpressionSegment(subquerySegment);
}
if (null != ctx.parameterMarker()) {
return visit(ctx.parameterMarker());
return new ParameterMarkerExpressionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), ((ParameterMarkerValue) visit(ctx.parameterMarker())).getValue());
}
if (null != ctx.literals()) {
return visit(ctx.literals());
return createLiteralExpression(ctx.literals());
}
if (null != ctx.intervalExpression()) {
return visit(ctx.intervalExpression());
Expand Down Expand Up @@ -603,7 +599,7 @@ private ASTNode visitRemainSimpleExpr(final SimpleExprContext ctx) {
if (null != ctx.caseExpression()) {
visit(ctx.caseExpression());
String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
return new OtherLiteralValue(text);
return new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), text);
}
for (ExprContext each : ctx.expr()) {
visit(each);
Expand Down
Expand Up @@ -471,6 +471,13 @@
</where>
</select>

<select sql-case-id="select_like_with_single_quotes" >
<projections start-index="7" stop-index="8">
<column-projection name="id" start-index="7" stop-index="8"/>
</projections>
<where></where>
</select>

<select sql-case-id="select_count_tilde_concat" parameters="'init', 1, 2, 9, 10">
<table-reference>
<table-factor>
Expand Down
Expand Up @@ -32,6 +32,7 @@
<sql-case id="select_equal_with_same_sharding_column" value="SELECT * FROM t_order WHERE order_id = ? AND order_id = ?" />
<sql-case id="select_in_with_same_sharding_column" value="SELECT * FROM t_order WHERE order_id IN (?, ?) AND order_id IN (?, ?) ORDER BY order_id" />
<sql-case id="select_count_like_concat" value="SELECT count(0) as orders_count FROM t_order o WHERE o.status LIKE CONCAT('%%', ?, '%%') AND o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ?" />
<sql-case id="select_like_with_single_quotes" value="select id from admin where fullname like 'a%'" db-types="MySQL"/>
<sql-case id="select_count_tilde_concat" value="SELECT count(0) as orders_count FROM t_order o WHERE o.status ~~ CONCAT('%%', ?, '%%') AND o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ?" db-types="PostgreSQL" />
<sql-case id="select_sharding_route_with_binding_tables" value="SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? ORDER BY i.item_id" />
<sql-case id="select_full_route_with_binding_tables" value="SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id ORDER BY i.item_id" />
Expand Down

0 comments on commit be24c71

Please sign in to comment.