Make sure the query string has valid regex and add a test
parent
d3b6c1b010
commit
cace54d8c8
|
@ -279,14 +279,11 @@ func (self *Coordinator) expandRegex(spec *parser.QuerySpec) {
|
|||
}
|
||||
|
||||
if f := q.FromClause; f.Type == parser.FromClauseMergeFun {
|
||||
series := self.clusterConfiguration.MetaStore.GetSeriesForDatabaseAndRegex(spec.Database(), q.FromClause.Regex)
|
||||
f.Type = parser.FromClauseMerge
|
||||
f.Regex = nil
|
||||
for _, s := range series {
|
||||
f.Names = append(f.Names, &parser.TableName{
|
||||
Name: &parser.Value{Name: s, Type: parser.ValueTableName},
|
||||
})
|
||||
f := func(r *regexp.Regexp) []string {
|
||||
return self.clusterConfiguration.MetaStore.GetSeriesForDatabaseAndRegex(spec.Database(), r)
|
||||
}
|
||||
|
||||
parser.RewriteMergeQuery(q, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,14 +48,14 @@ func (self *FromClause) GetString() string {
|
|||
buffer := bytes.NewBufferString("")
|
||||
switch self.Type {
|
||||
case FromClauseMerge:
|
||||
fmt.Fprintf(buffer, "merge(")
|
||||
fmt.Fprintf(buffer, "merge(/")
|
||||
for i, n := range self.Names {
|
||||
if i > 0 {
|
||||
buffer.WriteRune('|')
|
||||
}
|
||||
buffer.WriteString(n.Name.GetString())
|
||||
}
|
||||
buffer.WriteRune(')')
|
||||
buffer.WriteString("/)")
|
||||
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())
|
||||
|
|
|
@ -32,6 +32,25 @@ func (self *QueryParserSuite) TestInvalidFromClause(c *C) {
|
|||
c.Assert(err, ErrorMatches, ".*\\$undefined.*")
|
||||
}
|
||||
|
||||
func (self *QueryParserSuite) TestParseMergeGetString(c *C) {
|
||||
f := func(r *regexp.Regexp) []string {
|
||||
return []string{"foobar"}
|
||||
}
|
||||
|
||||
query := "select * from merge(/.*foo.*/)"
|
||||
qs, err := ParseQuery(query)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(qs, HasLen, 1)
|
||||
RewriteMergeQuery(qs[0].SelectQuery, f)
|
||||
fmt.Printf("Parsing %s\n", qs[0].GetQueryStringWithTimeCondition())
|
||||
actualQs, err := ParseQuery(qs[0].GetQueryStringWithTimeCondition())
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(actualQs, HasLen, 1)
|
||||
RewriteMergeQuery(actualQs[0].SelectQuery, f)
|
||||
actualQs[0].SelectQuery.startTimeSpecified = false
|
||||
c.Assert(actualQs[0].SelectQuery, DeepEquals, qs[0].SelectQuery)
|
||||
}
|
||||
|
||||
func (self *QueryParserSuite) TestInvalidExplainQueries(c *C) {
|
||||
query := "explain select foo, baz group by time(1d)"
|
||||
_, err := ParseQuery(query)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package parser
|
||||
|
||||
import "regexp"
|
||||
|
||||
type RegexMatcher func(r *regexp.Regexp) []string
|
||||
|
||||
func RewriteMergeQuery(query *SelectQuery, rm RegexMatcher) {
|
||||
if query.FromClause.Type != FromClauseMergeFun {
|
||||
return
|
||||
}
|
||||
|
||||
series := rm(query.FromClause.Regex)
|
||||
f := query.FromClause
|
||||
f.Type = FromClauseMerge
|
||||
f.Regex = nil
|
||||
for _, s := range series {
|
||||
f.Names = append(f.Names, &TableName{
|
||||
Name: &Value{Name: s, Type: ValueTableName},
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue