@@ -25,6 +25,12 @@ pub struct FieldMapping {
2525 node_field_name : Option < FieldName > ,
2626}
2727
28+ impl FieldMapping {
29+ fn get_node_field_name ( & self ) -> & FieldName {
30+ self . node_field_name . as_ref ( ) . unwrap_or ( & self . field_name )
31+ }
32+ }
33+
2834#[ derive( Debug , Deserialize ) ]
2935pub struct RelationshipEndSpec {
3036 label : String ,
@@ -133,7 +139,8 @@ impl GraphPool {
133139#[ derive( Debug , Clone ) ]
134140struct AnalyzedGraphFieldMapping {
135141 field_idx : usize ,
136- field_schema : FieldSchema ,
142+ field_name : String ,
143+ value_type : schema:: ValueType ,
137144}
138145
139146struct AnalyzedGraphFields {
@@ -203,6 +210,23 @@ fn field_values_to_bolt<'a>(
203210 Ok ( bolt_value)
204211}
205212
213+ fn mapped_field_values_to_bolt < ' a > (
214+ field_values : impl IntoIterator < Item = & ' a value:: Value > ,
215+ field_mappings : impl IntoIterator < Item = & ' a AnalyzedGraphFieldMapping > ,
216+ ) -> Result < BoltType > {
217+ let bolt_value = BoltType :: Map ( neo4rs:: BoltMap {
218+ value : std:: iter:: zip ( field_mappings, field_values)
219+ . map ( |( mapping, value) | {
220+ Ok ( (
221+ neo4rs:: BoltString :: new ( & mapping. field_name ) ,
222+ value_to_bolt ( value, & mapping. value_type ) ?,
223+ ) )
224+ } )
225+ . collect :: < Result < _ > > ( ) ?,
226+ } ) ;
227+ Ok ( bolt_value)
228+ }
229+
206230fn basic_value_to_bolt ( value : & BasicValue , schema : & BasicValueType ) -> Result < BoltType > {
207231 let bolt_value = match value {
208232 BasicValue :: Bytes ( v) => {
@@ -390,46 +414,46 @@ FINISH
390414 SRC_ID_PARAM ,
391415 value_to_bolt (
392416 & value. fields [ self . src_fields . key_field . field_idx ] ,
393- & self . src_fields . key_field . field_schema . value_type . typ ,
417+ & self . src_fields . key_field . value_type ,
394418 ) ?,
395419 )
396420 . param (
397421 TGT_ID_PARAM ,
398422 value_to_bolt (
399423 & value. fields [ self . tgt_fields . key_field . field_idx ] ,
400- & self . tgt_fields . key_field . field_schema . value_type . typ ,
424+ & self . tgt_fields . key_field . value_type ,
401425 ) ?,
402426 ) ;
403427 if !self . src_fields . value_fields . is_empty ( ) {
404428 insert_cypher = insert_cypher. param (
405429 SRC_PROPS_PARAM ,
406- field_values_to_bolt (
430+ mapped_field_values_to_bolt (
407431 self . src_fields
408432 . value_fields
409433 . iter ( )
410434 . map ( |f| & value. fields [ f. field_idx ] ) ,
411- self . src_fields . value_fields . iter ( ) . map ( |f| & f . field_schema ) ,
435+ self . src_fields . value_fields . iter ( ) ,
412436 ) ?,
413437 ) ;
414438 }
415439 if !self . tgt_fields . value_fields . is_empty ( ) {
416440 insert_cypher = insert_cypher. param (
417441 TGT_PROPS_PARAM ,
418- field_values_to_bolt (
442+ mapped_field_values_to_bolt (
419443 self . tgt_fields
420444 . value_fields
421445 . iter ( )
422446 . map ( |f| & value. fields [ f. field_idx ] ) ,
423- self . tgt_fields . value_fields . iter ( ) . map ( |f| & f . field_schema ) ,
447+ self . tgt_fields . value_fields . iter ( ) ,
424448 ) ?,
425449 ) ;
426450 }
427451 if !self . value_fields . is_empty ( ) {
428452 insert_cypher = insert_cypher. param (
429453 REL_PROPS_PARAM ,
430- field_values_to_bolt (
454+ mapped_field_values_to_bolt (
431455 self . value_fields . iter ( ) . map ( |f| & value. fields [ f. field_idx ] ) ,
432- self . value_fields . iter ( ) . map ( |f| & f . field_schema ) ,
456+ self . value_fields . iter ( ) ,
433457 ) ?,
434458 ) ;
435459 }
@@ -819,34 +843,44 @@ impl StorageFactoryBase for RelationshipFactory {
819843 for ( field_idx, field_schema) in value_fields_schema. into_iter ( ) . enumerate ( ) {
820844 let src_field_info = field_name_to_src_field_info. remove ( field_schema. name . as_str ( ) ) ;
821845 let tgt_field_info = field_name_to_tgt_field_info. remove ( field_schema. name . as_str ( ) ) ;
822- let field_mapping = AnalyzedGraphFieldMapping {
823- field_idx,
824- field_schema,
825- } ;
826846 if let Some ( src_field_info) = src_field_info {
847+ let field_mapping = AnalyzedGraphFieldMapping {
848+ field_idx,
849+ field_name : src_field_info. get_node_field_name ( ) . clone ( ) ,
850+ value_type : field_schema. value_type . typ . clone ( ) ,
851+ } ;
827852 let node_field_name = src_field_info
828853 . node_field_name
829854 . as_ref ( )
830855 . unwrap_or ( & src_field_info. field_name ) ;
831856 if & src_label_info. key_field_name == node_field_name {
832- src_key_field_info = Some ( field_mapping. clone ( ) ) ;
857+ src_key_field_info = Some ( field_mapping) ;
833858 } else {
834- src_value_fields_info. push ( field_mapping. clone ( ) ) ;
859+ src_value_fields_info. push ( field_mapping) ;
835860 }
836861 }
837862 if let Some ( tgt_field_info) = tgt_field_info {
863+ let field_mapping = AnalyzedGraphFieldMapping {
864+ field_idx,
865+ field_name : tgt_field_info. get_node_field_name ( ) . clone ( ) ,
866+ value_type : field_schema. value_type . typ . clone ( ) ,
867+ } ;
838868 let node_field_name = tgt_field_info
839869 . node_field_name
840870 . as_ref ( )
841871 . unwrap_or ( & tgt_field_info. field_name ) ;
842872 if & tgt_label_info. key_field_name == node_field_name {
843- tgt_key_field_info = Some ( field_mapping. clone ( ) ) ;
873+ tgt_key_field_info = Some ( field_mapping) ;
844874 } else {
845- tgt_value_fields_info. push ( field_mapping. clone ( ) ) ;
875+ tgt_value_fields_info. push ( field_mapping) ;
846876 }
847877 }
848878 if src_field_info. is_none ( ) && tgt_field_info. is_none ( ) {
849- rel_value_fields_info. push ( field_mapping) ;
879+ rel_value_fields_info. push ( AnalyzedGraphFieldMapping {
880+ field_idx,
881+ field_name : field_schema. name . clone ( ) ,
882+ value_type : field_schema. value_type . typ . clone ( ) ,
883+ } ) ;
850884 }
851885 }
852886 if !field_name_to_src_field_info. is_empty ( ) {
0 commit comments