Skip to content

[BUG] getPrimaryKeys fails when catalog, schema or table name contains backtick #1471

@vadym-janea

Description

@vadym-janea

Describe the bug
When not in thrift mode, DatabaseMetaData#getPrimaryKeys fails when catalog, schema, or table identifiers contain backtick

To Reproduce
Call DatabaseMetaData#getPrimaryKeys on the table which either has name with backtick, or belongs to catalog or schema with backtick in name

Expected behavior
Call should not fail and should return table's primary keys

Client side logs

[PARSE_SYNTAX_ERROR] org.apache.spark.sql.catalyst.parser.ParseException: 
[PARSE_SYNTAX_ERROR] Syntax error at or near 'table_with'. SQLSTATE: 42601 (line 1, pos 79)

== SQL ==
SHOW KEYS IN CATALOG `my_workspace` IN SCHEMA `default` IN TABLE `test`table_with'special"chars`
-----------------------------------------------------------------------^^^

Client Environment

  • OS: Ubuntu 25.10
  • Java version: Java 21
  • Java vendor: OpenJDK
  • Driver Version: 3.4.1

Additional context
Issue is presumably in com.databricks.jdbc.dbclient.impl.sqlexec.CommandBuilder#fetchPrimaryKeysSQL which constructs the query like this

return String.format(SHOW_PRIMARY_KEYS_SQL, catalogName, schemaName, tableName);

where SHOW_PRIMARY_KEYS_SQL is declared as

  public static final String SHOW_PRIMARY_KEYS_SQL =
      "SHOW KEYS" + IN_CATALOG_SQL + IN_ABSOLUTE_SCHEMA_SQL + IN_ABSOLUTE_TABLE_SQL;

which evaluates to

SHOW KEYS IN CATALOG `%s` IN SCHEMA `%s` IN TABLE `%s`

The same issue affects multiple commands constructed in CommandBuilder.

This issue is supposedly present in earlier versions of driver as well, however starting from 3.4.1 thrift mode seem to be off by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions