Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3e024c8e
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3e024c8e
编写于
8月 16, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
8月 16, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3086 from taosdata/develop
Merge from develop into master
上级
30bccbd7
f89e0168
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
79 deletion
+55
-79
cmake/define.inc
cmake/define.inc
+3
-5
documentation20/webdocs/markdowndocs/advanced features-ch.md
documentation20/webdocs/markdowndocs/advanced features-ch.md
+43
-68
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+7
-4
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+2
-2
未找到文件。
cmake/define.inc
浏览文件 @
3e024c8e
...
...
@@ -33,11 +33,7 @@ IF (TD_LINUX_64)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_TD_LINUX_64
)
SET
(
COMMON_FLAGS
"-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
FIND_PATH
(
ICONV_INCLUDE_EXIST
iconv
.
h
/
usr
/
include
/
/
usr
/
local
/
include
/
)
IF
(
ICONV_INCLUDE_EXIST
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
ENDIF
()
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
ENDIF
()
IF
(
TD_LINUX_32
)
...
...
@@ -50,6 +46,7 @@ IF (TD_ARM_64)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_TD_ARM_64_
)
ADD_DEFINITIONS
(
-
D_TD_ARM_
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
SET
(
COMMON_FLAGS
"-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
...
...
@@ -133,6 +130,7 @@ ENDIF ()
IF
(
TD_WINDOWS_32
)
ADD_DEFINITIONS
(
-
D_TD_WINDOWS_32
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
ENDIF
()
INCLUDE_DIRECTORIES
(
$
{
TD_COMMUNITY_DIR
}
/
src
/
inc
)
...
...
documentation20/webdocs/markdowndocs/advanced features-ch.md
浏览文件 @
3e024c8e
...
...
@@ -295,27 +295,30 @@ $ taos
这时,因为电流超过了10A,您应该可以看到示例程序将它输出到了屏幕上。
您可以继续插入一些数据观察示例程序的输出。
###
jdbc
使用数据订阅功能
###
Java
使用数据订阅功能
(1)使用订阅功能前的数据准备
订阅功能也提供了 Java 开发接口,相关说明请见
[
Java Connector
](
https://www.taosdata.com/cn/documentation20/connector/
)
。需要注意的是,目前 Java 接口没有提供异步订阅模式,但用户程序可以通过创建
`TimerTask`
等方式达到同样的效果。
```
shell
# 创建power库
下面以一个示例程序介绍其具体使用方法。它所完成的功能与前面介绍的 C 语言示例基本相同,也是订阅数据库中所有电流超过 10A 的记录。
#### 准备数据
```
sql
#
创建
power
库
taos
>
create
database
power
;
#
切换库
taos
>
use
power
;
#
创建超级表
taos> create table meters
(
ts timestamp, current float, voltage int, phase int
)
tags
(
location binary
(
64
)
, groupI
d int
)
;
taos
>
create
table
meters
(
ts
timestamp
,
current
float
,
voltage
int
,
phase
int
)
tags
(
location
binary
(
64
),
groupId
int
);
#
创建表
taos> create table d1001 using meters tags
(
"Beijing.Chaoyang"
,2
)
;
taos> create table d1002 using meters tags
(
"Beijing.Haidian"
,2
)
;
taos
>
create
table
d1001
using
meters
tags
(
"Beijing.Chaoyang"
,
2
);
taos
>
create
table
d1002
using
meters
tags
(
"Beijing.Haidian"
,
2
);
#
插入测试数据
taos
>
insert
into
d1001
values
(
"2020-08-15 12:00:00.000"
,
12
,
220
,
1
),(
"2020-08-15 12:10:00.000"
,
12
.
3
,
220
,
2
),(
"2020-08-15 12:20:00.000"
,
12
.
2
,
220
,
1
);
taos
>
insert
into
d1002
values
(
"2020-08-15 12:00:00.000"
,
9
.
9
,
220
,
1
),(
"2020-08-15 12:10:00.000"
,
10
.
3
,
220
,
1
),(
"2020-08-15 12:20:00.000"
,
11
.
2
,
220
,
1
);
# 从超级表
meters查询current大于10的数据
#
从超级表
meters
查询电流大于
10
A
的记录
taos
>
select
*
from
meters
where
current
>
10
;
ts | current | voltage | phase|
location | groupid |
ts
|
current
|
voltage
|
phase
|
location
|
groupid
|
===========================================================================================================
2020
-
08
-
15
12
:
10
:
00
.
000
|
10
.
30000
|
220
|
1
|
Beijing
.
Haidian
|
2
|
2020
-
08
-
15
12
:
20
:
00
.
000
|
11
.
20000
|
220
|
1
|
Beijing
.
Haidian
|
2
|
...
...
@@ -325,70 +328,50 @@ taos> select * from meters where current > 10;
Query
OK
,
5
row
(
s
)
in
set
(
0
.
004896
s
)
```
(2)使用jdbc提供的订阅功能
#### 示例程序
```
java
public
class
SubscribeDemo
{
private
static
final
String
topic
=
"topic
_meter_current_bg_
10"
;
private
static
final
String
topic
=
"topic
-meter-current-bg-
10"
;
private
static
final
String
sql
=
"select * from meters where current > 10"
;
public
static
void
main
(
String
[]
args
)
{
Connection
connection
=
null
;
Statement
statement
=
null
;
TSDBSubscribe
subscribe
=
null
;
long
subscribeId
=
0
;
try
{
// 加载驱动
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
// 获取Connectin
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
String
jdbcUrl
=
"jdbc:TAOS://127.0.0.1:6030/power?user=root&password=taosdata"
;
connection
=
DriverManager
.
getConnection
(
jdbcUrl
,
properties
);
System
.
out
.
println
(
"create the connection"
);
// 创建Subscribe
subscribe
=
((
TSDBConnection
)
connection
).
createSubscribe
();
// subscribe订阅topic,topic为主题名称,sql为查询语句,restart代表是否每次订阅接受历史数据
subscribeId
=
subscribe
.
subscribe
(
topic
,
sql
,
true
);
System
.
out
.
println
(
"create a subscribe topic: "
+
topic
+
"@["
+
subscribeId
+
"]"
);
subscribe
=
((
TSDBConnection
)
connection
).
subscribe
(
topic
,
sql
,
true
);
// 创建订阅
int
count
=
0
;
while
(
true
)
{
// 消费数据
TSDBResultSet
resultSet
=
subscribe
.
consume
(
subscribeId
);
// 打印结果集
if
(
resultSet
!=
null
)
{
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
while
(
resultSet
.
next
())
{
int
columnCount
=
metaData
.
getColumnCount
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
" : "
+
resultSet
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
(
"\n===================="
);
count
++;
while
(
count
<
10
)
{
TimeUnit
.
SECONDS
.
sleep
(
1
);
// 等待1秒,避免频繁调用 consume,给服务端造成压力
TSDBResultSet
resultSet
=
subscribe
.
consume
();
// 消费数据
if
(
resultSet
==
null
)
{
continue
;
}
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
while
(
resultSet
.
next
())
{
int
columnCount
=
metaData
.
getColumnCount
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
": "
+
resultSet
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
count
++;
}
if
(
count
>
10
)
break
;
TimeUnit
.
SECONDS
.
sleep
(
1
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
null
!=
subscribe
&&
subscribeId
!=
0
)
{
subscribe
.
unsubscribe
(
subscribeId
,
true
);
System
.
out
.
println
(
"unsubscribe the top@["
+
subscribeId
+
"]"
);
}
if
(
statement
!=
null
)
{
statement
.
close
();
System
.
out
.
println
(
"close the statement."
);
}
if
(
connection
!=
null
)
{
connection
.
close
();
System
.
out
.
println
(
"close the connection."
);
}
if
(
null
!=
subscribe
)
subscribe
.
close
(
true
);
// 关闭订阅
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
throwables
)
{
throwables
.
printStackTrace
();
}
...
...
@@ -397,38 +380,30 @@ public class SubscribeDemo {
}
```
(3)订阅功能演示
运行demo,首先,subscribe会将满足情况的历史数据消费
运行示例程序,首先,它会消费符合查询条件的所有历史数据:
```
shell
# java -jar subscribe.jar
ts : 1597464000000 current : 12.0 voltage : 220 phase : 1 location : Beijing.Chaoyang groupid : 2
====================
ts : 1597464600000 current : 12.3 voltage : 220 phase : 2 location : Beijing.Chaoyang groupid : 2
====================
ts : 1597465200000 current : 12.2 voltage : 220 phase : 1 location : Beijing.Chaoyang groupid : 2
====================
ts : 1597464600000 current : 10.3 voltage : 220 phase : 1 location : Beijing.Haidian groupid : 2
====================
ts : 1597465200000 current : 11.2 voltage : 220 phase : 1 location : Beijing.Haidian groupid : 2
====================
ts: 1597464000000 current: 12.0 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid : 2
ts: 1597464600000 current: 12.3 voltage: 220 phase: 2 location: Beijing.Chaoyang groupid : 2
ts: 1597465200000 current: 12.2 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid : 2
ts: 1597464600000 current: 10.3 voltage: 220 phase: 1 location: Beijing.Haidian groupid : 2
ts: 1597465200000 current: 11.2 voltage: 220 phase: 1 location: Beijing.Haidian groupid : 2
```
接着,使用
taos客户端向表中新增数据
接着,使用
taos 客户端向表中新增一条数据:
```
s
hel
l
```
s
q
l
#
taos
taos
>
use
power
;
taos
>
insert
into
d1001
values
(
"2020-08-15 12:40:00.000"
,
12
.
4
,
220
,
1
);
```
查看数据消费情况
因为这条数据的电流大于10A,示例程序会将其消费:
```
shell
ts : 1597466400000 current : 12.4 voltage : 220 phase : 1 location : Beijing.Chaoyang groupid : 2
====================
ts: 1597466400000 current: 12.4 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid: 2
```
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
3e024c8e
...
...
@@ -1795,19 +1795,22 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
if
(
pQueryHandle
->
checkFiles
)
{
bool
exists
=
true
;
int32_t
code
=
getDataBlocksInFiles
(
pQueryHandle
,
&
exists
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
pQueryHandle
->
activeIndex
=
0
;
pQueryHandle
->
checkFiles
=
false
;
return
false
;
}
if
(
exists
)
{
elapsedTime
=
taosGetTimestampUs
()
-
stime
;
pQueryHandle
->
cost
.
checkForNextTime
+=
elapsedTime
;
pQueryHandle
->
cost
.
checkForNextTime
+=
(
taosGetTimestampUs
()
-
stime
);
return
exists
;
}
pQueryHandle
->
activeIndex
=
0
;
pQueryHandle
->
checkFiles
=
false
;
pQueryHandle
->
checkFiles
=
false
;
}
// TODO: opt by consider the scan order
...
...
tests/script/jenkins/basic.txt
浏览文件 @
3e024c8e
...
...
@@ -135,7 +135,6 @@ cd ../../../debug; make
./test.sh -f general/parser/limit2.sim
./test.sh -f general/parser/fill.sim
./test.sh -f general/parser/fill_stb.sim
#./test.sh -f general/parser/fill_us.sim
./test.sh -f general/parser/where.sim
./test.sh -f general/parser/slimit.sim
./test.sh -f general/parser/select_with_tags.sim
...
...
@@ -143,7 +142,6 @@ cd ../../../debug; make
./test.sh -f general/parser/tags_dynamically_specifiy.sim
./test.sh -f general/parser/groupby.sim
./test.sh -f general/parser/set_tag_vals.sim
#./test.sh -f general/parser/sliding.sim
./test.sh -f general/parser/tags_filter.sim
./test.sh -f general/parser/slimit_alter_tags.sim
./test.sh -f general/parser/join.sim
...
...
@@ -151,6 +149,8 @@ cd ../../../debug; make
./test.sh -f general/parser/binary_escapeCharacter.sim
./test.sh -f general/parser/bug.sim
./test.sh -f general/parser/repeatAlter.sim
./test.sh -f general/parser/union.sim
./test.sh -f general/parser/topbot.sim
./test.sh -f general/stable/disk.sim
./test.sh -f general/stable/dnode3.sim
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录