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 into
sodadata: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 into
sodadata: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

@hirenkumar-n-dholariya
Copy link
Copy Markdown
Author

Hi @Niels-b @bmarinovic @tomassatka 👋

I've submitted this fix for issue #2483 where AWS Athena database/schema names containing hyphens (-) cause SQL query failures because they are not quoted in the table prefix.

The fix wraps the schema in double quotes in _create_table_prefix() so the generated SQL becomes "my-schema".my_table instead of my-schema.my_table.

All checks are passing!

Could someone please review when you get a chance? Happy to make any changes based on feedback. Thank you!

@hirenkumar-n-dholariya
Copy link
Copy Markdown
Author

Hi @bmarinovic @Niels-b

I hope you're doing well! I wanted to gently follow up on this PR which addresses the Athena query failure reported in issue #2483.

The fix is minimal - just wrapping the schema in double quotes in _create_table_prefix() so hyphenated database/schema names like "my-schema" are handled correctly in SQL queries.

I know your time is valuable and there are many things competing for your attention. Whenever this bubbles up in your queue, even a brief comment on whether the approach looks right with PR approval would mean a lot to me as a first-time contributor on this repo.

Thank you so much for your time!

@hirenkumar-n-dholariya
Copy link
Copy Markdown
Author

Hi @bmarinovic @tomassatka @Niels-b

Hope you are doing well!
Could you please review PR #2657 and give your approval/feedback to proceed.

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