-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for boolean primary MySQL queries #25424
Changes from all commits
0fad338
757a8d9
2bdf6c0
500d9eb
dc5b165
cecddb7
224ffa6
53da3df
36e2eeb
f8c8a07
363f769
abeeeb8
74eccad
54ee8dc
0dd3956
9f4bbe9
cc95efe
aa67406
daeeacf
0e049e6
be5427d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,6 +421,7 @@ private BinaryOperationExpression createBinaryOperationExpression(final ExprCont | |
public final ASTNode visitBooleanPrimary(final BooleanPrimaryContext ctx) { | ||
if (null != ctx.IS()) { | ||
// TODO optimize operatorToken | ||
String operator = "IS"; | ||
String rightText = ""; | ||
if (null != ctx.NOT()) { | ||
rightText = rightText.concat(ctx.start.getInputStream().getText(new Interval(ctx.NOT().getSymbol().getStartIndex(), | ||
|
@@ -429,6 +430,10 @@ public final ASTNode visitBooleanPrimary(final BooleanPrimaryContext ctx) { | |
Token operatorToken = null; | ||
if (null != ctx.NULL()) { | ||
operatorToken = ctx.NULL().getSymbol(); | ||
operator = "IS NULL"; | ||
} | ||
if (null != ctx.NULL() && null != ctx.NOT()) { | ||
operator = "IS NOT NULL"; | ||
} | ||
if (null != ctx.TRUE()) { | ||
operatorToken = ctx.TRUE().getSymbol(); | ||
|
@@ -441,7 +446,9 @@ public final ASTNode visitBooleanPrimary(final BooleanPrimaryContext ctx) { | |
ExpressionSegment right = new LiteralExpressionSegment(ctx.IS().getSymbol().getStopIndex() + 2, ctx.stop.getStopIndex(), rightText); | ||
String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); | ||
ExpressionSegment left = (ExpressionSegment) visit(ctx.booleanPrimary()); | ||
String operator = "IS"; | ||
if (null != ctx.NULL()) { | ||
right = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you refer https://github.com/polardb/polardbx-sql/blob/cdd976850bdfc3264dff279198b6b06eb8641fbe/polardbx-optimizer/src/main/java/com/alibaba/polardbx/optimizer/parse/visitor/FastSqlToCalciteNodeVisitor.java#L5346-L5350 to extract There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely sir, I tried it on my local system. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can modify is null operator to is operator, is not null operator to is not operator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @strongduanmu Sir, I tried it. The problem I am encountering is that Calcite's SqlStdOperatorTable do not have "IS" as a function or PostFixOperator. Therefore While breaking "IS NULL" into "IS" as operator & "NULL" in right as LiteralExpressionSegment, It gives error "IS" is not supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @strongduanmu Therefore Please suggest a solution for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@kanha-gupta Can you take a look at this link? It provide an example to convert to sql node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @strongduanmu Okay sir, I will update you with the progress :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @strongduanmu Sir, should I just revise CodeStyle ? in the example code, operator is set when Right is instanceof SqlNullExpr. Therefore I can understand that the Logic would stay same just like this current PR ? |
||
} | ||
return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); | ||
} | ||
if (null != ctx.comparisonOperator() || null != ctx.SAFE_EQ_()) { | ||
|
@@ -474,12 +481,17 @@ private ASTNode createAssignmentSegment(final BooleanPrimaryContext ctx) { | |
private ASTNode createCompareSegment(final BooleanPrimaryContext ctx) { | ||
ExpressionSegment left = (ExpressionSegment) visit(ctx.booleanPrimary()); | ||
ExpressionSegment right; | ||
String operator; | ||
if (null != ctx.ALL()) { | ||
kanha-gupta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
operator = null != ctx.SAFE_EQ_() ? ctx.SAFE_EQ_().getText() : ctx.comparisonOperator().getText() + " ALL"; | ||
} else { | ||
operator = null != ctx.SAFE_EQ_() ? ctx.SAFE_EQ_().getText() : ctx.comparisonOperator().getText(); | ||
} | ||
if (null != ctx.predicate()) { | ||
right = (ExpressionSegment) visit(ctx.predicate()); | ||
} else { | ||
right = new SubqueryExpressionSegment(new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), (MySQLSelectStatement) visit(ctx.subquery()))); | ||
} | ||
String operator = null != ctx.SAFE_EQ_() ? ctx.SAFE_EQ_().getText() : ctx.comparisonOperator().getText(); | ||
String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); | ||
return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, operator, text); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,7 +356,7 @@ private BinaryOperationExpression createPatternMatchingOperationSegment(final AE | |
|
||
private BinaryOperationExpression createBinaryOperationSegment(final AExprContext ctx, final String operator) { | ||
if ("IS".equalsIgnoreCase(operator)) { | ||
ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0)); | ||
String ifOperator = operator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does ifOperator mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sir, I'll rename it. The variable helps in storing & changing String values when IF conditions are met. |
||
String rightText; | ||
ExpressionSegment right; | ||
if (null != ctx.IS()) { | ||
|
@@ -366,7 +366,15 @@ private BinaryOperationExpression createBinaryOperationSegment(final AExprContex | |
rightText = ctx.start.getInputStream().getText(new Interval(ctx.ISNULL().getSymbol().getStartIndex() + 2, ctx.stop.getStopIndex())).trim(); | ||
right = new LiteralExpressionSegment(ctx.ISNULL().getSymbol().getStartIndex() + 2, ctx.stop.getStopIndex(), rightText); | ||
} | ||
return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, "IS", | ||
if (null != ctx.NULL()) { | ||
ifOperator = "IS NULL"; | ||
right = null; | ||
} | ||
if (null != ctx.NULL() && null != ctx.NOT()) { | ||
ifOperator = "IS NOT NULL"; | ||
} | ||
ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0)); | ||
return new BinaryOperationExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, ifOperator, | ||
ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()))); | ||
} | ||
ExpressionSegment left = (ExpressionSegment) visit(ctx.aExpr(0)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove useless IS operator.