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
add tableReferences in selectStatement #4916
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4916 +/- ##
============================================
- Coverage 54.65% 54.45% -0.21%
- Complexity 436 440 +4
============================================
Files 1138 1140 +2
Lines 20403 20482 +79
Branches 3750 3765 +15
============================================
+ Hits 11152 11154 +2
- Misses 8547 8620 +73
- Partials 704 708 +4
Continue to review full report at Codecov.
|
...l/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java
Show resolved
Hide resolved
...l/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java
Show resolved
Hide resolved
|
||
private final Collection<JoinedTableSegment> joinedTables = new LinkedList<>(); | ||
|
||
private final Collection<SimpleTableSegment> tables = new LinkedList<>(); |
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.
Is it likely to remove this member?
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.
yes
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.
So? Why not now?
@@ -44,6 +45,8 @@ | |||
|
|||
private ProjectionsSegment projections; | |||
|
|||
private final Collection<TableReferenceSegment> tableReferences = new LinkedList<>(); |
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.
Do you think private final Collection<TableSegment> tables = new LinkedList<>();
can be deleted from this class?
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.
yes
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.
Why do not you delete them right now?
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.
It has been deleted.
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.
But I can not find any relevant changes on this page.
@@ -48,8 +48,8 @@ | |||
<simple-table name="t_order" start-index="27" stop-index="33" /> | |||
<simple-table name="t_order_item" start-index="40" stop-index="51" /> | |||
<!-- FIXME should not has table segment for owner --> | |||
<simple-table name="t_order" start-index="56" stop-index="62" /> | |||
<simple-table name="t_order_item" start-index="75" stop-index="86" /> |
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 add TODO comment
to avoid forgetting this issue here.
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.
this 2 lines should be deleted. other case will change like this. so,should i add TODO comment?
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.
If you plan to delete them in the future, please add TODO comment for reminding.
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.
? I guess you missed this comment
@@ -315,7 +326,12 @@ public ASTNode visitSelectClause(final SelectClauseContext ctx) { | |||
result.getProjections().setDistinctRow(isDistinct(ctx)); | |||
} | |||
if (null != ctx.fromClause()) { | |||
result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.fromClause())).getValue()); | |||
CollectionValue<TableReferenceSegment> tableReferences = (CollectionValue<TableReferenceSegment>) visit(ctx.fromClause()); | |||
for (TableReferenceSegment t : tableReferences.getValue()) { |
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 use the value named each
for for loop
.
for (TableReferenceSegment t : tableReferences.getValue()) { | ||
result.getValue().addAll(t.getTables()); | ||
} | ||
// result.combine((CollectionValue<SimpleTableSegment>) visit(ctx.tableReferences())); |
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.
Why did not you comment on this sentence instead of deleting it?
for (TableReferenceSegment t : tableReferences.getValue()) { | ||
result.getTables().addAll(t.getTables()); | ||
} | ||
// result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableReferences())).getValue()); |
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.
Why did not you comment on this sentence instead of deleting it?
@@ -279,7 +286,11 @@ public ASTNode visitSingleTableClause(final SingleTableClauseContext ctx) { | |||
public ASTNode visitMultipleTablesClause(final MultipleTablesClauseContext ctx) { | |||
CollectionValue<SimpleTableSegment> result = new CollectionValue<>(); | |||
result.combine((CollectionValue<SimpleTableSegment>) visit(ctx.multipleTableNames())); | |||
result.combine((CollectionValue<SimpleTableSegment>) visit(ctx.tableReferences())); | |||
CollectionValue<TableReferenceSegment> tableReferences = (CollectionValue<TableReferenceSegment>) visit(ctx.tableReferences()); | |||
for (TableReferenceSegment t : tableReferences.getValue()) { |
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 use the value named each
for for loop
.
for (JoinedTableContext each : ctx.joinedTable()) { | ||
result.getValue().addAll(getTableSegments(result.getValue(), each)); | ||
if (!ctx.joinedTable().isEmpty()) { | ||
for (JoinedTableContext jc : ctx.joinedTable()) { |
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 use the value named each
for for loop
.
The approach you took is basically correct and a good start for this issue. However some comments and doubts need your feedback. |
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 look at my comments.
...l/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java
Show resolved
Hide resolved
TableFactorSegment result = new TableFactorSegment(); | ||
if (null != ctx.subquery()) { | ||
SelectStatement subquery = (SelectStatement) visit(ctx.subquery()); | ||
result.setSubquery(new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), subquery)); |
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 use SubqueryTableSegment
|
||
private final Collection<JoinedTableSegment> joinedTables = new LinkedList<>(); | ||
|
||
private final Collection<SimpleTableSegment> tables = new LinkedList<>(); |
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.
So? Why not now?
@@ -48,8 +48,8 @@ | |||
<simple-table name="t_order" start-index="27" stop-index="33" /> | |||
<simple-table name="t_order_item" start-index="40" stop-index="51" /> | |||
<!-- FIXME should not has table segment for owner --> | |||
<simple-table name="t_order" start-index="56" stop-index="62" /> | |||
<simple-table name="t_order_item" start-index="75" stop-index="86" /> |
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.
If you plan to delete them in the future, please add TODO comment for reminding.
@@ -133,6 +133,9 @@ private static boolean isPlaceholderWithoutParameter(final Object[] sqlTestParam | |||
|
|||
@Test | |||
public void assertSupportedSQL() { | |||
if ("select_alias_as_keyword".equals(sqlCaseId) && "MySQL".equals(databaseType)) { | |||
System.out.println("dadf"); |
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.
Delete system out
.
@@ -44,6 +45,8 @@ | |||
|
|||
private ProjectionsSegment projections; | |||
|
|||
private final Collection<TableReferenceSegment> tableReferences = new LinkedList<>(); |
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.
Why do not you delete them right now?
...t/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/TableFactorSegment.java
Show resolved
Hide resolved
@tristaZero I have changed base comment,please review. |
@@ -48,8 +48,8 @@ | |||
<simple-table name="t_order" start-index="27" stop-index="33" /> | |||
<simple-table name="t_order_item" start-index="40" stop-index="51" /> | |||
<!-- FIXME should not has table segment for owner --> | |||
<simple-table name="t_order" start-index="56" stop-index="62" /> | |||
<simple-table name="t_order_item" start-index="75" stop-index="86" /> |
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.
? I guess you missed this comment
@@ -44,6 +45,8 @@ | |||
|
|||
private ProjectionsSegment projections; | |||
|
|||
private final Collection<TableReferenceSegment> tableReferences = new LinkedList<>(); |
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.
But I can not find any relevant changes on this page.
ref #4885 .
Changes proposed in this pull request: