Issue 31437 with keyword query error mysql#34163
Issue 31437 with keyword query error mysql#34163strongduanmu merged 38 commits intoapache:masterfrom
Conversation
…y and resolved the CheckTableExist error during With keyword Query execution
…31437_WITH_KEYWORD_QUERY_ERROR_MYSQL
|
Hi @Yash-cor, can you sync master branch, and add sql bind test case for with statement. |
Yeah sure |
| return new SubquerySegment(segment.getStartIndex(), segment.getStopIndex(), boundSelectStatement, segment.getText()); | ||
| SubquerySegment result = new SubquerySegment(segment.getStartIndex(), segment.getStopIndex(), boundSelectStatement, segment.getText()); | ||
| selectBinderContext.getCommonTableExpressionsSegmentsUniqueAliases().forEach(each -> { | ||
| ShardingSpherePreconditions.checkNotContains(binderContext.getCommonTableExpressionsSegmentsUniqueAliases(), each, () -> new UniqueCommonTableExpressionException(each.toString())); |
There was a problem hiding this comment.
Does this check happen in MySQL? If yes, please provide MySQL test results.
...pache/shardingsphere/infra/binder/engine/segment/dml/from/type/SimpleTableSegmentBinder.java
Outdated
Show resolved
Hide resolved
...n/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/WithSegmentBinder.java
Outdated
Show resolved
Hide resolved
|
|
||
| private final SQLStatement sqlStatement; | ||
|
|
||
| private final Set<CaseInsensitiveString> commonTableExpressionsSegmentsUniqueAliases = new HashSet<>(); |
There was a problem hiding this comment.
Please use Collection<CaseInsensitiveString> to replace Set<CaseInsensitiveString>.
There was a problem hiding this comment.
Besides, dou you think CaseInsensitiveSet is better?
There was a problem hiding this comment.
Now I am using Collection<String> commonTableExpressionsSegmentsUniqueAliases = new CaseInsensitiveSet<>();
CaseInsensitiveSet will be better as it ease the overhead of creating the object in case of Set
.../binder/src/test/java/org/apache/shardingsphere/infra/binder/with/WithSegmentBinderTest.java
Show resolved
Hide resolved
| private static final long serialVersionUID = -8206891094419297634L; | ||
|
|
||
| public UniqueCommonTableExpressionException(final String alias) { | ||
| super(XOpenSQLState.SYNTAX_ERROR, 500, "Not unique table/alias: '%s'", alias); |
There was a problem hiding this comment.
Is this exception consistent with the database?
There was a problem hiding this comment.
If yes, please update the exception document.
There was a problem hiding this comment.
Yes this Error is present in MySQL with MySQl error code 1066
and SQLState as 42000 so do I have to create this exception somewhere else
| import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; | ||
| import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.SyntaxSQLException; | ||
|
|
||
| public final class UniqueCommonTableExpressionException extends SyntaxSQLException { |
There was a problem hiding this comment.
Please add java doc for this class.
|
|
||
| private ReturningSegment returningSegment; | ||
|
|
||
| private WithSegment withSegment; |
There was a problem hiding this comment.
Can you provide the documentation for MySQL DELETE WITH ?
There was a problem hiding this comment.
For this class, you change the SQL parsing result, you need to add SQL Parser IT test to ensure that we handle withSegment
There was a problem hiding this comment.
Will make these changes once the logic for the CTE's Unique Alias Name is clear.
…RROR_MYSQL' into ISSUE_31437_WITH_KEYWORD_QUERY_ERROR_MYSQL
…with a different PR.
…RROR_MYSQL' into ISSUE_31437_WITH_KEYWORD_QUERY_ERROR_MYSQL
...ardingsphere/infra/exception/kernel/syntax/DuplicateCommonTableExpressionAliasException.java
Show resolved
Hide resolved
strongduanmu
left a comment
There was a problem hiding this comment.
Looks so great, thank you for your efforts on this PR, I believe the community will benefit from it.

Fixes #31437
Changes proposed in this pull request:
Added DuplicateCommonTableExpressionAliasException to support with keyword binding.
This Issue is solved by the update in Sql binder in PR - #34141
Added WithSegmentBinderTest
Added with clause test in SQLBinderIT
Before committing this PR, I'm sure that I have checked the following options:
./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.