dejankrak-db opened a new pull request, #60741:
URL: https://github.com/apache/spark/pull/60741

   ### What changes were proposed in this pull request?
   
   Slice 1 of the SPARK-59132 implementation plan: the physical representation 
and the value of FILE.
   
   **FileType in the Types Framework.** `FileTypeOps` (catalyst) and 
`FileTypeApiOps` (sql/api) register FileType. Its physical type is 
`PhysicalStructType(FileType.FIELDS)` (uri, offset, size, content_type, 
checksum, inline), so with the generic row access of SPARK-56076 its row 
representation is `FileType.asStruct`, and the row readers and writers, the 
projections and code generation handle it without per-type changes. The default 
literal is a reference with an empty uri.
   
   **FileRef.** The user-facing Java value class of FILE, in 
`org.apache.spark.sql.types`, with the nullable getters `uri`, `offset`, 
`size`, `contentType` and `checksum` from the SPIP, and `equals`, `hashCode` 
and `toString`. The SPIP keeps `inline` internal: a FileRef carries it, so that 
a value converts to a FileRef and back without loss, but its constructor and 
getter for it are package-private, reached through `private[sql] 
FileRefInternals`. The I/O methods (`open`, `asLocalFile`, `fromBytes`, 
`fromLocalFile`) come with slice 5.
   
   **Encoders.** `AgnosticEncoders.FileRefEncoder`, `Encoders.FILE` and an 
implicit encoder in `SQLImplicits`; `ScalaReflection` and `JavaTypeInference` 
map `FileRef` to FILE, so case classes and beans can hold one; `Row.getFile`. 
As for TIME, building the serializer or deserializer requires 
`spark.sql.fileType.enabled`.
   
   **Casts between modes.** A FILE casts and up-casts to a FILE of unknown 
mode, as the value does not change. The FileRef encoder needs this to read a 
FILE EXTERNAL column, for example `df.as[FileRef]`. A cast to FILE EXTERNAL is 
not allowed, so a FILE of unknown mode cannot be cast past the check on writing 
one to a table.
   
   **Cast to STRING.** The SPIP defines a cast of a FILE to STRING as reading 
its bytes (slice 4a), so `CAST(f AS STRING)`, also of a value with a nested 
FILE, now fails at analysis instead of rendering the struct.
   
   **Display.** `df.show()` and other uses of `ToPrettyString` render a FILE as 
its canonical JSON, 
`{"uri":...,"offset":...,"size":...,"content_type":...,"checksum":...,"inline":...}`
 without the null fields, in both the interpreted and the code generation 
paths. `ToStringBase` formats a struct-backed framework type with its 
catalyst-side ops, whose internal value is an InternalRow.
   
   **Column vectors and the columnar cache.** SPARK-56076 left column vectors 
to the first type that needs them. `WritableColumnVector` and 
`ConstantColumnVector` build one child vector per field for a framework type 
whose row representation is a struct, and `ColumnVectorUtils.populate`, 
`RowToColumnConverter`, and the cache (`ColumnType`, `ColumnBuilder`, 
`ColumnAccessor`, `InMemoryRelation`) handle it as that representation. They 
look it up through a new Java-friendly `TypeOps.rowRepresentationOrSelf`. 
Array- and map-backed framework types are not handled in column vectors yet.
   
   ### Why are the changes needed?
   
   FILE (SPARK-59132) has DDL, a JSON schema and restrictions, but no values. 
This adds its values, which the next slices build on: field access and casts 
(2), Parquet storage (3), byte access (4a) and the FileRef I/O API (5).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, behind `spark.sql.fileType.enabled`, which stays off by default:
   - A FILE value can be created, collected and shown, as a `FileRef` in 
Datasets, DataFrames, `Row.getFile`, case classes and beans.
   - `CAST(f AS STRING)` of a FILE fails at analysis, where it rendered the 
struct before. A FILE casts to a FILE of unknown mode.
   
   A Dataset of FileRef in the Spark Connect clients, Python, `to_json`, 
Parquet storage and field access are not supported yet.
   
   ### How was this patch tested?
   
   - New `FileTypeOpsSuite` (catalyst): the physical type and row 
representation, the default literal, conversions between FileRef and 
InternalRow (all fields, inline, no uri, nulls), `CatalystTypeConverters`, 
`SpecializedGettersReader`, interpreted and generated unsafe projections of a 
FILE column, null values and fields, arrays, map values and structs of FILE, 
the safe projection on a reused UnsafeRow, formatting and JSON escaping, 
FileRef equality and string form, the encoders of FileRef, of a case class with 
FileRef fields and of a Row, reading a FILE EXTERNAL column through the FileRef 
encoder, the encoder flag, and the casts.
   - New `FileTypeDatasetSuite` (sql/core): Datasets of FileRef and of a case 
class with FileRef fields, a DataFrame with a FILE EXTERNAL column read back as 
FileRef, `show` with and without whole-stage code generation, a bean with a 
FileRef property, a cached DataFrame, the rejected cast to STRING, and the flag.
   - `RowToColumnConverterSuite`: FILE columns, null values, null fields, an 
array of FILE and a struct with a FILE, in on-heap and off-heap vectors, read 
through `ColumnarBatchRow`.
   - `ColumnVectorUtilsSuite`: populating a constant FILE vector.
   - Also ran the `CastWithAnsiOn/Off` and `TryCast` suites, `DataTypeSuite`, 
`ExpressionEncoderSuite`, `EncoderResolutionSuite`, the `types.ops` suites, 
`ScalaReflectionSuite`, `JavaTypeInferenceSuite`, `ToPrettyStringSuite`, the 
`execution.vectorized` and `execution.columnar` suites, `CachedTableSuite` and 
`FileTypeRestrictionsSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
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]

Reply via email to