-
Notifications
You must be signed in to change notification settings - Fork 24
🚨🚨[DON'T MERGE] all CDK changes for google analytics migration🚨🚨 #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
lazebnyi
wants to merge
3
commits into
main
from
lazebnyi/all-chenges-for-google-analytics-migration
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
airbyte_cdk/sources/declarative/extractors/combined_extractor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from dataclasses import InitVar, dataclass, field | ||
from itertools import islice | ||
from typing import Any, Iterable, List, Mapping, MutableMapping, Union | ||
|
||
import dpath | ||
import requests | ||
|
||
from airbyte_cdk.sources.declarative.decoders import Decoder, JsonDecoder | ||
from airbyte_cdk.sources.declarative.extractors.record_extractor import RecordExtractor | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_string import InterpolatedString | ||
from airbyte_cdk.sources.types import Config | ||
|
||
|
||
@dataclass | ||
class CombinedExtractor(RecordExtractor): | ||
""" | ||
Extractor that combines keys and values from two separate extractors. | ||
|
||
The `keys_extractor` and `values_extractor` extract records independently | ||
from the response. Their outputs are zipped together to form key-value mappings. | ||
|
||
Each key from `keys_extractor` should correspond to a key in the resulting dictionary, | ||
and each value from `values_extractor` is the value for that key. | ||
|
||
Example: | ||
keys_extractor -> yields: ["name", "age"] | ||
values_extractor -> yields: ["Alice", 30] | ||
result: { "name": "Alice", "age": 30 } | ||
""" | ||
|
||
extractors: List[RecordExtractor] | ||
|
||
def extract_records(self, response: requests.Response) -> Iterable[MutableMapping[Any, Any]]: | ||
extractors_records = [extractor.extract_records(response) for extractor in self.extractors] | ||
|
||
for records in zip(*extractors_records): | ||
merged = {} | ||
for record in records: | ||
merged.update(record) # merge all fields | ||
yield merged |
46 changes: 46 additions & 0 deletions
46
airbyte_cdk/sources/declarative/extractors/key_value_extractor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from dataclasses import InitVar, dataclass, field | ||
from itertools import islice | ||
from typing import Any, Iterable, List, Mapping, MutableMapping, Union | ||
|
||
import dpath | ||
import requests | ||
|
||
from airbyte_cdk.sources.declarative.decoders import Decoder, JsonDecoder | ||
from airbyte_cdk.sources.declarative.extractors.record_extractor import RecordExtractor | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_string import InterpolatedString | ||
from airbyte_cdk.sources.types import Config | ||
|
||
|
||
@dataclass | ||
class KeyValueExtractor(RecordExtractor): | ||
""" | ||
Extractor that combines keys and values from two separate extractors. | ||
|
||
The `keys_extractor` and `values_extractor` extract records independently | ||
from the response. Their outputs are zipped together to form key-value mappings. | ||
|
||
Each key from `keys_extractor` should correspond to a key in the resulting dictionary, | ||
and each value from `values_extractor` is the value for that key. | ||
|
||
Example: | ||
keys_extractor -> yields: ["name", "age"] | ||
values_extractor -> yields: ["Alice", 30] | ||
result: { "name": "Alice", "age": 30 } | ||
""" | ||
|
||
keys_extractor: RecordExtractor | ||
values_extractor: RecordExtractor | ||
|
||
def extract_records(self, response: requests.Response) -> Iterable[MutableMapping[Any, Any]]: | ||
keys = list(self.keys_extractor.extract_records(response)) | ||
values = self.values_extractor.extract_records(response) | ||
|
||
while True: | ||
chunk = list(islice(values, len(keys))) | ||
if not chunk: | ||
break | ||
yield dict(zip(keys, chunk)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.