Skip to content

Commit

Permalink
FromClause.GetString() shouldn't assume 2 series in the merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Oct 22, 2014
1 parent baabefd commit d3b6c1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions integration/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,28 @@ func (self *DataTestSuite) TestModeWithNils(c *C) {
c.Assert(maps[0]["m2"], Equals, nil)
}

func (self *DataTestSuite) TestMergeRegexOneSeries(c *C) {
data := `
[
{
"name": "test_merge_1",
"columns": ["time", "value"],
"points": [
[1401321700000, "m11"],
[1401321600000, "m12"]
]
}
]`

self.client.WriteJsonData(data, c, influxdb.Millisecond)
serieses := self.client.RunQuery("select * from merge(/.*/)", c, "m")
c.Assert(serieses, HasLen, 1)
maps := ToMap(serieses[0])
c.Assert(maps, HasLen, 2)
c.Assert(maps[0]["value"], Equals, "m11")
c.Assert(maps[1]["value"], Equals, "m12")
}

func (self *DataTestSuite) TestMergeRegex(c *C) {
data := `
[
Expand Down
10 changes: 8 additions & 2 deletions parser/from_clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ func (self *FromClause) GetString() string {
buffer := bytes.NewBufferString("")
switch self.Type {
case FromClauseMerge:
fmt.Fprintf(buffer, "%s%s merge %s %s", self.Names[0].Name.GetString(), self.Names[1].GetAliasString(),
self.Names[1].Name.GetString(), self.Names[1].GetAliasString())
fmt.Fprintf(buffer, "merge(")
for i, n := range self.Names {
if i > 0 {
buffer.WriteRune('|')
}
buffer.WriteString(n.Name.GetString())
}
buffer.WriteRune(')')
case FromClauseInnerJoin:
fmt.Fprintf(buffer, "%s%s inner join %s%s", self.Names[0].Name.GetString(), self.Names[0].GetAliasString(),
self.Names[1].Name.GetString(), self.Names[1].GetAliasString())
Expand Down

0 comments on commit d3b6c1b

Please sign in to comment.