Commit 4fdfee73 by bergquist

fix(influxdb): add support for regex measurments

closes #6560
parent a87fd11f
......@@ -11,7 +11,8 @@ import (
)
var (
regexpOperatorPattern *regexp.Regexp = regexp.MustCompile(`^\/.*\/$`)
regexpOperatorPattern *regexp.Regexp = regexp.MustCompile(`^\/.*\/$`)
regexpMeasurementPattern *regexp.Regexp = regexp.MustCompile(`^\/.*\/$`)
)
func (query *Query) Build(queryContext *tsdb.QueryContext) (string, error) {
......@@ -108,7 +109,14 @@ func (query *Query) renderMeasurement() string {
} else {
policy = `"` + query.Policy + `".`
}
return fmt.Sprintf(` FROM %s"%s"`, policy, query.Measurement)
measurement := query.Measurement
if !regexpMeasurementPattern.Match([]byte(measurement)) {
measurement = fmt.Sprintf(`"%s"`, measurement)
}
return fmt.Sprintf(` FROM %s%s`, policy, measurement)
}
func (query *Query) renderWhereClause() string {
......
......@@ -120,5 +120,17 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = 'value'`)
})
Convey("can render regular measurement", func() {
query := &Query{Measurement: `apa`, Policy: "policy"}
So(query.renderMeasurement(), ShouldEqual, ` FROM "policy"."apa"`)
})
Convey("can render regexp measurement", func() {
query := &Query{Measurement: `/apa/`, Policy: "policy"}
So(query.renderMeasurement(), ShouldEqual, ` FROM "policy"./apa/`)
})
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment