-
Notifications
You must be signed in to change notification settings - Fork 477
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
base: main
Are you sure you want to change the base?
feat: add copy_grants to write_pandas #2050
Conversation
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
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") |
There was a problem hiding this comment.
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()
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. |
There was a problem hiding this comment.
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.
Please answer these questions before submitting your pull requests. Thanks!
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
Fill out the following pre-review checklist:
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.