[SPARK-17832][SQL] TableIdentifier.quotedString creates un-parseable names when name contains a backtick#15403
[SPARK-17832][SQL] TableIdentifier.quotedString creates un-parseable names when name contains a backtick#15403jiangxb1987 wants to merge 3 commits into
Conversation
|
Besides, we have similar problem in |
|
Test build #66576 has finished for PR 15403 at commit
|
| } | ||
|
|
||
| def unquotedString: String = { | ||
| if (database.isDefined) s"${database.get}.$identifier" else identifier |
There was a problem hiding this comment.
I think we should keep unquotedString this as it is. That gives some a more readable (less parseable) version of the identifier. I just added an example with unquotedIdentifier to show that there was no way to get a parseable string from the table identifier.
|
|
||
| test("SPARK-17832 table identifier - contains backtick") { | ||
| val complexName = TableIdentifier("`weird`table`name", Some("`d`b`1")) | ||
| assert(TableIdentifier("`weird`table`name", Some("`d`b`1")) === |
There was a problem hiding this comment.
Use complexName? Why create the identifier twice?
|
@jiangxb1987 This looks pretty good. What is the problem |
|
@hvanhovell nvm about the |
|
Test build #66596 has finished for PR 15403 at commit
|
|
LGTM - merging to master/2.0. Thanks! |
…names when name contains a backtick
## What changes were proposed in this pull request?
The `quotedString` method in `TableIdentifier` and `FunctionIdentifier` produce an illegal (un-parseable) name when the name contains a backtick. For example:
```
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser._
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
val complexName = TableIdentifier("`weird`table`name", Some("`d`b`1"))
parseTableIdentifier(complexName.unquotedString) // Does not work
parseTableIdentifier(complexName.quotedString) // Does not work
parseExpression(complexName.unquotedString) // Does not work
parseExpression(complexName.quotedString) // Does not work
```
We should handle the backtick properly to make `quotedString` parseable.
## How was this patch tested?
Add new testcases in `TableIdentifierParserSuite` and `ExpressionParserSuite`.
Author: jiangxingbo <jiangxb1987@gmail.com>
Closes #15403 from jiangxb1987/backtick.
(cherry picked from commit 26fbca4)
Signed-off-by: Herman van Hovell <hvanhovell@databricks.com>
…names when name contains a backtick
## What changes were proposed in this pull request?
The `quotedString` method in `TableIdentifier` and `FunctionIdentifier` produce an illegal (un-parseable) name when the name contains a backtick. For example:
```
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser._
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
val complexName = TableIdentifier("`weird`table`name", Some("`d`b`1"))
parseTableIdentifier(complexName.unquotedString) // Does not work
parseTableIdentifier(complexName.quotedString) // Does not work
parseExpression(complexName.unquotedString) // Does not work
parseExpression(complexName.quotedString) // Does not work
```
We should handle the backtick properly to make `quotedString` parseable.
## How was this patch tested?
Add new testcases in `TableIdentifierParserSuite` and `ExpressionParserSuite`.
Author: jiangxingbo <jiangxb1987@gmail.com>
Closes apache#15403 from jiangxb1987/backtick.
What changes were proposed in this pull request?
The
quotedStringmethod inTableIdentifierandFunctionIdentifierproduce an illegal (un-parseable) name when the name contains a backtick. For example:We should handle the backtick properly to make
quotedStringparseable.How was this patch tested?
Add new testcases in
TableIdentifierParserSuiteandExpressionParserSuite.