Skip to content

fix(athena): quote schema/database identifiers in table prefix to handle hyphenated names#2657

Open
hirenkumar-n-dholariya wants to merge 1 commit intosodadata:v3from
hirenkumar-n-dholariya:patch-2
Open

fix(athena): quote schema/database identifiers in table prefix to handle hyphenated names#2657
hirenkumar-n-dholariya wants to merge 1 commit intosodadata:v3from
hirenkumar-n-dholariya:patch-2

Conversation

@hirenkumar-n-dholariya
Copy link
Copy Markdown

Problem

AWS Athena database and schema names can contain hyphen (-) characters.
The current code returns self.schema unquoted in _create_table_prefix(),
causing SQL query failures when hyphens are present:

SELECT * FROM my-schema.my_table ← SQL engine misreads the hyphen

Root Cause

In data_source.py, the _create_table_prefix() method returns:

return self.schema

This bare, unquoted value is then used directly in qualified_table_name() to build SQL strings, with no protection against special characters.

Fix

Wrap the schema in double quotes:

if self.schema:
return f'"{self.schema}"'
return None

This produces valid SQL: SELECT * FROM "my-schema".my_table

Impact

  • Fixes query failures for Athena databases/schemas with hyphens
  • No breaking change for normal names without special characters
  • Double quoting is standard SQL and supported by Athena

References

…ted names (sodadata#2483)

Database and schema names in AWS Athena can contain hyphen (-) characters. Without quoting, these names are misinterpreted by the SQL query engine, causing query failures.

The _create_table_prefix() method was returning self.schema unquoted, which meant any schema or database name with special characters like hyphens would produce invalid SQL.

Fix: wrap the schema in double quotes in _create_table_prefix() so
the generated SQL becomes: 
SELECT * FROM "my-schema".my_table

Fixes sodadata#2483
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant