in cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/translator/translator_insert.go [327:392]
func (t *Translator) BuildInsertPrepareQuery(columnsResponse []Column, values []*primitive.Value, st *InsertQueryMapping, protocolV primitive.ProtocolVersion) (*InsertQueryMapping, error) {
var newColumns []Column
var newValues []interface{}
var primaryKeys []string = st.PrimaryKeys
var delColumnFamily []string
var err error
var unencrypted map[string]interface{}
var prepareOutput *ProcessPrepareCollectionsOutput // Declare prepareOutput
if len(primaryKeys) == 0 {
primaryKeys, _ = getPrimaryKeys(t.SchemaMappingConfig, st.Table, st.Keyspace)
}
timestampInfo, err := ProcessTimestamp(st, values)
if err != nil {
return nil, err
}
// Building new colum family, qualifier and values for collection type of data.
prepareInput := ProcessPrepareCollectionsInput{
ColumnsResponse: columnsResponse,
Values: values,
TableName: st.Table,
ProtocolV: protocolV,
PrimaryKeys: primaryKeys,
Translator: t,
KeySpace: st.Keyspace,
ComplexMeta: nil, // Assuming nil for insert
}
prepareOutput, err = processCollectionColumnsForPrepareQueries(prepareInput)
if err != nil {
fmt.Println("Error processing prepared collection columns:", err)
return nil, err
}
newColumns = prepareOutput.NewColumns
newValues = prepareOutput.NewValues
unencrypted = prepareOutput.Unencrypted
delColumnFamily = prepareOutput.DelColumnFamily
pmks, err := t.SchemaMappingConfig.GetPkByTableNameWithFilter(st.Table, st.Keyspace, primaryKeys)
if err != nil {
return nil, err
}
rowKeyBytes, err := createOrderedCodeKey(pmks, unencrypted, t.EncodeIntValuesWithBigEndian)
if err != nil {
return nil, err
}
rowKey := string(rowKeyBytes)
insertQueryData := &InsertQueryMapping{
Columns: newColumns,
Values: newValues,
PrimaryKeys: primaryKeys,
RowKey: rowKey,
DeleteColumnFamilies: delColumnFamily,
TimestampInfo: timestampInfo,
Query: st.Query,
QueryType: st.QueryType,
Table: st.Table,
Keyspace: st.Keyspace,
Params: st.Params,
ParamKeys: st.PrimaryKeys,
IfNotExists: st.IfNotExists,
}
return insertQueryData, nil
}