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-1852779 Fix AST encoding for Column in_, asc, and desc #2756

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
641 changes: 320 additions & 321 deletions src/snowflake/snowpark/_internal/proto/ast.proto

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/snowflake/snowpark/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def in_(
ast = None
if _emit_ast:
ast = proto.Expr()
Copy link
Contributor

Choose a reason for hiding this comment

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

is the IR server-side branch for this already merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup!

proto_ast = ast.sp_column_in__seq
proto_ast = ast.sp_column_in
proto_ast.col.CopyFrom(self._ast)

return Column(Literal(False), _ast=ast, _emit_ast=_emit_ast)
Expand Down Expand Up @@ -699,7 +699,7 @@ def validate_value(value_expr: Expression):
ast = None
if _emit_ast:
ast = proto.Expr()
proto_ast = ast.sp_column_in__seq
proto_ast = ast.sp_column_in
proto_ast.col.CopyFrom(self._ast)
for val in vals:
val_ast = proto_ast.values.add()
Expand Down Expand Up @@ -952,6 +952,7 @@ def desc(self, _emit_ast: bool = True) -> "Column":
expr = proto.Expr()
ast = with_src_position(expr.sp_column_desc)
ast.col.CopyFrom(self._ast)
ast.null_order.sp_null_order_default = True
return Column(
SortOrder(self._expression, Descending()), _ast=expr, _emit_ast=_emit_ast
)
Expand All @@ -965,7 +966,7 @@ def desc_nulls_first(self, _emit_ast: bool = True) -> "Column":
expr = proto.Expr()
ast = with_src_position(expr.sp_column_desc)
ast.col.CopyFrom(self._ast)
ast.nulls_first.value = True
ast.null_order.sp_null_order_nulls_first = True
return Column(
SortOrder(self._expression, Descending(), NullsFirst()),
_ast=expr,
Expand All @@ -981,7 +982,7 @@ def desc_nulls_last(self, _emit_ast: bool = True) -> "Column":
expr = proto.Expr()
ast = with_src_position(expr.sp_column_desc)
ast.col.CopyFrom(self._ast)
ast.nulls_first.value = False
ast.null_order.sp_null_order_nulls_last = True
return Column(
SortOrder(self._expression, Descending(), NullsLast()),
_ast=expr,
Expand All @@ -996,6 +997,7 @@ def asc(self, _emit_ast: bool = True) -> "Column":
expr = proto.Expr()
ast = with_src_position(expr.sp_column_asc)
ast.col.CopyFrom(self._ast)
ast.null_order.sp_null_order_default = True
return Column(
SortOrder(self._expression, Ascending()), _ast=expr, _emit_ast=_emit_ast
)
Expand All @@ -1009,7 +1011,7 @@ def asc_nulls_first(self, _emit_ast: bool = True) -> "Column":
expr = proto.Expr()
ast = with_src_position(expr.sp_column_asc)
ast.col.CopyFrom(self._ast)
ast.nulls_first.value = True
ast.null_order.sp_null_order_nulls_first = True
return Column(
SortOrder(self._expression, Ascending(), NullsFirst()),
_ast=expr,
Expand All @@ -1025,7 +1027,7 @@ def asc_nulls_last(self, _emit_ast: bool = True) -> "Column":
expr = proto.Expr()
ast = with_src_position(expr.sp_column_asc)
ast.col.CopyFrom(self._ast)
ast.nulls_first.value = False
ast.null_order.sp_null_order_nulls_last = True
return Column(
SortOrder(self._expression, Ascending(), NullsLast()),
_ast=expr,
Expand Down
10 changes: 7 additions & 3 deletions tests/ast/data/col_asc.test
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ body {
}
}
}
null_order {
sp_null_order_default: true
}
src {
end_column: 37
end_line: 29
Expand Down Expand Up @@ -163,8 +166,8 @@ body {
}
}
}
nulls_first {
value: true
null_order {
sp_null_order_nulls_first: true
}
src {
end_column: 49
Expand Down Expand Up @@ -239,7 +242,8 @@ body {
}
}
}
nulls_first {
null_order {
sp_null_order_nulls_last: true
}
src {
end_column: 48
Expand Down
10 changes: 7 additions & 3 deletions tests/ast/data/col_desc.test
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ body {
}
}
}
null_order {
sp_null_order_default: true
}
src {
end_column: 38
end_line: 27
Expand Down Expand Up @@ -161,8 +164,8 @@ body {
}
}
}
nulls_first {
value: true
null_order {
sp_null_order_nulls_first: true
}
src {
end_column: 50
Expand Down Expand Up @@ -237,7 +240,8 @@ body {
}
}
}
nulls_first {
null_order {
sp_null_order_nulls_last: true
}
src {
end_column: 49
Expand Down
6 changes: 3 additions & 3 deletions tests/ast/data/col_in_.test
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ body {
expr {
sp_dataframe_select__columns {
cols {
sp_column_in__seq {
sp_column_in {
col {
apply_expr {
fn {
Expand Down Expand Up @@ -157,7 +157,7 @@ body {
expr {
sp_dataframe_select__columns {
cols {
sp_column_in__seq {
sp_column_in {
col {
apply_expr {
fn {
Expand Down Expand Up @@ -230,7 +230,7 @@ body {
expr {
sp_dataframe_select__columns {
cols {
sp_column_in__seq {
sp_column_in {
col {
apply_expr {
fn {
Expand Down
3 changes: 3 additions & 0 deletions tests/ast/data/windows.test
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ body {
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a test for this where it is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can't be "false" -- it's an enum. It can only be set to true but this should be tested by the asc/desc tests.

null_order {
sp_null_order_default: true
}
src {
end_column: 51
end_line: 35
Expand Down
Loading