提交 5495be27 编写于 作者: wmmhello's avatar wmmhello

TD-6129<feature> add taos json key hash free function

上级 53bcb31c
......@@ -5285,6 +5285,7 @@ end:
}
int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId){
// set json NULL data
uint8_t nullTypeVal[CHAR_BYTES + VARSTR_HEADER_SIZE + CHAR_BYTES] = {0};
uint8_t jsonNULL = TSDB_DATA_JSON_NULL;
int jsonIndex = startColId + 1;
......@@ -5302,6 +5303,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
*(uint8_t*)(varDataVal(nullTypeVal + CHAR_BYTES)) = jsonNotNull;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, &nullTypeVal, true); // add json type
// set json real data
cJSON *root = cJSON_Parse(json);
if (root == NULL){
tscError("json parse error");
......@@ -5329,7 +5331,11 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
if (item->type == cJSON_NULL){
continue;
}
if(!isValidateTag(jsonKey)){
tscError("json key not validate");
retCode = tscSQLSyntaxErrMsg(errMsg, "json key not validate", NULL);
goto end;
}
if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
tscError("json key too long error");
retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
......
......@@ -46,6 +46,7 @@ int taosCheckVersion(char *input_client_version, char *input_server_version, in
char * taosIpStr(uint32_t ipInt);
uint32_t ip2uint(const char *const ip_addr);
void jsonKeyMd5(void *pMsg, int msgLen, void *pKey);
bool isValidateTag(char *input);
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
MD5_CTX context;
......
......@@ -466,6 +466,17 @@ void jsonKeyMd5(void *pMsg, int msgLen, void *pKey) {
memcpy(pKey, context.digest, sizeof(context.digest));
}
bool isValidateTag(char *input) {
if (!input) return false;
int len = strlen(input);
if (len == 0) return false;
if (input[0] != '_' || isalpha(input[0]) == 0) return false;
for (int i = 1; i < len; ++i) {
if (input[0] != '_' || isalnum(input[0]) == 0) return false;
}
return true;
}
FORCE_INLINE float taos_align_get_float(const char* pBuf) {
#if __STDC_VERSION__ >= 201112L
static_assert(sizeof(float) == sizeof(uint32_t), "sizeof(float) must equal to sizeof(uint32_t)");
......
......@@ -33,6 +33,9 @@ class TDTestCase:
tdSql.execute("create table if not exists db_json_tag_test.jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50)) tags(jtag json)")
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_1 using db_json_tag_test.jsons1 tags('{\"loc\":\"fff\",\"id\":5}')")
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags(3333)")
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags('{\"1loc\":\"fff\",\";id\":5}')")
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags('{\"。loc\":\"fff\",\"fsd\":5}')")
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags('{\"试试\":\"fff\",\";id\":5}')")
tdSql.execute("insert into db_json_tag_test.jsons1_2 using db_json_tag_test.jsons1 tags('{\"num\":5,\"location\":\"beijing\"}') values (now, 2, true, 'json2')")
tdSql.error("insert into db_json_tag_test.jsons1_4 using db_json_tag_test.jsons1 tags(3)")
tdSql.execute("insert into db_json_tag_test.jsons1_1 values(now, 1, false, 'json1')")
......@@ -228,6 +231,12 @@ class TDTestCase:
tdSql.query("select distinct jtag from db_json_tag_test.jsons1")
tdSql.checkRows(6)
tdSql.query("select distinct jtag->'location' from db_json_tag_test.jsons1")
tdSql.checkRows(3)
# test chinese
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_11 using db_json_tag_test.jsons1 tags('{\"k1\":\"中国\",\"k2\":\"是是是\"}')")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册