diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 1c63174bf6..1c0b696aaa 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -2411,13 +2411,24 @@ _end: void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId) { char tmp[TSDB_TABLE_NAME_LEN] = {0}; - if (stbName == NULL) { - snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%" PRIu64, groupId); - } else { - snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%s_%" PRIu64, stbName, groupId); + if (stbName == NULL){ + snprintf(tmp, TSDB_TABLE_NAME_LEN, "_%"PRIu64, groupId); + }else{ + 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 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. diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index 2dfa706728..e8b7b132f2 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" @@ -475,6 +476,45 @@ TEST(testCase, AllNormTest) { 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 TEST(testCase, NoneTest) { const static int nCols = 14; diff --git a/tests/system-test/8-stream/stream_basic.py b/tests/system-test/8-stream/stream_basic.py index c32f9a3166..2067c2395e 100644 --- a/tests/system-test/8-stream/stream_basic.py +++ b/tests/system-test/8-stream/stream_basic.py @@ -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 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) 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.checkRows(3) 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") - 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") - 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") tdSql.query("select * from stb") tdSql.checkRows(3) 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") - 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") - 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") # run