Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c39ae688
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
c39ae688
编写于
3月 28, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add schemaless example
上级
b44325f7
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
256 addition
and
72 deletion
+256
-72
docs-cn/06-insert-data/_py_line.mdx
docs-cn/06-insert-data/_py_line.mdx
+3
-0
docs-cn/06-insert-data/_py_opts_json.mdx
docs-cn/06-insert-data/_py_opts_json.mdx
+3
-0
docs-cn/06-insert-data/_py_opts_telnet.mdx
docs-cn/06-insert-data/_py_opts_telnet.mdx
+3
-0
docs-cn/14-reference/03-connector/python.mdx
docs-cn/14-reference/03-connector/python.mdx
+0
-72
docs-examples/c/.gitignore
docs-examples/c/.gitignore
+3
-0
docs-examples/c/json_protocol_example.c
docs-examples/c/json_protocol_example.c
+67
-0
docs-examples/java/src/main/java/com/taos/example/JSONProtocolExample.java
...a/src/main/java/com/taos/example/JSONProtocolExample.java
+1
-0
docs-examples/java/src/main/java/com/taos/example/LineProtocolExample.java
...a/src/main/java/com/taos/example/LineProtocolExample.java
+42
-0
docs-examples/java/src/main/java/com/taos/example/TelnetLineProtocolExample.java
...main/java/com/taos/example/TelnetLineProtocolExample.java
+41
-0
docs-examples/python/json_protocol_example.py
docs-examples/python/json_protocol_example.py
+31
-0
docs-examples/python/line_protocol_example.py
docs-examples/python/line_protocol_example.py
+31
-0
docs-examples/python/telnet_line_protocol_example.py
docs-examples/python/telnet_line_protocol_example.py
+31
-0
未找到文件。
docs-cn/06-insert-data/_py_line.mdx
浏览文件 @
c39ae688
```py
{{#include docs-examples/python/line_protocol_example.py}}
```
docs-cn/06-insert-data/_py_opts_json.mdx
浏览文件 @
c39ae688
```py
{{#include docs-examples/python/json_protocol_example.py}}
```
docs-cn/06-insert-data/_py_opts_telnet.mdx
浏览文件 @
c39ae688
```py
{{#include docs-examples/python/telnet_line_protocol_example.py}}
```
docs-cn/14-reference/03-connector/python.mdx
浏览文件 @
c39ae688
...
...
@@ -281,75 +281,3 @@ k1 = conn.query("select info->'k1' as k1 from s1").fetch_all_into_dict()
- _connect_ 方法
用于生成 taos.TaosConnection 的实例。
## <a class="anchor" id="restful"></a>RESTful Connector
为支持各种不同类型平台的开发,TDengine 提供符合 REST 设计标准的 API,即 RESTful API。为最大程度降低学习成本,不同于其他数据库 RESTful API 的设计方法,TDengine 直接通过 HTTP POST 请求 BODY 中包含的 SQL 语句来操作数据库,仅需要一个 URL。RESTful 连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1965.html)。
注意:与原生连接器的一个区别是,RESTful 接口是无状态的,因此 `USE db_name` 指令没有效果,所有对表名、超级表名的引用都需要指定数据库名前缀。(从 2.2.0.0 版本开始,支持在 RESTful url 中指定 db_name,这时如果 SQL 语句中没有指定数据库名前缀的话,会使用 url 中指定的这个 db_name。从 2.4.0.0 版本开始,RESTful 默认有 taosAdapter 提供,要求必须在 url 中指定 db_name。)
### 安装
RESTful 接口不依赖于任何 TDengine 的库,因此客户端不需要安装任何 TDengine 的库,只要客户端的开发语言支持 HTTP 协议即可。
### 验证
在已经安装 TDengine 服务器端的情况下,可以按照如下方式进行验证。
下面以 Ubuntu 环境中使用 curl 工具(确认已经安装)来验证 RESTful 接口的正常。
下面示例是列出所有的数据库,请把 h1.taosdata.com 和 6041(缺省值)替换为实际运行的 TDengine 服务 fqdn 和端口号:
```html
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;'
h1.taosdata.com:6041/rest/sql
```
返回值结果如下表示验证通过:
```json
{
"status": "succ",
"head": [
"name",
"created_time",
"ntables",
"vgroups",
"replica",
"quorum",
"days",
"keep1,keep2,keep(D)",
"cache(MB)",
"blocks",
"minrows",
"maxrows",
"wallevel",
"fsync",
"comp",
"precision",
"status"
],
"data": [
[
"log",
"2020-09-02 17:23:00.039",
4,
1,
1,
1,
10,
"30,30,30",
1,
3,
100,
4096,
1,
3000,
2,
"us",
"ready"
]
],
"rows": 1
}
```
docs-examples/c/.gitignore
0 → 100644
浏览文件 @
c39ae688
*
!*.c
!.gitignore
docs-examples/c/json_protocol_example.c
0 → 100644
浏览文件 @
c39ae688
// compile with
// gcc connect_example.c -o connect_example -I /usr/local/taos/include -L /usr/local/taos/driver -ltaos
#include <stdio.h>
#include "taos.h"
#include "taoserror.h"
int
main
()
{
// if don't want to connect to a default db, set it to NULL.
const
char
*
db
=
"test"
;
TAOS
*
taos
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
db
,
6030
);
printf
(
"Connected
\n
"
);
char
*
message
[]
=
{
"[ \
{ \
\"
metric
\"
:
\"
cpu_load_1
\"
, \
\"
timestamp
\"
: 1626006833, \
\"
value
\"
: 55.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth1
\"
, \
\"
Id
\"
:
\"
tb1
\"
\
} \
}, \
{ \
\"
metric
\"
:
\"
cpu_load_2
\"
, \
\"
timestamp
\"
: 1626006833, \
\"
value
\"
: 55.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth2
\"
, \
\"
Id
\"
:
\"
tb2
\"
\
} \
} \
]"
,
"[ \
{ \
\"
metric
\"
:
\"
cpu_load_1
\"
, \
\"
timestamp
\"
: 1626006834, \
\"
value
\"
: 56.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth1
\"
, \
\"
Id
\"
:
\"
tb1
\"
\
} \
}, \
{ \
\"
metric
\"
:
\"
cpu_load_2
\"
, \
\"
timestamp
\"
: 1626006834, \
\"
value
\"
: 56.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth2
\"
, \
\"
Id
\"
:
\"
tb2
\"
\
} \
} \
]"
};
void
*
code
=
taos_schemaless_insert
(
taos
,
message
,
1
,
3
,
NULL
);
if
(
code
)
{
printf
(
"payload_1 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
taos_close
(
taos
);
}
docs-examples/java/src/main/java/com/taos/example/JSONProtocolExample.java
浏览文件 @
c39ae688
package
com.taos.example
;
public
class
JSONProtocolExample
{
}
docs-examples/java/src/main/java/com/taos/example/LineProtocolExample.java
浏览文件 @
c39ae688
package
com.taos.example
;
import
com.taosdata.jdbc.SchemalessWriter
;
import
com.taosdata.jdbc.enums.SchemalessProtocolType
;
import
com.taosdata.jdbc.enums.SchemalessTimestampType
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
LineProtocolExample
{
// format: measurement,tag_set field_set timestamp
private
static
String
[]
lines
=
{
"meters,location=Beijing.Chaoyang,groupid=2 current=10.3,voltage=219,phase=0.31 1648432611249300"
,
// micro seconds
"meters,location=Beijing.Chaoyang,groupid=2 current=12.6,voltage=218,phase=0.33 1648432611249800"
,
"meters,location=Beijing.Chaoyang,groupid=2 current=12.3,voltage=221,phase=0.31 1648432611250300"
,
"meters,location=Beijing.Chaoyang,groupid=3 current=10.3,voltage=218,phase=0.25 1648432611249200"
,
"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249000"
,
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500"
,
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249300"
,
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800"
,
};
private
static
Connection
getConnection
()
throws
SQLException
{
String
jdbcUrl
=
"jdbc:TAOS://localhost:6030?user=root&password=taosdata"
;
return
DriverManager
.
getConnection
(
jdbcUrl
);
}
private
static
void
createDatabase
(
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
// the default precision is ms (microsecond), but we use us(microsecond) here.
stmt
.
execute
(
"create database test precision 'us'"
);
stmt
.
execute
(
"use test"
);
}
}
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
try
(
Connection
conn
=
getConnection
())
{
createDatabase
(
conn
);
SchemalessWriter
writer
=
new
SchemalessWriter
(
conn
);
writer
.
write
(
lines
,
SchemalessProtocolType
.
LINE
,
SchemalessTimestampType
.
MICRO_SECONDS
);
}
}
}
docs-examples/java/src/main/java/com/taos/example/TelnetLineProtocolExample.java
浏览文件 @
c39ae688
package
com.taos.example
;
import
com.taosdata.jdbc.SchemalessWriter
;
import
com.taosdata.jdbc.enums.SchemalessProtocolType
;
import
com.taosdata.jdbc.enums.SchemalessTimestampType
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
TelnetLineProtocolExample
{
// format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
private
static
String
[]
lines
=
{
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2"
,
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2"
,
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3"
,
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3"
,
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2"
,
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2"
,
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3"
,
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3"
,
};
private
static
Connection
getConnection
()
throws
SQLException
{
String
jdbcUrl
=
"jdbc:TAOS://localhost:6030?user=root&password=taosdata"
;
return
DriverManager
.
getConnection
(
jdbcUrl
);
}
private
static
void
createDatabase
(
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
// the default precision is ms (microsecond), but we use us(microsecond) here.
stmt
.
execute
(
"create database test precision 'us'"
);
stmt
.
execute
(
"use test"
);
}
}
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
try
(
Connection
conn
=
getConnection
())
{
createDatabase
(
conn
);
SchemalessWriter
writer
=
new
SchemalessWriter
(
conn
);
writer
.
write
(
lines
,
SchemalessProtocolType
.
TELNET
,
SchemalessTimestampType
.
NOT_CONFIGURED
);
}
}
}
docs-examples/python/json_protocol_example.py
0 → 100644
浏览文件 @
c39ae688
import
json
import
taos
from
taos
import
SmlProtocol
,
SmlPrecision
lines
=
[[{
"metric"
:
"meters.current"
,
"timestamp"
:
1648432611249
,
"value"
:
10.3
,
"tags"
:
{
"location"
:
"Beijing.Chaoyang"
,
"groupid"
:
2
}},
{
"metric"
:
"meters.voltage"
,
"timestamp"
:
1648432611249
,
"value"
:
219
,
"tags"
:
{
"location"
:
"Beijing.Haidian"
,
"groupid"
:
1
}}],
[{
"metric"
:
"meters.current"
,
"timestamp"
:
1648432611250
,
"value"
:
12.6
,
"tags"
:
{
"location"
:
"Beijing.Chaoyang"
,
"groupid"
:
2
}},
{
"metric"
:
"meters.voltage"
,
"timestamp"
:
1648432611250
,
"value"
:
221
,
"tags"
:
{
"location"
:
"Beijing.Haidian"
,
"groupid"
:
1
}}]
]
# create connection use firstEP in taos.cfg.
conn
=
taos
.
connect
()
def
create_database
():
conn
.
execute
(
"create database test"
)
conn
.
execute
(
"use test"
)
def
insert_lines
():
global
lines
lines
=
[
json
.
dumps
(
line
)
for
line
in
lines
]
print
(
lines
)
affected_rows
=
conn
.
schemaless_insert
(
lines
,
SmlProtocol
.
JSON_PROTOCOL
,
SmlPrecision
.
NOT_CONFIGURED
)
print
(
affected_rows
)
# 这里有 bug, 4 条数据只写入 2 条。
if
__name__
==
'__main__'
:
create_database
()
insert_lines
()
docs-examples/python/line_protocol_example.py
浏览文件 @
c39ae688
import
taos
from
taos
import
SmlProtocol
,
SmlPrecision
lines
=
[
"meters,location=Beijing.Chaoyang,groupid=2 current=10.3,voltage=219,phase=0.31 1648432611249300"
,
"meters,location=Beijing.Chaoyang,groupid=2 current=12.6,voltage=218,phase=0.33 1648432611249800"
,
"meters,location=Beijing.Chaoyang,groupid=2 current=12.3,voltage=221,phase=0.31 1648432611250300"
,
"meters,location=Beijing.Chaoyang,groupid=3 current=10.3,voltage=218,phase=0.25 1648432611249200"
,
"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249000"
,
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500"
,
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249300"
,
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800"
,
]
# create connection use firstEP in taos.cfg.
conn
=
taos
.
connect
()
def
create_database
():
# the default precision is ms (microsecond), but we use us(microsecond) here.
conn
.
execute
(
"create database test precision 'us'"
)
conn
.
execute
(
"use test"
)
def
insert_lines
():
affected_rows
=
conn
.
schemaless_insert
(
lines
,
SmlProtocol
.
LINE_PROTOCOL
,
SmlPrecision
.
MICRO_SECONDS
)
print
(
affected_rows
)
# 8
if
__name__
==
'__main__'
:
create_database
()
insert_lines
()
docs-examples/python/telnet_line_protocol_example.py
0 → 100644
浏览文件 @
c39ae688
import
taos
from
taos
import
SmlProtocol
,
SmlPrecision
# format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
lines
=
[
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2"
,
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2"
,
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3"
,
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3"
,
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2"
,
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2"
,
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3"
,
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3"
,
]
# create connection use firstEP in taos.cfg.
conn
=
taos
.
connect
()
def
create_database
():
conn
.
execute
(
"create database test"
)
conn
.
execute
(
"use test"
)
def
insert_lines
():
affected_rows
=
conn
.
schemaless_insert
(
lines
,
SmlProtocol
.
TELNET_PROTOCOL
,
SmlPrecision
.
NOT_CONFIGURED
)
print
(
affected_rows
)
# 8
if
__name__
==
'__main__'
:
create_database
()
insert_lines
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录