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

Add max_table_nesting to resource decorator #1242

Merged
merged 42 commits into from
Apr 24, 2024

Conversation

sultaniman
Copy link
Contributor

This PR addresses #945 and implements max_table_nesting for resources

@sultaniman sultaniman self-assigned this Apr 18, 2024
Copy link

netlify bot commented Apr 18, 2024

Deploy Preview for dlt-hub-docs ready!

Name Link
🔨 Latest commit 72ed561
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/662920fefaa7bf00083622ac
😎 Deploy Preview https://deploy-preview-1242--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.

def test_resource_max_nesting(
nesting_level: int, expected_num_tables: int, expected_table_names: List[str]
):
@dlt.resource(max_table_nesting=nesting_level)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should have multiple resources with different nesting levels at the same time here, also add a source with a nesting level and check that it is overwritten by the resource setting but kept when there is no resource settingl.

Copy link
Collaborator

Choose a reason for hiding this comment

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

also test what happens if you load to the same table again with the same pipeline but set no nesting level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sh-rp I updated the test with additional check

  1. setting the max_table_nesting
  2. then running the pipeline
  3. unsetting the max_table_nesting
  4. check if the tables are still there.

@sultaniman sultaniman force-pushed the feat/resource-max-nesting-level branch from 0bb86a3 to d35775a Compare April 19, 2024 08:15
@sultaniman sultaniman marked this pull request as ready for review April 19, 2024 12:07
@sultaniman sultaniman requested a review from sh-rp April 19, 2024 12:25
@sultaniman sultaniman added the enhancement New feature or request label Apr 19, 2024
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! just two small improvements and a chapter in the docs :)

@@ -79,21 +80,27 @@ def _is_complex_type(self, table_name: str, field_name: str, _r_lvl: int) -> boo
# turn everything at the recursion level into complex type
max_nesting = self.max_nesting
schema = self.schema
table = schema.tables.get(table_name)
if table:
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we able to cache nesting per table in extend_table? and here to only access a dict with a cache? why: because this is called for each dict/list in the results so is time critical

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I am not sure if I understand extend_table ’s purpose and how to use it, grepping in source code doesn’t give definitive examples I could use, should I just define some dictionary for this? Now that we have getter and setter in a resource we will have to invalidate this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rudolfix can you please take a look again?

dlt/extract/decorators.py Show resolved Hide resolved
@sultaniman sultaniman force-pushed the feat/resource-max-nesting-level branch from 652446a to d5a80ee Compare April 19, 2024 14:56
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.

  1. please improve the docs and maybe ask @VioletM for proof reading
  2. you do not test getter / setter for max_table_nesting

otherwise LGTM!

docs/website/docs/general-usage/resource.md Outdated Show resolved Hide resolved
docs/website/docs/general-usage/resource.md Outdated Show resolved Hide resolved
@sultaniman sultaniman force-pushed the feat/resource-max-nesting-level branch from d5a80ee to 129502e Compare April 24, 2024 07:28
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.

Maybe I'm too picky

  1. you never read max_table_nesting only set it. read it ie. to check if you see the same value as in decorator and if the setter works
  2. max_table_nesting will not see the value coming from the source, right? then also test for it and comment that we do not support it

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 4cce178 into devel Apr 24, 2024
48 checks passed
@rudolfix rudolfix deleted the feat/resource-max-nesting-level branch April 24, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants