Merge pull request #1700 from influxdb/vlaues_to_fields

Rename "Values" to "Fields" for writes
pull/1689/head
Philip O'Toole 2015-02-23 15:14:14 -08:00
commit fa1f6d1d70
11 changed files with 115 additions and 115 deletions

View File

@ -258,12 +258,12 @@ func (t Timestamp) MarshalJSON() ([]byte, error) {
return []byte(`"` + s + `"`), nil
}
// Point defines the values that will be written to the database
// Point defines the fields that will be written to the database
type Point struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
Timestamp Timestamp `json:"timestamp"`
Values map[string]interface{} `json:"values"`
Fields map[string]interface{} `json:"fields"`
Precision string `json:"precision"`
}
@ -274,14 +274,14 @@ func (p *Point) UnmarshalJSON(b []byte) error {
Tags map[string]string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
Precision string `json:"precision"`
Values map[string]interface{} `json:"values"`
Fields map[string]interface{} `json:"fields"`
}
var epoch struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
Timestamp *int64 `json:"timestamp"`
Precision string `json:"precision"`
Values map[string]interface{} `json:"values"`
Fields map[string]interface{} `json:"fields"`
}
if err := func() error {
@ -304,7 +304,7 @@ func (p *Point) UnmarshalJSON(b []byte) error {
p.Tags = epoch.Tags
p.Timestamp = Timestamp(ts)
p.Precision = epoch.Precision
p.Values = normalizeValues(epoch.Values)
p.Fields = normalizeFields(epoch.Fields)
return nil
}(); err == nil {
return nil
@ -320,28 +320,28 @@ func (p *Point) UnmarshalJSON(b []byte) error {
p.Tags = normal.Tags
p.Timestamp = Timestamp(normal.Timestamp)
p.Precision = normal.Precision
p.Values = normalizeValues(normal.Values)
p.Fields = normalizeFields(normal.Fields)
return nil
}
// Remove any notion of json.Number
func normalizeValues(values map[string]interface{}) map[string]interface{} {
newValues := map[string]interface{}{}
func normalizeFields(fields map[string]interface{}) map[string]interface{} {
newFields := map[string]interface{}{}
for k, v := range values {
for k, v := range fields {
switch v := v.(type) {
case json.Number:
jv, e := v.Float64()
if e != nil {
panic(fmt.Sprintf("unable to convert json.Number to float64: %s", e))
}
newValues[k] = jv
newFields[k] = jv
default:
newValues[k] = v
newFields[k] = v
}
}
return newValues
return newFields
}
// utility functions

View File

@ -56,7 +56,7 @@ func createBatch(nPoints int, database, retention, measurement string, tags map[
Tags map[string]string `json:"tags"`
Timestamp int64 `json:"timestamp"`
Precision string `json:"precision"`
Values map[string]int `json:"values"`
Fields map[string]int `json:"fields"`
}
type PointBatch struct {
Database string `json:"database"`
@ -67,8 +67,8 @@ func createBatch(nPoints int, database, retention, measurement string, tags map[
rand.Seed(time.Now().UTC().UnixNano())
points := make([]Point, 0)
for i := 0; i < nPoints; i++ {
values := map[string]int{"value": rand.Int()}
point := Point{Name: measurement, Tags: tags, Timestamp: time.Now().UTC().UnixNano(), Precision: "n", Values: values}
fields := map[string]int{"value": rand.Int()}
point := Point{Name: measurement, Tags: tags, Timestamp: time.Now().UTC().UnixNano(), Precision: "n", Fields: fields}
points = append(points, point)
}
batch := PointBatch{Database: database, RetentionPolicy: retention, Points: points}
@ -425,7 +425,7 @@ func Test_ServerSingleIntegration(t *testing.T) {
},
"timestamp": %d,
"precision": "n",
"values":{
"fields":{
"value": 100
}
}]
@ -470,7 +470,7 @@ func Test_Server3NodeIntegration(t *testing.T) {
},
"timestamp": %d,
"precision": "n",
"values":{
"fields":{
"value": 100
}
}]
@ -516,7 +516,7 @@ func Test_Server5NodeIntegration(t *testing.T) {
},
"timestamp": %d,
"precision": "n",
"values":{
"fields":{
"value": 100
}
}]

View File

@ -158,9 +158,9 @@ func Unmarshal(data *gollectd.Packet) []influxdb.Point {
for i := range data.Values {
name := fmt.Sprintf("%s_%s", data.Plugin, data.Values[i].Name)
tags := make(map[string]string)
values := make(map[string]interface{})
fields := make(map[string]interface{})
values[name] = data.Values[i].Value
fields[name] = data.Values[i].Value
if data.Hostname != "" {
tags["host"] = data.Hostname
@ -178,7 +178,7 @@ func Unmarshal(data *gollectd.Packet) []influxdb.Point {
Name: name,
Tags: tags,
Timestamp: timestamp,
Values: values,
Fields: fields,
}
points = append(points, p)

View File

@ -211,7 +211,7 @@ func TestUnmarshal_Points(t *testing.T) {
{
name: "single value",
points: []influxdb.Point{
{Name: "disk_read", Values: map[string]interface{}{"disk_read": float64(1)}},
{Name: "disk_read", Fields: map[string]interface{}{"disk_read": float64(1)}},
},
packet: gollectd.Packet{
Plugin: "disk",
@ -223,8 +223,8 @@ func TestUnmarshal_Points(t *testing.T) {
{
name: "multi value",
points: []influxdb.Point{
{Name: "disk_read", Values: map[string]interface{}{"disk_read": float64(1)}},
{Name: "disk_write", Values: map[string]interface{}{"disk_write": float64(5)}},
{Name: "disk_read", Fields: map[string]interface{}{"disk_read": float64(1)}},
{Name: "disk_write", Fields: map[string]interface{}{"disk_write": float64(5)}},
},
packet: gollectd.Packet{
Plugin: "disk",
@ -240,7 +240,7 @@ func TestUnmarshal_Points(t *testing.T) {
{
Name: "disk_read",
Tags: map[string]string{"host": "server01", "instance": "sdk", "type": "disk_octets", "type_instance": "single"},
Values: map[string]interface{}{"disk_read": float64(1)},
Fields: map[string]interface{}{"disk_read": float64(1)},
},
},
packet: gollectd.Packet{
@ -269,7 +269,7 @@ func TestUnmarshal_Points(t *testing.T) {
t.Errorf("point name mismatch. expected %q, got %q", name, m.Name)
}
// test value
mv := m.Values[m.Name].(float64)
mv := m.Fields[m.Name].(float64)
pv := test.packet.Values[i].Value
if mv != pv {
t.Errorf("point value mismatch. expected %v, got %v", pv, mv)

View File

@ -69,12 +69,12 @@ func (p *Parser) Parse(line string) (influxdb.Point, error) {
return influxdb.Point{}, err
}
values := make(map[string]interface{})
fieldValues := make(map[string]interface{})
// Determine if value is a float or an int.
if i := int64(v); float64(i) == v {
values[name] = int64(v)
fieldValues[name] = int64(v)
} else {
values[name] = v
fieldValues[name] = v
}
// Parse timestamp.
@ -88,7 +88,7 @@ func (p *Parser) Parse(line string) (influxdb.Point, error) {
point := influxdb.Point{
Name: name,
Tags: tags,
Values: values,
Fields: fieldValues,
Timestamp: timestamp,
}

View File

@ -225,13 +225,13 @@ func Test_DecodeMetric(t *testing.T) {
t.Fatalf("tags len mismatch. expected %d, got %d", len(test.tags), len(point.Tags))
}
if test.isInt {
i := point.Values[point.Name].(int64)
i := point.Fields[point.Name].(int64)
if i != test.iv {
t.Fatalf("integerValue value mismatch. expected %v, got %v", test.iv, point.Values[point.Name])
t.Fatalf("integerValue value mismatch. expected %v, got %v", test.iv, point.Fields[point.Name])
}
} else {
f := point.Values[point.Name].(float64)
if point.Values[point.Name] != f {
f := point.Fields[point.Name].(float64)
if point.Fields[point.Name] != f {
t.Fatalf("floatValue value mismatch. expected %v, got %v", test.fv, f)
}
}

View File

@ -579,7 +579,7 @@ func TestHandler_WaitIncrement(t *testing.T) {
status, _ := MustHTTP("GET", s.URL+`/wait/2`, map[string]string{"timeout": "200"}, nil, "")
// Write some data
_, _ = MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}]}`)
_, _ = MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status, expected: %d, actual: %d", http.StatusOK, status)
@ -1163,7 +1163,7 @@ func TestHandler_DropSeries(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
@ -1184,7 +1184,7 @@ func TestHandler_serveWriteSeries(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
@ -1198,7 +1198,7 @@ func TestHandler_serveWriteSeriesWithAuthNilUser(t *testing.T) {
s := NewAuthenticatedHTTPServer(srvr)
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}]}`)
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)
if status != http.StatusUnauthorized {
t.Fatalf("unexpected status: %d", status)
@ -1215,7 +1215,7 @@ func TestHandler_serveWriteSeries_noDatabaseExists(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}]}`)
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)
expectedStatus := http.StatusNotFound
if status != expectedStatus {
@ -1233,7 +1233,7 @@ func TestHandler_serveWriteSeries_invalidJSON(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}]}`)
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}]}`)
if status != http.StatusInternalServerError {
t.Fatalf("unexpected status: expected: %d, actual: %d", http.StatusInternalServerError, status)
@ -1271,7 +1271,7 @@ func TestHandler_serveWriteSeriesNonZeroTime(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z", "values": {"value": 100}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z", "fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
}
@ -1314,7 +1314,7 @@ func TestHandler_serveWriteSeriesZeroTime(t *testing.T) {
now := time.Now()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"values": {"value": 100}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
@ -1365,7 +1365,7 @@ func TestHandler_serveWriteSeriesStringValues(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "logs", "tags": {"host": "server01"},"values": {"event": "disk full"}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "logs", "tags": {"host": "server01"},"fields": {"event": "disk full"}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
}
@ -1408,7 +1408,7 @@ func TestHandler_serveWriteSeriesBoolValues(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "disk", "tags": {"host": "server01"},"values": {"full": false}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "disk", "tags": {"host": "server01"},"fields": {"full": false}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
}
@ -1462,7 +1462,7 @@ func TestHandler_serveWriteSeriesBatch(t *testing.T) {
"tags": {
"host": "server01"
},
"values": {
"fields": {
"full": false
}
},
@ -1472,7 +1472,7 @@ func TestHandler_serveWriteSeriesBatch(t *testing.T) {
"tags": {
"host": "server01"
},
"values": {
"fields": {
"full": true
}
},
@ -1482,7 +1482,7 @@ func TestHandler_serveWriteSeriesBatch(t *testing.T) {
"tags": {
"host": "server02"
},
"values": {
"fields": {
"full_pct": 64
}
}
@ -1534,7 +1534,7 @@ func TestHandler_serveWriteSeriesInvalidQueryField(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"values": {"value": 100}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
}
@ -1575,12 +1575,12 @@ func TestHandler_serveWriteSeriesFieldTypeConflict(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"values": {"value": 100}}]}`)
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"fields": {"value": 100}}]}`)
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
}
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"values": {"value": "foo"}}]}`)
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"fields": {"value": "foo"}}]}`)
if status != http.StatusInternalServerError {
t.Errorf("unexpected status: %d", status)
}
@ -1607,12 +1607,12 @@ func TestHandler_serveShowSeries(t *testing.T) {
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}
]}`)
if status != http.StatusOK {
@ -1827,13 +1827,13 @@ func TestHandler_serveShowMeasurements(t *testing.T) {
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "other", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "other", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}
]}`)
if status != http.StatusOK {
@ -1897,12 +1897,12 @@ func TestHandler_serveShowTagKeys(t *testing.T) {
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}
]}`)
if status != http.StatusOK {
@ -2009,12 +2009,12 @@ func TestHandler_serveShowTagValues(t *testing.T) {
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","values": {"value": 100}}
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}
]}`)
if status != http.StatusOK {
@ -2191,12 +2191,12 @@ func TestHandler_serveShowFieldKeys(t *testing.T) {
defer s.Close()
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","values": {"field1": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","values": {"field1": 200, "field2": 300, "field3": 400}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"field1": 200, "field2": 300, "field3": 400}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"field1": 200, "field2": 300, "field3": 400}},
{"name": "gpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","values": {"field4": 200, "field5": 300}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","values": {"field6": 200, "field7": 300}}
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"field1": 100}},
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"field1": 200, "field2": 300, "field3": 400}},
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"field1": 200, "field2": 300, "field3": 400}},
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"field1": 200, "field2": 300, "field3": 400}},
{"name": "gpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"field4": 200, "field5": 300}},
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"field6": 200, "field7": 300}}
]}`)
if status != http.StatusOK {

View File

@ -100,8 +100,8 @@ var (
// ErrMeasurementNotFound is returned when a measurement does not exist.
ErrMeasurementNotFound = errors.New("measurement not found")
// ErrValuesRequired is returned when a point does not any values
ErrValuesRequired = errors.New("values required")
// ErrFieldsRequired is returned when a point does not any fields.
ErrFieldsRequired = errors.New("fields required")
// ErrFieldOverflow is returned when too many fields are created on a measurement.
ErrFieldOverflow = errors.New("field overflow")
@ -229,7 +229,7 @@ func NormalizeBatchPoints(bp BatchPoints) ([]Point, error) {
Name: p.Name,
Tags: p.Tags,
Timestamp: p.Timestamp.Time(),
Values: p.Values,
Fields: p.Fields,
})
}

