-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add a new Queries task to run multiple SQL with multiple outputs, parameter binding and transactions #368
Comments
@loicmathieu can you perhaps check the proposed design, evaluate the feasibility and let Matt tackle this with your guidance and review? |
Design is OK, the only complexity will be to parse the string into multiple statements as statements must be passed one by one to the driver. @mgabelle can you have a look? |
I tried make it an array but everyone I talked to suggested we need to find a way to make it work with SQL as a string, often users have autogenerated SQL scripts like DB backup files etc and we need to bulk-execute them 👍 |
FYI moved to 0.20 as it's too big project for a last week before the release |
follow up #377 |
…s, parameter binding and transactions extract common logic to utils and abstract classes created test for queries implemented queries for MySQL #368
Done at the moment :
|
Related to add params to Query task to avoid SQL injection #376
Context
The current
Query
task is limited to executing a single SQL statement and handling its output. Some automation tasks require executing multiple SQL statements, potentially wrapped in a transaction, while handling outputs of multipleSELECT
statements.To avoid breaking changes in the
Query
tasks, here is a proposal for a newQueries
task.This task will enable:
parameters
to prevent SQL injectionUse case for testing
Start Postgres in a container:
Create tables (alternatively directly from the new
Queries
task):Implementation
Task Type:
io.kestra.plugin.jdbc.postgresql.Queries
(equivalent tasks will be needed for all JDBC plugin subgroups, not just Postgres)Description: The
Queries
task allows executing multiple SQL statements within a single task, with support for parameter binding and transaction management. The task can handle multipleSELECT
statements and their outputs, allowing you to fetch the results directly or store them as internal storage ION files.Note on parsing SQL statements from a single string
Important note: we want to make the
sql
property work as a single string allowing to execute multiple SQL statements separated by semicolons (;
). We want to support both:parameters
as a mapsql
as a single string with multiple SQL statements separated by semicolons (;
)If supporting both is not feasible at the same time e.g. because of the performance/cost of parsing the SQL string, we can consider supporting only the
sql
as a single string withoutparameters
. Supportingsql
as a single string with multiple SQL statements separated by semicolons (;
) has higher priority than supportingparameters
.We should investigate how other tools in the Java ecosystem parse queries for execution e.g. Flyway https://www.baeldung.com/liquibase-vs-flyway.
TL;DR
sql
as a string withoutparameters
>sql
as an array withparameters
Properties
sql:
string
;
). The statements will be executed sequentially as part of the transaction.parameters:
map
:parameterName
.fetchType:
string
STORE
STORE
: Store all rows to a file.FETCH
: Output all rows as an output variable.FETCH_ONE
: Output only the first row.NONE
: Do nothing.transaction:
boolean
Outputs
The outputs will be an array, with each element corresponding to the output of a single query in the
sql
string. Each output element may contain the following fields based on thefetchType
:row (if
fetchType: FETCH_ONE
):object
fetchType
is set toFETCH_ONE
.rows (if
fetchType: FETCH
):array
object
fetchType
is set toFETCH
.size (if
fetchType: FETCH
orSTORE
):integer
fetchType
is set to eitherFETCH
orSTORE
.uri (if
fetchType: STORE
):string
uri
fetchType
is set toSTORE
.Example flow
Example Output
For a query with
fetchType: FETCH
:For a query with
fetchType: STORE
:For a query with
fetchType: FETCH_ONE
:The text was updated successfully, but these errors were encountered: