diff --git a/src/integration/benchmark_test.go b/src/integration/benchmark_test.go index 486fdae346..cc8ddff22b 100644 --- a/src/integration/benchmark_test.go +++ b/src/integration/benchmark_test.go @@ -1004,6 +1004,41 @@ func (self *IntegrationSuite) TestReading(c *C) { } } +func (self *IntegrationSuite) TestReadingWhenColumnHasDot(c *C) { + err := self.server.WriteData(` +[ + { + "name": "test_column_names_with_dots", + "columns": ["first.name", "last.name"], + "points": [["paul", "dix"], ["john", "shahid"]] + } +]`) + c.Assert(err, IsNil) + + for name, expected := range map[string]map[string]bool{ + "first.name": map[string]bool{"paul": true, "john": true}, + "last.name": map[string]bool{"dix": true, "shahid": true}, + } { + q := fmt.Sprintf("select %s from test_column_names_with_dots", name) + + bs, err := self.server.RunQuery(q, "m") + c.Assert(err, IsNil) + + data := []*h.SerializedSeries{} + err = json.Unmarshal(bs, &data) + c.Assert(err, IsNil) + + c.Assert(data, HasLen, 1) + c.Assert(data[0].Columns, HasLen, 3) // time, sequence number and the requested columns + c.Assert(data[0].Columns[2], Equals, name) + names := map[string]bool{} + for _, p := range data[0].Points { + names[p[2].(string)] = true + } + c.Assert(names, DeepEquals, expected) + } +} + func (self *IntegrationSuite) TestSinglePointSelect(c *C) { err := self.server.WriteData(` [ diff --git a/src/parser/parser_test.go b/src/parser/parser_test.go index 3d8decaf21..571940d581 100644 --- a/src/parser/parser_test.go +++ b/src/parser/parser_test.go @@ -73,6 +73,24 @@ func (self *QueryParserSuite) TestParseDeleteQueryWithEndTime(c *C) { c.Assert(q.GetEndTime(), Equals, time.Unix(1389040522, 0).UTC()) } +func (self *QueryParserSuite) TestParseSelectQueryWithDotInColumnName(c *C) { + query := "select patient.first.name from foo" + queries, err := ParseQuery(query) + c.Assert(err, IsNil) + + c.Assert(queries, HasLen, 1) + + _q := queries[0] + + c.Assert(_q.SelectQuery, NotNil) + + q := _q.SelectQuery + + for _, columns := range q.GetReferencedColumns() { + c.Assert(columns, DeepEquals, []string{"patient.first.name"}) + } +} + func (self *QueryParserSuite) TestParseDropSeries(c *C) { query := "drop series foobar" queries, err := ParseQuery(query) diff --git a/src/parser/query_api.go b/src/parser/query_api.go index 3636ac5638..f9f331747d 100644 --- a/src/parser/query_api.go +++ b/src/parser/query_api.go @@ -158,6 +158,24 @@ func (self *SelectQuery) GetReferencedColumns() map[*Value][]string { delete(mapping, name) } + if len(mapping) == 0 { + return returnedMapping + } + + // if `mapping` still have some mappings, then we have mistaken a + // column name with dots with a prefix.column, see issue #240 + for prefix, columnNames := range mapping { + for _, columnName := range columnNames { + for table, columns := range returnedMapping { + if len(returnedMapping[table]) > 1 && returnedMapping[table][0] == "*" { + continue + } + returnedMapping[table] = append(columns, prefix+"."+columnName) + } + } + delete(mapping, prefix) + } + return returnedMapping }