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

fix the output format of json string; add ""

上级 10036749
......@@ -763,19 +763,27 @@ static void setResRawPtrImpl(SSqlRes* pRes, SInternalField* pInfo, int32_t i, bo
char* dst = pRes->buffer[i] + k * pInfo->field.bytes;
char type = *p;
char* realData = p + CHAR_BYTES;
if (type == TSDB_DATA_TYPE_NCHAR && isNull(realData, TSDB_DATA_TYPE_NCHAR)) {
if (type == TSDB_DATA_TYPE_JSON && isNull(realData, TSDB_DATA_TYPE_JSON)) {
memcpy(dst, realData, varDataTLen(realData));
} else if (type == TSDB_DATA_TYPE_BINARY) {
assert(*(uint32_t*)varDataVal(realData) == TSDB_DATA_JSON_null); // json null value
assert(varDataLen(realData) == INT_BYTES);
sprintf(varDataVal(dst), "%s", "null");
varDataSetLen(dst, strlen(varDataVal(dst)));
}else if (type == TSDB_DATA_TYPE_NCHAR) {
}else if (type == TSDB_DATA_TYPE_JSON) {
int32_t length = taosUcs4ToMbs(varDataVal(realData), varDataLen(realData), varDataVal(dst));
varDataSetLen(dst, length);
if (length == 0) {
tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)p);
}
}else if (type == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
*(char*)varDataVal(dst) = '\"';
int32_t length = taosUcs4ToMbs(varDataVal(realData), varDataLen(realData), POINTER_SHIFT(varDataVal(dst), CHAR_BYTES));
*(char*)(POINTER_SHIFT(varDataVal(dst), length + CHAR_BYTES)) = '\"';
varDataSetLen(dst, length + CHAR_BYTES*2);
if (length == 0) {
tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)p);
}
}else if (type == TSDB_DATA_TYPE_DOUBLE) {
double jsonVd = *(double*)(realData);
sprintf(varDataVal(dst), "%.9lf", jsonVd);
......
......@@ -69,7 +69,7 @@ class TDTestCase:
# test select condition
tdSql.query("select jtag->'location' from db_json_tag_test.jsons1_2")
tdSql.checkData(0, 0, "beijing")
tdSql.checkData(0, 0, "\"beijing\"")
tdSql.query("select jtag->'location' from db_json_tag_test.jsons1")
tdSql.checkRows(4)
......@@ -105,7 +105,7 @@ class TDTestCase:
tdSql.checkRows(0)
tdSql.query("select jtag->'sex' from db_json_tag_test.jsons1 where jtag?'sex' or jtag?'num'")
tdSql.checkData(0, 0, "femail")
tdSql.checkData(0, 0, "\"femail\"")
tdSql.checkRows(3)
tdSql.query("select *,tbname from db_json_tag_test.jsons1 where jtag->'location'='beijing'")
......@@ -265,13 +265,13 @@ class TDTestCase:
tdSql.execute("insert into db_json_tag_test.jsons2_1 values('2020-04-18 15:00:00.000', 1, false, 'json1')")
tdSql.query("select 'sss',33,a.jtag->'loc' from db_json_tag_test.jsons2 a,db_json_tag_test.jsons3 b where a.ts=b.ts and a.jtag->'loc'=b.jtag->'loc'")
tdSql.checkData(0, 0, "sss")
tdSql.checkData(0, 2, "fff")
tdSql.checkData(0, 2, "\"fff\"")
# test group by & order by string
tdSql.query("select avg(dataint),count(*) from db_json_tag_test.jsons1 group by jtag->'location' order by jtag->'location' desc")
tdSql.checkData(1, 0, 2.5)
tdSql.checkData(1, 1, 2)
tdSql.checkData(1, 2, "beijing")
tdSql.checkData(1, 2, "\"beijing\"")
tdSql.checkData(2, 2, None)
# test group by & order by int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册