dataSinkMgt.h 2.6 KB
Newer Older
X
Xiaoyu Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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/>.
 */

#ifndef _DATA_SINK_MGT_H
#define _DATA_SINK_MGT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "os.h"
X
Xiaoyu Wang 已提交
24
#include "thash.h"
D
dapan1121 已提交
25
#include "executor.h"
X
Xiaoyu Wang 已提交
26

X
Xiaoyu Wang 已提交
27 28 29
#define DS_BUF_LOW   1
#define DS_BUF_FULL  2
#define DS_BUF_EMPTY 3
X
Xiaoyu Wang 已提交
30 31 32 33 34

struct SDataSink;
struct SSDataBlock;

typedef struct SDataSinkMgtCfg {
35
  uint32_t maxDataBlockNum;           // todo: this should be numOfRows?
X
Xiaoyu Wang 已提交
36 37 38 39 40
  uint32_t maxDataBlockNumPerQuery;
} SDataSinkMgtCfg;

int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg);

41
typedef struct SInputData {
X
Xiaoyu Wang 已提交
42
  const struct SSDataBlock* pData;
X
Xiaoyu Wang 已提交
43
  SHashObj* pTableRetrieveTsMap;
44 45
} SInputData;

X
Xiaoyu Wang 已提交
46
typedef struct SOutputData {
47 48 49
  int32_t numOfRows;
  int8_t  compressed;
  char*   pData;
X
Xiaoyu Wang 已提交
50 51 52 53 54 55
  bool    queryEnd;
  bool    needSchedule;
  int32_t bufStatus;
  int64_t useconds;
  int8_t  precision;
} SOutputData;
X
Xiaoyu Wang 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

/**
 * Create a subplan's datasinker handle for all later operations. 
 * @param pDataSink
 * @param pHandle output
 * @return error code
 */
int32_t dsCreateDataSinker(const struct SDataSink *pDataSink, DataSinkHandle* pHandle);

/**
 * Put the result set returned by the executor into datasinker.
 * @param handle
 * @param pRes
 * @return error code
 */
X
Xiaoyu Wang 已提交
71
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue);
72

X
Xiaoyu Wang 已提交
73
void dsEndPut(DataSinkHandle handle, int64_t useconds);
X
Xiaoyu Wang 已提交
74 75 76 77

/**
 * Get the length of the data returned by the next call to dsGetDataBlock.
 * @param handle
X
Xiaoyu Wang 已提交
78
 * @param pLen data length
X
Xiaoyu Wang 已提交
79
 */
X
Xiaoyu Wang 已提交
80
void dsGetDataLength(DataSinkHandle handle, int32_t* pLen, bool* pQueryEnd);
X
Xiaoyu Wang 已提交
81 82 83 84

/**
 * Get data, the caller needs to allocate data memory.
 * @param handle
85 86
 * @param pOutput output
 * @param pStatus output
X
Xiaoyu Wang 已提交
87 88
 * @return error code
 */
X
Xiaoyu Wang 已提交
89
int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput);
X
Xiaoyu Wang 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

/**
 * After dsGetStatus returns DS_NEED_SCHEDULE, the caller need to put this into the work queue.
 * @param ahandle
 * @param pItem
 */
void dsScheduleProcess(void* ahandle, void* pItem);

/**
 * Destroy the datasinker handle.
 * @param handle
 */
void dsDestroyDataSinker(DataSinkHandle handle);

#ifdef __cplusplus
}
#endif

#endif /*_DATA_SINK_MGT_H*/