planGroupByTest.cpp 2.5 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
  run("SELECT LAST(*), FIRST(*) FROM t1 GROUP BY c1");
52 53

  run("SELECT SUM(10), COUNT(c1) FROM t1 GROUP BY c2");
54 55
}

X
Xiaoyu Wang 已提交
56 57 58 59 60 61 62 63
TEST_F(PlanGroupByTest, rewriteFunc) {
  useDb("root", "test");

  run("SELECT AVG(c1) FROM t1");

  run("SELECT AVG(c1) FROM t1 GROUP BY c2");
}

64 65 66 67 68 69 70 71 72 73 74 75 76
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 已提交
77
}
X
Xiaoyu Wang 已提交
78 79 80 81 82 83 84

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

  run("SELECT COUNT(*) FROM st1");

  run("SELECT COUNT(*) FROM st1 GROUP BY c1");
X
Xiaoyu Wang 已提交
85 86

  run("SELECT SUM(c1) FROM st1 GROUP BY c2 HAVING SUM(c1) IS NOT NULL");
X
Xiaoyu Wang 已提交
87
}