[td-171] refactor client code
This commit is contained in:
parent
59a77a3657
commit
47c2796bf7
|
@ -58,7 +58,7 @@ typedef struct SJoinSubquerySupporter {
|
|||
SLimitVal limit; // limit info
|
||||
uint64_t uid; // query meter uid
|
||||
SArray* colList; // previous query information
|
||||
SSqlExprInfo exprsInfo;
|
||||
SArray* exprsInfo;
|
||||
SFieldInfo fieldsInfo;
|
||||
STagCond tagCond;
|
||||
SSqlGroupbyExpr groupbyExpr;
|
||||
|
@ -85,8 +85,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
|
|||
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
||||
STableDataBlocks** dataBlocks);
|
||||
|
||||
SVnodeSidList* tscGetVnodeSidList(SSuperTableMeta* pMetricmeta, int32_t vnodeIdx);
|
||||
STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
|
||||
UNUSED_FUNC STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -115,49 +114,49 @@ void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex
|
|||
|
||||
void addRequiredTagColumn(SQueryInfo* pQueryInfo, int32_t tagColIndex, int32_t tableIndex);
|
||||
|
||||
int32_t setMeterID(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
|
||||
int32_t tscSetTableId(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
|
||||
void tscClearInterpInfo(SQueryInfo* pQueryInfo);
|
||||
|
||||
bool tscIsInsertOrImportData(char* sqlstr);
|
||||
|
||||
/* use for keep current db info temporarily, for handle table with db prefix */
|
||||
// todo remove it
|
||||
void tscGetDBInfoFromMeterId(char* tableId, char* db);
|
||||
|
||||
int tscAllocPayload(SSqlCmd* pCmd, int size);
|
||||
|
||||
void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema);
|
||||
void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField);
|
||||
void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, const char* name, int16_t bytes);
|
||||
void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible);
|
||||
void tscFieldInfoSetExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlExpr* pExpr);
|
||||
void tscFieldInfoSetBinExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlFunctionExpr* pExpr);
|
||||
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);
|
||||
|
||||
SFieldSupInfo* tscFieldInfoGetSupp(SFieldInfo* pFieldInfo, int32_t index);
|
||||
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
|
||||
|
||||
void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo);
|
||||
void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList, int32_t size);
|
||||
void tscFieldInfoCopyAll(SFieldInfo* dst, SFieldInfo* src);
|
||||
void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo);
|
||||
|
||||
TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index);
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||
int32_t tscGetResRowLength(SQueryInfo* pQueryInfo);
|
||||
void tscClearFieldInfo(SFieldInfo* pFieldInfo);
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||
void tscFieldInfoClear(SFieldInfo* pFieldInfo);
|
||||
int32_t tscNumOfFields(SQueryInfo* pQueryInfo);
|
||||
int32_t tscFieldInfoCompare(SFieldInfo* pFieldInfo1, SFieldInfo* pFieldInfo2);
|
||||
int32_t tscFieldInfoCompare(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2);
|
||||
|
||||
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex);
|
||||
|
||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t interSize);
|
||||
SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId);
|
||||
int32_t tscGetResRowLength(SArray* pExprList);
|
||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t interSize);
|
||||
SSqlExpr* tscSqlExprAppend(SArray* exprInfo, int16_t functionId);
|
||||
|
||||
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||
int16_t size);
|
||||
int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo);
|
||||
|
||||
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
|
||||
void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t uid, bool deepcopy);
|
||||
void* tscSqlExprDestroy(SSqlExpr* pExpr);
|
||||
void tscSqlExprInfoDestroy(SSqlExprInfo* pExprInfo);
|
||||
SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy);
|
||||
void tscSqlExprInfoDestroy(SArray* pExprInfo);
|
||||
|
||||
SColumn* tscColumnClone(const SColumn* src);
|
||||
SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex);
|
||||
|
@ -184,17 +183,16 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo);
|
|||
void tscSetFreeHeatBeat(STscObj* pObj);
|
||||
bool tscShouldFreeHeatBeat(SSqlObj* pHb);
|
||||
void tscCleanSqlCmd(SSqlCmd* pCmd);
|
||||
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql);
|
||||
bool tscShouldBeFreed(SSqlObj* pSql);
|
||||
|
||||
void tscRemoveAllMeterMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||
void tscClearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex);
|
||||
STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||
|
||||
SQueryInfo *tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||
int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo);
|
||||
|
||||
STableMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index);
|
||||
void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache);
|
||||
void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache);
|
||||
|
||||
STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta,
|
||||
SVgroupsInfo* vgroupList, int16_t numOfTags, int16_t* tags);
|
||||
|
@ -204,7 +202,6 @@ int32_t tscAddSubqueryInfo(SSqlCmd *pCmd);
|
|||
void tscFreeSubqueryInfo(SSqlCmd* pCmd);
|
||||
void tscClearSubqueryInfo(SSqlCmd* pCmd);
|
||||
|
||||
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* keyStr, uint64_t uid);
|
||||
int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex);
|
||||
int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo);
|
||||
int tscGetMeterMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists);
|
||||
|
|
|
@ -34,8 +34,6 @@ extern "C" {
|
|||
#include "tsqlfunction.h"
|
||||
#include "queryExecutor.h"
|
||||
|
||||
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
|
||||
|
||||
// forward declaration
|
||||
struct SSqlInfo;
|
||||
|
||||
|
@ -92,29 +90,18 @@ typedef struct SColumnIndex {
|
|||
int16_t columnIndex;
|
||||
} SColumnIndex;
|
||||
|
||||
typedef struct SFieldSupInfo {
|
||||
bool visible;
|
||||
SArithExprInfo* pArithExprInfo;
|
||||
SSqlExpr* pSqlExpr;
|
||||
} SFieldSupInfo;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutputCols; // number of column in result
|
||||
int16_t numOfAlloc; // allocated size
|
||||
TAOS_FIELD *pFields;
|
||||
|
||||
/*
|
||||
* define if this column is belong to the queried result, it may be add by parser to faciliate
|
||||
* the query process
|
||||
*
|
||||
* NOTE: these hidden columns always locate at the end of the output columns
|
||||
*/
|
||||
bool * pVisibleCols;
|
||||
int32_t numOfHiddenCols; // the number of column not belongs to the queried result columns
|
||||
SSqlFunctionExpr** pExpr; // used for aggregation arithmetic express,such as count(*)+count(*)
|
||||
SSqlExpr** pSqlExpr;
|
||||
int16_t numOfOutput; // number of column in result
|
||||
SArray* pFields; // SArray<TAOS_FIELD>
|
||||
SArray* pSupportInfo; // SArray<SFieldSupInfo>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SSqlExprInfo {
|
||||
int16_t numOfAlloc;
|
||||
int16_t numOfExprs;
|
||||
SSqlExpr** pExprs;
|
||||
} SSqlExprInfo;
|
||||
|
||||
typedef struct SColumn {
|
||||
SColumnIndex colIndex;
|
||||
int32_t numOfFilters;
|
||||
|
@ -193,7 +180,7 @@ typedef struct STableDataBlocks {
|
|||
SParamInfo *params;
|
||||
} STableDataBlocks;
|
||||
|
||||
typedef struct SDataBlockList {
|
||||
typedef struct SDataBlockList { // todo remove
|
||||
uint32_t nSize;
|
||||
uint32_t nAlloc;
|
||||
STableDataBlocks **pData;
|
||||
|
@ -209,9 +196,9 @@ typedef struct SQueryInfo {
|
|||
int64_t slidingTime; // sliding window in mseconds
|
||||
SSqlGroupbyExpr groupbyExpr; // group by tags info
|
||||
|
||||
SArray* colList;
|
||||
SArray* colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SSqlExprInfo exprsInfo;
|
||||
SArray* exprsInfo; // SArray<SSqlExpr*>
|
||||
SLimitVal limit;
|
||||
SLimitVal slimit;
|
||||
STagCond tagCond;
|
||||
|
@ -441,6 +428,7 @@ int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *s
|
|||
|
||||
void tscQueueAsyncFreeResult(SSqlObj *pSql);
|
||||
int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
||||
char* tscGetResultColumnChr(SSqlRes* pRes, SQueryInfo* pQueryInfo, int32_t column);
|
||||
|
||||
extern void * pVnodeConn;
|
||||
extern void * pTscMgmtConn;
|
||||
|
|
|
@ -287,9 +287,9 @@ void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols; ++i){
|
||||
SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i];
|
||||
if (pExpr != NULL) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pExpr->resBytes * pRes->row;
|
||||
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
// pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pSup->pSqlExpr->resBytes * pRes->row;
|
||||
} else {
|
||||
//todo add
|
||||
}
|
||||
|
@ -308,11 +308,12 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
|
|||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols; ++i) {
|
||||
SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i];
|
||||
if (pExpr != NULL) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pExpr->resBytes * pRes->row;
|
||||
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i);
|
||||
} else {
|
||||
//todo add
|
||||
// todo add
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +333,7 @@ void tscProcessAsyncRes(SSchedMsg *pMsg) {
|
|||
int code = pRes->code;
|
||||
|
||||
// in case of async insert, restore the user specified callback function
|
||||
bool shouldFree = tscShouldFreeAsyncSqlObj(pSql);
|
||||
bool shouldFree = tscShouldBeFreed(pSql);
|
||||
|
||||
if (cmd == TSDB_SQL_INSERT) {
|
||||
assert(pSql->fp != NULL);
|
||||
|
|
|
@ -3297,7 +3297,7 @@ static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
|||
char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
|
||||
SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
|
||||
|
||||
SSqlFunctionExpr *pExpr = pSupport->pExpr;
|
||||
SArithExprInfo *pExpr = pSupport->pArithExpr;
|
||||
int32_t colIndex = -1;
|
||||
|
||||
for (int32_t i = 0; i < pExpr->binExprInfo.numOfCols; ++i) {
|
||||
|
@ -3315,7 +3315,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
|
|||
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
|
||||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||
|
||||
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
|
||||
tSQLBinaryExprCalcTraverse(sas->pArithExpr->binExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
|
||||
arithmetic_callback_function);
|
||||
|
||||
pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size;
|
||||
|
@ -3327,10 +3327,10 @@ static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
|||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||
|
||||
sas->offset = index;
|
||||
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pCtx->aOutputBuf, sas, pCtx->order,
|
||||
tSQLBinaryExprCalcTraverse(sas->pArithExpr->binExprInfo.pBinExpr, 1, pCtx->aOutputBuf, sas, pCtx->order,
|
||||
arithmetic_callback_function);
|
||||
|
||||
pCtx->aOutputBuf += pCtx->outputBytes/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/;
|
||||
pCtx->aOutputBuf += pCtx->outputBytes;
|
||||
}
|
||||
|
||||
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
|
||||
|
|
|
@ -130,13 +130,13 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
SSchema *pSchema = tscGetTableSchema(pMeta);
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
||||
TSDB_COL_NAME_LEN);
|
||||
|
||||
char *type = tDataTypeDesc[pSchema[i].type].aName;
|
||||
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 1);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
|
||||
|
||||
int32_t bytes = pSchema[i].bytes;
|
||||
|
@ -144,10 +144,10 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
bytes = bytes / TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 2);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 2);
|
||||
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3);
|
||||
if (i >= tscGetNumOfColumns(pMeta) && tscGetNumOfTags(pMeta) != 0) {
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i, "tag",
|
||||
strlen("tag") + 1);
|
||||
|
@ -162,18 +162,18 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
char *pTagValue = tsGetTagsValue(pMeta);
|
||||
for (int32_t i = numOfRows; i < totalNumOfRows; ++i) {
|
||||
// field name
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
||||
TSDB_COL_NAME_LEN);
|
||||
|
||||
// type name
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 1);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
|
||||
char *type = tDataTypeDesc[pSchema[i].type].aName;
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
|
||||
|
||||
// type length
|
||||
int32_t bytes = pSchema[i].bytes;
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 2);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 2);
|
||||
if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
bytes = bytes / TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||
|
||||
// tag value
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3);
|
||||
char *target = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i;
|
||||
|
||||
if (isNull(pTagValue, pSchema[i].type)) {
|
||||
|
@ -236,31 +236,47 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, int32_t typeColLength,
|
||||
int32_t noteColLength) {
|
||||
int32_t rowLen = 0;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
pCmd->numOfCols = numOfCols;
|
||||
SColumnIndex index = {0};
|
||||
|
||||
pSql->cmd.numOfCols = numOfCols;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, "Field", TSDB_COL_NAME_LEN);
|
||||
TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_COL_NAME_LEN};
|
||||
strncpy(f.name, "Field", TSDB_COL_NAME_LEN);
|
||||
|
||||
SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, TSDB_COL_NAME_LEN, TSDB_COL_NAME_LEN);
|
||||
|
||||
rowLen += TSDB_COL_NAME_LEN;
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 1, TSDB_DATA_TYPE_BINARY, "Type", typeColLength);
|
||||
f.bytes = typeColLength;
|
||||
f.type = TSDB_DATA_TYPE_BINARY;
|
||||
strncpy(f.name, "Type", TSDB_COL_NAME_LEN);
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength, typeColLength);
|
||||
|
||||
rowLen += typeColLength;
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 2, TSDB_DATA_TYPE_INT, "Length", sizeof(int32_t));
|
||||
f.bytes = sizeof(int32_t);
|
||||
f.type = TSDB_DATA_TYPE_INT;
|
||||
strncpy(f.name, "Length", TSDB_COL_NAME_LEN);
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t), sizeof(int32_t));
|
||||
|
||||
rowLen += sizeof(int32_t);
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 3, TSDB_DATA_TYPE_BINARY, "Note", noteColLength);
|
||||
rowLen += noteColLength;
|
||||
f.bytes = noteColLength;
|
||||
f.type = TSDB_DATA_TYPE_BINARY;
|
||||
strncpy(f.name, "Note", TSDB_COL_NAME_LEN);
|
||||
|
||||
//set the sqlexpr part
|
||||
SColumnIndex index = {0};
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[0] = tscSqlExprInsert(pQueryInfo, 0, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, TSDB_COL_NAME_LEN, TSDB_COL_NAME_LEN);
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[1] = tscSqlExprInsert(pQueryInfo, 1, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength, typeColLength);
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[2] = tscSqlExprInsert(pQueryInfo, 2, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t), sizeof(int32_t));
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[3] = tscSqlExprInsert(pQueryInfo, 3, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength, noteColLength);
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength, noteColLength);
|
||||
|
||||
rowLen += noteColLength;
|
||||
return rowLen;
|
||||
}
|
||||
|
||||
|
@ -310,7 +326,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
int32_t totalNumOfResults = pMetricMeta->numOfTables;
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
|
||||
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
|
||||
|
||||
|
@ -321,7 +337,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
for (int32_t j = 0; j < pSidList->numOfSids; ++j) {
|
||||
STableIdInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
|
||||
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutput; ++k) {
|
||||
SColIndex *pColIndex = &tscSqlExprGet(pQueryInfo, k)->colInfo;
|
||||
int16_t offsetId = pColIndex->colIdx;
|
||||
|
||||
|
@ -329,7 +345,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
assert(0);
|
||||
|
||||
char * val = NULL;//pSidExt->tags + vOffset[offsetId];
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, k);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, k);
|
||||
|
||||
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, k) * totalNumOfResults + pField->bytes * rowIdx, val,
|
||||
(size_t)pField->bytes);
|
||||
|
@ -350,17 +366,17 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
|
|||
#if 0
|
||||
SSuperTableMeta *pMetricMeta = tscGetMetaInfo(pQueryInfo, 0)->pMetricMeta;
|
||||
int32_t totalNumOfResults = 1; // count function only produce one result
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
|
||||
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
|
||||
|
||||
int32_t rowIdx = 0;
|
||||
for (int32_t i = 0; i < totalNumOfResults; ++i) {
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutput; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, k);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, k);
|
||||
|
||||
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, i) * totalNumOfResults + pField->bytes * rowIdx,
|
||||
&pMetricMeta->numOfTables, sizeof(pMetricMeta->numOfTables));
|
||||
|
@ -388,7 +404,7 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
|
|||
return pSql->res.code;
|
||||
}
|
||||
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr *pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
if (pExpr->functionId == TSDB_FUNC_COUNT) {
|
||||
return tscBuildMetricTagSqlFunctionResult(pSql);
|
||||
} else {
|
||||
|
@ -399,7 +415,7 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
|
|||
static void tscProcessCurrentUser(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
|
@ -414,7 +430,7 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
|
|||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN);
|
||||
}
|
||||
|
||||
|
@ -422,14 +438,14 @@ static void tscProcessServerVer(SSqlObj *pSql) {
|
|||
const char* v = pSql->pTscObj->sversion;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, tListLen(pSql->pTscObj->sversion));
|
||||
}
|
||||
|
||||
static void tscProcessClientVer(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version));
|
||||
}
|
||||
|
||||
|
@ -449,7 +465,7 @@ static void tscProcessServStatus(SSqlObj *pSql) {
|
|||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2);
|
||||
}
|
||||
|
||||
|
@ -462,13 +478,16 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
|||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
tscClearFieldInfo(&pQueryInfo->fieldsInfo);
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_BINARY, columnName, valueLength);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength);
|
||||
tscInitResObjForLocalQuery(pSql, 1, valueLength);
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[0] = pQueryInfo->exprsInfo.pExprs[0];
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0);
|
||||
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
|
||||
strncpy(pRes->data, val, pField->bytes);
|
||||
}
|
||||
|
|
|
@ -779,7 +779,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
STableMetaInfo *pSTableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX);
|
||||
setMeterID(pSTableMeterMetaInfo, &sToken, pSql);
|
||||
tscSetTableId(pSTableMeterMetaInfo, &sToken, pSql);
|
||||
|
||||
strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_TABLE_ID_LEN);
|
||||
code = tscGetTableMeta(pSql, pSTableMeterMetaInfo);
|
||||
|
@ -922,7 +922,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
return tscInvalidSQLErrMsg(pCmd->payload, "invalid table name", *sqlstr);
|
||||
}
|
||||
|
||||
int32_t ret = setMeterID(pTableMetaInfo, &tableToken, pSql);
|
||||
int32_t ret = tscSetTableId(pTableMetaInfo, &tableToken, pSql);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -1059,7 +1059,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
|||
goto _error_clean;
|
||||
}
|
||||
|
||||
if ((code = setMeterID(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
if ((code = tscSetTableId(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,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(tExprNode **pExpr, tSQLExpr* pSqlExpr, SSqlExprInfo* pExprInfo, SQueryInfo* pQueryInfo, SArray* pCols);
|
||||
static int32_t exprTreeFromSqlExpr(tExprNode **pExpr, tSQLExpr* pSqlExpr, SArray* pExprInfo, SQueryInfo* pQueryInfo, SArray* pCols);
|
||||
|
||||
/*
|
||||
* Used during parsing query sql. Since the query sql usually small in length, error position
|
||||
|
@ -126,23 +126,6 @@ static int32_t invalidSqlErrMsg(char* dstBuffer, const char* errMsg) {
|
|||
return tscInvalidSQLErrMsg(dstBuffer, errMsg, NULL);
|
||||
}
|
||||
|
||||
static int32_t tscQueryOnlyMetricTags(SQueryInfo* pQueryInfo, bool* queryOnMetricTags) {
|
||||
assert(QUERY_IS_STABLE_QUERY(pQueryInfo->type));
|
||||
|
||||
*queryOnMetricTags = true;
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
if (pExpr->functionId != TSDB_FUNC_TAGPRJ &&
|
||||
!(pExpr->functionId == TSDB_FUNC_COUNT && pExpr->colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX)) {
|
||||
*queryOnMetricTags = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int setColumnFilterInfoForTimestamp(SQueryInfo* pQueryInfo, tVariant* pVar) {
|
||||
int64_t time = 0;
|
||||
const char* msg = "invalid timestamp";
|
||||
|
@ -243,7 +226,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
} else if (pInfo->type == TSDB_SQL_DROP_TABLE) {
|
||||
assert(pInfo->pDCLInfo->nTokens == 1);
|
||||
|
||||
if (setMeterID(pTableMetaInfo, pzName, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pTableMetaInfo, pzName, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
} else if (pInfo->type == TSDB_SQL_DROP_DNODE) {
|
||||
|
@ -376,7 +359,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
if (setMeterID(pTableMetaInfo, pToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pTableMetaInfo, pToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
|
@ -577,7 +560,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
* are available.
|
||||
*/
|
||||
static bool isTopBottomQuery(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
|
||||
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
|
||||
|
@ -631,7 +616,8 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
|||
* check invalid SQL:
|
||||
* select count(tbname)/count(tag1)/count(tag2) from super_table_name interval(1d);
|
||||
*/
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_COUNT && TSDB_COL_IS_TAG(pExpr->colInfo.flag)) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
|
||||
|
@ -663,7 +649,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
|||
}
|
||||
|
||||
SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, 0, TSDB_FUNC_TS, &index, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE);
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS, &index, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE);
|
||||
|
||||
SColumnList ids = getColumnList(1, 0, PRIMARYKEY_TIMESTAMP_COL_INDEX);
|
||||
|
||||
|
@ -708,7 +694,7 @@ int32_t parseSlidingClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t setMeterID(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql) {
|
||||
int32_t tscSetTableId(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql) {
|
||||
const char* msg = "name too long";
|
||||
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
|
@ -1129,7 +1115,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
|||
}
|
||||
|
||||
for (int32_t i = 0; i < pSelection->nExpr; ++i) {
|
||||
int32_t outputIndex = pQueryInfo->exprsInfo.numOfExprs;
|
||||
int32_t outputIndex = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
tSQLExprItem* pItem = &pSelection->a[i];
|
||||
|
||||
// project on all fields
|
||||
|
@ -1182,7 +1168,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
|||
|
||||
// expr string is set as the parameter of function
|
||||
SColumnIndex index = {.tableIndex = tableIndex};
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, outputIndex, TSDB_FUNC_ARITHM, &index, TSDB_DATA_TYPE_DOUBLE,
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_ARITHM, &index, TSDB_DATA_TYPE_DOUBLE,
|
||||
sizeof(double), sizeof(double));
|
||||
addExprParams(pExpr, arithmeticExprStr, TSDB_DATA_TYPE_BINARY, strlen(arithmeticExprStr), index.tableIndex);
|
||||
|
||||
|
@ -1198,22 +1184,23 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
|||
insertResultField(pQueryInfo, i, &columnList, sizeof(double), TSDB_DATA_TYPE_DOUBLE, "abc", NULL);
|
||||
|
||||
int32_t slot = tscNumOfFields(pQueryInfo) - 1;
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, slot);
|
||||
|
||||
if (pQueryInfo->fieldsInfo.pExpr[slot] == NULL) {
|
||||
SSqlFunctionExpr* pFuncExpr = calloc(1, sizeof(SSqlFunctionExpr));
|
||||
tscFieldInfoSetBinExpr(&pQueryInfo->fieldsInfo, slot, pFuncExpr);
|
||||
if (pInfo->pSqlExpr == NULL) {
|
||||
SArithExprInfo* pFuncExpr = calloc(1, sizeof(SArithExprInfo));
|
||||
pInfo->pArithExprInfo = pFuncExpr;
|
||||
|
||||
// arithmetic expression always return result in the format of double float
|
||||
pFuncExpr->resBytes = sizeof(double);
|
||||
pFuncExpr->bytes = sizeof(double);
|
||||
pFuncExpr->interResBytes = sizeof(double);
|
||||
pFuncExpr->resType = TSDB_DATA_TYPE_DOUBLE;
|
||||
pFuncExpr->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
|
||||
SSqlBinaryExprInfo* pBinExprInfo = &pFuncExpr->binExprInfo;
|
||||
SExprInfo* pBinExprInfo = &pFuncExpr->binExprInfo;
|
||||
|
||||
tExprNode* pNode = NULL;
|
||||
// SArray* colList = taosArrayInit(10, sizeof(SColIndex));
|
||||
|
||||
int32_t ret = exprTreeFromSqlExpr(&pNode, pItem->pNode, &pQueryInfo->exprsInfo, pQueryInfo, NULL);
|
||||
|
||||
int32_t ret = exprTreeFromSqlExpr(&pNode, pItem->pNode, pQueryInfo->exprsInfo, pQueryInfo, NULL);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tExprTreeDestroy(&pNode, NULL);
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, "invalid expression in select clause");
|
||||
|
@ -1225,15 +1212,17 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
|||
|
||||
for(int32_t k = 0; k < pBinExprInfo->numOfCols; ++k) {
|
||||
SColIndex* pCol = &pBinExprInfo->pReqColumns[k];
|
||||
for(int32_t f = 0; f < pQueryInfo->exprsInfo.numOfExprs; ++f) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for(int32_t f = 0; f < size; ++f) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, f);
|
||||
if (strcmp(pExpr->aliasName, pCol->name) == 0) {
|
||||
pCol->colIndex = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(pCol->colIndex >= 0 && pCol->colIndex < pQueryInfo->exprsInfo.numOfExprs);
|
||||
|
||||
assert(pCol->colIndex >= 0 && pCol->colIndex < size);
|
||||
tfree(pNode);
|
||||
}
|
||||
}
|
||||
|
@ -1246,7 +1235,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
|||
return invalidSqlErrMsg(pQueryInfo->msg, msg3);
|
||||
}
|
||||
|
||||
if (pQueryInfo->fieldsInfo.numOfOutputCols > TSDB_MAX_COLUMNS) {
|
||||
if (pQueryInfo->fieldsInfo.numOfOutput > TSDB_MAX_COLUMNS) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
}
|
||||
|
@ -1284,9 +1273,10 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi
|
|||
for (int32_t i = 0; i < pIdList->num; ++i) {
|
||||
tscColumnListInsert(pQueryInfo->colList, &(pIdList->ids[i]));
|
||||
}
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, outputIndex, type, fieldName, bytes);
|
||||
tscFieldInfoSetExpr(&pQueryInfo->fieldsInfo, outputIndex, pSqlExpr);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(type, fieldName, bytes);
|
||||
SFieldSupInfo* pInfo =tscFieldInfoInsert(&pQueryInfo->fieldsInfo, outputIndex, &f);
|
||||
pInfo->pSqlExpr = pSqlExpr;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1299,19 +1289,10 @@ SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, int32_t c
|
|||
SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, colIndex);
|
||||
|
||||
int16_t functionId = (int16_t)((colIndex >= numOfCols) ? TSDB_FUNC_TAGPRJ : TSDB_FUNC_PRJ);
|
||||
|
||||
if (functionId == TSDB_FUNC_TAGPRJ) {
|
||||
// addRequiredTagColumn(pQueryInfo, colIndex - numOfCols, tableIndex);
|
||||
pQueryInfo->type = TSDB_QUERY_TYPE_STABLE_QUERY;
|
||||
} else {
|
||||
pQueryInfo->type = TSDB_QUERY_TYPE_PROJECTION_QUERY;
|
||||
}
|
||||
pQueryInfo->type = (functionId == TSDB_FUNC_TAGPRJ)? TSDB_QUERY_TYPE_STABLE_QUERY:TSDB_QUERY_TYPE_PROJECTION_QUERY;
|
||||
|
||||
SColumnIndex index = {tableIndex, colIndex};
|
||||
SSqlExpr* pExpr =
|
||||
tscSqlExprInsert(pQueryInfo, outputIndex, functionId, &index, pSchema->type, pSchema->bytes, pSchema->bytes);
|
||||
|
||||
return pExpr;
|
||||
return tscSqlExprInsert(pQueryInfo, functionId, &index, pSchema->type, pSchema->bytes, pSchema->bytes);
|
||||
}
|
||||
|
||||
void addRequiredTagColumn(SQueryInfo* pQueryInfo, int32_t tagColIndex, int32_t tableIndex) {
|
||||
|
@ -1365,7 +1346,7 @@ static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumn
|
|||
|
||||
void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
|
||||
SColumnIndex* pIndex, SSchema* pColSchema, int16_t flag) {
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, outputColIndex, functionId, pIndex, pColSchema->type,
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, functionId, pIndex, pColSchema->type,
|
||||
pColSchema->bytes, pColSchema->bytes);
|
||||
|
||||
SColumnList ids = getColumnList(1, pIndex->tableIndex, pIndex->columnIndex);
|
||||
|
@ -1415,8 +1396,8 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
|
|||
int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pItem) {
|
||||
const char* msg0 = "invalid column name";
|
||||
const char* msg1 = "tag for table query is not allowed";
|
||||
|
||||
int32_t startPos = pQueryInfo->exprsInfo.numOfExprs;
|
||||
|
||||
int32_t startPos = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
if (pItem->pNode->nSQLOptr == TK_ALL) { // project on all fields
|
||||
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
|
||||
|
@ -1493,10 +1474,10 @@ static int32_t setExprInfoForFunctions(SQueryInfo* pQueryInfo, SSchema* pSchema,
|
|||
getRevisedName(columnName, functionID, TSDB_COL_NAME_LEN, pSchema[pColIndex->columnIndex].name);
|
||||
}
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, resColIdx, functionID, pColIndex, type, bytes, bytes);
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, functionID, pColIndex, type, bytes, bytes);
|
||||
strncpy(pExpr->aliasName, columnName, tListLen(pExpr->aliasName));
|
||||
|
||||
// for all querie, the timestamp column meeds to be loaded
|
||||
// for all queries, the timestamp column needs to be loaded
|
||||
SColumnIndex index = {.tableIndex = pColIndex->tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||
tscColumnListInsert(pQueryInfo->colList, &index);
|
||||
|
||||
|
@ -1550,7 +1531,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
|
||||
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, colIndex, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size);
|
||||
} else {
|
||||
// count the number of meters created according to the metric
|
||||
if (getColumnIndexByName(pToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1565,13 +1546,13 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
}
|
||||
|
||||
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, colIndex, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size);
|
||||
}
|
||||
} else { // count(*) is equalled to count(primary_timestamp_key)
|
||||
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||
|
||||
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, colIndex, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size);
|
||||
}
|
||||
|
||||
memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName));
|
||||
|
@ -1651,7 +1632,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
if (optr == TK_DIFF) {
|
||||
colIndex += 1;
|
||||
SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0};
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, 0, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE,
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE,
|
||||
TSDB_KEYSIZE);
|
||||
|
||||
SColumnList ids = getColumnList(1, 0, 0);
|
||||
|
@ -1663,7 +1644,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
return invalidSqlErrMsg(pQueryInfo->msg, msg6);
|
||||
}
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, colIndex, functionID, &index, resultType, resultSize, resultSize);
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, functionID, &index, resultType, resultSize, resultSize);
|
||||
|
||||
if (optr == TK_LEASTSQUARES) {
|
||||
/* set the leastsquares parameters */
|
||||
|
@ -1855,7 +1836,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, colIndex, functionId, &index, resultType, resultSize, resultSize);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, functionId, &index, resultType, resultSize, resultSize);
|
||||
addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0);
|
||||
} else {
|
||||
tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT);
|
||||
|
@ -1872,7 +1853,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
|
||||
// set the first column ts for top/bottom query
|
||||
SColumnIndex index1 = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, 0, TSDB_FUNC_TS, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE);
|
||||
|
||||
const int32_t TS_COLUMN_INDEX = 0;
|
||||
SColumnList ids = getColumnList(1, 0, TS_COLUMN_INDEX);
|
||||
|
@ -1881,7 +1862,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
|||
|
||||
colIndex += 1; // the first column is ts
|
||||
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, colIndex, functionId, &index, resultType, resultSize, resultSize);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, functionId, &index, resultType, resultSize, resultSize);
|
||||
addExprParams(pExpr, val, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0);
|
||||
}
|
||||
|
||||
|
@ -2273,8 +2254,9 @@ int32_t tscTansformSQLFunctionForSTableQuery(SQueryInfo* pQueryInfo) {
|
|||
int16_t bytes = 0;
|
||||
int16_t type = 0;
|
||||
int16_t intermediateBytes = 0;
|
||||
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
int16_t functionId = aAggs[pExpr->functionId].stableFuncId;
|
||||
|
||||
|
@ -2305,8 +2287,9 @@ void tscRestoreSQLFunctionForMetricQuery(SQueryInfo* pQueryInfo) {
|
|||
if (!UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex);
|
||||
|
||||
|
@ -2340,7 +2323,8 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) {
|
|||
const char* msg3 = "function not support for super table query";
|
||||
|
||||
// filter sql function not supported by metric query yet.
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_METRIC) == 0) {
|
||||
invalidSqlErrMsg(pQueryInfo->msg, msg3);
|
||||
|
@ -2366,7 +2350,8 @@ bool hasUnsupportFunctionsForSTableQuery(SQueryInfo* pQueryInfo) {
|
|||
|
||||
static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) {
|
||||
int32_t startIdx = 0;
|
||||
int32_t functionID = tscSqlExprGet(pQueryInfo, startIdx)->functionId;
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, startIdx);
|
||||
int32_t functionID = pExpr->functionId;
|
||||
|
||||
// ts function can be simultaneously used with any other functions.
|
||||
if (functionID == TSDB_FUNC_TS || functionID == TSDB_FUNC_TS_DUMMY) {
|
||||
|
@ -2377,7 +2362,9 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) {
|
|||
|
||||
// diff function cannot be executed with other function
|
||||
// arithmetic function can be executed with other arithmetic functions
|
||||
for (int32_t i = startIdx + 1; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = startIdx + 1; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
int16_t functionId = pExpr->functionId;
|
||||
|
@ -2419,7 +2406,8 @@ void updateTagColumnIndex(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
|||
}
|
||||
|
||||
// update tags column index for expression
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
if (!TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { // not tags, continue
|
||||
|
@ -3080,7 +3068,8 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL
|
|||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
int32_t outputIndex = pQueryInfo->exprsInfo.numOfExprs;
|
||||
int32_t outputIndex = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
tSQLExprItem item = {.pNode = pExpr, .aliasName = NULL};
|
||||
|
||||
// sql function in selection clause, append sql function info in pSqlCmd structure sequentially
|
||||
|
@ -3927,8 +3916,8 @@ int32_t getTimeRange(int64_t* stime, int64_t* etime, tSQLExpr* pRight, int32_t o
|
|||
int32_t tsRewriteFieldNameIfNecessary(SQueryInfo* pQueryInfo) {
|
||||
const char rep[] = {'(', ')', '*', ',', '.', '/', '\\', '+', '-', '%', ' '};
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
char* fieldName = tscFieldInfoGetField(pQueryInfo, i)->name;
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
char* fieldName = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->name;
|
||||
for (int32_t j = 0; j < TSDB_COL_NAME_LEN && fieldName[j] != 0; ++j) {
|
||||
for (int32_t k = 0; k < tListLen(rep); ++k) {
|
||||
if (fieldName[j] == rep[k]) {
|
||||
|
@ -3942,10 +3931,10 @@ int32_t tsRewriteFieldNameIfNecessary(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
// the column name may be identical, here check again
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
char* fieldName = tscFieldInfoGetField(pQueryInfo, i)->name;
|
||||
for (int32_t j = i + 1; j < pQueryInfo->fieldsInfo.numOfOutputCols; ++j) {
|
||||
if (strncasecmp(fieldName, tscFieldInfoGetField(pQueryInfo, j)->name, TSDB_COL_NAME_LEN) == 0) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
char* fieldName = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->name;
|
||||
for (int32_t j = i + 1; j < pQueryInfo->fieldsInfo.numOfOutput; ++j) {
|
||||
if (strncasecmp(fieldName, tscFieldInfoGetField(&pQueryInfo->fieldsInfo, j)->name, TSDB_COL_NAME_LEN) == 0) {
|
||||
const char* msg = "duplicated column name in new table";
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg);
|
||||
}
|
||||
|
@ -3968,9 +3957,11 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
|
|||
if (pItem->pVar.nType != TSDB_DATA_TYPE_BINARY) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg2);
|
||||
}
|
||||
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
if (pQueryInfo->defaultVal == NULL) {
|
||||
pQueryInfo->defaultVal = calloc(pQueryInfo->exprsInfo.numOfExprs, sizeof(int64_t));
|
||||
pQueryInfo->defaultVal = calloc(size, sizeof(int64_t));
|
||||
if (pQueryInfo->defaultVal == NULL) {
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -3980,8 +3971,8 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
|
|||
pQueryInfo->interpoType = TSDB_INTERPO_NONE;
|
||||
} else if (strncasecmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4) {
|
||||
pQueryInfo->interpoType = TSDB_INTERPO_NULL;
|
||||
for (int32_t i = START_INTERPO_COL_IDX; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int32_t i = START_INTERPO_COL_IDX; i < size; ++i) {
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
setNull((char*)&pQueryInfo->defaultVal[i], pFields->type, pFields->bytes);
|
||||
}
|
||||
} else if (strncasecmp(pItem->pVar.pz, "prev", 4) == 0 && pItem->pVar.nLen == 4) {
|
||||
|
@ -4002,19 +3993,17 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
|
|||
if (tscIsPointInterpQuery(pQueryInfo)) {
|
||||
startPos = 0;
|
||||
|
||||
if (numOfFillVal > pQueryInfo->exprsInfo.numOfExprs) {
|
||||
numOfFillVal = pQueryInfo->exprsInfo.numOfExprs;
|
||||
if (numOfFillVal > size) {
|
||||
numOfFillVal = size;
|
||||
}
|
||||
} else {
|
||||
numOfFillVal = (pFillToken->nExpr > pQueryInfo->exprsInfo.numOfExprs)
|
||||
? pQueryInfo->exprsInfo.numOfExprs
|
||||
: pFillToken->nExpr;
|
||||
numOfFillVal = (pFillToken->nExpr > size) ? size : pFillToken->nExpr;
|
||||
}
|
||||
|
||||
int32_t j = 1;
|
||||
|
||||
for (int32_t i = startPos; i < numOfFillVal; ++i, ++j) {
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
if (pFields->type == TSDB_DATA_TYPE_BINARY || pFields->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
setNull((char*)(&pQueryInfo->defaultVal[i]), pFields->type, pFields->bytes);
|
||||
|
@ -4026,13 +4015,15 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
|
|||
return invalidSqlErrMsg(pQueryInfo->msg, msg);
|
||||
}
|
||||
}
|
||||
|
||||
if ((pFillToken->nExpr < pQueryInfo->exprsInfo.numOfExprs) ||
|
||||
((pFillToken->nExpr - 1 < pQueryInfo->exprsInfo.numOfExprs) && (tscIsPointInterpQuery(pQueryInfo)))) {
|
||||
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
if ((pFillToken->nExpr < size) ||
|
||||
((pFillToken->nExpr - 1 < size) && (tscIsPointInterpQuery(pQueryInfo)))) {
|
||||
tVariantListItem* lastItem = &pFillToken->a[pFillToken->nExpr - 1];
|
||||
|
||||
for (int32_t i = numOfFillVal; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int32_t i = numOfFillVal; i < size; ++i) {
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
if (pFields->type == TSDB_DATA_TYPE_BINARY || pFields->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
setNull((char*)(&pQueryInfo->defaultVal[i]), pFields->type, pFields->bytes);
|
||||
|
@ -4231,7 +4222,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
|
||||
}
|
||||
|
||||
if (setMeterID(pTableMetaInfo, &(pAlterSQL->name), pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pTableMetaInfo, &(pAlterSQL->name), pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg2);
|
||||
}
|
||||
|
||||
|
@ -4263,8 +4254,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
if (!validateOneTags(pCmd, &pFieldList->p[0])) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
tscFieldInfoSetValFromField(&pQueryInfo->fieldsInfo, 0, &pFieldList->p[0]);
|
||||
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
|
||||
const char* msg1 = "no tags can be dropped";
|
||||
const char* msg2 = "only support one tag";
|
||||
|
@ -4301,8 +4292,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
|
||||
char name1[128] = {0};
|
||||
strncpy(name1, pItem->pVar.pz, pItem->pVar.nLen);
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name1,
|
||||
tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
|
||||
const char* msg1 = "tag name too long";
|
||||
const char* msg2 = "invalid tag name";
|
||||
|
@ -4336,13 +4328,15 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
char name[128] = {0};
|
||||
char name[TSDB_COL_NAME_LEN + 1] = {0};
|
||||
strncpy(name, pVarList->a[0].pVar.pz, pVarList->a[0].pVar.nLen);
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
|
||||
memset(name, 0, tListLen(name));
|
||||
strncpy(name, pVarList->a[1].pVar.pz, pVarList->a[1].pVar.nLen);
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 1, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
|
||||
const char* msg1 = "invalid tag value";
|
||||
const char* msg2 = "update normal column not supported";
|
||||
|
@ -4377,9 +4371,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
|
||||
char name1[128] = {0};
|
||||
strncpy(name1, pTagName->pz, pTagName->nLen);
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name1,
|
||||
tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
|
||||
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
|
||||
tFieldList* pFieldList = pAlterSQL->pAddColumns;
|
||||
if (pFieldList->nField > 1) {
|
||||
|
@ -4390,8 +4385,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
if (!validateOneColumn(pCmd, &pFieldList->p[0])) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
tscFieldInfoSetValFromField(&pQueryInfo->fieldsInfo, 0, &pFieldList->p[0]);
|
||||
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
|
||||
const char* msg1 = "no columns can be dropped";
|
||||
const char* msg2 = "only support one column";
|
||||
|
@ -4418,10 +4413,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(pQueryInfo->msg, msg3);
|
||||
}
|
||||
|
||||
char name1[128] = {0};
|
||||
char name1[TSDB_COL_NAME_LEN + 1] = {0};
|
||||
strncpy(name1, pItem->pVar.pz, pItem->pVar.nLen);
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name1,
|
||||
tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -4434,8 +4429,9 @@ int32_t validateSqlFunctionInStreamSql(SQueryInfo* pQueryInfo) {
|
|||
if (pQueryInfo->intervalTime != 0 && pQueryInfo->intervalTime < 10) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg0);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if (!IS_STREAM_QUERY_VALID(aAggs[functId].nStatus)) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
|
||||
|
@ -4450,13 +4446,15 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SQueryInfo* pQueryInfo) {
|
|||
const char* msg1 = "column projection is not compatible with interval";
|
||||
|
||||
// multi-output set/ todo refactor
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
|
||||
// projection query on primary timestamp, the selectivity function needs to be present.
|
||||
if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
bool hasSelectivity = false;
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
SSqlExpr* pEx = tscSqlExprGet(pQueryInfo, j);
|
||||
if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) {
|
||||
hasSelectivity = true;
|
||||
|
@ -4645,11 +4643,11 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
|
|||
|
||||
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||
bool queryOnTags = false;
|
||||
if (tscQueryOnlyMetricTags(pQueryInfo, &queryOnTags) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
// if (tscQueryOnlyMetricTags(pQueryInfo, &queryOnTags) != TSDB_CODE_SUCCESS) {
|
||||
// return TSDB_CODE_INVALID_SQL;
|
||||
// }
|
||||
|
||||
if (queryOnTags == true) { // local handle the metric tag query
|
||||
if (queryOnTags == true) { // local handle the super table tag query
|
||||
pQueryInfo->command = TSDB_SQL_RETRIEVE_TAGS;
|
||||
} else {
|
||||
if (tscIsProjectionQueryOnSTable(pQueryInfo, 0)) {
|
||||
|
@ -4707,9 +4705,11 @@ int32_t parseLimitClause(SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL*
|
|||
if (pQueryInfo->slimit.limit != -1 || pQueryInfo->slimit.offset != 0) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
|
||||
}
|
||||
|
||||
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
// filter the query functions operating on "tbname" column that are not supported by normal columns.
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg2);
|
||||
|
@ -4811,14 +4811,14 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
|
|||
void tscAddTimestampColumn(SQueryInfo* pQueryInfo, int16_t functionId, int16_t tableIndex) {
|
||||
// the first column not timestamp column, add it
|
||||
SSqlExpr* pExpr = NULL;
|
||||
if (pQueryInfo->exprsInfo.numOfExprs > 0) {
|
||||
if (tscSqlExprNumOfExprs(pQueryInfo) > 0) {
|
||||
pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
}
|
||||
|
||||
if (pExpr == NULL || pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX || pExpr->functionId != functionId) {
|
||||
SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, 0, functionId, &index, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE);
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, functionId, &index, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, TSDB_KEYSIZE);
|
||||
pExpr->colInfo.flag = TSDB_COL_NORMAL;
|
||||
|
||||
// NOTE: tag column does not add to source column list
|
||||
|
@ -4833,9 +4833,9 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau
|
|||
|
||||
if (pParentQueryInfo->groupbyExpr.numOfGroupCols > 0) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, subClauseIndex);
|
||||
int32_t num = pQueryInfo->exprsInfo.numOfExprs;
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, num - 1);
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, size - 1);
|
||||
|
||||
if (pExpr->functionId != TSDB_FUNC_TAG) {
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex);
|
||||
|
@ -4846,14 +4846,13 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t subClau
|
|||
int16_t type = pSchema[index.columnIndex].type;
|
||||
int16_t bytes = pSchema[index.columnIndex].bytes;
|
||||
char* name = pSchema[index.columnIndex].name;
|
||||
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, pQueryInfo->exprsInfo.numOfExprs, TSDB_FUNC_TAG, &index, type, bytes,
|
||||
bytes);
|
||||
|
||||
pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TAG, &index, type, bytes, bytes);
|
||||
pExpr->colInfo.flag = TSDB_COL_TAG;
|
||||
|
||||
// NOTE: tag column does not add to source column list
|
||||
SColumnList ids = {0};
|
||||
insertResultField(pQueryInfo, pQueryInfo->exprsInfo.numOfExprs, &ids, bytes, type, name, pExpr);
|
||||
insertResultField(pQueryInfo, size, &ids, bytes, type, name, pExpr);
|
||||
|
||||
int32_t relIndex = index.columnIndex;
|
||||
|
||||
|
@ -4879,9 +4878,9 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex) {
|
|||
|
||||
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index);
|
||||
SColumnIndex colIndex = {.tableIndex = 0, .columnIndex = index};
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, pQueryInfo->exprsInfo.numOfExprs, TSDB_FUNC_PRJ, &colIndex,
|
||||
pSchema->type, pSchema->bytes, pSchema->bytes);
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_PRJ, &colIndex, pSchema->type, pSchema->bytes, pSchema->bytes);
|
||||
|
||||
pExpr->colInfo.flag = TSDB_COL_NORMAL;
|
||||
doLimitOutputNormalColOfGroupby(pExpr);
|
||||
|
@ -4891,14 +4890,17 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex) {
|
|||
list.num = 1;
|
||||
list.ids[0] = colIndex;
|
||||
|
||||
insertResultField(pQueryInfo, pQueryInfo->exprsInfo.numOfExprs - 1, &list, pSchema->bytes, pSchema->type,
|
||||
pSchema->name, pExpr);
|
||||
tscFieldInfoUpdateVisible(&pQueryInfo->fieldsInfo, pQueryInfo->exprsInfo.numOfExprs - 1, false);
|
||||
insertResultField(pQueryInfo, size - 1, &list, pSchema->bytes, pSchema->type, pSchema->name, pExpr);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, size - 1);
|
||||
pInfo->visible = false;
|
||||
}
|
||||
|
||||
static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
|
||||
int32_t tagLength = 0;
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAGPRJ || pExpr->functionId == TSDB_FUNC_TAG) {
|
||||
pExpr->functionId = TSDB_FUNC_TAG_DUMMY;
|
||||
|
@ -4912,7 +4914,7 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
|
|||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
SSchema* pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) {
|
||||
SSchema* pColSchema = &pSchema[pExpr->colInfo.colIndex];
|
||||
|
@ -4923,7 +4925,9 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
static void doUpdateSqlFunctionForColPrj(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_PRJ) {
|
||||
bool qualifiedCol = false;
|
||||
|
@ -4954,8 +4958,9 @@ static bool tagColumnInGroupby(SSqlGroupbyExpr* pGroupbyExpr, int16_t columnId)
|
|||
static bool onlyTagPrjFunction(SQueryInfo* pQueryInfo) {
|
||||
bool hasTagPrj = false;
|
||||
bool hasColumnPrj = false;
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_PRJ) {
|
||||
hasColumnPrj = true;
|
||||
|
@ -4971,7 +4976,8 @@ static bool onlyTagPrjFunction(SQueryInfo* pQueryInfo) {
|
|||
static bool allTagPrjInGroupby(SQueryInfo* pQueryInfo) {
|
||||
bool allInGroupby = true;
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId != TSDB_FUNC_TAGPRJ) {
|
||||
continue;
|
||||
|
@ -4988,7 +4994,9 @@ static bool allTagPrjInGroupby(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
static void updateTagPrjFunction(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAGPRJ) {
|
||||
pExpr->functionId = TSDB_FUNC_TAG;
|
||||
|
@ -5010,8 +5018,9 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) {
|
|||
int16_t numOfSelectivity = 0;
|
||||
int16_t numOfAggregation = 0;
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
size_t numOfExprs = taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAGPRJ ||
|
||||
(pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) {
|
||||
tagColExists = true;
|
||||
|
@ -5019,8 +5028,10 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
int16_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, i);
|
||||
|
||||
int16_t functionId = pExpr->functionId;
|
||||
if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS ||
|
||||
functionId == TSDB_FUNC_ARITHM) {
|
||||
continue;
|
||||
|
@ -5051,7 +5062,8 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo) {
|
|||
* If more than one selectivity functions exist, all the selectivity functions must be last_row.
|
||||
* Otherwise, return with error code.
|
||||
*/
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
|
||||
int16_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if (functionId == TSDB_FUNC_TAGPRJ) {
|
||||
continue;
|
||||
|
@ -5107,12 +5119,12 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) {
|
|||
bytes = pSchema[colIndex].bytes;
|
||||
name = pSchema[colIndex].name;
|
||||
}
|
||||
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
if (TSDB_COL_IS_TAG(pColIndex->flag)) {
|
||||
SColumnIndex index = {.tableIndex = pQueryInfo->groupbyExpr.tableIndex, .columnIndex = colIndex};
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, pQueryInfo->exprsInfo.numOfExprs, TSDB_FUNC_TAG, &index,
|
||||
type, bytes, bytes);
|
||||
SSqlExpr* pExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TAG, &index, type, bytes, bytes);
|
||||
|
||||
memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName));
|
||||
strncpy(pExpr->aliasName, name, TSDB_COL_NAME_LEN);
|
||||
|
@ -5121,7 +5133,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) {
|
|||
|
||||
// NOTE: tag column does not add to source column list
|
||||
SColumnList ids = getColumnList(1, 0, pColIndex->colIndex);
|
||||
insertResultField(pQueryInfo, pQueryInfo->exprsInfo.numOfExprs-1, &ids, bytes, type, name, pExpr);
|
||||
insertResultField(pQueryInfo, size - 1, &ids, bytes, type, name, pExpr);
|
||||
} else {
|
||||
// if this query is "group by" normal column, interval is not allowed
|
||||
if (pQueryInfo->intervalTime > 0) {
|
||||
|
@ -5129,7 +5141,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
bool hasGroupColumn = false;
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, j);
|
||||
if (pExpr->colInfo.colId == pColIndex->colId) {
|
||||
break;
|
||||
|
@ -5172,7 +5184,8 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
// check all query functions in selection clause, multi-output functions are not allowed
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
int32_t functId = pExpr->functionId;
|
||||
|
||||
|
@ -5259,7 +5272,8 @@ int32_t doLocalQueryProcess(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
|||
}
|
||||
}
|
||||
|
||||
SSqlExpr* pExpr1 = tscSqlExprInsertEmpty(pQueryInfo, 0, TSDB_FUNC_TAG_DUMMY);
|
||||
SSqlExpr* pExpr1 = tscSqlExprAppend(pQueryInfo->exprsInfo, TSDB_FUNC_TAG_DUMMY);
|
||||
|
||||
const char* name = (pExprList->a[0].aliasName != NULL)? pExprList->a[0].aliasName:functionsInfo[index].name;
|
||||
strncpy(pExpr1->aliasName, name, tListLen(pExpr1->aliasName));
|
||||
|
||||
|
@ -5361,7 +5375,8 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) {
|
|||
void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, subClauseIndex);
|
||||
|
||||
if (pQueryInfo->exprsInfo.numOfExprs == 0) {
|
||||
int32_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5370,8 +5385,8 @@ void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex) {
|
|||
char str[1024] = {0};
|
||||
int32_t offset = 0;
|
||||
|
||||
offset += sprintf(str, "num:%d [", pQueryInfo->exprsInfo.numOfExprs);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
offset += sprintf(str, "num:%d [", size);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
char tmpBuf[1024] = {0};
|
||||
|
@ -5382,7 +5397,7 @@ void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex) {
|
|||
|
||||
offset += sprintf(str + offset, "%s", tmpBuf);
|
||||
|
||||
if (i < pQueryInfo->exprsInfo.numOfExprs - 1) {
|
||||
if (i < size - 1) {
|
||||
str[offset++] = ',';
|
||||
}
|
||||
}
|
||||
|
@ -5413,7 +5428,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
if (setMeterID(pTableMetaInfo, pzTableName, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pTableMetaInfo, pzTableName, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
|
@ -5424,14 +5439,14 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
|
|||
|
||||
int32_t col = 0;
|
||||
for (; col < pFieldList->nField; ++col) {
|
||||
tscFieldInfoSetValFromField(&pQueryInfo->fieldsInfo, col, &pFieldList->p[col]);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[col]);
|
||||
}
|
||||
|
||||
pCmd->numOfCols = (int16_t)pFieldList->nField;
|
||||
|
||||
if (pTagList != NULL) { // create metric[optional]
|
||||
for (int32_t i = 0; i < pTagList->nField; ++i) {
|
||||
tscFieldInfoSetValFromField(&pQueryInfo->fieldsInfo, col++, &pTagList->p[i]);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pTagList->p[col]);
|
||||
}
|
||||
|
||||
pCmd->count = pTagList->nField;
|
||||
|
@ -5468,7 +5483,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
if (setMeterID(pStableMeterMetaInfo, pToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pStableMeterMetaInfo, pToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
|
@ -5510,7 +5525,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
STableMetaInfo* pTableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX);
|
||||
int32_t ret = setMeterID(pTableMeterMetaInfo, &pInfo->pCreateTableInfo->name, pSql);
|
||||
int32_t ret = tscSetTableId(pTableMeterMetaInfo, &pInfo->pCreateTableInfo->name, pSql);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -5548,7 +5563,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
|
||||
}
|
||||
|
||||
if (setMeterID(pTableMetaInfo, &srcToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pTableMetaInfo, &srcToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg2);
|
||||
}
|
||||
|
||||
|
@ -5579,7 +5594,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
// set the created table[stream] name
|
||||
if (setMeterID(pTableMetaInfo, pzTableName, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pTableMetaInfo, pzTableName, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
|
||||
}
|
||||
|
||||
|
@ -5591,7 +5606,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
|
||||
if (validateSqlFunctionInStreamSql(pQueryInfo) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
|
@ -5616,7 +5631,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
// set the number of stream table columns
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -5688,7 +5703,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
STableMetaInfo* pMeterInfo1 = tscGetMetaInfo(pQueryInfo, i);
|
||||
|
||||
SSQLToken t = {.type = TSDB_DATA_TYPE_BINARY, .n = pTableItem->nLen, .z = pTableItem->pz};
|
||||
if (setMeterID(pMeterInfo1, &t, pSql) != TSDB_CODE_SUCCESS) {
|
||||
if (tscSetTableId(pMeterInfo1, &t, pSql) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
|
@ -5815,7 +5830,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
return TSDB_CODE_SUCCESS; // Does not build query message here
|
||||
}
|
||||
|
||||
int32_t exprTreeFromSqlExpr(tExprNode **pExpr, tSQLExpr* pSqlExpr, SSqlExprInfo* pExprInfo, SQueryInfo* pQueryInfo, SArray* pCols) {
|
||||
int32_t exprTreeFromSqlExpr(tExprNode **pExpr, tSQLExpr* pSqlExpr, SArray* pExprInfo, SQueryInfo* pQueryInfo, SArray* pCols) {
|
||||
tExprNode* pLeft = NULL;
|
||||
tExprNode* pRight= NULL;
|
||||
|
||||
|
@ -5848,10 +5863,14 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, tSQLExpr* pSqlExpr, SSqlExprInfo*
|
|||
strncpy((*pExpr)->pSchema->name, pSqlExpr->operand.z, pSqlExpr->operand.n);
|
||||
|
||||
// set the input column data byte and type.
|
||||
for (int32_t i = 0; i < pExprInfo->numOfExprs; ++i) {
|
||||
if (strcmp((*pExpr)->pSchema->name, pExprInfo->pExprs[i]->aliasName) == 0) {
|
||||
(*pExpr)->pSchema->type = pExprInfo->pExprs[i]->resType;
|
||||
(*pExpr)->pSchema->bytes = pExprInfo->pExprs[i]->resBytes;
|
||||
size_t size = taosArrayGetSize(pExprInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* p1 = taosArrayGetP(pExprInfo, i);
|
||||
|
||||
if (strcmp((*pExpr)->pSchema->name, p1->aliasName) == 0) {
|
||||
(*pExpr)->pSchema->type = p1->resType;
|
||||
(*pExpr)->pSchema->bytes = p1->resBytes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,9 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
|
|||
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
|
||||
*/
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SQLFunctionCtx *pCtx = &pReducer->pCtx[i];
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
|
@ -108,10 +110,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
|
|||
|
||||
int16_t n = 0;
|
||||
int16_t tagLen = 0;
|
||||
SQLFunctionCtx **pTagCtx = calloc(pQueryInfo->fieldsInfo.numOfOutputCols, POINTER_BYTES);
|
||||
SQLFunctionCtx **pTagCtx = calloc(pQueryInfo->fieldsInfo.numOfOutput, POINTER_BYTES);
|
||||
|
||||
SQLFunctionCtx *pCtx = NULL;
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
tagLen += pExpr->resBytes;
|
||||
|
@ -254,8 +256,9 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
// the input data format follows the old format, but output in a new format.
|
||||
// so, all the input must be parsed as old format
|
||||
pReducer->pCtx = (SQLFunctionCtx *)calloc(pQueryInfo->exprsInfo.numOfExprs, sizeof(SQLFunctionCtx));
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
pReducer->pCtx = (SQLFunctionCtx *)calloc(size, sizeof(SQLFunctionCtx));
|
||||
pReducer->rowSize = pMemBuffer[0]->nElemSize;
|
||||
|
||||
tscRestoreSQLFunctionForMetricQuery(pQueryInfo);
|
||||
|
@ -279,7 +282,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16;
|
||||
pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage));
|
||||
|
||||
int32_t finalRowLength = tscGetResRowLength(pQueryInfo);
|
||||
int32_t finalRowLength = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
pReducer->resColModel = finalmodel;
|
||||
pReducer->resColModel->capacity = pReducer->nResultBufSize / finalRowLength;
|
||||
assert(finalRowLength <= pReducer->rowSize);
|
||||
|
@ -301,7 +304,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
}
|
||||
|
||||
pReducer->pTempBuffer->numOfElems = 0;
|
||||
pReducer->pResInfo = calloc((size_t)pQueryInfo->exprsInfo.numOfExprs, sizeof(SResultInfo));
|
||||
pReducer->pResInfo = calloc(size, sizeof(SResultInfo));
|
||||
|
||||
tscCreateResPointerInfo(pRes, pQueryInfo);
|
||||
tscInitSqlContext(pCmd, pRes, pReducer, pDesc);
|
||||
|
@ -332,7 +335,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
||||
pReducer->rowSize);
|
||||
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutput - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
||||
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) {
|
||||
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
@ -462,7 +465,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
taosDestoryInterpoInfo(&pLocalReducer->interpolationInfo);
|
||||
|
||||
if (pLocalReducer->pCtx != NULL) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i];
|
||||
|
||||
tVariantDestroy(&pCtx->tag);
|
||||
|
@ -480,7 +483,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
tfree(pLocalReducer->pResultBuf);
|
||||
|
||||
if (pLocalReducer->pResInfo != NULL) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
tfree(pLocalReducer->pResInfo[i].interResultBuf);
|
||||
}
|
||||
|
||||
|
@ -532,7 +535,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
|
|||
}
|
||||
|
||||
if (numOfGroupByCols > 0) {
|
||||
int32_t startCols = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
int32_t startCols = pQueryInfo->fieldsInfo.numOfOutput - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
||||
// tags value locate at the last columns
|
||||
for (int32_t i = 0; i < pQueryInfo->groupbyExpr.numOfGroupCols; ++i) {
|
||||
|
@ -612,8 +615,10 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * pQueryInfo->exprsInfo.numOfExprs);
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size);
|
||||
if (pSchema == NULL) {
|
||||
tscError("%p failed to allocate memory", pSql);
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
|
@ -621,7 +626,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
}
|
||||
|
||||
int32_t rlen = 0;
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
pSchema[i].bytes = pExpr->resBytes;
|
||||
|
@ -634,8 +639,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
if (rlen != 0) {
|
||||
capacity = nBufferSizes / rlen;
|
||||
}
|
||||
|
||||
pModel = createColumnModel(pSchema, pQueryInfo->exprsInfo.numOfExprs, capacity);
|
||||
|
||||
pModel = createColumnModel(pSchema, size, capacity);
|
||||
|
||||
size_t numOfSubs = pTableMetaInfo->vgroupList->numOfVgroups;
|
||||
for (int32_t i = 0; i < numOfSubs; ++i) {
|
||||
|
@ -649,8 +654,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
}
|
||||
|
||||
// final result depends on the fields number
|
||||
memset(pSchema, 0, sizeof(SSchema) * pQueryInfo->exprsInfo.numOfExprs);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
memset(pSchema, 0, sizeof(SSchema) * size);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
SSchema *p1 = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex);
|
||||
|
@ -683,8 +688,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
pSchema[i].bytes = bytes;
|
||||
strcpy(pSchema[i].name, pModel->pFields[i].field.name);
|
||||
}
|
||||
|
||||
*pFinalModel = createColumnModel(pSchema, pQueryInfo->exprsInfo.numOfExprs, capacity);
|
||||
|
||||
*pFinalModel = createColumnModel(pSchema, size, capacity);
|
||||
tfree(pSchema);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -800,7 +805,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
|
|||
// static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) {
|
||||
//
|
||||
// for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
// TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
// TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
//
|
||||
// int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
// char * src = pFinalDataPage->data + (pRes->numOfRows - 1) * pField->bytes + pRes->numOfRows * offset;
|
||||
|
@ -817,8 +822,10 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
|
|||
static void reversedCopyFromInterpolationToDstBuf(SQueryInfo *pQueryInfo, SSqlRes *pRes, tFilePage **pResPages,
|
||||
SLocalReducer *pLocalReducer) {
|
||||
assert(0);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
assert(offset == getColumnModelOffset(pLocalReducer->resColModel, i));
|
||||
|
@ -894,7 +901,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, &pLocalReducer->interpolationInfo);
|
||||
}
|
||||
|
||||
int32_t rowSize = tscGetResRowLength(pQueryInfo);
|
||||
int32_t rowSize = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize);
|
||||
|
||||
pFinalDataPage->numOfElems = 0;
|
||||
|
@ -907,16 +914,16 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
|
||||
int64_t actualETime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
||||
|
||||
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->capacity);
|
||||
}
|
||||
|
||||
char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
int32_t *functions = (int32_t *)((char *)srcData + pQueryInfo->fieldsInfo.numOfOutputCols * sizeof(void *));
|
||||
char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pQueryInfo->fieldsInfo.numOfOutput);
|
||||
int32_t *functions = (int32_t *)((char *)srcData + pQueryInfo->fieldsInfo.numOfOutput * sizeof(void *));
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
srcData[i] =
|
||||
pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pQueryInfo, i) * pInterpoInfo->numOfRawDataInRows;
|
||||
functions[i] = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
|
@ -943,8 +950,8 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
newRows -= pQueryInfo->limit.offset;
|
||||
|
||||
if (pQueryInfo->limit.offset > 0) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pQueryInfo->limit.offset,
|
||||
newRows * pField->bytes);
|
||||
}
|
||||
|
@ -992,8 +999,8 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
}
|
||||
|
||||
if (pQueryInfo->order.order == TSDB_ORDER_ASC) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
int16_t offset = getColumnModelOffset(pLocalReducer->resColModel, i);
|
||||
memcpy(pRes->data + offset * pRes->numOfRows, pResPages[i]->data, pField->bytes * pRes->numOfRows);
|
||||
}
|
||||
|
@ -1003,7 +1010,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
}
|
||||
|
||||
pFinalDataPage->numOfElems = 0;
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
tfree(pResPages[i]);
|
||||
}
|
||||
tfree(pResPages);
|
||||
|
@ -1030,8 +1037,9 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
|
|||
static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, bool needInit) {
|
||||
// the tag columns need to be set before all functions execution
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, j);
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j];
|
||||
|
||||
|
@ -1051,7 +1059,7 @@ static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer,
|
|||
}
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
int32_t functionId = tscSqlExprGet(pQueryInfo, j)->functionId;
|
||||
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
continue;
|
||||
|
@ -1071,8 +1079,9 @@ static void handleUnprocessedRow(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tF
|
|||
|
||||
static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx) {
|
||||
int64_t maxOutput = 0;
|
||||
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
// SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[j];
|
||||
// if (pExpr == NULL) {
|
||||
// assert(pQueryInfo->fieldsInfo.pExpr[j] != NULL);
|
||||
|
@ -1107,7 +1116,9 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx)
|
|||
*/
|
||||
static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLocalReducer *pLocalReducer) {
|
||||
int32_t maxBufSize = 0; // find the max tags column length to prepare the buffer
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
if (maxBufSize < pExpr->resBytes && pExpr->functionId == TSDB_FUNC_TAG) {
|
||||
maxBufSize = pExpr->resBytes;
|
||||
|
@ -1117,7 +1128,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
|
|||
assert(maxBufSize >= 0);
|
||||
|
||||
char *buf = malloc((size_t)maxBufSize);
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
if (pExpr->functionId != TSDB_FUNC_TAG) {
|
||||
continue;
|
||||
|
@ -1139,7 +1150,9 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
|
|||
}
|
||||
|
||||
int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) {
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]);
|
||||
}
|
||||
|
@ -1242,7 +1255,7 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
|
|||
#endif
|
||||
|
||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutput - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->groupbyExpr.numOfGroupCols; ++i) {
|
||||
int16_t offset = getColumnModelOffset(pModel, startIndex + i);
|
||||
|
@ -1258,7 +1271,7 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
|
|||
}
|
||||
|
||||
void resetOutputBuf(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) { // reset output buffer to the beginning
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
pLocalReducer->pCtx[i].aOutputBuf =
|
||||
pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pQueryInfo, i) * pLocalReducer->resColModel->capacity;
|
||||
}
|
||||
|
@ -1386,8 +1399,9 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
|
|||
|
||||
SLocalReducer *pLocalReducer = pRes->pLocalReducer;
|
||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k];
|
||||
|
||||
|
|
|
@ -359,13 +359,13 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
|
|||
|
||||
/*
|
||||
* Whether to free sqlObj or not should be decided before call the user defined function, since this SqlObj
|
||||
* may be freed in UDF, and reused by other threads before tscShouldFreeAsyncSqlObj called, in which case
|
||||
* tscShouldFreeAsyncSqlObj checks an object which is actually allocated by other threads.
|
||||
* may be freed in UDF, and reused by other threads before tscShouldBeFreed called, in which case
|
||||
* tscShouldBeFreed checks an object which is actually allocated by other threads.
|
||||
*
|
||||
* If this block of memory is re-allocated for an insert thread, in which tscKeepConn[command] equals to 0,
|
||||
* the tscShouldFreeAsyncSqlObj will success and tscFreeSqlObj free it immediately.
|
||||
* the tscShouldBeFreed will success and tscFreeSqlObj free it immediately.
|
||||
*/
|
||||
bool shouldFree = tscShouldFreeAsyncSqlObj(pSql);
|
||||
bool shouldFree = tscShouldBeFreed(pSql);
|
||||
(*pSql->fp)(pSql->param, taosres, rpcMsg->code);
|
||||
|
||||
if (shouldFree) {
|
||||
|
@ -573,8 +573,10 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
|
|||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||
|
||||
int32_t srcColListSize = taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo);
|
||||
|
||||
int32_t exprSize = sizeof(SSqlFuncExprMsg) * pQueryInfo->exprsInfo.numOfExprs;
|
||||
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
int32_t exprSize = sizeof(SSqlFuncMsg) * numOfExprs;
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
// meter query without tags values
|
||||
|
@ -583,20 +585,6 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
|
|||
}
|
||||
|
||||
int32_t size = 4096;
|
||||
|
||||
#if 0
|
||||
SSuperTableMeta *pMetricMeta = pTableMetaInfo->pMetricMeta;
|
||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vgroupIndex);
|
||||
|
||||
int32_t meterInfoSize = (pMetricMeta->tagLen + sizeof(STableIdInfo)) * pVnodeSidList->numOfSids;
|
||||
int32_t outputColumnSize = pQueryInfo->exprsInfo.numOfExprs * sizeof(SSqlFuncExprMsg);
|
||||
|
||||
int32_t size = meterInfoSize + outputColumnSize + srcColListSize + exprSize + MIN_QUERY_MSG_PKT_SIZE;
|
||||
if (pQueryInfo->tsBuf != NULL) {
|
||||
size += pQueryInfo->tsBuf->fileSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -674,17 +662,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pSql->ipList.ip[i] = pVgroupInfo->ipAddr[i].ip;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vgroupIndex);
|
||||
uint32_t vnodeId = pVnodeSidList->vpeerDesc[pVnodeSidList->index].vnode;
|
||||
|
||||
numOfTables = pVnodeSidList->numOfSids;
|
||||
if (numOfTables <= 0) {
|
||||
tscError("%p vid:%d,error numOfTables in query message:%d", pSql, vnodeId, numOfTables);
|
||||
return -1; // error
|
||||
}
|
||||
#endif
|
||||
|
||||
tscTrace("%p query on super table, numOfVgroup:%d, vgroupIndex:%d", pSql, pTableMetaInfo->vgroupList->numOfVgroups, index);
|
||||
|
||||
pQueryMsg->head.vgId = htonl(pVgroupInfo->vgId);
|
||||
|
@ -712,9 +689,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols);
|
||||
|
||||
pQueryMsg->queryType = htons(pQueryInfo->type);
|
||||
pQueryMsg->numOfOutputCols = htons(pQueryInfo->exprsInfo.numOfExprs);
|
||||
|
||||
int32_t numOfOutput = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
|
||||
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
pQueryMsg->numOfOutput = htons(numOfOutput);
|
||||
if (numOfOutput < 0) {
|
||||
tscError("%p illegal value of number of output columns in query msg: %d", pSql, numOfOutput);
|
||||
return -1;
|
||||
|
@ -773,7 +750,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
bool hasArithmeticFunction = false;
|
||||
|
||||
SSqlFuncExprMsg *pSqlFuncExpr = (SSqlFuncExprMsg *)pMsg;
|
||||
SSqlFuncMsg *pSqlFuncExpr = (SSqlFuncMsg *)pMsg;
|
||||
for (int32_t i = 0; i < tscSqlExprNumOfExprs(pQueryInfo); ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
|
@ -793,7 +770,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
pSqlFuncExpr->functionId = htons(pExpr->functionId);
|
||||
pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams);
|
||||
pMsg += sizeof(SSqlFuncExprMsg);
|
||||
pMsg += sizeof(SSqlFuncMsg);
|
||||
|
||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) {
|
||||
pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
|
||||
|
@ -809,7 +786,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
pSqlFuncExpr = (SSqlFuncExprMsg *)pMsg;
|
||||
pSqlFuncExpr = (SSqlFuncMsg *)pMsg;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
|
@ -855,7 +832,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
*((int64_t *)pMsg) = htobe64(pQueryInfo->defaultVal[i]);
|
||||
pMsg += sizeof(pQueryInfo->defaultVal[0]);
|
||||
}
|
||||
|
@ -1260,7 +1237,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pSchema = (SSchema *)pCreateTableMsg->schema;
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
pSchema->type = pField->type;
|
||||
strcpy(pSchema->name, pField->name);
|
||||
|
@ -1279,7 +1256,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
tscClearFieldInfo(&pQueryInfo->fieldsInfo);
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
|
||||
msgLen = pMsg - (char*)pCreateTableMsg;
|
||||
pCreateTableMsg->contLen = htonl(msgLen);
|
||||
|
@ -1327,7 +1304,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
SSchema *pSchema = pAlterTableMsg->schema;
|
||||
for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
pSchema->type = pField->type;
|
||||
strcpy(pSchema->name, pField->name);
|
||||
|
@ -1386,9 +1363,9 @@ static int tscSetResultPointer(SQueryInfo *pQueryInfo, SSqlRes *pRes) {
|
|||
return pRes->code;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
pRes->tsrow[i] = (pRes->data + offset * pRes->numOfRows);
|
||||
pRes->tsrow[i] = ((char*) pRes->data + offset * pRes->numOfRows);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -2198,21 +2175,30 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
|||
pTableMetaInfo->pTableMeta =
|
||||
(STableMeta *)taosCachePut(tscCacheHandle, key, (char *)pTableMeta, size, tsMeterMetaKeepTimer);
|
||||
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
SSchema *pTableSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||
|
||||
if (pQueryInfo->colList == NULL) {
|
||||
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
|
||||
}
|
||||
|
||||
SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
|
||||
|
||||
SColumnIndex index = {0};
|
||||
for (int16_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
index.columnIndex = i;
|
||||
tscColumnListInsert(pQueryInfo->colList, &index);
|
||||
|
||||
tscFieldInfoSetValFromSchema(&pQueryInfo->fieldsInfo, i, &pTableSchema[i]);
|
||||
TAOS_FIELD field = {
|
||||
.bytes = pSchema->bytes,
|
||||
.type = pSchema->type,
|
||||
};
|
||||
|
||||
strncpy(field.name, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
tscFieldInfoAppend(pFieldInfo, &field);
|
||||
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[i] = tscSqlExprInsert(pQueryInfo, i, TSDB_FUNC_TS_DUMMY, &index,
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(pFieldInfo, i);
|
||||
pInfo->pSqlExpr = tscSqlExprInsert(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index,
|
||||
pTableSchema[i].type, pTableSchema[i].bytes, pTableSchema[i].bytes);
|
||||
}
|
||||
|
||||
|
@ -2327,7 +2313,7 @@ int tscProcessQueryRsp(SSqlObj *pSql) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
||||
int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
|
@ -2344,9 +2330,9 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
|||
tscSetResultPointer(pQueryInfo, pRes);
|
||||
|
||||
if (pSql->pSubscription != NULL) {
|
||||
int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, numOfCols - 1);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, numOfCols - 1);
|
||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, numOfCols - 1);
|
||||
|
||||
char* p = pRes->data + (pField->bytes + offset) * pRes->numOfRows;
|
||||
|
@ -2629,7 +2615,7 @@ void tscInitMsgsFp() {
|
|||
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromVnode;
|
||||
tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromNode;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_DROP_DB] = tscProcessDropDbRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_DROP_TABLE] = tscProcessDropTableRsp;
|
||||
|
@ -2640,7 +2626,7 @@ void tscInitMsgsFp() {
|
|||
tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp;
|
||||
|
|
|
@ -326,16 +326,21 @@ int taos_num_fields(TAOS_RES *res) {
|
|||
SSqlObj *pSql = (SSqlObj *)res;
|
||||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
int32_t num = 0;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
if (pQueryInfo == NULL) {
|
||||
return 0;
|
||||
return num;
|
||||
}
|
||||
|
||||
SFieldInfo *pFieldsInfo = &pQueryInfo->fieldsInfo;
|
||||
if (pFieldsInfo)
|
||||
return (pFieldsInfo->numOfOutputCols - pFieldsInfo->numOfHiddenCols);
|
||||
else
|
||||
return 0;
|
||||
size_t numOfCols = tscNumOfFields(pQueryInfo);
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SFieldSupInfo* pInfo = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
if (pInfo->visible) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int taos_field_count(TAOS *taos) {
|
||||
|
@ -357,11 +362,16 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
|||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
if (pQueryInfo)
|
||||
return pQueryInfo->fieldsInfo.pFields;
|
||||
else
|
||||
if (pQueryInfo == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t numOfCols = tscNumOfFields(pQueryInfo);
|
||||
if (numOfCols == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pQueryInfo->fieldsInfo.pFields->pData;
|
||||
}
|
||||
|
||||
int taos_retrieve(TAOS_RES *res) {
|
||||
|
@ -414,8 +424,8 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
if (pQueryInfo == NULL)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i);
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i);
|
||||
}
|
||||
|
||||
*rows = pRes->tsrow;
|
||||
|
@ -448,7 +458,7 @@ static void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pF
|
|||
|
||||
static char *getArithemicInputSrc(void *param, char *name, int32_t colId) {
|
||||
SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
|
||||
SSqlFunctionExpr * pExpr = pSupport->pExpr;
|
||||
SArithExprInfo * pExpr = pSupport->pArithExpr;
|
||||
|
||||
int32_t index = -1;
|
||||
for (int32_t i = 0; i < pExpr->binExprInfo.numOfCols; ++i) {
|
||||
|
@ -476,7 +486,8 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
|||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
//todo refactor move away
|
||||
for(int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for(int32_t k = 0; k < numOfExprs; ++k) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
|
||||
if (k > 0) {
|
||||
|
@ -487,9 +498,9 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
|||
|
||||
int32_t num = 0;
|
||||
for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) {
|
||||
if (pQueryInfo->fieldsInfo.pSqlExpr[i] != NULL) {
|
||||
SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i];
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pExpr->resBytes * pRes->row;
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, i);
|
||||
if (pInfo->pSqlExpr != NULL) {
|
||||
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i) + pInfo->pSqlExpr->resBytes * pRes->row;
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -499,37 +510,37 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
|||
continue;
|
||||
}
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
transferNcharData(pSql, i, pField);
|
||||
|
||||
// calculate the result from serveral other columns
|
||||
if (pQueryInfo->fieldsInfo.pExpr != NULL && pQueryInfo->fieldsInfo.pExpr[i] != NULL) {
|
||||
// calculate the result from several other columns
|
||||
if (pInfo->pArithExprInfo != NULL) {
|
||||
SArithmeticSupport *sas = (SArithmeticSupport *)calloc(1, sizeof(SArithmeticSupport));
|
||||
sas->offset = 0;
|
||||
sas->pExpr = pQueryInfo->fieldsInfo.pExpr[i];
|
||||
sas->pArithExpr = pInfo->pArithExprInfo;
|
||||
|
||||
sas->numOfCols = sas->pExpr->binExprInfo.numOfCols;
|
||||
sas->numOfCols = sas->pArithExpr->binExprInfo.numOfCols;
|
||||
|
||||
if (pRes->buffer[i] == NULL) {
|
||||
pRes->buffer[i] = malloc(tscFieldInfoGetField(pQueryInfo, i)->bytes);
|
||||
pRes->buffer[i] = malloc(tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->bytes);
|
||||
}
|
||||
|
||||
for(int32_t k = 0; k < sas->numOfCols; ++k) {
|
||||
int32_t columnIndex = sas->pExpr->binExprInfo.pReqColumns[k].colIndex;
|
||||
int32_t columnIndex = sas->pArithExpr->binExprInfo.pReqColumns[k].colIndex;
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
|
||||
|
||||
sas->elemSize[k] = pExpr->resBytes;
|
||||
sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
|
||||
}
|
||||
|
||||
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pRes->buffer[i], sas, TSDB_ORDER_ASC, getArithemicInputSrc);
|
||||
tSQLBinaryExprCalcTraverse(sas->pArithExpr->binExprInfo.pBinExpr, 1, pRes->buffer[i], sas, TSDB_ORDER_ASC, getArithemicInputSrc);
|
||||
pRes->tsrow[i] = pRes->buffer[i];
|
||||
|
||||
free(sas); //todo optimization
|
||||
}
|
||||
}
|
||||
|
||||
assert(num <= pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
assert(num <= pQueryInfo->fieldsInfo.numOfOutput);
|
||||
|
||||
pRes->row++; // index increase one-step
|
||||
return pRes->tsrow;
|
||||
|
@ -591,11 +602,13 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
|
|||
|
||||
static UNUSED_FUNC void **tscBuildResFromSubqueries(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
|
||||
while (1) {
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
if (pRes->tsrow == NULL) {
|
||||
pRes->tsrow = calloc(pQueryInfo->exprsInfo.numOfExprs, POINTER_BYTES);
|
||||
pRes->tsrow = calloc(numOfExprs, POINTER_BYTES);
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
@ -619,7 +632,9 @@ static UNUSED_FUNC void **tscBuildResFromSubqueries(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
if (success) { // current row of final output has been built, return to app
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
int32_t tableIndex = pRes->pColumnIndex[i].tableIndex;
|
||||
int32_t columnIndex = pRes->pColumnIndex[i].columnIndex;
|
||||
|
||||
|
@ -1126,7 +1141,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
|||
return code;
|
||||
}
|
||||
|
||||
if ((code = setMeterID(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
if ((code = tscSetTableId(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ static int64_t getDelayValueAfterTimewindowClosed(SSqlStream* pStream, int64_t l
|
|||
}
|
||||
|
||||
static bool isProjectStream(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId != TSDB_FUNC_PRJ) {
|
||||
return false;
|
||||
|
@ -219,9 +219,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
void *oldPtr = pSql->res.data;
|
||||
pSql->res.data = tmpRes;
|
||||
|
||||
for (int32_t i = 1; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 1; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
assignVal(pSql->res.data + offset, (char *)(&pQueryInfo->defaultVal[i]), pField->bytes, pField->type);
|
||||
row[i] = pSql->res.data + offset;
|
||||
|
@ -231,7 +231,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
row[0] = pRes->data;
|
||||
|
||||
// char result[512] = {0};
|
||||
// taos_print_row(result, row, pQueryInfo->fieldsInfo.pFields, pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
// taos_print_row(result, row, pQueryInfo->fieldsInfo.pFields, pQueryInfo->fieldsInfo.numOfOutput);
|
||||
// tscPrint("%p stream:%p query result: %s", pSql, pStream, result);
|
||||
tscTrace("%p stream:%p fetch result", pSql, pStream);
|
||||
|
||||
|
|
|
@ -190,10 +190,10 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
|
|||
return;
|
||||
}
|
||||
|
||||
tscSqlExprInfoDestroy(&pSupporter->exprsInfo);
|
||||
tscSqlExprInfoDestroy(pSupporter->exprsInfo);
|
||||
tscColumnListDestroy(pSupporter->colList);
|
||||
|
||||
tscClearFieldInfo(&pSupporter->fieldsInfo);
|
||||
tscFieldInfoClear(&pSupporter->fieldsInfo);
|
||||
|
||||
if (pSupporter->f != NULL) {
|
||||
fclose(pSupporter->f);
|
||||
|
@ -238,7 +238,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
|
||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
||||
pSupporter = pSql->pSubs[i]->param;
|
||||
if (pSupporter->exprsInfo.numOfExprs > 0) {
|
||||
if (taosArrayGetSize(pSupporter->exprsInfo) > 0) {
|
||||
++numOfSub;
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
|
||||
pSupporter = pPrevSub->param;
|
||||
|
||||
if (pSupporter->exprsInfo.numOfExprs == 0) {
|
||||
if (taosArrayGetSize(pSupporter->exprsInfo) == 0) {
|
||||
tscTrace("%p subIndex: %d, not need to launch query, ignore it", pSql, i);
|
||||
|
||||
tscDestroyJoinSupporter(pSupporter);
|
||||
|
@ -279,7 +279,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
pSubQueryInfo->tsBuf = NULL;
|
||||
|
||||
// free result for async object will also free sqlObj
|
||||
assert(pSubQueryInfo->exprsInfo.numOfExprs == 1); // ts_comp query only requires one resutl columns
|
||||
assert(tscSqlExprNumOfExprs(pSubQueryInfo) == 1); // ts_comp query only requires one resutl columns
|
||||
taos_free_result(pPrevSub);
|
||||
|
||||
SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL);
|
||||
|
@ -304,17 +304,17 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
tscColumnListAssign(pQueryInfo->colList, pSupporter->colList, 0);
|
||||
tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond);
|
||||
|
||||
tscSqlExprCopy(&pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid, false);
|
||||
pQueryInfo->exprsInfo = tscSqlExprCopy(pSupporter->exprsInfo, pSupporter->uid, false);
|
||||
tscFieldInfoCopyAll(&pQueryInfo->fieldsInfo, &pSupporter->fieldsInfo);
|
||||
|
||||
pSupporter->exprsInfo.numOfExprs = 0;
|
||||
pSupporter->fieldsInfo.numOfOutputCols = 0;
|
||||
pSupporter->fieldsInfo.numOfOutput = 0;
|
||||
|
||||
/*
|
||||
* if the first column of the secondary query is not ts function, add this function.
|
||||
* Because this column is required to filter with timestamp after intersecting.
|
||||
*/
|
||||
if (pSupporter->exprsInfo.pExprs[0]->functionId != TSDB_FUNC_TS) {
|
||||
SSqlExpr* pExpr = taosArrayGet(pSupporter->exprsInfo, 0);
|
||||
if (pExpr->functionId != TSDB_FUNC_TS) {
|
||||
tscAddTimestampColumn(pQueryInfo, TSDB_FUNC_TS, 0);
|
||||
}
|
||||
|
||||
|
@ -347,8 +347,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
|
||||
tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
|
||||
pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type,
|
||||
pNewQueryInfo->exprsInfo.numOfExprs, numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
taosArrayGetSize(pNewQueryInfo->exprsInfo), numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
}
|
||||
|
||||
//prepare the subqueries object failed, abort
|
||||
|
@ -691,9 +691,9 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
|
|||
}
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pQueryInfo->fieldsInfo.numOfOutput);
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
int32_t tableIndexOfSub = -1;
|
||||
|
@ -710,7 +710,8 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
|
|||
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd;
|
||||
SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0);
|
||||
|
||||
for (int32_t k = 0; k < pSubQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t numOfExprs = taosArrayGetSize(pSubQueryInfo->exprsInfo);
|
||||
for (int32_t k = 0; k < numOfExprs; ++k) {
|
||||
SSqlExpr* pSubExpr = tscSqlExprGet(pSubQueryInfo, k);
|
||||
if (pExpr->functionId == pSubExpr->functionId && pExpr->colInfo.colId == pSubExpr->colInfo.colId) {
|
||||
pRes->pColumnIndex[i] = (SColumnIndex){.tableIndex = tableIndexOfSub, .columnIndex = k};
|
||||
|
@ -726,11 +727,6 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
|
||||
// int32_t idx = pSql->cmd.vnodeIdx;
|
||||
|
||||
// SVnodeSidList *vnodeInfo = NULL;
|
||||
// if (pTableMetaInfo->pMetricMeta != NULL) {
|
||||
// vnodeInfo = tscGetVnodeSidList(pTableMetaInfo->pMetricMeta, idx - 1);
|
||||
// }
|
||||
|
||||
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
|
||||
|
||||
// if (atomic_add_fetch_32(pSupporter->numOfComplete, 1) >=
|
||||
|
@ -861,8 +857,8 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
|
|||
}
|
||||
|
||||
tscColumnListAssign(pSupporter->colList, pNewQueryInfo->colList, 0);
|
||||
|
||||
tscSqlExprCopy(&pSupporter->exprsInfo, &pNewQueryInfo->exprsInfo, pSupporter->uid, false);
|
||||
|
||||
pSupporter->exprsInfo = tscSqlExprCopy(pNewQueryInfo->exprsInfo, pSupporter->uid, false);
|
||||
tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNewQueryInfo->fieldsInfo);
|
||||
|
||||
tscTagCondCopy(&pSupporter->tagCond, &pNewQueryInfo->tagCond);
|
||||
|
@ -876,8 +872,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
|
|||
memset(&pNewQueryInfo->groupbyExpr, 0, sizeof(SSqlGroupbyExpr));
|
||||
|
||||
// this data needs to be transfer to support struct
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols = 0;
|
||||
pNewQueryInfo->exprsInfo.numOfExprs = 0;
|
||||
pNewQueryInfo->fieldsInfo.numOfOutput = 0;
|
||||
|
||||
// set the ts,tags that involved in join, as the output column of intermediate result
|
||||
tscClearSubqueryInfo(&pNew->cmd);
|
||||
|
@ -913,8 +908,8 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
|
|||
tscTrace("%p subquery:%p tableIndex:%d, vnodeIdx:%d, type:%d, transfer to ts_comp query to retrieve timestamps, "
|
||||
"exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
|
||||
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type,
|
||||
pNewQueryInfo->exprsInfo.numOfExprs, numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
tscPrintSelectClause(pNew, 0);
|
||||
|
||||
} else {
|
||||
|
|
|
@ -30,69 +30,6 @@
|
|||
#include "ttokendef.h"
|
||||
#include "tscLog.h"
|
||||
|
||||
/*
|
||||
* the detailed information regarding metric meta key is:
|
||||
* fullmetername + '.' + tagQueryCond + '.' + tableNameCond + '.' + joinCond +
|
||||
* '.' + relation + '.' + [tagId1, tagId2,...] + '.' + group_orderType
|
||||
*
|
||||
* if querycond/tablenameCond/joinCond is null, its format is:
|
||||
* fullmetername + '.' + '(nil)' + '.' + '(nil)' + relation + '.' + [tagId1,
|
||||
* tagId2,...] + '.' + group_orderType
|
||||
*/
|
||||
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
|
||||
int32_t index = -1;
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMeterMetaInfoByUid(pQueryInfo, uid, &index);
|
||||
|
||||
int32_t len = 0;
|
||||
char tagIdBuf[128] = {0};
|
||||
for (int32_t i = 0; i < pTableMetaInfo->numOfTags; ++i) {
|
||||
len += sprintf(&tagIdBuf[len], "%d,", pTableMetaInfo->tagColumnIndex[i]);
|
||||
}
|
||||
|
||||
STagCond* pTagCond = &pQueryInfo->tagCond;
|
||||
assert(len < tListLen(tagIdBuf));
|
||||
|
||||
const int32_t maxKeySize = TSDB_MAX_TAGS_LEN; // allowed max key size
|
||||
|
||||
SCond* cond = tsGetSTableQueryCond(pTagCond, uid);
|
||||
|
||||
char join[512] = {0};
|
||||
if (pTagCond->joinInfo.hasJoin) {
|
||||
sprintf(join, "%s,%s", pTagCond->joinInfo.left.tableId, pTagCond->joinInfo.right.tableId);
|
||||
}
|
||||
|
||||
// estimate the buffer size
|
||||
size_t tbnameCondLen = pTagCond->tbnameCond.cond != NULL ? strlen(pTagCond->tbnameCond.cond) : 0;
|
||||
size_t redundantLen = 20;
|
||||
|
||||
size_t bufSize = strlen(pTableMetaInfo->name) + tbnameCondLen + strlen(join) + strlen(tagIdBuf);
|
||||
if (cond != NULL && cond->cond != NULL) {
|
||||
bufSize += strlen(cond->cond);
|
||||
}
|
||||
|
||||
bufSize = (size_t)((bufSize + redundantLen) * 1.5);
|
||||
char* tmp = calloc(1, bufSize);
|
||||
|
||||
int32_t keyLen = snprintf(tmp, bufSize, "%s,%s,%s,%d,%s,[%s],%d", pTableMetaInfo->name,
|
||||
((cond != NULL && cond->cond != NULL) ? cond->cond : NULL), (tbnameCondLen > 0 ? pTagCond->tbnameCond.cond : NULL),
|
||||
pTagCond->relType, join, tagIdBuf, pQueryInfo->groupbyExpr.orderType);
|
||||
|
||||
assert(keyLen <= bufSize);
|
||||
|
||||
if (keyLen < maxKeySize) {
|
||||
strcpy(str, tmp);
|
||||
} else { // using md5 to hash
|
||||
MD5_CTX ctx;
|
||||
MD5Init(&ctx);
|
||||
|
||||
MD5Update(&ctx, (uint8_t*)tmp, keyLen);
|
||||
char* pStr = base64_encode(ctx.digest, tListLen(ctx.digest));
|
||||
strcpy(str, pStr);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) {
|
||||
if (pTagCond->pCond == NULL) {
|
||||
return NULL;
|
||||
|
@ -138,7 +75,7 @@ bool tscQueryOnSTable(SSqlCmd* pCmd) {
|
|||
}
|
||||
|
||||
bool tscQueryTags(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
if (tscSqlExprGet(pQueryInfo, i)->functionId != TSDB_FUNC_TAGPRJ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -153,7 +90,7 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) {
|
|||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if (functId == TSDB_FUNC_TAG_DUMMY) {
|
||||
hasTags = true;
|
||||
|
@ -186,29 +123,6 @@ void tscGetDBInfoFromMeterId(char* tableId, char* db) {
|
|||
db[0] = 0;
|
||||
}
|
||||
|
||||
SVnodeSidList* tscGetVnodeSidList(SSuperTableMeta* pMetricmeta, int32_t vnodeIdx) {
|
||||
#if 0
|
||||
if (pMetricmeta == NULL) {
|
||||
tscError("illegal metricmeta");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pMetricmeta->numOfVnodes == 0 || pMetricmeta->numOfTables == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vnodeIdx < 0 || vnodeIdx >= pMetricmeta->numOfVnodes) {
|
||||
int32_t vnodeRange = (pMetricmeta->numOfVnodes > 0) ? (pMetricmeta->numOfVnodes - 1) : 0;
|
||||
tscError("illegal vnodeIdx:%d, reset to 0, vnodeIdx range:%d-%d", vnodeIdx, 0, vnodeRange);
|
||||
|
||||
vnodeIdx = 0;
|
||||
}
|
||||
|
||||
return (SVnodeSidList*)(pMetricmeta->list[vnodeIdx] + (char*)pMetricmeta);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) {
|
||||
if (pSidList == NULL) {
|
||||
tscError("illegal sidlist");
|
||||
|
@ -271,8 +185,9 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
|||
* 1. failed to get metermeta from server; 2. not a super table; 3. limitation is 0;
|
||||
* 4. show queries, instead of a select query
|
||||
*/
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
if (pTableMetaInfo == NULL || !UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo) ||
|
||||
pQueryInfo->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pQueryInfo->exprsInfo.numOfExprs == 0) {
|
||||
pQueryInfo->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || numOfExprs == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -282,7 +197,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
|||
}
|
||||
|
||||
// for project query, only the following two function is allowed
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG &&
|
||||
functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) {
|
||||
|
@ -312,7 +227,7 @@ bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableInde
|
|||
}
|
||||
|
||||
bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TS) {
|
||||
return false;
|
||||
|
@ -323,7 +238,9 @@ bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr == NULL) {
|
||||
return false;
|
||||
|
@ -342,7 +259,8 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr == NULL) {
|
||||
continue;
|
||||
|
@ -368,11 +286,11 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo) {
|
|||
|
||||
int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
||||
if (pRes->tsrow == NULL) {
|
||||
int32_t numOfOutputCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
pRes->numOfCols = numOfOutputCols;
|
||||
int32_t numOfOutput = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
pRes->numOfCols = numOfOutput;
|
||||
|
||||
pRes->tsrow = calloc(POINTER_BYTES, numOfOutputCols);
|
||||
pRes->buffer = calloc(POINTER_BYTES, numOfOutputCols);
|
||||
pRes->tsrow = calloc(POINTER_BYTES, numOfOutput);
|
||||
pRes->buffer = calloc(POINTER_BYTES, numOfOutput);
|
||||
|
||||
// not enough memory
|
||||
if (pRes->tsrow == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) {
|
||||
|
@ -883,139 +801,71 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void ensureSpace(SFieldInfo* pFieldInfo, int32_t size) {
|
||||
if (size > pFieldInfo->numOfAlloc) {
|
||||
int32_t oldSize = pFieldInfo->numOfAlloc;
|
||||
TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes) {
|
||||
TAOS_FIELD f = { .type = type, .bytes = bytes, };
|
||||
strncpy(f.name, name, TSDB_COL_NAME_LEN);
|
||||
return f;
|
||||
}
|
||||
|
||||
int32_t newSize = (oldSize <= 0) ? 8 : (oldSize << 1);
|
||||
while (newSize < size) {
|
||||
newSize = (newSize << 1);
|
||||
}
|
||||
|
||||
if (newSize > TSDB_MAX_COLUMNS) {
|
||||
newSize = TSDB_MAX_COLUMNS;
|
||||
}
|
||||
|
||||
int32_t inc = newSize - oldSize;
|
||||
|
||||
pFieldInfo->pFields = realloc(pFieldInfo->pFields, newSize * sizeof(TAOS_FIELD));
|
||||
memset(&pFieldInfo->pFields[oldSize], 0, inc * sizeof(TAOS_FIELD));
|
||||
|
||||
// pFieldInfo->pOffset = realloc(pFieldInfo->pOffset, newSize * sizeof(int16_t));
|
||||
// memset(&pFieldInfo->pOffset[oldSize], 0, inc * sizeof(int16_t));
|
||||
|
||||
pFieldInfo->pVisibleCols = realloc(pFieldInfo->pVisibleCols, newSize * sizeof(bool));
|
||||
memset(&pFieldInfo->pVisibleCols[oldSize], 0, inc * sizeof(bool));
|
||||
|
||||
pFieldInfo->pSqlExpr = realloc(pFieldInfo->pSqlExpr, POINTER_BYTES*newSize);
|
||||
pFieldInfo->pExpr = realloc(pFieldInfo->pExpr, POINTER_BYTES*newSize);
|
||||
SFieldSupInfo* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) {
|
||||
assert(pFieldInfo != NULL);
|
||||
taosArrayPush(pFieldInfo->pFields, pField);
|
||||
pFieldInfo->numOfOutput++;
|
||||
|
||||
memset(&pFieldInfo->pSqlExpr[oldSize], 0, inc * POINTER_BYTES);
|
||||
memset(&pFieldInfo->pExpr[oldSize], 0, inc * POINTER_BYTES);
|
||||
struct SFieldSupInfo info = {
|
||||
.pSqlExpr = NULL,
|
||||
.pArithExprInfo = NULL,
|
||||
.visible = true,
|
||||
};
|
||||
|
||||
pFieldInfo->numOfAlloc = newSize;
|
||||
}
|
||||
return taosArrayPush(pFieldInfo->pSupportInfo, &info);
|
||||
}
|
||||
|
||||
static void evic(SFieldInfo* pFieldInfo, int32_t index) {
|
||||
if (index < pFieldInfo->numOfOutputCols) {
|
||||
memmove(&pFieldInfo->pFields[index + 1], &pFieldInfo->pFields[index],
|
||||
sizeof(pFieldInfo->pFields[0]) * (pFieldInfo->numOfOutputCols - index));
|
||||
|
||||
memmove(&pFieldInfo->pVisibleCols[index + 1], &pFieldInfo->pVisibleCols[index],
|
||||
sizeof(pFieldInfo->pVisibleCols[0]) * (pFieldInfo->numOfOutputCols - index));
|
||||
|
||||
memmove(&pFieldInfo->pSqlExpr[index + 1], &pFieldInfo->pSqlExpr[index],
|
||||
sizeof(pFieldInfo->pSqlExpr[0]) * (pFieldInfo->numOfOutputCols - index));
|
||||
SFieldSupInfo* tscFieldInfoGetSupp(SFieldInfo* pFieldInfo, int32_t index) {
|
||||
return taosArrayGet(pFieldInfo->pSupportInfo, index);
|
||||
}
|
||||
|
||||
SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field) {
|
||||
taosArrayInsert(pFieldInfo->pFields, index, field);
|
||||
pFieldInfo->numOfOutput++;
|
||||
|
||||
memmove(&pFieldInfo->pExpr[index + 1], &pFieldInfo->pExpr[index],
|
||||
sizeof(pFieldInfo->pExpr[0]) * (pFieldInfo->numOfOutputCols - index));
|
||||
}
|
||||
}
|
||||
|
||||
static void setValueImpl(TAOS_FIELD* pField, int8_t type, const char* name, int16_t bytes) {
|
||||
pField->type = type;
|
||||
strncpy(pField->name, name, TSDB_COL_NAME_LEN);
|
||||
pField->bytes = bytes;
|
||||
}
|
||||
|
||||
void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema) {
|
||||
ensureSpace(pFieldInfo, pFieldInfo->numOfOutputCols + 1);
|
||||
evic(pFieldInfo, index);
|
||||
|
||||
TAOS_FIELD* pField = &pFieldInfo->pFields[index];
|
||||
setValueImpl(pField, pSchema->type, pSchema->name, pSchema->bytes);
|
||||
pFieldInfo->numOfOutputCols++;
|
||||
}
|
||||
|
||||
void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField) {
|
||||
ensureSpace(pFieldInfo, pFieldInfo->numOfOutputCols + 1);
|
||||
evic(pFieldInfo, index);
|
||||
|
||||
memcpy(&pFieldInfo->pFields[index], pField, sizeof(TAOS_FIELD));
|
||||
pFieldInfo->pVisibleCols[index] = true;
|
||||
pFieldInfo->numOfOutputCols++;
|
||||
}
|
||||
|
||||
void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible) {
|
||||
if (index < 0 || index >= pFieldInfo->numOfOutputCols) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool oldVisible = pFieldInfo->pVisibleCols[index];
|
||||
pFieldInfo->pVisibleCols[index] = visible;
|
||||
|
||||
if (oldVisible != visible) {
|
||||
if (!visible) {
|
||||
pFieldInfo->numOfHiddenCols += 1;
|
||||
} else {
|
||||
if (pFieldInfo->numOfHiddenCols > 0) {
|
||||
pFieldInfo->numOfHiddenCols -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, const char* name, int16_t bytes) {
|
||||
ensureSpace(pFieldInfo, pFieldInfo->numOfOutputCols + 1);
|
||||
evic(pFieldInfo, index);
|
||||
|
||||
TAOS_FIELD* pField = &pFieldInfo->pFields[index];
|
||||
setValueImpl(pField, type, name, bytes);
|
||||
|
||||
pFieldInfo->pVisibleCols[index] = true;
|
||||
pFieldInfo->numOfOutputCols++;
|
||||
}
|
||||
|
||||
void tscFieldInfoSetExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlExpr* pExpr) {
|
||||
assert(index >= 0 && index < pFieldInfo->numOfOutputCols);
|
||||
pFieldInfo->pSqlExpr[index] = pExpr;
|
||||
}
|
||||
|
||||
void tscFieldInfoSetBinExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlFunctionExpr* pExpr) {
|
||||
assert(index >= 0 && index < pFieldInfo->numOfOutputCols);
|
||||
pFieldInfo->pExpr[index] = pExpr;
|
||||
struct SFieldSupInfo info = {
|
||||
.pSqlExpr = NULL,
|
||||
.pArithExprInfo = NULL,
|
||||
.visible = true,
|
||||
};
|
||||
|
||||
return taosArrayInsert(pFieldInfo->pSupportInfo, index, &info);
|
||||
}
|
||||
|
||||
void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo) {
|
||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||
pExprInfo->pExprs[0]->offset = 0;
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 1; i < pExprInfo->numOfExprs; ++i) {
|
||||
pExprInfo->pExprs[i]->offset = pExprInfo->pExprs[i - 1]->offset + pExprInfo->pExprs[i - 1]->resBytes;
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
pExpr->offset = 0;
|
||||
|
||||
for (int32_t i = 1; i < numOfExprs; ++i) {
|
||||
SSqlExpr* prev = taosArrayGetP(pQueryInfo->exprsInfo, i - 1);
|
||||
SSqlExpr* p = taosArrayGetP(pQueryInfo->exprsInfo, i);
|
||||
|
||||
p->offset = prev->offset + prev->resBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo) {
|
||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||
if (pExprInfo->numOfExprs == 0) {
|
||||
if (tscSqlExprNumOfExprs(pQueryInfo) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
pExprInfo->pExprs[0]->offset = 0;
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
pExpr->offset = 0;
|
||||
|
||||
for (int32_t i = 1; i < pExprInfo->numOfExprs; ++i) {
|
||||
pExprInfo->pExprs[i]->offset = pExprInfo->pExprs[i - 1]->offset + pExprInfo->pExprs[i - 1]->resBytes;
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 1; i < numOfExprs; ++i) {
|
||||
SSqlExpr* prev = taosArrayGetP(pQueryInfo->exprsInfo, i - 1);
|
||||
SSqlExpr* p = taosArrayGetP(pQueryInfo->exprsInfo, i);
|
||||
|
||||
p->offset = prev->offset + prev->resBytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1025,62 +875,52 @@ void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList
|
|||
}
|
||||
|
||||
if (size <= 0) {
|
||||
*dst = *src;
|
||||
tscFieldInfoCopyAll(dst, src);
|
||||
} else { // only copy the required column
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
assert(indexList[i] >= 0 && indexList[i] <= src->numOfOutputCols);
|
||||
tscFieldInfoSetValFromField(dst, i, &src->pFields[indexList[i]]);
|
||||
dst->pVisibleCols[i] = src->pVisibleCols[indexList[i]];
|
||||
dst->pSqlExpr[i] = src->pSqlExpr[indexList[i]];
|
||||
assert(indexList[i] >= 0 && indexList[i] <= src->numOfOutput);
|
||||
TAOS_FIELD* p = taosArrayGet(src->pFields, indexList[i]);
|
||||
SFieldSupInfo* pInfo = taosArrayGet(src->pSupportInfo, indexList[i]);
|
||||
|
||||
SFieldSupInfo* pInfo1 = tscFieldInfoAppend(dst, p);
|
||||
*pInfo1 = *pInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tscFieldInfoCopyAll(SFieldInfo* dst, SFieldInfo* src) {
|
||||
*dst = *src;
|
||||
dst->numOfOutput = src->numOfOutput;
|
||||
|
||||
dst->pFields = malloc(sizeof(TAOS_FIELD) * dst->numOfAlloc);
|
||||
dst->pVisibleCols = malloc(sizeof(bool) * dst->numOfAlloc);
|
||||
dst->pSqlExpr = malloc(POINTER_BYTES * dst->numOfAlloc);
|
||||
dst->pExpr = malloc(POINTER_BYTES * dst->numOfAlloc);
|
||||
|
||||
memcpy(dst->pFields, src->pFields, sizeof(TAOS_FIELD) * dst->numOfOutputCols);
|
||||
memcpy(dst->pVisibleCols, src->pVisibleCols, sizeof(bool) * dst->numOfOutputCols);
|
||||
memcpy(dst->pSqlExpr, src->pSqlExpr, POINTER_BYTES * dst->numOfOutputCols);
|
||||
memcpy(dst->pExpr, src->pExpr, POINTER_BYTES * dst->numOfOutputCols);
|
||||
taosArrayCopy(dst->pFields, src->pFields);
|
||||
taosArrayCopy(dst->pSupportInfo, src->pSupportInfo);
|
||||
}
|
||||
|
||||
TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index) {
|
||||
if (index >= pQueryInfo->fieldsInfo.numOfOutputCols) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &pQueryInfo->fieldsInfo.pFields[index];
|
||||
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) {
|
||||
return taosArrayGet(pFieldInfo->pFields, index);
|
||||
}
|
||||
|
||||
int32_t tscNumOfFields(SQueryInfo* pQueryInfo) { return pQueryInfo->fieldsInfo.numOfOutputCols; }
|
||||
int32_t tscNumOfFields(SQueryInfo* pQueryInfo) { return pQueryInfo->fieldsInfo.numOfOutput; }
|
||||
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index) {
|
||||
if (index >= pQueryInfo->exprsInfo.numOfExprs) {
|
||||
return 0;
|
||||
}
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, index);
|
||||
assert(pInfo != NULL);
|
||||
|
||||
return pQueryInfo->exprsInfo.pExprs[index]->offset;
|
||||
return pInfo->pSqlExpr->offset;
|
||||
}
|
||||
|
||||
int32_t tscFieldInfoCompare(SFieldInfo* pFieldInfo1, SFieldInfo* pFieldInfo2) {
|
||||
int32_t tscFieldInfoCompare(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2) {
|
||||
assert(pFieldInfo1 != NULL && pFieldInfo2 != NULL);
|
||||
|
||||
if (pFieldInfo1->numOfOutputCols != pFieldInfo2->numOfOutputCols) {
|
||||
return pFieldInfo1->numOfOutputCols - pFieldInfo2->numOfOutputCols;
|
||||
if (pFieldInfo1->numOfOutput != pFieldInfo2->numOfOutput) {
|
||||
return pFieldInfo1->numOfOutput - pFieldInfo2->numOfOutput;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pFieldInfo1->numOfOutputCols; ++i) {
|
||||
TAOS_FIELD* pField1 = &pFieldInfo1->pFields[i];
|
||||
TAOS_FIELD* pField2 = &pFieldInfo2->pFields[i];
|
||||
for (int32_t i = 0; i < pFieldInfo1->numOfOutput; ++i) {
|
||||
TAOS_FIELD* pField1 = tscFieldInfoGetField((SFieldInfo*) pFieldInfo1, i);
|
||||
TAOS_FIELD* pField2 = tscFieldInfoGetField((SFieldInfo*) pFieldInfo2, i);
|
||||
|
||||
if (pField1->type != pField2->type || pField1->bytes != pField2->bytes ||
|
||||
if (pField1->type != pField2->type ||
|
||||
pField1->bytes != pField2->bytes ||
|
||||
strcasecmp(pField1->name, pField2->name) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -1089,99 +929,56 @@ int32_t tscFieldInfoCompare(SFieldInfo* pFieldInfo1, SFieldInfo* pFieldInfo2) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tscGetResRowLength(SQueryInfo* pQueryInfo) {
|
||||
if (pQueryInfo->exprsInfo.numOfExprs <= 0) {
|
||||
int32_t tscGetResRowLength(SArray* pExprList) {
|
||||
size_t num = taosArrayGetSize(pExprList);
|
||||
if (num == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t size = 0;
|
||||
for(int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size += pQueryInfo->exprsInfo.pExprs[i]->resBytes;
|
||||
for(int32_t i = 0; i < num; ++i) {
|
||||
SSqlExpr* pExpr = taosArrayGetP(pExprList, i);
|
||||
size += pExpr->resBytes;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void tscClearFieldInfo(SFieldInfo* pFieldInfo) {
|
||||
void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
|
||||
if (pFieldInfo == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tfree(pFieldInfo->pFields);
|
||||
tfree(pFieldInfo->pVisibleCols);
|
||||
tfree(pFieldInfo->pSqlExpr);
|
||||
taosArrayDestroy(pFieldInfo->pFields);
|
||||
|
||||
for(int32_t i = 0; i < pFieldInfo->numOfOutputCols; ++i) {
|
||||
if (pFieldInfo->pExpr[i] != NULL) {
|
||||
tExprTreeDestroy(&pFieldInfo->pExpr[i]->binExprInfo.pBinExpr, NULL);
|
||||
tfree(pFieldInfo->pExpr[i]->binExprInfo.pReqColumns);
|
||||
tfree(pFieldInfo->pExpr[i]);
|
||||
for(int32_t i = 0; i < pFieldInfo->numOfOutput; ++i) {
|
||||
SFieldSupInfo* pInfo = taosArrayGet(pFieldInfo->pSupportInfo, i);
|
||||
|
||||
if (pInfo->pArithExprInfo != NULL) {
|
||||
tExprTreeDestroy(&pInfo->pArithExprInfo->binExprInfo.pBinExpr, NULL);
|
||||
tfree(pInfo->pArithExprInfo->binExprInfo.pReqColumns);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(pFieldInfo->pExpr);
|
||||
taosArrayDestroy(pFieldInfo->pSupportInfo);
|
||||
memset(pFieldInfo, 0, sizeof(SFieldInfo));
|
||||
}
|
||||
|
||||
static void _exprCheckSpace(SSqlExprInfo* pExprInfo, int32_t size) {
|
||||
if (size > pExprInfo->numOfAlloc) {
|
||||
uint32_t oldSize = pExprInfo->numOfAlloc;
|
||||
|
||||
uint32_t newSize = (oldSize <= 0) ? 8 : (oldSize << 1U);
|
||||
while (newSize < size) {
|
||||
newSize = (newSize << 1U);
|
||||
}
|
||||
|
||||
if (newSize > TSDB_MAX_COLUMNS) {
|
||||
newSize = TSDB_MAX_COLUMNS;
|
||||
}
|
||||
|
||||
int32_t inc = newSize - oldSize;
|
||||
|
||||
pExprInfo->pExprs = realloc(pExprInfo->pExprs, newSize * sizeof(SSqlExpr));
|
||||
memset(&pExprInfo->pExprs[oldSize], 0, inc * sizeof(SSqlExpr));
|
||||
|
||||
pExprInfo->numOfAlloc = newSize;
|
||||
}
|
||||
}
|
||||
|
||||
static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) {
|
||||
if (index < pExprInfo->numOfExprs) {
|
||||
memmove(&pExprInfo->pExprs[index + 1], &pExprInfo->pExprs[index],
|
||||
sizeof(pExprInfo->pExprs[0]) * (pExprInfo->numOfExprs - index));
|
||||
}
|
||||
}
|
||||
|
||||
SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId) {
|
||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||
|
||||
_exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1);
|
||||
_exprEvic(pExprInfo, index);
|
||||
|
||||
SSqlExpr* tscSqlExprAppend(SArray* exprInfo, int16_t functionId) {
|
||||
SSqlExpr* pExpr = calloc(1, sizeof(SSqlExpr));
|
||||
pExpr->functionId = functionId;
|
||||
|
||||
pExprInfo->numOfExprs++;
|
||||
pExprInfo->pExprs[index] = pExpr;
|
||||
return pExpr;
|
||||
return taosArrayPush(exprInfo, &pExpr);
|
||||
}
|
||||
|
||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex,
|
||||
int16_t type, int16_t size, int16_t interSize) {
|
||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t interSize) {
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pColIndex->tableIndex);
|
||||
|
||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||
|
||||
_exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1);
|
||||
_exprEvic(pExprInfo, index);
|
||||
|
||||
SSqlExpr* pExpr = calloc(1, sizeof(SSqlExpr));
|
||||
pExprInfo->pExprs[index] = pExpr;
|
||||
|
||||
pExpr->functionId = functionId;
|
||||
|
||||
int16_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
|
||||
|
||||
SSqlExpr* pExpr = calloc(1, sizeof(SSqlExpr));
|
||||
pExpr->functionId = functionId;
|
||||
|
||||
// set the correct column index
|
||||
if (pColIndex->columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
pExpr->colInfo.colId = TSDB_TBNAME_COLUMN_INDEX;
|
||||
|
@ -1206,21 +1003,19 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
|||
pExpr->resBytes = size;
|
||||
pExpr->interResBytes = interSize;
|
||||
pExpr->uid = pTableMetaInfo->pTableMeta->uid;
|
||||
|
||||
pExprInfo->numOfExprs++;
|
||||
|
||||
taosArrayPush(pQueryInfo->exprsInfo, &pExpr);
|
||||
return pExpr;
|
||||
}
|
||||
|
||||
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex,
|
||||
int16_t type, int16_t size) {
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||
if (index > pExprInfo->numOfExprs) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, index);
|
||||
if (pExpr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSqlExpr* pExpr = pExprInfo->pExprs[index];
|
||||
|
||||
pExpr->functionId = functionId;
|
||||
|
||||
pExpr->colInfo.colIndex = srcColumnIndex;
|
||||
|
@ -1233,7 +1028,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
|||
}
|
||||
|
||||
int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo) {
|
||||
return pQueryInfo->exprsInfo.numOfExprs;
|
||||
return taosArrayGetSize(pQueryInfo->exprsInfo);
|
||||
}
|
||||
|
||||
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex) {
|
||||
|
@ -1250,14 +1045,10 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes,
|
|||
}
|
||||
|
||||
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) {
|
||||
if (pQueryInfo->exprsInfo.numOfExprs <= index) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pQueryInfo->exprsInfo.pExprs[index];
|
||||
return taosArrayGetP(pQueryInfo->exprsInfo, index);
|
||||
}
|
||||
|
||||
void* tscSqlExprDestroy(SSqlExpr* pExpr) {
|
||||
void* sqlExprDestroy(SSqlExpr* pExpr) {
|
||||
if (pExpr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1274,54 +1065,46 @@ void* tscSqlExprDestroy(SSqlExpr* pExpr) {
|
|||
/*
|
||||
* NOTE: Does not release SSqlExprInfo here.
|
||||
*/
|
||||
void tscSqlExprInfoDestroy(SSqlExprInfo* pExprInfo) {
|
||||
if (pExprInfo->numOfAlloc == 0) {
|
||||
return;
|
||||
void tscSqlExprInfoDestroy(SArray* pExprInfo) {
|
||||
size_t size = taosArrayGetSize(pExprInfo);
|
||||
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = taosArrayGetP(pExprInfo, i);
|
||||
sqlExprDestroy(pExpr);
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < pExprInfo->numOfExprs; ++i) {
|
||||
tscSqlExprDestroy(pExprInfo->pExprs[i]);
|
||||
}
|
||||
|
||||
tfree(pExprInfo->pExprs);
|
||||
|
||||
pExprInfo->numOfAlloc = 0;
|
||||
pExprInfo->numOfExprs = 0;
|
||||
taosArrayDestroy(pExprInfo);
|
||||
}
|
||||
|
||||
void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t tableuid, bool deepcopy) {
|
||||
if (src == NULL || src->numOfExprs == 0) {
|
||||
return;
|
||||
SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy) {
|
||||
if (src == NULL || taosArrayGetSize(src) == 0) {
|
||||
return taosArrayInit(1, POINTER_BYTES);
|
||||
}
|
||||
|
||||
*dst = *src;
|
||||
|
||||
dst->pExprs = calloc(dst->numOfAlloc, POINTER_BYTES);
|
||||
|
||||
int16_t num = 0;
|
||||
for (int32_t i = 0; i < src->numOfExprs; ++i) {
|
||||
if (src->pExprs[i]->uid == tableuid) {
|
||||
size_t size = taosArrayGetSize(src);
|
||||
SArray* dst = taosArrayInit(size, POINTER_BYTES);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = taosArrayGetP(src, i);
|
||||
|
||||
if (pExpr->uid == uid) {
|
||||
|
||||
if (deepcopy) {
|
||||
dst->pExprs[num] = calloc(1, sizeof(SSqlExpr));
|
||||
*dst->pExprs[num] = *src->pExprs[i];
|
||||
} else {
|
||||
dst->pExprs[num] = src->pExprs[i];
|
||||
}
|
||||
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
dst->numOfExprs = num;
|
||||
SSqlExpr* p1 = calloc(1, sizeof(SSqlExpr));
|
||||
*p1 = *pExpr;
|
||||
|
||||
if (deepcopy) {
|
||||
for (int32_t i = 0; i < dst->numOfExprs; ++i) {
|
||||
for (int32_t j = 0; j < src->pExprs[i]->numOfParams; ++j) {
|
||||
tVariantAssign(&dst->pExprs[i]->param[j], &src->pExprs[i]->param[j]);
|
||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) {
|
||||
tVariantAssign(&p1->param[j], &pExpr->param[j]);
|
||||
}
|
||||
|
||||
taosArrayPush(dst, &p1);
|
||||
} else {
|
||||
taosArrayPush(dst, &pExpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) {
|
||||
|
@ -1646,8 +1429,9 @@ void tscTagCondRelease(STagCond* pTagCond) {
|
|||
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
SSchema* pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
pColInfo[i].functionId = pExpr->functionId;
|
||||
|
||||
|
@ -1707,7 +1491,7 @@ void tscCleanSqlCmd(SSqlCmd* pCmd) {
|
|||
*
|
||||
* If connection need to be recycled, the SqlObj also should be freed.
|
||||
*/
|
||||
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
|
||||
bool tscShouldBeFreed(SSqlObj* pSql) {
|
||||
if (pSql == NULL || pSql->signature != pSql || pSql->fp == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1783,7 +1567,7 @@ int32_t tscGetQueryInfoDetailSafely(SSqlCmd* pCmd, int32_t subClauseIndex, SQuer
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index) {
|
||||
STableMetaInfo* tscGetTableMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index) {
|
||||
int32_t k = -1;
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||
|
@ -1813,6 +1597,13 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
|||
pCmd->pQueryInfo = (SQueryInfo**)tmp;
|
||||
|
||||
SQueryInfo* pQueryInfo = calloc(1, sizeof(SQueryInfo));
|
||||
|
||||
// todo refactor to extract functions.
|
||||
pQueryInfo->fieldsInfo.pFields = taosArrayInit(4, sizeof(TAOS_FIELD));
|
||||
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(4, sizeof(SFieldSupInfo));
|
||||
|
||||
pQueryInfo->exprsInfo = taosArrayInit(4, POINTER_BYTES);
|
||||
|
||||
pQueryInfo->msg = pCmd->payload; // pointer to the parent error message buffer
|
||||
|
||||
pCmd->pQueryInfo[pCmd->numOfClause++] = pQueryInfo;
|
||||
|
@ -1821,9 +1612,9 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
|||
|
||||
static void doClearSubqueryInfo(SQueryInfo* pQueryInfo) {
|
||||
tscTagCondRelease(&pQueryInfo->tagCond);
|
||||
tscClearFieldInfo(&pQueryInfo->fieldsInfo);
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
|
||||
tscSqlExprInfoDestroy(&pQueryInfo->exprsInfo);
|
||||
tscSqlExprInfoDestroy(pQueryInfo->exprsInfo);
|
||||
memset(&pQueryInfo->exprsInfo, 0, sizeof(pQueryInfo->exprsInfo));
|
||||
|
||||
tscColumnListDestroy(pQueryInfo->colList);
|
||||
|
@ -1851,7 +1642,7 @@ void tscFreeSubqueryInfo(SSqlCmd* pCmd) {
|
|||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, i);
|
||||
|
||||
doClearSubqueryInfo(pQueryInfo);
|
||||
tscRemoveAllMeterMetaInfo(pQueryInfo, (const char*)addr, false);
|
||||
tscClearAllTableMetaInfo(pQueryInfo, (const char*)addr, false);
|
||||
tfree(pQueryInfo);
|
||||
}
|
||||
|
||||
|
@ -1919,7 +1710,7 @@ void doRemoveTableMetaInfo(SQueryInfo* pQueryInfo, int32_t index, bool removeFro
|
|||
pQueryInfo->numOfTables -= 1;
|
||||
}
|
||||
|
||||
void tscRemoveAllMeterMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache) {
|
||||
void tscClearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache) {
|
||||
tscTrace("%p deref the table meta in cache, numOfTables:%d", address, pQueryInfo->numOfTables);
|
||||
|
||||
int32_t index = pQueryInfo->numOfTables;
|
||||
|
@ -1937,7 +1728,6 @@ void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache)
|
|||
|
||||
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), removeFromCache);
|
||||
tfree(pTableMetaInfo->vgroupList);
|
||||
// taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pMetricMeta), removeFromCache);
|
||||
}
|
||||
|
||||
void tscResetForNextRetrieve(SSqlRes* pRes) {
|
||||
|
@ -2003,8 +1793,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
|||
tscTagCondCopy(&pNewQueryInfo->tagCond, &pQueryInfo->tagCond);
|
||||
|
||||
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||
pNewQueryInfo->defaultVal = malloc(pQueryInfo->fieldsInfo.numOfOutputCols * sizeof(int64_t));
|
||||
memcpy(pNewQueryInfo->defaultVal, pQueryInfo->defaultVal, pQueryInfo->fieldsInfo.numOfOutputCols * sizeof(int64_t));
|
||||
pNewQueryInfo->defaultVal = malloc(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t));
|
||||
memcpy(pNewQueryInfo->defaultVal, pQueryInfo->defaultVal, pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t));
|
||||
}
|
||||
|
||||
if (tscAllocPayload(pnCmd, TSDB_DEFAULT_PAYLOAD_SIZE) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -2024,30 +1814,33 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
|||
}
|
||||
|
||||
uint64_t uid = pTableMetaInfo->pTableMeta->uid;
|
||||
tscSqlExprCopy(&pNewQueryInfo->exprsInfo, &pQueryInfo->exprsInfo, uid, true);
|
||||
pNewQueryInfo->exprsInfo = tscSqlExprCopy(pQueryInfo->exprsInfo, uid, true);
|
||||
|
||||
int32_t numOfOutputCols = pNewQueryInfo->exprsInfo.numOfExprs;
|
||||
int32_t numOfOutput = tscSqlExprNumOfExprs(pNewQueryInfo);
|
||||
|
||||
if (numOfOutputCols > 0) {
|
||||
int32_t* indexList = calloc(1, numOfOutputCols * sizeof(int32_t));
|
||||
for (int32_t i = 0, j = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
if (numOfOutput > 0) {
|
||||
int32_t* indexList = calloc(1, numOfOutput * sizeof(int32_t));
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0, j = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->uid == uid) {
|
||||
indexList[j++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
tscFieldInfoCopy(&pQueryInfo->fieldsInfo, &pNewQueryInfo->fieldsInfo, indexList, numOfOutputCols);
|
||||
tscFieldInfoCopy(&pQueryInfo->fieldsInfo, &pNewQueryInfo->fieldsInfo, indexList, numOfOutput);
|
||||
free(indexList);
|
||||
|
||||
// make sure the the sqlExpr for each fields is correct
|
||||
// todo handle the agg arithmetic expression
|
||||
for(int32_t f = 0; f < pNewQueryInfo->fieldsInfo.numOfOutputCols; ++f) {
|
||||
char* name = pNewQueryInfo->fieldsInfo.pFields[f].name;
|
||||
for(int32_t k1 = 0; k1 < pNewQueryInfo->exprsInfo.numOfExprs; ++k1) {
|
||||
for(int32_t f = 0; f < pNewQueryInfo->fieldsInfo.numOfOutput; ++f) {
|
||||
TAOS_FIELD* field = tscFieldInfoGetField(&pNewQueryInfo->fieldsInfo, f);
|
||||
for(int32_t k1 = 0; k1 < numOfExprs; ++k1) {
|
||||
SSqlExpr* pExpr1 = tscSqlExprGet(pNewQueryInfo, k1);
|
||||
if (strcmp(name, pExpr1->aliasName) == 0) {
|
||||
pNewQueryInfo->fieldsInfo.pSqlExpr[f] = pExpr1;
|
||||
if (strcmp(field->name, pExpr1->aliasName) == 0) {
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pNewQueryInfo->fieldsInfo, f);
|
||||
pInfo->pSqlExpr = pExpr1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2058,15 +1851,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
|||
pNew->fp = fp;
|
||||
pNew->param = param;
|
||||
|
||||
char key[TSDB_MAX_TAGS_LEN + 1] = {0};
|
||||
if (cmd == TSDB_SQL_SELECT) {
|
||||
tscGetMetricMetaCacheKey(pQueryInfo, key, uid);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
tscTrace("the metricmeta key is:%s", key);
|
||||
#endif
|
||||
|
||||
char* name = pTableMetaInfo->name;
|
||||
STableMetaInfo* pFinalInfo = NULL;
|
||||
|
||||
|
@ -2097,8 +1881,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
|||
tscTrace(
|
||||
"%p new subquery: %p, tableIndex:%d, vnodeIdx:%d, type:%d, exprInfo:%d, colList:%d,"
|
||||
"fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64,
|
||||
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, pNewQueryInfo->exprsInfo.numOfExprs,
|
||||
size, pNewQueryInfo->fieldsInfo.numOfOutputCols, pFinalInfo->name, pNewQueryInfo->stime,
|
||||
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
|
||||
size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->stime,
|
||||
pNewQueryInfo->etime, pNewQueryInfo->order.order, pNewQueryInfo->limit.limit);
|
||||
|
||||
tscPrintSelectClause(pNew, 0);
|
||||
|
@ -2326,3 +2110,11 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) {
|
|||
tscProcessSql(pSql);
|
||||
}
|
||||
}
|
||||
|
||||
char* tscGetResultColumnChr(SSqlRes* pRes, SQueryInfo* pQueryInfo, int32_t column) {
|
||||
SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(pFieldInfo, column);
|
||||
|
||||
return ((char*) pRes->data) + pInfo->pSqlExpr->offset * pRes->numOfRows;
|
||||
}
|
||||
|
||||
|
|
|
@ -372,7 +372,7 @@ typedef struct SColIndex {
|
|||
|
||||
/* sql function msg, to describe the message to vnode about sql function
|
||||
* operations in select clause */
|
||||
typedef struct SSqlFuncExprMsg {
|
||||
typedef struct SSqlFuncMsg {
|
||||
int16_t functionId;
|
||||
int16_t numOfParams;
|
||||
|
||||
|
@ -386,21 +386,21 @@ typedef struct SSqlFuncExprMsg {
|
|||
char * pz;
|
||||
} argValue;
|
||||
} arg[3];
|
||||
} SSqlFuncExprMsg;
|
||||
} SSqlFuncMsg;
|
||||
|
||||
typedef struct SSqlBinaryExprInfo {
|
||||
typedef struct SExprInfo {
|
||||
struct tExprNode *pBinExpr; /* for binary expression */
|
||||
int32_t numOfCols; /* binary expression involves the readed number of columns*/
|
||||
SColIndex * pReqColumns; /* source column list */
|
||||
} SSqlBinaryExprInfo;
|
||||
} SExprInfo;
|
||||
|
||||
typedef struct SSqlFunctionExpr {
|
||||
SSqlFuncExprMsg pBase;
|
||||
SSqlBinaryExprInfo binExprInfo;
|
||||
int16_t resBytes;
|
||||
int16_t resType;
|
||||
int16_t interResBytes;
|
||||
} SSqlFunctionExpr;
|
||||
typedef struct SArithExprInfo {
|
||||
SSqlFuncMsg pBase;
|
||||
SExprInfo binExprInfo;
|
||||
int16_t bytes;
|
||||
int16_t type;
|
||||
int16_t interResBytes;
|
||||
} SArithExprInfo;
|
||||
|
||||
typedef struct SColumnFilterInfo {
|
||||
int16_t lowerRelOptr;
|
||||
|
@ -469,7 +469,7 @@ typedef struct {
|
|||
int64_t limit;
|
||||
int64_t offset;
|
||||
uint16_t queryType; // denote another query process
|
||||
int16_t numOfOutputCols; // final output columns numbers
|
||||
int16_t numOfOutput; // final output columns numbers
|
||||
int16_t interpoType; // interpolate type
|
||||
uint64_t defaultVal; // default value array list
|
||||
|
||||
|
|
Loading…
Reference in New Issue