-
Notifications
You must be signed in to change notification settings - Fork 18
Adding support for LAST function #3
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
Open
sdcooke
wants to merge
1
commit into
alangpierce:master
Choose a base branch
from
mixcloud:last-function
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -558,6 +558,24 @@ def _evaluate(self, num_rows, column): | |
| values=values) | ||
|
|
||
|
|
||
| class LastFunction(AggregateFunction): | ||
| def check_types(self, rep_list_type): | ||
| return rep_list_type | ||
|
|
||
| def _evaluate(self, num_rows, column): | ||
| values = [] | ||
| if len(column.values) == 0: | ||
| values = [None] | ||
|
|
||
| if column.mode == tq_modes.REPEATED: | ||
| values = [repeated_row[-1] if len(repeated_row) > 0 else None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, looking at this code it looks like the returned value can have NULL's in it if the row is empty. Does this match what bigquery does? The documentation doesn't seem to say. It would be great if you could have a test-case for that as well. |
||
| for repeated_row in column.values] | ||
| else: | ||
| values = [column.values[-1]] | ||
| return context.Column(type=column.type, mode=tq_modes.NULLABLE, | ||
| values=values) | ||
|
|
||
|
|
||
| class NoArgFunction(ScalarFunction): | ||
| def __init__(self, func, return_type=tq_types.INT): | ||
| self.func = func | ||
|
|
@@ -1304,7 +1322,8 @@ def _evaluate(self, num_rows, json_expressions, json_paths): | |
| 'count_distinct': CountDistinctFunction(), | ||
| 'stddev_samp': StddevSampFunction(), | ||
| 'quantiles': QuantilesFunction(), | ||
| 'first': FirstFunction() | ||
| 'first': FirstFunction(), | ||
| 'last': LastFunction(), | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
Is it possible for column.values to be empty in repeated mode? If so, I think this comprehension will die because
repeated_rowwill beNonewhich you can't take the len of.Assuming that situation is possible, can you add a test-case for it?