Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
b3b7417e
I
Iotdb
项目概览
apache
/
Iotdb
11 个月 前同步成功
通知
25
Star
3344
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iotdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b3b7417e
编写于
9月 02, 2019
作者:
Q
qiaojialin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add insertRow interface
上级
6c4e432c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
144 addition
and
26 deletion
+144
-26
docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md
...ocumentation-CHN/UserGuide/7-Session API/1-Session API.md
+35
-11
docs/Documentation/UserGuide/7-Session API/1-Session API.md
docs/Documentation/UserGuide/7-Session API/1-Session API.md
+35
-12
example/session/src/main/java/org/apache/iotdb/SessionExample.java
...ession/src/main/java/org/apache/iotdb/SessionExample.java
+28
-3
server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
.../main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+21
-0
service-rpc/src/main/thrift/rpc.thrift
service-rpc/src/main/thrift/rpc.thrift
+9
-0
session/src/main/java/org/apache/iotdb/session/Session.java
session/src/main/java/org/apache/iotdb/session/Session.java
+16
-0
未找到文件。
docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md
浏览文件 @
b3b7417e
...
...
@@ -49,10 +49,11 @@ In root directory:
```
Java
import java.
sql.Connection
;
import java.
sql.DriverManager
;
import
java.sql.Statement
;
import java.
util.ArrayList
;
import java.
util.List
;
import
org.apache.iotdb.session.IoTDBSessionException
;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.write.record.RowBatch;
...
...
@@ -61,15 +62,39 @@ import org.apache.iotdb.tsfile.write.schema.Schema;
public class SessionExample {
public static void main(String[] args) throws ClassNotFoundException, IoTDBSessionException {
Session session = new Session("127.0.0.1", 6667, "root", "root");
private static Session session;
public static void main(String[] args) throws IoTDBSessionException {
session = new Session("127.0.0.1", 6667, "root", "root");
session.open();
session.setStorageGroup("root.sg1");
session.createTimeseriesResp("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE);
session.createTimeseriesResp("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE);
session.createTimeseriesResp("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE);
session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
insert();
// insertRowBatch();
session.close();
}
private static void insert() throws IoTDBSessionException {
String deviceId = "root.sg1.d1";
List<String> measurements = new ArrayList<>();
measurements.add("s1");
measurements.add("s2");
measurements.add("s3");
for (long time = 0; time < 30000; time++) {
List<String> values = new ArrayList<>();
values.add("1");
values.add("2");
values.add("3");
session.insert(deviceId, time, measurements, values);
}
}
private static void insertRowBatch() throws IoTDBSessionException {
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE));
...
...
@@ -85,7 +110,7 @@ public class SessionExample {
timestamps[row] = time;
for (int i = 0; i < 3; i++) {
long[] sensor = (long[]) values[i];
sensor[row] =
time
;
sensor[row] =
i
;
}
if (rowBatch.batchSize == rowBatch.getMaxBatchSize()) {
session.insertBatch(rowBatch);
...
...
@@ -97,7 +122,6 @@ public class SessionExample {
session.insertBatch(rowBatch);
rowBatch.reset();
}
session.close();
}
}
```
...
...
docs/Documentation/UserGuide/7-Session API/1-Session API.md
浏览文件 @
b3b7417e
...
...
@@ -58,10 +58,11 @@ This chapter provides an example of how to open an IoTDB session, execute a batc
Requires that you include the packages containing the Client classes needed for database programming.
```
Java
import java.
sql.Connection
;
import java.
sql.DriverManager
;
import
java.sql.Statement
;
import java.
util.ArrayList
;
import java.
util.List
;
import
org.apache.iotdb.session.IoTDBSessionException
;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.write.record.RowBatch;
...
...
@@ -70,15 +71,39 @@ import org.apache.iotdb.tsfile.write.schema.Schema;
public class SessionExample {
public static void main(String[] args) throws ClassNotFoundException, IoTDBSessionException {
Session session = new Session("127.0.0.1", 6667, "root", "root");
private static Session session;
public static void main(String[] args) throws IoTDBSessionException {
session = new Session("127.0.0.1", 6667, "root", "root");
session.open();
session.setStorageGroup("root.sg1");
session.createTimeseriesResp("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE);
session.createTimeseriesResp("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE);
session.createTimeseriesResp("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE);
session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
insert();
// insertRowBatch();
session.close();
}
private static void insert() throws IoTDBSessionException {
String deviceId = "root.sg1.d1";
List<String> measurements = new ArrayList<>();
measurements.add("s1");
measurements.add("s2");
measurements.add("s3");
for (long time = 0; time < 30000; time++) {
List<String> values = new ArrayList<>();
values.add("1");
values.add("2");
values.add("3");
session.insert(deviceId, time, measurements, values);
}
}
private static void insertRowBatch() throws IoTDBSessionException {
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE));
...
...
@@ -94,7 +119,7 @@ public class SessionExample {
timestamps[row] = time;
for (int i = 0; i < 3; i++) {
long[] sensor = (long[]) values[i];
sensor[row] =
time
;
sensor[row] =
i
;
}
if (rowBatch.batchSize == rowBatch.getMaxBatchSize()) {
session.insertBatch(rowBatch);
...
...
@@ -106,8 +131,6 @@ public class SessionExample {
session.insertBatch(rowBatch);
rowBatch.reset();
}
session.close();
}
}
```
...
...
example/session/src/main/java/org/apache/iotdb/SessionExample.java
浏览文件 @
b3b7417e
...
...
@@ -18,6 +18,8 @@
*/
package
org.apache.iotdb
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.iotdb.session.IoTDBSessionException
;
import
org.apache.iotdb.session.Session
;
import
org.apache.iotdb.tsfile.file.metadata.enums.CompressionType
;
...
...
@@ -29,8 +31,10 @@ import org.apache.iotdb.tsfile.write.schema.Schema;
public
class
SessionExample
{
private
static
Session
session
;
public
static
void
main
(
String
[]
args
)
throws
IoTDBSessionException
{
Session
session
=
new
Session
(
"127.0.0.1"
,
6667
,
"root"
,
"root"
);
session
=
new
Session
(
"127.0.0.1"
,
6667
,
"root"
,
"root"
);
session
.
open
();
session
.
setStorageGroup
(
"root.sg1"
);
...
...
@@ -38,6 +42,28 @@ public class SessionExample {
session
.
createTimeseries
(
"root.sg1.d1.s2"
,
TSDataType
.
INT64
,
TSEncoding
.
RLE
,
CompressionType
.
SNAPPY
);
session
.
createTimeseries
(
"root.sg1.d1.s3"
,
TSDataType
.
INT64
,
TSEncoding
.
RLE
,
CompressionType
.
SNAPPY
);
insert
();
// insertRowBatch();
session
.
close
();
}
private
static
void
insert
()
throws
IoTDBSessionException
{
String
deviceId
=
"root.sg1.d1"
;
List
<
String
>
measurements
=
new
ArrayList
<>();
measurements
.
add
(
"s1"
);
measurements
.
add
(
"s2"
);
measurements
.
add
(
"s3"
);
for
(
long
time
=
0
;
time
<
30000
;
time
++)
{
List
<
String
>
values
=
new
ArrayList
<>();
values
.
add
(
"1"
);
values
.
add
(
"2"
);
values
.
add
(
"3"
);
session
.
insert
(
deviceId
,
time
,
measurements
,
values
);
}
}
private
static
void
insertRowBatch
()
throws
IoTDBSessionException
{
Schema
schema
=
new
Schema
();
schema
.
registerMeasurement
(
new
MeasurementSchema
(
"s1"
,
TSDataType
.
INT64
,
TSEncoding
.
RLE
));
schema
.
registerMeasurement
(
new
MeasurementSchema
(
"s2"
,
TSDataType
.
INT64
,
TSEncoding
.
RLE
));
...
...
@@ -53,7 +79,7 @@ public class SessionExample {
timestamps
[
row
]
=
time
;
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
long
[]
sensor
=
(
long
[])
values
[
i
];
sensor
[
row
]
=
time
;
sensor
[
row
]
=
i
;
}
if
(
rowBatch
.
batchSize
==
rowBatch
.
getMaxBatchSize
())
{
session
.
insertBatch
(
rowBatch
);
...
...
@@ -65,6 +91,5 @@ public class SessionExample {
session
.
insertBatch
(
rowBatch
);
rowBatch
.
reset
();
}
session
.
close
();
}
}
\ No newline at end of file
server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
浏览文件 @
b3b7417e
...
...
@@ -930,6 +930,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
@Override
public
TSExecuteStatementResp
insert
(
TSInsertionReq
req
)
{
// TODO need to refactor this when implementing PreparedStatement
if
(!
checkLogin
())
{
logger
.
info
(
INFO_NOT_LOGIN
,
IoTDBConstant
.
GLOBAL_DB_NAME
);
return
getTSExecuteStatementResp
(
getStatus
(
TSStatusType
.
NOT_LOGIN_ERROR
));
...
...
@@ -960,6 +961,26 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
}
}
@Override
public
TSRPCResp
insertRow
(
TSInsertReq
req
)
throws
TException
{
if
(!
checkLogin
())
{
logger
.
info
(
INFO_NOT_LOGIN
,
IoTDBConstant
.
GLOBAL_DB_NAME
);
return
new
TSRPCResp
(
getStatus
(
TSStatusType
.
NOT_LOGIN_ERROR
));
}
InsertPlan
plan
=
new
InsertPlan
();
plan
.
setDeviceId
(
req
.
getDeviceId
());
plan
.
setTime
(
req
.
getTimestamp
());
plan
.
setMeasurements
(
req
.
getMeasurements
().
toArray
(
new
String
[
0
]));
plan
.
setValues
(
req
.
getValues
().
toArray
(
new
String
[
0
]));
TS_Status
status
=
checkAuthority
(
plan
);
if
(
status
!=
null
)
{
return
new
TSRPCResp
(
status
);
}
return
new
TSRPCResp
(
executePlan
(
plan
));
}
@Override
public
TSExecuteBatchStatementResp
insertBatch
(
TSBatchInsertionReq
req
)
{
long
t1
=
System
.
currentTimeMillis
();
...
...
service-rpc/src/main/thrift/rpc.thrift
浏览文件 @
b3b7417e
...
...
@@ -236,6 +236,13 @@ struct TSBatchInsertionReq {
6: required i32 size
}
struct TSInsertReq {
1: required string deviceId
2: required list<string> measurements
3: required list<string> values
4: required i64 timestamp
}
struct TSSetStorageGroupReq {
1: required string storageGroupId
}
...
...
@@ -292,5 +299,7 @@ service TSIService {
TSRPCResp createTimeseries(1:TSCreateTimeseriesReq req);
TSRPCResp insertRow(1:TSInsertReq req);
i64 requestStatementId();
}
session/src/main/java/org/apache/iotdb/session/Session.java
浏览文件 @
b3b7417e
...
...
@@ -18,6 +18,7 @@
*/
package
org.apache.iotdb.session
;
import
java.util.List
;
import
org.apache.iotdb.rpc.IoTDBRPCException
;
import
org.apache.iotdb.rpc.RpcUtils
;
import
org.apache.iotdb.service.rpc.thrift.*
;
...
...
@@ -156,6 +157,21 @@ public class Session {
}
}
public
TSRPCResp
insert
(
String
deviceId
,
long
time
,
List
<
String
>
measurements
,
List
<
String
>
values
)
throws
IoTDBSessionException
{
TSInsertReq
request
=
new
TSInsertReq
();
request
.
setDeviceId
(
deviceId
);
request
.
setTimestamp
(
time
);
request
.
setMeasurements
(
measurements
);
request
.
setValues
(
values
);
try
{
return
client
.
insertRow
(
request
);
}
catch
(
TException
e
)
{
throw
new
IoTDBSessionException
(
e
);
}
}
public
TSRPCResp
setStorageGroup
(
String
storageGroupId
)
throws
IoTDBSessionException
{
TSSetStorageGroupReq
request
=
new
TSSetStorageGroupReq
();
request
.
setStorageGroupId
(
storageGroupId
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录