Skip to content

Commit

Permalink
Fix dot replacement for int
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
  • Loading branch information
pavolloffay committed Jan 3, 2019
1 parent 5f6af99 commit 28a87c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin/storage/es/spanstore/dbmodel/to_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (td ToDomain) convertTagField(k string, v interface{}) (model.KeyValue, err
// The number is always a float64 therefore type assertion on int (v.(int/64/32)) does not work.
// If 1.0, 2.0.. was stored as float it will be read as int
if pInt, err := strconv.ParseInt(fmt.Sprintf("%v", v), 10, 64); err == nil {
return model.Int64(k, pInt), nil
return model.Int64(dKey, pInt), nil
}
switch val := v.(type) {
case float64:
Expand Down
4 changes: 4 additions & 0 deletions plugin/storage/es/spanstore/dbmodel/to_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,16 @@ func TestTagsMap(t *testing.T) {
}{
{fieldTags: map[string]interface{}{"bool:bool": true}, expected: []model.KeyValue{model.Bool("bool.bool", true)}},
{fieldTags: map[string]interface{}{"int.int": int64(1)}, expected: []model.KeyValue{model.Int64("int.int", 1)}},
{fieldTags: map[string]interface{}{"int:int": int64(2)}, expected: []model.KeyValue{model.Int64("int.int", 2)}},
{fieldTags: map[string]interface{}{"float": float64(1.1)}, expected: []model.KeyValue{model.Float64("float", 1.1)}},
// we are not able to reproduce type for float 123 or any N.0 number therefore returning int
{fieldTags: map[string]interface{}{"float": float64(123)}, expected: []model.KeyValue{model.Int64("float", 123)}},
{fieldTags: map[string]interface{}{"float": float64(123.0)}, expected: []model.KeyValue{model.Int64("float", 123)}},
{fieldTags: map[string]interface{}{"float:float": float64(123)}, expected: []model.KeyValue{model.Int64("float.float", 123)}},
{fieldTags: map[string]interface{}{"str": "foo"}, expected: []model.KeyValue{model.String("str", "foo")}},
{fieldTags: map[string]interface{}{"str:str": "foo"}, expected: []model.KeyValue{model.String("str.str", "foo")}},
{fieldTags: map[string]interface{}{"binary": []byte("foo")}, expected: []model.KeyValue{model.Binary("binary", []byte("foo"))}},
{fieldTags: map[string]interface{}{"binary:binary": []byte("foo")}, expected: []model.KeyValue{model.Binary("binary.binary", []byte("foo"))}},
{fieldTags: map[string]interface{}{"unsupported": struct{}{}}, err: fmt.Errorf("invalid tag type in %+v", struct{}{})},
}
converter := NewToDomain(":")
Expand Down

0 comments on commit 28a87c0

Please sign in to comment.