executor.c 3.3 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 18
#include "tq.h"
#include "executorimpl.h"
19 20
#include "planner.h"

21
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, char* id) {
H
Haojun Liao 已提交
22 23
  ASSERT(pOperator != NULL);
  if (pOperator->operatorType != OP_StreamScan) {
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 37 38 39 40 41
  } else {
    SStreamBlockScanInfo* pInfo = pOperator->info;
    tqReadHandleSetMsg(pInfo->readerHandle, input, 0);
    return TSDB_CODE_SUCCESS;
  }
}

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

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

  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*) tinfo;
H
Haojun Liao 已提交
52

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

  return code;
}

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

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

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

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

  return pTaskInfo;
}
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

int32_t qUpdateTQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isAdd) {
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo* )tinfo;

  // traverse to the streamscan node to add this table id
  SOperatorInfo* pInfo = pTaskInfo->pRoot;
  while(pInfo->operatorType != OP_StreamScan) {
    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;
}