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

Please add unsafe_alters to output comments when building table CTAS statement #141

Open
JohnL4 opened this issue Nov 6, 2024 · 1 comment

Comments

@JohnL4
Copy link

JohnL4 commented Nov 6, 2024

Is your feature request related to a problem? Please describe.
I'm still using snowddl-convert/singledb plan to generate sql to update a target Snowflake d/b to match our git repo. One of the problems I'm trying to solve is detecting when a CTAS statement implicitly drops a column, so I can flag the generated plan sql for human review/approval. It looks like, within TableResolver.compare_object() there is a variable, unsafe_alters that records the columns that are getting dropped (and probably some other stuff, too). It would make my problem case (column implicitly dropped by CTAS) easier to detect if the contents of that variable were emitted as a comment (ideally, one item per line), the same as replace_reasons.

Describe the solution you'd like
This, or something like it:

        if replace_reasons:
            replace_query = "\n".join(f"-- {r}" for r in replace_reasons) \
                + "\n" + "\n".join( f"-- {a}" for a in unsafe_alters) \                <------------------------- this
                + "\n" + str(self._build_create_table(bp, snow_cols))

Describe alternatives you've considered
Could detect CTAS in generated plan and issue my own sql query for DESC TABLE, but it's already happening in snowddl, and getting parsed and processed the same way I would.

Could also make the above change in my own local version of snowddl, but that would require an internal fork and following snowddl version updates.

Additional context
None.

@littleK0i
Copy link
Owner

In theory, we may add SQL comments about removed columns between column list and FROM.

CREATE OR REPLACE TABLE abc (...)
AS
SELECT col1
    , col2
    , col3
    -- col4 was removed
    -- col5 was removed
FROM abc

Showing everything is probably an overkill, since actual review should happen in Git for most users.

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

No branches or pull requests

2 participants