Closed tomasfarias closed 9 months ago
Just as I was starting to write a dictionary to map fields to encoders, I noticed that the infer_encoders
method exists. Completely missed it, it's my bad.
My problem can be solved with:
inferred = {field.name: pgpq.ArrowToPostgresBinaryEncoder.infer_encoder(field) for field in rec.schema}
encoder = pgpq.ArrowToPostgresBinaryEncoder.new_with_encoders(rec.schema, inferred | enc)
Happy to contribute samples if they can improve discovery of this method. Otherwise happy to close this issue.
Samples/documentation would be great!
I think we're all set here right @tomasfarias ? If so let's close the issue 🥳
Happy to close! Looking forward to the development of pgpq, thank you @adriangb
Feel free to leave any other feedback on API or otherwise.
Amazing library, thank you for your work. I'm using it to stream Apache Arrow batch records into PG in binary format, which, I assume, is the main use case.
I have some string fields that I wish to encode as JSONB. I'm following samples from other issues like https://github.com/adriangb/pgpq/issues/21.
My problem is that my records have many fields, and if using
new_with_encoders
I have to set an encoder for every field, even if all fields except the string to JSONB fields could just use the default.Example:
Fails with:
Even for well-known fields, having to set each encoder for fields that could just resolve to the default (as dictated in this match expression)
Expected:
An
ArrowToPostgresBinaryEncoder
is initialized with the encoder I set forjsonb_arr
and default encoders for other fields.Potential solution:
Extend
new_with_encoders
here to callbuild_encoders
on each schema field that doesn't have an encoder set in the py dictionary.Happy to contribute a patch and samples if that seems to be the way to go.