-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime: unified
duckdb
connector for motherduck
and external `db…
…` files (#3700) * external duckdb and motherduck * adding test and lint fix * lint fix * formatting fix * formatting fix * lint fix * review comments - fix defer res.Close() * fix defer res.Close() in other places
- Loading branch information
Showing
7 changed files
with
152 additions
and
23 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
runtime/drivers/duckdb/transporter_duckDB_to_duckDB_test.go
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,65 @@ | ||
package duckdb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/rilldata/rill/runtime/drivers" | ||
activity "github.com/rilldata/rill/runtime/pkg/activity" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestDuckDBToDuckDBTransfer(t *testing.T) { | ||
tempDir := t.TempDir() | ||
conn, err := Driver{}.Open(map[string]any{"dsn": fmt.Sprintf("%s.db?access_mode=read_write", filepath.Join(tempDir, "tranfser"))}, false, activity.NewNoopClient(), zap.NewNop()) | ||
require.NoError(t, err) | ||
|
||
olap, ok := conn.AsOLAP("") | ||
require.True(t, ok) | ||
|
||
err = olap.Exec(context.Background(), &drivers.Statement{ | ||
Query: "CREATE TABLE foo(bar VARCHAR, baz INTEGER)", | ||
}) | ||
require.NoError(t, err) | ||
|
||
err = olap.Exec(context.Background(), &drivers.Statement{ | ||
Query: "INSERT INTO foo VALUES ('a', 1), ('a', 2), ('b', 3), ('c', 4)", | ||
}) | ||
require.NoError(t, err) | ||
require.NoError(t, conn.Close()) | ||
|
||
to, err := Driver{}.Open(map[string]any{"dsn": ""}, false, activity.NewNoopClient(), zap.NewNop()) | ||
require.NoError(t, err) | ||
|
||
olap, _ = to.AsOLAP("") | ||
|
||
tr := NewDuckDBToDuckDB(olap, zap.NewNop()) | ||
|
||
// transfer once | ||
err = tr.Transfer(context.Background(), map[string]any{"sql": "SELECT * FROM foo", "db": filepath.Join(tempDir, "tranfser.db")}, map[string]any{"table": "test"}, &drivers.TransferOptions{Progress: drivers.NoOpProgress{}}) | ||
require.NoError(t, err) | ||
|
||
rows, err := olap.Execute(context.Background(), &drivers.Statement{Query: "SELECT COUNT(*) FROM test"}) | ||
require.NoError(t, err) | ||
|
||
var count int | ||
rows.Next() | ||
require.NoError(t, rows.Scan(&count)) | ||
require.Equal(t, 4, count) | ||
require.NoError(t, rows.Close()) | ||
|
||
// transfer again | ||
err = tr.Transfer(context.Background(), map[string]any{"sql": "SELECT * FROM foo", "db": filepath.Join(tempDir, "tranfser.db")}, map[string]any{"table": "test"}, &drivers.TransferOptions{Progress: drivers.NoOpProgress{}}) | ||
require.NoError(t, err) | ||
|
||
rows, err = olap.Execute(context.Background(), &drivers.Statement{Query: "SELECT COUNT(*) FROM test"}) | ||
require.NoError(t, err) | ||
|
||
rows.Next() | ||
require.NoError(t, rows.Scan(&count)) | ||
require.Equal(t, 4, count) | ||
require.NoError(t, rows.Close()) | ||
} |
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
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