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

append json field after inter field for [change json type with qid return logic]

上级 35801b0d
...@@ -80,6 +80,7 @@ typedef struct SInternalField { ...@@ -80,6 +80,7 @@ typedef struct SInternalField {
TAOS_FIELD field; TAOS_FIELD field;
bool visible; bool visible;
SExprInfo *pExpr; SExprInfo *pExpr;
TAOS_FIELD fieldJson; // for tag json
} SInternalField; } SInternalField;
typedef struct SParamInfo { typedef struct SParamInfo {
......
...@@ -2655,12 +2655,13 @@ static void updateFieldForJson(SSqlObj *pSql, SQueryTableRsp *pQueryAttr){ ...@@ -2655,12 +2655,13 @@ static void updateFieldForJson(SSqlObj *pSql, SQueryTableRsp *pQueryAttr){
SInternalField *pField = tscFieldInfoGetInternalField(pFieldInfo, i); SInternalField *pField = tscFieldInfoGetInternalField(pFieldInfo, i);
if (pField->field.type == TSDB_DATA_TYPE_JSON) { if (pField->field.type == TSDB_DATA_TYPE_JSON) {
pField->fieldJson.type = TSDB_DATA_TYPE_JSON;
for (int k = 0; k < pQueryAttr->tJsonSchLen; ++k) { for (int k = 0; k < pQueryAttr->tJsonSchLen; ++k) {
if (strncmp(pField->field.name, pQueryAttr->tagJsonSchema[k].name, TSDB_MAX_JSON_KEY_LEN) == 0) { if (strncmp(pField->field.name, pQueryAttr->tagJsonSchema[k].name, TSDB_MAX_JSON_KEY_LEN) == 0) {
pField->field.type = pQueryAttr->tagJsonSchema[k].type; pField->fieldJson.type = pQueryAttr->tagJsonSchema[k].type;
pField->field.bytes = TYPE_BYTES[pField->field.type]; pField->fieldJson.bytes = TYPE_BYTES[pField->field.type];
tscDebug("0x%" PRIx64 " change json type %s:%s to %d", pSql->self, pField->field.name, pQueryAttr->tagJsonSchema[k].name, tscDebug("0x%" PRIx64 " change json type %s:%s to %d", pSql->self, pField->field.name, pQueryAttr->tagJsonSchema[k].name,
pField->field.type); pField->fieldJson.type);
break; break;
} }
} }
......
...@@ -439,6 +439,12 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { ...@@ -439,6 +439,12 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
if (pField->visible) { if (pField->visible) {
f[j] = pField->field; f[j] = pField->field;
if(f[j].type == TSDB_DATA_TYPE_JSON){
f[j].type = pField->fieldJson.type;
if(!IS_VAR_DATA_TYPE(f[j].type) && f[j].type != TSDB_DATA_TYPE_JSON){
f[j].bytes = pField->fieldJson.bytes;
}
}
// revise the length for binary and nchar fields // revise the length for binary and nchar fields
if (f[j].type == TSDB_DATA_TYPE_BINARY) { if (f[j].type == TSDB_DATA_TYPE_BINARY) {
f[j].bytes -= VARSTR_HEADER_SIZE; f[j].bytes -= VARSTR_HEADER_SIZE;
......
...@@ -2247,7 +2247,7 @@ SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) { ...@@ -2247,7 +2247,7 @@ SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) {
assert(pFieldInfo != NULL); assert(pFieldInfo != NULL);
pFieldInfo->numOfOutput++; pFieldInfo->numOfOutput++;
struct SInternalField info = { .pExpr = NULL, .visible = true }; struct SInternalField info = { .pExpr = NULL, .visible = true, .fieldJson={0} };
info.field = *pField; info.field = *pField;
return taosArrayPush(pFieldInfo->internalField, &info); return taosArrayPush(pFieldInfo->internalField, &info);
...@@ -2255,7 +2255,7 @@ SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) { ...@@ -2255,7 +2255,7 @@ SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) {
SInternalField* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field) { SInternalField* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field) {
pFieldInfo->numOfOutput++; pFieldInfo->numOfOutput++;
struct SInternalField info = { .pExpr = NULL, .visible = true }; struct SInternalField info = { .pExpr = NULL, .visible = true, .fieldJson={0}};
info.field = *field; info.field = *field;
return taosArrayInsert(pFieldInfo->internalField, index, &info); return taosArrayInsert(pFieldInfo->internalField, index, &info);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册