├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── example ├── data │ └── kafka_data.csv ├── readme.md └── src │ └── main │ └── java │ └── cn │ └── edu │ └── tsinghua │ ├── jdbcDemo │ └── SendDataToIotdb.java │ └── kafka_iotdbDemo │ ├── KafkaConsumer.java │ └── KafkaProducer.java ├── interface ├── rpc.thrift └── thrift │ └── cn │ └── edu │ └── tsinghua │ └── iotdb │ └── jdbc │ └── thrift │ ├── TSCancelOperationReq.java │ ├── TSCancelOperationResp.java │ ├── TSCloseOperationReq.java │ ├── TSCloseOperationResp.java │ ├── TSCloseSessionReq.java │ ├── TSCloseSessionResp.java │ ├── TSColumnSchema.java │ ├── TSDataValue.java │ ├── TSExecuteBatchStatementReq.java │ ├── TSExecuteBatchStatementResp.java │ ├── TSExecuteStatementReq.java │ ├── TSExecuteStatementResp.java │ ├── TSFetchMetadataReq.java │ ├── TSFetchMetadataResp.java │ ├── TSFetchResultsReq.java │ ├── TSFetchResultsResp.java │ ├── TSGetOperationStatusReq.java │ ├── TSGetOperationStatusResp.java │ ├── TSGetTimeZoneResp.java │ ├── TSHandleIdentifier.java │ ├── TSIService.java │ ├── TSOpenSessionReq.java │ ├── TSOpenSessionResp.java │ ├── TSOperationHandle.java │ ├── TSProtocolVersion.java │ ├── TSQueryDataSet.java │ ├── TSRowRecord.java │ ├── TSSetTimeZoneReq.java │ ├── TSSetTimeZoneResp.java │ ├── TS_SessionHandle.java │ ├── TS_Status.java │ └── TS_StatusCode.java ├── package.sh ├── pom.xml └── src ├── main └── java │ └── cn │ └── edu │ └── tsinghua │ └── iotdb │ └── jdbc │ ├── TsFileDBConstant.java │ ├── TsfileConnection.java │ ├── TsfileConnectionParams.java │ ├── TsfileDatabaseMetadata.java │ ├── TsfileDriver.java │ ├── TsfileJDBCConfig.java │ ├── TsfileMetadataResultMetadata.java │ ├── TsfileMetadataResultSet.java │ ├── TsfilePrepareStatement.java │ ├── TsfileQueryResultSet.java │ ├── TsfileResultMetadata.java │ ├── TsfileSQLException.java │ ├── TsfileStatement.java │ ├── TsfileURLException.java │ └── Utils.java └── test └── java └── cn └── edu └── tsinghua └── iotdb └── jdbc ├── BatchTest.java ├── TsFilePrepareStatementTest.java ├── TsfileConnectionTest.java ├── TsfileDatabaseMetadataTest.java ├── TsfileMetadataResultMetadataTest.java ├── TsfileQueryResultSetTest.java ├── TsfileResultMetadataTest.java ├── TsfileStatementTest.java ├── UtilsTest.java └── demo ├── MetadataDemo.java ├── PrepareStatementDemo.java └── StatementDemo.java /.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | tsfiledb/data/* 3 | tsfiledb/derby.log 4 | tsfiledb/*.pid 5 | # Eclipse IDE files 6 | **/.classpath 7 | **/.project 8 | **/.settings/ 9 | # src/main/resources/ 10 | # intellij IDE files 11 | **/*.iml 12 | **/.idea/ 13 | **/*.log 14 | # Apple OS X related 15 | **/.DS_Store 16 | derby-tsfile-db 17 | 18 | # build generated 19 | **/target/ 20 | **/build/ 21 | 22 | # intermediately generated locally 23 | **/logs/ 24 | src/main/resources/* 25 | 26 | tsfile-timeseries/src/main/resources/logback.out.out.xml 27 | tsfile-timeseries/src/main/resources/logback.out.xml 28 | tsfile-service/derby-tsfile-db/ 29 | tsfile-timeseries/src/test/resources/data 30 | src/main/resources/metadata/mlog.txt 31 | tsfile-jdbc/src/main/resources/output/queryRes.csv 32 | 33 | *.jar 34 | *.gz 35 | *.tar.gz 36 | *.tar 37 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | #sudo: required 3 | 4 | language: java 5 | 6 | jdk: 7 | - oraclejdk8 8 | 9 | before_install: 10 | # - sudo apt-get install -qq libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev 11 | # - wget http://archive.apache.org/dist/thrift/0.9.1/thrift-0.9.1.tar.gz 12 | # - tar xfz thrift-0.9.1.tar.gz 13 | # - cd thrift-0.9.1 14 | # - chmod +x ./configure 15 | # - ./configure --disable-gen-erl --disable-gen-hs --without-cpp --without-boost --without-qt4 --without-c_glib --without-csharp --without-erlang --without-python --without-perl --without-php --without-php_extension --without-ruby --without-haskell --without-go --without-d 16 | # - sudo make install 17 | # - cd .. 18 | - pip install --user codecov 19 | - git clone https://github.com/thulab/tsfile.git 20 | - cd tsfile 21 | # - git checkout hxd_tsfile_sdk 22 | - mvn install -DskipTests=true 23 | - cd .. 24 | 25 | script: 26 | # only SNAPSHOT version needs to do the following phase 27 | - mvn cobertura:cobertura 28 | - bash <(curl -s https://codecov.io/bash) -t 853796a6-a626-422f-a897-ac233e121f8f 29 | - mvn clean test 30 | 31 | after_success: 32 | - mvn cobertura:cobertura 33 | - bash <(curl -s https://codecov.io/bash) -t 853796a6-a626-422f-a897-ac233e121f8f 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Status 2 | [![Build Status](https://travis-ci.org/thulab/iotdb-jdbc.svg?branch=master)](https://travis-ci.org/thulab/iotdb-jdbc) 3 | [![codecov](https://codecov.io/gh/thulab/iotdb-jdbc/branch/master/graph/badge.svg)](https://codecov.io/gh/thulab/iotdb-jdbc) 4 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/cn.edu.tsinghua/iotdb-jdbc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/cn.edu.tsinghua/iotdb-jdbc/) 5 | [![GitHub release](https://img.shields.io/github/release/thulab/iotdb-jdbc.svg)](https://github.com/thulab/iotdb-jdbc/releases) 6 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 7 | 8 | # Usage 9 | 10 | ## Dependencies 11 | 12 | * JDK >= 1.8 13 | * Maven >= 3.0 14 | 15 | ## How to package 16 | 17 | > mvn clean package -Dmaven.test.skip=true 18 | 19 | ## How to install in local maven repository 20 | 21 | > mvn clean install -Dmaven.test.skip=true 22 | 23 | ## Using IoTDB JDBC with Maven 24 | 25 | ``` 26 | 27 | 28 | cn.edu.tsinghua 29 | iotdb-jdbc 30 | 0.7.1 31 | 32 | 33 | ``` 34 | 35 | ## Example 36 | (for more detailes, please see example/src/main/java/cn/edu/tsinghua/jdbcDemo/SendDataToIotdb.java) 37 | ```Java 38 | import java.sql.Connection; 39 | import java.sql.DriverManager; 40 | import java.sql.ResultSet; 41 | import java.sql.SQLException; 42 | import java.sql.Statement; 43 | 44 | public class Example { 45 | public static void main(String[] args) throws ClassNotFoundException, SQLException { 46 | Class.forName("cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"); 47 | Connection connection = null; 48 | Statement statement = null; 49 | try { 50 | connection = DriverManager.getConnection("jdbc:tsfile://127.0.0.1:6667/", "root", "root"); 51 | statement = connection.createStatement(); 52 | statement.execute("select s1 from root.laptop.d1"); 53 | ResultSet resultSet = statement.getResultSet(); 54 | while(resultSet.next()){ 55 | System.out.println(String.format("timestamp %s, value %s", resultSet.getString(1), resultSet.getString(2))); 56 | } 57 | } finally { 58 | if(statement != null) statement.close(); 59 | if(connection != null) connection.close(); 60 | } 61 | } 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /example/data/kafka_data.csv: -------------------------------------------------------------------------------- 1 | sensor1,2017/10/24 19:30:00,60 61 62 2 | sensor2,2017/10/24 19:30:00,160 161 162 3 | sensor3,2017/10/24 19:30:00,260 261 262 4 | sensor4,2017/10/24 19:30:00,360 361 362 5 | sensor1,2017/10/24 19:31:00,81 81 82 6 | sensor2,2017/10/24 19:31:00,180 181 182 7 | sensor3,2017/10/24 19:31:00,280 281 282 8 | sensor4,2017/10/24 19:31:00,380 381 382 9 | sensor1,2017/10/24 19:32:00,50 51 52 10 | sensor2,2017/10/24 19:32:00,150 151 152 11 | sensor3,2017/10/24 19:32:00,250 251 252 12 | sensor4,2017/10/24 19:32:00,350 351 352 13 | sensor1,2017/10/24 19:33:00,40 41 42 14 | sensor2,2017/10/24 19:33:00,140 141 142 15 | sensor3,2017/10/24 19:33:00,240 241 242 16 | sensor4,2017/10/24 19:33:00,340 341 342 17 | sensor1,2017/10/24 19:34:00,10 11 12 18 | sensor2,2017/10/24 19:34:00,110 111 112 19 | sensor3,2017/10/24 19:34:00,210 211 212 20 | sensor4,2017/10/24 19:34:00,310 311 312 -------------------------------------------------------------------------------- /example/readme.md: -------------------------------------------------------------------------------- 1 | # Function 2 | ``` 3 | The example is to show how to send data from localhost to IoTDB through Kafka. 4 | ``` 5 | # Usage 6 | ## Dependencies with Maven 7 | 8 | ``` 9 | 10 | 11 | org.apache.kafka 12 | kafka_2.10 13 | 0.8.2.0 14 | 15 | 16 | cn.edu.tsinghua 17 | iotdb-jdbc 18 | 0.7.1 19 | 20 | 21 | ``` 22 | 23 | ## Launch the servers 24 | 25 | ``` 26 |  Before you run the program, make sure you have launched the servers of Kafka and IoTDB. 27 |  For details, please refer to http://kafka.apache.org/081/documentation.html#quickstart 28 | ``` 29 | 30 | ## Run KafkaProducer.java 31 | 32 | ``` 33 | The class is to send data from localhost to Kafka clusters. 34 |  Firstly, you have to change the parameter of TOPIC to what you create:(for example : "test") 35 |  > public final static String TOPIC = "test"; 36 |  The default format of data is "device,timestamp,value ". (for example : "sensor1,2017/10/24 19:30:00,60") 37 | Then you need to create a .CSV file in your localhost, which contains the data to be transmitted.Then set the parameter of Filename:(for example : examples/data/kafka_data.csv) 38 | > private final static String fileName = "kafka_data.csv"; 39 |  Finally, run KafkaProducer.java 40 | ``` 41 | 42 | ## Run KafkaConsumer.java 43 | 44 | ``` 45 | The class is to show how to consume data from kafka through multi-threads. 46 | The data is sent by class KafkaProducer. 47 |  You can set the parameter of threadsNum to make sure the number of consumer threads:(for example: "5") 48 | > private final static int threadsNum = 5; 49 | ``` 50 | 51 | ### Notice 52 |  If you want to use multiple consumers, please make sure that the number of topic's partition you create is more than 1. 53 | 54 | ## Run SendDataToIotdb.java 55 | 56 | ``` 57 | The class is to show how to write and read date from IoTDB through JDBC 58 |  You can set the parameter of threadsNum to make sure the number of consumer threads:(for example: "5") 59 | > private final static int threadsNum = 5; 60 |  Then you change the insert EQL according to your localhost's data. 61 | Finally, run SendDataToIotdb.java 62 | ``` 63 | -------------------------------------------------------------------------------- /example/src/main/java/cn/edu/tsinghua/jdbcDemo/SendDataToIotdb.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The class is to show how to write and read date from IoTDB through JDBC 3 | */ 4 | package cn.edu.tsinghua.jdbcDemo; 5 | 6 | import java.sql.Connection; 7 | import java.sql.DriverManager; 8 | import java.sql.Statement; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | import java.sql.ResultSet; 12 | import java.sql.DatabaseMetaData; 13 | 14 | public class SendDataToIotdb { 15 | Connection connection = null; 16 | Statement statement = null; 17 | ResultSet resultSet = null; 18 | 19 | public void connectToIotdb() throws Exception { 20 | // 1. load JDBC driver of IoTDB 21 | Class.forName("cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"); 22 | // 2. DriverManager connect to IoTDB 23 | connection = DriverManager.getConnection("jdbc:tsfile://localhost:6667/", "root", "root"); 24 | 25 | statement = connection.createStatement(); 26 | } 27 | 28 | public void writeData(String out) throws Exception { // write data to IoTDB 29 | 30 | String item[] = out.split(","); 31 | 32 | // get table structure information from IoTDB-JDBC 33 | DatabaseMetaData databaseMetaData = connection.getMetaData(); 34 | 35 | // String path is the path to insert 36 | String path = "root.vehicle.sensor." + item[0]; 37 | 38 | // get path set iterator 39 | resultSet = databaseMetaData.getColumns(null, null, path, null); 40 | 41 | // if path set iterator is null,then create path 42 | if (!resultSet.next()) { 43 | String epl = "CREATE TIMESERIES " + path + " WITH DATATYPE=TEXT, ENCODING=PLAIN"; 44 | statement.execute(epl); 45 | } 46 | // insert data to IoTDB 47 | String template = "INSERT INTO root.vehicle.sensor(timestamp,%s) VALUES (%s,'%s')"; 48 | String epl = String.format(template, item[0], item[1], item[2]); 49 | statement.execute(epl); 50 | } 51 | 52 | public void readData(String path) throws Exception { // read data from IoTDB 53 | 54 | String sql = "select * from root.vehicle"; 55 | boolean hasResultSet = statement.execute(sql); 56 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 57 | if (hasResultSet) { 58 | ResultSet res = statement.getResultSet(); 59 | System.out.println(" Time" + "|" + path); 60 | while (res.next()) { 61 | long time = Long.parseLong(res.getString("Time")); 62 | String dateTime = dateFormat.format(new Date(time)); 63 | System.out.println(dateTime + " | " + res.getString(path)); 64 | } 65 | } 66 | } 67 | 68 | public static void main(String[] args) throws Exception { 69 | SendDataToIotdb sendDataToIotdb = new SendDataToIotdb(); 70 | sendDataToIotdb.connectToIotdb(); 71 | sendDataToIotdb.writeData("sensor1,2017/10/24 19:33:00,40 41 42"); 72 | sendDataToIotdb.writeData("sensor2,2017/10/24 19:33:00,140 141 142"); 73 | sendDataToIotdb.writeData("sensor3,2017/10/24 19:33:00,240 241 242"); 74 | sendDataToIotdb.writeData("sensor4,2017/10/24 19:33:00,340 341 342"); 75 | sendDataToIotdb.readData("root.vehicle.sensor.sensor4"); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /example/src/main/java/cn/edu/tsinghua/kafka_iotdbDemo/KafkaConsumer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The class is to show how to get data from kafka through multi-threads. 3 | * The data is sent by class KafkaProducer. 4 | */ 5 | package cn.edu.tsinghua.kafka_iotdbDemo; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.Properties; 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | 14 | import kafka.consumer.ConsumerConfig; 15 | import kafka.consumer.ConsumerIterator; 16 | import kafka.consumer.KafkaStream; 17 | import kafka.javaapi.consumer.ConsumerConnector; 18 | import kafka.message.MessageAndMetadata; 19 | import kafka.serializer.StringDecoder; 20 | import kafka.utils.VerifiableProperties; 21 | import cn.edu.tsinghua.jdbcDemo.*; 22 | 23 | public class KafkaConsumer { 24 | 25 | private final ConsumerConnector consumer; 26 | private final static int threadsNum = 5; // consumer threads 27 | private ExecutorService executor; 28 | 29 | private KafkaConsumer() { 30 | // Consumer configuration 31 | Properties props = new Properties(); 32 | 33 | // zookeeper configuration 34 | props.put("zookeeper.connect", "127.0.0.1:2181"); 35 | 36 | 37 | props.put("group.id", "consumeGroup"); 38 | 39 | // ZooKeeper session timeout 40 | props.put("zookeeper.session.timeout.ms", "400"); 41 | 42 | // a ZooKeeper ‘follower’ can be behind the master before an error 43 | // occurs 44 | props.put("zookeeper.sync.time.ms", "200"); 45 | props.put("rebalance.max.retries", "5"); 46 | 47 | // Backoff time between retries during rebalance 48 | props.put("rebalance.backoff.ms", "1200"); 49 | 50 | // how often updates to the consumed offsets are written to ZooKeeper 51 | props.put("auto.commit.interval.ms", "1000"); 52 | 53 | // What to do when there is no initial offset in ZooKeeper or if an 54 | // offset is out of range: 55 | // * smallest : automatically reset the offset to the smallest offset 56 | props.put("auto.offset.reset", "smallest"); 57 | 58 | // serializer class 59 | props.put("serializer.class", "kafka.serializer.StringEncoder"); 60 | 61 | // consumer instance 62 | ConsumerConfig config = new ConsumerConfig(props); 63 | consumer = kafka.consumer.Consumer.createJavaConsumerConnector(config); 64 | } 65 | 66 | void consume() throws Exception { 67 | // specify the number of consumer threads 68 | Map topicCountMap = new HashMap(); 69 | topicCountMap.put(KafkaProducer.TOPIC, new Integer(threadsNum)); 70 | 71 | // specify data decoder 72 | StringDecoder keyDecoder = new StringDecoder(new VerifiableProperties()); 73 | StringDecoder valueDecoder = new StringDecoder(new VerifiableProperties()); 74 | 75 | Map>> consumerMap = consumer 76 | .createMessageStreams(topicCountMap, keyDecoder, valueDecoder); // 三个String分别为TOPIC、Key、Value 77 | 78 | // acquire data 79 | List> streams = consumerMap.get(KafkaProducer.TOPIC); 80 | 81 | // multi-threaded consume 82 | executor = Executors.newFixedThreadPool(threadsNum); //create a thread pool 83 | for (final KafkaStream stream : streams) { 84 | executor.submit(new ConsumerThread(stream)); // run thread 85 | } 86 | } 87 | 88 | public static void main(String[] args) throws Exception { 89 | new KafkaConsumer().consume(); 90 | } 91 | } 92 | 93 | class ConsumerThread implements Runnable { 94 | 95 | private KafkaStream stream; 96 | private SendDataToIotdb sendDataToIotdb; 97 | 98 | public ConsumerThread(KafkaStream stream) throws Exception { 99 | this.stream = stream; 100 | // establish JDBC connection of IoTDB 101 | sendDataToIotdb = new SendDataToIotdb(); 102 | sendDataToIotdb.connectToIotdb(); 103 | } 104 | 105 | public void run() { 106 | ConsumerIterator it = stream.iterator(); 107 | while (it.hasNext()) { 108 | MessageAndMetadata consumerIterator = it.next(); 109 | String uploadMessage = consumerIterator.message(); 110 | System.out.println(Thread.currentThread().getName() 111 | + " from partiton[" + consumerIterator.partition() + "]: " 112 | + uploadMessage); 113 | try { 114 | sendDataToIotdb.writeData(uploadMessage); // upload data to the IoTDB database 115 | 116 | } catch (Exception ex) { 117 | System.out.println("SQLException: " + ex.getMessage()); 118 | } 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /example/src/main/java/cn/edu/tsinghua/kafka_iotdbDemo/KafkaProducer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The class is to show how to send data to kafka 3 | */ 4 | package cn.edu.tsinghua.kafka_iotdbDemo; 5 | 6 | import java.util.Properties; 7 | 8 | import kafka.javaapi.producer.Producer; 9 | import kafka.producer.KeyedMessage; 10 | import kafka.producer.ProducerConfig; 11 | import java.io.BufferedReader; 12 | import java.io.File; 13 | import java.io.FileReader; 14 | 15 | public class KafkaProducer { 16 | private final Producer producer; 17 | public final static String TOPIC = "test"; 18 | private final static String fileName = "kafka_data.csv"; 19 | 20 | private KafkaProducer() { 21 | 22 | Properties props = new Properties(); 23 | 24 | props.put("metadata.broker.list", "127.0.0.1:9092"); 25 | props.put("zk.connect", "127.0.0.1:2181"); 26 | props.put("serializer.class", "kafka.serializer.StringEncoder"); 27 | props.put("key.serializer.class", "kafka.serializer.StringEncoder"); 28 | 29 | props.put("request.required.acks", "-1"); 30 | 31 | //Producer instance 32 | producer = new Producer(new ProducerConfig(props)); 33 | } 34 | 35 | void produce() { 36 | //read file 37 | try { 38 | File csv = new File(fileName); 39 | BufferedReader reader = new BufferedReader(new FileReader(csv)); 40 | String line = null; 41 | int messageNum = 1; 42 | while ((line = reader.readLine()) != null) { 43 | String key = String.valueOf(messageNum); 44 | String data = line; 45 | producer.send(new KeyedMessage(TOPIC, key, data)); 46 | System.out.println(data); 47 | messageNum++; 48 | } 49 | reader.close(); 50 | } catch (Exception e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | 55 | public static void main(String[] args) { 56 | new KafkaProducer().produce(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /interface/rpc.thrift: -------------------------------------------------------------------------------- 1 | namespace java cn.edu.tsinghua.iotdb.jdbc.thrift 2 | 3 | 4 | // The return status code contained in each response. 5 | enum TS_StatusCode { 6 | SUCCESS_STATUS, 7 | SUCCESS_WITH_INFO_STATUS, 8 | STILL_EXECUTING_STATUS, 9 | ERROR_STATUS, 10 | INVALID_HANDLE_STATUS 11 | } 12 | 13 | // The return status of a remote request 14 | struct TS_Status { 15 | 1: required TS_StatusCode statusCode 16 | 17 | // If status is SUCCESS_WITH_INFO, info_msgs may be populated with 18 | // additional diagnostic information. 19 | 2: optional list infoMessages 20 | 21 | // If status is ERROR, then the following fields may be set 22 | 3: optional string sqlState // as defined in the ISO/IEF CLI specification 23 | 4: optional i32 errorCode // internal error code 24 | 5: optional string errorMessage 25 | } 26 | 27 | struct TSHandleIdentifier { 28 | // 16 byte globally unique identifier This is the public ID of the handle and can be used for reporting. 29 | // In current version, it is not used. 30 | 1: required binary guid, 31 | 32 | // 16 byte secret generated by the server and used to verify that the handle is not being hijacked by another user. 33 | // In current version, it is not used. 34 | 2: required binary secret, 35 | } 36 | 37 | // Client-side reference to a task running asynchronously on the server. 38 | struct TSOperationHandle { 39 | 1: required TSHandleIdentifier operationId 40 | 41 | // If hasResultSet = TRUE, then this operation 42 | // generates a result set that can be fetched. 43 | // Note that the result set may be empty. 44 | // 45 | // If hasResultSet = FALSE, then this operation 46 | // does not generate a result set, and calling 47 | // GetResultSetMetadata or FetchResults against 48 | // this OperationHandle will generate an error. 49 | 2: required bool hasResultSet 50 | } 51 | 52 | struct TSExecuteStatementResp { 53 | 1: required TS_Status status 54 | 2: optional TSOperationHandle operationHandle 55 | // Column names in select statement of SQL 56 | 3: optional list columns 57 | 4: optional string operationType 58 | } 59 | 60 | enum TSProtocolVersion { 61 | TSFILE_SERVICE_PROTOCOL_V1, 62 | } 63 | 64 | // Client-side handle to persistent session information on the server-side. 65 | // In current version, it is not used. 66 | struct TS_SessionHandle { 67 | 1: required TSHandleIdentifier sessionId 68 | } 69 | 70 | 71 | struct TSOpenSessionResp { 72 | 1: required TS_Status status 73 | 74 | // The protocol version that the server is using. 75 | 2: required TSProtocolVersion serverProtocolVersion = TSProtocolVersion.TSFILE_SERVICE_PROTOCOL_V1 76 | 77 | // Session Handle 78 | 3: optional TS_SessionHandle sessionHandle 79 | 80 | // The configuration settings for this session. 81 | 4: optional map configuration 82 | } 83 | 84 | // OpenSession() 85 | // Open a session (connection) on the server against which operations may be executed. 86 | struct TSOpenSessionReq { 87 | 1: required TSProtocolVersion client_protocol = TSProtocolVersion.TSFILE_SERVICE_PROTOCOL_V1 88 | 2: optional string username 89 | 3: optional string password 90 | 4: optional map configuration 91 | } 92 | 93 | struct TSCloseSessionResp { 94 | 1: required TS_Status status 95 | } 96 | 97 | // CloseSession() 98 | // Closes the specified session and frees any resources currently allocated to that session. 99 | // Any open operations in that session will be canceled. 100 | struct TSCloseSessionReq { 101 | 1: required TS_SessionHandle sessionHandle 102 | } 103 | 104 | // ExecuteStatement() 105 | // 106 | // Execute a statement. 107 | // The returned OperationHandle can be used to check on the status of the statement, and to fetch results once the 108 | // statement has finished executing. 109 | struct TSExecuteStatementReq { 110 | // The session to execute the statement against 111 | 1: required TS_SessionHandle sessionHandle 112 | 113 | // The statement to be executed (DML, DDL, SET, etc) 114 | 2: required string statement 115 | } 116 | 117 | 118 | struct TSExecuteBatchStatementResp{ 119 | 1: required TS_Status status 120 | // For each value in result, Statement.SUCCESS_NO_INFO represents success, Statement.EXECUTE_FAILED represents fail otherwise. 121 | 2: optional list result 122 | } 123 | 124 | struct TSExecuteBatchStatementReq{ 125 | // The session to execute the statement against 126 | 1: required TS_SessionHandle sessionHandle 127 | 128 | // The statements to be executed (DML, DDL, SET, etc) 129 | 2: required list statements 130 | } 131 | 132 | 133 | struct TSGetOperationStatusReq { 134 | // Session to run this request against 135 | 1: required TSOperationHandle operationHandle 136 | } 137 | 138 | struct TSGetOperationStatusResp { 139 | 1: required TS_Status status 140 | } 141 | 142 | // CancelOperation() 143 | // 144 | // Cancels processing on the specified operation handle and frees any resources which were allocated. 145 | struct TSCancelOperationReq { 146 | // Operation to cancel 147 | 1: required TSOperationHandle operationHandle 148 | } 149 | 150 | struct TSCancelOperationResp { 151 | 1: required TS_Status status 152 | } 153 | 154 | 155 | // CloseOperation() 156 | struct TSCloseOperationReq { 157 | 1: required TSOperationHandle operationHandle 158 | } 159 | 160 | struct TSCloseOperationResp { 161 | 1: required TS_Status status 162 | } 163 | 164 | struct TSDataValue{ 165 | 1: required bool is_empty 166 | 2: optional bool bool_val 167 | 3: optional i32 int_val 168 | 4: optional i64 long_val 169 | 5: optional double float_val 170 | 6: optional double double_val 171 | 7: optional binary binary_val 172 | 8: optional string type; 173 | } 174 | 175 | struct TSRowRecord{ 176 | 1: required i64 timestamp 177 | // column names 178 | 2: required list keys 179 | // column values 180 | 3: required list values 181 | } 182 | 183 | struct TSQueryDataSet{ 184 | 1: required list records 185 | } 186 | 187 | struct TSFetchResultsReq{ 188 | 1: required string statement 189 | 2: required i32 fetch_size 190 | } 191 | 192 | struct TSFetchResultsResp{ 193 | 1: required TS_Status status 194 | 2: required bool hasResultSet 195 | 3: optional TSQueryDataSet queryDataSet 196 | } 197 | 198 | struct TSFetchMetadataResp{ 199 | 1: required TS_Status status 200 | 2: optional string metadataInJson 201 | 3: optional list ColumnsList 202 | 4: optional string dataType 203 | 5: optional list> showTimeseriesList 204 | 7: optional set showStorageGroups 205 | } 206 | 207 | struct TSFetchMetadataReq{ 208 | 1: required string type 209 | 2: optional string columnPath 210 | } 211 | 212 | struct TSColumnSchema{ 213 | 1: optional string name; 214 | 2: optional string dataType; 215 | 3: optional string encoding; 216 | 4: optional map otherArgs; 217 | } 218 | 219 | struct TSGetTimeZoneResp { 220 | 1: required TS_Status status 221 | 2: required string timeZone 222 | } 223 | 224 | struct TSSetTimeZoneReq { 225 | 1: required string timeZone 226 | } 227 | 228 | struct TSSetTimeZoneResp { 229 | 1: required TS_Status status 230 | } 231 | 232 | service TSIService { 233 | TSOpenSessionResp openSession(1:TSOpenSessionReq req); 234 | 235 | TSCloseSessionResp closeSession(1:TSCloseSessionReq req); 236 | 237 | TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req); 238 | 239 | TSExecuteBatchStatementResp executeBatchStatement(1:TSExecuteBatchStatementReq req); 240 | 241 | TSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req); 242 | 243 | TSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req); 244 | 245 | TSFetchResultsResp fetchResults(1:TSFetchResultsReq req) 246 | 247 | TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req) 248 | 249 | TSCancelOperationResp cancelOperation(1:TSCancelOperationReq req); 250 | 251 | TSCloseOperationResp closeOperation(1:TSCloseOperationReq req); 252 | 253 | TSGetTimeZoneResp getTimeZone(); 254 | 255 | TSSetTimeZoneResp setTimeZone(1:TSSetTimeZoneReq req); 256 | } 257 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TSCancelOperationResp.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | public class TSCancelOperationResp implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 36 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSCancelOperationResp"); 37 | 38 | private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.STRUCT, (short)1); 39 | 40 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 41 | static { 42 | schemes.put(StandardScheme.class, new TSCancelOperationRespStandardSchemeFactory()); 43 | schemes.put(TupleScheme.class, new TSCancelOperationRespTupleSchemeFactory()); 44 | } 45 | 46 | public TS_Status status; // required 47 | 48 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 49 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 50 | STATUS((short)1, "status"); 51 | 52 | private static final Map byName = new HashMap(); 53 | 54 | static { 55 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 56 | byName.put(field.getFieldName(), field); 57 | } 58 | } 59 | 60 | /** 61 | * Find the _Fields constant that matches fieldId, or null if its not found. 62 | */ 63 | public static _Fields findByThriftId(int fieldId) { 64 | switch(fieldId) { 65 | case 1: // STATUS 66 | return STATUS; 67 | default: 68 | return null; 69 | } 70 | } 71 | 72 | /** 73 | * Find the _Fields constant that matches fieldId, throwing an exception 74 | * if it is not found. 75 | */ 76 | public static _Fields findByThriftIdOrThrow(int fieldId) { 77 | _Fields fields = findByThriftId(fieldId); 78 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 79 | return fields; 80 | } 81 | 82 | /** 83 | * Find the _Fields constant that matches name, or null if its not found. 84 | */ 85 | public static _Fields findByName(String name) { 86 | return byName.get(name); 87 | } 88 | 89 | private final short _thriftId; 90 | private final String _fieldName; 91 | 92 | _Fields(short thriftId, String fieldName) { 93 | _thriftId = thriftId; 94 | _fieldName = fieldName; 95 | } 96 | 97 | public short getThriftFieldId() { 98 | return _thriftId; 99 | } 100 | 101 | public String getFieldName() { 102 | return _fieldName; 103 | } 104 | } 105 | 106 | // isset id assignments 107 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 108 | static { 109 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 110 | tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, 111 | new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TS_Status.class))); 112 | metaDataMap = Collections.unmodifiableMap(tmpMap); 113 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSCancelOperationResp.class, metaDataMap); 114 | } 115 | 116 | public TSCancelOperationResp() { 117 | } 118 | 119 | public TSCancelOperationResp( 120 | TS_Status status) 121 | { 122 | this(); 123 | this.status = status; 124 | } 125 | 126 | /** 127 | * Performs a deep copy on other. 128 | */ 129 | public TSCancelOperationResp(TSCancelOperationResp other) { 130 | if (other.isSetStatus()) { 131 | this.status = new TS_Status(other.status); 132 | } 133 | } 134 | 135 | public TSCancelOperationResp deepCopy() { 136 | return new TSCancelOperationResp(this); 137 | } 138 | 139 | @Override 140 | public void clear() { 141 | this.status = null; 142 | } 143 | 144 | public TS_Status getStatus() { 145 | return this.status; 146 | } 147 | 148 | public TSCancelOperationResp setStatus(TS_Status status) { 149 | this.status = status; 150 | return this; 151 | } 152 | 153 | public void unsetStatus() { 154 | this.status = null; 155 | } 156 | 157 | /** Returns true if field status is set (has been assigned a value) and false otherwise */ 158 | public boolean isSetStatus() { 159 | return this.status != null; 160 | } 161 | 162 | public void setStatusIsSet(boolean value) { 163 | if (!value) { 164 | this.status = null; 165 | } 166 | } 167 | 168 | public void setFieldValue(_Fields field, Object value) { 169 | switch (field) { 170 | case STATUS: 171 | if (value == null) { 172 | unsetStatus(); 173 | } else { 174 | setStatus((TS_Status)value); 175 | } 176 | break; 177 | 178 | } 179 | } 180 | 181 | public Object getFieldValue(_Fields field) { 182 | switch (field) { 183 | case STATUS: 184 | return getStatus(); 185 | 186 | } 187 | throw new IllegalStateException(); 188 | } 189 | 190 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 191 | public boolean isSet(_Fields field) { 192 | if (field == null) { 193 | throw new IllegalArgumentException(); 194 | } 195 | 196 | switch (field) { 197 | case STATUS: 198 | return isSetStatus(); 199 | } 200 | throw new IllegalStateException(); 201 | } 202 | 203 | @Override 204 | public boolean equals(Object that) { 205 | if (that == null) 206 | return false; 207 | if (that instanceof TSCancelOperationResp) 208 | return this.equals((TSCancelOperationResp)that); 209 | return false; 210 | } 211 | 212 | public boolean equals(TSCancelOperationResp that) { 213 | if (that == null) 214 | return false; 215 | 216 | boolean this_present_status = true && this.isSetStatus(); 217 | boolean that_present_status = true && that.isSetStatus(); 218 | if (this_present_status || that_present_status) { 219 | if (!(this_present_status && that_present_status)) 220 | return false; 221 | if (!this.status.equals(that.status)) 222 | return false; 223 | } 224 | 225 | return true; 226 | } 227 | 228 | @Override 229 | public int hashCode() { 230 | return 0; 231 | } 232 | 233 | @Override 234 | public int compareTo(TSCancelOperationResp other) { 235 | if (!getClass().equals(other.getClass())) { 236 | return getClass().getName().compareTo(other.getClass().getName()); 237 | } 238 | 239 | int lastComparison = 0; 240 | 241 | lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus()); 242 | if (lastComparison != 0) { 243 | return lastComparison; 244 | } 245 | if (isSetStatus()) { 246 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status); 247 | if (lastComparison != 0) { 248 | return lastComparison; 249 | } 250 | } 251 | return 0; 252 | } 253 | 254 | public _Fields fieldForId(int fieldId) { 255 | return _Fields.findByThriftId(fieldId); 256 | } 257 | 258 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 259 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 260 | } 261 | 262 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 263 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 264 | } 265 | 266 | @Override 267 | public String toString() { 268 | StringBuilder sb = new StringBuilder("TSCancelOperationResp("); 269 | boolean first = true; 270 | 271 | sb.append("status:"); 272 | if (this.status == null) { 273 | sb.append("null"); 274 | } else { 275 | sb.append(this.status); 276 | } 277 | first = false; 278 | sb.append(")"); 279 | return sb.toString(); 280 | } 281 | 282 | public void validate() throws org.apache.thrift.TException { 283 | // check for required fields 284 | if (status == null) { 285 | throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' was not present! Struct: " + toString()); 286 | } 287 | // check for sub-struct validity 288 | if (status != null) { 289 | status.validate(); 290 | } 291 | } 292 | 293 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 294 | try { 295 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 296 | } catch (org.apache.thrift.TException te) { 297 | throw new java.io.IOException(te); 298 | } 299 | } 300 | 301 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 302 | try { 303 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 304 | } catch (org.apache.thrift.TException te) { 305 | throw new java.io.IOException(te); 306 | } 307 | } 308 | 309 | private static class TSCancelOperationRespStandardSchemeFactory implements SchemeFactory { 310 | public TSCancelOperationRespStandardScheme getScheme() { 311 | return new TSCancelOperationRespStandardScheme(); 312 | } 313 | } 314 | 315 | private static class TSCancelOperationRespStandardScheme extends StandardScheme { 316 | 317 | public void read(org.apache.thrift.protocol.TProtocol iprot, TSCancelOperationResp struct) throws org.apache.thrift.TException { 318 | org.apache.thrift.protocol.TField schemeField; 319 | iprot.readStructBegin(); 320 | while (true) 321 | { 322 | schemeField = iprot.readFieldBegin(); 323 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 324 | break; 325 | } 326 | switch (schemeField.id) { 327 | case 1: // STATUS 328 | if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { 329 | struct.status = new TS_Status(); 330 | struct.status.read(iprot); 331 | struct.setStatusIsSet(true); 332 | } else { 333 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 334 | } 335 | break; 336 | default: 337 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 338 | } 339 | iprot.readFieldEnd(); 340 | } 341 | iprot.readStructEnd(); 342 | 343 | // check for required fields of primitive type, which can't be checked in the validate method 344 | struct.validate(); 345 | } 346 | 347 | public void write(org.apache.thrift.protocol.TProtocol oprot, TSCancelOperationResp struct) throws org.apache.thrift.TException { 348 | struct.validate(); 349 | 350 | oprot.writeStructBegin(STRUCT_DESC); 351 | if (struct.status != null) { 352 | oprot.writeFieldBegin(STATUS_FIELD_DESC); 353 | struct.status.write(oprot); 354 | oprot.writeFieldEnd(); 355 | } 356 | oprot.writeFieldStop(); 357 | oprot.writeStructEnd(); 358 | } 359 | 360 | } 361 | 362 | private static class TSCancelOperationRespTupleSchemeFactory implements SchemeFactory { 363 | public TSCancelOperationRespTupleScheme getScheme() { 364 | return new TSCancelOperationRespTupleScheme(); 365 | } 366 | } 367 | 368 | private static class TSCancelOperationRespTupleScheme extends TupleScheme { 369 | 370 | @Override 371 | public void write(org.apache.thrift.protocol.TProtocol prot, TSCancelOperationResp struct) throws org.apache.thrift.TException { 372 | TTupleProtocol oprot = (TTupleProtocol) prot; 373 | struct.status.write(oprot); 374 | } 375 | 376 | @Override 377 | public void read(org.apache.thrift.protocol.TProtocol prot, TSCancelOperationResp struct) throws org.apache.thrift.TException { 378 | TTupleProtocol iprot = (TTupleProtocol) prot; 379 | struct.status = new TS_Status(); 380 | struct.status.read(iprot); 381 | struct.setStatusIsSet(true); 382 | } 383 | } 384 | 385 | } 386 | 387 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TSCloseOperationResp.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | public class TSCloseOperationResp implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 36 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSCloseOperationResp"); 37 | 38 | private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.STRUCT, (short)1); 39 | 40 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 41 | static { 42 | schemes.put(StandardScheme.class, new TSCloseOperationRespStandardSchemeFactory()); 43 | schemes.put(TupleScheme.class, new TSCloseOperationRespTupleSchemeFactory()); 44 | } 45 | 46 | public TS_Status status; // required 47 | 48 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 49 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 50 | STATUS((short)1, "status"); 51 | 52 | private static final Map byName = new HashMap(); 53 | 54 | static { 55 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 56 | byName.put(field.getFieldName(), field); 57 | } 58 | } 59 | 60 | /** 61 | * Find the _Fields constant that matches fieldId, or null if its not found. 62 | */ 63 | public static _Fields findByThriftId(int fieldId) { 64 | switch(fieldId) { 65 | case 1: // STATUS 66 | return STATUS; 67 | default: 68 | return null; 69 | } 70 | } 71 | 72 | /** 73 | * Find the _Fields constant that matches fieldId, throwing an exception 74 | * if it is not found. 75 | */ 76 | public static _Fields findByThriftIdOrThrow(int fieldId) { 77 | _Fields fields = findByThriftId(fieldId); 78 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 79 | return fields; 80 | } 81 | 82 | /** 83 | * Find the _Fields constant that matches name, or null if its not found. 84 | */ 85 | public static _Fields findByName(String name) { 86 | return byName.get(name); 87 | } 88 | 89 | private final short _thriftId; 90 | private final String _fieldName; 91 | 92 | _Fields(short thriftId, String fieldName) { 93 | _thriftId = thriftId; 94 | _fieldName = fieldName; 95 | } 96 | 97 | public short getThriftFieldId() { 98 | return _thriftId; 99 | } 100 | 101 | public String getFieldName() { 102 | return _fieldName; 103 | } 104 | } 105 | 106 | // isset id assignments 107 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 108 | static { 109 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 110 | tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, 111 | new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TS_Status.class))); 112 | metaDataMap = Collections.unmodifiableMap(tmpMap); 113 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSCloseOperationResp.class, metaDataMap); 114 | } 115 | 116 | public TSCloseOperationResp() { 117 | } 118 | 119 | public TSCloseOperationResp( 120 | TS_Status status) 121 | { 122 | this(); 123 | this.status = status; 124 | } 125 | 126 | /** 127 | * Performs a deep copy on other. 128 | */ 129 | public TSCloseOperationResp(TSCloseOperationResp other) { 130 | if (other.isSetStatus()) { 131 | this.status = new TS_Status(other.status); 132 | } 133 | } 134 | 135 | public TSCloseOperationResp deepCopy() { 136 | return new TSCloseOperationResp(this); 137 | } 138 | 139 | @Override 140 | public void clear() { 141 | this.status = null; 142 | } 143 | 144 | public TS_Status getStatus() { 145 | return this.status; 146 | } 147 | 148 | public TSCloseOperationResp setStatus(TS_Status status) { 149 | this.status = status; 150 | return this; 151 | } 152 | 153 | public void unsetStatus() { 154 | this.status = null; 155 | } 156 | 157 | /** Returns true if field status is set (has been assigned a value) and false otherwise */ 158 | public boolean isSetStatus() { 159 | return this.status != null; 160 | } 161 | 162 | public void setStatusIsSet(boolean value) { 163 | if (!value) { 164 | this.status = null; 165 | } 166 | } 167 | 168 | public void setFieldValue(_Fields field, Object value) { 169 | switch (field) { 170 | case STATUS: 171 | if (value == null) { 172 | unsetStatus(); 173 | } else { 174 | setStatus((TS_Status)value); 175 | } 176 | break; 177 | 178 | } 179 | } 180 | 181 | public Object getFieldValue(_Fields field) { 182 | switch (field) { 183 | case STATUS: 184 | return getStatus(); 185 | 186 | } 187 | throw new IllegalStateException(); 188 | } 189 | 190 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 191 | public boolean isSet(_Fields field) { 192 | if (field == null) { 193 | throw new IllegalArgumentException(); 194 | } 195 | 196 | switch (field) { 197 | case STATUS: 198 | return isSetStatus(); 199 | } 200 | throw new IllegalStateException(); 201 | } 202 | 203 | @Override 204 | public boolean equals(Object that) { 205 | if (that == null) 206 | return false; 207 | if (that instanceof TSCloseOperationResp) 208 | return this.equals((TSCloseOperationResp)that); 209 | return false; 210 | } 211 | 212 | public boolean equals(TSCloseOperationResp that) { 213 | if (that == null) 214 | return false; 215 | 216 | boolean this_present_status = true && this.isSetStatus(); 217 | boolean that_present_status = true && that.isSetStatus(); 218 | if (this_present_status || that_present_status) { 219 | if (!(this_present_status && that_present_status)) 220 | return false; 221 | if (!this.status.equals(that.status)) 222 | return false; 223 | } 224 | 225 | return true; 226 | } 227 | 228 | @Override 229 | public int hashCode() { 230 | return 0; 231 | } 232 | 233 | @Override 234 | public int compareTo(TSCloseOperationResp other) { 235 | if (!getClass().equals(other.getClass())) { 236 | return getClass().getName().compareTo(other.getClass().getName()); 237 | } 238 | 239 | int lastComparison = 0; 240 | 241 | lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus()); 242 | if (lastComparison != 0) { 243 | return lastComparison; 244 | } 245 | if (isSetStatus()) { 246 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status); 247 | if (lastComparison != 0) { 248 | return lastComparison; 249 | } 250 | } 251 | return 0; 252 | } 253 | 254 | public _Fields fieldForId(int fieldId) { 255 | return _Fields.findByThriftId(fieldId); 256 | } 257 | 258 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 259 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 260 | } 261 | 262 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 263 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 264 | } 265 | 266 | @Override 267 | public String toString() { 268 | StringBuilder sb = new StringBuilder("TSCloseOperationResp("); 269 | boolean first = true; 270 | 271 | sb.append("status:"); 272 | if (this.status == null) { 273 | sb.append("null"); 274 | } else { 275 | sb.append(this.status); 276 | } 277 | first = false; 278 | sb.append(")"); 279 | return sb.toString(); 280 | } 281 | 282 | public void validate() throws org.apache.thrift.TException { 283 | // check for required fields 284 | if (status == null) { 285 | throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' was not present! Struct: " + toString()); 286 | } 287 | // check for sub-struct validity 288 | if (status != null) { 289 | status.validate(); 290 | } 291 | } 292 | 293 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 294 | try { 295 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 296 | } catch (org.apache.thrift.TException te) { 297 | throw new java.io.IOException(te); 298 | } 299 | } 300 | 301 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 302 | try { 303 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 304 | } catch (org.apache.thrift.TException te) { 305 | throw new java.io.IOException(te); 306 | } 307 | } 308 | 309 | private static class TSCloseOperationRespStandardSchemeFactory implements SchemeFactory { 310 | public TSCloseOperationRespStandardScheme getScheme() { 311 | return new TSCloseOperationRespStandardScheme(); 312 | } 313 | } 314 | 315 | private static class TSCloseOperationRespStandardScheme extends StandardScheme { 316 | 317 | public void read(org.apache.thrift.protocol.TProtocol iprot, TSCloseOperationResp struct) throws org.apache.thrift.TException { 318 | org.apache.thrift.protocol.TField schemeField; 319 | iprot.readStructBegin(); 320 | while (true) 321 | { 322 | schemeField = iprot.readFieldBegin(); 323 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 324 | break; 325 | } 326 | switch (schemeField.id) { 327 | case 1: // STATUS 328 | if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { 329 | struct.status = new TS_Status(); 330 | struct.status.read(iprot); 331 | struct.setStatusIsSet(true); 332 | } else { 333 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 334 | } 335 | break; 336 | default: 337 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 338 | } 339 | iprot.readFieldEnd(); 340 | } 341 | iprot.readStructEnd(); 342 | 343 | // check for required fields of primitive type, which can't be checked in the validate method 344 | struct.validate(); 345 | } 346 | 347 | public void write(org.apache.thrift.protocol.TProtocol oprot, TSCloseOperationResp struct) throws org.apache.thrift.TException { 348 | struct.validate(); 349 | 350 | oprot.writeStructBegin(STRUCT_DESC); 351 | if (struct.status != null) { 352 | oprot.writeFieldBegin(STATUS_FIELD_DESC); 353 | struct.status.write(oprot); 354 | oprot.writeFieldEnd(); 355 | } 356 | oprot.writeFieldStop(); 357 | oprot.writeStructEnd(); 358 | } 359 | 360 | } 361 | 362 | private static class TSCloseOperationRespTupleSchemeFactory implements SchemeFactory { 363 | public TSCloseOperationRespTupleScheme getScheme() { 364 | return new TSCloseOperationRespTupleScheme(); 365 | } 366 | } 367 | 368 | private static class TSCloseOperationRespTupleScheme extends TupleScheme { 369 | 370 | @Override 371 | public void write(org.apache.thrift.protocol.TProtocol prot, TSCloseOperationResp struct) throws org.apache.thrift.TException { 372 | TTupleProtocol oprot = (TTupleProtocol) prot; 373 | struct.status.write(oprot); 374 | } 375 | 376 | @Override 377 | public void read(org.apache.thrift.protocol.TProtocol prot, TSCloseOperationResp struct) throws org.apache.thrift.TException { 378 | TTupleProtocol iprot = (TTupleProtocol) prot; 379 | struct.status = new TS_Status(); 380 | struct.status.read(iprot); 381 | struct.setStatusIsSet(true); 382 | } 383 | } 384 | 385 | } 386 | 387 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TSCloseSessionResp.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | public class TSCloseSessionResp implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 36 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSCloseSessionResp"); 37 | 38 | private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.STRUCT, (short)1); 39 | 40 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 41 | static { 42 | schemes.put(StandardScheme.class, new TSCloseSessionRespStandardSchemeFactory()); 43 | schemes.put(TupleScheme.class, new TSCloseSessionRespTupleSchemeFactory()); 44 | } 45 | 46 | public TS_Status status; // required 47 | 48 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 49 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 50 | STATUS((short)1, "status"); 51 | 52 | private static final Map byName = new HashMap(); 53 | 54 | static { 55 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 56 | byName.put(field.getFieldName(), field); 57 | } 58 | } 59 | 60 | /** 61 | * Find the _Fields constant that matches fieldId, or null if its not found. 62 | */ 63 | public static _Fields findByThriftId(int fieldId) { 64 | switch(fieldId) { 65 | case 1: // STATUS 66 | return STATUS; 67 | default: 68 | return null; 69 | } 70 | } 71 | 72 | /** 73 | * Find the _Fields constant that matches fieldId, throwing an exception 74 | * if it is not found. 75 | */ 76 | public static _Fields findByThriftIdOrThrow(int fieldId) { 77 | _Fields fields = findByThriftId(fieldId); 78 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 79 | return fields; 80 | } 81 | 82 | /** 83 | * Find the _Fields constant that matches name, or null if its not found. 84 | */ 85 | public static _Fields findByName(String name) { 86 | return byName.get(name); 87 | } 88 | 89 | private final short _thriftId; 90 | private final String _fieldName; 91 | 92 | _Fields(short thriftId, String fieldName) { 93 | _thriftId = thriftId; 94 | _fieldName = fieldName; 95 | } 96 | 97 | public short getThriftFieldId() { 98 | return _thriftId; 99 | } 100 | 101 | public String getFieldName() { 102 | return _fieldName; 103 | } 104 | } 105 | 106 | // isset id assignments 107 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 108 | static { 109 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 110 | tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, 111 | new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TS_Status.class))); 112 | metaDataMap = Collections.unmodifiableMap(tmpMap); 113 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSCloseSessionResp.class, metaDataMap); 114 | } 115 | 116 | public TSCloseSessionResp() { 117 | } 118 | 119 | public TSCloseSessionResp( 120 | TS_Status status) 121 | { 122 | this(); 123 | this.status = status; 124 | } 125 | 126 | /** 127 | * Performs a deep copy on other. 128 | */ 129 | public TSCloseSessionResp(TSCloseSessionResp other) { 130 | if (other.isSetStatus()) { 131 | this.status = new TS_Status(other.status); 132 | } 133 | } 134 | 135 | public TSCloseSessionResp deepCopy() { 136 | return new TSCloseSessionResp(this); 137 | } 138 | 139 | @Override 140 | public void clear() { 141 | this.status = null; 142 | } 143 | 144 | public TS_Status getStatus() { 145 | return this.status; 146 | } 147 | 148 | public TSCloseSessionResp setStatus(TS_Status status) { 149 | this.status = status; 150 | return this; 151 | } 152 | 153 | public void unsetStatus() { 154 | this.status = null; 155 | } 156 | 157 | /** Returns true if field status is set (has been assigned a value) and false otherwise */ 158 | public boolean isSetStatus() { 159 | return this.status != null; 160 | } 161 | 162 | public void setStatusIsSet(boolean value) { 163 | if (!value) { 164 | this.status = null; 165 | } 166 | } 167 | 168 | public void setFieldValue(_Fields field, Object value) { 169 | switch (field) { 170 | case STATUS: 171 | if (value == null) { 172 | unsetStatus(); 173 | } else { 174 | setStatus((TS_Status)value); 175 | } 176 | break; 177 | 178 | } 179 | } 180 | 181 | public Object getFieldValue(_Fields field) { 182 | switch (field) { 183 | case STATUS: 184 | return getStatus(); 185 | 186 | } 187 | throw new IllegalStateException(); 188 | } 189 | 190 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 191 | public boolean isSet(_Fields field) { 192 | if (field == null) { 193 | throw new IllegalArgumentException(); 194 | } 195 | 196 | switch (field) { 197 | case STATUS: 198 | return isSetStatus(); 199 | } 200 | throw new IllegalStateException(); 201 | } 202 | 203 | @Override 204 | public boolean equals(Object that) { 205 | if (that == null) 206 | return false; 207 | if (that instanceof TSCloseSessionResp) 208 | return this.equals((TSCloseSessionResp)that); 209 | return false; 210 | } 211 | 212 | public boolean equals(TSCloseSessionResp that) { 213 | if (that == null) 214 | return false; 215 | 216 | boolean this_present_status = true && this.isSetStatus(); 217 | boolean that_present_status = true && that.isSetStatus(); 218 | if (this_present_status || that_present_status) { 219 | if (!(this_present_status && that_present_status)) 220 | return false; 221 | if (!this.status.equals(that.status)) 222 | return false; 223 | } 224 | 225 | return true; 226 | } 227 | 228 | @Override 229 | public int hashCode() { 230 | return 0; 231 | } 232 | 233 | @Override 234 | public int compareTo(TSCloseSessionResp other) { 235 | if (!getClass().equals(other.getClass())) { 236 | return getClass().getName().compareTo(other.getClass().getName()); 237 | } 238 | 239 | int lastComparison = 0; 240 | 241 | lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus()); 242 | if (lastComparison != 0) { 243 | return lastComparison; 244 | } 245 | if (isSetStatus()) { 246 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status); 247 | if (lastComparison != 0) { 248 | return lastComparison; 249 | } 250 | } 251 | return 0; 252 | } 253 | 254 | public _Fields fieldForId(int fieldId) { 255 | return _Fields.findByThriftId(fieldId); 256 | } 257 | 258 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 259 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 260 | } 261 | 262 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 263 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 264 | } 265 | 266 | @Override 267 | public String toString() { 268 | StringBuilder sb = new StringBuilder("TSCloseSessionResp("); 269 | boolean first = true; 270 | 271 | sb.append("status:"); 272 | if (this.status == null) { 273 | sb.append("null"); 274 | } else { 275 | sb.append(this.status); 276 | } 277 | first = false; 278 | sb.append(")"); 279 | return sb.toString(); 280 | } 281 | 282 | public void validate() throws org.apache.thrift.TException { 283 | // check for required fields 284 | if (status == null) { 285 | throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' was not present! Struct: " + toString()); 286 | } 287 | // check for sub-struct validity 288 | if (status != null) { 289 | status.validate(); 290 | } 291 | } 292 | 293 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 294 | try { 295 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 296 | } catch (org.apache.thrift.TException te) { 297 | throw new java.io.IOException(te); 298 | } 299 | } 300 | 301 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 302 | try { 303 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 304 | } catch (org.apache.thrift.TException te) { 305 | throw new java.io.IOException(te); 306 | } 307 | } 308 | 309 | private static class TSCloseSessionRespStandardSchemeFactory implements SchemeFactory { 310 | public TSCloseSessionRespStandardScheme getScheme() { 311 | return new TSCloseSessionRespStandardScheme(); 312 | } 313 | } 314 | 315 | private static class TSCloseSessionRespStandardScheme extends StandardScheme { 316 | 317 | public void read(org.apache.thrift.protocol.TProtocol iprot, TSCloseSessionResp struct) throws org.apache.thrift.TException { 318 | org.apache.thrift.protocol.TField schemeField; 319 | iprot.readStructBegin(); 320 | while (true) 321 | { 322 | schemeField = iprot.readFieldBegin(); 323 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 324 | break; 325 | } 326 | switch (schemeField.id) { 327 | case 1: // STATUS 328 | if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { 329 | struct.status = new TS_Status(); 330 | struct.status.read(iprot); 331 | struct.setStatusIsSet(true); 332 | } else { 333 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 334 | } 335 | break; 336 | default: 337 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 338 | } 339 | iprot.readFieldEnd(); 340 | } 341 | iprot.readStructEnd(); 342 | 343 | // check for required fields of primitive type, which can't be checked in the validate method 344 | struct.validate(); 345 | } 346 | 347 | public void write(org.apache.thrift.protocol.TProtocol oprot, TSCloseSessionResp struct) throws org.apache.thrift.TException { 348 | struct.validate(); 349 | 350 | oprot.writeStructBegin(STRUCT_DESC); 351 | if (struct.status != null) { 352 | oprot.writeFieldBegin(STATUS_FIELD_DESC); 353 | struct.status.write(oprot); 354 | oprot.writeFieldEnd(); 355 | } 356 | oprot.writeFieldStop(); 357 | oprot.writeStructEnd(); 358 | } 359 | 360 | } 361 | 362 | private static class TSCloseSessionRespTupleSchemeFactory implements SchemeFactory { 363 | public TSCloseSessionRespTupleScheme getScheme() { 364 | return new TSCloseSessionRespTupleScheme(); 365 | } 366 | } 367 | 368 | private static class TSCloseSessionRespTupleScheme extends TupleScheme { 369 | 370 | @Override 371 | public void write(org.apache.thrift.protocol.TProtocol prot, TSCloseSessionResp struct) throws org.apache.thrift.TException { 372 | TTupleProtocol oprot = (TTupleProtocol) prot; 373 | struct.status.write(oprot); 374 | } 375 | 376 | @Override 377 | public void read(org.apache.thrift.protocol.TProtocol prot, TSCloseSessionResp struct) throws org.apache.thrift.TException { 378 | TTupleProtocol iprot = (TTupleProtocol) prot; 379 | struct.status = new TS_Status(); 380 | struct.status.read(iprot); 381 | struct.setStatusIsSet(true); 382 | } 383 | } 384 | 385 | } 386 | 387 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TSProtocolVersion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | 10 | import java.util.Map; 11 | import java.util.HashMap; 12 | import org.apache.thrift.TEnum; 13 | 14 | public enum TSProtocolVersion implements org.apache.thrift.TEnum { 15 | TSFILE_SERVICE_PROTOCOL_V1(0); 16 | 17 | private final int value; 18 | 19 | private TSProtocolVersion(int value) { 20 | this.value = value; 21 | } 22 | 23 | /** 24 | * Get the integer value of this enum value, as defined in the Thrift IDL. 25 | */ 26 | public int getValue() { 27 | return value; 28 | } 29 | 30 | /** 31 | * Find a the enum type by its integer value, as defined in the Thrift IDL. 32 | * @return null if the value is not found. 33 | */ 34 | public static TSProtocolVersion findByValue(int value) { 35 | switch (value) { 36 | case 0: 37 | return TSFILE_SERVICE_PROTOCOL_V1; 38 | default: 39 | return null; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TSSetTimeZoneReq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | public class TSSetTimeZoneReq implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 36 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSSetTimeZoneReq"); 37 | 38 | private static final org.apache.thrift.protocol.TField TIME_ZONE_FIELD_DESC = new org.apache.thrift.protocol.TField("timeZone", org.apache.thrift.protocol.TType.STRING, (short)1); 39 | 40 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 41 | static { 42 | schemes.put(StandardScheme.class, new TSSetTimeZoneReqStandardSchemeFactory()); 43 | schemes.put(TupleScheme.class, new TSSetTimeZoneReqTupleSchemeFactory()); 44 | } 45 | 46 | public String timeZone; // required 47 | 48 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 49 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 50 | TIME_ZONE((short)1, "timeZone"); 51 | 52 | private static final Map byName = new HashMap(); 53 | 54 | static { 55 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 56 | byName.put(field.getFieldName(), field); 57 | } 58 | } 59 | 60 | /** 61 | * Find the _Fields constant that matches fieldId, or null if its not found. 62 | */ 63 | public static _Fields findByThriftId(int fieldId) { 64 | switch(fieldId) { 65 | case 1: // TIME_ZONE 66 | return TIME_ZONE; 67 | default: 68 | return null; 69 | } 70 | } 71 | 72 | /** 73 | * Find the _Fields constant that matches fieldId, throwing an exception 74 | * if it is not found. 75 | */ 76 | public static _Fields findByThriftIdOrThrow(int fieldId) { 77 | _Fields fields = findByThriftId(fieldId); 78 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 79 | return fields; 80 | } 81 | 82 | /** 83 | * Find the _Fields constant that matches name, or null if its not found. 84 | */ 85 | public static _Fields findByName(String name) { 86 | return byName.get(name); 87 | } 88 | 89 | private final short _thriftId; 90 | private final String _fieldName; 91 | 92 | _Fields(short thriftId, String fieldName) { 93 | _thriftId = thriftId; 94 | _fieldName = fieldName; 95 | } 96 | 97 | public short getThriftFieldId() { 98 | return _thriftId; 99 | } 100 | 101 | public String getFieldName() { 102 | return _fieldName; 103 | } 104 | } 105 | 106 | // isset id assignments 107 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 108 | static { 109 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 110 | tmpMap.put(_Fields.TIME_ZONE, new org.apache.thrift.meta_data.FieldMetaData("timeZone", org.apache.thrift.TFieldRequirementType.REQUIRED, 111 | new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); 112 | metaDataMap = Collections.unmodifiableMap(tmpMap); 113 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSSetTimeZoneReq.class, metaDataMap); 114 | } 115 | 116 | public TSSetTimeZoneReq() { 117 | } 118 | 119 | public TSSetTimeZoneReq( 120 | String timeZone) 121 | { 122 | this(); 123 | this.timeZone = timeZone; 124 | } 125 | 126 | /** 127 | * Performs a deep copy on other. 128 | */ 129 | public TSSetTimeZoneReq(TSSetTimeZoneReq other) { 130 | if (other.isSetTimeZone()) { 131 | this.timeZone = other.timeZone; 132 | } 133 | } 134 | 135 | public TSSetTimeZoneReq deepCopy() { 136 | return new TSSetTimeZoneReq(this); 137 | } 138 | 139 | @Override 140 | public void clear() { 141 | this.timeZone = null; 142 | } 143 | 144 | public String getTimeZone() { 145 | return this.timeZone; 146 | } 147 | 148 | public TSSetTimeZoneReq setTimeZone(String timeZone) { 149 | this.timeZone = timeZone; 150 | return this; 151 | } 152 | 153 | public void unsetTimeZone() { 154 | this.timeZone = null; 155 | } 156 | 157 | /** Returns true if field timeZone is set (has been assigned a value) and false otherwise */ 158 | public boolean isSetTimeZone() { 159 | return this.timeZone != null; 160 | } 161 | 162 | public void setTimeZoneIsSet(boolean value) { 163 | if (!value) { 164 | this.timeZone = null; 165 | } 166 | } 167 | 168 | public void setFieldValue(_Fields field, Object value) { 169 | switch (field) { 170 | case TIME_ZONE: 171 | if (value == null) { 172 | unsetTimeZone(); 173 | } else { 174 | setTimeZone((String)value); 175 | } 176 | break; 177 | 178 | } 179 | } 180 | 181 | public Object getFieldValue(_Fields field) { 182 | switch (field) { 183 | case TIME_ZONE: 184 | return getTimeZone(); 185 | 186 | } 187 | throw new IllegalStateException(); 188 | } 189 | 190 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 191 | public boolean isSet(_Fields field) { 192 | if (field == null) { 193 | throw new IllegalArgumentException(); 194 | } 195 | 196 | switch (field) { 197 | case TIME_ZONE: 198 | return isSetTimeZone(); 199 | } 200 | throw new IllegalStateException(); 201 | } 202 | 203 | @Override 204 | public boolean equals(Object that) { 205 | if (that == null) 206 | return false; 207 | if (that instanceof TSSetTimeZoneReq) 208 | return this.equals((TSSetTimeZoneReq)that); 209 | return false; 210 | } 211 | 212 | public boolean equals(TSSetTimeZoneReq that) { 213 | if (that == null) 214 | return false; 215 | 216 | boolean this_present_timeZone = true && this.isSetTimeZone(); 217 | boolean that_present_timeZone = true && that.isSetTimeZone(); 218 | if (this_present_timeZone || that_present_timeZone) { 219 | if (!(this_present_timeZone && that_present_timeZone)) 220 | return false; 221 | if (!this.timeZone.equals(that.timeZone)) 222 | return false; 223 | } 224 | 225 | return true; 226 | } 227 | 228 | @Override 229 | public int hashCode() { 230 | return 0; 231 | } 232 | 233 | @Override 234 | public int compareTo(TSSetTimeZoneReq other) { 235 | if (!getClass().equals(other.getClass())) { 236 | return getClass().getName().compareTo(other.getClass().getName()); 237 | } 238 | 239 | int lastComparison = 0; 240 | 241 | lastComparison = Boolean.valueOf(isSetTimeZone()).compareTo(other.isSetTimeZone()); 242 | if (lastComparison != 0) { 243 | return lastComparison; 244 | } 245 | if (isSetTimeZone()) { 246 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.timeZone, other.timeZone); 247 | if (lastComparison != 0) { 248 | return lastComparison; 249 | } 250 | } 251 | return 0; 252 | } 253 | 254 | public _Fields fieldForId(int fieldId) { 255 | return _Fields.findByThriftId(fieldId); 256 | } 257 | 258 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 259 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 260 | } 261 | 262 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 263 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 264 | } 265 | 266 | @Override 267 | public String toString() { 268 | StringBuilder sb = new StringBuilder("TSSetTimeZoneReq("); 269 | boolean first = true; 270 | 271 | sb.append("timeZone:"); 272 | if (this.timeZone == null) { 273 | sb.append("null"); 274 | } else { 275 | sb.append(this.timeZone); 276 | } 277 | first = false; 278 | sb.append(")"); 279 | return sb.toString(); 280 | } 281 | 282 | public void validate() throws org.apache.thrift.TException { 283 | // check for required fields 284 | if (timeZone == null) { 285 | throw new org.apache.thrift.protocol.TProtocolException("Required field 'timeZone' was not present! Struct: " + toString()); 286 | } 287 | // check for sub-struct validity 288 | } 289 | 290 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 291 | try { 292 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 293 | } catch (org.apache.thrift.TException te) { 294 | throw new java.io.IOException(te); 295 | } 296 | } 297 | 298 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 299 | try { 300 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 301 | } catch (org.apache.thrift.TException te) { 302 | throw new java.io.IOException(te); 303 | } 304 | } 305 | 306 | private static class TSSetTimeZoneReqStandardSchemeFactory implements SchemeFactory { 307 | public TSSetTimeZoneReqStandardScheme getScheme() { 308 | return new TSSetTimeZoneReqStandardScheme(); 309 | } 310 | } 311 | 312 | private static class TSSetTimeZoneReqStandardScheme extends StandardScheme { 313 | 314 | public void read(org.apache.thrift.protocol.TProtocol iprot, TSSetTimeZoneReq struct) throws org.apache.thrift.TException { 315 | org.apache.thrift.protocol.TField schemeField; 316 | iprot.readStructBegin(); 317 | while (true) 318 | { 319 | schemeField = iprot.readFieldBegin(); 320 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 321 | break; 322 | } 323 | switch (schemeField.id) { 324 | case 1: // TIME_ZONE 325 | if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { 326 | struct.timeZone = iprot.readString(); 327 | struct.setTimeZoneIsSet(true); 328 | } else { 329 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 330 | } 331 | break; 332 | default: 333 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 334 | } 335 | iprot.readFieldEnd(); 336 | } 337 | iprot.readStructEnd(); 338 | 339 | // check for required fields of primitive type, which can't be checked in the validate method 340 | struct.validate(); 341 | } 342 | 343 | public void write(org.apache.thrift.protocol.TProtocol oprot, TSSetTimeZoneReq struct) throws org.apache.thrift.TException { 344 | struct.validate(); 345 | 346 | oprot.writeStructBegin(STRUCT_DESC); 347 | if (struct.timeZone != null) { 348 | oprot.writeFieldBegin(TIME_ZONE_FIELD_DESC); 349 | oprot.writeString(struct.timeZone); 350 | oprot.writeFieldEnd(); 351 | } 352 | oprot.writeFieldStop(); 353 | oprot.writeStructEnd(); 354 | } 355 | 356 | } 357 | 358 | private static class TSSetTimeZoneReqTupleSchemeFactory implements SchemeFactory { 359 | public TSSetTimeZoneReqTupleScheme getScheme() { 360 | return new TSSetTimeZoneReqTupleScheme(); 361 | } 362 | } 363 | 364 | private static class TSSetTimeZoneReqTupleScheme extends TupleScheme { 365 | 366 | @Override 367 | public void write(org.apache.thrift.protocol.TProtocol prot, TSSetTimeZoneReq struct) throws org.apache.thrift.TException { 368 | TTupleProtocol oprot = (TTupleProtocol) prot; 369 | oprot.writeString(struct.timeZone); 370 | } 371 | 372 | @Override 373 | public void read(org.apache.thrift.protocol.TProtocol prot, TSSetTimeZoneReq struct) throws org.apache.thrift.TException { 374 | TTupleProtocol iprot = (TTupleProtocol) prot; 375 | struct.timeZone = iprot.readString(); 376 | struct.setTimeZoneIsSet(true); 377 | } 378 | } 379 | 380 | } 381 | 382 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TSSetTimeZoneResp.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | public class TSSetTimeZoneResp implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 36 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSSetTimeZoneResp"); 37 | 38 | private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.STRUCT, (short)1); 39 | 40 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 41 | static { 42 | schemes.put(StandardScheme.class, new TSSetTimeZoneRespStandardSchemeFactory()); 43 | schemes.put(TupleScheme.class, new TSSetTimeZoneRespTupleSchemeFactory()); 44 | } 45 | 46 | public TS_Status status; // required 47 | 48 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 49 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 50 | STATUS((short)1, "status"); 51 | 52 | private static final Map byName = new HashMap(); 53 | 54 | static { 55 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 56 | byName.put(field.getFieldName(), field); 57 | } 58 | } 59 | 60 | /** 61 | * Find the _Fields constant that matches fieldId, or null if its not found. 62 | */ 63 | public static _Fields findByThriftId(int fieldId) { 64 | switch(fieldId) { 65 | case 1: // STATUS 66 | return STATUS; 67 | default: 68 | return null; 69 | } 70 | } 71 | 72 | /** 73 | * Find the _Fields constant that matches fieldId, throwing an exception 74 | * if it is not found. 75 | */ 76 | public static _Fields findByThriftIdOrThrow(int fieldId) { 77 | _Fields fields = findByThriftId(fieldId); 78 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 79 | return fields; 80 | } 81 | 82 | /** 83 | * Find the _Fields constant that matches name, or null if its not found. 84 | */ 85 | public static _Fields findByName(String name) { 86 | return byName.get(name); 87 | } 88 | 89 | private final short _thriftId; 90 | private final String _fieldName; 91 | 92 | _Fields(short thriftId, String fieldName) { 93 | _thriftId = thriftId; 94 | _fieldName = fieldName; 95 | } 96 | 97 | public short getThriftFieldId() { 98 | return _thriftId; 99 | } 100 | 101 | public String getFieldName() { 102 | return _fieldName; 103 | } 104 | } 105 | 106 | // isset id assignments 107 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 108 | static { 109 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 110 | tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, 111 | new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TS_Status.class))); 112 | metaDataMap = Collections.unmodifiableMap(tmpMap); 113 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSSetTimeZoneResp.class, metaDataMap); 114 | } 115 | 116 | public TSSetTimeZoneResp() { 117 | } 118 | 119 | public TSSetTimeZoneResp( 120 | TS_Status status) 121 | { 122 | this(); 123 | this.status = status; 124 | } 125 | 126 | /** 127 | * Performs a deep copy on other. 128 | */ 129 | public TSSetTimeZoneResp(TSSetTimeZoneResp other) { 130 | if (other.isSetStatus()) { 131 | this.status = new TS_Status(other.status); 132 | } 133 | } 134 | 135 | public TSSetTimeZoneResp deepCopy() { 136 | return new TSSetTimeZoneResp(this); 137 | } 138 | 139 | @Override 140 | public void clear() { 141 | this.status = null; 142 | } 143 | 144 | public TS_Status getStatus() { 145 | return this.status; 146 | } 147 | 148 | public TSSetTimeZoneResp setStatus(TS_Status status) { 149 | this.status = status; 150 | return this; 151 | } 152 | 153 | public void unsetStatus() { 154 | this.status = null; 155 | } 156 | 157 | /** Returns true if field status is set (has been assigned a value) and false otherwise */ 158 | public boolean isSetStatus() { 159 | return this.status != null; 160 | } 161 | 162 | public void setStatusIsSet(boolean value) { 163 | if (!value) { 164 | this.status = null; 165 | } 166 | } 167 | 168 | public void setFieldValue(_Fields field, Object value) { 169 | switch (field) { 170 | case STATUS: 171 | if (value == null) { 172 | unsetStatus(); 173 | } else { 174 | setStatus((TS_Status)value); 175 | } 176 | break; 177 | 178 | } 179 | } 180 | 181 | public Object getFieldValue(_Fields field) { 182 | switch (field) { 183 | case STATUS: 184 | return getStatus(); 185 | 186 | } 187 | throw new IllegalStateException(); 188 | } 189 | 190 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 191 | public boolean isSet(_Fields field) { 192 | if (field == null) { 193 | throw new IllegalArgumentException(); 194 | } 195 | 196 | switch (field) { 197 | case STATUS: 198 | return isSetStatus(); 199 | } 200 | throw new IllegalStateException(); 201 | } 202 | 203 | @Override 204 | public boolean equals(Object that) { 205 | if (that == null) 206 | return false; 207 | if (that instanceof TSSetTimeZoneResp) 208 | return this.equals((TSSetTimeZoneResp)that); 209 | return false; 210 | } 211 | 212 | public boolean equals(TSSetTimeZoneResp that) { 213 | if (that == null) 214 | return false; 215 | 216 | boolean this_present_status = true && this.isSetStatus(); 217 | boolean that_present_status = true && that.isSetStatus(); 218 | if (this_present_status || that_present_status) { 219 | if (!(this_present_status && that_present_status)) 220 | return false; 221 | if (!this.status.equals(that.status)) 222 | return false; 223 | } 224 | 225 | return true; 226 | } 227 | 228 | @Override 229 | public int hashCode() { 230 | return 0; 231 | } 232 | 233 | @Override 234 | public int compareTo(TSSetTimeZoneResp other) { 235 | if (!getClass().equals(other.getClass())) { 236 | return getClass().getName().compareTo(other.getClass().getName()); 237 | } 238 | 239 | int lastComparison = 0; 240 | 241 | lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus()); 242 | if (lastComparison != 0) { 243 | return lastComparison; 244 | } 245 | if (isSetStatus()) { 246 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status); 247 | if (lastComparison != 0) { 248 | return lastComparison; 249 | } 250 | } 251 | return 0; 252 | } 253 | 254 | public _Fields fieldForId(int fieldId) { 255 | return _Fields.findByThriftId(fieldId); 256 | } 257 | 258 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 259 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 260 | } 261 | 262 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 263 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 264 | } 265 | 266 | @Override 267 | public String toString() { 268 | StringBuilder sb = new StringBuilder("TSSetTimeZoneResp("); 269 | boolean first = true; 270 | 271 | sb.append("status:"); 272 | if (this.status == null) { 273 | sb.append("null"); 274 | } else { 275 | sb.append(this.status); 276 | } 277 | first = false; 278 | sb.append(")"); 279 | return sb.toString(); 280 | } 281 | 282 | public void validate() throws org.apache.thrift.TException { 283 | // check for required fields 284 | if (status == null) { 285 | throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' was not present! Struct: " + toString()); 286 | } 287 | // check for sub-struct validity 288 | if (status != null) { 289 | status.validate(); 290 | } 291 | } 292 | 293 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 294 | try { 295 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 296 | } catch (org.apache.thrift.TException te) { 297 | throw new java.io.IOException(te); 298 | } 299 | } 300 | 301 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 302 | try { 303 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 304 | } catch (org.apache.thrift.TException te) { 305 | throw new java.io.IOException(te); 306 | } 307 | } 308 | 309 | private static class TSSetTimeZoneRespStandardSchemeFactory implements SchemeFactory { 310 | public TSSetTimeZoneRespStandardScheme getScheme() { 311 | return new TSSetTimeZoneRespStandardScheme(); 312 | } 313 | } 314 | 315 | private static class TSSetTimeZoneRespStandardScheme extends StandardScheme { 316 | 317 | public void read(org.apache.thrift.protocol.TProtocol iprot, TSSetTimeZoneResp struct) throws org.apache.thrift.TException { 318 | org.apache.thrift.protocol.TField schemeField; 319 | iprot.readStructBegin(); 320 | while (true) 321 | { 322 | schemeField = iprot.readFieldBegin(); 323 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 324 | break; 325 | } 326 | switch (schemeField.id) { 327 | case 1: // STATUS 328 | if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { 329 | struct.status = new TS_Status(); 330 | struct.status.read(iprot); 331 | struct.setStatusIsSet(true); 332 | } else { 333 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 334 | } 335 | break; 336 | default: 337 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 338 | } 339 | iprot.readFieldEnd(); 340 | } 341 | iprot.readStructEnd(); 342 | 343 | // check for required fields of primitive type, which can't be checked in the validate method 344 | struct.validate(); 345 | } 346 | 347 | public void write(org.apache.thrift.protocol.TProtocol oprot, TSSetTimeZoneResp struct) throws org.apache.thrift.TException { 348 | struct.validate(); 349 | 350 | oprot.writeStructBegin(STRUCT_DESC); 351 | if (struct.status != null) { 352 | oprot.writeFieldBegin(STATUS_FIELD_DESC); 353 | struct.status.write(oprot); 354 | oprot.writeFieldEnd(); 355 | } 356 | oprot.writeFieldStop(); 357 | oprot.writeStructEnd(); 358 | } 359 | 360 | } 361 | 362 | private static class TSSetTimeZoneRespTupleSchemeFactory implements SchemeFactory { 363 | public TSSetTimeZoneRespTupleScheme getScheme() { 364 | return new TSSetTimeZoneRespTupleScheme(); 365 | } 366 | } 367 | 368 | private static class TSSetTimeZoneRespTupleScheme extends TupleScheme { 369 | 370 | @Override 371 | public void write(org.apache.thrift.protocol.TProtocol prot, TSSetTimeZoneResp struct) throws org.apache.thrift.TException { 372 | TTupleProtocol oprot = (TTupleProtocol) prot; 373 | struct.status.write(oprot); 374 | } 375 | 376 | @Override 377 | public void read(org.apache.thrift.protocol.TProtocol prot, TSSetTimeZoneResp struct) throws org.apache.thrift.TException { 378 | TTupleProtocol iprot = (TTupleProtocol) prot; 379 | struct.status = new TS_Status(); 380 | struct.status.read(iprot); 381 | struct.setStatusIsSet(true); 382 | } 383 | } 384 | 385 | } 386 | 387 | -------------------------------------------------------------------------------- /interface/thrift/cn/edu/tsinghua/iotdb/jdbc/thrift/TS_StatusCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package cn.edu.tsinghua.iotdb.jdbc.thrift; 8 | 9 | 10 | import java.util.Map; 11 | import java.util.HashMap; 12 | import org.apache.thrift.TEnum; 13 | 14 | public enum TS_StatusCode implements org.apache.thrift.TEnum { 15 | SUCCESS_STATUS(0), 16 | SUCCESS_WITH_INFO_STATUS(1), 17 | STILL_EXECUTING_STATUS(2), 18 | ERROR_STATUS(3), 19 | INVALID_HANDLE_STATUS(4); 20 | 21 | private final int value; 22 | 23 | private TS_StatusCode(int value) { 24 | this.value = value; 25 | } 26 | 27 | /** 28 | * Get the integer value of this enum value, as defined in the Thrift IDL. 29 | */ 30 | public int getValue() { 31 | return value; 32 | } 33 | 34 | /** 35 | * Find a the enum type by its integer value, as defined in the Thrift IDL. 36 | * @return null if the value is not found. 37 | */ 38 | public static TS_StatusCode findByValue(int value) { 39 | switch (value) { 40 | case 0: 41 | return SUCCESS_STATUS; 42 | case 1: 43 | return SUCCESS_WITH_INFO_STATUS; 44 | case 2: 45 | return STILL_EXECUTING_STATUS; 46 | case 3: 47 | return ERROR_STATUS; 48 | case 4: 49 | return INVALID_HANDLE_STATUS; 50 | default: 51 | return null; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "Package iotdb-jdbc..." 3 | mvn clean package -Dmaven.test.skip=true 4 | 5 | if [ -d "./lib/" ]; then 6 | rm -r ./lib/ 7 | fi 8 | mkdir ./lib/ 9 | 10 | echo "Copy denpendency jars to ./lib" 11 | cp ./target/lib/*.jar ./lib/ 12 | 13 | file_name=`find ./target -name "iotdb-jdbc-?.?.?.jar"` 14 | version=${file_name#*iotdb-jdbc-} 15 | version=${version%.jar} 16 | # 拷贝到lib目录下 17 | echo "Copy latest iotdb-jdbc-jar to ./lib. version is : $version" 18 | cp ./target/iotdb-jdbc-$version.jar ./lib/ 19 | 20 | echo "Zip all jars..." 21 | # 压缩成一个zip 22 | cd ./lib 23 | zip iotdb-jdbc-$version.zip ./* 24 | echo "Done. see ./lib/iotdb-jdbc-$version.zip" 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | cn.edu.tsinghua 5 | iotdb-jdbc 6 | 0.7.1-SNAPSHOT 7 | jar 8 | 9 | IoTDB Jdbc 10 | A jdbc driver for a time series database, IoTDB, which uses TsFile as its storage format on disk. 11 | https://github.com/thulab/iotdb-jdbc 12 | 13 | 14 | 15 | The Apache License, Version 2.0 16 | http://www.apache.org/licenses/LICENSE-2.0.txt 17 | 18 | 19 | 20 | 21 | 22 | Jianmin Wang 23 | jimwang@tsinghua.edu.cn 24 | School of Software, Tsinghua University 25 | http://thss.tsinghua.edu.cn/publish/soften/index.html 26 | 27 | 28 | Chen Wang 29 | wang_chen@tsinghua.edu.cn 30 | School of Software, Tsinghua University 31 | http://thss.tsinghua.edu.cn/publish/soften/index.html 32 | 33 | 34 | Xiangdong Huang 35 | 36 | 37 | Rong Kang 38 | 39 | 40 | Jinrui Zhang 41 | 42 | 43 | Jialin Qiao 44 | 45 | 46 | Yi Xu 47 | 48 | 49 | Gaofei Cao 50 | 51 | 52 | Kun Liu 53 | 54 | 55 | 56 | 57 | scm:git:https://github.com/thulab/iotdb-jdbc.git 58 | scm:git:https://github.com/thulab/iotdb-jdbc.git 59 | https://github.com/thulab/iotdb-jdbc 60 | 61 | 62 | 63 | 64 | ossrh 65 | https://oss.sonatype.org/content/repositories/snapshots 66 | 67 | 68 | ossrh 69 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 70 | 71 | 72 | 73 | 74 | 1.8 75 | 1.8 76 | 1.8 77 | ${targetJavaVersion} 78 | UTF-8 79 | 4.12 80 | 1.7.12 81 | 1.1.3 82 | 2.9.9 83 | false 84 | false 85 | 86 | 87 | 88 | 89 | cn.edu.tsinghua 90 | tsfile 91 | 0.7.1 92 | 93 | 94 | junit 95 | junit 96 | ${junit.version} 97 | test 98 | 99 | 100 | joda-time 101 | joda-time 102 | ${joda.version} 103 | 104 | 105 | org.mockito 106 | mockito-all 107 | 1.10.19 108 | test 109 | 110 | 111 | 112 | 113 | 114 | 115 | org.apache.thrift.tools 116 | maven-thrift-plugin 117 | 0.1.11 118 | 119 | 120 | thrift-sources 121 | generate-sources 122 | 123 | compile 124 | 125 | 126 | 127 | 128 | 129 | org.codehaus.mojo 130 | build-helper-maven-plugin 131 | 3.0.0 132 | 133 | 134 | generate-sources 135 | 136 | add-source 137 | 138 | 139 | 140 | interface/thrift 141 | 142 | 143 | 144 | 145 | 146 | 147 | org.apache.maven.plugins 148 | maven-compiler-plugin 149 | 3.3 150 | 151 | ${compile.version} 152 | ${compile.version} 153 | UTF-8 154 | 155 | 156 | 157 | org.apache.maven.plugins 158 | maven-dependency-plugin 159 | 2.10 160 | 161 | 162 | copy-dependencies 163 | package 164 | 165 | copy-dependencies 166 | 167 | 168 | ${project.build.directory}/lib 169 | 170 | 171 | 172 | 173 | 174 | org.apache.maven.plugins 175 | maven-assembly-plugin 176 | 2.5.5 177 | 178 | 179 | 180 | 181 | jar-with-dependencies 182 | 183 | 184 | make-assembly 185 | package 186 | 187 | single 188 | 189 | 190 | 191 | 192 | 193 | org.codehaus.mojo 194 | cobertura-maven-plugin 195 | 2.7 196 | 197 | 198 | html 199 | xml 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | thrift 210 | 211 | 212 | 213 | org.apache.thrift.tools 214 | maven-thrift-plugin 215 | 0.1.11 216 | 217 | ${basedir}/interface 218 | 219 | 220 | 221 | thrift-sources 222 | generate-sources 223 | 224 | compile 225 | 226 | 227 | java 228 | interface/thrift 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | release 238 | 239 | 240 | 241 | org.sonatype.plugins 242 | nexus-staging-maven-plugin 243 | 1.6.7 244 | true 245 | 246 | ossrh 247 | https://oss.sonatype.org/ 248 | true 249 | 250 | 251 | 252 | org.apache.maven.plugins 253 | maven-compiler-plugin 254 | 3.6.1 255 | 256 | 1.8 257 | 1.8 258 | 259 | 260 | 261 | org.apache.maven.plugins 262 | maven-source-plugin 263 | 2.2.1 264 | 265 | 266 | attach-sources 267 | 268 | jar-no-fork 269 | 270 | 271 | 272 | 273 | 274 | org.apache.maven.plugins 275 | maven-javadoc-plugin 276 | 2.9.1 277 | 278 | *thrift* 279 | 280 | 281 | 282 | attach-javadocs 283 | 284 | jar 285 | 286 | 287 | 288 | 289 | 290 | org.apache.maven.plugins 291 | maven-gpg-plugin 292 | 1.5 293 | 294 | 295 | sign-artifacts 296 | verify 297 | 298 | sign 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | only-eclipse 308 | 309 | 310 | m2e.version 311 | 312 | 313 | 314 | 315 | 316 | 317 | org.eclipse.m2e 318 | lifecycle-mapping 319 | 1.0.0 320 | 321 | 322 | 323 | 324 | 325 | org.apache.maven.plugins 326 | maven-dependency-plugin 327 | ${maven-dependency-plugin.version} 328 | 329 | copy-dependencies 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | org.apache.thrift.tools 340 | 341 | 342 | maven-thrift-plugin 343 | 344 | 345 | [0.1.10,) 346 | 347 | 348 | compile 349 | 350 | 351 | 352 | 353 | false 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsFileDBConstant.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | public class TsFileDBConstant { 4 | 5 | public static final String GLOBAL_DB_NAME = "IoTDB"; 6 | 7 | public static final String GLOBAL_DB_VERSION = "0.7.1"; 8 | 9 | public static final String GLOBAL_COLUMN_REQ = "COLUMN"; 10 | 11 | public static final String GLOBAL_DELTA_OBJECT_REQ = "DELTA_OBEJECT"; 12 | 13 | public static final String GLOBAL_SHOW_TIMESERIES_REQ = "SHOW_TIMESERIES"; 14 | 15 | public static final String GLOBAL_SHOW_STORAGE_GROUP_REQ = "SHOW_STORAGE_GROUP"; 16 | 17 | public static final String GLOBAL_COLUMNS_REQ = "ALL_COLUMNS"; 18 | 19 | // catalog parameters used for DatabaseMetaData.getColumns() 20 | public static final String CatalogColumn = "col"; 21 | public static final String CatalogTimeseries = "ts"; 22 | public static final String CatalogStorageGroup = "sg"; 23 | public static final String CatalogDeltaObject = "delta"; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnectionParams.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | public class TsfileConnectionParams { 4 | private String host = TsfileJDBCConfig.TSFILE_DEFAULT_HOST; 5 | private int port = TsfileJDBCConfig.TSFILE_DEFAULT_PORT; 6 | private String jdbcUriString; 7 | private String seriesName = TsfileJDBCConfig.DEFAULT_SERIES_NAME; 8 | private String username = TsfileJDBCConfig.DEFAULT_USER; 9 | private String password = TsfileJDBCConfig.DEFALUT_PASSWORD; 10 | 11 | public TsfileConnectionParams(String url){ 12 | this.jdbcUriString = url; 13 | } 14 | 15 | public String getHost() { 16 | return host; 17 | } 18 | public void setHost(String host) { 19 | this.host = host; 20 | } 21 | public int getPort() { 22 | return port; 23 | } 24 | public void setPort(int port) { 25 | this.port = port; 26 | } 27 | public String getJdbcUriString() { 28 | return jdbcUriString; 29 | } 30 | public void setJdbcUriString(String jdbcUriString) { 31 | this.jdbcUriString = jdbcUriString; 32 | } 33 | public String getSeriesName() { 34 | return seriesName; 35 | } 36 | public void setSeriesName(String seriesName) { 37 | this.seriesName = seriesName; 38 | } 39 | public String getUsername() { 40 | return username; 41 | } 42 | public void setUsername(String username) { 43 | this.username = username; 44 | } 45 | public String getPassword() { 46 | return password; 47 | } 48 | public void setPassword(String password) { 49 | this.password = password; 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileDriver.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import org.apache.thrift.transport.TTransportException; 4 | 5 | import java.sql.Connection; 6 | import java.sql.Driver; 7 | import java.sql.DriverManager; 8 | import java.sql.DriverPropertyInfo; 9 | import java.sql.SQLException; 10 | import java.sql.SQLFeatureNotSupportedException; 11 | import java.util.Properties; 12 | import java.util.logging.Logger; 13 | import java.util.regex.Pattern; 14 | 15 | 16 | public class TsfileDriver implements Driver { 17 | private final String TSFILE_URL_PREFIX = TsfileJDBCConfig.TSFILE_URL_PREFIX+".*"; 18 | 19 | private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(TsfileDriver.class); 20 | 21 | static { 22 | try { 23 | DriverManager.registerDriver(new TsfileDriver()); 24 | } catch (SQLException e) { 25 | LOGGER.error("Error occurs when registering TsFile driver",e); 26 | } 27 | } 28 | 29 | /** 30 | * Is this driver JDBC compliant? 31 | */ 32 | private static final boolean TSFILE_JDBC_COMPLIANT = false; 33 | 34 | public TsfileDriver() { 35 | 36 | } 37 | 38 | @Override 39 | public boolean acceptsURL(String url) throws SQLException { 40 | return Pattern.matches(TSFILE_URL_PREFIX, url); 41 | } 42 | 43 | @Override 44 | public Connection connect(String url, Properties info) throws SQLException { 45 | try { 46 | return acceptsURL(url) ? new TsfileConnection(url, info) : null; 47 | } catch (TTransportException e) { 48 | throw new SQLException("Connection Error, please check whether the network is avaliable or the server has started."); 49 | } 50 | } 51 | 52 | @Override 53 | public int getMajorVersion() { 54 | // TODO Auto-generated method stub 55 | return 0; 56 | } 57 | 58 | @Override 59 | public int getMinorVersion() { 60 | // TODO Auto-generated method stub 61 | return 0; 62 | } 63 | 64 | @Override 65 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 66 | throw new SQLFeatureNotSupportedException("Method not supported"); 67 | } 68 | 69 | @Override 70 | public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { 71 | // TODO Auto-generated method stub 72 | return null; 73 | } 74 | 75 | @Override 76 | public boolean jdbcCompliant() { 77 | return TSFILE_JDBC_COMPLIANT; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileJDBCConfig.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | public class TsfileJDBCConfig { 4 | /** 5 | * The required prefix for the connection URL. 6 | */ 7 | public static final String TSFILE_URL_PREFIX = "jdbc:tsfile://"; 8 | 9 | public static final String TSFILE_DEFAULT_HOST = "localhost"; 10 | /** 11 | * If host is provided, without a port. 12 | */ 13 | public static final int TSFILE_DEFAULT_PORT = 6667; 14 | 15 | /** 16 | * tsfile's default series name 17 | */ 18 | public static final String DEFAULT_SERIES_NAME = "default"; 19 | 20 | public static final String AUTH_USER = "user"; 21 | public static final String DEFAULT_USER = "user"; 22 | 23 | public static final String AUTH_PASSWORD = "password"; 24 | public static final String DEFALUT_PASSWORD = "password"; 25 | 26 | public static final int RETRY_NUM = 3; 27 | public static final long RETRY_INTERVAL = 1000; 28 | 29 | public static int fetchSize = 10000; 30 | public static int connectionTimeoutInMs = 0; 31 | 32 | public static String JDBC_DRIVER_NAME = "cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileMetadataResultMetadata.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import java.sql.ResultSetMetaData; 4 | import java.sql.SQLException; 5 | import java.sql.Types; 6 | 7 | /* 8 | TsfileMetadataResultMetadata implements a similar api like TsfileQueryResultSet to display column metadata. 9 | */ 10 | 11 | public class TsfileMetadataResultMetadata implements ResultSetMetaData { 12 | private String[] showLabels; 13 | 14 | public TsfileMetadataResultMetadata(String[] showLabels) { 15 | this.showLabels = showLabels; 16 | } 17 | 18 | @Override 19 | public boolean isWrapperFor(Class arg0) throws SQLException { 20 | // TODO Auto-generated method stub 21 | return false; 22 | } 23 | 24 | @Override 25 | public T unwrap(Class arg0) throws SQLException { 26 | // TODO Auto-generated method stub 27 | return null; 28 | } 29 | 30 | @Override 31 | public String getCatalogName(int arg0) throws SQLException { 32 | // TODO Auto-generated method stub 33 | return null; 34 | } 35 | 36 | @Override 37 | public String getColumnClassName(int arg0) throws SQLException { 38 | // TODO Auto-generated method stub 39 | return null; 40 | } 41 | 42 | @Override 43 | public int getColumnCount() throws SQLException { 44 | if (showLabels == null || showLabels.length == 0) { 45 | throw new SQLException("No column exists"); 46 | } 47 | return showLabels.length; 48 | } 49 | 50 | @Override 51 | public int getColumnDisplaySize(int arg0) throws SQLException { 52 | // TODO Auto-generated method stub 53 | return 0; 54 | } 55 | 56 | private void checkColumnIndex(int column) throws SQLException { 57 | if (showLabels == null || showLabels.length == 0) { 58 | throw new SQLException("No column exists"); 59 | } 60 | if (column > showLabels.length) { 61 | throw new SQLException(String.format("column %d does not exist", column)); 62 | } 63 | if (column <= 0) { 64 | throw new SQLException("column index should start from 1"); 65 | } 66 | } 67 | 68 | @Override 69 | public String getColumnLabel(int column) throws SQLException { 70 | checkColumnIndex(column); 71 | return showLabels[column - 1]; 72 | } 73 | 74 | @Override 75 | public String getColumnName(int column) throws SQLException { 76 | return getColumnLabel(column); 77 | } 78 | 79 | @Override 80 | public int getColumnType(int column) throws SQLException { 81 | // TODO Auto-generated method stub 82 | checkColumnIndex(column); 83 | 84 | // TEXT 85 | return Types.VARCHAR; 86 | } 87 | 88 | @Override 89 | public String getColumnTypeName(int arg0) throws SQLException { 90 | // TODO Auto-generated method stub 91 | return null; 92 | } 93 | 94 | @Override 95 | public int getPrecision(int arg0) throws SQLException { 96 | // TODO Auto-generated method stub 97 | return 0; 98 | } 99 | 100 | @Override 101 | public int getScale(int arg0) throws SQLException { 102 | // TODO Auto-generated method stub 103 | return 0; 104 | } 105 | 106 | @Override 107 | public String getSchemaName(int arg0) throws SQLException { 108 | // TODO Auto-generated method stub 109 | return null; 110 | } 111 | 112 | @Override 113 | public String getTableName(int arg0) throws SQLException { 114 | // TODO Auto-generated method stub 115 | return null; 116 | } 117 | 118 | @Override 119 | public boolean isAutoIncrement(int arg0) throws SQLException { 120 | // TODO Auto-generated method stub 121 | return false; 122 | } 123 | 124 | @Override 125 | public boolean isCaseSensitive(int arg0) throws SQLException { 126 | // TODO Auto-generated method stub 127 | return false; 128 | } 129 | 130 | @Override 131 | public boolean isCurrency(int arg0) throws SQLException { 132 | // TODO Auto-generated method stub 133 | return false; 134 | } 135 | 136 | @Override 137 | public boolean isDefinitelyWritable(int arg0) throws SQLException { 138 | // TODO Auto-generated method stub 139 | return false; 140 | } 141 | 142 | @Override 143 | public int isNullable(int arg0) throws SQLException { 144 | // TODO Auto-generated method stub 145 | return 0; 146 | } 147 | 148 | @Override 149 | public boolean isReadOnly(int arg0) throws SQLException { 150 | // TODO Auto-generated method stub 151 | return false; 152 | } 153 | 154 | @Override 155 | public boolean isSearchable(int arg0) throws SQLException { 156 | // TODO Auto-generated method stub 157 | return false; 158 | } 159 | 160 | @Override 161 | public boolean isSigned(int arg0) throws SQLException { 162 | // TODO Auto-generated method stub 163 | return false; 164 | } 165 | 166 | @Override 167 | public boolean isWritable(int arg0) throws SQLException { 168 | // TODO Auto-generated method stub 169 | return false; 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileMetadataResultSet.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import java.math.BigDecimal; 4 | import java.sql.Date; 5 | import java.sql.ResultSetMetaData; 6 | import java.sql.SQLException; 7 | import java.sql.SQLWarning; 8 | import java.sql.Statement; 9 | import java.sql.Time; 10 | import java.util.Iterator; 11 | import java.util.List; 12 | import java.util.Set; 13 | 14 | 15 | public class TsfileMetadataResultSet extends TsfileQueryResultSet { 16 | 17 | private Iterator columnItr; 18 | 19 | private MetadataType type; 20 | 21 | private String currentColumn; 22 | public static final String GET_STRING_COLUMN = "COLUMN"; 23 | 24 | private String currentStorageGroup; 25 | public static final String GET_STRING_STORAGE_GROUP = "STORAGE_GROUP"; 26 | 27 | private List currentTimeseries; 28 | public static final String GET_STRING_TIMESERIES_NAME = "Timeseries"; 29 | public static final String GET_STRING_TIMESERIES_STORAGE_GROUP = "Storage Group"; 30 | public static final String GET_STRING_TIMESERIES_DATATYPE = "DataType"; 31 | public static final String GET_STRING_TIMESERIES_ENCODING = "Encoding"; 32 | 33 | // for display 34 | private int colCount; // the number of columns for show 35 | private String[] showLabels; // headers for show 36 | 37 | /** 38 | * Constructor used for the result of DatabaseMetadata.getColumns() 39 | */ 40 | public TsfileMetadataResultSet(List columns, Set storageGroupSet, 41 | List> showTimeseriesList) throws SQLException { 42 | if (columns != null) { 43 | type = MetadataType.COLUMN; 44 | colCount = 1; 45 | showLabels = new String[]{"Column"}; 46 | columnItr = columns.iterator(); 47 | } else if (storageGroupSet != null) { 48 | type = MetadataType.STORAGE_GROUP; 49 | colCount = 1; 50 | showLabels = new String[]{"Storage Group"}; 51 | columnItr = storageGroupSet.iterator(); 52 | } else if (showTimeseriesList != null) { 53 | type = MetadataType.TIMESERIES; 54 | colCount = 4; 55 | showLabels = new String[]{GET_STRING_TIMESERIES_NAME, GET_STRING_TIMESERIES_STORAGE_GROUP, 56 | GET_STRING_TIMESERIES_DATATYPE, GET_STRING_TIMESERIES_ENCODING}; 57 | columnItr = showTimeseriesList.iterator(); 58 | } else { 59 | throw new SQLException("TsfileMetadataResultSet constructor is wrongly used."); 60 | } 61 | } 62 | 63 | @Override 64 | public void close() throws SQLException { 65 | throw new SQLException("Method not supported"); 66 | } 67 | 68 | @Override 69 | public int findColumn(String columnName) throws SQLException { 70 | throw new SQLException("Method not supported"); 71 | } 72 | 73 | @Override 74 | public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 75 | throw new SQLException("Method not supported"); 76 | } 77 | 78 | @Override 79 | public BigDecimal getBigDecimal(String columnName) throws SQLException { 80 | throw new SQLException("Method not supported"); 81 | } 82 | 83 | @Override 84 | public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { 85 | throw new SQLException("Method not supported"); 86 | } 87 | 88 | @Override 89 | public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { 90 | throw new SQLException("Method not supported"); 91 | } 92 | 93 | @Override 94 | public boolean getBoolean(int columnIndex) throws SQLException { 95 | throw new SQLException("Method not supported"); 96 | } 97 | 98 | @Override 99 | public boolean getBoolean(String columnName) throws SQLException { 100 | throw new SQLException("Method not supported"); 101 | } 102 | 103 | @Override 104 | public byte getByte(int columnIndex) throws SQLException { 105 | throw new SQLException("Method not supported"); 106 | } 107 | 108 | @Override 109 | public byte getByte(String columnName) throws SQLException { 110 | throw new SQLException("Method not supported"); 111 | } 112 | 113 | @Override 114 | public byte[] getBytes(int columnIndex) throws SQLException { 115 | throw new SQLException("Method not supported"); 116 | } 117 | 118 | @Override 119 | public byte[] getBytes(String columnName) throws SQLException { 120 | throw new SQLException("Method not supported"); 121 | } 122 | 123 | @Override 124 | public int getConcurrency() throws SQLException { 125 | throw new SQLException("Method not supported"); 126 | } 127 | 128 | @Override 129 | public Date getDate(int columnIndex) throws SQLException { 130 | throw new SQLException("Method not supported"); 131 | } 132 | 133 | @Override 134 | public Date getDate(String columnName) throws SQLException { 135 | throw new SQLException("Method not supported"); 136 | } 137 | 138 | @Override 139 | public double getDouble(int columnIndex) throws SQLException { 140 | throw new SQLException("Method not supported"); 141 | } 142 | 143 | @Override 144 | public double getDouble(String columnName) throws SQLException { 145 | throw new SQLException("Method not supported"); 146 | } 147 | 148 | @Override 149 | public int getFetchDirection() throws SQLException { 150 | throw new SQLException("Method not supported"); 151 | } 152 | 153 | @Override 154 | public float getFloat(int columnIndex) throws SQLException { 155 | throw new SQLException("Method not supported"); 156 | } 157 | 158 | @Override 159 | public float getFloat(String columnName) throws SQLException { 160 | throw new SQLException("Method not supported"); 161 | } 162 | 163 | @Override 164 | public int getInt(int columnIndex) throws SQLException { 165 | throw new SQLException("Method not supported"); 166 | } 167 | 168 | @Override 169 | public int getInt(String columnName) throws SQLException { 170 | throw new SQLException("Method not supported"); 171 | } 172 | 173 | @Override 174 | public long getLong(int columnIndex) throws SQLException { 175 | throw new SQLException("Method not supported"); 176 | } 177 | 178 | @Override 179 | public long getLong(String columnName) throws SQLException { 180 | throw new SQLException("Method not supported"); 181 | } 182 | 183 | @Override 184 | public ResultSetMetaData getMetaData() throws SQLException { 185 | return new TsfileMetadataResultMetadata(showLabels); 186 | } 187 | 188 | @Override 189 | public boolean next() throws SQLException { 190 | boolean hasNext = columnItr.hasNext(); 191 | if (hasNext) { 192 | if (type == MetadataType.STORAGE_GROUP) { 193 | currentStorageGroup = (String) columnItr.next(); 194 | } else if (type == MetadataType.COLUMN) { 195 | currentColumn = (String) columnItr.next(); 196 | } else { 197 | currentTimeseries = (List) columnItr.next(); 198 | } 199 | } 200 | return hasNext; 201 | } 202 | 203 | @Override 204 | public Object getObject(int columnIndex) throws SQLException { 205 | throw new SQLException("Method not supported"); 206 | } 207 | 208 | @Override 209 | public Object getObject(String columnName) throws SQLException { 210 | throw new SQLException("Method not supported"); 211 | } 212 | 213 | @Override 214 | public short getShort(int columnIndex) throws SQLException { 215 | throw new SQLException("Method not supported"); 216 | } 217 | 218 | @Override 219 | public short getShort(String columnName) throws SQLException { 220 | throw new SQLException("Method not supported"); 221 | } 222 | 223 | @Override 224 | public Statement getStatement() throws SQLException { 225 | throw new SQLException("Method not supported"); 226 | } 227 | 228 | @Override 229 | public String getString(int columnIndex) throws SQLException { 230 | switch (type) { 231 | case STORAGE_GROUP: 232 | if (columnIndex == 1) { 233 | return getString(GET_STRING_STORAGE_GROUP); 234 | } 235 | break; 236 | case TIMESERIES: 237 | if (columnIndex >= 1 && columnIndex <= colCount) { 238 | return getString(showLabels[columnIndex - 1]); 239 | } 240 | break; 241 | case COLUMN: 242 | if (columnIndex == 1) { 243 | return getString(GET_STRING_COLUMN); 244 | } 245 | break; 246 | default: 247 | break; 248 | } 249 | throw new SQLException(String.format("select column index %d does not exists", columnIndex)); 250 | } 251 | 252 | @Override 253 | public String getString(String columnName) throws SQLException { 254 | // use special key word to judge return content 255 | switch (columnName) { 256 | case GET_STRING_STORAGE_GROUP: 257 | return currentStorageGroup; 258 | case GET_STRING_TIMESERIES_NAME: 259 | return currentTimeseries.get(0); 260 | case GET_STRING_TIMESERIES_STORAGE_GROUP: 261 | return currentTimeseries.get(1); 262 | case GET_STRING_TIMESERIES_DATATYPE: 263 | return currentTimeseries.get(2); 264 | case GET_STRING_TIMESERIES_ENCODING: 265 | return currentTimeseries.get(3); 266 | case GET_STRING_COLUMN: 267 | return currentColumn; 268 | default: 269 | break; 270 | } 271 | return null; 272 | } 273 | 274 | @Override 275 | public Time getTime(int columnIndex) throws SQLException { 276 | throw new SQLException("Method not supported"); 277 | } 278 | 279 | @Override 280 | public Time getTime(String columnName) throws SQLException { 281 | throw new SQLException("Method not supported"); 282 | } 283 | 284 | @Override 285 | public int getType() throws SQLException { 286 | return type.ordinal(); 287 | } 288 | 289 | @Override 290 | public SQLWarning getWarnings() throws SQLException { 291 | throw new SQLException("Method not supported"); 292 | } 293 | 294 | @Override 295 | public boolean isClosed() throws SQLException { 296 | throw new SQLException("Method not supported"); 297 | } 298 | 299 | @Override 300 | public boolean wasNull() throws SQLException { 301 | throw new SQLException("Method not supported"); 302 | } 303 | 304 | public enum MetadataType{ 305 | STORAGE_GROUP, TIMESERIES, COLUMN 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfilePrepareStatement.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import java.io.InputStream; 4 | import java.io.Reader; 5 | import java.math.BigDecimal; 6 | import java.net.URL; 7 | import java.sql.Array; 8 | import java.sql.Blob; 9 | import java.sql.Clob; 10 | import java.sql.Date; 11 | import java.sql.NClob; 12 | import java.sql.ParameterMetaData; 13 | import java.sql.PreparedStatement; 14 | import java.sql.Ref; 15 | import java.sql.ResultSet; 16 | import java.sql.ResultSetMetaData; 17 | import java.sql.RowId; 18 | import java.sql.SQLException; 19 | import java.sql.SQLXML; 20 | import java.sql.Time; 21 | import java.sql.Timestamp; 22 | import java.util.ArrayList; 23 | import java.util.Calendar; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import org.joda.time.DateTime; 29 | 30 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSIService.Iface; 31 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_SessionHandle; 32 | 33 | public class TsfilePrepareStatement extends TsfileStatement implements PreparedStatement { 34 | private final String sql; 35 | /** 36 | * save the SQL parameters as (paramLoc,paramValue) pair 37 | */ 38 | private final Map parameters=new HashMap(); 39 | 40 | public TsfilePrepareStatement(TsfileConnection connection, Iface client, TS_SessionHandle sessionHandle, String sql) { 41 | super(connection, client, sessionHandle); 42 | this.sql = sql; 43 | } 44 | 45 | @Override 46 | public void addBatch() throws SQLException { 47 | throw new SQLException("Method not supported"); 48 | } 49 | 50 | @Override 51 | public void clearParameters() throws SQLException { 52 | this.parameters.clear(); 53 | } 54 | 55 | @Override 56 | public boolean execute() throws SQLException { 57 | return super.execute(createCompleteSql(sql, parameters)); 58 | } 59 | 60 | @Override 61 | public ResultSet executeQuery() throws SQLException { 62 | return super.executeQuery(createCompleteSql(sql, parameters)); 63 | } 64 | 65 | @Override 66 | public int executeUpdate() throws SQLException { 67 | return super.executeUpdate(createCompleteSql(sql, parameters)); 68 | } 69 | 70 | @Override 71 | public ResultSetMetaData getMetaData() throws SQLException { 72 | throw new SQLException("Method not supported"); 73 | } 74 | 75 | @Override 76 | public ParameterMetaData getParameterMetaData() throws SQLException { 77 | throw new SQLException("Method not supported"); 78 | } 79 | 80 | @Override 81 | public void setArray(int parameterIndex, Array x) throws SQLException { 82 | throw new SQLException("Method not supported"); 83 | } 84 | 85 | @Override 86 | public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { 87 | throw new SQLException("Method not supported"); 88 | } 89 | 90 | @Override 91 | public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { 92 | throw new SQLException("Method not supported"); 93 | } 94 | 95 | @Override 96 | public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { 97 | throw new SQLException("Method not supported"); 98 | } 99 | 100 | @Override 101 | public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { 102 | throw new SQLException("Method not supported"); 103 | } 104 | 105 | @Override 106 | public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { 107 | throw new SQLException("Method not supported"); 108 | } 109 | 110 | @Override 111 | public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { 112 | throw new SQLException("Method not supported"); 113 | } 114 | 115 | @Override 116 | public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { 117 | throw new SQLException("Method not supported"); 118 | } 119 | 120 | @Override 121 | public void setBlob(int parameterIndex, Blob x) throws SQLException { 122 | throw new SQLException("Method not supported"); 123 | } 124 | 125 | @Override 126 | public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { 127 | throw new SQLException("Method not supported"); 128 | } 129 | 130 | @Override 131 | public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { 132 | throw new SQLException("Method not supported"); 133 | } 134 | 135 | @Override 136 | public void setBoolean(int parameterIndex, boolean x) throws SQLException { 137 | this.parameters.put(parameterIndex,""+x); 138 | } 139 | 140 | @Override 141 | public void setByte(int parameterIndex, byte x) throws SQLException { 142 | throw new SQLException("Method not supported"); 143 | } 144 | 145 | @Override 146 | public void setBytes(int parameterIndex, byte[] x) throws SQLException { 147 | throw new SQLException("Method not supported"); 148 | } 149 | 150 | @Override 151 | public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { 152 | throw new SQLException("Method not supported"); 153 | } 154 | 155 | @Override 156 | public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { 157 | throw new SQLException("Method not supported"); 158 | } 159 | 160 | @Override 161 | public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { 162 | throw new SQLException("Method not supported"); 163 | } 164 | 165 | @Override 166 | public void setClob(int parameterIndex, Clob x) throws SQLException { 167 | throw new SQLException("Method not supported"); 168 | } 169 | 170 | @Override 171 | public void setClob(int parameterIndex, Reader reader) throws SQLException { 172 | throw new SQLException("Method not supported"); 173 | } 174 | 175 | @Override 176 | public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { 177 | throw new SQLException("Method not supported"); 178 | } 179 | 180 | @Override 181 | public void setDate(int parameterIndex, Date x) throws SQLException { 182 | throw new SQLException("Method not supported"); 183 | } 184 | 185 | @Override 186 | public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { 187 | throw new SQLException("Method not supported"); 188 | } 189 | 190 | @Override 191 | public void setDouble(int parameterIndex, double x) throws SQLException { 192 | this.parameters.put(parameterIndex,""+x); 193 | } 194 | 195 | @Override 196 | public void setFloat(int parameterIndex, float x) throws SQLException { 197 | this.parameters.put(parameterIndex,""+x); 198 | } 199 | 200 | @Override 201 | public void setInt(int parameterIndex, int x) throws SQLException { 202 | this.parameters.put(parameterIndex,""+x); 203 | } 204 | 205 | @Override 206 | public void setLong(int parameterIndex, long x) throws SQLException { 207 | this.parameters.put(parameterIndex,""+x); 208 | } 209 | 210 | @Override 211 | public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { 212 | throw new SQLException("Method not supported"); 213 | } 214 | 215 | @Override 216 | public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { 217 | throw new SQLException("Method not supported"); 218 | } 219 | 220 | @Override 221 | public void setNClob(int parameterIndex, NClob value) throws SQLException { 222 | throw new SQLException("Method not supported"); 223 | } 224 | 225 | @Override 226 | public void setNClob(int parameterIndex, Reader reader) throws SQLException { 227 | throw new SQLException("Method not supported"); 228 | } 229 | 230 | @Override 231 | public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { 232 | throw new SQLException("Method not supported"); 233 | } 234 | 235 | @Override 236 | public void setNString(int parameterIndex, String value) throws SQLException { 237 | throw new SQLException("Method not supported"); 238 | } 239 | 240 | @Override 241 | public void setNull(int parameterIndex, int sqlType) throws SQLException { 242 | throw new SQLException("Method not supported"); 243 | } 244 | 245 | @Override 246 | public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { 247 | throw new SQLException("Method not supported"); 248 | } 249 | 250 | @Override 251 | public void setObject(int parameterIndex, Object x) throws SQLException { 252 | if (x instanceof String) { 253 | setString(parameterIndex, (String) x); 254 | } else if (x instanceof Integer) { 255 | setInt(parameterIndex, ((Integer) x).intValue()); 256 | } else if (x instanceof Long) { 257 | setLong(parameterIndex, ((Long) x).longValue()); 258 | } else if (x instanceof Float) { 259 | setFloat(parameterIndex, ((Float) x).floatValue()); 260 | } else if (x instanceof Double) { 261 | setDouble(parameterIndex, ((Double) x).doubleValue()); 262 | } else if (x instanceof Boolean) { 263 | setBoolean(parameterIndex, ((Boolean) x).booleanValue()); 264 | } else if (x instanceof Timestamp) { 265 | setTimestamp(parameterIndex, (Timestamp) x); 266 | } else { 267 | // Can't infer a type. 268 | throw new SQLException(String.format("Can''t infer the SQL type to use for an instance of %s. Use setObject() with an explicit Types value to specify the type to use.", x.getClass().getName())); 269 | } 270 | } 271 | 272 | @Override 273 | public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { 274 | throw new SQLException("Method not supported"); 275 | } 276 | 277 | @Override 278 | public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { 279 | throw new SQLException("Method not supported"); 280 | } 281 | 282 | @Override 283 | public void setRef(int parameterIndex, Ref x) throws SQLException { 284 | throw new SQLException("Method not supported"); 285 | } 286 | 287 | @Override 288 | public void setRowId(int parameterIndex, RowId x) throws SQLException { 289 | throw new SQLException("Method not supported"); 290 | } 291 | 292 | @Override 293 | public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { 294 | throw new SQLException("Method not supported"); 295 | } 296 | 297 | @Override 298 | public void setShort(int parameterIndex, short x) throws SQLException { 299 | throw new SQLException("Method not supported"); 300 | } 301 | 302 | @Override 303 | public void setString(int parameterIndex, String x) throws SQLException { 304 | x = x.replace("'", "\\'"); 305 | this.parameters.put(parameterIndex, "'" + x + "'"); 306 | } 307 | 308 | @Override 309 | public void setTime(int parameterIndex, Time x) throws SQLException { 310 | throw new SQLException("Method not supported"); 311 | } 312 | 313 | @Override 314 | public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { 315 | throw new SQLException("Method not supported"); 316 | } 317 | 318 | @Override 319 | public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { 320 | DateTime dt = new DateTime(x.getTime()); 321 | this.parameters.put(parameterIndex, dt.toString("yyyy-MM-dd HH:mm:ss.SSS")); 322 | } 323 | 324 | @Override 325 | public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { 326 | throw new SQLException("Method not supported"); 327 | } 328 | 329 | @Override 330 | public void setURL(int parameterIndex, URL x) throws SQLException { 331 | throw new SQLException("Method not supported"); 332 | } 333 | 334 | @Override 335 | public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { 336 | throw new SQLException("Method not supported"); 337 | } 338 | 339 | private String createCompleteSql(final String sql, Map parameters) throws SQLException { 340 | List parts = splitSqlStatement(sql); 341 | 342 | StringBuilder newSql = new StringBuilder(parts.get(0)); 343 | for (int i = 1; i < parts.size(); i++) { 344 | if (!parameters.containsKey(i)) { 345 | throw new SQLException("Parameter #" + i + " is unset"); 346 | } 347 | newSql.append(parameters.get(i)); 348 | newSql.append(parts.get(i)); 349 | } 350 | return newSql.toString(); 351 | 352 | } 353 | 354 | private List splitSqlStatement(final String sql) { 355 | List parts = new ArrayList<>(); 356 | int apCount = 0; 357 | int off = 0; 358 | boolean skip = false; 359 | 360 | for (int i = 0; i < sql.length(); i++) { 361 | char c = sql.charAt(i); 362 | if (skip) { 363 | skip = false; 364 | continue; 365 | } 366 | switch (c) { 367 | case '\'': 368 | // skip something like 'xxxxx' 369 | apCount++; 370 | break; 371 | case '\\': 372 | // skip something like \r\n 373 | skip = true; 374 | break; 375 | case '?': 376 | // for input like: select a from 'bc' where d, 'bc' will be skipped 377 | if ((apCount & 1) == 0) { 378 | parts.add(sql.substring(off, i)); 379 | off = i + 1; 380 | } 381 | break; 382 | default: 383 | break; 384 | } 385 | } 386 | parts.add(sql.substring(off, sql.length())); 387 | return parts; 388 | 389 | } 390 | 391 | } 392 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileResultMetadata.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import java.sql.ResultSetMetaData; 4 | import java.sql.SQLException; 5 | import java.sql.Types; 6 | import java.util.List; 7 | 8 | public class TsfileResultMetadata implements ResultSetMetaData { 9 | private List columnInfoList; 10 | private String operationType; 11 | private List columnTypeList; 12 | 13 | public TsfileResultMetadata(List columnInfoList, String operationType, List columnTypeList) { 14 | this.columnInfoList = columnInfoList; 15 | this.operationType = operationType; 16 | this.columnTypeList = columnTypeList; 17 | } 18 | 19 | @Override 20 | public boolean isWrapperFor(Class arg0) throws SQLException { 21 | // TODO Auto-generated method stub 22 | return false; 23 | } 24 | 25 | @Override 26 | public T unwrap(Class arg0) throws SQLException { 27 | // TODO Auto-generated method stub 28 | return null; 29 | } 30 | 31 | @Override 32 | public String getCatalogName(int arg0) throws SQLException { 33 | // TODO Auto-generated method stub 34 | return null; 35 | } 36 | 37 | @Override 38 | public String getColumnClassName(int arg0) throws SQLException { 39 | // TODO Auto-generated method stub 40 | return null; 41 | } 42 | 43 | @Override 44 | public int getColumnCount() throws SQLException { 45 | if (columnInfoList == null || columnInfoList.size() == 0) { 46 | throw new SQLException("No column exists"); 47 | } 48 | return columnInfoList.size(); 49 | } 50 | 51 | @Override 52 | public int getColumnDisplaySize(int arg0) throws SQLException { 53 | // TODO Auto-generated method stub 54 | return 0; 55 | } 56 | 57 | @Override 58 | public String getColumnLabel(int column) throws SQLException { 59 | if (columnInfoList == null || columnInfoList.size() == 0) { 60 | throw new SQLException("No column exists"); 61 | } 62 | if(column > columnInfoList.size()){ 63 | throw new SQLException(String.format("column %d does not exist", column)); 64 | } 65 | if(column <= 0) { 66 | throw new SQLException(String.format("column index should start from 1", column)); 67 | } 68 | return columnInfoList.get(column-1); 69 | } 70 | 71 | @Override 72 | public String getColumnName(int column) throws SQLException { 73 | return getColumnLabel(column); 74 | } 75 | 76 | @Override 77 | public int getColumnType(int column) throws SQLException { 78 | // TODO Auto-generated method stub 79 | if (columnInfoList == null || columnInfoList.size() == 0) { 80 | throw new SQLException("No column exists"); 81 | } 82 | if (column > columnInfoList.size()) { 83 | throw new SQLException(String.format("column %d does not exist", column)); 84 | } 85 | if (column <= 0) { 86 | throw new SQLException(String.format("column index should start from 1", column)); 87 | } 88 | 89 | if (column == 1) { 90 | return Types.TIMESTAMP; 91 | } 92 | // BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT, 93 | String columnType = columnTypeList.get(column - 2); 94 | switch (columnType.toUpperCase()) { 95 | case "BOOLEAN": 96 | return Types.BOOLEAN; 97 | case "INT32": 98 | return Types.INTEGER; 99 | case "INT64": 100 | return Types.BIGINT; 101 | case "FLOAT": 102 | return Types.FLOAT; 103 | case "DOUBLE": 104 | return Types.DOUBLE; 105 | case "TEXT": 106 | return Types.VARCHAR; 107 | default: 108 | break; 109 | } 110 | return 0; 111 | } 112 | 113 | @Override 114 | public String getColumnTypeName(int arg0) throws SQLException { 115 | return operationType; 116 | } 117 | 118 | @Override 119 | public int getPrecision(int arg0) throws SQLException { 120 | // TODO Auto-generated method stub 121 | return 0; 122 | } 123 | 124 | @Override 125 | public int getScale(int arg0) throws SQLException { 126 | // TODO Auto-generated method stub 127 | return 0; 128 | } 129 | 130 | @Override 131 | public String getSchemaName(int arg0) throws SQLException { 132 | // TODO Auto-generated method stub 133 | return null; 134 | } 135 | 136 | @Override 137 | public String getTableName(int arg0) throws SQLException { 138 | // TODO Auto-generated method stub 139 | return null; 140 | } 141 | 142 | @Override 143 | public boolean isAutoIncrement(int arg0) throws SQLException { 144 | // TODO Auto-generated method stub 145 | return false; 146 | } 147 | 148 | @Override 149 | public boolean isCaseSensitive(int arg0) throws SQLException { 150 | // TODO Auto-generated method stub 151 | return false; 152 | } 153 | 154 | @Override 155 | public boolean isCurrency(int arg0) throws SQLException { 156 | // TODO Auto-generated method stub 157 | return false; 158 | } 159 | 160 | @Override 161 | public boolean isDefinitelyWritable(int arg0) throws SQLException { 162 | // TODO Auto-generated method stub 163 | return false; 164 | } 165 | 166 | @Override 167 | public int isNullable(int arg0) throws SQLException { 168 | // TODO Auto-generated method stub 169 | return 0; 170 | } 171 | 172 | @Override 173 | public boolean isReadOnly(int arg0) throws SQLException { 174 | // TODO Auto-generated method stub 175 | return false; 176 | } 177 | 178 | @Override 179 | public boolean isSearchable(int arg0) throws SQLException { 180 | // TODO Auto-generated method stub 181 | return false; 182 | } 183 | 184 | @Override 185 | public boolean isSigned(int arg0) throws SQLException { 186 | // TODO Auto-generated method stub 187 | return false; 188 | } 189 | 190 | @Override 191 | public boolean isWritable(int arg0) throws SQLException { 192 | // TODO Auto-generated method stub 193 | return false; 194 | } 195 | 196 | } 197 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileSQLException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import java.sql.SQLException; 4 | 5 | public class TsfileSQLException extends SQLException{ 6 | private String errorMessage; 7 | 8 | private static final long serialVersionUID = -3306001287342258977L; 9 | 10 | public TsfileSQLException(String reason){ 11 | super(reason); 12 | } 13 | 14 | public String getErrorMessage() { 15 | return errorMessage; 16 | } 17 | 18 | public void setErrorMessage(String errorMessage) { 19 | this.errorMessage = errorMessage; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileURLException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import java.sql.SQLException; 4 | 5 | public class TsfileURLException extends SQLException{ 6 | private static final long serialVersionUID = -5071922897222027267L; 7 | 8 | public TsfileURLException(String reason){ 9 | super(reason); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/tsinghua/iotdb/jdbc/Utils.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSDataValue; 4 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSQueryDataSet; 5 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSRowRecord; 6 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_Status; 7 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_StatusCode; 8 | import cn.edu.tsinghua.tsfile.common.exception.UnSupportedDataTypeException; 9 | import cn.edu.tsinghua.tsfile.common.utils.Binary; 10 | import cn.edu.tsinghua.tsfile.file.metadata.enums.TSDataType; 11 | import cn.edu.tsinghua.tsfile.timeseries.read.common.Path; 12 | import cn.edu.tsinghua.tsfile.timeseries.read.datatype.RowRecord; 13 | import cn.edu.tsinghua.tsfile.timeseries.read.datatype.TsPrimitiveType; 14 | 15 | import java.util.ArrayList; 16 | import java.util.LinkedHashMap; 17 | import java.util.List; 18 | import java.util.Properties; 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | /** 23 | * Utils to convert between thrift format and TsFile format 24 | */ 25 | public class Utils { 26 | 27 | /** 28 | * Parse JDBC connection URL The only supported format of the URL is: 29 | * jdbc:tsfile://localhost:6667/ 30 | */ 31 | public static TsfileConnectionParams parseURL(String url, Properties info) throws TsfileURLException { 32 | TsfileConnectionParams params = new TsfileConnectionParams(url); 33 | if (url.trim().equalsIgnoreCase(TsfileJDBCConfig.TSFILE_URL_PREFIX)) { 34 | return params; 35 | } 36 | 37 | Pattern pattern = Pattern.compile("([^;]*):([^;]*)/"); 38 | Matcher matcher = pattern.matcher(url.substring(TsfileJDBCConfig.TSFILE_URL_PREFIX.length())); 39 | boolean isUrlLegal = false; 40 | while (matcher.find()) { 41 | params.setHost(matcher.group(1)); 42 | params.setPort(Integer.parseInt((matcher.group(2)))); 43 | isUrlLegal = true; 44 | } 45 | if (!isUrlLegal) { 46 | throw new TsfileURLException("Error url format, url should be jdbc:tsfile://ip:port/"); 47 | } 48 | 49 | if (info.containsKey(TsfileJDBCConfig.AUTH_USER)) { 50 | params.setUsername(info.getProperty(TsfileJDBCConfig.AUTH_USER)); 51 | } 52 | if (info.containsKey(TsfileJDBCConfig.AUTH_PASSWORD)) { 53 | params.setPassword(info.getProperty(TsfileJDBCConfig.AUTH_PASSWORD)); 54 | } 55 | 56 | return params; 57 | } 58 | 59 | public static void verifySuccess(TS_Status status) throws TsfileSQLException { 60 | if (status.getStatusCode() != TS_StatusCode.SUCCESS_STATUS) { 61 | throw new TsfileSQLException(status.errorMessage); 62 | } 63 | } 64 | 65 | public static List convertRowRecords(TSQueryDataSet tsQueryDataSet) { 66 | List records = new ArrayList<>(); 67 | for(TSRowRecord ts : tsQueryDataSet.getRecords()) { 68 | RowRecord r = new RowRecord(ts.getTimestamp()); 69 | r.setFields(new LinkedHashMap()); 70 | int l = ts.getKeysSize(); 71 | for(int i = 0; i < l;i++) { 72 | Path path = new Path(ts.getKeys().get(i)); 73 | if(ts.getValues().get(i).is_empty) { 74 | r.getFields().put(path, null); 75 | } else { 76 | TSDataValue value = ts.getValues().get(i); 77 | TSDataType dataType = TSDataType.valueOf(value.getType()); 78 | switch (dataType) { 79 | case BOOLEAN: 80 | r.getFields().put(path, new TsPrimitiveType.TsBoolean(value.isBool_val())); 81 | break; 82 | case INT32: 83 | r.getFields().put(path, new TsPrimitiveType.TsInt(value.getInt_val())); 84 | break; 85 | case INT64: 86 | r.getFields().put(path, new TsPrimitiveType.TsLong(value.getLong_val())); 87 | break; 88 | case FLOAT: 89 | r.getFields().put(path, new TsPrimitiveType.TsFloat((float)value.getFloat_val())); 90 | break; 91 | case DOUBLE: 92 | r.getFields().put(path, new TsPrimitiveType.TsDouble(value.getDouble_val())); 93 | break; 94 | case TEXT: 95 | r.getFields().put(path, new TsPrimitiveType.TsBinary(new Binary((value.getBinary_val())))); 96 | break; 97 | default: 98 | throw new UnSupportedDataTypeException(String.format("data type %s is not supported when convert data at client", dataType)); 99 | } 100 | } 101 | } 102 | records.add(r); 103 | } 104 | return records; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/BatchTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | import static org.mockito.Matchers.any; 6 | import static org.mockito.Mockito.when; 7 | 8 | import java.sql.BatchUpdateException; 9 | import java.sql.SQLException; 10 | import java.sql.Statement; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import org.apache.thrift.TException; 15 | import org.junit.After; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mock; 19 | import org.mockito.MockitoAnnotations; 20 | 21 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSExecuteBatchStatementReq; 22 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSExecuteBatchStatementResp; 23 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSIService; 24 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_SessionHandle; 25 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_Status; 26 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_StatusCode; 27 | 28 | 29 | public class BatchTest { 30 | @Mock 31 | private TsfileConnection connection; 32 | @Mock 33 | private TSIService.Iface client; 34 | @Mock 35 | private TS_SessionHandle sessHandle; 36 | private TS_Status Status_SUCCESS = new TS_Status(TS_StatusCode.SUCCESS_STATUS); 37 | private TS_Status Status_ERROR = new TS_Status(TS_StatusCode.ERROR_STATUS); 38 | private TSExecuteBatchStatementResp resp; 39 | 40 | @Before 41 | public void setUp() throws Exception { 42 | MockitoAnnotations.initMocks(this); 43 | when(connection.createStatement()).thenReturn(new TsfileStatement(connection, client, sessHandle)); 44 | } 45 | 46 | @After 47 | public void tearDown() throws Exception { 48 | } 49 | 50 | @SuppressWarnings("serial") 51 | @Test 52 | public void testExecuteBatchSQL1() throws SQLException, TException { 53 | Statement statement = connection.createStatement(); 54 | resp = new TSExecuteBatchStatementResp(Status_SUCCESS); 55 | when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); 56 | int[] result = statement.executeBatch(); 57 | assertEquals(result.length, 0); 58 | 59 | List resExpected = new ArrayList() {{ 60 | add(Statement.SUCCESS_NO_INFO); 61 | add(Statement.SUCCESS_NO_INFO); 62 | add(Statement.SUCCESS_NO_INFO); 63 | add(Statement.SUCCESS_NO_INFO); 64 | add(Statement.SUCCESS_NO_INFO); 65 | add(Statement.EXECUTE_FAILED); 66 | add(Statement.SUCCESS_NO_INFO); 67 | add(Statement.SUCCESS_NO_INFO); 68 | add(Statement.EXECUTE_FAILED); 69 | }}; 70 | resp.setResult(resExpected); 71 | 72 | statement.addBatch("SET STORAGE GROUP TO root.ln.wf01.wt01"); 73 | statement.addBatch("CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN"); 74 | statement.addBatch("CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE"); 75 | statement.addBatch("insert into root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)"); 76 | statement.addBatch("insert into root.ln.wf01.wt01(timestamp,status) values(1509465660000,true)"); 77 | statement.addBatch("insert into root.ln.wf01.wt01(timestamp,status) vvvvvv(1509465720000,false)"); 78 | statement.addBatch("insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,25.957603)"); 79 | statement.addBatch("insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465660000,24.359503)"); 80 | statement.addBatch("insert into root.ln.wf01.wt01(timestamp,temperature) vvvvvv(1509465720000,20.092794)"); 81 | result = statement.executeBatch(); 82 | assertEquals(result.length, resExpected.size()); 83 | for(int i = 0; i < resExpected.size();i++) { 84 | assertEquals(result[i], (int)resExpected.get(i)); 85 | } 86 | statement.clearBatch(); 87 | } 88 | 89 | @Test(expected = BatchUpdateException.class) 90 | public void testExecuteBatchSQL2() throws SQLException, TException { 91 | Statement statement = connection.createStatement(); 92 | resp = new TSExecuteBatchStatementResp(Status_ERROR); 93 | when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); 94 | statement.executeBatch(); 95 | } 96 | 97 | @SuppressWarnings("serial") 98 | @Test 99 | public void testExecuteBatchSQL3() throws SQLException, TException { 100 | Statement statement = connection.createStatement(); 101 | resp = new TSExecuteBatchStatementResp(Status_ERROR); 102 | List resExpected = new ArrayList() {{ 103 | add(Statement.SUCCESS_NO_INFO); 104 | add(Statement.EXECUTE_FAILED); 105 | }}; 106 | resp.setResult(resExpected); 107 | when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); 108 | try { 109 | statement.executeBatch(); 110 | } catch (BatchUpdateException e) { 111 | int[] result = e.getUpdateCounts(); 112 | for(int i = 0; i < resExpected.size();i++) { 113 | assertEquals(result[i], (int)resExpected.get(i)); 114 | } 115 | return; 116 | } 117 | fail(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsFilePrepareStatementTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.mockito.ArgumentCaptor; 8 | import org.mockito.Mock; 9 | import org.mockito.MockitoAnnotations; 10 | 11 | import static org.mockito.Matchers.any; 12 | import static org.mockito.Mockito.verify; 13 | import static org.mockito.Mockito.when; 14 | 15 | import java.sql.SQLException; 16 | import java.sql.Timestamp; 17 | 18 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSExecuteStatementReq; 19 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSExecuteStatementResp; 20 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSGetOperationStatusResp; 21 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSIService.Iface; 22 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSOperationHandle; 23 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_SessionHandle; 24 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_Status; 25 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_StatusCode; 26 | 27 | public class TsFilePrepareStatementTest { 28 | 29 | @Mock 30 | private TsfileConnection connection; 31 | 32 | @Mock 33 | private Iface client; 34 | 35 | @Mock 36 | private TS_SessionHandle sessHandle; 37 | 38 | @Mock 39 | TSExecuteStatementResp execStatementResp; 40 | 41 | @Mock 42 | TSGetOperationStatusResp getOperationStatusResp; 43 | 44 | private TS_Status Status_SUCCESS = new TS_Status(TS_StatusCode.SUCCESS_STATUS); 45 | 46 | @Mock 47 | private TSOperationHandle tOperationHandle; 48 | 49 | @Before 50 | public void before() throws Exception { 51 | MockitoAnnotations.initMocks(this); 52 | when(execStatementResp.getStatus()).thenReturn(Status_SUCCESS); 53 | when(execStatementResp.getOperationHandle()).thenReturn(tOperationHandle); 54 | 55 | when(getOperationStatusResp.getStatus()).thenReturn(Status_SUCCESS); 56 | when(client.executeStatement(any(TSExecuteStatementReq.class))).thenReturn(execStatementResp); 57 | } 58 | 59 | @SuppressWarnings("resource") 60 | @Test 61 | public void testNonParameterized() throws Exception { 62 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00"; 63 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 64 | ps.execute(); 65 | 66 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 67 | verify(client).executeStatement(argument.capture()); 68 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 69 | } 70 | 71 | @SuppressWarnings("resource") 72 | @Test 73 | public void unusedArgument() throws SQLException { 74 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00"; 75 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 76 | ps.setString(1, "123"); 77 | ps.execute(); 78 | } 79 | 80 | @SuppressWarnings("resource") 81 | @Test(expected = SQLException.class) 82 | public void unsetArgument() throws SQLException { 83 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > ?"; 84 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 85 | ps.execute(); 86 | } 87 | 88 | @SuppressWarnings("resource") 89 | @Test 90 | public void oneIntArgument() throws Exception { 91 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00"; 92 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 93 | ps.setInt(1, 123); 94 | ps.execute(); 95 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 96 | verify(client).executeStatement(argument.capture()); 97 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 123 and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 98 | } 99 | 100 | @SuppressWarnings("resource") 101 | @Test 102 | public void oneLongArgument() throws Exception { 103 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00"; 104 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 105 | ps.setLong(1, 123); 106 | ps.execute(); 107 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 108 | verify(client).executeStatement(argument.capture()); 109 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 123 and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 110 | } 111 | 112 | @SuppressWarnings("resource") 113 | @Test 114 | public void oneFloatArgument() throws Exception { 115 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00"; 116 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 117 | ps.setFloat(1, 123.133f); 118 | ps.execute(); 119 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 120 | verify(client).executeStatement(argument.capture()); 121 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 123.133 and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 122 | } 123 | 124 | @SuppressWarnings("resource") 125 | @Test 126 | public void oneDoubleArgument() throws Exception { 127 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00"; 128 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 129 | ps.setDouble(1, 123.456); 130 | ps.execute(); 131 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 132 | verify(client).executeStatement(argument.capture()); 133 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 123.456 and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 134 | } 135 | 136 | @SuppressWarnings("resource") 137 | @Test 138 | public void oneBooleanArgument() throws Exception { 139 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00"; 140 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 141 | ps.setBoolean(1, false); 142 | ps.execute(); 143 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 144 | verify(client).executeStatement(argument.capture()); 145 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < false and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 146 | } 147 | 148 | @SuppressWarnings("resource") 149 | @Test 150 | public void oneStringArgument() throws Exception { 151 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00"; 152 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 153 | ps.setString(1, "abcde"); 154 | ps.execute(); 155 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 156 | verify(client).executeStatement(argument.capture()); 157 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 'abcde' and time > 2017-11-1 0:13:00", argument.getValue().getStatement()); 158 | } 159 | 160 | @SuppressWarnings("resource") 161 | @Test 162 | public void oneTimeLongArgument() throws Exception { 163 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE time > ?"; 164 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 165 | ps.setLong(1, 1233); 166 | ps.execute(); 167 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 168 | verify(client).executeStatement(argument.capture()); 169 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE time > 1233", argument.getValue().getStatement()); 170 | } 171 | 172 | @SuppressWarnings("resource") 173 | @Test 174 | public void oneTimeTimestampArgument() throws Exception { 175 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE time > ?"; 176 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 177 | ps.setTimestamp(1, Timestamp.valueOf("2017-11-01 00:13:00")); 178 | ps.execute(); 179 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 180 | verify(client).executeStatement(argument.capture()); 181 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE time > 2017-11-01 00:13:00.000", argument.getValue().getStatement()); 182 | } 183 | 184 | @SuppressWarnings("resource") 185 | @Test 186 | public void escapingOfStringArgument() throws Exception { 187 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE status = '134' and temperature = ?"; 188 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 189 | ps.setLong(1, 1333); 190 | ps.execute(); 191 | 192 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 193 | verify(client).executeStatement(argument.capture()); 194 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE status = '134' and temperature = 1333", argument.getValue().getStatement()); 195 | } 196 | 197 | @SuppressWarnings("resource") 198 | @Test 199 | public void pastingIntoEscapedQuery() throws Exception { 200 | String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE status = '\\044e' || temperature = ?"; 201 | 202 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 203 | ps.setDouble(1, -1323.0); 204 | ps.execute(); 205 | 206 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 207 | verify(client).executeStatement(argument.capture()); 208 | assertEquals("SELECT status, temperature FROM root.ln.wf01.wt01 WHERE status = '\\044e' || temperature = -1323.0", argument.getValue().getStatement()); 209 | } 210 | 211 | @SuppressWarnings("resource") 212 | @Test 213 | public void testInsertStatement1() throws Exception{ 214 | String sql = "INSERT INTO root.ln.wf01.wt01(timestamp,a,b,c,d,e,f) VALUES(?,?,?,?,?,?,?)"; 215 | 216 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 217 | ps.setLong(1, 12324); 218 | ps.setBoolean(2, false); 219 | ps.setInt(3, 123); 220 | ps.setLong(4, 123234345); 221 | ps.setFloat(5, 123.423f); 222 | ps.setDouble(6, -1323.0); 223 | ps.setString(7, "abc"); 224 | ps.execute(); 225 | 226 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 227 | verify(client).executeStatement(argument.capture()); 228 | assertEquals("INSERT INTO root.ln.wf01.wt01(timestamp,a,b,c,d,e,f) VALUES(12324,false,123,123234345,123.423,-1323.0,'abc')", argument.getValue().getStatement()); 229 | } 230 | 231 | @SuppressWarnings("resource") 232 | @Test 233 | public void testInsertStatement2() throws Exception{ 234 | String sql = "INSERT INTO root.ln.wf01.wt01(timestamp,a,b,c,d,e,f) VALUES(?,?,?,?,?,?,?)"; 235 | 236 | TsfilePrepareStatement ps = new TsfilePrepareStatement(connection, client, sessHandle, sql); 237 | ps.setTimestamp(1, Timestamp.valueOf("2017-11-01 00:13:00")); 238 | ps.setBoolean(2, false); 239 | ps.setInt(3, 123); 240 | ps.setLong(4, 123234345); 241 | ps.setFloat(5, 123.423f); 242 | ps.setDouble(6, -1323.0); 243 | ps.setString(7, "abc"); 244 | ps.execute(); 245 | 246 | ArgumentCaptor argument = ArgumentCaptor.forClass(TSExecuteStatementReq.class); 247 | verify(client).executeStatement(argument.capture()); 248 | assertEquals("INSERT INTO root.ln.wf01.wt01(timestamp,a,b,c,d,e,f) VALUES(2017-11-01 00:13:00.000,false,123,123234345,123.423,-1323.0,'abc')", argument.getValue().getStatement()); 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnectionTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.mockito.Mock; 9 | import org.mockito.MockitoAnnotations; 10 | 11 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSGetTimeZoneResp; 12 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSIService; 13 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSSetTimeZoneReq; 14 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSSetTimeZoneResp; 15 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_Status; 16 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_StatusCode; 17 | 18 | import static org.mockito.Matchers.any; 19 | import static org.mockito.Mockito.when; 20 | 21 | import org.apache.thrift.TException; 22 | 23 | 24 | public class TsfileConnectionTest { 25 | @Mock 26 | private TSIService.Iface client; 27 | 28 | private TsfileConnection connection = new TsfileConnection(); 29 | private TS_Status Status_SUCCESS = new TS_Status(TS_StatusCode.SUCCESS_STATUS); 30 | 31 | @Before 32 | public void setUp() throws Exception { 33 | MockitoAnnotations.initMocks(this); 34 | } 35 | 36 | @After 37 | public void tearDown() throws Exception { 38 | } 39 | 40 | @Test 41 | public void testSetTimeZone() throws TException, TsfileSQLException { 42 | String timeZone = "Asia/Shanghai"; 43 | when(client.setTimeZone(any(TSSetTimeZoneReq.class))).thenReturn(new TSSetTimeZoneResp(Status_SUCCESS)); 44 | connection.client = client; 45 | connection.setTimeZone(timeZone); 46 | assertEquals(connection.getTimeZone(), timeZone); 47 | } 48 | 49 | @Test 50 | public void testGetTimeZone() throws TsfileSQLException, TException { 51 | String timeZone = "GMT+:08:00"; 52 | when(client.getTimeZone()).thenReturn(new TSGetTimeZoneResp(Status_SUCCESS, timeZone)); 53 | connection.client = client; 54 | assertEquals(connection.getTimeZone(), timeZone); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileDatabaseMetadataTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import cn.edu.tsinghua.iotdb.jdbc.thrift.*; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.mockito.Mock; 10 | import org.mockito.MockitoAnnotations; 11 | 12 | import java.sql.*; 13 | import java.util.ArrayList; 14 | import java.util.HashSet; 15 | import java.util.List; 16 | import java.util.Set; 17 | 18 | import static org.mockito.Matchers.any; 19 | import static org.mockito.Mockito.when; 20 | 21 | /** 22 | * This class is designed to test the function of databaseMetaData which is used to fetch metadata from IoTDB. 23 | * (1) get all columns' name under a given path, 24 | * e.g., databaseMetaData.getColumns(“col”, “root”, null, null); 25 | * (2) get all delta objects under a given column 26 | * e.g., databaseMetaData.getColumns(“delta”, “vehicle”, null, null); 27 | * (3) show timeseries path 28 | * e.g., databaseMetaData.getColumns(“ts”, “root.vehicle.d0.s0”, null, null); 29 | * (4) show storage group 30 | * databaseMetaData.getColumns(“sg”, null, null, null); 31 | * (5) show metadata in json 32 | * ((TsfileDatabaseMetadata)databaseMetaData).getMetadataInJson() 33 | *

