You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GH-891: Add ExtensionTypeWriterFactory to TransferPair (#892)
## What's Changed
This PR simplifies extension type writer creation by moving from a
factory-based pattern to a type-based pattern. Instead of passing
`ExtensionTypeWriterFactory` instances through multiple API layers,
extension types now provide their own writers via a new
`getNewFieldWriter()` method on `ArrowType.ExtensionType`.
- Added `getNewFieldWriter(ValueVector)` abstract method to
`ArrowType.ExtensionType`
- Removed `ExtensionTypeWriterFactory` interface and all implementations
- Removed factory parameters from `ComplexCopier`, `PromotableWriter`,
and `TransferPair` APIs
- Updated `UnionWriter` to support extension types (previously threw
`UnsupportedOperationException`)
- Simplified extension type implementations (`UuidType`, `OpaqueType`)
The factory pattern didn't scale well. Each new extension type required
creating a separate factory class and passing it through multiple API
layers. This was especially painful for external developers who had to
maintain two classes per extension type and manage factory parameters
everywhere.
The new approach follows the same pattern as `MinorType`, where each
type knows how to create its own writer. This reduces boilerplate,
simplifies the API, and makes it easier to implement custom extension
types outside arrow-java.
## Breaking Changes
- `ExtensionTypeWriterFactory` has been removed
- Extension types must now implement `getNewFieldWriter(ValueVector
vector)` method
- ExtensionHolders must implement `type()` which returns the
`ExtensionType` for that Holder
- (Writers are obtained directly from the extension type, not from a
factory)
### Migration Guide
- _Extension types must now implement `getNewFieldWriter(ValueVector
vector)` method_
```java
public class UuidType extends ExtensionType {
...
@OverRide
public FieldWriter getNewFieldWriter(ValueVector vector) {
return new UuidWriterImpl((UuidVector) vector);
}
...
}
```
- _ExtensionHolders must implement `type()` which returns the
`ExtensionType` for that Holder_
```java
public class UuidHolder extends ExtensionHolder {
...
@OverRide
public ArrowType type() {
return UuidType.INSTANCE;
}
```
- How to use Extension Writers?
**Before:**
```java
writer.extension(UuidType.INSTANCE);
writer.addExtensionTypeWriterFactory(extensionTypeWriterFactory);
writer.writeExtension(value);
```
**After:**
```java
writer.extension(UuidType.INSTANCE);
writer.writeExtension(value);
```
- Also `copyAsValue` does not need to provide the factory anymore.
Closes#891 .
thrownewIllegalArgumentException(String.format("You tried to read a [%s] type when you are using a field reader of type [%s].", name, this.getClass().getSimpleName()));
Copy file name to clipboardExpand all lines: vector/src/main/codegen/templates/AbstractFieldWriter.java
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -107,14 +107,17 @@ public void endEntry() {
107
107
thrownewIllegalStateException(String.format("You tried to end a map entry when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
0 commit comments