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

Full update options for Delta Sharing shares, recipients, and providers #530

Merged
merged 4 commits into from
Aug 12, 2022

Conversation

wchau
Copy link
Contributor

@wchau wchau commented Aug 2, 2022

Added support for all updates to shares, recipients, and providers.
Allow option to either specify individual fields to update or JSON.

Tested locally.

@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2022

Codecov Report

Merging #530 (0394144) into main (ef918f1) will decrease coverage by 0.42%.
The diff coverage is 1.69%.

@@            Coverage Diff             @@
##             main     #530      +/-   ##
==========================================
- Coverage   60.72%   60.29%   -0.43%     
==========================================
  Files          55       55              
  Lines        4692     4727      +35     
==========================================
+ Hits         2849     2850       +1     
- Misses       1843     1877      +34     
Impacted Files Coverage Δ
databricks_cli/unity_catalog/api.py 0.00% <0.00%> (ø)
databricks_cli/unity_catalog/delta_sharing_cli.py 0.00% <0.00%> (ø)
databricks_cli/unity_catalog/uc_service.py 0.00% <0.00%> (ø)
databricks_cli/utils.py 86.45% <20.00%> (-3.66%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@adamcain-db adamcain-db left a comment

Choose a reason for hiding this comment

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

Basically LGTM. Just a couple questions.

if recipient_profile is not None:
_data['recipient_profile_str'] = mc_pretty_format(recipient_profile)
if comment is not None:
_data['comment'] = comment
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we keeping the new_name, comment, recipient_profile args for backward compatibility (in case other apps call this function)? Looks like our CLI code only calls it with provider_spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The API is "public", so the test has been complaining about backwards incompatibility. This is to maintain the existing API.

updates = []
for a in add_table:
updates.append({'action': 'ADD', 'data_object': shared_data_object(a)})
for r in remove_table:
updates.append({'action': 'REMOVE', 'data_object': shared_data_object(r)})
d = {'updates': updates}
share_json = UnityCatalogApi(api_client).update_share(name, d)
data = {'name': new_name, 'comment': comment, 'owner': owner, 'updates': updates}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should filter out keys that have value None. Probably not needed now, since the server won't see those fields defined. We'll need to revisit this once the UC 'update' APIs allow clearing fields (with FieldMasks or whatever).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we can do that later, since all the other APIs do something similar along the lines.

Copy link
Contributor

@adamcain-db adamcain-db left a comment

Choose a reason for hiding this comment

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

LGTM. Might want to wait til @pietern or team member can have a look before merging.

@@ -188,7 +197,7 @@ def delete_share_cli(api_client, name):
@click.option('--allowed_ip_address', default=None, required=False, multiple=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

@wchau Could you change this to use dashes to be consistent with everything else and check if other commands use the same? We shouldn't end up in a situation where folks depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

help='Free-form text description.')
@click.option('--owner', default=None, required=False,
help='Owner of the recipient.')
@click.option('--allowed_ip_address', default=None, required=False, multiple=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


def merge_dicts(*dicts):
"""
Merges dicts throw shallow copy.
Copy link
Contributor

Choose a reason for hiding this comment

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

*through

Please rename this to merge_dicts_shallow to reflect the shallow nature at the call site.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this function at all, per the other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per other comment

name,
provider_spec=merge_dicts(
data,
{'recipient_profile_str': mc_pretty_format(profile_json)})),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can just set the recipient_profile_str key prior to this call. No need for a merge_dicts call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't set this easily without a nested def because it's scoped within a lambda function. With merge_dicts_shallow, it can be reused in the future in a easier fashion.

@wchau wchau requested a review from pietern August 11, 2022 20:49
Copy link
Contributor

@pietern pietern left a comment

Choose a reason for hiding this comment

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

Thanks for the update. Please consider addressing the concern w.r.t. --allowed-ip-address in the update operation in a follow up PR. No need to block a release for this to be addressed.

help=(
'IP address in CIDR notation that is allowed to use delta sharing '
'(can be specified multiple times). Specify a single empty string to disable '
'IP allowlist.'))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bad API, IMO. If the intent is to clear the allowed IP addresses field to delete them, there should be a dedicated option, e.g. --clear-allowed-ip-addresses to do so. Using a magic empty string can lead to incorrect usage where the list is cleared accidentally (e.g. bad interpolation in a script).

@pietern pietern merged commit 136e429 into databricks:main Aug 12, 2022
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.

4 participants