// from nested map create mutation map thrift struct func makeMutationMap(cf string, mutate map[string]map[string]string, timestamp int64) (mutationMap thrift.TMap) { mutationMap = thrift.NewTMap(thrift.STRING, thrift.MAP, len(mutate)) // len = # of keys(rows) for rowkey, cols := range mutate { colm := thrift.NewTMap(thrift.STRING, thrift.LIST, 1) // # of column families l := thrift.NewTList(thrift.STRUCT, 0) // auto-expands, starting length should be 0 columns := makeColumns(cols, timestamp) for i := 0; i < len(cols); i++ { cosc := cassandra.NewColumnOrSuperColumn() cosc.Column = &columns[i] mut := cassandra.NewMutation() mut.ColumnOrSupercolumn = cosc l.Push(mut) } // seems backwards, but.. row key on the outer map, cfname on inner colm.Set(cf, l) mutationMap.Set(rowkey, colm) } return }
func (r *reader) buildMultiKeys(keys [][]byte) thrift.TList { tkeys := thrift.NewTList(thrift.BINARY, 1) for _, k := range keys { tkeys.Push(k) } return tkeys }
func (r *reader) SuperGet(key []byte) (*SuperRow, error) { if r.cf == "" { return nil, errors.New("No column family specified") } cp := r.buildColumnParent() sp := r.buildPredicate() var ret thrift.TMap var keys thrift.TList = thrift.NewTList(thrift.BINARY, 0) // size appears to be ignored in the thrift lib keys.Push(key) err := r.pool.run(func(c *connection) (*cassandra.InvalidRequestException, *cassandra.UnavailableException, *cassandra.TimedOutException, error) { var ire *cassandra.InvalidRequestException var ue *cassandra.UnavailableException var te *cassandra.TimedOutException var err error ret, ire, ue, te, err = c.client.MultigetSlice(keys, cp, sp, cassandra.ConsistencyLevel(r.consistencyLevel)) return ire, ue, te, err }) if err != nil { return nil, err } return rowFromTMapColumns(key, ret), nil }
func (w *writer) InsertTtl(cf string, row *Row, ttl int) Writer { t := now() if len(row.SuperColumns) > 0 { for _, scol := range row.SuperColumns { tm := w.addWriter(cf, row.Key) sc := cassandra.NewSuperColumn() sc.Name = scol.Name sc.Columns = thrift.NewTList(thrift.STRUCT, 1) for _, col := range scol.Columns { c := cassandra.NewColumn() c.Name = col.Name c.Value = col.Value if ttl > 0 { c.Ttl = int32(ttl) } else { c.Ttl = col.Ttl } if col.Timestamp > 0 { c.Timestamp = col.Timestamp } else { c.Timestamp = t } sc.Columns.Push(c) } cs := cassandra.NewColumnOrSuperColumn() cs.SuperColumn = sc tm.ColumnOrSupercolumn = cs } } else if len(row.Columns) > 0 { for _, col := range row.Columns { tm := w.addWriter(cf, row.Key) c := cassandra.NewColumn() c.Name = col.Name c.Value = col.Value if ttl > 0 { c.Ttl = int32(ttl) } else { c.Ttl = col.Ttl } if col.Timestamp > 0 { c.Timestamp = col.Timestamp } else { c.Timestamp = t } cs := cassandra.NewColumnOrSuperColumn() cs.Column = c tm.ColumnOrSupercolumn = cs } } return w }
func (r *reader) Where(column []byte, op Operator, value []byte) Reader { if r.expressions == nil { r.expressions = thrift.NewTList(thrift.STRUCT, 1) } exp := cassandra.NewIndexExpression() exp.ColumnName = column exp.Op = cassandra.IndexOperator(op) exp.Value = value r.expressions.Push(exp) r.setWhere = true return r }
func (w *writer) DeleteColumns(cf string, key []byte, columns [][]byte) Writer { tm := w.addWriter(cf, key) d := cassandra.NewDeletion() d.Timestamp = now() sp := cassandra.NewSlicePredicate() sp.ColumnNames = thrift.NewTList(thrift.BINARY, 1) for _, name := range columns { sp.ColumnNames.Push(name) } d.Predicate = sp tm.Deletion = d return w }
func (c *CassandraConnection) GetCols(cf, rowkey string, cols []string) (cassCol []*cassandra.Column, err error) { sp := cassandra.NewSlicePredicate() cp := NewColumnParent(cf) //ColumnNames thrift.TList "column_names"; // 1 l := thrift.NewTList(thrift.STRING, 0) // auto-expands, starting length should be 0 for i := 0; i < len(cols); i++ { l.Push(cols[i]) } sp.ColumnNames = l return c.getslice(rowkey, cp, sp) }
func (r *reader) buildPredicate() *cassandra.SlicePredicate { sp := cassandra.NewSlicePredicate() if r.setColumns { sp.ColumnNames = thrift.NewTList(thrift.BINARY, 1) for _, col := range r.columns { sp.ColumnNames.Push(col) } } else if r.setSlice { sp.SliceRange = sliceToCassandra(&r.slice) } else { sp.SliceRange = fullSlice() } return sp }
func (w *writer) addWriter(cf string, key []byte) *cassandra.Mutation { tm := cassandra.NewMutation() var cfMuts thrift.TMap im, exists := w.writers.Get(key) if !exists { cfMuts = thrift.NewTMap(thrift.STRING, thrift.LIST, 1) w.writers.Set(key, cfMuts) } else { cfMuts = im.(thrift.TMap) } var mutList thrift.TList im, exists = cfMuts.Get(cf) if !exists { mutList = thrift.NewTList(thrift.STRUCT, 1) cfMuts.Set(cf, mutList) } else { mutList = im.(thrift.TList) } mutList.Push(tm) return tm }