From d75428f79f8d2d898835dd0a1138dbe5a8c75bd5 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Wed, 16 Mar 2016 17:16:05 -0400 Subject: [PATCH] Rename the special condition "name" to "_name" to reduce conflicts Fixes #6034. --- influxql/statement_rewriter.go | 27 ++++----------------------- influxql/statement_rewriter_test.go | 24 ++++++++++++------------ tsdb/meta.go | 14 +++++++------- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/influxql/statement_rewriter.go b/influxql/statement_rewriter.go index ceac74a7be0..a0f90619b32 100644 --- a/influxql/statement_rewriter.go +++ b/influxql/statement_rewriter.go @@ -21,25 +21,6 @@ func RewriteStatement(stmt Statement) (Statement, error) { } func rewriteShowFieldKeysStatement(stmt *ShowFieldKeysStatement) (Statement, error) { - var condition Expr - if len(stmt.Sources) > 0 { - if source, ok := stmt.Sources[0].(*Measurement); ok { - if source.Regex != nil { - condition = &BinaryExpr{ - Op: EQREGEX, - LHS: &VarRef{Val: "name"}, - RHS: &RegexLiteral{Val: source.Regex.Val}, - } - } else if source.Name != "" { - condition = &BinaryExpr{ - Op: EQ, - LHS: &VarRef{Val: "name"}, - RHS: &StringLiteral{Val: source.Name}, - } - } - } - } - return &SelectStatement{ Fields: Fields([]*Field{ {Expr: &VarRef{Val: "fieldKey"}}, @@ -47,7 +28,7 @@ func rewriteShowFieldKeysStatement(stmt *ShowFieldKeysStatement) (Statement, err Sources: Sources([]Source{ &Measurement{Name: "_fieldKeys"}, }), - Condition: condition, + Condition: rewriteSourcesCondition(stmt.Sources, nil), Offset: stmt.Offset, Limit: stmt.Limit, SortFields: stmt.SortFields, @@ -69,7 +50,7 @@ func rewriteShowMeasurementsStatement(stmt *ShowMeasurementsStatement) (Statemen return &SelectStatement{ Fields: Fields([]*Field{ - {Expr: &VarRef{Val: "name"}}, + {Expr: &VarRef{Val: "_name"}, Alias: "name"}, }), Sources: Sources([]Source{ &Measurement{Name: "_measurements"}, @@ -201,13 +182,13 @@ func rewriteSourcesCondition(sources Sources, cond Expr) Expr { if mm.Regex != nil { expr = &BinaryExpr{ Op: EQREGEX, - LHS: &VarRef{Val: "name"}, + LHS: &VarRef{Val: "_name"}, RHS: &RegexLiteral{Val: mm.Regex.Val}, } } else if mm.Name != "" { expr = &BinaryExpr{ Op: EQ, - LHS: &VarRef{Val: "name"}, + LHS: &VarRef{Val: "_name"}, RHS: &StringLiteral{Val: mm.Name}, } } diff --git a/influxql/statement_rewriter_test.go b/influxql/statement_rewriter_test.go index 73226f28e2a..96b8ab5ccc1 100644 --- a/influxql/statement_rewriter_test.go +++ b/influxql/statement_rewriter_test.go @@ -17,31 +17,31 @@ func TestRewriteStatement(t *testing.T) { }, { stmt: `SHOW FIELD KEYS FROM cpu`, - s: `SELECT fieldKey FROM _fieldKeys WHERE "name" = 'cpu'`, + s: `SELECT fieldKey FROM _fieldKeys WHERE _name = 'cpu'`, }, { stmt: `SHOW FIELD KEYS FROM /c.*/`, - s: `SELECT fieldKey FROM _fieldKeys WHERE "name" =~ /c.*/`, + s: `SELECT fieldKey FROM _fieldKeys WHERE _name =~ /c.*/`, }, { stmt: `SHOW MEASUREMENTS`, - s: `SELECT "name" FROM _measurements`, + s: `SELECT _name AS "name" FROM _measurements`, }, { stmt: `SHOW MEASUREMENTS WITH MEASUREMENT = cpu`, - s: `SELECT "name" FROM _measurements WHERE "name" = 'cpu'`, + s: `SELECT _name AS "name" FROM _measurements WHERE _name = 'cpu'`, }, { stmt: `SHOW MEASUREMENTS WITH MEASUREMENT =~ /c.*/`, - s: `SELECT "name" FROM _measurements WHERE "name" =~ /c.*/`, + s: `SELECT _name AS "name" FROM _measurements WHERE _name =~ /c.*/`, }, { stmt: `SHOW MEASUREMENTS WHERE region = 'uswest'`, - s: `SELECT "name" FROM _measurements WHERE region = 'uswest'`, + s: `SELECT _name AS "name" FROM _measurements WHERE region = 'uswest'`, }, { stmt: `SHOW MEASUREMENTS WITH MEASUREMENT = cpu WHERE region = 'uswest'`, - s: `SELECT "name" FROM _measurements WHERE ("name" = 'cpu') AND (region = 'uswest')`, + s: `SELECT _name AS "name" FROM _measurements WHERE (_name = 'cpu') AND (region = 'uswest')`, }, { stmt: `SHOW TAG KEYS`, @@ -49,15 +49,15 @@ func TestRewriteStatement(t *testing.T) { }, { stmt: `SHOW TAG KEYS FROM cpu`, - s: `SELECT tagKey FROM _tagKeys WHERE "name" = 'cpu'`, + s: `SELECT tagKey FROM _tagKeys WHERE _name = 'cpu'`, }, { stmt: `SHOW TAG KEYS FROM /c.*/`, - s: `SELECT tagKey FROM _tagKeys WHERE "name" =~ /c.*/`, + s: `SELECT tagKey FROM _tagKeys WHERE _name =~ /c.*/`, }, { stmt: `SHOW TAG KEYS FROM cpu WHERE region = 'uswest'`, - s: `SELECT tagKey FROM _tagKeys WHERE ("name" = 'cpu') AND (region = 'uswest')`, + s: `SELECT tagKey FROM _tagKeys WHERE (_name = 'cpu') AND (region = 'uswest')`, }, { stmt: `SHOW TAG VALUES WITH KEY = region`, @@ -65,11 +65,11 @@ func TestRewriteStatement(t *testing.T) { }, { stmt: `SHOW TAG VALUES FROM cpu WITH KEY = region`, - s: `SELECT _tagKey AS "key", value FROM _tags WHERE ("name" = 'cpu') AND (_tagKey = 'region')`, + s: `SELECT _tagKey AS "key", value FROM _tags WHERE (_name = 'cpu') AND (_tagKey = 'region')`, }, { stmt: `SHOW TAG VALUES FROM cpu WITH KEY IN (region, host)`, - s: `SELECT _tagKey AS "key", value FROM _tags WHERE ("name" = 'cpu') AND (_tagKey = 'region' OR _tagKey = 'host')`, + s: `SELECT _tagKey AS "key", value FROM _tags WHERE (_name = 'cpu') AND (_tagKey = 'region' OR _tagKey = 'host')`, }, { stmt: `SELECT value FROM cpu`, diff --git a/tsdb/meta.go b/tsdb/meta.go index 57bac4226c2..0077c945b84 100644 --- a/tsdb/meta.go +++ b/tsdb/meta.go @@ -178,7 +178,7 @@ func (d *DatabaseIndex) measurementsByExpr(expr influxql.Expr) (Measurements, bo } // Match on name, if specified. - if tag.Val == "name" { + if tag.Val == "_name" { return d.measurementsByNameFilter(tf.Op, tf.Value, tf.Regex), true, nil } else if influxql.IsSystemName(tag.Val) { return nil, false, nil @@ -743,12 +743,12 @@ func (m *Measurement) idsForExpr(n *influxql.BinaryExpr) (SeriesIDs, influxql.Ex // For fields, return all series IDs from this measurement and return // the expression passed in, as the filter. - if name.Val != "name" && m.HasField(name.Val) { + if name.Val != "_name" && m.HasField(name.Val) { return m.seriesIDs, n, nil } tagVals, ok := m.seriesByTagKeyValue[name.Val] - if name.Val != "name" && !ok { + if name.Val != "_name" && !ok { return nil, nil, nil } @@ -756,8 +756,8 @@ func (m *Measurement) idsForExpr(n *influxql.BinaryExpr) (SeriesIDs, influxql.Ex if str, ok := value.(*influxql.StringLiteral); ok { var ids SeriesIDs - // Special handling for "name" to match measurement name. - if name.Val == "name" { + // Special handling for "_name" to match measurement name. + if name.Val == "_name" { if (n.Op == influxql.EQ && str.Val == m.Name) || (n.Op == influxql.NEQ && str.Val != m.Name) { return m.seriesIDs, &influxql.BooleanLiteral{Val: true}, nil } @@ -777,8 +777,8 @@ func (m *Measurement) idsForExpr(n *influxql.BinaryExpr) (SeriesIDs, influxql.Ex if re, ok := value.(*influxql.RegexLiteral); ok { var ids SeriesIDs - // Special handling for "name" to match measurement name. - if name.Val == "name" { + // Special handling for "_name" to match measurement name. + if name.Val == "_name" { match := re.Val.MatchString(m.Name) if (n.Op == influxql.EQREGEX && match) || (n.Op == influxql.NEQREGEX && !match) { return m.seriesIDs, &influxql.BooleanLiteral{Val: true}, nil