34 | * The tests utilize the mockito framework to mock responses from an IoTDB server. 35 | * The status of the IoTDB server mocked here is determined by the following four sql commands: 36 | * SET STORAGE GROUP TO root.vehicle; 37 | * CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE; 38 | * CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE; 39 | * CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE; 40 | */ 41 | 42 | public class TsfileDatabaseMetadataTest { 43 | @Mock 44 | private TsfileConnection connection; 45 | 46 | @Mock 47 | private TSIService.Iface client; 48 | 49 | @Mock 50 | private TSFetchMetadataResp fetchMetadataResp; 51 | 52 | private TS_Status Status_SUCCESS = new TS_Status(TS_StatusCode.SUCCESS_STATUS); 53 | 54 | private DatabaseMetaData databaseMetaData; 55 | 56 | @Before 57 | public void before() throws Exception { 58 | MockitoAnnotations.initMocks(this); 59 | when(connection.getMetaData()).thenReturn(new TsfileDatabaseMetadata(connection, client)); 60 | 61 | when(client.fetchMetadata(any(TSFetchMetadataReq.class))).thenReturn(fetchMetadataResp); 62 | when(fetchMetadataResp.getStatus()).thenReturn(Status_SUCCESS); 63 | 64 | databaseMetaData = connection.getMetaData(); 65 | } 66 | 67 | /** 68 | * get all columns' name under a given path 69 | */ 70 | @SuppressWarnings("resource") 71 | @Test 72 | public void AllColumns() throws Exception { 73 | List columnList = new ArrayList<>(); 74 | columnList.add("root.vehicle.d0.s0"); 75 | columnList.add("root.vehicle.d0.s1"); 76 | columnList.add("root.vehicle.d0.s2"); 77 | 78 | when(fetchMetadataResp.getColumnsList()).thenReturn(columnList); 79 | 80 | String standard = "Column,\n" + 81 | "root.vehicle.d0.s0,\n" + 82 | "root.vehicle.d0.s1,\n" + 83 | "root.vehicle.d0.s2,\n"; 84 | try { 85 | ResultSet resultSet = databaseMetaData.getColumns(TsFileDBConstant.CatalogColumn, "root", null, null); 86 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 87 | int colCount = resultSetMetaData.getColumnCount(); 88 | StringBuilder resultStr = new StringBuilder(); 89 | for (int i = 1; i < colCount + 1; i++) { 90 | resultStr.append(resultSetMetaData.getColumnName(i)).append(","); 91 | } 92 | resultStr.append("\n"); 93 | while (resultSet.next()) { 94 | for (int i = 1; i <= colCount; i++) { 95 | resultStr.append(resultSet.getString(i)).append(","); 96 | } 97 | resultStr.append("\n"); 98 | } 99 | Assert.assertEquals(resultStr.toString(), standard); 100 | } catch (SQLException e) { 101 | System.out.println(e); 102 | } 103 | } 104 | 105 | /** 106 | * get all delta objects under a given column 107 | */ 108 | @SuppressWarnings("resource") 109 | @Test 110 | public void DeltaObject() throws Exception { 111 | List columnList = new ArrayList<>(); 112 | columnList.add("root.vehicle.d0"); 113 | 114 | when(fetchMetadataResp.getColumnsList()).thenReturn(columnList); 115 | 116 | String standard = "Column,\n" + 117 | "root.vehicle.d0,\n"; 118 | try { 119 | ResultSet resultSet = databaseMetaData.getColumns(TsFileDBConstant.CatalogDeltaObject, "vehicle", null, null); 120 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 121 | int colCount = resultSetMetaData.getColumnCount(); 122 | StringBuilder resultStr = new StringBuilder(); 123 | for (int i = 1; i < colCount + 1; i++) { 124 | resultStr.append(resultSetMetaData.getColumnName(i)).append(","); 125 | } 126 | resultStr.append("\n"); 127 | while (resultSet.next()) { 128 | for (int i = 1; i <= colCount; i++) { 129 | resultStr.append(resultSet.getString(i)).append(","); 130 | } 131 | resultStr.append("\n"); 132 | } 133 | Assert.assertEquals(resultStr.toString(), standard); 134 | } catch (SQLException e) { 135 | System.out.println(e); 136 | } 137 | } 138 | 139 | /** 140 | * show timeseries 141 | * usage 1 142 | */ 143 | @SuppressWarnings({ "resource", "serial" }) 144 | @Test 145 | public void ShowTimeseriesPath1() throws Exception { 146 | List> tslist = new ArrayList<>(); 147 | tslist.add(new ArrayList(4) {{ 148 | add("root.vehicle.d0.s0"); 149 | add("root.vehicle"); 150 | add("INT32"); 151 | add("RLE"); 152 | }}); 153 | tslist.add(new ArrayList(4) {{ 154 | add("root.vehicle.d0.s1"); 155 | add("root.vehicle"); 156 | add("INT64"); 157 | add("RLE"); 158 | }}); 159 | tslist.add(new ArrayList(4) {{ 160 | add("root.vehicle.d0.s2"); 161 | add("root.vehicle"); 162 | add("FLOAT"); 163 | add("RLE"); 164 | }}); 165 | 166 | when(fetchMetadataResp.getShowTimeseriesList()).thenReturn(tslist); 167 | 168 | String standard = "Timeseries,Storage Group,DataType,Encoding,\n" + 169 | "root.vehicle.d0.s0,root.vehicle,INT32,RLE,\n" + 170 | "root.vehicle.d0.s1,root.vehicle,INT64,RLE,\n" + 171 | "root.vehicle.d0.s2,root.vehicle,FLOAT,RLE,\n"; 172 | try { 173 | ResultSet resultSet = databaseMetaData.getColumns(TsFileDBConstant.CatalogTimeseries, "root", null, null); 174 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 175 | int colCount = resultSetMetaData.getColumnCount(); 176 | StringBuilder resultStr = new StringBuilder(); 177 | for (int i = 1; i < colCount + 1; i++) { 178 | resultStr.append(resultSetMetaData.getColumnName(i)).append(","); 179 | } 180 | resultStr.append("\n"); 181 | while (resultSet.next()) { 182 | for (int i = 1; i <= colCount; i++) { 183 | resultStr.append(resultSet.getString(i)).append(","); 184 | } 185 | resultStr.append("\n"); 186 | } 187 | Assert.assertEquals(resultStr.toString(), standard); 188 | } catch (SQLException e) { 189 | System.out.println(e); 190 | } 191 | } 192 | 193 | /** 194 | * show timeseries 195 | * usage 2: Get information about a specific column, e.g., DataType 196 | */ 197 | @SuppressWarnings({ "resource", "serial" }) 198 | @Test 199 | public void ShowTimeseriesPath2() throws Exception { 200 | List> tslist = new ArrayList<>(); 201 | tslist.add(new ArrayList(4) {{ 202 | add("root.vehicle.d0.s0"); 203 | add("root.vehicle"); 204 | add("INT32"); 205 | add("RLE"); 206 | }}); 207 | 208 | when(fetchMetadataResp.getShowTimeseriesList()).thenReturn(tslist); 209 | 210 | String standard = "DataType,\n" + 211 | "INT32,\n"; 212 | try { 213 | ResultSet resultSet = databaseMetaData.getColumns(TsFileDBConstant.CatalogTimeseries, "root.vehicle.d0.s0", null, null); 214 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 215 | StringBuilder resultStr = new StringBuilder(); 216 | resultStr.append(resultSetMetaData.getColumnName(3)).append(",\n"); 217 | while (resultSet.next()) { 218 | resultStr.append(resultSet.getString(TsfileMetadataResultSet.GET_STRING_TIMESERIES_DATATYPE)).append(","); 219 | resultStr.append("\n"); 220 | } 221 | Assert.assertEquals(resultStr.toString(), standard); 222 | } catch (SQLException e) { 223 | System.out.println(e); 224 | } 225 | } 226 | 227 | /** 228 | * show storage group 229 | */ 230 | @SuppressWarnings("resource") 231 | @Test 232 | public void ShowStorageGroup() throws Exception { 233 | Set sgSet = new HashSet<>(); 234 | sgSet.add("root.vehicle"); 235 | when(fetchMetadataResp.getShowStorageGroups()).thenReturn(sgSet); 236 | 237 | String standard = "Storage Group,\n" + 238 | "root.vehicle,\n"; 239 | try { 240 | ResultSet resultSet = databaseMetaData.getColumns(TsFileDBConstant.CatalogStorageGroup, null, null, null); 241 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 242 | int colCount = resultSetMetaData.getColumnCount(); 243 | StringBuilder resultStr = new StringBuilder(); 244 | for (int i = 1; i < colCount + 1; i++) { 245 | resultStr.append(resultSetMetaData.getColumnName(i)).append(","); 246 | } 247 | resultStr.append("\n"); 248 | while (resultSet.next()) { 249 | for (int i = 1; i <= colCount; i++) { 250 | resultStr.append(resultSet.getString(i)).append(","); 251 | } 252 | resultStr.append("\n"); 253 | } 254 | Assert.assertEquals(resultStr.toString(), standard); 255 | } catch (SQLException e) { 256 | System.out.println(e); 257 | } 258 | } 259 | 260 | /** 261 | * show metadata in json 262 | */ 263 | @SuppressWarnings("resource") 264 | @Test 265 | public void ShowTimeseriesInJson() throws Exception { 266 | String metadataInJson = "=== Timeseries Tree ===\n" + 267 | "\n" + 268 | "root:{\n" + 269 | " vehicle:{\n" + 270 | " d0:{\n" + 271 | " s0:{\n" + 272 | " DataType: INT32,\n" + 273 | " Encoding: RLE,\n" + 274 | " args: {},\n" + 275 | " StorageGroup: root.vehicle \n" + 276 | " },\n" + 277 | " s1:{\n" + 278 | " DataType: INT64,\n" + 279 | " Encoding: RLE,\n" + 280 | " args: {},\n" + 281 | " StorageGroup: root.vehicle \n" + 282 | " },\n" + 283 | " s2:{\n" + 284 | " DataType: FLOAT,\n" + 285 | " Encoding: RLE,\n" + 286 | " args: {},\n" + 287 | " StorageGroup: root.vehicle \n" + 288 | " }\n" + 289 | " }\n" + 290 | " }\n" + 291 | "}"; 292 | 293 | when(fetchMetadataResp.getMetadataInJson()).thenReturn(metadataInJson); 294 | 295 | String res = ((TsfileDatabaseMetadata)databaseMetaData).getMetadataInJson(); 296 | assertEquals(metadataInJson, res); 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileMetadataResultMetadataTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.sql.SQLException; 6 | 7 | import org.junit.After; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | public class TsfileMetadataResultMetadataTest { 12 | 13 | private TsfileMetadataResultMetadata metadata; 14 | private String[] cols = {"a1", "a2", "a3", "a4"}; 15 | 16 | @Before 17 | public void setUp() throws Exception { 18 | 19 | } 20 | 21 | @After 22 | public void tearDown() throws Exception { 23 | } 24 | 25 | @Test 26 | public void testGetColumnCount() throws SQLException { 27 | boolean flag = false; 28 | try { 29 | metadata = new TsfileMetadataResultMetadata(null); 30 | assertEquals((long)metadata.getColumnCount(), 0); 31 | } catch (Exception e) { 32 | flag = true; 33 | } 34 | assertEquals(flag, true); 35 | 36 | flag = false; 37 | try { 38 | String[] nullArray = {}; 39 | metadata = new TsfileMetadataResultMetadata(nullArray); 40 | assertEquals((long)metadata.getColumnCount(), 0); 41 | } catch (Exception e) { 42 | flag = true; 43 | } 44 | assertEquals(flag, true); 45 | 46 | metadata = new TsfileMetadataResultMetadata(cols); 47 | assertEquals((long)metadata.getColumnCount(), cols.length); 48 | } 49 | 50 | 51 | @Test 52 | public void testGetColumnName() throws SQLException { 53 | boolean flag = false; 54 | metadata = new TsfileMetadataResultMetadata(null); 55 | try { 56 | metadata.getColumnName(1); 57 | } catch (Exception e) { 58 | flag = true; 59 | } 60 | assertEquals(flag, true); 61 | try { 62 | String[] nullArray = {}; 63 | metadata = new TsfileMetadataResultMetadata(nullArray); 64 | metadata.getColumnName(1); 65 | } catch (Exception e) { 66 | flag = true; 67 | } 68 | assertEquals(flag, true); 69 | 70 | metadata = new TsfileMetadataResultMetadata(cols); 71 | try { 72 | metadata.getColumnName(0); 73 | } catch (Exception e) { 74 | flag = true; 75 | } 76 | assertEquals(flag, true); 77 | 78 | flag = false; 79 | try { 80 | metadata.getColumnName(cols.length+1); 81 | } catch (Exception e) { 82 | flag = true; 83 | } 84 | assertEquals(flag, true); 85 | 86 | for(int i = 1; i <= cols.length; i++){ 87 | assertEquals(metadata.getColumnName(i), cols[i-1]); 88 | } 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileResultMetadataTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.sql.SQLException; 6 | import java.sql.Types; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | 15 | public class TsfileResultMetadataTest { 16 | private TsfileResultMetadata metadata; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | } 21 | 22 | @After 23 | public void tearDown() throws Exception { 24 | } 25 | 26 | @Test 27 | public void testGetColumnCount() throws SQLException { 28 | metadata = new TsfileResultMetadata(null, null, null); 29 | boolean flag = false; 30 | try { 31 | metadata.getColumnCount(); 32 | } catch (Exception e) { 33 | flag = true; 34 | } 35 | assertEquals(flag, true); 36 | 37 | List columnInfoList = new ArrayList<>(); 38 | flag = false; 39 | try { 40 | metadata = new TsfileResultMetadata(columnInfoList, null, null); 41 | metadata.getColumnCount(); 42 | } catch (Exception e) { 43 | flag = true; 44 | } 45 | assertEquals(flag, true); 46 | 47 | columnInfoList.add("root.a.b.c"); 48 | assertEquals(metadata.getColumnCount(), 1); 49 | } 50 | 51 | 52 | @Test 53 | public void testGetColumnName() throws SQLException { 54 | metadata = new TsfileResultMetadata(null, null, null); 55 | boolean flag = false; 56 | try { 57 | metadata.getColumnName(1); 58 | } catch (Exception e) { 59 | flag = true; 60 | } 61 | assertEquals(flag, true); 62 | 63 | List columnInfoList = new ArrayList<>(); 64 | metadata = new TsfileResultMetadata(columnInfoList, null, null); 65 | flag = false; 66 | try { 67 | metadata.getColumnName(1); 68 | } catch (Exception e) { 69 | flag = true; 70 | } 71 | assertEquals(flag, true); 72 | 73 | String[] colums = {"root.a.b.c1", "root.a.b.c2", "root.a.b.c3"}; 74 | metadata = new TsfileResultMetadata(Arrays.asList(colums), null, null); 75 | flag = false; 76 | try { 77 | metadata.getColumnName(colums.length+1); 78 | } catch (Exception e) { 79 | flag = true; 80 | } 81 | assertEquals(flag, true); 82 | 83 | flag = false; 84 | try { 85 | metadata.getColumnName(0); 86 | } catch (Exception e) { 87 | flag = true; 88 | } 89 | assertEquals(flag, true); 90 | 91 | for(int i = 1; i <= colums.length;i++) { 92 | assertEquals(metadata.getColumnLabel(i), colums[i-1]); 93 | } 94 | 95 | } 96 | 97 | @Test 98 | public void testGetColumnType() throws SQLException { 99 | metadata = new TsfileResultMetadata(null, null, null); 100 | boolean flag = false; 101 | try { 102 | metadata.getColumnType(1); 103 | } catch (Exception e) { 104 | flag = true; 105 | } 106 | assertEquals(flag, true); 107 | 108 | List columnInfoList = new ArrayList<>(); 109 | metadata = new TsfileResultMetadata(columnInfoList, null, null); 110 | flag = false; 111 | try { 112 | metadata.getColumnType(1); 113 | } catch (Exception e) { 114 | flag = true; 115 | } 116 | assertEquals(flag, true); 117 | 118 | String[] columns = {"timestamp", "root.a.b.boolean", "root.a.b.int32", "root.a.b.int64" , "root.a.b.float", "root.a.b.double", "root.a.b.text"}; 119 | String[] typesString = {"BOOLEAN", "INT32", "INT64", "FLOAT", "DOUBLE", "TEXT"}; 120 | int[] types = {Types.BOOLEAN, Types.INTEGER, Types.BIGINT, Types.FLOAT, Types.DOUBLE, Types.VARCHAR}; 121 | metadata = new TsfileResultMetadata(Arrays.asList(columns), null, Arrays.asList(typesString)); 122 | flag = false; 123 | try { 124 | metadata.getColumnType(columns.length+1); 125 | } catch (Exception e) { 126 | flag = true; 127 | } 128 | assertEquals(flag, true); 129 | 130 | flag = false; 131 | try { 132 | metadata.getColumnType(0); 133 | } catch (Exception e) { 134 | flag = true; 135 | } 136 | assertEquals(flag, true); 137 | 138 | assertEquals(metadata.getColumnType(1), Types.TIMESTAMP); 139 | for(int i = 1; i <= types.length; i++) { 140 | assertEquals(metadata.getColumnType(i+1), types[i-1]); 141 | } 142 | } 143 | 144 | @Test 145 | public void testGetColumnTypeName() throws SQLException { 146 | String operationType = "sum"; 147 | metadata = new TsfileResultMetadata(null, operationType, null); 148 | assertEquals(metadata.getColumnTypeName(1), operationType); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileStatementTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.*; 4 | import static org.mockito.Mockito.when; 5 | import static org.mockito.Matchers.any; 6 | 7 | import java.sql.ResultSet; 8 | import java.sql.ResultSetMetaData; 9 | import java.sql.SQLException; 10 | import java.util.ArrayList; 11 | import java.util.HashSet; 12 | import java.util.List; 13 | import java.util.Set; 14 | 15 | import org.apache.thrift.TException; 16 | import org.junit.After; 17 | import org.junit.Assert; 18 | import org.junit.Before; 19 | import org.junit.Test; 20 | import org.mockito.Mock; 21 | import org.mockito.MockitoAnnotations; 22 | 23 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSFetchMetadataReq; 24 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSFetchMetadataResp; 25 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_SessionHandle; 26 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_Status; 27 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_StatusCode; 28 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSIService.Iface; 29 | 30 | public class TsfileStatementTest { 31 | @Mock 32 | private TsfileConnection connection; 33 | 34 | @Mock 35 | private Iface client; 36 | 37 | @Mock 38 | private TS_SessionHandle sessHandle; 39 | 40 | @Mock 41 | private TSFetchMetadataResp fetchMetadataResp; 42 | 43 | private TS_Status Status_SUCCESS = new TS_Status(TS_StatusCode.SUCCESS_STATUS); 44 | 45 | @Before 46 | public void setUp() throws Exception { 47 | MockitoAnnotations.initMocks(this); 48 | when(connection.getMetaData()).thenReturn(new TsfileDatabaseMetadata(connection, client)); 49 | when(connection.isClosed()).thenReturn(false); 50 | when(client.fetchMetadata(any(TSFetchMetadataReq.class))).thenReturn(fetchMetadataResp); 51 | when(fetchMetadataResp.getStatus()).thenReturn(Status_SUCCESS); 52 | } 53 | 54 | @After 55 | public void tearDown() throws Exception { 56 | } 57 | 58 | @SuppressWarnings("resource") 59 | @Test(expected = SQLException.class) 60 | public void testExecuteSQL1() throws SQLException { 61 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 62 | stmt.execute("show timeseries"); 63 | } 64 | 65 | @SuppressWarnings({ "resource", "serial" }) 66 | @Test 67 | public void testExecuteSQL2() throws SQLException, TException { 68 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 69 | List> tslist = new ArrayList<>(); 70 | tslist.add(new ArrayList(4) {{ 71 | add("root.vehicle.d0.s0"); 72 | add("root.vehicle"); 73 | add("INT32"); 74 | add("RLE"); 75 | }}); 76 | tslist.add(new ArrayList(4) {{ 77 | add("root.vehicle.d0.s1"); 78 | add("root.vehicle"); 79 | add("INT64"); 80 | add("RLE"); 81 | }}); 82 | tslist.add(new ArrayList(4) {{ 83 | add("root.vehicle.d0.s2"); 84 | add("root.vehicle"); 85 | add("FLOAT"); 86 | add("RLE"); 87 | }}); 88 | String standard = "Timeseries,Storage Group,DataType,Encoding,\n" + 89 | "root.vehicle.d0.s0,root.vehicle,INT32,RLE,\n" + 90 | "root.vehicle.d0.s1,root.vehicle,INT64,RLE,\n" + 91 | "root.vehicle.d0.s2,root.vehicle,FLOAT,RLE,\n"; 92 | when(fetchMetadataResp.getShowTimeseriesList()).thenReturn(tslist); 93 | boolean res = stmt.execute("show timeseries root"); 94 | assertEquals(res, true); 95 | try { 96 | ResultSet resultSet = stmt.getResultSet(); 97 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 98 | int colCount = resultSetMetaData.getColumnCount(); 99 | StringBuilder resultStr = new StringBuilder(); 100 | for (int i = 1; i < colCount + 1; i++) { 101 | resultStr.append(resultSetMetaData.getColumnName(i)).append(","); 102 | } 103 | resultStr.append("\n"); 104 | while (resultSet.next()) { 105 | for (int i = 1; i <= colCount; i++) { 106 | resultStr.append(resultSet.getString(i)).append(","); 107 | } 108 | resultStr.append("\n"); 109 | } 110 | Assert.assertEquals(resultStr.toString(), standard); 111 | } catch (SQLException e) { 112 | System.out.println(e); 113 | } 114 | } 115 | 116 | @SuppressWarnings({ "resource"}) 117 | @Test 118 | public void testExecuteSQL3() throws SQLException, TException { 119 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 120 | Set sgSet = new HashSet<>(); 121 | sgSet.add("root.vehicle"); 122 | when(fetchMetadataResp.getShowStorageGroups()).thenReturn(sgSet); 123 | String standard = "Storage Group,\nroot.vehicle,\n"; 124 | boolean res = stmt.execute("show storage group"); 125 | assertEquals(res, true); 126 | try { 127 | ResultSet resultSet = stmt.getResultSet(); 128 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 129 | int colCount = resultSetMetaData.getColumnCount(); 130 | StringBuilder resultStr = new StringBuilder(); 131 | for (int i = 1; i < colCount + 1; i++) { 132 | resultStr.append(resultSetMetaData.getColumnName(i)).append(","); 133 | } 134 | resultStr.append("\n"); 135 | while (resultSet.next()) { 136 | for (int i = 1; i <= colCount; i++) { 137 | resultStr.append(resultSet.getString(i)).append(","); 138 | } 139 | resultStr.append("\n"); 140 | } 141 | Assert.assertEquals(resultStr.toString(), standard); 142 | } catch (SQLException e) { 143 | System.out.println(e); 144 | } 145 | } 146 | 147 | @SuppressWarnings("resource") 148 | @Test 149 | public void testSetFetchSize1() throws SQLException { 150 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 151 | stmt.setFetchSize(123); 152 | assertEquals(123, stmt.getFetchSize()); 153 | } 154 | 155 | @SuppressWarnings("resource") 156 | @Test 157 | public void testSetFetchSize2() throws SQLException { 158 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 159 | int initial = stmt.getFetchSize(); 160 | stmt.setFetchSize(0); 161 | assertEquals(initial, stmt.getFetchSize()); 162 | } 163 | 164 | @SuppressWarnings("resource") 165 | @Test 166 | public void testSetFetchSize3() throws SQLException { 167 | final int fetchSize = 10000; 168 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle, fetchSize); 169 | assertEquals(fetchSize, stmt.getFetchSize()); 170 | } 171 | 172 | @SuppressWarnings("resource") 173 | @Test(expected = SQLException.class) 174 | public void testSetFetchSize4() throws SQLException { 175 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 176 | stmt.setFetchSize(-1); 177 | } 178 | 179 | @SuppressWarnings("resource") 180 | @Test 181 | public void testSetMaxRows1() throws SQLException { 182 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 183 | stmt.setMaxRows(123); 184 | assertEquals(123, stmt.getMaxRows()); 185 | } 186 | 187 | @SuppressWarnings("resource") 188 | @Test(expected = SQLException.class) 189 | public void testSetMaxRows2() throws SQLException { 190 | TsfileStatement stmt = new TsfileStatement(connection, client, sessHandle); 191 | stmt.setMaxRows(-1); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/UtilsTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.nio.ByteBuffer; 6 | import java.util.ArrayList; 7 | import java.util.LinkedHashMap; 8 | import java.util.List; 9 | import java.util.Properties; 10 | 11 | import cn.edu.tsinghua.tsfile.timeseries.read.common.Path; 12 | import cn.edu.tsinghua.tsfile.timeseries.read.datatype.RowRecord; 13 | import cn.edu.tsinghua.tsfile.timeseries.read.datatype.TsPrimitiveType; 14 | import org.junit.After; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | 18 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSDataValue; 19 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSQueryDataSet; 20 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TSRowRecord; 21 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_Status; 22 | import cn.edu.tsinghua.iotdb.jdbc.thrift.TS_StatusCode; 23 | import cn.edu.tsinghua.tsfile.file.metadata.enums.TSDataType; 24 | 25 | public class UtilsTest { 26 | 27 | @Before 28 | public void setUp() throws Exception { 29 | } 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | } 34 | 35 | @Test 36 | public void testParseURL() throws TsfileURLException { 37 | String userName = "test"; 38 | String userPwd = "test"; 39 | String host = "localhost"; 40 | int port = 6667; 41 | Properties properties = new Properties(); 42 | properties.setProperty(TsfileJDBCConfig.AUTH_USER, userName); 43 | properties.setProperty(TsfileJDBCConfig.AUTH_PASSWORD, userPwd); 44 | TsfileConnectionParams params = Utils.parseURL(String.format("jdbc:tsfile://%s:%s/", host, port), properties); 45 | assertEquals(params.getHost(), host); 46 | assertEquals(params.getPort(), port); 47 | assertEquals(params.getUsername(), userName); 48 | assertEquals(params.getPassword(), userPwd); 49 | } 50 | 51 | @Test 52 | public void testVerifySuccess() { 53 | try { 54 | Utils.verifySuccess(new TS_Status(TS_StatusCode.SUCCESS_STATUS)); 55 | } catch (Exception e) { 56 | fail(); 57 | } 58 | 59 | try { 60 | Utils.verifySuccess(new TS_Status(TS_StatusCode.ERROR_STATUS)); 61 | } catch (Exception e) { 62 | return; 63 | } 64 | fail(); 65 | } 66 | 67 | @Test 68 | public void testConvertRowRecords() { 69 | final int DATA_TYPE_NUM = 6; 70 | Object[][] input = { 71 | { 72 | 100L, 73 | "sensor1_boolean", TSDataType.BOOLEAN, false, 74 | "sensor1_int32", TSDataType.INT32, 100, 75 | "sensor1_int64", TSDataType.INT64, 9999999999L, 76 | "sensor1_float", TSDataType.FLOAT, 1.23f, 77 | "sensor1_double", TSDataType.DOUBLE, 1004234.435d, 78 | "sensor1_text", TSDataType.TEXT, "iotdb-jdbc", 79 | }, 80 | { 81 | 200L, 82 | "sensor2_boolean", TSDataType.BOOLEAN, true, 83 | "sensor2_int32", TSDataType.INT32, null, 84 | "sensor2_int64", TSDataType.INT64, -9999999999L, 85 | "sensor2_float", TSDataType.FLOAT, null, 86 | "sensor2_double", TSDataType.DOUBLE, -1004234.435d, 87 | "sensor2_text", TSDataType.TEXT, null, 88 | }, 89 | { 90 | 300L, 91 | "sensor3_boolean", TSDataType.BOOLEAN, null, 92 | "sensor3_int32", TSDataType.INT32, -100, 93 | "sensor3_int64", TSDataType.INT64, null, 94 | "sensor3_float", TSDataType.FLOAT, -1.23f, 95 | "sensor3_double", TSDataType.DOUBLE, null, 96 | "sensor3_text", TSDataType.TEXT, "jdbc-iotdb", 97 | }, 98 | }; 99 | TSQueryDataSet tsQueryDataSet = new TSQueryDataSet(new ArrayList<>()); 100 | for(Object[] item: input) { 101 | TSRowRecord record = new TSRowRecord(); 102 | record.setTimestamp((long)item[0]); 103 | List keys = new ArrayList<>(); 104 | List values = new ArrayList<>(); 105 | for(int i = 0; i < DATA_TYPE_NUM;i++) { 106 | keys.add((String)item[3*i+1]); 107 | TSDataValue value = new TSDataValue(false); 108 | if(item[3*i+3] == null) { 109 | value.setIs_empty(true); 110 | } else { 111 | if(i == 0) { 112 | value.setBool_val((boolean)item[3*i+3]); 113 | value.setType(((TSDataType) item[3*i+2]).toString()); 114 | } else if (i == 1) { 115 | value.setInt_val((int) item[3 * i + 3]); 116 | value.setType(((TSDataType) item[3*i+2]).toString()); 117 | } else if (i == 2) { 118 | value.setLong_val((long) item[3 * i + 3]); 119 | value.setType(((TSDataType) item[3*i+2]).toString()); 120 | } else if (i == 3) { 121 | value.setFloat_val((float) item[3 * i + 3]); 122 | value.setType(((TSDataType) item[3*i+2]).toString()); 123 | } else if (i == 4) { 124 | value.setDouble_val((double) item[3 * i + 3]); 125 | value.setType(((TSDataType) item[3*i+2]).toString()); 126 | } else { 127 | value.setBinary_val(ByteBuffer.wrap(((String) item[3*i+3]).getBytes())); 128 | value.setType(((TSDataType) item[3*i+2]).toString()); 129 | } 130 | } 131 | values.add(value); 132 | } 133 | record.setKeys(keys); 134 | record.setValues(values); 135 | tsQueryDataSet.getRecords().add(record); 136 | } 137 | List convertlist = Utils.convertRowRecords(tsQueryDataSet); 138 | int index = 0; 139 | for (RowRecord r : convertlist) { 140 | assertEquals(input[index][0], r.getTimestamp()); 141 | LinkedHashMap fields = r.getFields(); 142 | int j = 0; 143 | for (Path p : fields.keySet()) { 144 | String pString = p.getFullPath(); 145 | assertEquals(input[index][3 * j + 1], pString); 146 | // System.out.println(String.format("%d--%d", index, j)); 147 | if (j == 0) { 148 | if(input[index][3 * j + 3] == null){ 149 | assertEquals(input[index][3 * j + 3], fields.get(p)); 150 | } else { 151 | assertEquals(input[index][3 * j + 3], fields.get(p).getBoolean()); 152 | } 153 | } else if (j == 1) { 154 | if(input[index][3 * j + 3] == null){ 155 | assertEquals(input[index][3 * j + 3], fields.get(p)); 156 | } else { 157 | assertEquals(input[index][3 * j + 3], fields.get(p).getInt()); 158 | } 159 | } else if (j == 2) { 160 | if(input[index][3 * j + 3] == null){ 161 | assertEquals(input[index][3 * j + 3], fields.get(p)); 162 | } else { 163 | assertEquals(input[index][3 * j + 3], fields.get(p).getLong()); 164 | } 165 | } else if (j == 3) { 166 | if(input[index][3 * j + 3] == null){ 167 | assertEquals(input[index][3 * j + 3], fields.get(p)); 168 | } else { 169 | assertEquals(input[index][3 * j + 3], fields.get(p).getFloat()); 170 | } 171 | } else if (j == 4) { 172 | if(input[index][3 * j + 3] == null){ 173 | assertEquals(input[index][3 * j + 3], fields.get(p)); 174 | } else { 175 | assertEquals(input[index][3 * j + 3], fields.get(p).getDouble()); 176 | } 177 | } else { 178 | if(input[index][3 * j + 3] == null){ 179 | assertEquals(input[index][3 * j + 3], fields.get(p)); 180 | } else { 181 | assertEquals(input[index][3 * j + 3], fields.get(p).getStringValue()); 182 | } 183 | } 184 | j++; 185 | } 186 | index++; 187 | } 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/demo/MetadataDemo.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc.demo; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DatabaseMetaData; 5 | import java.sql.DriverManager; 6 | import java.sql.PreparedStatement; 7 | import java.sql.ResultSet; 8 | import java.sql.ResultSetMetaData; 9 | import java.sql.SQLException; 10 | import java.sql.Statement; 11 | import java.sql.Timestamp; 12 | 13 | import cn.edu.tsinghua.iotdb.jdbc.TsfileJDBCConfig; 14 | 15 | public class MetadataDemo { 16 | 17 | public static void main(String[] args) throws ClassNotFoundException, SQLException { 18 | // Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME); 19 | // Connection connection = null; 20 | // try { 21 | // connection = DriverManager.getConnection("jdbc:tsfile://127.0.0.1:6667/", "root", "root"); 22 | // DatabaseMetaData databaseMetaData = connection.getMetaData(); 23 | // } finally { 24 | // connection.close(); 25 | // } 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/demo/PrepareStatementDemo.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc.demo; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.ResultSetMetaData; 8 | import java.sql.SQLException; 9 | import java.sql.Timestamp; 10 | 11 | public class PrepareStatementDemo { 12 | 13 | public static void main(String[] args) throws ClassNotFoundException, SQLException { 14 | Class.forName("cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"); 15 | Connection connection = null; 16 | try { 17 | connection = DriverManager.getConnection("jdbc:tsfile://127.0.0.1:6667/", "root", "root"); 18 | PreparedStatement preparedStatement = connection.prepareStatement("insert into root.ln.wf01.wt01(timestamp,status,temperature) values(?,?,?)"); 19 | preparedStatement.setLong(1, 1509465600000L); 20 | preparedStatement.setBoolean(2, true); 21 | preparedStatement.setFloat(3, 25.957603f); 22 | preparedStatement.execute(); 23 | preparedStatement.clearParameters(); 24 | 25 | preparedStatement.setLong(1, 1509465660000L); 26 | preparedStatement.setBoolean(2, true); 27 | preparedStatement.setFloat(3, 24.359503f); 28 | preparedStatement.execute(); 29 | preparedStatement.clearParameters(); 30 | 31 | preparedStatement.setLong(1, 1509465720000L); 32 | preparedStatement.setBoolean(2, false); 33 | preparedStatement.setFloat(3, 20.092794f); 34 | preparedStatement.execute(); 35 | preparedStatement.clearParameters(); 36 | 37 | preparedStatement.setTimestamp(1, Timestamp.valueOf("2017-11-01 00:03:00")); 38 | preparedStatement.setBoolean(2, false); 39 | preparedStatement.setFloat(3, 20.092794f); 40 | preparedStatement.execute(); 41 | preparedStatement.clearParameters(); 42 | 43 | preparedStatement.close(); 44 | 45 | ResultSet resultSet = preparedStatement.executeQuery("select * from root"); 46 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 47 | while(resultSet.next()){ 48 | StringBuilder builder = new StringBuilder(); 49 | for (int i = 1; i <= resultSetMetaData.getColumnCount();i++) { 50 | builder.append(resultSet.getString(i)).append(","); 51 | } 52 | System.out.println(builder); 53 | } 54 | preparedStatement.close(); 55 | for(int i = 1; i <= resultSetMetaData.getColumnCount();i++) { 56 | System.out.println(resultSetMetaData.getColumnType(i)+"-"+resultSetMetaData.getColumnName(i)); 57 | } 58 | } finally { 59 | connection.close(); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/tsinghua/iotdb/jdbc/demo/StatementDemo.java: -------------------------------------------------------------------------------- 1 | package cn.edu.tsinghua.iotdb.jdbc.demo; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.ResultSet; 6 | import java.sql.ResultSetMetaData; 7 | import java.sql.SQLException; 8 | import java.sql.Statement; 9 | 10 | public class StatementDemo { 11 | 12 | public static void main(String[] args) throws ClassNotFoundException, SQLException { 13 | Class.forName("cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"); 14 | Connection connection = null; 15 | try { 16 | connection = DriverManager.getConnection("jdbc:tsfile://127.0.0.1:6667/", "root", "root"); 17 | Statement statement = connection.createStatement(); 18 | statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt01"); 19 | statement.execute("CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN"); 20 | statement.execute("CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE"); 21 | statement.execute("insert into root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)"); 22 | statement.execute("insert into root.ln.wf01.wt01(timestamp,status) values(1509465660000,true)"); 23 | statement.execute("insert into root.ln.wf01.wt01(timestamp,status) values(1509465720000,false)"); 24 | statement.execute("insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,25.957603)"); 25 | statement.execute("insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465660000,24.359503)"); 26 | statement.execute("insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465720000,20.092794)"); 27 | ResultSet resultSet = statement.executeQuery("select * from root"); 28 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); 29 | while(resultSet.next()){ 30 | StringBuilder builder = new StringBuilder(); 31 | for (int i = 1; i <= resultSetMetaData.getColumnCount();i++) { 32 | builder.append(resultSet.getString(i)).append(","); 33 | } 34 | System.out.println(builder); 35 | } 36 | statement.close(); 37 | 38 | } finally { 39 | connection.close(); 40 | } 41 | } 42 | } 43 | --------------------------------------------------------------------------------