提交 036695d4 编写于 作者: weixin_48148422's avatar weixin_48148422

TD-153: make whole project compile

上级 241f7a22
...@@ -25,6 +25,7 @@ extern "C" { ...@@ -25,6 +25,7 @@ extern "C" {
*/ */
#include "os.h" #include "os.h"
#include "tbuffer.h" #include "tbuffer.h"
#include "exception.h"
#include "qextbuffer.h" #include "qextbuffer.h"
#include "taosdef.h" #include "taosdef.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
...@@ -177,7 +178,7 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId); ...@@ -177,7 +178,7 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId);
// get starter position of metric query condition (query on tags) in SSqlCmd.payload // get starter position of metric query condition (query on tags) in SSqlCmd.payload
SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid); SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid);
void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBuffer* pBuf); void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw);
void tscTagCondCopy(STagCond* dest, const STagCond* src); void tscTagCondCopy(STagCond* dest, const STagCond* src);
void tscTagCondRelease(STagCond* pCond); void tscTagCondRelease(STagCond* pCond);
......
...@@ -1185,10 +1185,18 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1185,10 +1185,18 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
return invalidSqlErrMsg(pQueryInfo->msg, "invalid arithmetic expression in select clause"); return invalidSqlErrMsg(pQueryInfo->msg, "invalid arithmetic expression in select clause");
} }
SBuffer buf = exprTreeToBinary(pNode); SBufferWriter bw = tbufInitWriter(NULL, false);
TRY(0) {
exprTreeToBinary(&bw, pNode);
} CATCH(code) {
tbufCloseWriter(&bw);
UNUSED(code);
// TODO: other error handling
} END_TRY
size_t len = tbufTell(&buf); size_t len = tbufTell(&bw);
char* c = tbufGetData(&buf, true); char* c = tbufGetData(&bw, true);
// set the serialized binary string as the parameter of arithmetic expression // set the serialized binary string as the parameter of arithmetic expression
addExprParams(pExpr, c, TSDB_DATA_TYPE_BINARY, len, index.tableIndex); addExprParams(pExpr, c, TSDB_DATA_TYPE_BINARY, len, index.tableIndex);
...@@ -3751,7 +3759,15 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, ...@@ -3751,7 +3759,15 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
SArray* colList = taosArrayInit(10, sizeof(SColIndex)); SArray* colList = taosArrayInit(10, sizeof(SColIndex));
ret = exprTreeFromSqlExpr(&p, p1, NULL, pQueryInfo, colList); ret = exprTreeFromSqlExpr(&p, p1, NULL, pQueryInfo, colList);
SBuffer buf = exprTreeToBinary(p); SBufferWriter bw = tbufInitWriter(NULL, false);
TRY(0) {
exprTreeToBinary(&bw, p);
} CATCH(code) {
tbufCloseWriter(&bw);
UNUSED(code);
// TODO: more error handling
} END_TRY
// add to source column list // add to source column list
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i);
...@@ -3765,7 +3781,7 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, ...@@ -3765,7 +3781,7 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
addRequiredTagColumn(pTableMetaInfo, &index); addRequiredTagColumn(pTableMetaInfo, &index);
} }
tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &buf); tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw);
doCompactQueryExpr(pExpr); doCompactQueryExpr(pExpr);
tSQLExprDestroy(p1); tSQLExprDestroy(p1);
......
...@@ -47,18 +47,18 @@ SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) { ...@@ -47,18 +47,18 @@ SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) {
return NULL; return NULL;
} }
void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBuffer* pBuf) { void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw) {
if (tbufTell(pBuf) == 0) { if (tbufTell(bw) == 0) {
return; return;
} }
SCond cond = { SCond cond = {
.uid = uid, .uid = uid,
.len = tbufTell(pBuf), .len = tbufTell(bw),
.cond = NULL, .cond = NULL,
}; };
cond.cond = tbufGetData(pBuf, true); cond.cond = tbufGetData(bw, true);
if (pTagCond->pCond == NULL) { if (pTagCond->pCond == NULL) {
pTagCond->pCond = taosArrayInit(3, sizeof(SCond)); pTagCond->pCond = taosArrayInit(3, sizeof(SCond));
......
...@@ -90,9 +90,10 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res); ...@@ -90,9 +90,10 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res);
uint8_t getBinaryExprOptr(SSQLToken *pToken); uint8_t getBinaryExprOptr(SSQLToken *pToken);
SBuffer exprTreeToBinary(tExprNode* pExprTree); void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
tExprNode* exprTreeFromBinary(const void* pBuf, size_t size); tExprNode* exprTreeFromBinary(const void* data, size_t size);
tExprNode* exprTreeFromTableName(const char* tbnameCond); tExprNode* exprTreeFromTableName(const char* tbnameCond);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "tskiplist.h" #include "tskiplist.h"
#include "queryLog.h" #include "queryLog.h"
#include "tsdbMain.h" #include "tsdbMain.h"
#include "exception.h"
/* /*
* *
...@@ -44,7 +45,6 @@ ...@@ -44,7 +45,6 @@
* *
*/ */
static tExprNode *tExprNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken); static tExprNode *tExprNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken);
static void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i); static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i);
static void destroySyntaxTree(tExprNode *); static void destroySyntaxTree(tExprNode *);
...@@ -428,7 +428,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len) { ...@@ -428,7 +428,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len) {
static void UNUSED_FUNC destroySyntaxTree(tExprNode *pNode) { tExprNodeDestroy(pNode, NULL); } static void UNUSED_FUNC destroySyntaxTree(tExprNode *pNode) { tExprNodeDestroy(pNode, NULL); }
static void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) { void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) {
if (pNode == NULL) { if (pNode == NULL) {
return; return;
} }
...@@ -1023,104 +1023,116 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) { ...@@ -1023,104 +1023,116 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) {
} }
} }
static void exprTreeToBinaryImpl(tExprNode* pExprTree, SBuffer* pBuf) { static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
tbufWrite(pBuf, &pExprTree->nodeType, sizeof(pExprTree->nodeType)); tbufWriteUint8(bw, expr->nodeType);
if (pExprTree->nodeType == TSQL_NODE_VALUE) { if (expr->nodeType == TSQL_NODE_VALUE) {
tVariant* pVal = pExprTree->pVal; tVariant* pVal = expr->pVal;
tbufWrite(pBuf, &pVal->nType, sizeof(pVal->nType)); tbufWriteUint32(bw, pVal->nType);
if (pVal->nType == TSDB_DATA_TYPE_BINARY) { if (pVal->nType == TSDB_DATA_TYPE_BINARY) {
tbufWrite(pBuf, &pVal->nLen, sizeof(pVal->nLen)); tbufWriteInt32(bw, pVal->nLen);
tbufWrite(pBuf, pVal->pz, pVal->nLen); tbufWrite(bw, pVal->pz, pVal->nLen);
} else { } else {
tbufWrite(pBuf, &pVal->pz, sizeof(pVal->i64Key)); tbufWriteInt64(bw, pVal->i64Key);
} }
} else if (pExprTree->nodeType == TSQL_NODE_COL) { } else if (expr->nodeType == TSQL_NODE_COL) {
SSchema* pSchema = pExprTree->pSchema; SSchema* pSchema = expr->pSchema;
tbufWrite(pBuf, &pSchema->colId, sizeof(pSchema->colId)); tbufWriteInt16(bw, pSchema->colId);
tbufWrite(pBuf, &pSchema->bytes, sizeof(pSchema->bytes)); tbufWriteInt16(bw, pSchema->bytes);
tbufWrite(pBuf, &pSchema->type, sizeof(pSchema->type)); tbufWriteUint8(bw, pSchema->type);
tbufWriteString(bw, pSchema->name);
int32_t len = strlen(pSchema->name); } else if (expr->nodeType == TSQL_NODE_EXPR) {
tbufWriteStringLen(pBuf, pSchema->name, len); tbufWriteUint8(bw, expr->_node.optr);
tbufWriteUint8(bw, expr->_node.hasPK);
} else if (pExprTree->nodeType == TSQL_NODE_EXPR) { exprTreeToBinaryImpl(bw, expr->_node.pLeft);
tbufWrite(pBuf, &pExprTree->_node.optr, sizeof(pExprTree->_node.optr)); exprTreeToBinaryImpl(bw, expr->_node.pRight);
tbufWrite(pBuf, &pExprTree->_node.hasPK, sizeof(pExprTree->_node.hasPK));
exprTreeToBinaryImpl(pExprTree->_node.pLeft, pBuf);
exprTreeToBinaryImpl(pExprTree->_node.pRight, pBuf);
} }
} }
SBuffer exprTreeToBinary(tExprNode* pExprTree) { void exprTreeToBinary(SBufferWriter* bw, tExprNode* expr) {
SBuffer buf = {0}; if (expr != NULL) {
if (pExprTree == NULL) { exprTreeToBinaryImpl(bw, expr);
return buf;
} }
}
int32_t code = tbufBeginWrite(&buf);
if (code != 0) { // TODO: these three functions should be made global
return buf; static void* exception_calloc(size_t nmemb, size_t size) {
void* p = calloc(nmemb, size);
if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY);
} }
return p;
exprTreeToBinaryImpl(pExprTree, &buf); }
return buf;
static void* exception_malloc(size_t size) {
void* p = malloc(size);
if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY);
}
return p;
} }
static tExprNode* exprTreeFromBinaryImpl(SBuffer* pBuf) { static char* exception_strdup(const char* str) {
tExprNode* pExpr = calloc(1, sizeof(tExprNode)); char* p = strdup(str);
pExpr->nodeType = tbufReadUint8(pBuf); if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY);
}
return p;
}
static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) {
int32_t anchor = CLEANUP_GET_ANCHOR();
tExprNode* pExpr = exception_calloc(1, sizeof(tExprNode));
CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, pExpr, NULL);
pExpr->nodeType = tbufReadUint8(br);
if (pExpr->nodeType == TSQL_NODE_VALUE) { if (pExpr->nodeType == TSQL_NODE_VALUE) {
tVariant* pVal = calloc(1, sizeof(tVariant)); tVariant* pVal = exception_calloc(1, sizeof(tVariant));
if (pVal == NULL) {
// TODO:
}
pExpr->pVal = pVal; pExpr->pVal = pVal;
pVal->nType = tbufReadUint32(pBuf); pVal->nType = tbufReadUint32(br);
if (pVal->nType == TSDB_DATA_TYPE_BINARY) { if (pVal->nType == TSDB_DATA_TYPE_BINARY) {
tbufReadToBuffer(pBuf, &pVal->nLen, sizeof(pVal->nLen)); tbufReadToBuffer(br, &pVal->nLen, sizeof(pVal->nLen));
pVal->pz = calloc(1, pVal->nLen + 1); pVal->pz = calloc(1, pVal->nLen + 1);
tbufReadToBuffer(pBuf, pVal->pz, pVal->nLen); tbufReadToBuffer(br, pVal->pz, pVal->nLen);
} else { } else {
pVal->i64Key = tbufReadInt64(pBuf); pVal->i64Key = tbufReadInt64(br);
} }
} else if (pExpr->nodeType == TSQL_NODE_COL) { } else if (pExpr->nodeType == TSQL_NODE_COL) {
SSchema* pSchema = calloc(1, sizeof(SSchema)); SSchema* pSchema = exception_calloc(1, sizeof(SSchema));
if (pSchema == NULL) {
// TODO:
}
pExpr->pSchema = pSchema; pExpr->pSchema = pSchema;
pSchema->colId = tbufReadInt16(pBuf); pSchema->colId = tbufReadInt16(br);
pSchema->bytes = tbufReadInt16(pBuf); pSchema->bytes = tbufReadInt16(br);
pSchema->type = tbufReadUint8(pBuf); pSchema->type = tbufReadUint8(br);
tbufReadToString(pBuf, pSchema->name, TSDB_COL_NAME_LEN); tbufReadToString(br, pSchema->name, TSDB_COL_NAME_LEN);
} else if (pExpr->nodeType == TSQL_NODE_EXPR) { } else if (pExpr->nodeType == TSQL_NODE_EXPR) {
pExpr->_node.optr = tbufReadUint8(pBuf); pExpr->_node.optr = tbufReadUint8(br);
pExpr->_node.hasPK = tbufReadUint8(pBuf); pExpr->_node.hasPK = tbufReadUint8(br);
pExpr->_node.pLeft = exprTreeFromBinaryImpl(pBuf); pExpr->_node.pLeft = exprTreeFromBinaryImpl(br);
pExpr->_node.pRight = exprTreeFromBinaryImpl(pBuf); pExpr->_node.pRight = exprTreeFromBinaryImpl(br);
assert(pExpr->_node.pLeft != NULL && pExpr->_node.pRight != NULL); assert(pExpr->_node.pLeft != NULL && pExpr->_node.pRight != NULL);
} }
CLEANUP_EXECUTE_TO(anchor, false);
return pExpr; return pExpr;
} }
tExprNode* exprTreeFromBinary(const void* pBuf, size_t size) { tExprNode* exprTreeFromBinary(const void* data, size_t size) {
if (size == 0) { if (size == 0) {
return NULL; return NULL;
} }
SBuffer rbuf = {0}; SBufferReader br = tbufInitReader(data, size, false);
tbufBeginRead(&rbuf, pBuf, size); return exprTreeFromBinaryImpl(&br);
return exprTreeFromBinaryImpl(&rbuf);
} }
tExprNode* exprTreeFromTableName(const char* tbnameCond) { tExprNode* exprTreeFromTableName(const char* tbnameCond) {
...@@ -1128,23 +1140,18 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { ...@@ -1128,23 +1140,18 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
return NULL; return NULL;
} }
tExprNode* expr = calloc(1, sizeof(tExprNode)); int32_t anchor = CLEANUP_GET_ANCHOR();
if (expr == NULL) {
// TODO: tExprNode* expr = exception_calloc(1, sizeof(tExprNode));
} CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, expr, NULL);
expr->nodeType = TSQL_NODE_EXPR; expr->nodeType = TSQL_NODE_EXPR;
tExprNode* left = calloc(1, sizeof(tExprNode)); tExprNode* left = exception_calloc(1, sizeof(tExprNode));
if (left == NULL) {
// TODO:
}
expr->_node.pLeft = left; expr->_node.pLeft = left;
left->nodeType = TSQL_NODE_COL; left->nodeType = TSQL_NODE_COL;
SSchema* pSchema = calloc(1, sizeof(SSchema)); SSchema* pSchema = exception_calloc(1, sizeof(SSchema));
if (pSchema == NULL) {
// TODO:
}
left->pSchema = pSchema; left->pSchema = pSchema;
pSchema->type = TSDB_DATA_TYPE_BINARY; pSchema->type = TSDB_DATA_TYPE_BINARY;
...@@ -1152,36 +1159,24 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { ...@@ -1152,36 +1159,24 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
strcpy(pSchema->name, TSQL_TBNAME_L); strcpy(pSchema->name, TSQL_TBNAME_L);
pSchema->colId = -1; pSchema->colId = -1;
tExprNode* right = calloc(1, sizeof(tExprNode)); tExprNode* right = exception_calloc(1, sizeof(tExprNode));
if (right == NULL) {
// TODO
}
expr->_node.pRight = right; expr->_node.pRight = right;
if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) { if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) {
right->nodeType = TSQL_NODE_VALUE; right->nodeType = TSQL_NODE_VALUE;
expr->_node.optr = TSDB_RELATION_LIKE; expr->_node.optr = TSDB_RELATION_LIKE;
tVariant* pVal = calloc(1, sizeof(tVariant)); tVariant* pVal = exception_calloc(1, sizeof(tVariant));
if (pVal == NULL) {
// TODO:
}
right->pVal = pVal; right->pVal = pVal;
pVal->nType = TSDB_DATA_TYPE_BINARY;
size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1; size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1;
pVal->pz = malloc(len); pVal->pz = exception_malloc(len);
if (pVal->pz == NULL) {
// TODO:
}
memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN, len); memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN, len);
pVal->nType = TSDB_DATA_TYPE_BINARY;
pVal->nLen = (int32_t)len; pVal->nLen = (int32_t)len;
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) { } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) {
right->nodeType = TSQL_NODE_VALUE; right->nodeType = TSQL_NODE_VALUE;
expr->_node.optr = TSDB_RELATION_IN; expr->_node.optr = TSDB_RELATION_IN;
tVariant* pVal = calloc(1, sizeof(tVariant)); tVariant* pVal = exception_calloc(1, sizeof(tVariant));
if (pVal == NULL) {
// TODO:
}
right->pVal = pVal; right->pVal = pVal;
pVal->nType = TSDB_DATA_TYPE_ARRAY; pVal->nType = TSDB_DATA_TYPE_ARRAY;
pVal->arr = taosArrayInit(2, sizeof(char*)); pVal->arr = taosArrayInit(2, sizeof(char*));
...@@ -1192,7 +1187,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { ...@@ -1192,7 +1187,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
cond = e + 1; cond = e + 1;
} else if (*e == ',') { } else if (*e == ',') {
size_t len = e - cond + 1; size_t len = e - cond + 1;
char* p = malloc( len ); char* p = exception_malloc( len );
memcpy(p, cond, len); memcpy(p, cond, len);
p[len - 1] = 0; p[len - 1] = 0;
cond += len; cond += len;
...@@ -1201,12 +1196,13 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { ...@@ -1201,12 +1196,13 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
} }
if (*cond != 0) { if (*cond != 0) {
char* p = strdup( cond ); char* p = exception_strdup( cond );
taosArrayPush(pVal->arr, &p); taosArrayPush(pVal->arr, &p);
} }
taosArraySortString(pVal->arr); taosArraySortString(pVal->arr);
} }
CLEANUP_EXECUTE_TO(anchor, false);
return expr; return expr;
} }
\ No newline at end of file
...@@ -550,11 +550,12 @@ tExprNode* createExpr2() { ...@@ -550,11 +550,12 @@ tExprNode* createExpr2() {
void exprSerializeTest1() { void exprSerializeTest1() {
tExprNode* p1 = createExpr1(); tExprNode* p1 = createExpr1();
SBuffer buf = exprTreeToBinary(p1); SBufferWriter bw = tbufInitWriter(NULL, false);
exprTreeToBinary(&bw, p1);
size_t size = tbufTell(&buf); size_t size = tbufTell(&bw);
ASSERT_TRUE(size > 0); ASSERT_TRUE(size > 0);
char* b = tbufGetData(&buf, false); char* b = tbufGetData(&bw, false);
tExprNode* p2 = exprTreeFromBinary(b, size); tExprNode* p2 = exprTreeFromBinary(b, size);
ASSERT_EQ(p1->nodeType, p2->nodeType); ASSERT_EQ(p1->nodeType, p2->nodeType);
...@@ -581,16 +582,17 @@ void exprSerializeTest1() { ...@@ -581,16 +582,17 @@ void exprSerializeTest1() {
tExprTreeDestroy(&p1, nullptr); tExprTreeDestroy(&p1, nullptr);
tExprTreeDestroy(&p2, nullptr); tExprTreeDestroy(&p2, nullptr);
tbufClose(&buf, false); tbufClose(&bw);
} }
void exprSerializeTest2() { void exprSerializeTest2() {
tExprNode* p1 = createExpr2(); tExprNode* p1 = createExpr2();
SBuffer buf = exprTreeToBinary(p1); SBufferWriter bw = tbufInitWriter(NULL, false);
exprTreeToBinary(&bw, p1);
size_t size = tbufTell(&buf); size_t size = tbufTell(&bw);
ASSERT_TRUE(size > 0); ASSERT_TRUE(size > 0);
char* b = tbufGetData(&buf, false); char* b = tbufGetData(&bw, false);
tExprNode* p2 = exprTreeFromBinary(b, size); tExprNode* p2 = exprTreeFromBinary(b, size);
ASSERT_EQ(p1->nodeType, p2->nodeType); ASSERT_EQ(p1->nodeType, p2->nodeType);
...@@ -625,7 +627,7 @@ void exprSerializeTest2() { ...@@ -625,7 +627,7 @@ void exprSerializeTest2() {
tExprTreeDestroy(&p1, nullptr); tExprTreeDestroy(&p1, nullptr);
tExprTreeDestroy(&p2, nullptr); tExprTreeDestroy(&p2, nullptr);
tbufClose(&buf, false); tbufClose(&bw);
} }
} // namespace } // namespace
TEST(testCase, astTest) { TEST(testCase, astTest) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "talgo.h" #include "talgo.h"
#include "tutil.h" #include "tutil.h"
#include "tcompare.h" #include "tcompare.h"
#include "exception.h"
#include "../../../query/inc/qast.h" // todo move to common module #include "../../../query/inc/qast.h" // todo move to common module
#include "../../../query/inc/tlosertree.h" // todo move to util module #include "../../../query/inc/tlosertree.h" // todo move to util module
...@@ -1473,21 +1474,35 @@ int32_t tsdbQueryByTagsCond( ...@@ -1473,21 +1474,35 @@ int32_t tsdbQueryByTagsCond(
} }
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
tExprNode* expr = NULL;
tExprNode* expr = exprTreeFromTableName(tbnameCond); TRY(32) {
tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len); expr = exprTreeFromTableName(tbnameCond);
if (tagExpr != NULL) {
if (expr == NULL) { if (expr == NULL) {
expr = tagExpr; expr = exprTreeFromBinary(pTagCond, len);
} else { } else {
tExprNode* tbnameExpr = expr; CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, expr, NULL);
expr = calloc(1, sizeof(tExprNode)); tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len);
expr->nodeType = TSQL_NODE_EXPR; if (tagExpr != NULL) {
expr->_node.optr = tagNameRelType; CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, tagExpr, NULL);
expr->_node.pLeft = tagExpr; tExprNode* tbnameExpr = expr;
expr->_node.pRight = tbnameExpr; expr = calloc(1, sizeof(tExprNode));
if (expr == NULL) {
THROW( TSDB_CODE_SERV_OUT_OF_MEMORY );
}
expr->nodeType = TSQL_NODE_EXPR;
expr->_node.optr = tagNameRelType;
expr->_node.pLeft = tagExpr;
expr->_node.pRight = tbnameExpr;
}
} }
} CLEANUP_EXECUTE();
} CATCH( code ) {
CLEANUP_EXECUTE();
ret = code;
// TODO: more error handling
} END_TRY
doQueryTableList(pSTable, res, expr); doQueryTableList(pSTable, res, expr);
pGroupInfo->numOfTables = taosArrayGetSize(res); pGroupInfo->numOfTables = taosArrayGetSize(res);
......
...@@ -66,8 +66,6 @@ int main( int argc, char** argv ) { ...@@ -66,8 +66,6 @@ int main( int argc, char** argv ) {
printf( "you should not see this message.\n" ); printf( "you should not see this message.\n" );
} CATCH( code ) { } CATCH( code ) {
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code ); printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
// throw it again and the exception will be caught in main
THROW( code );
} END_TRY } END_TRY
tbufCloseWriter( &bw ); tbufCloseWriter( &bw );
...@@ -92,6 +90,7 @@ typedef struct { ...@@ -92,6 +90,7 @@ typedef struct {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// common functions & macros for both reader & writer // common functions & macros for both reader & writer
#define tbufTell( buf ) ((buf)->pos) #define tbufTell( buf ) ((buf)->pos)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册