-
Notifications
You must be signed in to change notification settings - Fork 24
fix(sql): Add fallback to source_defined_primary_key
in CatalogProvider
#627
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
065e737
fix(sql): Add fallback to source_defined_primary_key in CatalogProvider
devin-ai-integration[bot] 821848b
refactor(sql): Simplify primary key fallback logic with one-liner
devin-ai-integration[bot] 565aa64
refactor(test): Parametrize catalog provider tests to reduce duplication
devin-ai-integration[bot] 07de856
docs(sql): Expand docstring for get_primary_keys to explain fallback …
devin-ai-integration[bot] b4aa7df
fix(format): Apply ruff formatting to docstring changes
devin-ai-integration[bot] 65e8e87
feat(sql): Prioritize source_defined_primary_key and return None when…
devin-ai-integration[bot] be8d806
feat(sql): Add guard statements for primary key validation in merge o…
devin-ai-integration[bot] 8d1ecae
fix(format): Break long docstring line to meet line length requirements
devin-ai-integration[bot] 625cd1e
fix(cherry-pick me): improve messaging for 'could not import module' …
aaronsteers 74240ab
docs(sql): Clarify that get_primary_keys returns column names, not va…
devin-ai-integration[bot] 7bf86ab
Merge branch 'devin/1751064114-fix-primary-key-fallback' of https://g…
aaronsteers 10f39d2
remove extra space
aaronsteers 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from airbyte_cdk.models import AirbyteStream, ConfiguredAirbyteCatalog, ConfiguredAirbyteStream | ||
from airbyte_cdk.sql.shared.catalog_providers import CatalogProvider | ||
|
||
|
||
class TestCatalogProvider: | ||
"""Test cases for CatalogProvider.get_primary_keys() method.""" | ||
|
||
@pytest.mark.parametrize( | ||
"configured_primary_key,source_defined_primary_key,expected_result,test_description", | ||
[ | ||
(["configured_id"], ["source_id"], ["source_id"], "prioritizes source when both set"), | ||
([], ["source_id"], ["source_id"], "uses source when configured empty"), | ||
(None, ["source_id"], ["source_id"], "uses source when configured None"), | ||
( | ||
["configured_id"], | ||
[], | ||
["configured_id"], | ||
"falls back to configured when source empty", | ||
), | ||
( | ||
["configured_id"], | ||
None, | ||
["configured_id"], | ||
"falls back to configured when source None", | ||
), | ||
([], [], None, "returns None when both empty"), | ||
(None, None, None, "returns None when both None"), | ||
([], ["id1", "id2"], ["id1", "id2"], "handles composite keys from source"), | ||
], | ||
) | ||
def test_get_primary_keys_parametrized( | ||
self, configured_primary_key, source_defined_primary_key, expected_result, test_description | ||
): | ||
"""Test primary key fallback logic with various input combinations.""" | ||
configured_pk_wrapped = ( | ||
None | ||
if configured_primary_key is None | ||
else [[pk] for pk in configured_primary_key] | ||
if configured_primary_key | ||
else [] | ||
) | ||
source_pk_wrapped = ( | ||
None | ||
if source_defined_primary_key is None | ||
else [[pk] for pk in source_defined_primary_key] | ||
if source_defined_primary_key | ||
else [] | ||
) | ||
|
||
stream = AirbyteStream( | ||
name="test_stream", | ||
json_schema={ | ||
"type": "object", | ||
"properties": { | ||
"id": {"type": "string"}, | ||
"id1": {"type": "string"}, | ||
"id2": {"type": "string"}, | ||
}, | ||
}, | ||
supported_sync_modes=["full_refresh"], | ||
source_defined_primary_key=source_pk_wrapped, | ||
) | ||
configured_stream = ConfiguredAirbyteStream( | ||
stream=stream, | ||
sync_mode="full_refresh", | ||
destination_sync_mode="overwrite", | ||
primary_key=configured_pk_wrapped, | ||
) | ||
catalog = ConfiguredAirbyteCatalog(streams=[configured_stream]) | ||
|
||
provider = CatalogProvider(catalog) | ||
result = provider.get_primary_keys("test_stream") | ||
|
||
assert result == expected_result |
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.