diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 2f9a18b9fc7c18c7f467e8b550f8e72dc96a55e9..cc6310e9b126f73cc10fb088cd7003b2bc7203ea 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -134,6 +134,7 @@ void tscFieldInfoSetBinExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlFunctionE void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo); void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList, int32_t size); void tscFieldInfoCopyAll(SFieldInfo* dst, SFieldInfo* src); +void tscFieldInfoUpdateBySqlFunc(SQueryInfo* pQueryInfo); TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index); int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index b288b4eee4ec1c469af228efc81b55c8275a894e..bfaae0595d50e52e5a7f2aa809b74a5c030f4e2b 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1998,17 +1998,16 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColum } int32_t getMeterIndex(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) { + pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL; + if (pTableToken->n == 0) { // only one table and no table name prefix in column name if (pQueryInfo->numOfTables == 1) { pIndex->tableIndex = 0; } - + return TSDB_CODE_SUCCESS; } - pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL; - char tableName[TSDB_METER_ID_LEN + 1] = {0}; - for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, i); if (strncasecmp(pMeterMetaInfo->aliasName, pTableToken->z, pTableToken->n) == 0 && diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index eac402df86c193a804e8fb4ad37258b27fb5a8fd..f537e7d187cc3e8afb4ad65e4768cc1f6c59e02e 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -259,8 +259,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pReducer->rowSize = pMemBuffer[0]->nElemSize; tscRestoreSQLFunctionForMetricQuery(pQueryInfo); + tscFieldInfoUpdateBySqlFunc(pQueryInfo); tscFieldInfoCalOffset(pQueryInfo); - + if (pReducer->rowSize > pMemBuffer[0]->pageSize) { assert(false); // todo fixed row size is larger than the minimum page size; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index dbd3f464eaf457b9002bb5cd6af6bfd88e5cfbc1..28e063986c4c403eb34a14a753140264e688f9ca 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -926,6 +926,20 @@ void tscFieldInfoSetBinExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlFunctionE pFieldInfo->pExpr[index] = pExpr; } +void tscFieldInfoUpdateBySqlFunc(SQueryInfo* pQueryInfo) { + for(int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) { + TAOS_FIELD* field = tscFieldInfoGetField(pQueryInfo, i); + + SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i]; + if (pExpr == NULL) { + continue; + } + + field->type = pExpr->resType; + field->bytes = pExpr->resBytes; + } +} + void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo) { SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo; pExprInfo->pExprs[0]->offset = 0; @@ -2012,6 +2026,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void // create the fields info from the sql functions SColumnList columnList = {.num = 1}; + // for avg/last/first/histo.. query, the output type is binary not numeric data type for(int32_t k = 0; k < numOfOutputCols; ++k) { SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, indexList[k]); columnList.ids[0] = (SColumnIndex){.tableIndex = tableIndex, .columnIndex = pExpr->colInfo.colIdx};