Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AddBulkResponse wrapper for improved decoding of HTTP bulk responses#649

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
amotl wants to merge5 commits intomain
base:main
Choose a base branch
Loading
frombulk-response-wrapper

Conversation

@amotl
Copy link
Member

@amotlamotl commentedOct 2, 2024
edited
Loading

About

CrateDB HTTP bulk responses includerowcount= items, either signalling if a bulk operation succeeded or failed.

  • success meansrowcount=1
  • failure meansrowcount=-2

https://cratedb.com/docs/crate/reference/en/latest/interfaces/http.html#error-handling

References

The code is coming from CrateDB Toolkit, but is generally usable beyond there.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

tests.py is the entrypoint for zope.testing to discover test cases. Many utility functions had to be refactored away from here, in order to avoid circular imports.

@amotlamotlforce-pushed thebulk-response-wrapper branch 3 times, most recently from7ef36cd toccbffd2CompareOctober 2, 2024 21:06
@amotlamotl requested review frommatriv andseutOctober 2, 2024 21:13
@amotlamotl marked this pull request as ready for reviewOctober 2, 2024 21:13
Copy link
Contributor

@matrivmatriv left a comment

Choose a reason for hiding this comment

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

Thx for improving the bulk response handling. Left some comments.

@amotlamotlforce-pushed thebulk-response-wrapper branch fromccbffd2 toea27b3eCompareOctober 3, 2024 12:43
@amotlamotl requested a review frommatrivOctober 3, 2024 12:47
@amotlamotlforce-pushed thebulk-response-wrapper branch 2 times, most recently from50347d4 to433dfdfCompareOctober 3, 2024 13:03
@amotlamotlforce-pushed thebulk-response-wrapper branch 2 times, most recently from4da893a to6a58353CompareOctober 3, 2024 19:33
self.assertEqual(result, [{"rowcount": 1}, {"rowcount": -2}])

# Verify decoded response.
bulk_response = BulkResponse(invalid_records, result)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this more carefully, I don't like that BulkResponse is something you need con construct manually. Couldn't we directly return it from the insert execution, instead of a list ofBulkResultItem?

Copy link
MemberAuthor

@amotlamotlOct 6, 2024
edited
Loading

Choose a reason for hiding this comment

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

Hi. I don't think we can do anything like this here, because the Python database driver must adhere to thePython Database API Specification, so theBulkResponse is just meant as an optional extension to it.

Copy link
MemberAuthor

@amotlamotlOct 6, 2024
edited
Loading

Choose a reason for hiding this comment

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

af32409, just added, provides a bit of documentation for that extension in the section about bulk operations.

Copy link
Member

@mfusseneggermfussenegger left a comment

Choose a reason for hiding this comment

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

Could you elaborate a bit more on the motivation for this?

Seems to me as if getting the info without this is not really that much more difficult.

@amotl
Copy link
MemberAuthor

Hi@mfussenegger,

The code is coming from CrateDB Toolkit, but is generally usable beyond there.

The idea is to have a concise code representationover here, for theBulkProcessor component, by abstracting away the handling of magic numbers from user-side code.

Because CrateDB Toolkit is rather heavy, and I wanted to make it reusable, I wanted to add it elsewhere. Another option would be to use the now separate cratedb-sqlalchemy package.BulkProcessor depends on it anyway, butBulkResponse doesn't, and would provide a generic little convenience wrapper around CrateDB's special responses to bulk requests.

@mfussenegger
Copy link
Member

The idea is to have a concise code representationover here, for theBulkProcessor component, by abstracting away the handling of magic numbers from user-side code.

That kinda confirms my point in that there's not much more code without the BulkResponse wrapper:

cursor=self.connection.execute(statement=statement,parameters=operation.parameters)self.connection.commit()cratedb_bulk_result=getattr(cursor.context,"last_executemany_result",None)failed_records=0success_count=0forresultincratedb_bulk_result:ifresult["rowcount"]==-2:failed_records+=1else:success_count+=1self._metrics.count_success_total+=success_countself.progress_barandself.progress_bar.update(n=success_count)

This to me would even be more readable as it avoids the additional indirection.

Also, given that the DB API spec says:

Return values are not defined.

I think we could extend our return value - as long as we can keep it compatible with the existing one.

@amotlamotl marked this pull request as draftOctober 7, 2024 22:26
... when another CrateDB is running on the default port 4200.
`tests.py` is the entrypoint file that will be used by `zope.testing` todiscover the test cases on behalf of what's returned from `test_suite`.It is better to not overload it with other support code that may also beneeded in other contexts.
git mv src/crate/client/test* tests/client/git mv src/crate/testing/test* tests/testing/
CrateDB HTTP bulk responses include `rowcount=` items, either signallingif a bulk operation succeeded or failed.- success means `rowcount=1`- failure means `rowcount=-2`https://cratedb.com/docs/crate/reference/en/latest/interfaces/http.html#error-handling
@amotlamotl changed the base branch frommaster tobetter-testingOctober 31, 2024 16:04
@amotlamotlforce-pushed thebulk-response-wrapper branch fromaaf9ca6 toa016130CompareOctober 31, 2024 16:04
@amotlamotl added the triageAn issue that needs to be triaged by a maintainer labelOct 31, 2024
Base automatically changed frombetter-testing tomasterNovember 1, 2024 09:46
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mfusseneggermfusseneggermfussenegger left review comments

@matrivmatrivmatriv approved these changes

@seutseutAwaiting requested review from seut

Assignees

No one assigned

Labels

cla-signedtriageAn issue that needs to be triaged by a maintainer

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@amotl@mfussenegger@matriv

[8]ページ先頭

©2009-2025 Movatter.jp