Skip to content

Commit d0bb72d

Browse files
committed
Fix additional ordering issues
1 parent e83efe6 commit d0bb72d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/snowflake/snowpark/dataframe_analytics_functions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,15 @@ def moving_agg(
276276
... window_sizes=[2, 3],
277277
... order_by=["ORDERDATE"],
278278
... group_by=["PRODUCTKEY"],
279-
... )
279+
... ).sort("ORDERDATE")
280280
>>> result.show()
281281
--------------------------------------------------------------------------------------------------------------------------------------
282282
|"ORDERDATE" |"PRODUCTKEY" |"SALESAMOUNT" |"SALESAMOUNT_SUM_2" |"SALESAMOUNT_AVG_2" |"SALESAMOUNT_SUM_3" |"SALESAMOUNT_AVG_3" |
283283
--------------------------------------------------------------------------------------------------------------------------------------
284-
|2023-01-04 |102 |250 |250 |250.000 |250 |250.000 |
285284
|2023-01-01 |101 |200 |200 |200.000 |200 |200.000 |
286285
|2023-01-02 |101 |100 |300 |150.000 |300 |150.000 |
287286
|2023-01-03 |101 |300 |400 |200.000 |600 |200.000 |
287+
|2023-01-04 |102 |250 |250 |250.000 |250 |250.000 |
288288
--------------------------------------------------------------------------------------------------------------------------------------
289289
<BLANKLINE>
290290
"""
@@ -390,14 +390,14 @@ def cumulative_agg(
390390
... group_by=["PRODUCTKEY"],
391391
... order_by=["ORDERDATE"],
392392
... is_forward=True
393-
... )
393+
... ).sort("ORDERDATE")
394394
>>> res.show()
395395
----------------------------------------------------------------------------------------------------------
396396
|"ORDERDATE" |"PRODUCTKEY" |"SALESAMOUNT" |"SALESAMOUNT_SUM" |"SALESAMOUNT_MIN" |"SALESAMOUNT_MAX" |
397397
----------------------------------------------------------------------------------------------------------
398-
|2023-01-03 |101 |300 |300 |300 |300 |
399-
|2023-01-02 |101 |100 |400 |100 |300 |
400398
|2023-01-01 |101 |200 |600 |100 |300 |
399+
|2023-01-02 |101 |100 |400 |100 |300 |
400+
|2023-01-03 |101 |300 |300 |300 |300 |
401401
|2023-01-04 |102 |250 |250 |250 |250 |
402402
----------------------------------------------------------------------------------------------------------
403403
<BLANKLINE>
@@ -582,15 +582,15 @@ def compute_lead(
582582
... leads=[1, 2],
583583
... order_by=["ORDERDATE"],
584584
... group_by=["PRODUCTKEY"]
585-
... )
585+
... ).sort("ORDERDATE")
586586
>>> res.show()
587587
--------------------------------------------------------------------------------------------
588588
|"ORDERDATE" |"PRODUCTKEY" |"SALESAMOUNT" |"SALESAMOUNT_LEAD_1" |"SALESAMOUNT_LEAD_2" |
589589
--------------------------------------------------------------------------------------------
590-
|2023-01-04 |102 |250 |NULL |NULL |
591590
|2023-01-01 |101 |200 |100 |300 |
592591
|2023-01-02 |101 |100 |300 |NULL |
593592
|2023-01-03 |101 |300 |NULL |NULL |
593+
|2023-01-04 |102 |250 |NULL |NULL |
594594
--------------------------------------------------------------------------------------------
595595
<BLANKLINE>
596596
"""
@@ -684,15 +684,15 @@ def time_series_agg(
684684
... windows=["1D", "-1D"],
685685
... sliding_interval="12H",
686686
... col_formatter=custom_formatter,
687-
... )
687+
... ).sort("ORDERDATE")
688688
>>> res.show()
689689
----------------------------------------------------------------------------------------------------------------------------------------------------
690690
|"PRODUCTKEY" |"SALESAMOUNT" |"ORDERDATE" |"SUM_SALESAMOUNT_1D" |"MAX_SALESAMOUNT_1D" |"SUM_SALESAMOUNT_-1D" |"MAX_SALESAMOUNT_-1D" |
691691
----------------------------------------------------------------------------------------------------------------------------------------------------
692-
|102 |250 |2023-01-04 00:00:00 |250 |250 |250 |250 |
693692
|101 |200 |2023-01-01 00:00:00 |300 |200 |200 |200 |
694693
|101 |100 |2023-01-02 00:00:00 |400 |300 |300 |200 |
695694
|101 |300 |2023-01-03 00:00:00 |300 |300 |400 |300 |
695+
|102 |250 |2023-01-04 00:00:00 |250 |250 |250 |250 |
696696
----------------------------------------------------------------------------------------------------------------------------------------------------
697697
<BLANKLINE>
698698
"""

src/snowflake/snowpark/functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8928,15 +8928,15 @@ def percent_rank(_emit_ast: bool = True) -> Column:
89288928
... ],
89298929
... schema=["x", "y", "z"]
89308930
... )
8931-
>>> df.select(percent_rank().over(Window.partition_by("x").order_by(col("y"))).alias("result")).show()
8931+
>>> df.select(percent_rank().over(Window.partition_by("x").order_by(col("y"), col("z"))).alias("result")).show()
89328932
------------
89338933
|"RESULT" |
89348934
------------
89358935
|0.0 |
89368936
|0.5 |
8937-
|0.5 |
8938-
|0.0 |
8937+
|1.0 |
89398938
|0.0 |
8939+
|1.0 |
89408940
------------
89418941
<BLANKLINE>
89428942
"""
@@ -9058,10 +9058,10 @@ def lead(
90589058
>>> df = session.create_dataframe(
90599059
... [
90609060
... [1, 2, 1],
9061-
... [1, 2, 3],
9061+
... [1, 3, 3],
90629062
... [2, 1, 10],
90639063
... [2, 2, 1],
9064-
... [2, 2, 3],
9064+
... [2, 3, 3],
90659065
... ],
90669066
... schema=["x", "y", "z"]
90679067
... )
@@ -11501,7 +11501,7 @@ def bitmap_construct_agg(
1150111501
Example::
1150211502

1150311503
>>> df = session.create_dataframe([1, 32769], schema=["a"])
11504-
>>> df.select(bitmap_bucket_number(df["a"]).alias("bitmap_id"),bitmap_bit_position(df["a"]).alias("bit_position")).group_by("bitmap_id").agg(bitmap_construct_agg(col("bit_position")).alias("bitmap")).collect()
11504+
>>> df.select(bitmap_bucket_number(df["a"]).alias("bitmap_id"),bitmap_bit_position(df["a"]).alias("bit_position")).group_by("bitmap_id").agg(bitmap_construct_agg(col("bit_position")).alias("bitmap")).order_by("bitmap_id").collect()
1150511505
[Row(BITMAP_ID=1, BITMAP=bytearray(b'\\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00')), Row(BITMAP_ID=2, BITMAP=bytearray(b'\\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'))]
1150611506
"""
1150711507
c = _to_col_if_str(relative_position, "bitmap_construct_agg")

0 commit comments

Comments
 (0)