philo-he commented on code in PR #13776:
URL: https://github.com/apache/gluten/pull/13776#discussion_r4747911245
##########
gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala:
##########
@@ -669,6 +669,40 @@ abstract class IcebergSuite extends
WholeStageTransformerSuite {
}
}
+ test("iceberg scan with no data files") {
+ withTable("iceberg_empty", "iceberg_empty_orc", "iceberg_empty_avro",
"iceberg_pruned") {
+ spark.sql("create table iceberg_empty (id int, name string) using
iceberg")
+ runQueryAndCompare("select * from iceberg_empty") {
+ checkGlutenPlan[IcebergScanTransformer]
+ }
+
+ // The default write format doesn't matter when there is nothing to
read; scans that plan
+ // files still validate their real format.
Review Comment:
Thanks for adding these tests. The comment's second half, "scans that plan
files still validate their real format", isn't covered yet: every table here is
empty, so the real-format check never runs.
One more assertion would cover it. Add a row to the Avro table and check
that the scan is no longer offloaded:
```scala
spark.sql("insert into iceberg_empty_avro values (1)")
runQueryAndCompare("select * from iceberg_empty_avro") {
df => checkGlutenPlanCount[IcebergScanTransformer](df, 0)
}
```
Optional, but it protects the case that must keep falling back.
##########
gluten-iceberg/src/main/scala/org/apache/iceberg/spark/source/GlutenIcebergSourceUtil.scala:
##########
@@ -246,7 +248,12 @@ object GlutenIcebergSourceUtil {
}
}
- asFileScanTask(getScanTasks(sparkScan).toList).foreach {
+ val tasks = asFileScanTask(getScanTasks(sparkScan).toList)
+ if (tasks.isEmpty) {
+ return (ReadFileFormat.ParquetReadFormat, Seq.empty)
+ }
Review Comment:
Minor, optional: because of this early return, the `UnknownFormat` check at
the end of this function (`throw new GlutenNotSupportException("Iceberg Only
support parquet and orc file format.")`) can no longer fail. If there is at
least one task, the loop either sets `fileFormat` to Parquet or ORC, or
`convertFileFormat` throws first. So `fileFormat` is never `UnknownFormat`
there.
That check was here before this PR and is harmless, so keeping it as a
safety net is fine. Feel free to remove it if you prefer.
##########
gluten-iceberg/src/main/scala/org/apache/iceberg/spark/source/GlutenIcebergSourceUtil.scala:
##########
@@ -268,7 +275,13 @@ object GlutenIcebergSourceUtil {
}
def getReadPartitionSchema(sparkScan: Scan): StructType = {
- asFileScanTask(getScanTasks(sparkScan).toList).foreach {
+ val tasks = asFileScanTask(getScanTasks(sparkScan).toList)
+ // No splits are generated, so this schema never lays out any output rows.
+ if (tasks.isEmpty) {
+ return new StructType()
+ }
Review Comment:
Same idea here: because of this early return, the `throw new
UnsupportedOperationException("Failed to get partition schema from iceberg
scan.")` at the end of this function can no longer be reached. With at least
one task, the loop always returns on its first iteration. Fine to keep.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]