taosdef.h 12.7 KB
Newer Older
H
hzcheng 已提交
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
#1177  
slguan 已提交
16 17
#ifndef TDENGINE_TAOS_DEF_H
#define TDENGINE_TAOS_DEF_H
H
hzcheng 已提交
18 19 20 21 22 23

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
H
hzcheng 已提交
24
#include <stdbool.h>
H
hzcheng 已提交
25
#include "taos.h"
H
hzcheng 已提交
26 27 28 29 30 31 32 33 34

#define TSDB__packed

#ifdef TSKEY32
#define TSKEY int32_t;
#else
#define TSKEY int64_t
#endif

H
TD-166  
hzcheng 已提交
35 36 37 38 39 40 41
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
typedef int32_t VarDataOffsetT;
typedef int16_t VarDataLenT;
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
#define varDataVal(v) ((void *)((char *)v + sizeof(VarDataLenT)))

42 43
// this data type is internally used only in 'in' query to hold the values
#define TSDB_DATA_TYPE_ARRAY      (TSDB_DATA_TYPE_NCHAR + 1)
weixin_48148422's avatar
weixin_48148422 已提交
44

H
hzcheng 已提交
45
// Bytes for each type.
H
hzcheng 已提交
46 47
extern const int32_t TYPE_BYTES[11];
// TODO: replace and remove code below
H
hzcheng 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#define CHAR_BYTES   sizeof(char)
#define SHORT_BYTES  sizeof(short)
#define INT_BYTES    sizeof(int)
#define LONG_BYTES   sizeof(int64_t)
#define FLOAT_BYTES  sizeof(float)
#define DOUBLE_BYTES sizeof(double)

// NULL definition
#define TSDB_DATA_BOOL_NULL             0x02
#define TSDB_DATA_TINYINT_NULL          0x80
#define TSDB_DATA_SMALLINT_NULL         0x8000
#define TSDB_DATA_INT_NULL              0x80000000
#define TSDB_DATA_BIGINT_NULL           0x8000000000000000L

#define TSDB_DATA_FLOAT_NULL            0x7FF00000              // it is an NAN
#define TSDB_DATA_DOUBLE_NULL           0x7FFFFF0000000000L     // an NAN
#define TSDB_DATA_NCHAR_NULL            0xFFFFFFFF
#define TSDB_DATA_BINARY_NULL           0xFF

#define TSDB_DATA_NULL_STR              "NULL"
#define TSDB_DATA_NULL_STR_L            "null"

S
slguan 已提交
70 71 72 73
#define TSDB_TRUE 1
#define TSDB_FALSE 0
#define TSDB_OK 0
#define TSDB_ERR -1
H
hzcheng 已提交
74 75 76 77 78 79 80 81 82

#define TS_PATH_DELIMITER "."

#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1

#define TSDB_TIME_PRECISION_MILLI_STR "ms"
#define TSDB_TIME_PRECISION_MICRO_STR "us"

H
TD-27  
hzcheng 已提交
83 84 85 86 87 88 89 90 91 92 93
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#define T_APPEND_MEMBER(dst, ptr, type, member) \
do {\
  memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member));\
  dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member));\
} while(0)
#define T_READ_MEMBER(src, type, target) \
do { \
  (target) = *(type *)(src); \
  (src) = (void *)((char *)src + sizeof(type));\
} while(0)
H
hzcheng 已提交
94 95

#define TSDB_KEYSIZE              sizeof(TSKEY)
S
slguan 已提交
96

S
slguan 已提交
97 98 99 100 101
#if LINUX
  #define TSDB_NCHAR_SIZE         sizeof(wchar_t)
#else
  #define TSDB_NCHAR_SIZE         4
#endif
S
slguan 已提交
102
//#define TSDB_CHAR_TERMINATED_SPACE 1
H
hzcheng 已提交
103

