Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Fix field value import: Use signed int and respect field minimum #919

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ func (p Bits) GroupBySlice() map[uint64][]Bit {
// range-encoded frame.
type FieldValue struct {
ColumnID uint64
Value uint64
Value int64
}

// FieldValues represents a slice of field values.
Expand All @@ -1154,8 +1154,8 @@ func (p FieldValues) ColumnIDs() []uint64 {
}

// Values returns a slice of all the values.
func (p FieldValues) Values() []uint64 {
other := make([]uint64, len(p))
func (p FieldValues) Values() []int64 {
other := make([]int64, len(p))
for i := range p {
other[i] = p[i].Value
}
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestClient_ImportValue(t *testing.T) {
fld := pilosa.Field{
Name: "fld",
Type: pilosa.FieldTypeInt,
Min: 0,
Min: -100,
Max: 100,
}

Expand All @@ -320,7 +320,7 @@ func TestClient_ImportValue(t *testing.T) {
// Send import request.
c := test.MustNewClient(s.Host())
if err := c.ImportValue(context.Background(), "i", "f", fld.Name, 0, []pilosa.FieldValue{
{ColumnID: 1, Value: 10},
{ColumnID: 1, Value: -10},
{ColumnID: 2, Value: 20},
{ColumnID: 3, Value: 40},
}); err != nil {
Expand All @@ -333,7 +333,7 @@ func TestClient_ImportValue(t *testing.T) {
}

// Verify data.
if sum != 70 || cnt != 3 {
if sum != 50 || cnt != 3 {
t.Fatalf("unexpected values: got sum=%v, count=%v; expected sum=70, cnt=3", sum, cnt)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ctl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (cmd *ImportCommand) bufferFieldValues(ctx context.Context, path string) er
val.ColumnID = columnID

// Parse field value.
value, err := strconv.ParseUint(record[1], 10, 64)
value, err := strconv.ParseInt(record[1], 10, 64)
if err != nil {
return fmt.Errorf("invalid value on row %d: %q", rnum, record[1])
}
Expand Down
9 changes: 7 additions & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ func (f *Frame) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time) erro
}

// ImportValue bulk imports range-encoded value data.
func (f *Frame) ImportValue(fieldName string, columnIDs, values []uint64) error {
func (f *Frame) ImportValue(fieldName string, columnIDs []uint64, values []int64) error {
// Verify that this frame is range-encoded.
if !f.RangeEnabled() {
return fmt.Errorf("Frame not RangeEnabled: %s", f.name)
Expand Down Expand Up @@ -930,7 +930,12 @@ func (f *Frame) ImportValue(fieldName string, columnIDs, values []uint64) error
return err
}

if err := frag.ImportValue(data.ColumnIDs, data.Values, field.BitDepth()); err != nil {
baseValues := make([]uint64, len(data.Values))
for i, value := range data.Values {
baseValues[i] = uint64(value - field.Min)
}

if err := frag.ImportValue(data.ColumnIDs, baseValues, field.BitDepth()); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ type importData struct {

type importValueData struct {
ColumnIDs []uint64
Values []uint64
Values []int64
}

// CreateInputDefinition creates a new input definition.
Expand Down
23 changes: 12 additions & 11 deletions internal/public.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/public.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ message ImportValueRequest {
uint64 Slice = 3;
string Field = 4;
repeated uint64 ColumnIDs = 5;
repeated uint64 Values = 6;
repeated int64 Values = 6;
}