@@ -23,7 +23,10 @@ use serde::{Deserialize, Serialize};
23
23
use std:: str;
24
24
25
25
use arrow_schema:: { DataType , Field , Schema , TimeUnit } ;
26
- use std:: { collections:: { HashMap , HashSet } , sync:: Arc } ;
26
+ use std:: {
27
+ collections:: { HashMap , HashSet } ,
28
+ sync:: Arc ,
29
+ } ;
27
30
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
28
31
pub struct StaticSchema {
29
32
fields : Vec < SchemaFields > ,
@@ -91,7 +94,6 @@ pub fn convert_static_schema_to_arrow_schema(
91
94
let mut existing_field_names: HashSet < String > = HashSet :: new ( ) ;
92
95
93
96
for mut field in static_schema. fields {
94
-
95
97
validate_field_names ( & field. name , & mut existing_field_names) ?;
96
98
if !time_partition. is_empty ( ) && field. name == time_partition {
97
99
time_partition_exists = true ;
@@ -144,7 +146,6 @@ pub fn convert_static_schema_to_arrow_schema(
144
146
fn add_parseable_fields_to_static_schema (
145
147
parsed_schema : ParsedSchema ,
146
148
) -> Result < Arc < Schema > , AnyError > {
147
-
148
149
let mut schema: Vec < Arc < Field > > = Vec :: new ( ) ;
149
150
for field in parsed_schema. fields . iter ( ) {
150
151
let field = Field :: new ( field. name . clone ( ) , field. data_type . clone ( ) , field. nullable ) ;
@@ -183,8 +184,10 @@ fn default_dict_is_ordered() -> bool {
183
184
false
184
185
}
185
186
186
- fn validate_field_names ( field_name : & str , existing_fields : & mut HashSet < String > ) -> Result < ( ) , AnyError > {
187
-
187
+ fn validate_field_names (
188
+ field_name : & str ,
189
+ existing_fields : & mut HashSet < String > ,
190
+ ) -> Result < ( ) , AnyError > {
188
191
if field_name. is_empty ( ) {
189
192
return Err ( anyhow ! ( "field names should not be empty" ) ) ;
190
193
}
@@ -195,3 +198,21 @@ fn validate_field_names(field_name: &str, existing_fields: &mut HashSet<String>)
195
198
196
199
Ok ( ( ) )
197
200
}
201
+
202
+ #[ cfg( test) ]
203
+ mod tests {
204
+ use super :: * ;
205
+ use std:: collections:: HashSet ;
206
+ #[ test]
207
+ fn empty_field_names ( ) {
208
+ let mut existing_field_names: HashSet < String > = HashSet :: new ( ) ;
209
+ assert ! ( validate_field_names( "" , & mut existing_field_names) . is_err( ) ) ;
210
+ }
211
+
212
+ #[ test]
213
+ fn duplicate_field_names ( ) {
214
+ let mut existing_field_names: HashSet < String > = HashSet :: new ( ) ;
215
+ let _ = validate_field_names ( "test_field" , & mut existing_field_names) ;
216
+ assert ! ( validate_field_names( "test_field" , & mut existing_field_names) . is_err( ) ) ;
217
+ }
218
+ }
0 commit comments