apache / apache/shardingsphere

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

Open
#18,697 7 comments 0 reactions 1 assignee Claimed by @chakkk309 View on GitHub
good amateur issue in: SQL parse
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 35m
Merged PRs (30d)
326

Description

## 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:

```
:31, IdentifierValue (org.apache.shardingsphere.sql.parser.sql.common.value.identifier)
: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).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.