planSubqueryTest.cpp 2.3 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 PlanSubqeuryTest : public PlannerTestBase {};
X
Xiaoyu Wang 已提交
22

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

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

X
Xiaoyu Wang 已提交
28
  run("SELECT LAST(c1) FROM (SELECT * FROM t1)");
X
Xiaoyu Wang 已提交
29 30

  run("SELECT c1 FROM (SELECT TODAY() AS c1 FROM t1)");
X
Xiaoyu Wang 已提交
31 32 33 34 35

  run("SELECT NOW() FROM t1");

  run("SELECT NOW() FROM (SELECT * FROM t1)");

36 37 38
  run("SELECT * FROM (SELECT NOW() FROM t1)");

  run("SELECT NOW() FROM (SELECT * FROM t1) ORDER BY ts");
X
Xiaoyu Wang 已提交
39 40

  run("SELECT * FROM (SELECT AVG(c1) a FROM st1 INTERVAL(10s)) WHERE a > 1");
41 42 43 44 45
}

TEST_F(PlanSubqeuryTest, doubleGroupBy) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
46 47 48
  run("SELECT COUNT(*) FROM ("
      "SELECT c1 + c3 a, c1 + COUNT(*) b FROM t1 WHERE c2 = 'abc' GROUP BY c1, c3) "
      "WHERE a > 100 GROUP BY b");
X
Xiaoyu Wang 已提交
49
}
X
Xiaoyu Wang 已提交
50

51
TEST_F(PlanSubqeuryTest, innerSetOperator) {
X
Xiaoyu Wang 已提交
52 53 54 55 56 57
  useDb("root", "test");

  run("SELECT c1 FROM (SELECT c1 FROM t1 UNION ALL SELECT c1 FROM t1)");

  run("SELECT c1 FROM (SELECT c1 FROM t1 UNION SELECT c1 FROM t1)");
}
58

59
TEST_F(PlanSubqeuryTest, innerFill) {
60 61 62 63 64 65
  useDb("root", "test");

  run("SELECT cnt FROM (SELECT _WSTART ts, COUNT(*) cnt FROM t1 "
      "WHERE ts > '2022-04-01 00:00:00' and ts < '2022-04-30 23:59:59' INTERVAL(10s) FILL(LINEAR)) "
      "WHERE ts > '2022-04-06 00:00:00'");
}
66 67 68 69 70 71 72

TEST_F(PlanSubqeuryTest, outerInterval) {
  useDb("root", "test");

  run("SELECT COUNT(*) FROM (SELECT * FROM st1) INTERVAL(5s)");

  run("SELECT COUNT(*) + SUM(c1) FROM (SELECT * FROM st1) INTERVAL(5s)");
73 74

  run("SELECT COUNT(*) FROM (SELECT ts, TOP(c1, 10) FROM st1s1) INTERVAL(5s)");
75
}
X
Xiaoyu Wang 已提交
76 77 78 79 80 81

TEST_F(PlanSubqeuryTest, outerPartition) {
  useDb("root", "test");

  run("SELECT c1, COUNT(*) FROM (SELECT ts, c1 FROM st1) PARTITION BY c1");
}