planSetOpTest.cpp 2.7 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;

X
Xiaoyu Wang 已提交
21
class PlanSetOpTest : public PlannerTestBase {};
X
Xiaoyu Wang 已提交
22 23 24 25

TEST_F(PlanSetOpTest, unionAll) {
  useDb("root", "test");

26
  // sql 1: single UNION ALL operator
27
  run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION ALL SELECT c1, c2 FROM t1 WHERE c1 > 20");
28 29 30 31
  // sql 2: multi UNION ALL operator
  run("SELECT c1, c2 FROM t1 WHERE c1 > 10 "
      "UNION ALL SELECT c1, c2 FROM t1 WHERE c1 > 20 "
      "UNION ALL SELECT c1, c2 FROM t1 WHERE c1 > 30");
32 33 34 35 36 37
}

TEST_F(PlanSetOpTest, unionAllSubquery) {
  useDb("root", "test");

  run("SELECT * FROM (SELECT c1, c2 FROM t1 UNION ALL SELECT c1, c2 FROM t1)");
X
Xiaoyu Wang 已提交
38
}
X
Xiaoyu Wang 已提交
39

40 41 42 43 44 45 46 47 48
TEST_F(PlanSetOpTest, unionAllWithSubquery) {
  useDb("root", "test");

  // child table
  run("SELECT ts FROM (SELECT ts FROM st1s1) UNION ALL SELECT ts FROM (SELECT ts FROM st1s2)");
  // super table
  run("SELECT ts FROM (SELECT ts FROM st1) UNION ALL SELECT ts FROM (SELECT ts FROM st1)");
}

X
Xiaoyu Wang 已提交
49 50 51
TEST_F(PlanSetOpTest, union) {
  useDb("root", "test");

52
  // single UNION operator
53
  run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION SELECT c1, c2 FROM t1 WHERE c1 > 20");
54 55 56 57
  // multi UNION operator
  run("SELECT c1, c2 FROM t1 WHERE c1 > 10 "
      "UNION SELECT c1, c2 FROM t1 WHERE c1 > 20 "
      "UNION SELECT c1, c2 FROM t1 WHERE c1 > 30");
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
}

TEST_F(PlanSetOpTest, unionContainJoin) {
  useDb("root", "test");

  run("SELECT t1.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts "
      "WHERE t1.c1 IS NOT NULL GROUP BY t1.c1 HAVING t1.c1 IS NOT NULL "
      "UNION "
      "SELECT t1.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts "
      "WHERE t1.c1 IS NOT NULL GROUP BY t1.c1 HAVING t1.c1 IS NOT NULL");
}

TEST_F(PlanSetOpTest, unionSubquery) {
  useDb("root", "test");

  run("SELECT * FROM (SELECT c1, c2 FROM t1 UNION SELECT c1, c2 FROM t1)");
X
Xiaoyu Wang 已提交
74
}
75 76 77 78 79 80 81 82 83

TEST_F(PlanSetOpTest, bug001) {
  useDb("root", "test");

  run("SELECT c2 FROM t1 WHERE c1 IS NOT NULL GROUP BY c2 "
      "UNION "
      "SELECT 'abcdefghijklmnopqrstuvwxyz' FROM t1 "
      "WHERE 'abcdefghijklmnopqrstuvwxyz' IS NOT NULL GROUP BY 'abcdefghijklmnopqrstuvwxyz'");
}