Merge pull request #21152 from taosdata/fix/TS-3303
fix:[TS-3303]use stable name + child table name as key to save uid to…
This commit is contained in:
commit
db0ad95649
|
@ -169,6 +169,7 @@ typedef struct {
|
|||
int32_t uid; // used for automatic create child table
|
||||
|
||||
SHashObj *childTables;
|
||||
SHashObj *tableUids;
|
||||
SHashObj *superTables;
|
||||
SHashObj *pVgHash;
|
||||
|
||||
|
@ -242,6 +243,7 @@ int8_t smlGetTsTypeByLen(int32_t len);
|
|||
SSmlTableInfo* smlBuildTableInfo(int numRows, const char* measure, int32_t measureLen);
|
||||
SSmlSTableMeta* smlBuildSTableMeta(bool isDataFormat);
|
||||
int32_t smlSetCTableName(SSmlTableInfo *oneTable);
|
||||
void getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo);
|
||||
STableMeta* smlGetMeta(SSmlHandle *info, const void* measure, int32_t measureLen);
|
||||
int32_t is_same_child_table_telnet(const void *a, const void *b);
|
||||
int64_t smlParseOpenTsdbTime(SSmlHandle *info, const char *data, int32_t len);
|
||||
|
|
|
@ -195,6 +195,20 @@ int32_t smlSetCTableName(SSmlTableInfo *oneTable) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo){
|
||||
char key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
|
||||
size_t nLen = strlen(tinfo->childTableName);
|
||||
memcpy(key, currElement->measure, currElement->measureLen);
|
||||
memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
|
||||
void *uid = taosHashGet(info->tableUids, key, currElement->measureLen + 1 + nLen); // use \0 as separator for stable name and child table name
|
||||
if (uid == NULL) {
|
||||
tinfo->uid = info->uid++;
|
||||
taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
|
||||
}else{
|
||||
tinfo->uid = *(uint64_t*)uid;
|
||||
}
|
||||
}
|
||||
|
||||
SSmlSTableMeta *smlBuildSTableMeta(bool isDataFormat) {
|
||||
SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
|
||||
if (!meta) {
|
||||
|
@ -1142,6 +1156,7 @@ void smlDestroyInfo(SSmlHandle *info) {
|
|||
taosHashCleanup(info->pVgHash);
|
||||
taosHashCleanup(info->childTables);
|
||||
taosHashCleanup(info->superTables);
|
||||
taosHashCleanup(info->tableUids);
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
|
||||
cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
|
||||
|
@ -1192,6 +1207,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
|
|||
|
||||
info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
|
||||
info->id = smlGenId();
|
||||
|
@ -1202,7 +1218,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
|
|||
info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
|
||||
info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
|
||||
|
||||
if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables) {
|
||||
if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables || NULL == info->tableUids) {
|
||||
uError("create SSmlHandle failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -1428,6 +1444,7 @@ int32_t smlClearForRerun(SSmlHandle *info) {
|
|||
|
||||
taosHashClear(info->childTables);
|
||||
taosHashClear(info->superTables);
|
||||
taosHashClear(info->tableUids);
|
||||
|
||||
if (!info->dataFormat) {
|
||||
if (unlikely(info->lines != NULL)) {
|
||||
|
|
|
@ -778,7 +778,7 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo
|
|||
tinfo->tags = taosArrayDup(preLineKV, NULL);
|
||||
|
||||
smlSetCTableName(tinfo);
|
||||
tinfo->uid = info->uid++;
|
||||
getTableUid(info, elements, tinfo);
|
||||
if (info->dataFormat) {
|
||||
info->currSTableMeta->uid = tinfo->uid;
|
||||
tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
|
||||
|
|
|
@ -312,7 +312,7 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
|
|||
}
|
||||
|
||||
smlSetCTableName(tinfo);
|
||||
tinfo->uid = info->uid++;
|
||||
getTableUid(info, currElement, tinfo);
|
||||
if (info->dataFormat) {
|
||||
info->currSTableMeta->uid = tinfo->uid;
|
||||
tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
|
||||
|
|
|
@ -206,7 +206,7 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
tinfo->tags = taosArrayDup(preLineKV, NULL);
|
||||
|
||||
smlSetCTableName(tinfo);
|
||||
tinfo->uid = info->uid++;
|
||||
getTableUid(info, elements, tinfo);
|
||||
if (info->dataFormat) {
|
||||
info->currSTableMeta->uid = tinfo->uid;
|
||||
tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
|
||||
|
|
|
@ -34,6 +34,9 @@ class TDTestCase:
|
|||
if ret != 0:
|
||||
tdLog.info("sml_test ret != 0")
|
||||
|
||||
tdSql.query(f"select * from ts3303.stb2")
|
||||
tdSql.query(f"select * from ts3303.meters")
|
||||
|
||||
# tdSql.execute('use sml_db')
|
||||
tdSql.query(f"select * from {dbname}.t_b7d815c9222ca64cdf2614c61de8f211")
|
||||
tdSql.checkRows(1)
|
||||
|
|
|
@ -1159,6 +1159,57 @@ int sml_td23881_Test() {
|
|||
return code;
|
||||
}
|
||||
|
||||
int sml_ts3303_Test() {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
||||
TAOS_RES *pRes = taos_query(taos, "drop database if exists ts3303");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "create database if not exists ts3303");
|
||||
taos_free_result(pRes);
|
||||
|
||||
const char *sql[] = {
|
||||
"stb2,t1=1,dataModelName=t0 f1=283i32 1632299372000",
|
||||
"stb2,t1=1,dataModelName=t0 f1=106i32 1632299378000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=144i32 1629716944000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=125i32 1629717012000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=144i32 1629717012000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=107i32 1629717013000",
|
||||
"stb2,t1=6,dataModelName=t0 f1=154i32 1629717140000",
|
||||
"stb2,t1=6,dataModelName=t0 f1=93i32 1629717140000",
|
||||
"stb2,t1=6,dataModelName=t0 f1=134i32 1629717140000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=73i32 1629717140000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=83i32 1629717140000",
|
||||
"stb2,t1=4,dataModelName=t0 f1=72i32 1629717140000",
|
||||
};
|
||||
|
||||
const char *sql1[] = {
|
||||
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833339000000",
|
||||
"meters,groupid=2,location=California.LosAngeles current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833339000000",
|
||||
};
|
||||
|
||||
pRes = taos_query(taos, "use ts3303");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_schemaless_insert_ttl(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL,
|
||||
TSDB_SML_TIMESTAMP_MILLI_SECONDS, 20);
|
||||
|
||||
int code = taos_errno(pRes);
|
||||
printf("%s result0:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT(code == 0);
|
||||
|
||||
pRes = taos_schemaless_insert_ttl(taos, (char **)sql1, sizeof(sql1) / sizeof(sql1[0]), TSDB_SML_LINE_PROTOCOL,
|
||||
TSDB_SML_TIMESTAMP_NANO_SECONDS, 20);
|
||||
|
||||
printf("%s result1:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(taos);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int sml_ttl_Test() {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
||||
|
@ -1336,6 +1387,9 @@ int main(int argc, char *argv[]) {
|
|||
ASSERT(!ret);
|
||||
ret = sml_ts2385_Test(); // this test case need config sml table name using ./sml_test config_file
|
||||
ASSERT(!ret);
|
||||
ret = sml_ts3303_Test(); // this test case need config sml table name using ./sml_test config_file
|
||||
ASSERT(!ret);
|
||||
|
||||
// for(int i = 0; i < sizeof(str)/sizeof(str[0]); i++){
|
||||
// printf("str:%s \t %d\n", str[i], smlCalTypeSum(str[i], strlen(str[i])));
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue