in cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/collectiondecoder/collectiondecoder.go [152:239]
func ConvertToTypedSlice(decodedElements []interface{}, dt datatype.DataType) (interface{}, error) {
switch dt.GetDataTypeCode() {
case primitive.DataTypeCodeAscii, primitive.DataTypeCodeVarchar:
typedCollection := make([]string, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(string)
}
return typedCollection, nil
case primitive.DataTypeCodeBigint, primitive.DataTypeCodeCounter:
typedCollection := make([]int64, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(int64)
}
return typedCollection, nil
case primitive.DataTypeCodeInt:
typedCollection := make([]int32, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(int32)
}
return typedCollection, nil
case primitive.DataTypeCodeFloat:
typedCollection := make([]float32, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(float32)
}
return typedCollection, nil
case primitive.DataTypeCodeDouble:
typedCollection := make([]float64, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(float64)
}
return typedCollection, nil
case primitive.DataTypeCodeBoolean:
typedCollection := make([]bool, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(bool)
}
return typedCollection, nil
case primitive.DataTypeCodeTimestamp, primitive.DataTypeCodeDate, primitive.DataTypeCodeTime:
typedCollection := make([]int64, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(int64)
}
return typedCollection, nil
case primitive.DataTypeCodeUuid, primitive.DataTypeCodeTimeuuid:
typedCollection := make([]string, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(string)
}
return typedCollection, nil
case primitive.DataTypeCodeDecimal, primitive.DataTypeCodeVarint:
// Assuming decimal and varint are represented as strings
typedCollection := make([]string, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(string)
}
return typedCollection, nil
case primitive.DataTypeCodeBlob, primitive.DataTypeCodeInet:
// Assuming blob and inet are represented as byte slices
typedCollection := make([][]byte, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.([]byte)
}
return typedCollection, nil
case primitive.DataTypeCodeSmallint:
typedCollection := make([]int16, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(int16)
}
return typedCollection, nil
case primitive.DataTypeCodeTinyint:
typedCollection := make([]int8, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(int8)
}
return typedCollection, nil
case primitive.DataTypeCodeDuration:
// Assuming duration is represented as int64
typedCollection := make([]int64, len(decodedElements))
for i, elem := range decodedElements {
typedCollection[i] = elem.(int64)
}
return typedCollection, nil
default:
// Unsupported type
return nil, fmt.Errorf("unsupported data type: %v", dt.GetDataTypeCode())
}
}