H
hzcheng 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
#define GET_INT8_VAL(x)   (*(int8_t *)(x))
#define GET_INT16_VAL(x)  (*(int16_t *)(x))
#define GET_INT32_VAL(x)  (*(int32_t *)(x))
#define GET_INT64_VAL(x)  (*(int64_t *)(x))
#ifdef _TD_ARM_32_
  #define GET_FLOAT_VAL(x)  taos_align_get_float(x)
  #define GET_DOUBLE_VAL(x) taos_align_get_double(x)

  float  taos_align_get_float(const char* pBuf);
  double taos_align_get_double(const char* pBuf);

  //#define __float_align_declear()  float __underlyFloat = 0.0;
  //#define __float_align_declear()
  //#define GET_FLOAT_VAL_ALIGN(x) (*(int32_t*)&(__underlyFloat) = *(int32_t*)(x); __underlyFloat);
  // notes: src must be float or double type variable !!!
  #define SET_FLOAT_VAL_ALIGN(dst, src) (*(int32_t*) dst = *(int32_t*)src);
  #define SET_DOUBLE_VAL_ALIGN(dst, src) (*(int64_t*) dst = *(int64_t*)src);
#else
  #define GET_FLOAT_VAL(x)  (*(float *)(x))
  #define GET_DOUBLE_VAL(x) (*(double *)(x))
#endif

typedef struct tDataTypeDescriptor {
  int16_t nType;
  int16_t nameLen;
  int32_t nSize;
  char *  aName;
H
TD-166  
hzcheng 已提交
131 132 133 134
  int (*compFunc)(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
                  char algorithm, char *const buffer, int bufferSize);
  int (*decompFunc)(const char *const input, int compressedSize, const int nelements, char *const output,
                    int outputSize, char algorithm, char *const buffer, int bufferSize);
H
hzcheng 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
} tDataTypeDescriptor;

extern tDataTypeDescriptor tDataTypeDesc[11];
#define POINTER_BYTES sizeof(void *)  // 8 by default  assert(sizeof(ptrdiff_t) == sizseof(void*)

bool isValidDataType(int32_t type, int32_t length);
bool isNull(const char *val, int32_t type);

void setNull(char *val, int32_t type, int32_t bytes);
void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems);

void assignVal(char *val, const char *src, int32_t len, int32_t type);
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);

// TODO: check if below is necessary
150
#define TSDB_RELATION_INVALID     0
H
hzcheng 已提交
151
#define TSDB_RELATION_LESS        1
152
#define TSDB_RELATION_GREATER     2
H
hzcheng 已提交
153 154
#define TSDB_RELATION_EQUAL       3
#define TSDB_RELATION_LESS_EQUAL  4
155
#define TSDB_RELATION_GREATER_EQUAL 5
H
hzcheng 已提交
156 157
#define TSDB_RELATION_NOT_EQUAL   6
#define TSDB_RELATION_LIKE        7
weixin_48148422's avatar
weixin_48148422 已提交
158
#define TSDB_RELATION_IN          8
H
hzcheng 已提交
159

weixin_48148422's avatar
weixin_48148422 已提交
160 161 162
#define TSDB_RELATION_AND         9
#define TSDB_RELATION_OR          10
#define TSDB_RELATION_NOT         11
H
hzcheng 已提交
163

weixin_48148422's avatar
weixin_48148422 已提交
164 165 166 167 168
#define TSDB_BINARY_OP_ADD        12
#define TSDB_BINARY_OP_SUBTRACT   13
#define TSDB_BINARY_OP_MULTIPLY   14
#define TSDB_BINARY_OP_DIVIDE     15
#define TSDB_BINARY_OP_REMAINDER  16
H
hzcheng 已提交
169 170 171
#define TSDB_USERID_LEN           9
#define TS_PATH_DELIMITER_LEN     1

S
slguan 已提交
172
#define TSDB_METER_ID_LEN_MARGIN  10
S
slguan 已提交
173
#define TSDB_TABLE_ID_LEN         (TSDB_DB_NAME_LEN+TSDB_TABLE_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_TABLE_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID)
H
hzcheng 已提交
174 175 176 177 178 179
#define TSDB_UNI_LEN              24
#define TSDB_USER_LEN             TSDB_UNI_LEN
#define TSDB_ACCT_LEN             TSDB_UNI_LEN
#define TSDB_PASSWORD_LEN         TSDB_UNI_LEN

