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: add the ability to execute multiple statements in sql_raw plugins #3113

Merged
merged 3 commits into from
Jan 15, 2025

Conversation

rockwotj
Copy link
Collaborator

@rockwotj rockwotj commented Jan 14, 2025

A slightly different take on #2707 that doesn't require needing to parse SQL statements.

*Type*: `bool`


=== `queries`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am open to different designs/semantics.

@ligfx would love your thoughts feedback on this (there is an example above)

Copy link

Choose a reason for hiding this comment

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

Looks good to me 👍 This is pretty much the design I imagined when you said you wanted to have each query as a separate item.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good sign - really appreciate you taking a look!

_, err := db.Exec(fmt.Sprintf(`create table %s (
"foo" varchar(50) not null,
"bar" integer not null,
"bar" binary_float not null,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fixed the oracle tests, which are failing in main.

}

batch = batch.Copy()

for i, msg := range batch {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The logic here is a little more complex than I would like, so please do a close pass to make sure I didn't muck something up.

@rockwotj
Copy link
Collaborator Author

Will update the changelog prior to merging

Copy link
Collaborator

@Jeffail Jeffail left a comment

Choose a reason for hiding this comment

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

Couple comments, the important one is the output error handling, as that needs to differ quite a bit from the processor version.

if err != nil {
return err
msg.SetError(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

SetError doesn't work for outputs, we need to nack failed messages. The lazy way is to return the error and fail the whole batch, which is fine for now as it's what we do currently. However, eventually we'd want to create a BatchError and break down the errors by index to make retries more efficient and targeted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oof, duh. Thanks for catching. I rewrote this whole loop to use WalkWithBatchedErrors and it's better now.

return err
if tx != nil {
if err != nil {
msg.SetError(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above, we need to return the errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed


if _, err := s.db.ExecContext(ctx, queryStr, args...); err != nil {
return err
if tx != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a check for tx == nil that returns errors if appropriate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

} else {
rows, err := s.db.QueryContext(ctx, queryStr, args...)
}
if tx != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a tx == nil check on errors added as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Excellent catch!

Copy link
Collaborator

@mihaitodor mihaitodor 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 a few small nits. Feel free to 🐑 🚀

internal/impl/sql/conn_fields.go Show resolved Hide resolved
internal/impl/sql/processor_sql_raw.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Jeffail Jeffail left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@rockwotj rockwotj merged commit d32a89f into main Jan 15, 2025
4 checks passed
@rockwotj rockwotj deleted the sql-multi branch January 15, 2025 16:56
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.

4 participants