Repository navigation
fix(file-based): sample one file per path shape when capping schema inference - #1161
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1789433905-schema-inference-path-diversity#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1789433905-schema-inference-path-diversityPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
There was a problem hiding this comment.
🟡 Changes recommended
The selector can sample files outside the configured recent window.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Updates file-based schema inference to sample recent files across distinct path shapes when the file cap is reached.
Changes:
- Adds path-shape grouping and diverse file selection.
- Logs selected files for debugging.
- Adds unit and integration coverage.
Review finding (moderate, 3 votes): candidates should be limited to the configured recent-file window before diversification.
File summaries
| File | Summary |
|---|---|
unit_tests/sources/file_based/stream/test_default_file_based_stream.py |
Tests grouping, selection, and integration behavior. |
airbyte_cdk/sources/file_based/stream/default_file_based_stream.py |
Implements diverse capped schema sampling. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| first_n_files = max_n_files_for_schema_inference | ||
|
|
||
| files = sorted(files, key=lambda x: x.last_modified, reverse=True)[:first_n_files] | ||
| files = self._select_files_for_schema_inference(files, max_n_files_for_schema_inference) |
There was a problem hiding this comment.
👍 On it. Correct — when recent_n_files_to_read_for_schema_discovery exceeds the policy cap, the selector should only diversify within the newest first_n_files, not the whole listing. Will slice to that window before selecting and add a test for it.
There was a problem hiding this comment.
☑️ Resolved in 14b8466. Candidates are now sliced to the newest first_n_files before path-diverse selection, so recent_n_files_to_read_for_schema_discovery still bounds the window; added test_when_recent_n_files_exceeds_cap_then_selection_stays_within_recent_window.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
PyTest Results (Full)4 401 tests +10 4 388 ✅ +9 9m 37s ⏱️ - 4m 24s For more details on these failures, see this check. Results for commit 14b8466. ± Comparison against base commit 96a7c0a. |
|
Closing per maintainer request; the problem is being tracked as an internal issue instead of prescribing this fix. |
Overview
👉 TL;DR: When a file-based stream has too many files to read them all during schema discovery, the connector now samples one recent file from each distinct folder/file-name pattern instead of just the newest files. This stops buckets that mix several file types from producing a different schema on every discovery, which was flagging spurious breaking schema changes and disabling connections.
Specifically,
DefaultFileBasedStream._get_raw_json_schemanow selects files via the new_select_files_for_schema_inference/_schema_inference_group_keyhelpers when capping toget_max_n_files_for_schema_inference().Requested by Stephen Ibuoye (Airbyte support) for a Cloud S3 → Snowflake connection with ~67K heterogeneous Avro files.
Changes
_schema_inference_group_key(uri): directory segments containing a digit (dates, ids, uuids, hashes) become*; the file name is reduced to its leading alphabetic prefix + extension._select_files_for_schema_inference(files, n): newest-first, one file per group key first, then fill remaining slots with the next-newest files.first_n_files, sorecent_n_files_to_read_for_schema_discoverystill bounds the window.use_first_found_file_for_schema_discoveryis unaffected._get_raw_json_schemaintegration, and the recent-window bound.Review Spotlight
Reviewers with limited time, please review first:
default_file_based_stream.py#L306-L320: the capped branch now calls the diverse selector on the recent windowdefault_file_based_stream.py#L335-L374: grouping heuristic and selectionRisks
Follow-ups
source-s3(and other file-based connectors) to a CDK release containing this change.Test plan
poetry run pytest unit_tests/sources/file_based/stream/test_default_file_based_stream.py -q→ 33 passedpoetry run ruff check/ruff format --checkon the two changed files → cleanpoetry run mypy --config-file mypy.ini airbyte_cdk/sources/file_based/stream/default_file_based_stream.py→ no issuesDesign notes: why the sampling was unstable
Show/Hide Content
The affected bucket is a Pendo export writing
.../<uuid>/matchedEvents/Page/Page-<hash>.avro,.../matchedEvents/Feature/Feature-<hash>.avro,.../allguides.avro,.../allpages.avro, ... under one prefix. The 10 newest files are frequently allPagefiles, so columns present only in the other event types (guideId,pollId,uiElementId, ...) drop out of the inferred schema. Those columns are part of the user-defined composite primary key withappend_dedup, so the platform (CatalogDiffHelpers.fieldTransformBreaksConnection) marks the removal as breaking and disables the connection. Reviewing triggers another discovery against a different 10 files where the columns are present again, so the change appears to "auto-resolve". Sampling one file per path shape makes the sampled set cover every file family regardless of which family was exported most recently.Link to Devin session: https://app.devin.ai/sessions/1ccc4b821f6049e698ef5810f88b3383
Open in Devin Desktop: https://app.devin.ai/desktop/session/1ccc4b821f6049e698ef5810f88b3383?variant=devin