Skip to content
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

Merged
merged 7 commits into from Mar 26, 2020
Merged

Conversation

jingshanglu
Copy link
Contributor

ref #4885 .

Changes proposed in this pull request:

  • add tableReferences in selectStatement
  • Keep tables and remove tables in the next subtask
  • only change for mysql ,Subtasks behind will be compatible with other db

@codecov-io
Copy link

codecov-io commented Mar 24, 2020

Codecov Report

Merging #4916 into master will decrease coverage by 0.20%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...rser/sql/segment/dml/JoinSpecificationSegment.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...sql/parser/sql/segment/dml/JoinedTableSegment.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...sql/parser/sql/segment/dml/TableFactorSegment.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
.../parser/sql/segment/dml/TableReferenceSegment.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
.../sql/parser/sql/statement/dml/SelectStatement.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...or/impl/keygen/BaseGeneratedKeyTokenGenerator.java 66.66% <0.00%> (-16.67%) 1.00% <0.00%> (ø%)
...phere/sharding/merge/dql/orderby/OrderByValue.java 83.67% <0.00%> (-9.88%) 0.00% <0.00%> (ø%)
.../sharding/route/engine/ShardingRouteDecorator.java 23.21% <0.00%> (-3.91%) 0.00% <0.00%> (ø%)
...r/binder/statement/dml/InsertStatementContext.java 86.36% <0.00%> (-3.64%) 0.00% <0.00%> (ø%)
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 806c231...7377aa5. Read the comment docs.

@coveralls
Copy link

coveralls commented Mar 24, 2020

Pull Request Test Coverage Report for Build 10568

  • 0 of 72 (0.0%) changed or added relevant lines in 6 files are covered.
  • 53 unchanged lines in 9 files lost coverage.
  • Overall coverage decreased (-0.2%) to 57.973%

Changes Missing Coverage Covered Lines Changed/Added Lines %
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/SelectStatement.java 0 1 0.0%
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/JoinSpecificationSegment.java 0 2 0.0%
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/TableFactorSegment.java 0 3 0.0%
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/JoinedTableSegment.java 0 5 0.0%
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/TableReferenceSegment.java 0 12 0.0%
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java 0 49 0.0%
Files with Coverage Reduction New Missed Lines %
sharding-core/sharding-core-entry/src/main/java/org/apache/shardingsphere/core/shard/BaseShardingEngine.java 1 93.18%
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/engine/ShardingSQLRewriteEngine.java 1 95.65%
sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/util/IpUtils.java 3 76.0%
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java 3 0%
sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/core/rule/TableRule.java 5 89.77%
sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/synctask/history/HistoryDataSyncTask.java 7 76.47%
sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/core/rule/ShardingRule.java 8 85.21%
sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/execute/executor/channel/MemoryChannel.java 8 51.85%
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingRouteDecorator.java 17 32.14%
Totals Coverage Status
Change from base Build 1155: -0.2%
Covered Lines: 11874
Relevant Lines: 20482

💛 - Coveralls


private final Collection<JoinedTableSegment> joinedTables = new LinkedList<>();

private final Collection<SimpleTableSegment> tables = new LinkedList<>();
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor

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<>();
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been deleted.

Copy link
Contributor

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" />
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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()) {
Copy link
Contributor

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()));
Copy link
Contributor

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());
Copy link
Contributor

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()) {
Copy link
Contributor

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()) {
Copy link
Contributor

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.

@tristaZero
Copy link
Contributor

The approach you took is basically correct and a good start for this issue. However some comments and doubts need your feedback.
@jingshanglu

@tristaZero tristaZero self-requested a review March 25, 2020 04:09
Copy link
Contributor

@tristaZero tristaZero left a 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.

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));
Copy link
Contributor

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<>();
Copy link
Contributor

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" />
Copy link
Contributor

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");
Copy link
Contributor

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<>();
Copy link
Contributor

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?

@jingshanglu
Copy link
Contributor Author

@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" />
Copy link
Contributor

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<>();
Copy link
Contributor

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.

@tristaZero tristaZero merged commit 4d53d22 into apache:master Mar 26, 2020
@tristaZero tristaZero added this to the 5.0.0 milestone Mar 26, 2020
@jingshanglu jingshanglu deleted the ref-4885 branch March 26, 2020 06:30
@terrymanu terrymanu modified the milestones: 5.0.0, 4.1.0 Mar 28, 2020
@jingshanglu jingshanglu restored the ref-4885 branch April 1, 2020 04:18
@jingshanglu jingshanglu deleted the ref-4885 branch April 14, 2020 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants