move RewriteStatement and neldermead to influxdb/query package

pull/9038/head
Stuart Carnie 2017-10-30 10:24:15 -07:00
parent f2015afc0b
commit 7435725e05
7 changed files with 145 additions and 141 deletions

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/influxdata/influxdb/influxql" "github.com/influxdata/influxdb/influxql"
"github.com/influxdata/influxdb/influxql/neldermead" "github.com/influxdata/influxdb/query/neldermead"
) )
// FloatMeanReducer calculates the mean of the aggregated points. // FloatMeanReducer calculates the mean of the aggregated points.

View File

@ -4,7 +4,7 @@ import (
"math" "math"
"testing" "testing"
"github.com/influxdata/influxdb/influxql/neldermead" "github.com/influxdata/influxdb/query/neldermead"
) )
func round(num float64, precision float64) float64 { func round(num float64, precision float64) float64 {

View File

@ -355,7 +355,7 @@ LOOP:
// Rewrite statements, if necessary. // Rewrite statements, if necessary.
// This can occur on meta read statements which convert to SELECT statements. // This can occur on meta read statements which convert to SELECT statements.
newStmt, err := influxql.RewriteStatement(stmt) newStmt, err := RewriteStatement(stmt)
if err != nil { if err != nil {
results <- &Result{Err: err} results <- &Result{Err: err}
break break

View File

@ -1,43 +1,45 @@
package influxql package query
import ( import (
"errors" "errors"
"regexp" "regexp"
"github.com/influxdata/influxdb/influxql"
) )
// RewriteStatement rewrites stmt into a new statement, if applicable. // RewriteStatement rewrites stmt into a new statement, if applicable.
func RewriteStatement(stmt Statement) (Statement, error) { func RewriteStatement(stmt influxql.Statement) (influxql.Statement, error) {
switch stmt := stmt.(type) { switch stmt := stmt.(type) {
case *ShowFieldKeysStatement: case *influxql.ShowFieldKeysStatement:
return rewriteShowFieldKeysStatement(stmt) return rewriteShowFieldKeysStatement(stmt)
case *ShowFieldKeyCardinalityStatement: case *influxql.ShowFieldKeyCardinalityStatement:
return rewriteShowFieldKeyCardinalityStatement(stmt) return rewriteShowFieldKeyCardinalityStatement(stmt)
case *ShowMeasurementsStatement: case *influxql.ShowMeasurementsStatement:
return rewriteShowMeasurementsStatement(stmt) return rewriteShowMeasurementsStatement(stmt)
case *ShowMeasurementCardinalityStatement: case *influxql.ShowMeasurementCardinalityStatement:
return rewriteShowMeasurementCardinalityStatement(stmt) return rewriteShowMeasurementCardinalityStatement(stmt)
case *ShowSeriesStatement: case *influxql.ShowSeriesStatement:
return rewriteShowSeriesStatement(stmt) return rewriteShowSeriesStatement(stmt)
case *ShowSeriesCardinalityStatement: case *influxql.ShowSeriesCardinalityStatement:
return rewriteShowSeriesCardinalityStatement(stmt) return rewriteShowSeriesCardinalityStatement(stmt)
case *ShowTagKeysStatement: case *influxql.ShowTagKeysStatement:
return rewriteShowTagKeysStatement(stmt) return rewriteShowTagKeysStatement(stmt)
case *ShowTagKeyCardinalityStatement: case *influxql.ShowTagKeyCardinalityStatement:
return rewriteShowTagKeyCardinalityStatement(stmt) return rewriteShowTagKeyCardinalityStatement(stmt)
case *ShowTagValuesStatement: case *influxql.ShowTagValuesStatement:
return rewriteShowTagValuesStatement(stmt) return rewriteShowTagValuesStatement(stmt)
case *ShowTagValuesCardinalityStatement: case *influxql.ShowTagValuesCardinalityStatement:
return rewriteShowTagValuesCardinalityStatement(stmt) return rewriteShowTagValuesCardinalityStatement(stmt)
default: default:
return stmt, nil return stmt, nil
} }
} }
func rewriteShowFieldKeysStatement(stmt *ShowFieldKeysStatement) (Statement, error) { func rewriteShowFieldKeysStatement(stmt *influxql.ShowFieldKeysStatement) (influxql.Statement, error) {
return &SelectStatement{ return &influxql.SelectStatement{
Fields: Fields([]*Field{ Fields: influxql.Fields([]*influxql.Field{
{Expr: &VarRef{Val: "fieldKey"}}, {Expr: &influxql.VarRef{Val: "fieldKey"}},
{Expr: &VarRef{Val: "fieldType"}}, {Expr: &influxql.VarRef{Val: "fieldType"}},
}), }),
Sources: rewriteSources(stmt.Sources, "_fieldKeys", stmt.Database), Sources: rewriteSources(stmt.Sources, "_fieldKeys", stmt.Database),
Condition: rewriteSourcesCondition(stmt.Sources, nil), Condition: rewriteSourcesCondition(stmt.Sources, nil),
@ -50,28 +52,28 @@ func rewriteShowFieldKeysStatement(stmt *ShowFieldKeysStatement) (Statement, err
}, nil }, nil
} }
func rewriteShowFieldKeyCardinalityStatement(stmt *ShowFieldKeyCardinalityStatement) (Statement, error) { func rewriteShowFieldKeyCardinalityStatement(stmt *influxql.ShowFieldKeyCardinalityStatement) (influxql.Statement, error) {
// Check for time in WHERE clause (not supported). // Check for time in WHERE clause (not supported).
if HasTimeExpr(stmt.Condition) { if influxql.HasTimeExpr(stmt.Condition) {
return nil, errors.New("SHOW FIELD KEY CARDINALITY doesn't support time in WHERE clause") return nil, errors.New("SHOW FIELD KEY CARDINALITY doesn't support time in WHERE clause")
} }
// Use all field keys, if zero. // Use all field keys, if zero.
if len(stmt.Sources) == 0 { if len(stmt.Sources) == 0 {
stmt.Sources = Sources{ stmt.Sources = influxql.Sources{
&Measurement{Regex: &RegexLiteral{Val: regexp.MustCompile(`.+`)}}, &influxql.Measurement{Regex: &influxql.RegexLiteral{Val: regexp.MustCompile(`.+`)}},
} }
} }
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{ {
Expr: &Call{ Expr: &influxql.Call{
Name: "count", Name: "count",
Args: []Expr{ Args: []influxql.Expr{
&Call{ &influxql.Call{
Name: "distinct", Name: "distinct",
Args: []Expr{&VarRef{Val: "_fieldKey"}}, Args: []influxql.Expr{&influxql.VarRef{Val: "_fieldKey"}},
}, },
}, },
}, },
@ -87,15 +89,15 @@ func rewriteShowFieldKeyCardinalityStatement(stmt *ShowFieldKeyCardinalityStatem
}, nil }, nil
} }
func rewriteShowMeasurementsStatement(stmt *ShowMeasurementsStatement) (Statement, error) { func rewriteShowMeasurementsStatement(stmt *influxql.ShowMeasurementsStatement) (influxql.Statement, error) {
var sources Sources var sources influxql.Sources
if stmt.Source != nil { if stmt.Source != nil {
sources = Sources{stmt.Source} sources = influxql.Sources{stmt.Source}
} }
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{Expr: &VarRef{Val: "_name"}, Alias: "name"}, {Expr: &influxql.VarRef{Val: "_name"}, Alias: "name"},
}, },
Sources: rewriteSources2(sources, stmt.Database), Sources: rewriteSources2(sources, stmt.Database),
Condition: stmt.Condition, Condition: stmt.Condition,
@ -110,7 +112,7 @@ func rewriteShowMeasurementsStatement(stmt *ShowMeasurementsStatement) (Statemen
}, nil }, nil
} }
func rewriteShowMeasurementCardinalityStatement(stmt *ShowMeasurementCardinalityStatement) (Statement, error) { func rewriteShowMeasurementCardinalityStatement(stmt *influxql.ShowMeasurementCardinalityStatement) (influxql.Statement, error) {
// TODO(edd): currently we only support cardinality estimation for certain // TODO(edd): currently we only support cardinality estimation for certain
// types of query. As the estimation coverage is expanded, this condition // types of query. As the estimation coverage is expanded, this condition
// will become less strict. // will become less strict.
@ -119,26 +121,26 @@ func rewriteShowMeasurementCardinalityStatement(stmt *ShowMeasurementCardinality
} }
// Check for time in WHERE clause (not supported). // Check for time in WHERE clause (not supported).
if HasTimeExpr(stmt.Condition) { if influxql.HasTimeExpr(stmt.Condition) {
return nil, errors.New("SHOW MEASUREMENT EXACT CARDINALITY doesn't support time in WHERE clause") return nil, errors.New("SHOW MEASUREMENT EXACT CARDINALITY doesn't support time in WHERE clause")
} }
// Use all measurements, if zero. // Use all measurements, if zero.
if len(stmt.Sources) == 0 { if len(stmt.Sources) == 0 {
stmt.Sources = Sources{ stmt.Sources = influxql.Sources{
&Measurement{Regex: &RegexLiteral{Val: regexp.MustCompile(`.+`)}}, &influxql.Measurement{Regex: &influxql.RegexLiteral{Val: regexp.MustCompile(`.+`)}},
} }
} }
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{ {
Expr: &Call{ Expr: &influxql.Call{
Name: "count", Name: "count",
Args: []Expr{ Args: []influxql.Expr{
&Call{ &influxql.Call{
Name: "distinct", Name: "distinct",
Args: []Expr{&VarRef{Val: "_name"}}, Args: []influxql.Expr{&influxql.VarRef{Val: "_name"}},
}, },
}, },
}, },
@ -155,10 +157,10 @@ func rewriteShowMeasurementCardinalityStatement(stmt *ShowMeasurementCardinality
}, nil }, nil
} }
func rewriteShowSeriesStatement(stmt *ShowSeriesStatement) (Statement, error) { func rewriteShowSeriesStatement(stmt *influxql.ShowSeriesStatement) (influxql.Statement, error) {
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{Expr: &VarRef{Val: "_seriesKey"}, Alias: "key"}, {Expr: &influxql.VarRef{Val: "_seriesKey"}, Alias: "key"},
}, },
Sources: rewriteSources2(stmt.Sources, stmt.Database), Sources: rewriteSources2(stmt.Sources, stmt.Database),
Condition: stmt.Condition, Condition: stmt.Condition,
@ -172,7 +174,7 @@ func rewriteShowSeriesStatement(stmt *ShowSeriesStatement) (Statement, error) {
}, nil }, nil
} }
func rewriteShowSeriesCardinalityStatement(stmt *ShowSeriesCardinalityStatement) (Statement, error) { func rewriteShowSeriesCardinalityStatement(stmt *influxql.ShowSeriesCardinalityStatement) (influxql.Statement, error) {
// TODO(edd): currently we only support cardinality estimation for certain // TODO(edd): currently we only support cardinality estimation for certain
// types of query. As the estimation coverage is expanded, this condition // types of query. As the estimation coverage is expanded, this condition
// will become less strict. // will become less strict.
@ -181,20 +183,20 @@ func rewriteShowSeriesCardinalityStatement(stmt *ShowSeriesCardinalityStatement)
} }
// Check for time in WHERE clause (not supported). // Check for time in WHERE clause (not supported).
if HasTimeExpr(stmt.Condition) { if influxql.HasTimeExpr(stmt.Condition) {
return nil, errors.New("SHOW SERIES EXACT CARDINALITY doesn't support time in WHERE clause") return nil, errors.New("SHOW SERIES EXACT CARDINALITY doesn't support time in WHERE clause")
} }
// Use all measurements, if zero. // Use all measurements, if zero.
if len(stmt.Sources) == 0 { if len(stmt.Sources) == 0 {
stmt.Sources = Sources{ stmt.Sources = influxql.Sources{
&Measurement{Regex: &RegexLiteral{Val: regexp.MustCompile(`.+`)}}, &influxql.Measurement{Regex: &influxql.RegexLiteral{Val: regexp.MustCompile(`.+`)}},
} }
} }
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{Expr: &Call{Name: "count", Args: []Expr{&VarRef{Val: "_seriesKey"}}}, Alias: "count"}, {Expr: &influxql.Call{Name: "count", Args: []influxql.Expr{&influxql.VarRef{Val: "_seriesKey"}}}, Alias: "count"},
}, },
Sources: rewriteSources2(stmt.Sources, stmt.Database), Sources: rewriteSources2(stmt.Sources, stmt.Database),
Condition: stmt.Condition, Condition: stmt.Condition,
@ -205,24 +207,24 @@ func rewriteShowSeriesCardinalityStatement(stmt *ShowSeriesCardinalityStatement)
}, nil }, nil
} }
func rewriteShowTagValuesStatement(stmt *ShowTagValuesStatement) (Statement, error) { func rewriteShowTagValuesStatement(stmt *influxql.ShowTagValuesStatement) (influxql.Statement, error) {
// Check for time in WHERE clause (not supported). // Check for time in WHERE clause (not supported).
if HasTimeExpr(stmt.Condition) { if influxql.HasTimeExpr(stmt.Condition) {
return nil, errors.New("SHOW TAG VALUES doesn't support time in WHERE clause") return nil, errors.New("SHOW TAG VALUES doesn't support time in WHERE clause")
} }
var expr Expr var expr influxql.Expr
if list, ok := stmt.TagKeyExpr.(*ListLiteral); ok { if list, ok := stmt.TagKeyExpr.(*influxql.ListLiteral); ok {
for _, tagKey := range list.Vals { for _, tagKey := range list.Vals {
tagExpr := &BinaryExpr{ tagExpr := &influxql.BinaryExpr{
Op: EQ, Op: influxql.EQ,
LHS: &VarRef{Val: "_tagKey"}, LHS: &influxql.VarRef{Val: "_tagKey"},
RHS: &StringLiteral{Val: tagKey}, RHS: &influxql.StringLiteral{Val: tagKey},
} }
if expr != nil { if expr != nil {
expr = &BinaryExpr{ expr = &influxql.BinaryExpr{
Op: OR, Op: influxql.OR,
LHS: expr, LHS: expr,
RHS: tagExpr, RHS: tagExpr,
} }
@ -231,9 +233,9 @@ func rewriteShowTagValuesStatement(stmt *ShowTagValuesStatement) (Statement, err
} }
} }
} else { } else {
expr = &BinaryExpr{ expr = &influxql.BinaryExpr{
Op: stmt.Op, Op: stmt.Op,
LHS: &VarRef{Val: "_tagKey"}, LHS: &influxql.VarRef{Val: "_tagKey"},
RHS: stmt.TagKeyExpr, RHS: stmt.TagKeyExpr,
} }
} }
@ -243,15 +245,15 @@ func rewriteShowTagValuesStatement(stmt *ShowTagValuesStatement) (Statement, err
if condition == nil { if condition == nil {
condition = expr condition = expr
} else { } else {
condition = &BinaryExpr{ condition = &influxql.BinaryExpr{
Op: AND, Op: influxql.AND,
LHS: &ParenExpr{Expr: condition}, LHS: &influxql.ParenExpr{Expr: condition},
RHS: &ParenExpr{Expr: expr}, RHS: &influxql.ParenExpr{Expr: expr},
} }
} }
condition = rewriteSourcesCondition(stmt.Sources, condition) condition = rewriteSourcesCondition(stmt.Sources, condition)
return &ShowTagValuesStatement{ return &influxql.ShowTagValuesStatement{
Database: stmt.Database, Database: stmt.Database,
Op: stmt.Op, Op: stmt.Op,
TagKeyExpr: stmt.TagKeyExpr, TagKeyExpr: stmt.TagKeyExpr,
@ -262,26 +264,26 @@ func rewriteShowTagValuesStatement(stmt *ShowTagValuesStatement) (Statement, err
}, nil }, nil
} }
func rewriteShowTagValuesCardinalityStatement(stmt *ShowTagValuesCardinalityStatement) (Statement, error) { func rewriteShowTagValuesCardinalityStatement(stmt *influxql.ShowTagValuesCardinalityStatement) (influxql.Statement, error) {
// Use all measurements, if zero. // Use all measurements, if zero.
if len(stmt.Sources) == 0 { if len(stmt.Sources) == 0 {
stmt.Sources = Sources{ stmt.Sources = influxql.Sources{
&Measurement{Regex: &RegexLiteral{Val: regexp.MustCompile(`.+`)}}, &influxql.Measurement{Regex: &influxql.RegexLiteral{Val: regexp.MustCompile(`.+`)}},
} }
} }
var expr Expr var expr influxql.Expr
if list, ok := stmt.TagKeyExpr.(*ListLiteral); ok { if list, ok := stmt.TagKeyExpr.(*influxql.ListLiteral); ok {
for _, tagKey := range list.Vals { for _, tagKey := range list.Vals {
tagExpr := &BinaryExpr{ tagExpr := &influxql.BinaryExpr{
Op: EQ, Op: influxql.EQ,
LHS: &VarRef{Val: "_tagKey"}, LHS: &influxql.VarRef{Val: "_tagKey"},
RHS: &StringLiteral{Val: tagKey}, RHS: &influxql.StringLiteral{Val: tagKey},
} }
if expr != nil { if expr != nil {
expr = &BinaryExpr{ expr = &influxql.BinaryExpr{
Op: OR, Op: influxql.OR,
LHS: expr, LHS: expr,
RHS: tagExpr, RHS: tagExpr,
} }
@ -290,9 +292,9 @@ func rewriteShowTagValuesCardinalityStatement(stmt *ShowTagValuesCardinalityStat
} }
} }
} else { } else {
expr = &BinaryExpr{ expr = &influxql.BinaryExpr{
Op: stmt.Op, Op: stmt.Op,
LHS: &VarRef{Val: "_tagKey"}, LHS: &influxql.VarRef{Val: "_tagKey"},
RHS: stmt.TagKeyExpr, RHS: stmt.TagKeyExpr,
} }
} }
@ -302,22 +304,22 @@ func rewriteShowTagValuesCardinalityStatement(stmt *ShowTagValuesCardinalityStat
if condition == nil { if condition == nil {
condition = expr condition = expr
} else { } else {
condition = &BinaryExpr{ condition = &influxql.BinaryExpr{
Op: AND, Op: influxql.AND,
LHS: &ParenExpr{Expr: condition}, LHS: &influxql.ParenExpr{Expr: condition},
RHS: &ParenExpr{Expr: expr}, RHS: &influxql.ParenExpr{Expr: expr},
} }
} }
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{ {
Expr: &Call{ Expr: &influxql.Call{
Name: "count", Name: "count",
Args: []Expr{ Args: []influxql.Expr{
&Call{ &influxql.Call{
Name: "distinct", Name: "distinct",
Args: []Expr{&VarRef{Val: "_tagValue"}}, Args: []influxql.Expr{&influxql.VarRef{Val: "_tagValue"}},
}, },
}, },
}, },
@ -333,13 +335,13 @@ func rewriteShowTagValuesCardinalityStatement(stmt *ShowTagValuesCardinalityStat
}, nil }, nil
} }
func rewriteShowTagKeysStatement(stmt *ShowTagKeysStatement) (Statement, error) { func rewriteShowTagKeysStatement(stmt *influxql.ShowTagKeysStatement) (influxql.Statement, error) {
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{ {
Expr: &Call{ Expr: &influxql.Call{
Name: "distinct", Name: "distinct",
Args: []Expr{&VarRef{Val: "_tagKey"}}, Args: []influxql.Expr{&influxql.VarRef{Val: "_tagKey"}},
}, },
Alias: "tagKey", Alias: "tagKey",
}, },
@ -355,28 +357,28 @@ func rewriteShowTagKeysStatement(stmt *ShowTagKeysStatement) (Statement, error)
}, nil }, nil
} }
func rewriteShowTagKeyCardinalityStatement(stmt *ShowTagKeyCardinalityStatement) (Statement, error) { func rewriteShowTagKeyCardinalityStatement(stmt *influxql.ShowTagKeyCardinalityStatement) (influxql.Statement, error) {
// Check for time in WHERE clause (not supported). // Check for time in WHERE clause (not supported).
if HasTimeExpr(stmt.Condition) { if influxql.HasTimeExpr(stmt.Condition) {
return nil, errors.New("SHOW TAG KEY EXACT CARDINALITY doesn't support time in WHERE clause") return nil, errors.New("SHOW TAG KEY EXACT CARDINALITY doesn't support time in WHERE clause")
} }
// Use all measurements, if zero. // Use all measurements, if zero.
if len(stmt.Sources) == 0 { if len(stmt.Sources) == 0 {
stmt.Sources = Sources{ stmt.Sources = influxql.Sources{
&Measurement{Regex: &RegexLiteral{Val: regexp.MustCompile(`.+`)}}, &influxql.Measurement{Regex: &influxql.RegexLiteral{Val: regexp.MustCompile(`.+`)}},
} }
} }
return &SelectStatement{ return &influxql.SelectStatement{
Fields: []*Field{ Fields: []*influxql.Field{
{ {
Expr: &Call{ Expr: &influxql.Call{
Name: "count", Name: "count",
Args: []Expr{ Args: []influxql.Expr{
&Call{ &influxql.Call{
Name: "distinct", Name: "distinct",
Args: []Expr{&VarRef{Val: "_tagKey"}}, Args: []influxql.Expr{&influxql.VarRef{Val: "_tagKey"}},
}, },
}, },
}, },
@ -393,26 +395,26 @@ func rewriteShowTagKeyCardinalityStatement(stmt *ShowTagKeyCardinalityStatement)
} }
// rewriteSources rewrites sources with previous database and retention policy // rewriteSources rewrites sources with previous database and retention policy
func rewriteSources(sources Sources, measurementName, defaultDatabase string) Sources { func rewriteSources(sources influxql.Sources, measurementName, defaultDatabase string) influxql.Sources {
newSources := Sources{} newSources := influxql.Sources{}
for _, src := range sources { for _, src := range sources {
if src == nil { if src == nil {
continue continue
} }
mm := src.(*Measurement) mm := src.(*influxql.Measurement)
database := mm.Database database := mm.Database
if database == "" { if database == "" {
database = defaultDatabase database = defaultDatabase
} }
newSources = append(newSources, newSources = append(newSources,
&Measurement{ &influxql.Measurement{
Database: database, Database: database,
RetentionPolicy: mm.RetentionPolicy, RetentionPolicy: mm.RetentionPolicy,
Name: measurementName, Name: measurementName,
}) })
} }
if len(newSources) <= 0 { if len(newSources) <= 0 {
return append(newSources, &Measurement{ return append(newSources, &influxql.Measurement{
Database: defaultDatabase, Database: defaultDatabase,
Name: measurementName, Name: measurementName,
}) })
@ -422,37 +424,37 @@ func rewriteSources(sources Sources, measurementName, defaultDatabase string) So
// rewriteSourcesCondition rewrites sources into `name` expressions. // rewriteSourcesCondition rewrites sources into `name` expressions.
// Merges with cond and returns a new condition. // Merges with cond and returns a new condition.
func rewriteSourcesCondition(sources Sources, cond Expr) Expr { func rewriteSourcesCondition(sources influxql.Sources, cond influxql.Expr) influxql.Expr {
if len(sources) == 0 { if len(sources) == 0 {
return cond return cond
} }
// Generate an OR'd set of filters on source name. // Generate an OR'd set of filters on source name.
var scond Expr var scond influxql.Expr
for _, source := range sources { for _, source := range sources {
mm := source.(*Measurement) mm := source.(*influxql.Measurement)
// Generate a filtering expression on the measurement name. // Generate a filtering expression on the measurement name.
var expr Expr var expr influxql.Expr
if mm.Regex != nil { if mm.Regex != nil {
expr = &BinaryExpr{ expr = &influxql.BinaryExpr{
Op: EQREGEX, Op: influxql.EQREGEX,
LHS: &VarRef{Val: "_name"}, LHS: &influxql.VarRef{Val: "_name"},
RHS: &RegexLiteral{Val: mm.Regex.Val}, RHS: &influxql.RegexLiteral{Val: mm.Regex.Val},
} }
} else if mm.Name != "" { } else if mm.Name != "" {
expr = &BinaryExpr{ expr = &influxql.BinaryExpr{
Op: EQ, Op: influxql.EQ,
LHS: &VarRef{Val: "_name"}, LHS: &influxql.VarRef{Val: "_name"},
RHS: &StringLiteral{Val: mm.Name}, RHS: &influxql.StringLiteral{Val: mm.Name},
} }
} }
if scond == nil { if scond == nil {
scond = expr scond = expr
} else { } else {
scond = &BinaryExpr{ scond = &influxql.BinaryExpr{
Op: OR, Op: influxql.OR,
LHS: scond, LHS: scond,
RHS: expr, RHS: expr,
} }
@ -460,22 +462,22 @@ func rewriteSourcesCondition(sources Sources, cond Expr) Expr {
} }
if cond != nil { if cond != nil {
return &BinaryExpr{ return &influxql.BinaryExpr{
Op: AND, Op: influxql.AND,
LHS: &ParenExpr{Expr: scond}, LHS: &influxql.ParenExpr{Expr: scond},
RHS: &ParenExpr{Expr: cond}, RHS: &influxql.ParenExpr{Expr: cond},
} }
} }
return scond return scond
} }
func rewriteSources2(sources Sources, database string) Sources { func rewriteSources2(sources influxql.Sources, database string) influxql.Sources {
if len(sources) == 0 { if len(sources) == 0 {
sources = Sources{&Measurement{Regex: &RegexLiteral{Val: matchAllRegex.Copy()}}} sources = influxql.Sources{&influxql.Measurement{Regex: &influxql.RegexLiteral{Val: matchAllRegex.Copy()}}}
} }
for _, source := range sources { for _, source := range sources {
switch source := source.(type) { switch source := source.(type) {
case *Measurement: case *influxql.Measurement:
if source.Database == "" { if source.Database == "" {
source.Database = database source.Database = database
} }

View File

@ -1,9 +1,10 @@
package influxql_test package query_test
import ( import (
"testing" "testing"
"github.com/influxdata/influxdb/influxql" "github.com/influxdata/influxdb/influxql"
"github.com/influxdata/influxdb/query"
) )
func TestRewriteStatement(t *testing.T) { func TestRewriteStatement(t *testing.T) {
@ -150,7 +151,7 @@ func TestRewriteStatement(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("error parsing statement: %s", err) t.Errorf("error parsing statement: %s", err)
} else { } else {
stmt, err = influxql.RewriteStatement(stmt) stmt, err = query.RewriteStatement(stmt)
if err != nil { if err != nil {
t.Errorf("error rewriting statement: %s", err) t.Errorf("error rewriting statement: %s", err)
} else if s := stmt.String(); s != test.s { } else if s := stmt.String(); s != test.s {

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/influxdata/influxdb/influxql" "github.com/influxdata/influxdb/influxql"
"github.com/influxdata/influxdb/query"
) )
func TestConcurrentServer_WriteValues(t *testing.T) { func TestConcurrentServer_WriteValues(t *testing.T) {
@ -71,7 +72,7 @@ func TestConcurrentServer_TagValues(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
rewrite, err := influxql.RewriteStatement(stmt) rewrite, err := query.RewriteStatement(stmt)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }