[FEATURE] Support query more file format and specific schema data under Fileset in Spark
- Dominant language
- Java
- Stars
- 3.2k
- Forks
- 935
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 298
Description
### Describe the feature
In the current integration of Fileset and Spark, we can already read the data under Fileset in the form of gvfs path which file format supported by Spark:
```
// Dataframe API
val df = sparkSession
.read
.parquet("gvfs://fileset/fileset_catalog/tmp/test_fileset/date=20241021")
// SQL API
SELECT * FROM `parquet`.`gvfs://fileset/fileset_catalog/tmp/test_fileset` WHERE date = 20241022
```
In fact, Databricks also handles Volume in this way: https://docs.databricks.com/en/sql/language-manual/sql-ref-volumes.html#examples.

### Motivation
But there are two problems here:
1. If users want to read a specific file format that is not officially supported by Spark under Fileset through SQL, there is currently no way.
2. If the file format does not support schema inference, additional schema metadata is required.
### Describe the solution
My idea is that we should consider providing some new data sources which extends the Spark FileDatasourceV2 interface. For the file formats currently supported by Spark, we can reuse the relevant logic (such as parquet/csv/json, etc.); for the new file formats supported by fileset, users can use our new data sources (such as sequence file, tfrecord, etc.).
The specific file format and schema are obtained and routed through the fileset metadata:
```
// Dataframe API
val df = sparkSession
.read
.format("tfrecord-fileset")
.load("gvfs://fileset/fileset_catalog/tmp/test_fileset")
.where("date=20241021")
// SQL API
SELECT * FROM `tfrecord-fileset`.`gvfs://fileset/fileset_catalog/tmp/test_fileset` WHERE date = 20241022
```
At the same time, since we have a new data source, we can control when reading data, and deserializing it.
### Additional context
One production case in Xiaomi it that we need to deserialize records through thrift class when reading sequence files.
Contributor guide
Research direction
The issue names no repository files, tests, or entry points. Start by reviewing the existing Fileset and Spark integration and the Spark FileDataSourceV2 interface, then determine how Fileset metadata should provide file-format and schema information. Done would require an agreed design and support for the described DataFrame and SQL access patterns, including formats such as TFRecord and SequenceFile.
Written by the indexing model from the issue text.
Assessment
- Domain
- data-engineering
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100