executor.c 3.5 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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/>.
14 15 16
 */

#include "executor.h"
H
Haojun Liao 已提交
17
#include "executorimpl.h"
18
#include "planner.h"
L
Liu Jicong 已提交
19
#include "tq.h"
20

21
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, char* id) {
H
Haojun Liao 已提交
22
  ASSERT(pOperator != NULL);
X
Xiaoyu Wang 已提交
23
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
H
Haojun Liao 已提交
24
    if (pOperator->numOfDownstream == 0) {
25
      qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
H
Haojun Liao 已提交
26 27
      return TSDB_CODE_QRY_APP_ERROR;
    }
H
Haojun Liao 已提交
28

H
Haojun Liao 已提交
29
    if (pOperator->numOfDownstream > 1) {  // not handle this in join query
30
      qError("join not supported for stream block scan, %s" PRIx64, id);
H
Haojun Liao 已提交
31
      return TSDB_CODE_QRY_APP_ERROR;
H
Haojun Liao 已提交
32
    }
H
Haojun Liao 已提交
33

34
    return doSetStreamBlock(pOperator->pDownstream[0], input, id);
H
Haojun Liao 已提交
35 36
  } else {
    SStreamBlockScanInfo* pInfo = pOperator->info;
L
Liu Jicong 已提交
37
    if (tqReadHandleSetMsg(pInfo->readerHandle, input, 0) < 0) {
L
Liu Jicong 已提交
38
      qError("submit msg messed up when initing stream block, %s" PRIx64, id);
L
Liu Jicong 已提交
39 40
      return TSDB_CODE_QRY_APP_ERROR;
    }
H
Haojun Liao 已提交
41 42 43 44
    return TSDB_CODE_SUCCESS;
  }
}

H
Haojun Liao 已提交
45
int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input) {
H
Haojun Liao 已提交
46 47 48 49 50 51 52 53
  if (tinfo == NULL) {
    return TSDB_CODE_QRY_APP_ERROR;
  }

  if (input == NULL) {
    return TSDB_CODE_SUCCESS;
  }

L
Liu Jicong 已提交
54
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
H
Haojun Liao 已提交
55

L
Liu Jicong 已提交
56
  int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void*)input, GET_TASKID(pTaskInfo));
H
Haojun Liao 已提交
57
  if (code != TSDB_CODE_SUCCESS) {
H
Haojun Liao 已提交
58
    qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo));
H
Haojun Liao 已提交
59
  } else {
H
Haojun Liao 已提交
60
    qDebug("%s set the stream block successfully", GET_TASKID(pTaskInfo));
H
Haojun Liao 已提交
61 62 63 64 65
  }

  return code;
}

L
Liu Jicong 已提交
66 67
qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) {
  if (msg == NULL || streamReadHandle == NULL) {
68 69 70 71
    return NULL;
  }

  // print those info into log
L
Liu Jicong 已提交
72
#if 0
L
Liu Jicong 已提交
73 74 75 76
  pMsg->sId = pMsg->sId;
  pMsg->queryId = pMsg->queryId;
  pMsg->taskId = pMsg->taskId;
  pMsg->contentLen = pMsg->contentLen;
L
Liu Jicong 已提交
77
#endif
78

79
  struct SSubplan* plan = NULL;
L
Liu Jicong 已提交
80
  int32_t          code = qStringToSubplan(msg, &plan);
81 82 83 84 85 86
  if (code != TSDB_CODE_SUCCESS) {
    terrno = code;
    return NULL;
  }

  qTaskInfo_t pTaskInfo = NULL;
H
Haojun Liao 已提交
87
  code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL);
88 89 90 91 92 93 94 95
  if (code != TSDB_CODE_SUCCESS) {
    // TODO: destroy SSubplan & pTaskInfo
    terrno = code;
    return NULL;
  }

  return pTaskInfo;
}
96

H
Haojun Liao 已提交
97
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isAdd) {
98 99 100 101
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo* )tinfo;

  // traverse to the streamscan node to add this table id
  SOperatorInfo* pInfo = pTaskInfo->pRoot;
X
Xiaoyu Wang 已提交
102
  while(pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    pInfo = pInfo->pDownstream[0];
  }

  SStreamBlockScanInfo* pScanInfo = pInfo->info;
  if (isAdd) {
    int32_t code = tqReadHandleSetTbUidList(pScanInfo->readerHandle, tableIdList);
    if (code != TSDB_CODE_SUCCESS) {
      return code;
    }
  } else {
    assert(0);
  }

  return TSDB_CODE_SUCCESS;
}