-
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
Issue 31437 with keyword query error mysql #34163
Issue 31437 with keyword query error mysql #34163
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this check happen in MySQL? If yes, please provide MySQL test results.
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.
...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
@@ -47,6 +49,8 @@ public final class SQLStatementBinderContext { | |||
|
|||
private final SQLStatement sqlStatement; | |||
|
|||
private final Set<CaseInsensitiveString> commonTableExpressionsSegmentsUniqueAliases = new HashSet<>(); |
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 Collection<CaseInsensitiveString>
to replace Set<CaseInsensitiveString>
.
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.
Besides, dou you think CaseInsensitiveSet is better?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this exception consistent with the database?
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 yes, please update the exception document.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add java doc for this class.
@@ -38,6 +39,8 @@ public final class MySQLDeleteStatement extends DeleteStatement implements MySQL | |||
|
|||
private ReturningSegment returningSegment; | |||
|
|||
private WithSegment withSegment; |
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.
Can you provide the documentation for MySQL DELETE WITH ?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
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
.