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

feat(push): preserve null #362

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion internal/app/push/cli.go
Original file line number Diff line number Diff line change
@@ -312,7 +312,7 @@ func (c idToPushConverter) getTable(name string, autoTruncate bool) push.Table {

columns := []push.Column{}
for _, col := range table.Columns {
columns = append(columns, push.NewColumn(col.Name, col.Export, col.Import, col.DBInfo.Length, col.DBInfo.ByteBased, autoTruncate))
columns = append(columns, push.NewColumn(col.Name, col.Export, col.Import, col.DBInfo.Length, col.DBInfo.ByteBased, autoTruncate, col.DBInfo.Preserve))
}

return push.NewTable(table.Name, table.Keys, push.NewColumnList(columns))
10 changes: 7 additions & 3 deletions internal/infra/push/datadestination_oracle.go
Original file line number Diff line number Diff line change
@@ -148,9 +148,13 @@ func (d OracleDialect) UpdateStatement(tableName string, selectValues []ValueDes

headers = append(headers, column)

sql.WriteString(column.name)
sql.WriteString("=")
sql.WriteString(d.Placeholder(index + 1))
if column.column.Preserve() == "null" {
sql.WriteString(fmt.Sprintf("%s = CASE WHEN %s IS NOT NULL THEN %s ELSE %s END", column.name, column.name, d.Placeholder(index+1), column.name))
} else {
sql.WriteString(column.name)
sql.WriteString("=")
sql.WriteString(d.Placeholder(index + 1))
}
if index+1 < len(selectValues) {
sql.WriteString(", ")
}
1 change: 1 addition & 0 deletions internal/infra/table/storage_yaml.go
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ type YAMLDBInfo struct {
Size int64 `yaml:"size,omitempty"`
Precision int64 `yaml:"precision,omitempty"`
ByteBased bool `yaml:"bytes,omitempty"`
Preserve string `yaml:"preserve,omitempty"`
}

// YAMLStorage provides storage in a local YAML file
1 change: 1 addition & 0 deletions pkg/push/model.go
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ type Column interface {
Length() int64
LengthInBytes() bool
Truncate() bool
Preserve() string
}

// Plan describe how to push data
6 changes: 4 additions & 2 deletions pkg/push/model_table.go
Original file line number Diff line number Diff line change
@@ -96,11 +96,12 @@ type column struct {
lgth int64
inbytes bool
truncate bool
preserve string
}

// NewColumn initialize a new Column object
func NewColumn(name string, exp string, imp string, lgth int64, inbytes bool, truncate bool) Column {
return column{name, exp, imp, lgth, inbytes, truncate}
func NewColumn(name string, exp string, imp string, lgth int64, inbytes bool, truncate bool, preserve string) Column {
return column{name, exp, imp, lgth, inbytes, truncate, preserve}
}

func (c column) Name() string { return c.name }
@@ -109,6 +110,7 @@ func (c column) Import() string { return c.imp }
func (c column) Length() int64 { return c.lgth }
func (c column) LengthInBytes() bool { return c.inbytes }
func (c column) Truncate() bool { return c.truncate }
func (c column) Preserve() string { return c.preserve }

type ImportedRow struct {
jsonline.Row
1 change: 1 addition & 0 deletions pkg/table/model.go
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ type DBInfo struct {
Size int64
Precision int64
ByteBased bool
Preserve string
}

// Column holds the name of a column.