Repository navigation
Escape underscore wildcard in catalog names for Thrift metadata RPCs - #1261
Conversation
Thrift metadata RPCs treat catalog names as patterns, so `_` is interpreted as a single-character wildcard. This causes incorrect matches (e.g. `my_catalog` matching `mycatalog`). Add a TreatMetadataCatalogNameAsPattern connection property (default false) that escapes unescaped `_` in catalog names before passing them to Thrift requests. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gopal Lal <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gopal Lal <[email protected]>
…entifiers) Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gopal Lal <[email protected]>
|
please remove NO_CHANGELOG=true from description |
| ### Added | ||
| - Added connection property `OAuthWebServerTimeout` to configure the OAuth browser authentication timeout for U2M (user-to-machine) flows, and also updated hardcoded 1-hour timeout to default 120 seconds timeout. | ||
| - Added connection property `UseQueryForMetadata` to use SQL SHOW commands instead of Thrift RPCs for metadata operations (getCatalogs, getSchemas, getTables, getColumns, getFunctions). This fixes incorrect wildcard matching where `_` was treated as a single-character wildcard in Thrift metadata pattern filters. | ||
| - Added connection property `TreatMetadataCatalogNameAsPattern` to control whether catalog names are treated as patterns in Thrift metadata RPCs. When disabled (default), unescaped `_` in catalog names is escaped to prevent single-character wildcard matching. |
There was a problem hiding this comment.
can we also add expectations wrt jdbc spec in this message
| * @param catalogName the catalog name to escape | ||
| * @return the escaped catalog name, or {@code null} if the input is {@code null} | ||
| */ | ||
| public static String escapeCatalogName(String catalogName) { |
There was a problem hiding this comment.
should we also escape %, if not why? we should document, if we chose not to
There was a problem hiding this comment.
We are escaping "_" as it is a very common character in resource names, and users don't escape this due to lack of awareness, and this affects unintended latency majority of such cases. But "%" is not a common character in resource-names.
There was a problem hiding this comment.
why is the escaping not added to listPrimaryKeys, listImportedKeys, listExportedKeys, listCrossReferences?
There was a problem hiding this comment.
In implementation for these, they are not treated as pattern. I wanted to limit the change to minimal required.
| } | ||
| builder.append(ch); | ||
| } | ||
| return builder.toString(); |
There was a problem hiding this comment.
we can use regex here, llm suggests:
public static String escapeCatalogName(String catalogName) {
if (catalogName == null) {
return null;
}
// Escape unescaped underscores: match '_' not preceded by '\'
return catalogName.replaceAll("(?<!\\\\)_", "\\\\_");
}
There was a problem hiding this comment.
Loop is still better as it differentiates between _ and \_.
Summary
_is interpreted as a single-character wildcard. This causesmy_catalogto incorrectly matchmycatalog,my1catalog, etc.TreatMetadataCatalogNameAsPatternconnection property (defaultfalse). When disabled, unescaped_in catalog names are escaped with\before passing to Thrift requests.listSchemas,listTables,listColumns,listFunctions(Thrift RPC path)Test plan
WildcardUtil.escapeCatalogName()(null, no wildcards, single/multiple underscores, already-escaped, percent left unchanged)DatabricksThriftServiceClientTest: verifylistSchemasescapes catalog by default, does not escape when property istrue, andlistCrossReferencesescapes both parent and foreign catalogs_in its nameNO_CHANGELOG=true
🤖 Generated with Claude Code