generated from kestra-io/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Mysql - Batch implementation (#293)
* Add test for query with aliases * #109 * #124 Implemented batch * Fixed flow issue. Changed datetime type
- Loading branch information
1 parent
eeaa34a
commit c427086
Showing
7 changed files
with
454 additions
and
20 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
plugin-jdbc-mysql/src/main/java/io/kestra/plugin/jdbc/mysql/Batch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package io.kestra.plugin.jdbc.mysql; | ||
|
||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.models.tasks.RunnableTask; | ||
import io.kestra.core.runners.RunContext; | ||
import io.kestra.plugin.jdbc.AbstractCellConverter; | ||
import io.kestra.plugin.jdbc.AbstractJdbcBatch; | ||
import io.micronaut.http.uri.UriBuilder; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.net.URI; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.time.ZoneId; | ||
import java.util.Properties; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Execute a batch query to a MySQL server." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
title = "Fetch rows from a table, and bulk insert them to another one.", | ||
full = true, | ||
code = { | ||
"tasks:", | ||
" - id: query", | ||
" type: io.kestra.plugin.jdbc.mysql.Query", | ||
" url: jdbc:mysql://127.0.0.1:3306/", | ||
" username: mysql_user", | ||
" password: mysql_passwd", | ||
" sql: |", | ||
" SELECT *", | ||
" FROM xref", | ||
" LIMIT 1500;", | ||
" store: true", | ||
" - id: update", | ||
" type: io.kestra.plugin.jdbc.mysql.Batch", | ||
" from: \"{{ outputs.query.uri }}\"", | ||
" url: jdbc:mysql://127.0.0.1:3306/", | ||
" username: mysql_user", | ||
" password: mysql_passwd", | ||
" sql: |", | ||
" insert into xref values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )", | ||
} | ||
) | ||
} | ||
) | ||
public class Batch extends AbstractJdbcBatch implements RunnableTask<AbstractJdbcBatch.Output> { | ||
|
||
@Override | ||
protected AbstractCellConverter getCellConverter(ZoneId zoneId) { | ||
return new MysqlCellConverter(zoneId); | ||
} | ||
|
||
@Override | ||
public Properties connectionProperties(RunContext runContext) throws Exception { | ||
Properties props = super.connectionProperties(runContext); | ||
|
||
URI url = URI.create((String) props.get("jdbc.url")); | ||
url = URI.create(url.getSchemeSpecificPart()); | ||
|
||
UriBuilder builder = UriBuilder.of(url); | ||
|
||
builder.scheme("jdbc:mysql"); | ||
|
||
props.put("generateSimpleParameterMetadata", "true"); | ||
|
||
props.put("jdbc.url", builder.build().toString()); | ||
|
||
return props; | ||
} | ||
|
||
@Override | ||
public void registerDriver() throws SQLException { | ||
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.