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.
- Loading branch information
Showing
3 changed files
with
189 additions
and
45 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
plugin-jdbc-druid/src/main/java/io/kestra/plugin/jdbc/druid/Queries.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,58 @@ | ||
package io.kestra.plugin.jdbc.druid; | ||
|
||
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.kestra.plugin.jdbc.AbstractJdbcQuery; | ||
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 org.apache.calcite.avatica.remote.Driver; | ||
|
||
import java.sql.*; | ||
import java.time.ZoneId; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Perform multiple queries on an Apache Druid database." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
title = "Multiple queries on an Apache Druid database.", | ||
full = true, | ||
code = """ | ||
id: druid_queries | ||
namespace: company.team | ||
tasks: | ||
- id: queries | ||
type: io.kestra.plugin.jdbc.druid.Queries | ||
url: jdbc:avatica:remote:url=http://localhost:8888/druid/v2/sql/avatica/;transparent_reconnection=true | ||
sql: | | ||
SELECT * FROM wikiticker; SELECT * FROM product; | ||
fetchType: STORE | ||
""" | ||
) | ||
} | ||
) | ||
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput> { | ||
@Override | ||
protected AbstractCellConverter getCellConverter(ZoneId zoneId) { | ||
return new DruidCellConverter(zoneId); | ||
} | ||
|
||
@Override | ||
public void registerDriver() throws SQLException { | ||
DriverManager.registerDriver(new Driver()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
plugin-jdbc-druid/src/test/java/io/kestra/plugin/jdbc/druid/DruidQueriesTest.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,52 @@ | ||
package io.kestra.plugin.jdbc.druid; | ||
|
||
import io.kestra.core.junit.annotations.KestraTest; | ||
import io.kestra.core.models.property.Property; | ||
import io.kestra.core.runners.RunContext; | ||
import io.kestra.core.runners.RunContextFactory; | ||
import io.kestra.plugin.jdbc.AbstractJdbcQueries; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static io.kestra.core.models.tasks.common.FetchType.FETCH; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@KestraTest | ||
public class DruidQueriesTest { | ||
@Inject | ||
RunContextFactory runContextFactory; | ||
|
||
@BeforeAll | ||
public static void startServer() throws Exception { | ||
DruidTestHelper.initServer(); | ||
} | ||
|
||
@Test | ||
void insertAndQuery() throws Exception { | ||
RunContext runContext = runContextFactory.of(Map.of()); | ||
|
||
Queries task = Queries.builder() | ||
.url("jdbc:avatica:remote:url=http://localhost:8888/druid/v2/sql/avatica/;transparent_reconnection=true") | ||
.fetchType(FETCH) | ||
.timeZoneId("Europe/Paris") | ||
.parameters(Property.of(Map.of( | ||
"limitLow", 2, | ||
"limitHigh", 10)) | ||
) | ||
.sql(""" | ||
select * from products limit :limitLow; | ||
select * from products limit :limitHigh; | ||
""") | ||
.build(); | ||
|
||
AbstractJdbcQueries.MultiQueryOutput runOutput = task.run(runContext); | ||
assertThat(runOutput.getOutputs(), notNullValue()); | ||
assertThat(runOutput.getOutputs().getFirst().getRows().size(), is(2)); | ||
assertThat(runOutput.getOutputs().getLast().getRows().size(), is(10)); | ||
} | ||
} | ||
|
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