@@ -32,6 +32,7 @@ use crate::protobuf::{
32
32
OptimizedLogicalPlanType , OptimizedPhysicalPlanType , PlaceholderNode , RollupNode ,
33
33
} ;
34
34
use arrow:: {
35
+ array:: ArrayRef ,
35
36
datatypes:: {
36
37
DataType , Field , IntervalMonthDayNanoType , IntervalUnit , Schema , SchemaRef ,
37
38
TimeUnit , UnionMode ,
@@ -1159,54 +1160,15 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue {
1159
1160
}
1160
1161
// ScalarValue::List and ScalarValue::FixedSizeList are serialized using
1161
1162
// Arrow IPC messages as a single column RecordBatch
1162
- ScalarValue :: List ( arr)
1163
- | ScalarValue :: LargeList ( arr)
1164
- | ScalarValue :: FixedSizeList ( arr) => {
1163
+ ScalarValue :: List ( arr) => {
1164
+ encode_scalar_list_value ( arr. to_owned ( ) as ArrayRef , val)
1165
+ }
1166
+ ScalarValue :: LargeList ( arr) => {
1165
1167
// Wrap in a "field_name" column
1166
- let batch = RecordBatch :: try_from_iter ( vec ! [ (
1167
- "field_name" ,
1168
- arr. to_owned( ) ,
1169
- ) ] )
1170
- . map_err ( |e| {
1171
- Error :: General ( format ! ( "Error creating temporary batch while encoding ScalarValue::List: {e}" ) )
1172
- } ) ?;
1173
-
1174
- let gen = IpcDataGenerator { } ;
1175
- let mut dict_tracker = DictionaryTracker :: new ( false ) ;
1176
- let ( _, encoded_message) = gen
1177
- . encoded_batch ( & batch, & mut dict_tracker, & Default :: default ( ) )
1178
- . map_err ( |e| {
1179
- Error :: General ( format ! (
1180
- "Error encoding ScalarValue::List as IPC: {e}"
1181
- ) )
1182
- } ) ?;
1183
-
1184
- let schema: protobuf:: Schema = batch. schema ( ) . try_into ( ) ?;
1185
-
1186
- let scalar_list_value = protobuf:: ScalarListValue {
1187
- ipc_message : encoded_message. ipc_message ,
1188
- arrow_data : encoded_message. arrow_data ,
1189
- schema : Some ( schema) ,
1190
- } ;
1191
-
1192
- match val {
1193
- ScalarValue :: List ( _) => Ok ( protobuf:: ScalarValue {
1194
- value : Some ( protobuf:: scalar_value:: Value :: ListValue (
1195
- scalar_list_value,
1196
- ) ) ,
1197
- } ) ,
1198
- ScalarValue :: LargeList ( _) => Ok ( protobuf:: ScalarValue {
1199
- value : Some ( protobuf:: scalar_value:: Value :: LargeListValue (
1200
- scalar_list_value,
1201
- ) ) ,
1202
- } ) ,
1203
- ScalarValue :: FixedSizeList ( _) => Ok ( protobuf:: ScalarValue {
1204
- value : Some ( protobuf:: scalar_value:: Value :: FixedSizeListValue (
1205
- scalar_list_value,
1206
- ) ) ,
1207
- } ) ,
1208
- _ => unreachable ! ( ) ,
1209
- }
1168
+ encode_scalar_list_value ( arr. to_owned ( ) as ArrayRef , val)
1169
+ }
1170
+ ScalarValue :: FixedSizeList ( arr) => {
1171
+ encode_scalar_list_value ( arr. to_owned ( ) as ArrayRef , val)
1210
1172
}
1211
1173
ScalarValue :: Date32 ( val) => {
1212
1174
create_proto_scalar ( val. as_ref ( ) , & data_type, |s| Value :: Date32Value ( * s) )
@@ -1723,3 +1685,47 @@ fn create_proto_scalar<I, T: FnOnce(&I) -> protobuf::scalar_value::Value>(
1723
1685
1724
1686
Ok ( protobuf:: ScalarValue { value : Some ( value) } )
1725
1687
}
1688
+
1689
+ fn encode_scalar_list_value (
1690
+ arr : ArrayRef ,
1691
+ val : & ScalarValue ,
1692
+ ) -> Result < protobuf:: ScalarValue , Error > {
1693
+ let batch = RecordBatch :: try_from_iter ( vec ! [ ( "field_name" , arr) ] ) . map_err ( |e| {
1694
+ Error :: General ( format ! (
1695
+ "Error creating temporary batch while encoding ScalarValue::List: {e}"
1696
+ ) )
1697
+ } ) ?;
1698
+
1699
+ let gen = IpcDataGenerator { } ;
1700
+ let mut dict_tracker = DictionaryTracker :: new ( false ) ;
1701
+ let ( _, encoded_message) = gen
1702
+ . encoded_batch ( & batch, & mut dict_tracker, & Default :: default ( ) )
1703
+ . map_err ( |e| {
1704
+ Error :: General ( format ! ( "Error encoding ScalarValue::List as IPC: {e}" ) )
1705
+ } ) ?;
1706
+
1707
+ let schema: protobuf:: Schema = batch. schema ( ) . try_into ( ) ?;
1708
+
1709
+ let scalar_list_value = protobuf:: ScalarListValue {
1710
+ ipc_message : encoded_message. ipc_message ,
1711
+ arrow_data : encoded_message. arrow_data ,
1712
+ schema : Some ( schema) ,
1713
+ } ;
1714
+
1715
+ match val {
1716
+ ScalarValue :: List ( _) => Ok ( protobuf:: ScalarValue {
1717
+ value : Some ( protobuf:: scalar_value:: Value :: ListValue ( scalar_list_value) ) ,
1718
+ } ) ,
1719
+ ScalarValue :: LargeList ( _) => Ok ( protobuf:: ScalarValue {
1720
+ value : Some ( protobuf:: scalar_value:: Value :: LargeListValue (
1721
+ scalar_list_value,
1722
+ ) ) ,
1723
+ } ) ,
1724
+ ScalarValue :: FixedSizeList ( _) => Ok ( protobuf:: ScalarValue {
1725
+ value : Some ( protobuf:: scalar_value:: Value :: FixedSizeListValue (
1726
+ scalar_list_value,
1727
+ ) ) ,
1728
+ } ) ,
1729
+ _ => unreachable ! ( ) ,
1730
+ }
1731
+ }
0 commit comments