Skip to content

Commit

Permalink
removing postgres connector
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anshul committed Sep 8, 2023
1 parent 82ae48e commit ea178e0
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 100 deletions.
4 changes: 1 addition & 3 deletions runtime/compilers/rillv1/connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ func driverSourceForAnonAccessCheck(connector string, src *runtimev1.SourceSpec)
}
case "motherduck":
return &drivers.DatabaseSource{}
case "postgres_ext":
return &drivers.DatabaseSource{}
case "sqlite_ext":
case "sqlite":
return &drivers.DatabaseSource{}
default:
return nil
Expand Down
4 changes: 1 addition & 3 deletions runtime/compilers/rillv1beta/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ func source(connector string, src *runtimev1.Source) drivers.Source {
}
case "motherduck":
return &drivers.DatabaseSource{}
case "postgres_ext":
return &drivers.DatabaseSource{}
case "sqlite_ext":
case "sqlite":
return &drivers.DatabaseSource{}
case "bigquery":
return &drivers.DatabaseSource{
Expand Down
71 changes: 18 additions & 53 deletions runtime/drivers/duckdb/duckdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,27 @@ import (
func init() {
drivers.Register("duckdb", Driver{name: "duckdb"})
drivers.Register("motherduck", Driver{name: "motherduck"})
drivers.Register("postgres_ext", Driver{name: "postgres_ext"})
drivers.Register("sqlite_ext", Driver{name: "sqlite_ext"})
drivers.RegisterAsConnector("motherduck", Driver{name: "motherduck"})
drivers.RegisterAsConnector("postgres_ext", Driver{name: "postgres_ext"})
drivers.RegisterAsConnector("sqlite_ext", Driver{name: "sqlite_ext"})
}

var specs map[string]drivers.Spec = map[string]drivers.Spec{
"motherduck": {
DisplayName: "MotherDuck",
Description: "Import data from MotherDuck.",
SourceProperties: []drivers.PropertySchema{
{
Key: "sql",
Type: drivers.StringPropertyType,
Required: true,
DisplayName: "SQL",
Description: "Query to extract data from MotherDuck.",
Placeholder: "select * from my_db.my_table;",
},
},
ConfigProperties: []drivers.PropertySchema{
{
Key: "token",
Secret: true,
},
},
},
"postgres_ext": {
DisplayName: "Postgres",
Description: "Import data from Postgres table to DuckDB.",
SourceProperties: []drivers.PropertySchema{
{
Key: "sql",
Type: drivers.StringPropertyType,
Required: true,
DisplayName: "SQL",
Description: "Query to extract data from postgres",
Placeholder: "SELECT * FROM postgres_scan('dbname=postgres user=postgres password=*** host=127.0.0.1', 'public', 'users');",
Hint: "https://duckdb.org/docs/extensions/postgres_scanner.html#querying-individual-tables",
},
// spec for duckdb as motherduck connector
var spec = drivers.Spec{
DisplayName: "MotherDuck",
Description: "Import data from MotherDuck.",
SourceProperties: []drivers.PropertySchema{
{
Key: "sql",
Type: drivers.StringPropertyType,
Required: true,
DisplayName: "SQL",
Description: "Query to extract data from MotherDuck.",
Placeholder: "select * from my_db.my_table;",
},
},
"sqlite_ext": {
DisplayName: "SQLite",
Description: "Import data from SQLite table to DuckDB.",
SourceProperties: []drivers.PropertySchema{
{
Key: "sql",
Type: drivers.StringPropertyType,
Required: true,
DisplayName: "SQL",
Description: "Query to extract data from SQLite",
Placeholder: "SELECT * FROM sqlite_scan('sakila.db', 'film');",
Hint: "https://duckdb.org/docs/extensions/sqlite_scanner#querying-individual-tables",
},
ConfigProperties: []drivers.PropertySchema{
{
Key: "token",
Secret: true,
},
},
}
Expand Down Expand Up @@ -170,7 +135,7 @@ func (d Driver) Drop(config map[string]any, logger *zap.Logger) error {
}

func (d Driver) Spec() drivers.Spec {
return specs[d.name]
return spec
}

func (d Driver) HasAnonymousSourceAccess(ctx context.Context, src drivers.Source, logger *zap.Logger) (bool, error) {
Expand Down Expand Up @@ -269,7 +234,7 @@ func (c *connection) AsTransporter(from, to drivers.Handle) (drivers.Transporter
if from == to {
return transporter.NewDuckDBToDuckDB(olap, c.logger), true
}
if from.Driver() == "postgres_ext" || from.Driver() == "sqlite_ext" {
if from.Driver() == "sqlite" {
return transporter.NewSQLExtensionToDuckDB(from, olap, c.logger), true
}
if from.Driver() == "motherduck" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type sqlextensionToDuckDB struct {
var _ drivers.Transporter = &sqlextensionToDuckDB{}

// NewSQLExtensionToDuckDB returns a transporter to transfer data to duckdb from a sql extension supported by duckdb.
// Currently only sqlite extension is supported. Postgres is not supported due to licensing issues.
func NewSQLExtensionToDuckDB(from drivers.Handle, to drivers.OLAPStore, logger *zap.Logger) drivers.Transporter {
return &sqlextensionToDuckDB{
to: to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"

"github.com/rilldata/rill/runtime/drivers"
_ "github.com/rilldata/rill/runtime/drivers/sqlite"
"github.com/rilldata/rill/runtime/pkg/activity"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
_ "modernc.org/sqlite"
Expand All @@ -27,9 +29,9 @@ func Test_sqlextensionToDuckDB_Transfer(t *testing.T) {
require.NoError(t, err)
db.Close()

from, err := drivers.Open("sqlite_ext", map[string]any{"dsn": ""}, false, zap.NewNop())
from, err := drivers.Open("sqlite", map[string]any{"dsn": ""}, false, activity.NewNoopClient(), zap.NewNop())
require.NoError(t, err)
to, err := drivers.Open("duckdb", map[string]any{"dsn": ""}, false, zap.NewNop())
to, err := drivers.Open("duckdb", map[string]any{"dsn": ""}, false, activity.NewNoopClient(), zap.NewNop())
require.NoError(t, err)
olap, _ := to.AsOLAP("")

Expand Down
17 changes: 16 additions & 1 deletion runtime/drivers/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

func init() {
drivers.Register("sqlite", driver{})
drivers.RegisterAsConnector("sqlite", driver{})
}

type driver struct{}
Expand Down Expand Up @@ -55,7 +56,21 @@ func (d driver) Drop(config map[string]any, logger *zap.Logger) error {
}

func (d driver) Spec() drivers.Spec {
return drivers.Spec{}
return drivers.Spec{
DisplayName: "SQLite",
Description: "Import data from SQLite table to DuckDB.",
SourceProperties: []drivers.PropertySchema{
{
Key: "sql",
Type: drivers.StringPropertyType,
Required: true,
DisplayName: "SQL",
Description: "Query to extract data from SQLite",
Placeholder: "SELECT * FROM sqlite_scan('/Users/kanshul/.config/gcloud/access_tokens.db', 'film');",
Hint: "https://duckdb.org/docs/extensions/sqlite_scanner#querying-individual-tables",
},
},
}
}

func (d driver) HasAnonymousSourceAccess(ctx context.Context, src drivers.Source, logger *zap.Logger) (bool, error) {
Expand Down
11 changes: 1 addition & 10 deletions runtime/reconcilers/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,7 @@ func driversSource(conn drivers.Handle, propsPB *structpb.Struct) (drivers.Sourc
SQL: query,
Database: db,
}, nil
case "postgres_ext":
query, ok := props["sql"].(string)
if !ok {
return nil, fmt.Errorf("property \"sql\" is mandatory for connector \"postgres\"")
}

return &drivers.DatabaseSource{
SQL: query,
}, nil
case "sqlite_ext":
case "sqlite":
query, ok := props["sql"].(string)
if !ok {
return nil, fmt.Errorf("property \"sql\" is mandatory for connector \"sqlite\"")
Expand Down
15 changes: 2 additions & 13 deletions runtime/services/catalog/migrator/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,7 @@ func source(connector string, src *runtimev1.Source) (drivers.Source, error) {
SQL: query,
Props: props,
}, nil
case "postgres_ext":
query, ok := props["sql"].(string)
if !ok {
return nil, fmt.Errorf("property \"sql\" is mandatory for connector \"postgres\"")
}

return &drivers.DatabaseSource{
SQL: query,
}, nil
case "sqlite_ext":
case "sqlite":
query, ok := props["sql"].(string)
if !ok {
return nil, fmt.Errorf("property \"sql\" is mandatory for connector \"sqlite\"")
Expand Down Expand Up @@ -452,9 +443,7 @@ func connectorVariables(src *runtimev1.Source, env map[string]string, repoRoot s
case "motherduck":
vars["token"] = env["token"]
vars["dsn"] = ""
case "postgres_ext":
vars["dsn"] = ""
case "sqlite_ext":
case "sqlite":
vars["dsn"] = ""
case "local_file":
vars["dsn"] = repoRoot
Expand Down
5 changes: 2 additions & 3 deletions web-common/src/features/sources/modal/AddSourceModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"https",
"local_file",
"motherduck",
"postgres_ext",
"sqlite_ext",
"sqlite",
"bigquery",
];
Expand Down Expand Up @@ -93,7 +92,7 @@
</TabGroup>
</div>
<div class="flex-grow overflow-y-auto">
{#if selectedConnector?.name === "gcs" || selectedConnector?.name === "s3" || selectedConnector?.name === "https" || selectedConnector?.name === "motherduck" || selectedConnector?.name === "postgres_ext" || selectedConnector?.name === "sqlite_ext" || selectedConnector?.name === "bigquery"}
{#if selectedConnector?.name === "gcs" || selectedConnector?.name === "s3" || selectedConnector?.name === "https" || selectedConnector?.name === "motherduck" || selectedConnector?.name === "postgres_ext" || selectedConnector?.name === "sqlite"}
{#key selectedConnector}
<RemoteSourceForm connector={selectedConnector} on:close />
{/key}
Expand Down
13 changes: 1 addition & 12 deletions web-common/src/features/sources/modal/yupSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,7 @@ export function getYupSchema(connector: V1ConnectorSpec) {
)
.required("Source name is required"),
});
case "postgres_ext":
return yup.object().shape({
sql: yup.string().required("sql is required"),
sourceName: yup
.string()
.matches(
/^[a-zA-Z_][a-zA-Z0-9_]*$/,
"Source name must start with a letter or underscore and contain only letters, numbers, and underscores"
)
.required("Source name is required"),
});
case "sqlite_ext":
case "sqlite":
return yup.object().shape({
sql: yup.string().required("sql is required"),
sourceName: yup
Expand Down

0 comments on commit ea178e0

Please sign in to comment.