Repository navigation
GH-34884: [Python]: Support pickling pyarrow.dataset PartitioningFactory objects - #36550
Conversation
…ngFactory objects
westonpace
left a comment
There was a problem hiding this comment.
As long as this isn't actually running discovery I don't see a problem. I think I see what you mean about an awkward pattern but it should work. Seems like the biggest downside is that these _constructor_filename_partitioning_factory become visible symbols that users should ignore?
|
|
||
|
|
||
| def _constructor_hive_partitioning_factory(*args): | ||
| return HivePartitioning.discover(*args) |
There was a problem hiding this comment.
Does this method actually run discovery or does it just create the factory?
There was a problem hiding this comment.
It just creates the factory
| if c_factory.get() == nullptr: | ||
| return None | ||
| return PartitioningFactory.wrap(c_factory) | ||
| return PartitioningFactory.wrap(c_factory, None, None) |
There was a problem hiding this comment.
Won't this mean that this object can't be pickled?
There was a problem hiding this comment.
Yes, that's correct.
But this is only if you first create an options object with a factory, and then decide the pickle the factory accessed from the options object instead of the factory you created to start with:
partitioning_factory = ds.HivePartitioning.discover(..)
options = ds.FileSystemFactoryOptions(partitioning=partitioning_factory)
pickle.dumps(options.partitioning_factory) # instead of pickle.dumps(partitioning_factory)So in practice, if you run into this, you can always pickle the original factory object you created (as there is no other way to get such an object than creating it yourself, i.e. the options object only has it when you passed it manually).
We could support pickling those options-accessed factory objects (and ideally that would also be the case, for consistency / avoiding confusion), but the current code only stores the C++ factory object on the options class and recreates the python factory object from the C++ object, and then we don't know anymore how this C++ object was created. We could add some workaround to also store the python factory object, but I am not sure this is worth the effort, given that as a user you can always pickle the original object (explanation above)
There was a problem hiding this comment.
Ok, I agree this is probably not needed. I don't think many users create FileSystemFactoryOptions (I don't think I even knew it existed :)
| if c_factory.get() == nullptr: | ||
| return None | ||
| return PartitioningFactory.wrap(c_factory) | ||
| return PartitioningFactory.wrap(c_factory, None, None) |
I prefixed them with an underscore, so by default those shouldn't be visible (eg with tab completion) |
|
I just noticed that there is a minor lint failure in the CI. Then I think it's good to go. |
|
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit a63ead7. There were 3 benchmark results indicating a performance regression:
The full Conbench report has more details. |
Rationale for this change
#36462 already added support for pickling Partitioning objects, but not yet the PartitioningFactory objects.
The problem for PartitioningFactory is that we currently don't really expose the full class hierarchy in python, just the base class PartitioningFactory. We also don't expose creating those factory objects, except through the
discovermethods of the Partitioning classes.I think it would be nice to keep this minimal binding, but that means if we want to make them serializable with pickle, we need another way to do that (and if we don't want to add custom code for serialization on the C++ side).
In this PR, I went for the route of essentially storing the constructor (the discover static method) and the arguments that were passed to the constructor, on the factory object, so we can use this info for pickling. Not the nicest code, but the simplest solution I could think of.
Are these changes tested?
Yes