Merge from master
This commit is contained in:
commit
aff4adf71c
|
@ -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 设计中包含专门针对大量数据源的优化,包括数据的写入和查询,尤其适合高效处理海量(千万或者更多量级)的数据源。|
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -643,7 +643,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;
|
||||
|
@ -5103,10 +5108,6 @@ static void cleanQueryExpr(SCondExpr* pCondExpr) {
|
|||
tSqlExprDestroy(pCondExpr->pTableCond);
|
||||
}
|
||||
|
||||
if (pCondExpr->pTagCond) {
|
||||
tSqlExprDestroy(pCondExpr->pTagCond);
|
||||
}
|
||||
|
||||
if (pCondExpr->pColumnCond) {
|
||||
tSqlExprDestroy(pCondExpr->pColumnCond);
|
||||
}
|
||||
|
|
|
@ -337,16 +337,189 @@ int tscSendMsgToServer(SSqlObj *pSql) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
|
||||
SRpcMsg* rpcMsg = pSchedMsg->ahandle;
|
||||
SRpcEpSet* pEpSet = pSchedMsg->thandle;
|
||||
//static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
|
||||
// SRpcMsg* rpcMsg = pSchedMsg->ahandle;
|
||||
// SRpcEpSet* pEpSet = pSchedMsg->thandle;
|
||||
//
|
||||
// TSDB_CACHE_PTR_TYPE handle = (TSDB_CACHE_PTR_TYPE) rpcMsg->ahandle;
|
||||
// SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, handle);
|
||||
// if (pSql == NULL) {
|
||||
// rpcFreeCont(rpcMsg->pCont);
|
||||
// free(rpcMsg);
|
||||
// free(pEpSet);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// assert(pSql->self == handle);
|
||||
//
|
||||
// STscObj *pObj = pSql->pTscObj;
|
||||
// SSqlRes *pRes = &pSql->res;
|
||||
// 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);
|
||||
//
|
||||
// taosRemoveRef(tscObjRef, handle);
|
||||
// taosReleaseRef(tscObjRef, handle);
|
||||
// rpcFreeCont(rpcMsg->pCont);
|
||||
// free(rpcMsg);
|
||||
// free(pEpSet);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd);
|
||||
// if (pQueryInfo != NULL && pQueryInfo->type == TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
// tscDebug("0x%"PRIx64" sqlObj needs to be released or DB connection is closed, cmd:%d type:%d, pObj:%p signature:%p",
|
||||
// pSql->self, pCmd->command, pQueryInfo->type, pObj, pObj->signature);
|
||||
//
|
||||
// taosRemoveRef(tscObjRef, handle);
|
||||
// taosReleaseRef(tscObjRef, handle);
|
||||
// rpcFreeCont(rpcMsg->pCont);
|
||||
// free(rpcMsg);
|
||||
// free(pEpSet);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (pEpSet) {
|
||||
// if (!tscEpSetIsEqual(&pSql->epSet, pEpSet)) {
|
||||
// if (pCmd->command < TSDB_SQL_MGMT) {
|
||||
// tscUpdateVgroupInfo(pSql, pEpSet);
|
||||
// } else {
|
||||
// tscUpdateMgmtEpSet(pSql, pEpSet);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int32_t cmd = pCmd->command;
|
||||
//
|
||||
// // set the flag to denote that sql string needs to be re-parsed and build submit block with table schema
|
||||
// if (cmd == TSDB_SQL_INSERT && rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||
// pSql->cmd.insertParam.schemaAttached = 1;
|
||||
// }
|
||||
//
|
||||
// // single table query error need to be handled here.
|
||||
// if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAGS_VAL) &&
|
||||
// (((rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID)) ||
|
||||
// rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_APP_NOT_READY)) {
|
||||
//
|
||||
// // 1. super table subquery
|
||||
// // 2. nest queries are all not updated the tablemeta and retry parse the sql after cleanup local tablemeta/vgroup id buffer
|
||||
// if ((TSDB_QUERY_HAS_TYPE(pQueryInfo->type, (TSDB_QUERY_TYPE_STABLE_SUBQUERY | TSDB_QUERY_TYPE_SUBQUERY |
|
||||
// TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) &&
|
||||
// !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_PROJECTION_QUERY)) ||
|
||||
// (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_NEST_SUBQUERY)) || (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_SUBQUERY) && pQueryInfo->distinct)) {
|
||||
// // do nothing in case of super table subquery
|
||||
// } else {
|
||||
// pSql->retry += 1;
|
||||
// tscWarn("0x%" PRIx64 " it shall renew table meta, code:%s, retry:%d", pSql->self, tstrerror(rpcMsg->code), pSql->retry);
|
||||
//
|
||||
// pSql->res.code = rpcMsg->code; // keep the previous error code
|
||||
// if (pSql->retry > pSql->maxRetry) {
|
||||
// tscError("0x%" PRIx64 " max retry %d reached, give up", pSql->self, pSql->maxRetry);
|
||||
// } else {
|
||||
// // wait for a little bit moment and then retry
|
||||
// // todo do not sleep in rpc callback thread, add this process into queue to process
|
||||
// if (rpcMsg->code == TSDB_CODE_APP_NOT_READY || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) {
|
||||
// int32_t duration = getWaitingTimeInterval(pSql->retry);
|
||||
// taosMsleep(duration);
|
||||
// }
|
||||
//
|
||||
// pSql->retryReason = rpcMsg->code;
|
||||
// rpcMsg->code = tscRenewTableMeta(pSql, 0);
|
||||
// // if there is an error occurring, proceed to the following error handling procedure.
|
||||
// if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
// taosReleaseRef(tscObjRef, handle);
|
||||
// rpcFreeCont(rpcMsg->pCont);
|
||||
// free(rpcMsg);
|
||||
// free(pEpSet);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pRes->rspLen = 0;
|
||||
//
|
||||
// if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) {
|
||||
// tscDebug("0x%"PRIx64" query is cancelled, code:%s", pSql->self, tstrerror(pRes->code));
|
||||
// } else {
|
||||
// pRes->code = rpcMsg->code;
|
||||
// }
|
||||
//
|
||||
// if (pRes->code == TSDB_CODE_SUCCESS) {
|
||||
// tscDebug("0x%"PRIx64" reset retry counter to be 0 due to success rsp, old:%d", pSql->self, pSql->retry);
|
||||
// pSql->retry = 0;
|
||||
// }
|
||||
//
|
||||
// if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) {
|
||||
// assert(rpcMsg->msgType == pCmd->msgType + 1);
|
||||
// pRes->code = rpcMsg->code;
|
||||
// pRes->rspType = rpcMsg->msgType;
|
||||
// pRes->rspLen = rpcMsg->contLen;
|
||||
//
|
||||
// if (pRes->rspLen > 0 && rpcMsg->pCont) {
|
||||
// char *tmp = (char *)realloc(pRes->pRsp, pRes->rspLen);
|
||||
// if (tmp == NULL) {
|
||||
// pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
// } else {
|
||||
// pRes->pRsp = tmp;
|
||||
// memcpy(pRes->pRsp, rpcMsg->pCont, pRes->rspLen);
|
||||
// }
|
||||
// } else {
|
||||
// tfree(pRes->pRsp);
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * There is not response callback function for submit response.
|
||||
// * The actual inserted number of points is the first number.
|
||||
// */
|
||||
// if (rpcMsg->msgType == TSDB_MSG_TYPE_SUBMIT_RSP && pRes->pRsp != NULL) {
|
||||
// SShellSubmitRspMsg *pMsg = (SShellSubmitRspMsg*)pRes->pRsp;
|
||||
// pMsg->code = htonl(pMsg->code);
|
||||
// pMsg->numOfRows = htonl(pMsg->numOfRows);
|
||||
// pMsg->affectedRows = htonl(pMsg->affectedRows);
|
||||
// pMsg->failedRows = htonl(pMsg->failedRows);
|
||||
// pMsg->numOfFailedBlocks = htonl(pMsg->numOfFailedBlocks);
|
||||
//
|
||||
// pRes->numOfRows += pMsg->affectedRows;
|
||||
// tscDebug("0x%"PRIx64" SQL cmd:%s, code:%s inserted rows:%d rspLen:%d", pSql->self, sqlCmd[pCmd->command],
|
||||
// tstrerror(pRes->code), pMsg->affectedRows, pRes->rspLen);
|
||||
// } else {
|
||||
// tscDebug("0x%"PRIx64" SQL cmd:%s, code:%s rspLen:%d", pSql->self, sqlCmd[pCmd->command], tstrerror(pRes->code), pRes->rspLen);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) {
|
||||
// rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql);
|
||||
// }
|
||||
//
|
||||
// bool shouldFree = tscShouldBeFreed(pSql);
|
||||
// if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
// if (rpcMsg->code != TSDB_CODE_SUCCESS) {
|
||||
// pRes->code = rpcMsg->code;
|
||||
// }
|
||||
// rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? (int32_t)pRes->numOfRows : pRes->code;
|
||||
// (*pSql->fp)(pSql->param, pSql, rpcMsg->code);
|
||||
// }
|
||||
//
|
||||
// if (shouldFree) { // in case of table-meta/vgrouplist query, automatically free it
|
||||
// tscDebug("0x%"PRIx64" sqlObj is automatically freed", pSql->self);
|
||||
// taosRemoveRef(tscObjRef, handle);
|
||||
// }
|
||||
//
|
||||
// taosReleaseRef(tscObjRef, handle);
|
||||
// rpcFreeCont(rpcMsg->pCont);
|
||||
// free(rpcMsg);
|
||||
// free(pEpSet);
|
||||
//}
|
||||
|
||||
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
||||
TSDB_CACHE_PTR_TYPE handle = (TSDB_CACHE_PTR_TYPE) rpcMsg->ahandle;
|
||||
SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, handle);
|
||||
if (pSql == NULL) {
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
free(rpcMsg);
|
||||
free(pEpSet);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -357,15 +530,12 @@ static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
|
|||
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);
|
||||
|
||||
taosRemoveRef(tscObjRef, handle);
|
||||
taosReleaseRef(tscObjRef, handle);
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
free(rpcMsg);
|
||||
free(pEpSet);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -377,8 +547,6 @@ static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
|
|||
taosRemoveRef(tscObjRef, handle);
|
||||
taosReleaseRef(tscObjRef, handle);
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
free(rpcMsg);
|
||||
free(pEpSet);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -432,8 +600,6 @@ static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
|
|||
if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, handle);
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
free(rpcMsg);
|
||||
free(pEpSet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -532,6 +698,7 @@ static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
|
|||
|
||||
taosReleaseRef(tscObjRef, handle);
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
<<<<<<< HEAD
|
||||
free(rpcMsg);
|
||||
free(pEpSet);
|
||||
}
|
||||
|
@ -561,6 +728,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
if (et - st > 100) {
|
||||
tscDebug("add message to task queue, elapsed time:%"PRId64, et - st);
|
||||
}
|
||||
=======
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
int doBuildAndSendMsg(SSqlObj *pSql) {
|
||||
|
@ -733,8 +902,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,
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -3887,6 +3887,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;
|
||||
}
|
||||
|
@ -3966,6 +3968,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;
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -3328,8 +3328,7 @@ static void* createTable(void *sarg)
|
|||
}
|
||||
|
||||
len = 0;
|
||||
if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer,
|
||||
NO_INSERT_TYPE, false)) {
|
||||
if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, NO_INSERT_TYPE, false)) {
|
||||
errorPrint2("queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer);
|
||||
free(pThreadInfo->buffer);
|
||||
return NULL;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -604,6 +604,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);
|
||||
|
||||
|
|
|
@ -3638,12 +3638,43 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
|
|||
|
||||
// re-estabilish output buffer pointer.
|
||||
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 copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||
bool needCopyTs = false;
|
||||
int32_t tsNum = 0;
|
||||
char *src = NULL;
|
||||
for (int32_t i = 0; i < numOfOutput; i++) {
|
||||
int32_t functionId = pCtx[i].functionId;
|
||||
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
|
||||
needCopyTs = true;
|
||||
if (i > 0 && pCtx[i-1].functionId == TSDB_FUNC_TS_DUMMY){
|
||||
SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data
|
||||
src = pColRes->pData;
|
||||
}
|
||||
}else if(functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
tsNum++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!needCopyTs) return;
|
||||
if (tsNum < 2) return;
|
||||
if (src == NULL) return;
|
||||
|
||||
for (int32_t i = 0; i < numOfOutput; i++) {
|
||||
int32_t functionId = pCtx[i].functionId;
|
||||
if(functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i);
|
||||
memcpy(pColRes->pData, src, pColRes->info.bytes * pRes->info.rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity) {
|
||||
SSDataBlock* pDataBlock = pBInfo->pRes;
|
||||
|
||||
|
@ -7482,12 +7513,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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue