tcommon.h 6.5 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 29 30 31 32
enum {
  TMQ_CONF__RESET_OFFSET__LATEST = -1,
  TMQ_CONF__RESET_OFFSET__EARLIEAST = -2,
  TMQ_CONF__RESET_OFFSET__NONE = -3,
};
L
Liu Jicong 已提交
33

L
Liu Jicong 已提交
34
enum {
L
Liu Jicong 已提交
35 36
  TMQ_MSG_TYPE__DUMMY = 0,
  TMQ_MSG_TYPE__POLL_RSP,
L
Liu Jicong 已提交
37 38 39
  TMQ_MSG_TYPE__EP_RSP,
};

5
54liuyao 已提交
40 41 42
typedef enum EStreamType {
  STREAM_NORMAL = 1,
  STREAM_INVERT,
5
54liuyao 已提交
43
  STREAM_REPROCESS,
5
54liuyao 已提交
44
  STREAM_INVALID,
5
54liuyao 已提交
45
  STREAM_GET_ALL,
5
54liuyao 已提交
46 47
} EStreamType;

48
typedef struct {
wmmhello's avatar
wmmhello 已提交
49
  SArray*   pTableList;
L
Liu Jicong 已提交
50
  SHashObj* map;  // speedup acquire the tableQueryInfo by table uid
wmmhello's avatar
wmmhello 已提交
51
} STableListInfo;
52

53 54 55 56 57
typedef struct SColumnDataAgg {
  int16_t colId;
  int16_t maxIndex;
  int16_t minIndex;
  int16_t numOfNull;
58 59 60
  int64_t sum;
  int64_t max;
  int64_t min;
61 62 63
} SColumnDataAgg;

typedef struct SDataBlockInfo {
L
fix  
Liu Jicong 已提交
64 65 66
  STimeWindow window;
  int32_t     rows;
  int32_t     rowSize;
67 68 69 70 71
  int64_t     uid;      // the uid of table, from which current data block comes
  int64_t     blockId;  // block id, generated by physical planner
  uint64_t    groupId;  // no need to serialize
  int16_t     numOfCols;
  int16_t     hasVarCol;
72
  int32_t     capacity;
L
Liu Jicong 已提交
73 74 75
  // TODO: optimize and remove following
  int32_t     childId;  // used for stream, do not serialize
  EStreamType type;     // used for stream, do not serialize
76 77 78
} SDataBlockInfo;

typedef struct SSDataBlock {
79 80 81
  SColumnDataAgg** pBlockAgg;
  SArray*          pDataBlock;  // SArray<SColumnInfoData>
  SDataBlockInfo   info;
82 83
} SSDataBlock;

H
Haojun Liao 已提交
84
typedef struct SVarColAttr {
L
Liu Jicong 已提交
85
  int32_t* offset;    // start position for each entry in the list
H
Haojun Liao 已提交
86 87 88 89
  uint32_t length;    // used buffer size that contain the valid data
  uint32_t allocLen;  // allocated buffer size
} SVarColAttr;

90 91
// pBlockAgg->numOfNull == info.rows, all data are null
// pBlockAgg->numOfNull == 0, no data are null.
92
typedef struct SColumnInfoData {
L
Liu Jicong 已提交
93 94 95
  SColumnInfo info;     // TODO filter info needs to be removed
  bool        hasNull;  // if current column data has null value.
  char*       pData;    // the corresponding block data in memory
H
Haojun Liao 已提交
96
  union {
L
Liu Jicong 已提交
97
    char*       nullbitmap;  // bitmap, one bit for each item in the list
H
Haojun Liao 已提交
98 99
    SVarColAttr varmeta;
  };
100 101
} SColumnInfoData;

102
typedef struct SQueryTableDataCond {
H
more  
Hongze Cheng 已提交
103 104
  // STimeWindow  twindow;
  uint64_t     suid;
105 106
  int32_t      order;  // desc|asc order to iterate the data block
  int32_t      numOfCols;
H
more  
Hongze Cheng 已提交
107
  SColumnInfo* colList;
108 109
  bool         loadExternalRows;  // load external rows or not
  int32_t      type;              // data block load type:
110
  int32_t      numOfTWindows;
H
more  
Hongze Cheng 已提交
111
  STimeWindow* twindows;
H
Hongze Cheng 已提交
112 113
  int64_t      startVersion;
  int64_t      endVersion;
114 115
} SQueryTableDataCond;

H
Haojun Liao 已提交
116 117 118
void*   blockDataDestroy(SSDataBlock* pBlock);
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
void*   tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
H
Haojun Liao 已提交
119

L
Liu Jicong 已提交
120
int32_t tEncodeDataBlocks(void** buf, const SArray* blocks);
L
Liu Jicong 已提交
121
void*   tDecodeDataBlocks(const void* buf, SArray** blocks);
L
fix  
Liu Jicong 已提交
122
void    colDataDestroy(SColumnInfoData* pColData);
L
Liu Jicong 已提交
123

