Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
adminstrot
TDengine
提交
3e024c8e
TDengine
项目概览
adminstrot
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
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)
...
@@ -33,11 +33,7 @@ IF (TD_LINUX_64)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_TD_LINUX_64
)
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"
)
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
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
ENDIF
()
ENDIF
()
ENDIF
()
IF
(
TD_LINUX_32
)
IF
(
TD_LINUX_32
)
...
@@ -50,6 +46,7 @@ IF (TD_ARM_64)
...
@@ -50,6 +46,7 @@ IF (TD_ARM_64)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_TD_ARM_64_
)
ADD_DEFINITIONS
(
-
D_TD_ARM_64_
)
ADD_DEFINITIONS
(
-
D_TD_ARM_
)
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"
)
SET
(
COMMON_FLAGS
"-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
ENDIF
()
...
@@ -133,6 +130,7 @@ ENDIF ()
...
@@ -133,6 +130,7 @@ ENDIF ()
IF
(
TD_WINDOWS_32
)
IF
(
TD_WINDOWS_32
)
ADD_DEFINITIONS
(
-
D_TD_WINDOWS_32
)
ADD_DEFINITIONS
(
-
D_TD_WINDOWS_32
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
ENDIF
()
ENDIF
()
INCLUDE_DIRECTORIES
(
$
{
TD_COMMUNITY_DIR
}
/
src
/
inc
)
INCLUDE_DIRECTORIES
(
$
{
TD_COMMUNITY_DIR
}
/
src
/
inc
)
...
...
documentation20/webdocs/markdowndocs/advanced features-ch.md
浏览文件 @
3e024c8e
...
@@ -295,27 +295,30 @@ $ taos
...
@@ -295,27 +295,30 @@ $ taos
这时,因为电流超过了10A,您应该可以看到示例程序将它输出到了屏幕上。
这时,因为电流超过了10A,您应该可以看到示例程序将它输出到了屏幕上。
您可以继续插入一些数据观察示例程序的输出。
您可以继续插入一些数据观察示例程序的输出。
###
jdbc
使用数据订阅功能
###
Java
使用数据订阅功能
(1)使用订阅功能前的数据准备
订阅功能也提供了 Java 开发接口,相关说明请见
[
Java Connector
](
https://www.taosdata.com/cn/documentation20/connector/
)
。需要注意的是,目前 Java 接口没有提供异步订阅模式,但用户程序可以通过创建
`TimerTask`
等方式达到同样的效果。
```
shell
下面以一个示例程序介绍其具体使用方法。它所完成的功能与前面介绍的 C 语言示例基本相同,也是订阅数据库中所有电流超过 10A 的记录。
# 创建power库
#### 准备数据
```
sql
#
创建
power
库
taos
>
create
database
power
;
taos
>
create
database
power
;
#
切换库
#
切换库
taos
>
use
power
;
taos
>
use
power
;
#
创建超级表
#
创建超级表
taos> create table meters
(
ts timestamp, current float, voltage int, phase int
)
tags
(
location binary
(
64
)
, groupI
taos
>
create
table
meters
(
ts
timestamp
,
current
float
,
voltage
int
,
phase
int
)
tags
(
location
binary
(
64
),
groupId
int
);
d int
)
;
#
创建表
#
创建表
taos> create table d1001 using meters tags
(
"Beijing.Chaoyang"
,2
)
;
taos
>
create
table
d1001
using
meters
tags
(
"Beijing.Chaoyang"
,
2
);
taos> create table d1002 using meters tags
(
"Beijing.Haidian"
,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
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
);
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
;
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
:
10
:
00
.
000
|
10
.
30000
|
220
|
1
|
Beijing
.
Haidian
|
2
|
2020
-
08
-
15
12
:
20
:
00
.
000
|
11
.
20000
|
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;
...
@@ -325,70 +328,50 @@ taos> select * from meters where current > 10;
Query
OK
,
5
row
(
s
)
in
set
(
0
.
004896
s
)
Query
OK
,
5
row
(
s
)
in
set
(
0
.
004896
s
)
```
```
(2)使用jdbc提供的订阅功能
#### 示例程序
```
java
```
java
public
class
SubscribeDemo
{
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"
;
private
static
final
String
sql
=
"select * from meters where current > 10"
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Connection
connection
=
null
;
Connection
connection
=
null
;
Statement
statement
=
null
;
TSDBSubscribe
subscribe
=
null
;
TSDBSubscribe
subscribe
=
null
;
long
subscribeId
=
0
;
try
{
try
{
// 加载驱动
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
// 获取Connectin
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
String
jdbcUrl
=
"jdbc:TAOS://127.0.0.1:6030/power?user=root&password=taosdata"
;
String
jdbcUrl
=
"jdbc:TAOS://127.0.0.1:6030/power?user=root&password=taosdata"
;
connection
=
DriverManager
.
getConnection
(
jdbcUrl
,
properties
);
connection
=
DriverManager
.
getConnection
(
jdbcUrl
,
properties
);
System
.
out
.
println
(
"create the connection"
);
subscribe
=
((
TSDBConnection
)
connection
).
subscribe
(
topic
,
sql
,
true
);
// 创建订阅
// 创建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
+
"]"
);
int
count
=
0
;
int
count
=
0
;
while
(
true
)
{
while
(
count
<
10
)
{
// 消费数据
TimeUnit
.
SECONDS
.
sleep
(
1
);
// 等待1秒,避免频繁调用 consume,给服务端造成压力
TSDBResultSet
resultSet
=
subscribe
.
consume
(
subscribeId
);
TSDBResultSet
resultSet
=
subscribe
.
consume
();
// 消费数据
// 打印结果集
if
(
resultSet
==
null
)
{
if
(
resultSet
!=
null
)
{
continue
;
}
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
while
(
resultSet
.
next
())
{
while
(
resultSet
.
next
())
{
int
columnCount
=
metaData
.
getColumnCount
();
int
columnCount
=
metaData
.
getColumnCount
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
"
: "
+
resultSet
.
getString
(
i
)
+
"\t"
);
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
"
: "
+
resultSet
.
getString
(
i
)
+
"\t"
);
}
}
System
.
out
.
println
(
"\n===================="
);
System
.
out
.
println
(
);
count
++;
count
++;
}
}
}
}
if
(
count
>
10
)
break
;
TimeUnit
.
SECONDS
.
sleep
(
1
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
try
{
try
{
if
(
null
!=
subscribe
&&
subscribeId
!=
0
)
{
if
(
null
!=
subscribe
)
subscribe
.
unsubscribe
(
subscribeId
,
true
);
subscribe
.
close
(
true
);
// 关闭订阅
System
.
out
.
println
(
"unsubscribe the top@["
+
subscribeId
+
"]"
);
if
(
connection
!=
null
)
}
if
(
statement
!=
null
)
{
statement
.
close
();
System
.
out
.
println
(
"close the statement."
);
}
if
(
connection
!=
null
)
{
connection
.
close
();
connection
.
close
();
System
.
out
.
println
(
"close the connection."
);
}
}
catch
(
SQLException
throwables
)
{
}
catch
(
SQLException
throwables
)
{
throwables
.
printStackTrace
();
throwables
.
printStackTrace
();
}
}
...
@@ -397,38 +380,30 @@ public class SubscribeDemo {
...
@@ -397,38 +380,30 @@ public class SubscribeDemo {
}
}
```
```
(3)订阅功能演示
运行示例程序,首先,它会消费符合查询条件的所有历史数据:
运行demo,首先,subscribe会将满足情况的历史数据消费
```
shell
```
shell
# java -jar subscribe.jar
# java -jar subscribe.jar
ts : 1597464000000 current : 12.0 voltage : 220 phase : 1 location : Beijing.Chaoyang 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 : 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 : 12.2 voltage : 220 phase : 1 location : Beijing.Chaoyang groupid : 2
ts: 1597465200000 current: 11.2 voltage: 220 phase: 1 location: Beijing.Haidian 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
taos
>
use
power
;
taos
>
use
power
;
taos
>
insert
into
d1001
values
(
"2020-08-15 12:40:00.000"
,
12
.
4
,
220
,
1
);
taos
>
insert
into
d1001
values
(
"2020-08-15 12:40:00.000"
,
12
.
4
,
220
,
1
);
```
```
查看数据消费情况
因为这条数据的电流大于10A,示例程序会将其消费:
```
shell
```
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,14 +1795,17 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
...
@@ -1795,14 +1795,17 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
if
(
pQueryHandle
->
checkFiles
)
{
if
(
pQueryHandle
->
checkFiles
)
{
bool
exists
=
true
;
bool
exists
=
true
;
int32_t
code
=
getDataBlocksInFiles
(
pQueryHandle
,
&
exists
);
int32_t
code
=
getDataBlocksInFiles
(
pQueryHandle
,
&
exists
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
pQueryHandle
->
activeIndex
=
0
;
pQueryHandle
->
checkFiles
=
false
;
return
false
;
}
}
if
(
exists
)
{
if
(
exists
)
{
elapsedTime
=
taosGetTimestampUs
()
-
stime
;
pQueryHandle
->
cost
.
checkForNextTime
+=
(
taosGetTimestampUs
()
-
stime
);
pQueryHandle
->
cost
.
checkForNextTime
+=
elapsedTime
;
return
exists
;
return
exists
;
}
}
...
...
tests/script/jenkins/basic.txt
浏览文件 @
3e024c8e
...
@@ -135,7 +135,6 @@ cd ../../../debug; make
...
@@ -135,7 +135,6 @@ cd ../../../debug; make
./test.sh -f general/parser/limit2.sim
./test.sh -f general/parser/limit2.sim
./test.sh -f general/parser/fill.sim
./test.sh -f general/parser/fill.sim
./test.sh -f general/parser/fill_stb.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/where.sim
./test.sh -f general/parser/slimit.sim
./test.sh -f general/parser/slimit.sim
./test.sh -f general/parser/select_with_tags.sim
./test.sh -f general/parser/select_with_tags.sim
...
@@ -143,7 +142,6 @@ cd ../../../debug; make
...
@@ -143,7 +142,6 @@ cd ../../../debug; make
./test.sh -f general/parser/tags_dynamically_specifiy.sim
./test.sh -f general/parser/tags_dynamically_specifiy.sim
./test.sh -f general/parser/groupby.sim
./test.sh -f general/parser/groupby.sim
./test.sh -f general/parser/set_tag_vals.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/tags_filter.sim
./test.sh -f general/parser/slimit_alter_tags.sim
./test.sh -f general/parser/slimit_alter_tags.sim
./test.sh -f general/parser/join.sim
./test.sh -f general/parser/join.sim
...
@@ -151,6 +149,8 @@ cd ../../../debug; make
...
@@ -151,6 +149,8 @@ cd ../../../debug; make
./test.sh -f general/parser/binary_escapeCharacter.sim
./test.sh -f general/parser/binary_escapeCharacter.sim
./test.sh -f general/parser/bug.sim
./test.sh -f general/parser/bug.sim
./test.sh -f general/parser/repeatAlter.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/disk.sim
./test.sh -f general/stable/dnode3.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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录