[BUG] SEA metadata SHOW ... LIKE under-escapes backslashes; schema/table names containing '\' never match

Aperta Adatta ai principianti
#1,598 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@gibkim ci sta già lavorando.

Dal 5/11/2026.

  • #1765 di @gibkim — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
database

Direzione di ricerca

Iniziate in CommandBuilder.java, in corrispondenza delle chiamate a jdbcPatternToHive alle righe 52, 58 e 64, quindi esaminate i punti di interpolazione di LIKE_SQL, SCHEMA_LIKE_SQL e TABLE_LIKE_SQL indicati nell’issue. Riproducete la ricerca dei metadati SEA con un nome di schema o di tabella contenente una barra rovesciata letterale e confermate che tutte le chiamate ai metadati interessate la restituiscano con l’escaping SQL corretto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

The SEA (Statement Execution API) metadata path under-escapes backslashes when
building SHOW ... LIKE '<pattern>', so a schema/table/column whose name
literally contains a backslash can never be matched via getSchemas /
getTables / getColumns. Escaping the pattern with the JDBC escape char does
not help.

Root cause

CommandBuilder sets the pattern via WildcardUtil.jdbcPatternToHive(pattern)
(CommandBuilder.java:52/58/64) and then interpolates the result directly into
" LIKE '%s'" (LIKE_SQL, CommandBuilder.java:93/113/116/136/144). Only the
catalog identifier is escaped (escapeSqlIdentifier); the LIKE pattern value is not.

The glob is embedded in a single-quoted SQL string literal, so on the server
the SQL string-literal parser consumes one backslash layer before the
SHOW ... LIKE matcher (a regex; StringUtils.filterPattern, only *→.*
substituted) sees the pattern. jdbcPatternToHive emits \\ for an escaped
backslash, but that becomes a single \ after the string-literal parse, which the
regex then consumes as an escape — so the literal backslash is lost and nothing matches.

To match a literal backslash the LIKE string needs the backslash quadrupled
(survives string-literal halving → then regex halving); the driver only doubles it.

To Reproduce

  1. Create a schema whose name contains a backslash:
    CREATE SCHEMA `some_catalog`.`a\b`;
    
  2. Connect with the SEA path (e.g. usethriftclient=0 / SEA-enabled connection).
  3. Call connection.getMetaData().getSchemas("some_catalog", "a\\b") (JDBC pattern
    a\b — a literal backslash escaped for Java is "a\\b").

Expected behavior

Returns the schema a\b.

Actual behavior

Returns an empty result set. The driver emits
SHOW SCHEMAS IN some_catalog LIKE 'a\\b'; after the server's string-literal
parse this becomes regex a\b where \b is a word boundary, so nothing matches.
(Correct SQL would be LIKE 'a\\\\b'.)

Direct SQL confirmation (same warehouse, run manually):

  • SHOW SCHEMAS IN <cat> LIKE 'a\\b' → [] (what the driver sends today)
  • SHOW SCHEMAS IN <cat> LIKE 'a\\\\b' → a\b (correct — 4 backslashes)

Suggested fix

Escape backslashes for the SQL string literal at the LIKE '%s' interpolation
(e.g. schemaPattern.replace("\\", "\\\\") after jdbcPatternToHive), leaving
jdbcPatternToHive itself unchanged. Apply to all LIKE_SQL / SCHEMA_LIKE_SQL
/ TABLE_LIKE_SQL sites in CommandBuilder.

Additional context

Found while aligning the ADBC C# Databricks driver's SEA metadata behavior; ADBC
shares the identical jdbcPatternToHive→LIKE '%s' construction and had the same
bug. Verified live against schemas named a_b, a\b, a\_b, a\\b. Backslashes
in identifiers are rare, so real-world impact is low, but the SEA vs Thrift behavior
differs here (Thrift has its own separate server-side exact-match issue with
backslash names). Filing for parity/tracking.

  • Driver Version: main (SEA metadata path)
Lingua principale
Java
Stelle
41
Fork
49
Merge medio
1g 7h
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di databricks/databricks-jdbc

Tutte le issue di databricks/databricks-jdbc

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.