-
Notifications
You must be signed in to change notification settings - Fork 853
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
Conversation
*Type*: `bool` | ||
|
||
|
||
=== `queries` |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
Will update the changelog prior to merging |
There was a problem hiding this 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.
internal/impl/sql/output_sql_raw.go
Outdated
if err != nil { | ||
return err | ||
msg.SetError(err) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
internal/impl/sql/output_sql_raw.go
Outdated
return err | ||
if tx != nil { | ||
if err != nil { | ||
msg.SetError(err) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
internal/impl/sql/output_sql_raw.go
Outdated
|
||
if _, err := s.db.ExecContext(ctx, queryStr, args...); err != nil { | ||
return err | ||
if tx != nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent catch!
There was a problem hiding this 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 🐑 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
A slightly different take on #2707 that doesn't require needing to parse SQL statements.