qTableMeta.h 6.6 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5
#ifndef TDENGINE_QTABLEUTIL_H
#define TDENGINE_QTABLEUTIL_H

#include "tsdb.h"  //todo tsdb should not be here
#include "qSqlparser.h"
D
dapan1121 已提交
6
#include "qFilter.h"
H
Haojun Liao 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19

typedef struct SFieldInfo {
  int16_t      numOfOutput;   // number of column in result
  TAOS_FIELD*  final;
  SArray      *internalField; // SArray<SInternalField>
} SFieldInfo;

typedef struct SCond {
  uint64_t uid;
  int32_t  len;  // length of tag query condition data
  char *   cond;
} SCond;

20 21 22 23 24 25 26 27
typedef struct STblCond {
  uint64_t uid;
  int16_t  idx;  //table index
  int32_t  len;  // length of tag query condition data
  char *   cond;
} STblCond;


H
Haojun Liao 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
typedef struct SJoinNode {
  uint64_t uid;
  int16_t  tagColId;
  SArray*  tsJoin;
  SArray*  tagJoin;
} SJoinNode;

typedef struct SJoinInfo {
  bool       hasJoin;
  SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM];
} SJoinInfo;

typedef struct STagCond {
  // relation between tbname list and query condition, including : TK_AND or TK_OR
  int16_t relType;

  // tbname query condition, only support tbname query condition on one table
  SCond tbnameCond;

  // join condition, only support two tables join currently
  SJoinInfo joinInfo;

  // for different table, the query condition must be seperated
  SArray *pCond;
} STagCond;

typedef struct SGroupbyExpr {
  int16_t tableIndex;
  SArray* columnInfo;  // SArray<SColIndex>, group by columns information
  int16_t numOfGroupCols;  // todo remove it
  int16_t orderIndex;  // order by column index
  int16_t orderType;   // order by type: asc/desc
} SGroupbyExpr;

typedef struct STableComInfo {
  uint8_t numOfTags;
  uint8_t precision;
  int16_t numOfColumns;
  int32_t rowSize;
} STableComInfo;

typedef struct STableMeta {
  int32_t        vgId;
  STableId       id;
72
  int8_t         tableType;
H
Haojun Liao 已提交
73 74 75 76 77 78 79 80 81 82
  char           sTableName[TSDB_TABLE_FNAME_LEN];  // super table name
  uint64_t       suid;       // super table id
  int16_t        sversion;
  int16_t        tversion;
  STableComInfo  tableInfo;
  SSchema        schema[];  // if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
} STableMeta;

typedef struct STableMetaInfo {
  STableMeta    *pTableMeta;      // table meta, cached in client side and acquired by name
83 84
  uint32_t      tableMetaSize;
  size_t        tableMetaCapacity; 
H
Haojun Liao 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  SVgroupsInfo  *vgroupList;
  SArray        *pVgroupTables;   // SArray<SVgroupTableInfo>

  /*
   * 1. keep the vgroup index during the multi-vnode super table projection query
   * 2. keep the vgroup index for multi-vnode insertion
   */
  int32_t       vgroupIndex;
  SName         name;
  char          aliasName[TSDB_TABLE_NAME_LEN];    // alias name of table specified in query sql
  SArray       *tagColList;                        // SArray<SColumn*>, involved tag columns
} STableMetaInfo;

struct   SQInfo;      // global merge operator
struct   SQueryAttr;     // query object

D
dapan1121 已提交
101 102 103 104 105
typedef struct STableFilter {
  uint64_t uid;
  SFilterInfo info;
} STableFilter;

