[td-32] refactor codes.

This commit is contained in:
hjxilinx 2020-04-02 15:17:47 +08:00
parent 6e907a233d
commit ce88438ba1
9 changed files with 166 additions and 165 deletions

View File

@ -117,7 +117,7 @@ static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo);
static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo);
static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index); static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index);
static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr* pAst, int32_t* num, static int32_t tSQLBinaryExprCreateFromSqlExpr(tExprNode **pExpr, tSQLExpr* pAst, int32_t* num,
SColIndexEx** pColIndex, SSqlExprInfo* pExprInfo); SColIndexEx** pColIndex, SSqlExprInfo* pExprInfo);
/* /*
@ -1208,7 +1208,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
SSqlBinaryExprInfo* pBinExprInfo = &pFuncExpr->binExprInfo; SSqlBinaryExprInfo* pBinExprInfo = &pFuncExpr->binExprInfo;
tSQLSyntaxNode* pNode = NULL; tExprNode* pNode = NULL;
SColIndexEx* pColIndex = NULL; SColIndexEx* pColIndex = NULL;
int32_t ret = tSQLBinaryExprCreateFromSqlExpr(&pNode, pItem->pNode, &pBinExprInfo->numOfCols, &pColIndex, &pQueryInfo->exprsInfo); int32_t ret = tSQLBinaryExprCreateFromSqlExpr(&pNode, pItem->pNode, &pBinExprInfo->numOfCols, &pColIndex, &pQueryInfo->exprsInfo);
@ -5807,10 +5807,10 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return TSDB_CODE_SUCCESS; // Does not build query message here return TSDB_CODE_SUCCESS; // Does not build query message here
} }
static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr* pAst, int32_t* num, static int32_t tSQLBinaryExprCreateFromSqlExpr(tExprNode **pExpr, tSQLExpr* pAst, int32_t* num,
SColIndexEx** pColIndex, SSqlExprInfo* pExprInfo) { SColIndexEx** pColIndex, SSqlExprInfo* pExprInfo) {
tSQLSyntaxNode* pLeft = NULL; tExprNode* pLeft = NULL;
tSQLSyntaxNode* pRight= NULL; tExprNode* pRight= NULL;
if (pAst->pLeft != NULL) { if (pAst->pLeft != NULL) {
int32_t ret = tSQLBinaryExprCreateFromSqlExpr(&pLeft, pAst->pLeft, num, pColIndex, pExprInfo); int32_t ret = tSQLBinaryExprCreateFromSqlExpr(&pLeft, pAst->pLeft, num, pColIndex, pExprInfo);
@ -5828,14 +5828,14 @@ static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr*
if (pAst->pLeft == NULL) { if (pAst->pLeft == NULL) {
if (pAst->nSQLOptr >= TK_TINYINT && pAst->nSQLOptr <= TK_DOUBLE) { if (pAst->nSQLOptr >= TK_TINYINT && pAst->nSQLOptr <= TK_DOUBLE) {
*pExpr = calloc(1, sizeof(tSQLSyntaxNode) + sizeof(tVariant)); *pExpr = calloc(1, sizeof(tExprNode) + sizeof(tVariant));
(*pExpr)->nodeType = TSQL_NODE_VALUE; (*pExpr)->nodeType = TSQL_NODE_VALUE;
(*pExpr)->pVal = (tVariant*) ((char*)(*pExpr) + sizeof(tSQLSyntaxNode)); (*pExpr)->pVal = (tVariant*) ((char*)(*pExpr) + sizeof(tExprNode));
tVariantAssign((*pExpr)->pVal, &pAst->val); tVariantAssign((*pExpr)->pVal, &pAst->val);
} else if (pAst->nSQLOptr >= TK_COUNT && pAst->nSQLOptr <= TK_AVG_IRATE) { } else if (pAst->nSQLOptr >= TK_COUNT && pAst->nSQLOptr <= TK_AVG_IRATE) {
*pExpr = calloc(1, sizeof(tSQLSyntaxNode) + sizeof(SSchemaEx)); *pExpr = calloc(1, sizeof(tExprNode) + sizeof(SSchemaEx));
(*pExpr)->nodeType = TSQL_NODE_COL; (*pExpr)->nodeType = TSQL_NODE_COL;
(*pExpr)->pSchema = (SSchema*)((char*)(*pExpr) + sizeof(tSQLSyntaxNode)); (*pExpr)->pSchema = (SSchema*)((char*)(*pExpr) + sizeof(tExprNode));
strncpy((*pExpr)->pSchema->name, pAst->operand.z, pAst->operand.n); strncpy((*pExpr)->pSchema->name, pAst->operand.z, pAst->operand.n);
// set the input column data byte and type. // set the input column data byte and type.
@ -5855,7 +5855,7 @@ static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr*
strncpy((*pColIndex)[(*num) - 1].name, pAst->operand.z, pAst->operand.n); strncpy((*pColIndex)[(*num) - 1].name, pAst->operand.z, pAst->operand.n);
} else { } else {
*pExpr = (tSQLSyntaxNode *)calloc(1, sizeof(tSQLSyntaxNode)); *pExpr = (tExprNode *)calloc(1, sizeof(tExprNode));
(*pExpr)->_node.hasPK = false; (*pExpr)->_node.hasPK = false;
(*pExpr)->_node.pLeft = pLeft; (*pExpr)->_node.pLeft = pLeft;
(*pExpr)->_node.pRight = pRight; (*pExpr)->_node.pRight = pRight;

View File

@ -286,6 +286,7 @@ static void dnodeProcessRetrieveMsg(void *pVnode, SReadMsg *pMsg) {
dnodeContinueExecuteQuery(pVnode, pQInfo, pMsg); dnodeContinueExecuteQuery(pVnode, pQInfo, pMsg);
} else { // no further execution invoked, release the ref to vnode } else { // no further execution invoked, release the ref to vnode
dnodeProcessReadResult(pVnode, pMsg); dnodeProcessReadResult(pVnode, pMsg);
dnodeReleaseVnode(pVnode);
} }
} }

View File

@ -27,7 +27,7 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
#include "tvariant.h" #include "tvariant.h"
struct tSQLSyntaxNode; struct tExprNode;
struct SSchema; struct SSchema;
struct tSkipList; struct tSkipList;
struct tSkipListNode; struct tSkipListNode;
@ -60,7 +60,7 @@ typedef struct SBinaryFilterSupp {
void * pExtInfo; void * pExtInfo;
} SBinaryFilterSupp; } SBinaryFilterSupp;
typedef struct tSQLSyntaxNode { typedef struct tExprNode {
uint8_t nodeType; uint8_t nodeType;
union { union {
struct { struct {
@ -68,33 +68,26 @@ typedef struct tSQLSyntaxNode {
uint8_t hasPK; // 0: do not contain primary filter, 1: contain uint8_t hasPK; // 0: do not contain primary filter, 1: contain
void * info; // support filter operation on this expression only available for leaf node void * info; // support filter operation on this expression only available for leaf node
struct tSQLSyntaxNode *pLeft; // left child pointer struct tExprNode *pLeft; // left child pointer
struct tSQLSyntaxNode *pRight; // right child pointer struct tExprNode *pRight; // right child pointer
} _node; } _node;
struct SSchema *pSchema; struct SSchema *pSchema;
tVariant * pVal; tVariant * pVal;
}; };
} tSQLSyntaxNode; } tExprNode;
void tSQLBinaryExprFromString(tExprNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len);
typedef struct tQueryResultset { void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len);
void ** pRes;
int64_t num;
} tQueryResultset;
void tSQLBinaryExprFromString(tSQLSyntaxNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len); void tSQLBinaryExprDestroy(tExprNode **pExprs, void (*fp)(void*));
void tSQLBinaryExprToString(tSQLSyntaxNode *pExpr, char *dst, int32_t *len); void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param);
void tSQLBinaryExprDestroy(tSQLSyntaxNode **pExprs, void (*fp)(void*)); void tSQLBinaryExprCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param);
void tSQLBinaryExprCalcTraverse(tSQLSyntaxNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
char *(*cb)(void *, char *, int32_t)); char *(*cb)(void *, char *, int32_t));
void tSQLBinaryExprTrv(tSQLSyntaxNode *pExprs, int32_t *val, int16_t *ids); void tSQLBinaryExprTrv(tExprNode *pExprs, int32_t *val, int16_t *ids);
void tQueryResultClean(tQueryResultset *pRes);
uint8_t getBinaryExprOptr(SSQLToken *pToken); uint8_t getBinaryExprOptr(SSQLToken *pToken);

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_QASTDEF_H #ifndef TDENGINE_QSQLPARSER_H
#define TDENGINE_QASTDEF_H #define TDENGINE_QSQLPARSER_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -329,4 +329,4 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pSql);
} }
#endif #endif
#endif // TDENGINE_QASTDEF_H #endif // TDENGINE_QSQLPARSER_H

View File

@ -13,11 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "qast.h"
#include <tarray.h>
#include <tskiplist.h>
#include "../../client/inc/tschemautil.h"
#include "os.h" #include "os.h"
#include "tutil.h"
#include "qsqlparser.h" #include "qsqlparser.h"
#include "qsyntaxtreefunction.h" #include "qsyntaxtreefunction.h"
#include "taosdef.h" #include "taosdef.h"
@ -26,7 +25,12 @@
#include "tsqlfunction.h" #include "tsqlfunction.h"
#include "tstoken.h" #include "tstoken.h"
#include "ttokendef.h" #include "ttokendef.h"
#include "tutil.h"
#include "../../client/inc/tschemautil.h"
#include "qast.h"
#include "tarray.h"
#include "tskiplist.h"
/* /*
* *
@ -39,22 +43,20 @@
* ver 0.3, pipeline filter in the form of: (a+2)/9 > 14 * ver 0.3, pipeline filter in the form of: (a+2)/9 > 14
* *
*/ */
static tExprNode *tExprNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken);
static void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken); static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i);
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)); static void destroySyntaxTree(tExprNode *);
static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i); static uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight);
static void destroySyntaxTree(tSQLSyntaxNode *);
static uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode *pLeft,
const tSQLSyntaxNode *pRight);
/* /*
* Check the filter value type on the right hand side based on the column id on the left hand side, * Check the filter value type on the right hand side based on the column id on the left hand side,
* the filter value type must be identical to field type for relational operation * the filter value type must be identical to field type for relational operation
* As for binary arithmetic operation, it is not necessary to do so. * As for binary arithmetic operation, it is not necessary to do so.
*/ */
static void reviseBinaryExprIfNecessary(tSQLSyntaxNode **pLeft, tSQLSyntaxNode **pRight, uint8_t *optr) { static void reviseBinaryExprIfNecessary(tExprNode **pLeft, tExprNode **pRight, uint8_t *optr) {
if (*optr >= TSDB_RELATION_LESS && *optr <= TSDB_RELATION_LIKE) { if (*optr >= TSDB_RELATION_LESS && *optr <= TSDB_RELATION_LIKE) {
// make sure that the type of data on both sides of relational comparision are identical // make sure that the type of data on both sides of relational comparision are identical
if ((*pLeft)->nodeType == TSQL_NODE_VALUE) { if ((*pLeft)->nodeType == TSQL_NODE_VALUE) {
@ -79,7 +81,7 @@ static void reviseBinaryExprIfNecessary(tSQLSyntaxNode **pLeft, tSQLSyntaxNode *
*/ */
if ((*pLeft)->nodeType == TSQL_NODE_VALUE && (*pRight)->nodeType == TSQL_NODE_COL) { if ((*pLeft)->nodeType == TSQL_NODE_VALUE && (*pRight)->nodeType == TSQL_NODE_COL) {
if (*optr >= TSDB_RELATION_LARGE && *optr <= TSDB_RELATION_LARGE_EQUAL && *optr != TSDB_RELATION_EQUAL) { if (*optr >= TSDB_RELATION_LARGE && *optr <= TSDB_RELATION_LARGE_EQUAL && *optr != TSDB_RELATION_EQUAL) {
SWAP(*pLeft, *pRight, tSQLSyntaxNode *); SWAP(*pLeft, *pRight, tExprNode *);
} }
switch (*optr) { switch (*optr) {
@ -101,15 +103,15 @@ static void reviseBinaryExprIfNecessary(tSQLSyntaxNode **pLeft, tSQLSyntaxNode *
} }
} }
static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken) { static tExprNode *tExprNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken) {
/* if the token is not a value, return false */ /* if the token is not a value, return false */
if (pToken->type == TK_RP || (pToken->type != TK_INTEGER && pToken->type != TK_FLOAT && pToken->type != TK_ID && if (pToken->type == TK_RP || (pToken->type != TK_INTEGER && pToken->type != TK_FLOAT && pToken->type != TK_ID &&
pToken->type != TK_TBNAME && pToken->type != TK_STRING && pToken->type != TK_BOOL)) { pToken->type != TK_TBNAME && pToken->type != TK_STRING && pToken->type != TK_BOOL)) {
return NULL; return NULL;
} }
size_t nodeSize = sizeof(tSQLSyntaxNode); size_t nodeSize = sizeof(tExprNode);
tSQLSyntaxNode *pNode = NULL; tExprNode *pNode = NULL;
if (pToken->type == TK_ID || pToken->type == TK_TBNAME) { if (pToken->type == TK_ID || pToken->type == TK_TBNAME) {
int32_t i = 0; int32_t i = 0;
@ -130,7 +132,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
nodeSize += sizeof(SSchema); nodeSize += sizeof(SSchema);
pNode = calloc(1, nodeSize); pNode = calloc(1, nodeSize);
pNode->pSchema = (struct SSchema *)((char *)pNode + sizeof(tSQLSyntaxNode)); pNode->pSchema = (struct SSchema *)((char *)pNode + sizeof(tExprNode));
pNode->nodeType = TSQL_NODE_COL; pNode->nodeType = TSQL_NODE_COL;
if (pToken->type == TK_ID) { if (pToken->type == TK_ID) {
@ -145,7 +147,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
} else { } else {
nodeSize += sizeof(tVariant); nodeSize += sizeof(tVariant);
pNode = calloc(1, nodeSize); pNode = calloc(1, nodeSize);
pNode->pVal = (tVariant *)((char *)pNode + sizeof(tSQLSyntaxNode)); pNode->pVal = (tVariant *)((char *)pNode + sizeof(tExprNode));
toTSDBType(pToken->type); toTSDBType(pToken->type);
tVariantCreate(pNode->pVal, pToken); tVariantCreate(pNode->pVal, pToken);
@ -191,21 +193,21 @@ uint8_t getBinaryExprOptr(SSQLToken *pToken) {
} }
// previous generated expr is reduced as the left child // previous generated expr is reduced as the left child
static tSQLSyntaxNode *parseRemainStr(char *pstr, tSQLSyntaxNode *pExpr, SSchema *pSchema, int32_t optr, static tExprNode *parseRemainStr(char *pstr, tExprNode *pExpr, SSchema *pSchema, int32_t optr,
int32_t numOfCols, int32_t *i) { int32_t numOfCols, int32_t *i) {
// set the previous generated node as the left child of new root // set the previous generated node as the left child of new root
pExpr->nodeType = TSQL_NODE_EXPR; pExpr->nodeType = TSQL_NODE_EXPR;
// remain is the right child // remain is the right child
tSQLSyntaxNode *pRight = createSyntaxTree(pSchema, numOfCols, pstr, i); tExprNode *pRight = createSyntaxTree(pSchema, numOfCols, pstr, i);
if (pRight == NULL || (pRight->nodeType == TSQL_NODE_COL && pExpr->nodeType != TSQL_NODE_VALUE) || if (pRight == NULL || (pRight->nodeType == TSQL_NODE_COL && pExpr->nodeType != TSQL_NODE_VALUE) ||
(pExpr->nodeType == TSQL_NODE_VALUE && pRight->nodeType != TSQL_NODE_COL)) { (pExpr->nodeType == TSQL_NODE_VALUE && pRight->nodeType != TSQL_NODE_COL)) {
tSQLSyntaxNodeDestroy(pExpr, NULL); tExprNodeDestroy(pExpr, NULL);
tSQLSyntaxNodeDestroy(pRight, NULL); tExprNodeDestroy(pRight, NULL);
return NULL; return NULL;
} }
tSQLSyntaxNode *pNewExpr = (tSQLSyntaxNode *)calloc(1, sizeof(tSQLSyntaxNode)); tExprNode *pNewExpr = (tExprNode *)calloc(1, sizeof(tExprNode));
uint8_t k = optr; uint8_t k = optr;
reviseBinaryExprIfNecessary(&pExpr, &pRight, &k); reviseBinaryExprIfNecessary(&pExpr, &pRight, &k);
pNewExpr->_node.pLeft = pExpr; pNewExpr->_node.pLeft = pExpr;
@ -218,7 +220,7 @@ static tSQLSyntaxNode *parseRemainStr(char *pstr, tSQLSyntaxNode *pExpr, SSchema
return pNewExpr; return pNewExpr;
} }
uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode *pLeft, const tSQLSyntaxNode *pRight) { uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
if (pLeft->nodeType == TSQL_NODE_COL) { if (pLeft->nodeType == TSQL_NODE_COL) {
// if left node is the primary column,return true // if left node is the primary column,return true
return (strcmp(primaryColumnName, pLeft->pSchema->name) == 0) ? 1 : 0; return (strcmp(primaryColumnName, pLeft->pSchema->name) == 0) ? 1 : 0;
@ -231,20 +233,20 @@ uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode
} }
} }
static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i) { static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i) {
SSQLToken t0 = tStrGetToken(str, i, false, 0, NULL); SSQLToken t0 = tStrGetToken(str, i, false, 0, NULL);
if (t0.n == 0) { if (t0.n == 0) {
return NULL; return NULL;
} }
tSQLSyntaxNode *pLeft = NULL; tExprNode *pLeft = NULL;
if (t0.type == TK_LP) { // start new left child branch if (t0.type == TK_LP) { // start new left child branch
pLeft = createSyntaxTree(pSchema, numOfCols, str, i); pLeft = createSyntaxTree(pSchema, numOfCols, str, i);
} else { } else {
if (t0.type == TK_RP) { if (t0.type == TK_RP) {
return NULL; return NULL;
} }
pLeft = tSQLSyntaxNodeCreate(pSchema, numOfCols, &t0); pLeft = tExprNodeCreate(pSchema, numOfCols, &t0);
} }
if (pLeft == NULL) { if (pLeft == NULL) {
@ -254,7 +256,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
t0 = tStrGetToken(str, i, false, 0, NULL); t0 = tStrGetToken(str, i, false, 0, NULL);
if (t0.n == 0 || t0.type == TK_RP) { if (t0.n == 0 || t0.type == TK_RP) {
if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr
tSQLSyntaxNodeDestroy(pLeft, NULL); tExprNodeDestroy(pLeft, NULL);
return NULL; return NULL;
} }
@ -265,12 +267,12 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
uint8_t optr = getBinaryExprOptr(&t0); uint8_t optr = getBinaryExprOptr(&t0);
if (optr == 0) { if (optr == 0) {
pError("not support binary operator:%d", t0.type); pError("not support binary operator:%d", t0.type);
tSQLSyntaxNodeDestroy(pLeft, NULL); tExprNodeDestroy(pLeft, NULL);
return NULL; return NULL;
} }
assert(pLeft != NULL); assert(pLeft != NULL);
tSQLSyntaxNode *pRight = NULL; tExprNode *pRight = NULL;
if (t0.type == TK_AND || t0.type == TK_OR || t0.type == TK_LP) { if (t0.type == TK_AND || t0.type == TK_OR || t0.type == TK_LP) {
pRight = createSyntaxTree(pSchema, numOfCols, str, i); pRight = createSyntaxTree(pSchema, numOfCols, str, i);
@ -283,51 +285,51 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
*/ */
t0 = tStrGetToken(str, i, true, 0, NULL); t0 = tStrGetToken(str, i, true, 0, NULL);
if (t0.n == 0) { if (t0.n == 0) {
tSQLSyntaxNodeDestroy(pLeft, NULL); // illegal expression tExprNodeDestroy(pLeft, NULL); // illegal expression
return NULL; return NULL;
} }
if (t0.type == TK_LP) { if (t0.type == TK_LP) {
pRight = createSyntaxTree(pSchema, numOfCols, str, i); pRight = createSyntaxTree(pSchema, numOfCols, str, i);
} else { } else {
pRight = tSQLSyntaxNodeCreate(pSchema, numOfCols, &t0); pRight = tExprNodeCreate(pSchema, numOfCols, &t0);
} }
} }
if (pRight == NULL) { if (pRight == NULL) {
tSQLSyntaxNodeDestroy(pLeft, NULL); tExprNodeDestroy(pLeft, NULL);
return NULL; return NULL;
} }
/* create binary expr as the child of new parent node */ /* create binary expr as the child of new parent node */
tSQLSyntaxNode *pBinExpr = (tSQLSyntaxNode *)calloc(1, sizeof(tSQLSyntaxNode)); tExprNode *pExpr = (tExprNode *)calloc(1, sizeof(tExprNode));
reviseBinaryExprIfNecessary(&pLeft, &pRight, &optr); reviseBinaryExprIfNecessary(&pLeft, &pRight, &optr);
pBinExpr->_node.hasPK = isQueryOnPrimaryKey(pSchema[0].name, pLeft, pRight); pExpr->_node.hasPK = isQueryOnPrimaryKey(pSchema[0].name, pLeft, pRight);
pBinExpr->_node.pLeft = pLeft; pExpr->_node.pLeft = pLeft;
pBinExpr->_node.pRight = pRight; pExpr->_node.pRight = pRight;
pBinExpr->_node.optr = optr; pExpr->_node.optr = optr;
t0 = tStrGetToken(str, i, true, 0, NULL); t0 = tStrGetToken(str, i, true, 0, NULL);
if (t0.n == 0 || t0.type == TK_RP) { if (t0.n == 0 || t0.type == TK_RP) {
tSQLSyntaxNode *pn = malloc(sizeof(tSQLSyntaxNode)); pExpr->nodeType = TSQL_NODE_EXPR;
pBinExpr->nodeType = TSQL_NODE_EXPR; return pExpr;
return pBinExpr;
} else { } else {
uint8_t localOptr = getBinaryExprOptr(&t0); uint8_t localOptr = getBinaryExprOptr(&t0);
if (localOptr == 0) { if (localOptr == 0) {
pError("not support binary operator:%d", t0.type); pError("not support binary operator:%d", t0.type);
free(pBinExpr); free(pExpr);
return NULL; return NULL;
} }
return parseRemainStr(str, pBinExpr, pSchema, localOptr, numOfCols, i); return parseRemainStr(str, pExpr, pSchema, localOptr, numOfCols, i);
} }
} }
void tSQLBinaryExprFromString(tSQLSyntaxNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len) { void tSQLBinaryExprFromString(tExprNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len) {
*pExpr = NULL; *pExpr = NULL;
if (len <= 0 || src == NULL || pSchema == NULL || numOfCols <= 0) { if (len <= 0 || src == NULL || pSchema == NULL || numOfCols <= 0) {
return; return;
} }
@ -340,7 +342,7 @@ void tSQLBinaryExprFromString(tSQLSyntaxNode **pExpr, SSchema *pSchema, int32_t
} }
} }
int32_t tSQLBinaryExprToStringImpl(tSQLSyntaxNode *pNode, char *dst, uint8_t type) { int32_t tSQLBinaryExprToStringImpl(tExprNode *pNode, char *dst, uint8_t type) {
int32_t len = 0; int32_t len = 0;
if (type == TSQL_NODE_EXPR) { if (type == TSQL_NODE_EXPR) {
*dst = '('; *dst = '(';
@ -406,7 +408,7 @@ static char *tSQLOptrToString(uint8_t optr, char *dst) {
return dst; return dst;
} }
void tSQLBinaryExprToString(tSQLSyntaxNode *pExpr, char *dst, int32_t *len) { void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len) {
if (pExpr == NULL) { if (pExpr == NULL) {
*dst = 0; *dst = 0;
*len = 0; *len = 0;
@ -423,9 +425,9 @@ void tSQLBinaryExprToString(tSQLSyntaxNode *pExpr, char *dst, int32_t *len) {
*len += tSQLBinaryExprToStringImpl(pExpr->_node.pRight, start, pExpr->_node.pRight->nodeType); *len += tSQLBinaryExprToStringImpl(pExpr->_node.pRight, start, pExpr->_node.pRight->nodeType);
} }
static void UNUSED_FUNC destroySyntaxTree(tSQLSyntaxNode *pNode) { tSQLSyntaxNodeDestroy(pNode, NULL); } static void UNUSED_FUNC destroySyntaxTree(tExprNode *pNode) { tExprNodeDestroy(pNode, NULL); }
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)) { static void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) {
if (pNode == NULL) { if (pNode == NULL) {
return; return;
} }
@ -439,13 +441,13 @@ static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)) {
free(pNode); free(pNode);
} }
void tSQLBinaryExprDestroy(tSQLSyntaxNode **pExpr, void (*fp)(void *)) { void tSQLBinaryExprDestroy(tExprNode **pExpr, void (*fp)(void *)) {
if (*pExpr == NULL) { if (*pExpr == NULL) {
return; return;
} }
tSQLSyntaxNodeDestroy((*pExpr)->_node.pLeft, fp); tExprNodeDestroy((*pExpr)->_node.pLeft, fp);
tSQLSyntaxNodeDestroy((*pExpr)->_node.pRight, fp); tExprNodeDestroy((*pExpr)->_node.pRight, fp);
if (fp != NULL) { if (fp != NULL) {
fp((*pExpr)->_node.info); fp((*pExpr)->_node.info);
@ -559,7 +561,7 @@ void tSQLBinaryExprDestroy(tSQLSyntaxNode **pExpr, void (*fp)(void *)) {
// DEFAULT_COMP(p1, p2); // DEFAULT_COMP(p1, p2);
//} //}
int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *pFinalRes) { int32_t merge(SArray *pLeft, SArray *pRight, SArray *pFinalRes) {
// assert(pFinalRes->pRes == 0); // assert(pFinalRes->pRes == 0);
// //
// pFinalRes->pRes = calloc((size_t)(pLeft->num + pRight->num), POINTER_BYTES); // pFinalRes->pRes = calloc((size_t)(pLeft->num + pRight->num), POINTER_BYTES);
@ -600,7 +602,7 @@ int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *
return 0; return 0;
} }
int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *pFinalRes) { int32_t intersect(SArray *pLeft, SArray *pRight, SArray *pFinalRes) {
// int64_t num = MIN(pLeft->num, pRight->num); // int64_t num = MIN(pLeft->num, pRight->num);
// //
// assert(pFinalRes->pRes == 0); // assert(pFinalRes->pRes == 0);
@ -638,25 +640,26 @@ int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResults
/* /*
* traverse the result and apply the function to each item to check if the item is qualified or not * traverse the result and apply the function to each item to check if the item is qualified or not
*/ */
static UNUSED_FUNC void tSQLListTraverseOnResult(struct tSQLSyntaxNode *pExpr, __result_filter_fn_t fp, tQueryResultset *pResult) { static UNUSED_FUNC void tSQLListTraverseOnResult(struct tExprNode *pExpr, __result_filter_fn_t fp, SArray *pResult) {
assert(pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_VALUE); // assert(pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_VALUE);
//
// brutal force scan the result list and check for each item in the list // // brutal force scan the result list and check for each item in the list
int64_t num = pResult->num; // int64_t num = pResult->num;
for (int32_t i = 0, j = 0; i < pResult->num; ++i) { // for (int32_t i = 0, j = 0; i < pResult->num; ++i) {
if (fp == NULL || (fp(pResult->pRes[i], pExpr->_node.info) == true)) { // if (fp == NULL || (fp(pResult->pRes[i], pExpr->_node.info) == true)) {
pResult->pRes[j++] = pResult->pRes[i]; // pResult->pRes[j++] = pResult->pRes[i];
} else { // } else {
num--; // num--;
} // }
} // }
//
pResult->num = num; // pResult->num = num;
assert(0);
} }
static bool filterItem(tSQLSyntaxNode *pExpr, const void *pItem, SBinaryFilterSupp *param) { static bool filterItem(tExprNode *pExpr, const void *pItem, SBinaryFilterSupp *param) {
tSQLSyntaxNode *pLeft = pExpr->_node.pLeft; tExprNode *pLeft = pExpr->_node.pLeft;
tSQLSyntaxNode *pRight = pExpr->_node.pRight; tExprNode *pRight = pExpr->_node.pRight;
/* /*
* non-leaf nodes, recursively traverse the syntax tree in the post-root order * non-leaf nodes, recursively traverse the syntax tree in the post-root order
@ -695,7 +698,7 @@ static bool filterItem(tSQLSyntaxNode *pExpr, const void *pItem, SBinaryFilterSu
* @param pSchema tag schemas * @param pSchema tag schemas
* @param fp filter callback function * @param fp filter callback function
*/ */
static void tSQLBinaryTraverseOnResult(tSQLSyntaxNode *pExpr, SArray *pResult, SBinaryFilterSupp *param) { static void tSQLBinaryTraverseOnResult(tExprNode *pExpr, SArray *pResult, SBinaryFilterSupp *param) {
size_t size = taosArrayGetSize(pResult); size_t size = taosArrayGetSize(pResult);
SArray* array = taosArrayInit(size, POINTER_BYTES); SArray* array = taosArrayInit(size, POINTER_BYTES);
@ -710,7 +713,7 @@ static void tSQLBinaryTraverseOnResult(tSQLSyntaxNode *pExpr, SArray *pResult, S
taosArrayCopy(pResult, array); taosArrayCopy(pResult, array);
} }
static void tSQLBinaryTraverseOnSkipList(tSQLSyntaxNode *pExpr, SArray *pResult, SSkipList *pSkipList, static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSkipList *pSkipList,
SBinaryFilterSupp *param) { SBinaryFilterSupp *param) {
SSkipListIterator* iter = tSkipListCreateIter(pSkipList); SSkipListIterator* iter = tSkipListCreateIter(pSkipList);
@ -724,13 +727,13 @@ static void tSQLBinaryTraverseOnSkipList(tSQLSyntaxNode *pExpr, SArray *pResult,
} }
// post-root order traverse syntax tree // post-root order traverse syntax tree
void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param) { void tSQLBinaryExprTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param) {
if (pExpr == NULL) { if (pExpr == NULL) {
return; return;
} }
tSQLSyntaxNode *pLeft = pExpr->_node.pLeft; tExprNode *pLeft = pExpr->_node.pLeft;
tSQLSyntaxNode *pRight = pExpr->_node.pRight; tExprNode *pRight = pExpr->_node.pRight;
// recursive traverse left child branch // recursive traverse left child branch
if (pLeft->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_EXPR) { if (pLeft->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_EXPR) {
@ -751,22 +754,22 @@ void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray
assert(taosArrayGetSize(result) == 0); assert(taosArrayGetSize(result) == 0);
tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param); tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param);
} else if (weight == 2 || (weight == 1 && pExpr->_node.optr == TSDB_RELATION_OR)) { } else if (weight == 2 || (weight == 1 && pExpr->_node.optr == TSDB_RELATION_OR)) {
tQueryResultset rLeft = {0}; SArray* rLeft = taosArrayInit(10, POINTER_BYTES);
tQueryResultset rRight = {0}; SArray* rRight = taosArrayInit(10, POINTER_BYTES);
tSQLBinaryExprTraverse(pLeft, pSkipList, &rLeft, param); tSQLBinaryExprTraverse(pLeft, pSkipList, rLeft, param);
tSQLBinaryExprTraverse(pRight, pSkipList, &rRight, param); tSQLBinaryExprTraverse(pRight, pSkipList, rRight, param);
if (pExpr->_node.optr == TSDB_RELATION_AND) { // CROSS if (pExpr->_node.optr == TSDB_RELATION_AND) { // CROSS
intersect(&rLeft, &rRight, result); intersect(rLeft, rRight, result);
} else if (pExpr->_node.optr == TSDB_RELATION_OR) { // or } else if (pExpr->_node.optr == TSDB_RELATION_OR) { // or
merge(&rLeft, &rRight, result); merge(rLeft, rRight, result);
} else { } else {
assert(false); assert(false);
} }
free(rLeft.pRes); taosArrayDestroy(rLeft);
free(rRight.pRes); taosArrayDestroy(rRight);
} else { } else {
/* /*
* (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here * (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here
@ -776,8 +779,8 @@ void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray
*/ */
assert(pExpr->_node.optr == TSDB_RELATION_AND); assert(pExpr->_node.optr == TSDB_RELATION_AND);
tSQLSyntaxNode *pFirst = NULL; tExprNode *pFirst = NULL;
tSQLSyntaxNode *pSecond = NULL; tExprNode *pSecond = NULL;
if (pLeft->_node.hasPK == 1) { if (pLeft->_node.hasPK == 1) {
pFirst = pLeft; pFirst = pLeft;
pSecond = pRight; pSecond = pRight;
@ -810,14 +813,14 @@ void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray
} }
} }
void tSQLBinaryExprCalcTraverse(tSQLSyntaxNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order, void tSQLBinaryExprCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
char *(*getSourceDataBlock)(void *, char *, int32_t)) { char *(*getSourceDataBlock)(void *, char *, int32_t)) {
if (pExprs == NULL) { if (pExprs == NULL) {
return; return;
} }
tSQLSyntaxNode *pLeft = pExprs->_node.pLeft; tExprNode *pLeft = pExprs->_node.pLeft;
tSQLSyntaxNode *pRight = pExprs->_node.pRight; tExprNode *pRight = pExprs->_node.pRight;
/* the left output has result from the left child syntax tree */ /* the left output has result from the left child syntax tree */
char *pLeftOutput = (char*)malloc(sizeof(int64_t) * numOfRows); char *pLeftOutput = (char*)malloc(sizeof(int64_t) * numOfRows);
@ -890,13 +893,13 @@ void tSQLBinaryExprCalcTraverse(tSQLSyntaxNode *pExprs, int32_t numOfRows, char
free(pRightOutput); free(pRightOutput);
} }
void tSQLBinaryExprTrv(tSQLSyntaxNode *pExprs, int32_t *val, int16_t *ids) { void tSQLBinaryExprTrv(tExprNode *pExprs, int32_t *val, int16_t *ids) {
if (pExprs == NULL) { if (pExprs == NULL) {
return; return;
} }
tSQLSyntaxNode *pLeft = pExprs->_node.pLeft; tExprNode *pLeft = pExprs->_node.pLeft;
tSQLSyntaxNode *pRight = pExprs->_node.pRight; tExprNode *pRight = pExprs->_node.pRight;
// recursive traverse left child branch // recursive traverse left child branch
if (pLeft->nodeType == TSQL_NODE_EXPR) { if (pLeft->nodeType == TSQL_NODE_EXPR) {
@ -913,12 +916,3 @@ void tSQLBinaryExprTrv(tSQLSyntaxNode *pExprs, int32_t *val, int16_t *ids) {
(*val) += 1; (*val) += 1;
} }
} }
void tQueryResultClean(tQueryResultset *pRes) {
if (pRes == NULL) {
return;
}
tfree(pRes->pRes);
pRes->num = 0;
}

View File

@ -13,10 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "hash.h" #include "hash.h"
#include "hashfunc.h" #include "hashfunc.h"
#include "os.h"
#include "shash.h"
#include "taosdef.h" #include "taosdef.h"
#include "tstoken.h" #include "tstoken.h"
#include "ttokendef.h" #include "ttokendef.h"

View File

@ -2609,7 +2609,6 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
GET_QINFO_ADDR(pRuntimeEnv), pQuery->window.skey, pQuery->window.ekey, pQuery->lastKey, pQuery->order.order); GET_QINFO_ADDR(pRuntimeEnv), pQuery->window.skey, pQuery->window.ekey, pQuery->lastKey, pQuery->order.order);
tsdb_query_handle_t pQueryHandle = pRuntimeEnv->pQueryHandle; tsdb_query_handle_t pQueryHandle = pRuntimeEnv->pQueryHandle;
while (tsdbNextDataBlock(pQueryHandle)) { while (tsdbNextDataBlock(pQueryHandle)) {
// check if query is killed or not set the status of query to pass the status check // check if query is killed or not set the status of query to pass the status check
if (isQueryKilled(GET_QINFO_ADDR(pRuntimeEnv))) { if (isQueryKilled(GET_QINFO_ADDR(pRuntimeEnv))) {
@ -5461,7 +5460,7 @@ static int32_t buildAirthmeticExprFromMsg(SSqlFunctionExpr *pExpr, SQueryTableMs
SSqlBinaryExprInfo *pBinaryExprInfo = &pExpr->binExprInfo; SSqlBinaryExprInfo *pBinaryExprInfo = &pExpr->binExprInfo;
SColumnInfo * pColMsg = pQueryMsg->colList; SColumnInfo * pColMsg = pQueryMsg->colList;
#if 0 #if 0
tSQLSyntaxNode* pBinExpr = NULL; tExprNode* pBinExpr = NULL;
SSchema* pSchema = toSchema(pQueryMsg, pColMsg, pQueryMsg->numOfCols); SSchema* pSchema = toSchema(pQueryMsg, pColMsg, pQueryMsg->numOfCols);
dTrace("qmsg:%p create binary expr from string:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz); dTrace("qmsg:%p create binary expr from string:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz);

View File

@ -24,6 +24,7 @@
#include "ttime.h" #include "ttime.h"
#include "queryExecutor.h" #include "queryExecutor.h"
#include "queryUtil.h"
int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t size, int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t size,
int32_t threshold, int16_t type) { int32_t threshold, int16_t type) {

View File

@ -424,15 +424,12 @@ static SDataBlockInfo getTrueDataBlockInfo(STsdbQueryHandle* pHandle, STableChec
SArray *getDefaultLoadColumns(STsdbQueryHandle *pQueryHandle, bool loadTS); SArray *getDefaultLoadColumns(STsdbQueryHandle *pQueryHandle, bool loadTS);
static void filterDataInDataBlock(STsdbQueryHandle *pQueryHandle, SDataCols* pCols, SArray *sa); static void filterDataInDataBlock(STsdbQueryHandle *pQueryHandle, SDataCols* pCols, SArray *sa);
static bool loadQualifiedDataFromFileBlock(STsdbQueryHandle *pQueryHandle) { static bool doLoadDataFromFileBlock(STsdbQueryHandle *pQueryHandle) {
SQueryFilePos *cur = &pQueryHandle->cur; SQueryFilePos *cur = &pQueryHandle->cur;
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex); STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
SCompBlock* pBlock = &pCheckInfo->pCompInfo->blocks[cur->slot]; SCompBlock* pBlock = &pCheckInfo->pCompInfo->blocks[cur->slot];
SArray *sa = getDefaultLoadColumns(pQueryHandle, true);
if (QUERY_IS_ASC_QUERY(pQueryHandle->order)) {
if (pQueryHandle->window.ekey < pBlock->keyLast) {
SCompData* data = calloc(1, sizeof(SCompData)+ sizeof(SCompCol)*pBlock->numOfCols); SCompData* data = calloc(1, sizeof(SCompData)+ sizeof(SCompCol)*pBlock->numOfCols);
data->numOfCols = pBlock->numOfCols; data->numOfCols = pBlock->numOfCols;
@ -446,17 +443,29 @@ static bool loadQualifiedDataFromFileBlock(STsdbQueryHandle *pQueryHandle) {
pFile->fd = open(pFile->fname, O_RDONLY); pFile->fd = open(pFile->fname, O_RDONLY);
} }
if (tsdbLoadDataBlock(pFile, pBlock, 1, pCheckInfo->pDataCols, data) == 0) { tsdbLoadDataBlock(pFile, pBlock, 1, pCheckInfo->pDataCols, data);
//do something }
static bool loadQualifiedDataFromFileBlock(STsdbQueryHandle *pQueryHandle) {
SQueryFilePos *cur = &pQueryHandle->cur;
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
SCompBlock* pBlock = &pCheckInfo->pCompInfo->blocks[cur->slot];
SArray *sa = getDefaultLoadColumns(pQueryHandle, true);
if (QUERY_IS_ASC_QUERY(pQueryHandle->order)) {
// query ended in current block
if (pQueryHandle->window.ekey < pBlock->keyLast) {
doLoadDataFromFileBlock(pQueryHandle);
filterDataInDataBlock(pQueryHandle, pCheckInfo->pDataCols, sa);
} }
} } else {// todo desc query
} else {
if (pQueryHandle->window.ekey > pBlock->keyFirst) { if (pQueryHandle->window.ekey > pBlock->keyFirst) {
// loadDataBlockIntoMem_(pQueryHandle, pBlock, &pQueryHandle->pFields[cur->slot], cur->fileId, sa); //
} }
} }
filterDataInDataBlock(pQueryHandle, pCheckInfo->pDataCols, sa);
return pQueryHandle->realNumOfRows > 0; return pQueryHandle->realNumOfRows > 0;
} }
@ -508,7 +517,7 @@ bool moveToNextBlock(STsdbQueryHandle *pQueryHandle, int32_t step) {
// next block in the same file // next block in the same file
cur->slot += step; cur->slot += step;
SCompBlock* pBlock = &pQueryHandle->pBlock[cur->slot]; SCompBlock* pBlock = &pCheckInfo->pCompInfo->blocks[cur->slot];
cur->pos = (step == QUERY_ASC_FORWARD_STEP) ? 0 : pBlock->numOfPoints - 1; cur->pos = (step == QUERY_ASC_FORWARD_STEP) ? 0 : pBlock->numOfPoints - 1;
return loadQualifiedDataFromFileBlock(pQueryHandle); return loadQualifiedDataFromFileBlock(pQueryHandle);
} }
@ -769,12 +778,11 @@ static bool getQualifiedDataBlock(STsdbQueryHandle *pQueryHandle, STableCheckInf
// load first data block into memory failed, caused by disk block error // load first data block into memory failed, caused by disk block error
bool blockLoaded = false; bool blockLoaded = false;
SArray *sa = NULL; SArray *sa = getDefaultLoadColumns(pQueryHandle, true);
// todo no need to loaded at all // todo no need to loaded at all
cur->slot = index; cur->slot = index;
sa = getDefaultLoadColumns(pQueryHandle, true);
SCompBlock* pBlock = &pCheckInfo->pCompInfo->blocks[cur->slot]; SCompBlock* pBlock = &pCheckInfo->pCompInfo->blocks[cur->slot];
SCompData* data = calloc(1, sizeof(SCompData)+ sizeof(SCompCol)*pBlock->numOfCols); SCompData* data = calloc(1, sizeof(SCompData)+ sizeof(SCompCol)*pBlock->numOfCols);
@ -973,11 +981,16 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList
STableCheckInfo* pCheckInfo = taosArrayGet(pHandle->pTableCheckInfo, pHandle->activeIndex); STableCheckInfo* pCheckInfo = taosArrayGet(pHandle->pTableCheckInfo, pHandle->activeIndex);
SDataBlockInfo binfo = getTrueDataBlockInfo(pHandle, pCheckInfo); SDataBlockInfo binfo = getTrueDataBlockInfo(pHandle, pCheckInfo);
if (pHandle->realNumOfRows <= binfo.size) { assert(pHandle->realNumOfRows <= binfo.size);
if (pHandle->realNumOfRows < binfo.size) {
return pHandle->pColumns; return pHandle->pColumns;
} else { } else {
// todo do load data block SArray *sa = getDefaultLoadColumns(pHandle, true);
assert(0);
doLoadDataFromFileBlock(pHandle);
filterDataInDataBlock(pHandle, pCheckInfo->pDataCols, sa);
return pHandle->pColumns;
} }
} }
} }
@ -1197,7 +1210,7 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
} }
void filterPrepare(void* expr, void* param) { void filterPrepare(void* expr, void* param) {
tSQLSyntaxNode *pExpr = (tSQLSyntaxNode*) expr; tExprNode *pExpr = (tExprNode*) expr;
if (pExpr->_node.info != NULL) { if (pExpr->_node.info != NULL) {
return; return;
} }
@ -1276,7 +1289,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond) { static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond) {
STColumn* stcol = schemaColAt(pSTable->tagSchema, 0); STColumn* stcol = schemaColAt(pSTable->tagSchema, 0);
tSQLSyntaxNode* pExpr = NULL; tExprNode* pExpr = NULL;
tSQLBinaryExprFromString(&pExpr, stcol, schemaNCols(pSTable->tagSchema), pCond, strlen(pCond)); tSQLBinaryExprFromString(&pExpr, stcol, schemaNCols(pSTable->tagSchema), pCond, strlen(pCond));
// failed to build expression, no result, return immediately // failed to build expression, no result, return immediately