Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize is_iceberg Field for Consistency in Snowflake with QUOTED_IDENTIFIERS_IGNORE_CASE #1229

Merged
merged 9 commits into from
Nov 10, 2024

Conversation

VersusFacit
Copy link
Contributor

@VersusFacit VersusFacit commented Nov 5, 2024

resolves #1227

Problem

In Snowflake, the QUOTED_IDENTIFIERS_IGNORE_CASE setting influences column names created by users, such as is_iceberg. However, this setting does not affect the column values returned by Snowflake’s SHOW OBJECTS query, creating inconsistency in how the is_iceberg field is referenced across different parts of the code.

When QUOTED_IDENTIFIERS_IGNORE_CASE is enabled, the is_iceberg column may appear in uppercase (IS_ICEBERG) in our homemade SHOW OBJECTS query, causing potential misalignment with the system table's always lowercase column names. This mismatch requires normalization to consistently refer to is_iceberg as a lowercase field name across Snowflake queries and Python processing, especially when working with adapters that handle Iceberg materializations.

Solution

Take 2: Removing quoting from the problem entirely and prove by hand that quoting in this metadata query doesn't matter one way or another.

I did so by hand and verified the test fails before the two fix lines are inserted.

just for fun, I did this with tdd: reproduce the failure/error, add the fix, go green!~~

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@VersusFacit VersusFacit self-assigned this Nov 5, 2024
@VersusFacit VersusFacit requested a review from a team as a code owner November 5, 2024 01:21
@cla-bot cla-bot bot added the cla:yes label Nov 5, 2024
Copy link
Contributor

github-actions bot commented Nov 5, 2024

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-snowflake contributing guide.

mikealfare
mikealfare previously approved these changes Nov 5, 2024
Copy link
Contributor

@mikealfare mikealfare left a comment

Choose a reason for hiding this comment

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

One sanity check, other wise it looks good. The failing CI is due to an expired token that we need to update.

dbt/adapters/snowflake/impl.py Show resolved Hide resolved
@VersusFacit VersusFacit dismissed mikealfare’s stale review November 5, 2024 06:37

I made a big chance to test things properly.

@adrianburusdbt
Copy link

adrianburusdbt commented Nov 5, 2024

@VersusFacit, there are a few other scenarios we need to consider as well, like this one: dbt-labs/dbt-core#4422
The way we handle QUOTED_IDENTIFIERS_IGNORE_CASE is again the culprit, so I think we should fix this issue throughout the adapter, not just for is_iceberg, i.e. normalize all column names.

mikealfare and others added 4 commits November 5, 2024 13:57
Use a session-only configuration.
Columns that unquoted are capitalized regardless of the quoting ignore flag. So we let it be uppercase and then normalize it down to lowercase in Python.
@@ -147,7 +149,7 @@
{# -- Gated for performance reason. If you don't want Iceberg, you shouldn't pay the
-- latency penalty. #}
{% if adapter.behavior.enable_iceberg_materializations.no_warn %}
select all_objects.*, is_iceberg as "is_iceberg"
select all_objects.*, is_iceberg
Copy link
Contributor Author

@VersusFacit VersusFacit Nov 6, 2024

Choose a reason for hiding this comment

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

I tested this by manually place QUOTED_IDENTIFIERS_IGNORE_CASE = true and QUOTED_IDENTIFIERS_IGNORE_CASE = false and then verifying it didn't matter. This is a more predictable way to handle metadata query column names.

Copy link
Contributor

@mikealfare mikealfare left a comment

Choose a reason for hiding this comment

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

Two comments suggesting docstring updates, but these are non-blocking.

dbt/include/snowflake/macros/adapters.sql Outdated Show resolved Hide resolved
@VersusFacit VersusFacit merged commit f6468f6 into main Nov 10, 2024
41 checks passed
@VersusFacit VersusFacit deleted the ADAP-1227/fix_iceberg_with_quoted_ignore_flag branch November 10, 2024 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants