|
| 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 IoTDBTableFunctionIT { |
| 39 | + private static final String DATABASE_NAME = "test"; |
| 40 | + protected static final String[] createSqls = |
| 41 | + new String[] { |
| 42 | + "CREATE DATABASE " + DATABASE_NAME, |
| 43 | + "USE " + DATABASE_NAME, |
| 44 | + "CREATE TABLE table1(s1 INT32 FIELD)", |
| 45 | + "INSERT INTO table1(time,s1) values(1, 1)", |
| 46 | + "INSERT INTO table1(time,s1) values(2, 2)", |
| 47 | + "INSERT INTO table1(time,s1) values(3, 3)", |
| 48 | + "flush", |
| 49 | + "INSERT INTO table1(time,s1) values(4, 4)", |
| 50 | + "INSERT INTO table1(time,s1) values(5, 5)", |
| 51 | + "INSERT INTO table1(time,s1) values(6, 6)", |
| 52 | + "flush", |
| 53 | + "INSERT INTO table1(time,s1) values(7, 7)", |
| 54 | + "INSERT INTO table1(time,s1) values(8, 8)", |
| 55 | + "INSERT INTO table1(time,s1) values(9, 9)", |
| 56 | + "flush", |
| 57 | + }; |
| 58 | + |
| 59 | + @BeforeClass |
| 60 | + public static void setUp() { |
| 61 | + EnvFactory.getEnv().getConfig().getCommonConfig().setMaxTsBlockLineNumber(4); |
| 62 | + EnvFactory.getEnv().initClusterEnvironment(); |
| 63 | + prepareTableData(createSqls); |
| 64 | + } |
| 65 | + |
| 66 | + @AfterClass |
| 67 | + public static void tearDown() { |
| 68 | + EnvFactory.getEnv().cleanClusterEnvironment(); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void sessionGroupNode2SortNodeTest() { |
| 73 | + String[] expectedHeader = new String[] {"window_start", "window_end", "TIME", "s1"}; |
| 74 | + String[] retArray = |
| 75 | + new String[] { |
| 76 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.001Z,1,", |
| 77 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.002Z,2,", |
| 78 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.003Z,3,", |
| 79 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.004Z,4,", |
| 80 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.005Z,5,", |
| 81 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.006Z,6,", |
| 82 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.007Z,7,", |
| 83 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.008Z,8,", |
| 84 | + "1970-01-01T00:00:00.001Z,1970-01-01T00:00:00.009Z,1970-01-01T00:00:00.009Z,9,", |
| 85 | + }; |
| 86 | + tableResultSetEqualTest( |
| 87 | + "SELECT * FROM SESSION (DATA => (SELECT TIME, s1 FROM table1 ORDER BY TIME DESC LIMIT 10) ORDER BY TIME, GAP => 2s)", |
| 88 | + expectedHeader, |
| 89 | + retArray, |
| 90 | + DATABASE_NAME); |
| 91 | + } |
| 92 | +} |
0 commit comments