diff --git a/arrow-pg/src/datatypes.rs b/arrow-pg/src/datatypes.rs index 6ec61e5..7af25f1 100644 --- a/arrow-pg/src/datatypes.rs +++ b/arrow-pg/src/datatypes.rs @@ -35,12 +35,15 @@ pub fn into_pg_type(arrow_type: &DataType) -> PgWireResult { DataType::Time32(_) | DataType::Time64(_) => Type::TIME, DataType::Date32 | DataType::Date64 => Type::DATE, DataType::Interval(_) => Type::INTERVAL, - DataType::Binary | DataType::FixedSizeBinary(_) | DataType::LargeBinary => Type::BYTEA, + DataType::Binary + | DataType::FixedSizeBinary(_) + | DataType::LargeBinary + | DataType::BinaryView => Type::BYTEA, DataType::Float16 | DataType::Float32 => Type::FLOAT4, DataType::Float64 => Type::FLOAT8, DataType::Decimal128(_, _) => Type::NUMERIC, DataType::Utf8 => Type::VARCHAR, - DataType::LargeUtf8 => Type::TEXT, + DataType::LargeUtf8 | DataType::Utf8View => Type::TEXT, DataType::List(field) | DataType::FixedSizeList(field, _) | DataType::LargeList(field) => { match field.data_type() { DataType::Boolean => Type::BOOL_ARRAY, @@ -58,11 +61,14 @@ pub fn into_pg_type(arrow_type: &DataType) -> PgWireResult { DataType::Time32(_) | DataType::Time64(_) => Type::TIME_ARRAY, DataType::Date32 | DataType::Date64 => Type::DATE_ARRAY, DataType::Interval(_) => Type::INTERVAL_ARRAY, - DataType::FixedSizeBinary(_) | DataType::Binary => Type::BYTEA_ARRAY, + DataType::FixedSizeBinary(_) + | DataType::Binary + | DataType::LargeBinary + | DataType::BinaryView => Type::BYTEA_ARRAY, DataType::Float16 | DataType::Float32 => Type::FLOAT4_ARRAY, DataType::Float64 => Type::FLOAT8_ARRAY, DataType::Utf8 => Type::VARCHAR_ARRAY, - DataType::LargeUtf8 => Type::TEXT_ARRAY, + DataType::LargeUtf8 | DataType::Utf8View => Type::TEXT_ARRAY, struct_type @ DataType::Struct(_) => Type::new( Type::RECORD_ARRAY.name().into(), Type::RECORD_ARRAY.oid(), @@ -78,7 +84,6 @@ pub fn into_pg_type(arrow_type: &DataType) -> PgWireResult { } } } - DataType::Utf8View => Type::TEXT, DataType::Dictionary(_, value_type) => into_pg_type(value_type)?, DataType::Struct(fields) => { let name: String = fields diff --git a/arrow-pg/src/encoder.rs b/arrow-pg/src/encoder.rs index 9b3b930..e6cb63f 100644 --- a/arrow-pg/src/encoder.rs +++ b/arrow-pg/src/encoder.rs @@ -143,6 +143,15 @@ fn get_utf8_view_value(arr: &Arc, idx: usize) -> Option<&str> { }) } +fn get_binary_view_value(arr: &Arc, idx: usize) -> Option<&[u8]> { + (!arr.is_null(idx)).then(|| { + arr.as_any() + .downcast_ref::() + .unwrap() + .value(idx) + }) +} + fn get_utf8_value(arr: &Arc, idx: usize) -> Option<&str> { (!arr.is_null(idx)).then(|| { arr.as_any() @@ -161,12 +170,15 @@ fn get_large_utf8_value(arr: &Arc, idx: usize) -> Option<&str> { }) } -fn get_binary_value(arr: &Arc, idx: usize) -> Option<&[u8]> { +fn get_binary_value(arr: &Arc, idx: usize) -> Option { (!arr.is_null(idx)).then(|| { - arr.as_any() - .downcast_ref::() - .unwrap() - .value(idx) + String::from_utf8_lossy( + arr.as_any() + .downcast_ref::() + .unwrap() + .value(idx), + ) + .to_string() }) } @@ -330,6 +342,11 @@ pub fn encode_value( type_, format, )?, + DataType::BinaryView => encoder.encode_field_with_type_and_format( + &get_binary_view_value(arr, idx), + type_, + format, + )?, DataType::LargeUtf8 => encoder.encode_field_with_type_and_format( &get_large_utf8_value(arr, idx), type_,