Skip to content

Commit

Permalink
Merge pull request #4434 from influxdb/upper_scientific
Browse files Browse the repository at this point in the history
Allow uppercase 'e' with scientific notation
  • Loading branch information
otoolep committed Oct 13, 2015
2 parents 87d99fb + ea3ecc7 commit ff9a307
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- [#4410](https://github.com/influxdb/influxdb/pull/4410): Fix infinite recursion in statement string(). Thanks @kostya-sh
- [#4360](https://github.com/influxdb/influxdb/issues/4360): Aggregate Selectors overwrite values during post-processing
- [#4421](https://github.com/influxdb/influxdb/issues/4421): Fix line protocol accepting tags with no values
- [#4434](https://github.com/influxdb/influxdb/pull/4434): Allow 'E' for scientific values. Fixes [#4433](https://github.com/influxdb/influxdb/issues/4433)

## v0.9.4 [2015-09-14]

Expand Down
4 changes: 2 additions & 2 deletions models/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,14 @@ func scanNumber(buf []byte, i int) (int, error) {
}

// `e` is valid for floats but not as the first char
if i > start && (buf[i] == 'e') {
if i > start && (buf[i] == 'e' || buf[i] == 'E') {
scientific = true
i += 1
continue
}

// + and - are only valid at this point if they follow an e (scientific notation)
if (buf[i] == '+' || buf[i] == '-') && buf[i-1] == 'e' {
if (buf[i] == '+' || buf[i] == '-') && (buf[i-1] == 'e' || buf[i-1] == 'E') {
i += 1
continue
}
Expand Down
18 changes: 15 additions & 3 deletions models/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func TestParsePointNoFields(t *testing.T) {
if err == nil {
t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu,,, value=1")
}

}

func TestParsePointNoTimestamp(t *testing.T) {
Expand Down Expand Up @@ -252,7 +251,6 @@ func TestParsePointMissingTagValue(t *testing.T) {
if err == nil {
t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=,zone=us-west value=1i`)
}

}

func TestParsePointMissingFieldName(t *testing.T) {
Expand All @@ -274,7 +272,6 @@ func TestParsePointMissingFieldName(t *testing.T) {
if err == nil {
t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=123i,=456i`)
}

}

func TestParsePointMissingFieldValue(t *testing.T) {
Expand Down Expand Up @@ -473,7 +470,22 @@ func TestParsePointFloatScientific(t *testing.T) {
if pts[0].Fields()["value"] != 1e4 {
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1e4`, err)
}
}

func TestParsePointFloatScientificUpper(t *testing.T) {
_, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=1.0E4`)
if err != nil {
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1.0E4`, err)
}

pts, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=1E4`)
if err != nil {
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1.0E4`, err)
}

if pts[0].Fields()["value"] != 1e4 {
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1E4`, err)
}
}

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

0 comments on commit ff9a307

Please sign in to comment.