This is an automated email from the ASF dual-hosted git repository. hui pushed a commit to branch lmh/addQueryIT in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 8e852d2b47e6d595c5c146e70e98ce64cab6f0ec Author: Minghui Liu <[email protected]> AuthorDate: Fri Jun 17 16:06:24 2022 +0800 move IoTDBResultMetadataIT & IoTDBResultSetIT to newIT --- .../apache/iotdb/db/it/query/IoTDBResultSetIT.java | 142 +++++++++++++++++++++ .../db/integration/IoTDBResultMetadataIT.java | 1 - .../iotdb/db/integration/IoTDBResultSetIT.java | 40 ++---- 3 files changed, 155 insertions(+), 28 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java new file mode 100644 index 0000000000..1cfdbb76c0 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java @@ -0,0 +1,142 @@ +/* + * 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.db.it.query; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; +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.ResultSetMetaData; +import java.sql.Statement; +import java.sql.Types; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBResultSetIT { + + private static final List<String> SQLs = Arrays.asList( + "SET STORAGE GROUP TO root.t1", + "CREATE TIMESERIES root.t1.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", + "CREATE TIMESERIES root.t1.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE", + "CREATE TIMESERIES root.t1.wf01.wt01.type WITH DATATYPE=INT32, ENCODING=RLE", + "CREATE TIMESERIES root.t1.wf01.wt01.grade WITH DATATYPE=INT64, ENCODING=RLE", + "CREATE TIMESERIES root.sg.dev.status WITH DATATYPE=text,ENCODING=PLAIN", + "insert into root.sg.dev(time,status) values(1,3.14)" + ); + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().initBeforeClass(); + insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + } + + 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(); + fail(e.getMessage()); + } + } + + @Test + public void testIntAndLongConversion() { + try (Connection connection = EnvFactory.getEnv().getConnection()) { + Statement st0 = connection.createStatement(); + st0.execute( + "insert into root.t1.wf01.wt01(timestamp, status, type, grade) values (1000, true, 1, 1000)"); + st0.execute( + "insert into root.t1.wf01.wt01(timestamp, status, type, grade) values (2000, false, 2, 2000)"); + st0.close(); + + Statement st1 = connection.createStatement(); + ResultSet rs1 = st1.executeQuery("select count(status) from root.t1.wf01.wt01"); + rs1.next(); + // type of r1 is INT64(long), test long convert to int + int countStatus = rs1.getInt(1); + Assert.assertEquals(2L, countStatus); + + ResultSet rs2 = + st1.executeQuery("select type from root.t1.wf01.wt01 where time = 1000 limit 1"); + rs2.next(); + // type of r2 is INT32(int), test int convert to long + long type = rs2.getLong(2); + Assert.assertEquals(1, type); + + ResultSet rs3 = + st1.executeQuery("select grade from root.t1.wf01.wt01 where time = 1000 limit 1"); + rs3.next(); + // type of r3 is INT64(long), test long convert to int + int grade = rs3.getInt(2); + Assert.assertEquals(1000, grade); + + st1.close(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void columnTypeTest() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select status from root.sg.dev")) { + Assert.assertTrue(resultSet.next()); + ResultSetMetaData metaData = resultSet.getMetaData(); + assertEquals(2, metaData.getColumnCount()); + assertEquals("Time", metaData.getColumnName(1)); + assertEquals(Types.TIMESTAMP, metaData.getColumnType(1)); + assertEquals("TIME", metaData.getColumnTypeName(1)); + assertEquals("root.sg.dev.status", metaData.getColumnName(2)); + assertEquals(Types.VARCHAR, metaData.getColumnType(2)); + assertEquals("TEXT", metaData.getColumnTypeName(2)); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultMetadataIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultMetadataIT.java index 5498a202d4..40c612a2e7 100644 --- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultMetadataIT.java +++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultMetadataIT.java @@ -68,7 +68,6 @@ public class IoTDBResultMetadataIT { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { - long lastTimestamp; try (ResultSet resultSet = statement.executeQuery("select status from root.sg.dev")) { Assert.assertTrue(resultSet.next()); ResultSetMetaData metaData = resultSet.getMetaData(); diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultSetIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultSetIT.java index fa14939f68..265b7d4beb 100644 --- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultSetIT.java +++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBResultSetIT.java @@ -34,8 +34,8 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import java.util.Objects; import static org.junit.Assert.fail; @@ -47,45 +47,31 @@ import static org.junit.Assert.fail; */ @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class}) public class IoTDBResultSetIT { - private static List<String> sqls = new ArrayList<>(); - private static Connection connection; + + private static final List<String> SQLs = Arrays.asList( + "SET STORAGE GROUP TO root.t1", + "CREATE TIMESERIES root.t1.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", + "CREATE TIMESERIES root.t1.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE", + "CREATE TIMESERIES root.t1.wf01.wt01.type WITH DATATYPE=INT32, ENCODING=RLE", + "CREATE TIMESERIES root.t1.wf01.wt01.grade WITH DATATYPE=INT64, ENCODING=RLE" + ); @BeforeClass public static void setUp() throws Exception { EnvFactory.getEnv().initBeforeClass(); - initCreateSQLStatement(); insertData(); } @AfterClass public static void tearDown() throws Exception { - close(); EnvFactory.getEnv().cleanAfterClass(); } - private static void close() { - if (Objects.nonNull(connection)) { - try { - connection.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private static void initCreateSQLStatement() { - sqls.add("SET STORAGE GROUP TO 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 TIMESERIES root.t1.wf01.wt01.type WITH DATATYPE=INT32, ENCODING=RLE"); - sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.grade WITH DATATYPE=INT64, ENCODING=RLE"); - } - private static void insertData() { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { - for (String sql : sqls) { + for (String sql : SQLs) { statement.execute(sql); } } catch (Exception e) { @@ -109,21 +95,21 @@ public class IoTDBResultSetIT { rs1.next(); // type of r1 is INT64(long), test long convert to int int countStatus = rs1.getInt(1); - Assert.assertTrue(countStatus == 2L); + Assert.assertEquals(2L, countStatus); ResultSet rs2 = st1.executeQuery("select type from root.t1.wf01.wt01 where time = 1000 limit 1"); rs2.next(); // type of r2 is INT32(int), test int convert to long long type = rs2.getLong(2); - Assert.assertTrue(type == 1); + Assert.assertEquals(1, type); ResultSet rs3 = st1.executeQuery("select grade from root.t1.wf01.wt01 where time = 1000 limit 1"); rs3.next(); // type of r3 is INT64(long), test long convert to int int grade = rs3.getInt(2); - Assert.assertTrue(grade == 1000); + Assert.assertEquals(1000, grade); st1.close(); } catch (Exception e) {
