dataSinkMgt.h 3.2 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
/*
 * 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

D
dapan1121 已提交
23
#include "executor.h"
H
Hongze Cheng 已提交
24
#include "os.h"
X
Xiaoyu Wang 已提交
25
#include "plannodes.h"
H
Hongze Cheng 已提交
26
#include "thash.h"
X
Xiaoyu Wang 已提交
27

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

struct SDataSink;
struct SSDataBlock;

D
dapan1121 已提交
35
typedef struct SDeleterRes {
D
dapan1121 已提交
36
  uint64_t suid;
D
dapan1121 已提交
37 38 39 40
  SArray*  uidList;
  int64_t  skey;
  int64_t  ekey;
  int64_t  affectedRows;
41 42
  char     tableName[TSDB_TABLE_NAME_LEN];
  char     tsColName[TSDB_COL_NAME_LEN];
D
dapan1121 已提交
43 44 45
} SDeleterRes;

typedef struct SDeleterParam {
D
dapan1121 已提交
46 47
  uint64_t suid;
  SArray*  pUidList;
D
dapan1121 已提交
48 49
} SDeleterParam;

D
dapan1121 已提交
50 51 52 53
typedef struct SInserterParam {
  SReadHandle* readHandle;
} SInserterParam;

D
dapan1121 已提交
54 55 56 57
typedef struct SDataSinkStat {
  uint64_t cachedSize;
} SDataSinkStat;

X
Xiaoyu Wang 已提交
58
typedef struct SDataSinkMgtCfg {
H
Hongze Cheng 已提交
59
  uint32_t maxDataBlockNum;  // todo: this should be numOfRows?
X
Xiaoyu Wang 已提交
60 61 62
  uint32_t maxDataBlockNumPerQuery;
} SDataSinkMgtCfg;

H
Hongze Cheng 已提交
63
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg);
X
Xiaoyu Wang 已提交
64

65
typedef struct SInputData {
X
Xiaoyu Wang 已提交
66
  const struct SSDataBlock* pData;
67 68
} SInputData;

X
Xiaoyu Wang 已提交
69
typedef struct SOutputData {
70
  int32_t numOfBlocks;
71
  int32_t numOfRows;
72
  int32_t numOfCols;
73 74
  int8_t  compressed;
  char*   pData;
X
Xiaoyu Wang 已提交
75 76 77 78 79
  bool    queryEnd;
  int32_t bufStatus;
  int64_t useconds;
  int8_t  precision;
} SOutputData;
X
Xiaoyu Wang 已提交
80 81

/**
H
Hongze Cheng 已提交
82
 * Create a subplan's datasinker handle for all later operations.
X
Xiaoyu Wang 已提交
83 84 85 86
 * @param pDataSink
 * @param pHandle output
 * @return error code
 */
H
Haojun Liao 已提交
87
int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id);
X
Xiaoyu Wang 已提交
88

H
Hongze Cheng 已提交
89
int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat);
D
dapan1121 已提交
90

X
Xiaoyu Wang 已提交
91 92 93 94 95 96
/**
 * Put the result set returned by the executor into datasinker.
 * @param handle
 * @param pRes
 * @return error code
 */
X
Xiaoyu Wang 已提交
97
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue);
98

D
dapan1121 已提交
99
void dsEndPut(DataSinkHandle handle, uint64_t useconds);
X
Xiaoyu Wang 已提交
100 101 102 103

/**
 * Get the length of the data returned by the next call to dsGetDataBlock.
 * @param handle
X
Xiaoyu Wang 已提交
104
 * @param pLen data length
X
Xiaoyu Wang 已提交
105
 */
D
dapan1121 已提交
106
void dsGetDataLength(DataSinkHandle handle, int64_t* pLen, bool* pQueryEnd);
X
Xiaoyu Wang 已提交
107 108 109 110

/**
 * Get data, the caller needs to allocate data memory.
 * @param handle
111 112
 * @param pOutput output
 * @param pStatus output
X
Xiaoyu Wang 已提交
113 114
 * @return error code
 */
X
Xiaoyu Wang 已提交
115
int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput);
X
Xiaoyu Wang 已提交
116

H
Hongze Cheng 已提交
117
int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t* pSize);
D
dapan1121 已提交
118

X
Xiaoyu Wang 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/**
 * 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*/