Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
2be7275d
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2be7275d
编写于
6月 17, 2021
作者:
sangshuduo
提交者:
GitHub
6月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-4752]<feature>: python connector support nanosecond. (#6528)
上级
a20f708a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
24 deletion
+34
-24
src/connector/python/setup.py
src/connector/python/setup.py
+1
-1
src/connector/python/taos/cinterface.py
src/connector/python/taos/cinterface.py
+31
-23
src/connector/python/taos/constants.py
src/connector/python/taos/constants.py
+2
-0
未找到文件。
src/connector/python/setup.py
浏览文件 @
2be7275d
...
...
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools
.
setup
(
name
=
"taos"
,
version
=
"2.0.1
0
"
,
version
=
"2.0.1
1
"
,
author
=
"Taosdata Inc."
,
author_email
=
"support@taosdata.com"
,
description
=
"TDengine python client package"
,
...
...
src/connector/python/taos/cinterface.py
浏览文件 @
2be7275d
...
...
@@ -14,12 +14,22 @@ def _convert_microsecond_to_datetime(micro):
return
datetime
.
datetime
.
fromtimestamp
(
micro
/
1000000.0
)
def
_crow_timestamp_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_convert_nanosecond_to_datetime
(
nanosec
):
return
datetime
.
datetime
.
fromtimestamp
(
nanosec
/
1000000000.0
)
def
_crow_timestamp_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C bool row to python row
"""
_timestamp_converter
=
_convert_millisecond_to_datetime
if
micro
:
if
precision
==
FieldType
.
C_TIMESTAMP_MILLI
:
_timestamp_converter
=
_convert_millisecond_to_datetime
elif
precision
==
FieldType
.
C_TIMESTAMP_MICRO
:
_timestamp_converter
=
_convert_microsecond_to_datetime
elif
precision
==
FieldType
.
C_TIMESTAMP_NANO
:
_timestamp_converter
=
_convert_nanosecond_to_datetime
else
:
raise
DatabaseError
(
"Unknown precision returned from database"
)
return
[
None
if
ele
==
FieldType
.
C_BIGINT_NULL
else
_timestamp_converter
(
ele
)
for
ele
in
ctypes
.
cast
(
...
...
@@ -28,7 +38,7 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
:
abs
(
num_of_rows
)]]
def
_crow_bool_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_bool_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C bool row to python row
"""
return
[
...
...
@@ -38,7 +48,7 @@ def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
:
abs
(
num_of_rows
)]]
def
_crow_tinyint_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_tinyint_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C tinyint row to python row
"""
return
[
None
if
ele
==
FieldType
.
C_TINYINT_NULL
else
ele
for
ele
in
ctypes
.
cast
(
...
...
@@ -49,7 +59,7 @@ def _crow_tinyint_unsigned_to_python(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C tinyint row to python row
"""
return
[
...
...
@@ -59,7 +69,7 @@ def _crow_tinyint_unsigned_to_python(
:
abs
(
num_of_rows
)]]
def
_crow_smallint_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_smallint_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C smallint row to python row
"""
return
[
...
...
@@ -70,7 +80,7 @@ def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False):
def
_crow_smallint_unsigned_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C smallint row to python row
"""
return
[
...
...
@@ -80,14 +90,14 @@ def _crow_smallint_unsigned_to_python(
:
abs
(
num_of_rows
)]]
def
_crow_int_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_int_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C int row to python row
"""
return
[
None
if
ele
==
FieldType
.
C_INT_NULL
else
ele
for
ele
in
ctypes
.
cast
(
data
,
ctypes
.
POINTER
(
ctypes
.
c_int
))[:
abs
(
num_of_rows
)]]
def
_crow_int_unsigned_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_int_unsigned_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C int row to python row
"""
return
[
...
...
@@ -97,7 +107,7 @@ def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False):
:
abs
(
num_of_rows
)]]
def
_crow_bigint_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_bigint_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C bigint row to python row
"""
return
[
None
if
ele
==
FieldType
.
C_BIGINT_NULL
else
ele
for
ele
in
ctypes
.
cast
(
...
...
@@ -108,7 +118,7 @@ def _crow_bigint_unsigned_to_python(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C bigint row to python row
"""
return
[
...
...
@@ -118,21 +128,21 @@ def _crow_bigint_unsigned_to_python(
:
abs
(
num_of_rows
)]]
def
_crow_float_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_float_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C float row to python row
"""
return
[
None
if
math
.
isnan
(
ele
)
else
ele
for
ele
in
ctypes
.
cast
(
data
,
ctypes
.
POINTER
(
ctypes
.
c_float
))[:
abs
(
num_of_rows
)]]
def
_crow_double_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_double_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C double row to python row
"""
return
[
None
if
math
.
isnan
(
ele
)
else
ele
for
ele
in
ctypes
.
cast
(
data
,
ctypes
.
POINTER
(
ctypes
.
c_double
))[:
abs
(
num_of_rows
)]]
def
_crow_binary_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_binary_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C binary row to python row
"""
assert
(
nbytes
is
not
None
)
...
...
@@ -140,7 +150,7 @@ def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False):
'utf-8'
)
for
ele
in
(
ctypes
.
cast
(
data
,
ctypes
.
POINTER
(
ctypes
.
c_char
*
nbytes
)))[:
abs
(
num_of_rows
)]]
def
_crow_nchar_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_nchar_to_python
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C nchar row to python row
"""
assert
(
nbytes
is
not
None
)
...
...
@@ -159,7 +169,7 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False):
return
res
def
_crow_binary_to_python_block
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_binary_to_python_block
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C binary row to python row
"""
assert
(
nbytes
is
not
None
)
...
...
@@ -178,7 +188,7 @@ def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False):
return
res
def
_crow_nchar_to_python_block
(
data
,
num_of_rows
,
nbytes
=
None
,
micro
=
False
):
def
_crow_nchar_to_python_block
(
data
,
num_of_rows
,
nbytes
=
None
,
precision
=
FieldType
.
C_TIMESTAMP_UNKNOWN
):
"""Function to convert C nchar row to python row
"""
assert
(
nbytes
is
not
None
)
...
...
@@ -448,8 +458,7 @@ class CTaosInterface(object):
result
,
ctypes
.
byref
(
pblock
))
if
num_of_rows
==
0
:
return
None
,
0
isMicro
=
(
CTaosInterface
.
libtaos
.
taos_result_precision
(
result
)
==
FieldType
.
C_TIMESTAMP_MICRO
)
precision
=
CTaosInterface
.
libtaos
.
taos_result_precision
(
result
)
blocks
=
[
None
]
*
len
(
fields
)
fieldL
=
CTaosInterface
.
libtaos
.
taos_fetch_lengths
(
result
)
fieldLen
=
[
...
...
@@ -462,7 +471,7 @@ class CTaosInterface(object):
if
fields
[
i
][
'type'
]
not
in
_CONVERT_FUNC_BLOCK
:
raise
DatabaseError
(
"Invalid data type returned from database"
)
blocks
[
i
]
=
_CONVERT_FUNC_BLOCK
[
fields
[
i
][
'type'
]](
data
,
num_of_rows
,
fieldLen
[
i
],
isMicro
)
data
,
num_of_rows
,
fieldLen
[
i
],
precision
)
return
blocks
,
abs
(
num_of_rows
)
...
...
@@ -472,8 +481,7 @@ class CTaosInterface(object):
pblock
=
CTaosInterface
.
libtaos
.
taos_fetch_row
(
result
)
if
pblock
:
num_of_rows
=
1
isMicro
=
(
CTaosInterface
.
libtaos
.
taos_result_precision
(
result
)
==
FieldType
.
C_TIMESTAMP_MICRO
)
precision
=
CTaosInterface
.
libtaos
.
taos_result_precision
(
result
)
blocks
=
[
None
]
*
len
(
fields
)
fieldL
=
CTaosInterface
.
libtaos
.
taos_fetch_lengths
(
result
)
fieldLen
=
[
...
...
@@ -490,7 +498,7 @@ class CTaosInterface(object):
blocks
[
i
]
=
[
None
]
else
:
blocks
[
i
]
=
_CONVERT_FUNC
[
fields
[
i
][
'type'
]](
data
,
num_of_rows
,
fieldLen
[
i
],
isMicro
)
data
,
num_of_rows
,
fieldLen
[
i
],
precision
)
else
:
return
None
,
0
return
blocks
,
abs
(
num_of_rows
)
...
...
src/connector/python/taos/constants.py
浏览文件 @
2be7275d
...
...
@@ -40,3 +40,5 @@ class FieldType(object):
# Timestamp precision definition
C_TIMESTAMP_MILLI
=
0
C_TIMESTAMP_MICRO
=
1
C_TIMESTAMP_NANO
=
2
C_TIMESTAMP_UNKNOWN
=
3
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录