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 24 25 26 27 28
/*
 * 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"
#include "executorimpl.h"

#define DS_CAPACITY_ENOUGH 1
#define DS_CAPACITY_FULL   2
#define DS_NEED_SCHEDULE   3
29 30
#define DS_END             4
#define DS_IN_PROCESS      5
X
Xiaoyu Wang 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43

struct SDataSink;
struct SSDataBlock;

typedef struct SDataSinkMgtCfg {
  uint32_t maxDataBlockNum;
  uint32_t maxDataBlockNumPerQuery;
} SDataSinkMgtCfg;

int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg);

typedef void* DataSinkHandle;

44
typedef struct SInputData {
X
Xiaoyu Wang 已提交
45 46
  const SSDataBlock* pData;
  SHashObj* pTableRetrieveTsMap;
47 48 49 50 51 52 53
} SInputData;

typedef struct SOutPutData {
  int32_t numOfRows;
  int8_t  compressed;
  char*   pData;
} SOutPutData;
X
Xiaoyu Wang 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

/**
 * 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
 */
69 70 71
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, int32_t* pStatus);

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

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

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

/**
 * 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*/