-
Notifications
You must be signed in to change notification settings - Fork 119
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
base: main
Are you sure you want to change the base?
Conversation
src/snowflake/snowpark/dataframe.py
Outdated
elif isinstance(e, (list, tuple, set)): | ||
for sub_e in e: | ||
names.append(sub_e._named()) | ||
if _emit_ast and _ast_stmt is None: | ||
ast_cols.append(sub_e._ast) |
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.
how does this change affect this new funcs?
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.
json_tuple will have to return a list of columns, while our select function currently does not support this form of call:
df.select(col1, [col2,col3]), this is meant to support it
CHANGELOG.md
Outdated
- `array_slice` | ||
- `try_to_binary` |
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.
did this change get removed?
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.
+ need to update functions.rst?
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 found out that we already support it, so I removed it from this PR
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.
minor fixes about _emit_ast
. Please also take a review from IR team.
src/snowflake/snowpark/functions.py
Outdated
max_bit = bitshiftleft(lit(1), 64) | ||
unsigned_c = iff(c < 0, bitshiftright(c + max_bit, n), bitshiftright(c, n)) | ||
return call_builtin("bitand", unsigned_c, max_bit - 1, _emit_ast=_emit_ast) |
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.
max_bit = bitshiftleft(lit(1), 64) | |
unsigned_c = iff(c < 0, bitshiftright(c + max_bit, n), bitshiftright(c, n)) | |
return call_builtin("bitand", unsigned_c, max_bit - 1, _emit_ast=_emit_ast) | |
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) | |
return call_builtin("bitand", unsigned_c, max_bit - 1, _emit_ast=_emit_ast) |
let's make sure that for all internal calls to our functions, we set _emit_ast=False
src/snowflake/snowpark/functions.py
Outdated
""" | ||
c = _to_col_if_str(col, "json_tuple") | ||
return [ | ||
json_extract_path_text(parse_json(c), lit(field)).as_(f"c{i}") |
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.
same here, _emit_ast=False
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.
Please add expectation tests in the mentioned files, use the suggested helper functions from ast.utils
, and see notes about json_tuple
.
src/snowflake/snowpark/dataframe.py
Outdated
@@ -1414,6 +1418,11 @@ def select( | |||
names.append(e._named()) | |||
if _emit_ast and _ast_stmt is None: | |||
ast_cols.append(e._ast) | |||
elif isinstance(e, (list, tuple)): |
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.
Instead of adding the column ASTs manually for this case, please use build_expr_from_python_val(ast_cols.add(), e)
(from ast.utils
) to capture when an input provided is a list or tuple.
It would also be very helpful if you could add an expectation test for this in tests/ast/data/select.test
src/snowflake/snowpark/functions.py
Outdated
bitshiftright(c, n, _emit_ast=False), | ||
_emit_ast=False, | ||
) | ||
return call_builtin("bitand", unsigned_c, max_bit - 1, _emit_ast=_emit_ast) |
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.
Since the arguments to the public API and the internal call_builtin
method are different the AST needs to be constructed manually via build_builtin_fn_apply
and assigned to the _ast
field of the Column
instance returned by call_builtin
before returning. See functions.bround
for a relevant example.
An expectation test in tests/ast/data/functions2.test
would also be very helpful.
src/snowflake/snowpark/functions.py
Outdated
_emit_ast=False, | ||
).as_(f"c{i}", _emit_ast=False) | ||
for i, field in enumerate(fields) | ||
] |
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 don't think this API would emit any AST currently.
Modeling this API with the AST would still be more involved though, as this is the first Snowpark function that returns a List[Column]
AFAIK. Usually we rely on the returned Column
object storing its own AST in the ._ast
field.
Is there any way the return type here can be a Column
object? This would allow the AST to be constructed via build_builtin_fn_apply
and assigned to the Column
instance to be returned.
src/snowflake/snowpark/functions.py
Outdated
ast = None | ||
if _emit_ast: | ||
ast = proto.Expr() | ||
build_builtin_fn_apply(ast, "bround", to_shift_column, n) |
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.
Nit: Change builtin_name
arg to "bitshiftright_unsigned"
instead of "bround"
bitshiftright(c, n, _emit_ast=False), | ||
_emit_ast=False, | ||
) | ||
col = call_builtin("bitand", unsigned_c, max_bit - 1, _emit_ast=_emit_ast) |
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.
One more nit: _emit_ast
should be False here as well now
Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-1904191
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
Please write a short description of how your code change solves the related issue.