feat:get child table name in tmq meta
This commit is contained in:
parent
824d3db96b
commit
2b442621e8
|
@ -97,14 +97,14 @@ int32_t init_env() {
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes =
|
pRes =
|
||||||
taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int)");
|
taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 nchar(8), t4 bool)");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000)");
|
pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000, \"ttt\", true)");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -118,14 +118,14 @@ int32_t init_env() {
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(pConn, "create table if not exists ct1 using st1 tags(2000)");
|
pRes = taos_query(pConn, "create table if not exists ct1 using st1(t1) tags(2000)");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create child table ct1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create child table ct1, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(pConn, "create table if not exists ct2 using st1 tags(NULL)");
|
pRes = taos_query(pConn, "create table if not exists ct2 using st1(t1) tags(NULL)");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create child table ct2, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create child table ct2, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -139,7 +139,7 @@ int32_t init_env() {
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(pConn, "create table if not exists ct3 using st1 tags(3000)");
|
pRes = taos_query(pConn, "create table if not exists ct3 using st1(t1) tags(3000)");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create child table ct3, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create child table ct3, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -97,7 +97,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
|
||||||
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
|
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
|
||||||
int32_t tTagToValArray(const STag *pTag, SArray **ppArray);
|
int32_t tTagToValArray(const STag *pTag, SArray **ppArray);
|
||||||
void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
|
void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
|
||||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf, const char* colName);
|
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf);
|
||||||
|
|
||||||
// STRUCT =================
|
// STRUCT =================
|
||||||
struct STColumn {
|
struct STColumn {
|
||||||
|
|
|
@ -1968,8 +1968,9 @@ typedef struct SVCreateTbReq {
|
||||||
int8_t type;
|
int8_t type;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
char* name;
|
char* name; // super table name
|
||||||
tb_uid_t suid;
|
tb_uid_t suid;
|
||||||
|
SArray* tagName;
|
||||||
uint8_t* pTag;
|
uint8_t* pTag;
|
||||||
} ctb;
|
} ctb;
|
||||||
struct {
|
struct {
|
||||||
|
@ -1987,6 +1988,7 @@ static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
|
||||||
if (req->type == TSDB_CHILD_TABLE) {
|
if (req->type == TSDB_CHILD_TABLE) {
|
||||||
taosMemoryFreeClear(req->ctb.pTag);
|
taosMemoryFreeClear(req->ctb.pTag);
|
||||||
taosMemoryFreeClear(req->ctb.name);
|
taosMemoryFreeClear(req->ctb.name);
|
||||||
|
taosArrayDestroy(req->ctb.tagName);
|
||||||
} else if (req->type == TSDB_NORMAL_TABLE) {
|
} else if (req->type == TSDB_NORMAL_TABLE) {
|
||||||
taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
|
taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2074,7 +2074,7 @@ static char *processAlterStb(SMqMetaRsp *metaRsp){
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *buildCreateCTableJson(STag* pTag, char* sname, char* name, int64_t id){
|
static char *buildCreateCTableJson(STag* pTag, char* sname, char* name, SArray* tagName, int64_t id){
|
||||||
char* string = NULL;
|
char* string = NULL;
|
||||||
SArray* pTagVals = NULL;
|
SArray* pTagVals = NULL;
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
|
@ -2112,8 +2112,9 @@ static char *buildCreateCTableJson(STag* pTag, char* sname, char* name, int64_t
|
||||||
cJSON* tag = cJSON_CreateObject();
|
cJSON* tag = cJSON_CreateObject();
|
||||||
STagVal* pTagVal = taosArrayGet(pTagVals, 0);
|
STagVal* pTagVal = taosArrayGet(pTagVals, 0);
|
||||||
|
|
||||||
// cJSON* tname = cJSON_CreateString(pTagVal->colName);
|
char* ptname = taosArrayGet(tagName, 0);
|
||||||
// cJSON_AddItemToObject(tag, "name", tname);
|
cJSON* tname = cJSON_CreateString(ptname);
|
||||||
|
cJSON_AddItemToObject(tag, "name", tname);
|
||||||
// cJSON* cid_ = cJSON_CreateString("");
|
// cJSON* cid_ = cJSON_CreateString("");
|
||||||
// cJSON_AddItemToObject(tag, "cid", cid_);
|
// cJSON_AddItemToObject(tag, "cid", cid_);
|
||||||
cJSON* ttype = cJSON_CreateNumber(TSDB_DATA_TYPE_JSON);
|
cJSON* ttype = cJSON_CreateNumber(TSDB_DATA_TYPE_JSON);
|
||||||
|
@ -2130,8 +2131,11 @@ static char *buildCreateCTableJson(STag* pTag, char* sname, char* name, int64_t
|
||||||
|
|
||||||
cJSON* tag = cJSON_CreateObject();
|
cJSON* tag = cJSON_CreateObject();
|
||||||
|
|
||||||
cJSON* cid = cJSON_CreateNumber(pTagVal->cid);
|
char* ptname = taosArrayGet(tagName, i);
|
||||||
cJSON_AddItemToObject(tag, "cid", cid);
|
cJSON* tname = cJSON_CreateString(ptname);
|
||||||
|
cJSON_AddItemToObject(tag, "name", tname);
|
||||||
|
// cJSON* cid = cJSON_CreateNumber(pTagVal->cid);
|
||||||
|
// cJSON_AddItemToObject(tag, "cid", cid);
|
||||||
cJSON* ttype = cJSON_CreateNumber(pTagVal->type);
|
cJSON* ttype = cJSON_CreateNumber(pTagVal->type);
|
||||||
cJSON_AddItemToObject(tag, "type", ttype);
|
cJSON_AddItemToObject(tag, "type", ttype);
|
||||||
|
|
||||||
|
@ -2175,7 +2179,7 @@ static char *processCreateTable(SMqMetaRsp *metaRsp){
|
||||||
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
||||||
pCreateReq = req.pReqs + iReq;
|
pCreateReq = req.pReqs + iReq;
|
||||||
if(pCreateReq->type == TSDB_CHILD_TABLE){
|
if(pCreateReq->type == TSDB_CHILD_TABLE){
|
||||||
string = buildCreateCTableJson((STag*)pCreateReq->ctb.pTag, pCreateReq->ctb.name, pCreateReq->name, pCreateReq->uid);
|
string = buildCreateCTableJson((STag*)pCreateReq->ctb.pTag, pCreateReq->ctb.name, pCreateReq->name, pCreateReq->ctb.tagName, pCreateReq->uid);
|
||||||
}else if(pCreateReq->type == TSDB_NORMAL_TABLE){
|
}else if(pCreateReq->type == TSDB_NORMAL_TABLE){
|
||||||
string = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE);
|
string = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4943,6 +4943,12 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
|
||||||
if (tEncodeCStr(pCoder, pReq->ctb.name) < 0) return -1;
|
if (tEncodeCStr(pCoder, pReq->ctb.name) < 0) return -1;
|
||||||
if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
|
if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
|
||||||
if (tEncodeTag(pCoder, (const STag *)pReq->ctb.pTag) < 0) return -1;
|
if (tEncodeTag(pCoder, (const STag *)pReq->ctb.pTag) < 0) return -1;
|
||||||
|
int32_t len = taosArrayGetSize(pReq->ctb.tagName);
|
||||||
|
if (tEncodeI32(pCoder, len) < 0) return -1;
|
||||||
|
for (int32_t i = 0; i < len; i++){
|
||||||
|
char* name = taosArrayGet(pReq->ctb.tagName, i);
|
||||||
|
if (tEncodeCStr(pCoder, name) < 0) return -1;
|
||||||
|
}
|
||||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||||
if (tEncodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
|
if (tEncodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -4973,6 +4979,15 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
||||||
if (tDecodeCStr(pCoder, &pReq->ctb.name) < 0) return -1;
|
if (tDecodeCStr(pCoder, &pReq->ctb.name) < 0) return -1;
|
||||||
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
|
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
|
||||||
if (tDecodeTag(pCoder, (STag **)&pReq->ctb.pTag) < 0) return -1;
|
if (tDecodeTag(pCoder, (STag **)&pReq->ctb.pTag) < 0) return -1;
|
||||||
|
int32_t len = 0;
|
||||||
|
if (tDecodeI32(pCoder, &len) < 0) return -1;
|
||||||
|
pReq->ctb.tagName = taosArrayInit(len, TSDB_COL_NAME_LEN);
|
||||||
|
if(pReq->ctb.tagName == NULL) return -1;
|
||||||
|
for (int32_t i = 0; i < len; i++){
|
||||||
|
char *name = NULL;
|
||||||
|
if (tDecodeCStr(pCoder, &name) < 0) return -1;
|
||||||
|
taosArrayPush(pReq->ctb.tagName, name);
|
||||||
|
}
|
||||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||||
if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
|
if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -163,6 +163,7 @@ typedef struct SSdbRow {
|
||||||
ESdbType type;
|
ESdbType type;
|
||||||
ESdbStatus status;
|
ESdbStatus status;
|
||||||
int32_t refCount;
|
int32_t refCount;
|
||||||
|
int64_t forAlign;
|
||||||
char pObj[];
|
char pObj[];
|
||||||
} SSdbRow;
|
} SSdbRow;
|
||||||
|
|
||||||
|
|
|
@ -732,12 +732,13 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTag, int64_t suid, const char* sname) {
|
static void buildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTag, int64_t suid, const char* sname, SArray* tagName) {
|
||||||
pTbReq->type = TD_CHILD_TABLE;
|
pTbReq->type = TD_CHILD_TABLE;
|
||||||
pTbReq->name = strdup(tname);
|
pTbReq->name = strdup(tname);
|
||||||
pTbReq->ctb.suid = suid;
|
pTbReq->ctb.suid = suid;
|
||||||
if(sname) pTbReq->ctb.name = strdup(sname);
|
if(sname) pTbReq->ctb.name = strdup(sname);
|
||||||
pTbReq->ctb.pTag = (uint8_t*)pTag;
|
pTbReq->ctb.pTag = (uint8_t*)pTag;
|
||||||
|
pTbReq->ctb.tagName = taosArrayDup(tagName);
|
||||||
pTbReq->commentLen = -1;
|
pTbReq->commentLen = -1;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -936,6 +937,7 @@ static int32_t parseTagToken(char** end, SToken* pToken, SSchema* pSchema, int16
|
||||||
static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint8_t precision, const char* tName) {
|
static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint8_t precision, const char* tName) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SArray* pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal));
|
SArray* pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal));
|
||||||
|
SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||||
SToken sToken;
|
SToken sToken;
|
||||||
bool isParseBindParam = false;
|
bool isParseBindParam = false;
|
||||||
bool isJson = false;
|
bool isJson = false;
|
||||||
|
@ -965,6 +967,10 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
||||||
taosMemoryFree(tmpTokenBuf);
|
taosMemoryFree(tmpTokenBuf);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isNullStr(&sToken)) {
|
||||||
|
taosArrayPush(tagName, pTagSchema->name);
|
||||||
|
}
|
||||||
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||||
if (sToken.n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
if (sToken.n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||||
code = buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", sToken.z);
|
code = buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", sToken.z);
|
||||||
|
@ -974,7 +980,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
||||||
if (isNullStr(&sToken)) {
|
if (isNullStr(&sToken)) {
|
||||||
code = tTagNew(pTagVals, 1, true, &pTag);
|
code = tTagNew(pTagVals, 1, true, &pTag);
|
||||||
} else {
|
} else {
|
||||||
code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg, pTagSchema->name);
|
code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg);
|
||||||
}
|
}
|
||||||
taosMemoryFree(tmpTokenBuf);
|
taosMemoryFree(tmpTokenBuf);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1004,7 +1010,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCreateTbReq(&pCxt->createTblReq, tName, pTag, pCxt->pTableMeta->suid, pCxt->sTableName);
|
buildCreateTbReq(&pCxt->createTblReq, tName, pTag, pCxt->pTableMeta->suid, pCxt->sTableName, tagName);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
|
for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
|
||||||
|
@ -1014,6 +1020,7 @@ end:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pTagVals);
|
taosArrayDestroy(pTagVals);
|
||||||
|
taosArrayDestroy(tagName);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1798,6 +1805,11 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||||
|
if (!tagName) {
|
||||||
|
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
||||||
|
|
||||||
|
@ -1814,6 +1826,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
||||||
colLen = bind[c].length[0];
|
colLen = bind[c].length[0];
|
||||||
}
|
}
|
||||||
|
taosArrayPush(tagName, pTagSchema->name);
|
||||||
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||||
if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||||
code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bind[c].buffer);
|
code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bind[c].buffer);
|
||||||
|
@ -1823,7 +1836,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
isJson = true;
|
isJson = true;
|
||||||
char* tmp = taosMemoryCalloc(1, colLen + 1);
|
char* tmp = taosMemoryCalloc(1, colLen + 1);
|
||||||
memcpy(tmp, bind[c].buffer, colLen);
|
memcpy(tmp, bind[c].buffer, colLen);
|
||||||
code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf, pTagSchema->name);
|
code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf);
|
||||||
taosMemoryFree(tmp);
|
taosMemoryFree(tmp);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -1867,7 +1880,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
}
|
}
|
||||||
|
|
||||||
SVCreateTbReq tbReq = {0};
|
SVCreateTbReq tbReq = {0};
|
||||||
buildCreateTbReq(&tbReq, tName, pTag, suid, sTableName);
|
buildCreateTbReq(&tbReq, tName, pTag, suid, sTableName, tagName);
|
||||||
code = buildCreateTbMsg(pDataBlock, &tbReq);
|
code = buildCreateTbMsg(pDataBlock, &tbReq);
|
||||||
tdDestroySVCreateTbReq(&tbReq);
|
tdDestroySVCreateTbReq(&tbReq);
|
||||||
|
|
||||||
|
@ -1879,6 +1892,7 @@ end:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pTagArray);
|
taosArrayDestroy(pTagArray);
|
||||||
|
taosArrayDestroy(tagName);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2219,17 +2233,22 @@ static int32_t smlBoundColumnData(SArray* cols, SParsedDataColInfo* pColList, SS
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* pSchema, STag** ppTag, SMsgBuf* msg) {
|
static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* pSchema, STag** ppTag, SArray** tagName, SMsgBuf* msg) {
|
||||||
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
||||||
if (!pTagArray) {
|
if (!pTagArray) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
*tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||||
|
if (!*tagName) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
for (int i = 0; i < tags->numOfBound; ++i) {
|
for (int i = 0; i < tags->numOfBound; ++i) {
|
||||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[i]];
|
SSchema* pTagSchema = &pSchema[tags->boundColumns[i]];
|
||||||
SSmlKv* kv = taosArrayGetP(cols, i);
|
SSmlKv* kv = taosArrayGetP(cols, i);
|
||||||
|
|
||||||
|
taosArrayPush(*tagName, pTagSchema->name);
|
||||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||||
// strcpy(val.colName, pTagSchema->name);
|
// strcpy(val.colName, pTagSchema->name);
|
||||||
if (pTagSchema->type == TSDB_DATA_TYPE_BINARY) {
|
if (pTagSchema->type == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
@ -2288,12 +2307,16 @@ int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
STag* pTag = NULL;
|
STag* pTag = NULL;
|
||||||
ret = smlBuildTagRow(tags, &smlHandle->tableExecHandle.tags, pTagsSchema, &pTag, &pBuf);
|
SArray* tagName = NULL;
|
||||||
|
ret = smlBuildTagRow(tags, &smlHandle->tableExecHandle.tags, pTagsSchema, &pTag, &tagName, &pBuf);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
taosArrayDestroy(tagName);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCreateTbReq(&smlHandle->tableExecHandle.createTblReq, tableName, pTag, pTableMeta->suid, NULL);
|
buildCreateTbReq(&smlHandle->tableExecHandle.createTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName);
|
||||||
|
taosArrayDestroy(tagName);
|
||||||
|
|
||||||
smlHandle->tableExecHandle.createTblReq.ctb.name = taosMemoryMalloc(sTableNameLen + 1);
|
smlHandle->tableExecHandle.createTblReq.ctb.name = taosMemoryMalloc(sTableNameLen + 1);
|
||||||
memcpy(smlHandle->tableExecHandle.createTblReq.ctb.name, sTableName, sTableNameLen);
|
memcpy(smlHandle->tableExecHandle.createTblReq.ctb.name, sTableName, sTableNameLen);
|
||||||
smlHandle->tableExecHandle.createTblReq.ctb.name[sTableNameLen] = 0;
|
smlHandle->tableExecHandle.createTblReq.ctb.name[sTableNameLen] = 0;
|
||||||
|
|
|
@ -5263,6 +5263,8 @@ static void destroyCreateTbReqBatch(void* data) {
|
||||||
taosMemoryFreeClear(pTableReq->ntb.schemaRow.pSchema);
|
taosMemoryFreeClear(pTableReq->ntb.schemaRow.pSchema);
|
||||||
} else if (pTableReq->type == TSDB_CHILD_TABLE) {
|
} else if (pTableReq->type == TSDB_CHILD_TABLE) {
|
||||||
taosMemoryFreeClear(pTableReq->ctb.pTag);
|
taosMemoryFreeClear(pTableReq->ctb.pTag);
|
||||||
|
taosMemoryFreeClear(pTableReq->ctb.name);
|
||||||
|
taosArrayDestroy(pTableReq->ctb.tagName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5334,7 +5336,7 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, SCreateSubTableClause* pStmt,
|
static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, SCreateSubTableClause* pStmt,
|
||||||
const STag* pTag, uint64_t suid, const char* sTableNmae, SVgroupInfo* pVgInfo) {
|
const STag* pTag, uint64_t suid, const char* sTableNmae, SVgroupInfo* pVgInfo, SArray* tagName) {
|
||||||
// char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
// char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
// SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
|
// SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
|
||||||
// strcpy(name.dbname, pStmt->dbName);
|
// strcpy(name.dbname, pStmt->dbName);
|
||||||
|
@ -5353,6 +5355,7 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S
|
||||||
req.ctb.suid = suid;
|
req.ctb.suid = suid;
|
||||||
req.ctb.name = strdup(sTableNmae);
|
req.ctb.name = strdup(sTableNmae);
|
||||||
req.ctb.pTag = (uint8_t*)pTag;
|
req.ctb.pTag = (uint8_t*)pTag;
|
||||||
|
req.ctb.tagName = taosArrayDup(tagName);
|
||||||
if (pStmt->ignoreExists) {
|
if (pStmt->ignoreExists) {
|
||||||
req.flags |= TD_CREATE_IF_NOT_EXISTS;
|
req.flags |= TD_CREATE_IF_NOT_EXISTS;
|
||||||
}
|
}
|
||||||
|
@ -5437,7 +5440,7 @@ static int32_t buildJsonTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SVa
|
||||||
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
|
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf, pTagSchema->name);
|
return parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildNormalTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SValueNode* pVal, SArray* pTagArray) {
|
static int32_t buildNormalTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SValueNode* pVal, SArray* pTagArray) {
|
||||||
|
@ -5457,7 +5460,7 @@ static int32_t buildNormalTagVal(STranslateContext* pCxt, SSchema* pTagSchema, S
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
||||||
STag** ppTag) {
|
STag** ppTag, SArray* tagName) {
|
||||||
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
||||||
if (LIST_LENGTH(pStmt->pValsOfTags) != LIST_LENGTH(pStmt->pSpecificTags) ||
|
if (LIST_LENGTH(pStmt->pValsOfTags) != LIST_LENGTH(pStmt->pSpecificTags) ||
|
||||||
numOfTags < LIST_LENGTH(pStmt->pValsOfTags)) {
|
numOfTags < LIST_LENGTH(pStmt->pValsOfTags)) {
|
||||||
|
@ -5488,8 +5491,10 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
||||||
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
|
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||||
isJson = true;
|
isJson = true;
|
||||||
code = buildJsonTagVal(pCxt, pSchema, pVal, pTagArray, ppTag);
|
code = buildJsonTagVal(pCxt, pSchema, pVal, pTagArray, ppTag);
|
||||||
|
taosArrayPush(tagName, pCol->colName);
|
||||||
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
|
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
|
||||||
code = buildNormalTagVal(pCxt, pSchema, pVal, pTagArray);
|
code = buildNormalTagVal(pCxt, pSchema, pVal, pTagArray);
|
||||||
|
taosArrayPush(tagName, pCol->colName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -5510,7 +5515,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
||||||
STag** ppTag) {
|
STag** ppTag, SArray* tagName) {
|
||||||
if (getNumOfTags(pSuperTableMeta) != LIST_LENGTH(pStmt->pValsOfTags)) {
|
if (getNumOfTags(pSuperTableMeta) != LIST_LENGTH(pStmt->pValsOfTags)) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED);
|
||||||
}
|
}
|
||||||
|
@ -5535,6 +5540,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
||||||
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||||
isJson = true;
|
isJson = true;
|
||||||
code = buildJsonTagVal(pCxt, pTagSchema, pVal, pTagArray, ppTag);
|
code = buildJsonTagVal(pCxt, pTagSchema, pVal, pTagArray, ppTag);
|
||||||
|
taosArrayPush(tagName, pTagSchema->name);
|
||||||
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL && !pVal->isNull) {
|
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL && !pVal->isNull) {
|
||||||
char* tmpVal = nodesGetValueFromNode(pVal);
|
char* tmpVal = nodesGetValueFromNode(pVal);
|
||||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||||
|
@ -5546,6 +5552,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
||||||
memcpy(&val.i64, tmpVal, pTagSchema->bytes);
|
memcpy(&val.i64, tmpVal, pTagSchema->bytes);
|
||||||
}
|
}
|
||||||
taosArrayPush(pTagArray, &val);
|
taosArrayPush(pTagArray, &val);
|
||||||
|
taosArrayPush(tagName, pTagSchema->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -5581,12 +5588,13 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla
|
||||||
}
|
}
|
||||||
|
|
||||||
STag* pTag = NULL;
|
STag* pTag = NULL;
|
||||||
|
SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
if (NULL != pStmt->pSpecificTags) {
|
if (NULL != pStmt->pSpecificTags) {
|
||||||
code = buildKVRowForBindTags(pCxt, pStmt, pSuperTableMeta, &pTag);
|
code = buildKVRowForBindTags(pCxt, pStmt, pSuperTableMeta, &pTag, tagName);
|
||||||
} else {
|
} else {
|
||||||
code = buildKVRowForAllTags(pCxt, pStmt, pSuperTableMeta, &pTag);
|
code = buildKVRowForAllTags(pCxt, pStmt, pSuperTableMeta, &pTag, tagName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5595,9 +5603,10 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla
|
||||||
code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info);
|
code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
addCreateTbReqIntoVgroup(pCxt->pParseCxt->acctId, pVgroupHashmap, pStmt, pTag, pSuperTableMeta->uid, pStmt->useTableName, &info);
|
addCreateTbReqIntoVgroup(pCxt->pParseCxt->acctId, pVgroupHashmap, pStmt, pTag, pSuperTableMeta->uid, pStmt->useTableName, &info, tagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(tagName);
|
||||||
taosMemoryFreeClear(pSuperTableMeta);
|
taosMemoryFreeClear(pSuperTableMeta);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -5823,7 +5832,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
STag* pTag = NULL;
|
STag* pTag = NULL;
|
||||||
do {
|
do {
|
||||||
code = parseJsontoTagData(pStmt->pVal->literal, pTagVals, &pTag, &pCxt->msgBuf, pReq->tagName);
|
code = parseJsontoTagData(pStmt->pVal->literal, pTagVals, &pTag, &pCxt->msgBuf);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,7 +341,7 @@ static bool isValidateTag(char* input) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf, const char* colName) {
|
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf) {
|
||||||
int32_t retCode = TSDB_CODE_SUCCESS;
|
int32_t retCode = TSDB_CODE_SUCCESS;
|
||||||
cJSON* root = NULL;
|
cJSON* root = NULL;
|
||||||
SHashObj* keyHash = NULL;
|
SHashObj* keyHash = NULL;
|
||||||
|
|
|
@ -1150,7 +1150,7 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
||||||
}
|
}
|
||||||
memcpy(tmp, varDataVal(input), varDataLen(input));
|
memcpy(tmp, varDataVal(input), varDataLen(input));
|
||||||
tmp[varDataLen(input)] = 0;
|
tmp[varDataLen(input)] = 0;
|
||||||
if(parseJsontoTagData(tmp, pTagVals, &pTag, NULL, "")){
|
if(parseJsontoTagData(tmp, pTagVals, &pTag, NULL)){
|
||||||
tTagNew(pTagVals, 1, true, &pTag);
|
tTagNew(pTagVals, 1, true, &pTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ TEST(columnTest, json_column_arith_op) {
|
||||||
memcpy(rightv, rightvTmp, strlen(rightvTmp));
|
memcpy(rightv, rightvTmp, strlen(rightvTmp));
|
||||||
SArray *tags = taosArrayInit(1, sizeof(STagVal));
|
SArray *tags = taosArrayInit(1, sizeof(STagVal));
|
||||||
STag* row = NULL;
|
STag* row = NULL;
|
||||||
parseJsontoTagData(rightv, tags, &row, NULL, "");
|
parseJsontoTagData(rightv, tags, &row, NULL);
|
||||||
|
|
||||||
const int32_t len = 8;
|
const int32_t len = 8;
|
||||||
EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV,
|
EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV,
|
||||||
|
@ -1262,7 +1262,7 @@ TEST(columnTest, json_column_logic_op) {
|
||||||
memcpy(rightv, rightvTmp, strlen(rightvTmp));
|
memcpy(rightv, rightvTmp, strlen(rightvTmp));
|
||||||
SArray *tags = taosArrayInit(1, sizeof(STagVal));
|
SArray *tags = taosArrayInit(1, sizeof(STagVal));
|
||||||
STag* row = NULL;
|
STag* row = NULL;
|
||||||
parseJsontoTagData(rightv, tags, &row, NULL, "");
|
parseJsontoTagData(rightv, tags, &row, NULL);
|
||||||
|
|
||||||
const int32_t len0 = 6;
|
const int32_t len0 = 6;
|
||||||
const int32_t len = 9;
|
const int32_t len = 9;
|
||||||
|
|
Loading…
Reference in New Issue