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

feat: add queries : redshift, snowflake, sybase, vectorwise, vertica #424

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}