func processCollectionColumnsForRawQueries()

in cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/translator/utils.go [481:532]


func processCollectionColumnsForRawQueries(input ProcessRawCollectionsInput) (*ProcessRawCollectionsOutput, error) {
	output := &ProcessRawCollectionsOutput{
		ComplexMeta: make(map[string]*ComplexOperation),
	}

	for i, column := range input.Columns {
		if column.IsPrimaryKey {
			continue
		}
		if input.Translator.IsCollection(input.KeySpace, input.TableName, column.Name) {
			val := input.Values[i].(string)
			if strings.Contains(val, column.Name) && (strings.Contains(val, "+") || strings.Contains(val, "-")) {
				// in (+) cases we are extracting the value from the collection type from the query. for example map=map+{key:val}
				//  so it extracts {key:val} || {key1,key2} in case of set and list
				if strings.Contains(val, "+") {
					trimmedStr := strings.TrimPrefix(val, column.Name)
					trimmedStr = strings.TrimPrefix(trimmedStr, "+")
					val = strings.TrimSpace(trimmedStr)
				} else if strings.Contains(val, "-") {
					// in (-) cases we are extracting the value from the collection type from the query. for example map=map-{key1,key2}
					// extracts the column family and the element keys for deletion of collection elements. For collection types (e.g., map=map-{key1,key2}),
					// extract both the column family (e.g., 'map') and the element keys (e.g., 'key1', 'key2')
					// to be used for deleting the corresponding columns
					cf, qualifiers, err := ExtractCFAndQualifiersforMap(val)
					if err != nil {
						return nil, fmt.Errorf("error reading map set value: %w", err)
					}
					for _, key := range qualifiers {
						output.DelColumns = append(output.DelColumns, Column{Name: key, ColumnFamily: cf})
					}
					continue
					//once delete keys and cf are captured from the set Item continuing to next one.
				}
			} else {
				// its a deafult block when collection=newcolletion is bheing set. then we are deleting the whole column family and inserting the value
				output.DelColumnFamily = append(output.DelColumnFamily, column.Name)
			}

			colFamily := input.Translator.GetColumnFamily(input.KeySpace, input.TableName, column.Name)
			cols, vals, err := processCollectionByType(val, colFamily, column.CQLType, input.PrependColumns, output.ComplexMeta)
			if err != nil {
				return nil, err
			}
			output.NewColumns = append(output.NewColumns, cols...)
			output.NewValues = append(output.NewValues, vals...)
		} else {
			output.NewColumns = append(output.NewColumns, column)
			output.NewValues = append(output.NewValues, input.Values[i])
		}
	}
	return output, nil
}