diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index f21a7380329412d18a2fbc7f41dab33439719197..cdccf0b1a17a15bb132ba4d53c2c6fda5bba9878 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1407,11 +1407,7 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, } SSchema* pColSchema = &pSchema[spd->boundColumns[colIdx] - 1]; - - if (bind->buffer_type != pColSchema->type) { - return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); - } - + if (bind->num != rowNum) { return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); } @@ -1426,6 +1422,10 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, CHECK_CODE(MemRowAppend(&pBuf, NULL, 0, ¶m)); } else { + if (bind->buffer_type != pColSchema->type) { + return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + } + int32_t colLen = pColSchema->bytes; if (IS_VAR_DATA_TYPE(pColSchema->type)) { colLen = bind->length[r]; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 322dc004e2f61dae0c1726c8d3273901fbdf3c71..6f1531bd5f3387666b4024755ffd2db875d5a040 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -547,6 +547,9 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { TSDB_DATA_TYPE_BLOB == rdt.type) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } + if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { + ((SExprNode*)pOp->pRight)->resType = ((SExprNode*)pOp->pLeft)->resType; + } pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; } else if (nodesIsJsonOp(pOp)){ diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index 2b9e3c7f39f848cdfa3bb1793962b6769e2d0b68..99c33d3165d306bd89cb1411b6de417065b182ea 100644 --- a/source/libs/scalar/inc/filterInt.h +++ b/source/libs/scalar/inc/filterInt.h @@ -215,8 +215,10 @@ typedef struct SFilterPCtx { } SFilterPCtx; typedef struct SFltTreeStat { - int32_t code; - bool scalarMode; + int32_t code; + int8_t precision; + bool scalarMode; + SFilterInfo* info; } SFltTreeStat; typedef struct SFltScalarCtx { diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 23047c293073299096afc3a0a596d0bfeb73f7aa..e24162bccbd97657d8097309dd38076c9f71f35e 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3364,6 +3364,12 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * filterGetRangeRes(prev, &tra); win->skey = tra.s; win->ekey = tra.e; + if (FILTER_GET_FLAG(tra.sflag, RANGE_FLG_EXCLUDE)) { + win->skey++; + } + if (FILTER_GET_FLAG(tra.eflag, RANGE_FLG_EXCLUDE)) { + win->ekey--; + } } filterFreeRangeCtx(prev); @@ -3492,7 +3498,40 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { + if (QUERY_NODE_VALUE == nodeType(*pNode)) { + if (!FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP)) { + return DEAL_RES_CONTINUE; + } + + SValueNode *valueNode = (SValueNode *)*pNode; + if (TSDB_DATA_TYPE_BINARY != valueNode->node.resType.type) { + return DEAL_RES_CONTINUE; + } + +#if 0 + if (stat->precision < 0) { + //TODO + return DEAL_RES_CONTINUE; + } + + char *timeStr = valueNode->datum.p; + if (taosParseTime(valueNode->datum.p, &valueNode->datum.i, valueNode->node.resType.bytes, stat->precision, tsDaylight) != + TSDB_CODE_SUCCESS) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); + } + TODO +#else + return DEAL_RES_CONTINUE; +#endif + } + + if (QUERY_NODE_COLUMN == nodeType(*pNode)) { + SColumnNode *colNode = (SColumnNode *)*pNode; + stat->precision = colNode->node.resType.precision; + return DEAL_RES_CONTINUE; + } + + if (QUERY_NODE_NODE_LIST == nodeType(*pNode)) { return DEAL_RES_CONTINUE; } @@ -3656,16 +3695,19 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) info = *pInfo; info->options = options; - SFltTreeStat stat1 = {0}; - FLT_ERR_JRET(fltReviseNodes(info, &pNode, &stat1)); + SFltTreeStat stat = {0}; + stat.precision = -1; + stat.info = info; + + FLT_ERR_JRET(fltReviseNodes(info, &pNode, &stat)); - info->scalarMode = stat1.scalarMode; + info->scalarMode = stat.scalarMode; if (!info->scalarMode) { FLT_ERR_JRET(fltInitFromNode(pNode, info, options)); } else { info->sclCtx.node = pNode; - FLT_ERR_JRET(fltOptimizeNodes(info, &info->sclCtx.node, &stat1)); + FLT_ERR_JRET(fltOptimizeNodes(info, &info->sclCtx.node, &stat)); } return code; diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 42998aba003217dcfa42dff2fe3203a299529425..9670dc0180a72ecaadc6bfc95e4eee5ed38ee220 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -242,7 +242,7 @@ TEST(timerangeTest, greater) { int32_t code = filterGetTimeRange(opNode1, &win, &isStrict); ASSERT_EQ(code, 0); ASSERT_EQ(isStrict, true); - ASSERT_EQ(win.skey, tsmall); + ASSERT_EQ(win.skey, tsmall+1); ASSERT_EQ(win.ekey, INT64_MAX); //filterFreeInfo(filter); nodesDestroyNode(opNode1); @@ -265,6 +265,37 @@ TEST(timerangeTest, greater_and_lower) { flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); + //SFilterInfo *filter = NULL; + //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); + //ASSERT_EQ(code, 0); + STimeWindow win = {0}; + bool isStrict = false; + int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); + ASSERT_EQ(isStrict, true); + ASSERT_EQ(code, 0); + ASSERT_EQ(win.skey, tsmall+1); + ASSERT_EQ(win.ekey, tbig-1); + //filterFreeInfo(filter); + nodesDestroyNode(logicNode); +} + +TEST(timerangeTest, greater_equal_and_lower_equal) { + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; + bool eRes[5] = {false, false, true, true, true}; + SScalarParam res = {0}; + int64_t tsmall = 222, tbig = 333; + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); + flttMakeOpNode(&opNode1, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig); + flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval); + SNode *list[2] = {0}; + list[0] = opNode1; + list[1] = opNode2; + + flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); + //SFilterInfo *filter = NULL; //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); //ASSERT_EQ(code, 0); @@ -279,6 +310,7 @@ TEST(timerangeTest, greater_and_lower) { nodesDestroyNode(logicNode); } + TEST(timerangeTest, greater_and_lower_not_strict) { SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL; bool eRes[5] = {false, false, true, true, true}; @@ -321,8 +353,8 @@ TEST(timerangeTest, greater_and_lower_not_strict) { int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict); ASSERT_EQ(isStrict, false); ASSERT_EQ(code, 0); - ASSERT_EQ(win.skey, tsmall1); - ASSERT_EQ(win.ekey, tbig2); + ASSERT_EQ(win.skey, tsmall1+1); + ASSERT_EQ(win.ekey, tbig2-1); //filterFreeInfo(filter); nodesDestroyNode(logicNode1); }