Merge pull request #240 from influxdb/fix-240-column-names-with-dots

Unable to query against columns with dots in their names
pull/251/head
Paul Dix 2014-02-10 14:20:02 -05:00
commit 2c8ee2eaf8
3 changed files with 71 additions and 0 deletions

View File

@ -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(`
[

View File

@ -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)

View File

@ -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
}