CREATE TABLE http_requests ( ts timestamp(3) time index, host STRING, idc STRING, val BIGINT, PRIMARY KEY(host, idc), ); INSERT INTO TABLE http_requests VALUES (0, 'host1', "idc1", 200), (0, 'host2', "idc1", 200), (0, 'host3', "idc2", 200), (0, 'host4', "idc2", 401), (5000, 'host1', "idc1", 404), (5000, 'host2', "idc1", 401), (5000, 'host3', "idc2", 404), (5000, 'host4', "idc2", 500), (10000, 'host1', "idc1", 200), (10000, 'host2', "idc1", 200), (10000, 'host3', "idc2", 201), (10000, 'host4', "idc2", 201), (15000, 'host1', "idc1", 500), (15000, 'host2', "idc1", 500), (15000, 'host3', "idc2", 500), (15000, 'host4', "idc2", 500); TQL EVAL (0, 15, '5s') count_values("status_code", http_requests); TQL EVAL (0, 15, '5s') count_values("status_code", http_requests) by (idc); -- https://github.com/GreptimeTeam/greptimedb/issues/9181 -- The label generated by `count_values` must survive an enclosing expression, -- e.g. a per-sample function, an arithmetic operation or an enclosing aggregation. -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 15, '5s') abs(count_values("v", http_requests)); -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 15, '5s') round(count_values("v", http_requests)); -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 15, '5s') count_values("v", http_requests) + 1; -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 15, '5s') sum by (v) (count_values("v", http_requests)); -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 15, '5s') topk(10, count_values("v", http_requests)); -- The generated label overwrites an input label with the same name (PromQL semantics), -- and must not turn the generated column into an ambiguous reference. -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 15, '5s') count_values("idc", http_requests) by (idc); -- The generated label is the sample value in PromQL's textual form -- (`strconv.FormatFloat(value, 'f', -1, 64)`: the shortest decimal form without an -- exponent), so it is a string: `200.0` becomes the label `200` and `1e21` becomes -- `1000000000000000000000`. CREATE TABLE http_requests_double ( ts timestamp(3) time index, host STRING, idc STRING, val DOUBLE, PRIMARY KEY(host, idc), ); INSERT INTO TABLE http_requests_double VALUES (0, 'host1', "idc1", 200.0), (0, 'host2', "idc1", 0.5), (5000, 'host1', "idc1", 200.0), (5000, 'host2', "idc1", 1e21); -- SQLNESS SORT_RESULT 3 1 TQL EVAL (0, 5, '5s') count_values("val_label", http_requests_double); DROP TABLE http_requests_double; DROP TABLE http_requests;