Skip to content

Commit

Permalink
Remove defunct Substatement() call
Browse files Browse the repository at this point in the history
  • Loading branch information
jsternberg committed Sep 13, 2016
1 parent 8b07e9d commit 394c138
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 136 deletions.
65 changes: 0 additions & 65 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,71 +1921,6 @@ func (s *SelectStatement) rewriteWithoutTimeDimensions() string {
return n.String()
}

/*
BinaryExpr
SELECT mean(xxx.value) + avg(yyy.value) FROM xxx JOIN yyy WHERE xxx.host = 123
from xxx where host = 123
select avg(value) from yyy where host = 123
SELECT xxx.value FROM xxx WHERE xxx.host = 123
SELECT yyy.value FROM yyy
---
SELECT MEAN(xxx.value) + MEAN(cpu.load.value)
FROM xxx JOIN yyy
GROUP BY host
WHERE (xxx.region == "uswest" OR yyy.region == "uswest") AND xxx.otherfield == "XXX"
select * from (
select mean + mean from xxx join yyy
group by time(5m), host
) (xxx.region == "uswest" OR yyy.region == "uswest") AND xxx.otherfield == "XXX"
(seriesIDS for xxx.region = 'uswest' union seriesIDs for yyy.regnion = 'uswest') | seriesIDS xxx.otherfield = 'XXX'
WHERE xxx.region == "uswest" AND xxx.otherfield == "XXX"
WHERE yyy.region == "uswest"
*/

// Substatement returns a single-series statement for a given variable reference.
func (s *SelectStatement) Substatement(ref *VarRef) (*SelectStatement, error) {
// Copy dimensions and properties to new statement.
other := &SelectStatement{
Fields: Fields{{Expr: ref}},
Dimensions: s.Dimensions,
Limit: s.Limit,
Offset: s.Offset,
SortFields: s.SortFields,
}

// If there is only one series source then return it with the whole condition.
if len(s.Sources) == 1 {
other.Sources = s.Sources
other.Condition = s.Condition
return other, nil
}

// Find the matching source.
name := MatchSource(s.Sources, ref.Val)
if name == "" {
return nil, fmt.Errorf("field source not found: %s", ref.Val)
}
other.Sources = append(other.Sources, &Measurement{Name: name})

// Filter out conditions.
if s.Condition != nil {
other.Condition = filterExprBySource(name, s.Condition)
}

return other, nil
}

// NamesInWhere returns the field and tag names (idents) referenced in the where clause
func (s *SelectStatement) NamesInWhere() []string {
var a []string
Expand Down
71 changes: 0 additions & 71 deletions influxql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,77 +61,6 @@ func TestDataType_String(t *testing.T) {
}
}

// Ensure the SELECT statement can extract substatements.
func TestSelectStatement_Substatement(t *testing.T) {
var tests = []struct {
stmt string
expr *influxql.VarRef
sub string
err string
}{
// 0. Single series
{
stmt: `SELECT value FROM myseries WHERE value > 1`,
expr: &influxql.VarRef{Val: "value"},
sub: `SELECT value FROM myseries WHERE value > 1`,
},

// 1. Simple join
{
stmt: `SELECT sum(aa.value) + sum(bb.value) FROM aa, bb`,
expr: &influxql.VarRef{Val: "aa.value"},
sub: `SELECT "aa.value" FROM aa`,
},

// 2. Simple merge
{
stmt: `SELECT sum(aa.value) + sum(bb.value) FROM aa, bb`,
expr: &influxql.VarRef{Val: "bb.value"},
sub: `SELECT "bb.value" FROM bb`,
},

// 3. Join with condition
{
stmt: `SELECT sum(aa.value) + sum(bb.value) FROM aa, bb WHERE aa.host = 'servera' AND bb.host = 'serverb'`,
expr: &influxql.VarRef{Val: "bb.value"},
sub: `SELECT "bb.value" FROM bb WHERE "bb.host" = 'serverb'`,
},

// 4. Join with complex condition
{
stmt: `SELECT sum(aa.value) + sum(bb.value) FROM aa, bb WHERE aa.host = 'servera' AND (bb.host = 'serverb' OR bb.host = 'serverc') AND 1 = 2`,
expr: &influxql.VarRef{Val: "bb.value"},
sub: `SELECT "bb.value" FROM bb WHERE ("bb.host" = 'serverb' OR "bb.host" = 'serverc') AND 1 = 2`,
},

// 5. 4 with different condition order
{
stmt: `SELECT sum(aa.value) + sum(bb.value) FROM aa, bb WHERE ((bb.host = 'serverb' OR bb.host = 'serverc') AND aa.host = 'servera') AND 1 = 2`,
expr: &influxql.VarRef{Val: "bb.value"},
sub: `SELECT "bb.value" FROM bb WHERE (("bb.host" = 'serverb' OR "bb.host" = 'serverc')) AND 1 = 2`,
},
}

for i, tt := range tests {
// Parse statement.
stmt, err := influxql.NewParser(strings.NewReader(tt.stmt)).ParseStatement()
if err != nil {
t.Fatalf("invalid statement: %q: %s", tt.stmt, err)
}

// Extract substatement.
sub, err := stmt.(*influxql.SelectStatement).Substatement(tt.expr)
if err != nil {
t.Errorf("%d. %q: unexpected error: %s", i, tt.stmt, err)
continue
}
if substr := sub.String(); tt.sub != substr {
t.Errorf("%d. %q: unexpected substatement:\n\nexp=%s\n\ngot=%s\n\n", i, tt.stmt, tt.sub, substr)
continue
}
}
}

// Ensure the SELECT statement can extract GROUP BY interval.
func TestSelectStatement_GroupByInterval(t *testing.T) {
q := "SELECT sum(value) from foo where time < now() GROUP BY time(10m)"
Expand Down

0 comments on commit 394c138

Please sign in to comment.