H
Haojun Liao 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
typedef struct SQueryInfo {
  int16_t          command;       // the command may be different for each subclause, so keep it seperately.
  uint32_t         type;          // query/insert type
  STimeWindow      window;        // the whole query time window

  SInterval        interval;      // tumble time window
  SSessionWindow   sessionWindow; // session time window

  SGroupbyExpr     groupbyExpr;   // groupby tags info
  SArray *         colList;       // SArray<SColumn*>
  SFieldInfo       fieldsInfo;
  SArray *         exprList;      // SArray<SExprInfo*>
  SArray *         exprList1;     // final exprlist in case of arithmetic expression exists
  SLimitVal        limit;
  SLimitVal        slimit;
  STagCond         tagCond;

D
dapan1121 已提交
123
  SArray *         colCond;
D
dapan1121 已提交
124

H
Haojun Liao 已提交
125 126
  SOrderVal        order;
  int16_t          numOfTables;
127
  int16_t          curTableIdx;
H
Haojun Liao 已提交
128 129
  STableMetaInfo **pTableMetaInfo;
  struct STSBuf   *tsBuf;
Y
yihaoDeng 已提交
130 131

  int16_t          fillType;      // final result fill type
H
Haojun Liao 已提交
132
  int64_t *        fillVal;       // default value for fill
Y
yihaoDeng 已提交
133 134
  int32_t          numOfFillVal;  // fill value size

H
Haojun Liao 已提交
135 136 137 138 139 140 141
  char *           msg;           // pointer to the pCmd->payload to keep error message temporarily
  int64_t          clauseLimit;   // limit for current sub clause

  int64_t          prjOffset;     // offset value in the original sql expression, only applied at client side
  int64_t          vgroupLimit;    // table limit in case of super table projection query + global order + limit

  int32_t          udColumnId;    // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
Y
TD-5438  
yihaoDeng 已提交
142 143
  bool             distinct;   // distinct tag or not
  bool             onlyHasTagCond;
H
Haojun Liao 已提交
144 145 146
  int32_t          round;         // 0/1/....
  int32_t          bufLen;
  char*            buf;
D
dapan1121 已提交
147 148

  bool               udfCopy;
H
Haojun Liao 已提交
149 150 151 152
  SArray            *pUdfInfo;

  struct SQInfo     *pQInfo;      // global merge operator
  struct SQueryAttr *pQueryAttr;     // query object
H
Haojun Liao 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165

  struct SQueryInfo *sibling;     // sibling
  SArray            *pUpstream;   // SArray<struct SQueryInfo>
  struct SQueryInfo *pDownstream;
  int32_t            havingFieldNum;
  bool               stableQuery;
  bool               groupbyColumn;
  bool               simpleAgg;
  bool               arithmeticOnAgg;
  bool               projectionQuery;
  bool               hasFilter;
  bool               onlyTagQuery;
  bool               orderProjectQuery;
H
Haojun Liao 已提交
166
  bool               stateWindow;
H
Haojun Liao 已提交
167
  bool               globalMerge;
H
Haojun Liao 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
} SQueryInfo;

/**
 * get the number of tags of this table
 * @param pTableMeta
 * @return
 */
int32_t tscGetNumOfTags(const STableMeta* pTableMeta);

/**
 * get the number of columns of this table
 * @param pTableMeta
 * @return
 */
int32_t tscGetNumOfColumns(const STableMeta* pTableMeta);

/**
 * get the basic info of this table
 * @param pTableMeta
 * @return
 */
STableComInfo tscGetTableInfo(const STableMeta* pTableMeta);

/**
 * get the schema
 * @param pTableMeta
 * @return
 */
SSchema* tscGetTableSchema(const STableMeta* pTableMeta);

/**
 * get the tag schema
 * @param pMeta
 * @return
 */
SSchema *tscGetTableTagSchema(const STableMeta *pMeta);

/**
 * get the column schema according to the column index
 * @param pMeta
 * @param colIndex
 * @return
 */
SSchema *tscGetTableColumnSchema(const STableMeta *pMeta, int32_t colIndex);

/**
 * get the column schema according to the column id
 * @param pTableMeta
 * @param colId
 * @return
 */
SSchema* tscGetColumnSchemaById(STableMeta* pTableMeta, int16_t colId);

/**
 * create the table meta from the msg
 * @param pTableMetaMsg
 * @param size size of the table meta
 * @return
 */
STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg);

#endif  // TDENGINE_QTABLEUTIL_H