-
Notifications
You must be signed in to change notification settings - Fork 17.2k
Validate Hive Beeline parameters #29502
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it make sense to push this validation to the constructor? The Connection object is retrieved there as well as determining the
use_beelineattr. Could fail faster before even executing the task. WDYT?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.
hmm, didn't notice maybe makes sense here since we have conn in
__init__.Not related to changes in this PR but should we think of moving
self.get_connection(hive_cli_conn_id)call outside__init__otherwise it will make a db call to get conn whenever dag parsing will happen?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.
The db call would only happen if an operator using this hook constructed the hook in its
__init__. There is almost an instance of that in the HiveOperator, but it's to setup lazy loading the hook and make it an instance attr.But yes, ideally the constructors of hooks, operators, sensor, etc. don't make any external calls
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.
Additionally, If you initialize connection in init you cannot make connection_id templated - even if you extend the operator.
While I used to think the same @josh-fell that early validation helps to surface such problems earlier, I think It has evolved and I am now of an opinion that constructors in our operators should just assign fields. Full stop.
And in the past (cannot find it easily) @uranusjr proposed that we get rid of explicit constructor and turn all our operators in 'dataclasses' https://peps.python.org/pep-0557/ - where you have only fields declared and all the init boilerplate is generated.
And I tend to agree that would be a good idea.
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.
I agree that we need to avoid anything which might cause call to Airflow DB or any other resource.
There is situation when hook initialised in operator not lazily and even expected as one of argument:
SSHHook and SSHOperator
Also I agree that operator should only allow fields declared however even if I'am a fan of dataclasses there is couple of issues exists:
__post_init__, there will be temptation to use it.@dataclassotherwise it turned into the regular class with part of dataclass 🙄Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, same. I guess I figured since this was a hook, we're not moving the connection call out, and it's currently not going to get called in an operator, why not push up the validation? But I see it was misguided suggestion.
I would be over the moon if this was the implementation or
attrs; the latter has been life changing. It's a shame you can't build an operator now, with any real added value in simplication, withattrsbecause of the metaclass logic going on. Alas, I would love this.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.
I share the sentiment :)