Skip to content

feat: Allow SQL targets to customize how they parse <db>-<schema>-<table> and <schema>-<table> stream names explicitly - #3776

Draft
edgarrmondragon wants to merge 4 commits into
mainfrom
feat/parse-stream-parts
Draft

edgarrmondragon wants to merge 4 commits into
mainfrom
feat/parse-stream-parts

Conversation

@edgarrmondragon

@edgarrmondragon edgarrmondragon commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Related

Summary by Sourcery

Enable customizable SQL stream-name parsing and adapt SQLite targets to represent qualifiers as physical table-name components.

New Features:

  • Allow SQL targets to customize parsing of database, schema, and table components from stream names.
  • Fold SQLite database and schema qualifiers into physical table names because SQLite does not support cross-database or user-defined schemas.

Bug Fixes:

  • Prevent SQLite from attempting unsupported schema creation for schema-qualified stream names.

Enhancements:

  • Centralize stream-name parsing in SQL sinks and make database handling explicitly overridable while preserving single-database defaults.

Documentation:

  • Document the default stream-name parsing behavior and customization options for SQL targets.

Tests:

  • Update SQLite coverage to verify schema-qualified streams load into folded table names.
  • Add coverage for existing and missing schema detection and schema preparation behavior.

…able>` and `<schema>-<table>` stream names explicitly

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon edgarrmondragon self-assigned this Sep 11, 2026
@edgarrmondragon edgarrmondragon added SQL Support for SQL taps and targets Type/Target Singer targets labels Sep 11, 2026
@edgarrmondragon edgarrmondragon added this to the v0.55 milestone Sep 11, 2026
@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Introduces a centralized, overridable SQL stream-name parser and uses a SQLite-specific implementation to fold qualified stream names into physical tables, with tests updated to validate successful schema-qualified loads.

Sequence diagram for SQLite qualified stream-name folding

sequenceDiagram
    participant Stream as Stream name
    participant SQLiteSink
    participant SQLSink
    participant SQLiteDB as SQLite database

    Stream->>SQLiteSink: parse_stream_name(stream_name)
    SQLiteSink->>SQLSink: parse_stream_name(stream_name)
    SQLSink-->>SQLiteSink: db_name, schema_name, table_name
    SQLiteSink-->>SQLiteSink: filter main/temp and join qualifiers with __
    SQLiteSink-->>SQLiteSink: return None, None, folded_table_name
    SQLiteSink->>SQLiteDB: load into folded physical table
Loading

Flow diagram for SQL stream-name component resolution

flowchart LR
    A[stream_name] --> B[SQLSink.parse_stream_name]
    B --> C[stream_name_parts]
    C --> D[table_name]
    C --> E[schema_name]
    C --> F[database_name]
    B --> G[SQLiteSink.parse_stream_name]
    G --> H[Drop main/temp qualifiers]
    H --> I[Join remaining qualifiers with __]
    I --> J[SQLite physical table name]
Loading

File-Level Changes

Change Details Files
Centralize stream-name parsing and expose an override point for target-specific naming conventions.
  • Add cached database/schema/table stream components.
  • Replace ad hoc parsing in table, schema, and database properties with the centralized components.
  • Keep the default database behavior single-database while documenting override patterns for targets that honor database segments.
singer_sdk/sql/sink.py
Adapt SQLite stream names to its single-database, schema-less storage model.
  • Fold database and schema qualifiers into physical table names separated by double underscores.
  • Ignore SQLite’s built-in main and temp qualifiers.
  • Return no database or schema for the folded SQLite table representation.
packages/meltano-target-sqlite/target_sqlite/target.py
Update SQLite coverage for successful loading and querying of schema-qualified streams.
  • Replace the expected schema-creation failure with a successful sync assertion.
  • Verify rows are stored under the folded physical table name.
tests/packages/test_target_sqlite.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Sep 11, 2026

Copy link
Copy Markdown

Documentation build overview

📚 Meltano SDK | 🛠️ Build #34519074 | 📁 Comparing 612a810 against latest (43b3563)

  🔍 Preview build  

2 files changed
± genindex.html
± classes/singer_sdk.sql.SQLSink.html

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.48%. Comparing base (43b3563) to head (612a810).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3776   +/-   ##
=======================================
  Coverage   94.47%   94.48%           
=======================================
  Files          74       74           
  Lines        6298     6309   +11     
  Branches      771      773    +2     
=======================================
+ Hits         5950     5961   +11     
  Misses        260      260           
  Partials       88       88           
Flag Coverage Δ
core 83.21% <100.00%> (+0.12%) ⬆️
end-to-end 76.05% <75.00%> (-0.17%) ⬇️
optional-components 44.96% <31.25%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@edgarrmondragon

Copy link
Copy Markdown
Collaborator Author

@sourcery-ai review

@codspeed

codspeed Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 14 untouched benchmarks


Comparing feat/parse-stream-parts (612a810) with main (43b3563)

Open in CodSpeed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/meltano-target-sqlite/target_sqlite/target.py" line_range="136" />
<code_context>
+            for part in (db_name, schema_name)
+            if part and part.lower() not in self._default_schemas
+        ]
+        return None, None, "__".join([*qualifiers, table_name])
+

</code_context>
<issue_to_address>
**issue (bug_risk):** SQLite folds a qualified stream into a physical table name but the inherited `schema_name` still returns the configured `default_target_schema` whenever that setting is present. The sink then prepares and addresses the folded table under that SQLite schema, causing schema-qualified streams to fail with SQLite's unsupported schema handling instead of loading into the folded table.

**Triggers:** When the SQLite target configuration sets `default_target_schema` and the stream name contains a schema or database qualifier.

**Suggested fix:** Override `schema_name` for SQLite to always return `None`, or otherwise ensure the SQLite parser's folded representation takes precedence over `default_target_schema`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the parsing convention is wrong, records can be written to an unexpected physical table or with an unexpected folded name, and reverting will not remove or relocate those tables automatically. The misplaced data is bounded and can be repaired by moving or reloading it, rather than causing irreversible deletion or external side effects.

Blocking findings: packages/meltano-target-sqlite/target_sqlite/target.py:136


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread packages/meltano-target-sqlite/target_sqlite/target.py
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SQL Support for SQL taps and targets Type/Target Singer targets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant