@@ -3,11 +3,7 @@ use crate::builder::plan::AnalyzedValueMapping;
33use super :: spec:: * ;
44use anyhow:: Result ;
55use serde:: { Deserialize , Serialize } ;
6- use std:: {
7- collections:: BTreeMap ,
8- ops:: Deref ,
9- sync:: { Arc , LazyLock } ,
10- } ;
6+ use std:: { collections:: BTreeMap , ops:: Deref , sync:: Arc } ;
117
128#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
139pub struct VectorTypeSchema {
@@ -127,21 +123,20 @@ pub struct CollectionSchema {
127123impl CollectionSchema {
128124 pub fn has_key ( & self ) -> bool {
129125 match self . kind {
130- CollectionKind :: Collection => false ,
131- CollectionKind :: Table | CollectionKind :: List => true ,
126+ CollectionKind :: Table => true ,
127+ CollectionKind :: Collection | CollectionKind :: List => false ,
132128 }
133129 }
134130
135131 pub fn key_type ( & self ) -> Option < & EnrichedValueType > {
136132 match self . kind {
137- CollectionKind :: Collection => None ,
138133 CollectionKind :: Table => self
139134 . row
140135 . fields
141136 . first ( )
142137 . as_ref ( )
143138 . map ( |field| & field. value_type ) ,
144- CollectionKind :: List => Some ( & LIST_INDEX_FIELD . value_type ) ,
139+ CollectionKind :: Collection | CollectionKind :: List => None ,
145140 }
146141 }
147142
@@ -172,89 +167,21 @@ impl std::fmt::Display for CollectionSchema {
172167 }
173168}
174169
175- pub const KEY_FIELD_NAME : & ' static str = "__key" ;
176- pub const VALUE_FIELD_NAME : & ' static str = "__value" ;
177- pub const LIST_INDEX_FIELD_NAME : & ' static str = "__index" ;
178-
179- pub static LIST_INDEX_FIELD : LazyLock < FieldSchema > = LazyLock :: new ( || FieldSchema {
180- name : LIST_INDEX_FIELD_NAME . to_string ( ) ,
181- value_type : EnrichedValueType {
182- typ : ValueType :: Basic ( BasicValueType :: Int64 ) ,
183- nullable : false ,
184- attrs : Default :: default ( ) ,
185- } ,
186- } ) ;
187-
188170impl CollectionSchema {
189- pub fn new_collection ( value_name : Option < String > , value : EnrichedValueType ) -> Self {
190- Self {
191- kind : CollectionKind :: Collection ,
192- row : StructSchema {
193- fields : Arc :: new ( vec ! [ FieldSchema {
194- name: value_name. unwrap_or_else( || VALUE_FIELD_NAME . to_string( ) ) ,
195- value_type: value,
196- } ] ) ,
197- } ,
198- collectors : Default :: default ( ) ,
199- }
200- }
201-
202- pub fn new_table (
203- key_name : Option < String > ,
204- key : EnrichedValueType ,
205- value_name : Option < String > ,
206- value : EnrichedValueType ,
207- ) -> Self {
171+ pub fn new ( kind : CollectionKind , fields : Vec < FieldSchema > ) -> Self {
208172 Self {
209- kind : CollectionKind :: Table ,
173+ kind,
210174 row : StructSchema {
211- fields : Arc :: new ( vec ! [
212- FieldSchema {
213- name: key_name. unwrap_or_else( || KEY_FIELD_NAME . to_string( ) ) ,
214- value_type: key,
215- } ,
216- FieldSchema {
217- name: value_name. unwrap_or_else( || VALUE_FIELD_NAME . to_string( ) ) ,
218- value_type: value,
219- } ,
220- ] ) ,
175+ fields : Arc :: new ( fields) ,
221176 } ,
222177 collectors : Default :: default ( ) ,
223178 }
224179 }
225180
226- pub fn new_list ( value_name : Option < String > , value : EnrichedValueType ) -> Self {
227- Self {
228- kind : CollectionKind :: List ,
229- row : StructSchema {
230- fields : Arc :: new ( vec ! [
231- LIST_INDEX_FIELD . clone( ) ,
232- FieldSchema {
233- name: value_name. unwrap_or_else( || VALUE_FIELD_NAME . to_string( ) ) ,
234- value_type: value,
235- } ,
236- ] ) ,
237- } ,
238- collectors : Default :: default ( ) ,
239- }
240- }
241-
242- pub fn is_table ( & self ) -> bool {
243- match self . kind {
244- CollectionKind :: Collection => false ,
245- CollectionKind :: Table | CollectionKind :: List => true ,
246- }
247- }
248-
249- pub fn is_list ( & self ) -> bool {
250- self . kind == CollectionKind :: List
251- }
252-
253181 pub fn key_field < ' a > ( & ' a self ) -> Option < & ' a FieldSchema > {
254- if self . is_table ( ) {
255- Some ( self . row . fields . first ( ) . unwrap ( ) )
256- } else {
257- None
182+ match self . kind {
183+ CollectionKind :: Table => Some ( self . row . fields . first ( ) . unwrap ( ) ) ,
184+ CollectionKind :: Collection | CollectionKind :: List => None ,
258185 }
259186 }
260187}
@@ -373,6 +300,13 @@ pub struct FieldSchema<DataType = ValueType> {
373300}
374301
375302impl FieldSchema {
303+ pub fn new ( name : impl ToString , value_type : EnrichedValueType ) -> Self {
304+ Self {
305+ name : name. to_string ( ) ,
306+ value_type,
307+ }
308+ }
309+
376310 pub fn without_attrs ( & self ) -> Self {
377311 Self {
378312 name : self . name . clone ( ) ,
0 commit comments