[td-255] merge develop
This commit is contained in:
commit
a66e65b724
|
@ -4,7 +4,7 @@ PROJECT(TDengine)
|
|||
IF (DEFINED VERNUMBER)
|
||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||
ELSE ()
|
||||
SET(TD_VER_NUMBER "2.1.7.1")
|
||||
SET(TD_VER_NUMBER "2.1.7.2")
|
||||
ENDIF ()
|
||||
|
||||
IF (DEFINED VERCOMPATIBLE)
|
||||
|
|
|
@ -30,7 +30,7 @@ TDengine 的模块之一是时序数据库。但除此之外,为减少研发
|
|||
|
||||
|数据源特点和需求|不适用|可能适用|非常适用|简单说明|
|
||||
|---|---|---|---|---|
|
||||
|总体数据量巨大| | | √ |TDengine 在容量方面提供出色的水平扩展功能,并且具备匹配高压缩的存储结构,达到业界最优的存储效率。|
|
||||
|总体数据量巨大| | | √ | TDengine 在容量方面提供出色的水平扩展功能,并且具备匹配高压缩的存储结构,达到业界最优的存储效率。|
|
||||
|数据输入速度偶尔或者持续巨大| | | √ | TDengine 的性能大大超过同类产品,可以在同样的硬件环境下持续处理大量的输入数据,并且提供很容易在用户环境里面运行的性能评估工具。|
|
||||
|数据源数目巨大| | | √ | TDengine 设计中包含专门针对大量数据源的优化,包括数据的写入和查询,尤其适合高效处理海量(千万或者更多量级)的数据源。|
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Java 对
|
|||
## 安装Java Connector
|
||||
|
||||
### 安装前准备
|
||||
|
||||
使用Java Connector连接数据库前,需要具备以下条件:
|
||||
1. Linux或Windows操作系统
|
||||
2. Java 1.8以上运行时环境
|
||||
|
@ -96,6 +97,7 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Java 对
|
|||
**注意**:在 Windows 环境开发时需要安装 TDengine 对应的 [windows 客户端](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client),Linux 服务器安装完 TDengine 之后默认已安装 client,也可以单独安装 [Linux 客户端](https://www.taosdata.com/cn/getting-started/#快速上手) 连接远程 TDengine Server。
|
||||
|
||||
### 通过maven获取JDBC driver
|
||||
|
||||
目前 taos-jdbcdriver 已经发布到 [Sonatype Repository](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) 仓库,且各大仓库都已同步。
|
||||
- [sonatype](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
- [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
|
@ -118,6 +120,7 @@ git clone https://github.com/taosdata/TDengine.git
|
|||
cd TDengine/src/connector/jdbc
|
||||
mvn clean package -Dmaven.test.skip=true
|
||||
```
|
||||
|
||||
编译后,在target目录下会产生taos-jdbcdriver-2.0.XX-dist.jar的jar包。
|
||||
|
||||
## Java连接器的使用
|
||||
|
@ -125,6 +128,7 @@ mvn clean package -Dmaven.test.skip=true
|
|||
### 获取连接
|
||||
|
||||
#### 指定URL获取连接
|
||||
|
||||
通过指定URL获取连接,如下所示:
|
||||
|
||||
```java
|
||||
|
@ -132,6 +136,7 @@ Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
|||
String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl);
|
||||
```
|
||||
|
||||
以上示例,使用 **JDBC-RESTful** 的 driver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
|
||||
|
||||
使用 JDBC-RESTful 接口,不需要依赖本地函数库。与 JDBC-JNI 相比,仅需要:
|
||||
|
@ -145,6 +150,7 @@ Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|||
String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata";
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl);
|
||||
```
|
||||
|
||||
以上示例,使用了 JDBC-JNI 的 driver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
|
||||
|
||||
**注意**:使用 JDBC-JNI 的 driver,taos-jdbcdriver 驱动包时需要依赖系统对应的本地函数库(Linux 下是 libtaos.so;Windows 下是 taos.dll)。
|
||||
|
@ -201,6 +207,7 @@ properties 中的配置参数如下:
|
|||
#### 使用客户端配置文件建立连接
|
||||
|
||||
当使用 JDBC-JNI 连接 TDengine 集群时,可以使用客户端配置文件,在客户端配置文件中指定集群的 firstEp、secondEp参数。如下所示:
|
||||
|
||||
1. 在 Java 应用中不指定 hostname 和 port
|
||||
|
||||
```java
|
||||
|
@ -217,6 +224,7 @@ public Connection getConn() throws Exception{
|
|||
```
|
||||
|
||||
2. 在配置文件中指定 firstEp 和 secondEp
|
||||
|
||||
```
|
||||
# first fully qualified domain name (FQDN) for TDengine system
|
||||
firstEp cluster_node1:6030
|
||||
|
@ -232,6 +240,7 @@ secondEp cluster_node2:6030
|
|||
```
|
||||
|
||||
以上示例,jdbc 会使用客户端的配置文件,建立到 hostname 为 cluster_node1、端口为 6030、数据库名为 test 的连接。当集群中 firstEp 节点失效时,JDBC 会尝试使用 secondEp 连接集群。
|
||||
|
||||
TDengine 中,只要保证 firstEp 和 secondEp 中一个节点有效,就可以正常建立到集群的连接。
|
||||
|
||||
> 注意:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值 C://TDengine/cfg/taos.cfg。
|
||||
|
@ -315,6 +324,7 @@ try (Statement statement = connection.createStatement()) {
|
|||
```
|
||||
|
||||
JDBC连接器可能报错的错误码包括3种:JDBC driver本身的报错(错误码在0x2301到0x2350之间),JNI方法的报错(错误码在0x2351到0x2400之间),TDengine其他功能模块的报错。
|
||||
|
||||
具体的错误码请参考:
|
||||
* https://github.com/taosdata/TDengine/blob/develop/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
|
||||
* https://github.com/taosdata/TDengine/blob/develop/src/inc/taoserror.h
|
||||
|
@ -395,6 +405,7 @@ public void setShort(int columnIndex, ArrayList<Short> list) throws SQLException
|
|||
public void setString(int columnIndex, ArrayList<String> list, int size) throws SQLException
|
||||
public void setNString(int columnIndex, ArrayList<String> list, int size) throws SQLException
|
||||
```
|
||||
|
||||
其中 setString 和 setNString 都要求用户在 size 参数里声明表定义中对应列的列宽。
|
||||
|
||||
## <a class="anchor" id="subscribe"></a>订阅
|
||||
|
@ -452,6 +463,7 @@ conn.close();
|
|||
## 与连接池使用
|
||||
|
||||
### HikariCP
|
||||
|
||||
使用示例如下:
|
||||
|
||||
```java
|
||||
|
@ -485,6 +497,7 @@ conn.close();
|
|||
> 更多 HikariCP 使用问题请查看[官方说明](https://github.com/brettwooldridge/HikariCP)。
|
||||
|
||||
### Druid
|
||||
|
||||
使用示例如下:
|
||||
|
||||
```java
|
||||
|
@ -539,7 +552,7 @@ Query OK, 1 row(s) in set (0.000141s)
|
|||
* Springbootdemo:springboot示例源程序
|
||||
* SpringJdbcTemplate:SpringJDBC模板
|
||||
|
||||
请参考:
|
||||
请参考:[JDBC example](https://github.com/taosdata/TDengine/tree/develop/tests/examples/JDBC)
|
||||
|
||||
## 常见问题
|
||||
|
||||
|
|
|
@ -504,8 +504,8 @@ Query OK, 1 row(s) in set (0.000141s)
|
|||
- Please refer to [springbootdemo](https://github.com/taosdata/TDengine/tree/develop/tests/examples/JDBC/springbootdemo) if using taos-jdbcdriver in Spring JdbcTemplate.
|
||||
|
||||
## Example Codes
|
||||
you see sample code here: 
|
||||
|
||||
you see sample code here: [JDBC example](https://github.com/taosdata/TDengine/tree/develop/tests/examples/JDBC)
|
||||
|
||||
## FAQ
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: tdengine
|
||||
base: core18
|
||||
version: '2.1.7.1'
|
||||
version: '2.1.7.2'
|
||||
icon: snap/gui/t-dengine.svg
|
||||
summary: an open-source big data platform designed and optimized for IoT.
|
||||
description: |
|
||||
|
@ -72,7 +72,7 @@ parts:
|
|||
- usr/bin/taosd
|
||||
- usr/bin/taos
|
||||
- usr/bin/taosdemo
|
||||
- usr/lib/libtaos.so.2.1.7.1
|
||||
- usr/lib/libtaos.so.2.1.7.2
|
||||
- usr/lib/libtaos.so.1
|
||||
- usr/lib/libtaos.so
|
||||
|
||||
|
|
|
@ -191,6 +191,7 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo);
|
|||
void tscFieldInfoCopy(SFieldInfo* pFieldInfo, const SFieldInfo* pSrc, const SArray* pExprList);
|
||||
|
||||
static FORCE_INLINE int32_t tscNumOfFields(SQueryInfo* pQueryInfo) { return pQueryInfo->fieldsInfo.numOfOutput; }
|
||||
int32_t tscGetFirstInvisibleFieldPos(SQueryInfo* pQueryInfo);
|
||||
|
||||
int32_t tscFieldInfoCompare(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2, int32_t *diffSize);
|
||||
void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t uid);
|
||||
|
|
|
@ -649,7 +649,7 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD
|
|||
for(int32_t j = 0; j < numOfExpr; ++j) {
|
||||
pCtx[j].pOutput += (pCtx[j].outputBytes * numOfRows);
|
||||
if (pCtx[j].functionId == TSDB_FUNC_TOP || pCtx[j].functionId == TSDB_FUNC_BOTTOM) {
|
||||
if(j > 0)pCtx[j].ptsOutputBuf = pCtx[j - 1].pOutput;
|
||||
if(j > 0) pCtx[j].ptsOutputBuf = pCtx[j - 1].pOutput;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,8 @@ static int normalStmtPrepare(STscStmt* stmt) {
|
|||
return code;
|
||||
}
|
||||
start = i + token.n;
|
||||
} else if (token.type == TK_ILLEGAL) {
|
||||
return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "invalid sql");
|
||||
}
|
||||
|
||||
i += token.n;
|
||||
|
|
|
@ -893,6 +893,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
case TSDB_SQL_SELECT: {
|
||||
const char * msg1 = "no nested query supported in union clause";
|
||||
code = loadAllTableMeta(pSql, pInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
@ -906,6 +907,10 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
|
||||
tscTrace("0x%"PRIx64" start to parse the %dth subclause, total:%"PRIzu, pSql->self, i, size);
|
||||
|
||||
if (size > 1 && pSqlNode->from && pSqlNode->from->type == SQL_NODE_FROM_SUBQUERY) {
|
||||
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
// normalizeSqlNode(pSqlNode); // normalize the column name in each function
|
||||
if ((code = validateSqlNode(pSql, pSqlNode, pQueryInfo)) != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
@ -5102,10 +5107,6 @@ static void cleanQueryExpr(SCondExpr* pCondExpr) {
|
|||
tSqlExprDestroy(pCondExpr->pTableCond);
|
||||
}
|
||||
|
||||
if (pCondExpr->pTagCond) {
|
||||
tSqlExprDestroy(pCondExpr->pTagCond);
|
||||
}
|
||||
|
||||
if (pCondExpr->pColumnCond) {
|
||||
tSqlExprDestroy(pCondExpr->pColumnCond);
|
||||
}
|
||||
|
@ -7228,9 +7229,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
|
|||
s = &pSchema[colIndex];
|
||||
}
|
||||
}
|
||||
|
||||
size_t size = tscNumOfExprs(pQueryInfo);
|
||||
|
||||
|
||||
if (TSDB_COL_IS_TAG(pColIndex->flag)) {
|
||||
|
||||
int32_t f = TSDB_FUNC_TAG;
|
||||
|
@ -7238,8 +7237,10 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
|
|||
f = TSDB_FUNC_TAGPRJ;
|
||||
}
|
||||
|
||||
int32_t pos = tscGetFirstInvisibleFieldPos(pQueryInfo);
|
||||
|
||||
SColumnIndex index = {.tableIndex = pQueryInfo->groupbyExpr.tableIndex, .columnIndex = colIndex};
|
||||
SExprInfo* pExpr = tscExprAppend(pQueryInfo, f, &index, s->type, s->bytes, getNewResColId(pCmd), s->bytes, true);
|
||||
SExprInfo* pExpr = tscExprInsert(pQueryInfo, pos, f, &index, s->type, s->bytes, getNewResColId(pCmd), s->bytes, true);
|
||||
|
||||
memset(pExpr->base.aliasName, 0, sizeof(pExpr->base.aliasName));
|
||||
tstrncpy(pExpr->base.aliasName, s->name, sizeof(pExpr->base.aliasName));
|
||||
|
@ -7249,13 +7250,15 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
|
|||
|
||||
// NOTE: tag column does not add to source column list
|
||||
SColumnList ids = createColumnList(1, 0, pColIndex->colIndex);
|
||||
insertResultField(pQueryInfo, (int32_t)size, &ids, s->bytes, (int8_t)s->type, s->name, pExpr);
|
||||
insertResultField(pQueryInfo, pos, &ids, s->bytes, (int8_t)s->type, s->name, pExpr);
|
||||
} else {
|
||||
// if this query is "group by" normal column, time window query is not allowed
|
||||
if (isTimeWindowQuery(pQueryInfo)) {
|
||||
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
size_t size = tscNumOfExprs(pQueryInfo);
|
||||
|
||||
bool hasGroupColumn = false;
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
SExprInfo* pExpr = tscExprGet(pQueryInfo, j);
|
||||
|
@ -8483,7 +8486,10 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
|
||||
size_t len = strlen(name);
|
||||
|
||||
taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&pTableMeta, &tableMetaCapacity);
|
||||
if (NULL == taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&pTableMeta, &tableMetaCapacity)) {
|
||||
// not found
|
||||
tfree(pTableMeta);
|
||||
}
|
||||
|
||||
if (pTableMeta && pTableMeta->id.uid > 0) {
|
||||
tscDebug("0x%"PRIx64" retrieve table meta %s from local buf", pSql->self, name);
|
||||
|
|
|
@ -377,7 +377,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
pSql->rpcRid = -1;
|
||||
|
||||
if (pObj->signature != pObj) {
|
||||
tscDebug("0x%"PRIx64" DB connection is closed, cmd:%d pObj:%p signature:%p", pSql->self, pCmd->command, pObj, pObj->signature);
|
||||
|
||||
|
@ -703,8 +702,13 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) {
|
|||
}
|
||||
}
|
||||
|
||||
return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + srcTagFilterSize + exprSize + tsBufSize +
|
||||
tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen;
|
||||
SCond* pCond = &pQueryInfo->tagCond.tbnameCond;
|
||||
if (pCond->len > 0) {
|
||||
srcColListSize += pCond->len;
|
||||
}
|
||||
|
||||
return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + srcTagFilterSize +
|
||||
exprSize + tsBufSize + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen;
|
||||
}
|
||||
|
||||
static char *doSerializeTableInfo(SQueryTableMsg *pQueryMsg, SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, char *pMsg,
|
||||
|
@ -2921,7 +2925,9 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
|
|||
if (pTableMetaInfo->tableMetaCapacity != 0 && pTableMetaInfo->pTableMeta != NULL) {
|
||||
memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity);
|
||||
}
|
||||
taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity);
|
||||
if (NULL == taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity)) {
|
||||
tfree(pTableMetaInfo->pTableMeta);
|
||||
}
|
||||
|
||||
STableMeta* pMeta = pTableMetaInfo->pTableMeta;
|
||||
STableMeta* pSTMeta = (STableMeta *)(pSql->pBuf);
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
#define _GNU_SOURCE
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "texpr.h"
|
||||
|
||||
#include "tsched.h"
|
||||
#include "qTsbuf.h"
|
||||
#include "tcompare.h"
|
||||
#include "tscLog.h"
|
||||
|
|
|
@ -2120,6 +2120,22 @@ TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes) {
|
|||
return f;
|
||||
}
|
||||
|
||||
int32_t tscGetFirstInvisibleFieldPos(SQueryInfo* pQueryInfo) {
|
||||
if (pQueryInfo->fieldsInfo.numOfOutput <= 0 || pQueryInfo->fieldsInfo.internalField == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SInternalField* pField = taosArrayGet(pQueryInfo->fieldsInfo.internalField, i);
|
||||
if (!pField->visible) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return pQueryInfo->fieldsInfo.numOfOutput;
|
||||
}
|
||||
|
||||
|
||||
SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) {
|
||||
assert(pFieldInfo != NULL);
|
||||
pFieldInfo->numOfOutput++;
|
||||
|
@ -3891,6 +3907,8 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) {
|
|||
// todo refactor
|
||||
tscDebug("0x%"PRIx64" all subquery response received, retry", pParentSql->self);
|
||||
if (code && !((code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) && pParentSql->retry < pParentSql->maxRetry)) {
|
||||
pParentSql->res.code = code;
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
return;
|
||||
}
|
||||
|
@ -3970,6 +3988,7 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
|
|||
pNew->signature = pNew;
|
||||
pNew->sqlstr = strdup(pSql->sqlstr);
|
||||
pNew->fp = tscSubqueryCompleteCallback;
|
||||
pNew->fetchFp = tscSubqueryCompleteCallback;
|
||||
pNew->maxRetry = pSql->maxRetry;
|
||||
|
||||
pNew->cmd.resColumnId = TSDB_RES_COL_ID;
|
||||
|
@ -4512,22 +4531,21 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name,
|
|||
memset((char *)p, 0, sz);
|
||||
}
|
||||
|
||||
STableMeta* pChild1;
|
||||
|
||||
taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz);
|
||||
*ppSTable = p;
|
||||
if (NULL == taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz)) {
|
||||
tfree(p);
|
||||
} else {
|
||||
*ppSTable = p;
|
||||
}
|
||||
|
||||
// tableMeta exists, build child table meta according to the super table meta
|
||||
// the uid need to be checked in addition to the general name of the super table.
|
||||
if (p && p->id.uid > 0 && pChild->suid == p->id.uid) {
|
||||
|
||||
int32_t totalBytes = (p->tableInfo.numOfColumns + p->tableInfo.numOfTags) * sizeof(SSchema);
|
||||
int32_t tableMetaSize = sizeof(STableMeta) + totalBytes;
|
||||
if (*tableMetaCapacity < tableMetaSize) {
|
||||
pChild1 = realloc(pChild, tableMetaSize);
|
||||
if(pChild1 == NULL)
|
||||
return -1;
|
||||
pChild = pChild1;
|
||||
STableMeta* pChild1 = realloc(pChild, tableMetaSize);
|
||||
if(pChild1 == NULL) return -1;
|
||||
pChild = pChild1;
|
||||
*tableMetaCapacity = (size_t)tableMetaSize;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class RestfulConnection extends AbstractConnection {
|
|||
private final String url;
|
||||
private final String database;
|
||||
private final String token;
|
||||
/******************************************************/
|
||||
|
||||
private boolean isClosed;
|
||||
private final DatabaseMetaData metadata;
|
||||
|
||||
|
|
|
@ -88,17 +88,24 @@ public class RestfulStatement extends AbstractStatement {
|
|||
}
|
||||
|
||||
private String getUrl() throws SQLException {
|
||||
String dbname = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_DBNAME);
|
||||
if (dbname == null || dbname.trim().isEmpty()) {
|
||||
dbname = "";
|
||||
} else {
|
||||
dbname = "/" + dbname.toLowerCase();
|
||||
}
|
||||
TimestampFormat timestampFormat = TimestampFormat.valueOf(conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT).trim().toUpperCase());
|
||||
String url;
|
||||
|
||||
switch (timestampFormat) {
|
||||
case TIMESTAMP:
|
||||
url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlt";
|
||||
url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlt" + dbname;
|
||||
break;
|
||||
case UTC:
|
||||
url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc";
|
||||
url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc" + dbname;
|
||||
break;
|
||||
default:
|
||||
url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql" + dbname;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class MultiConnectionWithDifferentDbTest {
|
||||
|
||||
private static String host = "127.0.0.1";
|
||||
private static String db1 = "db1";
|
||||
private static String db2 = "db2";
|
||||
|
||||
private long ts;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
List<Thread> threads = IntStream.range(1, 3).mapToObj(i -> new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
queryDb();
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void queryDb() {
|
||||
String url = "jdbc:TAOS-RS://" + host + ":6041/db" + i + "?user=root&password=taosdata";
|
||||
try (Connection connection = DriverManager.getConnection(url)) {
|
||||
Statement stmt = connection.createStatement();
|
||||
|
||||
ResultSet rs = stmt.executeQuery("select * from weather");
|
||||
assertNotNull(rs);
|
||||
rs.next();
|
||||
long actual = rs.getTimestamp("ts").getTime();
|
||||
assertEquals(ts, actual);
|
||||
|
||||
int f1 = rs.getInt("f1");
|
||||
assertEquals(i, f1);
|
||||
|
||||
String loc = i == 1 ? "beijing" : "shanghai";
|
||||
String loc_actual = rs.getString("loc");
|
||||
assertEquals(loc, loc_actual);
|
||||
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "thread-" + i)).collect(Collectors.toList());
|
||||
|
||||
threads.forEach(Thread::start);
|
||||
|
||||
for (Thread t : threads) {
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ts = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("drop database if exists " + db1);
|
||||
stmt.execute("create database if not exists " + db1);
|
||||
stmt.execute("use " + db1);
|
||||
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
|
||||
stmt.execute("insert into t1 using weather tags('beijing') values(" + ts + ", 1)");
|
||||
|
||||
stmt.execute("drop database if exists " + db2);
|
||||
stmt.execute("create database if not exists " + db2);
|
||||
stmt.execute("use " + db2);
|
||||
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
|
||||
stmt.execute("insert into t1 using weather tags('shanghai') values(" + ts + ", 2)");
|
||||
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DatabaseSpecifiedTest {
|
||||
|
||||
private static String host = "127.0.0.1";
|
||||
private static String dbname = "test_db_spec";
|
||||
|
||||
private Connection connection;
|
||||
private long ts;
|
||||
|
||||
@Test
|
||||
public void test() throws SQLException {
|
||||
// when
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/" + dbname + "?user=root&password=taosdata");
|
||||
try (Statement stmt = connection.createStatement();) {
|
||||
ResultSet rs = stmt.executeQuery("select * from weather");
|
||||
|
||||
//then
|
||||
assertNotNull(rs);
|
||||
rs.next();
|
||||
long now = rs.getTimestamp("ts").getTime();
|
||||
assertEquals(ts, now);
|
||||
int f1 = rs.getInt(2);
|
||||
assertEquals(1, f1);
|
||||
String loc = rs.getString("loc");
|
||||
assertEquals("beijing", loc);
|
||||
}
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ts = System.currentTimeMillis();
|
||||
try {
|
||||
Connection connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
|
||||
Statement stmt = connection.createStatement();
|
||||
|
||||
stmt.execute("drop database if exists " + dbname);
|
||||
stmt.execute("create database if not exists " + dbname);
|
||||
stmt.execute("use " + dbname);
|
||||
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
|
||||
stmt.execute("insert into t1 using weather tags('beijing') values( " + ts + ", 1)");
|
||||
|
||||
stmt.close();
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@ import taos
|
|||
|
||||
conn = taos.connect(host='127.0.0.1',
|
||||
user='root',
|
||||
passworkd='taodata',
|
||||
password='taosdata',
|
||||
database='log')
|
||||
cursor = conn.cursor()
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||
arguments->is_raw_time = true;
|
||||
break;
|
||||
case 'f':
|
||||
if (wordexp(arg, &full_path, 0) != 0) {
|
||||
if ((0 == strlen(arg)) || (wordexp(arg, &full_path, 0) != 0)) {
|
||||
fprintf(stderr, "Invalid path %s\n", arg);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -3328,6 +3328,7 @@ static void* createTable(void *sarg)
|
|||
}
|
||||
|
||||
len = 0;
|
||||
|
||||
if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer,
|
||||
NO_INSERT_TYPE, false)) {
|
||||
errorPrint2("queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer);
|
||||
|
@ -7956,12 +7957,12 @@ static int insertTestProcess() {
|
|||
end = taosGetTimestampMs();
|
||||
|
||||
fprintf(stderr,
|
||||
"Spent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n",
|
||||
"\nSpent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n",
|
||||
(end - start)/1000.0, g_totalChildTables,
|
||||
g_Dbs.threadCountByCreateTbl, g_actualChildTables);
|
||||
if (g_fpOfInsertResult) {
|
||||
fprintf(g_fpOfInsertResult,
|
||||
"Spent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n",
|
||||
"\nSpent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n",
|
||||
(end - start)/1000.0, g_totalChildTables,
|
||||
g_Dbs.threadCountByCreateTbl, g_actualChildTables);
|
||||
}
|
||||
|
|
|
@ -50,14 +50,20 @@ void osInit() {
|
|||
char* taosGetCmdlineByPID(int pid) {
|
||||
static char cmdline[1024];
|
||||
sprintf(cmdline, "/proc/%d/cmdline", pid);
|
||||
FILE* f = fopen(cmdline, "r");
|
||||
if (f) {
|
||||
size_t size;
|
||||
size = fread(cmdline, sizeof(char), 1024, f);
|
||||
if (size > 0) {
|
||||
if ('\n' == cmdline[size - 1]) cmdline[size - 1] = '\0';
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
int fd = open(cmdline, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
int n = read(fd, cmdline, sizeof(cmdline) - 1);
|
||||
if (n < 0) n = 0;
|
||||
|
||||
if (n > 0 && cmdline[n - 1] == '\n') --n;
|
||||
|
||||
cmdline[n] = 0;
|
||||
|
||||
close(fd);
|
||||
} else {
|
||||
cmdline[0] = 0;
|
||||
}
|
||||
|
||||
return cmdline;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#define monTrace(...) { if (monDebugFlag & DEBUG_TRACE) { taosPrintLog("MON ", monDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define SQL_LENGTH 1030
|
||||
#define LOG_LEN_STR 100
|
||||
#define LOG_LEN_STR 512
|
||||
#define IP_LEN_STR TSDB_EP_LEN
|
||||
#define CHECK_INTERVAL 1000
|
||||
|
||||
|
|
|
@ -613,6 +613,7 @@ bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilter
|
|||
void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p);
|
||||
|
||||
SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows);
|
||||
|
||||
void* destroyOutputBuf(SSDataBlock* pBlock);
|
||||
void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols);
|
||||
|
||||
|
|
|
@ -4089,7 +4089,7 @@ static void mergeTableBlockDist(SResultRowCellInfo* pResInfo, const STableBlockD
|
|||
} else {
|
||||
pDist->maxRows = pSrc->maxRows;
|
||||
pDist->minRows = pSrc->minRows;
|
||||
|
||||
|
||||
int32_t maxSteps = TSDB_MAX_MAX_ROW_FBLOCK/TSDB_BLOCK_DIST_STEP_ROWS;
|
||||
if (TSDB_MAX_MAX_ROW_FBLOCK % TSDB_BLOCK_DIST_STEP_ROWS != 0) {
|
||||
++maxSteps;
|
||||
|
@ -4223,7 +4223,7 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) {
|
|||
taosArrayDestroy(pDist->dataBlockInfos);
|
||||
pDist->dataBlockInfos = NULL;
|
||||
}
|
||||
|
||||
|
||||
// cannot set the numOfIteratedElems again since it is set during previous iteration
|
||||
pResInfo->numOfRes = 1;
|
||||
pResInfo->hasResult = DATA_SET_FLAG;
|
||||
|
|
|
@ -3635,25 +3635,13 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
|
|||
|
||||
// set the correct pointer after the memory buffer reallocated.
|
||||
int32_t functionId = pBInfo->pCtx[i].functionId;
|
||||
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE){
|
||||
|
||||
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
|
||||
if (i > 0) pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity) {
|
||||
SSDataBlock* pDataBlock = pBInfo->pRes;
|
||||
|
||||
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
|
||||
int32_t functionId = pBInfo->pCtx[i].functionId;
|
||||
if (functionId < 0) {
|
||||
memset(pBInfo->pCtx[i].pOutput, 0, pColInfo->info.bytes * (*bufCapacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||
bool needCopyTs = false;
|
||||
int32_t tsNum = 0;
|
||||
|
@ -3684,6 +3672,19 @@ void copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput)
|
|||
}
|
||||
}
|
||||
|
||||
void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity) {
|
||||
SSDataBlock* pDataBlock = pBInfo->pRes;
|
||||
|
||||
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
|
||||
int32_t functionId = pBInfo->pCtx[i].functionId;
|
||||
if (functionId < 0) {
|
||||
memset(pBInfo->pCtx[i].pOutput, 0, pColInfo->info.bytes * (*bufCapacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
SResultRowCellInfo* pResInfo = GET_RES_INFO(&pCtx[j]);
|
||||
|
@ -7548,12 +7549,15 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
|
|||
pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols);
|
||||
pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput);
|
||||
pQueryMsg->numOfGroupCols = htons(pQueryMsg->numOfGroupCols);
|
||||
|
||||
pQueryMsg->tagCondLen = htons(pQueryMsg->tagCondLen);
|
||||
pQueryMsg->colCondLen = htons(pQueryMsg->colCondLen);
|
||||
|
||||
pQueryMsg->tsBuf.tsOffset = htonl(pQueryMsg->tsBuf.tsOffset);
|
||||
pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen);
|
||||
pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks);
|
||||
pQueryMsg->tsBuf.tsOrder = htonl(pQueryMsg->tsBuf.tsOrder);
|
||||
|
||||
pQueryMsg->numOfTags = htonl(pQueryMsg->numOfTags);
|
||||
pQueryMsg->tbnameCondLen = htonl(pQueryMsg->tbnameCondLen);
|
||||
pQueryMsg->secondStageOutput = htonl(pQueryMsg->secondStageOutput);
|
||||
|
|
|
@ -2460,7 +2460,7 @@ int32_t tsdbGetFileBlocksDistInfo(TsdbQueryHandleT* queryHandle, STableBlockDist
|
|||
|
||||
// current file are not overlapped with query time window, ignore remain files
|
||||
if ((ASCENDING_TRAVERSE(pQueryHandle->order) && win.skey > pQueryHandle->window.ekey) ||
|
||||
(!ASCENDING_TRAVERSE(pQueryHandle->order) && win.ekey < pQueryHandle->window.ekey)) {
|
||||
(!ASCENDING_TRAVERSE(pQueryHandle->order) && win.ekey < pQueryHandle->window.ekey)) {
|
||||
tsdbUnLockFS(REPO_FS(pQueryHandle->pTsdb));
|
||||
tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, 0x%"PRIx64, pQueryHandle,
|
||||
pQueryHandle->window.skey, pQueryHandle->window.ekey, pQueryHandle->qId);
|
||||
|
|
|
@ -537,7 +537,8 @@ void taosCacheCleanup(SCacheObj *pCacheObj) {
|
|||
pCacheObj->deleting = 1;
|
||||
|
||||
// wait for the refresh thread quit before destroying the cache object.
|
||||
while(atomic_load_8(&pCacheObj->deleting) != 0) {
|
||||
// But in the dll, the child thread will be killed before atexit takes effect.So here we only wait for 2 seconds.
|
||||
for (int i = 0; i < 40&&atomic_load_8(&pCacheObj->deleting) != 0; i++) {
|
||||
taosMsleep(50);
|
||||
}
|
||||
|
||||
|
|
|
@ -671,7 +671,7 @@ void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen,
|
|||
taosNetCheckSpeed(host, port, pkgLen, pkgNum, strtolower(type, pkgType));
|
||||
}else if (0 == strcmp("fqdn", role)) {
|
||||
taosNetTestFqdn(host);
|
||||
}else {
|
||||
} else {
|
||||
taosNetTestStartup(host, port);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,12 +64,15 @@ int32_t strRmquote(char *z, int32_t len){
|
|||
int32_t j = 0;
|
||||
for (uint32_t k = 1; k < len - 1; ++k) {
|
||||
if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) {
|
||||
if (z[k] == '\\' && z[k + 1] == '_') {
|
||||
//match '_' self
|
||||
} else {
|
||||
z[j] = z[k + 1];
|
||||
|
||||
cnt++;
|
||||
j++;
|
||||
k++;
|
||||
continue;
|
||||
cnt++;
|
||||
j++;
|
||||
k++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
z[j] = z[k];
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
taos -n fqdn
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
for N in -1 0 1 10000 10001
|
||||
do
|
||||
for l in 1023 1024 1073741824 1073741825
|
||||
do
|
||||
for S in udp tcp
|
||||
do
|
||||
taos -n speed -h BCC-2 -P 6030 -N $N -l $l -S $S 2>&1 | tee -a result.txt
|
||||
done
|
||||
done
|
||||
done
|
|
@ -1,13 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
for N in -1 0 1 10000 10001
|
||||
do
|
||||
for l in 1023 1024 1073741824 1073741825
|
||||
do
|
||||
for S in udp tcp
|
||||
do
|
||||
taos -n speed -h BCC-2 -P 6030 -N $N -l $l -S $S 2>&1 | tee -a result.txt
|
||||
done
|
||||
do
|
||||
taos -n speed -h BCC-2 -P 6030 -N $N -l $l -S $S 2>&1 | tee -a result.txt
|
||||
done
|
||||
done
|
||||
done
|
||||
|
|
|
@ -260,7 +260,7 @@ python3 ./test.py -f query/queryTsisNull.py
|
|||
python3 ./test.py -f query/subqueryFilter.py
|
||||
python3 ./test.py -f query/nestedQuery/queryInterval.py
|
||||
python3 ./test.py -f query/queryStateWindow.py
|
||||
python3 ./test.py -f query/nestedQuery/queryWithOrderLimit.py
|
||||
# python3 ./test.py -f query/nestedQuery/queryWithOrderLimit.py
|
||||
python3 ./test.py -f query/nestquery_last_row.py
|
||||
python3 ./test.py -f query/queryCnameDisplay.py
|
||||
python3 ./test.py -f query/operator_cost.py
|
||||
|
|
|
@ -72,7 +72,6 @@ class TDTestCase:
|
|||
tdSql.checkData(1, 1, "2018-09-17 09:00:20.009")
|
||||
tdSql.checkData(1, 3, "2018-09-17 09:00:20.009")
|
||||
|
||||
|
||||
tdSql.query("select ts from(select ts,derivative(col, 10s, 0) from stb group by tbname)")
|
||||
|
||||
tdSql.checkData(0, 0, "2018-09-17 09:00:10.000")
|
||||
|
|
|
@ -94,6 +94,23 @@ class TDTestCase:
|
|||
tdSql.error("select diff(col13) from test")
|
||||
tdSql.error("select diff(col14) from test")
|
||||
|
||||
tdSql.query("select ts,diff(col1),ts from test1")
|
||||
tdSql.checkRows(10)
|
||||
tdSql.checkData(0, 0, "2018-09-17 09:00:00.000")
|
||||
tdSql.checkData(0, 1, "2018-09-17 09:00:00.000")
|
||||
tdSql.checkData(0, 3, "2018-09-17 09:00:00.000")
|
||||
tdSql.checkData(9, 0, "2018-09-17 09:00:00.009")
|
||||
tdSql.checkData(9, 1, "2018-09-17 09:00:00.009")
|
||||
tdSql.checkData(9, 3, "2018-09-17 09:00:00.009")
|
||||
|
||||
tdSql.query("select ts,diff(col1),ts from test group by tbname")
|
||||
tdSql.checkRows(10)
|
||||
tdSql.checkData(0, 0, "2018-09-17 09:00:00.000")
|
||||
tdSql.checkData(0, 1, "2018-09-17 09:00:00.000")
|
||||
tdSql.checkData(0, 3, "2018-09-17 09:00:00.000")
|
||||
tdSql.checkData(9, 0, "2018-09-17 09:00:00.009")
|
||||
tdSql.checkData(9, 1, "2018-09-17 09:00:00.009")
|
||||
tdSql.checkData(9, 3, "2018-09-17 09:00:00.009")
|
||||
|
||||
tdSql.query("select ts,diff(col1),ts from test1")
|
||||
tdSql.checkRows(10)
|
||||
|
|
|
@ -697,10 +697,10 @@ class TDTestCase:
|
|||
tdSql.checkRows(tbnum*3)
|
||||
tdSql.query(f"select distinct c1 c2, c2 c3 from t1 where c1 <{tbnum}")
|
||||
tdSql.checkRows(3)
|
||||
tdSql.query("select distinct c1, c2 from stb1 order by ts")
|
||||
tdSql.checkRows(tbnum*3+1)
|
||||
tdSql.query("select distinct c1, c2 from t1 order by ts")
|
||||
tdSql.checkRows(4)
|
||||
tdSql.error("select distinct c1, c2 from stb1 order by ts")
|
||||
#tdSql.checkRows(tbnum*3+1)
|
||||
tdSql.error("select distinct c1, c2 from t1 order by ts")
|
||||
#tdSql.checkRows(4)
|
||||
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 ")
|
||||
|
@ -884,6 +884,126 @@ class TDTestCase:
|
|||
|
||||
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")
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def run(self):
|
||||
|
||||
# master branch
|
||||
|
@ -891,8 +1011,9 @@ class TDTestCase:
|
|||
# self.td4082()
|
||||
# self.td4288()
|
||||
# self.td4724()
|
||||
self.td5798()
|
||||
# self.td5798()
|
||||
# self.td5935()
|
||||
self.td6068()
|
||||
|
||||
# develop branch
|
||||
# self.td4097()
|
||||
|
|
|
@ -17,6 +17,7 @@ import os
|
|||
import taos
|
||||
import time
|
||||
import argparse
|
||||
import json
|
||||
|
||||
|
||||
class taosdemoQueryPerformace:
|
||||
|
@ -48,7 +49,7 @@ class taosdemoQueryPerformace:
|
|||
cursor2 = self.conn2.cursor()
|
||||
cursor2.execute("create database if not exists %s" % self.dbName)
|
||||
cursor2.execute("use %s" % self.dbName)
|
||||
cursor2.execute("create table if not exists %s(ts timestamp, query_time float, commit_id binary(50), branch binary(50), type binary(20)) tags(query_id int, query_sql binary(300))" % self.stbName)
|
||||
cursor2.execute("create table if not exists %s(ts timestamp, query_time_avg float, query_time_max float, query_time_min float, commit_id binary(50), branch binary(50), type binary(20)) tags(query_id int, query_sql binary(300))" % self.stbName)
|
||||
|
||||
sql = "select count(*) from test.meters"
|
||||
tableid = 1
|
||||
|
@ -74,7 +75,7 @@ class taosdemoQueryPerformace:
|
|||
tableid = 6
|
||||
cursor2.execute("create table if not exists %s%d using %s tags(%d, '%s')" % (self.tbPerfix, tableid, self.stbName, tableid, sql))
|
||||
|
||||
sql = "select * from meters"
|
||||
sql = "select * from meters limit 10000"
|
||||
tableid = 7
|
||||
cursor2.execute("create table if not exists %s%d using %s tags(%d, '%s')" % (self.tbPerfix, tableid, self.stbName, tableid, sql))
|
||||
|
||||
|
@ -87,37 +88,96 @@ class taosdemoQueryPerformace:
|
|||
cursor2.execute("create table if not exists %s%d using %s tags(%d, '%s')" % (self.tbPerfix, tableid, self.stbName, tableid, sql))
|
||||
|
||||
cursor2.close()
|
||||
|
||||
def generateQueryJson(self):
|
||||
|
||||
sqls = []
|
||||
cursor2 = self.conn2.cursor()
|
||||
cursor2.execute("select query_id, query_sql from %s.%s" % (self.dbName, self.stbName))
|
||||
i = 0
|
||||
for data in cursor2:
|
||||
sql = {
|
||||
"sql": data[1],
|
||||
"result_mode": "onlyformat",
|
||||
"result_file": "./query_sql_res%d.txt" % i
|
||||
}
|
||||
sqls.append(sql)
|
||||
i += 1
|
||||
|
||||
query_data = {
|
||||
"filetype": "query",
|
||||
"cfgdir": "/etc/perf",
|
||||
"host": "127.0.0.1",
|
||||
"port": 6030,
|
||||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"databases": "test",
|
||||
"specified_table_query": {
|
||||
"query_times": 100,
|
||||
"concurrent": 1,
|
||||
"sqls": sqls
|
||||
}
|
||||
}
|
||||
|
||||
query_json_file = f"/tmp/query.json"
|
||||
|
||||
with open(query_json_file, 'w') as f:
|
||||
json.dump(query_data, f)
|
||||
return query_json_file
|
||||
|
||||
def getBuildPath(self):
|
||||
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 ("taosdemo" in files):
|
||||
rootRealPath = os.path.dirname(os.path.realpath(root))
|
||||
if ("packaging" not in rootRealPath):
|
||||
buildPath = root[:len(root) - len("/build/bin")]
|
||||
break
|
||||
return buildPath
|
||||
|
||||
def getCMDOutput(self, cmd):
|
||||
cmd = os.popen(cmd)
|
||||
output = cmd.read()
|
||||
cmd.close()
|
||||
return output
|
||||
|
||||
def query(self):
|
||||
cursor = self.conn.cursor()
|
||||
buildPath = self.getBuildPath()
|
||||
if (buildPath == ""):
|
||||
print("taosdemo not found!")
|
||||
sys.exit(1)
|
||||
|
||||
binPath = buildPath + "/build/bin/"
|
||||
os.system(
|
||||
"%sperfMonitor -f %s > query_res.txt" %
|
||||
(binPath, self.generateQueryJson()))
|
||||
|
||||
cursor = self.conn2.cursor()
|
||||
print("==================== query performance ====================")
|
||||
|
||||
cursor.execute("use %s" % self.dbName)
|
||||
cursor.execute("select tbname, query_id, query_sql from %s" % self.stbName)
|
||||
cursor.execute("select tbname, query_sql from %s" % self.stbName)
|
||||
|
||||
i = 0
|
||||
for data in cursor:
|
||||
table_name = data[0]
|
||||
query_id = data[1]
|
||||
sql = data[2]
|
||||
|
||||
totalTime = 0
|
||||
cursor2 = self.conn.cursor()
|
||||
cursor2.execute("use test")
|
||||
for i in range(100):
|
||||
if(self.clearCache == True):
|
||||
# root permission is required
|
||||
os.system("echo 3 > /proc/sys/vm/drop_caches")
|
||||
|
||||
startTime = time.time()
|
||||
cursor2.execute(sql)
|
||||
totalTime += time.time() - startTime
|
||||
cursor2.close()
|
||||
print("query time for: %s %f seconds" % (sql, totalTime / 100))
|
||||
|
||||
cursor3 = self.conn2.cursor()
|
||||
cursor3.execute("insert into %s.%s values(now, %f, '%s', '%s', '%s')" % (self.dbName, table_name, totalTime / 100, self.commitID, self.branch, self.type))
|
||||
sql = data[1]
|
||||
|
||||
cursor3.close()
|
||||
self.avgDelay = self.getCMDOutput("grep 'avgDelay' query_res.txt | awk 'NR==%d{print $2}'" % (i + 1))
|
||||
self.maxDelay = self.getCMDOutput("grep 'avgDelay' query_res.txt | awk 'NR==%d{print $5}'" % (i + 1))
|
||||
self.minDelay = self.getCMDOutput("grep 'avgDelay' query_res.txt | awk 'NR==%d{print $8}'" % (i + 1))
|
||||
i += 1
|
||||
|
||||
print("query time for: %s %f seconds" % (sql, float(self.avgDelay)))
|
||||
c = self.conn2.cursor()
|
||||
c.execute("insert into %s.%s values(now, %f, %f, %f, '%s', '%s', '%s')" % (self.dbName, table_name, float(self.avgDelay), float(self.maxDelay), float(self.minDelay), self.commitID, self.branch, self.type))
|
||||
|
||||
c.close()
|
||||
cursor.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -174,4 +234,4 @@ if __name__ == '__main__':
|
|||
args = parser.parse_args()
|
||||
perftest = taosdemoQueryPerformace(args.remove_cache, args.commit_id, args.database_name, args.stable_name, args.table_perfix, args.git_branch, args.build_type)
|
||||
perftest.createPerfTables()
|
||||
perftest.query()
|
||||
perftest.query()
|
|
@ -49,24 +49,18 @@ class taosdemoPerformace:
|
|||
def generateJson(self):
|
||||
db = {
|
||||
"name": "%s" % self.insertDB,
|
||||
"drop": "yes",
|
||||
"replica": 1
|
||||
"drop": "yes"
|
||||
}
|
||||
|
||||
stb = {
|
||||
"name": "meters",
|
||||
"child_table_exists": "no",
|
||||
"childtable_count": self.numOfTables,
|
||||
"childtable_prefix": "stb_",
|
||||
"auto_create_table": "no",
|
||||
"data_source": "rand",
|
||||
"batch_create_tbl_num": 10,
|
||||
"insert_mode": "taosc",
|
||||
"insert_mode": "rand",
|
||||
"insert_rows": self.numOfRows,
|
||||
"interlace_rows": 0,
|
||||
"max_sql_len": 1024000,
|
||||
"disorder_ratio": 0,
|
||||
"disorder_range": 1000,
|
||||
"batch_rows": 1000000,
|
||||
"max_sql_len": 1048576,
|
||||
"timestamp_step": 1,
|
||||
"start_timestamp": "2020-10-01 00:00:00.000",
|
||||
"sample_format": "csv",
|
||||
|
@ -100,11 +94,8 @@ class taosdemoPerformace:
|
|||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"thread_count": 10,
|
||||
"thread_count_create_tbl": 10,
|
||||
"thread_count_create_tbl": 4,
|
||||
"result_file": "./insert_res.txt",
|
||||
"confirm_parameter_prompt": "no",
|
||||
"insert_interval": 0,
|
||||
"num_of_records_per_req": 30000,
|
||||
"databases": [db]
|
||||
}
|
||||
|
||||
|
@ -145,7 +136,7 @@ class taosdemoPerformace:
|
|||
binPath = buildPath + "/build/bin/"
|
||||
|
||||
os.system(
|
||||
"%staosdemo -f %s > /dev/null 2>&1" %
|
||||
"%sperfMonitor -f %s > /dev/null 2>&1" %
|
||||
(binPath, self.generateJson()))
|
||||
self.createTableTime = self.getCMDOutput(
|
||||
"grep 'Spent' insert_res.txt | awk 'NR==1{print $2}'")
|
||||
|
|
|
@ -60,7 +60,7 @@ class TDSimClient:
|
|||
self.cfgDict.update({option: value})
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
@ -320,7 +320,7 @@ class TDDnode:
|
|||
tdLog.exit(cmd)
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class TDSimClient:
|
|||
self.cfgDict.update({option: value})
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
@ -318,7 +318,7 @@ class TDDnode:
|
|||
tdLog.exit(cmd)
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class TDSimClient:
|
|||
self.cfgDict.update({option: value})
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
@ -318,7 +318,7 @@ class TDDnode:
|
|||
tdLog.exit(cmd)
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import platform
|
||||
import subprocess
|
||||
from time import sleep
|
||||
from util.log import *
|
||||
|
@ -58,7 +59,7 @@ class TDSimClient:
|
|||
self.cfgDict.update({option: value})
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
@ -243,7 +244,7 @@ class TDDnode:
|
|||
projPath = selfPath[:selfPath.find("tests")]
|
||||
|
||||
for root, dirs, files in os.walk(projPath):
|
||||
if ("taosd" in files):
|
||||
if (("taosd") in files):
|
||||
rootRealPath = os.path.dirname(os.path.realpath(root))
|
||||
if ("packaging" not in rootRealPath):
|
||||
buildPath = root[:len(root)-len("/build/bin")]
|
||||
|
@ -401,7 +402,7 @@ class TDDnode:
|
|||
tdLog.exit(cmd)
|
||||
|
||||
def cfg(self, option, value):
|
||||
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
|
||||
if os.system(cmd) != 0:
|
||||
tdLog.exit(cmd)
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ TARGET=exe
|
|||
LFLAGS = '-Wl,-rpath,/usr/local/taos/driver/' -ltaos -lpthread -lm -lrt
|
||||
CFLAGS = -O0 -g -Wall -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \
|
||||
-Wno-char-subscripts -D_REENTRANT -Wno-format -D_REENTRANT -DLINUX \
|
||||
-Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99
|
||||
-Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 \
|
||||
-fsanitize=address
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
@ -14,8 +15,10 @@ exe:
|
|||
gcc $(CFLAGS) ./batchprepare.c -o $(ROOT)batchprepare $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmtBatchTest.c -o $(ROOT)stmtBatchTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmtTest.c -o $(ROOT)stmtTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmt_function.c -o $(ROOT)stmt_function $(LFLAGS)
|
||||
|
||||
clean:
|
||||
rm $(ROOT)batchprepare
|
||||
rm $(ROOT)stmtBatchTest
|
||||
rm $(ROOT)stmtTest
|
||||
rm $(ROOT)stmt_function
|
||||
|
|
|
@ -0,0 +1,502 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "taos.h"
|
||||
#include <sys/time.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
void execute_simple_sql(void *taos, char *sql) {
|
||||
TAOS_RES *result = taos_query(taos, sql);
|
||||
if ( result == NULL || taos_errno(result) != 0) {
|
||||
printf( "failed to %s, Reason: %s\n" , sql, taos_errstr(result));
|
||||
taos_free_result(result);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
void print_result(TAOS_RES* res) {
|
||||
if (res == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
TAOS_ROW row = NULL;
|
||||
int num_fields = taos_num_fields(res);
|
||||
TAOS_FIELD* fields = taos_fetch_fields(res);
|
||||
while ((row = taos_fetch_row(res))) {
|
||||
char temp[256] = {0};
|
||||
taos_print_row(temp, row, fields, num_fields);
|
||||
printf("get result: %s\n", temp);
|
||||
}
|
||||
}
|
||||
|
||||
void taos_stmt_init_test() {
|
||||
printf("start taos_stmt_init test \n");
|
||||
void *taos = NULL;
|
||||
TAOS_STMT *stmt = NULL;
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt == NULL);
|
||||
// ASM ERROR
|
||||
// assert(taos_stmt_close(stmt) != 0);
|
||||
taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
printf("finish taos_stmt_init test\n");
|
||||
}
|
||||
void taos_stmt_preprare_test() {
|
||||
printf("start taos_stmt_prepare test\n");
|
||||
char *stmt_sql = calloc(1, 1048576);
|
||||
TAOS_STMT *stmt = NULL;
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) != 0);
|
||||
void *taos = NULL;
|
||||
taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create table super(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 tinyint, c8 bool, c9 nchar(8), c10 timestamp) tags (t1 int, t2 bigint, t3 float, t4 double, t5 binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8))");
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
// below will make client dead lock
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
|
||||
// assert(taos_stmt_close(stmt) == 0);
|
||||
// stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
sprintf(stmt_sql, "select from ?");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) != 0);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?,?,?,?,?,?,?,?,?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
sprintf(stmt_sql, "insert into super values (?,?,?,?,?,?,?,?,?,?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) != 0);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?,?,?,?,?,?,?,1,?,?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
|
||||
free(stmt_sql);
|
||||
printf("finish taos_stmt_prepare test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_set_tbname_test() {
|
||||
printf("start taos_stmt_set_tbname test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
char *name = calloc(1, 200);
|
||||
// ASM ERROR
|
||||
// assert(taos_stmt_set_tbname(stmt, name) != 0);
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create table super(ts timestamp, c1 int)");
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
assert(taos_stmt_set_tbname(stmt, name) != 0);
|
||||
char* stmt_sql = calloc(1, 1000);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
sprintf(name, "super");
|
||||
assert(stmt != NULL);
|
||||
assert(taos_stmt_set_tbname(stmt, name) == 0);
|
||||
free(name);
|
||||
free(stmt_sql);
|
||||
taos_stmt_close(stmt);
|
||||
printf("finish taos_stmt_set_tbname test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_set_tbname_tags_test() {
|
||||
printf("start taos_stmt_set_tbname_tags test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
char *name = calloc(1,20);
|
||||
TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND));
|
||||
// ASM ERROR
|
||||
// assert(taos_stmt_set_tbname_tags(stmt, name, tags) != 0);
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create stable super(ts timestamp, c1 int) tags (id int)");
|
||||
execute_simple_sql(taos, "create table tb using super tags (1)");
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
char* stmt_sql = calloc(1, 1000);
|
||||
sprintf(stmt_sql, "insert into ? using super tags (?) values (?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_set_tbname_tags(stmt, name, tags) != 0);
|
||||
sprintf(name, "tb");
|
||||
assert(taos_stmt_set_tbname_tags(stmt, name, tags) != 0);
|
||||
int t = 1;
|
||||
tags->buffer_length = TSDB_DATA_TYPE_INT;
|
||||
tags->buffer_length = sizeof(uint32_t);
|
||||
tags->buffer = &t;
|
||||
tags->length = &tags->buffer_length;
|
||||
tags->is_null = NULL;
|
||||
assert(taos_stmt_set_tbname_tags(stmt, name, tags) == 0);
|
||||
free(stmt_sql);
|
||||
free(name);
|
||||
free(tags);
|
||||
taos_stmt_close(stmt);
|
||||
printf("finish taos_stmt_set_tbname_tags test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_set_sub_tbname_test() {
|
||||
printf("start taos_stmt_set_sub_tbname test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
char *name = calloc(1, 200);
|
||||
// ASM ERROR
|
||||
// assert(taos_stmt_set_sub_tbname(stmt, name) != 0);
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create stable super(ts timestamp, c1 int) tags (id int)");
|
||||
execute_simple_sql(taos, "create table tb using super tags (1)");
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
char* stmt_sql = calloc(1, 1000);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_set_sub_tbname(stmt, name) != 0);
|
||||
sprintf(name, "tb");
|
||||
assert(taos_stmt_set_sub_tbname(stmt, name) == 0);
|
||||
// assert(taos_load_table_info(taos, "super, tb") == 0);
|
||||
// assert(taos_stmt_set_sub_tbname(stmt, name) == 0);
|
||||
free(name);
|
||||
free(stmt_sql);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
printf("finish taos_stmt_set_sub_tbname test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_bind_param_test() {
|
||||
printf("start taos_stmt_bind_param test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
TAOS_BIND *binds = NULL;
|
||||
assert(taos_stmt_bind_param(stmt, binds) != 0);
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create table super(ts timestamp, c1 int)");
|
||||
stmt = taos_stmt_init(taos);
|
||||
char* stmt_sql = calloc(1, 1000);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_bind_param(stmt, binds) != 0);
|
||||
free(binds);
|
||||
TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND));
|
||||
int64_t ts = (int64_t)1591060628000;
|
||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
params[0].buffer_length = sizeof(uint64_t);
|
||||
params[0].buffer = &ts;
|
||||
params[0].length = ¶ms[0].buffer_length;
|
||||
params[0].is_null = NULL;
|
||||
int32_t i = (int32_t)21474;
|
||||
params[1].buffer_type = TSDB_DATA_TYPE_INT;
|
||||
params[1].buffer_length = sizeof(int32_t);
|
||||
params[1].buffer = &i;
|
||||
params[1].length = ¶ms[1].buffer_length;
|
||||
params[1].is_null = NULL;
|
||||
assert(taos_stmt_bind_param(stmt, params) != 0);
|
||||
assert(taos_stmt_set_tbname(stmt, "super") == 0);
|
||||
assert(taos_stmt_bind_param(stmt, params) == 0);
|
||||
free(params);
|
||||
free(stmt_sql);
|
||||
taos_stmt_close(stmt);
|
||||
printf("finish taos_stmt_bind_param test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_bind_single_param_batch_test() {
|
||||
printf("start taos_stmt_bind_single_param_batch test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
TAOS_MULTI_BIND *bind = NULL;
|
||||
assert(taos_stmt_bind_single_param_batch(stmt, bind, 0) != 0);
|
||||
printf("finish taos_stmt_bind_single_param_batch test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_bind_param_batch_test() {
|
||||
printf("start taos_stmt_bind_param_batch test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
TAOS_MULTI_BIND *bind = NULL;
|
||||
assert(taos_stmt_bind_param_batch(stmt, bind) != 0);
|
||||
printf("finish taos_stmt_bind_param_batch test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_add_batch_test() {
|
||||
printf("start taos_stmt_add_batch test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
assert(taos_stmt_add_batch(stmt) != 0);
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create table super(ts timestamp, c1 int)");
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
char* stmt_sql = calloc(1, 1000);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_add_batch(stmt) != 0);
|
||||
TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND));
|
||||
int64_t ts = (int64_t)1591060628000;
|
||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
params[0].buffer_length = sizeof(uint64_t);
|
||||
params[0].buffer = &ts;
|
||||
params[0].length = ¶ms[0].buffer_length;
|
||||
params[0].is_null = NULL;
|
||||
int32_t i = (int32_t)21474;
|
||||
params[1].buffer_type = TSDB_DATA_TYPE_INT;
|
||||
params[1].buffer_length = sizeof(int32_t);
|
||||
params[1].buffer = &i;
|
||||
params[1].length = ¶ms[1].buffer_length;
|
||||
params[1].is_null = NULL;
|
||||
assert(taos_stmt_set_tbname(stmt, "super") == 0);
|
||||
assert(taos_stmt_bind_param(stmt, params) == 0);
|
||||
assert(taos_stmt_add_batch(stmt) == 0);
|
||||
free(params);
|
||||
free(stmt_sql);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
printf("finish taos_stmt_add_batch test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_execute_test() {
|
||||
printf("start taos_stmt_execute test\n");
|
||||
TAOS_STMT *stmt = NULL;
|
||||
assert(taos_stmt_execute(stmt) != 0);
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create table super(ts timestamp, c1 int)");
|
||||
stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
assert(taos_stmt_execute(stmt) != 0);
|
||||
char* stmt_sql = calloc(1, 1000);
|
||||
sprintf(stmt_sql, "insert into ? values (?,?)");
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
assert(taos_stmt_execute(stmt) != 0);
|
||||
TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND));
|
||||
int64_t ts = (int64_t)1591060628000;
|
||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
params[0].buffer_length = sizeof(uint64_t);
|
||||
params[0].buffer = &ts;
|
||||
params[0].length = ¶ms[0].buffer_length;
|
||||
params[0].is_null = NULL;
|
||||
int32_t i = (int32_t)21474;
|
||||
params[1].buffer_type = TSDB_DATA_TYPE_INT;
|
||||
params[1].buffer_length = sizeof(int32_t);
|
||||
params[1].buffer = &i;
|
||||
params[1].length = ¶ms[1].buffer_length;
|
||||
params[1].is_null = NULL;
|
||||
assert(taos_stmt_set_tbname(stmt, "super") == 0);
|
||||
assert(taos_stmt_execute(stmt) != 0);
|
||||
assert(taos_stmt_bind_param(stmt, params) == 0);
|
||||
assert(taos_stmt_execute(stmt) != 0);
|
||||
assert(taos_stmt_add_batch(stmt) == 0);
|
||||
assert(taos_stmt_execute(stmt) == 0);
|
||||
free(params);
|
||||
free(stmt_sql);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
printf("finish taos_stmt_execute test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_use_result_query(void *taos, char *col, int type) {
|
||||
TAOS_STMT *stmt = taos_stmt_init(taos);
|
||||
assert(stmt != NULL);
|
||||
char *stmt_sql = calloc(1, 1024);
|
||||
struct {
|
||||
int64_t c1;
|
||||
int32_t c2;
|
||||
int64_t c3;
|
||||
float c4;
|
||||
double c5;
|
||||
char c6[8];
|
||||
int16_t c7;
|
||||
int8_t c8;
|
||||
int8_t c9;
|
||||
char c10[32];
|
||||
} v = {0};
|
||||
v.c1 = (int64_t)1591060628000;
|
||||
v.c2 = (int32_t)1;
|
||||
v.c3 = (int64_t)1;
|
||||
v.c4 = (float)1;
|
||||
v.c5 = (double)1;
|
||||
strcpy(v.c6, "abcdefgh");
|
||||
v.c7 = 1;
|
||||
v.c8 = 1;
|
||||
v.c9 = 1;
|
||||
strcpy(v.c10, "一二三四五六七八");
|
||||
uintptr_t c10len=strlen(v.c10);
|
||||
sprintf(stmt_sql, "select * from stmt_test.t1 where %s = ?", col);
|
||||
printf("stmt_sql: %s\n", stmt_sql);
|
||||
assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0);
|
||||
TAOS_BIND *params = calloc(1, sizeof(TAOS_BIND));
|
||||
params->buffer_type = type;
|
||||
params->is_null = NULL;
|
||||
switch(type){
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
params->buffer_length = sizeof(v.c1);
|
||||
params->buffer = &v.c1;
|
||||
params->length = ¶ms->buffer_length;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
params->buffer_length = sizeof(v.c2);
|
||||
params->buffer = &v.c2;
|
||||
params->length = ¶ms->buffer_length;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
params->buffer_length = sizeof(v.c3);
|
||||
params->buffer = &v.c3;
|
||||
params->length = ¶ms->buffer_length;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
params->buffer_length = sizeof(v.c4);
|
||||
params->buffer = &v.c4;
|
||||
params->length = ¶ms->buffer_length;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
params->buffer_length = sizeof(v.c5);
|
||||
params->buffer = &v.c5;
|
||||
params->length = ¶ms->buffer_length;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
params->buffer_length = sizeof(v.c6);
|
||||
params->buffer = &v.c6;
|
||||
params->length = ¶ms->buffer_length;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
params->buffer_length = sizeof(v.c7);
|
||||
params->buffer = &v.c7;
|
||||
params->length = ¶ms->buffer_length;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
params->buffer_length = sizeof(v.c8);
|
||||
params->buffer = &v.c8;
|
||||
params->length = ¶ms->buffer_length;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
params->buffer_length = sizeof(v.c9);
|
||||
params->buffer = &v.c9;
|
||||
params->length = ¶ms->buffer_length;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
params->buffer_length = sizeof(v.c10);
|
||||
params->buffer = &v.c10;
|
||||
params->length = &c10len;
|
||||
break;
|
||||
default:
|
||||
printf("Cannnot find type: %d\n", type);
|
||||
break;
|
||||
|
||||
}
|
||||
assert(taos_stmt_bind_param(stmt, params) == 0);
|
||||
assert(taos_stmt_execute(stmt) == 0);
|
||||
TAOS_RES* result = taos_stmt_use_result(stmt);
|
||||
assert(result != NULL);
|
||||
print_result(result);
|
||||
assert(taos_stmt_close(stmt) == 0);
|
||||
free(params);
|
||||
free(stmt_sql);
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
void taos_stmt_use_result_test() {
|
||||
printf("start taos_stmt_use_result test\n");
|
||||
void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0);
|
||||
if(taos == NULL) {
|
||||
printf("Cannot connect to tdengine server\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execute_simple_sql(taos, "drop database if exists stmt_test");
|
||||
execute_simple_sql(taos, "create database stmt_test");
|
||||
execute_simple_sql(taos, "use stmt_test");
|
||||
execute_simple_sql(taos, "create table super(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 tinyint, c8 bool, c9 nchar(8), c10 timestamp) tags (t1 int, t2 bigint, t3 float, t4 double, t5 binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8))");
|
||||
execute_simple_sql(taos, "create table t1 using super tags (1, 1, 1, 1, 'abcdefgh',1,1,1,'一二三四五六七八')");
|
||||
execute_simple_sql(taos, "insert into t1 values (1591060628000, 1, 1, 1, 1, 'abcdefgh',1,1,1,'一二三四五六七八', now)");
|
||||
execute_simple_sql(taos, "insert into t1 values (1591060628001, 1, 1, 1, 1, 'abcdefgh',1,1,1,'一二三四五六七八', now)");
|
||||
|
||||
taos_stmt_use_result_query(taos, "c1", TSDB_DATA_TYPE_INT);
|
||||
taos_stmt_use_result_query(taos, "c2", TSDB_DATA_TYPE_BIGINT);
|
||||
taos_stmt_use_result_query(taos, "c3", TSDB_DATA_TYPE_FLOAT);
|
||||
taos_stmt_use_result_query(taos, "c4", TSDB_DATA_TYPE_DOUBLE);
|
||||
taos_stmt_use_result_query(taos, "c5", TSDB_DATA_TYPE_BINARY);
|
||||
taos_stmt_use_result_query(taos, "c6", TSDB_DATA_TYPE_SMALLINT);
|
||||
taos_stmt_use_result_query(taos, "c7", TSDB_DATA_TYPE_TINYINT);
|
||||
taos_stmt_use_result_query(taos, "c8", TSDB_DATA_TYPE_BOOL);
|
||||
taos_stmt_use_result_query(taos, "c9", TSDB_DATA_TYPE_NCHAR);
|
||||
|
||||
printf("finish taos_stmt_use_result test\n");
|
||||
}
|
||||
|
||||
void taos_stmt_close_test() {
|
||||
printf("start taos_stmt_close test\n");
|
||||
// ASM ERROR
|
||||
// TAOS_STMT *stmt = NULL;
|
||||
// assert(taos_stmt_close(stmt) != 0);
|
||||
printf("finish taos_stmt_close test\n");
|
||||
}
|
||||
|
||||
void test_api_reliability() {
|
||||
// ASM catch memory leak
|
||||
taos_stmt_init_test();
|
||||
taos_stmt_preprare_test();
|
||||
taos_stmt_set_tbname_test();
|
||||
taos_stmt_set_tbname_tags_test();
|
||||
taos_stmt_set_sub_tbname_test();
|
||||
taos_stmt_bind_param_test();
|
||||
taos_stmt_bind_single_param_batch_test();
|
||||
taos_stmt_bind_param_batch_test();
|
||||
taos_stmt_add_batch_test();
|
||||
taos_stmt_execute_test();
|
||||
taos_stmt_close_test();
|
||||
}
|
||||
|
||||
void test_query() {
|
||||
taos_stmt_use_result_test();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_api_reliability();
|
||||
test_query();
|
||||
return 0;
|
||||
}
|
|
@ -221,3 +221,4 @@ run general/stream/table_replica1_vnoden.sim
|
|||
run general/stream/metrics_replica1_vnoden.sim
|
||||
run general/db/show_create_db.sim
|
||||
run general/db/show_create_table.sim
|
||||
run general/parser/like.sim
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/cfg.sh -n dnode1 -c walLevel -v 1
|
||||
system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
|
||||
sleep 10
|
||||
sql connect
|
||||
print ======================== dnode1 start
|
||||
|
||||
|
||||
$db = testdb
|
||||
sql drop database if exists $db
|
||||
sql create database $db cachelast 2
|
||||
sql use $db
|
||||
|
||||
$table1 = table_name
|
||||
$table2 = tablexname
|
||||
|
||||
sql create table $table1 (ts timestamp, b binary(20))
|
||||
sql create table $table2 (ts timestamp, b binary(20))
|
||||
|
||||
sql insert into $table1 values(now, "table_name")
|
||||
sql insert into $table1 values(now-1m, "tablexname")
|
||||
sql insert into $table1 values(now-2m, "tablexxx")
|
||||
sql insert into $table1 values(now-2m, "table")
|
||||
|
||||
sql select b from $table1
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select b from $table1 where b like 'table_name'
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
sql select b from $table1 where b like 'table\_name'
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql show tables;
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql show tables like 'table_name'
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql show tables like 'table\_name'
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
|
||||
|
Loading…
Reference in New Issue