planGroupByTest.cpp 2.1 KB
Newer Older
X
Xiaoyu Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "planTestUtil.h"
#include "planner.h"

using namespace std;

21
class PlanGroupByTest : public PlannerTestBase {};
X
Xiaoyu Wang 已提交
22

23
TEST_F(PlanGroupByTest, basic) {
X
Xiaoyu Wang 已提交
24 25
  useDb("root", "test");

26
  run("SELECT COUNT(*) FROM t1");
27

28
  run("SELECT c1, MAX(c3), MIN(c3), COUNT(*) FROM t1 GROUP BY c1");
29

30
  run("SELECT c1 + c3, c1 + COUNT(*) FROM t1 WHERE c2 = 'abc' GROUP BY c1, c3");
31

32
  run("SELECT c1 + c3, SUM(c4 * c5) FROM t1 WHERE CONCAT(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
33

34
  run("SELECT SUM(CEIL(c1)) FROM t1 GROUP BY CEIL(c1)");
35 36 37 38 39
}

TEST_F(PlanGroupByTest, withOrderBy) {
  useDb("root", "test");

40 41 42 43
  // ORDER BY aggfunc
  run("SELECT COUNT(*), SUM(c1) FROM t1 ORDER BY SUM(c1)");
  // ORDER BY alias of aggfunc
  // run("SELECT COUNT(*), SUM(c1) a FROM t1 ORDER BY a");
X
Xiaoyu Wang 已提交
44
}
X
Xiaoyu Wang 已提交
45 46 47 48

TEST_F(PlanGroupByTest, aggFunc) {
  useDb("root", "test");

49
  run("SELECT LAST(*), FIRST(*) FROM t1");
X
Xiaoyu Wang 已提交
50

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  run("SELECT LAST(*), FIRST(*) FROM t1 GROUP BY c1");
}

TEST_F(PlanGroupByTest, selectFunc) {
  useDb("root", "test");

  // select function
  run("SELECT MAX(c1), MIN(c1) FROM t1");
  // select function for GROUP BY clause
  run("SELECT MAX(c1), MIN(c1) FROM t1 GROUP BY c1");
  // select function along with the columns of select row
  run("SELECT MAX(c1), c2 FROM t1");
  run("SELECT MAX(c1), t1.* FROM t1");
  // select function along with the columns of select row, and with GROUP BY clause
  run("SELECT MAX(c1), c2 FROM t1 GROUP BY c3");
  run("SELECT MAX(c1), t1.* FROM t1 GROUP BY c3");
X
Xiaoyu Wang 已提交
67
}