Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
handle byte slice batch record IDs
Browse files Browse the repository at this point in the history
also check for unsupported field types and error
  • Loading branch information
jaffee committed Oct 4, 2019
1 parent 2dfc4b7 commit bfe8680
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions gpexp/importbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func NewBatch(client *pilosa.Client, size int, index *pilosa.Index, fields []*pi
hasTime = typ == pilosa.FieldTypeTime || hasTime
case pilosa.FieldTypeInt:
values[field.Name()] = make([]int64, 0, size)
default:
return nil, errors.Errorf("field type %s is not currently supported through Batch", typ)
}
}
b := &Batch{
Expand Down Expand Up @@ -254,10 +256,7 @@ func (b *Batch) Add(rec Row) error {
return errors.Errorf("record needs to match up with batch fields, got %d fields and %d record", len(b.header), len(rec.Values))
}

switch rid := rec.ID.(type) {
case uint64:
b.ids = append(b.ids, rid)
case string:
handleStringID := func(rid string) error {
if colID, ok, err := b.transCache.GetCol(b.index.Name(), rid); err != nil {
return errors.Wrap(err, "translating column")
} else if ok {
Expand All @@ -271,6 +270,23 @@ func (b *Batch) Add(rec Row) error {
b.toTranslateID[rid] = ints
b.ids = append(b.ids, 0)
}
return nil
}
var err error

switch rid := rec.ID.(type) {
case uint64:
b.ids = append(b.ids, rid)
case string:
err := handleStringID(rid)
if err != nil {
return err
}
case []byte:
err = handleStringID(string(rid))
if err != nil {
return err
}
default: // TODO support nil ID as being auto-allocated.
return errors.Errorf("unsupported id type %T value %v", rid, rid)
}
Expand Down

0 comments on commit bfe8680

Please sign in to comment.