TDengine/source/libs/executor/src/executor.c

184 lines
5.8 KiB
C
Raw Normal View History

2021-09-24 10:05:56 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "executor.h"
2022-01-21 07:16:17 +00:00
#include "executorimpl.h"
#include "planner.h"
2022-03-29 07:24:25 +00:00
#include "tdatablock.h"
2022-03-22 11:47:57 +00:00
#include "vnode.h"
2022-03-29 07:24:25 +00:00
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
2022-01-21 07:16:17 +00:00
ASSERT(pOperator != NULL);
2022-02-28 09:02:43 +00:00
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
2022-01-21 07:36:24 +00:00
if (pOperator->numOfDownstream == 0) {
2022-01-25 15:08:22 +00:00
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
2022-01-21 07:36:24 +00:00
return TSDB_CODE_QRY_APP_ERROR;
}
2022-01-21 07:16:17 +00:00
2022-01-21 07:36:24 +00:00
if (pOperator->numOfDownstream > 1) { // not handle this in join query
2022-01-25 15:08:22 +00:00
qError("join not supported for stream block scan, %s" PRIx64, id);
2022-01-21 07:36:24 +00:00
return TSDB_CODE_QRY_APP_ERROR;
2022-01-21 07:16:17 +00:00
}
2022-03-23 09:00:21 +00:00
pOperator->status = OP_NOT_OPENED;
2022-03-29 05:31:17 +00:00
return doSetStreamBlock(pOperator->pDownstream[0], input, numOfBlocks, type, id);
2022-01-21 07:16:17 +00:00
} else {
pOperator->status = OP_NOT_OPENED;
2022-01-21 07:16:17 +00:00
SStreamBlockScanInfo* pInfo = pOperator->info;
2022-03-21 08:15:51 +00:00
// the block type can not be changed in the streamscan operators
if (pInfo->blockType == 0) {
pInfo->blockType = type;
} else if (pInfo->blockType != type) {
2022-02-21 02:48:23 +00:00
return TSDB_CODE_QRY_APP_ERROR;
}
2022-03-21 08:15:51 +00:00
if (type == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
if (tqReadHandleSetMsg(pInfo->streamBlockReader, input, 0) < 0) {
2022-03-21 08:15:51 +00:00
qError("submit msg messed up when initing stream block, %s" PRIx64, id);
return TSDB_CODE_QRY_APP_ERROR;
}
} else {
2022-03-29 05:31:17 +00:00
for (int32_t i = 0; i < numOfBlocks; ++i) {
2022-03-29 07:24:25 +00:00
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
2022-03-21 08:15:51 +00:00
SSDataBlock* p = createOneDataBlock(pDataBlock, false);
2022-03-29 05:31:17 +00:00
p->info = pDataBlock->info;
2022-03-21 08:15:51 +00:00
2022-03-29 07:24:25 +00:00
taosArrayClear(p->pDataBlock);
2022-03-29 05:31:17 +00:00
taosArrayAddAll(p->pDataBlock, pDataBlock->pDataBlock);
taosArrayPush(pInfo->pBlockLists, &p);
}
2022-03-21 08:15:51 +00:00
}
2022-01-21 07:16:17 +00:00
return TSDB_CODE_SUCCESS;
}
}
2022-03-21 08:15:51 +00:00
int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type) {
2022-03-29 07:24:25 +00:00
return qSetMultiStreamInput(tinfo, input, 1, type);
2022-03-29 05:31:17 +00:00
}
2022-03-29 07:24:25 +00:00
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
2022-01-21 07:16:17 +00:00
if (tinfo == NULL) {
return TSDB_CODE_QRY_APP_ERROR;
}
2022-03-29 05:31:17 +00:00
if (pBlocks == NULL || numOfBlocks == 0) {
2022-01-21 07:16:17 +00:00
return TSDB_CODE_SUCCESS;
}
2022-02-21 02:48:23 +00:00
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2022-01-21 07:36:24 +00:00
2022-03-29 05:31:17 +00:00
int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void**)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo));
2022-01-21 07:16:17 +00:00
if (code != TSDB_CODE_SUCCESS) {
2022-01-25 05:42:33 +00:00
qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo));
2022-01-21 07:16:17 +00:00
} else {
2022-01-25 05:42:33 +00:00
qDebug("%s set the stream block successfully", GET_TASKID(pTaskInfo));
2022-01-21 07:16:17 +00:00
}
return code;
}
2022-01-24 13:39:00 +00:00
qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) {
if (msg == NULL || streamReadHandle == NULL) {
return NULL;
}
// print those info into log
2022-01-21 08:13:11 +00:00
#if 0
2022-01-21 08:12:02 +00:00
pMsg->sId = pMsg->sId;
pMsg->queryId = pMsg->queryId;
pMsg->taskId = pMsg->taskId;
pMsg->contentLen = pMsg->contentLen;
2022-01-21 08:13:11 +00:00
#endif
/*qDebugL("stream task string %s", (const char*)msg);*/
2022-03-27 01:31:27 +00:00
struct SSubplan* plan = NULL;
2022-01-24 13:39:00 +00:00
int32_t code = qStringToSubplan(msg, &plan);
if (code != TSDB_CODE_SUCCESS) {
terrno = code;
return NULL;
}
qTaskInfo_t pTaskInfo = NULL;
code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL, OPTR_EXEC_MODEL_STREAM);
if (code != TSDB_CODE_SUCCESS) {
// TODO: destroy SSubplan & pTaskInfo
terrno = code;
return NULL;
}
return pTaskInfo;
}
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
2022-03-02 08:22:43 +00:00
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
// traverse to the stream scanner node to add this table id
SOperatorInfo* pInfo = pTaskInfo->pRoot;
2022-03-22 10:00:03 +00:00
while (pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
pInfo = pInfo->pDownstream[0];
}
SStreamBlockScanInfo* pScanInfo = pInfo->info;
if (isAdd) {
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
SMetaReader mr = {0};
metaReaderInit(&mr, pScanInfo->readHandle.meta, 0);
for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) {
int64_t* id = (int64_t*)taosArrayGet(tableIdList, i);
int32_t code = metaGetTableEntryByUid(&mr, *id);
if (code != TSDB_CODE_SUCCESS) {
qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno));
continue;
}
ASSERT(mr.me.type == TSDB_CHILD_TABLE);
if (mr.me.ctbEntry.suid != pScanInfo->tableUid) {
continue;
}
taosArrayPush(qa, id);
}
metaReaderClear(&mr);
qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa));
int32_t code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, qa);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
} else {
assert(0);
}
return TSDB_CODE_SUCCESS;
2022-03-02 08:22:43 +00:00
}
int32_t qGetQueriedTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, int32_t* tversion) {
ASSERT(tinfo != NULL && dbName != NULL && tableName != NULL);
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*) tinfo;
*sversion = pTaskInfo->schemaVer.sversion;
*tversion = pTaskInfo->schemaVer.tversion;
strcpy(dbName, pTaskInfo->schemaVer.dbname);
strcpy(tableName, pTaskInfo->schemaVer.tablename);
return 0;
}