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

feature/TD-6129 add table delete logic for json tag table

上级 49b750bd
......@@ -5296,12 +5296,12 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, nullTypeKey, false); // add json null type
if (strtrim(json) == 0 || strcasecmp(json, "null") == 0){
*(uint8_t*)(varDataVal(nullTypeVal + CHAR_BYTES)) = jsonNULL;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, &nullTypeVal, true); // add json null value
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, nullTypeVal, true); // add json null value
return TSDB_CODE_SUCCESS;
}
int8_t jsonNotNull = TSDB_DATA_JSON_NOT_NULL;
*(uint8_t*)(varDataVal(nullTypeVal + CHAR_BYTES)) = jsonNotNull;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, &nullTypeVal, true); // add json type
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, nullTypeVal, true); // add json type
// set json real data
cJSON *root = cJSON_Parse(json);
......@@ -5393,7 +5393,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
if(taosHashGetSize(keyHash) == 0){ // set json NULL true
*(uint8_t*)(varDataVal(nullTypeVal + CHAR_BYTES)) = jsonNULL;
memcpy(POINTER_SHIFT(kvRowBuilder->buf, kvRowBuilder->pColIdx[2].offset), &nullTypeVal, CHAR_BYTES + VARSTR_HEADER_SIZE + CHAR_BYTES);
memcpy(POINTER_SHIFT(kvRowBuilder->buf, kvRowBuilder->pColIdx[2].offset), nullTypeVal, CHAR_BYTES + VARSTR_HEADER_SIZE + CHAR_BYTES);
}
end:
......
......@@ -1494,26 +1494,12 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
}
static SArray* getJsonTagTableList(STable *pTable){
SArray** pRecord = taosHashIterate(pTable->jsonKeyMap, NULL);
SArray* tablist = taosArrayInit(32, sizeof(JsonMapValue));
while(pRecord){
SArray* tallistOld = *pRecord;
for (int i = 0; i < taosArrayGetSize(tallistOld); ++i) { // sort to elimate dumplicate
void* element = taosArrayGet(tallistOld, i);
void* pFind = taosArraySearch(tablist, element, tsdbCompareJsonMapValue, TD_EQ);
if(pFind == NULL){
void* p = taosArraySearch(tablist, element, tsdbCompareJsonMapValue, TD_GE);
if(p == NULL){
taosArrayPush(tablist, element);
}else{
taosArrayInsert(tablist, TARRAY_ELEM_IDX(tablist, p), element);
}
}
}
pRecord = taosHashIterate(pTable->jsonKeyMap, pRecord);
}
return tablist;
uint8_t key = TSDB_DATA_JSON_NULL;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
jsonKeyMd5(&key, 1, keyMd5);
SArray** tablist = (SArray**)taosHashGet(pTable->jsonKeyMap, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
return *tablist;
}
static int tsdbGetTableEncodeSize(int8_t act, STable *pTable) {
......@@ -1576,7 +1562,6 @@ static int tsdbRemoveTableFromStore(STsdbRepo *pRepo, STable *pTable) {
ASSERT(TABLE_TYPE((STable *)(p->table)) == TSDB_CHILD_TABLE);
pBuf = tsdbInsertTableAct(pRepo, TSDB_DROP_META, pBuf, p->table);
}
taosArrayDestroy(tablist);
}else {
SSkipListIterator *pIter = tSkipListCreateIter(pTable->pIndex);
if (pIter == NULL) {
......@@ -1609,7 +1594,6 @@ static int tsdbRmTableFromMeta(STsdbRepo *pRepo, STable *pTable) {
JsonMapValue* p = taosArrayGet(tablist, i);
tsdbRemoveTableFromMeta(pRepo, p->table, false, false);
}
taosArrayDestroy(tablist);
}else{
SSkipListIterator *pIter = tSkipListCreateIter(pTable->pIndex);
if (pIter == NULL) {
......
......@@ -2679,31 +2679,16 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
static int32_t getAllTableList(STable* pSuperTable, SArray* list) {
STSchema* pTagSchema = tsdbGetTableTagSchema(pSuperTable);
if(pTagSchema && pTagSchema->numOfCols == 1 && pTagSchema->columns[0].type == TSDB_DATA_TYPE_JSON){
SArray** pRecord = taosHashIterate(pSuperTable->jsonKeyMap, NULL);
SArray* tablist = taosArrayInit(32, sizeof(JsonMapValue));
while(pRecord){
SArray* tallistOld = *pRecord;
for (int i = 0; i < taosArrayGetSize(tallistOld); ++i) { // sort to elimate dumplicate
void* element = taosArrayGet(tallistOld, i);
void* pFind = taosArraySearch(tablist, element, tsdbCompareJsonMapValue, TD_EQ);
if(pFind == NULL){
void* p = taosArraySearch(tablist, element, tsdbCompareJsonMapValue, TD_GE);
if(p == NULL){
taosArrayPush(tablist, element);
}else{
taosArrayInsert(tablist, TARRAY_ELEM_IDX(tablist, p), element);
}
}
}
pRecord = taosHashIterate(pSuperTable->jsonKeyMap, pRecord);
}
for (int i = 0; i < taosArrayGetSize(tablist); ++i) {
JsonMapValue* p = taosArrayGet(tablist, i);
uint8_t key = TSDB_DATA_JSON_NULL;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
jsonKeyMd5(&key, 1, keyMd5);
SArray** tablist = (SArray**)taosHashGet(pSuperTable->jsonKeyMap, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
for (int i = 0; i < taosArrayGetSize(*tablist); ++i) {
JsonMapValue* p = taosArrayGet(*tablist, i);
STableKeyInfo info = {.pTable = p->table, .lastKey = TSKEY_INITIAL_VAL};
taosArrayPush(list, &info);
}
taosArrayDestroy(tablist);
}else{
SSkipListIterator* iter = tSkipListCreateIter(pSuperTable->pIndex);
while (tSkipListIterNext(iter)) {
......
......@@ -470,9 +470,8 @@ 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[i] != '_' && isalnum(input[i]) == 0) return false;
if (isprint(input[i]) == 0) return false;
}
return true;
}
......
......@@ -243,6 +243,17 @@ class TDTestCase:
tdSql.query("select tbname,jtag from db_json_tag_test.jsons1 where jtag->'k1'='中国'")
tdSql.checkRows(1)
#test dumplicate key with normal colomn
tdSql.execute("INSERT INTO db_json_tag_test.jsons1_12 using db_json_tag_test.jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"dataStr\":\"是是是\"}') values(now, 4, false, \"你就会\")")
tdSql.query("select *,tbname,jtag from db_json_tag_test.jsons1 where jtag->'dataStr' match '是'")
tdSql.checkRows(1)
tdSql.query("select tbname,jtag->'tbname' from db_json_tag_test.jsons1 where jtag->'tbname'='tt'")
tdSql.checkRows(1)
tdSql.query("select *,tbname,jtag from db_json_tag_test.jsons1 where dataBool=true")
tdSql.checkRows(2)
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.
先完成此消息的编辑!
想要评论请 注册