parInsertTest.cpp 3.1 KB
Newer Older
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 <gtest/gtest.h>

X
Xiaoyu Wang 已提交
18
#include "parTestUtil.h"
19 20 21

using namespace std;

X
Xiaoyu Wang 已提交
22
namespace ParserTest {
23 24 25 26 27 28 29 30

// syntax:
// INSERT INTO
//   tb_name
//       [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)]
//       [(field1_name, ...)]
//       VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
//   [...];
X
Xiaoyu Wang 已提交
31
class ParserInsertTest : public ParserTestBase {};
32

33
// INSERT INTO tb_name [(field1_name, ...)] VALUES (field1_value, ...)
X
Xiaoyu Wang 已提交
34 35
TEST_F(ParserInsertTest, singleTableSingleRowTest) {
  useDb("root", "test");
36

X
Xiaoyu Wang 已提交
37
  run("INSERT INTO t1 VALUES (now, 1, 'beijing', 3, 4, 5)");
38

X
Xiaoyu Wang 已提交
39
  run("INSERT INTO t1 (ts, c1, c2, c3, c4, c5) VALUES (now, 1, 'beijing', 3, 4, 5)");
40 41 42
}

// INSERT INTO tb_name VALUES (field1_value, ...)(field1_value, ...)
X
Xiaoyu Wang 已提交
43 44
TEST_F(ParserInsertTest, singleTableMultiRowTest) {
  useDb("root", "test");
45

X
Xiaoyu Wang 已提交
46 47
  run("INSERT INTO t1 VALUES (now, 1, 'beijing', 3, 4, 5)"
      "(now+1s, 2, 'shanghai', 6, 7, 8)"
48
      "(now+2s, 3, 'guangzhou', 9, 10, 11)");
49 50 51
}

// INSERT INTO tb1_name VALUES (field1_value, ...) tb2_name VALUES (field1_value, ...)
X
Xiaoyu Wang 已提交
52 53
TEST_F(ParserInsertTest, multiTableSingleRowTest) {
  useDb("root", "test");
54

X
Xiaoyu Wang 已提交
55
  run("INSERT INTO st1s1 VALUES (now, 1, 'beijing') st1s2 VALUES (now, 10, '131028')");
56 57 58
}

// INSERT INTO tb1_name VALUES (field1_value, ...) tb2_name VALUES (field1_value, ...)
X
Xiaoyu Wang 已提交
59 60
TEST_F(ParserInsertTest, multiTableMultiRowTest) {
  useDb("root", "test");
61

X
Xiaoyu Wang 已提交
62 63 64
  run("INSERT INTO "
      "st1s1 VALUES (now, 1, 'beijing')(now+1s, 2, 'shanghai')(now+2s, 3, 'guangzhou') "
      "st1s2 VALUES (now, 10, '131028')(now+1s, 20, '132028')");
65 66
}

X
Xiaoyu Wang 已提交
67
// INSERT INTO
X
Xiaoyu Wang 已提交
68 69
//    tb1_name USING st1_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...)
//    tb2_name USING st2_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...)
X
Xiaoyu Wang 已提交
70 71
TEST_F(ParserInsertTest, autoCreateTableTest) {
  useDb("root", "test");
72

X
Xiaoyu Wang 已提交
73 74
  run("INSERT INTO st1s1 USING st1 TAGS(1, 'wxy', now) "
      "VALUES (now, 1, 'beijing')(now+1s, 2, 'shanghai')(now+2s, 3, 'guangzhou')");
75

X
Xiaoyu Wang 已提交
76 77
  run("INSERT INTO st1s1 USING st1 (tag1, tag2) TAGS(1, 'wxy') (ts, c1, c2) "
      "VALUES (now, 1, 'beijing')(now+1s, 2, 'shanghai')(now+2s, 3, 'guangzhou')");
78

X
Xiaoyu Wang 已提交
79 80
  run("INSERT INTO st1s1 (ts, c1, c2) USING st1 (tag1, tag2) TAGS(1, 'wxy') "
      "VALUES (now, 1, 'beijing')(now+1s, 2, 'shanghai')(now+2s, 3, 'guangzhou')");
81

X
Xiaoyu Wang 已提交
82 83 84
  run("INSERT INTO "
      "st1s1 USING st1 (tag1, tag2) TAGS(1, 'wxy') (ts, c1, c2) VALUES (now, 1, 'beijing') "
      "st1s2 (ts, c1, c2) USING st1 TAGS(2, 'abc', now) VALUES (now+1s, 2, 'shanghai')");
X
Xiaoyu Wang 已提交
85 86
}

X
Xiaoyu Wang 已提交
87
}  // namespace ParserTest