apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
20k stars 6.76k forks source link

When multiple back quotation marks are used as a table name, the back quotation marks will be removed all #18697

Open FlyingZC opened 2 years ago

FlyingZC commented 2 years ago

Bug Report

Which version of ShardingSphere did you use?

master

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

keep correct quotation marks.

Actual behavior

When I want to support create table sql with multiple back quotes, like CREATE TABLE ```ab````cd``` (i INT);,the table name is resolved to abcd.

Reason analyze (If you can)

org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue#IdentifierValue(java.lang.String) uses the method org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil#getExactlyValue(java.lang.String) to handle table name,this method removes all back quotes.

Before:

image

After:

image

The execution result of this sql in mysql:

image

StackTrace:

<init>:31, IdentifierValue (org.apache.shardingsphere.sql.parser.sql.common.value.identifier)
<init>:41, IdentifierValue (org.apache.shardingsphere.sql.parser.sql.common.value.identifier)
visitTableName:322, MySQLStatementSQLVisitor (org.apache.shardingsphere.sql.parser.mysql.visitor.statement.impl)
visitTableName:223, MySQLStatementSQLVisitor (org.apache.shardingsphere.sql.parser.mysql.visitor.statement.impl)
accept:31379, MySQLStatementParser$TableNameContext (org.apache.shardingsphere.sql.parser.autogen)
visit:18, AbstractParseTreeVisitor (org.antlr.v4.runtime.tree)
visitCreateTable:238, MySQLDDLStatementSQLVisitor (org.apache.shardingsphere.sql.parser.mysql.visitor.statement.impl)
visitCreateTable:182, MySQLDDLStatementSQLVisitor (org.apache.shardingsphere.sql.parser.mysql.visitor.statement.impl)
accept:1931, MySQLStatementParser$CreateTableContext (org.apache.shardingsphere.sql.parser.autogen)
visit:55, SQLVisitorEngine (org.apache.shardingsphere.sql.parser.api)
parseSQLStatement:78, SQLParserParameterizedTest (org.apache.shardingsphere.test.sql.parser.parameterized.engine)
assertSupportedSQL:72, SQLParserParameterizedTest (org.apache.shardingsphere.test.sql.parser.parameterized.engine)
invoke:-1, GeneratedMethodAccessor5 (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
runReflectiveCall:50, FrameworkMethod$1 (org.junit.runners.model)
run:12, ReflectiveCallable (org.junit.internal.runners.model)
invokeExplosively:47, FrameworkMethod (org.junit.runners.model)
evaluate:17, InvokeMethod (org.junit.internal.runners.statements)
runLeaf:325, ParentRunner (org.junit.runners)
runChild:78, BlockJUnit4ClassRunner (org.junit.runners)
runChild:57, BlockJUnit4ClassRunner (org.junit.runners)
run:290, ParentRunner$3 (org.junit.runners)
schedule:71, ParentRunner$1 (org.junit.runners)
runChildren:288, ParentRunner (org.junit.runners)
access$000:58, ParentRunner (org.junit.runners)
evaluate:268, ParentRunner$2 (org.junit.runners)
run:363, ParentRunner (org.junit.runners)
runChild:128, Suite (org.junit.runners)
runChild:27, Suite (org.junit.runners)
run:290, ParentRunner$3 (org.junit.runners)
schedule:71, ParentRunner$1 (org.junit.runners)
runChildren:288, ParentRunner (org.junit.runners)
access$000:58, ParentRunner (org.junit.runners)
evaluate:268, ParentRunner$2 (org.junit.runners)
run:363, ParentRunner (org.junit.runners)
run:137, JUnitCore (org.junit.runner)
startRunnerWithArgs:69, JUnit4IdeaTestRunner (com.intellij.junit4)
execute:38, IdeaTestRunner$Repeater$1 (com.intellij.rt.junit)
repeat:11, TestsRepeater (com.intellij.rt.execution.junit)
startRunnerWithArgs:35, IdeaTestRunner$Repeater (com.intellij.rt.junit)
prepareStreamsAndStart:235, JUnitStarter (com.intellij.rt.junit)
main:54, JUnitStarter (com.intellij.rt.junit)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

terrymanu commented 2 years ago

It looks like not very important issue, I just set it as good amateur issue. Please feel free to pick up this issue if anybody interest it.

chakkk309 commented 2 years ago

Hi, I want to try it.

strongduanmu commented 2 years ago

@chakkk309 Welcome, I will assign this issue to you.

github-actions[bot] commented 2 years ago

Hello , this issue has not received a reply for several days. This issue is supposed to be closed.

RaigorJiang commented 1 year ago

Hi @chakkk309 , Is there an update?

chakkk309 commented 1 year ago

Hi @chakkk309 , Is there an update?

Not yet, please feel free to pick it up.

RaigorJiang commented 1 year ago

Not yet, please feel free to pick it up.

OK, thank you!