in cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/testing/compliance/utility/utils.go [753:862]
func ConvertExpectedResult(input []map[string]interface{}) []map[string]interface{} {
if len(input) == 0 || input == nil {
return nil
}
// Output slice
convertedResult := make([]map[string]interface{}, 1)
convertedResult[0] = make(map[string]interface{}) // Initialize the first map
// Iterate through the input and process each field
for _, field := range input {
for key, value := range field {
if key == "datatype" {
continue // Skip the "datatype" key
}
if datatype, exists := field["datatype"].(string); exists {
// Perform conversion based on datatype
switch datatype {
// Primitive Types
case "text":
convertedResult[0][key] = fmt.Sprintf("%v", value) // Convert to string
case "bigint":
if val, err := toInt64(value); err == nil {
convertedResult[0][key] = val
}
case "int":
if val, err := toInt(value); err == nil {
convertedResult[0][key] = val
}
case "double":
if val, err := toFloat64(value); err == nil {
convertedResult[0][key] = val
}
case "float":
if val, err := toFloat32(value); err == nil {
convertedResult[0][key] = val
}
case "boolean":
if val, err := toBool(value); err == nil {
convertedResult[0][key] = val
}
case "timestamp":
if val, err := toTimestamp(value); err == nil {
convertedResult[0][key] = val
}
// Map Types
case "map<text,text>":
convertedResult[0][key] = toMapStringString(value)
case "map<text,int>":
convertedResult[0][key] = toMapStringInt(value)
case "map<text,bigint>":
convertedResult[0][key] = toMapStringInt64(value)
case "map<text,boolean>":
convertedResult[0][key] = toMapStringBool(value)
case "map<text,timestamp>":
convertedResult[0][key] = toMapStringTimestamp(value)
case "map<text,float>":
convertedResult[0][key] = toMapStringFloat32(value)
case "map<text,double>":
convertedResult[0][key] = toMapStringFloat64(value)
case "map<timestamp,text>":
convertedResult[0][key] = toMapTimestampString(value)
case "map<timestamp,boolean>":
convertedResult[0][key] = toMapTimestampBool(value)
case "map<timestamp,float>":
convertedResult[0][key] = toMapTimestampFloat32(value)
case "map<timestamp,double>":
convertedResult[0][key] = toMapTimestampFloat64(value)
case "map<timestamp,bigint>":
convertedResult[0][key] = toMapTimestampInt64(value)
case "map<timestamp,timestamp>":
convertedResult[0][key] = toMapTimestampTimestamp(value)
case "map<timestamp,int>":
convertedResult[0][key] = toMapTimestampInt(value)
// Set Types
case "set<text>":
convertedResult[0][key] = toSetString(value)
case "set<boolean>":
convertedResult[0][key] = toSetBool(value)
case "set<int>":
convertedResult[0][key] = toSetInt(value)
case "set<bigint>":
convertedResult[0][key] = toSetInt64(value)
case "set<float>":
convertedResult[0][key] = toSetFloat32(value)
case "set<double>":
convertedResult[0][key] = toSetFloat64(value)
case "set<timestamp>":
convertedResult[0][key] = toSetTimestamp(value)
case "list<text>":
convertedResult[0][key] = toSetString(value)
case "list<boolean>":
convertedResult[0][key] = toSetBool(value)
case "list<int>":
convertedResult[0][key] = toSetInt(value)
case "list<bigint>":
convertedResult[0][key] = toSetInt64(value)
case "list<float>":
convertedResult[0][key] = toSetFloat32(value)
case "list<double>":
convertedResult[0][key] = toSetFloat64(value)
case "list<timestamp>":
convertedResult[0][key] = toSetTimestamp(value)
}
}
}
}
return convertedResult
}