adriangb commented on code in PR #7015:
URL: https://github.com/apache/arrow-rs/pull/7015#discussion_r1929594559
##########
arrow-json/src/writer/encoder.rs:
##########
@@ -24,11 +26,42 @@ use arrow_schema::{ArrowError, DataType, FieldRef};
use half::f16;
use lexical_core::FormattedSize;
use serde::Serializer;
-use std::io::Write;
#[derive(Debug, Clone, Default)]
pub struct EncoderOptions {
pub explicit_nulls: bool,
+ pub encoder_factory: Option<Arc<dyn EncoderFactory>>,
+}
+
+type EncoderFactoryResult<'a> =
+ Result<Option<(Box<dyn Encoder + 'a>, Option<NullBuffer>)>, ArrowError>;
+
+/// A trait to create custom encoders for specific data types.
+///
+/// This allows overriding the default encoders for specific data types,
+/// or adding new encoders for custom data types.
+pub trait EncoderFactory: std::fmt::Debug {
+ /// Make an encoder that if returned runs before all of the default
encoders.
+ /// This can be used to override how e.g. binary data is encoded so that
it is an encoded string or an array of integers.
+ fn make_default_encoder<'a>(
+ &self,
+ _array: &'a dyn Array,
+ _data_type: &DataType,
+ _options: &EncoderOptions,
+ ) -> EncoderFactoryResult<'a> {
+ Ok(None)
+ }
+
+ /// Make an encoder that if returned runs after all of the default
encoders.
+ /// If this method returns None then an error will be returned.
+ fn make_fallback_encoder<'a>(
Review Comment:
I'll drop it in favor of a single method, I think it should work for our use
case.
--
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]