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

enable different value type of the same key in json

上级 3d868b5b
......@@ -747,7 +747,18 @@ int32_t tagValCompar(const void* p1, const void* p2) {
}else if(!f1IsNull && f2IsNull){
return 1;
}else {
assert(*t1->tag == *t1->tag);
bool f1IsJsonNull = (*t1->tag == TSDB_DATA_TYPE_BINARY && *(uint32_t*)(t1->tag + CHAR_BYTES) == TSDB_DATA_JSON_null);
bool f2IsJsonNull = (*t2->tag == TSDB_DATA_TYPE_BINARY && *(uint32_t*)(t2->tag + CHAR_BYTES) == TSDB_DATA_JSON_null);
if(f1IsJsonNull && f2IsJsonNull){
return 0;
}else if(f1IsJsonNull && !f2IsJsonNull){
return -1;
}else if(!f1IsJsonNull && f2IsJsonNull) {
return 1;
}
if(*t1->tag != *t2->tag) {
return 1;
}
__compar_fn_t func = getComparFunc(t1->tag[0], 0);
return func(t1->tag + CHAR_BYTES, t2->tag + CHAR_BYTES);
}
......
......@@ -5602,7 +5602,6 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
}
char *jsonKey = item->string;
if(strtrim(jsonKey) == 0) continue;
if(!isValidateTag(jsonKey)){
tscError("json key not validate");
retCode = tscSQLSyntaxErrMsg(errMsg, "json key not validate", NULL);
......@@ -5629,7 +5628,6 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
if(item->type == cJSON_String){ // add json value format: type|data
char *jsonValue = item->valuestring;
strtrim(jsonValue);
outLen = 0;
char tagVal[TSDB_MAX_JSON_TAGS_LEN] = {0};
*tagVal = jsonType2DbType(0, item->type); // type
......
......@@ -74,6 +74,7 @@ extern const int32_t TYPE_BYTES[16];
#define TSDB_DATA_JSON_NULL 0xFFFFFFFF
#define TSDB_DATA_JSON_null 0xFFFFFFFE
#define TSDB_DATA_JSON_NOT_NULL 0x01
#define TSDB_DATA_JSON_CAN_NOT_COMPARE 0x7FFFFFFF
#define TSDB_DATA_UTINYINT_NULL 0xFF
#define TSDB_DATA_USMALLINT_NULL 0xFFFF
......
......@@ -377,7 +377,18 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t
}else if(!f1IsNull && f2IsNull){
return 1;
}else{
assert(*f1 == *f2);
bool f1IsJsonNull = (*f1 == TSDB_DATA_TYPE_BINARY && *(uint32_t*)(f1 + CHAR_BYTES) == TSDB_DATA_JSON_null);
bool f2IsJsonNull = (*f2 == TSDB_DATA_TYPE_BINARY && *(uint32_t*)(f1 + CHAR_BYTES) == TSDB_DATA_JSON_null);
if(f1IsJsonNull && f2IsJsonNull){
return 0;
}else if(f1IsJsonNull && !f2IsJsonNull){
return -1;
}else if(!f1IsJsonNull && f2IsJsonNull) {
return 1;
}
if(*f1 != *f2) {
return 1;
}
type = *f1;
f1 += CHAR_BYTES;
f2 += CHAR_BYTES;
......
......@@ -1910,6 +1910,8 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) {
int32_t ret = func(left, right);
if(ret == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
switch (optr) {
case TSDB_RELATION_EQUAL: {
return ret == 0;
......
......@@ -220,17 +220,21 @@ int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight) {
}
int32_t compareJsonVal(const void *pLeft, const void *pRight) {
if(*(char*)pLeft == TSDB_DATA_TYPE_BINARY){ // json null
return -1;
}
const tVariant* right = pRight;
if(right->nType != *(char*)pLeft) return -1;
if(right->nType != *(char*)pLeft && !(IS_NUMERIC_TYPE(right->nType) && IS_NUMERIC_TYPE(*(char*)pLeft)))
return TSDB_DATA_JSON_CAN_NOT_COMPARE;
uint8_t type = *(char*)pLeft;
char* realData = POINTER_SHIFT(pLeft, CHAR_BYTES);
if(type == TSDB_DATA_TYPE_BOOL) {
DEFAULT_COMP(GET_INT8_VAL(realData), right->i64);
}else if(type == TSDB_DATA_TYPE_BIGINT){
DEFAULT_COMP(GET_INT64_VAL(realData), right->i64);
DEFAULT_COMP(GET_INT64_VAL(realData), (right->nType == TSDB_DATA_TYPE_BIGINT) ? right->i64 : right->dKey);
}else if(type == TSDB_DATA_TYPE_DOUBLE){
DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(realData), right->dKey);
DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(realData), (right->nType == TSDB_DATA_TYPE_DOUBLE) ? right->dKey : right->i64);
}else if(type == TSDB_DATA_TYPE_NCHAR){
if (varDataLen(realData) != right->nLen) {
return varDataLen(realData) > right->nLen ? 1 : -1;
......@@ -243,7 +247,6 @@ int32_t compareJsonVal(const void *pLeft, const void *pRight) {
}else{
assert(0);
}
return 0;
}
/*
......@@ -624,7 +627,18 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
}else if(!f1IsNull && f2IsNull){
return 1;
}else{
assert(*f1 == *f2);
bool f1IsJsonNull = (*f1 == TSDB_DATA_TYPE_BINARY && *(uint32_t*)(f1 + CHAR_BYTES) == TSDB_DATA_JSON_null);
bool f2IsJsonNull = (*f2 == TSDB_DATA_TYPE_BINARY && *(uint32_t*)(f1 + CHAR_BYTES) == TSDB_DATA_JSON_null);
if(f1IsJsonNull && f2IsJsonNull){
return 0;
}else if(f1IsJsonNull && !f2IsJsonNull){
return -1;
}else if(!f1IsJsonNull && f2IsJsonNull) {
return 1;
}
if(*f1 != *f2) {
return 1;
}
type = *f1;
f1 += CHAR_BYTES;
f2 += CHAR_BYTES;
......
......@@ -528,7 +528,7 @@ bool isValidateTag(char *input) {
if (!input) return false;
int len = strlen(input);
if (len == 0) return false;
for (int i = 1; i < len; ++i) {
for (int i = 0; i < len; ++i) {
if (isprint(input[i]) == 0) return false;
}
return true;
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册