#define TSDB_MAX_COLUMNS          256
S
slguan 已提交
180
#define TSDB_MIN_COLUMNS          2       //PRIMARY COLUMN(timestamp) + other columns
H
hzcheng 已提交
181

S
slguan 已提交
182
#define TSDB_NODE_NAME_LEN        64
H
hjxilinx 已提交
183
#define TSDB_TABLE_NAME_LEN       192
H
hzcheng 已提交
184 185
#define TSDB_DB_NAME_LEN          32
#define TSDB_COL_NAME_LEN         64
S
slguan 已提交
186 187
#define TSDB_MAX_SAVED_SQL_LEN    TSDB_MAX_COLUMNS * 16
#define TSDB_MAX_SQL_LEN          TSDB_PAYLOAD_SIZE
H
hjxilinx 已提交
188
#define TSDB_MAX_ALLOWED_SQL_LEN  (8*1024*1024U)          // sql length should be less than 6mb
H
hzcheng 已提交
189

S
slguan 已提交
190
#define TSDB_MAX_BYTES_PER_ROW    TSDB_MAX_COLUMNS * 16
H
hzcheng 已提交
191
#define TSDB_MAX_TAGS_LEN         512
S
slguan 已提交
192
#define TSDB_MAX_TAGS             32
H
hzcheng 已提交
193 194 195 196 197 198 199 200 201 202 203

#define TSDB_AUTH_LEN             16
#define TSDB_KEY_LEN              16
#define TSDB_VERSION_LEN          12
#define TSDB_STREET_LEN           64
#define TSDB_CITY_LEN             20
#define TSDB_STATE_LEN            20
#define TSDB_COUNTRY_LEN          20
#define TSDB_LOCALE_LEN           64
#define TSDB_TIMEZONE_LEN         64

S
slguan 已提交
204
#define TSDB_FQDN_LEN             72
S
slguan 已提交
205
#define TSDB_IPv4ADDR_LEN      	  16
H
hzcheng 已提交
206 207 208 209 210 211 212 213 214 215 216
#define TSDB_FILENAME_LEN         128
#define TSDB_METER_VNODE_BITS     20
#define TSDB_METER_SID_MASK       0xFFFFF
#define TSDB_SHELL_VNODE_BITS     24
#define TSDB_SHELL_SID_MASK       0xFF
#define TSDB_HTTP_TOKEN_LEN       20
#define TSDB_SHOW_SQL_LEN         32

#define TSDB_METER_STATE_OFFLINE  0
#define TSDB_METER_STATE_ONLLINE  1

S
slguan 已提交
217
#define TSDB_DEFAULT_PKT_SIZE     65480  //same as RPC_MAX_UDP_SIZE
H
hzcheng 已提交
218

S
slguan 已提交
219 220 221
#define TSDB_PAYLOAD_SIZE         (TSDB_DEFAULT_PKT_SIZE - 100)
#define TSDB_DEFAULT_PAYLOAD_SIZE 1024   // default payload size
#define TSDB_EXTRA_PAYLOAD_SIZE   128    // extra bytes for auth
H
hzcheng 已提交
222 223 224 225 226 227 228 229 230
#define TSDB_SQLCMD_SIZE          1024
#define TSDB_MAX_VNODES           256
#define TSDB_MIN_VNODES           50
#define TSDB_INVALID_VNODE_NUM    0

#define TSDB_DNODE_ROLE_ANY       0
#define TSDB_DNODE_ROLE_MGMT      1
#define TSDB_DNODE_ROLE_VNODE     2

J
jtao1735 已提交
231
#define TSDB_MAX_REPLICA          5
S
slguan 已提交
232 233 234

