Skip to content

Commit 5405a52

Browse files
committed
Add unit tests for flatten fields tranformation
1 parent 010543c commit 5405a52

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ definitions:
12351235
- "$ref": "#/definitions/RemoveFields"
12361236
- "$ref": "#/definitions/KeysToLower"
12371237
- "$ref": "#/definitions/KeysToSnakeCase"
1238+
- "$ref": "#/definitions/FlattenFields"
12381239
state_migrations:
12391240
title: State Migrations
12401241
description: Array of state migrations to be applied on the input state
@@ -1778,6 +1779,7 @@ definitions:
17781779
- "$ref": "#/definitions/RemoveFields"
17791780
- "$ref": "#/definitions/KeysToLower"
17801781
- "$ref": "#/definitions/KeysToSnakeCase"
1782+
- "$ref": "#/definitions/FlattenFields"
17811783
schema_type_identifier:
17821784
"$ref": "#/definitions/SchemaTypeIdentifier"
17831785
$parameters:

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ class Config:
16711671
RemoveFields,
16721672
KeysToLower,
16731673
KeysToSnakeCase,
1674+
FlattenFields,
16741675
]
16751676
]
16761677
] = Field(
@@ -1844,6 +1845,7 @@ class DynamicSchemaLoader(BaseModel):
18441845
RemoveFields,
18451846
KeysToLower,
18461847
KeysToSnakeCase,
1848+
FlattenFields,
18471849
]
18481850
]
18491851
] = Field(

unit_tests/sources/declarative/test_manifest_declarative_source.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,90 @@ def _create_page(response_body):
13671367
],
13681368
[call({}, {})],
13691369
),
1370+
(
1371+
"test_read_manifest_with_flatten_fields",
1372+
{
1373+
"version": "0.34.2",
1374+
"type": "DeclarativeSource",
1375+
"check": {"type": "CheckStream", "stream_names": ["Rates"]},
1376+
"streams": [
1377+
{
1378+
"type": "DeclarativeStream",
1379+
"name": "Rates",
1380+
"primary_key": [],
1381+
"schema_loader": {
1382+
"type": "InlineSchemaLoader",
1383+
"schema": {
1384+
"$schema": "http://json-schema.org/schema#",
1385+
"properties": {
1386+
"ABC": {"type": "number"},
1387+
"AED": {"type": "number"},
1388+
},
1389+
"type": "object",
1390+
},
1391+
},
1392+
"transformations": [{"type": "FlattenFields"}],
1393+
"retriever": {
1394+
"type": "SimpleRetriever",
1395+
"requester": {
1396+
"type": "HttpRequester",
1397+
"url_base": "https://api.apilayer.com",
1398+
"path": "/exchangerates_data/latest",
1399+
"http_method": "GET",
1400+
"request_parameters": {},
1401+
"request_headers": {},
1402+
"request_body_json": {},
1403+
"authenticator": {
1404+
"type": "ApiKeyAuthenticator",
1405+
"header": "apikey",
1406+
"api_token": "{{ config['api_key'] }}",
1407+
},
1408+
},
1409+
"record_selector": {
1410+
"type": "RecordSelector",
1411+
"extractor": {"type": "DpathExtractor", "field_path": ["rates"]},
1412+
},
1413+
"paginator": {"type": "NoPagination"},
1414+
},
1415+
}
1416+
],
1417+
"spec": {
1418+
"connection_specification": {
1419+
"$schema": "http://json-schema.org/draft-07/schema#",
1420+
"type": "object",
1421+
"required": ["api_key"],
1422+
"properties": {
1423+
"api_key": {
1424+
"type": "string",
1425+
"title": "API Key",
1426+
"airbyte_secret": True,
1427+
}
1428+
},
1429+
"additionalProperties": True,
1430+
},
1431+
"documentation_url": "https://example.org",
1432+
"type": "Spec",
1433+
},
1434+
},
1435+
(
1436+
_create_page(
1437+
{
1438+
"rates": [
1439+
{"nested_fields": {"ABC": 0}, "id": 1},
1440+
{"nested_fields": {"AED": 1}, "id": 2},
1441+
],
1442+
"_metadata": {"next": "next"},
1443+
}
1444+
),
1445+
_create_page({"rates": [{"USD": 2}], "_metadata": {"next": "next"}}),
1446+
)
1447+
* 10,
1448+
[
1449+
{"ABC": 0, "id": 1},
1450+
{"AED": 1, "id": 2},
1451+
],
1452+
[call({}, {})],
1453+
),
13701454
(
13711455
"test_read_with_pagination_no_partitions",
13721456
{

0 commit comments

Comments
 (0)