fix rowID=0 bug

This commit is contained in:
Linh Vo 2017-09-01 16:49:04 -05:00
parent 5a0eea2948
commit 9fc308925b
3 changed files with 44 additions and 46 deletions

View file

@ -940,28 +940,27 @@ func TestFragment_Zero_Tanimoto(t *testing.T) {
}
func TestFragment_Snapshot_Run(t *testing.T) {
f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, "")
defer f.Close()
f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, "")
defer f.Close()
// Set bits on the fragment.
for i := uint64(1); i < 3; i++ {
if _, err := f.SetBit(1000, i); err != nil {
t.Fatal(err)
}
}
// Set bits on the fragment.
for i := uint64(1); i < 3; i++ {
if _, err := f.SetBit(1000, i); err != nil {
t.Fatal(err)
}
}
// Snapshot bitmap and verify data.
if err := f.Snapshot(); err != nil {
t.Fatal(err)
} else if n := f.Row(1000).Count(); n != 2 {
t.Fatalf("unexpected count: %d", n)
}
// Snapshot bitmap and verify data.
if err := f.Snapshot(); err != nil {
t.Fatal(err)
} else if n := f.Row(1000).Count(); n != 2 {
t.Fatalf("unexpected count: %d", n)
}
// Close and reopen the fragment & verify the data.
if err := f.Reopen(); err != nil {
t.Fatal(err)
} else if n := f.Row(1000).Count(); n != 2 {
t.Fatalf("unexpected count (reopen): %d", n)
}
// Close and reopen the fragment & verify the data.
if err := f.Reopen(); err != nil {
t.Fatal(err)
} else if n := f.Row(1000).Count(); n != 2 {
t.Fatalf("unexpected count (reopen): %d", n)
}
}

View file

@ -211,7 +211,6 @@ func (a *Action) Validate() error {
if len(a.ValueMap) == 0 {
return ErrInputDefinitionValueMap
}
case InputSetTimestamp:
}
@ -372,7 +371,7 @@ func HandleAction(a Action, value interface{}, colID uint64, timestamp int64) (*
}
bit.RowID = uint64(v)
case InputSetTimestamp:
break
return nil, nil
default:
return nil, fmt.Errorf("Unrecognized Value Destination: %s in Action", a.ValueDestination)
}

View file

@ -198,34 +198,26 @@ func TestHandleAction(t *testing.T) {
action := pilosa.Action{ValueDestination: pilosa.InputSingleRowBool, RowID: &rowID}
timestamp := int64(0)
value = 1
b, err := pilosa.HandleAction(action, value, colID, timestamp)
if b != nil {
t.Fatalf("Expected integer type is not handled by single-row-boolean")
} else if !strings.Contains(err.Error(), "single-row-boolean value") {
t.Fatalf("Expected single-row-boolean value error, actual error: %s", err)
tests := []struct {
name string
value interface{}
expected string
}{
{name: "integer value", value: 1, expected: "single-row-boolean value"},
{name: "string value", value: "1", expected: "single-row-boolean value 1 must equate to a Bool"},
}
for _, r := range tests {
t.Run(r.name, func(t *testing.T) {
_, err := pilosa.HandleAction(action, r.value, colID, timestamp)
if !strings.Contains(err.Error(), r.expected) {
t.Fatalf("Expect err: %s, actual: %s", r.expected, err.Error())
}
})
value = "1"
b, err = pilosa.HandleAction(action, value, colID, timestamp)
if b != nil {
t.Fatalf("Expected Ignore strings, only accept boolean")
}
value = "t"
b, err = pilosa.HandleAction(action, value, colID, timestamp)
if !strings.Contains(err.Error(), "must equate to a Bool") {
t.Fatalf("Expected Unrecognized Value Destination error, actual error: %s", err)
}
value = float64(1)
b, err = pilosa.HandleAction(action, value, colID, timestamp)
if !strings.Contains(err.Error(), "must equate to a Bool") {
t.Fatalf("Expected Unrecognized Value Destination error, actual error: %s", err)
}
value = false
b, err = pilosa.HandleAction(action, value, colID, timestamp)
b, err := pilosa.HandleAction(action, value, colID, timestamp)
if b != nil {
t.Fatalf("Expected Ignore values that do not equate to True")
}
@ -274,4 +266,12 @@ func TestHandleAction(t *testing.T) {
if !strings.Contains(err.Error(), "Unrecognized Value Destination") {
t.Fatalf("Expected Unrecognized Value Destination error, actual error: %s", err)
}
action.ValueDestination = pilosa.InputSetTimestamp
t.Run("nil bit", func(t *testing.T) {
b, err = pilosa.HandleAction(action, value, colID, timestamp)
if b != nil {
t.Fatalf("Expected nil bit is set")
}
})
}