@@ -125,9 +125,9 @@ def __repr__(self):
125125
126126 def __eq__ (self , other ):
127127 try :
128- if self .tag == StructTagV1 .path :
128+ if self .tag in ( StructTagV1 .path , StructTagV2 . path ) :
129129 # path struct => order of nodes and rels is irrelevant
130- return (other .tag == StructTagV1 . path
130+ return (other .tag == self . tag
131131 and len (other .fields ) == 3
132132 and sorted (self .fields [0 ]) == sorted (other .fields [0 ])
133133 and sorted (self .fields [1 ]) == sorted (other .fields [1 ])
@@ -202,8 +202,13 @@ def _from_jolt_v1_type(cls, jolt: jolt_v1_types.JoltType):
202202 return cls (StructTagV1 .local_time , jolt .nanoseconds ,
203203 packstream_version = 1 )
204204 if isinstance (jolt , jolt_v1_types .JoltDateTime ):
205- return cls (StructTagV1 .date_time , * jolt .seconds_nanoseconds ,
206- jolt .time .utc_offset , packstream_version = 1 )
205+ if jolt .time .zone_id :
206+ return cls (StructTagV1 .date_time_zone_id ,
207+ * jolt .seconds_nanoseconds , jolt .time .zone_id ,
208+ packstream_version = 1 )
209+ else :
210+ return cls (StructTagV1 .date_time , * jolt .seconds_nanoseconds ,
211+ jolt .time .utc_offset , packstream_version = 1 )
207212 if isinstance (jolt , jolt_v1_types .JoltLocalDateTime ):
208213 return cls (StructTagV1 .local_date_time , * jolt .seconds_nanoseconds ,
209214 packstream_version = 1 )
@@ -277,34 +282,39 @@ def _from_jolt_v1_type(cls, jolt: jolt_v1_types.JoltType):
277282 @classmethod
278283 def _from_jolt_v2_type (cls , jolt : jolt_v1_types .JoltType ):
279284 if isinstance (jolt , jolt_v2_types .JoltDate ):
280- return cls (StructTagV1 .date , jolt .days , packstream_version = 2 )
285+ return cls (StructTagV2 .date , jolt .days , packstream_version = 2 )
281286 if isinstance (jolt , jolt_v2_types .JoltTime ):
282- return cls (StructTagV1 .time , jolt .nanoseconds , jolt .utc_offset ,
287+ return cls (StructTagV2 .time , jolt .nanoseconds , jolt .utc_offset ,
283288 packstream_version = 2 )
284289 if isinstance (jolt , jolt_v2_types .JoltLocalTime ):
285- return cls (StructTagV1 .local_time , jolt .nanoseconds ,
290+ return cls (StructTagV2 .local_time , jolt .nanoseconds ,
286291 packstream_version = 2 )
287292 if isinstance (jolt , jolt_v2_types .JoltDateTime ):
288- return cls (StructTagV1 .date_time , * jolt .seconds_nanoseconds ,
289- jolt .time .utc_offset , packstream_version = 2 )
293+ if jolt .time .zone_id :
294+ return cls (StructTagV2 .date_time_zone_id ,
295+ * jolt .seconds_nanoseconds , jolt .time .zone_id ,
296+ packstream_version = 2 )
297+ else :
298+ return cls (StructTagV2 .date_time , * jolt .seconds_nanoseconds ,
299+ jolt .time .utc_offset , packstream_version = 2 )
290300 if isinstance (jolt , jolt_v2_types .JoltLocalDateTime ):
291- return cls (StructTagV1 .local_date_time , * jolt .seconds_nanoseconds ,
301+ return cls (StructTagV2 .local_date_time , * jolt .seconds_nanoseconds ,
292302 packstream_version = 2 )
293303 if isinstance (jolt , jolt_v2_types .JoltDuration ):
294- return cls (StructTagV1 .duration , jolt .months , jolt .days ,
304+ return cls (StructTagV2 .duration , jolt .months , jolt .days ,
295305 jolt .seconds , jolt .nanoseconds , packstream_version = 2 )
296306 if isinstance (jolt , jolt_v2_types .JoltPoint ):
297307 if jolt .z is None : # 2D
298- return cls (StructTagV1 .point_2d , jolt .srid , jolt .x , jolt .y ,
308+ return cls (StructTagV2 .point_2d , jolt .srid , jolt .x , jolt .y ,
299309 packstream_version = 2 )
300310 else :
301- return cls (StructTagV1 .point_3d , jolt .srid , jolt .x , jolt .y ,
311+ return cls (StructTagV2 .point_3d , jolt .srid , jolt .x , jolt .y ,
302312 jolt .z , packstream_version = 2 )
303313 if isinstance (jolt , jolt_v2_types .JoltNode ):
304- return cls (StructTagV1 .node , jolt .id , jolt .labels ,
314+ return cls (StructTagV2 .node , jolt .id , jolt .labels ,
305315 jolt .properties , jolt .element_id , packstream_version = 2 )
306316 if isinstance (jolt , jolt_v2_types .JoltRelationship ):
307- return cls (StructTagV1 .relationship , jolt .id , jolt .start_node_id ,
317+ return cls (StructTagV2 .relationship , jolt .id , jolt .start_node_id ,
308318 jolt .end_node_id , jolt .rel_type , jolt .properties ,
309319 jolt .element_id , jolt .start_node_element_id ,
310320 jolt .end_node_element_id , packstream_version = 2 )
@@ -332,7 +342,7 @@ def _from_jolt_v2_type(cls, jolt: jolt_v1_types.JoltType):
332342 for rel in jolt .path [1 ::2 ]:
333343 rels .append (rel )
334344
335- ub_rel = cls (StructTagV1 .unbound_relationship , rel .id ,
345+ ub_rel = cls (StructTagV2 .unbound_relationship , rel .id ,
336346 rel .rel_type , rel .properties , rel .element_id ,
337347 packstream_version = 2 )
338348 if ub_rel not in uniq_rels :
@@ -354,7 +364,7 @@ def _from_jolt_v2_type(cls, jolt: jolt_v1_types.JoltType):
354364 else :
355365 ids .append (- index )
356366
357- return cls (StructTagV1 .path , uniq_nodes , uniq_rels , ids ,
367+ return cls (StructTagV2 .path , uniq_nodes , uniq_rels , ids ,
358368 packstream_version = 2 )
359369 raise TypeError ("Unsupported jolt type: {}" .format (type (jolt )))
360370
@@ -373,7 +383,7 @@ def _to_jolt_v1_type(self):
373383 return jolt_v1_types .JoltTime .new (* self .fields )
374384 if self .tag == StructTagV1 .local_time :
375385 return jolt_v1_types .JoltLocalTime .new (* self .fields )
376- if self .tag == StructTagV1 .date_time :
386+ if self .tag in ( StructTagV1 .date_time , StructTagV1 . date_time_zone_id ) :
377387 return jolt_v1_types .JoltDateTime .new (* self .fields )
378388 if self .tag == StructTagV1 .local_date_time :
379389 return jolt_v1_types .JoltLocalDateTime .new (* self .fields )
@@ -422,7 +432,7 @@ def _to_jolt_v2_type(self):
422432 return jolt_v2_types .JoltTime .new (* self .fields )
423433 if self .tag == StructTagV2 .local_time :
424434 return jolt_v2_types .JoltLocalTime .new (* self .fields )
425- if self .tag == StructTagV2 .date_time :
435+ if self .tag in ( StructTagV2 .date_time , StructTagV2 . date_time_zone_id ) :
426436 return jolt_v2_types .JoltDateTime .new (* self .fields )
427437 if self .tag == StructTagV2 .local_date_time :
428438 return jolt_v2_types .JoltLocalDateTime .new (* self .fields )
@@ -664,12 +674,28 @@ def _verify_relationship(cls, structure, fields):
664674
665675 @classmethod
666676 def verify_fields (cls , structure : Structure ):
667- # assert tags didn't change
668677 assert all (
669678 hasattr (StructTagV1 , tag )
670679 and getattr (StructTagV1 , tag ) == getattr (StructTagV2 , tag )
671- for tag in dir (StructTagV2 ) if not tag .startswith ("_" )
680+ for tag in dir (StructTagV2 ) if not (
681+ tag .startswith ("_" )
682+ or tag in ("date_time" , "date_time_zone_id" )
683+ )
672684 )
685+
686+ tag , fields = structure .tag , structure .fields
687+
688+ field_validator = {
689+ StructTagV2 .date_time : cls ._build_generic_verifier (
690+ (int , int , int ,), "DateTime"
691+ ),
692+ StructTagV2 .date_time_zone_id : cls ._build_generic_verifier (
693+ (int , int , str ), "DateTimeZoneId"
694+ ),
695+ }
696+
697+ if tag in field_validator :
698+ return field_validator [tag ](structure , fields )
673699 return super ().verify_fields (structure )
674700
675701
0 commit comments