View File

@ -1363,7 +1363,7 @@ type Point struct {
Name string
Tags map[string]string
Timestamp time.Time
Values map[string]interface{}
Fields map[string]interface{}
}
// WriteSeries writes series data to the database.
@ -1426,7 +1426,7 @@ func (s *Server) WriteSeries(database, retentionPolicy string, points []Point) (
}
// Convert string-key/values to encoded fields.
encodedFields, err := codec.EncodeFields(p.Values)
encodedFields, err := codec.EncodeFields(p.Fields)
if err != nil {
return err
}
@ -1505,7 +1505,7 @@ func (s *Server) createMeasurementsIfNotExists(database, retentionPolicy string,
c.addSeriesIfNotExists(p.Name, p.Tags)
}
for k, v := range p.Values {
for k, v := range p.Fields {
if measurement != nil {
if f := measurement.FieldByName(k); f != nil {
// Field present in Metastore, make sure there is no type conflict.
@ -1669,14 +1669,14 @@ func (s *Server) ReadSeries(database, retentionPolicy, name string, tags map[str
// Decode into a raw value map.
codec := NewFieldCodec(mm)
rawValues := codec.DecodeFields(data)
if rawValues == nil {
rawFields := codec.DecodeFields(data)
if rawFields == nil {
return nil, nil
}
// Decode into a string-key value map.
values := make(map[string]interface{}, len(rawValues))
for fieldID, value := range rawValues {
values := make(map[string]interface{}, len(rawFields))
for fieldID, value := range rawFields {
f := mm.Field(fieldID)
if f == nil {
continue
@ -3102,7 +3102,7 @@ func (s *Server) convertRowToPoints(measurementName string, row *influxql.Row) (
Name: measurementName,
Tags: row.Tags,
Timestamp: v[timeIndex].(time.Time),
Values: vals,
Fields: vals,
}
points = append(points, *p)

View File

@ -788,7 +788,7 @@ func TestServer_WriteSeries(t *testing.T) {
// Write series with one point to the database.
tags := map[string]string{"host": "servera.influx.com", "region": "uswest"}
index, err := s.WriteSeries("foo", "mypolicy", []influxdb.Point{{Name: "cpu_load", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(23.2)}}})
index, err := s.WriteSeries("foo", "mypolicy", []influxdb.Point{{Name: "cpu_load", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(23.2)}}})
if err != nil {
t.Fatal(err)
} else if err = s.Sync(index); err != nil {
@ -796,7 +796,7 @@ func TestServer_WriteSeries(t *testing.T) {
}
// Write another point 10 seconds later so it goes through "raw series".
index, err = s.WriteSeries("foo", "mypolicy", []influxdb.Point{{Name: "cpu_load", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Values: map[string]interface{}{"value": float64(100)}}})
index, err = s.WriteSeries("foo", "mypolicy", []influxdb.Point{{Name: "cpu_load", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Fields: map[string]interface{}{"value": float64(100)}}})
if err != nil {
t.Fatal(err)
} else if err = s.Sync(index); err != nil {
@ -842,7 +842,7 @@ func TestServer_DropSeries(t *testing.T) {
// Write series with one point to the database.
tags := map[string]string{"host": "serverA", "region": "uswest"}
index, err := s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(23.2)}}})
index, err := s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(23.2)}}})
if err != nil {
t.Fatal(err)
} else if err = s.Sync(index); err != nil {
@ -893,7 +893,7 @@ func TestServer_DropSeriesTagsPreserved(t *testing.T) {
// Write series with one point to the database.
tags := map[string]string{"host": "serverA", "region": "uswest"}
index, err := s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(23.2)}}})
index, err := s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(23.2)}}})
if err != nil {
t.Fatal(err)
} else if err = s.Sync(index); err != nil {
@ -901,7 +901,7 @@ func TestServer_DropSeriesTagsPreserved(t *testing.T) {
}
tags = map[string]string{"host": "serverB", "region": "uswest"}
index, err = s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:01Z"), Values: map[string]interface{}{"value": float64(33.2)}}})
index, err = s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:01Z"), Fields: map[string]interface{}{"value": float64(33.2)}}})
if err != nil {
t.Fatal(err)
} else if err = s.Sync(index); err != nil {
@ -967,9 +967,9 @@ func TestServer_ExecuteQuery(t *testing.T) {
s.CreateUser("susy", "pass", false)
// Write series with one point to the database.
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(20)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Values: map[string]interface{}{"value": float64(30)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(100)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(20)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Fields: map[string]interface{}{"value": float64(30)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(100)}}})
// Select data from the server.
results := s.ExecuteQuery(MustParseQuery(`SELECT sum(value) FROM cpu GROUP BY time(10s), region`), "foo", nil)
@ -998,7 +998,7 @@ func TestServer_ExecuteQuery(t *testing.T) {
}
// Aggregation with a null field value
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:03Z"), Values: map[string]interface{}{"otherVal": float64(20)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:03Z"), Fields: map[string]interface{}{"otherVal": float64(20)}}})
// Sum aggregation.
results = s.ExecuteQuery(MustParseQuery(`SELECT sum(value) FROM cpu GROUP BY region`), "foo", nil)
if res := results.Results[0]; res.Err != nil {
@ -1019,9 +1019,9 @@ func TestServer_ExecuteWildcardQuery(t *testing.T) {
// Write series with one point to the database.
// We deliberatly write one value per insert as we need to create each field in a predicatable order for testing.
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(10)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Values: map[string]interface{}{"val-x": 20}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:20Z"), Values: map[string]interface{}{"value": 30, "val-x": 40}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(10)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Fields: map[string]interface{}{"val-x": 20}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: mustParseTime("2000-01-01T00:00:20Z"), Fields: map[string]interface{}{"value": 30, "val-x": 40}}})
// Select * (wildcard).
results := s.ExecuteQuery(MustParseQuery(`SELECT * FROM cpu`), "foo", nil)
@ -1104,7 +1104,7 @@ func TestServer_Measurements(t *testing.T) {
tags := map[string]string{"host": "servera.influx.com", "region": "uswest"}
values := map[string]interface{}{"value": 23.2}
index, err := s.WriteSeries("foo", "mypolicy", []influxdb.Point{influxdb.Point{Name: "cpu_load", Tags: tags, Timestamp: timestamp, Values: values}})
index, err := s.WriteSeries("foo", "mypolicy", []influxdb.Point{influxdb.Point{Name: "cpu_load", Tags: tags, Timestamp: timestamp, Fields: values}})
if err != nil {
t.Fatal(err)
} else if err = s.Sync(index); err != nil {
@ -1326,9 +1326,9 @@ func TestServer_RunContinuousQueries(t *testing.T) {
}
testTime.Add(time.Millisecond * 2)
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: testTime, Values: map[string]interface{}{"value": float64(30)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: testTime.Add(-time.Millisecond * 5), Values: map[string]interface{}{"value": float64(20)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west"}, Timestamp: testTime, Values: map[string]interface{}{"value": float64(100)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: testTime, Fields: map[string]interface{}{"value": float64(30)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east"}, Timestamp: testTime.Add(-time.Millisecond * 5), Fields: map[string]interface{}{"value": float64(20)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west"}, Timestamp: testTime, Fields: map[string]interface{}{"value": float64(100)}}})
// Run CQs after a period of time
time.Sleep(time.Millisecond * 50)
@ -1356,7 +1356,7 @@ func TestServer_RunContinuousQueries(t *testing.T) {
// ensure that data written into a previous window is picked up and the result recomputed.
time.Sleep(time.Millisecond * 2)
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west"}, Timestamp: testTime.Add(-time.Millisecond), Values: map[string]interface{}{"value": float64(50)}}})
s.MustWriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west"}, Timestamp: testTime.Add(-time.Millisecond), Fields: map[string]interface{}{"value": float64(50)}}})
s.RunContinuousQueries()
// give CQs time to run
time.Sleep(time.Millisecond * 50)

View File

@ -16,14 +16,14 @@ func TestTx_CreateIterators(t *testing.T) {
defer s.Close()
// Write to us-east
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverA", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(100)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverB", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Values: map[string]interface{}{"value": float64(90)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverC"}, Timestamp: mustParseTime("2000-01-01T00:00:20Z"), Values: map[string]interface{}{"value": float64(80)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverA", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:30Z"), Values: map[string]interface{}{"value": float64(70)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverA", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(100)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverB", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:10Z"), Fields: map[string]interface{}{"value": float64(90)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverC"}, Timestamp: mustParseTime("2000-01-01T00:00:20Z"), Fields: map[string]interface{}{"value": float64(80)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-east", "host": "serverA", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:30Z"), Fields: map[string]interface{}{"value": float64(70)}}})
// Write to us-west
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west", "host": "serverD"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(1)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west", "host": "serverE", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Values: map[string]interface{}{"value": float64(2)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west", "host": "serverD"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(1)}}})
s.MustWriteSeries("db", "raw", []influxdb.Point{{Name: "cpu", Tags: map[string]string{"region": "us-west", "host": "serverE", "service": "redis"}, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(2)}}})
// Create a statement to iterate over.
// stmt := MustParseSelectStatement(`