Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6c3a2e2c
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6c3a2e2c
编写于
4月 15, 2023
作者:
A
Adam Ji
提交者:
GitHub
4月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: support schemaless insert (#20944)
* docs: support schemaless insert * docs: code reformat
上级
61ef12a1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
388 addition
and
0 deletion
+388
-0
docs/en/14-reference/03-connector/07-python.mdx
docs/en/14-reference/03-connector/07-python.mdx
+50
-0
docs/examples/python/schemaless_insert.py
docs/examples/python/schemaless_insert.py
+21
-0
docs/examples/python/schemaless_insert_raw.py
docs/examples/python/schemaless_insert_raw.py
+74
-0
docs/examples/python/schemaless_insert_raw_req_id.py
docs/examples/python/schemaless_insert_raw_req_id.py
+76
-0
docs/examples/python/schemaless_insert_raw_ttl.py
docs/examples/python/schemaless_insert_raw_ttl.py
+73
-0
docs/examples/python/schemaless_insert_req_id.py
docs/examples/python/schemaless_insert_req_id.py
+22
-0
docs/examples/python/schemaless_insert_ttl.py
docs/examples/python/schemaless_insert_ttl.py
+22
-0
docs/zh/08-connector/30-python.mdx
docs/zh/08-connector/30-python.mdx
+50
-0
未找到文件。
docs/en/14-reference/03-connector/07-python.mdx
浏览文件 @
6c3a2e2c
...
...
@@ -459,6 +459,56 @@ For a more detailed description of the `sql()` method, please refer to [RestClie
</TabItem>
</Tabs>
### Schemaless Insert
Connector support schemaless insert.
<Tabs defaultValue="list">
<TabItem value="list" label="List Insert">
Simple insert
```python
{{#include docs/examples/python/schemaless_insert.py}}
```
Insert with ttl argument
```python
{{#include docs/examples/python/schemaless_insert_ttl.py}}
```
Insert with req_id argument
```python
{{#include docs/examples/python/schemaless_insert_req_id.py}}
```
</TabItem>
<TabItem value="raw" label="Raw Insert">
Simple insert
```python
{{#include docs/examples/python/schemaless_insert_raw.py}}
```
Insert with ttl argument
```python
{{#include docs/examples/python/schemaless_insert_raw_ttl.py}}
```
Insert with req_id argument
```python
{{#include docs/examples/python/schemaless_insert_raw_req_id.py}}
```
</TabItem>
</Tabs>
### Other sample programs
| Example program links | Example program content |
...
...
docs/examples/python/schemaless_insert.py
0 → 100644
浏览文件 @
6c3a2e2c
import
taos
conn
=
taos
.
connect
()
dbname
=
"pytest_line"
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
execute
(
"create database if not exists %s precision 'us'"
%
dbname
)
conn
.
select_db
(
dbname
)
lines
=
[
'st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"pass",c2=false,c4=4f64 1626006833639000000'
,
]
conn
.
schemaless_insert
(
lines
,
taos
.
SmlProtocol
.
LINE_PROTOCOL
,
taos
.
SmlPrecision
.
NOT_CONFIGURED
)
print
(
"inserted"
)
conn
.
schemaless_insert
(
lines
,
taos
.
SmlProtocol
.
LINE_PROTOCOL
,
taos
.
SmlPrecision
.
NOT_CONFIGURED
)
result
=
conn
.
query
(
"show tables"
)
for
row
in
result
:
print
(
row
)
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
docs/examples/python/schemaless_insert_raw.py
0 → 100644
浏览文件 @
6c3a2e2c
import
taos
from
taos
import
utils
from
taos
import
TaosConnection
from
taos.cinterface
import
*
from
taos.error
import
OperationalError
,
SchemalessError
conn
=
taos
.
connect
()
dbname
=
"taos_schemaless_insert"
try
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
if
taos
.
IS_V3
:
conn
.
execute
(
"create database if not exists %s schemaless 1 precision 'ns'"
%
dbname
)
else
:
conn
.
execute
(
"create database if not exists %s update 2 precision 'ns'"
%
dbname
)
conn
.
select_db
(
dbname
)
lines
=
'''st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000
st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin, abc",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000
stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000'''
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
)
print
(
"affected rows: "
,
res
)
assert
(
res
==
3
)
lines
=
'''stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000'''
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
)
print
(
"affected rows: "
,
res
)
assert
(
res
==
1
)
result
=
conn
.
query
(
"select * from st"
)
dict2
=
result
.
fetch_all_into_dict
()
print
(
dict2
)
print
(
result
.
row_count
)
all
=
result
.
rows_iter
()
for
row
in
all
:
print
(
row
)
result
.
close
()
assert
(
result
.
row_count
==
2
)
# error test
lines
=
''',t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000'''
try
:
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
)
print
(
res
)
# assert(False)
except
SchemalessError
as
err
:
print
(
'**** error: '
,
err
)
# assert (err.msg == 'Invalid data format')
result
=
conn
.
query
(
"select * from st"
)
print
(
result
.
row_count
)
all
=
result
.
rows_iter
()
for
row
in
all
:
print
(
row
)
result
.
close
()
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
except
InterfaceError
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
except
SchemalessError
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
except
Exception
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
raise
err
docs/examples/python/schemaless_insert_raw_req_id.py
0 → 100644
浏览文件 @
6c3a2e2c
import
taos
from
taos
import
utils
from
taos
import
TaosConnection
from
taos.cinterface
import
*
from
taos.error
import
OperationalError
,
SchemalessError
conn
=
taos
.
connect
()
dbname
=
"taos_schemaless_insert"
try
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
if
taos
.
IS_V3
:
conn
.
execute
(
"create database if not exists %s schemaless 1 precision 'ns'"
%
dbname
)
else
:
conn
.
execute
(
"create database if not exists %s update 2 precision 'ns'"
%
dbname
)
conn
.
select_db
(
dbname
)
lines
=
'''st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000
st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin, abc",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000
stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000'''
ttl
=
1000
req_id
=
utils
.
gen_req_id
()
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
,
ttl
=
ttl
,
req_id
=
req_id
)
print
(
"affected rows: "
,
res
)
assert
(
res
==
3
)
lines
=
'''stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000'''
ttl
=
1000
req_id
=
utils
.
gen_req_id
()
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
,
ttl
=
ttl
,
req_id
=
req_id
)
print
(
"affected rows: "
,
res
)
assert
(
res
==
1
)
result
=
conn
.
query
(
"select * from st"
)
dict2
=
result
.
fetch_all_into_dict
()
print
(
dict2
)
print
(
result
.
row_count
)
all
=
result
.
rows_iter
()
for
row
in
all
:
print
(
row
)
result
.
close
()
assert
(
result
.
row_count
==
2
)
# error test
lines
=
''',t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000'''
try
:
ttl
=
1000
req_id
=
utils
.
gen_req_id
()
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
,
ttl
=
ttl
,
req_id
=
req_id
)
print
(
res
)
# assert(False)
except
SchemalessError
as
err
:
print
(
'**** error: '
,
err
)
# assert (err.msg == 'Invalid data format')
result
=
conn
.
query
(
"select * from st"
)
print
(
result
.
row_count
)
all
=
result
.
rows_iter
()
for
row
in
all
:
print
(
row
)
result
.
close
()
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
except
InterfaceError
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
except
Exception
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
raise
err
docs/examples/python/schemaless_insert_raw_ttl.py
0 → 100644
浏览文件 @
6c3a2e2c
import
taos
from
taos
import
utils
from
taos
import
TaosConnection
from
taos.cinterface
import
*
from
taos.error
import
OperationalError
,
SchemalessError
conn
=
taos
.
connect
()
dbname
=
"taos_schemaless_insert"
try
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
if
taos
.
IS_V3
:
conn
.
execute
(
"create database if not exists %s schemaless 1 precision 'ns'"
%
dbname
)
else
:
conn
.
execute
(
"create database if not exists %s update 2 precision 'ns'"
%
dbname
)
conn
.
select_db
(
dbname
)
lines
=
'''st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000
st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin, abc",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000
stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000'''
ttl
=
1000
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
,
ttl
=
ttl
)
print
(
"affected rows: "
,
res
)
assert
(
res
==
3
)
lines
=
'''stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000'''
ttl
=
1000
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
,
ttl
=
ttl
)
print
(
"affected rows: "
,
res
)
assert
(
res
==
1
)
result
=
conn
.
query
(
"select * from st"
)
dict2
=
result
.
fetch_all_into_dict
()
print
(
dict2
)
print
(
result
.
row_count
)
all
=
result
.
rows_iter
()
for
row
in
all
:
print
(
row
)
result
.
close
()
assert
(
result
.
row_count
==
2
)
# error test
lines
=
''',t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000'''
try
:
ttl
=
1000
res
=
conn
.
schemaless_insert_raw
(
lines
,
1
,
0
,
ttl
=
ttl
)
print
(
res
)
# assert(False)
except
SchemalessError
as
err
:
print
(
'**** error: '
,
err
)
# assert (err.msg == 'Invalid data format')
result
=
conn
.
query
(
"select * from st"
)
print
(
result
.
row_count
)
all
=
result
.
rows_iter
()
for
row
in
all
:
print
(
row
)
result
.
close
()
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
except
InterfaceError
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
except
Exception
as
err
:
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
close
()
print
(
err
)
raise
err
docs/examples/python/schemaless_insert_req_id.py
0 → 100644
浏览文件 @
6c3a2e2c
import
taos
from
taos
import
SmlProtocol
,
SmlPrecision
conn
=
taos
.
connect
()
dbname
=
"pytest_line"
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
execute
(
"create database if not exists %s precision 'us'"
%
dbname
)
conn
.
select_db
(
dbname
)
lines
=
[
'st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"pass",c2=false,c4=4f64 1626006833639000000'
,
]
conn
.
schemaless_insert
(
lines
,
taos
.
SmlProtocol
.
LINE_PROTOCOL
,
taos
.
SmlPrecision
.
NOT_CONFIGURED
,
req_id
=
1
)
print
(
"inserted"
)
conn
.
schemaless_insert
(
lines
,
taos
.
SmlProtocol
.
LINE_PROTOCOL
,
taos
.
SmlPrecision
.
NOT_CONFIGURED
,
req_id
=
2
)
result
=
conn
.
query
(
"show tables"
)
for
row
in
result
:
print
(
row
)
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
docs/examples/python/schemaless_insert_ttl.py
0 → 100644
浏览文件 @
6c3a2e2c
import
taos
from
taos
import
SmlProtocol
,
SmlPrecision
conn
=
taos
.
connect
()
dbname
=
"pytest_line"
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
execute
(
"create database if not exists %s precision 'us'"
%
dbname
)
conn
.
select_db
(
dbname
)
lines
=
[
'st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"pass",c2=false,c4=4f64 1626006833639000000'
,
]
conn
.
schemaless_insert
(
lines
,
taos
.
SmlProtocol
.
LINE_PROTOCOL
,
taos
.
SmlPrecision
.
NOT_CONFIGURED
,
ttl
=
1000
)
print
(
"inserted"
)
conn
.
schemaless_insert
(
lines
,
taos
.
SmlProtocol
.
LINE_PROTOCOL
,
taos
.
SmlPrecision
.
NOT_CONFIGURED
,
ttl
=
1000
)
result
=
conn
.
query
(
"show tables"
)
for
row
in
result
:
print
(
row
)
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
docs/zh/08-connector/30-python.mdx
浏览文件 @
6c3a2e2c
...
...
@@ -484,6 +484,56 @@ TaosCursor 类使用原生连接进行写入、查询操作。在客户端多线
</TabItem>
</Tabs>
### 无模式写入
连接器支持无模式写入功能。
<Tabs defaultValue="list">
<TabItem value="list" label="List 写入">
简单写入
```python
{{#include docs/examples/python/schemaless_insert.py}}
```
带有 ttl 参数的写入
```python
{{#include docs/examples/python/schemaless_insert_ttl.py}}
```
带有 req_id 参数的写入
```python
{{#include docs/examples/python/schemaless_insert_req_id.py}}
```
</TabItem>
<TabItem value="raw" label="Raw 写入">
简单写入
```python
{{#include docs/examples/python/schemaless_insert_raw.py}}
```
带有 ttl 参数的写入
```python
{{#include docs/examples/python/schemaless_insert_raw_ttl.py}}
```
带有 req_id 参数的写入
```python
{{#include docs/examples/python/schemaless_insert_raw_req_id.py}}
```
</TabItem>
</Tabs>
### 其它示例程序
| 示例程序链接 | 示例程序内容 |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录