Yibo-Dong opened a new issue, #20904:
URL: https://github.com/apache/hudi/issues/20904
### Bug Description
**What happened:**
With `hoodie.datasource.read.file.index.list.partitions.from.catalog=true`,
any read of a partitioned table fails with `SparkException: Task not
serializable`. `CatalogBackedTableMetadata` falls back to
`FileSystemBackedTableMetadata` listing, whose `engineContext.flatMap(...)`
lambda calls `getStorage()` and so captures `this`. `this` is the
`CatalogBackedTableMetadata`, which holds the Spark `CatalogTable` (not
serializable), so the closure cannot be shipped.
**What you expected:**
The query returns `(1, a1, a), (2, b1, b)`, as it does with the option off.
**Steps to reproduce:**
```sql
SET hoodie.datasource.read.file.index.list.partitions.from.catalog = true;
CREATE TABLE t (id INT, value STRING, ts INT, p STRING)
USING hudi
PARTITIONED BY (p)
LOCATION '/tmp/hudi_catalog_listing'
TBLPROPERTIES (type = 'cow', primaryKey = 'id', orderingFields = 'ts',
'hoodie.metadata.enable' = 'false');
INSERT INTO t VALUES (1, 'a1', 1, 'a'), (2, 'b1', 2, 'b');
SELECT id, value, p FROM t ORDER BY id; -- fails
```
The `INSERT` succeeds; the `SELECT` fails. The same happens with the
metadata table enabled.
### Environment
**Hudi version:** master (8dafd38, 2026-11-24) and 1.2.1
**Query engine:** Spark 3.5.5 (spark-sql, `HoodieSparkSessionExtension` +
`HoodieCatalog`), JDK 17
**Relevant configs:**
`hoodie.datasource.read.file.index.list.partitions.from.catalog=true`
### Logs and Stack Trace
```
org.apache.spark.SparkException: Task not serializable
at
org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:444)
...
at
org.apache.hudi.client.common.HoodieSparkEngineContext.flatMap(HoodieSparkEngineContext.java:200)
at
org.apache.hudi.metadata.FileSystemBackedTableMetadata.getPartitionPathWithPathPrefixUsingFilterExpression(FileSystemBackedTableMetadata.java:179)
at
org.apache.hudi.metadata.FileSystemBackedTableMetadata.getPartitionPathWithPathPrefix(FileSystemBackedTableMetadata.java:137)
at
org.apache.hudi.metadata.FileSystemBackedTableMetadata.getPartitionPathWithPathPrefixes(FileSystemBackedTableMetadata.java:133)
at
org.apache.hudi.metadata.CatalogBackedTableMetadata.getPartitionPathWithPathPrefixes(CatalogBackedTableMetadata.scala:88)
at
org.apache.hudi.core.read.BaseHoodieTableFileIndex.listPartitionPaths(BaseHoodieTableFileIndex.java:416)
at
org.apache.hudi.HoodieFileIndex.prunePartitionsAndGetFileSlices(HoodieFileIndex.scala:373)
at
org.apache.spark.sql.hudi.analysis.Spark3HoodiePruneFileSourcePartitions$$anonfun$apply$1.applyOrElse(Spark3HoodiePruneFileSourcePartitions.scala:55)
...
Caused by: java.io.NotSerializableException:
scala.collection.immutable.MapLike$$anon$1
Serialization stack:
- object not serializable (class:
scala.collection.immutable.MapLike$$anon$1, value: Map(hoodie.query.as.ro.table
-> false))
- field (class:
org.apache.spark.sql.catalyst.catalog.CatalogStorageFormat, name: properties,
...)
- field (class: org.apache.spark.sql.catalyst.catalog.CatalogTable,
name: storage, ...)
- field (class: org.apache.hudi.metadata.CatalogBackedTableMetadata,
name: catalogTable, ...)
- object (class org.apache.hudi.metadata.CatalogBackedTableMetadata,
...)
- object (class java.lang.invoke.SerializedLambda,
SerializedLambda[capturingClass=class
org.apache.hudi.metadata.FileSystemBackedTableMetadata, ...
getPartitionPathWithPathPrefixUsingFilterExpression ...])
```
--
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]