提交 bae6f38d 编写于 作者: C Cary Xu

Merge branch 'develop' into hotfix/TS-774-D

...@@ -66,10 +66,12 @@ def pre_test(){ ...@@ -66,10 +66,12 @@ def pre_test(){
} }
sh''' sh'''
cd ${WKC} cd ${WKC}
[ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
git pull >/dev/null git pull >/dev/null
git fetch origin +refs/pull/${CHANGE_ID}/merge git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD git checkout -qf FETCH_HEAD
git clean -dfx git clean -dfx
git ls-files --stage | grep 160000 | awk '{print $4}' | xargs git rm --cached
git submodule update --init --recursive git submodule update --init --recursive
cd ${WK} cd ${WK}
git reset --hard HEAD~10 git reset --hard HEAD~10
...@@ -139,10 +141,12 @@ def pre_test_noinstall(){ ...@@ -139,10 +141,12 @@ def pre_test_noinstall(){
} }
sh''' sh'''
cd ${WKC} cd ${WKC}
[ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
git pull >/dev/null git pull >/dev/null
git fetch origin +refs/pull/${CHANGE_ID}/merge git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD git checkout -qf FETCH_HEAD
git clean -dfx git clean -dfx
git ls-files --stage | grep 160000 | awk '{print $4}' | xargs git rm --cached
git submodule update --init --recursive git submodule update --init --recursive
cd ${WK} cd ${WK}
git reset --hard HEAD~10 git reset --hard HEAD~10
...@@ -209,10 +213,12 @@ def pre_test_mac(){ ...@@ -209,10 +213,12 @@ def pre_test_mac(){
} }
sh''' sh'''
cd ${WKC} cd ${WKC}
[ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
git pull >/dev/null git pull >/dev/null
git fetch origin +refs/pull/${CHANGE_ID}/merge git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD git checkout -qf FETCH_HEAD
git clean -dfx git clean -dfx
git ls-files --stage | grep 160000 | awk '{print $4}' | xargs git rm --cached
git submodule update --init --recursive git submodule update --init --recursive
cd ${WK} cd ${WK}
git reset --hard HEAD~10 git reset --hard HEAD~10
......
...@@ -29,7 +29,7 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, ...@@ -29,7 +29,7 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6,
## <a class="anchor" id="schemaless"></a>无模式(Schemaless)写入 ## <a class="anchor" id="schemaless"></a>无模式(Schemaless)写入
**前言** **前言**
<br/>在物联网应用中,常会采集比较多的数据项,用于实现智能控制、业务分析、设备监控等。由于应用逻辑的版本升级,或者设备自身的硬件调整等原因,数据采集项就有可能比较频繁地出现变动。为了在这种情况下方便地完成数据记录工作,TDengine 从 2.2.0.0 版本开始,提供调用 Schemaless 写入方式,可以免于预先创建超级表/子表的步骤,随着数据写入写入接口能够自动创建与数据对应的存储结构。并且在必要时,Schemaless 将自动增加必要的数据列,保证用户写入的数据可以被正确存储。 <br/>在物联网应用中,常会采集比较多的数据项,用于实现智能控制、业务分析、设备监控等。由于应用逻辑的版本升级,或者设备自身的硬件调整等原因,数据采集项就有可能比较频繁地出现变动。为了在这种情况下方便地完成数据记录工作,TDengine 从 2.2.0.0 版本开始,提供调用 Schemaless 写入方式,可以免于预先创建超级表/子表的步骤,随着数据写入接口能够自动创建与数据对应的存储结构。并且在必要时,Schemaless 将自动增加必要的数据列,保证用户写入的数据可以被正确存储。
<br/>目前,TDengine 的 C/C++ Connector 提供支持 Schemaless 的操作接口,详情请参见 [Schemaless 方式写入接口](https://www.taosdata.com/cn/documentation/connector#schemaless)章节。这里对 Schemaless 的数据表达格式进行了描述。 <br/>目前,TDengine 的 C/C++ Connector 提供支持 Schemaless 的操作接口,详情请参见 [Schemaless 方式写入接口](https://www.taosdata.com/cn/documentation/connector#schemaless)章节。这里对 Schemaless 的数据表达格式进行了描述。
<br/>无模式写入方式建立的超级表及其对应的子表与通过 SQL 直接建立的超级表和子表完全没有区别,您也可以通过 SQL 语句直接向其中写入数据。需要注意的是,通过无模式写入方式建立的表,其表名是基于标签值按照固定的映射规则生成,所以无法明确地进行表意,缺乏可读性。 <br/>无模式写入方式建立的超级表及其对应的子表与通过 SQL 直接建立的超级表和子表完全没有区别,您也可以通过 SQL 语句直接向其中写入数据。需要注意的是,通过无模式写入方式建立的表,其表名是基于标签值按照固定的映射规则生成,所以无法明确地进行表意,缺乏可读性。
...@@ -74,21 +74,19 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000 ...@@ -74,21 +74,19 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
### 无模式写入的主要处理逻辑 ### 无模式写入的主要处理逻辑
无模式写入按照如下原则来处理行数据: 无模式写入按照如下原则来处理行数据:
1. 当 tag_set 中有 ID 字段时,该字段的值将作为子表的表名。 <br/>1. 将使用如下规则来生成子表名:首先将measurement 的名称和标签的 key 和 value 组合成为如下的字符串
2. 没有 ID 字段时,将使用如下规则来生成子表名:
首先将measurement 的名称和标签的 key 和 value 组合成为如下的字符串
```json ```json
"measurement,tag_key1=tag_value1,tag_key2=tag_value2" "measurement,tag_key1=tag_value1,tag_key2=tag_value2"
``` ```
需要注意的是,这里的tag_key1, tag_key2并不是用户输入的标签的原始顺序,而是使用了标签名称按照字符串升序排列后的结果。所以,tag_key1 并不是在行协议中输入的第一个标签。 需要注意的是,这里的tag_key1, tag_key2并不是用户输入的标签的原始顺序,而是使用了标签名称按照字符串升序排列后的结果。所以,tag_key1 并不是在行协议中输入的第一个标签。
排列完成以后计算该字符串的 MD5 散列值 "md5_val"。然后将计算的结果与字符串组合生成表名:“t_md5_val”。其中的 “t_” 是固定的前缀,每个通过该映射关系自动生成的表都具有该前缀。 排列完成以后计算该字符串的 MD5 散列值 "md5_val"。然后将计算的结果与字符串组合生成表名:“t_md5_val”。其中的 “t_” 是固定的前缀,每个通过该映射关系自动生成的表都具有该前缀。
<br/>3. 如果解析行协议获得的超级表不存在,则会创建这个超级表。 <br/>2. 如果解析行协议获得的超级表不存在,则会创建这个超级表。
<br/>4. 如果解析行协议获得子表不存在,则 Schemaless 会按照步骤 1 或 2 确定的子表名来创建子表。 <br/>3. 如果解析行协议获得子表不存在,则 Schemaless 会按照步骤 1 或 2 确定的子表名来创建子表。
<br/>5. 如果数据行中指定的标签列或普通列不存在,则在超级表中增加对应的标签列或普通列(只增不减)。 <br/>4. 如果数据行中指定的标签列或普通列不存在,则在超级表中增加对应的标签列或普通列(只增不减)。
<br/>6. 如果超级表中存在一些标签列或普通列未在一个数据行中被指定取值,那么这些列的值在这一行中会被置为 NULL。 <br/>5. 如果超级表中存在一些标签列或普通列未在一个数据行中被指定取值,那么这些列的值在这一行中会被置为 NULL。
<br/>7. 对 BINARY 或 NCHAR 列,如果数据行中所提供值的长度超出了列类型的限制,自动增加该列允许存储的字符长度上限(只增不减),以保证数据的完整保存。 <br/>6. 对 BINARY 或 NCHAR 列,如果数据行中所提供值的长度超出了列类型的限制,自动增加该列允许存储的字符长度上限(只增不减),以保证数据的完整保存。
<br/>8. 如果指定的数据子表已经存在,而且本次指定的标签列取值跟已保存的值不一样,那么最新的数据行中的值会覆盖旧的标签列取值。 <br/>7. 如果指定的数据子表已经存在,而且本次指定的标签列取值跟已保存的值不一样,那么最新的数据行中的值会覆盖旧的标签列取值。
<br/>9. 整个处理过程中遇到的错误会中断写入过程,并返回错误代码。 <br/>8. 整个处理过程中遇到的错误会中断写入过程,并返回错误代码。
**备注:** **备注:**
<br/>无模式所有的处理逻辑,仍会遵循 TDengine 对数据结构的底层限制,例如每行数据的总长度不能超过 16k 字节。这方面的具体限制约束请参见 [TAOS SQL 边界限制](https://www.taosdata.com/cn/documentation/taos-sql#limitation) 章节。 <br/>无模式所有的处理逻辑,仍会遵循 TDengine 对数据结构的底层限制,例如每行数据的总长度不能超过 16k 字节。这方面的具体限制约束请参见 [TAOS SQL 边界限制](https://www.taosdata.com/cn/documentation/taos-sql#limitation) 章节。
...@@ -116,6 +114,17 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000 ...@@ -116,6 +114,17 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
在 SML_TELNET_PROTOCOL 和 SML_JSON_PROTOCOL 模式下,根据时间戳的长度来确定时间精度(与 OpenTSDB 标准操作方式相同),此时会忽略用户指定的时间分辨率。 在 SML_TELNET_PROTOCOL 和 SML_JSON_PROTOCOL 模式下,根据时间戳的长度来确定时间精度(与 OpenTSDB 标准操作方式相同),此时会忽略用户指定的时间分辨率。
**数据模式映射规则**
<br/>本节将说明行协议的数据如何映射成为具有模式的数据。每个行协议中数据 measurement 映射为 超级表名称。tag_set 中的 标签名称为 数据模式中的标签名,field_set 中的名称为列名称。以如下数据为例,说明映射规则:
```json
st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
```
该行数据映射生成一个超级表: st, 其包含了 3 个类型为 nchar 的标签,分别是:t1, t2, t3。五个数据列,分别是ts(timestamp),c1 (bigint),c3(binary),c2 (bool), c4 (bigint)。映射成为如下 SQL 语句:
```json
create stable st (_ts timestamp, c1 bigint, c2 bool, c3 binary(6), c4 bigint) tags(t1 nchar(1), t2 nchar(1), t3 nchar(2))
```
**数据模式变更处理** **数据模式变更处理**
<br/>本节将说明不同行数据写入情况下,对于数据模式的影响。 <br/>本节将说明不同行数据写入情况下,对于数据模式的影响。
......
...@@ -181,7 +181,7 @@ select count(*) from memory ...@@ -181,7 +181,7 @@ select count(*) from memory
完成查询后,如果写入的数据与预期的相比没有差别,同时写入程序本身没有异常的报错信息,那么可用确认数据写入是完整有效的。 完成查询后,如果写入的数据与预期的相比没有差别,同时写入程序本身没有异常的报错信息,那么可用确认数据写入是完整有效的。
TDengine不支持采用OpenTSDB的查询语法进行查询或数据获取处理,但是针对OpenTSDB的每种查询都提供对应的支持。你可以用检查附件2获取对应的查询处理的调整和应用使用的方式,如果需要全面了解TDengine支持的查询类型,请参阅TDengine的用户手册。 TDengine不支持采用OpenTSDB的查询语法进行查询或数据获取处理,但是针对OpenTSDB的每种查询都提供对应的支持。可以用检查附录1获取对应的查询处理的调整和应用使用的方式,如果需要全面了解TDengine支持的查询类型,请参阅TDengine的用户手册。
TDengine支持标准的JDBC 3.0接口操纵数据库,你也可以使用其他类型的高级语言的连接器来查询读取数据,以适配你的应用。具体的操作和使用帮助也请参阅用户手册。 TDengine支持标准的JDBC 3.0接口操纵数据库,你也可以使用其他类型的高级语言的连接器来查询读取数据,以适配你的应用。具体的操作和使用帮助也请参阅用户手册。
......
...@@ -364,7 +364,9 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SQueryInfo* ...@@ -364,7 +364,9 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SQueryInfo*
SExprInfo* pExprInfo = tscExprGet(pQueryInfo, j); SExprInfo* pExprInfo = tscExprGet(pQueryInfo, j);
int32_t functionId = pExprInfo->base.functionId; int32_t functionId = pExprInfo->base.functionId;
if (pColIndex->colId == pExprInfo->base.colInfo.colId && (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ)) { if (pColIndex->colId == pExprInfo->base.colInfo.colId && (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ)) {
orderColIndexList[i] = j; orderColIndexList[i] = j;
break; break;
} }
......
...@@ -152,7 +152,9 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra ...@@ -152,7 +152,9 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, int* tableNameLen, static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, int* tableNameLen,
SSmlLinesInfo* info) { SSmlLinesInfo* info) {
tscDebug("SML:0x%"PRIx64" taos_sml_insert get child table name through md5", info->id); tscDebug("SML:0x%"PRIx64" taos_sml_insert get child table name through md5", info->id);
if (point->tagNum) {
qsort(point->tags, point->tagNum, sizeof(TAOS_SML_KV), compareSmlColKv); qsort(point->tags, point->tagNum, sizeof(TAOS_SML_KV), compareSmlColKv);
}
SStringBuilder sb; memset(&sb, 0, sizeof(sb)); SStringBuilder sb; memset(&sb, 0, sizeof(sb));
char sTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char sTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0};
...@@ -185,6 +187,18 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa ...@@ -185,6 +187,18 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa
return 0; return 0;
} }
static int32_t buildSmlChildTableName(TAOS_SML_DATA_POINT* point, SSmlLinesInfo* info) {
tscDebug("SML:0x%"PRIx64" taos_sml_insert build child table name", info->id);
char childTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE];
int32_t tableNameLen = TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE;
getSmlMd5ChildTableName(point, childTableName, &tableNameLen, info);
point->childTableName = calloc(1, tableNameLen+1);
strncpy(point->childTableName, childTableName, tableNameLen);
point->childTableName[tableNameLen] = '\0';
return 0;
}
static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, SArray* stableSchemas, SSmlLinesInfo* info) { static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, SArray* stableSchemas, SSmlLinesInfo* info) {
int32_t code = 0; int32_t code = 0;
SHashObj* sname2shema = taosHashInit(32, SHashObj* sname2shema = taosHashInit(32,
...@@ -216,12 +230,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -216,12 +230,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
for (int j = 0; j < point->tagNum; ++j) { for (int j = 0; j < point->tagNum; ++j) {
TAOS_SML_KV* tagKv = point->tags + j; TAOS_SML_KV* tagKv = point->tags + j;
if (!point->childTableName) { if (!point->childTableName) {
char childTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; buildSmlChildTableName(point, info);
int32_t tableNameLen = TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE;
getSmlMd5ChildTableName(point, childTableName, &tableNameLen, info);
point->childTableName = calloc(1, tableNameLen+1);
strncpy(point->childTableName, childTableName, tableNameLen);
point->childTableName[tableNameLen] = '\0';
} }
code = buildSmlKvSchema(tagKv, pStableSchema->tagHash, pStableSchema->tags, info); code = buildSmlKvSchema(tagKv, pStableSchema->tagHash, pStableSchema->tags, info);
...@@ -231,6 +240,27 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -231,6 +240,27 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
} }
} }
//for Line Protocol tags may be omitted, add a tag with NULL value
if (point->tagNum == 0) {
if (!point->childTableName) {
buildSmlChildTableName(point, info);
}
char tagNullName[TSDB_COL_NAME_LEN] = {0};
size_t nameLen = strlen(tsSmlTagNullName);
strncpy(tagNullName, tsSmlTagNullName, nameLen);
addEscapeCharToString(tagNullName, (int32_t)nameLen);
size_t* pTagNullIdx = taosHashGet(pStableSchema->tagHash, tagNullName, nameLen + TS_ESCAPE_CHAR_SIZE);
if (!pTagNullIdx) {
SSchema tagNull = {0};
tagNull.type = TSDB_DATA_TYPE_NCHAR;
tagNull.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
strncpy(tagNull.name, tagNullName, nameLen + TS_ESCAPE_CHAR_SIZE);
taosArrayPush(pStableSchema->tags, &tagNull);
size_t tagNullIdx = taosArrayGetSize(pStableSchema->tags) - 1;
taosHashPut(pStableSchema->tagHash, tagNull.name, nameLen + TS_ESCAPE_CHAR_SIZE, &tagNullIdx, sizeof(tagNullIdx));
}
}
for (int j = 0; j < point->fieldNum; ++j) { for (int j = 0; j < point->fieldNum; ++j) {
TAOS_SML_KV* fieldKv = point->fields + j; TAOS_SML_KV* fieldKv = point->fields + j;
code = buildSmlKvSchema(fieldKv, pStableSchema->fieldHash, pStableSchema->fields, info); code = buildSmlKvSchema(fieldKv, pStableSchema->fieldHash, pStableSchema->fields, info);
......
...@@ -237,6 +237,7 @@ extern int8_t tsDeadLockKillQuery; ...@@ -237,6 +237,7 @@ extern int8_t tsDeadLockKillQuery;
// schemaless // schemaless
extern char tsDefaultJSONStrType[]; extern char tsDefaultJSONStrType[];
extern char tsSmlChildTableName[]; extern char tsSmlChildTableName[];
extern char tsSmlTagNullName[];
typedef struct { typedef struct {
......
...@@ -291,7 +291,11 @@ int8_t tsDeadLockKillQuery = 0; ...@@ -291,7 +291,11 @@ int8_t tsDeadLockKillQuery = 0;
// default JSON string type // default JSON string type
char tsDefaultJSONStrType[7] = "nchar"; char tsDefaultJSONStrType[7] = "nchar";
char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; //user defined child table name can be specified in tag value. If set to empty system will generate table name using MD5 hash. char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; //user defined child table name can be specified in tag value.
//If set to empty system will generate table name using MD5 hash.
char tsSmlTagNullName[TSDB_COL_NAME_LEN] = "_tag_null"; //for line protocol if tag is omitted, add a tag with NULL value
//to make sure inserted records belongs to the same measurement
//default name is _tag_null and can be user configurable
int32_t (*monStartSystemFp)() = NULL; int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL; void (*monStopSystemFp)() = NULL;
...@@ -1701,6 +1705,17 @@ static void doInitGlobalConfig(void) { ...@@ -1701,6 +1705,17 @@ static void doInitGlobalConfig(void) {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
// name for a NULL value tag added for Line Protocol when tag fields are omitted
cfg.option = "smlTagNullName";
cfg.ptr = tsSmlTagNullName;
cfg.valType = TAOS_CFG_VTYPE_STRING;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = tListLen(tsSmlTagNullName);
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
// flush vnode wal file if walSize > walFlushSize and walSize > cache*0.5*blocks // flush vnode wal file if walSize > walFlushSize and walSize > cache*0.5*blocks
cfg.option = "walFlushSize"; cfg.option = "walFlushSize";
cfg.ptr = &tsdbWalFlushSize; cfg.ptr = &tsdbWalFlushSize;
......
TDengine Grafana plugin is no more part of the TDengine repo. Please check it out from https://github.com/taosdata/grafanaplugin.
...@@ -51,7 +51,7 @@ conn.close() ...@@ -51,7 +51,7 @@ conn.close()
import taos import taos
conn = taos.connect() conn = taos.connect()
conn.exec("create database if not exists pytest") conn.execute("create database if not exists pytest")
result = conn.query("show databases") result = conn.query("show databases")
num_of_fields = result.field_count num_of_fields = result.field_count
...@@ -60,7 +60,7 @@ for field in result.fields: ...@@ -60,7 +60,7 @@ for field in result.fields:
for row in result: for row in result:
print(row) print(row)
result.close() result.close()
conn.exec("drop database pytest") conn.execute("drop database pytest")
conn.close() conn.close()
``` ```
...@@ -136,11 +136,11 @@ from taos import * ...@@ -136,11 +136,11 @@ from taos import *
conn = connect() conn = connect()
dbname = "pytest_taos_stmt" dbname = "pytest_taos_stmt"
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.exec("create database if not exists %s" % dbname) conn.execute("create database if not exists %s" % dbname)
conn.select_db(dbname) conn.select_db(dbname)
conn.exec( conn.execute(
"create table if not exists log(ts timestamp, bo bool, nil tinyint, \ "create table if not exists log(ts timestamp, bo bool, nil tinyint, \
ti tinyint, si smallint, ii int, bi bigint, tu tinyint unsigned, \ ti tinyint, si smallint, ii int, bi bigint, tu tinyint unsigned, \
su smallint unsigned, iu int unsigned, bu bigint unsigned, \ su smallint unsigned, iu int unsigned, bu bigint unsigned, \
...@@ -196,11 +196,11 @@ from taos import * ...@@ -196,11 +196,11 @@ from taos import *
conn = connect() conn = connect()
dbname = "pytest_taos_stmt" dbname = "pytest_taos_stmt"
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.exec("create database if not exists %s" % dbname) conn.execute("create database if not exists %s" % dbname)
conn.select_db(dbname) conn.select_db(dbname)
conn.exec( conn.execute(
"create table if not exists log(ts timestamp, bo bool, nil tinyint, \ "create table if not exists log(ts timestamp, bo bool, nil tinyint, \
ti tinyint, si smallint, ii int, bi bigint, tu tinyint unsigned, \ ti tinyint, si smallint, ii int, bi bigint, tu tinyint unsigned, \
su smallint unsigned, iu int unsigned, bu bigint unsigned, \ su smallint unsigned, iu int unsigned, bu bigint unsigned, \
...@@ -249,12 +249,12 @@ import taos ...@@ -249,12 +249,12 @@ import taos
conn = taos.connect() conn = taos.connect()
dbname = "pytest_taos_subscribe_callback" dbname = "pytest_taos_subscribe_callback"
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.exec("create database if not exists %s" % dbname) conn.execute("create database if not exists %s" % dbname)
conn.select_db(dbname) conn.select_db(dbname)
conn.exec("create table if not exists log(ts timestamp, n int)") conn.execute("create table if not exists log(ts timestamp, n int)")
for i in range(10): for i in range(10):
conn.exec("insert into log values(now, %d)" % i) conn.execute("insert into log values(now, %d)" % i)
sub = conn.subscribe(True, "test", "select * from log", 1000) sub = conn.subscribe(True, "test", "select * from log", 1000)
print("# consume from begin") print("# consume from begin")
...@@ -263,14 +263,14 @@ for ts, n in sub.consume(): ...@@ -263,14 +263,14 @@ for ts, n in sub.consume():
print("# consume new data") print("# consume new data")
for i in range(5): for i in range(5):
conn.exec("insert into log values(now, %d)(now+1s, %d)" % (i, i)) conn.execute("insert into log values(now, %d)(now+1s, %d)" % (i, i))
result = sub.consume() result = sub.consume()
for ts, n in result: for ts, n in result:
print(ts, n) print(ts, n)
print("# consume with a stop condition") print("# consume with a stop condition")
for i in range(10): for i in range(10):
conn.exec("insert into log values(now, %d)" % int(random() * 10)) conn.execute("insert into log values(now, %d)" % int(random() * 10))
result = sub.consume() result = sub.consume()
try: try:
ts, n = next(result) ts, n = next(result)
...@@ -284,7 +284,7 @@ for i in range(10): ...@@ -284,7 +284,7 @@ for i in range(10):
sub.close() sub.close()
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.close() conn.close()
``` ```
...@@ -311,23 +311,23 @@ def test_subscribe_callback(conn): ...@@ -311,23 +311,23 @@ def test_subscribe_callback(conn):
# type: (TaosConnection) -> None # type: (TaosConnection) -> None
dbname = "pytest_taos_subscribe_callback" dbname = "pytest_taos_subscribe_callback"
try: try:
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.exec("create database if not exists %s" % dbname) conn.execute("create database if not exists %s" % dbname)
conn.select_db(dbname) conn.select_db(dbname)
conn.exec("create table if not exists log(ts timestamp, n int)") conn.execute("create table if not exists log(ts timestamp, n int)")
print("# subscribe with callback") print("# subscribe with callback")
sub = conn.subscribe(False, "test", "select * from log", 1000, subscribe_callback) sub = conn.subscribe(False, "test", "select * from log", 1000, subscribe_callback)
for i in range(10): for i in range(10):
conn.exec("insert into log values(now, %d)" % i) conn.execute("insert into log values(now, %d)" % i)
time.sleep(0.7) time.sleep(0.7)
sub.close() sub.close()
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.close() conn.close()
except Exception as err: except Exception as err:
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.close() conn.close()
raise err raise err
...@@ -374,10 +374,10 @@ def test_stream(conn): ...@@ -374,10 +374,10 @@ def test_stream(conn):
# type: (TaosConnection) -> None # type: (TaosConnection) -> None
dbname = "pytest_taos_stream" dbname = "pytest_taos_stream"
try: try:
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.exec("create database if not exists %s" % dbname) conn.execute("create database if not exists %s" % dbname)
conn.select_db(dbname) conn.select_db(dbname)
conn.exec("create table if not exists log(ts timestamp, n int)") conn.execute("create table if not exists log(ts timestamp, n int)")
result = conn.query("select count(*) from log interval(5s)") result = conn.query("select count(*) from log interval(5s)")
assert result.field_count == 2 assert result.field_count == 2
...@@ -386,13 +386,13 @@ def test_stream(conn): ...@@ -386,13 +386,13 @@ def test_stream(conn):
stream = conn.stream("select count(*) from log interval(5s)", stream_callback, param=byref(counter)) stream = conn.stream("select count(*) from log interval(5s)", stream_callback, param=byref(counter))
for _ in range(0, 20): for _ in range(0, 20):
conn.exec("insert into log values(now,0)(now+1s, 1)(now + 2s, 2)") conn.execute("insert into log values(now,0)(now+1s, 1)(now + 2s, 2)")
time.sleep(2) time.sleep(2)
stream.close() stream.close()
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.close() conn.close()
except Exception as err: except Exception as err:
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.close() conn.close()
raise err raise err
...@@ -408,8 +408,8 @@ import taos ...@@ -408,8 +408,8 @@ import taos
conn = taos.connect() conn = taos.connect()
dbname = "pytest_line" dbname = "pytest_line"
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.exec("create database if not exists %s precision 'us'" % dbname) conn.execute("create database if not exists %s precision 'us'" % dbname)
conn.select_db(dbname) conn.select_db(dbname)
lines = [ lines = [
...@@ -431,7 +431,7 @@ for row in result: ...@@ -431,7 +431,7 @@ for row in result:
result.close() result.close()
conn.exec("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.close() conn.close()
``` ```
......
Subproject commit d7cba95249678611caa3b22dac771419d2b7ef82 Subproject commit b76b5a76756a5c6530ba1d418de51fd336ae23b1
...@@ -371,6 +371,8 @@ python3 ./test.py -f functions/function_irate.py ...@@ -371,6 +371,8 @@ python3 ./test.py -f functions/function_irate.py
python3 ./test.py -f functions/function_ceil.py python3 ./test.py -f functions/function_ceil.py
python3 ./test.py -f functions/function_floor.py python3 ./test.py -f functions/function_floor.py
python3 ./test.py -f functions/function_round.py python3 ./test.py -f functions/function_round.py
python3 ./test.py -f functions/function_mavg.py
python3 ./test.py -f functions/function_csum.py
python3 ./test.py -f insert/unsignedInt.py python3 ./test.py -f insert/unsignedInt.py
python3 ./test.py -f insert/unsignedBigint.py python3 ./test.py -f insert/unsignedBigint.py
......
此差异已折叠。
###################################################################
# 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
import re
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("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def csum_query_form(self, col="c1", alias="", table_expr="t1", condition=""):
'''
csum function:
:param col: string, column name, required parameters;
:param alias: string, result column another name,or add other funtion;
: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)',or give result column another name, like 'c2'
:return: csum query statement,default: select csum(c1) from t1
'''
return f"select csum({col}) {alias} from {table_expr} {condition}"
def checkcsum(self,col="c1", alias="", table_expr="t1", condition="" ):
line = sys._getframe().f_back.f_lineno
pre_sql = self.csum_query_form(
col=col, table_expr=table_expr, condition=condition
).replace("csum", "count")
tdSql.query(pre_sql)
if tdSql.queryRows == 0:
tdSql.query(self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
))
print(f"case in {line}: ", end='')
tdSql.checkRows(0)
return
if "order by tbname" in condition:
tdSql.error(self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
))
return
if "group" in condition:
tb_condition = condition.split("group by")[1].split(" ")[1]
tdSql.query(f"select distinct {tb_condition} from {table_expr}")
query_result = tdSql.queryResult
query_rows = tdSql.queryRows
clear_condition = re.sub('order by [0-9a-z]*|slimit [0-9]*|soffset [0-9]*', "", condition)
pre_row = 0
for i in range(query_rows):
group_name = query_result[i][0]
if "where" in clear_condition:
pre_condition = re.sub('group by [0-9a-z]*', f"{tb_condition}='{group_name}'", clear_condition)
else:
pre_condition = "where " + re.sub('group by [0-9a-z]*',f"{tb_condition}='{group_name}'", clear_condition)
tdSql.query(f"select {col} {alias} from {table_expr} {pre_condition}")
pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None]
pre_csum = np.cumsum(pre_data)
tdSql.query(self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
))
for j in range(len(pre_csum)):
print(f"case in {line}:", end='')
tdSql.checkData(pre_row+j, 1, pre_csum[j])
pre_row += len(pre_csum)
return
elif "union" in condition:
union_sql_0 = self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
).split("union all")[0]
union_sql_1 = self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
).split("union all")[1]
tdSql.query(union_sql_0)
union_csum_0 = tdSql.queryResult
row_union_0 = tdSql.queryRows
tdSql.query(union_sql_1)
union_csum_1 = tdSql.queryResult
tdSql.query(self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
))
for i in range(tdSql.queryRows):
print(f"case in {line}: ", end='')
if i < row_union_0:
tdSql.checkData(i, 1, union_csum_0[i][1])
else:
tdSql.checkData(i, 1, union_csum_1[i-row_union_0][1])
return
else:
tdSql.query(f"select {col} from {table_expr} {re.sub('limit [0-9]*|offset [0-9]*','',condition)}")
offset_val = condition.split("offset")[1].split(" ")[1] if "offset" in condition else 0
pre_result = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None]
pre_csum = np.cumsum(pre_result)[offset_val:]
tdSql.query(self.csum_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition
))
for i in range(tdSql.queryRows):
print(f"case in {line}: ", end='')
tdSql.checkData(i, 1, pre_csum[i])
pass
def csum_current_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~6: numeric col:int/bigint/tinyint/smallint/float/double
self.checkcsum()
case2 = {"col": "c2"}
self.checkcsum(**case2)
case3 = {"col": "c5"}
self.checkcsum(**case3)
case4 = {"col": "c7"}
self.checkcsum(**case4)
case5 = {"col": "c8"}
self.checkcsum(**case5)
case6 = {"col": "c9"}
self.checkcsum(**case6)
# case7~8: nested query
case7 = {"table_expr": "(select c1 from stb1)"}
self.checkcsum(**case7)
case8 = {"table_expr": "(select csum(c1) c1 from stb1 group by tbname)"}
self.checkcsum(**case8)
# case9~10: mix with tbname/ts/tag/col
case9 = {"alias": ", tbname"}
self.checkcsum(**case9)
case10 = {"alias": ", _c0"}
self.checkcsum(**case10)
case11 = {"alias": ", st1"}
self.checkcsum(**case11)
case12 = {"alias": ", c1"}
# self.checkcsum(**case12)
# case13~15: with single condition
case13 = {"condition": "where c1 <= 10"}
self.checkcsum(**case13)
case14 = {"condition": "where c6 in (0, 1)"}
self.checkcsum(**case14)
case15 = {"condition": "where c1 between 1 and 10"}
self.checkcsum(**case15)
# case16: with multi-condition
case16 = {"condition": "where c6=1 or c6 =0"}
self.checkcsum(**case16)
# case17: only support normal table join
case17 = {
"col": "t1.c1",
"table_expr": "t1, t2",
"condition": "where t1.ts=t2.ts"
}
self.checkcsum(**case17)
# # case18~19: with group by
# case18 = {
# "table_expr": "t1",
# "condition": "group by c6"
# }
# self.checkcsum(**case18)
case19 = {
"table_expr": "stb1",
"condition": "group by tbname"
}
self.checkcsum(**case19)
# case20~21: with order by
case20 = {"condition": "order by ts"}
self.checkcsum(**case20)
# case22: with union
case22 = {
"condition": "union all select csum(c1) from t2"
}
self.checkcsum(**case22)
# case23: with limit/slimit
case23 = {
"condition": "limit 1"
}
self.checkcsum(**case23)
# case24 = {
# "table_expr": "stb1",
# "condition": "group by tbname slimit 1 soffset 1"
# }
# self.checkcsum(**case24)
pass
def csum_error_query(self) -> None :
# 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.csum_query_form(col="")) # no col
tdSql.error("csum(c1) from stb1") # no select
tdSql.error("select csum from t1") # no csum condition
tdSql.error("select csum c1 from t1") # no brackets
tdSql.error("select csum(c1) t1") # no from
tdSql.error("select csum( c1 ) from ") # no table_expr
tdSql.error(self.csum_query_form(col="st1")) # tag col
tdSql.error(self.csum_query_form(col=1)) # col is a value
tdSql.error(self.csum_query_form(col="'c1'")) # col is a string
tdSql.error(self.csum_query_form(col=None)) # col is NULL 1
tdSql.error(self.csum_query_form(col="NULL")) # col is NULL 2
tdSql.error(self.csum_query_form(col='""')) # col is ""
tdSql.error(self.csum_query_form(col='c%')) # col is spercial char 1
tdSql.error(self.csum_query_form(col='c_')) # col is spercial char 2
tdSql.error(self.csum_query_form(col='c.')) # col is spercial char 3
tdSql.error(self.csum_query_form(col='c3')) # timestamp col
tdSql.error(self.csum_query_form(col='ts')) # Primary key
tdSql.error(self.csum_query_form(col='avg(c1)')) # expr col
tdSql.error(self.csum_query_form(col='c6')) # bool col
tdSql.error(self.csum_query_form(col='c4')) # binary col
tdSql.error(self.csum_query_form(col='c10')) # nachr col
tdSql.error(self.csum_query_form(col='c10')) # not table_expr col
tdSql.error(self.csum_query_form(col='t1')) # tbname
tdSql.error(self.csum_query_form(col='stb1')) # stbname
tdSql.error(self.csum_query_form(col='db')) # datbasename
tdSql.error(self.csum_query_form(col=True)) # col is BOOL 1
tdSql.error(self.csum_query_form(col='True')) # col is BOOL 2
tdSql.error(self.csum_query_form(col='*')) # col is all col
tdSql.error("select csum[c1] from t1") # sql form error 1
tdSql.error("select csum{c1} from t1") # sql form error 2
tdSql.error(self.csum_query_form(col="[c1]")) # sql form error 3
tdSql.error(self.csum_query_form(col="c1, c2")) # sql form error 3
tdSql.error(self.csum_query_form(col="c1, 2")) # sql form error 3
tdSql.error(self.csum_query_form(alias=", count(c1)")) # mix with aggregate function 1
tdSql.error(self.csum_query_form(alias=", avg(c1)")) # mix with aggregate function 2
tdSql.error(self.csum_query_form(alias=", min(c1)")) # mix with select function 1
tdSql.error(self.csum_query_form(alias=", top(c1, 5)")) # mix with select function 2
tdSql.error(self.csum_query_form(alias=", spread(c1)")) # mix with calculation function 1
tdSql.error(self.csum_query_form(alias=", diff(c1)")) # mix with calculation function 2
tdSql.error(self.csum_query_form(alias=" + 2")) # mix with arithmetic 1
tdSql.error(self.csum_query_form(alias=" + avg(c1)")) # mix with arithmetic 2
tdSql.error(self.csum_query_form(alias=", c2")) # mix with other 1
tdSql.error(self.csum_query_form(table_expr="stb1")) # select stb directly
stb_join = {
"col": "stb1.c1",
"table_expr": "stb1, stb2",
"condition": "where stb1.ts=stb2.ts and stb1.st1=stb2.st2 order by stb1.ts"
}
tdSql.error(self.csum_query_form(**stb_join)) # stb join
interval_sql = {
"condition": "where ts>0 and ts < now interval(1h) fill(next)"
}
tdSql.error(self.csum_query_form(**interval_sql)) # interval
group_normal_col = {
"table_expr": "t1",
"condition": "group by c6"
}
tdSql.error(self.csum_query_form(**group_normal_col)) # group by normal col
slimit_soffset_sql = {
"table_expr": "stb1",
"condition": "group by tbname slimit 1 soffset 1"
}
# tdSql.error(self.csum_query_form(**slimit_soffset_sql))
order_by_tbname_sql = {
"table_expr": "stb1",
"condition": "group by tbname order by tbname"
}
tdSql.error(self.csum_query_form(**order_by_tbname_sql))
pass
def csum_test_data(self, tbnum:int, data_row:int, basetime:int) -> None :
for i in range(tbnum):
for j in range(data_row):
tdSql.execute(
f"insert into t{i} values ("
f"{basetime + (j+1)*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 csum_test_table(self,tbnum: int) -> None :
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)"
)
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})")
pass
def csum_test_run(self) :
tdLog.printNoPrefix("==========TD-10594==========")
tbnum = 10
nowtime = int(round(time.time() * 1000))
per_table_rows = 100
self.csum_test_table(tbnum)
tdLog.printNoPrefix("######## no data test:")
self.csum_current_query()
self.csum_error_query()
tdLog.printNoPrefix("######## insert only NULL test:")
for i in range(tbnum):
tdSql.execute(f"insert into t{i}(ts) values ({nowtime - 5})")
tdSql.execute(f"insert into t{i}(ts) values ({nowtime + 5})")
self.csum_current_query()
self.csum_error_query()
tdLog.printNoPrefix("######## insert data in the range near the max(bigint/double):")
self.csum_test_table(tbnum)
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 1) * 10}, {2**31-1}, {3.4*10**38}, {1.7*10**308}, {2**63-1})")
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 2) * 10}, {2**31-1}, {3.4*10**38}, {1.7*10**308}, {2**63-1})")
self.csum_current_query()
self.csum_error_query()
tdLog.printNoPrefix("######## insert data in the range near the min(bigint/double):")
self.csum_test_table(tbnum)
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 1) * 10}, {1-2**31}, {-3.4*10**38}, {-1.7*10**308}, {1-2**63})")
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 2) * 10}, {1-2**31}, {-3.4*10**38}, {-1.7*10**308}, {512-2**63})")
self.csum_current_query()
self.csum_error_query()
tdLog.printNoPrefix("######## insert data without NULL data test:")
self.csum_test_table(tbnum)
self.csum_test_data(tbnum, per_table_rows, nowtime)
self.csum_current_query()
self.csum_error_query()
tdLog.printNoPrefix("######## insert data mix with NULL test:")
for i in range(tbnum):
tdSql.execute(f"insert into t{i}(ts) values ({nowtime})")
tdSql.execute(f"insert into t{i}(ts) values ({nowtime-(per_table_rows+3)*10})")
tdSql.execute(f"insert into t{i}(ts) values ({nowtime+(per_table_rows+3)*10})")
self.csum_current_query()
self.csum_error_query()
tdLog.printNoPrefix("######## check after WAL test:")
tdSql.query("show dnodes")
index = tdSql.getData(0, 0)
tdDnodes.stop(index)
tdDnodes.start(index)
self.csum_current_query()
self.csum_error_query()
def run(self):
import traceback
try:
# run in develop branch
self.csum_test_run()
pass
except Exception as e:
traceback.print_exc()
raise e
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
此差异已折叠。
...@@ -129,7 +129,7 @@ class TDTestCase: ...@@ -129,7 +129,7 @@ class TDTestCase:
print("schemaless_insert result {}".format(code)) print("schemaless_insert result {}".format(code))
tdSql.query("describe stb0_3") tdSql.query("describe stb0_3")
tdSql.checkData(1, 1, "BINARY") tdSql.checkData(1, 1, "NCHAR")
payload = [''' payload = ['''
{ {
...@@ -835,7 +835,7 @@ class TDTestCase: ...@@ -835,7 +835,7 @@ class TDTestCase:
code = self._conn.schemaless_insert(payload, TDSmlProtocolType.JSON.value, TDSmlTimestampType.NOT_CONFIGURED.value) code = self._conn.schemaless_insert(payload, TDSmlProtocolType.JSON.value, TDSmlTimestampType.NOT_CONFIGURED.value)
print("schemaless_insert result {}".format(code)) print("schemaless_insert result {}".format(code))
tdSql.query("describe `stable`") tdSql.query("describe `STABLE`")
tdSql.checkRows(9) tdSql.checkRows(9)
#tdSql.query("select * from `key`") #tdSql.query("select * from `key`")
......
...@@ -333,7 +333,7 @@ class TDTestCase: ...@@ -333,7 +333,7 @@ class TDTestCase:
tdSql.query('describe `!@#$.%^&*()`') tdSql.query('describe `!@#$.%^&*()`')
tdSql.checkRows(9) tdSql.checkRows(9)
tdSql.query('describe `stable`') tdSql.query('describe `STABLE`')
tdSql.checkRows(9) tdSql.checkRows(9)
#tdSql.query('select * from `123`') #tdSql.query('select * from `123`')
......
...@@ -86,6 +86,67 @@ class TDTestCase: ...@@ -86,6 +86,67 @@ class TDTestCase:
#tdSql.query('select tbname, * from childtable') #tdSql.query('select tbname, * from childtable')
#tdSql.checkRows(1) #tdSql.checkRows(1)
###Test when tag is omitted
lines3 = [ "sti c1=4i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"sti c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"
]
code = self._conn.schemaless_insert(lines3, TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
tdSql.query('select * from sti')
tdSql.checkRows(2)
tdSql.query('select tbname from sti')
tdSql.checkRows(1)
lines4 = [ "stp c1=4i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"stp c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"
]
code = self._conn.schemaless_insert([ lines4[0] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
code = self._conn.schemaless_insert([ lines4[1] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
tdSql.query('select * from stp')
tdSql.checkRows(2)
tdSql.query('select tbname from stp')
tdSql.checkRows(1)
lines5 = [ "stq c1=4i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"stq,t1=abc c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000",
"stq,t2=abc c1=3i64,c3=L\"passitagin\",c4=5f64,c5=5f64,c6=true 1626006833640000000"
]
code = self._conn.schemaless_insert([ lines5[0] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
code = self._conn.schemaless_insert([ lines5[1] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
code = self._conn.schemaless_insert([ lines5[2] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
tdSql.query('select * from stq')
tdSql.checkRows(3)
tdSql.query('select tbname from stq')
tdSql.checkRows(3)
lines6 = [ "str c1=4i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"str,t1=abc c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000",
"str,t2=abc c1=3i64,c3=L\"passitagin\",c4=5f64,c5=5f64,c6=true 1626006833640000000"
]
code = self._conn.schemaless_insert(lines6, TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
print("schemaless_insert result {}".format(code))
tdSql.query('select * from str')
tdSql.checkRows(3)
tdSql.query('select tbname from str')
tdSql.checkRows(3)
###Special Character and keyss ###Special Character and keyss
self._conn.schemaless_insert([ self._conn.schemaless_insert([
"1234,id=3456,abc=4i64,def=3i64 123=3i64,int=2i64,bool=false,into=5f64,column=7u64,!@#$.%^&*()=false 1626006933641", "1234,id=3456,abc=4i64,def=3i64 123=3i64,int=2i64,bool=false,into=5f64,column=7u64,!@#$.%^&*()=false 1626006933641",
...@@ -112,7 +173,7 @@ class TDTestCase: ...@@ -112,7 +173,7 @@ class TDTestCase:
tdSql.query('describe `!@#$.%^&*()`') tdSql.query('describe `!@#$.%^&*()`')
tdSql.checkRows(9) tdSql.checkRows(9)
tdSql.query('describe `stable`') tdSql.query('describe `STABLE`')
tdSql.checkRows(9) tdSql.checkRows(9)
#tdSql.query('select * from `3456`') #tdSql.query('select * from `3456`')
......
...@@ -92,13 +92,13 @@ class TDTestCase: ...@@ -92,13 +92,13 @@ class TDTestCase:
tdSql.query("select * from st where tbname like 'tb_\_'") tdSql.query("select * from st where tbname like 'tb_\_'")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.query("select * from st where tbname like 'tb___'") tdSql.query("select * from st where tbname like 'tb___'")
tdSql.checkRows(4)
tdSql.query("select * from st where tbname like 'tb_\__'")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select * from st where tbname like 'tb_\__'")
tdSql.checkRows(2)
tdSql.query("select * from st where tbname like 'tb_\_\_'") tdSql.query("select * from st where tbname like 'tb_\_\_'")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.query("select * from st where tbname like 'tb\__\_'") tdSql.query("select * from st where tbname like 'tb\__\_'")
tdSql.checkRows(1) tdSql.checkRows(2)
tdSql.query("select * from st where tbname like 'tb\__\__'") tdSql.query("select * from st where tbname like 'tb\__\__'")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query("select * from st where tbname like 'tb\__\_\_'") tdSql.query("select * from st where tbname like 'tb\__\_\_'")
...@@ -116,9 +116,9 @@ class TDTestCase: ...@@ -116,9 +116,9 @@ class TDTestCase:
tdSql.query("select * from st where name like 'tbname\__';") tdSql.query("select * from st where name like 'tbname\__';")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select * from st where name like 'tbname___';") tdSql.query("select * from st where name like 'tbname___';")
tdSql.checkRows(4)
tdSql.query("select * from st where name like 'tbname_\__';")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select * from st where name like 'tbname_\__';")
tdSql.checkRows(2)
tdSql.query("select * from st where name like 'tbname_\_\_';") tdSql.query("select * from st where name like 'tbname_\_\_';")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.query("select * from st where name like 'tbname\_\__';") tdSql.query("select * from st where name like 'tbname\_\__';")
...@@ -132,7 +132,8 @@ class TDTestCase: ...@@ -132,7 +132,8 @@ class TDTestCase:
tdSql.query("select * from st where name like 'tbname\_\__\_';") tdSql.query("select * from st where name like 'tbname\_\__\_';")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query("select name from st where name like 'tbname\_\_\__';") tdSql.query("select name from st where name like 'tbname\_\_\__';")
tdSql.checkData(0,0 "tbname____") tdSql.checkRows(1)
tdSql.checkData(0,0, "tbname____")
# check escape about tags # check escape about tags
tdSql.query("select * from st where tagg like 'tag\_';") tdSql.query("select * from st where tagg like 'tag\_';")
...@@ -142,9 +143,9 @@ class TDTestCase: ...@@ -142,9 +143,9 @@ class TDTestCase:
tdSql.query("select * from st where tagg like 'tag\__';") tdSql.query("select * from st where tagg like 'tag\__';")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select * from st where tagg like 'tag___';") tdSql.query("select * from st where tagg like 'tag___';")
tdSql.checkRows(4)
tdSql.query("select * from st where tagg like 'tag_\__';")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select * from st where tagg like 'tag_\__';")
tdSql.checkRows(2)
tdSql.query("select * from st where tagg like 'tag_\_\_';") tdSql.query("select * from st where tagg like 'tag_\_\_';")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.query("select * from st where tagg like 'tag\_\__';") tdSql.query("select * from st where tagg like 'tag\_\__';")
...@@ -158,7 +159,7 @@ class TDTestCase: ...@@ -158,7 +159,7 @@ class TDTestCase:
tdSql.query("select * from st where tagg like 'tag\_\__\_';") tdSql.query("select * from st where tagg like 'tag\_\__\_';")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query("select * from st where tagg like 'tag\_\__\_';") tdSql.query("select * from st where tagg like 'tag\_\__\_';")
tdSql.checkData(0,0 "tag__a_") tdSql.checkData(0,0, "tag__a_")
os.system("rm -rf ./*.py.sql") os.system("rm -rf ./*.py.sql")
......
...@@ -101,9 +101,16 @@ if $data11 != -2 then ...@@ -101,9 +101,16 @@ if $data11 != -2 then
endi endi
print ==========>TD10758 print ==========>TD10758
sql create database groupby_tbname
sql use groupby_tbname
sql create stable st(ts timestamp, c1 int) tags(t int); sql create stable st(ts timestamp, c1 int) tags(t int);
sql create table ct1 using st tags(1) sql create table ct1 using st tags(1)
sql insert into ct1 values(now, 1)(now+1s, 2)(now+2s, 3) sql insert into ct1 values(now, 1)(now+1s, 2)(now+2s, 3)
sql create table ct2 using st tags(2)
sql insert into ct2 values(now, 21)(now+1s, 22)(now+2s, 23)
sql create table ct3 using st tags(3)
sql insert into ct3 values(now, 31)(now+1s, 32)(now+2s, 33)
sql select csum(c1),ts,tbname,t from ct1 sql select csum(c1),ts,tbname,t from ct1
print $data10 , $data11 , $data12, $data13, $data14 print $data10 , $data11 , $data12, $data13, $data14
if $data13 != ct1 then if $data13 != ct1 then
...@@ -169,6 +176,81 @@ if $data14 != 1 then ...@@ -169,6 +176,81 @@ if $data14 != 1 then
return -1 return -1
endi endi
sql select mavg(c1,2),tbname from st group by tbname
print $data10 , $data11 , $data12 , $data13
if $data12 != ct1 then
return -1
endi
if $data13 != ct1 then
return -1
endi
sql select diff(c1),tbname from st group by tbname
print $data10 , $data11 , $data12 , $data13
if $data12 != ct1 then
return -1
endi
if $data13 != ct1 then
return -1
endi
sql select csum(c1),tbname from st group by tbname
print $data10 , $data11 , $data12, $data13, $data14
print $data10 , $data11 , $data12 , $data13
if $data12 != ct1 then
return -1
endi
if $data13 != ct1 then
return -1
endi
sql select csum(c1),t,tbname from st group by tbname limit 2
print $data10 , $data11 , $data12 , $data13 , $data14
print $data30 , $data31 , $data32 , $data33 , $data34
if $data13 != ct1 then
return -1
endi
if $data14 != ct1 then
return -1
endi
if $data33 != ct2 then
return -1
endi
if $data34 != ct2 then
return -1
endi
sql select mavg(c1,2),t,tbname from st group by tbname limit 2
print $data10 , $data11 , $data12 , $data13 , $data14
print $data30 , $data31 , $data32 , $data33 , $data34
if $data13 != ct1 then
return -1
endi
if $data14 != ct1 then
return -1
endi
if $data33 != ct2 then
return -1
endi
if $data34 != ct2 then
return -1
endi
sql select diff(c1),t,tbname from st group by tbname limit 2
print $data10 , $data11 , $data12 , $data13 , $data14
print $data30 , $data31 , $data32 , $data33 , $data34
if $data13 != ct1 then
return -1
endi
if $data14 != ct1 then
return -1
endi
if $data33 != ct2 then
return -1
endi
if $data34 != ct2 then
return -1
endi
sql drop database groupby_tbname
print =============== clear print =============== clear
sql drop database $db sql drop database $db
......
...@@ -30,35 +30,50 @@ sql create dnode $hostname2 ...@@ -30,35 +30,50 @@ sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start system sh/exec.sh -n dnode2 -s start
sql create dnode $hostname3 sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start system sh/exec.sh -n dnode3 -s start
sleep 5000 sleep 3000
$x = 0
show1:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show dnodes sql show dnodes
print dnode1 $data5_1 print dnode1 $data5_1
print dnode1 $data5_2 print dnode2 $data5_2
print dnode1 $data5_3 print dnode3 $data5_3
if $data5_1 != mnode then if $data5_1 != mnode then
return -1 goto show1
endi endi
if $data5_2 != vnode then if $data5_2 != vnode then
return -1 goto show1
endi endi
if $data5_3 != any then if $data5_3 != any then
return -1 goto show1
endi endi
show2:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show mnodes sql show mnodes
print dnode1 ==> $data2_1 print dnode1 ==> $data2_1
print dnode2 ==> $data2_2 print dnode2 ==> $data2_2
print dnode3 ==> $data2_3 print dnode3 ==> $data2_3
if $data2_1 != master then if $data2_1 != master then
return -1 goto show2
endi endi
if $data2_2 != null then if $data2_2 != null then
return -1 goto show2
endi endi
if $data2_3 != slave then if $data2_3 != slave then
return -1 goto show2
endi endi
print ========== step2 print ========== step2
...@@ -72,26 +87,28 @@ sql create table d1.t6 (ts timestamp, i int) ...@@ -72,26 +87,28 @@ sql create table d1.t6 (ts timestamp, i int)
sql create table d1.t7 (ts timestamp, i int) sql create table d1.t7 (ts timestamp, i int)
sql create table d1.t8 (ts timestamp, i int) sql create table d1.t8 (ts timestamp, i int)
show3:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show dnodes sql show dnodes
print dnode1 $data2_1 print dnode1 $data2_1
print dnode2 $data2_2 print dnode2 $data2_2
print dnode3 $data2_3 print dnode3 $data2_3
if $data2_1 != 0 then if $data2_1 != 0 then
return -1 goto show3
endi endi
if $data2_2 != 1 then if $data2_2 != 1 then
return -1 goto show3
endi endi
if $data2_3 != 1 then if $data2_3 != 1 then
return -1 goto show3
endi endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec.sh -n dnode3 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT
system sh/exec.sh -n dnode6 -s stop -x SIGINT
system sh/exec.sh -n dnode7 -s stop -x SIGINT
system sh/exec.sh -n dnode8 -s stop -x SIGINT
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册