Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.4.2 #500

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions core/dbio/database/database_redshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ func (conn *RedshiftConn) Unload(ctx *g.Context, tables ...Table) (s3Path string

AwsID := conn.GetProp("AWS_ACCESS_KEY_ID")
AwsAccessKey := conn.GetProp("AWS_SECRET_ACCESS_KEY")
AwsSessionToken := conn.GetProp("AWS_SESSION_TOKEN")

AwsSessionTokenExpr := ""
if AwsSessionToken != "" {
AwsSessionTokenExpr = g.F(";token=%s", AwsSessionToken)
}

g.Info("unloading from redshift to s3")
queryContext := g.NewContext(ctx.Ctx)
Expand All @@ -118,6 +124,7 @@ func (conn *RedshiftConn) Unload(ctx *g.Context, tables ...Table) (s3Path string
"s3_path", s3PathPart,
"aws_access_key_id", AwsID,
"aws_secret_access_key", AwsAccessKey,
"aws_session_token_expr", AwsSessionTokenExpr,
"parallel", conn.GetProp("PARALLEL"),
)

Expand Down Expand Up @@ -347,11 +354,17 @@ func (conn *RedshiftConn) GenerateUpsertSQL(srcTable string, tgtTable string, pk
func (conn *RedshiftConn) CopyFromS3(tableFName, s3Path string, columns iop.Columns) (count uint64, err error) {
AwsID := conn.GetProp("AWS_ACCESS_KEY_ID")
AwsAccessKey := conn.GetProp("AWS_SECRET_ACCESS_KEY")
if AwsID == "" || AwsAccessKey == "" {
err = g.Error("Need to set 'AWS_ACCESS_KEY_ID' and 'AWS_SECRET_ACCESS_KEY' to copy to snowflake from S3")
AwsSessionToken := conn.GetProp("AWS_SESSION_TOKEN")
if (AwsID == "" || AwsAccessKey == "") && (AwsSessionToken == "") {
err = g.Error("Need to set 'AWS_ACCESS_KEY_ID' and 'AWS_SECRET_ACCESS_KEY' or 'AWS_SESSION_TOKEN' to copy to redshift from S3")
return
}

AwsSessionTokenExpr := ""
if AwsSessionToken != "" {
AwsSessionTokenExpr = g.F(";token=%s", AwsSessionToken)
}

tgtColumns := conn.GetType().QuoteNames(columns.Names()...)

g.Debug("copying into redshift from s3")
Expand All @@ -363,6 +376,7 @@ func (conn *RedshiftConn) CopyFromS3(tableFName, s3Path string, columns iop.Colu
"s3_path", s3Path,
"aws_access_key_id", AwsID,
"aws_secret_access_key", AwsAccessKey,
"aws_session_token_expr", AwsSessionTokenExpr,
)
sql = conn.setEmptyAsNull(sql)

Expand Down
2 changes: 1 addition & 1 deletion core/dbio/filesys/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ func WriteDataflowViaDuckDB(fs FileSysClient, df *iop.Dataflow, uri string) (bw

// generate sql for export
switch fs.FsType() {
case dbio.TypeFileS3, dbio.TypeFileLocal:
case dbio.TypeFileLocal:
// copy files bytes recursively to target
if strings.Contains(duckURI, "*") {
duckURI = GetDeepestParent(duckURI) // get target folder, since split by files
Expand Down
4 changes: 2 additions & 2 deletions core/dbio/templates/redshift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ core:
copy_from_s3: |
COPY {tgt_table} ({tgt_columns})
from '{s3_path}'
credentials 'aws_access_key_id={aws_access_key_id};aws_secret_access_key={aws_secret_access_key}'
credentials 'aws_access_key_id={aws_access_key_id};aws_secret_access_key={aws_secret_access_key}{aws_session_token_expr}'
CSV delimiter ',' EMPTYASNULL BLANKSASNULL GZIP IGNOREHEADER 1 DATEFORMAT 'auto' TIMEFORMAT 'auto'
copy_to_s3: |
unload ('{sql}')
to '{s3_path}'
credentials 'aws_access_key_id={aws_access_key_id};aws_secret_access_key={aws_secret_access_key}'
credentials 'aws_access_key_id={aws_access_key_id};aws_secret_access_key={aws_secret_access_key}{aws_session_token_expr}'
gzip allowoverwrite CSV PARALLEL {parallel} NULL '\\N' HEADER DELIMITER ','
alter_columns: |
alter table {table} {col_ddl}
Expand Down
Loading