-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(destination-motherduck): handle camel cased object/array columns #83694
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
Aaron ("AJ") Steers (aaronsteers)
merged 2 commits into
airbytehq:master
from
Donnype:donnypy/fix-motherduck-serialization-normalized-columns
Aug 4, 2026
Merged
Changes from all commits
Commits
Show all changes
2 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
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
2 changes: 1 addition & 1 deletion
2
airbyte-integrations/connectors/destination-motherduck/pyproject.toml
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| import pytest | ||
| from destination_motherduck.processors.duckdb import _serialize_object_columns | ||
|
|
||
| from airbyte_cdk.sql._util.name_normalizers import LowerCaseNormalizer | ||
|
|
||
|
|
||
| JSON_SCHEMA = { | ||
| "type": "object", | ||
|
|
@@ -15,6 +17,7 @@ | |
| "obj": {"type": ["null", "object"]}, | ||
| "array_of_objects": {"type": ["null", "array"], "items": {"type": "object"}}, | ||
| "array_of_scalars": {"type": ["null", "array"], "items": {"type": "string"}}, | ||
| "Line": {"type": ["null", "array"], "items": {"type": "object"}}, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -38,10 +41,11 @@ | |
| id="array_of_scalars_serialized", | ||
| ), | ||
| pytest.param("not_in_schema", [{"x": 1}], [{"x": 1}], id="airbyte_column_untouched"), | ||
| pytest.param("line", [[{}], None], ["[{}]", None], id="pascal_case_property_matched_via_normalization"), | ||
| ], | ||
| ) | ||
| def test_serialize_object_columns(col_name, values, expected) -> None: | ||
| result = _serialize_object_columns({col_name: values}, JSON_SCHEMA) | ||
| result = _serialize_object_columns({col_name: values}, JSON_SCHEMA, LowerCaseNormalizer) | ||
| assert result[col_name] == expected | ||
|
Comment on lines
47
to
49
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto my last comment. Passing the class is correct and expected. |
||
|
|
||
|
|
||
|
|
@@ -55,7 +59,7 @@ def test_serialize_object_columns_prevents_empty_struct_error() -> None: | |
| """ | ||
| buffer_data = {"id": ["1"], "array_of_objects": [[{}]]} | ||
|
|
||
| serialized = _serialize_object_columns(buffer_data, JSON_SCHEMA) | ||
| serialized = _serialize_object_columns(buffer_data, JSON_SCHEMA, LowerCaseNormalizer) | ||
| pa_table = pa.Table.from_pydict(serialized) | ||
|
|
||
| # The column must be a string, not a list-of-struct type. | ||
|
|
@@ -65,3 +69,23 @@ def test_serialize_object_columns_prevents_empty_struct_error() -> None: | |
| con = duckdb.connect() | ||
| con.register("buf", pa_table) | ||
| assert con.execute("SELECT array_of_objects FROM buf").fetchall() == [("[{}]",)] | ||
|
|
||
|
|
||
| def test_serialize_object_columns_normalized_column_names() -> None: | ||
| """Regression test for the empty STRUCT failure. | ||
|
|
||
| Buffer keys are normalized column names ("line"), but the schema property is the source's | ||
| original name ("Line"). Matching on the raw property names skips serialization entirely, so | ||
| `[{"SubTotalLineDetail": {}}]` reached PyArrow as `list<struct<SubTotalLineDetail: struct<>>>`, | ||
| which DuckDB rejects with "Attempted to convert a STRUCT with no fields to DuckDB". | ||
| """ | ||
| buffer_data = {"id": ["1"], "line": [[{"Amount": 100.0, "SubTotalLineDetail": {}}]]} | ||
|
|
||
| serialized = _serialize_object_columns(buffer_data, JSON_SCHEMA, LowerCaseNormalizer) | ||
| pa_table = pa.Table.from_pydict(serialized) | ||
|
|
||
| assert pa.types.is_string(pa_table.schema.field("line").type) | ||
|
|
||
| con = duckdb.connect() | ||
| con.register("buf", pa_table) | ||
| assert con.execute("SELECT line FROM buf").fetchall() == [('[{"Amount":100.0,"SubTotalLineDetail":{}}]',)] | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, I think this class is designed to work either way - with class methods and optional instance properties.
It may be fine as-is, or optionally as: