func BenchmarkMeasurement_SeriesIDForExp_NERegex(b *testing.B) { m := tsdb.NewMeasurement("cpu") for i := 0; i < 100000; i++ { s := tsdb.NewSeries("cpu", models.Tags{models.Tag{ Key: []byte("host"), Value: []byte(fmt.Sprintf("host%d", i))}}) s.ID = uint64(i) m.AddSeries(s) } if exp, got := 100000, len(m.SeriesKeys()); exp != got { b.Fatalf("series count mismatch: exp %v got %v", exp, got) } stmt, err := influxql.NewParser(strings.NewReader(`SELECT * FROM cpu WHERE host !~ /foo\d+/`)).ParseStatement() if err != nil { b.Fatalf("invalid statement: %s", err) } selectStmt := stmt.(*influxql.SelectStatement) b.ResetTimer() for i := 0; i < b.N; i++ { ids := m.IDsForExpr(selectStmt.Condition.(*influxql.BinaryExpr)) if exp, got := 100000, len(ids); exp != got { b.Fatalf("series count mismatch: exp %v got %v", exp, got) } } }
func TestMeasurement_AppendSeriesKeysByID_Missing(t *testing.T) { m := tsdb.NewMeasurement("cpu") var dst []string dst = m.AppendSeriesKeysByID(dst, []uint64{1}) if exp, got := 0, len(dst); exp != got { t.Fatalf("series len mismatch: exp %v, got %v", exp, got) } }
func TestMeasurement_AppendSeriesKeysByID_Exists(t *testing.T) { m := tsdb.NewMeasurement("cpu") s := tsdb.NewSeries("cpu,host=foo", models.Tags{models.Tag{Key: []byte("host"), Value: []byte("foo")}}) s.ID = 1 m.AddSeries(s) var dst []string dst = m.AppendSeriesKeysByID(dst, []uint64{1}) if exp, got := 1, len(dst); exp != got { t.Fatalf("series len mismatch: exp %v, got %v", exp, got) } if exp, got := "cpu,host=foo", dst[0]; exp != got { t.Fatalf("series mismatch: exp %v, got %v", exp, got) } }