Merge pull request #13239 from taosdata/feature/3.0_wxy
fix: problems of some function parameters with negative numbers
This commit is contained in:
commit
945ac571b5
|
@ -3384,7 +3384,7 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan
|
|||
// todo add more information about exchange operation
|
||||
int32_t type = pOperator->operatorType;
|
||||
if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE || type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN ||
|
||||
type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN) {
|
||||
*order = TSDB_ORDER_ASC;
|
||||
*scanFlag = MAIN_SCAN;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -3506,7 +3506,8 @@ int32_t aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* len
|
|||
SAggSupporter* pSup = (SAggSupporter*)POINTER_SHIFT(pOperator->info, sizeof(SOptrBasicInfo));
|
||||
int32_t size = taosHashGetSize(pSup->pResultRowHashTable);
|
||||
size_t keyLen = sizeof(uint64_t) * 2; // estimate the key length
|
||||
int32_t totalSize = sizeof(int32_t) + sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize);
|
||||
int32_t totalSize =
|
||||
sizeof(int32_t) + sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize);
|
||||
|
||||
*result = (char*)taosMemoryCalloc(1, totalSize);
|
||||
if (*result == NULL) {
|
||||
|
@ -4512,8 +4513,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
|
||||
SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table.
|
||||
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
||||
STimeWindowAggSupp twSup = {.waterMark = pTableScanNode->watermark,
|
||||
.calTrigger = pTableScanNode->triggerType, .maxTs = INT64_MIN};
|
||||
STimeWindowAggSupp twSup = {
|
||||
.waterMark = pTableScanNode->watermark, .calTrigger = pTableScanNode->triggerType, .maxTs = INT64_MIN};
|
||||
tsdbReaderT pDataReader = NULL;
|
||||
if (pHandle->vnode) {
|
||||
pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId, pTagCond);
|
||||
|
@ -4528,8 +4529,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
qDebug("%s pDataReader is not NULL", GET_TASKID(pTaskInfo));
|
||||
}
|
||||
SArray* tableIdList = extractTableIdList(pTableListInfo);
|
||||
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pDataReader, pHandle,
|
||||
tableIdList, pTableScanNode, pTaskInfo, &twSup, pTableScanNode->tsColId);
|
||||
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pDataReader, pHandle, tableIdList, pTableScanNode,
|
||||
pTaskInfo, &twSup, pTableScanNode->tsColId);
|
||||
|
||||
taosArrayDestroy(tableIdList);
|
||||
return pOperator;
|
||||
|
|
|
@ -752,18 +752,30 @@ static bool isMultiResFunc(SNode* pNode) {
|
|||
return (QUERY_NODE_COLUMN == nodeType(pParam) ? 0 == strcmp(((SColumnNode*)pParam)->colName, "*") : false);
|
||||
}
|
||||
|
||||
static EDealRes translateUnaryOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
||||
static int32_t rewriteNegativeOperator(SNode** pOp) {
|
||||
SNode* pRes = NULL;
|
||||
int32_t code = scalarCalculateConstants(*pOp, &pRes);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOp = pRes;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static EDealRes translateUnaryOperator(STranslateContext* pCxt, SOperatorNode** pOpRef) {
|
||||
SOperatorNode* pOp = *pOpRef;
|
||||
if (OP_TYPE_MINUS == pOp->opType) {
|
||||
if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pLeft))->aliasName);
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
pCxt->errCode = rewriteNegativeOperator((SNode**)pOpRef);
|
||||
} else {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
static EDealRes translateArithmeticOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
||||
|
@ -824,7 +836,9 @@ static EDealRes translateJsonOperator(STranslateContext* pCxt, SOperatorNode* pO
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
||||
static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode** pOpRef) {
|
||||
SOperatorNode* pOp = *pOpRef;
|
||||
|
||||
if (isMultiResFunc(pOp->pLeft)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pLeft))->aliasName);
|
||||
}
|
||||
|
@ -833,7 +847,7 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
|||
}
|
||||
|
||||
if (nodesIsUnaryOp(pOp)) {
|
||||
return translateUnaryOperator(pCxt, pOp);
|
||||
return translateUnaryOperator(pCxt, pOpRef);
|
||||
} else if (nodesIsArithmeticOp(pOp)) {
|
||||
return translateArithmeticOperator(pCxt, pOp);
|
||||
} else if (nodesIsComparisonOp(pOp)) {
|
||||
|
@ -992,7 +1006,7 @@ static EDealRes doTranslateExpr(SNode** pNode, void* pContext) {
|
|||
case QUERY_NODE_VALUE:
|
||||
return translateValue(pCxt, (SValueNode*)*pNode);
|
||||
case QUERY_NODE_OPERATOR:
|
||||
return translateOperator(pCxt, (SOperatorNode*)*pNode);
|
||||
return translateOperator(pCxt, (SOperatorNode**)pNode);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return translateFunction(pCxt, (SFunctionNode*)*pNode);
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
|
@ -1891,9 +1905,9 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SNodeList* pPartiti
|
|||
return translateExprList(pCxt, pPartitionByList);
|
||||
}
|
||||
|
||||
static int32_t translateWhere(STranslateContext* pCxt, SNode* pWhere) {
|
||||
static int32_t translateWhere(STranslateContext* pCxt, SNode** pWhere) {
|
||||
pCxt->currClause = SQL_CLAUSE_WHERE;
|
||||
return translateExpr(pCxt, &pWhere);
|
||||
return translateExpr(pCxt, pWhere);
|
||||
}
|
||||
|
||||
static int32_t translateFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
|
@ -1964,7 +1978,7 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
pCxt->pCurrStmt = pSelect;
|
||||
int32_t code = translateFrom(pCxt, pSelect);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateWhere(pCxt, pSelect->pWhere);
|
||||
code = translateWhere(pCxt, &pSelect->pWhere);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translatePartitionBy(pCxt, pSelect->pPartitionByList);
|
||||
|
|
|
@ -44,6 +44,8 @@ TEST_F(ParserSelectTest, constant) {
|
|||
"timestamp '2022-02-09 17:30:20', true, false, 15s FROM t1");
|
||||
|
||||
run("SELECT 123 + 45 FROM t1 WHERE 2 - 1");
|
||||
|
||||
run("SELECT * FROM t1 WHERE -2");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, expression) {
|
||||
|
@ -76,6 +78,12 @@ TEST_F(ParserSelectTest, pseudoColumnSemanticCheck) {
|
|||
run("SELECT TBNAME FROM (SELECT * FROM st1s1)", TSDB_CODE_PAR_INVALID_TBNAME, PARSER_STAGE_TRANSLATE);
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, aggFunc) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT LEASTSQUARES(c1, -1, 1) FROM t1");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, multiResFunc) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
|
|
@ -27,6 +27,14 @@ TEST_F(PlanSuperTableTest, pseudoCol) {
|
|||
run("SELECT TBNAME, tag1, tag2 FROM st1");
|
||||
}
|
||||
|
||||
TEST_F(PlanSuperTableTest, pseudoColOnChildTable) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT TBNAME FROM st1s1");
|
||||
|
||||
run("SELECT TBNAME, tag1, tag2 FROM st1s1");
|
||||
}
|
||||
|
||||
TEST_F(PlanSuperTableTest, orderBy) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
|
Loading…
Reference in New Issue