#define TSDB_TBNAME_COLUMN_INDEX       (-1)
#define TSDB_MULTI_METERMETA_MAX_NUM    100000  // maximum batch size allowed to load metermeta
H
hzcheng 已提交
235

S
slguan 已提交
236 237 238
#define TSDB_MIN_CACHE_BLOCK_SIZE       1
#define TSDB_MAX_CACHE_BLOCK_SIZE       1000000
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE   16
H
hzcheng 已提交
239

S
slguan 已提交
240 241 242
#define TSDB_MIN_TOTAL_BLOCKS           2
#define TSDB_MAX_TOTAL_BLOCKS           10000
#define TSDB_DEFAULT_TOTAL_BLOCKS       2
H
hzcheng 已提交
243

S
slguan 已提交
244 245 246
#define TSDB_MIN_TABLES                 4
#define TSDB_MAX_TABLES                 200000
#define TSDB_DEFAULT_TABLES             1000
H
hzcheng 已提交
247

S
slguan 已提交
248 249 250
#define TSDB_MIN_DAYS_PER_FILE          1
#define TSDB_MAX_DAYS_PER_FILE          3650 
#define TSDB_DEFAULT_DAYS_PER_FILE      10 
H
hzcheng 已提交
251

S
slguan 已提交
252 253 254
#define TSDB_MIN_KEEP                   1        // data in db to be reserved.
#define TSDB_MAX_KEEP                   365000   // data in db to be reserved.
#define TSDB_DEFAULT_KEEP               3650     // ten years
H
hzcheng 已提交
255

S
slguan 已提交
256 257 258
#define TSDB_DEFAULT_MIN_ROW_FBLOCK     100
#define TSDB_MIN_MIN_ROW_FBLOCK         10
#define TSDB_MAX_MIN_ROW_FBLOCK         1000
H
hzcheng 已提交
259

S
slguan 已提交
260 261 262
#define TSDB_DEFAULT_MAX_ROW_FBLOCK     4096
#define TSDB_MIN_MAX_ROW_FBLOCK         200
#define TSDB_MAX_MAX_ROW_FBLOCK         10000
H
hzcheng 已提交
263

S
slguan 已提交
264 265 266
#define TSDB_MIN_COMMIT_TIME            30
#define TSDB_MAX_COMMIT_TIME            40960
#define TSDB_DEFAULT_COMMIT_TIME        3600
H
hzcheng 已提交
267

S
slguan 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
#define TSDB_MIN_PRECISION              TSDB_PRECISION_MILLI
#define TSDB_MAX_PRECISION              TSDB_PRECISION_NANO
#define TSDB_DEFAULT_PRECISION          TSDB_PRECISION_MILLI

#define TSDB_MIN_COMP_LEVEL             0
#define TSDB_MAX_COMP_LEVEL             2
#define TSDB_DEFAULT_COMP_LEVEL         2

#define TSDB_MIN_CLOG_LEVEL             0
#define TSDB_MAX_CLOG_LEVEL             2
#define TSDB_DEFAULT_CLOG_LEVEL         2

#define TSDB_MIN_REPLICA_NUM            1
#define TSDB_MAX_REPLICA_NUM            3
#define TSDB_DEFAULT_REPLICA_NUM        1
H
hzcheng 已提交
283

S
slguan 已提交
284
#define TSDB_MAX_JOIN_TABLE_NUM         5
285
#define TSDB_MAX_UNION_CLAUSE           5
H
hzcheng 已提交
286

S
slguan 已提交
287 288 289
#define TSDB_MAX_BINARY_LEN            (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_NCHAR_LEN             (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define PRIMARYKEY_TIMESTAMP_COL_INDEX  0
H
hzcheng 已提交
290

S
slguan 已提交
291 292
#define TSDB_MAX_RPC_THREADS            5

293
#define TSDB_QUERY_TYPE_NON_TYPE                       0x00U     // none type
294
#define TSDB_QUERY_TYPE_FREE_RESOURCE                  0x01U     // free qhandle at vnode
S
slguan 已提交
295 296 297 298 299

