Skip to content

Commit

Permalink
chore(warehouse): handle schema table driven tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr committed Nov 4, 2022
1 parent 00ba231 commit c196dbc
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 227 deletions.
28 changes: 15 additions & 13 deletions warehouse/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,38 @@ type SchemaHandleT struct {
uploadSchema warehouseutils.SchemaT
}

func HandleSchemaChange(existingDataType, columnType string, columnVal interface{}) (newColumnVal interface{}, ok bool) {
func HandleSchemaChange(existingDataType, newDataType string, value interface{}) (interface{}, bool) {
var newColumnVal interface{}

if existingDataType == "string" || existingDataType == "text" {
// only stringify if the previous type is non-string/text/json
if columnType != "string" && columnType != "text" && columnType != "json" {
newColumnVal = fmt.Sprintf("%v", columnVal)
if newDataType != "string" && newDataType != "text" && newDataType != "json" {
newColumnVal = fmt.Sprintf("%v", value)
} else {
newColumnVal = columnVal
newColumnVal = value
}
} else if (columnType == "int" || columnType == "bigint") && existingDataType == "float" {
intVal, ok := columnVal.(int)
} else if (newDataType == "int" || newDataType == "bigint") && existingDataType == "float" {
intVal, ok := value.(int)
if !ok {
newColumnVal = nil
} else {
newColumnVal = float64(intVal)
}
} else if columnType == "float" && (existingDataType == "int" || existingDataType == "bigint") {
floatVal, ok := columnVal.(float64)
} else if newDataType == "float" && (existingDataType == "int" || existingDataType == "bigint") {
floatVal, ok := value.(float64)
if !ok {
newColumnVal = nil
} else {
newColumnVal = int(floatVal)
}
} else if existingDataType == "json" {
var interfaceSliceSample []interface{}
if columnType == "int" || columnType == "float" || columnType == "boolean" {
newColumnVal = fmt.Sprintf("%v", columnVal)
} else if reflect.TypeOf(columnVal) == reflect.TypeOf(interfaceSliceSample) {
newColumnVal = columnVal
if newDataType == "int" || newDataType == "float" || newDataType == "boolean" {
newColumnVal = fmt.Sprintf("%v", value)
} else if reflect.TypeOf(value) == reflect.TypeOf(interfaceSliceSample) {
newColumnVal = value
} else {
newColumnVal = fmt.Sprintf(`"%v"`, columnVal)
newColumnVal = fmt.Sprintf(`"%v"`, value)
}
} else {
return nil, false
Expand Down
Loading

0 comments on commit c196dbc

Please sign in to comment.