tcommon.h 6.9 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16 17
#ifndef _TD_COMMON_DEF_H_
#define _TD_COMMON_DEF_H_
H
Haojun Liao 已提交
18

H
Haojun Liao 已提交
19
#include "taosdef.h"
H
Haojun Liao 已提交
20
#include "tarray.h"
L
Liu Jicong 已提交
21
#include "tmsg.h"
22
#include "tvariant.h"
S
Shengliang Guan 已提交
23 24 25 26 27

#ifdef __cplusplus
extern "C" {
#endif

L
Liu Jicong 已提交
28
// TODO remove it
L
Liu Jicong 已提交
29 30
enum {
  TMQ_CONF__RESET_OFFSET__NONE = -3,
L
Liu Jicong 已提交
31 32
  TMQ_CONF__RESET_OFFSET__EARLIEAST = -2,
  TMQ_CONF__RESET_OFFSET__LATEST = -1,
L
Liu Jicong 已提交
33
};
L
Liu Jicong 已提交
34

L
Liu Jicong 已提交
35
enum {
L
Liu Jicong 已提交
36 37
  TMQ_MSG_TYPE__DUMMY = 0,
  TMQ_MSG_TYPE__POLL_RSP,
L
Liu Jicong 已提交
38
  TMQ_MSG_TYPE__POLL_META_RSP,
L
Liu Jicong 已提交
39
  TMQ_MSG_TYPE__EP_RSP,
L
Liu Jicong 已提交
40
  TMQ_MSG_TYPE__END_RSP,
L
Liu Jicong 已提交
41 42
};

L
Liu Jicong 已提交
43 44 45 46 47 48 49 50 51 52
enum {
  STREAM_INPUT__DATA_SUBMIT = 1,
  STREAM_INPUT__DATA_BLOCK,
  STREAM_INPUT__DATA_SCAN,
  STREAM_INPUT__DATA_RETRIEVE,
  STREAM_INPUT__TRIGGER,
  STREAM_INPUT__CHECKPOINT,
  STREAM_INPUT__DROP,
};

5
54liuyao 已提交
53 54 55
typedef enum EStreamType {
  STREAM_NORMAL = 1,
  STREAM_INVERT,
5
54liuyao 已提交
56
  STREAM_CLEAR,
5
54liuyao 已提交
57
  STREAM_INVALID,
5
54liuyao 已提交
58
  STREAM_GET_ALL,
59 60
  STREAM_DELETE_RESULT,
  STREAM_DELETE_DATA,
L
Liu Jicong 已提交
61
  STREAM_RETRIEVE,
L
Liu Jicong 已提交
62 63
  STREAM_PULL_DATA,
  STREAM_PULL_OVER,
5
54liuyao 已提交
64 65
} EStreamType;

66
typedef struct {
wmmhello's avatar
wmmhello 已提交
67
  SArray*   pGroupList;
wmmhello's avatar
wmmhello 已提交
68
  SArray*   pTableList;
L
Liu Jicong 已提交
69
  SHashObj* map;  // speedup acquire the tableQueryInfo by table uid
70
  bool      needSortTableByGroupId;
wmmhello's avatar
wmmhello 已提交
71 72
  void*     pTagCond;
  void*     pTagIndexCond;
D
dapan1121 已提交
73
  uint64_t  suid;
wmmhello's avatar
wmmhello 已提交
74
} STableListInfo;
75

H
Hongze Cheng 已提交
76
#pragma pack(push, 1)
77 78 79
typedef struct SColumnDataAgg {
  int16_t colId;
  int16_t minIndex;
H
Hongze Cheng 已提交
80
  int16_t maxIndex;
81
  int16_t numOfNull;
82 83 84
  int64_t sum;
  int64_t max;
  int64_t min;
85
} SColumnDataAgg;
H
Hongze Cheng 已提交
86
#pragma pack(pop)
87 88

typedef struct SDataBlockInfo {
L
fix  
Liu Jicong 已提交
89
  STimeWindow window;
90
  int32_t     rows;  // todo hide this attribute
L
fix  
Liu Jicong 已提交
91
  int32_t     rowSize;
92
  uint64_t    uid;      // the uid of table, from which current data block comes
93
  uint16_t    blockId;  // block id, generated by physical planner
94 95
  uint64_t    groupId;  // no need to serialize
  int16_t     hasVarCol;
96
  uint32_t    capacity;
L
Liu Jicong 已提交
97 98 99
  // TODO: optimize and remove following
  int32_t     childId;  // used for stream, do not serialize
  EStreamType type;     // used for stream, do not serialize
100 101 102
} SDataBlockInfo;

typedef struct SSDataBlock {
103 104 105
  SColumnDataAgg** pBlockAgg;
  SArray*          pDataBlock;  // SArray<SColumnInfoData>
  SDataBlockInfo   info;
106 107
} SSDataBlock;

H
Haojun Liao 已提交
108
typedef struct SVarColAttr {
L
Liu Jicong 已提交
109
  int32_t* offset;    // start position for each entry in the list
H
Haojun Liao 已提交
110 111 112 113
  uint32_t length;    // used buffer size that contain the valid data
  uint32_t allocLen;  // allocated buffer size
} SVarColAttr;

114 115
// pBlockAgg->numOfNull == info.rows, all data are null
// pBlockAgg->numOfNull == 0, no data are null.
116
typedef struct SColumnInfoData {
117
  SColumnInfo info;     // column info
L
Liu Jicong 已提交
118 119
  bool        hasNull;  // if current column data has null value.
  char*       pData;    // the corresponding block data in memory
H
Haojun Liao 已提交
120
  union {
L
Liu Jicong 已提交
121
    char*       nullbitmap;  // bitmap, one bit for each item in the list
H
Haojun Liao 已提交
122 123
    SVarColAttr varmeta;
  };
124 125
} SColumnInfoData;

126
typedef struct SQueryTableDataCond {
H
more  
Hongze Cheng 已提交
127
  uint64_t     suid;
128 129
  int32_t      order;  // desc|asc order to iterate the data block
  int32_t      numOfCols;
H
more  
Hongze Cheng 已提交
130
  SColumnInfo* colList;
H
Hongze Cheng 已提交
131
  int32_t      type;  // data block load type:
132
  int32_t      numOfTWindows;
H
more  
Hongze Cheng 已提交
133
  STimeWindow* twindows;
L
Liu Jicong 已提交
134 135
  int64_t      startVersion;
  int64_t      endVersion;
136 137
} SQueryTableDataCond;

H
Haojun Liao 已提交
138 139 140
void*   blockDataDestroy(SSDataBlock* pBlock);
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
void*   tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
H
Haojun Liao 已提交
141

L
Liu Jicong 已提交
142
int32_t tEncodeDataBlocks(void** buf, const SArray* blocks);
L
Liu Jicong 已提交
143
void*   tDecodeDataBlocks(const void* buf, SArray** blocks);
L
fix  
Liu Jicong 已提交
144
void    colDataDestroy(SColumnInfoData* pColData);
L
Liu Jicong 已提交
145

L
Liu Jicong 已提交
146 147 148 149
static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) {
  int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock);
  for (int32_t i = 0; i < numOfOutput; ++i) {
    SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
150
    colDataDestroy(pColInfoData);
L
Liu Jicong 已提交
151
  }
