Skip to content

feat: Support for User Specifying Primary Key Scheme (default or cq-ids)#732

Merged
kodiakhq[bot] merged 27 commits intocloudquery:mainfrom
bbernays:cq-id-as-pk
Mar 17, 2023
Merged

feat: Support for User Specifying Primary Key Scheme (default or cq-ids)#732
kodiakhq[bot] merged 27 commits intocloudquery:mainfrom
bbernays:cq-id-as-pk

Conversation

@bbernays
Copy link
Copy Markdown
Contributor

@bbernays bbernays commented Mar 14, 2023

Summary

Initial implementation for cloudquery/cloudquery#8811


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 14, 2023

⏱️ Benchmark results

  • DefaultConcurrencyDFS-2 resources/s: 10,698
  • DefaultConcurrencyRoundRobin-2 resources/s: 11,087
  • Glob-2 ns/op: 278.4
  • TablesWithChildrenDFS-2 resources/s: 23,905
  • TablesWithChildrenRoundRobin-2 resources/s: 22,564
  • TablesWithRateLimitingDFS-2 resources/s: 28.32
  • TablesWithRateLimitingRoundRobin-2 resources/s: 846.5
  • BufferedScanner-2 ns/op: 12.52
  • LogReader-2 ns/op: 39.75

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 48.93% and project coverage change: -5.68 ⚠️

Comparison is base (a0a58c4) 48.82% compared to head (7c323cc) 43.15%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #732      +/-   ##
==========================================
- Coverage   48.82%   43.15%   -5.68%     
==========================================
  Files          70       80      +10     
  Lines        6923     7886     +963     
==========================================
+ Hits         3380     3403      +23     
- Misses       3077     4015     +938     
- Partials      466      468       +2     
Impacted Files Coverage Δ
plugins/destination/plugin_testing.go 0.00% <0.00%> (ø)
plugins/destination/plugin_testing_migrate.go 0.00% <0.00%> (ø)
specs/destination.go 68.51% <ø> (ø)
plugins/destination/plugin.go 3.48% <50.00%> (ø)
specs/pk_mode.go 69.56% <69.56%> (ø)
schema/table.go 44.58% <100.00%> (+0.23%) ⬆️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

I know this is still in draft, but maybe since PKs and columns are defined on sources, this should be a source option?

I mean, what if I want _cq_id PK for AWS, and regular PKs for Azure?

@bbernays
Copy link
Copy Markdown
Contributor Author

I know this is still in draft, but maybe since PKs and columns are defined on sources, this should be a source option?

I mean, what if I want _cq_id PK for AWS, and regular PKs for Azure?

I am actually against putting it on the source because then the user will have to fetch the same data multiple times if they want to put the same data in multiple destinations (with different PK settings). In the case where a user has multiple sources and a single destination but want different behavior for each source, they should duplicate the destination.

@erezrokah
Copy link
Copy Markdown
Member

I am actually against putting it on the source because then the user will have to fetch the same data multiple times if they want to put the same data in multiple destinations (with different PK settings). In the case where a user has multiple sources and a single destination but want different behavior for each source, they should duplicate the destination.

Got it, makes sense

@bbernays bbernays marked this pull request as ready for review March 14, 2023 19:25
@bbernays bbernays requested a review from yevgenypats as a code owner March 14, 2023 19:25
Copy link
Copy Markdown
Member

@disq disq left a comment

Choose a reason for hiding this comment

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

LGTM, looked for a simpler approach but I don't see it

@bbernays bbernays changed the title feat: Destination Spec Support for Different Primary Key feat: Support for User Specifying Primary Key Scheme (composite or cq-id) Mar 15, 2023
@github-actions github-actions bot added feat and removed feat labels Mar 15, 2023
Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Added a few comments (non blocking)

Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
@bbernays bbernays changed the title feat: Support for User Specifying Primary Key Scheme (composite or cq-id) feat: Support for User Specifying Primary Key Scheme (default or cq-ids) Mar 15, 2023
@github-actions github-actions bot added feat and removed feat labels Mar 15, 2023
@yevgenypats yevgenypats self-requested a review March 16, 2023 07:34
Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

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

I think setCQIDAsPrimaryKeysForTables might need to be called also on destination Write . We have e2e test suites in the SDK under https://github.com/cloudquery/plugin-sdk/tree/main/internal/memdb we might want to see that this test is covered there as well.

SetDestinationManagedCqColumns(tables)
setCqIDColumnOptionsForTables(tables)
if p.spec.PKMode == specs.PKModeCQID {
setCQIDAsPrimaryKeysForTables(tables)
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.

Should that also be called on Write?

@bbernays bbernays requested a review from yevgenypats March 16, 2023 16:48
@bbernays bbernays requested a review from candiduslynx March 16, 2023 18:08
Copy link
Copy Markdown
Contributor

@candiduslynx candiduslynx left a comment

Choose a reason for hiding this comment

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

1 nit, non-blocking

case schema.CqIDColumn.Name:
table.Columns[i].CreationOptions.PrimaryKey = true
case schema.CqParentIDColumn.Name:
table.Columns[i].CreationOptions.PrimaryKey = table.Parent != nil
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.

Why a parent should ever be a primary key ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

2 different top level resources could resolve the same nested resource. In that case, the cq_id would be the same which means that one of the resources would be dropped

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have removed this because the table.Parent is always nil

Copy link
Copy Markdown
Contributor

@candiduslynx candiduslynx left a comment

Choose a reason for hiding this comment

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

also a non-blocking nit

bbernays and others added 2 commits March 17, 2023 09:48
Co-authored-by: candiduslynx <candiduslynx@users.noreply.github.com>
@kodiakhq kodiakhq bot merged commit a41af50 into cloudquery:main Mar 17, 2023
kodiakhq bot pushed a commit that referenced this pull request Mar 19, 2023
🤖 I have created a release *beep* *boop*
---


## [1.44.0](v1.43.0...v1.44.0) (2023-03-17)


### Features

* Support for User Specifying Primary Key Scheme (default or cq-ids) ([#732](#732)) ([a41af50](a41af50))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants