44mod reader;
55pub mod writer;
66
7- use std:: sync:: Arc ;
7+ use std:: env;
8+ use std:: sync:: { Arc , LazyLock } ;
89
9- use vortex_array:: { ArrayContext , DeserializeMetadata , EmptyMetadata } ;
10+ use vortex_array:: { ArrayContext , DeserializeMetadata , ProstMetadata } ;
11+ use vortex_buffer:: ByteBuffer ;
1012use vortex_dtype:: DType ;
1113use vortex_error:: { VortexResult , vortex_bail, vortex_panic} ;
1214
@@ -17,12 +19,15 @@ use crate::{
1719 LayoutChildType , LayoutEncodingRef , LayoutId , LayoutReaderRef , LayoutRef , VTable , vtable,
1820} ;
1921
22+ static FLAT_LAYOUT_INLINE_ARRAY_NODE : LazyLock < bool > =
23+ LazyLock :: new ( || env:: var ( "FLAT_LAYOUT_INLINE_ARRAY_NODE" ) . is_ok ( ) ) ;
24+
2025vtable ! ( Flat ) ;
2126
2227impl VTable for FlatVTable {
2328 type Layout = FlatLayout ;
2429 type Encoding = FlatLayoutEncoding ;
25- type Metadata = EmptyMetadata ;
30+ type Metadata = ProstMetadata < FlatLayoutMetadata > ;
2631
2732 fn id ( _encoding : & Self :: Encoding ) -> LayoutId {
2833 LayoutId :: new_ref ( "vortex.flat" )
@@ -40,8 +45,10 @@ impl VTable for FlatVTable {
4045 & layout. dtype
4146 }
4247
43- fn metadata ( _layout : & Self :: Layout ) -> Self :: Metadata {
44- EmptyMetadata
48+ fn metadata ( layout : & Self :: Layout ) -> Self :: Metadata {
49+ ProstMetadata ( FlatLayoutMetadata {
50+ array_encoding_tree : layout. array_tree . as_ref ( ) . map ( |bytes| bytes. to_vec ( ) ) ,
51+ } )
4552 }
4653
4754 fn segment_ids ( layout : & Self :: Layout ) -> Vec < SegmentId > {
@@ -76,20 +83,24 @@ impl VTable for FlatVTable {
7683 _encoding : & Self :: Encoding ,
7784 dtype : & DType ,
7885 row_count : u64 ,
79- _metadata : & <Self :: Metadata as DeserializeMetadata >:: Output ,
86+ metadata : & <Self :: Metadata as DeserializeMetadata >:: Output ,
8087 segment_ids : Vec < SegmentId > ,
8188 _children : & dyn LayoutChildren ,
8289 ctx : ArrayContext ,
8390 ) -> VortexResult < Self :: Layout > {
8491 if segment_ids. len ( ) != 1 {
8592 vortex_bail ! ( "Flat layout must have exactly one segment ID" ) ;
8693 }
87- Ok ( FlatLayout {
94+ Ok ( FlatLayout :: new_with_metadata (
8895 row_count,
89- dtype : dtype . clone ( ) ,
90- segment_id : segment_ids[ 0 ] ,
96+ dtype. clone ( ) ,
97+ segment_ids[ 0 ] ,
9198 ctx,
92- } )
99+ metadata
100+ . array_encoding_tree
101+ . as_ref ( )
102+ . map ( |v| ByteBuffer :: from ( v. clone ( ) ) ) ,
103+ ) )
93104 }
94105}
95106
@@ -102,6 +113,7 @@ pub struct FlatLayout {
102113 dtype : DType ,
103114 segment_id : SegmentId ,
104115 ctx : ArrayContext ,
116+ array_tree : Option < ByteBuffer > ,
105117}
106118
107119impl FlatLayout {
@@ -111,10 +123,36 @@ impl FlatLayout {
111123 dtype,
112124 segment_id,
113125 ctx,
126+ array_tree : None ,
127+ }
128+ }
129+
130+ pub fn new_with_metadata (
131+ row_count : u64 ,
132+ dtype : DType ,
133+ segment_id : SegmentId ,
134+ ctx : ArrayContext ,
135+ metadata : Option < ByteBuffer > ,
136+ ) -> Self {
137+ Self {
138+ row_count,
139+ dtype,
140+ segment_id,
141+ ctx,
142+ array_tree : metadata,
114143 }
115144 }
116145
117146 pub fn segment_id ( & self ) -> SegmentId {
118147 self . segment_id
119148 }
120149}
150+
151+ #[ derive( prost:: Message ) ]
152+ pub struct FlatLayoutMetadata {
153+ // We can optionally store the array encoding tree here to avoid needing to fetch the segment
154+ // to plan array deserialization.
155+ // This will be a `ArrayNode`.
156+ #[ prost( optional, bytes, tag = "1" ) ]
157+ pub array_encoding_tree : Option < Vec < u8 > > ,
158+ }
0 commit comments