Skip to content

[SPARK-55155] Fix SET CATALOG to use special chars and backticks in the identifier name#54076

Open
tangrizzly wants to merge 1 commit intoapache:masterfrom
tangrizzly:SPARK-55155-set-catalog-expression-fix-special-char
Open

[SPARK-55155] Fix SET CATALOG to use special chars and backticks in the identifier name#54076
tangrizzly wants to merge 1 commit intoapache:masterfrom
tangrizzly:SPARK-55155-set-catalog-expression-fix-special-char

Conversation

@tangrizzly
Copy link

@tangrizzly tangrizzly commented Jan 30, 2026

What changes were proposed in this pull request?

This PR fixes the handling of catalog names with special characters in the SET CATALOG command. The changes modify ResolveSetCatalogCommand to properly wrap identifier parts with backticks and escape any existing backticks by doubling them when converting SET CATALOG commands to string literals.

Why are the changes needed?

A previous change in #53941 extended the SET CATALOG command to accept foldable expressions. As part of that change, identifiers quoted with backticks are resolved to Literal("some-identifier") with the backticks stripped. This behavior breaks SET CATALOG when catalog names contain special characters such as %, @, -, $, #, or backticks.

This fix wraps identifiers in explicit backticks and escapes any existing backticks, ensuring the catalog names are resolved correctly during analysis.

Does this PR introduce any user-facing change?

Yes. Users can continue using SET CATALOG with catalog names that contain special characters when properly quoted with backticks:

SET CATALOG `te%s@t-c$a#t` -- works with special characters
SET CATALOG ``test`quote` -- works with backticks in the name

How was this patch tested?

DataSourceV2SQLSuite:

  • SET CATALOG with special characters with backticks in identifier
  • SET CATALOG with backtick character in identifier

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Sonnet 4.5 - claude-sonnet-4-5-20250929)

@github-actions
Copy link

github-actions bot commented Jan 30, 2026

JIRA Issue Information

=== Improvement SPARK-55155 ===
Summary: Support foldable expression for SET CATALOG
Assignee: Yuyuan Tang
Status: Resolved
Affected: ["4.2.0","4.1.2"]


This comment was automatically generated by GitHub Actions

@github-actions github-actions bot added the SQL label Jan 30, 2026
@tangrizzly tangrizzly changed the title init [SPARK-55155] Fix SET CATALOG to use special chars and backticks in the identifier name Jan 30, 2026
Copy link
Contributor

@dtenedor dtenedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix!

// Wrap each identifier part with backticks to handle special characters.
// Escape any existing backticks in the identifier name by doubling them.
Literal(nameParts.map { part =>
val escaped = part.replace("`", "``")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like similar functionality already exists in QuotingUtils.scala, can we consolidate?

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("`", "``") + "`"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants