func setParamsFromValues()

in cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/translator/translator_insert.go [113:166]


func setParamsFromValues(input cql.IInsertValuesSpecContext, columns []Column, schemaMapping *schemaMapping.SchemaMappingConfig, protocolV primitive.ProtocolVersion, tableName string, keySpace string, isPreparedQuery bool) (map[string]interface{}, []interface{}, map[string]interface{}, error) {
	if input != nil {
		valuesExpressionList := input.ExpressionList()
		if valuesExpressionList == nil {
			return nil, nil, nil, errors.New("setParamsFromValues: error while parsing values")
		}

		values := valuesExpressionList.AllExpression()
		if values == nil {
			return nil, nil, nil, errors.New("setParamsFromValues: error while parsing values")
		}
		var valuesArr []string
		var respValue []interface{}
		for _, val := range values {
			valueName := val.GetText()
			if valueName != "" {
				valuesArr = append(valuesArr, valueName)
			} else {
				return nil, nil, nil, errors.New("setParamsFromValues: Invalid Value paramaters")
			}
		}
		response := make(map[string]interface{})
		unencrypted := make(map[string]interface{})
		for i, col := range columns {
			value := strings.ReplaceAll(valuesArr[i], "'", "")
			colName := col.Name
			if !isPreparedQuery {
				var val interface{}
				var unenVal interface{}
				var err error
				columnType, er := schemaMapping.GetColumnType(keySpace, tableName, col.Name)
				if er != nil {
					return nil, nil, nil, er
				}
				if columnType.IsCollection {
					val = value
					unenVal = value
				} else {
					unenVal = value
					val, err = formatValues(value, col.CQLType, protocolV)
					if err != nil {
						return nil, nil, nil, err
					}
				}
				response[colName] = val
				unencrypted[colName] = unenVal
				respValue = append(respValue, val)
			}
		}

		return response, respValue, unencrypted, nil
	}
	return nil, nil, nil, errors.New("setParamsFromValues: No Value paramaters found")
}