[td-1764]
This commit is contained in:
parent
015f1b82c5
commit
8e188274f0
|
@ -149,14 +149,13 @@ int tscAllocPayload(SSqlCmd* pCmd, int size);
|
|||
|
||||
TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes);
|
||||
|
||||
SFieldSupInfo* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField);
|
||||
SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field);
|
||||
SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField);
|
||||
SInternalField* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field);
|
||||
|
||||
SFieldSupInfo* tscFieldInfoGetSupp(SFieldInfo* pFieldInfo, int32_t index);
|
||||
SInternalField* tscFieldInfoGetInternalField(SFieldInfo* pFieldInfo, int32_t index);
|
||||
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
|
||||
|
||||
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
|
||||
void tscFieldInfoCopy(SFieldInfo* dst, const SFieldInfo* src);
|
||||
void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo);
|
||||
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||
|
|
|
@ -142,16 +142,17 @@ typedef struct SColumnIndex {
|
|||
int16_t columnIndex;
|
||||
} SColumnIndex;
|
||||
|
||||
typedef struct SFieldSupInfo {
|
||||
typedef struct SInternalField {
|
||||
TAOS_FIELD field;
|
||||
bool visible;
|
||||
SExprInfo *pArithExprInfo;
|
||||
SSqlExpr *pSqlExpr;
|
||||
} SFieldSupInfo;
|
||||
} SInternalField;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutput; // number of column in result
|
||||
SArray *pFields; // SArray<TAOS_FIELD>
|
||||
SArray *pSupportInfo; // SArray<SFieldSupInfo>
|
||||
int16_t numOfOutput; // number of column in result
|
||||
TAOS_FIELD* final;
|
||||
SArray *internalField; // SArray<SInternalField>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SColumn {
|
||||
|
@ -469,7 +470,7 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s
|
|||
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
|
||||
|
||||
static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) {
|
||||
SFieldSupInfo* pInfo = (SFieldSupInfo*) TARRAY_GET_ELEM(pFieldInfo->pSupportInfo, columnIndex);
|
||||
SInternalField* pInfo = (SInternalField*) TARRAY_GET_ELEM(pFieldInfo->internalField, columnIndex);
|
||||
assert(pInfo->pSqlExpr != NULL);
|
||||
|
||||
int32_t type = pInfo->pSqlExpr->resType;
|
||||
|
|
|
@ -327,7 +327,7 @@ void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols; ++i){
|
||||
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
SInternalField* pSup = taosArrayGet(pQueryInfo->fieldsInfo.internalField, i);
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
// pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pSup->pSqlExpr->resBytes * pRes->row;
|
||||
} else {
|
||||
|
@ -348,7 +348,7 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
|
|||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols; ++i) {
|
||||
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
SInternalField* pSup = taosArrayGet(pQueryInfo->fieldsInfo.internalField, i);
|
||||
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
tscGetResultColumnChr(pRes, &pQueryInfo->fieldsInfo, i);
|
||||
|
|
|
@ -239,7 +239,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = (TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE};
|
||||
tstrncpy(f.name, "Field", sizeof(f.name));
|
||||
|
||||
SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
SInternalField* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||
(TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE, (TSDB_COL_NAME_LEN - 1), false);
|
||||
|
||||
|
@ -485,7 +485,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
|
|||
tstrncpy(f.name, "Database", sizeof(f.name));
|
||||
}
|
||||
|
||||
SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
SInternalField* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||
f.bytes, f.bytes - VARSTR_HEADER_SIZE, false);
|
||||
|
||||
|
@ -922,19 +922,17 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
|||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
pQueryInfo->fieldsInfo.pFields = taosArrayInit(1, sizeof(TAOS_FIELD));
|
||||
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(1, sizeof(SFieldSupInfo));
|
||||
pQueryInfo->fieldsInfo.internalField = taosArrayInit(1, sizeof(SInternalField));
|
||||
|
||||
TAOS_FIELD f = tscCreateField((int8_t)type, columnName, (int16_t)valueLength);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
|
||||
tscInitResObjForLocalQuery(pSql, 1, (int32_t)valueLength);
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0);
|
||||
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, 0);
|
||||
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
|
||||
memcpy(pRes->data, val, pField->bytes);
|
||||
memcpy(pRes->data, val, pInfo->field.bytes);
|
||||
}
|
||||
|
||||
int tscProcessLocalCmd(SSqlObj *pSql) {
|
||||
|
|
|
@ -122,7 +122,7 @@ static int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSql
|
|||
static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo);
|
||||
static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo);
|
||||
static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index);
|
||||
static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* pExprInfo, SQueryInfo* pQueryInfo, SArray* pCols);
|
||||
static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid);
|
||||
|
||||
/*
|
||||
* Used during parsing query sql. Since the query sql usually small in length, error position
|
||||
|
@ -1250,7 +1250,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
|||
tExprNode* pNode = NULL;
|
||||
SArray* colList = taosArrayInit(10, sizeof(SColIndex));
|
||||
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pNode, pItem->pNode, pQueryInfo->exprList, pQueryInfo, colList);
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pNode, pItem->pNode, pQueryInfo, colList, NULL);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(colList);
|
||||
tExprTreeDestroy(&pNode, NULL);
|
||||
|
@ -1306,17 +1306,17 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
|||
insertResultField(pQueryInfo, exprIndex, &columnList, sizeof(double), TSDB_DATA_TYPE_DOUBLE, aliasName, NULL);
|
||||
|
||||
int32_t slot = tscNumOfFields(pQueryInfo) - 1;
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, slot);
|
||||
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, slot);
|
||||
|
||||
if (pInfo->pSqlExpr == NULL) {
|
||||
SExprInfo* pArithExprInfo = calloc(1, sizeof(SExprInfo));
|
||||
|
||||
// arithmetic expression always return result in the format of double float
|
||||
pArithExprInfo->bytes = sizeof(double);
|
||||
pArithExprInfo->bytes = sizeof(double);
|
||||
pArithExprInfo->interBytes = sizeof(double);
|
||||
pArithExprInfo->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pArithExprInfo->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pArithExprInfo->pExpr, pItem->pNode, pQueryInfo->exprList, pQueryInfo, NULL);
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pArithExprInfo->pExpr, pItem->pNode, pQueryInfo, NULL, &pArithExprInfo->uid);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tExprTreeDestroy(&pArithExprInfo->pExpr, NULL);
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "invalid expression in select clause");
|
||||
|
@ -1373,7 +1373,7 @@ static void addPrimaryTsColIntoResult(SQueryInfo* pQueryInfo) {
|
|||
int32_t numOfCols = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
||||
tscAddSpecialColumnForSelect(pQueryInfo, numOfCols, TSDB_FUNC_PRJ, &index, pSchema, TSDB_COL_NORMAL);
|
||||
|
||||
SFieldSupInfo* pSupInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, numOfCols);
|
||||
SInternalField* pSupInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, numOfCols);
|
||||
pSupInfo->visible = false;
|
||||
|
||||
pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY;
|
||||
|
@ -1470,7 +1470,7 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi
|
|||
}
|
||||
|
||||
TAOS_FIELD f = tscCreateField(type, fieldName, bytes);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoInsert(&pQueryInfo->fieldsInfo, outputIndex, &f);
|
||||
SInternalField* pInfo = tscFieldInfoInsert(&pQueryInfo->fieldsInfo, outputIndex, &f);
|
||||
pInfo->pSqlExpr = pSqlExpr;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -4063,7 +4063,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
|
|||
tExprNode* p = NULL;
|
||||
|
||||
SArray* colList = taosArrayInit(10, sizeof(SColIndex));
|
||||
ret = exprTreeFromSqlExpr(pCmd, &p, p1, NULL, pQueryInfo, colList);
|
||||
ret = exprTreeFromSqlExpr(pCmd, &p, p1, pQueryInfo, colList, NULL);
|
||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||
|
||||
TRY(0) {
|
||||
|
@ -5316,7 +5316,7 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex) {
|
|||
|
||||
tscAddSpecialColumnForSelect(pQueryInfo, (int32_t)size, TSDB_FUNC_PRJ, &colIndex, pSchema, TSDB_COL_NORMAL);
|
||||
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, (int32_t)size);
|
||||
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, (int32_t)size);
|
||||
doLimitOutputNormalColOfGroupby(pInfo->pSqlExpr);
|
||||
pInfo->visible = false;
|
||||
}
|
||||
|
@ -6361,19 +6361,19 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
return TSDB_CODE_SUCCESS; // Does not build query message here
|
||||
}
|
||||
|
||||
int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* pExprInfo, SQueryInfo* pQueryInfo, SArray* pCols) {
|
||||
int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid) {
|
||||
tExprNode* pLeft = NULL;
|
||||
tExprNode* pRight= NULL;
|
||||
|
||||
if (pSqlExpr->pLeft != NULL) {
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pLeft, pSqlExpr->pLeft, pExprInfo, pQueryInfo, pCols);
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pLeft, pSqlExpr->pLeft, pQueryInfo, pCols, uid);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (pSqlExpr->pRight != NULL) {
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pRight, pSqlExpr->pRight, pExprInfo, pQueryInfo, pCols);
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pRight, pSqlExpr->pRight, pQueryInfo, pCols, uid);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -6400,14 +6400,19 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
|
|||
strncpy((*pExpr)->pSchema->name, pSqlExpr->operand.z, pSqlExpr->operand.n);
|
||||
|
||||
// set the input column data byte and type.
|
||||
size_t size = taosArrayGetSize(pExprInfo);
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprList);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* p1 = taosArrayGetP(pExprInfo, i);
|
||||
SSqlExpr* p1 = taosArrayGetP(pQueryInfo->exprList, i);
|
||||
|
||||
if (strcmp((*pExpr)->pSchema->name, p1->aliasName) == 0) {
|
||||
(*pExpr)->pSchema->type = (uint8_t)p1->resType;
|
||||
(*pExpr)->pSchema->type = (uint8_t)p1->resType;
|
||||
(*pExpr)->pSchema->bytes = p1->resBytes;
|
||||
|
||||
if (uid != NULL) {
|
||||
*uid = p1->uid;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1934,7 +1934,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
|||
tscColumnListInsert(pQueryInfo->colList, &index);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(pSchema->type, pSchema->name, pSchema->bytes);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoAppend(pFieldInfo, &f);
|
||||
SInternalField* pInfo = tscFieldInfoAppend(pFieldInfo, &f);
|
||||
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index,
|
||||
pTableSchema[i].type, pTableSchema[i].bytes, pTableSchema[i].bytes, false);
|
||||
|
|
|
@ -370,7 +370,7 @@ int taos_num_fields(TAOS_RES *res) {
|
|||
|
||||
size_t numOfCols = tscNumOfFields(pQueryInfo);
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SFieldSupInfo* pInfo = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
SInternalField* pInfo = taosArrayGet(pQueryInfo->fieldsInfo.internalField, i);
|
||||
if (pInfo->visible) {
|
||||
num++;
|
||||
}
|
||||
|
@ -406,8 +406,24 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
|||
if (numOfCols == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pQueryInfo->fieldsInfo.pFields->pData;
|
||||
|
||||
SFieldInfo *pFieldInfo = &pQueryInfo->fieldsInfo;
|
||||
|
||||
if (pFieldInfo->final == NULL) {
|
||||
TAOS_FIELD* f = calloc(pFieldInfo->numOfOutput, sizeof(TAOS_FIELD));
|
||||
|
||||
int32_t j = 0;
|
||||
for(int32_t i = 0; i < pFieldInfo->numOfOutput; ++i) {
|
||||
SInternalField* pField = tscFieldInfoGetInternalField(pFieldInfo, i);
|
||||
if (pField->visible) {
|
||||
f[j++] = pField->field;
|
||||
}
|
||||
}
|
||||
|
||||
pFieldInfo->final = f;
|
||||
}
|
||||
|
||||
return pFieldInfo->final;
|
||||
}
|
||||
|
||||
int taos_retrieve(TAOS_RES *res) {
|
||||
|
|
|
@ -2013,7 +2013,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
|
|||
static char* getResultBlockPosition(SSqlCmd* pCmd, SSqlRes* pRes, int32_t columnIndex, int16_t* bytes) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
SFieldSupInfo* pInfo = (SFieldSupInfo*) TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.pSupportInfo, columnIndex);
|
||||
SInternalField* pInfo = (SInternalField*) TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.internalField, columnIndex);
|
||||
assert(pInfo->pSqlExpr != NULL);
|
||||
|
||||
*bytes = pInfo->pSqlExpr->resBytes;
|
||||
|
@ -2163,7 +2163,7 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) {
|
|||
|
||||
size_t size = tscNumOfFields(pQueryInfo);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
SFieldSupInfo* pSup = TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
SInternalField* pSup = TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.internalField, i);
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
tscGetResultColumnChr(pRes, &pQueryInfo->fieldsInfo, i);
|
||||
}
|
||||
|
@ -2173,7 +2173,7 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) {
|
|||
continue;
|
||||
}
|
||||
|
||||
TAOS_FIELD *pField = TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.pFields, i);
|
||||
TAOS_FIELD *pField = TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.internalField, i);
|
||||
if (pRes->tsrow[i] != NULL && pField->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
transferNcharData(pSql, i, pField);
|
||||
}
|
||||
|
|
|
@ -847,35 +847,30 @@ TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes) {
|
|||
return f;
|
||||
}
|
||||
|
||||
SFieldSupInfo* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) {
|
||||
SInternalField* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) {
|
||||
assert(pFieldInfo != NULL);
|
||||
taosArrayPush(pFieldInfo->pFields, pField);
|
||||
pFieldInfo->numOfOutput++;
|
||||
|
||||
struct SFieldSupInfo info = {
|
||||
struct SInternalField info = {
|
||||
.pSqlExpr = NULL,
|
||||
.pArithExprInfo = NULL,
|
||||
.visible = true,
|
||||
};
|
||||
|
||||
return taosArrayPush(pFieldInfo->pSupportInfo, &info);
|
||||
|
||||
info.field = *pField;
|
||||
return taosArrayPush(pFieldInfo->internalField, &info);
|
||||
}
|
||||
|
||||
SFieldSupInfo* tscFieldInfoGetSupp(SFieldInfo* pFieldInfo, int32_t index) {
|
||||
return TARRAY_GET_ELEM(pFieldInfo->pSupportInfo, index);
|
||||
}
|
||||
|
||||
SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field) {
|
||||
taosArrayInsert(pFieldInfo->pFields, index, field);
|
||||
SInternalField* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field) {
|
||||
pFieldInfo->numOfOutput++;
|
||||
|
||||
struct SFieldSupInfo info = {
|
||||
struct SInternalField info = {
|
||||
.pSqlExpr = NULL,
|
||||
.pArithExprInfo = NULL,
|
||||
.visible = true,
|
||||
};
|
||||
|
||||
return taosArrayInsert(pFieldInfo->pSupportInfo, index, &info);
|
||||
|
||||
info.field = *field;
|
||||
return taosArrayInsert(pFieldInfo->internalField, index, &info);
|
||||
}
|
||||
|
||||
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo) {
|
||||
|
@ -909,29 +904,18 @@ void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
void tscFieldInfoCopy(SFieldInfo* dst, const SFieldInfo* src) {
|
||||
dst->numOfOutput = src->numOfOutput;
|
||||
|
||||
if (dst->pFields == NULL) {
|
||||
dst->pFields = taosArrayClone(src->pFields);
|
||||
} else {
|
||||
taosArrayCopy(dst->pFields, src->pFields);
|
||||
}
|
||||
|
||||
if (dst->pSupportInfo == NULL) {
|
||||
dst->pSupportInfo = taosArrayClone(src->pSupportInfo);
|
||||
} else {
|
||||
taosArrayCopy(dst->pSupportInfo, src->pSupportInfo);
|
||||
}
|
||||
SInternalField* tscFieldInfoGetInternalField(SFieldInfo* pFieldInfo, int32_t index) {
|
||||
assert(index < pFieldInfo->numOfOutput);
|
||||
return TARRAY_GET_ELEM(pFieldInfo->internalField, index);
|
||||
}
|
||||
|
||||
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) {
|
||||
assert(index < pFieldInfo->numOfOutput);
|
||||
return TARRAY_GET_ELEM(pFieldInfo->pFields, index);
|
||||
return &((SInternalField*)TARRAY_GET_ELEM(pFieldInfo->internalField, index))->field;
|
||||
}
|
||||
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index) {
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, index);
|
||||
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, index);
|
||||
assert(pInfo != NULL && pInfo->pSqlExpr != NULL);
|
||||
|
||||
return pInfo->pSqlExpr->offset;
|
||||
|
@ -978,10 +962,8 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
|
|||
return;
|
||||
}
|
||||
|
||||
taosArrayDestroy(pFieldInfo->pFields);
|
||||
|
||||
for(int32_t i = 0; i < pFieldInfo->numOfOutput; ++i) {
|
||||
SFieldSupInfo* pInfo = taosArrayGet(pFieldInfo->pSupportInfo, i);
|
||||
SInternalField* pInfo = taosArrayGet(pFieldInfo->internalField, i);
|
||||
|
||||
if (pInfo->pArithExprInfo != NULL) {
|
||||
tExprTreeDestroy(&pInfo->pArithExprInfo->pExpr, NULL);
|
||||
|
@ -989,7 +971,7 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(pFieldInfo->pSupportInfo);
|
||||
taosArrayDestroy(pFieldInfo->internalField);
|
||||
memset(pFieldInfo, 0, sizeof(SFieldInfo));
|
||||
}
|
||||
|
||||
|
@ -1633,11 +1615,8 @@ STableMetaInfo* tscGetTableMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, i
|
|||
}
|
||||
|
||||
void tscInitQueryInfo(SQueryInfo* pQueryInfo) {
|
||||
assert(pQueryInfo->fieldsInfo.pFields == NULL);
|
||||
pQueryInfo->fieldsInfo.pFields = taosArrayInit(4, sizeof(TAOS_FIELD));
|
||||
|
||||
assert(pQueryInfo->fieldsInfo.pSupportInfo == NULL);
|
||||
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(4, sizeof(SFieldSupInfo));
|
||||
assert(pQueryInfo->fieldsInfo.internalField == NULL);
|
||||
pQueryInfo->fieldsInfo.internalField = taosArrayInit(4, sizeof(SInternalField));
|
||||
|
||||
assert(pQueryInfo->exprList == NULL);
|
||||
pQueryInfo->exprList = taosArrayInit(4, POINTER_BYTES);
|
||||
|
@ -1849,54 +1828,23 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm
|
|||
return pNew;
|
||||
}
|
||||
|
||||
// current sql function is not direct output result, so create a dummy output field
|
||||
static void doSetNewFieldInfo(SQueryInfo* pNewQueryInfo, SSqlExpr* pExpr) {
|
||||
TAOS_FIELD f = {.type = (uint8_t)pExpr->resType, .bytes = pExpr->resBytes};
|
||||
tstrncpy(f.name, pExpr->aliasName, sizeof(f.name));
|
||||
|
||||
SFieldSupInfo* pInfo1 = tscFieldInfoAppend(&pNewQueryInfo->fieldsInfo, &f);
|
||||
|
||||
pInfo1->pSqlExpr = pExpr;
|
||||
pInfo1->visible = false;
|
||||
}
|
||||
|
||||
static void doSetSqlExprAndResultFieldInfo(SQueryInfo* pQueryInfo, SQueryInfo* pNewQueryInfo, int64_t uid) {
|
||||
int32_t numOfOutput = (int32_t)tscSqlExprNumOfExprs(pNewQueryInfo);
|
||||
if (numOfOutput == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
|
||||
|
||||
// set the field info in pNewQueryInfo object
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pNewQueryInfo);
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pNewQueryInfo, i);
|
||||
|
||||
if (pExpr->uid == uid) {
|
||||
if (i < pFieldInfo->numOfOutput) {
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(pFieldInfo, i);
|
||||
|
||||
if (pInfo->pSqlExpr != NULL) {
|
||||
TAOS_FIELD* p = tscFieldInfoGetField(pFieldInfo, i);
|
||||
assert(strcmp(p->name, pExpr->aliasName) == 0);
|
||||
|
||||
SFieldSupInfo* pInfo1 = tscFieldInfoAppend(&pNewQueryInfo->fieldsInfo, p);
|
||||
*pInfo1 = *pInfo;
|
||||
} else {
|
||||
assert(pInfo->pArithExprInfo != NULL);
|
||||
doSetNewFieldInfo(pNewQueryInfo, pExpr);
|
||||
}
|
||||
} else { // it is a arithmetic column, does not have actual field for sqlExpr, so build it
|
||||
doSetNewFieldInfo(pNewQueryInfo, pExpr);
|
||||
}
|
||||
}
|
||||
TAOS_FIELD f = tscCreateField(pExpr->resType, pExpr->aliasName, pExpr->resBytes);
|
||||
SInternalField* pInfo1 = tscFieldInfoAppend(&pNewQueryInfo->fieldsInfo, &f);
|
||||
pInfo1->pSqlExpr = pExpr;
|
||||
}
|
||||
|
||||
// make sure the the sqlExpr for each fields is correct
|
||||
numOfExprs = tscSqlExprNumOfExprs(pNewQueryInfo);
|
||||
|
||||
// update the pSqlExpr pointer in SFieldSupInfo according the field name
|
||||
// update the pSqlExpr pointer in SInternalField according the field name
|
||||
// make sure the pSqlExpr point to the correct SqlExpr in pNewQueryInfo, not SqlExpr in pQueryInfo
|
||||
for (int32_t f = 0; f < pNewQueryInfo->fieldsInfo.numOfOutput; ++f) {
|
||||
TAOS_FIELD* field = tscFieldInfoGetField(&pNewQueryInfo->fieldsInfo, f);
|
||||
|
@ -1906,7 +1854,7 @@ static void doSetSqlExprAndResultFieldInfo(SQueryInfo* pQueryInfo, SQueryInfo* p
|
|||
SSqlExpr* pExpr1 = tscSqlExprGet(pNewQueryInfo, k1);
|
||||
|
||||
if (strcmp(field->name, pExpr1->aliasName) == 0) { // establish link according to the result field name
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pNewQueryInfo->fieldsInfo, f);
|
||||
SInternalField* pInfo = tscFieldInfoGetInternalField(&pNewQueryInfo->fieldsInfo, f);
|
||||
pInfo->pSqlExpr = pExpr1;
|
||||
|
||||
matched = true;
|
||||
|
|
|
@ -407,6 +407,7 @@ typedef struct SExprInfo {
|
|||
int16_t bytes;
|
||||
int16_t type;
|
||||
int32_t interBytes;
|
||||
int64_t uid;
|
||||
} SExprInfo;
|
||||
|
||||
typedef struct SColumnFilterInfo {
|
||||
|
|
Loading…
Reference in New Issue