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

Fixes issue (127) where append_date_dirs wasn't working properly. #130

Merged
merged 1 commit into from Mar 31, 2022

Conversation

pbattaglia
Copy link
Collaborator

  • Fixed bug where partition_keys was being modified in-place, and causing problems laters.

  • Adjusted how target_path is constructed so that trailing forward slashes in target_path are all removed.

  • Added typing.cast to comply with pytype. I'm not sure why this wasn't triggered previously, but I was getting pytype errors from the prepare_target_name() function, which I was editing, so I fixed it in this PR.

Comment on lines 331 to 334
try:
target_path = t.cast(str, params['target_path'])
except KeyError:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

A more conventional method we use in our codebase is to call get with a default value. Would something like:

target_path = t.cast(str, params.get('target_path', ''))

work here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep that should be fine. Updating the PR

* Fixed bug where partition_keys was being modified in-place, and causing problems laters.

* Adjusted how target_path is constructed so that trailing forward slashes in target_path are all removed.

* Added typing.cast to comply with pytype.
Copy link
Collaborator

@alxmrs alxmrs left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

if str(params.get('target_path')).endswith('/'):
params['target_path'] = params.get('target_path')[:-1]
target_path = t.cast(str, params.get('target_path', ''))
if target_path != '':
Copy link
Collaborator

Choose a reason for hiding this comment

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

One last nit: It this if statement necessary? I think rstrip on an empty string will produce an empty string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, but I added it because you don't want to add a key to the dict if it doesn't already have it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Though, generally, I'm not actually sure why this is located here, because it seems like it'd be more natural to handle it in prepare_target_name().

On a similar note, I think subtracting 1 from num_partition_keys here, but actually removing the "date" partition key in prepare_target_name(), might be a little risky. Could they be done in the same place?

Copy link
Collaborator

@alxmrs alxmrs Mar 29, 2022

Choose a reason for hiding this comment

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

Right, but I added it because you don't want to add a key to the dict if it doesn't already have it.

Ah, that makes sense.

it seems like it'd be more natural to handle it in prepare_target_name().

I agree – this would be a better fit: It'd be best if the parser had less logic, in general.

Could they be done in the same place?

Yes, that totally sounds right to me.

Last: I think we are no longer using the num_partition_keys counter anymore. It would be prudent to pull that out.

@alxmrs alxmrs merged commit ecb194c into google:main Mar 31, 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.

None yet

2 participants