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

perf: Use NULLS FIRST/LAST syntax for window order clauses #1033

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions bigframes/core/compile/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,20 +1416,14 @@ def _convert_ordering_to_table_values(
expr = op_compiler.compile_expression(
ordering_col.scalar_expression, value_lookup
)
ordering_value = (
bigframes_vendored.ibis.asc(expr) # type: ignore
if ordering_col.direction.is_ascending
else bigframes_vendored.ibis.desc(expr) # type: ignore
)
# Bigquery SQL considers NULLS to be "smallest" values, but we need to override in these cases.
if (not ordering_col.na_last) and (not ordering_col.direction.is_ascending):
# Force nulls to be first
is_null_val = typing.cast(ibis_types.Column, expr.isnull())
ordering_values.append(bigframes_vendored.ibis.desc(is_null_val))
elif (ordering_col.na_last) and (ordering_col.direction.is_ascending):
# Force nulls to be last
is_null_val = typing.cast(ibis_types.Column, expr.isnull())
ordering_values.append(bigframes_vendored.ibis.asc(is_null_val))
if ordering_col.direction.is_ascending:
ordering_value = bigframes_vendored.ibis.asc(
expr, nulls_first=not ordering_col.na_last
)
else:
ordering_value = bigframes_vendored.ibis.desc(
expr, nulls_first=not ordering_col.na_last
)
ordering_values.append(ordering_value)
return ordering_values

Expand Down
2 changes: 1 addition & 1 deletion bigframes/ml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_only_column(input: ArrayType) -> Union[pd.Series, bpd.Series]:
label = typing.cast(Hashable, input.columns.tolist()[0])
if isinstance(input, pd.DataFrame):
return typing.cast(pd.Series, input[label])
return typing.cast(bpd.Series, input[label])
return typing.cast(bpd.Series, input[label]) # type: ignore


def parse_model_endpoint(model_endpoint: str) -> tuple[str, Optional[str]]:
Expand Down
Loading