dejankrak-db opened a new pull request, #60531: URL: https://github.com/apache/spark/pull/60531
### What changes were proposed in this pull request? This PR implements Phase 1b (generic row access) of the Types Framework (SPARK-53504). It lets a framework type that is stored as a struct, an array or a map work through Spark's row infrastructure, in both the interpreted and the whole-stage codegen paths, without per-type changes to that infrastructure. **`TypeOps.rowRepresentationType: Option[DataType]`.** A framework type with a complex physical layout returns an equivalent built-in type, such as `StructType(fields)` for a struct-backed type. Each dispatch site resolves it and recurses through its existing code path for that built-in type. Primitive-backed types such as `TimeType` return `None` (the default) and keep their current paths. The framework type keeps its identity in schemas, expressions and error messages; the representation type is only a dispatch hint for row internals. The dispatch sites that resolve it: - `CodeGenerator`: `addBufferedState`, `genEqual`, `genComp`, `setColumn` and the column vector read in `getValueFromVector`. - `GenerateUnsafeProjection`: `canSupport` and `writeElement`. The single `writeNullable` call is not used for these types, as they are written through their representation. - `GenerateSafeProjection.convertToSafe`. - `MapObjects` and `CatalystToExternalMap`, which copy unsafe-backed lambda results. - `ColumnarRow` and `ColumnarBatchRow`: the constructor accepts a struct-backed framework type, and `get()` reads one through `SpecializedGettersReader`. This keeps the existing error for types that are not recognized. **`TypeOps.getElementSize: Int`.** This is the size of a value in the fixed region of `UnsafeArrayData`, used by `InterpretedUnsafeProjection` for arrays and maps of a framework type. `TimeTypeOps` returns 8 (a `Long` stored in place), and the nanosecond timestamp ops return 8 (an offset and size pointer to the 16-byte payload), the sizes they already have. The `TypeOps` doc now states the physical type contract: `getPhysicalType` returns the raw physical type (for example `PhysicalStructType(fields)`), which the `PhysicalDataType`-based readers and writers already handle. A test-only marker, `private[ops] trait TestableFrameworkType`, lets a test type register its own `TypeOps` in `TypeOps.apply` without global mutable state. ### Why are the changes needed? Without this, adding a struct-backed type (for example FILE, SPARK-59132) needs the same per-type boilerplate as `VariantType`: a getter in `SpecializedGetters`, `UnsafeRow`, `ColumnVector` and `ColumnarRow`, a writer in `UnsafeWriter`, and a branch in each codegen dispatcher. That is around 16 files for each new type. Other designs considered: - **A `PhysicalDataType` fallback at each site.** This adds a second dispatch at every site, and every site changes when a physical type is added. - **Rewriting all row dispatch on `PhysicalDataType`.** This changes the code paths of every existing type, not only framework types. - **Per-type codegen getters and setters on `TypeOps`** (as in apache/spark#56199). This moves the boilerplate into each type's ops rather than removing it. - **`UserDefinedType`.** `sqlType` gives the same recursion, but a UDT loses its type identity in schemas, JSON, protocols and error messages. `rowRepresentationType` is the identity-preserving equivalent of a UDT's `sqlType`, limited to row infrastructure. It also follows the `TypeOps(dt).map(...).getOrElse(...)` pattern of Phases 1a and 1c. ### Does this PR introduce _any_ user-facing change? No. No built-in type returns a row representation yet, and the existing types keep their behavior. ### How was this patch tested? Added `StructBackedFrameworkTypeSuite`. It uses a test-only struct-backed type with a nullable string field and a long field, and covers: - `PhysicalDataType` resolution and literal validation. - Interpreted read (`SpecializedGettersReader`, `InternalRow.getAccessor`) and write (`InterpretedUnsafeProjection`), including null values. - Codegen write with `GenerateUnsafeProjection`, including null values and a null field. - Arrays and map values of the type, in both paths. - `GenerateSafeProjection`, `GenerateOrdering` (`genComp`) and `GenerateMutableProjection` (`setColumn`). Also ran `TimeTypeOpsSuite`, `TimestampNanosTypeOpsSuite`, the `expressions.codegen` suites, `OrderingSuite`, `ObjectExpressionsSuite`, `UnsafeRowConverterSuite`, `ColumnarBatchSuite`, `ColumnVectorSuite` and `WholeStageCodegenSuite`. ### 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]
