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

SNOW-1904191:[API Coverage] functions coverage #2964

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- `bitmap_bit_position`
- `bitmap_bucket_number`
- `bitmap_construct_agg`
- `bitshiftright_unsigned`
- `cbrt`
- `equal_null`
- `from_json`
Expand Down
38 changes: 38 additions & 0 deletions src/snowflake/snowpark/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,44 @@ def bitshiftleft(
return call_builtin("bitshiftleft", c, n, _emit_ast=_emit_ast)


@publicapi
def bitshiftright_unsigned(
to_shift_column: ColumnOrName, n: Union[Column, int], _emit_ast: bool = True
) -> Column:
"""Returns the bitwise negation of a numeric expression.

Example:
>>> df = session.createDataFrame([(-1999)], ['a'])
>>> df.select(bitshiftright_unsigned('a', 1)).collect()[0][0]
9223372036854774808

>>> df = session.createDataFrame([(42)], ['a'])
>>> df.select(bitshiftright_unsigned('a', 1)).collect()[0][0]
21

>>> df = session.createDataFrame([(-21)], ['a'])
>>> df.select(bitshiftright_unsigned('a', 1)).collect()[0][0]
9223372036854775797
"""
# AST.
ast = None
if _emit_ast:
ast = proto.Expr()
build_builtin_fn_apply(ast, "bitshiftright_unsigned", to_shift_column, n)

c = _to_col_if_str(to_shift_column, "bitshiftright_unsigned")
max_bit = bitshiftleft(lit(1, _emit_ast=False), 64, _emit_ast=False)
unsigned_c = iff(
c < 0,
bitshiftright(c + max_bit, n, _emit_ast=False),
bitshiftright(c, n, _emit_ast=False),
_emit_ast=False,
)
col = call_builtin("bitand", unsigned_c, max_bit - 1, _emit_ast=_emit_ast)
Copy link
Contributor

Choose a reason for hiding this comment

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

One more nit: _emit_ast should be False here as well now

col._ast = ast
return col


@publicapi
def bitshiftright(
to_shift_column: ColumnOrName, n: Union[Column, int], _emit_ast: bool = True
Expand Down
Loading