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

   ### What changes were proposed in this pull request?
   
   This PR adds the FILE type (SPARK-59132) to PySpark and Spark Connect, at 
the type and schema level only. FILE values are not covered.
   
   **PySpark** (`pyspark.sql.types`):
   - `FileTypeMode` with `EXTERNAL` and `UNKNOWN`, and 
`FileType(mode=FileTypeMode.UNKNOWN)` with `FileType.external()`. The mode is 
part of the type identity, as on the JVM.
   - `simpleString()` is `file external` or `file`, and `treeString()` shows 
the mode.
   - The JSON form is the JVM's. `jsonValue()` is `"file external"` or `"file 
unknown"`, and an external file directly in a struct field, or in an array or 
map of one, is the plain `"file"`. When reading, a plain `"file"` is external 
in a struct field and unknown elsewhere. This needs an `inStructField` flag in 
`_parse_datatype_json_value` and in `ArrayType.fromJson` / `MapType.fromJson`, 
as in `DataType.parseDataType` on the JVM.
   
   **Spark Connect protocol** (`types.proto`):
   
   ```proto
       // A reference to a file, with metadata describing the file.
       File file = 31;
     ...
     enum FileTypeMode {
       FILE_TYPE_MODE_UNSPECIFIED = 0;
       FILE_TYPE_MODE_UNKNOWN = 1;
       reserved 2;
       FILE_TYPE_MODE_EXTERNAL = 3;
     }
   
     message File {
       FileTypeMode mode = 1;
       uint32 type_variation_reference = 2;
     }
   ```
   
   Value 2 is reserved for another file mode. A mode other than `EXTERNAL`, 
including an unset one, is read as `UNKNOWN`. The Python stubs are regenerated 
with `dev/connect-gen-protos.sh`.
   
   **Spark Connect clients**: `DataTypeProtoConverter` (Scala) and 
`pyspark.sql.connect.types` (Python) convert `FileType` to and from 
`DataType.File`.
   
   ### Why are the changes needed?
   
   `FileType` exists on the JVM (SPARK-60092), but a schema with a FILE column 
cannot be read in PySpark, and Spark Connect cannot send the type. For example, 
`DataType.fromDDL("f FILE EXTERNAL")` and `df.schema` for such a column fail in 
PySpark today.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. PySpark gets `pyspark.sql.types.FileType` and `FileTypeMode`, and 
schemas with FILE columns can be read and written in PySpark and through Spark 
Connect. The FILE type is not released yet and is enabled by 
`spark.sql.fileType.enabled`, which is off by default.
   
   ### How was this patch tested?
   
   New tests:
   - `test_types.DataTypeTests`: the type, its string and JSON forms and the 
mode check (`test_file_type`), JSON parsing in and outside struct fields, 
arrays and maps (`test_file_type_json`), and a field with both a collated 
string and a file (`test_file_type_json_with_collations`).
   - `test_types.TypesTestsMixin.test_file_type_from_ddl`: DDL parsing, in 
classic and in Spark Connect (`test_parity_types`).
   - `test_types.TypesTests.test_file_type_json_matches_jvm`: the JSON from 
Python and from the JVM is the same, and each reads the other's.
   - `test_connect_plan.test_file_datatype_conversion` and 
`LiteralExpressionProtoConverterSuite`: proto round trips, and an unset mode 
read as `UNKNOWN`.
   
   Ran `pyspark.sql.tests.test_types`, 
`pyspark.sql.tests.connect.test_parity_types`, the type conversion tests in 
`test_connect_plan` and `LiteralExpressionProtoConverterSuite`.
   
   ### 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