This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/branch-1.9 by this push:
new 208c9ec04 [KYUUBI #6205] Backport SPARK-47300: quoteIfNeeded should
quote identifier starts with digits
208c9ec04 is described below
commit 208c9ec04e51c74eb40814e42f455c7833d09830
Author: Cheng Pan <[email protected]>
AuthorDate: Mon Mar 25 18:34:40 2024 +0800
[KYUUBI #6205] Backport SPARK-47300: quoteIfNeeded should quote identifier
starts with digits
# :mag: Description
The function is forked from Apache Spark, and we should align behavior with
upstream timely.
## Types of changes :bookmark:
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
## Test Plan ๐งช
Pass GA.
---
# Checklist ๐
- [x] This patch was not authored or co-authored using [Generative
Tooling](https://www.apache.org/legal/generative-tooling.html)
**Be nice. Be informative.**
Closes #6205 from pan3793/quoteIfNeeded.
Closes #6205
2e44fe757 [Cheng Pan] Backport SPARK-47300: quoteIfNeeded should quote
identifier starts with digits
Authored-by: Cheng Pan <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
(cherry picked from commit b73bf8802a32f0b731b21c752d7f96a57ee4770a)
Signed-off-by: Cheng Pan <[email protected]>
---
.../kyuubi/engine/spark/util/SparkCatalogUtils.scala | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/util/SparkCatalogUtils.scala
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/util/SparkCatalogUtils.scala
index b55319830..ff4564e54 100644
---
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/util/SparkCatalogUtils.scala
+++
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/util/SparkCatalogUtils.scala
@@ -377,14 +377,22 @@ object SparkCatalogUtils extends Logging {
// format: on
}
- /**
- * Forked from Apache Spark's
[[org.apache.spark.sql.catalyst.util.quoteIfNeeded]]
- */
+ // SPARK-47300 (4.0.0): quoteIfNeeded should quote identifier starts with
digits
+ private val validIdentPattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*")
+
+ // Forked from Apache Spark's
[[org.apache.spark.sql.catalyst.util.QuotingUtils.quoteIfNeeded]]
def quoteIfNeeded(part: String): String = {
- if (part.matches("[a-zA-Z0-9_]+") && !part.matches("\\d+")) {
+ if (validIdentPattern.matcher(part).matches()) {
part
} else {
- s"`${part.replace("`", "``")}`"
+ quoteIdentifier(part)
}
}
+
+ // Forked from Apache Spark's
[[org.apache.spark.sql.catalyst.util.QuotingUtils.quoteIdentifier]]
+ def quoteIdentifier(name: String): String = {
+ // Escapes back-ticks within the identifier name with double-back-ticks,
and then quote the
+ // identifier with back-ticks.
+ "`" + name.replace("`", "``") + "`"
+ }
}