L
Liu Jicong 已提交
124 125 126 127
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);
128
    colDataDestroy(pColInfoData);
L
Liu Jicong 已提交
129
  }
L
Liu Jicong 已提交
130 131

  taosArrayDestroy(pBlock->pDataBlock);
wafwerar's avatar
wafwerar 已提交
132
  taosMemoryFreeClear(pBlock->pBlockAgg);
L
Liu Jicong 已提交
133 134
}

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

137 138
//======================================================================================================================
// the following structure shared by parser and executor
139
typedef struct SColumn {
H
Haojun Liao 已提交
140 141 142 143 144
  union {
    uint64_t uid;
    int64_t  dataBlockId;
  };

H
Haojun Liao 已提交
145 146
  int16_t colId;
  int16_t slotId;
H
Haojun Liao 已提交
147

H
Haojun Liao 已提交
148 149
  char    name[TSDB_COL_NAME_LEN];
  int8_t  flag;  // column type: normal column, tag, or user-input column (integer/float/string)
H
Haojun Liao 已提交
150 151 152 153
  int16_t type;
  int32_t bytes;
  uint8_t precision;
  uint8_t scale;
154 155
} SColumn;

H
Haojun Liao 已提交
156
typedef struct STableBlockDistInfo {
157
  uint32_t rowSize;
L
Liu Jicong 已提交
158 159
  uint16_t numOfFiles;
  uint32_t numOfTables;
160
  uint32_t numOfBlocks;
L
Liu Jicong 已提交
161 162 163 164
  uint64_t totalSize;
  uint64_t totalRows;
  int32_t  maxRows;
  int32_t  minRows;
165 166
  int32_t  defMinRows;
  int32_t  defMaxRows;
L
Liu Jicong 已提交
167
  int32_t  firstSeekTimeUs;
168
  uint32_t numOfInmemRows;
L
Liu Jicong 已提交
169
  uint32_t numOfSmallBlocks;
170
  int32_t  blockRowsHisto[20];
H
Haojun Liao 已提交
171
} STableBlockDistInfo;
172

173 174 175
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo);
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);

G
Ganlin Zhao 已提交
176
enum {
H
Haojun Liao 已提交
177
  FUNC_PARAM_TYPE_VALUE = 0x1,
L
Liu Jicong 已提交
178
  FUNC_PARAM_TYPE_COLUMN = 0x2,
G
Ganlin Zhao 已提交
179 180
};

H
Haojun Liao 已提交
181 182
typedef struct SFunctParam {
  int32_t  type;
L
Liu Jicong 已提交
183
  SColumn* pCol;
H
Haojun Liao 已提交
184 185
  SVariant param;
} SFunctParam;
H
Haojun Liao 已提交
186

H
Haojun Liao 已提交
187
// the structure for sql function in select clause
H
Haojun Liao 已提交
188 189
typedef struct SResSchame {
  int8_t  type;
190
  int32_t slotId;
H
Haojun Liao 已提交
191 192 193 194 195 196
  int32_t bytes;
  int32_t precision;
  int32_t scale;
  char    name[TSDB_COL_NAME_LEN];
} SResSchema;

H
Haojun Liao 已提交
197
typedef struct SExprBasicInfo {
H
Haojun Liao 已提交
198
  SResSchema   resSchema;
H
Haojun Liao 已提交
199
  int16_t      numOfParams;  // argument value of each function
L
Liu Jicong 已提交
200
  SFunctParam* pParam;
H
Haojun Liao 已提交
201
} SExprBasicInfo;
202 203

typedef struct SExprInfo {
L
Liu Jicong 已提交
204 205
  struct SExprBasicInfo base;
  struct tExprNode*     pExpr;
206 207
} SExprInfo;

wmmhello's avatar
wmmhello 已提交
208
typedef struct {
H
more  
Hongze Cheng 已提交
209 210 211 212
  const char* key;
  int32_t     keyLen;
  uint8_t     type;
  union {
wmmhello's avatar
wmmhello 已提交
213
    const char* value;
wmmhello's avatar
wmmhello 已提交
214 215 216 217
    int64_t     i;
    uint64_t    u;
    double      d;
    float       f;
wmmhello's avatar
wmmhello 已提交
218
  };
H
more  
Hongze Cheng 已提交
219
  int32_t length;
wmmhello's avatar
wmmhello 已提交
220 221
} SSmlKv;

L
Liu Jicong 已提交
222
#define QUERY_ASC_FORWARD_STEP  1
223 224 225 226
#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 已提交
227
#define SORT_QSORT_T              0x1
228 229 230 231 232 233 234 235 236
#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 已提交
237 238 239 240
#ifdef __cplusplus
}
#endif

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