Fix delete time fields creating unparseable points

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.
pull/8254/head
Jason Wilder 2017-04-04 15:16:13 -06:00
parent 014c8a6c27
commit 1a4b1b3109
2 changed files with 23 additions and 1 deletions

View File

@ -1936,7 +1936,9 @@ func (p *point) Delete() {
switch { switch {
case p.it.end == p.it.start: case p.it.end == p.it.start:
case p.it.end >= len(p.fields): 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: case p.it.start == 0:
p.fields = p.fields[p.it.end:] p.fields = p.fields[p.it.end:]
default: default:

View File

@ -2182,6 +2182,10 @@ func TestPoint_FieldIterator_Delete_Begin(t *testing.T) {
if !reflect.DeepEqual(got, exp) { if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", 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) { func TestPoint_FieldIterator_Delete_Middle(t *testing.T) {
@ -2203,6 +2207,10 @@ func TestPoint_FieldIterator_Delete_Middle(t *testing.T) {
if !reflect.DeepEqual(got, exp) { if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", 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) { func TestPoint_FieldIterator_Delete_End(t *testing.T) {
@ -2225,6 +2233,10 @@ func TestPoint_FieldIterator_Delete_End(t *testing.T) {
if !reflect.DeepEqual(got, exp) { if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", 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) { func TestPoint_FieldIterator_Delete_Nothing(t *testing.T) {
@ -2244,6 +2256,10 @@ func TestPoint_FieldIterator_Delete_Nothing(t *testing.T) {
if !reflect.DeepEqual(got, exp) { if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", 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) { func TestPoint_FieldIterator_Delete_Twice(t *testing.T) {
@ -2266,6 +2282,10 @@ func TestPoint_FieldIterator_Delete_Twice(t *testing.T) {
if !reflect.DeepEqual(got, exp) { if !reflect.DeepEqual(got, exp) {
t.Fatalf("Delete failed, got %#v, exp %#v", 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) { func TestEscapeStringField(t *testing.T) {