From 9fc308925b210bb3053ed769a30e1f83edb0c5b1 Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Fri, 1 Sep 2017 16:49:04 -0500 Subject: [PATCH 1/5] fix rowID=0 bug --- fragment_test.go | 41 +++++++++++++++++------------------ input_definition.go | 3 +-- input_definition_test.go | 46 ++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/fragment_test.go b/fragment_test.go index 702eec70a..e7f112837 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -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) + } } - diff --git a/input_definition.go b/input_definition.go index ab5af2bc4..faa303eda 100644 --- a/input_definition.go +++ b/input_definition.go @@ -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) } diff --git a/input_definition_test.go b/input_definition_test.go index da6e91231..550549c9a 100644 --- a/input_definition_test.go +++ b/input_definition_test.go @@ -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") + } + }) } From 15ed65cb6029e32dea17fc924b8a96c9ee044045 Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Mon, 4 Sep 2017 23:37:16 -0500 Subject: [PATCH 2/5] update driven table test, add timestamp action test --- input_definition_test.go | 54 ++++++++++++---------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/input_definition_test.go b/input_definition_test.go index 550549c9a..e3ef3ee6b 100644 --- a/input_definition_test.go +++ b/input_definition_test.go @@ -195,35 +195,37 @@ func TestHandleAction(t *testing.T) { var value interface{} colID := uint64(0) rowID := uint64(100) - action := pilosa.Action{ValueDestination: pilosa.InputSingleRowBool, RowID: &rowID} + action := pilosa.Action{RowID: &rowID} timestamp := int64(0) tests := []struct { + action string name string value interface{} - expected string + expected uint64 + err 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"}, + {name: "integer single-row-bool", action: pilosa.InputSingleRowBool, value: 1, err: "single-row-boolean value"}, + {name: "string single-row-bool", action: pilosa.InputSingleRowBool,value: "1", err: "single-row-boolean value 1 must equate to a Bool"}, + {name: "string value-to-row", action: pilosa.InputValueToRow,value: "25", err: "value-to-row value must equate to an integer"}, + {name: "string mapping", action: pilosa.InputMapping,value: "test", err: "Value test does not exist in definition map"}, + {name: "int mapping", action: pilosa.InputMapping,value: 25, err: "Mapping value must be a string"}, + {name: "handle single-row-value", action: "test",value: true, err: "Unrecognized Value Destination"}, } for _, r := range tests { t.Run(r.name, func(t *testing.T) { + action.ValueDestination = r.action _, 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()) + if !strings.Contains(err.Error(), r.err) { + t.Fatalf("Expect err: %s, actual: %s", r.err, err.Error()) } }) } - value = false - b, err := pilosa.HandleAction(action, value, colID, timestamp) - if b != nil { - t.Fatalf("Expected Ignore values that do not equate to True") - } - value = true - b, err = pilosa.HandleAction(action, value, colID, timestamp) + action.ValueDestination = pilosa.InputSingleRowBool + b, err := pilosa.HandleAction(action, value, colID, timestamp) if b != nil { if b.ColumnID != 0 { t.Fatalf("Unexpected ColumnID %v", b.ColumnID) @@ -236,36 +238,12 @@ func TestHandleAction(t *testing.T) { action.ValueDestination = pilosa.InputValueToRow rowID = 101 value = float64(25.0) - b, err = pilosa.HandleAction(action, value, colID, timestamp) + b, _ = pilosa.HandleAction(action, value, colID, timestamp) if b != nil { if b.RowID != 25 { t.Fatalf("Unexpected RowID %v", b.RowID) } } - value = "25" - b, err = pilosa.HandleAction(action, value, colID, timestamp) - if b != nil { - t.Fatalf("Expected Ignore values that are not type float64") - } - - action.ValueDestination = pilosa.InputMapping - value = "test" - b, err = pilosa.HandleAction(action, value, colID, timestamp) - if b != nil { - t.Fatalf("Expected Ignore values that are not type string") - } - - value = 25 - b, err = pilosa.HandleAction(action, value, colID, timestamp) - if b != nil { - t.Fatalf("Expected Ignore values that are not type string") - } - - action.ValueDestination = "test" - b, err = pilosa.HandleAction(action, value, colID, timestamp) - 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) { From 98c22d8eb33dfac09ceb4ad920c86d68146a0c6d Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Tue, 5 Sep 2017 09:56:10 -0500 Subject: [PATCH 3/5] add comment for settimestamp action --- input_definition.go | 1 + 1 file changed, 1 insertion(+) diff --git a/input_definition.go b/input_definition.go index faa303eda..18c75f8a4 100644 --- a/input_definition.go +++ b/input_definition.go @@ -371,6 +371,7 @@ func HandleAction(a Action, value interface{}, colID uint64, timestamp int64) (* } bit.RowID = uint64(v) case InputSetTimestamp: + // SetTimestamp action return nil bit because it is to set timestamp for a frame if it's defined, not for setting bit return nil, nil default: return nil, fmt.Errorf("Unrecognized Value Destination: %s in Action", a.ValueDestination) From dacaf91ab40b87c02e9feeae68cc3a213f383ffe Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Tue, 5 Sep 2017 10:29:32 -0500 Subject: [PATCH 4/5] clearer comment on InputSetTimestamps --- input_definition.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/input_definition.go b/input_definition.go index 18c75f8a4..13b27bd17 100644 --- a/input_definition.go +++ b/input_definition.go @@ -371,7 +371,8 @@ func HandleAction(a Action, value interface{}, colID uint64, timestamp int64) (* } bit.RowID = uint64(v) case InputSetTimestamp: - // SetTimestamp action return nil bit because it is to set timestamp for a frame if it's defined, not for setting bit + // InputSetTimestamp action is used in the InputJSONDataParser Handler to append a timestamp to all bits in the frame. + // There are no individual rowID's to set, and the action is a no-op at this step return nil, nil default: return nil, fmt.Errorf("Unrecognized Value Destination: %s in Action", a.ValueDestination) From 197415f8cbc3f4bf89308d6569c555d34eefbf54 Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Tue, 5 Sep 2017 10:41:24 -0500 Subject: [PATCH 5/5] change test name --- input_definition_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input_definition_test.go b/input_definition_test.go index e3ef3ee6b..6531ca69d 100644 --- a/input_definition_test.go +++ b/input_definition_test.go @@ -210,7 +210,7 @@ func TestHandleAction(t *testing.T) { {name: "string value-to-row", action: pilosa.InputValueToRow,value: "25", err: "value-to-row value must equate to an integer"}, {name: "string mapping", action: pilosa.InputMapping,value: "test", err: "Value test does not exist in definition map"}, {name: "int mapping", action: pilosa.InputMapping,value: 25, err: "Mapping value must be a string"}, - {name: "handle single-row-value", action: "test",value: true, err: "Unrecognized Value Destination"}, + {name: "invalid action", action: "test",value: true, err: "Unrecognized Value Destination"}, } for _, r := range tests { t.Run(r.name, func(t *testing.T) {