-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use MD5 hash to fix aliasname not enough to hold dbname.tbname #22540
Changes from 6 commits
1190442
1a5e288
e26e0e2
d0fb485
026f61e
d2433a4
4b954c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1610,8 +1610,12 @@ static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) { | |
} | ||
|
||
// todo refact: just to mask compilation warnings | ||
static void partTagsSetAlias(char* pAlias, int32_t len, const char* pTableAlias, const char* pColName) { | ||
snprintf(pAlias, len, "%s.%s", pTableAlias, pColName); | ||
static void partTagsSetAlias(char* pAlias, const char* pTableAlias, const char* pColName) { | ||
char name[TSDB_COL_FNAME_LEN + 1] = {0}; | ||
int32_t len = snprintf(name, TSDB_COL_FNAME_LEN, "%s.%s", pTableAlias, pColName); | ||
|
||
taosCreateMD5Hash(name, len); | ||
strcpy(pAlias, name); | ||
} | ||
|
||
static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) { | ||
|
@@ -1623,7 +1627,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) { | |
snprintf(pFunc->functionName, sizeof(pFunc->functionName), "%s", pFuncName); | ||
if (QUERY_NODE_COLUMN == nodeType(pNode) && COLUMN_TYPE_TBNAME != ((SColumnNode*)pNode)->colType) { | ||
SColumnNode* pCol = (SColumnNode*)pNode; | ||
partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName); | ||
partTagsSetAlias(pFunc->node.aliasName, pCol->tableAlias, pCol->colName); | ||
} else { | ||
strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName); | ||
} | ||
|
@@ -2132,7 +2136,10 @@ static SNode* rewriteUniqueOptCreateFirstFunc(SFunctionNode* pSelectValue, SNode | |
strcpy(pFunc->node.aliasName, pSelectValue->node.aliasName); | ||
} else { | ||
int64_t pointer = (int64_t)pFunc; | ||
snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), "%s.%" PRId64 "", pFunc->functionName, pointer); | ||
char name[TSDB_FUNC_NAME_LEN + sizeof(pointer) + TSDB_NAME_DELIMITER_LEN + 1] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同理,sizeof(pointer) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
int32_t len = snprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pFunc->functionName, pointer); | ||
taosCreateMD5Hash(name, len); | ||
strncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN - 1); | ||
} | ||
int32_t code = nodesListMakeStrictAppend(&pFunc->pParameterList, nodesCloneNode(pCol)); | ||
if (TSDB_CODE_SUCCESS == code) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,7 +388,11 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex) { | |
} | ||
strcpy(pWStart->functionName, "_wstart"); | ||
int64_t pointer = (int64_t)pWStart; | ||
snprintf(pWStart->node.aliasName, sizeof(pWStart->node.aliasName), "%s.%" PRId64 "", pWStart->functionName, pointer); | ||
char name[TSDB_COL_NAME_LEN + sizeof(pointer) + TSDB_NAME_DELIMITER_LEN + 1] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同理 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
int32_t len = snprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer); | ||
taosCreateMD5Hash(name, len); | ||
strncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN - 1); | ||
|
||
int32_t code = fmGetFuncInfo(pWStart, NULL, 0); | ||
if (TSDB_CODE_SUCCESS == code) { | ||
code = nodesListStrictAppend(pFuncs, (SNode*)pWStart); | ||
|
@@ -414,7 +418,11 @@ static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) { | |
} | ||
strcpy(pWEnd->functionName, "_wend"); | ||
int64_t pointer = (int64_t)pWEnd; | ||
snprintf(pWEnd->node.aliasName, sizeof(pWEnd->node.aliasName), "%s.%" PRId64 "", pWEnd->functionName, pointer); | ||
char name[TSDB_COL_NAME_LEN + sizeof(pointer) + TSDB_NAME_DELIMITER_LEN + 1] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同理 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
int32_t len = snprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWEnd->functionName, pointer); | ||
taosCreateMD5Hash(name, len); | ||
strncpy(pWEnd->node.aliasName, name, TSDB_COL_NAME_LEN - 1); | ||
|
||
int32_t code = fmGetFuncInfo(pWEnd, NULL, 0); | ||
if (TSDB_CODE_SUCCESS == code) { | ||
code = nodesListStrictAppend(pWin->pFuncs, (SNode*)pWEnd); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import taos | ||
import sys | ||
import time | ||
import socket | ||
import os | ||
import threading | ||
|
||
from util.log import * | ||
from util.sql import * | ||
from util.cases import * | ||
from util.dnodes import * | ||
|
||
class TDTestCase: | ||
hostname = socket.gethostname() | ||
|
||
def init(self, conn, logSql, replicaVar=1): | ||
self.replicaVar = int(replicaVar) | ||
tdLog.debug(f"start to excute {__file__}") | ||
#tdSql.init(conn.cursor()) | ||
tdSql.init(conn.cursor(), logSql) # output sql.txt file | ||
|
||
def getBuildPath(self): | ||
selfPath = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
if ("community" in selfPath): | ||
projPath = selfPath[:selfPath.find("community")] | ||
else: | ||
projPath = selfPath[:selfPath.find("tests")] | ||
|
||
for root, dirs, files in os.walk(projPath): | ||
if ("taosd" in files or "taosd.exe" in files): | ||
rootRealPath = os.path.dirname(os.path.realpath(root)) | ||
if ("packaging" not in rootRealPath): | ||
buildPath = root[:len(root) - len("/build/bin")] | ||
break | ||
return buildPath | ||
|
||
def create_tables(self): | ||
tdSql.execute(f'''CREATE STABLE `s_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` | ||
(`ts` TIMESTAMP, `event_time` TIMESTAMP, `wbli` DOUBLE, `vrc` DOUBLE, `csd` DOUBLE, | ||
`oiv` DOUBLE, `tiv` DOUBLE, `flol` DOUBLE, `capacity` DOUBLE, `ispc` NCHAR(50)) TAGS | ||
(`device_identification` NCHAR(64))''') | ||
tdSql.execute(f''' CREATE TABLE `t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` | ||
USING `s_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` (`device_identification`) | ||
TAGS ("1000000000001001")''') | ||
|
||
def insert_data(self): | ||
tdLog.debug("start to insert data ............") | ||
|
||
tdSql.execute(f"INSERT INTO `t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` VALUES ('2023-08-06 17:47:35.685','2023-07-24 11:18:20.000', 17.199999999999999, 100.000000000000000, 100.000000000000000, NULL, 112.328999999999994, 132.182899999999989, 12.300000000000001, '符合条件')") | ||
tdSql.execute(f"INSERT INTO `t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` VALUES ('2023-08-06 17:47:36.239','2023-07-24 11:18:20.000', 17.199999999999999, 100.000000000000000, 100.000000000000000, NULL, 112.328999999999994, 132.182899999999989, 12.300000000000001, '符合条件')") | ||
tdSql.execute(f"INSERT INTO `t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` VALUES ('2023-08-06 17:47:37.290','2023-07-24 11:18:20.000', 17.199999999999999, 100.000000000000000, 100.000000000000000, NULL, 112.328999999999994, 132.182899999999989, 12.300000000000001, '符合条件')") | ||
tdSql.execute(f"INSERT INTO `t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` VALUES ('2023-08-06 17:47:38.414','2023-07-24 11:18:20.000', 17.199999999999999, 100.000000000000000, 100.000000000000000, NULL, 112.328999999999994, 132.182899999999989, 12.300000000000001, '符合条件')") | ||
tdSql.execute(f"INSERT INTO `t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators` VALUES ('2023-08-06 17:47:39.471','2023-07-24 11:18:20.000', 17.199999999999999, 100.000000000000000, 100.000000000000000, NULL, 112.328999999999994, 132.182899999999989, 12.300000000000001, '符合条件')") | ||
|
||
tdLog.debug("insert data ............ [OK]") | ||
|
||
def run(self): | ||
tdSql.prepare() | ||
self.create_tables() | ||
self.insert_data() | ||
tdLog.printNoPrefix("======== test TS-3821") | ||
|
||
tdSql.query(f'''select count(*),device_identification from s_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators | ||
where 1=1 and device_identification ='1000000000001001' group by device_identification;''') | ||
tdSql.checkRows(1) | ||
tdSql.checkCols(2) | ||
tdSql.checkData(0, 0, 5) | ||
tdSql.checkData(0, 1, "1000000000001001") | ||
|
||
tdSql.query(f'''select count(*),device_identification from t_1000000000001001_e8d66f7af53e4c88866efbc44252a8cd_device_technical_indicators | ||
group by device_identification;''') | ||
tdSql.checkRows(1) | ||
tdSql.checkCols(2) | ||
tdSql.checkData(0, 0, 5) | ||
tdSql.checkData(0, 1, "1000000000001001") | ||
|
||
|
||
def stop(self): | ||
tdSql.close() | ||
tdLog.success(f"{__file__} successfully executed") | ||
|
||
tdCases.addLinux(__file__, TDTestCase()) | ||
tdCases.addWindows(__file__, TDTestCase()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeof(pSrcFunc)这个大小不对,%p可能会超过的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用TSDB_POINTER_PRINT_BYTES 18, 包含16个字符表示最大8个地址字节,加上0x的两个字符。