提交 d6647dd6 编写于 作者: H hjxilinx

[td-186] add select on tags support

上级 b93fbf7c
...@@ -102,7 +102,7 @@ typedef struct SColumnIndex { ...@@ -102,7 +102,7 @@ typedef struct SColumnIndex {
typedef struct SFieldSupInfo { typedef struct SFieldSupInfo {
bool visible; bool visible;
SArithExprInfo *pArithExprInfo; SExprInfo *pArithExprInfo;
SSqlExpr * pSqlExpr; SSqlExpr * pSqlExpr;
} SFieldSupInfo; } SFieldSupInfo;
......
...@@ -1207,7 +1207,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1207,7 +1207,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, slot); SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, slot);
if (pInfo->pSqlExpr == NULL) { if (pInfo->pSqlExpr == NULL) {
SArithExprInfo* pFuncExpr = calloc(1, sizeof(SArithExprInfo)); SExprInfo* pFuncExpr = calloc(1, sizeof(SExprInfo));
pInfo->pArithExprInfo = pFuncExpr; pInfo->pArithExprInfo = pFuncExpr;
// arithmetic expression always return result in the format of double float // arithmetic expression always return result in the format of double float
......
...@@ -437,7 +437,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -437,7 +437,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
static UNUSED_FUNC char *getArithemicInputSrc(void *param, const char *name, int32_t colId) { static UNUSED_FUNC char *getArithemicInputSrc(void *param, const char *name, int32_t colId) {
// SArithmeticSupport *pSupport = (SArithmeticSupport *)param; // SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
// SArithExprInfo * pExpr = pSupport->pArithExpr; // SExprInfo * pExpr = pSupport->pArithExpr;
// int32_t index = -1; // int32_t index = -1;
// for (int32_t i = 0; i < pExpr->numOfCols; ++i) { // for (int32_t i = 0; i < pExpr->numOfCols; ++i) {
......
...@@ -380,13 +380,13 @@ typedef struct SSqlFuncMsg { ...@@ -380,13 +380,13 @@ typedef struct SSqlFuncMsg {
} arg[3]; } arg[3];
} SSqlFuncMsg; } SSqlFuncMsg;
typedef struct SArithExprInfo { typedef struct SExprInfo {
SSqlFuncMsg base; SSqlFuncMsg base;
struct tExprNode* pExpr; struct tExprNode* pExpr;
int16_t bytes; int16_t bytes;
int16_t type; int16_t type;
int16_t interResBytes; int16_t interResBytes;
} SArithExprInfo; } SExprInfo;
typedef struct SColumnFilterInfo { typedef struct SColumnFilterInfo {
int16_t lowerRelOptr; int16_t lowerRelOptr;
......
...@@ -97,8 +97,8 @@ int tsdbTableSetName(STableCfg *config, char *name, bool dup); ...@@ -97,8 +97,8 @@ int tsdbTableSetName(STableCfg *config, char *name, bool dup);
int tsdbTableSetSName(STableCfg *config, char *sname, bool dup); int tsdbTableSetSName(STableCfg *config, char *sname, bool dup);
void tsdbClearTableCfg(STableCfg *config); void tsdbClearTableCfg(STableCfg *config);
int32_t tsdbGetTableTagVal(TsdbRepoT *repo, STableId id, int32_t col, int16_t *type, int16_t *bytes, char **val); int32_t tsdbGetTableTagVal(TsdbRepoT *repo, STableId* id, int32_t col, int16_t *type, int16_t *bytes, char **val);
int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name); int32_t tsdbTableGetName(TsdbRepoT *repo, STableId* id, char** name);
int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg);
int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId); int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId);
...@@ -150,21 +150,12 @@ typedef struct STsdbQueryCond { ...@@ -150,21 +150,12 @@ typedef struct STsdbQueryCond {
SColumnInfo *colList; SColumnInfo *colList;
} STsdbQueryCond; } STsdbQueryCond;
typedef struct SBlockInfo {
STimeWindow window;
int32_t numOfRows;
int32_t numOfCols;
STableId tableId;
} SBlockInfo;
typedef struct SDataBlockInfo { typedef struct SDataBlockInfo {
STimeWindow window; STimeWindow window;
int32_t rows; int32_t rows;
int32_t numOfCols; int32_t numOfCols;
int64_t uid; int64_t uid;
int32_t sid; int32_t tid;
} SDataBlockInfo; } SDataBlockInfo;
typedef struct { typedef struct {
...@@ -279,7 +270,7 @@ SArray *tsdbGetTableList(TsdbQueryHandleT *pQueryHandle); ...@@ -279,7 +270,7 @@ SArray *tsdbGetTableList(TsdbQueryHandleT *pQueryHandle);
* @param pTagCond. tag query condition * @param pTagCond. tag query condition
* *
*/ */
int32_t tsdbQueryByTagsCond( int32_t tsdbQuerySTableByTagCond(
TsdbRepoT *tsdb, TsdbRepoT *tsdb,
int64_t uid, int64_t uid,
const char *pTagCond, const char *pTagCond,
......
...@@ -96,24 +96,20 @@ typedef struct SSingleColumnFilterInfo { ...@@ -96,24 +96,20 @@ typedef struct SSingleColumnFilterInfo {
void* pData; void* pData;
} SSingleColumnFilterInfo; } SSingleColumnFilterInfo;
typedef struct STableQueryInfo { typedef struct STableQueryInfo { // todo merge with the STableQueryInfo struct
int64_t lastKey; int32_t tableIndex;
STimeWindow win; int32_t groupIdx; // group id in table list
TSKEY lastKey;
int32_t numOfRes; int32_t numOfRes;
int16_t queryRangeSet; // denote if the query range is set, only available for interval query int16_t queryRangeSet; // denote if the query range is set, only available for interval query
int64_t tag; int64_t tag;
STimeWindow win;
STSCursor cur; STSCursor cur;
int32_t tid; // for retrieve the page id list STableId id; // for retrieve the page id list
SWindowResInfo windowResInfo; SWindowResInfo windowResInfo;
} STableQueryInfo; } STableQueryInfo;
typedef struct STableDataInfo { // todo merge with the STableQueryInfo struct
int32_t tableIndex;
int32_t groupIdx; // group id in table list
STableQueryInfo* pTableQInfo;
} STableDataInfo;
typedef struct SQuery { typedef struct SQuery {
int16_t numOfCols; int16_t numOfCols;
int16_t numOfTags; int16_t numOfTags;
...@@ -130,7 +126,7 @@ typedef struct SQuery { ...@@ -130,7 +126,7 @@ typedef struct SQuery {
SLimitVal limit; SLimitVal limit;
int32_t rowSize; int32_t rowSize;
SSqlGroupbyExpr* pGroupbyExpr; SSqlGroupbyExpr* pGroupbyExpr;
SArithExprInfo* pSelectExpr; SExprInfo* pSelectExpr;
SColumnInfo* colList; SColumnInfo* colList;
SColumnInfo* tagColList; SColumnInfo* tagColList;
int32_t numOfFilterCols; int32_t numOfFilterCols;
...@@ -170,14 +166,15 @@ typedef struct SQInfo { ...@@ -170,14 +166,15 @@ typedef struct SQInfo {
TSKEY startTime; TSKEY startTime;
TSKEY elapsedTime; TSKEY elapsedTime;
int32_t pointsInterpo; int32_t pointsInterpo;
int32_t code; // error code to returned to client int32_t code; // error code to returned to client
sem_t dataReady; sem_t dataReady;
void* tsdb; void* tsdb;
STableGroupInfo groupInfo; // table id list STableGroupInfo tableIdGroupInfo; // table id list < only includes the STableId list>
STableGroupInfo groupInfo; //
SQueryRuntimeEnv runtimeEnv; SQueryRuntimeEnv runtimeEnv;
int32_t groupIndex; int32_t groupIndex;
int32_t offset; /* offset in group result set of subgroup */ int32_t offset; // offset in group result set of subgroup, todo refactor
T_REF_DECLARE() T_REF_DECLARE()
/* /*
......
...@@ -114,7 +114,7 @@ enum { ...@@ -114,7 +114,7 @@ enum {
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0) #define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
typedef struct SArithmeticSupport { typedef struct SArithmeticSupport {
SArithExprInfo *pArithExpr; SExprInfo *pArithExpr;
int32_t numOfCols; int32_t numOfCols;
SColumnInfo* colList; SColumnInfo* colList;
int32_t offset; int32_t offset;
......
此差异已折叠。
...@@ -225,9 +225,9 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable) { ...@@ -225,9 +225,9 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable) {
} }
} }
int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId id, int32_t colId, int16_t* type, int16_t* bytes, char** val) { int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId* id, int32_t colId, int16_t* type, int16_t* bytes, char** val) {
STsdbMeta* pMeta = tsdbGetMeta(repo); STsdbMeta* pMeta = tsdbGetMeta(repo);
STable* pTable = tsdbGetTableByUid(pMeta, id.uid); STable* pTable = tsdbGetTableByUid(pMeta, id->uid);
STSchema* pSchema = tsdbGetTableTagSchema(pMeta, pTable); STSchema* pSchema = tsdbGetTableTagSchema(pMeta, pTable);
...@@ -251,9 +251,9 @@ int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId id, int32_t colId, int16_t* ...@@ -251,9 +251,9 @@ int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId id, int32_t colId, int16_t*
return 0; return 0;
} }
int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name) { int32_t tsdbTableGetName(TsdbRepoT *repo, STableId* id, char** name) {
STsdbMeta* pMeta = tsdbGetMeta(repo); STsdbMeta* pMeta = tsdbGetMeta(repo);
STable* pTable = tsdbGetTableByUid(pMeta, id.uid); STable* pTable = tsdbGetTableByUid(pMeta, id->uid);
*name = strndup(pTable->name, TSDB_TABLE_NAME_LEN); *name = strndup(pTable->name, TSDB_TABLE_NAME_LEN);
if (*name == NULL) { if (*name == NULL) {
......
...@@ -62,13 +62,9 @@ typedef struct STableCheckInfo { ...@@ -62,13 +62,9 @@ typedef struct STableCheckInfo {
STableId tableId; STableId tableId;
TSKEY lastKey; TSKEY lastKey;
STable* pTableObj; STable* pTableObj;
int64_t offsetInHeaderFile;
int32_t start; int32_t start;
bool checkFirstFileBlock;
SCompInfo* pCompInfo; SCompInfo* pCompInfo;
int32_t compSize; int32_t compSize;
int32_t numOfBlocks; // number of qualified data blocks not the original blocks int32_t numOfBlocks; // number of qualified data blocks not the original blocks
SDataCols* pDataCols; SDataCols* pDataCols;
...@@ -159,15 +155,15 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable ...@@ -159,15 +155,15 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable
assert(gsize > 0); assert(gsize > 0);
for (int32_t j = 0; j < gsize; ++j) { for (int32_t j = 0; j < gsize; ++j) {
SPair* d = (SPair*) taosArrayGet(group, j); STableId* id = (STableId*) taosArrayGet(group, j);
assert(d->first != NULL);
STableCheckInfo info = { STableCheckInfo info = {
.lastKey = pQueryHandle->window.skey, .lastKey = pQueryHandle->window.skey,
.tableId = ((STable*) d->first)->tableId, .tableId = *id,
.pTableObj = d->first, .pTableObj = tsdbGetTableByUid(tsdbGetMeta(tsdb), id->uid),
}; };
assert(info.pTableObj != NULL);
taosArrayPush(pQueryHandle->pTableCheckInfo, &info); taosArrayPush(pQueryHandle->pTableCheckInfo, &info);
} }
} }
...@@ -357,7 +353,7 @@ static SDataBlockInfo getTrueDataBlockInfo(STableCheckInfo* pCheckInfo, SCompBlo ...@@ -357,7 +353,7 @@ static SDataBlockInfo getTrueDataBlockInfo(STableCheckInfo* pCheckInfo, SCompBlo
.window = {.skey = pBlock->keyFirst, .ekey = pBlock->keyLast}, .window = {.skey = pBlock->keyFirst, .ekey = pBlock->keyLast},
.numOfCols = pBlock->numOfCols, .numOfCols = pBlock->numOfCols,
.rows = pBlock->numOfPoints, .rows = pBlock->numOfPoints,
.sid = pCheckInfo->tableId.tid, .tid = pCheckInfo->tableId.tid,
.uid = pCheckInfo->tableId.uid, .uid = pCheckInfo->tableId.uid,
}; };
...@@ -1058,7 +1054,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) { ...@@ -1058,7 +1054,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) {
SDataBlockInfo blockInfo = { SDataBlockInfo blockInfo = {
.uid = pTable->tableId.uid, .uid = pTable->tableId.uid,
.sid = pTable->tableId.tid, .tid = pTable->tableId.tid,
.rows = rows, .rows = rows,
.window = {.skey = MIN(skey, ekey), .ekey = MAX(skey, ekey)} .window = {.skey = MIN(skey, ekey), .ekey = MAX(skey, ekey)}
}; };
...@@ -1293,24 +1289,19 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { ...@@ -1293,24 +1289,19 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
} }
void createTableGroupImpl(SArray* pGroups, STable** pTables, size_t numOfTables, STableGroupSupporter* pSupp, __ext_compar_fn_t compareFn) { void createTableGroupImpl(SArray* pGroups, STable** pTables, size_t numOfTables, STableGroupSupporter* pSupp, __ext_compar_fn_t compareFn) {
SArray* g = taosArrayInit(16, sizeof(SPair)); SArray* g = taosArrayInit(16, sizeof(STableId));
taosArrayPush(g, &pTables[0]->tableId);
SPair p = {.first = pTables[0]};
taosArrayPush(g, &p);
for (int32_t i = 1; i < numOfTables; ++i) { for (int32_t i = 1; i < numOfTables; ++i) {
int32_t ret = compareFn(&pTables[i - 1], &pTables[i], pSupp); int32_t ret = compareFn(&pTables[i - 1], &pTables[i], pSupp);
assert(ret == 0 || ret == -1); assert(ret == 0 || ret == -1);
if (ret == 0) { if (ret == 0) {
SPair p1 = {.first = pTables[i]}; taosArrayPush(g, &pTables[i]->tableId);
taosArrayPush(g, &p1);
} else { } else {
taosArrayPush(pGroups, &g); // current group is ended, start a new group taosArrayPush(pGroups, &g); // current group is ended, start a new group
g = taosArrayInit(16, POINTER_BYTES); g = taosArrayInit(16, POINTER_BYTES);
taosArrayPush(g, &pTables[i]->tableId);
SPair p1 = {.first = pTables[i]};
taosArrayPush(g, &p1);
} }
} }
...@@ -1329,11 +1320,10 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC ...@@ -1329,11 +1320,10 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
} }
if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table
SArray* sa = taosArrayInit(size, sizeof(SPair)); SArray* sa = taosArrayInit(size, sizeof(STableId));
for(int32_t i = 0; i < size; ++i) { for(int32_t i = 0; i < size; ++i) {
STable* pTable = taosArrayGetP(pTableList, i); STable* pTable = taosArrayGetP(pTableList, i);
SPair p = {.first = pTable}; taosArrayPush(sa, &pTable->tableId);
taosArrayPush(sa, &p);
} }
taosArrayPush(pTableGroup, &sa); taosArrayPush(pTableGroup, &sa);
...@@ -1441,24 +1431,15 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) ...@@ -1441,24 +1431,15 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr)
} }
int32_t tsdbQueryByTagsCond( int32_t tsdbQuerySTableByTagCond(TsdbRepoT *tsdb, int64_t uid, const char *pTagCond, size_t len, int16_t tagNameRelType,
TsdbRepoT *tsdb, const char* tbnameCond, STableGroupInfo *pGroupInfo, SColIndex *pColIndex, int32_t numOfCols) {
int64_t uid,
const char *pTagCond,
size_t len,
int16_t tagNameRelType,
const char* tbnameCond,
STableGroupInfo *pGroupInfo,
SColIndex *pColIndex,
int32_t numOfCols
) {
STable* pSTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); STable* pSTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
if (pSTable == NULL) { if (pSTable == NULL) {
uError("failed to get stable, uid:%" PRIu64, uid); uError("failed to get stable, uid:%" PRIu64, uid);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_INVALID_TABLE_ID;
} }
SArray* res = taosArrayInit(8, POINTER_BYTES); SArray* res = taosArrayInit(8, sizeof(STableId));
STSchema* pTagSchema = tsdbGetTableTagSchema(tsdbGetMeta(tsdb), pSTable); STSchema* pTagSchema = tsdbGetTableTagSchema(tsdbGetMeta(tsdb), pSTable);
// no tags and tbname condition, all child tables of this stable are involved // no tags and tbname condition, all child tables of this stable are involved
...@@ -1472,7 +1453,7 @@ int32_t tsdbQueryByTagsCond( ...@@ -1472,7 +1453,7 @@ int32_t tsdbQueryByTagsCond(
return ret; return ret;
} }
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
tExprNode* expr = exprTreeFromTableName(tbnameCond); tExprNode* expr = exprTreeFromTableName(tbnameCond);
tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len); tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len);
...@@ -1507,9 +1488,9 @@ int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, int64_t uid, STableGroupInfo* pGro ...@@ -1507,9 +1488,9 @@ int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, int64_t uid, STableGroupInfo* pGro
pGroupInfo->numOfTables = 1; pGroupInfo->numOfTables = 1;
pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES); pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES);
SArray* group = taosArrayInit(1, POINTER_BYTES); SArray* group = taosArrayInit(1, sizeof(STableId));
taosArrayPush(group, &pTable); taosArrayPush(group, &pTable->tableId);
taosArrayPush(pGroupInfo->pGroupList, &group); taosArrayPush(pGroupInfo->pGroupList, &group);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
......
...@@ -107,11 +107,6 @@ extern "C" { ...@@ -107,11 +107,6 @@ extern "C" {
#define POW2(x) ((x) * (x)) #define POW2(x) ((x) * (x))
typedef struct SPair {
void* first;
void* sec;
} SPair;
int32_t strdequote(char *src); int32_t strdequote(char *src);
void strtrim(char *src); void strtrim(char *src);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册