planOtherTest.cpp 3.1 KB
Newer Older
X
Xiaoyu Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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"
X
Xiaoyu Wang 已提交
18
#include "tglobal.h"
X
Xiaoyu Wang 已提交
19 20 21

using namespace std;

22
class PlanOtherTest : public PlannerTestBase {};
X
Xiaoyu Wang 已提交
23

24
TEST_F(PlanOtherTest, createTopic) {
X
Xiaoyu Wang 已提交
25 26
  useDb("root", "test");

27
  run("create topic tp as SELECT * FROM st1");
X
Xiaoyu Wang 已提交
28
}
29 30 31 32 33 34

TEST_F(PlanOtherTest, createStream) {
  useDb("root", "test");

  run("create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 "
      "interval(10s)");
35 36 37 38 39 40

  run("CREATE STREAM s1 INTO st3 TAGS(tname VARCHAR(10), id INT) SUBTABLE(CONCAT('new-', tname)) "
      "AS SELECT _WSTART wstart, COUNT(*) cnt FROM st1 PARTITION BY TBNAME tname, c1 id INTERVAL(10S)");

  run("CREATE STREAM s1 INTO st3 TAGS(tname VARCHAR(10), id INT) SUBTABLE(CONCAT('new-', tname)) "
      "AS SELECT _WSTART wstart, COUNT(*) cnt FROM st1 PARTITION BY TBNAME tname, tag1 id INTERVAL(10S)");
41 42
}

43 44 45
TEST_F(PlanOtherTest, createStreamUseSTable) {
  useDb("root", "test");

46
  run("CREATE STREAM IF NOT EXISTS s1 into st1 as SELECT COUNT(*) FROM st1 INTERVAL(10s)");
X
Xiaoyu Wang 已提交
47

48
  run("CREATE STREAM IF NOT EXISTS s1 into st1 as SELECT COUNT(*) FROM st1 PARTITION BY TBNAME INTERVAL(10s)");
49 50
}

51 52 53
TEST_F(PlanOtherTest, createSmaIndex) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
54
  run("CREATE SMA INDEX idx1 ON t1 FUNCTION(MAX(c1), MIN(c3 + 10), SUM(c4)) INTERVAL(10s)");
X
Xiaoyu Wang 已提交
55 56

  run("SELECT SUM(c4) FROM t1 INTERVAL(10s)");
X
Xiaoyu Wang 已提交
57

58
  run("SELECT _WSTART, MIN(c3 + 10) FROM t1 "
X
Xiaoyu Wang 已提交
59 60 61 62 63 64
      "WHERE ts BETWEEN TIMESTAMP '2022-04-01 00:00:00' AND TIMESTAMP '2022-04-30 23:59:59.999' INTERVAL(10s)");

  run("SELECT SUM(c4), MAX(c3) FROM t1 INTERVAL(10s)");

  tsQuerySmaOptimize = 0;
  run("SELECT SUM(c4) FROM t1 INTERVAL(10s)");
65 66 67 68 69 70 71 72 73 74
}

TEST_F(PlanOtherTest, explain) {
  useDb("root", "test");

  run("explain SELECT * FROM t1");

  run("explain analyze SELECT * FROM t1");

  run("explain analyze verbose true ratio 0.01 SELECT * FROM t1");
X
Xiaoyu Wang 已提交
75 76 77 78 79 80
}

TEST_F(PlanOtherTest, show) {
  useDb("root", "test");

  run("SHOW DATABASES");
81 82 83 84

  run("SHOW TABLE DISTRIBUTED t1");

  run("SHOW TABLE DISTRIBUTED st1");
85 86

  run("SHOW DNODE 1 VARIABLES");
X
Xiaoyu Wang 已提交
87
}
X
Xiaoyu Wang 已提交
88 89 90 91 92 93 94 95 96 97 98 99

TEST_F(PlanOtherTest, delete) {
  useDb("root", "test");

  run("DELETE FROM t1");

  run("DELETE FROM t1 WHERE ts > now - 2d and ts < now - 1d");

  run("DELETE FROM st1");

  run("DELETE FROM st1 WHERE ts > now - 2d and ts < now - 1d AND tag1 = 10");
}
100 101 102 103

TEST_F(PlanOtherTest, insert) {
  useDb("root", "test");

104
  run("INSERT INTO t1 SELECT * FROM t1");
105 106 107 108

  run("INSERT INTO t1 (ts, c1, c2) SELECT ts, c1, c2 FROM st1");

  run("INSERT INTO t1 (ts, c1, c2) SELECT ts, c1, c2 FROM st1s1 UNION ALL SELECT ts, c1, c2 FROM st2");
109
}