From 11facc06d4a5d6b8b7167110b16b9b977d54810d Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Mon, 22 Jul 2024 17:33:33 +0800 Subject: [PATCH 1/4] IoTDBFloatPrecisionIT --- .../it/IOTDBInsertWithTimeAtAnyIndexIT.java | 99 ++++ .../relational/it/db/it/IoTDBEncodingIT.java | 432 ++++++++++++++++++ .../it/db/it/IoTDBExecuteBatchIT.java | 206 +++++++++ .../it/db/it/IoTDBFloatPrecisionIT.java | 160 +++++++ .../it/db/it/IoTDBFlushQueryIT.java | 187 ++++++++ .../it/db/it/IoTDBInsertMultiPartitionIT.java | 71 +++ .../it/db/it/IoTDBInsertMultiRowIT.java | 193 ++++++++ .../relational/it/db/it/IoTDBInsertNaNIT.java | 199 ++++++++ .../it/db/it/IoTDBInsertNullIT.java | 207 +++++++++ .../it/db/it/IoTDBInsertWithoutTimeIT.java | 127 +++++ .../it/db/it/IoTDBMultiDeviceIT.java | 291 ++++++++++++ .../it/db/it/IoTDBPartialInsertionIT.java | 202 ++++++++ .../relational/it/db/it/IoTDBRecoverIT.java | 314 +++++++++++++ .../it/db/it/IoTDBRecoverUnclosedIT.java | 265 +++++++++++ .../relational/it/db/it/IoTDBRestartIT.java | 384 ++++++++++++++++ ...IoTDBSameMeasurementsDifferentTypesIT.java | 155 +++++++ .../aligned/IoTDBInsertAlignedValues2IT.java | 170 +++++++ .../aligned/IoTDBInsertAlignedValues3IT.java | 117 +++++ .../aligned/IoTDBInsertAlignedValues4IT.java | 74 +++ .../aligned/IoTDBInsertAlignedValuesIT.java | 404 ++++++++++++++++ .../db/it/schema/IoTDBAutoCreateSchemaIT.java | 272 +++++++++++ .../IoTDBCreateAlignedTimeseriesIT.java | 144 ++++++ .../it/schema/IoTDBCreateStorageGroupIT.java | 153 +++++++ .../db/it/schema/IoTDBCreateTimeseriesIT.java | 298 ++++++++++++ 24 files changed, 5124 insertions(+) create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBEncodingIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNaNIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateAlignedTimeseriesIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java new file mode 100644 index 0000000000000..84a7b783961f9 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IOTDBInsertWithTimeAtAnyIndexIT { + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().getConfig().getCommonConfig().setAutoCreateSchemaEnabled(true); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testInsertTimeAtAnyIndex() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.addBatch("insert into root.db.d1(s1, s2, time) aligned values (2, 3, 1)"); + statement.addBatch("insert into root.db.d1(s1, time, s2) aligned values (20, 10, 30)"); + statement.addBatch("insert into root.db.d1(`time`, s1, s2) aligned values (100, 200, 300)"); + statement.executeBatch(); + + try (ResultSet resultSet = statement.executeQuery("select s1 from root.db.d1")) { + assertTrue(resultSet.next()); + assertEquals(1, resultSet.getLong(1)); + assertEquals(2, resultSet.getDouble(2), 0.00001); + assertTrue(resultSet.next()); + assertEquals(10, resultSet.getLong(1)); + assertEquals(20, resultSet.getDouble(2), 0.00001); + assertTrue(resultSet.next()); + assertEquals(100, resultSet.getLong(1)); + assertEquals(200, resultSet.getDouble(2), 0.00001); + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testInsertMultiTime() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + try { + statement.addBatch( + "insert into root.db.d1(s1, s2, time, time) aligned values (2, 3, 1, 1)"); + statement.executeBatch(); + fail(); + } catch (SQLException e) { + // expected + } + + } catch (SQLException e) { + fail(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBEncodingIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBEncodingIT.java new file mode 100644 index 0000000000000..c6bc4662fbf9d --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBEncodingIT.java @@ -0,0 +1,432 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.isession.ISession; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class}) +@Ignore +public class IoTDBEncodingIT { + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + try (ISession session = EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) { + session.executeNonQueryStatement("CREATE DATABASE db1"); + } + } + + @After + public void tearDown() throws Exception { + try (ISession session = EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) { + session.executeNonQueryStatement("DROP DATABASE db1"); + } + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderTS_2DIFF() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=TS_2DIFF"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(3,1300)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,1400)"); + + statement.execute("flush"); + + int[] result = new int[] {1100, 1200, 1300, 1400}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderTS_2DIFFOutofOrder() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=TS_2DIFF"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(7,1000)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,2200)"); + statement.execute("flush"); + + int[] result = new int[] {1200, 1100, 2200, 1000}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderRLE() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=RLE"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(3,1300)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,1400)"); + statement.execute("flush"); + + int[] result = new int[] {1100, 1200, 1300, 1400}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderRLEOutofOrder() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=RLE"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(7,1000)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,2200)"); + statement.execute("flush"); + + int[] result = new int[] {1200, 1100, 2200, 1000}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderGORILLA() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=GORILLA"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(3,1300)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,1400)"); + statement.execute("flush"); + + int[] result = new int[] {1100, 1200, 1300, 1400}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderGORILLAOutofOrder() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=GORILLA"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(7,1000)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,2200)"); + statement.execute("flush"); + + int[] result = new int[] {1200, 1100, 2200, 1000}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderZIGZAG() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=ZIGZAG"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(3,1300)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,1400)"); + statement.execute("flush"); + + int[] result = new int[] {1100, 1200, 1300, 1400}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderZIGZAGOutofOrder() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=ZIGZAG"); + statement.execute("insert into root.db_0.tab0(time,salary) values(1,1200)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(2,1100)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(7,1000)"); + statement.execute("insert into root.db_0.tab0(time,salary) values(4,2200)"); + statement.execute("flush"); + + int[] result = new int[] {1200, 1100, 2200, 1000}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + int salary = resultSet.getInt("root.db_0.tab0.salary"); + assertEquals(result[index], salary); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderDictionary() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.city WITH DATATYPE=TEXT,ENCODING=DICTIONARY"); + statement.execute("insert into root.db_0.tab0(time,city) values(1,\"Nanjing\")"); + statement.execute("insert into root.db_0.tab0(time,city) values(2,\"Nanjing\")"); + statement.execute("insert into root.db_0.tab0(time,city) values(3,\"Beijing\")"); + statement.execute("insert into root.db_0.tab0(time,city) values(4,\"Shanghai\")"); + statement.execute("flush"); + + String[] result = new String[] {"Nanjing", "Nanjing", "Beijing", "Shanghai"}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + String city = resultSet.getString("root.db_0.tab0.city"); + assertEquals(result[index], city); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testSetTimeEncoderRegularAndValueEncoderDictionaryOutOfOrder() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.db_0.tab0.city WITH DATATYPE=TEXT,ENCODING=DICTIONARY"); + statement.execute("insert into root.db_0.tab0(time,city) values(1,\"Nanjing\")"); + statement.execute("insert into root.db_0.tab0(time,city) values(2,\"Nanjing\")"); + statement.execute("insert into root.db_0.tab0(time,city) values(4,\"Beijing\")"); + statement.execute("insert into root.db_0.tab0(time,city) values(3,\"Shanghai\")"); + statement.execute("flush"); + + String[] result = new String[] {"Nanjing", "Nanjing", "Shanghai", "Beijing"}; + try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) { + int index = 0; + while (resultSet.next()) { + String city = resultSet.getString("root.db_0.tab0.city"); + assertEquals(result[index], city); + index++; + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + public double SNR(int[] gd, int[] x, int length) { + double noise_power = 0, signal_power = 0; + for (int i = 0; i < length; i++) { + noise_power += (gd[i] - x[i]) * (gd[i] - x[i]); + signal_power += gd[i] * gd[i]; + } + if (noise_power == 0) { + return Double.POSITIVE_INFINITY; + } else { + return 10 * Math.log10(signal_power / noise_power); + } + } + + @Test + public void testDoublePrecision1() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.turbine1"); + statement.execute( + "create timeseries root.turbine1.d1.s1 with datatype=DOUBLE, encoding=PLAIN, compression=SNAPPY"); + + statement.execute("insert into root.turbine1.d1(timestamp,s1) values(1,1.2345678)"); + + ResultSet resultSet = statement.executeQuery("select * from root.turbine1.**"); + + String str = "1.2345678"; + while (resultSet.next()) { + assertEquals(str, resultSet.getString("root.turbine1.d1.s1")); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testDoublePrecision2() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.turbine1"); + statement.execute( + "create timeseries root.turbine1.d1.s1 with datatype=DOUBLE, encoding=RLE, compression=SNAPPY"); + + statement.execute("insert into root.turbine1.d1(timestamp,s1) values(1,1.2345678)"); + + ResultSet resultSet = statement.executeQuery("select * from root.turbine1.**"); + + String str = "1.23"; + while (resultSet.next()) { + assertEquals(str, resultSet.getString("root.turbine1.d1.s1")); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testFloatPrecision1() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.turbine1"); + statement.execute( + "create timeseries root.turbine1.d1.s1 with datatype=FLOAT, encoding=PLAIN, compression=SNAPPY"); + + statement.execute("insert into root.turbine1.d1(timestamp,s1) values(1,1.2345678)"); + + ResultSet resultSet = statement.executeQuery("select * from root.turbine1.**"); + + String str = "1.2345678"; + while (resultSet.next()) { + assertEquals(str, resultSet.getString("root.turbine1.d1.s1")); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void testFloatPrecision2() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.turbine1"); + statement.execute( + "create timeseries root.turbine1.d1.s1 with datatype=FLOAT, encoding=RLE, compression=SNAPPY"); + + statement.execute("insert into root.turbine1.d1(timestamp,s1) values(1,1.2345678)"); + + ResultSet resultSet = statement.executeQuery("select * from root.turbine1.**"); + + String str = "1.23"; + while (resultSet.next()) { + assertEquals(str, resultSet.getString("root.turbine1.d1.s1")); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java new file mode 100644 index 0000000000000..252d3bc0cacce --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.isession.ISession; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.category.RemoteIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) +public class IoTDBExecuteBatchIT { + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + try (ISession session = EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) { + session.executeNonQueryStatement("CREATE DATABASE ln"); + } + } + + @After + public void tearDown() throws Exception { + try (ISession session = EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) { + session.executeNonQueryStatement("DROP DATABASE ln"); + } + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testJDBCExecuteBatch() { + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.setFetchSize(5); + statement.addBatch( + "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,1.2)"); + statement.addBatch( + "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600001,2.3)"); + statement.addBatch("delete timeseries root.ln.wf01.wt01.**"); + statement.addBatch( + "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600002,3.4)"); + statement.executeBatch(); + ResultSet resultSet = statement.executeQuery("select * from root.ln.wf01.wt01"); + int count = 0; + + String[] timestamps = {"1509465600002"}; + String[] values = {"3.4"}; + + while (resultSet.next()) { + assertEquals(timestamps[count], resultSet.getString(ColumnHeaderConstant.TIME)); + assertEquals(values[count], resultSet.getString("root.ln.wf01.wt01.temperature")); + count++; + } + } catch (SQLException e) { + fail(e.getMessage()); + } + } + + @Test + public void testJDBCExecuteBatchForCreateMultiTimeSeriesPlan() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.setFetchSize(100); + statement.addBatch( + "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,1.2)"); + statement.addBatch( + "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600001,2.3)"); + statement.addBatch("delete timeseries root.ln.wf01.wt01.**"); + statement.addBatch( + "create timeseries root.turbine.d1.s1(s1) with datatype=boolean, encoding=plain , compression=snappy " + + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v3', 'attr2'='v4')"); + statement.addBatch( + "create timeseries root.turbine.d1.s2(s2) with datatype=float, encoding=rle, compression=uncompressed " + + "tags('tag1'='v5', 'tag2'='v6') attributes('attr1'='v7', 'attr2'='v8') "); + statement.addBatch( + "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600002,3.4)"); + statement.addBatch( + "create timeseries root.turbine.d1.s3 with datatype=boolean, encoding=rle"); + statement.executeBatch(); + statement.clearBatch(); + ResultSet resultSet = statement.executeQuery("select * from root.ln.wf01.wt01"); + String[] timestamps = {"1509465600002"}; + String[] values = {"3.4"}; + int count = 0; + while (resultSet.next()) { + assertEquals(timestamps[count], resultSet.getString(ColumnHeaderConstant.TIME)); + assertEquals(values[count], resultSet.getString("root.ln.wf01.wt01.temperature")); + count++; + } + ResultSet timeSeriesResultSetForS1 = + statement.executeQuery("SHOW TIMESERIES root.turbine.d1.s1"); + count = 0; + String[] key_s1 = { + ColumnHeaderConstant.TIMESERIES, + ColumnHeaderConstant.ALIAS, + ColumnHeaderConstant.DATABASE, + ColumnHeaderConstant.DATATYPE, + ColumnHeaderConstant.ENCODING, + ColumnHeaderConstant.COMPRESSION, + ColumnHeaderConstant.TAGS, + ColumnHeaderConstant.ATTRIBUTES + }; + String[] value_s1 = { + "root.turbine.d1.s1", + "s1", + "root.turbine", + "BOOLEAN", + "PLAIN", + "SNAPPY", + "{\"tag1\":\"v1\",\"tag2\":\"v2\"}", + "{\"attr2\":\"v3\",\"attr1\":\"v4\"}" + }; + + while (timeSeriesResultSetForS1.next()) { + assertEquals(value_s1[count], timeSeriesResultSetForS1.getString(key_s1[count])); + count++; + } + + ResultSet timeSeriesResultSetForS2 = + statement.executeQuery("SHOW TIMESERIES root.turbine.d1.s2"); + count = 0; + String[] key_s2 = { + ColumnHeaderConstant.TIMESERIES, + ColumnHeaderConstant.ALIAS, + ColumnHeaderConstant.DATABASE, + ColumnHeaderConstant.DATATYPE, + ColumnHeaderConstant.ENCODING, + ColumnHeaderConstant.COMPRESSION, + ColumnHeaderConstant.TAGS, + ColumnHeaderConstant.ATTRIBUTES + }; + String[] value_s2 = { + "root.turbine.d1.s2", + "s2", + "root.turbine", + "FLOAT", + "RLE", + "UNCOMPRESSED", + "{\"tag1\":\"v5\",\"tag2\":\"v6\"}", + "{\"attr2\":\"v7\",\"attr1\":\"v8\"}" + }; + while (timeSeriesResultSetForS2.next()) { + assertEquals(value_s2[count], timeSeriesResultSetForS2.getString(key_s2[count])); + count++; + } + + count = 0; + String[] key_s3 = { + ColumnHeaderConstant.TIMESERIES, + ColumnHeaderConstant.ALIAS, + ColumnHeaderConstant.DATABASE, + ColumnHeaderConstant.DATATYPE, + ColumnHeaderConstant.ENCODING, + ColumnHeaderConstant.COMPRESSION, + ColumnHeaderConstant.TAGS, + ColumnHeaderConstant.ATTRIBUTES + }; + String[] value_s3 = { + "root.turbine.d1.s3", "null", "root.turbine", "BOOLEAN", "RLE", "SNAPPY", "null", "null" + }; + ResultSet timeSeriesResultSetForS3 = + statement.executeQuery("SHOW TIMESERIES root.turbine.d1.s3"); + + while (timeSeriesResultSetForS3.next()) { + assertEquals(value_s3[count], timeSeriesResultSetForS3.getString(key_s3[count])); + count++; + } + } catch (SQLException e) { + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java new file mode 100644 index 0000000000000..7588bea97dc12 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.db.utils.MathUtils; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.category.RemoteIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.StringJoiner; + +import static org.apache.iotdb.db.utils.constant.TestConstant.TIMESTAMP_STR; +import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) +public class IoTDBFloatPrecisionIT { + + private static final String INSERT_TEMPLATE_SQL = + "insert into %s(id1,Time,%s) values(%s,%d,%s)"; + private static List sqls = new ArrayList<>(); + private static final int TIMESTAMP = 10; + private static final String VALUE = "1.2345678901"; + private static final float DELTA_FLOAT = 0.0000001f; + private static final double DELTA_DOUBLE = 0.0000001d; + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + initCreateSQLStatement(); + + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void initCreateSQLStatement() { + sqls.add("CREATE DATABASE test"); + StringJoiner createTableSql = + new StringJoiner(",", "CREATE TABLE vehicle (id1 string id, ", ")"); + for (int i = 0; i < 10; i++) { + createTableSql.add("s" + i + "f" + " FLOAT measurement"); + createTableSql.add("s" + i + "d" + " DOUBLE measurement"); + } + sqls.add("USE \"test\""); + sqls.add(createTableSql.toString()); + for (int i = 0; i < 10; i++) { + sqls.add( + String.format(INSERT_TEMPLATE_SQL, "vehicle", "s" + i + "f", "\'fd\'", TIMESTAMP, VALUE)); + sqls.add( + String.format(INSERT_TEMPLATE_SQL, "vehicle", "s" + i + "d", "\'fd\'", TIMESTAMP, VALUE)); + } + } + + private static void insertData() { + try (Connection connection = EnvFactory.getEnv().getConnection(TABLE_SQL_DIALECT); + Statement statement = connection.createStatement()) { + + for (String sql : sqls) { + System.out.println(sql); + statement.execute(sql); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void selectAllSQLTest() { + try (Connection connection = EnvFactory.getEnv().getConnection(TABLE_SQL_DIALECT); + Statement statement = connection.createStatement()) { + statement.execute("USE \"test\""); + int cnt; + try (ResultSet resultSet = statement.executeQuery("select * from vehicle")) { + assertNotNull(resultSet); + cnt = 0; + while (resultSet.next()) { + assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR)); + for (int i = 0; i < 10; i++) { + assertEquals( + MathUtils.roundWithGivenPrecision(Float.parseFloat(VALUE), i), + resultSet.getFloat("s" + i + "f"), + DELTA_FLOAT); + assertEquals( + MathUtils.roundWithGivenPrecision(Double.parseDouble(VALUE), i), + resultSet.getDouble("s" + i + "d"), + DELTA_DOUBLE); + } + cnt++; + } + assertEquals(1, cnt); + } + + statement.execute("flush"); + try (ResultSet resultSet = statement.executeQuery("select * from vehicle")) { + cnt = 0; + while (resultSet.next()) { + assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR)); + for (int i = 0; i < 10; i++) { + BigDecimal b = new BigDecimal(VALUE); + assertEquals( + b.setScale(i, RoundingMode.HALF_UP).floatValue(), + resultSet.getFloat("s" + i + "f"), + DELTA_FLOAT); + assertEquals( + b.setScale(i, RoundingMode.HALF_UP).doubleValue(), + resultSet.getDouble("s" + i + "d"), + DELTA_DOUBLE); + } + cnt++; + } + assertEquals(1, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java new file mode 100644 index 0000000000000..a746f82b34579 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBFlushQueryIT { + + private static String[] sqls = + new String[] { + "CREATE DATABASE root.vehicle.d0", + "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", + "insert into root.vehicle.d0(timestamp,s0) values(1,101)", + "insert into root.vehicle.d0(timestamp,s0) values(2,198)", + "insert into root.vehicle.d0(timestamp,s0) values(100,99)", + "insert into root.vehicle.d0(timestamp,s0) values(101,99)", + "insert into root.vehicle.d0(timestamp,s0) values(102,80)", + "insert into root.vehicle.d0(timestamp,s0) values(103,99)", + "insert into root.vehicle.d0(timestamp,s0) values(104,90)", + "insert into root.vehicle.d0(timestamp,s0) values(105,99)", + "insert into root.vehicle.d0(timestamp,s0) values(106,99)", + "flush", + "insert into root.vehicle.d0(timestamp,s0) values(2,10000)", + "insert into root.vehicle.d0(timestamp,s0) values(50,10000)", + "insert into root.vehicle.d0(timestamp,s0) values(1000,22222)", + }; + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void insertData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + for (String sql : sqls) { + statement.execute(sql); + } + } catch (Exception e) { + fail("insertData failed."); + } + } + + @Test + public void selectAllSQLTest() { + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + try (ResultSet resultSet = statement.executeQuery("SELECT * FROM root.**"); ) { + int cnt = 0; + while (resultSet.next()) { + cnt++; + } + } + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @Test + public void testFlushGivenGroup() { + String insertTemplate = + "INSERT INTO root.group%d(timestamp, s1, s2, s3) VALUES (%d, %d, %f, %s)"; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.group1"); + statement.execute("CREATE DATABASE root.group2"); + statement.execute("CREATE DATABASE root.group3"); + + for (int i = 1; i <= 3; i++) { + for (int j = 10; j < 20; j++) { + statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j)); + } + } + statement.execute("FLUSH"); + + for (int i = 1; i <= 3; i++) { + for (int j = 0; j < 10; j++) { + statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j)); + } + } + statement.execute("FLUSH root.group1"); + statement.execute("FLUSH root.group2,root.group3"); + + for (int i = 1; i <= 3; i++) { + for (int j = 0; j < 30; j++) { + statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j)); + } + } + statement.execute("FLUSH root.group1 TRUE"); + statement.execute("FLUSH root.group2,root.group3 FALSE"); + + int i = 0; + try (ResultSet resultSet = + statement.executeQuery("SELECT * FROM root.group1,root.group2,root" + ".group3")) { + while (resultSet.next()) { + i++; + } + } + assertEquals(30, i); + + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @Test + public void testFlushGivenGroupNoData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.nodatagroup1"); + statement.execute("CREATE DATABASE root.nodatagroup2"); + statement.execute("CREATE DATABASE root.nodatagroup3"); + statement.execute("FLUSH root.nodatagroup1"); + statement.execute("FLUSH root.nodatagroup2"); + statement.execute("FLUSH root.nodatagroup3"); + statement.execute("FLUSH root.nodatagroup1, root.nodatagroup2"); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @Test + @Ignore + public void testFlushNotExistGroupNoData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.noexist.nodatagroup1"); + try { + statement.execute( + "FLUSH root.noexist.nodatagroup1,root.notExistGroup1,root.notExistGroup2"); + } catch (SQLException sqe) { + String expectedMsg = + "322: 322: storageGroup root.notExistGroup1,root.notExistGroup2 does not exist"; + sqe.printStackTrace(); + assertTrue(sqe.getMessage().contains(expectedMsg)); + } + } catch (Exception e) { + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java new file mode 100644 index 0000000000000..234e1eb2479e4 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.category.RemoteIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.Statement; + +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) +public class IoTDBInsertMultiPartitionIT { + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getDataNodeCommonConfig() + .setWriteMemoryProportion("10000000:1"); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testInsertMultiPartition() { + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg.d1(time,s1) values(1,2)"); + statement.execute("flush"); + statement.execute("insert into root.sg.d1(time,s1) values(2,2)"); + statement.execute("insert into root.sg.d1(time,s1) values(604800001,2)"); + statement.execute("flush"); + } catch (Exception e) { + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java new file mode 100644 index 0000000000000..686a5dcef4f71 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.rpc.TSStatusCode; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * @Author: Architect @Date: 2021-03-30 18:36 @Description: This class is initially intend to test + * the issue of IOTDB-924 + */ +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBInsertMultiRowIT { + private static List sqls = new ArrayList<>(); + private static Connection connection; + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().getConfig().getCommonConfig().setMaxInnerCompactionCandidateFileNum(2); + EnvFactory.getEnv().initClusterEnvironment(); + initCreateSQLStatement(); + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + close(); + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void close() { + if (Objects.nonNull(connection)) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static void initCreateSQLStatement() { + sqls.add("CREATE DATABASE root.t1"); + sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN"); + sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE"); + } + + private static void insertData() throws ClassNotFoundException, SQLException { + connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + + for (String sql : sqls) { + statement.execute(sql); + } + + statement.close(); + } + + @Test + public void testInsertMultiRow() throws SQLException { + Statement st0 = connection.createStatement(); + st0.execute("insert into root.t1.wf01.wt01(timestamp, status) values (1, true)"); + st0.execute("insert into root.t1.wf01.wt01(timestamp, status) values (2, true),(3, false)"); + st0.execute( + "insert into root.t1.wf01.wt01(timestamp, status) values (4, true),(5, true),(6, false)"); + + st0.execute( + "insert into root.t1.wf01.wt01(timestamp, temperature, status) values (7, 15.3, true)"); + st0.execute( + "insert into root.t1.wf01.wt01(timestamp, temperature, status) values (8, 18.3, false),(9, 23.1, false)"); + st0.execute( + "insert into root.t1.wf01.wt01(timestamp, temperature, status) values (10, 22.3, true),(11, 18.8, false),(12, 24.4, true)"); + st0.close(); + + Statement st1 = connection.createStatement(); + ResultSet rs1 = st1.executeQuery("select count(status) from root.t1.wf01.wt01"); + rs1.next(); + long countStatus = rs1.getLong(1); + assertEquals(countStatus, 12L); + + ResultSet rs2 = st1.executeQuery("select count(temperature) from root.t1.wf01.wt01"); + rs2.next(); + long countTemperature = rs2.getLong(1); + assertEquals(countTemperature, 6L); + + st1.close(); + } + + @Test(expected = Exception.class) + public void testInsertWithTimesColumns() throws SQLException { + Statement st1 = connection.createStatement(); + st1.execute("insert into root.t1.wf01.wt01(timestamp) values(1)"); + } + + @Test + public void testInsertMultiRowWithMisMatchDataType() { + try { + Statement st1 = connection.createStatement(); + st1.execute("insert into root.t1.wf01.wt01(timestamp, s1) values(1, 1.0), (2, 'hello')"); + fail(); + } catch (SQLException e) { + assertTrue( + e.getMessage().contains(Integer.toString(TSStatusCode.METADATA_ERROR.getStatusCode()))); + } + } + + @Test + public void testInsertMultiRowWithNull() { + try (Statement st1 = connection.createStatement()) { + st1.execute( + "insert into root.t1.d99.wt01(timestamp, s1, s2) values(100, null, 1), (101, null, 2)"); + fail(); + } catch (SQLException e) { + assertTrue( + e.getMessage().contains(Integer.toString(TSStatusCode.METADATA_ERROR.getStatusCode()))); + } + try (Statement st2 = connection.createStatement()) { + st2.execute("CREATE TIMESERIES root.t1.d1.s1 WITH DATATYPE=double, ENCODING=PLAIN;"); + st2.execute( + "INSERT INTO root.t1.d1(timestamp, s1) VALUES (6, 10),(7,12),(8,14),(9,160),(10,null),(11,58)"); + } catch (SQLException e) { + fail(); + } + } + + @Test + public void testInsertMultiRowWithWrongTimestampPrecision() { + try (Statement st1 = connection.createStatement()) { + st1.execute( + "insert into root.t1.d99.wt01(timestamp, s1, s2) values(1618283005586000, 1, 1), (1618283005586001, 1, 2)"); + fail(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("Current system timestamp precision is ms")); + } + } + + @Test + public void testInsertMultiRowWithMultiTimePartition() throws Exception { + try (Statement st1 = connection.createStatement()) { + st1.execute("insert into root.sg1.d1(time,s1) values(604800010,1)"); + st1.execute("flush"); + st1.execute("insert into root.sg1.d1(time,s1) values(604799990,1), (604800001,1)"); + st1.execute("flush"); + ResultSet rs1 = st1.executeQuery("select s1 from root.sg1.d1"); + assertTrue(rs1.next()); + assertEquals(604799990, rs1.getLong("Time")); + assertTrue(rs1.next()); + assertEquals(604800001, rs1.getLong("Time")); + assertTrue(rs1.next()); + assertEquals(604800010, rs1.getLong("Time")); + assertFalse(rs1.next()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNaNIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNaNIT.java new file mode 100644 index 0000000000000..bb597bfc3d27a --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNaNIT.java @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.category.RemoteIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.iotdb.db.utils.constant.TestConstant.TIMESTAMP_STR; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + * + *

This test stores NaN Values and retrieves them via SQL Interface. + */ +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) +public class IoTDBInsertNaNIT { + + private static final String CREATE_TEMPLATE_SQL = + "CREATE TIMESERIES root.vehicle.%s.%s WITH DATATYPE=%s, ENCODING=%s, 'MAX_POINT_NUMBER'='%d'"; + private static final String INSERT_TEMPLATE_SQL = + "insert into root.vehicle.%s(timestamp,%s) values(%d,%s)"; + private static final String INSERT_BRAND_NEW_TEMPLATE_SQL = + "insert into root.cycle.%s(timestamp,%s) values(%d,%s)"; + private static List sqls = new ArrayList<>(); + private static final int TIMESTAMP = 10; + private static final String VALUE = "NaN"; + private static final float DELTA_FLOAT = 0.0000001f; + private static final double DELTA_DOUBLE = 0.0000001d; + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + initCreateSQLStatement(); + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void initCreateSQLStatement() { + sqls.add("CREATE DATABASE root.happy"); + sqls.add("CREATE DATABASE root.cycle"); + sqls.add("CREATE DATABASE root.vehicle.f0"); + sqls.add("CREATE DATABASE root.vehicle.d0"); + for (int i = 0; i < 10; i++) { + sqls.add(String.format(CREATE_TEMPLATE_SQL, "f0", "s" + i + "rle", "FLOAT", "RLE", i)); + sqls.add(String.format(CREATE_TEMPLATE_SQL, "f0", "s" + i + "2f", "FLOAT", "TS_2DIFF", i)); + sqls.add(String.format(CREATE_TEMPLATE_SQL, "d0", "s" + i + "rle", "DOUBLE", "RLE", i)); + sqls.add(String.format(CREATE_TEMPLATE_SQL, "d0", "s" + i + "2f", "DOUBLE", "TS_2DIFF", i)); + } + for (int i = 0; i < 10; i++) { + sqls.add(String.format(INSERT_TEMPLATE_SQL, "f0", "s" + i + "rle", TIMESTAMP, VALUE)); + sqls.add(String.format(INSERT_TEMPLATE_SQL, "f0", "s" + i + "2f", TIMESTAMP, VALUE)); + sqls.add(String.format(INSERT_TEMPLATE_SQL, "d0", "s" + i + "rle", TIMESTAMP, VALUE)); + sqls.add(String.format(INSERT_TEMPLATE_SQL, "d0", "s" + i + "2f", TIMESTAMP, VALUE)); + } + } + + private static void insertData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + for (String sql : sqls) { + statement.execute(sql); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void selectAllSQLTest() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + int cnt; + try (ResultSet resultSet = statement.executeQuery("select * from root.vehicle.*")) { + assertNotNull(resultSet); + cnt = 0; + while (resultSet.next()) { + assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR)); + for (int i = 0; i < 10; i++) { + assertEquals( + Float.parseFloat(VALUE), + resultSet.getFloat(String.format("root.vehicle.%s.%s", "f0", "s" + i + "rle")), + DELTA_FLOAT); + assertEquals( + Float.parseFloat(VALUE), + resultSet.getFloat(String.format("root.vehicle.%s.%s", "f0", "s" + i + "2f")), + DELTA_FLOAT); + assertEquals( + Double.parseDouble(VALUE), + resultSet.getDouble(String.format("root.vehicle.%s.%s", "d0", "s" + i + "rle")), + DELTA_DOUBLE); + assertEquals( + Double.parseDouble(VALUE), + resultSet.getDouble(String.format("root.vehicle.%s.%s", "d0", "s" + i + "2f")), + DELTA_DOUBLE); + } + cnt++; + } + assertEquals(1, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectTest() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TIMESERIES root.happy.device1.sensor1.temperature WITH DATATYPE=DOUBLE, ENCODING=RLE"); + statement.execute( + "INSERT INTO root.happy.device1.sensor1(timestamp,temperature) values(7925, NaN)"); + int cnt; + try (ResultSet resultSet = + statement.executeQuery("select * from root.happy.device1.sensor1")) { + assertNotNull(resultSet); + cnt = 0; + while (resultSet.next()) { + assertEquals(7925 + "", resultSet.getString(TIMESTAMP_STR)); + assertEquals( + Double.parseDouble(VALUE), + resultSet.getDouble("root.happy.device1.sensor1.temperature"), + DELTA_DOUBLE); + cnt++; + } + assertEquals(1, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testNaNValue() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format(INSERT_BRAND_NEW_TEMPLATE_SQL, "d0", "s0" + "2f", TIMESTAMP, VALUE)); + boolean exist = false; + try (ResultSet resultSet = statement.executeQuery("show timeseries")) { + assertNotNull(resultSet); + while (resultSet.next()) { + if ((resultSet.getString(ColumnHeaderConstant.TIMESERIES)).contains("root.cycle.d0.s0")) { + exist = true; + } + } + } + assertTrue(exist); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java new file mode 100644 index 0000000000000..2e51000a96554 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java @@ -0,0 +1,207 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.category.RemoteIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Types; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) +public class IoTDBInsertNullIT { + private static final List sqls = new ArrayList<>(); + private static Connection connection; + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + initCreateSQLStatement(); + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + close(); + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void close() { + if (Objects.nonNull(connection)) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static void initCreateSQLStatement() { + sqls.add("CREATE DATABASE root.sg"); + sqls.add("CREATE TIMESERIES root.sg.d1.s1 WITH DATATYPE=BOOLEAN"); + sqls.add("CREATE TIMESERIES root.sg.d1.s2 WITH DATATYPE=FLOAT"); + sqls.add("CREATE TIMESERIES root.sg.d1.s3 WITH DATATYPE=INT32"); + sqls.add("CREATE ALIGNED TIMESERIES root.sg.d2(s1 BOOLEAN,s2 FLOAT,s3 INT32)"); + } + + private static void insertData() throws SQLException { + connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + + for (String sql : sqls) { + statement.execute(sql); + } + + statement.close(); + } + + @Test + public void testInsertNull() { + String[] retArray = + new String[] { + "1,null,1.0,1,", "2,true,null,2,", "3,true,3.0,null,", + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg.d1(time,s1,s2,s3) values(1,null,1.0,1)"); + statement.execute("insert into root.sg.d1(time,s1,s2,s3) values(2,true,null,2)"); + statement.execute("insert into root.sg.d1(time,s1,s2,s3) values(3,true,3.0,null)"); + + try (ResultSet resultSet = statement.executeQuery("select * from root.sg.d1")) { + assertNotNull(resultSet); + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + List actualIndexToExpectedIndexList = + checkHeader( + resultSetMetaData, + "Time,root.sg.d1.s1,root.sg.d1.s2,root.sg.d1.s3", + new int[] { + Types.TIMESTAMP, Types.BOOLEAN, Types.FLOAT, Types.INTEGER, + }); + + int cnt = 0; + while (resultSet.next()) { + String[] expectedStrings = retArray[cnt].split(","); + StringBuilder expectedBuilder = new StringBuilder(); + StringBuilder actualBuilder = new StringBuilder(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + actualBuilder.append(resultSet.getString(i)).append(","); + expectedBuilder + .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)]) + .append(","); + } + assertEquals(expectedBuilder.toString(), actualBuilder.toString()); + cnt++; + } + assertEquals(3, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testInsertAlignedNull() { + String[] retArray = + new String[] { + "1,null,1.0,1,", "2,true,null,2,", "3,true,3.0,null,", + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg.d2(time,s1,s2,s3) aligned values(1,null,1.0,1)"); + statement.execute("insert into root.sg.d2(time,s1,s2,s3) aligned values(2,true,null,2)"); + statement.execute("insert into root.sg.d2(time,s1,s2,s3) aligned values(3,true,3.0,null)"); + + try (ResultSet resultSet = statement.executeQuery("select * from root.sg.d2")) { + assertNotNull(resultSet); + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + List actualIndexToExpectedIndexList = + checkHeader( + resultSetMetaData, + "Time,root.sg.d2.s1,root.sg.d2.s2,root.sg.d2.s3", + new int[] { + Types.TIMESTAMP, Types.BOOLEAN, Types.FLOAT, Types.INTEGER, + }); + + int cnt = 0; + while (resultSet.next()) { + String[] expectedStrings = retArray[cnt].split(","); + StringBuilder expectedBuilder = new StringBuilder(); + StringBuilder actualBuilder = new StringBuilder(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + actualBuilder.append(resultSet.getString(i)).append(","); + expectedBuilder + .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)]) + .append(","); + } + assertEquals(expectedBuilder.toString(), actualBuilder.toString()); + cnt++; + } + assertEquals(3, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + private List checkHeader( + ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] expectedTypes) + throws SQLException { + String[] expectedHeaders = expectedHeaderStrings.split(","); + Map expectedHeaderToTypeIndexMap = new HashMap<>(); + for (int i = 0; i < expectedHeaders.length; ++i) { + expectedHeaderToTypeIndexMap.put(expectedHeaders[i], i); + } + + List actualIndexToExpectedIndexList = new ArrayList<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + Integer typeIndex = expectedHeaderToTypeIndexMap.get(resultSetMetaData.getColumnName(i)); + assertNotNull(typeIndex); + assertEquals(expectedTypes[typeIndex], resultSetMetaData.getColumnType(i)); + actualIndexToExpectedIndexList.add(typeIndex); + } + return actualIndexToExpectedIndexList; + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java new file mode 100644 index 0000000000000..ac5ef5786d24b --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Arrays; +import java.util.List; + +import static org.apache.iotdb.db.it.utils.TestUtils.assertNonQueryTestFail; +import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBInsertWithoutTimeIT { + + private static final List sqls = + Arrays.asList( + "CREATE DATABASE root.sg1", + "CREATE TIMESERIES root.sg1.d1.s1 INT64", + "CREATE TIMESERIES root.sg1.d1.s2 FLOAT", + "CREATE TIMESERIES root.sg1.d1.s3 TEXT"); + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + createTimeseries(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private void createTimeseries() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + for (String sql : sqls) { + statement.execute(sql); + } + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testInsertWithoutTime() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg1.d1(s1, s2, s3) values (1, 1, '1')"); + Thread.sleep(1); + statement.execute("insert into root.sg1.d1(s2, s1, s3) values (2, 2, '2')"); + Thread.sleep(1); + statement.execute("insert into root.sg1.d1(s3, s2, s1) values ('3', 3, 3)"); + Thread.sleep(1); + statement.execute("insert into root.sg1.d1(s1) values (1)"); + statement.execute("insert into root.sg1.d1(s2) values (2)"); + statement.execute("insert into root.sg1.d1(s3) values ('3')"); + } catch (SQLException | InterruptedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + String expectedHeader = "count(root.sg1.d1.s1),count(root.sg1.d1.s2),count(root.sg1.d1.s3),"; + String[] retArray = new String[] {"4,4,4,"}; + resultSetEqualTest( + "select count(s1), count(s2), count(s3) from root.sg1.d1", expectedHeader, retArray); + } + + @Test + public void testInsertWithoutValueColumns() { + assertNonQueryTestFail( + "insert into root.sg1.d1(time) values (1)", + "InsertStatement should contain at least one measurement"); + } + + @Test + public void testInsertMultiRow() { + assertNonQueryTestFail( + "insert into root.sg1.d1(s3) values ('1'), ('2')", + "need timestamps when insert multi rows"); + assertNonQueryTestFail( + "insert into root.sg1.d1(s1, s2) values (1, 1), (2, 2)", + "need timestamps when insert multi rows"); + } + + @Test + public void testInsertWithMultiTimesColumns() { + assertNonQueryTestFail( + "insert into root.sg1.d1(time, time) values (1, 1)", + "One row should only have one time value"); + assertNonQueryTestFail( + "insert into root.sg1.d1(time, s1, time) values (1, 1, 1)", + "One row should only have one time value"); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java new file mode 100644 index 0000000000000..f154bd2bc1701 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.constant.TestConstant; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBMultiDeviceIT { + + @Before + public void setUp() throws Exception { + // use small page + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setMaxNumberOfPointsInPage(100) + .setPageSizeInByte(1024 * 15) + .setGroupSizeInByte(1024 * 100) + .setMemtableSizeThreshold(1024 * 100) + .setPartitionInterval(100) + .setQueryThreadCount(2) + .setCompressor("LZ4"); + + EnvFactory.getEnv().initClusterEnvironment(); + + insertData(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void insertData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + for (String sql : TestConstant.createSql) { + statement.addBatch(sql); + } + + statement.addBatch("CREATE DATABASE root.fans"); + statement.addBatch("CREATE TIMESERIES root.fans.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE"); + statement.addBatch("CREATE TIMESERIES root.fans.d1.s0 WITH DATATYPE=INT32, ENCODING=RLE"); + statement.addBatch("CREATE TIMESERIES root.fans.d2.s0 WITH DATATYPE=INT32, ENCODING=RLE"); + statement.addBatch("CREATE TIMESERIES root.fans.d3.s0 WITH DATATYPE=INT32, ENCODING=RLE"); + statement.addBatch("CREATE TIMESERIES root.car.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE"); + statement.addBatch("CREATE TIMESERIES root.car.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE"); + statement.addBatch("CREATE TIMESERIES root.car.d2.s1 WITH DATATYPE=INT64, ENCODING=RLE"); + + // insert of data time range :0-100 into fans + for (int time = 0; time < 100; time++) { + + String sql = + String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + } + + // insert large amount of data time range : 1370 ~ 2400 + for (int time = 1370; time < 2400; time++) { + + String sql = + String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + } + + // insert large amount of data time range : 300 ~ 1360 + for (int time = 300; time < 1360; time++) { + // System.out.println("===" + time); + String sql = + String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + } + + statement.addBatch("flush"); + + // unsequential data, memory data + for (int time = 1000; time < 1100; time++) { + + String sql = + String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + } + + // sequential data, memory data + for (int time = 20000; time < 20100; time++) { + + String sql = + String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + statement.addBatch(sql); + sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + statement.addBatch(sql); + } + statement.executeBatch(); + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testMultiDeviceQueryAndDelete() { + testSelectAll(); + testSelectAfterDelete(); + } + + private void testSelectAll() { + String selectSql = "select * from root.**"; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + int cnt = 0; + long before = -1; + while (resultSet.next()) { + long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + if (cur <= before) { + fail("time order wrong!"); + } + before = cur; + cnt++; + } + assertEquals(2290, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + private void testSelectAfterDelete() { + String selectSql = "select * from root.**"; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + statement.execute("DELETE FROM root.fans.** WHERE time <= 100"); + statement.execute("DELETE FROM root.car.** WHERE time <= 100"); + statement.execute("DELETE FROM root.fans.** WHERE time >= 20050 and time < 20100"); + statement.execute("DELETE FROM root.car.** WHERE time >= 20050 and time < 20100"); + + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + int cnt = 0; + long before = -1; + while (resultSet.next()) { + long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + if (cur <= before) { + fail("time order wrong!"); + } + before = cur; + cnt++; + } + assertEquals(2140, cnt); + } + + statement.execute("DELETE FROM root.fans.** WHERE time <= 20000"); + statement.execute("DELETE FROM root.car.** WHERE time <= 20000"); + + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + int cnt = 0; + long before = -1; + while (resultSet.next()) { + long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + if (cur <= before) { + fail("time order wrong!"); + } + before = cur; + cnt++; + } + assertEquals(49, cnt); + } + + statement.execute("DELETE FROM root.** WHERE time >= 20000"); + + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + int cnt = 0; + long before = -1; + while (resultSet.next()) { + long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + if (cur <= before) { + fail("time order wrong!"); + } + before = cur; + cnt++; + } + assertEquals(0, cnt); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java new file mode 100644 index 0000000000000..28ac8a17baf61 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.isession.ISession; +import org.apache.iotdb.isession.SessionDataSet; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.apache.tsfile.enums.TSDataType; +import org.apache.tsfile.file.metadata.enums.CompressionType; +import org.apache.tsfile.file.metadata.enums.TSEncoding; +import org.apache.tsfile.read.common.RowRecord; +import org.apache.tsfile.write.record.Tablet; +import org.apache.tsfile.write.schema.IMeasurementSchema; +import org.apache.tsfile.write.schema.MeasurementSchema; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBPartialInsertionIT { + private final Logger logger = LoggerFactory.getLogger(IoTDBPartialInsertionIT.class); + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().getConfig().getCommonConfig().setAutoCreateSchemaEnabled(false); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testPartialInsertionAllFailed() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + statement.execute("CREATE DATABASE root.sg1"); + + try { + statement.execute("INSERT INTO root.sg1(timestamp, s0) VALUES (1, 1)"); + fail(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("Path [root.sg1.s0] does not exist")); + } + } + } + + @Test + public void testPartialInsertionRestart() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + statement.execute("CREATE DATABASE root.sg"); + statement.execute("CREATE TIMESERIES root.sg.d1.s1 datatype=text"); + statement.execute("CREATE TIMESERIES root.sg.d1.s2 datatype=double"); + + try { + statement.execute("INSERT INTO root.sg.d1(time,s1,s2) VALUES(100,'test','test')"); + } catch (SQLException e) { + // ignore + } + } + + // TODO: replace restartDaemon() with new methods in Env. + /* + long time = 0; + try { + EnvironmentUtils.restartDaemon(); + StorageEngine.getInstance().recover(); + // wait for recover + while (!StorageEngine.getInstance().isAllSgReady()) { + Thread.sleep(500); + time += 500; + if (time > 10000) { + logger.warn("wait too long in restart, wait for: " + time / 1000 + "s"); + } + } + } catch (Exception e) { + fail(e.getMessage()); + } + */ + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg.d1")) { + assertNotNull(resultSet); + int cnt = 0; + while (resultSet.next()) { + cnt++; + assertEquals("test", resultSet.getString("root.sg.d1.s1")); + } + assertEquals(1, cnt); + } + try (ResultSet resultSet = statement.executeQuery("SELECT s2 FROM root.sg.d1")) { + assertNotNull(resultSet); + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testPartialInsertTablet() { + try (ISession session = EnvFactory.getEnv().getSessionConnection()) { + session.createTimeseries( + "root.sg1.d1.s1", TSDataType.INT64, TSEncoding.PLAIN, CompressionType.SNAPPY); + session.createTimeseries( + "root.sg1.d1.s2", TSDataType.INT64, TSEncoding.PLAIN, CompressionType.SNAPPY); + List schemaList = new ArrayList<>(); + schemaList.add(new MeasurementSchema("s1", TSDataType.INT64)); + schemaList.add(new MeasurementSchema("s2", TSDataType.INT64)); + schemaList.add(new MeasurementSchema("s3", TSDataType.INT64)); + Tablet tablet = new Tablet("root.sg1.d1", schemaList, 300); + long timestamp = 0; + for (long row = 0; row < 100; row++) { + int rowIndex = tablet.rowSize++; + tablet.addTimestamp(rowIndex, timestamp); + for (int s = 0; s < 3; s++) { + long value = timestamp; + tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value); + } + timestamp++; + } + timestamp = System.currentTimeMillis(); + for (long row = 0; row < 100; row++) { + int rowIndex = tablet.rowSize++; + tablet.addTimestamp(rowIndex, timestamp); + for (int s = 0; s < 3; s++) { + long value = timestamp; + tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value); + } + timestamp++; + } + try { + session.insertTablet(tablet); + } catch (Exception e) { + if (!e.getMessage().contains("507")) { + fail(e.getMessage()); + } + } + try (SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM root.sg1.d1")) { + assertEquals(dataSet.getColumnNames().size(), 3); + assertEquals(dataSet.getColumnNames().get(0), "Time"); + assertEquals(dataSet.getColumnNames().get(1), "root.sg1.d1.s1"); + assertEquals(dataSet.getColumnNames().get(2), "root.sg1.d1.s2"); + int cnt = 0; + while (dataSet.hasNext()) { + RowRecord rowRecord = dataSet.next(); + long time = rowRecord.getTimestamp(); + assertEquals(time, rowRecord.getFields().get(0).getLongV()); + assertEquals(time, rowRecord.getFields().get(1).getLongV()); + cnt++; + } + Assert.assertEquals(200, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java new file mode 100644 index 0000000000000..c6f28609ada18 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java @@ -0,0 +1,314 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.cluster.env.AbstractEnv; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Locale; + +import static org.apache.iotdb.db.utils.constant.TestConstant.count; +import static org.apache.iotdb.db.utils.constant.TestConstant.maxValue; +import static org.apache.iotdb.db.utils.constant.TestConstant.minTime; +import static org.apache.iotdb.db.utils.constant.TestConstant.minValue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRecoverIT { + + private static final Logger logger = LoggerFactory.getLogger(IoTDBRecoverIT.class); + + private static final String TIMESTAMP_STR = "Time"; + private static final String TEMPERATURE_STR = "root.ln.wf01.wt01.temperature"; + private static final String[] creationSqls = + new String[] { + "CREATE DATABASE root.vehicle.d0", + "CREATE DATABASE root.vehicle.d1", + "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN", + "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN" + }; + private static final String[] dataSet2 = + new String[] { + "CREATE DATABASE root.ln.wf01.wt01", + "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", + "CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=PLAIN", + "CREATE TIMESERIES root.ln.wf01.wt01.hardware WITH DATATYPE=INT32, ENCODING=PLAIN", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(1, 1.1, false, 11)", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(2, 2.2, true, 22)", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(3, 3.3, false, 33 )", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(4, 4.4, false, 44)", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(5, 5.5, false, 55)" + }; + private final String d0s0 = "root.vehicle.d0.s0"; + private final String d0s1 = "root.vehicle.d0.s1"; + private final String d0s2 = "root.vehicle.d0.s2"; + private final String d0s3 = "root.vehicle.d0.s3"; + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + prepareData(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void recoverTest1() { + // stop cluster + EnvFactory.getEnv().shutdownAllDataNodes(); + logger.info("All DataNodes are shut down"); + EnvFactory.getEnv().shutdownAllConfigNodes(); + logger.info("All ConfigNodes are shut down"); + EnvFactory.getEnv().startAllConfigNodes(); + logger.info("All ConfigNodes are started"); + EnvFactory.getEnv().startAllDataNodes(); + logger.info("All DataNodes are started"); + // check cluster whether restart + ((AbstractEnv) EnvFactory.getEnv()).checkClusterStatusWithoutUnknown(); + String[] retArray = new String[] {"0,2", "0,4", "0,3"}; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + String selectSql = "select count(temperature) from root.ln.wf01.wt01 where time > 3"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(TEMPERATURE_STR)); + Assert.assertEquals(retArray[0], ans); + } + + selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where time > 3"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(minTime(TEMPERATURE_STR)); + Assert.assertEquals(retArray[1], ans); + } + + selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where temperature > 3"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(minTime(TEMPERATURE_STR)); + Assert.assertEquals(retArray[2], ans); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + // max min ValueTest + retArray = new String[] {"0,8499,500.0", "0,2499,500.0"}; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + String selectSql = + "select max_value(s0),min_value(s2) " + + "from root.vehicle.d0 where time >= 100 and time < 9000"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(maxValue(d0s0)) + + "," + + resultSet.getString(minValue(d0s2)); + Assert.assertEquals(retArray[0], ans); + } + + selectSql = "select max_value(s0),min_value(s2) from root.vehicle.d0 where time < 2500"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(maxValue(d0s0)) + + "," + + resultSet.getString(minValue(d0s2)); + Assert.assertEquals(retArray[1], ans); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void recoverTest2() { + // stop cluster + EnvFactory.getEnv().shutdownAllDataNodes(); + logger.info("All DataNodes are shut down"); + EnvFactory.getEnv().shutdownAllConfigNodes(); + logger.info("All ConfigNodes are shut down"); + EnvFactory.getEnv().startAllConfigNodes(); + logger.info("All ConfigNodes are started"); + EnvFactory.getEnv().startAllDataNodes(); + logger.info("All DataNodes are started"); + // wait for cluster to start and check + ((AbstractEnv) EnvFactory.getEnv()).checkClusterStatusWithoutUnknown(); + // count test + String[] retArray = new String[] {"0,2001,2001,2001,2001", "0,7500,7500,7500,7500"}; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + String selectSql = + "select count(s0),count(s1),count(s2),count(s3) " + + "from root.vehicle.d0 where time >= 6000 and time <= 9000"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(count(d0s0)) + + "," + + resultSet.getString(count(d0s1)) + + "," + + resultSet.getString(count(d0s2)) + + "," + + resultSet.getString(count(d0s3)); + Assert.assertEquals(retArray[0], ans); + } + + selectSql = "select count(s0),count(s1),count(s2),count(s3) from root.vehicle.d0"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(count(d0s0)) + + "," + + resultSet.getString(count(d0s1)) + + "," + + resultSet.getString(count(d0s2)) + + "," + + resultSet.getString(count(d0s3)); + Assert.assertEquals(retArray[1], ans); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + private void prepareData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + for (String sql : creationSqls) { + statement.execute(sql); + } + + for (String sql : dataSet2) { + statement.execute(sql); + } + + // prepare BufferWrite file + String insertTemplate = + "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4)" + " VALUES(%d,%d,%d,%f,%s,%s)"; + for (int i = 5000; i < 7000; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "true")); + } + statement.executeBatch(); + statement.execute("flush"); + for (int i = 7500; i < 8500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "false")); + } + statement.executeBatch(); + statement.execute("flush"); + // prepare Unseq-File + for (int i = 500; i < 1500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "true")); + } + statement.executeBatch(); + statement.execute("flush"); + for (int i = 3000; i < 6500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "false")); + } + statement.executeBatch(); + statement.execute("flush"); + + // prepare BufferWrite cache + for (int i = 9000; i < 10000; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "true")); + } + statement.executeBatch(); + // prepare Overflow cache + for (int i = 2000; i < 2500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "false")); + } + statement.executeBatch(); + statement.execute("flush"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java new file mode 100644 index 0000000000000..b24b3b03e573f --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.cluster.env.AbstractEnv; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Locale; + +import static org.apache.iotdb.db.utils.constant.TestConstant.count; +import static org.apache.iotdb.db.utils.constant.TestConstant.maxValue; +import static org.apache.iotdb.db.utils.constant.TestConstant.minTime; +import static org.apache.iotdb.db.utils.constant.TestConstant.minValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRecoverUnclosedIT { + private static final Logger logger = LoggerFactory.getLogger(IoTDBRecoverUnclosedIT.class); + private static final String TIMESTAMP_STR = "Time"; + private static final String TEMPERATURE_STR = "root.ln.wf01.wt01.temperature"; + private static final String[] creationSqls = + new String[] { + "CREATE DATABASE root.vehicle.d0", + "CREATE DATABASE root.vehicle.d1", + "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN", + "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN" + }; + private static final String[] dataSet2 = + new String[] { + "CREATE DATABASE root.ln.wf01.wt01", + "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", + "CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=PLAIN", + "CREATE TIMESERIES root.ln.wf01.wt01.hardware WITH DATATYPE=INT32, ENCODING=PLAIN", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(1, 1.1, false, 11)", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(2, 2.2, true, 22)", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(3, 3.3, false, 33 )", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(4, 4.4, false, 44)", + "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " + + "values(5, 5.5, false, 55)" + }; + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().getConfig().getCommonConfig().setWalMode("SYNC"); + EnvFactory.getEnv().initClusterEnvironment(); + prepareData(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void test() throws SQLException, IOException { + String[] retArray = new String[] {"0,2", "0,4", "0,3"}; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + String selectSql = "select count(temperature) from root.ln.wf01.wt01 where time > 3"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(TEMPERATURE_STR)); + assertEquals(retArray[0], ans); + } + + selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where time > 3"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(minTime(TEMPERATURE_STR)); + assertEquals(retArray[1], ans); + } + + selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where temperature > 3"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(minTime(TEMPERATURE_STR)); + assertEquals(retArray[2], ans); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + insertMoreData(); + + // stop cluster + EnvFactory.getEnv().shutdownAllDataNodes(); + logger.info("All DataNodes are shut down"); + EnvFactory.getEnv().shutdownAllConfigNodes(); + logger.info("All ConfigNodes are shut down"); + EnvFactory.getEnv().startAllConfigNodes(); + logger.info("All ConfigNodes are started"); + EnvFactory.getEnv().startAllDataNodes(); + logger.info("All DataNodes are started"); + // wait for cluster to start and check + ((AbstractEnv) EnvFactory.getEnv()).checkClusterStatusWithoutUnknown(); + + // test count, + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + String selectSql = "select count(*) from root.vehicle.d0"; + ResultSet tempResultSet = statement.executeQuery(selectSql); + assertNotNull(tempResultSet); + tempResultSet.next(); + String d0s0 = "root.vehicle.d0.s0"; + String d0s1 = "root.vehicle.d0.s1"; + String d0s2 = "root.vehicle.d0.s2"; + assertEquals(7500, tempResultSet.getInt("count(" + d0s0 + ")")); + + // test max, min value + retArray = new String[] {"0,8499,500.0", "0,2499,500.0"}; + selectSql = + "select max_value(s0),min_value(s2) " + + "from root.vehicle.d0 where time >= 100 and time < 9000"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(maxValue(d0s0)) + + "," + + resultSet.getString(minValue(d0s2)); + assertEquals(retArray[0], ans); + } + + selectSql = "select max_value(s1),min_value(s2) from root.vehicle.d0 where time < 2500"; + try (ResultSet resultSet = statement.executeQuery(selectSql)) { + assertNotNull(resultSet); + resultSet.next(); + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(maxValue(d0s1)) + + "," + + resultSet.getString(minValue(d0s2)); + assertEquals(retArray[1], ans); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + private void prepareData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + for (String sql : creationSqls) { + statement.execute(sql); + } + + for (String sql : dataSet2) { + statement.execute(sql); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void insertMoreData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + // prepare BufferWrite file + String insertTemplate = + "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4)" + " VALUES(%d,%d,%d,%f,%s,%s)"; + for (int i = 5000; i < 7000; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "true")); + } + statement.executeBatch(); + for (int i = 7500; i < 8500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "false")); + } + statement.executeBatch(); + // prepare Unseq-File + for (int i = 500; i < 1500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "true")); + } + for (int i = 3000; i < 6500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "false")); + } + statement.executeBatch(); + // prepare BufferWrite cache + for (int i = 9000; i < 10000; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "true")); + } + statement.executeBatch(); + // prepare Overflow cache + for (int i = 2000; i < 2500; i++) { + statement.addBatch( + String.format( + Locale.ENGLISH, insertTemplate, i, i, i, (double) i, "'" + i + "'", "false")); + } + statement.executeBatch(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java new file mode 100644 index 0000000000000..89270c1b87b1a --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java @@ -0,0 +1,384 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.db.conf.IoTDBConfig; +import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.apache.iotdb.db.utils.constant.TestConstant.TIMESTAMP_STR; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +@Ignore +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRestartIT { + + private final Logger logger = LoggerFactory.getLogger(IoTDBRestartIT.class); + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().initClusterEnvironment(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testRestart() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(1,1.0)"); + statement.execute("flush"); + } + + try { + // TODO: replace restartDaemon() with new methods in Env. + // EnvironmentUtils.restartDaemon(); + } catch (Exception e) { + fail(e.getMessage()); + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(2,1.0)"); + } + + try { + // EnvironmentUtils.restartDaemon(); + } catch (Exception e) { + fail(e.getMessage()); + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(3,1.0)"); + + String[] exp = new String[] {"1,1.0", "2,1.0", "3,1.0"}; + int cnt = 0; + try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.turbine.d1")) { + assertNotNull(resultSet); + while (resultSet.next()) { + String result = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(2); + assertEquals(exp[cnt], result); + cnt++; + } + } + } + } + + @Test + public void testRestartDelete() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(1,1)"); + statement.execute("insert into root.turbine.d1(timestamp,s1) values(2,2)"); + statement.execute("insert into root.turbine.d1(timestamp,s1) values(3,3)"); + } + + long time = 0; + /* + try { + EnvironmentUtils.restartDaemon(); + StorageEngine.getInstance().recover(); + // wait for recover + while (!StorageEngine.getInstance().isAllSgReady()) { + Thread.sleep(500); + time += 500; + if (time > 10000) { + logger.warn("wait too long in restart, wait for: " + time / 1000 + "s"); + } + } + } catch (Exception e) { + fail(e.getMessage()); + } + */ + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("delete from root.turbine.d1.s1 where time<=1"); + + ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.turbine.d1"); + assertNotNull(resultSet); + String[] exp = new String[] {"2,2.0", "3,3.0"}; + int cnt = 0; + try { + while (resultSet.next()) { + String result = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(2); + assertEquals(exp[cnt], result); + cnt++; + } + + statement.execute("flush"); + statement.execute("delete from root.turbine.d1.s1 where time<=2"); + + exp = new String[] {"3,3.0"}; + resultSet = statement.executeQuery("SELECT s1 FROM root.turbine.d1"); + assertNotNull(resultSet); + cnt = 0; + while (resultSet.next()) { + String result = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(2); + assertEquals(exp[cnt], result); + cnt++; + } + } finally { + resultSet.close(); + } + } + } + + @Test + public void testRestartQueryLargerThanEndTime() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(1,1)"); + statement.execute("insert into root.turbine.d1(timestamp,s1) values(2,2)"); + } + + try { + // EnvironmentUtils.restartDaemon(); + } catch (Exception e) { + fail(e.getMessage()); + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(3,1)"); + statement.execute("insert into root.turbine.d1(timestamp,s1) values(4,2)"); + } + + try { + // EnvironmentUtils.restartDaemon(); + } catch (Exception e) { + fail(e.getMessage()); + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + String[] exp = + new String[] { + "4,2.0", + }; + int cnt = 0; + try (ResultSet resultSet = + statement.executeQuery("SELECT s1 FROM root.turbine.d1 where time > 3")) { + assertNotNull(resultSet); + while (resultSet.next()) { + String result = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(2); + assertEquals(exp[cnt], result); + cnt++; + } + } + assertEquals(1, cnt); + } + } + + @Test + public void testRestartEndTime() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s1) values(1,1)"); + statement.execute("insert into root.turbine.d1(timestamp,s1) values(2,2)"); + } + + try { + // EnvironmentUtils.restartDaemon(); + } catch (Exception e) { + fail(e.getMessage()); + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine.d1(timestamp,s2) values(1,1)"); + statement.execute("insert into root.turbine.d1(timestamp,s2) values(2,2)"); + } + + try { + // EnvironmentUtils.restartDaemon(); + } catch (Exception e) { + fail(e.getMessage()); + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + String[] exp = new String[] {"1,1.0", "2,2.0"}; + int cnt = 0; + try (ResultSet resultSet = statement.executeQuery("SELECT s2 FROM root.turbine.d1")) { + assertNotNull(resultSet); + while (resultSet.next()) { + String result = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(2); + assertEquals(exp[cnt], result); + cnt++; + } + } + assertEquals(2, cnt); + } + } + + @Test + public void testRecoverWALMismatchDataType() throws Exception { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine1.d1(timestamp,s1,s2) values(1,1.1,2.2)"); + statement.execute("delete timeseries root.turbine1.d1.s1"); + statement.execute( + "create timeseries root.turbine1.d1.s1 with datatype=INT32, encoding=RLE, compression=SNAPPY"); + } + + // EnvironmentUtils.restartDaemon(); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select * from root.**")) { + assertNotNull(resultSet); + int cnt = 0; + assertEquals(3, resultSet.getMetaData().getColumnCount()); + while (resultSet.next()) { + assertEquals("1", resultSet.getString(1)); + assertNull(resultSet.getString(2)); + assertEquals("2.2", resultSet.getString(3)); + cnt++; + } + assertEquals(1, cnt); + } + } + } + + @Test + public void testRecoverWALDeleteSchema() throws Exception { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine1.d1(timestamp,s1,s2) values(1,1.1,2.2)"); + statement.execute("delete timeseries root.turbine1.d1.s1"); + } + + // EnvironmentUtils.restartDaemon(); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select * from root.**")) { + assertNotNull(resultSet); + int cnt = 0; + assertEquals(2, resultSet.getMetaData().getColumnCount()); + while (resultSet.next()) { + assertEquals("1", resultSet.getString(1)); + assertEquals("2.2", resultSet.getString(2)); + cnt++; + } + assertEquals(1, cnt); + } + } + } + + @Test + public void testRecoverWALDeleteSchemaCheckResourceTime() throws Exception { + IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); + int avgSeriesPointNumberThreshold = config.getAvgSeriesPointNumberThreshold(); + config.setAvgSeriesPointNumberThreshold(2); + long tsFileSize = config.getSeqTsFileSize(); + long unFsFileSize = config.getSeqTsFileSize(); + config.setSeqTsFileSize(10000000); + config.setUnSeqTsFileSize(10000000); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("create timeseries root.turbine1.d1.s1 with datatype=INT64"); + statement.execute("insert into root.turbine1.d1(timestamp,s1) values(1,1)"); + statement.execute("insert into root.turbine1.d1(timestamp,s1) values(2,1)"); + statement.execute("create timeseries root.turbine1.d1.s2 with datatype=BOOLEAN"); + statement.execute("insert into root.turbine1.d1(timestamp,s2) values(3,true)"); + statement.execute("insert into root.turbine1.d1(timestamp,s2) values(4,true)"); + } + + Thread.sleep(1000); + // EnvironmentUtils.restartDaemon(); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + long[] result = new long[] {1L, 2L}; + ResultSet resultSet = + statement.executeQuery("select s1 from root.turbine1.d1 where time < 3"); + assertNotNull(resultSet); + int cnt = 0; + while (resultSet.next()) { + assertEquals(resultSet.getLong(1), result[cnt]); + cnt++; + } + assertEquals(2, cnt); + } + + config.setAvgSeriesPointNumberThreshold(avgSeriesPointNumberThreshold); + config.setSeqTsFileSize(tsFileSize); + config.setUnSeqTsFileSize(unFsFileSize); + } + + @Test + public void testRecoverFromFlushMemTableError() throws Exception { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.turbine1.d1(timestamp,s1,s2) values(1,1.1,2.2)"); + } + + // mock exception during flush memtable + // EnvironmentUtils.restartDaemon(); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select * from root.**")) { + assertNotNull(resultSet); + int cnt = 0; + while (resultSet.next()) { + assertEquals("1", resultSet.getString(1)); + assertEquals("1.1", resultSet.getString(2)); + assertEquals("2.2", resultSet.getString(3)); + cnt++; + } + assertEquals(1, cnt); + } + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java new file mode 100644 index 0000000000000..c0c7280f09ca1 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.constant.TestConstant; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.junit.Assert.fail; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBSameMeasurementsDifferentTypesIT { + + @BeforeClass + public static void setUp() throws Exception { + // use small page + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setMaxNumberOfPointsInPage(1000) + .setPageSizeInByte(1024 * 150) + .setGroupSizeInByte(1024 * 1000) + .setMemtableSizeThreshold(1024 * 1000); + + EnvFactory.getEnv().initClusterEnvironment(); + + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + private static void insertData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + statement.execute("CREATE DATABASE root.fans"); + statement.execute("CREATE TIMESERIES root.fans.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE"); + statement.execute("CREATE TIMESERIES root.fans.d1.s0 WITH DATATYPE=INT64, ENCODING=RLE"); + + for (int time = 1; time < 10; time++) { + + String sql = + String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 10); + statement.execute(sql); + sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 5); + statement.execute(sql); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllTest() { + String[] retArray = + new String[] { + "1,1,1", "2,2,2", "3,3,3", "4,4,4", "5,5,0", "6,6,1", "7,7,2", "8,8,3", "9,9,4" + }; + + String selectSql = "select * from root.**"; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement1 = connection.createStatement(); + Statement statement2 = connection.createStatement()) { + statement1.setFetchSize(10); + ResultSet resultSet1 = statement1.executeQuery(selectSql); + int cnt1 = 0; + while (resultSet1.next() && cnt1 < 5) { + String ans = + resultSet1.getString(TestConstant.TIMESTAMP_STR) + + "," + + resultSet1.getString("root.fans.d0.s0") + + "," + + resultSet1.getString("root.fans.d1.s0"); + Assert.assertEquals(retArray[cnt1], ans); + cnt1++; + } + + statement2.setFetchSize(10); + ResultSet resultSet2 = statement2.executeQuery(selectSql); + int cnt2 = 0; + while (resultSet2.next()) { + String ans = + resultSet2.getString(TestConstant.TIMESTAMP_STR) + + "," + + resultSet2.getString("root.fans.d0.s0") + + "," + + resultSet2.getString("root.fans.d1.s0"); + Assert.assertEquals(retArray[cnt2], ans); + cnt2++; + } + Assert.assertEquals(9, cnt2); + + // use do-while instead of while because in the previous while loop, we have executed the next + // function, + // and the cursor has been moved to the next position, so we should fetch that value first. + do { + String ans = + resultSet1.getString(TestConstant.TIMESTAMP_STR) + + "," + + resultSet1.getString("root.fans.d0.s0") + + "," + + resultSet1.getString("root.fans.d1.s0"); + Assert.assertEquals(retArray[cnt1], ans); + cnt1++; + } while (resultSet1.next()); + // Although the statement2 has the same sql as statement1, they shouldn't affect each other. + // So the statement1's ResultSet should also have 9 rows in total. + Assert.assertEquals(9, cnt1); + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java new file mode 100644 index 0000000000000..21c5c74ec2e70 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it.aligned; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBInsertAlignedValues2IT { + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setAutoCreateSchemaEnabled(true) + .setMaxNumberOfPointsInPage(2); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testInsertAlignedWithEmptyPage() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(S1 INT32 encoding=PLAIN compressor=SNAPPY, S2 INT32 encoding=PLAIN compressor=SNAPPY, S3 INT32 encoding=PLAIN compressor=SNAPPY) "); + for (int i = 0; i < 100; i++) { + if (i == 99) { + statement.addBatch( + "insert into root.lz.dev.GPS(time,S1,S3) aligned values(" + + i + + "," + + i + + "," + + i + + ")"); + } else { + statement.addBatch( + "insert into root.lz.dev.GPS(time,S1,S2) aligned values(" + + i + + "," + + i + + "," + + i + + ")"); + } + } + statement.executeBatch(); + + statement.execute("flush"); + int rowCount = 0; + try (ResultSet resultSet = statement.executeQuery("select S3 from root.lz.dev.GPS")) { + while (resultSet.next()) { + assertEquals(99, resultSet.getInt(2)); + rowCount++; + } + assertEquals(1, rowCount); + } + + try (ResultSet resultSet = statement.executeQuery("select S2 from root.lz.dev.GPS")) { + rowCount = 0; + while (resultSet.next()) { + assertEquals(rowCount, resultSet.getInt(2)); + rowCount++; + } + assertEquals(99, rowCount); + } + + try (ResultSet resultSet = statement.executeQuery("select S1 from root.lz.dev.GPS")) { + rowCount = 0; + while (resultSet.next()) { + assertEquals(rowCount, resultSet.getInt(2)); + rowCount++; + } + assertEquals(100, rowCount); + } + } + } + + @Test + public void testInsertAlignedWithEmptyPage2() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); + statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); + statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); + statement.execute("flush"); + statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); + } + } + + @Test + public void testInsertComplexAlignedValues() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.addBatch("create aligned timeseries root.sg.d1(s1 int32, s2 int32, s3 int32)"); + statement.addBatch("insert into root.sg.d1(time,s1) values(3,1)"); + statement.addBatch("insert into root.sg.d1(time,s1) values(1,1)"); + statement.addBatch("insert into root.sg.d1(time,s1) values(2,1)"); + statement.addBatch("insert into root.sg.d1(time,s2) values(2,2)"); + statement.addBatch("insert into root.sg.d1(time,s2) values(1,2)"); + statement.addBatch("insert into root.sg.d1(time,s2) values(3,2)"); + statement.addBatch("insert into root.sg.d1(time,s3) values(1,3)"); + statement.addBatch("insert into root.sg.d1(time,s3) values(3,3)"); + statement.executeBatch(); + + try (ResultSet resultSet = + statement.executeQuery("select count(s1), count(s2), count(s3) from root.sg.d1")) { + + assertTrue(resultSet.next()); + assertEquals(3, resultSet.getInt(1)); + assertEquals(3, resultSet.getInt(2)); + assertEquals(2, resultSet.getInt(3)); + + assertFalse(resultSet.next()); + } + + statement.execute("flush"); + try (ResultSet resultSet = + statement.executeQuery("select count(s1), count(s2), count(s3) from root.sg.d1")) { + + assertTrue(resultSet.next()); + assertEquals(3, resultSet.getInt(1)); + assertEquals(3, resultSet.getInt(2)); + assertEquals(2, resultSet.getInt(3)); + + assertFalse(resultSet.next()); + } + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java new file mode 100644 index 0000000000000..311f57bf0672e --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it.aligned; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.assertEquals; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBInsertAlignedValues3IT { + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setAutoCreateSchemaEnabled(true) + .setMaxNumberOfPointsInPage(4); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testInsertAlignedWithEmptyPage2() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(S1 INT32 encoding=PLAIN compressor=SNAPPY, S2 INT32 encoding=PLAIN compressor=SNAPPY, S3 INT32 encoding=PLAIN compressor=SNAPPY) "); + for (int i = 0; i < 100; i++) { + if (i >= 49) { + statement.addBatch( + "insert into root.lz.dev.GPS(time,S1,S2,S3) aligned values(" + + i + + "," + + i + + "," + + i + + "," + + i + + ")"); + } else { + statement.addBatch( + "insert into root.lz.dev.GPS(time,S1,S2) aligned values(" + + i + + "," + + i + + "," + + i + + ")"); + } + } + statement.executeBatch(); + statement.execute("flush"); + int rowCount = 0; + try (ResultSet resultSet = statement.executeQuery("select S3 from root.lz.dev.GPS")) { + while (resultSet.next()) { + assertEquals(rowCount + 49, resultSet.getInt(2)); + rowCount++; + } + assertEquals(51, rowCount); + } + + try (ResultSet resultSet = statement.executeQuery("select S2 from root.lz.dev.GPS")) { + rowCount = 0; + while (resultSet.next()) { + assertEquals(rowCount, resultSet.getInt(2)); + rowCount++; + } + assertEquals(100, rowCount); + } + + try (ResultSet resultSet = statement.executeQuery("select S1 from root.lz.dev.GPS")) { + rowCount = 0; + while (resultSet.next()) { + assertEquals(rowCount, resultSet.getInt(2)); + rowCount++; + } + assertEquals(100, rowCount); + } + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java new file mode 100644 index 0000000000000..aad0ad5ebfdbc --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it.aligned; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBInsertAlignedValues4IT { + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setAutoCreateSchemaEnabled(true) + .setPrimitiveArraySize(2); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testExtendTextColumn() { + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(1,'test','test')"); + statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(2,'test','test')"); + statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(3,'test','test')"); + statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(4,'test','test')"); + statement.execute("insert into root.sg.d1(time,s1,s3) aligned values(5,'test','test')"); + statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(6,'test','test')"); + statement.execute("flush"); + statement.execute("insert into root.sg.d1(time,s1,s3) aligned values(7,'test','test')"); + } catch (SQLException e) { + fail(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java new file mode 100644 index 0000000000000..80127ff8e4a03 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java @@ -0,0 +1,404 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it.aligned; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBInsertAlignedValuesIT { + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().getConfig().getCommonConfig().setAutoCreateSchemaEnabled(true); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testInsertAlignedValues() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.addBatch( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (4000, true, 17.1)"); + statement.addBatch( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (5000, true, 20.1)"); + statement.addBatch( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (6000, true, 22)"); + statement.executeBatch(); + + try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertFalse(resultSet.next()); + } + + try (ResultSet resultSet = + statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + + assertTrue(resultSet.next()); + assertEquals(4000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(17.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(5000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(20.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(6000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(22, resultSet.getDouble(3), 0.1); + + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testInsertAlignedNullableValues() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.addBatch( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (4000, true, 17.1)"); + statement.addBatch("insert into root.t1.wf01.wt01(time, status) aligned values (5000, true)"); + statement.addBatch( + "insert into root.t1.wf01.wt01(time, temperature) aligned values (6000, 22)"); + statement.executeBatch(); + + try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertFalse(resultSet.next()); + } + + try (ResultSet resultSet = + statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + + assertTrue(resultSet.next()); + assertEquals(4000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(17.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(5000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertNull(resultSet.getObject(3)); + + assertTrue(resultSet.next()); + assertEquals(6000, resultSet.getLong(1)); + assertNull(resultSet.getObject(2)); + assertEquals(22.0d, resultSet.getObject(3)); + + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testUpdatingAlignedValues() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.addBatch( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (4000, true, 17.1)"); + statement.addBatch("insert into root.t1.wf01.wt01(time, status) aligned values (5000, true)"); + statement.addBatch( + "insert into root.t1.wf01.wt01(time, temperature) aligned values (5000, 20.1)"); + statement.addBatch( + "insert into root.t1.wf01.wt01(time, temperature) aligned values (6000, 22)"); + statement.executeBatch(); + + try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertFalse(resultSet.next()); + } + + try (ResultSet resultSet = + statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + + assertTrue(resultSet.next()); + assertEquals(4000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(17.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(5000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(20.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(6000, resultSet.getLong(1)); + assertNull(resultSet.getObject(2)); + assertEquals(22.0d, resultSet.getObject(3)); + + assertFalse(resultSet.next()); + } + + statement.execute("flush"); + try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertFalse(resultSet.next()); + } + + try (ResultSet resultSet = + statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + + assertTrue(resultSet.next()); + assertEquals(4000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(17.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(5000, resultSet.getLong(1)); + assertTrue(resultSet.getBoolean(2)); + assertEquals(20.1, resultSet.getDouble(3), 0.1); + + assertTrue(resultSet.next()); + assertEquals(6000, resultSet.getLong(1)); + assertNull(resultSet.getObject(2)); + assertEquals(22.0d, resultSet.getObject(3)); + + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testInsertAlignedValuesWithSameTimestamp() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.addBatch("insert into root.sg.d1(time,s2) aligned values(1,2)"); + statement.addBatch("insert into root.sg.d1(time,s1) aligned values(1,2)"); + statement.executeBatch(); + + try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) { + + assertTrue(resultSet.next()); + assertEquals(1, resultSet.getLong(1)); + assertEquals(2.0d, resultSet.getObject(2)); + assertEquals(2.0d, resultSet.getObject(3)); + + assertFalse(resultSet.next()); + } + + statement.execute("flush"); + try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) { + + assertTrue(resultSet.next()); + assertEquals(1, resultSet.getLong(1)); + assertEquals(2.0d, resultSet.getObject(2)); + assertEquals(2.0d, resultSet.getObject(3)); + + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testInsertWithWrongMeasurementNum1() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values(11000, 100)"); + fail(); + } catch (SQLException e) { + assertTrue( + e.getMessage() + .contains( + "the measurementList's size 2 is not consistent with the valueList's size 1")); + } + } + + @Test + public void testInsertWithWrongMeasurementNum2() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "insert into root.t1.wf01.wt01(time, status, temperature) aligned values(11000, 100, 300, 400)"); + fail(); + } catch (SQLException e) { + assertTrue( + e.getMessage(), + e.getMessage() + .contains( + "the measurementList's size 2 is not consistent with the valueList's size 3")); + } + } + + @Test(expected = Exception.class) + public void testInsertWithWrongType() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(latitude INT32 encoding=PLAIN compressor=SNAPPY, longitude INT32 encoding=PLAIN compressor=SNAPPY) "); + statement.execute( + "insert into root.lz.dev.GPS(time,latitude,longitude) aligned values(1,1.3,6.7)"); + fail(); + } + } + + @Test + public void testInsertAlignedTimeseriesWithoutAligned() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE ALIGNED TIMESERIES root.lz.dev.GPS2(latitude INT32 encoding=PLAIN compressor=SNAPPY, longitude INT32 encoding=PLAIN compressor=SNAPPY) "); + statement.execute("insert into root.lz.dev.GPS2(time,latitude,longitude) values(1,123,456)"); + // it's supported. + } + } + + @Test + public void testInsertTimeseriesWithUnMatchedAlignedType() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("create ALIGNED timeseries root.db.d_aligned(s01 INT64 encoding=RLE)"); + statement.execute("insert into root.db.d_aligned(time, s01) aligned values (4000, 123)"); + statement.execute("insert into root.db.d_aligned(time, s01) values (5000, 456)"); + statement.execute("create timeseries root.db.d_not_aligned.s01 INT64 encoding=RLE"); + statement.execute("insert into root.db.d_not_aligned(time, s01) values (4000, 987)"); + statement.execute("insert into root.db.d_not_aligned(time, s01) aligned values (5000, 654)"); + + try (ResultSet resultSet = statement.executeQuery("select s01 from root.db.d_aligned")) { + assertTrue(resultSet.next()); + assertEquals(4000, resultSet.getLong(1)); + assertEquals(123, resultSet.getLong(2)); + + assertTrue(resultSet.next()); + assertEquals(5000, resultSet.getLong(1)); + assertEquals(456, resultSet.getLong(2)); + + assertFalse(resultSet.next()); + } + + try (ResultSet resultSet = statement.executeQuery("select s01 from root.db.d_not_aligned")) { + assertTrue(resultSet.next()); + assertEquals(4000, resultSet.getLong(1)); + assertEquals(987, resultSet.getLong(2)); + + assertTrue(resultSet.next()); + assertEquals(5000, resultSet.getLong(1)); + assertEquals(654, resultSet.getLong(2)); + + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testInsertNonAlignedTimeseriesWithAligned() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE TIMESERIES root.lz.dev.GPS3.latitude with datatype=INT32"); + statement.execute("CREATE TIMESERIES root.lz.dev.GPS3.longitude with datatype=INT32"); + statement.execute( + "insert into root.lz.dev.GPS3(time,latitude,longitude) aligned values(1,123,456)"); + // it's supported. + } + } + + @Test + public void testInsertAlignedValuesWithThreeLevelPath() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("insert into root.sg_device(time, status) aligned values (4000, true)"); + + try (ResultSet resultSet = statement.executeQuery("select ** from root")) { + assertTrue(resultSet.next()); + assertTrue(resultSet.getBoolean(2)); + assertFalse(resultSet.next()); + } + } + } + + @Test + public void testInsertWithDuplicatedMeasurements() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "insert into root.t1.wf01.wt01(time, s3, status, status) aligned values(100, true, 20.1, 20.2)"); + fail(); + } catch (SQLException e) { + assertTrue( + e.getMessage(), + e.getMessage().contains("Insertion contains duplicated measurement: status")); + } + } + + @Test + public void testInsertMultiRows() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "insert into root.sg1.d1(time, s1, s2) aligned values(10, 2, 2), (11, 3, '3'), (12,12.11,false);"); + fail(); + } catch (SQLException e) { + assertTrue(e.getMessage(), e.getMessage().contains("data type is not consistent")); + } + } + + @Test + public void testInsertLargeNumber() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "insert into root.sg1.d1(time, s98, s99) aligned values(10, 2, 271840880000000000000000)"); + } catch (SQLException e) { + fail(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java new file mode 100644 index 0000000000000..54184bb636cdf --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it.schema; + +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.constant.TestConstant; +import org.apache.iotdb.util.AbstractSchemaIT; + +import org.apache.tsfile.enums.TSDataType; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runners.Parameterized; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBAutoCreateSchemaIT extends AbstractSchemaIT { + + public IoTDBAutoCreateSchemaIT(SchemaTestMode schemaTestMode) { + super(schemaTestMode); + } + + @Parameterized.BeforeParam + public static void before() throws Exception { + setUpEnvironment(); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @Parameterized.AfterParam + public static void after() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + tearDownEnvironment(); + } + + @After + public void tearDown() throws Exception { + clearSchema(); + } + + /** create timeseries without setting database */ + @Test + public void createTimeseriesTest() throws ClassNotFoundException { + String[] sqls = { + "CREATE TIMESERIES root.sg0.d1.s2 WITH DATATYPE=INT32,ENCODING=RLE", + "INSERT INTO root.sg0.d1(timestamp,s2) values(1,123)", + }; + executeSQL(sqls); + } + + /** insert data when database has been set but timeseries hasn't been created */ + @Test + public void insertTest1() throws ClassNotFoundException { + String[] sqls = { + "CREATE DATABASE root.sg0", + "INSERT INTO root.sg0.d1(timestamp,s2) values(1,123.123)", + "INSERT INTO root.sg0.d1(timestamp,s3) values(1,\"abc\")", + }; + executeSQL(sqls); + } + + /** insert data when database hasn't been set and timeseries hasn't been created */ + @Test + public void insertTest2() throws ClassNotFoundException { + String[] sqls = { + "INSERT INTO root.sg0.d1(timestamp,s2) values(1,\"abc\")", + "INSERT INTO root.sg0.d2(timestamp,s3) values(1,123.123)", + "INSERT INTO root.sg0.d2(timestamp,s4) values(1,123456)", + }; + executeSQL(sqls); + } + + private void executeSQL(String[] sqls) throws ClassNotFoundException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + String result = ""; + Long now_start = 0L; + boolean cmp = false; + + for (String sql : sqls) { + if (cmp) { + Assert.assertEquals(sql, result); + cmp = false; + } else if (sql.equals("SHOW TIMESERIES")) { + DatabaseMetaData data = connection.getMetaData(); + result = data.toString(); + cmp = true; + } else { + if (sql.contains("NOW()") && now_start == 0L) { + now_start = System.currentTimeMillis(); + } + + if (sql.split(" ")[0].equals("SELECT")) { + ResultSet resultSet = statement.executeQuery(sql); + ResultSetMetaData metaData = resultSet.getMetaData(); + int count = metaData.getColumnCount(); + String[] column = new String[count]; + for (int i = 0; i < count; i++) { + column[i] = metaData.getColumnName(i + 1); + } + result = ""; + while (resultSet.next()) { + for (int i = 1; i <= count; i++) { + if (now_start > 0L && column[i - 1].equals(TestConstant.TIMESTAMP_STR)) { + String timestr = resultSet.getString(i); + Long tn = Long.valueOf(timestr); + Long now = System.currentTimeMillis(); + if (tn >= now_start && tn <= now) { + timestr = "NOW()"; + } + result += timestr + ','; + } else { + result += resultSet.getString(i) + ','; + } + } + result += '\n'; + } + cmp = true; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * test if automatically creating a time series will cause the database with same name to + * disappear + */ + @Test + public void testInsertAutoCreate2() throws Exception { + String storageGroup = "root.sg2.a.b.c"; + String timeSeriesPrefix = "root.sg2.a.b"; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(String.format("CREATE DATABASE %s", storageGroup)); + try { + statement.execute( + String.format("INSERT INTO %s(timestamp, c) values(123, \"aabb\")", timeSeriesPrefix)); + } catch (SQLException ignored) { + } + + // ensure that current database in cache is right. + InsertAutoCreate2Tool(statement, storageGroup, timeSeriesPrefix); + } + // todo restart test + // EnvironmentUtils.stopDaemon(); + // setUp(); + // + // // ensure that database in cache is right after recovering. + // InsertAutoCreate2Tool(storageGroup, timeSeriesPrefix); + } + + private void InsertAutoCreate2Tool( + Statement statement, String storageGroup, String timeSeriesPrefix) throws SQLException { + Set resultList = new HashSet<>(); + try (ResultSet resultSet = statement.executeQuery("show timeseries")) { + while (resultSet.next()) { + String str = resultSet.getString(ColumnHeaderConstant.TIMESERIES); + resultList.add(str); + } + } + Assert.assertFalse(resultList.contains(timeSeriesPrefix + "c")); + + resultList.clear(); + try (ResultSet resultSet = statement.executeQuery("show databases")) { + while (resultSet.next()) { + resultList.add(resultSet.getString(ColumnHeaderConstant.DATABASE)); + } + } + Assert.assertTrue(resultList.contains(storageGroup)); + } + + /** + * insert data when database hasn't been set, timeseries hasn't been created and have null values + */ + @Test + public void testInsertAutoCreate3() throws SQLException { + String[] sqls = { + "INSERT INTO root.sg0.d3(timestamp,s1) values(1,null)", + "INSERT INTO root.sg0.d3(timestamp,s1,s2) values(1,null,2)", + }; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + for (String sql : sqls) { + try { + statement.execute(sql); + } catch (SQLException e) { + Assert.assertTrue(e.getMessage().contains("Path [root.sg0.d3.s1] does not exist")); + } + } + } + } + + /** + * insert data when database hasn't been set, timeseries hasn't been created and have null values + */ + @Test + public void testAutoCreateDataType() throws SQLException { + String SQL = + "INSERT INTO root.sg0.d1(time,s1,s2,s3,s4,s5,s6) values(1,true,1,now(),X'cafe',\"string\",\"2024-01-01\")"; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(SQL); + ResultSet resultSet = statement.executeQuery("show timeseries"); + while (resultSet.next()) { + switch (resultSet.getString(ColumnHeaderConstant.TIMESERIES)) { + case "root.sg0.d1.s1": + assertEquals( + TSDataType.BOOLEAN.toString(), resultSet.getString(ColumnHeaderConstant.DATATYPE)); + break; + case "root.sg0.d1.s2": + assertEquals( + TSDataType.DOUBLE.toString(), resultSet.getString(ColumnHeaderConstant.DATATYPE)); + break; + case "root.sg0.d1.s3": + assertEquals( + TSDataType.INT64.toString(), resultSet.getString(ColumnHeaderConstant.DATATYPE)); + break; + case "root.sg0.d1.s4": + assertEquals( + TSDataType.BLOB.toString(), resultSet.getString(ColumnHeaderConstant.DATATYPE)); + break; + case "root.sg0.d1.s5": + assertEquals( + TSDataType.TEXT.toString(), resultSet.getString(ColumnHeaderConstant.DATATYPE)); + break; + case "root.sg0.d1.s6": + assertEquals( + TSDataType.TEXT.toString(), resultSet.getString(ColumnHeaderConstant.DATATYPE)); + break; + } + } + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateAlignedTimeseriesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateAlignedTimeseriesIT.java new file mode 100644 index 0000000000000..a6b7450b34689 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateAlignedTimeseriesIT.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.relational.it.db.it.schema; + +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.util.AbstractSchemaIT; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runners.Parameterized; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +public class IoTDBCreateAlignedTimeseriesIT extends AbstractSchemaIT { + + public IoTDBCreateAlignedTimeseriesIT(SchemaTestMode schemaTestMode) { + super(schemaTestMode); + } + + @Parameterized.BeforeParam + public static void before() throws Exception { + setUpEnvironment(); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @Parameterized.AfterParam + public static void after() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + tearDownEnvironment(); + } + + @After + public void tearDown() throws Exception { + clearSchema(); + } + + @Test + @Category({LocalStandaloneIT.class, ClusterIT.class}) + public void testCreateAlignedTimeseries() throws Exception { + String[] timeSeriesArray = + new String[] { + "root.sg1.d1.vector1.s1,FLOAT,PLAIN,UNCOMPRESSED", "root.sg1.d1.vector1.s2,INT64,RLE,LZ4" + }; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.sg1"); + try { + statement.execute( + "CREATE ALIGNED TIMESERIES root.sg1.d1.vector1(s1 FLOAT encoding=PLAIN compressor=UNCOMPRESSED,s2 INT64 encoding=RLE)"); + } catch (SQLException ignored) { + } + + // ensure that current database in cache is right. + assertTimeseriesEquals(timeSeriesArray); + } + // todo test restart + // EnvironmentUtils.stopDaemon(); + // setUp(); + // + // // ensure database in cache is right after recovering. + // assertTimeseriesEquals(timeSeriesArray); + } + + @Test + public void testCreateAlignedTimeseriesWithDeletion() throws Exception { + String[] timeSeriesArray = + new String[] { + "root.sg1.d1.vector1.s1,DOUBLE,PLAIN,SNAPPY", "root.sg1.d1.vector1.s2,INT64,RLE,LZ4" + }; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("CREATE DATABASE root.sg1"); + try { + statement.execute( + "CREATE ALIGNED TIMESERIES root.sg1.d1.vector1(s1 FLOAT encoding=PLAIN compressor=UNCOMPRESSED,s2 INT64 encoding=RLE)"); + statement.execute("DELETE TIMESERIES root.sg1.d1.vector1.s1"); + statement.execute( + "CREATE ALIGNED TIMESERIES root.sg1.d1.vector1(s1 DOUBLE encoding=PLAIN compressor=SNAPPY)"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // ensure that current database in cache is right. + assertTimeseriesEquals(timeSeriesArray); + + // todo + // EnvironmentUtils.stopDaemon(); + // setUp(); + + // ensure database in cache is right after recovering. + assertTimeseriesEquals(timeSeriesArray); + } + + private void assertTimeseriesEquals(String[] timeSeriesArray) throws SQLException { + + int count = 0; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES")) { + while (resultSet.next()) { + String ActualResult = + resultSet.getString(ColumnHeaderConstant.TIMESERIES) + + "," + + resultSet.getString(ColumnHeaderConstant.DATATYPE) + + "," + + resultSet.getString(ColumnHeaderConstant.ENCODING) + + "," + + resultSet.getString(ColumnHeaderConstant.COMPRESSION); + Assert.assertEquals(timeSeriesArray[count], ActualResult); + count++; + } + } + Assert.assertEquals(timeSeriesArray.length, count); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java new file mode 100644 index 0000000000000..62f49cbde2bb9 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it.schema; + +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.rpc.TSStatusCode; +import org.apache.iotdb.util.AbstractSchemaIT; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runners.Parameterized; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.Assert.fail; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBCreateStorageGroupIT extends AbstractSchemaIT { + + public IoTDBCreateStorageGroupIT(SchemaTestMode schemaTestMode) { + super(schemaTestMode); + } + + @Parameterized.BeforeParam + public static void before() throws Exception { + setUpEnvironment(); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @Parameterized.AfterParam + public static void after() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + tearDownEnvironment(); + } + + @After + public void tearDown() throws Exception { + clearSchema(); + } + + /** The test creates three databases */ + @Test + public void testCreateStorageGroup() throws Exception { + String[] storageGroups = {"root.sg1", "root.sg2", "root.sg3"}; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + for (String storageGroup : storageGroups) { + statement.execute(String.format("create database %s", storageGroup)); + } + + // ensure that current StorageGroup in cache is right. + createStorageGroupTool(statement, storageGroups); + } + // todo test restart + // EnvironmentUtils.stopDaemon(); + // setUp(); + // + // // ensure StorageGroup in cache is right after recovering. + // createStorageGroupTool(storageGroups); + } + + private void createStorageGroupTool(Statement statement, String[] storageGroups) + throws SQLException { + + List resultList = new ArrayList<>(); + try (ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) { + while (resultSet.next()) { + String storageGroupPath = resultSet.getString(ColumnHeaderConstant.DATABASE); + resultList.add(storageGroupPath); + } + } + Assert.assertEquals(3, resultList.size()); + + resultList = resultList.stream().sorted().collect(Collectors.toList()); + + Assert.assertEquals(storageGroups[0], resultList.get(0)); + Assert.assertEquals(storageGroups[1], resultList.get(1)); + Assert.assertEquals(storageGroups[2], resultList.get(2)); + } + + /** Test creating a database that path is an existence database */ + @Test + public void testCreateExistStorageGroup1() throws Exception { + String storageGroup = "root.sg"; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(String.format("CREATE DATABASE %s", storageGroup)); + + try { + statement.execute(String.format("create database %s", storageGroup)); + fail(); + } catch (SQLException e) { + Assert.assertEquals( + TSStatusCode.DATABASE_ALREADY_EXISTS.getStatusCode() + + ": root.sg has already been created as database", + e.getMessage()); + } + } + } + + /** Test the parent node has been set as a database */ + @Test + public void testCreateExistStorageGroup2() throws Exception { + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("create database root.sg"); + + try { + statement.execute("create database root.sg.`device`"); + fail(); + } catch (SQLException e) { + Assert.assertEquals( + TSStatusCode.DATABASE_ALREADY_EXISTS.getStatusCode() + + ": root.sg has already been created as database", + e.getMessage()); + } + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java new file mode 100644 index 0000000000000..21093391f2ca0 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.relational.it.db.it.schema; + +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.util.AbstractSchemaIT; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runners.Parameterized; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.fail; + +/** + * Notice that, all test begins with "IoTDB" is integration test. All test which will start the + * IoTDB server should be defined as integration test. + */ +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBCreateTimeseriesIT extends AbstractSchemaIT { + + public IoTDBCreateTimeseriesIT(SchemaTestMode schemaTestMode) { + super(schemaTestMode); + } + + @Parameterized.BeforeParam + public static void before() throws Exception { + setUpEnvironment(); + EnvFactory.getEnv().initClusterEnvironment(); + } + + @Parameterized.AfterParam + public static void after() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + tearDownEnvironment(); + } + + @After + public void tearDown() throws Exception { + clearSchema(); + } + + /** Test if creating a time series will cause the database with same name to disappear */ + @Test + public void testCreateTimeseries() throws Exception { + String storageGroup = "root.sg1.a.b.c"; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(String.format("CREATE DATABASE %s", storageGroup)); + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + storageGroup)); + + } catch (Exception ignored) { + } + + // ensure that current database in cache is right. + createTimeSeriesTool(storageGroup); + } + + private void createTimeSeriesTool(String storageGroup) throws SQLException { + Set resultList = new HashSet<>(); + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("show timeseries")) { + while (resultSet.next()) { + String str = resultSet.getString(ColumnHeaderConstant.TIMESERIES); + resultList.add(str); + } + } + Assert.assertFalse(resultList.contains(storageGroup)); + resultList.clear(); + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) { + while (resultSet.next()) { + String res = resultSet.getString(ColumnHeaderConstant.DATABASE); + resultList.add(res); + } + } + Assert.assertTrue(resultList.contains(storageGroup)); + } + + @Test + public void testCreateTimeseriesWithSpecialCharacter() throws Exception { + try (Connection connection = EnvFactory.getEnv().getConnection()) { + try (Statement statement = connection.createStatement()) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + "root.sg.d.a\".\"b")); + fail(); + } catch (SQLException ignored) { + } + try (Statement statement = connection.createStatement()) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + "root.sg.d.a“(Φ)”b")); + fail(); + } catch (SQLException ignored) { + } + try (Statement statement = connection.createStatement()) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + "root.sg.d.a>b")); + fail(); + } catch (SQLException ignored) { + } + } + + String[] timeSeriesArray = { + "root.sg.d.`a.b`", "root.sg.d.`a“(Φ)”b`", "root.sg.d.`a>b`", "root.sg.d.`0e38`" + }; + String[] timeSeriesResArray = { + "root.sg.d.`a.b`", "root.sg.d.`a“(Φ)”b`", "root.sg.d.`a>b`", "root.sg.d.`0e38`", + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + for (String timeSeries : timeSeriesArray) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + timeSeries)); + } + } + + // ensure that current timeseries in cache is right. + createTimeSeriesWithSpecialCharacterTool(timeSeriesResArray); + } + + private void createTimeSeriesWithSpecialCharacterTool(String[] timeSeriesArray) + throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("count timeseries root.sg.**")) { + while (resultSet.next()) { + long count = resultSet.getLong(1); + Assert.assertEquals(timeSeriesArray.length, count); + } + } + } + + @Test + public void testCreateTimeSeriesWithWrongAttribute() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format("create timeseries %s with datatype=INT64, datatype = test", "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(String.format("create timeseries %s with encoding=plain", "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format( + "create timeseries %s with encoding=plain, compressor=snappy", "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format("create timeseries %s with datatype=float, encoding=plan", "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format("create timeseries %s with datatype=INT64, encoding=test", "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=test, compression=test", + "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format("create timeseries %s with datatype=INT64,compression=test", "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=test", + "root.sg.a")); + fail(); + } catch (SQLException ignored) { + } + } + + @Test + public void testQueryDataFromTimeSeriesWithoutData() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("create timeseries root.sg2.d.s1 with datatype=INT64"); + } catch (SQLException ignored) { + fail(); + } + int cnt = 0; + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("select s1 from root.sg2.d")) { + while (resultSet.next()) { + cnt++; + } + } catch (SQLException e) { + fail(); + } + Assert.assertEquals(0, cnt); + } + + @Test + public void testIllegalInput() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute("create timeseries root.sg2.d.s1 with datatype=INT64"); + assertThrows( + "Unsupported datatype: UNKNOWN", + SQLException.class, + () -> statement.execute("create timeseries root.sg2.d.s1 with datatype=UNKNOWN")); + assertThrows( + "Unsupported datatype: VECTOR", + SQLException.class, + () -> statement.execute("create timeseries root.sg2.d.s1 with datatype=VECTOR")); + assertThrows( + "Unsupported datatype: YES", + SQLException.class, + () -> statement.execute("create timeseries root.sg2.d.s1 with datatype=YES")); + assertThrows( + "Unsupported datatype: UNKNOWN", + SQLException.class, + () -> statement.execute("create device template t1 (s1 UNKNOWN, s2 boolean)")); + assertThrows( + "Unsupported datatype: VECTOR", + SQLException.class, + () -> statement.execute("create device template t1 (s1 VECTOR, s2 boolean)")); + } catch (SQLException ignored) { + fail(); + } + } +} From 682e5af6460cb67b22aa977b64a60e35f797b9b8 Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Wed, 24 Jul 2024 10:42:50 +0800 Subject: [PATCH 2/4] modify it --- .../it/db/it/IoTDBExecuteBatchIT.java | 149 ++++++------------ .../it/db/it/IoTDBFloatPrecisionIT.java | 13 +- .../it/db/it/IoTDBFlushQueryIT.java | 93 ++++++----- 3 files changed, 106 insertions(+), 149 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java index 252d3bc0cacce..2727aa3cf3e3b 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBExecuteBatchIT.java @@ -18,8 +18,6 @@ */ package org.apache.iotdb.relational.it.db.it; -import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; -import org.apache.iotdb.isession.ISession; import org.apache.iotdb.it.env.EnvFactory; import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; @@ -28,6 +26,7 @@ import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -43,46 +42,48 @@ @RunWith(IoTDBTestRunner.class) @Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) +@Ignore // 'Drop Table' and 'Alter table' is not supported public class IoTDBExecuteBatchIT { @Before public void setUp() throws Exception { EnvFactory.getEnv().initClusterEnvironment(); - try (ISession session = EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) { - session.executeNonQueryStatement("CREATE DATABASE ln"); - } } @After public void tearDown() throws Exception { - try (ISession session = EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) { - session.executeNonQueryStatement("DROP DATABASE ln"); - } EnvFactory.getEnv().cleanClusterEnvironment(); } @Test public void testJDBCExecuteBatch() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { statement.setFetchSize(5); + statement.addBatch("create database ln"); + statement.addBatch("USE \"ln\""); + statement.addBatch("create table wf01 (id1 string id, temprature double measurement)"); statement.addBatch( - "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,1.2)"); + "insert into wf01(id1,time,temperature) values(\'wt01\', 1509465600000,1.2)"); statement.addBatch( - "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600001,2.3)"); - statement.addBatch("delete timeseries root.ln.wf01.wt01.**"); + "insert into wf01(id1,time,temperature) values(\'wt01\', 1509465600001,2.3)"); + + statement.addBatch("drop table wf01"); + statement.addBatch("create table wf01 (id1 string id, temprature double measurement)"); + statement.addBatch( - "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600002,3.4)"); + "insert into wf01(id1,time,temperature) values(\'wt01\', 1509465600002,3.4)"); statement.executeBatch(); - ResultSet resultSet = statement.executeQuery("select * from root.ln.wf01.wt01"); + statement.clearBatch(); + ResultSet resultSet = statement.executeQuery("select * from wf01"); int count = 0; String[] timestamps = {"1509465600002"}; String[] values = {"3.4"}; while (resultSet.next()) { - assertEquals(timestamps[count], resultSet.getString(ColumnHeaderConstant.TIME)); - assertEquals(values[count], resultSet.getString("root.ln.wf01.wt01.temperature")); + assertEquals(timestamps[count], resultSet.getString("time")); + assertEquals(values[count], resultSet.getString("temperature")); count++; } } catch (SQLException e) { @@ -92,111 +93,53 @@ public void testJDBCExecuteBatch() { @Test public void testJDBCExecuteBatchForCreateMultiTimeSeriesPlan() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { statement.setFetchSize(100); + statement.execute("create database ln"); + statement.execute("USE \"ln\""); + statement.addBatch("create table wf01 (id1 string id, temprature double measurement)"); + statement.addBatch( - "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,1.2)"); - statement.addBatch( - "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600001,2.3)"); - statement.addBatch("delete timeseries root.ln.wf01.wt01.**"); - statement.addBatch( - "create timeseries root.turbine.d1.s1(s1) with datatype=boolean, encoding=plain , compression=snappy " - + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v3', 'attr2'='v4')"); + "insert into wf01(id1,time,temperature) values(\'wt01\', 1509465600000,1.2)"); statement.addBatch( - "create timeseries root.turbine.d1.s2(s2) with datatype=float, encoding=rle, compression=uncompressed " - + "tags('tag1'='v5', 'tag2'='v6') attributes('attr1'='v7', 'attr2'='v8') "); + "insert into wf01(id1,time,temperature) values(\'wt01\', 1509465600001,2.3)"); + statement.addBatch("drop table wf01"); + statement.addBatch( - "insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600002,3.4)"); + "create table turbine (id1 string id, attr1 string attribute, attr2 string attribute, s1 boolean measurement, s2 float measurement)"); + + statement.addBatch("create table wf01 (id1 string id, temprature double measurement)"); statement.addBatch( - "create timeseries root.turbine.d1.s3 with datatype=boolean, encoding=rle"); + "insert into wf01(id1,time,temperature) values(\'wt01\', 1509465600002,3.4)"); + statement.addBatch("alter table turbine add column s3 boolean measurement"); statement.executeBatch(); statement.clearBatch(); - ResultSet resultSet = statement.executeQuery("select * from root.ln.wf01.wt01"); + ResultSet resultSet = statement.executeQuery("select * from wf01"); String[] timestamps = {"1509465600002"}; String[] values = {"3.4"}; int count = 0; while (resultSet.next()) { - assertEquals(timestamps[count], resultSet.getString(ColumnHeaderConstant.TIME)); - assertEquals(values[count], resultSet.getString("root.ln.wf01.wt01.temperature")); + assertEquals(timestamps[count], resultSet.getString("time")); + assertEquals(values[count], resultSet.getString("temperature")); count++; } - ResultSet timeSeriesResultSetForS1 = - statement.executeQuery("SHOW TIMESERIES root.turbine.d1.s1"); + ResultSet timeSeriesResultSetForS1 = statement.executeQuery("describe turbine"); count = 0; - String[] key_s1 = { - ColumnHeaderConstant.TIMESERIES, - ColumnHeaderConstant.ALIAS, - ColumnHeaderConstant.DATABASE, - ColumnHeaderConstant.DATATYPE, - ColumnHeaderConstant.ENCODING, - ColumnHeaderConstant.COMPRESSION, - ColumnHeaderConstant.TAGS, - ColumnHeaderConstant.ATTRIBUTES - }; - String[] value_s1 = { - "root.turbine.d1.s1", - "s1", - "root.turbine", - "BOOLEAN", - "PLAIN", - "SNAPPY", - "{\"tag1\":\"v1\",\"tag2\":\"v2\"}", - "{\"attr2\":\"v3\",\"attr1\":\"v4\"}" + String[] keys = {"ColumnName", "DataType", "Category"}; + String[][] value_columns = { + new String[] {"Time", "TIMESTAMP", "TIME"}, + new String[] {"id1", "STRING", "ID"}, + new String[] {"attr1", "STRING", "ATTRIBUTE"}, + new String[] {"attr2", "STRING", "ATTRIBUTE"}, + new String[] {"s1", "BOOLEAN", "MEASUREMENT"}, + new String[] {"s2", "FLOAT", "MEASUREMENT"}, }; while (timeSeriesResultSetForS1.next()) { - assertEquals(value_s1[count], timeSeriesResultSetForS1.getString(key_s1[count])); - count++; - } - - ResultSet timeSeriesResultSetForS2 = - statement.executeQuery("SHOW TIMESERIES root.turbine.d1.s2"); - count = 0; - String[] key_s2 = { - ColumnHeaderConstant.TIMESERIES, - ColumnHeaderConstant.ALIAS, - ColumnHeaderConstant.DATABASE, - ColumnHeaderConstant.DATATYPE, - ColumnHeaderConstant.ENCODING, - ColumnHeaderConstant.COMPRESSION, - ColumnHeaderConstant.TAGS, - ColumnHeaderConstant.ATTRIBUTES - }; - String[] value_s2 = { - "root.turbine.d1.s2", - "s2", - "root.turbine", - "FLOAT", - "RLE", - "UNCOMPRESSED", - "{\"tag1\":\"v5\",\"tag2\":\"v6\"}", - "{\"attr2\":\"v7\",\"attr1\":\"v8\"}" - }; - while (timeSeriesResultSetForS2.next()) { - assertEquals(value_s2[count], timeSeriesResultSetForS2.getString(key_s2[count])); - count++; - } - - count = 0; - String[] key_s3 = { - ColumnHeaderConstant.TIMESERIES, - ColumnHeaderConstant.ALIAS, - ColumnHeaderConstant.DATABASE, - ColumnHeaderConstant.DATATYPE, - ColumnHeaderConstant.ENCODING, - ColumnHeaderConstant.COMPRESSION, - ColumnHeaderConstant.TAGS, - ColumnHeaderConstant.ATTRIBUTES - }; - String[] value_s3 = { - "root.turbine.d1.s3", "null", "root.turbine", "BOOLEAN", "RLE", "SNAPPY", "null", "null" - }; - ResultSet timeSeriesResultSetForS3 = - statement.executeQuery("SHOW TIMESERIES root.turbine.d1.s3"); - - while (timeSeriesResultSetForS3.next()) { - assertEquals(value_s3[count], timeSeriesResultSetForS3.getString(key_s3[count])); + for (int i = 0; i < keys.length; i++) { + assertEquals(value_columns[count][i], timeSeriesResultSetForS1.getString(keys[i])); + } count++; } } catch (SQLException e) { diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java index 7588bea97dc12..3dac960d65d15 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFloatPrecisionIT.java @@ -27,6 +27,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -40,7 +41,6 @@ import java.util.List; import java.util.StringJoiner; -import static org.apache.iotdb.db.utils.constant.TestConstant.TIMESTAMP_STR; import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -54,8 +54,7 @@ @Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class}) public class IoTDBFloatPrecisionIT { - private static final String INSERT_TEMPLATE_SQL = - "insert into %s(id1,Time,%s) values(%s,%d,%s)"; + private static final String INSERT_TEMPLATE_SQL = "insert into %s(id1,time,%s) values(%s,%d,%s)"; private static List sqls = new ArrayList<>(); private static final int TIMESTAMP = 10; private static final String VALUE = "1.2345678901"; @@ -98,7 +97,6 @@ private static void insertData() { Statement statement = connection.createStatement()) { for (String sql : sqls) { - System.out.println(sql); statement.execute(sql); } } catch (Exception e) { @@ -107,6 +105,9 @@ private static void insertData() { } @Test + @Ignore + // CREATE TIMESERIES root.vehicle.%s.%s WITH DATATYPE=%s, ENCODING=%s, 'MAX_POINT_NUMBER'='%d' + // Should support 'MAX_POINT_NUMBER'='%d' public void selectAllSQLTest() { try (Connection connection = EnvFactory.getEnv().getConnection(TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { @@ -116,7 +117,7 @@ public void selectAllSQLTest() { assertNotNull(resultSet); cnt = 0; while (resultSet.next()) { - assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR)); + assertEquals(TIMESTAMP, resultSet.getTimestamp("time").getTime()); for (int i = 0; i < 10; i++) { assertEquals( MathUtils.roundWithGivenPrecision(Float.parseFloat(VALUE), i), @@ -136,7 +137,7 @@ public void selectAllSQLTest() { try (ResultSet resultSet = statement.executeQuery("select * from vehicle")) { cnt = 0; while (resultSet.next()) { - assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR)); + assertEquals(TIMESTAMP, resultSet.getTimestamp("time").getTime()); for (int i = 0; i < 10; i++) { BigDecimal b = new BigDecimal(VALUE); assertEquals( diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java index a746f82b34579..42d1ce43fc43e 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryIT.java @@ -23,6 +23,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -47,21 +48,22 @@ public class IoTDBFlushQueryIT { private static String[] sqls = new String[] { - "CREATE DATABASE root.vehicle.d0", - "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", - "insert into root.vehicle.d0(timestamp,s0) values(1,101)", - "insert into root.vehicle.d0(timestamp,s0) values(2,198)", - "insert into root.vehicle.d0(timestamp,s0) values(100,99)", - "insert into root.vehicle.d0(timestamp,s0) values(101,99)", - "insert into root.vehicle.d0(timestamp,s0) values(102,80)", - "insert into root.vehicle.d0(timestamp,s0) values(103,99)", - "insert into root.vehicle.d0(timestamp,s0) values(104,90)", - "insert into root.vehicle.d0(timestamp,s0) values(105,99)", - "insert into root.vehicle.d0(timestamp,s0) values(106,99)", + "CREATE DATABASE test", + "USE \"test\"", + "CREATE TABLE vehicle (id1 string id, s0 int32 measurement)", + "insert into vehicle(id1,time,s0) values('d0',1,101)", + "insert into vehicle(id1,time,s0) values('d0',2,198)", + "insert into vehicle(id1,time,s0) values('d0',100,99)", + "insert into vehicle(id1,time,s0) values('d0',101,99)", + "insert into vehicle(id1,time,s0) values('d0',102,80)", + "insert into vehicle(id1,time,s0) values('d0',103,99)", + "insert into vehicle(id1,time,s0) values('d0',104,90)", + "insert into vehicle(id1,time,s0) values('d0',105,99)", + "insert into vehicle(id1,time,s0) values('d0',106,99)", "flush", - "insert into root.vehicle.d0(timestamp,s0) values(2,10000)", - "insert into root.vehicle.d0(timestamp,s0) values(50,10000)", - "insert into root.vehicle.d0(timestamp,s0) values(1000,22222)", + "insert into vehicle(id1,time,s0) values('d0',2,10000)", + "insert into vehicle(id1,time,s0) values('d0',50,10000)", + "insert into vehicle(id1,time,s0) values('d0',1000,22222)", }; @BeforeClass @@ -76,9 +78,10 @@ public static void tearDown() throws Exception { } private static void insertData() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { for (String sql : sqls) { + System.out.println(sql); statement.execute(sql); } } catch (Exception e) { @@ -89,9 +92,10 @@ private static void insertData() { @Test public void selectAllSQLTest() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - try (ResultSet resultSet = statement.executeQuery("SELECT * FROM root.**"); ) { + statement.execute("USE \"test\""); + try (ResultSet resultSet = statement.executeQuery("SELECT * FROM vehicle"); ) { int cnt = 0; while (resultSet.next()) { cnt++; @@ -105,14 +109,18 @@ public void selectAllSQLTest() { @Test public void testFlushGivenGroup() { String insertTemplate = - "INSERT INTO root.group%d(timestamp, s1, s2, s3) VALUES (%d, %d, %f, %s)"; - try (Connection connection = EnvFactory.getEnv().getConnection(); + "INSERT INTO vehicle(id1, time, s1, s2, s3) VALUES (%s, %d, %d, %f, %s)"; + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.group1"); - statement.execute("CREATE DATABASE root.group2"); - statement.execute("CREATE DATABASE root.group3"); + + statement.execute("CREATE DATABASE group1"); + statement.execute("CREATE DATABASE group2"); + statement.execute("CREATE DATABASE group3"); for (int i = 1; i <= 3; i++) { + statement.execute(String.format("USE \"group%d\"", i)); + statement.execute( + "CREATE TABLE vehicle (id1 string id, s1 int32 measurement, s2 float measurement, s3 string measurement)"); for (int j = 10; j < 20; j++) { statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j)); } @@ -120,46 +128,51 @@ public void testFlushGivenGroup() { statement.execute("FLUSH"); for (int i = 1; i <= 3; i++) { + statement.execute(String.format("USE \"group%d\"", i)); for (int j = 0; j < 10; j++) { statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j)); } } - statement.execute("FLUSH root.group1"); - statement.execute("FLUSH root.group2,root.group3"); + statement.execute("FLUSH group1"); + statement.execute("FLUSH group2,group3"); for (int i = 1; i <= 3; i++) { + statement.execute(String.format("USE \"group%d\"", i)); for (int j = 0; j < 30; j++) { statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j)); } } - statement.execute("FLUSH root.group1 TRUE"); - statement.execute("FLUSH root.group2,root.group3 FALSE"); + statement.execute("FLUSH group1 TRUE"); + statement.execute("FLUSH group2,group3 FALSE"); - int i = 0; - try (ResultSet resultSet = - statement.executeQuery("SELECT * FROM root.group1,root.group2,root" + ".group3")) { - while (resultSet.next()) { - i++; + for (int i = 1; i <= 3; i++) { + statement.execute(String.format("USE \"group%d\"", i)); + int count = 0; + try (ResultSet resultSet = statement.executeQuery("SELECT * FROM vehicle")) { + while (resultSet.next()) { + count++; + } } + assertEquals(30, count); } - assertEquals(30, i); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } } @Test public void testFlushGivenGroupNoData() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.nodatagroup1"); - statement.execute("CREATE DATABASE root.nodatagroup2"); - statement.execute("CREATE DATABASE root.nodatagroup3"); - statement.execute("FLUSH root.nodatagroup1"); - statement.execute("FLUSH root.nodatagroup2"); - statement.execute("FLUSH root.nodatagroup3"); - statement.execute("FLUSH root.nodatagroup1, root.nodatagroup2"); + statement.execute("CREATE DATABASE nodatagroup1"); + statement.execute("CREATE DATABASE nodatagroup2"); + statement.execute("CREATE DATABASE nodatagroup3"); + statement.execute("FLUSH nodatagroup1"); + statement.execute("FLUSH nodatagroup2"); + statement.execute("FLUSH nodatagroup3"); + statement.execute("FLUSH nodatagroup1, nodatagroup2"); } catch (Exception e) { fail(e.getMessage()); } From 334aad04a1dae899f8cc48e80ab5ceac60f7227a Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Wed, 24 Jul 2024 18:24:55 +0800 Subject: [PATCH 3/4] modify it --- .../apache/iotdb/db/it/utils/TestUtils.java | 22 ++ .../it/IOTDBInsertWithTimeAtAnyIndexIT.java | 17 +- .../it/db/it/IoTDBInsertMultiPartitionIT.java | 12 +- .../it/db/it/IoTDBInsertMultiRowIT.java | 58 +++--- .../it/db/it/IoTDBInsertNullIT.java | 81 ++------ .../it/db/it/IoTDBInsertWithoutTimeIT.java | 73 ++++--- .../it/db/it/IoTDBMultiDeviceIT.java | 192 ++++++++++++------ .../it/db/it/IoTDBPartialInsertionIT.java | 85 +++++--- .../relational/it/db/it/IoTDBRecoverIT.java | 85 ++++---- .../it/db/it/IoTDBRecoverUnclosedIT.java | 80 ++++---- .../relational/it/db/it/IoTDBRestartIT.java | 18 +- ...IoTDBSameMeasurementsDifferentTypesIT.java | 3 + .../aligned/IoTDBInsertAlignedValues2IT.java | 64 +++--- .../aligned/IoTDBInsertAlignedValues3IT.java | 21 +- .../aligned/IoTDBInsertAlignedValues4IT.java | 23 ++- .../aligned/IoTDBInsertAlignedValuesIT.java | 132 +++++++----- .../db/it/schema/IoTDBAutoCreateSchemaIT.java | 2 + .../it/schema/IoTDBCreateStorageGroupIT.java | 14 +- .../db/it/schema/IoTDBCreateTimeseriesIT.java | 2 + 19 files changed, 565 insertions(+), 419 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java index d2712df7f5908..f288385758541 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java @@ -369,11 +369,21 @@ public static void assertNonQueryTestFail(String sql, String errMsg) { assertNonQueryTestFail(sql, errMsg, SessionConfig.DEFAULT_USER, SessionConfig.DEFAULT_PASSWORD); } + public static void assertTableNonQueryTestFail(String sql, String errMsg, String dbName) { + assertTableNonQueryTestFail( + sql, errMsg, SessionConfig.DEFAULT_USER, SessionConfig.DEFAULT_PASSWORD, dbName); + } + public static void assertNonQueryTestFail( String sql, String errMsg, String userName, String password) { assertNonQueryTestFail(EnvFactory.getEnv(), sql, errMsg, userName, password); } + public static void assertTableNonQueryTestFail( + String sql, String errMsg, String userName, String password, String dbName) { + assertTableNonQueryTestFail(EnvFactory.getEnv(), sql, errMsg, userName, password, dbName); + } + public static void assertNonQueryTestFail( BaseEnv env, String sql, String errMsg, String userName, String password) { try (Connection connection = env.getConnection(userName, password); @@ -385,6 +395,18 @@ public static void assertNonQueryTestFail( } } + public static void assertTableNonQueryTestFail( + BaseEnv env, String sql, String errMsg, String userName, String password, String db) { + try (Connection connection = env.getConnection(userName, password, BaseEnv.TABLE_SQL_DIALECT); + Statement statement = connection.createStatement()) { + statement.execute("use " + "\"" + db + "\""); + statement.execute(sql); + fail("No exception!"); + } catch (SQLException e) { + Assert.assertTrue(e.getMessage(), e.getMessage().contains(errMsg)); + } + } + public static void assertResultSetEqual( ResultSet actualResultSet, String expectedHeader, String[] expectedRetArray) { assertResultSetEqual( diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java index 84a7b783961f9..cfe7d8c2ecfa6 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IOTDBInsertWithTimeAtAnyIndexIT.java @@ -59,12 +59,16 @@ public static void tearDown() throws Exception { public void testInsertTimeAtAnyIndex() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { - statement.addBatch("insert into root.db.d1(s1, s2, time) aligned values (2, 3, 1)"); - statement.addBatch("insert into root.db.d1(s1, time, s2) aligned values (20, 10, 30)"); - statement.addBatch("insert into root.db.d1(`time`, s1, s2) aligned values (100, 200, 300)"); + statement.addBatch("create database test"); + statement.addBatch("use \"test\""); + statement.addBatch( + "create table (id1 string id, s1 int32 measurement, s2 int32 measurement)"); + statement.addBatch("insert into db(id, s1, s2, time) ('d1', 2, 3, 1)"); + statement.addBatch("insert into db(id, s1, time, s2) values ('d1', 20, 10, 30)"); + statement.addBatch("insert into db(id, `time`, s1, s2) values ('d1', 100, 200, 300)"); statement.executeBatch(); - try (ResultSet resultSet = statement.executeQuery("select s1 from root.db.d1")) { + try (ResultSet resultSet = statement.executeQuery("select time, s1 from db")) { assertTrue(resultSet.next()); assertEquals(1, resultSet.getLong(1)); assertEquals(2, resultSet.getDouble(2), 0.00001); @@ -84,8 +88,11 @@ public void testInsertMultiTime() { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { try { + statement.addBatch("create database test"); + statement.addBatch("use \"test\""); statement.addBatch( - "insert into root.db.d1(s1, s2, time, time) aligned values (2, 3, 1, 1)"); + "create table (id1 string id, s1 int32 measurement, s2 int32 measurement)"); + statement.addBatch("insert into db(id1, s1, s2, time, time) values ('d1', 2, 3, 1, 1)"); statement.executeBatch(); fail(); } catch (SQLException e) { diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java index 234e1eb2479e4..3d3654de265bf 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiPartitionIT.java @@ -24,6 +24,7 @@ import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; import org.apache.iotdb.itbase.category.RemoteIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -57,12 +58,15 @@ public static void tearDown() throws Exception { @Test public void testInsertMultiPartition() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.sg.d1(time,s1) values(1,2)"); + statement.execute("create database test"); + statement.execute("use \"test\""); + statement.execute("create table sg (id1 string id, s1 int32 measurement)"); + statement.execute("insert into sg(id1,time,s1) values('d1',1,2)"); statement.execute("flush"); - statement.execute("insert into root.sg.d1(time,s1) values(2,2)"); - statement.execute("insert into root.sg.d1(time,s1) values(604800001,2)"); + statement.execute("insert into sg(id1,time,s1) values('d1',2,2)"); + statement.execute("insert into sg(id1,time,s1) values('d1',604800001,2)"); statement.execute("flush"); } catch (Exception e) { fail(e.getMessage()); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java index 686a5dcef4f71..2509766e4f6d7 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertMultiRowIT.java @@ -23,10 +23,12 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.apache.iotdb.rpc.TSStatusCode; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -44,10 +46,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -/** - * @Author: Architect @Date: 2021-03-30 18:36 @Description: This class is initially intend to test - * the issue of IOTDB-924 - */ @RunWith(IoTDBTestRunner.class) @Category({LocalStandaloneIT.class, ClusterIT.class}) public class IoTDBInsertMultiRowIT { @@ -79,13 +77,14 @@ private static void close() { } private static void initCreateSQLStatement() { - sqls.add("CREATE DATABASE root.t1"); - sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN"); - sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE"); + sqls.add("CREATE DATABASE t1"); + sqls.add("USE \"t1\""); + sqls.add( + "create table wf01 (id1 string id, status boolean measurement, temperature float measurement)"); } private static void insertData() throws ClassNotFoundException, SQLException { - connection = EnvFactory.getEnv().getConnection(); + connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement(); for (String sql : sqls) { @@ -98,26 +97,25 @@ private static void insertData() throws ClassNotFoundException, SQLException { @Test public void testInsertMultiRow() throws SQLException { Statement st0 = connection.createStatement(); - st0.execute("insert into root.t1.wf01.wt01(timestamp, status) values (1, true)"); - st0.execute("insert into root.t1.wf01.wt01(timestamp, status) values (2, true),(3, false)"); + st0.execute("insert into wf01(id1, time, status) values ('wt01', 1, true)"); + st0.execute("insert into wf01(id1, time, status) values ('wt01', 2, true), ('wt01', 3, false)"); st0.execute( - "insert into root.t1.wf01.wt01(timestamp, status) values (4, true),(5, true),(6, false)"); + "insert into wf01(id1, time, status) values ('wt01', 4, true), ('wt01', 5, true), ('wt01', 6, false)"); + st0.execute("insert into wf01(id1, time, temperature, status) values ('wt01', 7, 15.3, true)"); st0.execute( - "insert into root.t1.wf01.wt01(timestamp, temperature, status) values (7, 15.3, true)"); - st0.execute( - "insert into root.t1.wf01.wt01(timestamp, temperature, status) values (8, 18.3, false),(9, 23.1, false)"); + "insert into wf01(id1, time, temperature, status) values ('wt01', 8, 18.3, false), ('wt01', 9, 23.1, false)"); st0.execute( - "insert into root.t1.wf01.wt01(timestamp, temperature, status) values (10, 22.3, true),(11, 18.8, false),(12, 24.4, true)"); + "insert into wf01(id1, time, temperature, status) values ('wt01', 10, 22.3, true), ('wt01', 11, 18.8, false), ('wt01', 12, 24.4, true)"); st0.close(); Statement st1 = connection.createStatement(); - ResultSet rs1 = st1.executeQuery("select count(status) from root.t1.wf01.wt01"); + ResultSet rs1 = st1.executeQuery("select count(status) from wf01"); rs1.next(); long countStatus = rs1.getLong(1); assertEquals(countStatus, 12L); - ResultSet rs2 = st1.executeQuery("select count(temperature) from root.t1.wf01.wt01"); + ResultSet rs2 = st1.executeQuery("select count(temperature) from wf01"); rs2.next(); long countTemperature = rs2.getLong(1); assertEquals(countTemperature, 6L); @@ -126,16 +124,18 @@ public void testInsertMultiRow() throws SQLException { } @Test(expected = Exception.class) + @Ignore public void testInsertWithTimesColumns() throws SQLException { Statement st1 = connection.createStatement(); - st1.execute("insert into root.t1.wf01.wt01(timestamp) values(1)"); + st1.execute("insert into wf01(id1,time) values('wt01', 1)"); } @Test public void testInsertMultiRowWithMisMatchDataType() { try { Statement st1 = connection.createStatement(); - st1.execute("insert into root.t1.wf01.wt01(timestamp, s1) values(1, 1.0), (2, 'hello')"); + st1.execute( + "insert into wf01(id1, time, status) values('wt01', 1, 1.0), ('wt01', 2, 'hello')"); fail(); } catch (SQLException e) { assertTrue( @@ -144,10 +144,11 @@ public void testInsertMultiRowWithMisMatchDataType() { } @Test + @Ignore // TODO: delete public void testInsertMultiRowWithNull() { try (Statement st1 = connection.createStatement()) { st1.execute( - "insert into root.t1.d99.wt01(timestamp, s1, s2) values(100, null, 1), (101, null, 2)"); + "insert into root.t1.d99.wt01(time, s1, s2) values(100, null, 1), (101, null, 2)"); fail(); } catch (SQLException e) { assertTrue( @@ -156,7 +157,7 @@ public void testInsertMultiRowWithNull() { try (Statement st2 = connection.createStatement()) { st2.execute("CREATE TIMESERIES root.t1.d1.s1 WITH DATATYPE=double, ENCODING=PLAIN;"); st2.execute( - "INSERT INTO root.t1.d1(timestamp, s1) VALUES (6, 10),(7,12),(8,14),(9,160),(10,null),(11,58)"); + "INSERT INTO root.t1.d1(time, s1) VALUES (6, 10),(7,12),(8,14),(9,160),(10,null),(11,58)"); } catch (SQLException e) { fail(); } @@ -166,7 +167,7 @@ public void testInsertMultiRowWithNull() { public void testInsertMultiRowWithWrongTimestampPrecision() { try (Statement st1 = connection.createStatement()) { st1.execute( - "insert into root.t1.d99.wt01(timestamp, s1, s2) values(1618283005586000, 1, 1), (1618283005586001, 1, 2)"); + "insert into wf01(id1, time, status) values('wt01', 1618283005586000, true), ('wt01', 1618283005586001, false)"); fail(); } catch (SQLException e) { assertTrue(e.getMessage().contains("Current system timestamp precision is ms")); @@ -176,17 +177,18 @@ public void testInsertMultiRowWithWrongTimestampPrecision() { @Test public void testInsertMultiRowWithMultiTimePartition() throws Exception { try (Statement st1 = connection.createStatement()) { - st1.execute("insert into root.sg1.d1(time,s1) values(604800010,1)"); + st1.execute("create table sg1 (id1 string id, s1 int32 measurement)"); + st1.execute("insert into sg1(id1, time, s1) values('d1', 604800010,1)"); st1.execute("flush"); - st1.execute("insert into root.sg1.d1(time,s1) values(604799990,1), (604800001,1)"); + st1.execute("insert into sg1(id1, time, s1) values('d1', 604799990,1), ('d1', 604800001,1)"); st1.execute("flush"); - ResultSet rs1 = st1.executeQuery("select s1 from root.sg1.d1"); + ResultSet rs1 = st1.executeQuery("select time, s1 from sg1"); assertTrue(rs1.next()); - assertEquals(604799990, rs1.getLong("Time")); + assertEquals(604799990, rs1.getLong("time")); assertTrue(rs1.next()); - assertEquals(604800001, rs1.getLong("Time")); + assertEquals(604800001, rs1.getLong("time")); assertTrue(rs1.next()); - assertEquals(604800010, rs1.getLong("Time")); + assertEquals(604800010, rs1.getLong("time")); assertFalse(rs1.next()); } } diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java index 2e51000a96554..75c2a7093d63a 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertNullIT.java @@ -23,6 +23,7 @@ import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; import org.apache.iotdb.itbase.category.RemoteIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -76,15 +77,14 @@ private static void close() { } private static void initCreateSQLStatement() { - sqls.add("CREATE DATABASE root.sg"); - sqls.add("CREATE TIMESERIES root.sg.d1.s1 WITH DATATYPE=BOOLEAN"); - sqls.add("CREATE TIMESERIES root.sg.d1.s2 WITH DATATYPE=FLOAT"); - sqls.add("CREATE TIMESERIES root.sg.d1.s3 WITH DATATYPE=INT32"); - sqls.add("CREATE ALIGNED TIMESERIES root.sg.d2(s1 BOOLEAN,s2 FLOAT,s3 INT32)"); + sqls.add("CREATE DATABASE test"); + sqls.add("USE \"test\""); + sqls.add( + "CREATE TABLE sg (id1 string id, s1 boolean measurement, s2 float measurement, s3 int32 measurement)"); } private static void insertData() throws SQLException { - connection = EnvFactory.getEnv().getConnection(); + connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement(); for (String sql : sqls) { @@ -98,24 +98,25 @@ private static void insertData() throws SQLException { public void testInsertNull() { String[] retArray = new String[] { - "1,null,1.0,1,", "2,true,null,2,", "3,true,3.0,null,", + "1,d2,null,1.0,1,", "2,d2,true,null,2,", "3,d2,true,3.0,null,", }; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.sg.d1(time,s1,s2,s3) values(1,null,1.0,1)"); - statement.execute("insert into root.sg.d1(time,s1,s2,s3) values(2,true,null,2)"); - statement.execute("insert into root.sg.d1(time,s1,s2,s3) values(3,true,3.0,null)"); + statement.execute("use \"test\""); + statement.execute("insert into sg(id1,time,s1,s2,s3) values('d2',1,null,1.0,1)"); + statement.execute("insert into sg(id1,time,s1,s2,s3) values('d2',2,true,null,2)"); + statement.execute("insert into sg(id1,time,s1,s2,s3) values('d2',3,true,3.0,null)"); - try (ResultSet resultSet = statement.executeQuery("select * from root.sg.d1")) { + try (ResultSet resultSet = statement.executeQuery("select * from sg")) { assertNotNull(resultSet); ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); List actualIndexToExpectedIndexList = checkHeader( resultSetMetaData, - "Time,root.sg.d1.s1,root.sg.d1.s2,root.sg.d1.s3", + "time,id1,s1,s2,s3", new int[] { - Types.TIMESTAMP, Types.BOOLEAN, Types.FLOAT, Types.INTEGER, + Types.TIMESTAMP, Types.VARCHAR, Types.BOOLEAN, Types.FLOAT, Types.INTEGER, }); int cnt = 0; @@ -124,53 +125,11 @@ public void testInsertNull() { StringBuilder expectedBuilder = new StringBuilder(); StringBuilder actualBuilder = new StringBuilder(); for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { - actualBuilder.append(resultSet.getString(i)).append(","); - expectedBuilder - .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)]) - .append(","); - } - assertEquals(expectedBuilder.toString(), actualBuilder.toString()); - cnt++; - } - assertEquals(3, cnt); - } - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void testInsertAlignedNull() { - String[] retArray = - new String[] { - "1,null,1.0,1,", "2,true,null,2,", "3,true,3.0,null,", - }; - - try (Connection connection = EnvFactory.getEnv().getConnection(); - Statement statement = connection.createStatement()) { - statement.execute("insert into root.sg.d2(time,s1,s2,s3) aligned values(1,null,1.0,1)"); - statement.execute("insert into root.sg.d2(time,s1,s2,s3) aligned values(2,true,null,2)"); - statement.execute("insert into root.sg.d2(time,s1,s2,s3) aligned values(3,true,3.0,null)"); - - try (ResultSet resultSet = statement.executeQuery("select * from root.sg.d2")) { - assertNotNull(resultSet); - ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); - List actualIndexToExpectedIndexList = - checkHeader( - resultSetMetaData, - "Time,root.sg.d2.s1,root.sg.d2.s2,root.sg.d2.s3", - new int[] { - Types.TIMESTAMP, Types.BOOLEAN, Types.FLOAT, Types.INTEGER, - }); - - int cnt = 0; - while (resultSet.next()) { - String[] expectedStrings = retArray[cnt].split(","); - StringBuilder expectedBuilder = new StringBuilder(); - StringBuilder actualBuilder = new StringBuilder(); - for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { - actualBuilder.append(resultSet.getString(i)).append(","); + if (i == 1) { + actualBuilder.append(resultSet.getTimestamp(i).getTime()).append(","); + } else { + actualBuilder.append(resultSet.getString(i)).append(","); + } expectedBuilder .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)]) .append(","); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java index ac5ef5786d24b..2106626aace81 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertWithoutTimeIT.java @@ -23,9 +23,11 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -36,7 +38,7 @@ import java.util.Arrays; import java.util.List; -import static org.apache.iotdb.db.it.utils.TestUtils.assertNonQueryTestFail; +import static org.apache.iotdb.db.it.utils.TestUtils.assertTableNonQueryTestFail; import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest; import static org.junit.Assert.fail; @@ -46,15 +48,14 @@ public class IoTDBInsertWithoutTimeIT { private static final List sqls = Arrays.asList( - "CREATE DATABASE root.sg1", - "CREATE TIMESERIES root.sg1.d1.s1 INT64", - "CREATE TIMESERIES root.sg1.d1.s2 FLOAT", - "CREATE TIMESERIES root.sg1.d1.s3 TEXT"); + "CREATE DATABASE test", + "USE \"test\"", + "CREATE TABLE sg1(id1 string id, s1 int64 measurement, s2 float measurement, s3 string measurement)"); @Before public void setUp() throws Exception { EnvFactory.getEnv().initClusterEnvironment(); - createTimeseries(); + createTable(); } @After @@ -62,8 +63,8 @@ public void tearDown() throws Exception { EnvFactory.getEnv().cleanClusterEnvironment(); } - private void createTimeseries() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + private void createTable() { + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { for (String sql : sqls) { statement.execute(sql); @@ -76,52 +77,58 @@ private void createTimeseries() { @Test public void testInsertWithoutTime() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.sg1.d1(s1, s2, s3) values (1, 1, '1')"); + statement.execute("use \"test\""); + statement.execute("insert into sg1(id1, s1, s2, s3) values ('d1',1, 1, '1')"); Thread.sleep(1); - statement.execute("insert into root.sg1.d1(s2, s1, s3) values (2, 2, '2')"); + statement.execute("insert into sg1(id1, s2, s1, s3) values ('d1',2, 2, '2')"); Thread.sleep(1); - statement.execute("insert into root.sg1.d1(s3, s2, s1) values ('3', 3, 3)"); + statement.execute("insert into sg1(id1, s3, s2, s1) values ('d1','3', 3, 3)"); Thread.sleep(1); - statement.execute("insert into root.sg1.d1(s1) values (1)"); - statement.execute("insert into root.sg1.d1(s2) values (2)"); - statement.execute("insert into root.sg1.d1(s3) values ('3')"); + statement.execute("insert into sg1(id1, s1) values ('d1',1)"); + statement.execute("insert into sg1(id1, s2) values ('d1',2)"); + statement.execute("insert into sg1(id1, s3) values ('d1','3')"); } catch (SQLException | InterruptedException e) { e.printStackTrace(); fail(e.getMessage()); } - String expectedHeader = "count(root.sg1.d1.s1),count(root.sg1.d1.s2),count(root.sg1.d1.s3),"; + String expectedHeader = "count(s1),count(s2),count(s3),"; String[] retArray = new String[] {"4,4,4,"}; - resultSetEqualTest( - "select count(s1), count(s2), count(s3) from root.sg1.d1", expectedHeader, retArray); + resultSetEqualTest("select count(s1), count(s2), count(s3) from sg1", expectedHeader, retArray); } @Test + @Ignore // TODO: delete public void testInsertWithoutValueColumns() { - assertNonQueryTestFail( - "insert into root.sg1.d1(time) values (1)", - "InsertStatement should contain at least one measurement"); + assertTableNonQueryTestFail( + "insert into sg1(id1, time) values ('d1', 1)", + "InsertStatement should contain at least one measurement", + "test"); } @Test public void testInsertMultiRow() { - assertNonQueryTestFail( - "insert into root.sg1.d1(s3) values ('1'), ('2')", - "need timestamps when insert multi rows"); - assertNonQueryTestFail( - "insert into root.sg1.d1(s1, s2) values (1, 1), (2, 2)", - "need timestamps when insert multi rows"); + assertTableNonQueryTestFail( + "insert into sg1(s3) values ('d1', '1'), ('d1', '2')", + "need timestamps when insert multi rows", + "test"); + assertTableNonQueryTestFail( + "insert into sg1(id1, s1, s2) values ('d1', 1, 1), ('d1', 2, 2)", + "need timestamps when insert multi rows", + "test"); } @Test public void testInsertWithMultiTimesColumns() { - assertNonQueryTestFail( - "insert into root.sg1.d1(time, time) values (1, 1)", - "One row should only have one time value"); - assertNonQueryTestFail( - "insert into root.sg1.d1(time, s1, time) values (1, 1, 1)", - "One row should only have one time value"); + assertTableNonQueryTestFail( + "insert into sg1(id1, time, time) values ('d1', 1, 1)", + "One row should only have one time value", + "test"); + assertTableNonQueryTestFail( + "insert into sg1(id1, time, s1, time) values ('d1', 1, 1, 1)", + "One row should only have one time value", + "test"); } } diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java index f154bd2bc1701..87e65870c6062 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiDeviceIT.java @@ -23,6 +23,7 @@ import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; import org.apache.iotdb.itbase.constant.TestConstant; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; @@ -33,6 +34,8 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -70,39 +73,48 @@ public void tearDown() throws Exception { } private static void insertData() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { for (String sql : TestConstant.createSql) { statement.addBatch(sql); } - statement.addBatch("CREATE DATABASE root.fans"); - statement.addBatch("CREATE TIMESERIES root.fans.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE"); - statement.addBatch("CREATE TIMESERIES root.fans.d1.s0 WITH DATATYPE=INT32, ENCODING=RLE"); - statement.addBatch("CREATE TIMESERIES root.fans.d2.s0 WITH DATATYPE=INT32, ENCODING=RLE"); - statement.addBatch("CREATE TIMESERIES root.fans.d3.s0 WITH DATATYPE=INT32, ENCODING=RLE"); - statement.addBatch("CREATE TIMESERIES root.car.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE"); - statement.addBatch("CREATE TIMESERIES root.car.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE"); - statement.addBatch("CREATE TIMESERIES root.car.d2.s1 WITH DATATYPE=INT64, ENCODING=RLE"); + statement.addBatch("CREATE DATABASE test"); + statement.addBatch("USE \"test\""); + statement.addBatch( + "create table t (id1 string id, id2 string id, s0 int32 measurement, s1 int32 measurement)"); // insert of data time range :0-100 into fans for (int time = 0; time < 100; time++) { String sql = - String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + String.format( + "insert into t(id1,id2,time,s0) values('fans','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d2',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d3','%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d2',%s,%s)", time, time % 4); statement.addBatch(sql); } @@ -110,19 +122,32 @@ private static void insertData() { for (int time = 1370; time < 2400; time++) { String sql = - String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + String.format( + "insert into t(id1,id2,time,s0) values('fans','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d2',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d3','%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d2',%s,%s)", time, time % 4); statement.addBatch(sql); } @@ -130,19 +155,32 @@ private static void insertData() { for (int time = 300; time < 1360; time++) { // System.out.println("===" + time); String sql = - String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + String.format( + "insert into t(id1,id2,time,s0) values('fans','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d2',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d3','%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d2',%s,%s)", time, time % 4); statement.addBatch(sql); } @@ -152,19 +190,32 @@ private static void insertData() { for (int time = 1000; time < 1100; time++) { String sql = - String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + String.format( + "insert into t(id1,id2,time,s0) values('fans','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d2',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d3','%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d2',%s,%s)", time, time % 4); statement.addBatch(sql); } @@ -172,19 +223,32 @@ private static void insertData() { for (int time = 20000; time < 20100; time++) { String sql = - String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 7); + String.format( + "insert into t(id1,id2,time,s0) values('fans','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d2',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1,id2,time,s0) values('fans','d3','%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 7); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d0',%s,%s)", time, time % 7); statement.addBatch(sql); - sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d1',%s,%s)", time, time % 4); statement.addBatch(sql); - sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 4); + sql = + String.format( + "insert into t(id1, id2,time,s0) values('car','d2',%s,%s)", time, time % 4); statement.addBatch(sql); } statement.executeBatch(); @@ -202,22 +266,25 @@ public void testMultiDeviceQueryAndDelete() { } private void testSelectAll() { - String selectSql = "select * from root.**"; + String selectSql = "select * from t"; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("use \"test\""); + Map lastTimeMap = new HashMap<>(); try (ResultSet resultSet = statement.executeQuery(selectSql)) { int cnt = 0; - long before = -1; while (resultSet.next()) { - long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + String id = resultSet.getString("id1") + "_" + resultSet.getString("id2"); + long before = lastTimeMap.getOrDefault(id, -1L); + long cur = resultSet.getTimestamp("time").getTime(); if (cur <= before) { fail("time order wrong!"); } - before = cur; + lastTimeMap.put(id, cur); cnt++; } - assertEquals(2290, cnt); + assertEquals(13740, cnt); } } catch (Exception e) { e.printStackTrace(); @@ -226,21 +293,22 @@ private void testSelectAll() { } private void testSelectAfterDelete() { - String selectSql = "select * from root.**"; + String selectSql = "select * from t"; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("USE \"test\""); - statement.execute("DELETE FROM root.fans.** WHERE time <= 100"); - statement.execute("DELETE FROM root.car.** WHERE time <= 100"); - statement.execute("DELETE FROM root.fans.** WHERE time >= 20050 and time < 20100"); - statement.execute("DELETE FROM root.car.** WHERE time >= 20050 and time < 20100"); + statement.execute("DELETE FROM t WHERE id1='fans' and time <= 100"); + statement.execute("DELETE FROM t WHERE id1='car' and time <= 100"); + statement.execute("DELETE FROM t WHERE id1='fans' and time >= 20050 and time < 20100"); + statement.execute("DELETE FROM t WHERE id1='car' and time >= 20050 and time < 20100"); try (ResultSet resultSet = statement.executeQuery(selectSql)) { int cnt = 0; long before = -1; while (resultSet.next()) { - long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + long cur = Long.parseLong(resultSet.getString("time")); if (cur <= before) { fail("time order wrong!"); } @@ -250,14 +318,14 @@ private void testSelectAfterDelete() { assertEquals(2140, cnt); } - statement.execute("DELETE FROM root.fans.** WHERE time <= 20000"); - statement.execute("DELETE FROM root.car.** WHERE time <= 20000"); + statement.execute("DELETE FROM t WHERE id1 = 'fans' and time <= 20000"); + statement.execute("DELETE FROM t WHERE id1 = 'car' and time <= 20000"); try (ResultSet resultSet = statement.executeQuery(selectSql)) { int cnt = 0; long before = -1; while (resultSet.next()) { - long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + long cur = resultSet.getTimestamp("time").getTime(); if (cur <= before) { fail("time order wrong!"); } @@ -267,13 +335,13 @@ private void testSelectAfterDelete() { assertEquals(49, cnt); } - statement.execute("DELETE FROM root.** WHERE time >= 20000"); + statement.execute("DELETE FROM t WHERE time >= 20000"); try (ResultSet resultSet = statement.executeQuery(selectSql)) { int cnt = 0; long before = -1; while (resultSet.next()) { - long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR)); + long cur = resultSet.getTimestamp("time").getTime(); if (cur <= before) { fail("time order wrong!"); } diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java index 28ac8a17baf61..c3aa94c728906 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPartialInsertionIT.java @@ -24,10 +24,9 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.apache.tsfile.enums.TSDataType; -import org.apache.tsfile.file.metadata.enums.CompressionType; -import org.apache.tsfile.file.metadata.enums.TSEncoding; import org.apache.tsfile.read.common.RowRecord; import org.apache.tsfile.write.record.Tablet; import org.apache.tsfile.write.schema.IMeasurementSchema; @@ -46,6 +45,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertEquals; @@ -72,13 +72,14 @@ public void tearDown() throws Exception { @Test public void testPartialInsertionAllFailed() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.sg1"); - try { - statement.execute("INSERT INTO root.sg1(timestamp, s0) VALUES (1, 1)"); + statement.execute("CREATE DATABASE test"); + statement.execute("USE \"test\""); + statement.execute("create table sg1 (id1 string id, s0 int32 measurement)"); + statement.execute("INSERT INTO sg1(id1, timestamp, s0) VALUES ('id', 1, 1)"); fail(); } catch (SQLException e) { assertTrue(e.getMessage().contains("Path [root.sg1.s0] does not exist")); @@ -91,12 +92,13 @@ public void testPartialInsertionRestart() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.sg"); - statement.execute("CREATE TIMESERIES root.sg.d1.s1 datatype=text"); - statement.execute("CREATE TIMESERIES root.sg.d1.s2 datatype=double"); + statement.execute("CREATE DATABASE test"); + statement.execute("USE \"test\""); + statement.execute( + "create table sg (id1 string id, s1 text measurement, s2 double measurement)"); try { - statement.execute("INSERT INTO root.sg.d1(time,s1,s2) VALUES(100,'test','test')"); + statement.execute("INSERT INTO sg(id1,time,s1,s2) VALUES('d1', 100,'test','test')"); } catch (SQLException e) { // ignore } @@ -121,19 +123,20 @@ public void testPartialInsertionRestart() throws SQLException { } */ - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("use \"test\""); - try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg.d1")) { + try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM sg")) { assertNotNull(resultSet); int cnt = 0; while (resultSet.next()) { cnt++; - assertEquals("test", resultSet.getString("root.sg.d1.s1")); + assertEquals("test", resultSet.getString("s1")); } assertEquals(1, cnt); } - try (ResultSet resultSet = statement.executeQuery("SELECT s2 FROM root.sg.d1")) { + try (ResultSet resultSet = statement.executeQuery("SELECT s2 FROM sg")) { assertNotNull(resultSet); assertFalse(resultSet.next()); } @@ -142,23 +145,34 @@ public void testPartialInsertionRestart() throws SQLException { @Test public void testPartialInsertTablet() { - try (ISession session = EnvFactory.getEnv().getSessionConnection()) { - session.createTimeseries( - "root.sg1.d1.s1", TSDataType.INT64, TSEncoding.PLAIN, CompressionType.SNAPPY); - session.createTimeseries( - "root.sg1.d1.s2", TSDataType.INT64, TSEncoding.PLAIN, CompressionType.SNAPPY); + try (ISession session = EnvFactory.getEnv().getSessionConnection(BaseEnv.TABLE_SQL_DIALECT)) { + session.executeNonQueryStatement("create database test"); + session.executeNonQueryStatement("use \"test\""); + session.executeNonQueryStatement( + "create table sg1 (id1 string id, s1 int64 measurement, s2 int64 measurement)"); List schemaList = new ArrayList<>(); + schemaList.add(new MeasurementSchema("id1", TSDataType.STRING)); schemaList.add(new MeasurementSchema("s1", TSDataType.INT64)); schemaList.add(new MeasurementSchema("s2", TSDataType.INT64)); schemaList.add(new MeasurementSchema("s3", TSDataType.INT64)); - Tablet tablet = new Tablet("root.sg1.d1", schemaList, 300); + final List columnTypes = + Arrays.asList( + Tablet.ColumnType.ID, + Tablet.ColumnType.MEASUREMENT, + Tablet.ColumnType.MEASUREMENT, + Tablet.ColumnType.MEASUREMENT); + Tablet tablet = new Tablet("sg1", schemaList, columnTypes, 300); long timestamp = 0; for (long row = 0; row < 100; row++) { int rowIndex = tablet.rowSize++; tablet.addTimestamp(rowIndex, timestamp); - for (int s = 0; s < 3; s++) { + for (int s = 0; s < 4; s++) { long value = timestamp; - tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value); + if (s == 0) { + tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, "d1"); + } else { + tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value); + } } timestamp++; } @@ -166,30 +180,35 @@ public void testPartialInsertTablet() { for (long row = 0; row < 100; row++) { int rowIndex = tablet.rowSize++; tablet.addTimestamp(rowIndex, timestamp); - for (int s = 0; s < 3; s++) { + for (int s = 0; s < 4; s++) { long value = timestamp; - tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value); + if (s == 0) { + tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, "d1"); + } else { + tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value); + } } timestamp++; } try { - session.insertTablet(tablet); + session.insertRelationalTablet(tablet); } catch (Exception e) { if (!e.getMessage().contains("507")) { fail(e.getMessage()); } } - try (SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM root.sg1.d1")) { - assertEquals(dataSet.getColumnNames().size(), 3); - assertEquals(dataSet.getColumnNames().get(0), "Time"); - assertEquals(dataSet.getColumnNames().get(1), "root.sg1.d1.s1"); - assertEquals(dataSet.getColumnNames().get(2), "root.sg1.d1.s2"); + try (SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM sg1")) { + assertEquals(dataSet.getColumnNames().size(), 4); + assertEquals(dataSet.getColumnNames().get(0), "time"); + assertEquals(dataSet.getColumnNames().get(1), "id1"); + assertEquals(dataSet.getColumnNames().get(2), "s1"); + assertEquals(dataSet.getColumnNames().get(3), "s2"); int cnt = 0; while (dataSet.hasNext()) { RowRecord rowRecord = dataSet.next(); - long time = rowRecord.getTimestamp(); - assertEquals(time, rowRecord.getFields().get(0).getLongV()); - assertEquals(time, rowRecord.getFields().get(1).getLongV()); + long time = rowRecord.getFields().get(0).getLongV(); + assertEquals(time, rowRecord.getFields().get(2).getLongV()); + assertEquals(time, rowRecord.getFields().get(3).getLongV()); cnt++; } Assert.assertEquals(200, cnt); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java index c6f28609ada18..881e9c0fa939e 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverIT.java @@ -24,6 +24,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Assert; @@ -53,38 +54,33 @@ public class IoTDBRecoverIT { private static final Logger logger = LoggerFactory.getLogger(IoTDBRecoverIT.class); private static final String TIMESTAMP_STR = "Time"; - private static final String TEMPERATURE_STR = "root.ln.wf01.wt01.temperature"; + private static final String TEMPERATURE_STR = "temperature"; private static final String[] creationSqls = new String[] { - "CREATE DATABASE root.vehicle.d0", - "CREATE DATABASE root.vehicle.d1", - "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", - "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE", - "CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE", - "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN", - "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN" + "CREATE DATABASE test", + "USE \"test\"", + "CREATE TABLE vehicle (id1 string id, s0 int32 measurement, s1 int64 measurement, s2 float measurement, s3 text measurement, s4 boolean measurement)" }; private static final String[] dataSet2 = new String[] { - "CREATE DATABASE root.ln.wf01.wt01", - "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", - "CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=PLAIN", - "CREATE TIMESERIES root.ln.wf01.wt01.hardware WITH DATATYPE=INT32, ENCODING=PLAIN", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(1, 1.1, false, 11)", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(2, 2.2, true, 22)", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(3, 3.3, false, 33 )", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(4, 4.4, false, 44)", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(5, 5.5, false, 55)" + "CREATE DATABASE ln", + "USE \"ln\"", + "CREATE TABLE wf01 (id1 string id, status boolean measurement, temperature float measurement, hardware int32 measurement)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 1, 1.1, false, 11)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 2, 2.2, true, 22)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 3, 3.3, false, 33 )", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 4, 4.4, false, 44)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01',5, 5.5, false, 55)" }; - private final String d0s0 = "root.vehicle.d0.s0"; - private final String d0s1 = "root.vehicle.d0.s1"; - private final String d0s2 = "root.vehicle.d0.s2"; - private final String d0s3 = "root.vehicle.d0.s3"; + private final String d0s0 = "s0"; + private final String d0s1 = "s1"; + private final String d0s2 = "s2"; + private final String d0s3 = "s3"; @Before public void setUp() throws Exception { @@ -111,37 +107,34 @@ public void recoverTest1() { // check cluster whether restart ((AbstractEnv) EnvFactory.getEnv()).checkClusterStatusWithoutUnknown(); String[] retArray = new String[] {"0,2", "0,4", "0,3"}; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - String selectSql = "select count(temperature) from root.ln.wf01.wt01 where time > 3"; + statement.execute("use \"ln\""); + String selectSql = "select count(temperature) from wf01 where time > 3"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(TEMPERATURE_STR)); + resultSet.getString("time") + "," + resultSet.getString(count(TEMPERATURE_STR)); Assert.assertEquals(retArray[0], ans); } - selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where time > 3"; + selectSql = "select min_time(temperature) from wf01 where time > 3"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) - + "," - + resultSet.getString(minTime(TEMPERATURE_STR)); + resultSet.getString("time") + "," + resultSet.getString(minTime(TEMPERATURE_STR)); Assert.assertEquals(retArray[1], ans); } - selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where temperature > 3"; + selectSql = "select min_time(temperature) from wf01 where temperature > 3"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) - + "," - + resultSet.getString(minTime(TEMPERATURE_STR)); + resultSet.getString("time") + "," + resultSet.getString(minTime(TEMPERATURE_STR)); Assert.assertEquals(retArray[2], ans); } @@ -162,7 +155,7 @@ public void recoverTest1() { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + resultSet.getString("time") + "," + resultSet.getString(maxValue(d0s0)) + "," @@ -175,7 +168,7 @@ public void recoverTest1() { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + resultSet.getString("time") + "," + resultSet.getString(maxValue(d0s0)) + "," @@ -203,17 +196,17 @@ public void recoverTest2() { ((AbstractEnv) EnvFactory.getEnv()).checkClusterStatusWithoutUnknown(); // count test String[] retArray = new String[] {"0,2001,2001,2001,2001", "0,7500,7500,7500,7500"}; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { String selectSql = "select count(s0),count(s1),count(s2),count(s3) " - + "from root.vehicle.d0 where time >= 6000 and time <= 9000"; + + "from vehicle where time >= 6000 and time <= 9000"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + resultSet.getString("time") + "," + resultSet.getString(count(d0s0)) + "," @@ -225,12 +218,12 @@ public void recoverTest2() { Assert.assertEquals(retArray[0], ans); } - selectSql = "select count(s0),count(s1),count(s2),count(s3) from root.vehicle.d0"; + selectSql = "select count(s0),count(s1),count(s2),count(s3) from vehicle"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + resultSet.getString("time") + "," + resultSet.getString(count(d0s0)) + "," @@ -248,7 +241,7 @@ public void recoverTest2() { } private void prepareData() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { for (String sql : creationSqls) { @@ -261,7 +254,7 @@ private void prepareData() { // prepare BufferWrite file String insertTemplate = - "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4)" + " VALUES(%d,%d,%d,%f,%s,%s)"; + "INSERT INTO vehicle(id1,timestamp,s0,s1,s2,s3,s4)" + " VALUES('d0',%d,%d,%d,%f,%s,%s)"; for (int i = 5000; i < 7000; i++) { statement.addBatch( String.format( diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java index b24b3b03e573f..29f4e5b8d5b4d 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRecoverUnclosedIT.java @@ -24,6 +24,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; @@ -52,34 +53,29 @@ @Category({LocalStandaloneIT.class, ClusterIT.class}) public class IoTDBRecoverUnclosedIT { private static final Logger logger = LoggerFactory.getLogger(IoTDBRecoverUnclosedIT.class); - private static final String TIMESTAMP_STR = "Time"; - private static final String TEMPERATURE_STR = "root.ln.wf01.wt01.temperature"; + private static final String TIMESTAMP_STR = "time"; + private static final String TEMPERATURE_STR = "temperature"; private static final String[] creationSqls = new String[] { - "CREATE DATABASE root.vehicle.d0", - "CREATE DATABASE root.vehicle.d1", - "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", - "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE", - "CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE", - "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN", - "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN" + "CREATE DATABASE test", + "USE \"test\"", + "CREATE TABLE vehicle (id1 string id, s0 int32 measurement, s1 int64 measurement, s2 float measurement, s3 text measurement, s4 boolean measurement)" }; private static final String[] dataSet2 = new String[] { - "CREATE DATABASE root.ln.wf01.wt01", - "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", - "CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=PLAIN", - "CREATE TIMESERIES root.ln.wf01.wt01.hardware WITH DATATYPE=INT32, ENCODING=PLAIN", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(1, 1.1, false, 11)", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(2, 2.2, true, 22)", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(3, 3.3, false, 33 )", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(4, 4.4, false, 44)", - "INSERT INTO root.ln.wf01.wt01(timestamp,temperature,status, hardware) " - + "values(5, 5.5, false, 55)" + "CREATE DATABASE ln", + "USE \"ln\"", + "CREATE TABLE wf01 (id1 string id, status boolean measurement, temperature float measurement, hardware int32 measurement)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 1, 1.1, false, 11)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 2, 2.2, true, 22)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 3, 3.3, false, 33 )", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01', 4, 4.4, false, 44)", + "INSERT INTO wf01(id1, time,temperature,status, hardware) " + + "values('wt01',5, 5.5, false, 55)" }; @Before @@ -97,37 +93,34 @@ public void tearDown() throws Exception { @Test public void test() throws SQLException, IOException { String[] retArray = new String[] {"0,2", "0,4", "0,3"}; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - String selectSql = "select count(temperature) from root.ln.wf01.wt01 where time > 3"; + statement.execute("use \"ln\""); + String selectSql = "select count(temperature) from wf01 where time > 3"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(TEMPERATURE_STR)); + resultSet.getString("time") + "," + resultSet.getString(count(TEMPERATURE_STR)); assertEquals(retArray[0], ans); } - selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where time > 3"; + selectSql = "select min_time(temperature) from wf01 where time > 3"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) - + "," - + resultSet.getString(minTime(TEMPERATURE_STR)); + resultSet.getString("time") + "," + resultSet.getString(minTime(TEMPERATURE_STR)); assertEquals(retArray[1], ans); } - selectSql = "select min_time(temperature) from root.ln.wf01.wt01 where temperature > 3"; + selectSql = "select min_time(temperature) from wf01 where temperature > 3"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) - + "," - + resultSet.getString(minTime(TEMPERATURE_STR)); + resultSet.getString("time") + "," + resultSet.getString(minTime(TEMPERATURE_STR)); assertEquals(retArray[2], ans); } @@ -153,20 +146,19 @@ public void test() throws SQLException, IOException { // test count, try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { - String selectSql = "select count(*) from root.vehicle.d0"; + String selectSql = "select count(*) from vehicle"; ResultSet tempResultSet = statement.executeQuery(selectSql); assertNotNull(tempResultSet); tempResultSet.next(); - String d0s0 = "root.vehicle.d0.s0"; - String d0s1 = "root.vehicle.d0.s1"; - String d0s2 = "root.vehicle.d0.s2"; + String d0s0 = "s0"; + String d0s1 = "s1"; + String d0s2 = "s2"; assertEquals(7500, tempResultSet.getInt("count(" + d0s0 + ")")); // test max, min value retArray = new String[] {"0,8499,500.0", "0,2499,500.0"}; selectSql = - "select max_value(s0),min_value(s2) " - + "from root.vehicle.d0 where time >= 100 and time < 9000"; + "select max_value(s0),min_value(s2) " + "from vehicle where time >= 100 and time < 9000"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); @@ -179,12 +171,12 @@ public void test() throws SQLException, IOException { assertEquals(retArray[0], ans); } - selectSql = "select max_value(s1),min_value(s2) from root.vehicle.d0 where time < 2500"; + selectSql = "select max_value(s1),min_value(s2) from vehicle where time < 2500"; try (ResultSet resultSet = statement.executeQuery(selectSql)) { assertNotNull(resultSet); resultSet.next(); String ans = - resultSet.getString(TIMESTAMP_STR) + resultSet.getString("time") + "," + resultSet.getString(maxValue(d0s1)) + "," @@ -198,7 +190,7 @@ public void test() throws SQLException, IOException { } private void prepareData() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { for (String sql : creationSqls) { statement.execute(sql); @@ -219,7 +211,7 @@ private void insertMoreData() { // prepare BufferWrite file String insertTemplate = - "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4)" + " VALUES(%d,%d,%d,%f,%s,%s)"; + "INSERT INTO vehicle(id1,timestamp,s0,s1,s2,s3,s4)" + " VALUES('d0',%d,%d,%d,%f,%s,%s)"; for (int i = 5000; i < 7000; i++) { statement.addBatch( String.format( diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java index 89270c1b87b1a..f17f80ef75aab 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBRestartIT.java @@ -24,6 +24,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; @@ -64,9 +65,12 @@ public void tearDown() throws Exception { @Test public void testRestart() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.turbine.d1(timestamp,s1) values(1,1.0)"); + statement.execute("create database test"); + statement.execute("use \"test\""); + statement.execute("create table turbine (id1 string id, s1 float measurement)"); + statement.execute("insert into turbine(id1, timestamp,s1) values('d1', 1,1.0)"); statement.execute("flush"); } @@ -77,9 +81,9 @@ public void testRestart() throws SQLException { fail(e.getMessage()); } - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.turbine.d1(timestamp,s1) values(2,1.0)"); + statement.execute("insert into turbine(id1, timestamp,s1) values('d1', 2,1.0)"); } try { @@ -90,14 +94,14 @@ public void testRestart() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { - statement.execute("insert into root.turbine.d1(timestamp,s1) values(3,1.0)"); + statement.execute("insert into turbine(id1, timestamp,s1) values('d1', 3,1.0)"); String[] exp = new String[] {"1,1.0", "2,1.0", "3,1.0"}; int cnt = 0; - try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.turbine.d1")) { + try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM turbine")) { assertNotNull(resultSet); while (resultSet.next()) { - String result = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(2); + String result = resultSet.getString("time") + "," + resultSet.getString(2); assertEquals(exp[cnt], result); cnt++; } diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java index c0c7280f09ca1..21971551b2d1f 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBSameMeasurementsDifferentTypesIT.java @@ -27,6 +27,7 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -43,6 +44,8 @@ */ @RunWith(IoTDBTestRunner.class) @Category({LocalStandaloneIT.class, ClusterIT.class}) +@Ignore +// TODO: Delete this IT public class IoTDBSameMeasurementsDifferentTypesIT { @BeforeClass diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java index 21c5c74ec2e70..202cef9adb5e2 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java @@ -22,6 +22,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; @@ -59,14 +60,18 @@ public void tearDown() throws Exception { @Test public void testInsertAlignedWithEmptyPage() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database lz"); + statement.execute("use \"lz\""); statement.execute( - "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(S1 INT32 encoding=PLAIN compressor=SNAPPY, S2 INT32 encoding=PLAIN compressor=SNAPPY, S3 INT32 encoding=PLAIN compressor=SNAPPY) "); + "create table dev (id1 string id, s1 int32 measurement, s2 int32 measurement, s3 int32 measurement)"); for (int i = 0; i < 100; i++) { if (i == 99) { statement.addBatch( - "insert into root.lz.dev.GPS(time,S1,S3) aligned values(" + "insert into dev(id1,time,s1,s3) values(" + + "'GPS''" + + "," + i + "," + i @@ -75,7 +80,9 @@ public void testInsertAlignedWithEmptyPage() throws SQLException { + ")"); } else { statement.addBatch( - "insert into root.lz.dev.GPS(time,S1,S2) aligned values(" + "insert into dev(id1, time,s1,s2) values(" + + "'GPS'" + + "," + i + "," + i @@ -88,7 +95,7 @@ public void testInsertAlignedWithEmptyPage() throws SQLException { statement.execute("flush"); int rowCount = 0; - try (ResultSet resultSet = statement.executeQuery("select S3 from root.lz.dev.GPS")) { + try (ResultSet resultSet = statement.executeQuery("select time, s3 from dev")) { while (resultSet.next()) { assertEquals(99, resultSet.getInt(2)); rowCount++; @@ -96,7 +103,7 @@ public void testInsertAlignedWithEmptyPage() throws SQLException { assertEquals(1, rowCount); } - try (ResultSet resultSet = statement.executeQuery("select S2 from root.lz.dev.GPS")) { + try (ResultSet resultSet = statement.executeQuery("select time, s2 from dev")) { rowCount = 0; while (resultSet.next()) { assertEquals(rowCount, resultSet.getInt(2)); @@ -105,7 +112,7 @@ public void testInsertAlignedWithEmptyPage() throws SQLException { assertEquals(99, rowCount); } - try (ResultSet resultSet = statement.executeQuery("select S1 from root.lz.dev.GPS")) { + try (ResultSet resultSet = statement.executeQuery("select time, s1 from dev")) { rowCount = 0; while (resultSet.next()) { assertEquals(rowCount, resultSet.getInt(2)); @@ -118,33 +125,42 @@ public void testInsertAlignedWithEmptyPage() throws SQLException { @Test public void testInsertAlignedWithEmptyPage2() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); - statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); - statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); + statement.execute("create database test"); + statement.execute("use \"test\""); + statement.execute( + "create table sg (id1 string id, s1 string measurement, s2 string measurement)"); + + statement.execute("insert into sg(id1, time, s1, s2) aligned values('d1', 1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) aligned values('d1', 1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) aligned values('d2', 1,'aa','bb')"); statement.execute("flush"); - statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) aligned values('d1', 1,'aa','bb')"); } } @Test public void testInsertComplexAlignedValues() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.addBatch("create aligned timeseries root.sg.d1(s1 int32, s2 int32, s3 int32)"); - statement.addBatch("insert into root.sg.d1(time,s1) values(3,1)"); - statement.addBatch("insert into root.sg.d1(time,s1) values(1,1)"); - statement.addBatch("insert into root.sg.d1(time,s1) values(2,1)"); - statement.addBatch("insert into root.sg.d1(time,s2) values(2,2)"); - statement.addBatch("insert into root.sg.d1(time,s2) values(1,2)"); - statement.addBatch("insert into root.sg.d1(time,s2) values(3,2)"); - statement.addBatch("insert into root.sg.d1(time,s3) values(1,3)"); - statement.addBatch("insert into root.sg.d1(time,s3) values(3,3)"); + statement.addBatch("create database sg"); + statement.addBatch("use database \"test\""); + statement.addBatch( + "create table sg (id1 string id, s1 int32 measurement, s2 int32 measurement)"); + statement.addBatch("insert into sg(id1, time, s1) values('id1', 3,1)"); + statement.addBatch("insert into sg(id1, time, s1) values('id1', 3,1)"); + statement.addBatch("insert into sg(id1, time, s1) values('id1', 1,1)"); + statement.addBatch("insert into sg(id1, time, s1) values('id1', 2,1)"); + statement.addBatch("insert into sg(id1, time, s2) values('id1', 2,2)"); + statement.addBatch("insert into sg(id1, time, s2) values('id1', 1,2)"); + statement.addBatch("insert into sg(id1, time, s2) values('id1', 3,2)"); + statement.addBatch("insert into sg(id1, time, s3) values('id1', 1,3)"); + statement.addBatch("insert into sg(id1, time, s3) values('id1', 3,3)"); statement.executeBatch(); try (ResultSet resultSet = - statement.executeQuery("select count(s1), count(s2), count(s3) from root.sg.d1")) { + statement.executeQuery("select count(s1), count(s2), count(s3) from sg")) { assertTrue(resultSet.next()); assertEquals(3, resultSet.getInt(1)); @@ -156,7 +172,7 @@ public void testInsertComplexAlignedValues() throws SQLException { statement.execute("flush"); try (ResultSet resultSet = - statement.executeQuery("select count(s1), count(s2), count(s3) from root.sg.d1")) { + statement.executeQuery("select count(s1), count(s2), count(s3) from sg")) { assertTrue(resultSet.next()); assertEquals(3, resultSet.getInt(1)); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java index 311f57bf0672e..01ac9b1cf0327 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java @@ -22,6 +22,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; @@ -57,14 +58,18 @@ public void tearDown() throws Exception { @Test public void testInsertAlignedWithEmptyPage2() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database lz"); + statement.execute("use \"lz\""); statement.execute( - "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(S1 INT32 encoding=PLAIN compressor=SNAPPY, S2 INT32 encoding=PLAIN compressor=SNAPPY, S3 INT32 encoding=PLAIN compressor=SNAPPY) "); + "create table dev (id1 string id, s1 int32 measurement, s2 int32 measurement, s3 int32 measurement)"); for (int i = 0; i < 100; i++) { if (i >= 49) { statement.addBatch( - "insert into root.lz.dev.GPS(time,S1,S2,S3) aligned values(" + "insert into dev(id1,time,s1,s2,s3) values(" + + "GPS" + + "," + i + "," + i @@ -75,7 +80,9 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { + ")"); } else { statement.addBatch( - "insert into root.lz.dev.GPS(time,S1,S2) aligned values(" + "insert into root.lz.dev.GPS(id1,time,s1,s2) aligned values(" + + "GPS" + + "," + i + "," + i @@ -87,7 +94,7 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { statement.executeBatch(); statement.execute("flush"); int rowCount = 0; - try (ResultSet resultSet = statement.executeQuery("select S3 from root.lz.dev.GPS")) { + try (ResultSet resultSet = statement.executeQuery("select s3 from dev")) { while (resultSet.next()) { assertEquals(rowCount + 49, resultSet.getInt(2)); rowCount++; @@ -95,7 +102,7 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { assertEquals(51, rowCount); } - try (ResultSet resultSet = statement.executeQuery("select S2 from root.lz.dev.GPS")) { + try (ResultSet resultSet = statement.executeQuery("select s2 from dev")) { rowCount = 0; while (resultSet.next()) { assertEquals(rowCount, resultSet.getInt(2)); @@ -104,7 +111,7 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { assertEquals(100, rowCount); } - try (ResultSet resultSet = statement.executeQuery("select S1 from root.lz.dev.GPS")) { + try (ResultSet resultSet = statement.executeQuery("select s1 from dev")) { rowCount = 0; while (resultSet.next()) { assertEquals(rowCount, resultSet.getInt(2)); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java index aad0ad5ebfdbc..aa6b4e2c56968 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues4IT.java @@ -22,6 +22,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; @@ -57,18 +58,22 @@ public void tearDown() throws Exception { @Test public void testExtendTextColumn() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(1,'test','test')"); - statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(2,'test','test')"); - statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(3,'test','test')"); - statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(4,'test','test')"); - statement.execute("insert into root.sg.d1(time,s1,s3) aligned values(5,'test','test')"); - statement.execute("insert into root.sg.d1(time,s1,s2) aligned values(6,'test','test')"); + statement.execute("create database test"); + statement.execute("use \"test\""); + statement.execute( + "create table sg (id1 string id, s1 string measurement, s2 string measurement)"); + statement.execute("insert into sg(id1,time,s1,s2) values('d1',1,'test','test')"); + statement.execute("insert into sg(id1,time,s1,s2) values('d1',2,'test','test')"); + statement.execute("insert into sg(id1,time,s1,s2) values('d1',3,'test','test')"); + statement.execute("insert into sg(id1,time,s1,s2) values('d1',4,'test','test')"); + statement.execute("insert into sg(id1,time,s1,s3) values('d1',5,'test','test')"); + statement.execute("insert into sg(id1,time,s1,s2) values('d1',6,'test','test')"); statement.execute("flush"); - statement.execute("insert into root.sg.d1(time,s1,s3) aligned values(7,'test','test')"); - } catch (SQLException e) { + statement.execute("insert into sg(id1,time,s1,s3) values('d1',7,'test','test')"); fail(); + } catch (SQLException ignored) { } } } diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java index 80127ff8e4a03..b81dd975b76fc 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValuesIT.java @@ -23,9 +23,11 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -58,17 +60,21 @@ public void tearDown() throws Exception { @Test public void testInsertAlignedValues() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.addBatch("create database t1"); + statement.addBatch("use \"t1\""); + statement.addBatch( + "create table wf01 (id1 string id, status int32 measurement, temperature float measurement)"); statement.addBatch( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (4000, true, 17.1)"); + "insert into wf01(id1, time, status, temperature) values ('wt01', 4000, true, 17.1)"); statement.addBatch( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (5000, true, 20.1)"); + "insert into wf01(id1, time, status, temperature) values ('wt01', 5000, true, 20.1)"); statement.addBatch( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (6000, true, 22)"); + "insert into wf01(id1, time, status, temperature) values ('wt01', 6000, true, 22)"); statement.executeBatch(); - try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + try (ResultSet resultSet = statement.executeQuery("select time, status from wf01")) { assertTrue(resultSet.next()); assertTrue(resultSet.getBoolean(2)); assertTrue(resultSet.next()); @@ -79,7 +85,7 @@ public void testInsertAlignedValues() throws SQLException { } try (ResultSet resultSet = - statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + statement.executeQuery("select time, status, temperature from wf01")) { assertTrue(resultSet.next()); assertEquals(4000, resultSet.getLong(1)); @@ -103,16 +109,20 @@ public void testInsertAlignedValues() throws SQLException { @Test public void testInsertAlignedNullableValues() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + + statement.addBatch("create database t1"); + statement.addBatch("use \"t1\""); statement.addBatch( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (4000, true, 17.1)"); - statement.addBatch("insert into root.t1.wf01.wt01(time, status) aligned values (5000, true)"); + "create table wf01 (id1 string id, status boolean measurement, temperature float measurement)"); statement.addBatch( - "insert into root.t1.wf01.wt01(time, temperature) aligned values (6000, 22)"); + "insert into wf01(id1, time, status, temperature) values ('wt01', 4000, true, 17.1)"); + statement.addBatch("insert into wf01(id1, time, status) values ('wt01', 5000, true)"); + statement.addBatch("insert into wf01(id1, time, temperature) values ('wt01', 6000, 22)"); statement.executeBatch(); - try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + try (ResultSet resultSet = statement.executeQuery("select status from wf01")) { assertTrue(resultSet.next()); assertTrue(resultSet.getBoolean(2)); assertTrue(resultSet.next()); @@ -121,7 +131,7 @@ public void testInsertAlignedNullableValues() throws SQLException { } try (ResultSet resultSet = - statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + statement.executeQuery("select time, status, temperature from wf01")) { assertTrue(resultSet.next()); assertEquals(4000, resultSet.getLong(1)); @@ -145,18 +155,20 @@ public void testInsertAlignedNullableValues() throws SQLException { @Test public void testUpdatingAlignedValues() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.addBatch("create database t1"); + statement.addBatch("use \"t1\""); statement.addBatch( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values (4000, true, 17.1)"); - statement.addBatch("insert into root.t1.wf01.wt01(time, status) aligned values (5000, true)"); - statement.addBatch( - "insert into root.t1.wf01.wt01(time, temperature) aligned values (5000, 20.1)"); + "create table wf01 (id1 string id, status boolean measurement, temperature float measurement)"); statement.addBatch( - "insert into root.t1.wf01.wt01(time, temperature) aligned values (6000, 22)"); + "insert into wf01(id1, time, status, temperature) values ('wt01', 4000, true, 17.1)"); + statement.addBatch("insert into wf01(id1, time, status) values ('wt01', 5000, true)"); + statement.addBatch("insert into wf01(id1, time, temperature)values ('wt01', 5000, 20.1)"); + statement.addBatch("insert into wf01(id1, time, temperature)values ('wt01', 6000, 22)"); statement.executeBatch(); - try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + try (ResultSet resultSet = statement.executeQuery("select time, status from wf01")) { assertTrue(resultSet.next()); assertTrue(resultSet.getBoolean(2)); assertTrue(resultSet.next()); @@ -165,7 +177,7 @@ public void testUpdatingAlignedValues() throws SQLException { } try (ResultSet resultSet = - statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + statement.executeQuery("select time, status, temperature from wf01")) { assertTrue(resultSet.next()); assertEquals(4000, resultSet.getLong(1)); @@ -186,7 +198,7 @@ public void testUpdatingAlignedValues() throws SQLException { } statement.execute("flush"); - try (ResultSet resultSet = statement.executeQuery("select status from root.t1.wf01.wt01")) { + try (ResultSet resultSet = statement.executeQuery("select time, status from wf01")) { assertTrue(resultSet.next()); assertTrue(resultSet.getBoolean(2)); assertTrue(resultSet.next()); @@ -195,7 +207,7 @@ public void testUpdatingAlignedValues() throws SQLException { } try (ResultSet resultSet = - statement.executeQuery("select status, temperature from root.t1.wf01.wt01")) { + statement.executeQuery("select time, status, temperature from wf01")) { assertTrue(resultSet.next()); assertEquals(4000, resultSet.getLong(1)); @@ -219,13 +231,17 @@ public void testUpdatingAlignedValues() throws SQLException { @Test public void testInsertAlignedValuesWithSameTimestamp() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.addBatch("insert into root.sg.d1(time,s2) aligned values(1,2)"); - statement.addBatch("insert into root.sg.d1(time,s1) aligned values(1,2)"); + statement.addBatch("create database test"); + statement.addBatch("use \"test\""); + statement.addBatch( + "create table sg (ids string id, s2 int32 measurement, s1 int32 measurement)"); + statement.addBatch("insert into sg(id1,time,s2) values('d1',1,2)"); + statement.addBatch("insert into sg(id1,time,s1) values('d1',1,2)"); statement.executeBatch(); - try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) { + try (ResultSet resultSet = statement.executeQuery("select time, s1, s2 from sg")) { assertTrue(resultSet.next()); assertEquals(1, resultSet.getLong(1)); @@ -236,7 +252,7 @@ public void testInsertAlignedValuesWithSameTimestamp() throws SQLException { } statement.execute("flush"); - try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) { + try (ResultSet resultSet = statement.executeQuery("select time, s1, s2 from sg")) { assertTrue(resultSet.next()); assertEquals(1, resultSet.getLong(1)); @@ -250,48 +266,51 @@ public void testInsertAlignedValuesWithSameTimestamp() throws SQLException { @Test public void testInsertWithWrongMeasurementNum1() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database t1"); + statement.execute("use \"t1\""); statement.execute( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values(11000, 100)"); + "create table wf01 (id1 string id, status int32, temperature int32 measurement)"); + statement.execute( + "insert into wf01(id1, time, status, temperature) values('wt01', 11000, 100)"); fail(); } catch (SQLException e) { - assertTrue( - e.getMessage() - .contains( - "the measurementList's size 2 is not consistent with the valueList's size 1")); + assertTrue(e.getMessage().contains("failed")); } } @Test public void testInsertWithWrongMeasurementNum2() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database t1"); + statement.execute("use \"t1\""); + statement.execute( + "create table wf01 (id1 string id, status int32, temperature int32 measurement)"); statement.execute( - "insert into root.t1.wf01.wt01(time, status, temperature) aligned values(11000, 100, 300, 400)"); + "insert into wf01(id1, time, status, temperature) values('wt01', 11000, 100, 300, 400)"); fail(); } catch (SQLException e) { - assertTrue( - e.getMessage(), - e.getMessage() - .contains( - "the measurementList's size 2 is not consistent with the valueList's size 3")); + assertTrue(e.getMessage(), e.getMessage().contains("failed")); } } @Test(expected = Exception.class) public void testInsertWithWrongType() throws SQLException { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database lz"); + statement.execute("use \"lz\""); statement.execute( - "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(latitude INT32 encoding=PLAIN compressor=SNAPPY, longitude INT32 encoding=PLAIN compressor=SNAPPY) "); - statement.execute( - "insert into root.lz.dev.GPS(time,latitude,longitude) aligned values(1,1.3,6.7)"); + "create table dev (id1 string id, latitude int32 measurement, longitude int32 measurement)"); + statement.execute("insert into dev(id1,time,latitude,longitude) values('GPS', 1,1.3,6.7)"); fail(); } } @Test + @Ignore // TODO: delete public void testInsertAlignedTimeseriesWithoutAligned() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { @@ -340,6 +359,7 @@ public void testInsertTimeseriesWithUnMatchedAlignedType() throws SQLException { } @Test + @Ignore // TODO: delete public void testInsertNonAlignedTimeseriesWithAligned() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { @@ -352,6 +372,7 @@ public void testInsertNonAlignedTimeseriesWithAligned() throws SQLException { } @Test + @Ignore // TODO: delete public void testInsertAlignedValuesWithThreeLevelPath() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { @@ -367,10 +388,13 @@ public void testInsertAlignedValuesWithThreeLevelPath() throws SQLException { @Test public void testInsertWithDuplicatedMeasurements() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database t1"); + statement.execute("use \"t1\""); + statement.execute("create table wf01(id1 string id, s3 boolean measurement, status int32)"); statement.execute( - "insert into root.t1.wf01.wt01(time, s3, status, status) aligned values(100, true, 20.1, 20.2)"); + "insert into wf01(id1, time, s3, status, status) values('wt01', 100, true, 20.1, 20.2)"); fail(); } catch (SQLException e) { assertTrue( @@ -381,10 +405,14 @@ public void testInsertWithDuplicatedMeasurements() { @Test public void testInsertMultiRows() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database test"); + statement.execute("use \"test\""); + statement.execute( + "create table sg1 (id1 string id, s1 int32 measurement, s2 int32 measurement)"); statement.execute( - "insert into root.sg1.d1(time, s1, s2) aligned values(10, 2, 2), (11, 3, '3'), (12,12.11,false);"); + "insert into sg1(id1, time, s1, s2) values('d1', 10, 2, 2), ('d1', 11, 3, '3'), ('d1', 12,12.11,false)"); fail(); } catch (SQLException e) { assertTrue(e.getMessage(), e.getMessage().contains("data type is not consistent")); @@ -393,10 +421,14 @@ public void testInsertMultiRows() { @Test public void testInsertLargeNumber() { - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { + statement.execute("create database test"); + statement.execute("use \"test\""); + statement.execute( + "create table sg1 (id1 string id, s98 int64 measurement, s99 int64 measurement)"); statement.execute( - "insert into root.sg1.d1(time, s98, s99) aligned values(10, 2, 271840880000000000000000)"); + "insert into sg1(id1, time, s98, s99) values('d1', 10, 2, 271840880000000000000000)"); } catch (SQLException e) { fail(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java index 54184bb636cdf..69a1148eac311 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBAutoCreateSchemaIT.java @@ -29,6 +29,7 @@ import org.apache.tsfile.enums.TSDataType; import org.junit.After; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runners.Parameterized; @@ -49,6 +50,7 @@ * IoTDB server should be defined as integration test. */ @Category({LocalStandaloneIT.class, ClusterIT.class}) +@Ignore // TODO: delete this test public class IoTDBAutoCreateSchemaIT extends AbstractSchemaIT { public IoTDBAutoCreateSchemaIT(SchemaTestMode schemaTestMode) { diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java index 62f49cbde2bb9..761ff14c02635 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateStorageGroupIT.java @@ -23,11 +23,13 @@ import org.apache.iotdb.it.env.EnvFactory; import org.apache.iotdb.itbase.category.ClusterIT; import org.apache.iotdb.itbase.category.LocalStandaloneIT; +import org.apache.iotdb.itbase.env.BaseEnv; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.util.AbstractSchemaIT; import org.junit.After; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runners.Parameterized; @@ -73,8 +75,8 @@ public void tearDown() throws Exception { /** The test creates three databases */ @Test public void testCreateStorageGroup() throws Exception { - String[] storageGroups = {"root.sg1", "root.sg2", "root.sg3"}; - try (Connection connection = EnvFactory.getEnv().getConnection(); + String[] storageGroups = {"sg1", "sg2", "sg3"}; + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { for (String storageGroup : storageGroups) { statement.execute(String.format("create database %s", storageGroup)); @@ -113,9 +115,9 @@ private void createStorageGroupTool(Statement statement, String[] storageGroups) /** Test creating a database that path is an existence database */ @Test public void testCreateExistStorageGroup1() throws Exception { - String storageGroup = "root.sg"; + String storageGroup = "sg"; - try (Connection connection = EnvFactory.getEnv().getConnection(); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { statement.execute(String.format("CREATE DATABASE %s", storageGroup)); @@ -124,8 +126,7 @@ public void testCreateExistStorageGroup1() throws Exception { fail(); } catch (SQLException e) { Assert.assertEquals( - TSStatusCode.DATABASE_ALREADY_EXISTS.getStatusCode() - + ": root.sg has already been created as database", + TSStatusCode.DATABASE_ALREADY_EXISTS.getStatusCode() + ": Database sg already exists", e.getMessage()); } } @@ -133,6 +134,7 @@ public void testCreateExistStorageGroup1() throws Exception { /** Test the parent node has been set as a database */ @Test + @Ignore // TODO: delete this test public void testCreateExistStorageGroup2() throws Exception { try (Connection connection = EnvFactory.getEnv().getConnection(); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java index 21093391f2ca0..6468938e1b082 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/schema/IoTDBCreateTimeseriesIT.java @@ -27,6 +27,7 @@ import org.junit.After; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runners.Parameterized; @@ -46,6 +47,7 @@ * IoTDB server should be defined as integration test. */ @Category({LocalStandaloneIT.class, ClusterIT.class}) +@Ignore // TODO: delete this test public class IoTDBCreateTimeseriesIT extends AbstractSchemaIT { public IoTDBCreateTimeseriesIT(SchemaTestMode schemaTestMode) { From 15afd8542b411f919f7dba6a4bc004a4bc99cd4c Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Fri, 26 Jul 2024 10:47:38 +0800 Subject: [PATCH 4/4] fix it --- .../it/db/it/aligned/IoTDBInsertAlignedValues2IT.java | 10 +++++----- .../it/db/it/aligned/IoTDBInsertAlignedValues3IT.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java index 202cef9adb5e2..a44d1c8bad204 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues2IT.java @@ -132,11 +132,11 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { statement.execute( "create table sg (id1 string id, s1 string measurement, s2 string measurement)"); - statement.execute("insert into sg(id1, time, s1, s2) aligned values('d1', 1,'aa','bb')"); - statement.execute("insert into sg(id1, time, s1, s2) aligned values('d1', 1,'aa','bb')"); - statement.execute("insert into sg(id1, time, s1, s2) aligned values('d2', 1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) values('d1', 1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) values('d1', 1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) values('d2', 1,'aa','bb')"); statement.execute("flush"); - statement.execute("insert into sg(id1, time, s1, s2) aligned values('d1', 1,'aa','bb')"); + statement.execute("insert into sg(id1, time, s1, s2) values('d1', 1,'aa','bb')"); } } @@ -144,7 +144,7 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { public void testInsertComplexAlignedValues() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); Statement statement = connection.createStatement()) { - statement.addBatch("create database sg"); + statement.addBatch("create database test"); statement.addBatch("use database \"test\""); statement.addBatch( "create table sg (id1 string id, s1 int32 measurement, s2 int32 measurement)"); diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java index 01ac9b1cf0327..d7c031d7d13da 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/aligned/IoTDBInsertAlignedValues3IT.java @@ -80,7 +80,7 @@ public void testInsertAlignedWithEmptyPage2() throws SQLException { + ")"); } else { statement.addBatch( - "insert into root.lz.dev.GPS(id1,time,s1,s2) aligned values(" + "insert into root.lz.dev.GPS(id1,time,s1,s2) values(" + "GPS" + "," + i