Skip to content

Commit

Permalink
SNOW-18844419 Change the aliasing fn type to be an enum instead of op…
Browse files Browse the repository at this point in the history
…tional boolean (#2712)

1. Which Jira issue is this PR addressing? Make sure that there is an
accompanying issue to your PR.
 Fixes SNOW-18844419

2. Fill out the following pre-review checklist:

- [ ] I am adding a new automated test(s) to verify correctness of my
new code
- [ ] If this test skips Local Testing mode, I'm requesting review from
@snowflakedb/local-testing
   - [ ] I am adding new logging messages
   - [ ] I am adding a new telemetry message
   - [ ] I am adding new credentials
   - [ ] I am adding a new dependency
- [ ] If this is a new feature/behavior, I'm adding the Local Testing
parity changes.
- [x] I acknowledge that I have ensured my changes to be thread-safe.
Follow the link for more information: [Thread-safe Developer
Guidelines](https://github.com/snowflakedb/snowpark-python/blob/main/CONTRIBUTING.md#thread-safe-development)

3. Please describe how your code solves the related issue.

Change the aliasing fn type to be an enum instead of optional boolean to
differentiate between as_, name, and alias.
  • Loading branch information
sfc-gh-vbudati authored Dec 11, 2024
1 parent 92ce21f commit ae1fe68
Show file tree
Hide file tree
Showing 110 changed files with 2,136 additions and 2,544 deletions.
4,353 changes: 1,963 additions & 2,390 deletions src/snowflake/snowpark/_internal/proto/ast.proto

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions src/snowflake/snowpark/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#

import sys
import typing
from typing import Any, Optional, Union

import snowflake.snowpark
Expand Down Expand Up @@ -1230,16 +1231,19 @@ def __repr__(self):
@publicapi
def as_(self, alias: str, _emit_ast: bool = True) -> "Column":
"""Returns a new renamed Column. Alias of :func:`name`."""
return self.name(alias, variant_is_as=True, _emit_ast=_emit_ast)
return self.name(alias, variant="as_", _emit_ast=_emit_ast)

@publicapi
def alias(self, alias: str, _emit_ast: bool = True) -> "Column":
"""Returns a new renamed Column. Alias of :func:`name`."""
return self.name(alias, variant_is_as=False, _emit_ast=_emit_ast)
return self.name(alias, variant="alias", _emit_ast=_emit_ast)

@publicapi
def name(
self, alias: str, variant_is_as: bool = None, _emit_ast: bool = True
self,
alias: str,
variant: typing.Literal["as_", "alias", "name"] = "name",
_emit_ast: bool = True,
) -> "Column":
"""Returns a new renamed Column."""
expr = self._expression # Snowpark expression
Expand All @@ -1252,8 +1256,13 @@ def name(
ast = with_src_position(ast_expr.sp_column_alias)
ast.col.CopyFrom(self._ast)
ast.name = alias
if variant_is_as is not None:
ast.variant_is_as.value = variant_is_as
if variant == "as_":
ast.fn.sp_column_alias_fn_as = True
elif variant == "alias":
ast.fn.sp_column_alias_fn_alias = True
elif variant == "name":
ast.fn.sp_column_alias_fn_name = True

return Column(
Alias(expr, quote_name(alias)), _ast=ast_expr, _emit_ast=_emit_ast
)
Expand Down
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.agg.test
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.collect.test
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.count.test
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.count2.test
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.create_or_replace.test
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.cross_join.lsuffix.test
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.cross_join.rsuffix.test
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.cross_join.suffix.test
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.describe.test
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.flatten.test
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.indexers.test
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
7 changes: 4 additions & 3 deletions tests/ast/data/DataFrame.join.inner.column.test
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ body {
}
}
}
fn {
sp_column_alias_fn_alias: true
}
name: "n1"
src {
end_column: 61
Expand All @@ -162,8 +165,6 @@ body {
start_column: 42
start_line: 29
}
variant_is_as {
}
}
}
cols {
Expand Down Expand Up @@ -243,5 +244,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.join.inner.column_list.test
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
14 changes: 7 additions & 7 deletions tests/ast/data/DataFrame.join.inner.column_list_predicate.test
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ body {
}
}
}
fn {
sp_column_alias_fn_as: true
}
name: "num_1"
src {
end_column: 111
Expand All @@ -259,9 +262,6 @@ body {
start_column: 88
start_line: 29
}
variant_is_as {
value: true
}
}
}
cols {
Expand All @@ -285,6 +285,9 @@ body {
}
}
}
fn {
sp_column_alias_fn_as: true
}
name: "str_1"
src {
end_column: 136
Expand All @@ -293,9 +296,6 @@ body {
start_column: 113
start_line: 29
}
variant_is_as {
value: true
}
}
}
df {
Expand Down Expand Up @@ -337,5 +337,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
12 changes: 7 additions & 5 deletions tests/ast/data/DataFrame.join.inner.predicate.test
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ body {
}
}
}
fn {
sp_column_alias_fn_alias: true
}
name: "num1"
src {
end_column: 76
Expand All @@ -199,8 +202,6 @@ body {
start_column: 55
start_line: 29
}
variant_is_as {
}
}
}
cols {
Expand All @@ -224,6 +225,9 @@ body {
}
}
}
fn {
sp_column_alias_fn_alias: true
}
name: "num2"
src {
end_column: 99
Expand All @@ -232,8 +236,6 @@ body {
start_column: 78
start_line: 29
}
variant_is_as {
}
}
}
cols {
Expand Down Expand Up @@ -294,5 +296,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.join.inner.predicate_rsuffix.test
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.join.left_outer.column.test
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.join.right_outer.predicate.test
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.natural_join.test
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.pivot.test
Original file line number Diff line number Diff line change
Expand Up @@ -767,5 +767,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.select_expr.test
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.stat.test
Original file line number Diff line number Diff line change
Expand Up @@ -1218,5 +1218,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.to_df.test
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.to_local_iterator.test
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.to_pandas.test
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.to_pandas_batch.test
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.unpivot.test
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/DataFrame.write.test
Original file line number Diff line number Diff line change
Expand Up @@ -1149,5 +1149,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.cube.test
Original file line number Diff line number Diff line change
Expand Up @@ -535,5 +535,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.distinct.test
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.drop_duplicates.test
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.filter.test
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.getitem.test
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.group_by.test
Original file line number Diff line number Diff line change
Expand Up @@ -535,5 +535,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.group_by_grouping_sets.test
Original file line number Diff line number Diff line change
Expand Up @@ -1059,5 +1059,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
2 changes: 1 addition & 1 deletion tests/ast/data/Dataframe.join.asof.test
Original file line number Diff line number Diff line change
Expand Up @@ -747,5 +747,5 @@ client_language {
}
client_version {
major: 1
minor: 25
minor: 26
}
Loading

0 comments on commit ae1fe68

Please sign in to comment.