@@ -36,6 +36,7 @@ use crate::otel::metrics::flatten_otel_metrics;
36
36
use crate :: otel:: traces:: flatten_otel_traces;
37
37
use crate :: storage:: { ObjectStorageError , StreamType } ;
38
38
use crate :: utils:: header_parsing:: ParseHeaderError ;
39
+ use crate :: utils:: json:: flatten:: JsonFlattenError ;
39
40
use actix_web:: { http:: header:: ContentType , HttpRequest , HttpResponse } ;
40
41
use arrow_array:: RecordBatch ;
41
42
use arrow_schema:: Schema ;
@@ -89,13 +90,7 @@ pub async fn ingest_internal_stream(stream_name: String, body: Bytes) -> Result<
89
90
. clone ( ) ;
90
91
let event = format:: json:: Event { data : body_val } ;
91
92
// For internal streams, use old schema
92
- event. into_recordbatch (
93
- & schema,
94
- None ,
95
- None ,
96
- SchemaVersion :: V0 ,
97
- & LogSource :: default ( ) ,
98
- ) ?
93
+ event. into_recordbatch ( & schema, None , None , SchemaVersion :: V0 ) ?
99
94
} ;
100
95
event:: Event {
101
96
rb,
@@ -328,6 +323,8 @@ pub enum PostError {
328
323
DashboardError ( #[ from] DashboardError ) ,
329
324
#[ error( "Error: {0}" ) ]
330
325
StreamError ( #[ from] StreamError ) ,
326
+ #[ error( "Error: {0}" ) ]
327
+ JsonFlattenError ( #[ from] JsonFlattenError ) ,
331
328
}
332
329
333
330
impl actix_web:: ResponseError for PostError {
@@ -349,6 +346,7 @@ impl actix_web::ResponseError for PostError {
349
346
PostError :: DashboardError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
350
347
PostError :: FiltersError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
351
348
PostError :: StreamError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
349
+ PostError :: JsonFlattenError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
352
350
}
353
351
}
354
352
@@ -369,8 +367,9 @@ mod tests {
369
367
use std:: { collections:: HashMap , sync:: Arc } ;
370
368
371
369
use crate :: {
372
- event :: format :: LogSource , handlers:: http:: modal:: utils:: ingest_utils:: into_event_batch,
370
+ handlers:: http:: modal:: utils:: ingest_utils:: into_event_batch,
373
371
metadata:: SchemaVersion ,
372
+ utils:: json:: { convert_array_to_object, flatten:: convert_to_array} ,
374
373
} ;
375
374
376
375
trait TestExt {
@@ -405,15 +404,8 @@ mod tests {
405
404
"b" : "hello" ,
406
405
} ) ;
407
406
408
- let ( rb, _) = into_event_batch (
409
- & json,
410
- HashMap :: default ( ) ,
411
- None ,
412
- None ,
413
- SchemaVersion :: V0 ,
414
- & LogSource :: default ( ) ,
415
- )
416
- . unwrap ( ) ;
407
+ let ( rb, _) =
408
+ into_event_batch ( & json, HashMap :: default ( ) , None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
417
409
418
410
assert_eq ! ( rb. num_rows( ) , 1 ) ;
419
411
assert_eq ! ( rb. num_columns( ) , 4 ) ;
@@ -439,15 +431,8 @@ mod tests {
439
431
"c" : null
440
432
} ) ;
441
433
442
- let ( rb, _) = into_event_batch (
443
- & json,
444
- HashMap :: default ( ) ,
445
- None ,
446
- None ,
447
- SchemaVersion :: V0 ,
448
- & LogSource :: default ( ) ,
449
- )
450
- . unwrap ( ) ;
434
+ let ( rb, _) =
435
+ into_event_batch ( & json, HashMap :: default ( ) , None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
451
436
452
437
assert_eq ! ( rb. num_rows( ) , 1 ) ;
453
438
assert_eq ! ( rb. num_columns( ) , 3 ) ;
@@ -477,15 +462,7 @@ mod tests {
477
462
. into_iter ( ) ,
478
463
) ;
479
464
480
- let ( rb, _) = into_event_batch (
481
- & json,
482
- schema,
483
- None ,
484
- None ,
485
- SchemaVersion :: V0 ,
486
- & LogSource :: default ( ) ,
487
- )
488
- . unwrap ( ) ;
465
+ let ( rb, _) = into_event_batch ( & json, schema, None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
489
466
490
467
assert_eq ! ( rb. num_rows( ) , 1 ) ;
491
468
assert_eq ! ( rb. num_columns( ) , 3 ) ;
@@ -515,15 +492,7 @@ mod tests {
515
492
. into_iter ( ) ,
516
493
) ;
517
494
518
- assert ! ( into_event_batch(
519
- & json,
520
- schema,
521
- None ,
522
- None ,
523
- SchemaVersion :: V0 ,
524
- & LogSource :: default ( )
525
- )
526
- . is_err( ) ) ;
495
+ assert ! ( into_event_batch( & json, schema, None , None , SchemaVersion :: V0 , ) . is_err( ) ) ;
527
496
}
528
497
529
498
#[ test]
@@ -539,15 +508,7 @@ mod tests {
539
508
. into_iter ( ) ,
540
509
) ;
541
510
542
- let ( rb, _) = into_event_batch (
543
- & json,
544
- schema,
545
- None ,
546
- None ,
547
- SchemaVersion :: V0 ,
548
- & LogSource :: default ( ) ,
549
- )
550
- . unwrap ( ) ;
511
+ let ( rb, _) = into_event_batch ( & json, schema, None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
551
512
552
513
assert_eq ! ( rb. num_rows( ) , 1 ) ;
553
514
assert_eq ! ( rb. num_columns( ) , 1 ) ;
@@ -556,14 +517,13 @@ mod tests {
556
517
#[ test]
557
518
fn non_object_arr_is_err ( ) {
558
519
let json = json ! ( [ 1 ] ) ;
559
-
560
- assert ! ( into_event_batch(
561
- & json,
562
- HashMap :: default ( ) ,
520
+ assert ! ( convert_array_to_object(
521
+ json,
522
+ None ,
563
523
None ,
564
524
None ,
565
525
SchemaVersion :: V0 ,
566
- & LogSource :: default ( )
526
+ & crate :: event :: format :: LogSource :: default ( )
567
527
)
568
528
. is_err( ) )
569
529
}
@@ -586,15 +546,8 @@ mod tests {
586
546
} ,
587
547
] ) ;
588
548
589
- let ( rb, _) = into_event_batch (
590
- & json,
591
- HashMap :: default ( ) ,
592
- None ,
593
- None ,
594
- SchemaVersion :: V0 ,
595
- & LogSource :: default ( ) ,
596
- )
597
- . unwrap ( ) ;
549
+ let ( rb, _) =
550
+ into_event_batch ( & json, HashMap :: default ( ) , None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
598
551
599
552
assert_eq ! ( rb. num_rows( ) , 3 ) ;
600
553
assert_eq ! ( rb. num_columns( ) , 4 ) ;
@@ -640,15 +593,8 @@ mod tests {
640
593
} ,
641
594
] ) ;
642
595
643
- let ( rb, _) = into_event_batch (
644
- & json,
645
- HashMap :: default ( ) ,
646
- None ,
647
- None ,
648
- SchemaVersion :: V0 ,
649
- & LogSource :: default ( ) ,
650
- )
651
- . unwrap ( ) ;
596
+ let ( rb, _) =
597
+ into_event_batch ( & json, HashMap :: default ( ) , None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
652
598
653
599
assert_eq ! ( rb. num_rows( ) , 3 ) ;
654
600
assert_eq ! ( rb. num_columns( ) , 4 ) ;
@@ -695,15 +641,7 @@ mod tests {
695
641
. into_iter ( ) ,
696
642
) ;
697
643
698
- let ( rb, _) = into_event_batch (
699
- & json,
700
- schema,
701
- None ,
702
- None ,
703
- SchemaVersion :: V0 ,
704
- & LogSource :: default ( ) ,
705
- )
706
- . unwrap ( ) ;
644
+ let ( rb, _) = into_event_batch ( & json, schema, None , None , SchemaVersion :: V0 ) . unwrap ( ) ;
707
645
708
646
assert_eq ! ( rb. num_rows( ) , 3 ) ;
709
647
assert_eq ! ( rb. num_columns( ) , 4 ) ;
@@ -750,15 +688,7 @@ mod tests {
750
688
. into_iter ( ) ,
751
689
) ;
752
690
753
- assert ! ( into_event_batch(
754
- & json,
755
- schema,
756
- None ,
757
- None ,
758
- SchemaVersion :: V0 ,
759
- & LogSource :: default ( )
760
- )
761
- . is_err( ) ) ;
691
+ assert ! ( into_event_batch( & json, schema, None , None , SchemaVersion :: V0 , ) . is_err( ) ) ;
762
692
}
763
693
764
694
#[ test]
@@ -783,17 +713,27 @@ mod tests {
783
713
"c" : [ { "a" : 1 , "b" : 2 } ]
784
714
} ,
785
715
] ) ;
716
+ let flattened_json = convert_to_array (
717
+ convert_array_to_object (
718
+ json,
719
+ None ,
720
+ None ,
721
+ None ,
722
+ SchemaVersion :: V0 ,
723
+ & crate :: event:: format:: LogSource :: default ( ) ,
724
+ )
725
+ . unwrap ( ) ,
726
+ )
727
+ . unwrap ( ) ;
786
728
787
729
let ( rb, _) = into_event_batch (
788
- & json ,
730
+ & flattened_json ,
789
731
HashMap :: default ( ) ,
790
732
None ,
791
733
None ,
792
734
SchemaVersion :: V0 ,
793
- & LogSource :: default ( ) ,
794
735
)
795
736
. unwrap ( ) ;
796
-
797
737
assert_eq ! ( rb. num_rows( ) , 4 ) ;
798
738
assert_eq ! ( rb. num_columns( ) , 5 ) ;
799
739
assert_eq ! (
@@ -861,14 +801,25 @@ mod tests {
861
801
"c" : [ { "a" : 1 , "b" : 2 } ]
862
802
} ,
863
803
] ) ;
804
+ let flattened_json = convert_to_array (
805
+ convert_array_to_object (
806
+ json,
807
+ None ,
808
+ None ,
809
+ None ,
810
+ SchemaVersion :: V1 ,
811
+ & crate :: event:: format:: LogSource :: default ( ) ,
812
+ )
813
+ . unwrap ( ) ,
814
+ )
815
+ . unwrap ( ) ;
864
816
865
817
let ( rb, _) = into_event_batch (
866
- & json ,
818
+ & flattened_json ,
867
819
HashMap :: default ( ) ,
868
820
None ,
869
821
None ,
870
822
SchemaVersion :: V1 ,
871
- & LogSource :: default ( ) ,
872
823
)
873
824
. unwrap ( ) ;
874
825
0 commit comments