Skip to content

Commit

Permalink
Fix delete time fields creating unparseable points
Browse files Browse the repository at this point in the history
If a field was named time was written and was subsequently dropped,
it could leave a trailing comma in the series key causing it to fail
to be parseable in other parts of the code.
  • Loading branch information
jwilder committed Apr 4, 2017
1 parent df0ea87 commit ca55fff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion models/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,9 @@ func (p *point) Delete() {
switch {
case p.it.end == p.it.start:
case p.it.end >= len(p.fields):
p.fields = p.fields[:p.it.start]
// Remove the trailing comma if there are more than one fields
p.fields = bytes.TrimSuffix(p.fields[:p.it.start], []byte(","))

case p.it.start == 0:
p.fields = p.fields[p.it.end:]
default:
Expand Down
20 changes: 20 additions & 0 deletions models/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,10 @@ func TestPoint_FieldIterator_Delete_Begin(t *testing.T) {
if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", got, exp)
}

if _, err = models.ParsePointsString(points[0].String()); err != nil {
t.Fatalf("Failed to parse point: %v", err)
}
}

func TestPoint_FieldIterator_Delete_Middle(t *testing.T) {
Expand All @@ -2203,6 +2207,10 @@ func TestPoint_FieldIterator_Delete_Middle(t *testing.T) {
if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", got, exp)
}

if _, err = models.ParsePointsString(points[0].String()); err != nil {
t.Fatalf("Failed to parse point: %v", err)
}
}

func TestPoint_FieldIterator_Delete_End(t *testing.T) {
Expand All @@ -2225,6 +2233,10 @@ func TestPoint_FieldIterator_Delete_End(t *testing.T) {
if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", got, exp)
}

if _, err = models.ParsePointsString(points[0].String()); err != nil {
t.Fatalf("Failed to parse point: %v", err)
}
}

func TestPoint_FieldIterator_Delete_Nothing(t *testing.T) {
Expand All @@ -2244,6 +2256,10 @@ func TestPoint_FieldIterator_Delete_Nothing(t *testing.T) {
if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", got, exp)
}

if _, err = models.ParsePointsString(points[0].String()); err != nil {
t.Fatalf("Failed to parse point: %v", err)
}
}

func TestPoint_FieldIterator_Delete_Twice(t *testing.T) {
Expand All @@ -2266,6 +2282,10 @@ func TestPoint_FieldIterator_Delete_Twice(t *testing.T) {
if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", got, exp)
}

if _, err = models.ParsePointsString(points[0].String()); err != nil {
t.Fatalf("Failed to parse point: %v", err)
}
}

func TestEscapeStringField(t *testing.T) {
Expand Down

0 comments on commit ca55fff

Please sign in to comment.