L
Liu Jicong 已提交
152 153

  taosArrayDestroy(pBlock->pDataBlock);
wafwerar's avatar
wafwerar 已提交
154
  taosMemoryFreeClear(pBlock->pBlockAgg);
L
Liu Jicong 已提交
155 156
}

L
Liu Jicong 已提交
157 158
static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) { blockDestroyInner(pBlock); }

159 160
//======================================================================================================================
// the following structure shared by parser and executor
161
typedef struct SColumn {
H
Haojun Liao 已提交
162 163 164 165 166
  union {
    uint64_t uid;
    int64_t  dataBlockId;
  };

H
Haojun Liao 已提交
167 168
  int16_t colId;
  int16_t slotId;
H
Haojun Liao 已提交
169

H
Haojun Liao 已提交
170 171
  char    name[TSDB_COL_NAME_LEN];
  int8_t  flag;  // column type: normal column, tag, or user-input column (integer/float/string)
H
Haojun Liao 已提交
172 173 174 175
  int16_t type;
  int32_t bytes;
  uint8_t precision;
  uint8_t scale;
176 177
} SColumn;

H
Haojun Liao 已提交
178
typedef struct STableBlockDistInfo {
179
  uint32_t rowSize;
L
Liu Jicong 已提交
180 181
  uint16_t numOfFiles;
  uint32_t numOfTables;
182
  uint32_t numOfBlocks;
L
Liu Jicong 已提交
183 184 185 186
  uint64_t totalSize;
  uint64_t totalRows;
  int32_t  maxRows;
  int32_t  minRows;
187 188
  int32_t  defMinRows;
  int32_t  defMaxRows;
L
Liu Jicong 已提交
189
  int32_t  firstSeekTimeUs;
190
  uint32_t numOfInmemRows;
L
Liu Jicong 已提交
191
  uint32_t numOfSmallBlocks;
192
  int32_t  blockRowsHisto[20];
H
Haojun Liao 已提交
193
} STableBlockDistInfo;
194

