Merge pull request #13433 from taosdata/feature/TD-13041
feat:add json test case
This commit is contained in:
commit
8566917971
|
@ -186,6 +186,8 @@ static FORCE_INLINE void colDataAppendDouble(SColumnInfoData* pColumnInfoData, u
|
|||
*(double*)p = *(double*)v;
|
||||
}
|
||||
|
||||
int32_t getJsonValueLen(const char *data);
|
||||
|
||||
int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull);
|
||||
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, int32_t* capacity,
|
||||
const SColumnInfoData* pSource, uint32_t numOfRow2);
|
||||
|
|
|
@ -1234,7 +1234,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
|
|||
sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L);
|
||||
varDataSetLen(dst, strlen(varDataVal(dst)));
|
||||
} else if (jsonInnerType == TD_TAG_JSON) {
|
||||
char* jsonString = parseTagDatatoJson(jsonInnerData);
|
||||
char* jsonString = parseTagDatatoJson(pStart);
|
||||
STR_TO_VARSTR(dst, jsonString);
|
||||
taosMemoryFree(jsonString);
|
||||
} else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
|
||||
|
|
|
@ -99,6 +99,24 @@ void colDataTrim(SColumnInfoData* pColumnInfoData) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
int32_t getJsonValueLen(const char *data) {
|
||||
int32_t dataLen = 0;
|
||||
if (*data == TSDB_DATA_TYPE_NULL) {
|
||||
dataLen = CHAR_BYTES;
|
||||
} else if (*data == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(data + CHAR_BYTES) + CHAR_BYTES;
|
||||
} else if (*data == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = DOUBLE_BYTES + CHAR_BYTES;
|
||||
} else if (*data == TSDB_DATA_TYPE_BOOL) {
|
||||
dataLen = CHAR_BYTES + CHAR_BYTES;
|
||||
} else if (*data == TD_TAG_JSON) { // json string
|
||||
dataLen = ((STag*)(data))->len;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull) {
|
||||
ASSERT(pColumnInfoData != NULL);
|
||||
|
||||
|
@ -118,19 +136,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
int32_t dataLen = 0;
|
||||
if (type == TSDB_DATA_TYPE_JSON) {
|
||||
if (*pData == TSDB_DATA_TYPE_NULL) {
|
||||
dataLen = CHAR_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(pData + CHAR_BYTES) + CHAR_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = DOUBLE_BYTES + CHAR_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_BOOL) {
|
||||
dataLen = CHAR_BYTES + CHAR_BYTES;
|
||||
} else if (*pData == TD_TAG_JSON) { // json string
|
||||
dataLen = ((STag*)(pData))->len;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
dataLen = getJsonValueLen(pData);
|
||||
}else {
|
||||
dataLen = varDataTLen(pData);
|
||||
}
|
||||
|
|
|
@ -93,7 +93,15 @@ static bool groupKeyCompare(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlo
|
|||
|
||||
char* val = colDataGetData(pColInfoData, rowIndex);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
if (pkey->type == TSDB_DATA_TYPE_JSON) {
|
||||
int32_t dataLen = getJsonValueLen(val);
|
||||
|
||||
if (memcmp(pkey->pData, val, dataLen) == 0){
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
int32_t len = varDataLen(val);
|
||||
if (len == varDataLen(pkey->pData) && memcmp(varDataVal(pkey->pData), varDataVal(val), len) == 0) {
|
||||
continue;
|
||||
|
@ -129,7 +137,10 @@ void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock*
|
|||
} else {
|
||||
pkey->isNull = false;
|
||||
char* val = colDataGetData(pColInfoData, rowIndex);
|
||||
if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
if (pkey->type == TSDB_DATA_TYPE_JSON) {
|
||||
int32_t dataLen = getJsonValueLen(val);
|
||||
memcpy(pkey->pData, val, dataLen);
|
||||
} else if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
memcpy(pkey->pData, val, varDataTLen(val));
|
||||
ASSERT(varDataTLen(val) <= pkey->bytes);
|
||||
} else {
|
||||
|
@ -153,7 +164,11 @@ int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
|
|||
}
|
||||
|
||||
isNull[i] = 0;
|
||||
if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
if (pkey->type == TSDB_DATA_TYPE_JSON) {
|
||||
int32_t dataLen = getJsonValueLen(pkey->pData);
|
||||
memcpy(pStart, (pkey->pData), dataLen);
|
||||
pStart += dataLen;
|
||||
} else if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
varDataCopy(pStart, pkey->pData);
|
||||
pStart += varDataTLen(pkey->pData);
|
||||
ASSERT(varDataTLen(pkey->pData) <= pkey->bytes);
|
||||
|
@ -178,7 +193,10 @@ static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t
|
|||
char* dest = GET_ROWCELL_INTERBUF(pEntryInfo);
|
||||
char* data = colDataGetData(pColInfoData, rowIndex);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
if (pColInfoData->info.type == TSDB_DATA_TYPE_JSON) {
|
||||
int32_t dataLen = getJsonValueLen(data);
|
||||
memcpy(dest, data, dataLen);
|
||||
} else if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
varDataCopy(dest, data);
|
||||
} else {
|
||||
memcpy(dest, data, pColInfoData->info.bytes);
|
||||
|
@ -447,6 +465,16 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
if (colDataIsNull_s(pColInfoData, j)) {
|
||||
offset[(*rows)] = -1;
|
||||
contentLen = 0;
|
||||
} else if(pColInfoData->info.type == TSDB_DATA_TYPE_JSON){
|
||||
offset[*rows] = (*columnLen);
|
||||
char* src = colDataGetData(pColInfoData, j);
|
||||
int32_t dataLen = getJsonValueLen(src);
|
||||
|
||||
memcpy(data + (*columnLen), src, dataLen);
|
||||
int32_t v = (data + (*columnLen) + dataLen - (char*)pPage);
|
||||
ASSERT(v > 0);
|
||||
|
||||
contentLen = dataLen;
|
||||
} else {
|
||||
offset[*rows] = (*columnLen);
|
||||
char* src = colDataGetData(pColInfoData, j);
|
||||
|
|
|
@ -140,7 +140,7 @@ static int32_t sifGetValueFromNode(SNode *node, char **value) {
|
|||
dataLen = 0;
|
||||
} else if (*pData == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(pData + CHAR_BYTES);
|
||||
} else if (*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
} else if (*pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = LONG_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_BOOL) {
|
||||
dataLen = CHAR_BYTES;
|
||||
|
@ -457,10 +457,6 @@ static int32_t sifGetOperFn(int32_t funcId, sif_func_t *func, SIdxFltStatus *sta
|
|||
static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||
int32_t code = 0;
|
||||
int32_t nParam = sifGetOperParamNum(node->opType);
|
||||
if (nParam <= 1) {
|
||||
SIF_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
SIFParam *params = NULL;
|
||||
SIF_ERR_RET(sifInitOperParams(¶ms, node, ctx));
|
||||
|
||||
|
@ -469,14 +465,12 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
|||
|
||||
sif_func_t operFn = sifNullFunc;
|
||||
code = sifGetOperFn(node->opType, &operFn, &output->status);
|
||||
if (ctx->noExec) {
|
||||
SIF_RET(code);
|
||||
} else {
|
||||
return operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output);
|
||||
if (!ctx->noExec) {
|
||||
code = operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output);
|
||||
}
|
||||
_return:
|
||||
|
||||
taosMemoryFree(params);
|
||||
SIF_RET(code);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||
|
|
|
@ -227,6 +227,33 @@ int32_t compareJsonContainsKey(const void* pLeft, const void* pRight) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// string > number > bool > null
|
||||
// ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
|
||||
int32_t compareJsonVal(const void *pLeft, const void *pRight) {
|
||||
char leftType = *(char*)pLeft;
|
||||
char rightType = *(char*)pRight;
|
||||
if(leftType != rightType){
|
||||
return leftType > rightType ? 1 : -1;
|
||||
}
|
||||
|
||||
char* realDataLeft = POINTER_SHIFT(pLeft, CHAR_BYTES);
|
||||
char* realDataRight = POINTER_SHIFT(pRight, CHAR_BYTES);
|
||||
if(leftType == TSDB_DATA_TYPE_BOOL) {
|
||||
DEFAULT_COMP(GET_INT8_VAL(realDataLeft), GET_INT8_VAL(realDataRight));
|
||||
}else if(leftType == TSDB_DATA_TYPE_DOUBLE){
|
||||
DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(realDataLeft), GET_DOUBLE_VAL(realDataRight));
|
||||
}else if(leftType == TSDB_DATA_TYPE_NCHAR){
|
||||
return compareLenPrefixedWStr(realDataLeft, realDataRight);
|
||||
}else if(leftType == TSDB_DATA_TYPE_NULL) {
|
||||
return 0;
|
||||
}else{
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t compareJsonValDesc(const void *pLeft, const void *pRight) {
|
||||
return compareJsonVal(pRight, pLeft);
|
||||
}
|
||||
/*
|
||||
* Compare two strings
|
||||
* TSDB_MATCH: Match
|
||||
|
@ -601,6 +628,8 @@ __compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) {
|
|||
return (order == TSDB_ORDER_ASC) ? compareLenPrefixedStr : compareLenPrefixedStrDesc;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
return (order == TSDB_ORDER_ASC) ? compareLenPrefixedWStr : compareLenPrefixedWStrDesc;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
return (order == TSDB_ORDER_ASC) ? compareJsonVal : compareJsonValDesc;
|
||||
default:
|
||||
return (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ class TDTestCase:
|
|||
|
||||
# test duplicate key using the first one. elimate empty key
|
||||
tdSql.execute("CREATE TABLE if not exists jsons1_8 using jsons1 tags('{\"tag1\":null, \"tag1\":true, \"tag1\":45, \"1tag$\":2, \" \":90, \"\":32}')")
|
||||
#tdSql.query("select jtag from jsons1_8")
|
||||
#tdSql.checkData(0, 0, '{"tag1":null,"1tag$":2," ":90}')
|
||||
tdSql.query("select jtag from jsons1_8")
|
||||
tdSql.checkData(0, 0, '{" ":90,"1tag$":2,"tag1":null}')
|
||||
|
||||
# test empty json string, save as jtag is NULL
|
||||
tdSql.execute("insert into jsons1_9 using jsons1 tags('\t') values (1591062328000, 24, NULL, '你就会', '2sdw')")
|
||||
|
@ -95,8 +95,8 @@ class TDTestCase:
|
|||
tdSql.error("ALTER TABLE jsons1 MODIFY TAG jtag nchar(128)")
|
||||
#
|
||||
tdSql.execute("ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'")
|
||||
# tdSql.query("select jtag from jsons1_1")
|
||||
# tdSql.checkData(0, 0, '{"tag1":"femail","tag2":35,"tag3":true}')
|
||||
tdSql.query("select jtag from jsons1_1")
|
||||
tdSql.checkData(0, 0, '{"tag1":"femail","tag2":35,"tag3":true}')
|
||||
tdSql.execute("ALTER TABLE jsons1 rename TAG jtag jtag_new")
|
||||
tdSql.execute("ALTER TABLE jsons1 rename TAG jtag_new jtag")
|
||||
|
||||
|
@ -106,69 +106,69 @@ class TDTestCase:
|
|||
#
|
||||
# print("============== STEP 3 ===== query table")
|
||||
# # test error syntax
|
||||
# tdSql.error("select * from jsons1 where jtag->tag1='beijing'")
|
||||
# tdSql.error("select * from jsons1 where jtag->'location'")
|
||||
# tdSql.error("select * from jsons1 where jtag->''")
|
||||
# tdSql.error("select * from jsons1 where jtag->''=9")
|
||||
# tdSql.error("select -> from jsons1")
|
||||
# tdSql.error("select * from jsons1 where contains")
|
||||
# tdSql.error("select * from jsons1 where jtag->")
|
||||
# tdSql.error("select jtag->location from jsons1")
|
||||
# tdSql.error("select jtag contains location from jsons1")
|
||||
# tdSql.error("select * from jsons1 where jtag contains location")
|
||||
# tdSql.error("select * from jsons1 where jtag contains''")
|
||||
# tdSql.error("select * from jsons1 where jtag contains 'location'='beijing'")
|
||||
tdSql.error("select * from jsons1 where jtag->tag1='beijing'")
|
||||
#tdSql.error("select * from jsons1 where jtag->'location'")
|
||||
#tdSql.error("select * from jsons1 where jtag->''")
|
||||
#tdSql.error("select * from jsons1 where jtag->''=9")
|
||||
tdSql.error("select -> from jsons1")
|
||||
tdSql.error("select * from jsons1 where contains")
|
||||
tdSql.error("select * from jsons1 where jtag->")
|
||||
tdSql.error("select jtag->location from jsons1")
|
||||
tdSql.error("select jtag contains location from jsons1")
|
||||
tdSql.error("select * from jsons1 where jtag contains location")
|
||||
tdSql.error("select * from jsons1 where jtag contains''")
|
||||
tdSql.error("select * from jsons1 where jtag contains 'location'='beijing'")
|
||||
#
|
||||
# # test function error
|
||||
# tdSql.error("select avg(jtag->'tag1') from jsons1")
|
||||
# tdSql.error("select avg(jtag) from jsons1")
|
||||
# tdSql.error("select min(jtag->'tag1') from jsons1")
|
||||
# tdSql.error("select min(jtag) from jsons1")
|
||||
# tdSql.error("select ceil(jtag->'tag1') from jsons1")
|
||||
# tdSql.error("select ceil(jtag) from jsons1")
|
||||
tdSql.error("select avg(jtag->'tag1') from jsons1")
|
||||
tdSql.error("select avg(jtag) from jsons1")
|
||||
tdSql.error("select min(jtag->'tag1') from jsons1")
|
||||
tdSql.error("select min(jtag) from jsons1")
|
||||
tdSql.error("select ceil(jtag->'tag1') from jsons1")
|
||||
tdSql.error("select ceil(jtag) from jsons1")
|
||||
#
|
||||
# # test select normal column
|
||||
# tdSql.query("select dataint from jsons1")
|
||||
# tdSql.checkRows(9)
|
||||
# tdSql.checkData(1, 0, 1)
|
||||
tdSql.query("select dataint from jsons1")
|
||||
tdSql.checkRows(9)
|
||||
tdSql.checkData(1, 0, 1)
|
||||
|
||||
# test select json tag
|
||||
# tdSql.query("select * from jsons1")
|
||||
# tdSql.checkRows(8)
|
||||
# tdSql.query("select jtag from jsons1")
|
||||
# tdSql.checkRows(7)
|
||||
tdSql.query("select * from jsons1")
|
||||
tdSql.checkRows(9)
|
||||
tdSql.query("select jtag from jsons1")
|
||||
tdSql.checkRows(13)
|
||||
# tdSql.query("select jtag from jsons1 where jtag is null")
|
||||
# tdSql.checkRows(5)
|
||||
# tdSql.query("select jtag from jsons1 where jtag is not null")
|
||||
# tdSql.checkRows(8)
|
||||
|
||||
# test jtag is NULL
|
||||
#tdSql.query("select jtag from jsons1_9")
|
||||
#tdSql.checkData(0, 0, None)
|
||||
tdSql.query("select jtag from jsons1_9")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
# # test select json tag->'key', value is string
|
||||
# tdSql.query("select jtag->'tag1' from jsons1_1")
|
||||
# tdSql.checkData(0, 0, '"femail"')
|
||||
# tdSql.query("select jtag->'tag2' from jsons1_6")
|
||||
# tdSql.checkData(0, 0, '""')
|
||||
# # test select json tag->'key', value is int
|
||||
# tdSql.query("select jtag->'tag2' from jsons1_1")
|
||||
# tdSql.checkData(0, 0, 35)
|
||||
# # test select json tag->'key', value is bool
|
||||
# tdSql.query("select jtag->'tag3' from jsons1_1")
|
||||
# tdSql.checkData(0, 0, "true")
|
||||
# # test select json tag->'key', value is null
|
||||
# tdSql.query("select jtag->'tag1' from jsons1_4")
|
||||
# tdSql.checkData(0, 0, "null")
|
||||
# # test select json tag->'key', value is double
|
||||
# tdSql.query("select jtag->'tag1' from jsons1_5")
|
||||
# tdSql.checkData(0, 0, "1.232000000")
|
||||
# # test select json tag->'key', key is not exist
|
||||
# tdSql.query("select jtag->'tag10' from jsons1_4")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
tdSql.query("select jtag->'tag1' from jsons1_1")
|
||||
tdSql.checkData(0, 0, '"femail"')
|
||||
tdSql.query("select jtag->'tag2' from jsons1_6")
|
||||
tdSql.checkData(0, 0, '""')
|
||||
# test select json tag->'key', value is int
|
||||
tdSql.query("select jtag->'tag2' from jsons1_1")
|
||||
tdSql.checkData(0, 0, "35.000000000")
|
||||
# test select json tag->'key', value is bool
|
||||
tdSql.query("select jtag->'tag3' from jsons1_1")
|
||||
tdSql.checkData(0, 0, "true")
|
||||
# test select json tag->'key', value is null
|
||||
tdSql.query("select jtag->'tag1' from jsons1_4")
|
||||
tdSql.checkData(0, 0, "null")
|
||||
# test select json tag->'key', value is double
|
||||
tdSql.query("select jtag->'tag1' from jsons1_5")
|
||||
tdSql.checkData(0, 0, "1.232000000")
|
||||
# test select json tag->'key', key is not exist
|
||||
tdSql.query("select jtag->'tag10' from jsons1_4")
|
||||
tdSql.checkData(0, 0, None)
|
||||
#
|
||||
# tdSql.query("select jtag->'tag1' from jsons1")
|
||||
# tdSql.checkRows(13)
|
||||
tdSql.query("select jtag->'tag1' from jsons1")
|
||||
tdSql.checkRows(13)
|
||||
# test header name
|
||||
res = tdSql.getColNameList("select jtag->'tag1' from jsons1")
|
||||
cname_list = []
|
||||
|
@ -176,7 +176,6 @@ class TDTestCase:
|
|||
tdSql.checkColNameList(res, cname_list)
|
||||
|
||||
|
||||
|
||||
# # test where with json tag
|
||||
# tdSql.error("select * from jsons1_1 where jtag is not null")
|
||||
# tdSql.error("select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'")
|
||||
|
@ -313,8 +312,8 @@ class TDTestCase:
|
|||
# tdSql.checkRows(2)
|
||||
#
|
||||
# # test with tbname/normal column
|
||||
# tdSql.query("select * from jsons1 where tbname = 'jsons1_1'")
|
||||
# tdSql.checkRows(2)
|
||||
tdSql.query("select * from jsons1 where tbname = 'jsons1_1'")
|
||||
tdSql.checkRows(2)
|
||||
# tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'")
|
||||
# tdSql.checkRows(2)
|
||||
# tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3")
|
||||
|
@ -345,14 +344,14 @@ class TDTestCase:
|
|||
# tdSql.checkRows(1)
|
||||
#
|
||||
# # test distinct
|
||||
# tdSql.execute("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')")
|
||||
# tdSql.query("select distinct jtag->'tag1' from jsons1")
|
||||
# tdSql.checkRows(8)
|
||||
# tdSql.query("select distinct jtag from jsons1")
|
||||
# tdSql.checkRows(9)
|
||||
tdSql.execute("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')")
|
||||
tdSql.query("select distinct jtag->'tag1' from jsons1")
|
||||
tdSql.checkRows(8)
|
||||
tdSql.query("select distinct jtag from jsons1")
|
||||
tdSql.checkRows(9)
|
||||
#
|
||||
# #test dumplicate key with normal colomn
|
||||
# tdSql.execute("INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"是是是\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")")
|
||||
tdSql.execute("INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"是是是\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")")
|
||||
# tdSql.query("select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'")
|
||||
# tdSql.checkRows(1)
|
||||
# tdSql.query("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'")
|
||||
|
@ -377,67 +376,71 @@ class TDTestCase:
|
|||
# cname_list.append("a.jtag->'tag3'")
|
||||
# tdSql.checkColNameList(res, cname_list)
|
||||
#
|
||||
# # test group by & order by json tag
|
||||
# tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag2'")
|
||||
# tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag")
|
||||
# tdSql.query("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc")
|
||||
# tdSql.checkRows(8)
|
||||
# tdSql.checkData(1, 0, 2)
|
||||
# tdSql.checkData(1, 1, '"femail"')
|
||||
# tdSql.checkData(2, 0, 1)
|
||||
# tdSql.checkData(2, 1, 11)
|
||||
# tdSql.checkData(5, 0, 1)
|
||||
# tdSql.checkData(5, 1, "false")
|
||||
# test group by & order by json tag
|
||||
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag2'")
|
||||
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag")
|
||||
tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc")
|
||||
tdSql.checkRows(8)
|
||||
tdSql.checkData(0, 0, 2)
|
||||
tdSql.checkData(0, 1, '"femail"')
|
||||
tdSql.checkData(1, 0, 2)
|
||||
tdSql.checkData(1, 1, '"收到货"')
|
||||
tdSql.checkData(2, 0, 1)
|
||||
tdSql.checkData(2, 1, "11.000000000")
|
||||
tdSql.checkData(5, 0, 1)
|
||||
tdSql.checkData(5, 1, "false")
|
||||
# tdSql.checkData(6, 0, 1)
|
||||
# tdSql.checkData(6, 1, "null")
|
||||
# tdSql.checkData(7, 0, 2)
|
||||
# tdSql.checkData(7, 1, None)
|
||||
tdSql.checkData(7, 0, 2)
|
||||
tdSql.checkData(7, 1, None)
|
||||
|
||||
tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc")
|
||||
tdSql.checkRows(8)
|
||||
tdSql.checkData(0, 0, 2)
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(2, 0, 1)
|
||||
tdSql.checkData(2, 1, "false")
|
||||
tdSql.checkData(5, 0, 1)
|
||||
tdSql.checkData(5, 1, "11.000000000")
|
||||
tdSql.checkData(7, 0, 2)
|
||||
tdSql.checkData(7, 1, '"femail"')
|
||||
#
|
||||
# tdSql.query("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc")
|
||||
# tdSql.checkRows(8)
|
||||
# tdSql.checkData(0, 0, 2)
|
||||
# test stddev with group by json tag
|
||||
tdSql.query("select stddev(dataint),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'")
|
||||
tdSql.checkRows(8)
|
||||
tdSql.checkData(0, 0, 10)
|
||||
# tdSql.checkData(0, 1, None)
|
||||
# tdSql.checkData(2, 0, 1)
|
||||
# tdSql.checkData(2, 1, "false")
|
||||
# tdSql.checkData(5, 0, 1)
|
||||
# tdSql.checkData(5, 1, 11)
|
||||
# tdSql.checkData(6, 0, 2)
|
||||
# tdSql.checkData(6, 1, '"femail"')
|
||||
#
|
||||
# # test stddev with group by json tag
|
||||
# tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1'")
|
||||
# tdSql.checkData(0, 0, 10)
|
||||
# tdSql.checkData(0, 1, None)
|
||||
# tdSql.checkData(1, 0, 0)
|
||||
# tdSql.checkData(1, 1, "null")
|
||||
# tdSql.checkData(6, 0, 11)
|
||||
# tdSql.checkData(6, 1, '"femail"')
|
||||
#
|
||||
# res = tdSql.getColNameList("select stddev(dataint) from jsons1 group by jsons1.jtag->'tag1'")
|
||||
# cname_list = []
|
||||
# cname_list.append("stddev(dataint)")
|
||||
# cname_list.append("jsons1.jtag->'tag1'")
|
||||
# tdSql.checkColNameList(res, cname_list)
|
||||
#
|
||||
# # test top/bottom with group by json tag
|
||||
# tdSql.query("select top(dataint,100) from jsons1 group by jtag->'tag1'")
|
||||
# tdSql.checkRows(11)
|
||||
# tdSql.checkData(0, 1, 4)
|
||||
# tdSql.checkData(1, 1, 24)
|
||||
# tdSql.checkData(1, 2, None)
|
||||
# tdSql.checkData(8, 1, 1)
|
||||
# tdSql.checkData(8, 2, '"femail"')
|
||||
#
|
||||
# # test having
|
||||
tdSql.checkData(4, 0, 0)
|
||||
tdSql.checkData(4, 1, "5.000000000")
|
||||
tdSql.checkData(7, 0, 11)
|
||||
tdSql.checkData(7, 1, '"femail"')
|
||||
|
||||
res = tdSql.getColNameList("select stddev(dataint),jsons1.jtag->'tag1' from jsons1 group by jsons1.jtag->'tag1' order by jtag->'tag1'")
|
||||
cname_list = []
|
||||
cname_list.append("stddev(dataint)")
|
||||
cname_list.append("jsons1.jtag->'tag1'")
|
||||
tdSql.checkColNameList(res, cname_list)
|
||||
|
||||
# test top/bottom with group by json tag
|
||||
tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'")
|
||||
tdSql.checkRows(11)
|
||||
tdSql.checkData(3, 0, 3)
|
||||
tdSql.checkData(3, 1, "false")
|
||||
# tdSql.checkData(3, 0, 24)
|
||||
# tdSql.checkData(3, 1, None)
|
||||
tdSql.checkData(10, 0, 23)
|
||||
tdSql.checkData(10, 1, '"femail"')
|
||||
|
||||
# test having
|
||||
# tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0")
|
||||
# tdSql.checkRows(2)
|
||||
#
|
||||
# # subquery with json tag
|
||||
# tdSql.query("select * from (select jtag, dataint from jsons1)")
|
||||
# tdSql.checkRows(11)
|
||||
# tdSql.checkData(1, 1, 1)
|
||||
# tdSql.checkData(2, 0, '{"tag1":5,"tag2":"beijing"}')
|
||||
#
|
||||
|
||||
# subquery with json tag
|
||||
tdSql.query("select * from (select jtag, dataint from jsons1)")
|
||||
tdSql.checkRows(11)
|
||||
tdSql.checkData(1, 1, 1)
|
||||
tdSql.checkData(2, 0, '{"tag1":5,"tag2":"beijing"}')
|
||||
|
||||
# tdSql.query("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)")
|
||||
# tdSql.checkRows(11)
|
||||
# tdSql.checkData(1, 0, '"femail"')
|
||||
|
@ -514,17 +517,17 @@ class TDTestCase:
|
|||
# tdSql.checkRows(3)
|
||||
#
|
||||
# #test TD-12077
|
||||
# tdSql.execute("insert into jsons1_16 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":-2.111}') values(1591062628000, 2, NULL, '你就会', 'dws')")
|
||||
# tdSql.query("select jtag->'tag3' from jsons1_16")
|
||||
# tdSql.checkData(0, 0, '-2.111000000')
|
||||
#
|
||||
tdSql.execute("insert into jsons1_16 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":-2.111}') values(1591062628000, 2, NULL, '你就会', 'dws')")
|
||||
tdSql.query("select jtag->'tag3' from jsons1_16")
|
||||
tdSql.checkData(0, 0, '-2.111000000')
|
||||
|
||||
# # test TD-12452
|
||||
# tdSql.execute("ALTER TABLE jsons1_1 SET TAG jtag=NULL")
|
||||
# tdSql.query("select jtag from jsons1_1")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
# tdSql.execute("CREATE TABLE if not exists jsons1_20 using jsons1 tags(NULL)")
|
||||
# tdSql.query("select jtag from jsons1_20")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
tdSql.execute("ALTER TABLE jsons1_1 SET TAG jtag=NULL")
|
||||
tdSql.query("select jtag from jsons1_1")
|
||||
tdSql.checkData(0, 0, None)
|
||||
tdSql.execute("CREATE TABLE if not exists jsons1_20 using jsons1 tags(NULL)")
|
||||
tdSql.query("select jtag from jsons1_20")
|
||||
tdSql.checkData(0, 0, None)
|
||||
# tdSql.execute("insert into jsons1_21 using jsons1 tags(NULL) values(1591061628000, 11, false, '你就会','')")
|
||||
# tdSql.query("select jtag from jsons1_21")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
|
@ -536,24 +539,24 @@ class TDTestCase:
|
|||
tdSql.checkData(5, 2, 4095)
|
||||
#
|
||||
# #test TD-13918
|
||||
# tdSql.execute("drop table if exists jsons_13918_1")
|
||||
# tdSql.execute("drop table if exists jsons_13918_2")
|
||||
# tdSql.execute("drop table if exists jsons_13918_3")
|
||||
# tdSql.execute("drop table if exists jsons_13918_4")
|
||||
# tdSql.execute("drop table if exists jsons_stb")
|
||||
# tdSql.execute("create table jsons_stb (ts timestamp, dataInt int) tags (jtag json)")
|
||||
# tdSql.error("create table jsons_13918_1 using jsons_stb tags ('nullx')")
|
||||
# tdSql.error("create table jsons_13918_2 using jsons_stb tags (nullx)")
|
||||
# tdSql.error("insert into jsons_13918_3 using jsons_stb tags('NULLx') values(1591061628001, 11)")
|
||||
# tdSql.error("insert into jsons_13918_4 using jsons_stb tags(NULLx) values(1591061628002, 11)")
|
||||
# tdSql.execute("create table jsons_13918_1 using jsons_stb tags ('null')")
|
||||
# tdSql.execute("create table jsons_13918_2 using jsons_stb tags (null)")
|
||||
# tdSql.execute("insert into jsons_13918_1 values(1591061628003, 11)")
|
||||
# tdSql.execute("insert into jsons_13918_2 values(1591061628004, 11)")
|
||||
# tdSql.execute("insert into jsons_13918_3 using jsons_stb tags('NULL') values(1591061628005, 11)")
|
||||
# tdSql.execute("insert into jsons_13918_4 using jsons_stb tags(\"NULL\") values(1591061628006, 11)")
|
||||
# tdSql.query("select * from jsons_stb")
|
||||
# tdSql.checkRows(4)
|
||||
tdSql.execute("drop table if exists jsons_13918_1")
|
||||
tdSql.execute("drop table if exists jsons_13918_2")
|
||||
tdSql.execute("drop table if exists jsons_13918_3")
|
||||
tdSql.execute("drop table if exists jsons_13918_4")
|
||||
tdSql.execute("drop table if exists jsons_stb")
|
||||
tdSql.execute("create table jsons_stb (ts timestamp, dataInt int) tags (jtag json)")
|
||||
tdSql.error("create table jsons_13918_1 using jsons_stb tags ('nullx')")
|
||||
tdSql.error("create table jsons_13918_2 using jsons_stb tags (nullx)")
|
||||
tdSql.error("insert into jsons_13918_3 using jsons_stb tags('NULLx') values(1591061628001, 11)")
|
||||
tdSql.error("insert into jsons_13918_4 using jsons_stb tags(NULLx) values(1591061628002, 11)")
|
||||
tdSql.execute("create table jsons_13918_1 using jsons_stb tags ('null')")
|
||||
tdSql.execute("create table jsons_13918_2 using jsons_stb tags (null)")
|
||||
tdSql.execute("insert into jsons_13918_1 values(1591061628003, 11)")
|
||||
tdSql.execute("insert into jsons_13918_2 values(1591061628004, 11)")
|
||||
tdSql.execute("insert into jsons_13918_3 using jsons_stb tags('NULL') values(1591061628005, 11)")
|
||||
tdSql.execute("insert into jsons_13918_4 using jsons_stb tags(\"NULL\") values(1591061628006, 11)")
|
||||
tdSql.query("select * from jsons_stb")
|
||||
tdSql.checkRows(4)
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
Loading…
Reference in New Issue