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
4 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
plugin-jdbc-pinot/src/main/java/io/kestra/plugin/jdbc/pinot/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,63 @@ | ||
package io.kestra.plugin.jdbc.pinot; | ||
|
||
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.pinot.client.PinotDriver; | ||
|
||
import java.sql.*; | ||
import java.time.ZoneId; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Perform multiple queries on an Apache Pinot server." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
full = true, | ||
code = """ | ||
id: pinot_queries | ||
namespace: company.team | ||
tasks: | ||
- id: queries | ||
type: o.kestra.plugin.jdbc.pinot.Queries | ||
url: jdbc:pinot://localhost:9000 | ||
sql: | | ||
SELECT * FROM airlineStats; | ||
SELECT * FROM airlineStats; | ||
fetchType: FETCH | ||
""" | ||
) | ||
} | ||
) | ||
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput> { | ||
@Override | ||
protected AbstractCellConverter getCellConverter(ZoneId zoneId) { | ||
return new PinotCellConverter(zoneId); | ||
} | ||
|
||
@Override | ||
public void registerDriver() throws SQLException { | ||
DriverManager.registerDriver(new PinotDriver()); | ||
} | ||
|
||
@Override | ||
protected PreparedStatement createPreparedStatement(Connection conn, String preparedSql) throws SQLException { | ||
return conn.prepareStatement(preparedSql); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
plugin-jdbc-pinot/src/test/java/io/kestra/plugin/jdbc/pinot/PinotQueriesTest.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,45 @@ | ||
package io.kestra.plugin.jdbc.pinot; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
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 io.kestra.plugin.jdbc.AbstractJdbcQuery; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static io.kestra.core.models.tasks.common.FetchType.FETCH_ONE; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* See : | ||
* - https://docs.pinot.apache.org/configuration-reference/schema | ||
*/ | ||
@KestraTest | ||
class PinotQueriesTest { | ||
@Inject | ||
RunContextFactory runContextFactory; | ||
|
||
@Test | ||
void multiSelect() throws Exception { | ||
RunContext runContext = runContextFactory.of(ImmutableMap.of()); | ||
|
||
Queries task = Queries.builder() | ||
.url("jdbc:pinot://localhost:49000") | ||
.fetchType(FETCH_ONE) | ||
.timeZoneId("Europe/Paris") | ||
.sql(""" | ||
select count(*) as count from airlineStats; | ||
""") | ||
.build(); | ||
|
||
AbstractJdbcQueries.MultiQueryOutput runOutput = task.run(runContext); | ||
assertThat(runOutput.getOutputs().getFirst().getRow(), notNullValue()); | ||
assertThat(runOutput.getOutputs().getFirst().getRow().get("count"), is(9746L)); | ||
} | ||
} |
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
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