195 196 197
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo);
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);

G
Ganlin Zhao 已提交
198
enum {
H
Haojun Liao 已提交
199
  FUNC_PARAM_TYPE_VALUE = 0x1,
L
Liu Jicong 已提交
200
  FUNC_PARAM_TYPE_COLUMN = 0x2,
G
Ganlin Zhao 已提交
201 202
};

H
Haojun Liao 已提交
203 204
typedef struct SFunctParam {
  int32_t  type;
L
Liu Jicong 已提交
205
  SColumn* pCol;
H
Haojun Liao 已提交
206 207
  SVariant param;
} SFunctParam;
H
Haojun Liao 已提交
208

H
Haojun Liao 已提交
209
// the structure for sql function in select clause
H
Haojun Liao 已提交
210 211
typedef struct SResSchame {
  int8_t  type;
212
  int32_t slotId;
H
Haojun Liao 已提交
213 214 215 216 217 218
  int32_t bytes;
  int32_t precision;
  int32_t scale;
  char    name[TSDB_COL_NAME_LEN];
} SResSchema;

H
Haojun Liao 已提交
219
typedef struct SExprBasicInfo {
H
Haojun Liao 已提交
220
  SResSchema   resSchema;
H
Haojun Liao 已提交
221
  int16_t      numOfParams;  // argument value of each function
L
Liu Jicong 已提交
222
  SFunctParam* pParam;
H
Haojun Liao 已提交
223
} SExprBasicInfo;
224 225

typedef struct SExprInfo {
L
Liu Jicong 已提交
226 227
  struct SExprBasicInfo base;
  struct tExprNode*     pExpr;
228 229
} SExprInfo;

wmmhello's avatar
wmmhello 已提交
230
typedef struct {
H
more  
Hongze Cheng 已提交
231 232 233 234
  const char* key;
  int32_t     keyLen;
  uint8_t     type;
  union {
wmmhello's avatar
wmmhello 已提交
235
    const char* value;
wmmhello's avatar
wmmhello 已提交
236 237 238 239
    int64_t     i;
    uint64_t    u;
    double      d;
    float       f;
wmmhello's avatar
wmmhello 已提交
240
  };
H
more  
Hongze Cheng 已提交
241
  int32_t length;
wmmhello's avatar
wmmhello 已提交
242 243
} SSmlKv;

L
Liu Jicong 已提交
244
#define QUERY_ASC_FORWARD_STEP  1
245 246 247 248
#define QUERY_DESC_FORWARD_STEP -1

#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)

H
more  
Hongze Cheng 已提交
249
#define SORT_QSORT_T              0x1
250 251 252 253 254 255 256 257 258
#define SORT_SPILLED_MERGE_SORT_T 0x2
typedef struct SSortExecInfo {
  int32_t sortMethod;
  int32_t sortBuffer;
  int32_t loops;       // loop count
  int32_t writeBytes;  // write io bytes
  int32_t readBytes;   // read io bytes
} SSortExecInfo;

H
Haojun Liao 已提交
259 260 261 262
#ifdef __cplusplus
}
#endif

L
Liu Jicong 已提交
263
#endif /*_TD_COMMON_DEF_H_*/