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

Tag GpuWindow child expressions for GPU execution #6057

Merged
merged 6 commits into from
Jul 26, 2022
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
41 changes: 40 additions & 1 deletion integration_tests/src/main/python/window_function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,4 +1108,43 @@ def test_window_first_last_nth_ignore_nulls(data_gen):
lambda spark: three_col_df(spark, data_gen, string_gen, int_gen, num_slices=1).coalesce(1),
"window_agg_table",
'SELECT a, b, c, ' + exprs_for_nth_first_last_ignore_nulls +
'FROM window_agg_table')
'FROM window_agg_table')


@ignore_order(local=True)
def test_to_date_with_window_functions():
"""
This test ensures that date expressions participating alongside window aggregations
are initialized correctly. (See: https://github.com/NVIDIA/spark-rapids/issues/5984)

For certain vendor-specific Spark versions, the date expression might be evaluated
directly in the WindowExec, instead of being projected upstream. For instance,
the query in this test might produce this plan on CPU:
```
Window [cast(gettimestamp(cast(date_1#1 as string), yyyy-MM-dd, TimestampType, Some(Etc/UTC), false) as date)...]
+- Sort [id#0L ASC NULLS FIRST, date_2#2 ASC NULLS FIRST], false, 0
+- Exchange hashpartitioning(id#0L, 200), ENSURE_REQUIREMENTS, [id=#136]
+- *(1) Project [date_1#1, id#0L, date_2#2]
```

This might trip up the GPU plan, by incompletely initializing `GpuGetTimeStamp` for `date_1` thus:
```
+- GpuProject [cast(gpugettimestamp(cast(date_1#1 as string), yyyy-MM-dd, null, null, None) as date) AS my_date#6]
```

The correct initialization should have yielded:
```
+- GpuProject [cast(gpugettimestamp(cast(date_1#1 as string), yyyy-MM-dd, yyyy-MM-dd, %Y-%m-%d, None) as date)]
```
"""
assert_gpu_and_cpu_are_equal_sql(
df_fun=lambda spark: gen_df(spark, [('id', RepeatSeqGen(int_gen, 20)),
('date_1', DateGen()),
('date_2', DateGen())]),
table_name="window_input",
sql="""
SELECT TO_DATE( CAST(date_1 AS STRING), 'yyyy-MM-dd' ) AS my_date,
SUM(1) OVER(PARTITION BY id ORDER BY date_2) AS my_sum
FROM window_input
"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ abstract class GpuBaseWindowExecMeta[WindowExecType <: SparkPlan] (windowExec: W
getPartitionSpecs.map(GpuOverrides.wrapExpr(_, conf, Some(this)))
val orderSpec: Seq[BaseExprMeta[SortOrder]] =
getOrderSpecs.map(GpuOverrides.wrapExpr(_, conf, Some(this)))

lazy val inputFields: Seq[BaseExprMeta[Attribute]] =
windowExec.children.head.output.map(GpuOverrides.wrapExpr(_, conf, Some(this)))

/**
* Define all dependency expressions as `childExprs`.
* This ensures that they are tagged for GPU execution.
*/
override val childExprs: Seq[BaseExprMeta[_]] =
windowExpressions ++ partitionSpec ++ orderSpec ++ inputFields

override def namedChildExprs: Map[String, Seq[BaseExprMeta[_]]] = Map(
"partitionSpec" -> partitionSpec
Expand Down