func (sr *StreamResult) Next() (row []interface{}) { if sr.qr == nil { // we need to read the next record that may contain // multiple rows qr, ok := <-sr.sr if !ok { if sr.errFunc() != nil { log.Warningf("vt: error reading the next value %v", sr.errFunc()) sr.err = sr.errFunc() } return nil } sr.qr = qr sr.index = 0 } row = make([]interface{}, len(sr.qr.Rows[sr.index])) for i, v := range sr.qr.Rows[sr.index] { var err error row[i], err = mproto.Convert(sr.columns.Fields[i].Type, v) if err != nil { panic(err) // unexpected } } sr.index++ if sr.index == len(sr.qr.Rows) { // we reached the end of our rows, nil it so next run // will fetch the next one sr.qr = nil } return row }
func (vind *LookupHashUnique) Map(vcursor planbuilder.VCursor, ids []interface{}) ([]key.KeyspaceId, error) { out := make([]key.KeyspaceId, 0, len(ids)) bq := &tproto.BoundQuery{ Sql: vind.sel, } for _, id := range ids { bq.BindVariables = map[string]interface{}{ vind.From: id, } result, err := vcursor.Execute(bq) if err != nil { return nil, err } if len(result.Rows) == 0 { out = append(out, "") continue } if len(result.Rows) != 1 { return nil, fmt.Errorf("unexpected multiple results from vindex %s: %v", vind.Table, id) } inum, err := mproto.Convert(result.Fields[0].Type, result.Rows[0][0]) if err != nil { return nil, err } num, err := getNumber(inum) if err != nil { return nil, err } out = append(out, vhash(num)) } return out, nil }
// CompareRows returns: // -1 if left is smaller than right // 0 if left and right are equal // +1 if left is bigger than right // TODO: This can panic if types for left and right don't match. func CompareRows(fields []mproto.Field, compareCount int, left, right []sqltypes.Value) (int, error) { for i := 0; i < compareCount; i++ { fieldType := fields[i].Type lv, err := mproto.Convert(fieldType, left[i]) if err != nil { return 0, err } rv, err := mproto.Convert(fieldType, right[i]) if err != nil { return 0, err } switch l := lv.(type) { case int64: r := rv.(int64) if l < r { return -1, nil } else if l > r { return 1, nil } case uint64: r := rv.(uint64) if l < r { return -1, nil } else if l > r { return 1, nil } case float64: r := rv.(float64) if l < r { return -1, nil } else if l > r { return 1, nil } case []byte: r := rv.([]byte) return bytes.Compare(l, r), nil default: return 0, fmt.Errorf("Unsuported type %T returned by mysql.proto.Convert", l) } } return 0, nil }
func (result *Result) Next() (row []interface{}) { if result.index >= len(result.qr.Rows) { return nil } row = make([]interface{}, len(result.qr.Rows[result.index])) for i, v := range result.qr.Rows[result.index] { var err error row[i], err = mproto.Convert(result.qr.Fields[i].Type, v) if err != nil { panic(err) // unexpected } } result.index++ return row }