diff --git a/include/common/trow.h b/include/common/trow.h index dbbdef84a04c9434351d94c362336465d0eb25f2..963542fb31f2641ab36c5d2d9f6c9aa7e77f1c27 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -308,21 +308,21 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, // use literal value directly and not use formula to simplify the codes switch (nOffset) { case 0: - // *pDestByte = ((*pDestByte) & 0x3F) | (valType << 6); + *pDestByte = ((*pDestByte) & 0x3F) | (valType << 6); // set the value and clear other partitions for offset 0 - *pDestByte = (valType << 6); + // *pDestByte |= (valType << 6); break; case 1: - // *pDestByte = ((*pDestByte) & 0xCF) | (valType << 4); - *pDestByte |= (valType << 4); + *pDestByte = ((*pDestByte) & 0xCF) | (valType << 4); + // *pDestByte |= (valType << 4); break; case 2: - // *pDestByte = ((*pDestByte) & 0xF3) | (valType << 2); - *pDestByte |= (valType << 2); + *pDestByte = ((*pDestByte) & 0xF3) | (valType << 2); + // *pDestByte |= (valType << 2); break; case 3: - // *pDestByte = ((*pDestByte) & 0xFC) | valType; - *pDestByte |= (valType); + *pDestByte = ((*pDestByte) & 0xFC) | valType; + // *pDestByte |= (valType); break; default: TASSERT(0); @@ -417,37 +417,37 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, T // use literal value directly and not use formula to simplify the codes switch (nOffset) { case 0: - // *pDestByte = ((*pDestByte) & 0x7F) | (valType << 7); + *pDestByte = ((*pDestByte) & 0x7F) | (valType << 7); // set the value and clear other partitions for offset 0 - *pDestByte = (valType << 7); + // *pDestByte |= (valType << 7); break; case 1: - // *pDestByte = ((*pDestByte) & 0xBF) | (valType << 6); - *pDestByte |= (valType << 6); + *pDestByte = ((*pDestByte) & 0xBF) | (valType << 6); + // *pDestByte |= (valType << 6); break; case 2: - // *pDestByte = ((*pDestByte) & 0xDF) | (valType << 5); - *pDestByte |= (valType << 5); + *pDestByte = ((*pDestByte) & 0xDF) | (valType << 5); + // *pDestByte |= (valType << 5); break; case 3: - // *pDestByte = ((*pDestByte) & 0xEF) | (valType << 4); - *pDestByte |= (valType << 4); + *pDestByte = ((*pDestByte) & 0xEF) | (valType << 4); + // *pDestByte |= (valType << 4); break; case 4: - // *pDestByte = ((*pDestByte) & 0xF7) | (valType << 3); - *pDestByte |= (valType << 3); + *pDestByte = ((*pDestByte) & 0xF7) | (valType << 3); + // *pDestByte |= (valType << 3); break; case 5: - // *pDestByte = ((*pDestByte) & 0xFB) | (valType << 2); - *pDestByte |= (valType << 2); + *pDestByte = ((*pDestByte) & 0xFB) | (valType << 2); + // *pDestByte |= (valType << 2); break; case 6: - // *pDestByte = ((*pDestByte) & 0xFD) | (valType << 1); - *pDestByte |= (valType << 1); + *pDestByte = ((*pDestByte) & 0xFD) | (valType << 1); + // *pDestByte |= (valType << 1); break; case 7: - // *pDestByte = ((*pDestByte) & 0xFE) | valType; - *pDestByte |= (valType); + *pDestByte = ((*pDestByte) & 0xFE) | valType; + // *pDestByte |= (valType); break; default: TASSERT(0); @@ -656,6 +656,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { case TD_ROW_TP: #ifdef TD_SUPPORT_BITMAP pBuilder->pBitmap = tdGetBitmapAddrTp(pBuilder->pBuf, pBuilder->flen); + memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps); #endif // the primary TS key is stored separatedly len = TD_ROW_HEAD_LEN + pBuilder->flen - sizeof(TSKEY) + pBuilder->nBitmaps; @@ -665,6 +666,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { case TD_ROW_KV: #ifdef TD_SUPPORT_BITMAP pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols); + memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps); #endif len = TD_ROW_HEAD_LEN + TD_ROW_NCOLS_LEN + (pBuilder->nBoundCols - 1) * sizeof(SKvRowIdx) + pBuilder->nBoundBitmaps; // add diff --git a/include/util/tdef.h b/include/util/tdef.h index 5b863f592036ee9115b04bdcac5df4f0c22ad884..ec90dd888a3719a52035feddd91c645cd7eab419 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -199,7 +199,7 @@ typedef enum EOperatorType { } EOperatorType; typedef enum ELogicConditionType { - LOGIC_COND_TYPE_AND, + LOGIC_COND_TYPE_AND = 1, LOGIC_COND_TYPE_OR, LOGIC_COND_TYPE_NOT, } ELogicConditionType; diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index ee17de50e06ba54dafb731e389937ad3e96ecef9..cf87f57d4f3fa4b45373785be22afeed32757260 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -98,7 +98,7 @@ static FORCE_INLINE void getSTSRowAppendInfo(SSchema *pSchema, uint8_t rowType, *toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart *colIdx = schemaIdx; } else { - *toffset = idx * sizeof(SColIdx); // the offset of SColIdx + *toffset = idx * sizeof(SKvRowIdx); // the offset of SKvRowIdx *colIdx = idx; } } else { @@ -108,7 +108,7 @@ static FORCE_INLINE void getSTSRowAppendInfo(SSchema *pSchema, uint8_t rowType, *toffset = (spd->cols + schemaIdx)->toffset; *colIdx = schemaIdx; } else { - *toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SColIdx); + *toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SKvRowIdx); *colIdx = (spd->colIdxInfo + idx)->finalIdx; } } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 33b525cf3af08e7950c6d9427a625a068aa10a2d..93e56424df3b2d438a52638b4636320999df69d6 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -646,7 +646,7 @@ predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). { SToken s = getTokenFromRawExprNode(pCxt, B); SToken e = getTokenFromRawExprNode(pCxt, D); - A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D))); + A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D))); } predicate(A) ::= expression(B) IS NULL(C). { SToken s = getTokenFromRawExprNode(pCxt, B); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index ded9b5dbd165917b1055b354ef7a93295ca9441c..a6ec61c051ec7a1f847f7711fa2f845aa5d6d127 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -251,6 +251,9 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol pCol->colType = pProjCol->colType; } strcpy(pCol->colName, pExpr->aliasName); + if ('\0' == pCol->node.aliasName[0]) { + strcpy(pCol->node.aliasName, pCol->colName); + } pCol->node.resType = pExpr->resType; } @@ -381,23 +384,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { } res = (found ? DEAL_RES_CONTINUE : translateColumnWithoutPrefix(pCxt, pCol)); } - - if (DEAL_RES_ERROR == res) { - return res; - } - - if (SQL_CLAUSE_WINDOW == pCxt->currClause && QUERY_NODE_STATE_WINDOW == nodeType(pCxt->pCurrStmt->pWindow)) { - if (!IS_INTEGER_TYPE(pCol->node.resType.type)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); - } - if (COLUMN_TYPE_TAG == pCol->colType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); - } - if (TSDB_SUPER_TABLE == pCol->tableType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE); - } - } - return DEAL_RES_CONTINUE; + return res; } static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { @@ -1200,9 +1187,27 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* return TSDB_CODE_SUCCESS; } +static EDealRes checkStateExpr(SNode* pNode, void* pContext) { + if (QUERY_NODE_COLUMN == nodeType(pNode)) { + STranslateContext* pCxt = pContext; + SColumnNode* pCol = (SColumnNode*)pNode; + if (!IS_INTEGER_TYPE(pCol->node.resType.type)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); + } + if (COLUMN_TYPE_TAG == pCol->colType) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); + } + if (TSDB_SUPER_TABLE == pCol->tableType) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE); + } + } + return DEAL_RES_CONTINUE; +} + static int32_t checkStateWindow(STranslateContext* pCxt, SStateWindowNode* pState) { + nodesWalkExprPostOrder(pState->pExpr, checkStateExpr, pCxt); // todo check for "function not support for state_window" - return TSDB_CODE_SUCCESS; + return pCxt->errCode; } static int32_t checkSessionWindow(STranslateContext* pCxt, SSessionWindowNode* pSession) { diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 224d64701736fac4cf0e91eeb1baf3da46854cf0..110f4f9fb595f6cded70977bbd563c2b50ee20c7 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -3730,7 +3730,7 @@ static YYACTIONTYPE yy_reduce( { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy456); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[-5].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy456), releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); } yymsp[-5].minor.yy456 = yylhsminor.yy456; break; diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 6fcfc7df072c31bfe1927f20ced0c6958290d10f..e796d126eb213a7aa8e1b25609c85e5cce543ca2 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -77,6 +77,10 @@ static bool osdMayBeOptimized(SLogicNode* pNode) { if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) { return false; } + // todo: release after function splitting + if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) { + return false; + } if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) { return false; diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index e4c1d4100082468c69645ebb25a9d73da718b490..25457d3e411ea9b4be253409540d2e31cefe142d 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -32,6 +32,8 @@ using namespace testing; } \ } while(0); +bool g_isDump = false; + class PlannerTestBaseImpl { public: void useDb(const string& acctId, const string& db) { diff --git a/source/libs/planner/test/planTestUtil.h b/source/libs/planner/test/planTestUtil.h index 71039082f9b148936c7b44058ef8b78c93563f55..dbd14237eebb92f53319947f90e4b5af333031a5 100644 --- a/source/libs/planner/test/planTestUtil.h +++ b/source/libs/planner/test/planTestUtil.h @@ -32,4 +32,6 @@ private: std::unique_ptr impl_; }; +extern bool g_isDump; + #endif // PLAN_TEST_UTIL_H diff --git a/source/libs/planner/test/plannerTestMain.cpp b/source/libs/planner/test/plannerTestMain.cpp index 36a46ab99eb1734320dae1e4d04b3ec8056725b5..2878dc7954d234ef43c7002abacde163fe0a0671 100644 --- a/source/libs/planner/test/plannerTestMain.cpp +++ b/source/libs/planner/test/plannerTestMain.cpp @@ -18,6 +18,7 @@ #include #include "mockCatalog.h" +#include "planTestUtil.h" class PlannerEnv : public testing::Environment { public: @@ -34,8 +35,27 @@ public: virtual ~PlannerEnv() {} }; +static void parseArg(int argc, char* argv[]) { + int opt = 0; + const char *optstring = ""; + static struct option long_options[] = { + {"dump", no_argument, NULL, 'd'}, + {0, 0, 0, 0} + }; + while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { + switch (opt) { + case 'd': + g_isDump = true; + break; + default: + break; + } + } +} + int main(int argc, char* argv[]) { testing::AddGlobalTestEnvironment(new PlannerEnv()); testing::InitGoogleTest(&argc, argv); + parseArg(argc, argv); return RUN_ALL_TESTS(); }