Skip to content

Conversation

@eric-wang-1990
Copy link
Contributor

Add support for escaping underscores in metadata queries

Why

For current Power BI ODBC connection we are escaping all the underscore. I've thinking about change in the connector side to always pass in the escaped name, but it is not feasible since later we will introduce sql text based metadata query like DESCRIBE TABLE xxx as json, where we would expect xxx not be escaped since it will be treated as text.
Thus the best way is to introduce a new parameter in the metadata api to specify whether the client want to escape the underscore, then on the driver side based on different calling method(Thrift API or sql text) we can perform differently.

Description

This PR adds support for escaping underscores in metadata query parameters through a new parameter adbc.get_metadata.escape_underscore. When enabled, underscores in catalog, schema, table, and column names will be treated as literal characters rather than SQL wildcards.

Changes

  • Added new parameter EscapeUnderscore to control underscore escaping behavior
  • Added EscapeUnderscoreInName helper method to handle underscore escaping
  • Updated all metadata query methods to use the escaping functionality:
    • GetCatalogsAsync
    • GetSchemasAsync
    • GetTablesAsync
    • GetColumnsAsync
    • GetPrimaryKeysAsync
    • GetCrossReferenceAsync
    • GetCrossReferenceAsForeignTableAsync

Testing

  • Added test case in CanGetColumnsExtended to verify the escaping functionality
  • Verified that null values are handled correctly
  • Verified that escaping only occurs when the flag is enabled

Usage

To enable underscore escaping, set the parameter:

statement.SetOption(ApacheParameters.EscapeUnderscore, "true");

Impact

This change allows users to query metadata for objects that contain underscores in their names without the underscore being interpreted as a SQL wildcard character.

@github-actions github-actions bot added this to the ADBC Libraries 19 milestone Jun 4, 2025
@eric-wang-1990 eric-wang-1990 changed the title add escape underscore parameter feat(csharp/src/Drivers/Databricks): Add escape underscore parameter to metadata command Jun 4, 2025
@eric-wang-1990 eric-wang-1990 changed the title feat(csharp/src/Drivers/Databricks): Add escape underscore parameter to metadata command feat(csharp/src/Drivers/Apache): Add escape underscore parameter to metadata command Jun 4, 2025
Copy link
Contributor

@CurtHagenlocher CurtHagenlocher left a comment

Choose a reason for hiding this comment

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

Thanks! Is it only the underscore that needs escaping or would a percent sign also need it? If the answer is "no", I'll commit the change.

@eric-wang-1990
Copy link
Contributor Author

Thanks! Is it only the underscore that needs escaping or would a percent sign also need it? If the answer is "no", I'll commit the change.

Nope, if it needs it we need to introduce a new flag, but currently no for power bi odbc.

@CurtHagenlocher CurtHagenlocher merged commit 1914020 into apache:main Jun 5, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants