philo-he commented on code in PR #13776:
URL: https://github.com/apache/gluten/pull/13776#discussion_r4691577591
##########
gluten-iceberg/src/main/scala/org/apache/iceberg/spark/source/GlutenIcebergSourceUtil.scala:
##########
@@ -303,7 +308,7 @@ object GlutenIcebergSourceUtil {
return new StructType()
}
}
- throw new UnsupportedOperationException("Failed to get partition schema
from iceberg scan.")
+ new StructType()
Review Comment:
Same as above: this line now means "no tasks planned", but that's implicit.
A short comment or an explicit `tasks.isEmpty` check would help.
Also, for a partitioned table (like `iceberg_pruned` in the test) the
partition schema is now empty, so `name` is treated as a regular column in the
read rel. That's harmless because no splits are generated, but a comment would
keep someone from later relying on `getPartitionSchema` for the output layout
here.
##########
gluten-iceberg/src/test/scala/org/apache/gluten/execution/IcebergSuite.scala:
##########
@@ -626,6 +626,27 @@ abstract class IcebergSuite extends
WholeStageTransformerSuite {
}
}
+ test("iceberg scan with no data files") {
+ withTable("iceberg_empty", "iceberg_pruned") {
+ spark.sql("create table iceberg_empty (id int, name string) using
iceberg")
+ runQueryAndCompare("select * from iceberg_empty") {
+ checkGlutenPlan[IcebergScanTransformer]
+ }
+
+ spark.sql("""
+ |create table iceberg_pruned (id int, name string)
+ | using iceberg partitioned by (name)
+ |""".stripMargin)
+ spark.sql("""insert into iceberg_pruned values (1, "v1"), (2, "v2")""")
+ runQueryAndCompare("select * from iceberg_pruned where name = 'v3'") {
+ checkGlutenPlan[IcebergScanTransformer]
+ }
+ runQueryAndCompare("select true from iceberg_pruned where id > 100 limit
1") {
+ checkGlutenPlan[IcebergScanTransformer]
+ }
+ }
+ }
Review Comment:
A few test gaps that would be nice to cover:
- An empty table with `'write.format.default'='orc'`: planning should pick
ORC, the ORC-only checks are skipped because `hasOrcScanTask` is false, and the
scan should still offload.
- An empty table with `'write.format.default'='avro'`, which should still
fall back. That locks in the rejection path the description mentions.
##########
gluten-iceberg/src/main/scala/org/apache/iceberg/spark/source/GlutenIcebergSourceUtil.scala:
##########
@@ -262,7 +262,12 @@ object GlutenIcebergSourceUtil {
}
if (fileFormat == ReadFileFormat.UnknownFormat) {
- throw new GlutenNotSupportException("Iceberg Only support parquet and
orc file format.")
+ fileFormat = convertFileFormat(
+ FileFormat.fromString(
+ PropertyUtil.propertyAsString(
+ getTable(sparkScan).properties(),
+ TableProperties.DEFAULT_FILE_FORMAT,
+ TableProperties.DEFAULT_FILE_FORMAT_DEFAULT)))
Review Comment:
On an empty scan this calls `FileFormat.fromString(...)`, which throws
`IllegalArgumentException` for an unknown value (a typo, or a format added in a
newer Iceberg version). `failValidationWithException` in `ValidatablePlan` only
turns `GlutenNotSupportException` and `UnsupportedOperationException` into a
fallback and rethrows everything else, so query planning would fail. Before
this PR the same scan threw `GlutenNotSupportException` and fell back cleanly.
Could the parse error be rethrown as `GlutenNotSupportException`? For
example:
```scala
val defaultFormat = PropertyUtil.propertyAsString(
getTable(sparkScan).properties(),
TableProperties.DEFAULT_FILE_FORMAT,
TableProperties.DEFAULT_FILE_FORMAT_DEFAULT)
fileFormat = Try(FileFormat.fromString(defaultFormat)).toOption
.map(convertFileFormat)
.getOrElse(throw new GlutenNotSupportException(
s"Iceberg Only support parquet and orc file format, found
$defaultFormat."))
```
A simpler option is to skip the table property and use `ParquetReadFormat`
whenever there are no tasks, since the format doesn't matter when nothing is
read.
##########
gluten-iceberg/src/main/scala/org/apache/iceberg/spark/source/GlutenIcebergSourceUtil.scala:
##########
@@ -262,7 +262,12 @@ object GlutenIcebergSourceUtil {
}
if (fileFormat == ReadFileFormat.UnknownFormat) {
Review Comment:
This branch can now only be reached when no tasks are planned, because
`convertFileFormat` throws for every other format. That isn't obvious to a
reader. An explicit `tasks.isEmpty` check, or a one-line comment, would make
the intent clear. The Scaladoc above `getFileFormatAndRootPaths` could also
mention that the format comes from `write.format.default` when no tasks are
planned.
--
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]