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

feat: add copy_grants to write_pandas #2050

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

surpatean
Copy link

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1658882: Please provide the option to copy grants when overwriting table using write_pandas #2049

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    Replaces the DROP + RENAME logic into a REPLACE logic, which I believe is anyways better because it is an atomic statement.
    Adds COPY GRANTS if copy_grants is True.

Copy link

github-actions bot commented Sep 10, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@surpatean
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Comment on lines -447 to +467
drop_object(original_table_location, "table")
rename_table_sql = f"ALTER TABLE {target_table_location} RENAME TO {original_table_location} /* Python:snowflake.connector.pandas_tools.write_pandas() */"
logger.debug(f"rename table with '{rename_table_sql}'")
cursor.execute(rename_table_sql, _is_internal=True)
clone_table_sql = (
f"CREATE OR REPLACE TABLE {original_table_location} "
f"CLONE {target_table_location} "
f"{'COPY GRANTS' if copy_grants else ''}"
f" /* Python:snowflake.connector.pandas_tools.write_pandas() */ "
)
logger.debug(f"clone table with '{clone_table_sql}'")
cursor.execute(clone_table_sql, _is_internal=True)
drop_object(target_table_location, "table")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be a breaking change since not all users my have create table privileges. Can you refactor the code like so

if clone_table_sql:
    clone_table_sql = "create or replace ..."
    logger.debug()
    cursor.execute()
    drop_object()
else:
    rename_table_sql = "alter table ..."
    logger.debug()
    cursor.execute()

Comment on lines +249 to +251
copy_grants: When true and when both overwrite is true and auto_create_table is true, the grants of the table
being overwritten will be copied to the new table. Otherwise, the new table will be created with only the
default/future grants defined on the schema/database.
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add the fact that create table privileges are required with this option.

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.

SNOW-1658882: Please provide the option to copy grants when overwriting table using write_pandas
2 participants