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/>.
|
2022-01-21 05:45:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "executor.h"
|
2022-01-21 07:16:17 +00:00
|
|
|
#include "executorimpl.h"
|
2022-01-21 06:21:13 +00:00
|
|
|
#include "planner.h"
|
2022-02-21 02:48:23 +00:00
|
|
|
#include "tq.h"
|
2022-01-21 06:21:13 +00:00
|
|
|
|
2022-01-25 15:08:22 +00:00
|
|
|
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, char* id) {
|
2022-01-21 07:16:17 +00:00
|
|
|
ASSERT(pOperator != NULL);
|
|
|
|
|
if (pOperator->operatorType != OP_StreamScan) {
|
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-01-21 07:36:24 +00:00
|
|
|
|
2022-01-25 15:08:22 +00:00
|
|
|
return doSetStreamBlock(pOperator->pDownstream[0], input, id);
|
2022-01-21 07:16:17 +00:00
|
|
|
} else {
|
|
|
|
|
SStreamBlockScanInfo* pInfo = pOperator->info;
|
2022-02-21 02:48:23 +00:00
|
|
|
if (tqReadHandleSetMsg(pInfo->readerHandle, input, 0) < 0) {
|
2022-02-23 08:04:06 +00:00
|
|
|
qError("submit msg messed up when initing stream block, %s" PRIx64, id);
|
2022-02-21 02:48:23 +00:00
|
|
|
return TSDB_CODE_QRY_APP_ERROR;
|
|
|
|
|
}
|
2022-01-21 07:16:17 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 02:44:02 +00:00
|
|
|
int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input) {
|
2022-01-21 07:16:17 +00:00
|
|
|
if (tinfo == NULL) {
|
|
|
|
|
return TSDB_CODE_QRY_APP_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input == NULL) {
|
|
|
|
|
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-02-21 02:48:23 +00:00
|
|
|
int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void*)input, 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) {
|
2022-01-21 05:45:24 +00:00
|
|
|
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
|
2022-01-21 05:45:24 +00:00
|
|
|
|
2022-01-21 06:21:13 +00:00
|
|
|
struct SSubplan* plan = NULL;
|
2022-01-24 13:39:00 +00:00
|
|
|
int32_t code = qStringToSubplan(msg, &plan);
|
2022-01-21 05:45:24 +00:00
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
terrno = code;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qTaskInfo_t pTaskInfo = NULL;
|
2022-01-25 05:42:33 +00:00
|
|
|
code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL);
|
2022-01-21 05:45:24 +00:00
|
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
|
|
|
// TODO: destroy SSubplan & pTaskInfo
|
|
|
|
|
terrno = code;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pTaskInfo;
|
|
|
|
|
}
|