-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
bc929ab
commit 6c987b5
Showing
10 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskDuckDbTest.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,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))); | ||
} | ||
} |
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,3 @@ | ||
**/build/** | ||
build | ||
**/build/ |
1 change: 1 addition & 0 deletions
1
gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/.gitignore
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 @@ | ||
*.duckdb |
32 changes: 32 additions & 0 deletions
32
gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/build.gradle
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,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+"'"] | ||
} |
3 changes: 3 additions & 0 deletions
3
gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/create_insert.sql
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,3 @@ | ||
CREATE TABLE tbl (i INTEGER); | ||
INSERT INTO tbl VALUES (1), (2), (3); | ||
|
Binary file added
BIN
+256 KB
gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/data/ch.so.afu.abbaustellen.gpkg
Binary file not shown.
Binary file added
BIN
+3.52 KB
...grationTest/jobs/SqlExecutorTaskDuckDb/data/ch.so.afu.bewilligte_erdwaermeanlagen.parquet
Binary file not shown.
9 changes: 9 additions & 0 deletions
9
gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/import_parquet.sql
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,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
2
gretl/src/integrationTest/jobs/SqlExecutorTaskDuckDb/init.sql
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,2 @@ | ||
INSTALL httpfs; | ||
INSTALL spatial; |
Empty file.