Skip to content

Commit

Permalink
Return the merged data using the alias
Browse files Browse the repository at this point in the history
Since we return an error if the same series has more than one alias this
fixes #270
  • Loading branch information
jvshahid committed Oct 10, 2014
1 parent 2a1774d commit 9575037
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
6 changes: 5 additions & 1 deletion datastore/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ func (self *Shard) executeMergeQuery(querySpec *parser.QuerySpec, processor engi
log.Error(err)
return err
}
aliases := querySpec.SelectQuery().GetTableAliases(s.Name)
if len(aliases) > 1 {
return fmt.Errorf("Cannot have the same table joined more than once")
}
streams[i] = PointIteratorStream{
pi: iterators[i],
name: s.Name,
name: aliases[0],
fields: c,
}
i++
Expand Down
18 changes: 18 additions & 0 deletions integration/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,24 @@ func (self *DataTestSuite) TestWhereConditionWithExpression(c *C) {
c.Assert(maps[0]["b"], Equals, 1.0)
}

func (self *DataTestSuite) JoinedWithSelf(c *C) (Fun, Fun) {
return func(client Client) {
client.WriteJsonData(`
[
{
"name": "t",
"columns": ["time", "value"],
"points":[
[1381346706000, 3],
[1381346701000, 1]
]
}
]`, c, influxdb.Millisecond)
}, func(client Client) {
client.RunInvalidQuery("select * from t as foo inner join t as bar", c, "m")
}
}

// issue #740 and #781
func (self *DataTestSuite) TestJoiningDifferentFields(c *C) {
// TODO: why do we get a different error if we remove all but the first values
Expand Down
26 changes: 0 additions & 26 deletions integration/legacy_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1649,32 +1649,6 @@ func (self *DataTestSuite) QueryWithJoinedTablesWithWhereClause(c *C) (Fun, Fun)
}
}

func (self *DataTestSuite) JoinedWithSelf(c *C) (Fun, Fun) {
return func(client Client) {
createEngine(client, c, `[
{
"points": [
{ "values": [{ "int64_value": 3 }], "timestamp": 1381346706000000 },
{ "values": [{ "int64_value": 1 }], "timestamp": 1381346701000000 }
],
"name": "t",
"fields": ["value"]
}
]`)
}, func(client Client) {
runQuery(client, "select * from t as foo inner join t as bar", c, `[
{
"points": [
{ "values": [{ "int64_value": 3 }, { "int64_value": 3 }], "timestamp": 1381346706000000 },
{ "values": [{ "int64_value": 1 }, { "int64_value": 1 }], "timestamp": 1381346701000000 }
],
"name": "foo_join_bar",
"fields": ["foo.value", "bar.value"]
}
]`)
}
}

func (self *DataTestSuite) QueryWithMergedTablesWithPointsAppend(c *C) (Fun, Fun) {
return func(client Client) {
createEngine(client, c, `[
Expand Down

0 comments on commit 9575037

Please sign in to comment.