fix reviews

This commit is contained in:
qiaojialin 2019-08-22 18:58:39 +08:00
parent f9a1ab8a3d
commit a098310ec0
10 changed files with 71 additions and 213 deletions

View File

@ -57,7 +57,6 @@ public class IoTDBRowBatch {
columns = new ArrayList<>();
for (int i = 0; i < measurements.size(); i++) {
TSDataValueList dataValueList = new TSDataValueList();
dataValueList.setType(dataTypes.get(i));
switch (dataTypes.get(i)) {
case BOOLEAN:
dataValueList.setBool_vals(new ArrayList<>());

View File

@ -45,13 +45,13 @@ In root directory:
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-client</artifactId>
<version>0.8.0-SNAPSHOT</version>
<version>0.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
## Examples
## Examples without Standard JDBC
This chapter provides an example of how to open an IoTDB session, execute a batch insertion.

View File

@ -19,28 +19,25 @@
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iotdb-examples</artifactId>
<groupId>org.apache.iotdb</groupId>
<version>0.9.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-example</artifactId>
<name>client-example</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-client</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iotdb-examples</artifactId>
<groupId>org.apache.iotdb</groupId>
<version>0.9.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-example</artifactId>
<name>client-example</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-client</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -6,6 +6,16 @@ import org.apache.iotdb.service.rpc.thrift.IoTDBDataType;
import org.apache.iotdb.session.IoTDBRowBatch;
import org.apache.iotdb.session.Session;
/**
* you need to set storage group and create timeseries first from Client or JDBC
*
* for this example:
*
* SET STORAGE GROUP TO root.sg1
* CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=FLOAT, ENCODING=RLE
* CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE
* CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=FLOAT, ENCODING=RLE
*/
public class SessionExample {
public static void main(String[] args) {

View File

@ -1,70 +0,0 @@
package org.apache.iotdb.client;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.service.rpc.thrift.IoTDBDataType;
import org.apache.iotdb.session.IoTDBRowBatch;
import org.apache.iotdb.session.Session;
public class SessionTest {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement();
statement.execute("SET STORAGE GROUP TO root.sg1");
statement.execute("CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=FLOAT, ENCODING=RLE");
statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE");
statement.execute("CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=FLOAT, ENCODING=RLE");
Session session = new Session("127.0.0.1", 6667, "root", "root");
session.open();
List<String> measurements = new ArrayList<>();
measurements.add("s1");
measurements.add("s2");
measurements.add("s3");
List<IoTDBDataType> dataTypes = new ArrayList<>();
dataTypes.add(IoTDBDataType.FLOAT);
dataTypes.add(IoTDBDataType.FLOAT);
dataTypes.add(IoTDBDataType.FLOAT);
List<Object> values = new ArrayList<>();
values.add(1.0f);
values.add(1.0f);
values.add(1.0f);
long total = 0;
for (long i = 0; i < 1000; i++) {
IoTDBRowBatch rowBatch = new IoTDBRowBatch("root.sg1.d1", measurements, dataTypes);
for (long j = 0; j < 100; j++) {
rowBatch.addRow(i * 100 + j, values);
}
long start = System.nanoTime();
session.insertBatch(rowBatch);
total += System.nanoTime() - start;
}
System.out.println("cost: " + total);
session.close();
statement.close();
} finally {
connection.close();
}
}
}

View File

@ -25,7 +25,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
public class StatementTest {
public class StatementExample {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
@ -38,21 +38,23 @@ public class StatementTest {
statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE");
statement.execute("CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=FLOAT, ENCODING=RLE");
long total = 0;
for (int i = 0; i < 1000; i++) {
for (int j = 0 ; j < 100; j++) {
statement.addBatch("insert into root.sg1.d1(timestamp, s1, s2, s3) values("+ (i * 100 + j) + "," + 1.0 + "," + 1.0 + "," + 1.0 + ")");
for (int i = 0; i < 10; i++) {
for (int j = 0 ; j < 10; j++) {
statement.addBatch("insert into root.sg1.d1(timestamp, s1, s2, s3) values("+ (i * 10 + j) + "," + 1.0 + "," + 1.0 + "," + 1.0 + ")");
}
long start = System.nanoTime();
statement.executeBatch();
total += System.nanoTime() - start;
statement.clearBatch();
}
System.out.println("cost: " + total);
ResultSet resultSet = statement.executeQuery("select * from root");
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
while (resultSet.next()) {
StringBuilder builder = new StringBuilder();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
builder.append(resultSet.getString(i)).append(",");
}
System.out.println(builder);
}
statement.close();
} finally {
connection.close();
}

View File

@ -19,32 +19,25 @@
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-examples</artifactId>
<version>0.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-examples</artifactId>
<artifactId>tsfile-example</artifactId>
<version>0.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>tsfile-example</artifactId>
<version>0.9.0-SNAPSHOT</version>
<name>tsfile-example</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>tsfile</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
<name>tsfile-example</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>tsfile</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -1,68 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iotdb.jdbc.demo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
public class StatementDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement();
statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt01");
statement.execute(
"CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN");
statement.execute(
"CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE");
statement
.execute("insert into root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)");
statement
.execute("insert into root.ln.wf01.wt01(timestamp,status) values(1509465660000,true)");
statement
.execute("insert into root.ln.wf01.wt01(timestamp,status) values(1509465720000,false)");
statement.execute(
"insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465600000,25.957603)");
statement.execute(
"insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465660000,24.359503)");
statement.execute(
"insert into root.ln.wf01.wt01(timestamp,temperature) values(1509465720000,20.092794)");
ResultSet resultSet = statement.executeQuery("select * from root");
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
while (resultSet.next()) {
StringBuilder builder = new StringBuilder();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
builder.append(resultSet.getString(i)).append(",");
}
System.out.println(builder);
}
statement.close();
} finally {
connection.close();
}
}
}

View File

@ -92,9 +92,7 @@ public class StorageGroupProcessorTest {
Long[] times = new Long[100];
TSDataValueList[] dataValueLists = new TSDataValueList[2];
dataValueLists[0] = new TSDataValueList();
dataValueLists[0].setType(IoTDBDataType.INT32);
dataValueLists[1] = new TSDataValueList();
dataValueLists[1].setType(IoTDBDataType.INT64);
for (long i = 1; i <= 100; i++) {
times[(int) i-1] = i;
dataValueLists[0].addToInt_vals((int) i);
@ -113,9 +111,7 @@ public class StorageGroupProcessorTest {
times = new Long[100];
dataValueLists = new TSDataValueList[2];
dataValueLists[0] = new TSDataValueList();
dataValueLists[0].setType(IoTDBDataType.INT32);
dataValueLists[1] = new TSDataValueList();
dataValueLists[1].setType(IoTDBDataType.INT64);
for (long i = 50; i <= 149; i++) {
times[(int) i-50] = i;
dataValueLists[0].addToInt_vals((int) i);

View File

@ -202,13 +202,12 @@ struct TSDataValue{
struct TSDataValueList{
1: required IoTDBDataType type
2: optional list<bool> bool_vals
3: optional list<i32> int_vals
4: optional list<i64> long_vals
5: optional list<double> float_vals
6: optional list<double> double_vals
7: optional list<binary> binary_vals
1: optional list<bool> bool_vals
2: optional list<i32> int_vals
3: optional list<i64> long_vals
4: optional list<double> float_vals
5: optional list<double> double_vals
6: optional list<binary> binary_vals
}
struct TSRowRecord{