-- Regression test for promql `group()` aggregator planning.
CREATE TABLE kubernetes_build_info (
  ts timestamp(3) time index,
  cluster_name STRING,
  service_name STRING,
  job_name STRING,
  instance STRING,
  val DOUBLE,
  PRIMARY KEY(cluster_name, service_name, job_name, instance),
);

Affected Rows: 0

INSERT INTO TABLE kubernetes_build_info VALUES
    (0, 'cluster_a', 'kubernetes', 'apiserver', '0', 123.0),
    (0, 'cluster_a', 'kubernetes', 'apiserver', '1', 456.0),
    (0, 'cluster_b', 'kubernetes', 'apiserver', '0', 789.0);

Affected Rows: 3

TQL EVAL (0, 0, '1s') sum(group by (cluster_name)(kubernetes_build_info{service_name="kubernetes",job_name="apiserver"}));

+---------------------+----------------------+
| ts                  | sum(max(Float64(1))) |
+---------------------+----------------------+
| 1970-01-01T00:00:00 | 2.0                  |
+---------------------+----------------------+

DROP TABLE kubernetes_build_info;

Affected Rows: 0

-- `group()` doesn't support multi-field input without selecting a single field.
CREATE TABLE kubernetes_build_info_multi (
  ts timestamp(3) time index,
  cluster_name STRING,
  service_name STRING,
  job_name STRING,
  instance STRING,
  cpu DOUBLE,
  mem DOUBLE,
  PRIMARY KEY(cluster_name, service_name, job_name, instance),
);

Affected Rows: 0

INSERT INTO TABLE kubernetes_build_info_multi VALUES
    (0, 'cluster_a', 'kubernetes', 'apiserver', '0', 1.0, 2.0),
    (0, 'cluster_b', 'kubernetes', 'apiserver', '0', 3.0, 4.0);

Affected Rows: 2

TQL EVAL (0, 0, '1s') group by (cluster_name)(kubernetes_build_info_multi{service_name="kubernetes",job_name="apiserver"});

Error: 1001(Unsupported), Multi fields calculation is not supported in group()

DROP TABLE kubernetes_build_info_multi;

Affected Rows: 0

