Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into athena-connector
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Ryashin committed Sep 13, 2023
1 parent 8d4b69b commit 03d5c42
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions runtime/drivers/duckdb/transporter/objectStore_to_duckDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func (t *objectStoreToDuckDB) Transfer(ctx context.Context, srcProps, sinkProps
}

fromAthena := reflect.TypeOf(t.from).AssignableTo(reflect.TypeOf(&athena.Connection{}))
sql, hasSQL := src.Properties["sql"].(string)
sql, hasSQL := srcProps["sql"].(string)
// if sql is specified use ast rewrite to fill in the downloaded files
if hasSQL && !fromAthena {
return t.ingestDuckDBSQL(ctx, sql, iterator, dbSink, opts, p)
return t.ingestDuckDBSQL(ctx, sql, iterator, sinkCfg, opts, p)
}

p.Target(size, drivers.ProgressUnitByte)
Expand Down
30 changes: 30 additions & 0 deletions runtime/drivers/duckdb/transporter/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,38 @@ import (
"os"
"path/filepath"
"strings"

"github.com/mitchellh/mapstructure"
)

type sourceProperties struct {
Database string `mapstructure:"db"`
SQL string `mapstructure:"sql"`
}

func parseSourceProperties(props map[string]any) (*sourceProperties, error) {
cfg := &sourceProperties{}
if err := mapstructure.Decode(props, cfg); err != nil {
return nil, fmt.Errorf("failed to parse source properties: %w", err)
}
if cfg.SQL == "" {
return nil, fmt.Errorf("property 'sql' is mandatory")
}
return cfg, nil
}

type sinkProperties struct {
Table string `mapstructure:"table"`
}

func parseSinkProperties(props map[string]any) (*sinkProperties, error) {
cfg := &sinkProperties{}
if err := mapstructure.Decode(props, cfg); err != nil {
return nil, fmt.Errorf("failed to parse sink properties: %w", err)
}
return cfg, nil
}

func sourceReader(paths []string, format string, ingestionProps map[string]any, fromAthena bool) (string, error) {
// Generate a "read" statement
if containsAny(format, []string{".csv", ".tsv", ".txt"}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"local_file",
"motherduck",
"bigquery",
"athena",
];
const connectors = createRuntimeServiceListConnectors({
Expand Down

0 comments on commit 03d5c42

Please sign in to comment.