/*
 * 1. ordinary sub query for select * from super_table
 * 2. all sqlobj generated by createSubqueryObj with this flag
 */
300 301 302 303 304 305 306 307
#define TSDB_QUERY_TYPE_SUBQUERY                       0x02U
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY                0x04U     // two-stage subquery for super table

#define TSDB_QUERY_TYPE_TABLE_QUERY                    0x08U     // query ordinary table; below only apply to client side
#define TSDB_QUERY_TYPE_STABLE_QUERY                   0x10U    // query on super table
#define TSDB_QUERY_TYPE_JOIN_QUERY                     0x20U    // join query
#define TSDB_QUERY_TYPE_PROJECTION_QUERY               0x40U    // select *,columns... query
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE                 0x80U    // join sub query at the second stage
H
hzcheng 已提交
308

309 310 311 312 313 314 315
#define TSDB_QUERY_TYPE_INSERT                        0x100U    // insert type
#define TSDB_QUERY_TYPE_IMPORT                        0x200U    // import data

#define TSDB_QUERY_HAS_TYPE(x, _type)         (((x) & (_type)) != 0)
#define TSDB_QUERY_SET_TYPE(x, _type)         ((x) |= (_type))
#define TSDB_QUERY_RESET_TYPE(x)              ((x) = TSDB_QUERY_TYPE_NON_TYPE)

316 317
#define TSDB_ORDER_ASC   1
#define TSDB_ORDER_DESC  2
H
hjxilinx 已提交
318

S
slguan 已提交
319 320 321
#define TSDB_SESSIONS_PER_VNODE (300)
#define TSDB_SESSIONS_PER_DNODE (TSDB_SESSIONS_PER_VNODE * TSDB_MAX_VNODES)

S
slguan 已提交
322 323 324 325 326 327 328 329 330 331
#define TSDB_MAX_MNODES        5
#define TSDB_MAX_DNODES        10
#define TSDB_MAX_ACCOUNTS      10
#define TSDB_MAX_USERS         20
#define TSDB_MAX_DBS           100
#define TSDB_MAX_VGROUPS       1000
#define TSDB_MAX_SUPER_TABLES  100
#define TSDB_MAX_NORMAL_TABLES 1000
#define TSDB_MAX_CHILD_TABLES  100000

J
jtao1735 已提交
332
#define TSDB_PORT_DNODESHELL 0 
J
jtao1735 已提交
333 334 335 336
#define TSDB_PORT_DNODEMNODE 10
#define TSDB_PORT_MNODEDNODE 15 
#define TSDB_PORT_SYNC 20

J
jtao1735 已提交
337 338 339 340 341
#define TAOS_QTYPE_RPC      0
#define TAOS_QTYPE_FWD      1
#define TAOS_QTYPE_WAL      2 
#define TAOS_QTYPE_CQ       3

S
slguan 已提交
342
typedef enum {
S
[TD-10]  
slguan 已提交
343 344 345
  TSDB_PRECISION_MILLI,
  TSDB_PRECISION_MICRO,
  TSDB_PRECISION_NANO
S
slguan 已提交
346
} EPrecisionType;
S
[TD-10]  
slguan 已提交
347 348 349 350 351 352 353

typedef enum {
  TSDB_SUPER_TABLE        = 0,  // super table
  TSDB_CHILD_TABLE        = 1,  // table created from super table
  TSDB_NORMAL_TABLE       = 2,  // ordinary table
  TSDB_STREAM_TABLE       = 3,  // table created from stream computing
  TSDB_TABLE_MAX          = 4
S
slguan 已提交
354 355 356 357 358 359 360 361
} ETableType;

typedef enum {
  TSDB_MOD_MGMT,
  TSDB_MOD_HTTP,
  TSDB_MOD_MONITOR,
  TSDB_MOD_MAX
} EModuleType;
S
[TD-10]  
slguan 已提交
362

H
hzcheng 已提交
363 364 365 366 367
#ifdef __cplusplus
}
#endif

#endif