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

DMS/DynamoDB/MongoDB: Use SQL with parameters instead of inlining values #35

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

amotl
Copy link
Member

@amotl amotl commented Aug 26, 2024

About

At the core of this patch is the introduction of the SQLOperation class, which bundles together an SQL statement and its parameters, in order to convey those instances to callers, instead of rendering a full-fledged SQL statement in string format, which is problematic because of string escaping issues.

@define
class SQLOperation:
"""
Bundle data about an SQL operation, including statement and parameters.
Parameters can be a single dictionary or a list of dictionaries.
"""
statement: str
parameters: t.Optional[t.Union[t.Mapping[str, t.Any], t.List[t.Mapping[str, t.Any]]]] = None

Details

  • SQLOperation bundles data about an SQL operation, including statement and parameters.
  • DynamoDBFullLoadTranslator supports full-load data transfers.

References

This patch will need relevant adjustments in CrateDB Toolkit, effectively converging into releases of both packages in lock-step.

/cc @surister, @hammerhead, @hlcianfagna

@amotl amotl requested review from seut and wierdvanderhaar August 26, 2024 09:21
@amotl amotl marked this pull request as ready for review August 26, 2024 09:22
Copy link

@wierdvanderhaar wierdvanderhaar left a comment

Choose a reason for hiding this comment

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

I'm not able to test but based in the logic I think this looks good.

Copy link
Member

@seut seut left a comment

Choose a reason for hiding this comment

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

LGTM otherwise. Thx!

Manage details about a SQL parameterized clause, including column names, parameter names, and values.
"""

columns: t.List[str] = Factory(list)
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere? Looks to me this is only set but never read, but maybe I missed something.

Copy link
Member Author

@amotl amotl left a comment

Choose a reason for hiding this comment

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

Thanks for your positive review. Within this iteration, only the body of record values have been parameterized, i.e. the SET clause. The parameterization of values within the WHERE clauses have not been tackled yet.

@wierdvanderhaar: Software tests will be conducted on behalf of CrateDB Toolkit, but commons-codec will also receive an integration test suite in the future.

Comment on lines +109 to +114
@property
def set_clause(self):
"""
Render a SET clause of an SQL statement.
"""
return ", ".join([f"{key}={value}" for key, value in zip(self.columns, self.names)])
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for looking at the details. self.columns is used right here to render the parameterized SET clause.


columns: t.List[str] = Factory(list)
names: t.List[str] = Factory(list)
values: t.List[str] = Factory(list)
Copy link
Member Author

Choose a reason for hiding this comment

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

Most probably though, self.values is not used yet. However, there are also other shortcomings to be addressed on a subsequent iteration, see my followup PR comment.

- `SQLOperation` bundles data about an SQL operation, including
  statement and parameters.
- `DynamoDBFullLoadTranslator` supports full-load data transfers.
@amotl amotl merged commit c9e195c into main Aug 26, 2024
15 checks passed
@amotl amotl deleted the sql-with-params branch August 26, 2024 17:13
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.

3 participants