@@ -125,9 +125,9 @@ def __repr__(self):
125
125
126
126
def __eq__ (self , other ):
127
127
try :
128
- if self .tag == StructTagV1 .path :
128
+ if self .tag in ( StructTagV1 .path , StructTagV2 . path ) :
129
129
# path struct => order of nodes and rels is irrelevant
130
- return (other .tag == StructTagV1 . path
130
+ return (other .tag == self . tag
131
131
and len (other .fields ) == 3
132
132
and sorted (self .fields [0 ]) == sorted (other .fields [0 ])
133
133
and sorted (self .fields [1 ]) == sorted (other .fields [1 ])
@@ -202,8 +202,13 @@ def _from_jolt_v1_type(cls, jolt: jolt_v1_types.JoltType):
202
202
return cls (StructTagV1 .local_time , jolt .nanoseconds ,
203
203
packstream_version = 1 )
204
204
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 )
207
212
if isinstance (jolt , jolt_v1_types .JoltLocalDateTime ):
208
213
return cls (StructTagV1 .local_date_time , * jolt .seconds_nanoseconds ,
209
214
packstream_version = 1 )
@@ -277,34 +282,39 @@ def _from_jolt_v1_type(cls, jolt: jolt_v1_types.JoltType):
277
282
@classmethod
278
283
def _from_jolt_v2_type (cls , jolt : jolt_v1_types .JoltType ):
279
284
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 )
281
286
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 ,
283
288
packstream_version = 2 )
284
289
if isinstance (jolt , jolt_v2_types .JoltLocalTime ):
285
- return cls (StructTagV1 .local_time , jolt .nanoseconds ,
290
+ return cls (StructTagV2 .local_time , jolt .nanoseconds ,
286
291
packstream_version = 2 )
287
292
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 )
290
300
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 ,
292
302
packstream_version = 2 )
293
303
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 ,
295
305
jolt .seconds , jolt .nanoseconds , packstream_version = 2 )
296
306
if isinstance (jolt , jolt_v2_types .JoltPoint ):
297
307
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 ,
299
309
packstream_version = 2 )
300
310
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 ,
302
312
jolt .z , packstream_version = 2 )
303
313
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 ,
305
315
jolt .properties , jolt .element_id , packstream_version = 2 )
306
316
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 ,
308
318
jolt .end_node_id , jolt .rel_type , jolt .properties ,
309
319
jolt .element_id , jolt .start_node_element_id ,
310
320
jolt .end_node_element_id , packstream_version = 2 )
@@ -332,7 +342,7 @@ def _from_jolt_v2_type(cls, jolt: jolt_v1_types.JoltType):
332
342
for rel in jolt .path [1 ::2 ]:
333
343
rels .append (rel )
334
344
335
- ub_rel = cls (StructTagV1 .unbound_relationship , rel .id ,
345
+ ub_rel = cls (StructTagV2 .unbound_relationship , rel .id ,
336
346
rel .rel_type , rel .properties , rel .element_id ,
337
347
packstream_version = 2 )
338
348
if ub_rel not in uniq_rels :
@@ -354,7 +364,7 @@ def _from_jolt_v2_type(cls, jolt: jolt_v1_types.JoltType):
354
364
else :
355
365
ids .append (- index )
356
366
357
- return cls (StructTagV1 .path , uniq_nodes , uniq_rels , ids ,
367
+ return cls (StructTagV2 .path , uniq_nodes , uniq_rels , ids ,
358
368
packstream_version = 2 )
359
369
raise TypeError ("Unsupported jolt type: {}" .format (type (jolt )))
360
370
@@ -373,7 +383,7 @@ def _to_jolt_v1_type(self):
373
383
return jolt_v1_types .JoltTime .new (* self .fields )
374
384
if self .tag == StructTagV1 .local_time :
375
385
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 ) :
377
387
return jolt_v1_types .JoltDateTime .new (* self .fields )
378
388
if self .tag == StructTagV1 .local_date_time :
379
389
return jolt_v1_types .JoltLocalDateTime .new (* self .fields )
@@ -422,7 +432,7 @@ def _to_jolt_v2_type(self):
422
432
return jolt_v2_types .JoltTime .new (* self .fields )
423
433
if self .tag == StructTagV2 .local_time :
424
434
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 ) :
426
436
return jolt_v2_types .JoltDateTime .new (* self .fields )
427
437
if self .tag == StructTagV2 .local_date_time :
428
438
return jolt_v2_types .JoltLocalDateTime .new (* self .fields )
@@ -664,12 +674,28 @@ def _verify_relationship(cls, structure, fields):
664
674
665
675
@classmethod
666
676
def verify_fields (cls , structure : Structure ):
667
- # assert tags didn't change
668
677
assert all (
669
678
hasattr (StructTagV1 , tag )
670
679
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
+ )
672
684
)
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 )
673
699
return super ().verify_fields (structure )
674
700
675
701
0 commit comments