Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4883bfb4
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
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看板
提交
4883bfb4
编写于
11月 10, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into feature/TD-10748
上级
148b9034
e1c81f6d
变更
33
显示空白变更内容
内联
并排
Showing
33 changed file
with
12879 addition
and
43 deletion
+12879
-43
Jenkinsfile
Jenkinsfile
+76
-0
cmake/define.inc
cmake/define.inc
+7
-4
cmake/platform.inc
cmake/platform.inc
+10
-5
documentation20/cn/02.getting-started/02.taosdemo/docs.md
documentation20/cn/02.getting-started/02.taosdemo/docs.md
+2
-2
documentation20/en/02.getting-started/02.taosdemo/docs.md
documentation20/en/02.getting-started/02.taosdemo/docs.md
+1
-1
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+5
-5
src/client/src/tscServer.c
src/client/src/tscServer.c
+2
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/SchemalessStatement.java
.../src/main/java/com/taosdata/jdbc/SchemalessStatement.java
+31
-4
src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/SchemalessProtocolType.java
.../java/com/taosdata/jdbc/enums/SchemalessProtocolType.java
+8
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/SchemalessTimestampType.java
...java/com/taosdata/jdbc/enums/SchemalessTimestampType.java
+1
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java
...src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java
+21
-3
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-1
src/kit/shell/src/shellImport.c
src/kit/shell/src/shellImport.c
+1
-1
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+1
-1
src/kit/taosdump/taosdump.c
src/kit/taosdump/taosdump.c
+2
-2
src/plugins/CMakeLists.txt
src/plugins/CMakeLists.txt
+1
-1
src/query/src/tdigest.c
src/query/src/tdigest.c
+1
-1
src/sync/src/syncRetrieve.c
src/sync/src/syncRetrieve.c
+1
-1
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+2
-2
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+1
-1
src/util/src/talgo.c
src/util/src/talgo.c
+1
-1
src/util/src/tlog.c
src/util/src/tlog.c
+1
-1
src/util/src/tqueue.c
src/util/src/tqueue.c
+1
-1
src/util/src/tworker.c
src/util/src/tworker.c
+1
-1
tests/pytest/functions/queryTestCases-td3690.py
tests/pytest/functions/queryTestCases-td3690.py
+1588
-0
tests/pytest/functions/queryTestCases-td4082.py
tests/pytest/functions/queryTestCases-td4082.py
+1586
-0
tests/pytest/functions/queryTestCases-td4097.py
tests/pytest/functions/queryTestCases-td4097.py
+1587
-0
tests/pytest/functions/queryTestCases-td4288.py
tests/pytest/functions/queryTestCases-td4288.py
+1587
-0
tests/pytest/functions/queryTestCases-td4724.py
tests/pytest/functions/queryTestCases-td4724.py
+1587
-0
tests/pytest/functions/queryTestCases-td5790.py
tests/pytest/functions/queryTestCases-td5790.py
+1588
-0
tests/pytest/functions/queryTestCases-td5935.py
tests/pytest/functions/queryTestCases-td5935.py
+1587
-0
tests/pytest/functions/queryTestCases-td6068.py
tests/pytest/functions/queryTestCases-td6068.py
+1588
-0
tests/tsim/inc/sim.h
tests/tsim/inc/sim.h
+2
-2
未找到文件。
Jenkinsfile
浏览文件 @
4883bfb4
...
@@ -181,6 +181,76 @@ def pre_test_noinstall(){
...
@@ -181,6 +181,76 @@ def pre_test_noinstall(){
'''
'''
return
1
return
1
}
}
def
pre_test_mac
(){
sh
'hostname'
sh
'''
cd ${WKC}
git reset --hard HEAD~10 >/dev/null
'''
script
{
if
(
env
.
CHANGE_TARGET
==
'master'
)
{
sh
'''
cd ${WKC}
git checkout master
'''
}
else
if
(
env
.
CHANGE_TARGET
==
'2.0'
){
sh
'''
cd ${WKC}
git checkout 2.0
'''
}
else
{
sh
'''
cd ${WKC}
git checkout develop
'''
}
}
sh
'''
cd ${WKC}
git pull >/dev/null
git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD
git clean -dfx
git submodule update --init --recursive
cd ${WK}
git reset --hard HEAD~10
'''
script
{
if
(
env
.
CHANGE_TARGET
==
'master'
)
{
sh
'''
cd ${WK}
git checkout master
'''
}
else
if
(
env
.
CHANGE_TARGET
==
'2.0'
){
sh
'''
cd ${WK}
git checkout 2.0
'''
}
else
{
sh
'''
cd ${WK}
git checkout develop
'''
}
}
sh
'''
cd ${WK}
git pull >/dev/null
export TZ=Asia/Harbin
date
git clean -dfx
mkdir debug
cd debug
cmake .. > /dev/null
cmake --build .
'''
return
1
}
def
pre_test_win
(){
def
pre_test_win
(){
bat
'''
bat
'''
taskkill /f /t /im python.exe
taskkill /f /t /im python.exe
...
@@ -581,6 +651,12 @@ pipeline {
...
@@ -581,6 +651,12 @@ pipeline {
pre_test_noinstall
()
pre_test_noinstall
()
}
}
}
}
stage
(
'Mac_build'
)
{
agent
{
label
" catalina "
}
steps
{
pre_test_mac
()
}
}
stage
(
'build'
){
stage
(
'build'
){
agent
{
label
" wintest "
}
agent
{
label
" wintest "
}
...
...
cmake/define.inc
浏览文件 @
4883bfb4
...
@@ -121,7 +121,7 @@ IF (TD_MIPS_32)
...
@@ -121,7 +121,7 @@ IF (TD_MIPS_32)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
ENDIF
()
IF
(
TD_A
PLH
INE
)
IF
(
TD_A
LP
INE
)
SET
(
COMMON_FLAGS
"${COMMON_FLAGS} -largp"
)
SET
(
COMMON_FLAGS
"${COMMON_FLAGS} -largp"
)
link_libraries
(
/
usr
/
lib
/
libargp
.
a
)
link_libraries
(
/
usr
/
lib
/
libargp
.
a
)
ADD_DEFINITIONS
(
-
D_ALPINE
)
ADD_DEFINITIONS
(
-
D_ALPINE
)
...
@@ -172,11 +172,14 @@ IF (TD_LINUX)
...
@@ -172,11 +172,14 @@ IF (TD_LINUX)
ENDIF
()
ENDIF
()
IF
(
TD_MEMORY_SANITIZER
)
IF
(
TD_MEMORY_SANITIZER
)
IF
(
TD_ARCHLINUX
)
SET
(
DEBUG_FLAGS
"-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG"
)
ELSE
()
SET
(
DEBUG_FLAGS
"-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG"
)
SET
(
DEBUG_FLAGS
"-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG"
)
MESSAGE
(
STATUS
"memory sanitizer detected as true"
)
ENDIF
()
MESSAGE
(
STATUS
"${BoldRed}Will compile with memory sanitizer! ${ColourReset}"
)
ELSE
()
ELSE
()
SET
(
DEBUG_FLAGS
"-O0 -g3 -DDEBUG"
)
SET
(
DEBUG_FLAGS
"-O0 -g3 -DDEBUG"
)
MESSAGE
(
STATUS
"memory sanitizer detected as false"
)
ENDIF
()
ENDIF
()
SET
(
RELEASE_FLAGS
"-O3 -Wno-error"
)
SET
(
RELEASE_FLAGS
"-O3 -Wno-error"
)
...
...
cmake/platform.inc
浏览文件 @
4883bfb4
...
@@ -21,7 +21,7 @@ SET(TD_LINUX FALSE)
...
@@ -21,7 +21,7 @@ SET(TD_LINUX FALSE)
SET
(
TD_ARM_32
FALSE
)
SET
(
TD_ARM_32
FALSE
)
SET
(
TD_MIPS_64
FALSE
)
SET
(
TD_MIPS_64
FALSE
)
SET
(
TD_MIPS_32
FALSE
)
SET
(
TD_MIPS_32
FALSE
)
SET
(
TD_A
PLH
INE
FALSE
)
SET
(
TD_A
LP
INE
FALSE
)
SET
(
TD_NINGSI
FALSE
)
SET
(
TD_NINGSI
FALSE
)
SET
(
TD_NINGSI_60
FALSE
)
SET
(
TD_NINGSI_60
FALSE
)
SET
(
TD_NINGSI_80
FALSE
)
SET
(
TD_NINGSI_80
FALSE
)
...
@@ -36,7 +36,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
...
@@ -36,7 +36,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Get OS information and store in variable TD_OS_INFO.
# Get OS information and store in variable TD_OS_INFO.
#
#
execute_process
(
COMMAND
chmod
777
$
{
TD_COMMUNITY_DIR
}
/
packaging
/
tools
/
get_os
.
sh
)
execute_process
(
COMMAND
chmod
777
$
{
TD_COMMUNITY_DIR
}
/
packaging
/
tools
/
get_os
.
sh
)
execute_process
(
COMMAND
$
{
TD_COMMUNITY_DIR
}
/
packaging
/
tools
/
get_os
.
sh
""
OUTPUT_VARIABLE
TD_OS_INFO
)
execute_process
(
COMMAND
sh
$
{
TD_COMMUNITY_DIR
}
/
packaging
/
tools
/
get_os
.
sh
""
OUTPUT_VARIABLE
TD_OS_INFO
)
MESSAGE
(
STATUS
"The current os is "
$
{
TD_OS_INFO
})
MESSAGE
(
STATUS
"The current os is "
$
{
TD_OS_INFO
})
SET
(
TD_LINUX
TRUE
)
SET
(
TD_LINUX
TRUE
)
...
@@ -52,8 +52,13 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
...
@@ -52,8 +52,13 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ENDIF
()
ENDIF
()
IF
(
$
{
TD_OS_INFO
}
MATCHES
"Alpine"
)
IF
(
$
{
TD_OS_INFO
}
MATCHES
"Alpine"
)
SET
(
TD_APLHINE
TRUE
)
SET
(
TD_ALPINE
TRUE
)
MESSAGE
(
STATUS
"The current OS is Alpine, append extra flags"
)
MESSAGE
(
STATUS
"The current OS is Alpine Linux, append extra flags"
)
ELSEIF
(
$
{
TD_OS_INFO
}
MATCHES
"Arch"
)
SET
(
TD_ARCHLINUX
TRUE
)
MESSAGE
(
STATUS
"The current OS is Arch Linux"
)
ELSE
()
MESSAGE
(
STATUS
"Ths distro is "
$
{
TD_OS_INFO
})
ENDIF
()
ENDIF
()
ELSEIF
(
$
{
CMAKE_SYSTEM_NAME
}
MATCHES
"Darwin"
)
ELSEIF
(
$
{
CMAKE_SYSTEM_NAME
}
MATCHES
"Darwin"
)
SET
(
TD_DARWIN
TRUE
)
SET
(
TD_DARWIN
TRUE
)
...
@@ -155,7 +160,7 @@ ELSEIF (${OSTYPE} MATCHES "Linux")
...
@@ -155,7 +160,7 @@ ELSEIF (${OSTYPE} MATCHES "Linux")
MESSAGE
(
STATUS
"input osType: Linux"
)
MESSAGE
(
STATUS
"input osType: Linux"
)
ELSEIF
(
$
{
OSTYPE
}
MATCHES
"Alpine"
)
ELSEIF
(
$
{
OSTYPE
}
MATCHES
"Alpine"
)
MESSAGE
(
STATUS
"input osType: Alpine"
)
MESSAGE
(
STATUS
"input osType: Alpine"
)
SET
(
TD_A
PLH
INE
TRUE
)
SET
(
TD_A
LP
INE
TRUE
)
ELSE
()
ELSE
()
MESSAGE
(
STATUS
"The user specified osType is unknown: "
$
{
OSTYPE
})
MESSAGE
(
STATUS
"The user specified osType is unknown: "
$
{
OSTYPE
})
ENDIF
()
ENDIF
()
documentation20/cn/02.getting-started/02.taosdemo/docs.md
浏览文件 @
4883bfb4
...
@@ -145,7 +145,7 @@ insert delay, avg: 8.31ms, max: 860.12ms, min: 2.00ms
...
@@ -145,7 +145,7 @@ insert delay, avg: 8.31ms, max: 860.12ms, min: 2.00ms
```
```
$ taosdemo --help
$ taosdemo --help
-f, --file=FILE The meta file to the execution procedure.
-f, --file=FILE The meta file to the execution procedure.
Currently, we support standard UTF-8 (without BOM) encoded files only.
-u, --user=USER The user name to use when connecting to the server.
-u, --user=USER The user name to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-c, --config-dir=CONFIG_DIR Configuration directory.
-c, --config-dir=CONFIG_DIR Configuration directory.
...
@@ -442,7 +442,7 @@ TDengine是涛思数据专为物联网、车联网、工业互联网、IT运维
...
@@ -442,7 +442,7 @@ TDengine是涛思数据专为物联网、车联网、工业互联网、IT运维
taosdemo支持两种配置参数的模式,一种是命令行参数,一种是使用json格式的配置文件。
taosdemo支持两种配置参数的模式,一种是命令行参数,一种是使用json格式的配置文件。
一、命令行参数
一、命令行参数
-f:指定taosdemo所需参数的meta文件。当使用该参数时,其他所有命令行参数都失效。可选项,缺省是NULL。
-f:指定taosdemo所需参数的meta文件。当使用该参数时,其他所有命令行参数都失效。可选项,缺省是NULL。
目前仅支持不含 BOM(byte-order mark)的标准 UTF-8 编码文件。
-u: 用户名。可选项,缺省是“root“。
-u: 用户名。可选项,缺省是“root“。
...
...
documentation20/en/02.getting-started/02.taosdemo/docs.md
浏览文件 @
4883bfb4
...
@@ -154,7 +154,7 @@ The complete list of taosdemo command-line arguments can be displayed via taosde
...
@@ -154,7 +154,7 @@ The complete list of taosdemo command-line arguments can be displayed via taosde
```
```
$ taosdemo --help
$ taosdemo --help
-f, --file=FILE The meta file to the execution procedure.
-f, --file=FILE The meta file to the execution procedure.
Currently, we support standard UTF-8 (without BOM) encoded files only.
-u, --user=USER The user name to use when connecting to the server.
-u, --user=USER The user name to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-c, --config-dir=CONFIG_DIR Configuration directory.
-c, --config-dir=CONFIG_DIR Configuration directory.
...
...
src/client/src/tscParseLineProtocol.c
浏览文件 @
4883bfb4
...
@@ -1512,9 +1512,9 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char *str, SSmlLinesInfo* info
...
@@ -1512,9 +1512,9 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char *str, SSmlLinesInfo* info
errno
=
0
;
errno
=
0
;
uint8_t
type
=
pVal
->
type
;
uint8_t
type
=
pVal
->
type
;
int16_t
length
=
pVal
->
length
;
int16_t
length
=
pVal
->
length
;
int64_t
val_s
;
int64_t
val_s
=
0
;
uint64_t
val_u
;
uint64_t
val_u
=
0
;
double
val_d
;
double
val_d
=
0
.
0
;
strntolower_s
(
str
,
str
,
(
int32_t
)
strlen
(
str
));
strntolower_s
(
str
,
str
,
(
int32_t
)
strlen
(
str
));
if
(
IS_FLOAT_TYPE
(
type
))
{
if
(
IS_FLOAT_TYPE
(
type
))
{
...
@@ -1814,7 +1814,7 @@ static int32_t getTimeStampValue(char *value, uint16_t len,
...
@@ -1814,7 +1814,7 @@ static int32_t getTimeStampValue(char *value, uint16_t len,
int32_t
convertSmlTimeStamp
(
TAOS_SML_KV
*
pVal
,
char
*
value
,
int32_t
convertSmlTimeStamp
(
TAOS_SML_KV
*
pVal
,
char
*
value
,
uint16_t
len
,
SSmlLinesInfo
*
info
)
{
uint16_t
len
,
SSmlLinesInfo
*
info
)
{
int32_t
ret
;
int32_t
ret
;
SMLTimeStampType
type
;
SMLTimeStampType
type
=
SML_TIME_STAMP_NOW
;
int64_t
tsVal
;
int64_t
tsVal
;
ret
=
isTimeStamp
(
value
,
len
,
&
type
,
info
);
ret
=
isTimeStamp
(
value
,
len
,
&
type
,
info
);
...
@@ -2413,7 +2413,7 @@ static SSqlObj* createSmlQueryObj(TAOS* taos, int32_t affected_rows, int32_t cod
...
@@ -2413,7 +2413,7 @@ static SSqlObj* createSmlQueryObj(TAOS* taos, int32_t affected_rows, int32_t cod
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
)
{
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
)
{
int
code
=
TSDB_CODE_SUCCESS
;
int
code
=
TSDB_CODE_SUCCESS
;
int
affected_rows
=
0
;
int
affected_rows
=
0
;
SMLTimeStampType
tsType
;
SMLTimeStampType
tsType
=
SML_TIME_STAMP_NOW
;
if
(
protocol
==
TSDB_SML_LINE_PROTOCOL
)
{
if
(
protocol
==
TSDB_SML_LINE_PROTOCOL
)
{
code
=
convertPrecisionType
(
precision
,
&
tsType
);
code
=
convertPrecisionType
(
precision
,
&
tsType
);
...
...
src/client/src/tscServer.c
浏览文件 @
4883bfb4
...
@@ -2958,6 +2958,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
...
@@ -2958,6 +2958,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
if
(
pMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
if
(
pMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
int32_t
code
=
tscCreateTableMetaFromSTableMeta
(
pSql
,
&
pTableMetaInfo
->
pTableMeta
,
name
,
&
pTableMetaInfo
->
tableMetaCapacity
,
(
STableMeta
**
)(
&
pSTMeta
));
int32_t
code
=
tscCreateTableMetaFromSTableMeta
(
pSql
,
&
pTableMetaInfo
->
pTableMeta
,
name
,
&
pTableMetaInfo
->
tableMetaCapacity
,
(
STableMeta
**
)(
&
pSTMeta
));
pSql
->
pBuf
=
(
void
*
)(
pSTMeta
);
pSql
->
pBuf
=
(
void
*
)(
pSTMeta
);
pMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
getTableMetaFromMnode
(
pSql
,
pTableMetaInfo
,
autocreate
);
return
getTableMetaFromMnode
(
pSql
,
pTableMetaInfo
,
autocreate
);
}
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/SchemalessStatement.java
浏览文件 @
4883bfb4
...
@@ -8,16 +8,35 @@ import java.sql.Connection;
...
@@ -8,16 +8,35 @@ import java.sql.Connection;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
/**
* @author huolibo@qq.com
* @version v1.0.0
* @JDK: 1.8
* @description: this class is an extension of {@link Statement}. use like:
* Statement statement = conn.createStatement();
* SchemalessStatement schemalessStatement = new SchemalessStatement(statement);
* schemalessStatement.execute(sql);
* schemalessStatement.executeSchemaless(lines, SchemalessProtocolType, SchemalessTimestampType);
* @since 2021-11-03 17:10
*/
public
class
SchemalessStatement
extends
AbstractStatementWrapper
{
public
class
SchemalessStatement
extends
AbstractStatementWrapper
{
public
SchemalessStatement
(
Statement
statement
)
{
public
SchemalessStatement
(
Statement
statement
)
{
super
(
statement
);
super
(
statement
);
}
}
public
void
executeSchemaless
(
String
[]
strings
,
SchemalessProtocolType
protocolType
,
SchemalessTimestampType
timestampType
)
throws
SQLException
{
/**
* batch insert schemaless lines
*
* @param lines schemaless data
* @param protocolType schemaless type {@link SchemalessProtocolType}
* @param timestampType Time precision {@link SchemalessTimestampType}
* @throws SQLException execute insert exception
*/
public
void
executeSchemaless
(
String
[]
lines
,
SchemalessProtocolType
protocolType
,
SchemalessTimestampType
timestampType
)
throws
SQLException
{
Connection
connection
=
this
.
getConnection
();
Connection
connection
=
this
.
getConnection
();
if
(
connection
instanceof
TSDBConnection
)
{
if
(
connection
instanceof
TSDBConnection
)
{
TSDBConnection
tsdbConnection
=
(
TSDBConnection
)
connection
;
TSDBConnection
tsdbConnection
=
(
TSDBConnection
)
connection
;
tsdbConnection
.
getConnector
().
insertLines
(
string
s
,
protocolType
,
timestampType
);
tsdbConnection
.
getConnector
().
insertLines
(
line
s
,
protocolType
,
timestampType
);
}
else
if
(
connection
instanceof
RestfulConnection
)
{
}
else
if
(
connection
instanceof
RestfulConnection
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
,
"restful connection is not supported currently"
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
,
"restful connection is not supported currently"
);
}
else
{
}
else
{
...
@@ -25,7 +44,15 @@ public class SchemalessStatement extends AbstractStatementWrapper {
...
@@ -25,7 +44,15 @@ public class SchemalessStatement extends AbstractStatementWrapper {
}
}
}
}
public
void
executeSchemaless
(
String
sql
,
SchemalessProtocolType
protocolType
,
SchemalessTimestampType
timestampType
)
throws
SQLException
{
/**
executeSchemaless
(
new
String
[]{
sql
},
protocolType
,
timestampType
);
* only one insert
*
* @param line schemaless line
* @param protocolType schemaless type {@link SchemalessProtocolType}
* @param timestampType Time precision {@link SchemalessTimestampType}
* @throws SQLException execute insert exception
*/
public
void
executeSchemaless
(
String
line
,
SchemalessProtocolType
protocolType
,
SchemalessTimestampType
timestampType
)
throws
SQLException
{
executeSchemaless
(
new
String
[]{
line
},
protocolType
,
timestampType
);
}
}
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/SchemalessProtocolType.java
浏览文件 @
4883bfb4
package
com.taosdata.jdbc.enums
;
package
com.taosdata.jdbc.enums
;
import
java.util.Arrays
;
public
enum
SchemalessProtocolType
{
public
enum
SchemalessProtocolType
{
UNKNOWN
,
UNKNOWN
,
LINE
,
LINE
,
...
@@ -7,4 +9,10 @@ public enum SchemalessProtocolType {
...
@@ -7,4 +9,10 @@ public enum SchemalessProtocolType {
JSON
,
JSON
,
;
;
public
static
SchemalessProtocolType
parse
(
String
type
)
{
return
Arrays
.
stream
(
SchemalessProtocolType
.
values
())
.
filter
(
protocol
->
type
.
equalsIgnoreCase
(
protocol
.
name
()))
.
findFirst
().
orElse
(
UNKNOWN
);
}
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/SchemalessTimestampType.java
浏览文件 @
4883bfb4
package
com.taosdata.jdbc.enums
;
package
com.taosdata.jdbc.enums
;
public
enum
SchemalessTimestampType
{
public
enum
SchemalessTimestampType
{
// Let the database decide
NOT_CONFIGURED
,
NOT_CONFIGURED
,
HOURS
,
HOURS
,
MINUTES
,
MINUTES
,
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java
浏览文件 @
4883bfb4
package
com.taosdata.jdbc
;
package
com.taosdata.jdbc
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.taosdata.jdbc.enums.SchemalessProtocolType
;
import
com.taosdata.jdbc.enums.SchemalessProtocolType
;
import
com.taosdata.jdbc.enums.SchemalessTimestampType
;
import
com.taosdata.jdbc.enums.SchemalessTimestampType
;
import
org.junit.After
;
import
org.junit.After
;
...
@@ -10,10 +12,14 @@ import org.junit.Test;
...
@@ -10,10 +12,14 @@ import org.junit.Test;
import
java.sql.*
;
import
java.sql.*
;
public
class
SchemalessInsertTest
{
public
class
SchemalessInsertTest
{
private
String
host
=
"127.0.0.1"
;
private
final
String
dbname
=
"test_schemaless_insert"
;
private
String
dbname
=
"test_schemaless_insert"
;
private
Connection
conn
;
private
Connection
conn
;
/**
* schemaless insert compatible with influxdb
*
* @throws SQLException execute error
*/
@Test
@Test
public
void
schemalessInsert
()
throws
SQLException
{
public
void
schemalessInsert
()
throws
SQLException
{
// given
// given
...
@@ -41,6 +47,11 @@ public class SchemalessInsertTest {
...
@@ -41,6 +47,11 @@ public class SchemalessInsertTest {
statement
.
close
();
statement
.
close
();
}
}
/**
* telnet insert compatible with opentsdb
*
* @throws SQLException execute error
*/
@Test
@Test
public
void
telnetInsert
()
throws
SQLException
{
public
void
telnetInsert
()
throws
SQLException
{
// given
// given
...
@@ -71,6 +82,11 @@ public class SchemalessInsertTest {
...
@@ -71,6 +82,11 @@ public class SchemalessInsertTest {
statement
.
close
();
statement
.
close
();
}
}
/**
* json insert compatible with opentsdb json format
*
* @throws SQLException execute error
*/
@Test
@Test
public
void
jsonInsert
()
throws
SQLException
{
public
void
jsonInsert
()
throws
SQLException
{
// given
// given
...
@@ -113,13 +129,15 @@ public class SchemalessInsertTest {
...
@@ -113,13 +129,15 @@ public class SchemalessInsertTest {
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
rowCnt
++;
rowCnt
++;
}
}
// Assert.assertEquals(json.length, rowCnt);
Assert
.
assertEquals
(((
JSONArray
)
JSONObject
.
parse
(
json
)).
size
(),
rowCnt
);
rs
.
close
();
rs
.
close
();
statement
.
close
();
statement
.
close
();
}
}
@Before
@Before
public
void
before
()
{
public
void
before
()
{
String
host
=
"127.0.0.1"
;
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
try
{
try
{
conn
=
DriverManager
.
getConnection
(
url
);
conn
=
DriverManager
.
getConnection
(
url
);
...
...
src/inc/taosmsg.h
浏览文件 @
4883bfb4
...
@@ -400,7 +400,7 @@ typedef struct SColIndex {
...
@@ -400,7 +400,7 @@ typedef struct SColIndex {
int16_t
colId
;
// column id
int16_t
colId
;
// column id
int16_t
colIndex
;
// column index in colList if it is a normal column or index in tagColList if a tag
int16_t
colIndex
;
// column index in colList if it is a normal column or index in tagColList if a tag
uint16_t
flag
;
// denote if it is a tag or a normal column
uint16_t
flag
;
// denote if it is a tag or a normal column
char
name
[
TSDB_COL_NAME_LEN
+
TSDB_
DB
_NAME_LEN
+
1
];
char
name
[
TSDB_COL_NAME_LEN
+
TSDB_
TABLE
_NAME_LEN
+
1
];
}
SColIndex
;
}
SColIndex
;
typedef
struct
SColumnFilterInfo
{
typedef
struct
SColumnFilterInfo
{
...
...
src/kit/shell/src/shellImport.c
浏览文件 @
4883bfb4
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
static
char
**
shellSQLFiles
=
NULL
;
static
char
**
shellSQLFiles
=
NULL
;
static
int32_t
shellSQLFileNum
=
0
;
static
int32_t
shellSQLFileNum
=
0
;
static
char
shellTablesSQLFile
[
TSDB_FILENAME_LEN
]
=
{
0
};
static
char
shellTablesSQLFile
[
4096
]
=
{
0
};
typedef
struct
{
typedef
struct
{
pthread_t
threadID
;
pthread_t
threadID
;
...
...
src/kit/taosdemo/taosdemo.c
浏览文件 @
4883bfb4
...
@@ -10969,7 +10969,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
...
@@ -10969,7 +10969,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
}
}
int64_t
ntables
=
0
;
int64_t
ntables
=
0
;
uint64_t
tableFrom
;
uint64_t
tableFrom
=
0
;
if
(
stbInfo
)
{
if
(
stbInfo
)
{
if
(
stbInfo
->
iface
!=
SML_IFACE
)
{
if
(
stbInfo
->
iface
!=
SML_IFACE
)
{
...
...
src/kit/taosdump/taosdump.c
浏览文件 @
4883bfb4
...
@@ -1293,7 +1293,7 @@ static int getTableDes(
...
@@ -1293,7 +1293,7 @@ static int getTableDes(
length
[
0
],
tbuf
,
COL_VALUEBUF_LEN
-
2
);
length
[
0
],
tbuf
,
COL_VALUEBUF_LEN
-
2
);
sprintf
(
tableDes
->
cols
[
i
].
value
,
"%s"
,
tbuf
);
sprintf
(
tableDes
->
cols
[
i
].
value
,
"%s"
,
tbuf
);
}
else
{
}
else
{
tableDes
->
cols
[
i
].
var_value
=
calloc
(
1
,
len
*
4
);
tableDes
->
cols
[
i
].
var_value
=
calloc
(
1
,
n
len
*
4
);
if
(
tableDes
->
cols
[
i
].
var_value
==
NULL
)
{
if
(
tableDes
->
cols
[
i
].
var_value
==
NULL
)
{
errorPrint
(
"%s() LN%d, memory alalocation failed!
\n
"
,
errorPrint
(
"%s() LN%d, memory alalocation failed!
\n
"
,
__func__
,
__LINE__
);
__func__
,
__LINE__
);
...
@@ -1303,7 +1303,7 @@ static int getTableDes(
...
@@ -1303,7 +1303,7 @@ static int getTableDes(
converStringToReadable
(
converStringToReadable
(
(
char
*
)
row
[
TSDB_SHOW_TABLES_NAME_INDEX
],
(
char
*
)
row
[
TSDB_SHOW_TABLES_NAME_INDEX
],
length
[
0
],
length
[
0
],
(
char
*
)(
tableDes
->
cols
[
i
].
var_value
),
len
);
(
char
*
)(
tableDes
->
cols
[
i
].
var_value
),
n
len
);
}
}
break
;
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
...
...
src/plugins/CMakeLists.txt
浏览文件 @
4883bfb4
...
@@ -41,7 +41,7 @@ ELSE ()
...
@@ -41,7 +41,7 @@ ELSE ()
COMMAND git clean -f -d
COMMAND git clean -f -d
BUILD_COMMAND CGO_CFLAGS=-I
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc CGO_LDFLAGS=-L
${
CMAKE_BINARY_DIR
}
/build/lib go build -ldflags
"-s -w -X github.com/taosdata/taosadapter/version.CommitID=
${
taosadapter_commit_sha1
}
"
BUILD_COMMAND CGO_CFLAGS=-I
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc CGO_LDFLAGS=-L
${
CMAKE_BINARY_DIR
}
/build/lib go build -ldflags
"-s -w -X github.com/taosdata/taosadapter/version.CommitID=
${
taosadapter_commit_sha1
}
"
INSTALL_COMMAND
INSTALL_COMMAND
COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar xvJf upx.tar.xz --strip-components 1
&& ./upx taosadapter
COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar xvJf upx.tar.xz --strip-components 1
> /dev/null && ./upx taosadapter || :
COMMAND cmake -E copy taosadapter
${
CMAKE_BINARY_DIR
}
/build/bin
COMMAND cmake -E copy taosadapter
${
CMAKE_BINARY_DIR
}
/build/bin
COMMAND cmake -E make_directory
${
CMAKE_BINARY_DIR
}
/test/cfg/
COMMAND cmake -E make_directory
${
CMAKE_BINARY_DIR
}
/test/cfg/
COMMAND cmake -E copy ./example/config/taosadapter.toml
${
CMAKE_BINARY_DIR
}
/test/cfg/
COMMAND cmake -E copy ./example/config/taosadapter.toml
${
CMAKE_BINARY_DIR
}
/test/cfg/
...
...
src/query/src/tdigest.c
浏览文件 @
4883bfb4
...
@@ -296,7 +296,7 @@ double tdigestQuantile(TDigest *t, double q) {
...
@@ -296,7 +296,7 @@ double tdigestQuantile(TDigest *t, double q) {
a
=
b
;
a
=
b
;
right
=
t
->
max
;
right
=
t
->
max
;
if
(
idx
<
weight_so_far
+
a
->
weight
)
{
if
(
idx
<
weight_so_far
+
a
->
weight
&&
a
->
weight
!=
0
)
{
double
p
=
(
idx
-
weight_so_far
)
/
a
->
weight
;
double
p
=
(
idx
-
weight_so_far
)
/
a
->
weight
;
return
left
*
(
1
-
p
)
+
right
*
p
;
return
left
*
(
1
-
p
)
+
right
*
p
;
}
}
...
...
src/sync/src/syncRetrieve.c
浏览文件 @
4883bfb4
...
@@ -233,7 +233,7 @@ static int64_t syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index)
...
@@ -233,7 +233,7 @@ static int64_t syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index)
int32_t
once
=
0
;
// last WAL has once ever been processed
int32_t
once
=
0
;
// last WAL has once ever been processed
int64_t
offset
=
0
;
int64_t
offset
=
0
;
uint64_t
fversion
=
0
;
uint64_t
fversion
=
0
;
char
fname
[
TSDB_FILENAME_LEN
*
2
]
=
{
0
};
// full path to wal file
char
fname
[
TSDB_FILENAME_LEN
*
3
]
=
{
0
};
// full path to wal file
// get full path to wal file
// get full path to wal file
snprintf
(
fname
,
sizeof
(
fname
),
"%s/%s"
,
pNode
->
path
,
wname
);
snprintf
(
fname
,
sizeof
(
fname
),
"%s/%s"
,
pNode
->
path
,
wname
);
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
4883bfb4
...
@@ -229,7 +229,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
...
@@ -229,7 +229,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
SBlockIdx
*
pBlkIdx
;
SBlockIdx
*
pBlkIdx
;
size_t
nidx
=
taosArrayGetSize
(
pIdxA
);
size_t
nidx
=
taosArrayGetSize
(
pIdxA
);
int
tlen
=
0
,
size
;
int
tlen
=
0
,
size
;
int64_t
offset
;
int64_t
offset
=
0
;
if
(
nidx
<=
0
)
{
if
(
nidx
<=
0
)
{
// All data are deleted
// All data are deleted
...
@@ -1186,7 +1186,7 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDFile
...
@@ -1186,7 +1186,7 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDFile
return
-
1
;
return
-
1
;
}
}
uint32_t
aggrStatus
=
((
nColsNotAllNull
>
0
)
&&
(
rowsToWrite
>
8
))
?
1
:
0
;
// TODO: How to make the decision?
uint32_t
aggrStatus
=
nColsNotAllNull
>
0
?
1
:
0
;
if
(
aggrStatus
>
0
)
{
if
(
aggrStatus
>
0
)
{
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pAggrBlkData
,
tsizeAggr
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pAggrBlkData
,
tsizeAggr
);
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
4883bfb4
...
@@ -1544,7 +1544,7 @@ static void mergeTwoRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
...
@@ -1544,7 +1544,7 @@ static void mergeTwoRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
int16_t
offset
;
int16_t
offset
;
bool
isRow1DataRow
=
isDataRow
(
row1
);
bool
isRow1DataRow
=
isDataRow
(
row1
);
bool
isRow2DataRow
;
bool
isRow2DataRow
=
false
;
bool
isChosenRowDataRow
;
bool
isChosenRowDataRow
;
int32_t
chosen_itr
;
int32_t
chosen_itr
;
void
*
value
;
void
*
value
;
...
...
src/util/src/talgo.c
浏览文件 @
4883bfb4
...
@@ -230,7 +230,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
...
@@ -230,7 +230,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
{
{
int32_t
parent
;
int32_t
parent
;
int32_t
child
;
int32_t
child
;
char
*
buf
;
char
*
buf
=
NULL
;
if
(
base
&&
size
>
0
&&
compar
)
{
if
(
base
&&
size
>
0
&&
compar
)
{
parent
=
start
;
parent
=
start
;
...
...
src/util/src/tlog.c
浏览文件 @
4883bfb4
...
@@ -566,7 +566,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen)
...
@@ -566,7 +566,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen)
int32_t
end
=
0
;
int32_t
end
=
0
;
int32_t
remainSize
=
0
;
int32_t
remainSize
=
0
;
static
int64_t
lostLine
=
0
;
static
int64_t
lostLine
=
0
;
char
tmpBuf
[
4
0
]
=
{
0
};
char
tmpBuf
[
6
0
]
=
{
0
};
int32_t
tmpBufLen
=
0
;
int32_t
tmpBufLen
=
0
;
if
(
tLogBuff
==
NULL
||
tLogBuff
->
stop
)
return
-
1
;
if
(
tLogBuff
==
NULL
||
tLogBuff
->
stop
)
return
-
1
;
...
...
src/util/src/tqueue.c
浏览文件 @
4883bfb4
...
@@ -258,9 +258,9 @@ void taosCloseQset(taos_qset param) {
...
@@ -258,9 +258,9 @@ void taosCloseQset(taos_qset param) {
pthread_mutex_unlock
(
&
qset
->
mutex
);
pthread_mutex_unlock
(
&
qset
->
mutex
);
pthread_mutex_destroy
(
&
qset
->
mutex
);
pthread_mutex_destroy
(
&
qset
->
mutex
);
uTrace
(
"qset:%p is closed"
,
qset
);
tsem_destroy
(
&
qset
->
sem
);
tsem_destroy
(
&
qset
->
sem
);
free
(
qset
);
free
(
qset
);
uTrace
(
"qset:%p is closed"
,
qset
);
}
}
// tsem_post 'qset->sem', so that reader threads waiting for it
// tsem_post 'qset->sem', so that reader threads waiting for it
...
...
src/util/src/tworker.c
浏览文件 @
4883bfb4
...
@@ -91,6 +91,6 @@ void *tWorkerAllocQueue(SWorkerPool *pPool, void *ahandle) {
...
@@ -91,6 +91,6 @@ void *tWorkerAllocQueue(SWorkerPool *pPool, void *ahandle) {
}
}
void
tWorkerFreeQueue
(
SWorkerPool
*
pPool
,
void
*
pQueue
)
{
void
tWorkerFreeQueue
(
SWorkerPool
*
pPool
,
void
*
pQueue
)
{
taosCloseQueue
(
pQueue
);
uDebug
(
"worker:%s, queue:%p is freed"
,
pPool
->
name
,
pQueue
);
uDebug
(
"worker:%s, queue:%p is freed"
,
pPool
->
name
,
pQueue
);
taosCloseQueue
(
pQueue
);
}
}
tests/pytest/functions/queryTestCases-td3690.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
# master branch
self
.
td3690
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td4082.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
self
.
td4082
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td4097.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
self
.
td4097
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td4288.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
self
.
td4288
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td4724.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
self
.
td4724
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td5790.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
# master branch
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
self
.
td5798
()
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td5935.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
self
.
td5935
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/pytest/functions/queryTestCases-td6068.py
0 → 100644
浏览文件 @
4883bfb4
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
subprocess
import
random
import
math
import
numpy
as
np
import
inspect
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to execute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/debug/build/bin"
)]
break
return
buildPath
def
getCfgDir
(
self
)
->
str
:
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
cfgDir
=
self
.
getBuildPath
()
+
"/community/sim/dnode1/cfg"
else
:
cfgDir
=
self
.
getBuildPath
()
+
"/sim/dnode1/cfg"
return
cfgDir
def
getCfgFile
(
self
)
->
str
:
return
self
.
getCfgDir
()
+
"/taos.cfg"
def
td3690
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-3690=========="
)
tdSql
.
prepare
()
tdSql
.
execute
(
"show variables"
)
res_off
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_off
)
index
=
np
.
where
(
resList
==
"offlineThreshold"
)
index_value
=
np
.
dstack
((
index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
864000
)
def
td4082
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4082=========="
)
tdSql
.
prepare
()
cfgfile
=
self
.
getCfgFile
()
max_compressMsgSize
=
100000000
tdSql
.
execute
(
"show variables"
)
res_com
=
tdSql
.
cursor
.
fetchall
()
rescomlist
=
np
.
array
(
res_com
)
cpms_index
=
np
.
where
(
rescomlist
==
"compressMsgSize"
)
index_value
=
np
.
dstack
((
cpms_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$a compressMSgSize
{
max_compressMsgSize
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
100000000
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$s/
{
max_compressMsgSize
}
/
{
max_compressMsgSize
+
10
}
/g'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
-
1
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
def
td4097
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4097=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"create database if not exists db1 keep 3650"
)
tdSql
.
execute
(
"create database if not exists new keep 3650"
)
tdSql
.
execute
(
"create database if not exists private keep 3650"
)
tdSql
.
execute
(
"create database if not exists db2 keep 3650"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create stable db1.stb3 (ts timestamp, c1 int) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t10 using db.stb1 tags(1)"
)
tdSql
.
execute
(
"create table db.t11 using db.stb1 tags(2)"
)
tdSql
.
execute
(
"create table db.t20 using db.stb2 tags(3)"
)
tdSql
.
execute
(
"create table db1.t30 using db1.stb3 tags(4)"
)
# tdLog.printNoPrefix("==========TD-4097==========")
# 插入数据,然后进行show create 操作
# p1 不进入指定数据库
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database new"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database private"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stable stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table stb1"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
# p2 进入指定数据库
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create database db1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create database "
)
tdSql
.
error
(
"show create databases db "
)
tdSql
.
error
(
"show create database db.stb1"
)
tdSql
.
error
(
"show create database db0"
)
tdSql
.
error
(
"show create database db db1"
)
tdSql
.
error
(
"show create database db, db1"
)
tdSql
.
error
(
"show create database stb1"
)
tdSql
.
error
(
"show create database * "
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db1.stb3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create stable db.t10"
)
tdSql
.
error
(
"show create stable db"
)
tdSql
.
error
(
"show create stable t10"
)
tdSql
.
error
(
"show create stable db.stb0"
)
tdSql
.
error
(
"show create stables stb1"
)
tdSql
.
error
(
"show create stable "
)
tdSql
.
error
(
"show create stable *"
)
tdSql
.
error
(
"show create stable db.stb1 db.stb2"
)
tdSql
.
error
(
"show create stable stb1 stb2"
)
tdSql
.
error
(
"show create stable db.stb1, db.stb2"
)
tdSql
.
error
(
"show create stable stb1, stb2"
)
tdSql
.
query
(
"show create table db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db.t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table db1.t30"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"show create table t30"
)
tdSql
.
error
(
"show create table db.stb0"
)
tdSql
.
error
(
"show create table db.t0"
)
tdSql
.
error
(
"show create table db"
)
tdSql
.
error
(
"show create tables stb1"
)
tdSql
.
error
(
"show create tables t10"
)
tdSql
.
error
(
"show create table "
)
tdSql
.
error
(
"show create table *"
)
tdSql
.
error
(
"show create table db.stb1 db.stb2"
)
tdSql
.
error
(
"show create table db.t11 db.t10"
)
tdSql
.
error
(
"show create table db.stb1, db.stb2"
)
tdSql
.
error
(
"show create table db.t11, db.t10"
)
tdSql
.
error
(
"show create table stb1 stb2"
)
tdSql
.
error
(
"show create table t11 t10"
)
tdSql
.
error
(
"show create table stb1, stb2"
)
tdSql
.
error
(
"show create table t11, t10"
)
# p3 删库删表后进行查询
tdSql
.
execute
(
"drop table if exists t11"
)
tdSql
.
error
(
"show create table t11"
)
tdSql
.
error
(
"show create table db.t11"
)
tdSql
.
query
(
"show create stable stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create table t10"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop stable if exists stb2"
)
tdSql
.
error
(
"show create table stb2"
)
tdSql
.
error
(
"show create table db.stb2"
)
tdSql
.
error
(
"show create stable stb2"
)
tdSql
.
error
(
"show create stable db.stb2"
)
tdSql
.
error
(
"show create stable db.t20"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
error
(
"show create database db1"
)
tdSql
.
error
(
"show create stable db1.t31"
)
tdSql
.
error
(
"show create stable db1.stb3"
)
tdSql
.
query
(
"show create database db"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"show create stable db.stb1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"drop database if exists db1"
)
tdSql
.
execute
(
"drop database if exists new"
)
tdSql
.
execute
(
"drop database if exists db2"
)
tdSql
.
execute
(
"drop database if exists private"
)
def
td4153
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4153=========="
)
pass
def
td4288
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4288=========="
)
# keep ~ [days,365000]
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db"
)
tdSql
.
execute
(
"show variables"
)
res_kp
=
tdSql
.
cursor
.
fetchall
()
resList
=
np
.
array
(
res_kp
)
keep_index
=
np
.
where
(
resList
==
"keep"
)
index_value
=
np
.
dstack
((
keep_index
[
0
])).
squeeze
()
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
query
(
"show databases"
)
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
days
=
tdSql
.
getData
(
0
,
6
)
tdSql
.
error
(
"alter database db keep 3650001"
)
tdSql
.
error
(
"alter database db keep 9"
)
tdSql
.
error
(
"alter database db keep 0b"
)
tdSql
.
error
(
"alter database db keep 3650,9,36500"
)
tdSql
.
error
(
"alter database db keep 3650,3650,365001"
)
tdSql
.
error
(
"alter database db keep 36500,a,36500"
)
tdSql
.
error
(
"alter database db keep (36500,3650,3650)"
)
tdSql
.
error
(
"alter database db keep [36500,3650,36500]"
)
tdSql
.
error
(
"alter database db keep 36500,0xff,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0o365,3650"
)
tdSql
.
error
(
"alter database db keep 36500,0A3Ch,3650"
)
tdSql
.
error
(
"alter database db keep"
)
tdSql
.
error
(
"alter database db keep0 36500"
)
tdSql
.
execute
(
"alter database db keep 36500"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"36500,36500,36500"
)
else
:
tdSql
.
checkData
(
0
,
7
,
36500
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db1"
)
tdSql
.
query
(
"show databases"
)
if
(
"community"
in
selfPath
):
tdSql
.
checkData
(
0
,
7
,
"3650,3650,3650"
)
else
:
tdSql
.
checkData
(
0
,
7
,
3650
)
tdSql
.
query
(
"show variables"
)
tdSql
.
checkData
(
index_value
,
1
,
3650
)
tdSql
.
execute
(
"alter database db1 keep 365"
)
tdSql
.
execute
(
"drop database if exists db1"
)
pass
def
td4724
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4724=========="
)
cfgfile
=
self
.
getCfgFile
()
minTablesPerVnode
=
5
maxTablesPerVnode
=
10
maxVgroupsPerDb
=
100
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
vnode_cmd
=
f
"sed -i '$a maxVgroupsPerDb
{
maxVgroupsPerDb
}
'
{
cfgfile
}
"
min_cmd
=
f
"sed -i '$a minTablesPerVnode
{
minTablesPerVnode
}
'
{
cfgfile
}
"
max_cmd
=
f
"sed -i '$a maxTablesPerVnode
{
maxTablesPerVnode
}
'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
vnode_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
min_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
max_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
insert_sql
=
"insert into "
for
i
in
range
(
100
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
insert_sql
+=
f
" t1
{
i
}
values(
{
1604298064000
+
i
*
1000
}
,
{
i
}
)"
tdSql
.
query
(
"show dnodes"
)
vnode_count
=
tdSql
.
getData
(
0
,
2
)
if
vnode_count
<=
1
:
tdLog
.
exit
(
"vnode is less than 2"
)
tdSql
.
execute
(
insert_sql
)
tdDnodes
.
stop
(
index
)
cmd
=
f
"sed -i '$d'
{
cfgfile
}
"
try
:
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
_
=
subprocess
.
check_output
(
cmd
,
shell
=
True
).
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
e
tdDnodes
.
start
(
index
)
pass
def
td4889
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-4889=========="
)
cfg
=
{
'minRowsPerFileBlock'
:
'10'
,
'maxRowsPerFileBlock'
:
'200'
,
'minRows'
:
'10'
,
'maxRows'
:
'200'
,
'maxVgroupsPerDb'
:
'100'
,
'maxTablesPerVnode'
:
'1200'
,
}
tdSql
.
query
(
"show dnodes"
)
dnode_index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
dnode_index
)
tdDnodes
.
deploy
(
dnode_index
,
cfg
)
tdDnodes
.
start
(
dnode_index
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650 blocks 3 minrows 10 maxrows 200"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t1 int)"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
for
i
in
range
(
1000
):
tdSql
.
execute
(
f
"create table db.t1
{
i
}
using db.stb1 tags(
{
i
}
)"
)
sql
=
f
"insert into db.t1
{
i
}
values"
for
j
in
range
(
260
):
sql
+=
f
"(
{
nowtime
-
1000
*
i
-
j
}
,
{
i
+
j
}
)"
# tdSql.execute(f"insert into db.t1{i} values (now-100d, {i+j})")
tdSql
.
execute
(
sql
)
# tdDnodes.stop(dnode_index)
# tdDnodes.start(dnode_index)
tdSql
.
query
(
"show vgroups"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
checkData
(
0
,
6
,
0
)
tdSql
.
execute
(
f
"compact vnodes in(
{
index
}
)"
)
start_time
=
time
.
time
()
while
True
:
tdSql
.
query
(
"show vgroups"
)
if
tdSql
.
getData
(
0
,
6
)
!=
0
:
tdLog
.
printNoPrefix
(
"show vgroups row:0 col:6 data:1 == expect:1"
)
break
run_time
=
time
.
time
()
-
start_time
if
run_time
>
3
:
tdLog
.
exit
(
"compacting not occured"
)
# time.sleep(0.1)
pass
def
td5168insert
(
self
):
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 float, c2 float, c3 double, c4 double) tags(t1 int)"
)
tdSql
.
execute
(
"create table db.t1 using db.stb1 tags(1)"
)
for
i
in
range
(
5
):
c1
=
1001.11
+
i
*
0.1
c2
=
1001.11
+
i
*
0.1
+
1
*
0.01
c3
=
1001.11
+
i
*
0.1
+
2
*
0.01
c4
=
1001.11
+
i
*
0.1
+
3
*
0.01
tdSql
.
execute
(
f
"insert into db.t1 values ('2021-07-01 08:00:0
{
i
}
.000',
{
c1
}
,
{
c2
}
,
{
c3
}
,
{
c4
}
)"
)
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:00.000', 1001.11, 1001.12, 1001.13, 1001.14)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:01.000', 1001.21, 1001.22, 1001.23, 1001.24)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:02.000', 1001.31, 1001.32, 1001.33, 1001.34)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:03.000', 1001.41, 1001.42, 1001.43, 1001.44)")
# tdSql.execute("insert into db.t1 values ('2021-07-01 08:00:04.000', 1001.51, 1001.52, 1001.53, 1001.54)")
# for i in range(1000000):
for
i
in
range
(
10000
):
random1
=
random
.
uniform
(
1000
,
1001
)
random2
=
random
.
uniform
(
1000
,
1001
)
random3
=
random
.
uniform
(
1000
,
1001
)
random4
=
random
.
uniform
(
1000
,
1001
)
tdSql
.
execute
(
f
"insert into db.t1 values (now+
{
i
}
a,
{
random1
}
,
{
random2
}
,
{
random3
}
,
{
random4
}
)"
)
pass
def
td5168
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5168=========="
)
# 插入小范围内的随机数
tdLog
.
printNoPrefix
(
"=====step0: 默认情况下插入数据========"
)
self
.
td5168insert
()
# 获取五个时间点的数据作为基准数值,未压缩情况下精准匹配
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)]
=
tdSql
.
getData
(
0
,
j
+
1
)
print
(
f
"f
{
j
}{
i
}
:"
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# tdSql.query("select * from db.t1 limit 100,1")
# f10, f11, f12, f13 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000,1")
# f20, f21, f22, f23 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 10000,1")
# f30, f31, f32, f33 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 100000,1")
# f40, f41, f42, f43 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
#
# tdSql.query("select * from db.t1 limit 1000000,1")
# f50, f51, f52, f53 = tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0,3), tdSql.getData(0,4)
# 关闭服务并获取未开启压缩情况下的数据容量
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
cfgdir
=
self
.
getCfgDir
()
cfgfile
=
self
.
getCfgFile
()
lossy_cfg_cmd
=
f
"grep lossyColumns
{
cfgfile
}
|awk '{{print $2}}'"
data_size_cmd
=
f
"du -s
{
cfgdir
}
/../data/vnode/ | awk '{{print $1}}'"
dsize_init
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"close the lossyColumns,data size is:
{
dsize_init
}
;the lossyColumns line is:
{
lossy_args
}
"
)
###################################################
float_lossy
=
"float"
double_lossy
=
"double"
float_double_lossy
=
"float|double"
no_loosy
=
""
double_precision_cmd
=
f
"sed -i '$a dPrecision 0.000001'
{
cfgfile
}
"
_
=
subprocess
.
check_output
(
double_precision_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
lossy_float_cmd
=
f
"sed -i '$a lossyColumns
{
float_lossy
}
'
{
cfgfile
}
"
lossy_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
double_lossy
}
'
{
cfgfile
}
"
lossy_float_double_cmd
=
f
"sed -i '$d'
{
cfgfile
}
&& sed -i '$a lossyColumns
{
float_double_lossy
}
'
{
cfgfile
}
"
lossy_no_cmd
=
f
"sed -i '$a lossyColumns
{
no_loosy
}
'
{
cfgfile
}
"
###################################################
# 开启有损压缩,参数float,并启动服务插入数据
tdLog
.
printNoPrefix
(
"=====step1: lossyColumns设置为float========"
)
lossy_float
=
subprocess
.
check_output
(
lossy_float_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
# c1, c2, c3, c4 = tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4)
for
j
in
range
(
4
):
# locals()["f" + str(j) + str(i)] = tdSql.getData(0, j+1)
# print(f"f{j}{i}:", locals()["f" + str(j) + str(i)])
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为float情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数double,并启动服务
tdLog
.
printNoPrefix
(
"=====step2: lossyColumns设置为double========"
)
lossy_double
=
subprocess
.
check_output
(
lossy_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为double情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
# 修改有损压缩,参数 float&&double ,并启动服务
tdLog
.
printNoPrefix
(
"=====step3: lossyColumns设置为 float&&double ========"
)
lossy_float_double
=
subprocess
.
check_output
(
lossy_float_double_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdDnodes
.
start
(
index
)
self
.
td5168insert
()
# 查询前面所述5个时间数据并与基准数值进行比较
for
i
in
range
(
5
):
tdSql
.
query
(
f
"select * from db.t1 where ts='2021-07-01 08:00:0
{
i
}
.000' "
)
for
j
in
range
(
4
):
tdSql
.
checkData
(
0
,
j
+
1
,
locals
()[
"f"
+
str
(
j
)
+
str
(
i
)])
# 关闭服务并获取压缩参数为 float&&double 情况下的数据容量
tdDnodes
.
stop
(
index
)
dsize_float_double
=
int
(
subprocess
.
check_output
(
data_size_cmd
,
shell
=
True
).
decode
(
"utf-8"
))
lossy_args
=
subprocess
.
check_output
(
lossy_cfg_cmd
,
shell
=
True
).
decode
(
"utf-8"
)
tdLog
.
printNoPrefix
(
f
"open the lossyColumns, data size is:
{
dsize_float_double
}
;the lossyColumns line is:
{
lossy_args
}
"
)
if
not
((
dsize_float_double
<
dsize_init
)
and
(
dsize_double
<
dsize_init
)
and
(
dsize_float
<
dsize_init
))
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
exit
(
"压缩未生效"
)
else
:
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float, data size is:
{
dsize_float
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is double, data size is:
{
dsize_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns value is float and double, data size is:
{
dsize_float_double
}
"
)
tdLog
.
printNoPrefix
(
f
"When lossyColumns is closed, data size is:
{
dsize_init
}
"
)
tdLog
.
printNoPrefix
(
"压缩生效"
)
pass
def
td5433
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5433=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int) tags(t0 tinyint, t1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(t0 binary(16), t1 binary(16))"
)
numtab
=
20000
for
i
in
range
(
numtab
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
128
}
,
{
100
+
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
*
2
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
*
3
}
)"
)
tdSql
.
execute
(
"create table db.t01 using db.stb2 tags('1', '100')"
)
tdSql
.
execute
(
"create table db.t02 using db.stb2 tags('2', '200')"
)
tdSql
.
execute
(
"create table db.t03 using db.stb2 tags('3', '300')"
)
tdSql
.
execute
(
"create table db.t04 using db.stb2 tags('4', '400')"
)
tdSql
.
execute
(
"create table db.t05 using db.stb2 tags('5', '500')"
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != '150'"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 != 150"
)
tdSql
.
checkRows
(
numtab
-
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = 150"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1 where t1 = '150'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
numtab
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != '2'"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 != 2"
)
tdSql
.
checkRows
(
127
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb1"
)
tdSql
.
checkRows
(
128
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != '200'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 != 200"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = 200"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2 where t1 = '200'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t1 from stb2"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != '2'"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 != 2"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2 where t0 = '2'"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0 from stb2"
)
tdSql
.
checkRows
(
5
)
pass
def
td5798
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5798 + TD-5810=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)"
)
maxRemainderNum
=
7
tbnum
=
101
for
i
in
range
(
tbnum
-
1
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
maxRemainderNum
}
,
{
(
i
-
1
)
%
maxRemainderNum
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10d,
{
i
}
,
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9d,
{
i
}
,
{
(
i
-
1
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8d,
{
i
}
,
{
(
i
-
2
)
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
f
"create table db.t0
{
i
}
using db.stb2 tags('
{
i
%
maxRemainderNum
}
', '
{
(
i
-
1
)
%
maxRemainderNum
}
',
{
i
%
3
}
)"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-10d,
{
i
}
, '
{
(
i
+
1
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-9d,
{
i
}
, '
{
(
i
+
2
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
values (now-8d,
{
i
}
, '
{
(
i
)
%
3
}
')"
)
tdSql
.
execute
(
f
"insert into db.t0
{
i
}
(ts )values (now-7d)"
)
tdSql
.
execute
(
"create table db.t100num using db.stb1 tags(null, null, null)"
)
tdSql
.
execute
(
"create table db.t0100num using db.stb2 tags(null, null, null)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t100num (ts )values (now-7d)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-10d,
{
tbnum
-
1
}
, 1)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-9d,
{
tbnum
-
1
}
, 0)"
)
tdSql
.
execute
(
f
"insert into db.t0100num values (now-8d,
{
tbnum
-
1
}
, 2)"
)
tdSql
.
execute
(
f
"insert into db.t0100num (ts )values (now-7d)"
)
#========== TD-5810 suport distinct multi-data-coloumn ==========
tdSql
.
query
(
f
"select distinct c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c2 from stb1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from stb1 where c1 <
{
tbnum
}
limit 3 offset
{
tbnum
*
3
-
2
}
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c2 from t1"
)
tdSql
.
checkRows
(
4
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 "
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
f
"select distinct c1,c1 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from t1 where c1 <
{
tbnum
}
limit 3 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
f
"select distinct c3 from stb2 where c2 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c3, c2 from stb2 where c2 <
{
tbnum
}
limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
"select distinct c5 from stb1"
)
tdSql
.
error
(
"select distinct c5 from t1"
)
tdSql
.
error
(
"select distinct c1 from db.*"
)
tdSql
.
error
(
"select c2, distinct c1 from stb1"
)
tdSql
.
error
(
"select c2, distinct c1 from t1"
)
tdSql
.
error
(
"select distinct c2 from "
)
tdSql
.
error
(
"distinct c2 from stb1"
)
tdSql
.
error
(
"distinct c2 from t1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from stb1"
)
tdSql
.
error
(
"select distinct c1, c2, c3 from t1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1"
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from stb1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
tbnum
*
3
)
tdSql
.
query
(
f
"select distinct c1 c2, c2 c3 from t1 where c1 <
{
tbnum
}
"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 order by ts"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 order by ts"
)
tdSql
.
error
(
"select distinct c1, ts from stb1 group by c2"
)
tdSql
.
error
(
"select distinct c1, ts from t1 group by c2"
)
tdSql
.
error
(
"select distinct c1, max(c2) from stb1 "
)
tdSql
.
error
(
"select distinct c1, max(c2) from t1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from stb1 "
)
tdSql
.
error
(
"select max(c2), distinct c1 from t1 "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct c1, c2 from stb1 where c1 > 3 slimit 1"
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 slimit 1"
)
tdSql
.
query
(
f
"select distinct c1, c2 from stb1 where c1 between
{
tbnum
-
2
}
and
{
tbnum
}
"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select distinct c1, c2 from stb1 where c1 in (100,1000,10000)"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where c1 >
{
tbnum
-
2
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from t1 where c1 <
{
tbnum
}
) "
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
f
"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) "
)
tdSql
.
checkRows
(
0
)
tdSql
.
error
(
"select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
query
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)"
)
# tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)")
tdSql
.
error
(
"select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)"
)
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)")
# tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)")
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts "
)
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)")
# tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)")
#========== TD-5798 suport distinct multi-tags-coloumn ==========
tdSql
.
query
(
"select distinct t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0, t1, t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
*
2
+
1
)
tdSql
.
query
(
"select distinct t0 t1, t1 t2 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t0, t0 from stb1"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t0, t1 from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from t100num"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t4, t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2, t3, t4 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
*
3
+
1
)
tdSql
.
query
(
"select distinct t2 t1, t3 t2 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t3, t3, t3 from stb2"
)
tdSql
.
checkRows
(
maxRemainderNum
+
1
)
tdSql
.
query
(
"select distinct t2, t3 from t01"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t3, t4 from t0100num"
)
tdSql
.
checkRows
(
1
)
########## should be error #########
tdSql
.
error
(
"select distinct from stb1"
)
tdSql
.
error
(
"select distinct t3 from stb1"
)
tdSql
.
error
(
"select distinct t1 from db.*"
)
tdSql
.
error
(
"select distinct t2 from "
)
tdSql
.
error
(
"distinct t2 from stb1"
)
tdSql
.
error
(
"select distinct stb1"
)
tdSql
.
error
(
"select distinct t0, t1, t2, t3 from stb1"
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select dist t0 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2, stb2.t3 from stb1"
)
tdSql
.
error
(
"select distinct stb2.t2 t1, stb2.t3 t2 from stb1"
)
tdSql
.
error
(
"select distinct t0, t1 from t1 where t0 < 7"
)
########## add where condition ##########
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2"
)
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 slimit 2"
)
tdSql
.
checkRows
(
3
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where c1 > 2"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where stb2.t4 > 2"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 group by t0"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)"
)
tdSql
.
error
(
"select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
tdSql
.
error
(
"select max(c1), distinct t0 from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0, max(c1) from stb1 where t0 > 2"
)
tdSql
.
error
(
"select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)"
)
tdSql
.
query
(
"select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2) "
)
tdSql
.
checkRows
(
4
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) "
)
tdSql
.
error
(
"select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
query
(
"select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
"select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)"
)
tdSql
.
error
(
"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)"
)
tdSql
.
query
(
"select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
checkRows
(
1
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3"
)
tdSql
.
error
(
"select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3"
)
tdSql
.
error
(
" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3"
)
tdSql
.
error
(
"select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4"
)
tdSql
.
error
(
"select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts "
)
pass
def
td5935
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-5935=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 int)"
)
nowtime
=
int
(
round
((
time
.
time
()
*
1000
)))
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
%
7
}
,
{
i
%
2
}
)"
tdSql
.
execute
(
sql
)
for
j
in
range
(
1000
):
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (
{
nowtime
-
j
*
10
}
,
{
1000
-
j
}
,
{
round
(
random
.
random
()
*
j
,
3
)
}
)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts) values (
{
nowtime
-
10000
}
) "
)
########### TD-5933 verify the bug of "function stddev with interval return 0 rows" is fixed ##########
stddevAndIntervalSql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
interval(10a) limit 10"
tdSql
.
query
(
stddevAndIntervalSql
)
tdSql
.
checkRows
(
10
)
########## TD-5978 verify the bug of "when start row is null, result by fill(next) is 0 " is fixed ##########
fillsql
=
f
"select last(*) from t0 where ts>=
{
nowtime
-
10000
}
and ts<
{
nowtime
}
interval(10a) fill(next) limit 10"
tdSql
.
query
(
fillsql
)
fillResult
=
False
if
(
tdSql
.
getData
(
0
,
2
)
!=
0
)
and
(
tdSql
.
getData
(
0
,
2
)
is
not
None
):
fillResult
=
True
if
fillResult
:
tdLog
.
success
(
f
"sql is :
{
fillsql
}
, fill(next) is correct"
)
else
:
tdLog
.
exit
(
"fill(next) is wrong"
)
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
apercentile_query_form
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
"'t-digest'"
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
'''
apercentile function:
:param col: string, column name, required parameters;
:param p: float, percentile interval, [0,100], required parameters;
:param algo: string, alforithm, real form like: ', algorithm' , algorithm: {type:int, data:[0, 1]};
:param alias: string, result column another name;
:param table_expr: string or expression, data source(eg,table/stable name, result set), required parameters;
:param condition: expression;
:param args: other funtions,like: ', last(col)'
:return: apercentile query statement,default: select apercentile(c1, 0, 1) from t1
'''
return
f
"select apercentile(
{
col
}
,
{
p
}{
com
}
{
algo
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
def
checkapert
(
self
,
col
=
"c1"
,
p
=
0
,
com
=
','
,
algo
=
'"t-digest"'
,
alias
=
""
,
table_expr
=
"t1"
,
condition
=
""
):
tdSql
.
query
(
f
"select count(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
p
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
tdSql
.
checkRows
(
0
)
return
pset
=
[
0
,
40
,
60
,
100
]
if
p
not
in
pset
:
pset
.
append
(
p
)
if
"stb"
in
table_expr
:
tdSql
.
query
(
f
"select spread(
{
col
}
) from stb1"
)
else
:
tdSql
.
query
(
f
"select avg(c1) from (select spread(
{
col
.
split
(
'.'
)[
-
1
]
}
) c1 from stb1 group by tbname)"
)
spread_num
=
tdSql
.
getData
(
0
,
0
)
for
pi
in
pset
:
if
"group"
in
condition
:
tdSql
.
query
(
f
"select last_row(
{
col
}
) from
{
table_expr
}
{
condition
}
"
)
query_result
=
tdSql
.
queryResult
query_rows
=
tdSql
.
queryRows
for
i
in
range
(
query_rows
):
pre_condition
=
condition
.
replace
(
"slimit"
,
'limit'
).
replace
(
"group by tbname"
,
""
).
split
(
"soffset"
)[
0
]
tbname
=
query_result
[
i
][
-
1
]
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
tbname
}
{
pre_condition
}
"
)
print
(
tdSql
.
sql
)
pre_data
=
tdSql
.
getData
(
0
,
0
)
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"t-digest"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
i
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
i
,
0
,
pre_data
,
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
i
,
0
)
-
pre_data
)
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
i
,
0
)
}
, expect data:
{
pre_data
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
# if "group" in condition:
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"default"', alias=alias, table_expr=table_expr, condition=condition
# ))
# query_result = tdSql.queryResult
# query_rows = tdSql.queryRows
# tdSql.query(self.apercentile_query_form(
# col=col, p=pi, com=com, algo='"t-digest"', alias=alias, table_expr=table_expr, condition=condition
# ))
# for i in range(query_rows):
# if abs(tdSql.getData(i, 0)) >= (spread_num*0.02):
# tdSql.checkDeviaRation(i, 0, query_result[i][0], 0.1)
# else:
# devia = abs((tdSql.getData(i, 0) - query_result[i][0]) / (spread_num * 0.02))
# if devia < 0.5:
# tdLog.info(f"sql:{tdSql.sql}, result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} <= expect deviation: 0.01")
# else:
# tdLog.exit(
# f"[{inspect.getframeinfo(inspect.stack()[1][0]).lineno}],check failed:sql:{tdSql.sql}, "
# f"result data:{tdSql.getData(i, 0)}, expect data:{tdSql.queryResult[i][0]}, "
# f"actual deviation:{devia} > expect deviation: 0.01")
else
:
if
','
in
alias
or
not
alias
:
tdSql
.
query
(
f
"select
{
col
}
from
{
table_expr
}
{
condition
}
"
)
elif
"stb"
not
in
table_expr
:
tdSql
.
query
(
f
"select percentile(
{
col
}
,
{
pi
}
)
{
alias
}
from
{
table_expr
}
{
condition
}
"
)
else
:
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
'"default"'
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
self
.
apercentile_query_form
(
col
=
col
,
p
=
pi
,
com
=
com
,
algo
=
algo
,
alias
=
alias
,
table_expr
=
table_expr
,
condition
=
condition
))
if
abs
(
tdSql
.
getData
(
0
,
0
))
>=
(
spread_num
*
0.02
):
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
pi
),
0.1
)
else
:
devia
=
abs
((
tdSql
.
getData
(
0
,
0
)
-
np
.
percentile
(
query_result
,
pi
))
/
(
spread_num
*
0.02
))
if
devia
<
0.5
:
tdLog
.
info
(
f
"sql:
{
tdSql
.
sql
}
, result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
<= expect deviation: 0.01"
)
else
:
tdLog
.
exit
(
f
"[
{
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
]).
lineno
}
],check failed:sql:
{
tdSql
.
sql
}
, "
f
"result data:
{
tdSql
.
getData
(
0
,
0
)
}
, expect data:
{
np
.
percentile
(
query_result
,
pi
)
}
, "
f
"actual deviation:
{
devia
}
> expect deviation: 0.01"
)
def
apercentile_query
(
self
):
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
# case1: int col
self
.
checkapert
()
# case2: float col
case2
=
{
'col'
:
'c2'
}
self
.
checkapert
(
**
case2
)
# case3: double col
case3
=
{
'col'
:
'c5'
}
self
.
checkapert
(
**
case3
)
# case4: bigint col
case4
=
{
'col'
:
'c7'
}
self
.
checkapert
(
**
case4
)
# case5: smallint col
case5
=
{
'col'
:
'c8'
}
self
.
checkapert
(
**
case5
)
# case6: tinyint col
case6
=
{
'col'
:
'c9'
}
self
.
checkapert
(
**
case6
)
# case7: stable
case7
=
{
'table_expr'
:
'stb1'
}
self
.
checkapert
(
**
case7
)
# case8: nest query, outquery
case8
=
{
'table_expr'
:
'(select c1 from t1)'
}
self
.
checkapert
(
**
case8
)
# case9: nest query, inquery and out query
case9
=
{
'table_expr'
:
'(select apercentile(c1, 0) as c1 from t1)'
}
self
.
checkapert
(
**
case9
)
# case10: nest query, inquery
tdSql
.
query
(
"select * from (select c1 from stb1)"
)
if
tdSql
.
queryRows
==
0
:
tdSql
.
query
(
"select * from (select apercentile(c1,0) c1 from stb1)"
)
tdSql
.
checkRows
(
0
)
else
:
query_result
=
np
.
array
(
tdSql
.
queryResult
)[
np
.
array
(
tdSql
.
queryResult
)
!=
None
]
tdSql
.
query
(
"select * from (select apercentile(c1, 0) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
0
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,100) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
100
),
0.1
)
tdSql
.
query
(
"select * from (select apercentile(c1,40) c1 from stb1)"
)
tdSql
.
checkDeviaRation
(
0
,
0
,
np
.
percentile
(
query_result
,
40
),
0.1
)
# case11: no algorithm = algo:0
case11
=
{
'com'
:
''
,
'algo'
:
''
}
self
.
checkapert
(
**
case11
)
# case12~14: p: bin/oct/hex
case12
=
{
'p'
:
0b1100100
}
self
.
checkapert
(
**
case12
)
case13
=
{
'algo'
:
'"T-DIGEST"'
}
self
.
checkapert
(
**
case13
)
case14
=
{
'p'
:
0x32
,
'algo'
:
'"DEFAULT"'
}
self
.
checkapert
(
**
case14
)
# case15~21: mix with aggregate function
case15
=
{
'alias'
:
', count(*)'
}
self
.
checkapert
(
**
case15
)
case16
=
{
'alias'
:
', avg(c1)'
}
self
.
checkapert
(
**
case16
)
case17
=
{
'alias'
:
', twa(c1)'
}
self
.
checkapert
(
**
case17
)
case18
=
{
'alias'
:
', irate(c1)'
}
self
.
checkapert
(
**
case18
)
case19
=
{
'alias'
:
', sum(c1)'
}
self
.
checkapert
(
**
case19
)
case20
=
{
'alias'
:
', stddev(c1)'
}
self
.
checkapert
(
**
case20
)
case21
=
{
'alias'
:
', leastsquares(c1, 1, 1)'
}
self
.
checkapert
(
**
case21
)
# case22~27:mix with selector function
case22
=
{
'alias'
:
', min(c1)'
}
self
.
checkapert
(
**
case22
)
case23
=
{
'alias'
:
', max(c1)'
}
self
.
checkapert
(
**
case23
)
case24
=
{
'alias'
:
', first(c1)'
}
self
.
checkapert
(
**
case24
)
case25
=
{
'alias'
:
', last(c1)'
}
self
.
checkapert
(
**
case25
)
case26
=
{
'alias'
:
', percentile(c1, 0)'
}
self
.
checkapert
(
**
case26
)
case27
=
{
'alias'
:
', apercentile(c1, 0, "t-digest")'
}
self
.
checkapert
(
**
case27
)
# case28~29: mix with computing function
case28
=
{
'alias'
:
', spread(c1)'
}
self
.
checkapert
(
**
case28
)
# case29: mix with four operation
case29
=
{
'alias'
:
'+ spread(c1)'
}
self
.
checkapert
(
**
case29
)
# case30~36: with condition
case30
=
{
'condition'
:
'where ts > now'
}
self
.
checkapert
(
**
case30
)
case31
=
{
'condition'
:
'where c1 between 1 and 200'
}
self
.
checkapert
(
**
case31
)
case32
=
{
'condition'
:
f
'where c1 in
{
tuple
(
i
for
i
in
range
(
200
))
}
'
}
self
.
checkapert
(
**
case32
)
case33
=
{
'condition'
:
'where c1>100 and c2<100'
}
self
.
checkapert
(
**
case33
)
case34
=
{
'condition'
:
'where c1 is not null'
}
self
.
checkapert
(
**
case34
)
case35
=
{
'condition'
:
'where c4 like "_inary%"'
}
self
.
checkapert
(
**
case35
)
case36
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'where tbname like "t_"'
}
self
.
checkapert
(
**
case36
)
# case37~38: with join
case37
=
{
'col'
:
't1.c1'
,
'table_expr'
:
't1, t2 '
,
'condition'
:
'where t1.ts=t2.ts'
}
self
.
checkapert
(
**
case37
)
case38
=
{
'col'
:
'stb1.c1'
,
'table_expr'
:
'stb1, stb2'
,
'condition'
:
'where stb1.ts=stb2.ts and stb1.st1=stb2.st2'
}
self
.
checkapert
(
**
case38
)
# case39: with group by
case39
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname'
}
self
.
checkapert
(
**
case39
)
# case40: with slimit
case40
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1'
}
self
.
checkapert
(
**
case40
)
# case41: with soffset
case41
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname slimit 1 soffset 1'
}
self
.
checkapert
(
**
case41
)
# case42: with order by
case42
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case42
)
case43
=
{
'table_expr'
:
't1'
,
'condition'
:
'order by ts'
}
self
.
checkapert
(
**
case43
)
# case44: with limit offset
case44
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1'
}
self
.
checkapert
(
**
case44
)
case45
=
{
'table_expr'
:
'stb1'
,
'condition'
:
'group by tbname limit 1 offset 1'
}
self
.
checkapert
(
**
case45
)
pass
def
error_apercentile
(
self
):
# unusual test
#
# table schema :ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool
# c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
#
# form test
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
,
com
=
''
,
algo
=
''
))
# no col , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
""
))
# no col , algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
''
))
# no p , algorithm
tdSql
.
error
(
"apercentile( c1, 100) from t1"
)
# no select
tdSql
.
error
(
"select apercentile from t1"
)
# no algorithm condition
tdSql
.
error
(
"select apercentile c1,0 from t1"
)
# no brackets
tdSql
.
error
(
"select apercentile (c1,0) t1"
)
# no from
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
'(c1,0)'
,
p
=
''
,
com
=
''
,
algo
=
''
))
# no p , no algorithm
tdSql
.
error
(
"select apercentile( (c1,0) ) from t1"
)
# no table_expr
tdSql
.
error
(
"select apercentile{ (c1,0) } from t1"
)
# sql form error 1
tdSql
.
error
(
"select apercentile[ (c1,0) ] from t1"
)
# sql form error 2
tdSql
.
error
(
"select [apercentile(c1,0) ] from t1"
)
# sql form error 3
tdSql
.
error
(
"select apercentile((c1, 0), 'default') from t1"
)
# sql form error 5
tdSql
.
error
(
"select apercentile(c1, (0, 'default')) from t1"
)
# sql form error 6
tdSql
.
error
(
"select apercentile(c1, (0), 1) from t1"
)
# sql form error 7
tdSql
.
error
(
"select apercentile([c1, 0], 'default') from t1"
)
# sql form error 8
tdSql
.
error
(
"select apercentile(c1, [0, 'default']) from t1"
)
# sql form error 9
tdSql
.
error
(
"select apercentile(c1, {0, 'default'}) from t1"
)
# sql form error 10
tdSql
.
error
(
"select apercentile([c1, 0]) from t1"
)
# sql form error 11
tdSql
.
error
(
"select apercentile({c1, 0}) from t1"
)
# sql form error 12
tdSql
.
error
(
"select apercentile(c1) from t1"
)
# agrs: 1
tdSql
.
error
(
"select apercentile(c1, 0, 'default', 0) from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile(c1, 0, 0, 'default') from t1"
)
# agrs: 4
tdSql
.
error
(
"select apercentile() from t1"
)
# agrs: null 1
tdSql
.
error
(
"select apercentile from t1"
)
# agrs: null 2
tdSql
.
error
(
"select apercentile( , , ) from t1"
)
# agrs: null 3
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
,
p
=
''
,
algo
=
''
))
# agrs: null 4
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"st1"
))
# col:tag column
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
123
))
# col:numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
True
))
# col:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
''
))
# col:''
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"last(c1)"
))
# col:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"t%"
))
# col:non-numerical
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c3"
))
# col-type: timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c4"
))
# col-type: binary
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c6"
))
# col-type: bool
tdSql
.
error
(
self
.
apercentile_query_form
(
col
=
"c10"
))
# col-type: nchar
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
True
))
# p:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'a'
))
# p:str
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
'last(*)'
))
# p:expr
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
"2021-08-01 00:00:00.000"
))
# p:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
't-digest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t_digest"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest0"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest."'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest%"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'"t-digest*"'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'tdigest'
))
# algorithm:str
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
1.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
0.9999
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1.0
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0b1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0x1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
0o1
))
# algorithm:float
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
True
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
"True"
))
# algorithm:bool
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'2021-08-01 00:00:00.000'
))
# algorithm:timestamp
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
'last(c1)'
))
# algorithm:expr
# boundary test
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
1
))
# p left out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=-
9223372036854775809
))
# p left out of bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
100.1
))
# p right out of [0, 100]
tdSql
.
error
(
self
.
apercentile_query_form
(
p
=
18446744073709551616
))
# p right out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
1
))
# algorithm left out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=-
9223372036854775809
))
# algorithm left out of unsigned-bigint
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
2
))
# algorithm right out of [0, 1]
tdSql
.
error
(
self
.
apercentile_query_form
(
algo
=
18446744073709551616
))
# algorithm right out of unsigned-bigint
# mix function test
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with top function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', top(c1,1)'
))
# mix with bottom function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', last_row(c1)'
))
# mix with last_row function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', distinct c1 '
))
# mix with distinct function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', *'
))
# mix with *
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', interp(c1)'
,
condition
=
'ts="2021-10-10 00:00:00.000"'
))
# mix with interp function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', derivative(c1, 10m, 0)'
))
# mix with derivative function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
', diff(c1)'
))
# mix with diff function
tdSql
.
error
(
self
.
apercentile_query_form
(
alias
=
'+ c1)'
))
# mix with four operation
def
apercentile_data
(
self
,
tbnum
,
data_row
,
basetime
):
for
i
in
range
(
tbnum
):
for
j
in
range
(
data_row
):
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
+
j
*
10
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
uniform
(
200
,
-
1
)
}
,
{
basetime
+
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"'binary_
{
j
}
',
{
random
.
uniform
(
-
200
,
-
1
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
-
200
,
-
1
)
}
, "
f
"
{
random
.
randint
(
-
200
,
-
1
)
}
,
{
random
.
randint
(
-
127
,
-
1
)
}
, 'nchar_
{
j
}
' )"
)
tdSql
.
execute
(
f
"insert into t
{
i
}
values ("
f
"
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
uniform
(
1
,
200
)
}
,
{
basetime
-
random
.
randint
(
1
,
200
)
}
, "
f
"'binary_
{
j
}
_1',
{
random
.
uniform
(
1
,
200
)
}
,
{
random
.
choice
([
0
,
1
])
}
,
{
random
.
randint
(
1
,
200
)
}
, "
f
"
{
random
.
randint
(
1
,
200
)
}
,
{
random
.
randint
(
1
,
127
)
}
, 'nchar_
{
j
}
_1' )"
)
tdSql
.
execute
(
f
"insert into tt
{
i
}
values (
{
basetime
-
(
j
+
1
)
*
10
}
,
{
random
.
randint
(
1
,
200
)
}
)"
)
pass
def
td6108
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6108=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (
\
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
\
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
\
)
\
tags(st1 int)"
)
tdSql
.
execute
(
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
)
tbnum
=
10
for
i
in
range
(
tbnum
):
tdSql
.
execute
(
f
"create table t
{
i
}
using stb1 tags(
{
i
}
)"
)
tdSql
.
execute
(
f
"create table tt
{
i
}
using stb2 tags(
{
i
}
)"
)
tdLog
.
printNoPrefix
(
"######## no data test:"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data test:"
)
nowtime
=
int
(
round
(
time
.
time
()
*
1000
))
per_table_rows
=
1000
self
.
apercentile_data
(
tbnum
,
per_table_rows
,
nowtime
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## insert data with NULL test:"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
-
5
}
)"
)
tdSql
.
execute
(
f
"insert into t1(ts) values (
{
nowtime
+
5
}
)"
)
self
.
apercentile_query
()
self
.
error_apercentile
()
tdLog
.
printNoPrefix
(
"######## check after WAL test:"
)
tdSql
.
query
(
"show dnodes"
)
index
=
tdSql
.
getData
(
0
,
0
)
tdDnodes
.
stop
(
index
)
tdDnodes
.
start
(
index
)
self
.
apercentile_query
()
self
.
error_apercentile
()
def
run
(
self
):
# master branch
self
.
td6068
()
# self.td5168()
# self.td5433()
# self.td5798()
# develop branch
# self.td4889() In the scenario that with vnode/wal/wal* but without meta/data in vnode, the status is reset to 0 right now.
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/tsim/inc/sim.h
浏览文件 @
4883bfb4
...
@@ -135,7 +135,7 @@ typedef struct _script_t {
...
@@ -135,7 +135,7 @@ typedef struct _script_t {
int32_t
numOfLines
;
// number of lines in the script
int32_t
numOfLines
;
// number of lines in the script
int32_t
bgScriptLen
;
int32_t
bgScriptLen
;
char
fileName
[
MAX_FILE_NAME_LEN
];
// script file name
char
fileName
[
MAX_FILE_NAME_LEN
];
// script file name
char
error
[
MAX_ERROR_LEN
];
char
error
[
TSDB_MAX_BINARY_LEN
+
100
];
char
*
optionBuffer
;
char
*
optionBuffer
;
SCmdLine
*
lines
;
// command list
SCmdLine
*
lines
;
// command list
SVariable
variables
[
MAX_VAR_LEN
];
SVariable
variables
[
MAX_VAR_LEN
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录