[
https://issues.apache.org/jira/browse/SPARK-57321?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Akshat Shenoi updated SPARK-57321:
----------------------------------
Description:
SPARK-57135 added opt-in reading of CSV files packaged in tar archives (.tar,
.tar.gz, .tgz), but only with an explicit schema — schema inference was out of
scope, and inferring without a schema errors (UNABLE_TO_INFER_SCHEMA).
This follow-up adds schema inference for tar archives, so
spark.read.csv("data.tar") (with spark.sql.files.archive.reader.enabled=true)
infers a schema instead of erroring, matching how a directory of the same CSV
files is inferred:
- CSVDataSource.inferSchema streams each archive's entries through the existing
ArchiveReader (never unpacking to disk), tokenizes each entry like a standalone
CSV file (dropping its header row when header=true), and feeds all entries'
rows into a single CSVInferSchema pass keyed on the first entry's header — the
same first-header, type-widening model used for a multi-file CSV read.
- When archives and loose CSV files are read together, the two inferred schemas
are merged positionally with CSV-aware type widening.
- ignoreCorruptFiles / ignoreMissingFiles are honored at archive granularity,
matching the loose-file path.
- Reuses the spark.sql.files.archive.reader.enabled config from SPARK-57135; no
new config.
Scope: CSV over tar, building on SPARK-57135. Inference for other file formats
(JSON, text, XML) follows their respective read support.
Tests: directory parity, all archive formats agree, corrupt-archive skip among
good ones, cross-entry type widening, and mixed archive + loose-file inference.
was:
Spark cannot currently read CSV files packaged inside tar archives (.tar,
.tar.gz, .tgz); users must unpack them externally first.
This adds opt-in support (spark.sql.files.archive.reader.enabled, default
false) for reading such archives through the CSV data source by streaming each
entry through the CSV parser, without materializing entries to local disk:
* A streaming ArchiveReader opens the tar once and yields one bounded
InputStream per entry, advancing lazily so memory
stays bounded regardless of archive size. Directories and dot-prefixed
entries are skipped. .tar.gz is decompressed via
Hadoop's codec factory; .tgz is gunzipped explicitly. ArchiveReader is an
abstract base (TarArchiveReader is the only
implementation today), so other archive formats can be added as additive
subclasses.
* CSVFileFormat treats archives as non-splittable (one split per archive) and
streams each entry through UnivocityParser,
handling each entry as a standalone CSV file (headers, multiLine, delimiters,
column pruning).
Scope: CSV reads over tar only. Schema inference from archives, and other file
formats (e.g. JSON, text, XML), are left to follow-ups. Streaming supports
formats parseable sequentially; formats needing random access (Parquet/ORC
footers) cannot stream from a tar and are out of scope.
> [SQL] Support schema inference of CSV files inside tar archives
> ---------------------------------------------------------------
>
> Key: SPARK-57321
> URL: https://issues.apache.org/jira/browse/SPARK-57321
> Project: Spark
> Issue Type: New Feature
> Components: SQL
> Affects Versions: 4.3.0
> Reporter: Akshat Shenoi
> Priority: Major
> Labels: pull-request-available
>
> SPARK-57135 added opt-in reading of CSV files packaged in tar archives (.tar,
> .tar.gz, .tgz), but only with an explicit schema — schema inference was out
> of scope, and inferring without a schema errors (UNABLE_TO_INFER_SCHEMA).
> This follow-up adds schema inference for tar archives, so
> spark.read.csv("data.tar") (with spark.sql.files.archive.reader.enabled=true)
> infers a schema instead of erroring, matching how a directory of the same CSV
> files is inferred:
> - CSVDataSource.inferSchema streams each archive's entries through the
> existing ArchiveReader (never unpacking to disk), tokenizes each entry like a
> standalone CSV file (dropping its header row when header=true), and feeds all
> entries' rows into a single CSVInferSchema pass keyed on the first entry's
> header — the same first-header, type-widening model used for a multi-file CSV
> read.
> - When archives and loose CSV files are read together, the two inferred
> schemas are merged positionally with CSV-aware type widening.
> - ignoreCorruptFiles / ignoreMissingFiles are honored at archive granularity,
> matching the loose-file path.
> - Reuses the spark.sql.files.archive.reader.enabled config from SPARK-57135;
> no new config.
> Scope: CSV over tar, building on SPARK-57135. Inference for other file
> formats (JSON, text, XML) follows their respective read support.
> Tests: directory parity, all archive formats agree, corrupt-archive skip
> among good ones, cross-entry type widening, and mixed archive + loose-file
> inference.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]