Skip to content

Commit

Permalink
add duckdb sql executor task test
Browse files Browse the repository at this point in the history
  • Loading branch information
edigonzales committed Jan 2, 2024
1 parent bc929ab commit 6c987b5
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ch.so.agi.gretl.jobs;

import static org.junit.Assert.assertTrue;

import java.nio.file.Files;
import java.nio.file.Paths;

import org.junit.Test;

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;

public class SqlExecutorTaskDuckDbTest {

// DB-File erstellen.
// Tabelle erstellen und Werte inserten
// Parquet-Datei importieren
// GPKG importieren
@Test
public void multipleStuff_Ok() throws Exception {
String jobDir = "src/integrationTest/jobs/SqlExecutorTaskDuckDb";
String dbName = "foo.duckdb";

// Prepare
if (Files.exists(Paths.get(jobDir, dbName))) {
Files.delete(Paths.get(jobDir, dbName));
}

// Run job
GradleVariable[] gvs = null;
IntegrationTestUtil.runJob(jobDir, gvs);

// Check result
// Vor allem die Parquet- und GPKG-Imports werden bereits im SQL geprüft:
// Es wird ein SELECT auf die neue Tabelle gemacht.
assertTrue(Files.exists(Paths.get(jobDir, dbName)));
}
}
3 changes: 3 additions & 0 deletions gretl/src/integrationTest/jobs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/build/**
build
**/build/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.duckdb
32 changes: 32 additions & 0 deletions gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ch.so.agi.gretl.tasks.*

apply plugin: 'ch.so.agi.gretl'

def pwd = rootProject.projectDir.toString()
def db_uri = "jdbc:duckdb:$pwd/foo.duckdb"

def db_user = null
def db_pass = null

defaultTasks 'importParquet'


tasks.register('initDuckDb', SqlExecutor) {
database = [db_uri, db_user, db_pass]
sqlFiles = ['init.sql']
}

tasks.register('createTable', SqlExecutor) {
dependsOn 'initDuckDb'

database = [db_uri, db_user, db_pass]
sqlFiles = ['create_insert.sql']
}

tasks.register('importParquet', SqlExecutor) {
dependsOn 'createTable'

database = [db_uri, db_user, db_pass]
sqlFiles = ['import_parquet.sql']
sqlParameters = [pwd: "'"+pwd+"'"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE tbl (i INTEGER);
INSERT INTO tbl VALUES (1), (2), (3);

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LOAD spatial;

CREATE TABLE bewilligte_ews AS SELECT * FROM read_parquet(${pwd}||'/data/ch.so.afu.bewilligte_erdwaermeanlagen.parquet');

SELECT count(*) FROM bewilligte_ews;

CREATE TABLE abbaustelle AS SELECT * FROM ST_Read(${pwd}||'/data/ch.so.afu.abbaustellen.gpkg', layer='abbaustelle');

SELECT count(*) FROM abbaustelle;
2 changes: 2 additions & 0 deletions gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSTALL httpfs;
INSTALL spatial;
Empty file.

0 comments on commit 6c987b5

Please sign in to comment.