提交 3de234a2 编写于 作者: wmmhello's avatar wmmhello

TD-6129<feature> add json type check

上级 12a2c0b5
......@@ -1084,6 +1084,11 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
if(spd.numOfBound == 1 && pTagSchema[spd.boundedColumns[0]].type == TSDB_DATA_TYPE_JSON){
char tmp = sToken.z[sToken.n];
sToken.z[sToken.n] = 0;
if(sToken.type != TK_STRING) {
tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd);
return tscSQLSyntaxErrMsg(pInsertParam->msg, "json type error, should be string", NULL);
}
code = parseJsontoTagData(sToken.z, &kvRowBuilder, pInsertParam->msg, pTagSchema[spd.boundedColumns[0]].colId);
if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder);
......
......@@ -5867,6 +5867,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const char* msg23 = "only column length coulbe be modified";
const char* msg24 = "invalid binary/nchar column length";
const char* msg25 = "json type error, should be string";
int32_t code = TSDB_CODE_SUCCESS;
SSqlCmd* pCmd = &pSql->cmd;
......@@ -6070,6 +6072,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
if(pItem->pVar.nType != TSDB_DATA_TYPE_BINARY){
tscError("json type error, should be string");
return invalidOperationMsg(pMsg, "json type error, should be string");
}
code = parseJsontoTagData(pItem->pVar.pz, &kvRowBuilder, pMsg, pTagsSchema->colId);
if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder);
......@@ -7492,6 +7498,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
const char* msg3 = "tag value too long";
const char* msg4 = "illegal value or data overflow";
const char* msg5 = "tags number not matched";
const char* msg6 = "json type error, should be string";
SSqlCmd* pCmd = &pSql->cmd;
......@@ -7689,6 +7696,10 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
tVariantListItem* pItem = taosArrayGet(pValList, 0);
if(pItem->pVar.nType != TSDB_DATA_TYPE_BINARY){
tscError("json type error, should be string");
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "json type error, should be string");
}
ret = parseJsontoTagData(pItem->pVar.pz, &kvRowBuilder, tscGetErrorMsgPayload(pCmd), pTagSchema[0].colId);
if (ret != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder);
......
......@@ -5234,11 +5234,10 @@ end:
}
int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId){
cJSON *root = cJSON_Parse(json);
cJSON *root = cJSON_Parse(json->pz);
if (root == NULL){
tscError("json parse error");
return tscSQLSyntaxErrMsg(errMsg, "json parse error", NULL);
}
int retCode = 0;
......
......@@ -49,10 +49,16 @@ class TDTestCase:
print("==============step3")
tdLog.info("alter stable add tag")
tdSql.execute(
"ALTER STABLE db_json_tag_test.jsons1 add COLUMN tag2 nchar(20)")
"ALTER STABLE db_json_tag_test.jsons1 add tag tag2 nchar(20)")
tdSql.execute(
"ALTER STABLE db_json_tag_test.jsons1 drop COLUMN jtag")
"ALTER STABLE db_json_tag_test.jsons1 drop tag jtag")
tdSql.execute(
"ALTER TABLE db_json_tag_test.jsons1_1 SET TAG jtag=4")
tdSql.execute(
"ALTER TABLE db_json_tag_test.jsons1_1 SET TAG jtag='{\"sex\":\"femail\",\"age\":35}'")
def stop(self):
tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册