Skip to content
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

SQL Database: Support including/excluding NULL cursor values #1946

Merged
merged 4 commits into from
Oct 20, 2024

Conversation

steinitzu
Copy link
Collaborator

Description

Respect the on_cursor_value_missing incremental setting in sqlalchemy source.
Generating WHERE clause equvialent to:

-- include None
WHERE cursor_col >= :last_value OR cursor_col IS NULL

-- exclude None
WHERE cursor_col >= :last_value AND cursor_col IS NOT NULL

I'm not sure if the exclude case needs to be handled but thought I'd include explicitly anyway in case any databases interpret >= NULL differently.

Related Issues

Additional Context

Copy link

netlify bot commented Oct 10, 2024

Deploy Preview for dlt-hub-docs ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/6714de1e57a13bd240387e12
😎 Deploy Preview https://deploy-preview-1946--dlt-hub-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@steinitzu steinitzu marked this pull request as ready for review October 11, 2024 15:39
Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

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

looks good! see comments for small improvements

@@ -13,6 +13,8 @@
)
import operator

from sqlalchemy import and_, or_
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you import via our lib, not directly?

@@ -96,9 +100,15 @@ def _make_query(self) -> SelectAny:
return query # type: ignore[no-any-return]

if self.last_value is not None:
query = query.where(filter_op(self.cursor_column, self.last_value))
where_and_clauses = [filter_op(self.cursor_column, self.last_value)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

queries are OK. should exclude option be independent from if self.last_value is not None:? I think so. we could skip NONE also on initial load

@steinitzu steinitzu force-pushed the sql-database-include-none-cursor-value branch from 091548f to dfa300e Compare October 17, 2024 17:24
Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

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

LGTM!

@rudolfix rudolfix merged commit 213f82e into devel Oct 20, 2024
56 of 61 checks passed
@rudolfix rudolfix deleted the sql-database-include-none-cursor-value branch October 20, 2024 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql_database source ignores nullable cursor values during incremental loading
2 participants