Merge pull request #25790 from taosdata/fix/TD-30064

fix:remove dot from child table in stream
This commit is contained in:
Haojun Liao 2024-05-16 09:21:22 +08:00 committed by GitHub
commit f8eb217c75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 11 deletions

View File

@ -2411,13 +2411,24 @@ _end:
void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId) { void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId) {
char tmp[TSDB_TABLE_NAME_LEN] = {0}; char tmp[TSDB_TABLE_NAME_LEN] = {0};
if (stbName == NULL) { if (stbName == NULL){
snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%" PRIu64, groupId); snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%"PRIu64, groupId);
} else { }else{
snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%s_%" PRIu64, stbName, groupId); int32_t i = strlen(stbName) - 1;
for(; i >= 0; i--){
if (stbName[i] == '.'){
break;
}
}
snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%s_%"PRIu64, stbName + i + 1, groupId);
} }
ctbName[TSDB_TABLE_NAME_LEN - strlen(tmp) - 1] = 0; // put stbname + groupId to the end ctbName[TSDB_TABLE_NAME_LEN - strlen(tmp) - 1] = 0; // put stbname + groupId to the end
strcat(ctbName, tmp); strcat(ctbName, tmp);
for(int i = 0; i < strlen(ctbName); i++){
if(ctbName[i] == '.'){
ctbName[i] = '_';
}
}
} }
// auto stream subtable name starts with 't_', followed by the first segment of MD5 digest for group vals. // auto stream subtable name starts with 't_', followed by the first segment of MD5 digest for group vals.

View File

@ -20,6 +20,7 @@
#include <tglobal.h> #include <tglobal.h>
#include <tmsg.h> #include <tmsg.h>
#include <iostream> #include <iostream>
#include <tdatablock.h>
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"
@ -475,6 +476,45 @@ TEST(testCase, AllNormTest) {
taosMemoryFree(pTSchema); taosMemoryFree(pTSchema);
} }
TEST(testCase, StreamAllNormTest) {
char ctbName[TSDB_TABLE_NAME_LEN] = {0};
uint64_t groupId = 12345;
buildCtbNameAddGroupId(NULL, ctbName, groupId);
ASSERT_STREQ("_12345", ctbName);
}
TEST(testCase, StreamWithStbName) {
char stbName[] = "1.table.stb";
char ctbName[TSDB_TABLE_NAME_LEN] = {0};
uint64_t groupId = 12345;
buildCtbNameAddGroupId(stbName, ctbName, groupId);
ASSERT_STREQ("_stb_12345", ctbName);
}
TEST(testCase, StreamWithoutDotInStbName) {
char stbName[] = "table";
char ctbName[TSDB_TABLE_NAME_LEN] = {0};
uint64_t groupId = 12345;
buildCtbNameAddGroupId(stbName, ctbName, groupId);
ASSERT_STREQ("_table_12345", ctbName);
}
TEST(testCase, StreamWithoutDotInStbName2) {
char stbName[] = "";
char ctbName[TSDB_TABLE_NAME_LEN] = {0};
uint64_t groupId = 12345;
buildCtbNameAddGroupId(stbName, ctbName, groupId);
ASSERT_STREQ("__12345", ctbName);
}
#if 1 #if 1
TEST(testCase, NoneTest) { TEST(testCase, NoneTest) {
const static int nCols = 14; const static int nCols = 14;

View File

@ -87,7 +87,7 @@ class TDTestCase:
tdSql.execute(f'insert into t2 using st tags(2) values(now, 1) (now+1s, 2)') tdSql.execute(f'insert into t2 using st tags(2) values(now, 1) (now+1s, 2)')
tdSql.execute(f'insert into t3 using st tags(3) values(now, 1) (now+1s, 2)') tdSql.execute(f'insert into t3 using st tags(3) values(now, 1) (now+1s, 2)')
tdSql.execute("create stream stream1 fill_history 1 into sta subtable(concat('new-', tname)) AS SELECT " tdSql.execute("create stream stream1 fill_history 1 into sta subtable(concat('nee.w-', tname)) AS SELECT "
"_wstart, count(*), avg(i) FROM st PARTITION BY tbname tname INTERVAL(1m)", show=True) "_wstart, count(*), avg(i) FROM st PARTITION BY tbname tname INTERVAL(1m)", show=True)
tdSql.execute("create stream stream2 fill_history 1 into stb subtable(concat('new-', tname)) AS SELECT " tdSql.execute("create stream stream2 fill_history 1 into stb subtable(concat('new-', tname)) AS SELECT "
@ -97,25 +97,25 @@ class TDTestCase:
tdSql.query("select * from sta") tdSql.query("select * from sta")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select tbname from sta order by tbname") tdSql.query("select tbname from sta order by tbname")
if not tdSql.getData(0, 0).startswith('new-t1_1.d1.sta_'): if not tdSql.getData(0, 0).startswith('nee_w-t1_sta_'):
tdLog.exit("error1") tdLog.exit("error1")
if not tdSql.getData(1, 0).startswith('new-t2_1.d1.sta_'): if not tdSql.getData(1, 0).startswith('nee_w-t2_sta_'):
tdLog.exit("error2") tdLog.exit("error2")
if not tdSql.getData(2, 0).startswith('new-t3_1.d1.sta_'): if not tdSql.getData(2, 0).startswith('nee_w-t3_sta_'):
tdLog.exit("error3") tdLog.exit("error3")
tdSql.query("select * from stb") tdSql.query("select * from stb")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.query("select tbname from stb order by tbname") tdSql.query("select tbname from stb order by tbname")
if not tdSql.getData(0, 0).startswith('new-t1_1.d1.stb_'): if not tdSql.getData(0, 0).startswith('new-t1_stb_'):
tdLog.exit("error4") tdLog.exit("error4")
if not tdSql.getData(1, 0).startswith('new-t2_1.d1.stb_'): if not tdSql.getData(1, 0).startswith('new-t2_stb_'):
tdLog.exit("error5") tdLog.exit("error5")
if not tdSql.getData(2, 0).startswith('new-t3_1.d1.stb_'): if not tdSql.getData(2, 0).startswith('new-t3_stb_'):
tdLog.exit("error6") tdLog.exit("error6")
# run # run