Merge pull request #21310 from wangjiaming0909/fix/TS-3398
fix: select <expr1>, <expr1##sth else> from ... return error data whe…
This commit is contained in:
commit
5ac91597b6
|
@ -120,9 +120,9 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
|
|||
}
|
||||
|
||||
if (colNode->tableAlias[0]) {
|
||||
*len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->colName);
|
||||
*len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->node.userAlias);
|
||||
} else {
|
||||
*len += snprintf(buf + *len, bufSize - *len, "%s", colNode->colName);
|
||||
*len += snprintf(buf + *len, bufSize - *len, "%s", colNode->node.userAlias);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -2054,7 +2054,7 @@ char* nodesGetNameFromColumnNode(SNode* pNode) {
|
|||
return "NULL";
|
||||
}
|
||||
|
||||
return ((SColumnNode*)pNode)->colName;
|
||||
return ((SColumnNode*)pNode)->node.userAlias;
|
||||
}
|
||||
|
||||
int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
|
||||
|
|
|
@ -259,8 +259,19 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
|||
strcpy(pExpr->userAlias, ((SColumnNode*)pExpr)->colName);
|
||||
} else {
|
||||
int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pRawExpr->n);
|
||||
strncpy(pExpr->aliasName, pRawExpr->p, len);
|
||||
pExpr->aliasName[len] = '\0';
|
||||
|
||||
// See TS-3398.
|
||||
// Len of pRawExpr->p could be larger than len of aliasName[TSDB_COL_NAME_LEN].
|
||||
// If aliasName is truncated, hash value of aliasName could be the same.
|
||||
T_MD5_CTX ctx;
|
||||
tMD5Init(&ctx);
|
||||
tMD5Update(&ctx, (uint8_t*)pRawExpr->p, pRawExpr->n);
|
||||
tMD5Final(&ctx);
|
||||
char* p = pExpr->aliasName;
|
||||
for (uint8_t i = 0; i < tListLen(ctx.digest); ++i) {
|
||||
sprintf(p, "%02x", ctx.digest[i]);
|
||||
p += 2;
|
||||
}
|
||||
strncpy(pExpr->userAlias, pRawExpr->p, len);
|
||||
pExpr->userAlias[len] = '\0';
|
||||
}
|
||||
|
|
|
@ -827,7 +827,7 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
|
|||
strcpy(pCol->node.aliasName, pCol->colName);
|
||||
}
|
||||
if ('\0' == pCol->node.userAlias[0]) {
|
||||
strcpy(pCol->node.userAlias, pCol->colName);
|
||||
strcpy(pCol->node.userAlias, pExpr->userAlias);
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
}
|
||||
|
@ -1760,6 +1760,7 @@ static int32_t rewriteFuncToValue(STranslateContext* pCxt, char* pLiteral, SNode
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pVal->node.aliasName, ((SExprNode*)*pNode)->aliasName);
|
||||
strcpy(pVal->node.userAlias, ((SExprNode*)*pNode)->userAlias);
|
||||
pVal->node.resType = ((SExprNode*)*pNode)->resType;
|
||||
if (NULL == pLiteral) {
|
||||
pVal->isNull = true;
|
||||
|
@ -2739,6 +2740,7 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) {
|
|||
} else {
|
||||
len = snprintf(buf, sizeof(buf), "%s(%s)", pSrcFunc->functionName, pExpr->aliasName);
|
||||
strncpy(pFunc->node.aliasName, buf, TMIN(len, sizeof(pFunc->node.aliasName) - 1));
|
||||
len = snprintf(buf, sizeof(buf), "%s(%s)", pSrcFunc->functionName, pExpr->userAlias);
|
||||
strncpy(pFunc->node.userAlias, buf, TMIN(len, sizeof(pFunc->node.userAlias) - 1));
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode);
|
||||
pCol->node.resType = pToBeRewrittenExpr->resType;
|
||||
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName);
|
||||
strcpy(pCol->node.userAlias, ((SExprNode*)pExpr)->userAlias);
|
||||
strcpy(pCol->colName, ((SExprNode*)pExpr)->aliasName);
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pExpr)) {
|
||||
setColumnInfo((SFunctionNode*)pExpr, pCol);
|
||||
|
|
|
@ -906,6 +906,7 @@
|
|||
,,y,script,./test.sh -f tsim/query/partitionby.sim
|
||||
,,y,script,./test.sh -f tsim/query/tableCount.sim
|
||||
,,y,script,./test.sh -f tsim/query/nullColSma.sim
|
||||
,,y,script,./test.sh -f tsim/query/bug3398.sim
|
||||
,,y,script,./test.sh -f tsim/qnode/basic1.sim
|
||||
,,y,script,./test.sh -f tsim/snode/basic1.sim
|
||||
,,y,script,./test.sh -f tsim/mnode/basic1.sim
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
sql connect
|
||||
|
||||
print =============== create database
|
||||
sql create database test
|
||||
|
||||
print =============== create super table and child table
|
||||
sql use test
|
||||
|
||||
sql CREATE STABLE st (day timestamp, c2 int) TAGS (vin binary(32))
|
||||
|
||||
sql insert into test.g using st TAGS ("TAG1") values("2023-05-03 00:00:00.000", 1)
|
||||
sql insert into test.t using st TAGS ("TAG1") values("2023-05-03 00:00:00.000", 1)
|
||||
sql insert into test.tg using st TAGS ("TAG1") values("2023-05-03 00:00:00.000", 1)
|
||||
|
||||
sql select sum(case when t.c2 is NULL then 0 else 1 end + case when t.c2 is NULL then 0 else 1 end), sum(case when t.c2 is NULL then 0 else 1 end + case when t.c2 is NULL then 0 else 1 end + case when t.c2 is NULL then 0 else 1 end) from test.t t, test.g g, test.tg tg where t.day = g.day and t.day = tg.day and t.day between '2021-05-03' and '2023-05-04' and t.vin = 'TAG1' and t.vin = g.vin and t.vin = tg.vin group by t.day;
|
||||
|
||||
print $rows $data00 $data01
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 2.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 3.000000000 then
|
||||
return -1
|
||||
endi
|
Loading…
Reference in New Issue