Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions integration_tests/src/main/python/csv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from datetime import datetime, timezone
from data_gen import *
from marks import *
from pyspark.sql import functions as f
from pyspark.sql.types import *
from spark_session import *

Expand Down Expand Up @@ -720,3 +721,22 @@ def test_csv_read_gbk_encoded_data(std_input_path):
.schema("name string, age int, city string, job string")
.csv(std_input_path + "/test_gbk.csv"),
conf={"spark.sql.legacy.javaCharsets": legacy_charset})


@allow_non_gpu('CollectLimitExec')
def test_csv_stream_table_is_empty_when_join(std_input_path):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we want to coordinate with #13938 as they both are near duplicates and fix the problem is slightly different ways. I don't might having both fixes, but I don't want duplicate files checked in.

built_csv_path = std_input_path + '/one_row.csv'
stream_csv_path = std_input_path + '/empty_with_header.csv'

def _create_view(spark):
spark.read.csv(built_csv_path, header=True, inferSchema=True).createOrReplaceTempView("built_table")
spark.read.csv(stream_csv_path, header=True, inferSchema=True).createOrReplaceTempView("stream_table")

# create view first on CPU
with_cpu_session(lambda spark: _create_view(spark))

# then do the join on GPU
with_gpu_session(lambda spark:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would prefer a test that verifies we got the right result. Not just one that shows we didn't crash.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If using .collect() instead of .show(), the error does not occur.

@firestarman firestarman Dec 8, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can do a post project for the collect to simulate the "show" action. Just like the additional cast(c as string) at https://github.com/NVIDIA/spark-rapids/blob/main/integration_tests/src/main/python/join_test.py#L442

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

spark.table("built_table").join(spark.table("stream_table"), f.lit(True), "right_outer").select(
f.col("stream_table.c0")).show(),
conf=_enable_all_types_conf)
1 change: 1 addition & 0 deletions integration_tests/src/test/resources/empty_with_header.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c0
2 changes: 2 additions & 0 deletions integration_tests/src/test/resources/one_row.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
c0
1
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,14 @@ abstract class GpuTextBasedPartitionReader[BUFF <: LineBufferer, FACT <: LineBuf
// val cols = (0 until table.getNumberOfColumns).map(i => table.getColumn(i))
// Some(new Table(cols: _*))
// }
Some(table)
if (table.getRowCount == 0) {
// CSV reader can return empty table, close it and return None
// E.g.: CSV file with only header and no data rows, empty table will be returned
table.close()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

any concerns that this code can throw instead of returning None even if close fails?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The row count is zero, it means there is no GPU memory allocated although table has columns.
It is not likely to throw exceptions in practice.

None
} else {
Some(table)
}
}

override def next(): Boolean = {
Expand Down