|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.relational.it.query.recent; |
| 21 | + |
| 22 | +import org.apache.iotdb.it.env.EnvFactory; |
| 23 | +import org.apache.iotdb.it.framework.IoTDBTestRunner; |
| 24 | +import org.apache.iotdb.itbase.category.TableClusterIT; |
| 25 | +import org.apache.iotdb.itbase.category.TableLocalStandaloneIT; |
| 26 | + |
| 27 | +import org.junit.AfterClass; |
| 28 | +import org.junit.BeforeClass; |
| 29 | +import org.junit.Test; |
| 30 | +import org.junit.experimental.categories.Category; |
| 31 | +import org.junit.runner.RunWith; |
| 32 | + |
| 33 | +import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData; |
| 34 | +import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest; |
| 35 | + |
| 36 | +@RunWith(IoTDBTestRunner.class) |
| 37 | +@Category({TableLocalStandaloneIT.class, TableClusterIT.class}) |
| 38 | +public class IoTDBComplexQueryIT { |
| 39 | + protected static final String DATABASE_NAME = "test_db"; |
| 40 | + protected static final String[] createSqls = |
| 41 | + new String[] { |
| 42 | + "CREATE DATABASE " + DATABASE_NAME, |
| 43 | + "USE " + DATABASE_NAME, |
| 44 | + "create table employees(department_id STRING TAG,remark STRING ATTRIBUTE,name TEXT FIELD,Gender TEXT FIELD,Status BOOLEAN FIELD,employee_id INT32 FIELD,salary DOUBLE FIELD,date_of_birth DATE FIELD,Contac_info string FIELD)", |
| 45 | + "create table departments(department_id STRING TAG,dep_description STRING ATTRIBUTE,dep_name TEXT FIELD,dep_phone TEXT FIELD,dep_status BOOLEAN FIELD,dep_member INT32 FIELD,employee_id INT32 FIELD)", |
| 46 | + "insert into employees(time, department_id, remark, name, gender, status, employee_id, salary, date_of_birth, contac_info) values(1, 'D001', 'good', 'Mary','Female', false, 1223, 5500.22, '1988-10-12', '133-1212-1234')", |
| 47 | + "insert into employees(time, department_id, remark, name, gender, status, employee_id, salary, date_of_birth, contac_info) values(2, 'D001', 'great', 'John', 'Male', true, 40012, 8822, '1985-06-15', '130-1002-1334')", |
| 48 | + "insert into employees(time, department_id, remark, name, gender, status, employee_id, salary, date_of_birth, contac_info) values(3, 'D002', 'excellent', 'Nancy', 'Female', true, 30112, 10002, '1983-08-15', '135-1302-1354')", |
| 49 | + "insert into employees(time, department_id, remark, name, gender, status, employee_id, salary, date_of_birth, contac_info) values(4, 'D002', 'good', 'Jack', 'Male', false, 12212, 7000, '1990-03-26', '138-1012-1353')", |
| 50 | + "insert into employees(time, department_id, remark, name, gender, status, employee_id, salary, date_of_birth, contac_info) values(5, 'D003', 'great', 'Linda', 'Female', false, 10212, 5600, '1995-06-15', '150-2003-1355')", |
| 51 | + "insert into departments(time, department_id, dep_description, dep_name, dep_phone, dep_status, dep_member,employee_id) values(1, 'D001', 'goods','销售部', '010-2271-2120', false, 1223,1223)", |
| 52 | + "insert into departments(time, department_id, dep_description, dep_name, dep_phone, dep_status, dep_member,employee_id) values(2, 'D001', 'goods','销售部', '010-2271-2120', false, 102, 40012)", |
| 53 | + "insert into departments(time, department_id, dep_description, dep_name, dep_phone, dep_status, dep_member,employee_id) values(3, 'D002', 'service','客服部', '010-2077-2520', true, 220, 30112)", |
| 54 | + "insert into departments(time, department_id, dep_description, dep_name, dep_phone, dep_status, dep_member,employee_id) values(4, 'D002', 'service','客服部', '010-2077-2520', true, 2012, 12212)", |
| 55 | + "insert into departments(time, department_id, dep_description, dep_name, dep_phone, dep_status, dep_member,employee_id) values(5, 'D003', 'IT','研发部', '010-3272-2310', true, 300, 10212)", |
| 56 | + "insert into departments(time, department_id, dep_description, dep_name, dep_phone, dep_status, dep_member,employee_id) values(6, 'D004', 'IT','人事部', '010-3272-2312', true, 300, 10200)", |
| 57 | + "FLUSH", |
| 58 | + "CLEAR ATTRIBUTE CACHE", |
| 59 | + }; |
| 60 | + |
| 61 | + @BeforeClass |
| 62 | + public static void setUp() throws Exception { |
| 63 | + EnvFactory.getEnv().initClusterEnvironment(); |
| 64 | + prepareTableData(createSqls); |
| 65 | + } |
| 66 | + |
| 67 | + @AfterClass |
| 68 | + public static void tearDown() throws Exception { |
| 69 | + EnvFactory.getEnv().cleanClusterEnvironment(); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void queryTest1() { |
| 74 | + // Look for the non-intersecting departments in the two tables |
| 75 | + String[] expectedHeader = new String[] {"department_id", "dep_name"}; |
| 76 | + String[] retArray = new String[] {"D004,人事部,"}; |
| 77 | + tableResultSetEqualTest( |
| 78 | + "select department_id, dep_name from departments where not exists(" |
| 79 | + + "select 1 from employees where employees.department_id = departments.department_id)", |
| 80 | + expectedHeader, |
| 81 | + retArray, |
| 82 | + DATABASE_NAME); |
| 83 | + } |
| 84 | +} |
0 commit comments