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
{{ message }}
Repository navigation
ScalarUDFs created using datafusion.udf() do not propagate extension type metadata #1172
When creating a Python/Pyarrow UDF, extension types and arrays aren't propagated from the output of one to the input of another.
To Reproduce
fromuuidimportUUIDimportdatafusionimportpyarrowaspa@datafusion.udf([pa.string()], pa.uuid(), "stable")defuuid_from_string(uuid_string):
returnpa.array((UUID(s).bytesforsinuuid_string.to_pylist()), pa.uuid())
@datafusion.udf([pa.uuid()], pa.int64(), "stable")defuuid_version(uuid):
returnpa.array(s.versionforsinuuid.to_pylist())
defmain():
ctx=datafusion.SessionContext()
batch=pa.record_batch({"idx": pa.array(range(100))})
tab= (
ctx.create_dataframe([[batch]])
.with_column("uuid_string", datafusion.functions.uuid())
.with_column("uuid", uuid_from_string(datafusion.col("uuid_string")))
.with_column("uuid_version", uuid_version(datafusion.col("uuid")))
)
#> AttributeError("'bytes' object has no attribute 'version'"), since metadata doesn't make it throughprint(tab)
if__name__=="__main__":
main()
Expected behavior
The pyarrow.Array that is returned from uuid_from_string() is a UuidArray:
pa.array([uuid4().bytes], pa.uuid())
#> <pyarrow.lib.UuidArray object at 0x120292350>
However, the pyarrow.Array that is passed to uuid_version() is a FixedSizeBinary array. I would have expected the array passed here to have the pa.uuid() type.
Additional context
It seems like create_udf() is the mechanism being used to create the UDF; however, this doesn't propagate field information I believe since everything goes through the DataType:
Activity