func GetCassandraColumnType()

in cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/utilities/utils.go [129:189]


func GetCassandraColumnType(c string) (datatype.DataType, error) {
	choice := strings.ToLower(strings.ReplaceAll(c, " ", ""))
	if strings.HasSuffix(choice, ">") {
		if strings.HasPrefix(choice, "frozen<") {
			innerType, err := GetCassandraColumnType(choice[7 : len(choice)-1])
			if err != nil {
				return nil, fmt.Errorf("failed to extract type for '%s': %w", c, err)
			}
			// drop the frozen wrapper
			return innerType, nil
		} else if strings.HasPrefix(choice, "list<") {
			innerType, err := GetCassandraColumnType(choice[5 : len(choice)-1])
			if err != nil {
				return nil, fmt.Errorf("failed to extract type for '%s': %w", c, err)
			}
			return datatype.NewListType(innerType), nil
		} else if strings.HasPrefix(choice, "set<") {
			innerType, err := GetCassandraColumnType(choice[4 : len(choice)-1])
			if err != nil {
				return nil, fmt.Errorf("failed to extract type for '%s': %w", c, err)
			}
			return datatype.NewSetType(innerType), nil
		} else if strings.HasPrefix(choice, "map<") {
			parts := strings.SplitN(choice[4:len(choice)-1], ",", 2)
			if len(parts) != 2 {
				return nil, fmt.Errorf("malformed map type")
			}
			keyType, err := GetCassandraColumnType(parts[0])
			if err != nil {
				return nil, fmt.Errorf("failed to extract type for '%s': %w", c, err)
			}
			valueType, err := GetCassandraColumnType(parts[1])
			if err != nil {
				return nil, fmt.Errorf("failed to extract type for '%s': %w", c, err)
			}
			return datatype.NewMapType(keyType, valueType), nil
		}
	}
	switch choice {
	case CassandraTypeText, "varchar":
		return datatype.Varchar, nil
	case CassandraTypeBlob:
		return datatype.Blob, nil
	case CassandraTypeTimestamp:
		return datatype.Timestamp, nil
	case CassandraTypeInt:
		return datatype.Int, nil
	case CassandraTypeBigint:
		return datatype.Bigint, nil
	case CassandraTypeBoolean:
		return datatype.Boolean, nil
	case CassandraTypeUuid:
		return datatype.Uuid, nil
	case CassandraTypeFloat:
		return datatype.Float, nil
	case CassandraTypeDouble:
		return datatype.Double, nil
	default:
		return nil, fmt.Errorf("unsupported column type: %s", choice)
	}
}