Skip to content

Commit

Permalink
feat: add queries : redshift, snowflake, sybase, vectorwise, vertica (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabelle authored Oct 31, 2024
1 parent 245970f commit 04d94ff
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.kestra.plugin.jdbc.redshift;

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.plugin.jdbc.AbstractCellConverter;
import io.kestra.plugin.jdbc.AbstractJdbcQueries;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.ZoneId;

@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Perform multiple queries on a Redshift server."
)
@Plugin(
examples = {
@Example(
title = "Send SQL queries to a Redshift database and fetch the outputs.",
full = true,
code = """
id: redshift_queries
namespace: company.team
tasks:
- id: select
type: io.kestra.plugin.jdbc.redshift.Queries
url: jdbc:redshift://123456789.eu-central-1.redshift-serverless.amazonaws.com:5439/dev
username: admin
password: admin_password
sql: select count(*) from employee; select count(*) from laptop;
fetchType: FETCH_ONE
"""
)
}
)
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput> {
@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
return new RedshiftCellConverter(zoneId);
}

@Override
public void registerDriver() throws SQLException {
DriverManager.registerDriver(new com.amazon.redshift.jdbc.Driver());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.kestra.plugin.jdbc.snowflake;

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.AbstractJdbcQueries;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.ZoneId;
import java.util.Properties;

@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Perform multiple queries on a Snowflake server."
)
@Plugin(
examples = {
@Example(
full = true,
title = "Execute queries and fetch results in a task, and update another table with fetched results in a different task.",
code = """
id: snowflake_queries
namespace: company.team
tasks:
- id: select
type: io.kestra.plugin.jdbc.snowflake.Queries
url: jdbc:snowflake://<account_identifier>.snowflakecomputing.com
username: snowflake_user
password: snowflake_password
sql: select * from demo_db.public.customers; select * from demo_db.public.emplyees;
fetchType: FETCH
"""
)
}
)
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput>, SnowflakeInterface {
private String privateKey;
private String privateKeyFile;
private String privateKeyFilePassword;
private String database;
private String warehouse;
private String schema;
private String role;

@Override
public Properties connectionProperties(RunContext runContext) throws Exception {
Properties properties = super.connectionProperties(runContext);

this.renderProperties(runContext, properties);

return properties;
}

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
return new SnowflakeCellConverter(zoneId);
}

@Override
public void registerDriver() throws SQLException {
DriverManager.registerDriver(new net.snowflake.client.jdbc.SnowflakeDriver());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.kestra.plugin.jdbc.sybase;

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.plugin.jdbc.AbstractCellConverter;
import io.kestra.plugin.jdbc.AbstractJdbcQueries;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.ZoneId;

@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Perform multiple queries on a Sybase database."
)
@Plugin(
examples = {
@Example(
title = "Send SQL queries to a Sybase Database and fetch a row as output.",
full = true,
code = """
id: sybase_queries
namespace: company.team
tasks:
- id: queries
type: io.kestra.plugin.jdbc.sybase.Queries
url: jdbc:sybase:Tds:127.0.0.1:5000/
username: syb_user
password: syb_password
sql: select count(*) from employee, select count(*) from laptop;
fetchType: FETCH_ONE
"""
)
}
)
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput> {
@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
return new SybaseCellConverter(zoneId);
}

@Override
public void registerDriver() throws SQLException {
DriverManager.registerDriver(new com.sybase.jdbc4.jdbc.SybDriver());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.kestra.plugin.jdbc.vectorwise;

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.plugin.jdbc.AbstractCellConverter;
import io.kestra.plugin.jdbc.AbstractJdbcQueries;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.ZoneId;

@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Perform multiple queries on a Vectorwise database."
)
@Plugin(
examples = {
@Example(
title = "Send SQL queries to a Vectorwise database and fetch a row as output.",
full = true,
code = """
id: vectorwise_queries
namespace: company.team
tasks:
- id: queries
type: io.kestra.plugin.jdbc.vectorwise.Queries
url: jdbc:vectorwise://url:port/base
username: admin
password: admin_password
sql: select count(*) from employee; select count(*) from laptop;
fetchType: FETCH_ONE
"""
)
}
)
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput> {
@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
return new VectorwiseCellConverter(zoneId);
}

@Override
public void registerDriver() throws SQLException {
DriverManager.registerDriver(new com.ingres.jdbc.IngresDriver());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.kestra.plugin.jdbc.vertica;

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.plugin.jdbc.AbstractCellConverter;
import io.kestra.plugin.jdbc.AbstractJdbcQueries;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.ZoneId;

@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Perform multiple queries on a Vertica server."
)
@Plugin(
examples = {
@Example(
title = "Send SQL queries to a Vertica database, and fetch a row as output.",
full = true,
code = """
id: vertica_queries
namespace: company.team
tasks:
- id: queries
type: io.kestra.plugin.jdbc.vertica.Queries
url: jdbc:vertica://127.0.0.1:56982/db
username: vertica_user
password: vertica_password
sql: select * from customer
fetchType: FETCH_ONE
"""
)
}
)
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput> {
@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
return new VerticaCellConverter(zoneId);
}

@Override
public void registerDriver() throws SQLException {
DriverManager.registerDriver(new com.vertica.jdbc.Driver());
}
}

0 comments on commit 04d94ff

Please sign in to comment.