Exemple #1
0
// Ensure identifiers can be split into multiple quoted and unquoted parts.
func TestSplitIdent(t *testing.T) {
	var tests = []struct {
		in  string
		out []string
		err string
	}{
		{in: `"db"."rp"."measurement"`, out: []string{`db`, `rp`, `measurement`}},
		{in: `"db"."rp".measurement`, out: []string{`db`, `rp`, `measurement`}},
		{in: `cpu.load.total`, out: []string{`cpu.load.total`}},
		{in: `"rp".cpu.load.total`, out: []string{`rp`, `cpu.load.total`}},
		{in: `"db"..cpu.load.total`, out: []string{`db`, ``, `cpu.load.total`}},
		{in: `db."rp".cpu.total`, out: []string{`db`, `rp`, `cpu.total`}},
		{in: `db...cpu`, out: []string{`db`, ``, ``, `cpu`}},
		{in: `"db.rp".cpu`, out: []string{`db.rp`, `cpu`}},

		{in: ``, err: "invalid identifier"},
		{in: `.`, err: "invalid identifier"},
		{in: `.cpu`, err: "invalid identifier"},
		{in: `db.`, err: "invalid identifier"},
		{in: `hello world`, err: "invalid identifier"},
	}

	for i, tt := range tests {
		out, err := influxql.SplitIdent(tt.in)
		if tt.err != errstring(err) {
			t.Errorf("%d. %s: error: exp=%s, got=%s", i, tt.in, tt.err, err)
		} else if !reflect.DeepEqual(tt.out, out) {
			t.Errorf("%d. %s: out: exp=%s, got=%s", i, tt.in, tt.out, out)
		}
	}
}
Exemple #2
0
// splitIdent splits an identifier into it's database, policy, and measurement parts.
func splitIdent(s string) (db, rp, m string, err error) {
	a, err := influxql.SplitIdent(s)
	if err != nil {
		return "", "", "", err
	} else if len(a) != 3 {
		return "", "", "", fmt.Errorf("invalid ident, expected 3 segments: %q", s)
	}
	return a[0], a[1], a[2], nil
}