-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathcsv_scenarios.py
More file actions
3767 lines (3728 loc) · 148 KB
/
csv_scenarios.py
File metadata and controls
3767 lines (3728 loc) · 148 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from airbyte_cdk.models import AirbyteAnalyticsTraceMessage, SyncMode
from airbyte_cdk.sources.file_based.config.csv_format import CsvFormat
from airbyte_cdk.sources.file_based.exceptions import ConfigValidationError, FileBasedSourceError
from airbyte_cdk.test.catalog_builder import CatalogBuilder
from airbyte_cdk.utils.traced_exception import AirbyteTracedException
from unit_tests.sources.file_based.helpers import (
EmptySchemaParser,
LowInferenceLimitDiscoveryPolicy,
)
from unit_tests.sources.file_based.in_memory_files_source import InMemoryFilesSource
from unit_tests.sources.file_based.scenarios.file_based_source_builder import FileBasedSourceBuilder
from unit_tests.sources.file_based.scenarios.scenario_builder import (
TestScenario,
TestScenarioBuilder,
)
single_csv_scenario: TestScenario[InMemoryFilesSource] = (
TestScenarioBuilder[InMemoryFilesSource]()
.set_name("single_csv_scenario")
.set_config(
{
"streams": [
{
"name": "stream1",
"format": {"filetype": "csv"},
"globs": ["*"],
"validation_policy": "Emit Record",
}
],
"start_date": "2023-06-04T03:54:07.000000Z",
}
)
.set_source_builder(
FileBasedSourceBuilder()
.set_files(
{
"a.csv": {
"contents": [
("col1", "col2"),
("val11", "val12"),
("val21", "val22"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
}
}
)
.set_file_type("csv")
)
.set_expected_spec(
{
"documentationUrl": "https://docs.airbyte.com/integrations/sources/in_memory_files",
"connectionSpecification": {
"title": "InMemorySpec",
"description": "Used during spec; allows the developer to configure the cloud provider specific options\nthat are needed when users configure a file-based source.",
"type": "object",
"properties": {
"start_date": {
"title": "Start Date",
"description": "UTC date and time in the format 2017-01-25T00:00:00.000000Z. Any file modified before this date will not be replicated.",
"examples": ["2021-01-01T00:00:00.000000Z"],
"format": "date-time",
"order": 1,
"type": "string",
},
"streams": {
"title": "The list of streams to sync",
"description": 'Each instance of this configuration defines a <a href="https://docs.airbyte.com/cloud/core-concepts#stream">stream</a>. Use this to define which files belong in the stream, their format, and how they should be parsed and validated. When sending data to warehouse destination such as Snowflake or BigQuery, each stream is a separate table.',
"order": 10,
"type": "array",
"items": {
"title": "FileBasedStreamConfig",
"type": "object",
"properties": {
"name": {
"title": "Name",
"description": "The name of the stream.",
"type": "string",
},
"globs": {
"title": "Globs",
"description": 'The pattern used to specify which files should be selected from the file system. For more information on glob pattern matching look <a href="https://en.wikipedia.org/wiki/Glob_(programming)">here</a>.',
"type": "array",
"items": {"type": "string"},
"order": 1,
"default": ["**"],
},
"legacy_prefix": {
"title": "Legacy Prefix",
"airbyte_hidden": True,
"type": "string",
"description": "The path prefix configured in v3 versions of the S3 connector. This option is deprecated in favor of a single glob.",
},
"validation_policy": {
"title": "Validation Policy",
"description": "The name of the validation policy that dictates sync behavior when a record does not adhere to the stream schema.",
"default": "Emit Record",
"enum": ["Emit Record", "Skip Record", "Wait for Discover"],
},
"input_schema": {
"title": "Input Schema",
"description": "The schema that will be used to validate records extracted from the file. This will override the stream schema that is auto-detected from incoming files.",
"type": "string",
},
"primary_key": {
"title": "Primary Key",
"description": "The column or columns (for a composite key) that serves as the unique identifier of a record. If empty, the primary key will default to the parser's default primary key.",
"type": "string",
"airbyte_hidden": True,
},
"days_to_sync_if_history_is_full": {
"title": "Days To Sync If History Is Full",
"description": "When the state history of the file store is full, syncs will only read files that were last modified in the provided day range.",
"default": 3,
"type": "integer",
},
"format": {
"title": "Format",
"description": "The configuration options that are used to alter how to read incoming files that deviate from the standard formatting.",
"type": "object",
"oneOf": [
{
"title": "Avro Format",
"type": "object",
"properties": {
"filetype": {
"title": "Filetype",
"default": "avro",
"const": "avro",
"type": "string",
},
"double_as_string": {
"title": "Convert Double Fields to Strings",
"description": "Whether to convert double fields to strings. This is recommended if you have decimal numbers with a high degree of precision because there can be a loss precision when handling floating point numbers.",
"default": False,
"type": "boolean",
},
},
"required": ["filetype"],
},
{
"title": "CSV Format",
"type": "object",
"properties": {
"filetype": {
"title": "Filetype",
"default": "csv",
"const": "csv",
"type": "string",
},
"delimiter": {
"title": "Delimiter",
"description": "The character delimiting individual cells in the CSV data. This may only be a 1-character string. For tab-delimited data enter '\\t'.",
"default": ",",
"type": "string",
},
"quote_char": {
"title": "Quote Character",
"description": "The character used for quoting CSV values. To disallow quoting, make this field blank.",
"default": '"',
"type": "string",
},
"escape_char": {
"title": "Escape Character",
"description": "The character used for escaping special characters. To disallow escaping, leave this field blank.",
"type": "string",
},
"encoding": {
"title": "Encoding",
"description": 'The character encoding of the CSV data. Leave blank to default to <strong>UTF8</strong>. See <a href="https://docs.python.org/3/library/codecs.html#standard-encodings" target="_blank">list of python encodings</a> for allowable options.',
"default": "utf8",
"type": "string",
},
"double_quote": {
"title": "Double Quote",
"description": "Whether two quotes in a quoted CSV value denote a single quote in the data.",
"default": True,
"type": "boolean",
},
"null_values": {
"title": "Null Values",
"description": "A set of case-sensitive strings that should be interpreted as null values. For example, if the value 'NA' should be interpreted as null, enter 'NA' in this field.",
"default": [],
"type": "array",
"items": {"type": "string"},
"uniqueItems": True,
},
"strings_can_be_null": {
"title": "Strings Can Be Null",
"description": "Whether strings can be interpreted as null values. If true, strings that match the null_values set will be interpreted as null. If false, strings that match the null_values set will be interpreted as the string itself.",
"default": True,
"type": "boolean",
},
"skip_rows_before_header": {
"title": "Skip Rows Before Header",
"description": "The number of rows to skip before the header row. For example, if the header row is on the 3rd row, enter 2 in this field.",
"default": 0,
"type": "integer",
},
"skip_rows_after_header": {
"title": "Skip Rows After Header",
"description": "The number of rows to skip after the header row.",
"default": 0,
"type": "integer",
},
"header_definition": {
"title": "CSV Header Definition",
"type": "object",
"description": "How headers will be defined. `User Provided` assumes the CSV does not have a header row and uses the headers provided and `Autogenerated` assumes the CSV does not have a header row and the CDK will generate headers using for `f{i}` where `i` is the index starting from 0. Else, the default behavior is to use the header from the CSV file. If a user wants to autogenerate or provide column names for a CSV having headers, they can skip rows.",
"default": {
"header_definition_type": "From CSV"
},
"oneOf": [
{
"title": "From CSV",
"type": "object",
"properties": {
"header_definition_type": {
"title": "Header Definition Type",
"default": "From CSV",
"const": "From CSV",
"type": "string",
},
},
"required": ["header_definition_type"],
},
{
"title": "Autogenerated",
"type": "object",
"properties": {
"header_definition_type": {
"title": "Header Definition Type",
"default": "Autogenerated",
"const": "Autogenerated",
"type": "string",
},
},
"required": ["header_definition_type"],
},
{
"title": "User Provided",
"type": "object",
"properties": {
"header_definition_type": {
"title": "Header Definition Type",
"default": "User Provided",
"const": "User Provided",
"type": "string",
},
"column_names": {
"title": "Column Names",
"description": "The column names that will be used while emitting the CSV records",
"type": "array",
"items": {"type": "string"},
},
},
"required": [
"column_names",
"header_definition_type",
],
},
],
},
"true_values": {
"title": "True Values",
"description": "A set of case-sensitive strings that should be interpreted as true values.",
"default": ["y", "yes", "t", "true", "on", "1"],
"type": "array",
"items": {"type": "string"},
"uniqueItems": True,
},
"false_values": {
"title": "False Values",
"description": "A set of case-sensitive strings that should be interpreted as false values.",
"default": [
"n",
"no",
"f",
"false",
"off",
"0",
],
"type": "array",
"items": {"type": "string"},
"uniqueItems": True,
},
"inference_type": {
"title": "Inference Type",
"description": "How to infer the types of the columns. If none, inference default to strings.",
"default": "None",
"airbyte_hidden": True,
"enum": ["None", "Primitive Types Only"],
},
"ignore_errors_on_fields_mismatch": {
"type": "boolean",
"title": "Ignore errors on field mismatch",
"default": False,
"description": "Whether to ignore errors that occur when the number of fields in the CSV does not match the number of columns in the schema.",
},
},
"required": ["filetype"],
},
{
"title": "Jsonl Format",
"type": "object",
"properties": {
"filetype": {
"title": "Filetype",
"default": "jsonl",
"const": "jsonl",
"type": "string",
}
},
"required": ["filetype"],
},
{
"title": "Parquet Format",
"type": "object",
"properties": {
"filetype": {
"title": "Filetype",
"default": "parquet",
"const": "parquet",
"type": "string",
},
"decimal_as_float": {
"title": "Convert Decimal Fields to Floats",
"description": "Whether to convert decimal fields to floats. There is a loss of precision when converting decimals to floats, so this is not recommended.",
"default": False,
"type": "boolean",
},
},
"required": ["filetype"],
},
{
"title": "Unstructured Document Format",
"type": "object",
"properties": {
"filetype": {
"title": "Filetype",
"default": "unstructured",
"const": "unstructured",
"type": "string",
},
"skip_unprocessable_files": {
"type": "boolean",
"default": True,
"title": "Skip Unprocessable Files",
"description": "If true, skip files that cannot be parsed and pass the error message along as the _ab_source_file_parse_error field. If false, fail the sync.",
"always_show": True,
},
"strategy": {
"type": "string",
"always_show": True,
"order": 0,
"default": "auto",
"title": "Parsing Strategy",
"enum": ["auto", "fast", "ocr_only", "hi_res"],
"description": "The strategy used to parse documents. `fast` extracts text directly from the document which doesn't work for all files. `ocr_only` is more reliable, but slower. `hi_res` is the most reliable, but requires an API key and a hosted instance of unstructured and can't be used with local mode. See the unstructured.io documentation for more details: https://unstructured-io.github.io/unstructured/core/partition.html#partition-pdf",
},
"processing": {
"title": "Processing",
"description": "Processing configuration",
"default": {"mode": "local"},
"type": "object",
"oneOf": [
{
"title": "Local",
"type": "object",
"properties": {
"mode": {
"title": "Mode",
"default": "local",
"const": "local",
"enum": ["local"],
"type": "string",
}
},
"description": "Process files locally, supporting `fast` and `ocr` modes. This is the default option.",
"required": ["mode"],
},
{
"title": "via API",
"type": "object",
"properties": {
"mode": {
"title": "Mode",
"default": "api",
"const": "api",
"enum": ["api"],
"type": "string",
},
"api_key": {
"title": "API Key",
"description": "The API key to use matching the environment",
"default": "",
"always_show": True,
"airbyte_secret": True,
"type": "string",
},
"api_url": {
"title": "API URL",
"description": "The URL of the unstructured API to use",
"default": "https://api.unstructured.io",
"always_show": True,
"examples": [
"https://api.unstructured.com"
],
"type": "string",
},
"parameters": {
"title": "Additional URL Parameters",
"description": "List of parameters send to the API",
"default": [],
"always_show": True,
"type": "array",
"items": {
"title": "APIParameterConfigModel",
"type": "object",
"properties": {
"name": {
"title": "Parameter name",
"description": "The name of the unstructured API parameter to use",
"examples": [
"combine_under_n_chars",
"languages",
],
"type": "string",
},
"value": {
"title": "Value",
"description": "The value of the parameter",
"examples": [
"true",
"hi_res",
],
"type": "string",
},
},
"required": [
"name",
"value",
],
},
},
},
"description": "Process files via an API, using the `hi_res` mode. This option is useful for increased performance and accuracy, but requires an API key and a hosted instance of unstructured.",
"required": ["mode"],
},
],
},
},
"description": "Extract text from document formats (.pdf, .docx, .md, .pptx) and emit as one record per file.",
"required": ["filetype"],
},
{
"title": "Excel Format",
"type": "object",
"properties": {
"filetype": {
"title": "Filetype",
"default": "excel",
"const": "excel",
"type": "string",
}
},
"required": ["filetype"],
},
],
},
"schemaless": {
"title": "Schemaless",
"description": "When enabled, syncs will not validate or structure records against the stream's schema.",
"default": False,
"type": "boolean",
},
"recent_n_files_to_read_for_schema_discovery": {
"title": "Files To Read For Schema Discover",
"description": "The number of resent files which will be used to discover the schema for this stream.",
"exclusiveMinimum": 0,
"type": "integer",
},
"use_first_found_file_for_schema_discovery": {
"default": False,
"description": "When enabled, the source will use the first found file for schema discovery. Helps to avoid long discovery step.",
"title": "Use First Found File For Schema Discover",
"type": "boolean",
},
},
"required": ["name", "format"],
},
},
"delivery_method": {
"airbyte_hidden": True,
"title": "Delivery Method",
"default": "use_records_transfer",
"type": "object",
"order": 7,
"display_type": "radio",
"group": "advanced",
"oneOf": [
{
"title": "Replicate Records",
"type": "object",
"properties": {
"delivery_type": {
"title": "Delivery Type",
"default": "use_records_transfer",
"const": "use_records_transfer",
"enum": ["use_records_transfer"],
"type": "string",
}
},
"description": "Recommended - Extract and load structured records into your destination of choice. This is the classic method of moving data in Airbyte. It allows for blocking and hashing individual fields or files from a structured schema. Data can be flattened, typed and deduped depending on the destination.",
"required": ["delivery_type"],
},
{
"title": "Copy Raw Files",
"type": "object",
"properties": {
"delivery_type": {
"title": "Delivery Type",
"default": "use_file_transfer",
"const": "use_file_transfer",
"enum": ["use_file_transfer"],
"type": "string",
},
"preserve_directory_structure": {
"default": True,
"description": "If enabled, sends subdirectory folder structure along with source file names to the destination. Otherwise, files will be synced by their names only. This option is ignored when file-based replication is not enabled.",
"title": "Preserve Sub-Directories in File Paths",
"type": "boolean",
},
},
"description": "Copy raw files without parsing their contents. Bits are copied into the destination exactly as they appeared in the source. Recommended for use with unstructured text data, non-text and compressed files.",
"required": ["delivery_type"],
},
{
"description": "Sends one identity stream and one for more permissions (ACL) streams to the destination. This data can be used in downstream systems to recreate permission restrictions mirroring the original source.",
"properties": {
"delivery_type": {
"const": "use_permissions_transfer",
"default": "use_permissions_transfer",
"enum": ["use_permissions_transfer"],
"title": "Delivery Type",
"type": "string",
},
"include_identities_stream": {
"default": True,
"description": "This data can be used in downstream systems to recreate permission restrictions mirroring the original source",
"title": "Include Identity Stream",
"type": "boolean",
},
},
"required": ["delivery_type"],
"title": "Replicate Permissions ACL",
"type": "object",
},
],
},
},
"required": ["streams"],
},
"supportsDBT": False,
"supportsNormalization": False,
}
)
.set_expected_catalog(
{
"streams": [
{
"default_cursor_field": ["_ab_source_file_last_modified"],
"json_schema": {
"type": "object",
"properties": {
"col1": {"type": ["null", "string"]},
"col2": {"type": ["null", "string"]},
"_ab_source_file_last_modified": {"type": "string"},
"_ab_source_file_url": {"type": "string"},
},
},
"name": "stream1",
"source_defined_cursor": True,
"supported_sync_modes": ["full_refresh", "incremental"],
"is_resumable": True,
}
]
}
)
.set_expected_records(
[
{
"data": {
"col1": "val11",
"col2": "val12",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val21",
"col2": "val22",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
]
)
).build()
csv_analytics_scenario: TestScenario[InMemoryFilesSource] = (
TestScenarioBuilder[InMemoryFilesSource]()
.set_name("csv_analytics")
.set_config(
{
"streams": [
{
"name": "stream1",
"format": {"filetype": "csv"},
"globs": ["a.csv"],
"validation_policy": "Emit Record",
},
{
"name": "stream2",
"format": {"filetype": "csv"},
"globs": ["b.csv"],
"validation_policy": "Emit Record",
},
]
}
)
.set_source_builder(
FileBasedSourceBuilder()
.set_files(
{
"a.csv": {
"contents": [
("col1", "col2"),
("val11a", "val12a"),
("val21a", "val22a"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
"b.csv": {
"contents": [
("col1", "col2", "col3"),
("val11b", "val12b", "val13b"),
("val21b", "val22b", "val23b"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
}
)
.set_file_type("csv")
)
.set_expected_catalog(
{
"streams": [
{
"default_cursor_field": ["_ab_source_file_last_modified"],
"json_schema": {
"type": "object",
"properties": {
"col1": {"type": ["null", "string"]},
"col2": {"type": ["null", "string"]},
"_ab_source_file_last_modified": {"type": "string"},
"_ab_source_file_url": {"type": "string"},
},
},
"name": "stream1",
"source_defined_cursor": True,
"supported_sync_modes": ["full_refresh", "incremental"],
"is_resumable": True,
},
{
"default_cursor_field": ["_ab_source_file_last_modified"],
"json_schema": {
"type": "object",
"properties": {
"col1": {"type": ["null", "string"]},
"col2": {"type": ["null", "string"]},
"col3": {"type": ["null", "string"]},
"_ab_source_file_last_modified": {"type": "string"},
"_ab_source_file_url": {"type": "string"},
},
},
"name": "stream2",
"source_defined_cursor": True,
"supported_sync_modes": ["full_refresh", "incremental"],
"is_resumable": True,
"is_file_based": False,
},
]
}
)
.set_expected_records(
[
{
"data": {
"col1": "val11a",
"col2": "val12a",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val21a",
"col2": "val22a",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val11b",
"col2": "val12b",
"col3": "val13b",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "b.csv",
},
"stream": "stream2",
},
{
"data": {
"col1": "val21b",
"col2": "val22b",
"col3": "val23b",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "b.csv",
},
"stream": "stream2",
},
]
)
.set_expected_analytics(
[
AirbyteAnalyticsTraceMessage(type="file-cdk-csv-stream-count", value="2"),
]
)
).build()
multi_csv_scenario: TestScenario[InMemoryFilesSource] = (
TestScenarioBuilder[InMemoryFilesSource]()
.set_name("multi_csv_stream")
.set_config(
{
"streams": [
{
"name": "stream1",
"format": {"filetype": "csv"},
"globs": ["*"],
"validation_policy": "Emit Record",
}
]
}
)
.set_source_builder(
FileBasedSourceBuilder()
.set_files(
{
"a.csv": {
"contents": [
("col1", "col2"),
("val11a", "val12a"),
("val21a", "val22a"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
"b.csv": {
"contents": [
("col1", "col2", "col3"),
("val11b", "val12b", "val13b"),
("val21b", "val22b", "val23b"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
}
)
.set_file_type("csv")
)
.set_expected_catalog(
{
"streams": [
{
"default_cursor_field": ["_ab_source_file_last_modified"],
"json_schema": {
"type": "object",
"properties": {
"col1": {"type": ["null", "string"]},
"col2": {"type": ["null", "string"]},
"col3": {"type": ["null", "string"]},
"_ab_source_file_last_modified": {"type": "string"},
"_ab_source_file_url": {"type": "string"},
},
},
"name": "stream1",
"source_defined_cursor": True,
"supported_sync_modes": ["full_refresh", "incremental"],
"is_resumable": True,
}
]
}
)
.set_expected_records(
[
{
"data": {
"col1": "val11a",
"col2": "val12a",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val21a",
"col2": "val22a",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val11b",
"col2": "val12b",
"col3": "val13b",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "b.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val21b",
"col2": "val22b",
"col3": "val23b",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "b.csv",
},
"stream": "stream1",
},
]
)
).build()
multi_csv_stream_n_file_exceeds_limit_for_inference = (
TestScenarioBuilder[InMemoryFilesSource]()
.set_name("multi_csv_stream_n_file_exceeds_limit_for_inference")
.set_config(
{
"streams": [
{
"name": "stream1",
"format": {"filetype": "csv"},
"globs": ["*"],
"validation_policy": "Emit Record",
}
]
}
)
.set_source_builder(
FileBasedSourceBuilder()
.set_files(
{
"a.csv": {
"contents": [
("col1", "col2"),
("val11a", "val12a"),
("val21a", "val22a"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
"b.csv": {
"contents": [
("col1", "col2", "col3"),
("val11b", "val12b", "val13b"),
("val21b", "val22b", "val23b"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
}
)
.set_file_type("csv")
.set_discovery_policy(LowInferenceLimitDiscoveryPolicy())
)
.set_expected_catalog(
{
"streams": [
{
"default_cursor_field": ["_ab_source_file_last_modified"],
"json_schema": {
"type": "object",
"properties": {
"col1": {"type": ["null", "string"]},
"col2": {"type": ["null", "string"]},
"_ab_source_file_last_modified": {"type": "string"},
"_ab_source_file_url": {"type": "string"},
},
},
"name": "stream1",
"source_defined_cursor": True,
"supported_sync_modes": ["full_refresh", "incremental"],
"is_resumable": True,
}
]
}
)
.set_expected_records(
[
{
"data": {
"col1": "val11a",
"col2": "val12a",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val21a",
"col2": "val22a",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "a.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val11b",
"col2": "val12b",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "b.csv",
},
"stream": "stream1",
},
{
"data": {
"col1": "val21b",
"col2": "val22b",
"_ab_source_file_last_modified": "2023-06-05T03:54:07.000000Z",
"_ab_source_file_url": "b.csv",
},
"stream": "stream1",
},
]
)
).build()
multi_csv_stream_n_file_exceeds_config_limit_for_inference = (
TestScenarioBuilder[InMemoryFilesSource]()
.set_name("multi_csv_stream_n_file_exceeds_config_limit_for_inference")
.set_config(
{
"streams": [
{
"name": "stream1",
"format": {"filetype": "csv"},
"globs": ["*"],
"validation_policy": "Emit Record",
"recent_n_files_to_read_for_schema_discovery": 3,
}
]
}
)
.set_source_builder(
FileBasedSourceBuilder()
.set_files(
{
"a.csv": {
"contents": [
("col1", "col2"),
("val11a", "val12a"),
("val21a", "val22a"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
"b.csv": {
"contents": [
("col1", "col2", "col3"),
("val11b", "val12b", "val13b"),
("val21b", "val22b", "val23b"),
],
"last_modified": "2023-06-05T03:54:07.000Z",
},
"c.csv": {
"contents": [
("col1", "col2", "col3", "col4"),
("val11c", "val12c", "val13c", "val14c"),