tfill.h 4.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * 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 TDENGINE_TFILL_H
#define TDENGINE_TFILL_H

#ifdef __cplusplus
extern "C" {
#endif

#include "os.h"
#include "taosdef.h"
25
#include "tcommon.h"
5
54liuyao 已提交
26
#include "tsimplehash.h"
27

H
Haojun Liao 已提交
28 29
#define GET_DEST_SLOT_ID(_p) ((_p)->pExpr->base.resSchema.slotId)

30 31
struct SSDataBlock;

32
typedef struct SFillColInfo {
5
54liuyao 已提交
33 34
  SExprInfo* pExpr;
  bool       notFillCol;  // denote if this column needs fill operation
35
  SVariant   fillVal;
36 37
} SFillColInfo;

38
typedef struct SFillLinearInfo {
39 40
  SPoint  start;
  SPoint  end;
G
Ganlin Zhao 已提交
41 42
  bool    isStartSet;
  bool    isEndSet;
43 44
  int16_t type;
  int32_t bytes;
45 46
} SFillLinearInfo;

47 48 49 50
typedef struct {
  SSchema col;
  char*   tagVal;
} SFillTagColInfo;
H
Haojun Liao 已提交
51 52 53 54 55

typedef struct {
  int64_t key;
  SArray* pRowVal;
} SRowVal;
H
Haojun Liao 已提交
56

57
typedef struct SFillInfo {
5
54liuyao 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  TSKEY        start;         // start timestamp
  TSKEY        end;           // endKey for fill
  TSKEY        currentKey;    // current active timestamp, the value may be changed during the fill procedure.
  int32_t      tsSlotId;      // primary time stamp slot id
  int32_t      srcTsSlotId;   // timestamp column id in the source data block.
  int32_t      order;         // order [TSDB_ORDER_ASC|TSDB_ORDER_DESC]
  int32_t      type;          // fill type
  int32_t      numOfRows;     // number of rows in the input data block
  int32_t      index;         // active row index
  int32_t      numOfTotal;    // number of filled rows in one round
  int32_t      numOfCurrent;  // number of filled rows in current results
  int32_t      numOfCols;     // number of columns, including the tags columns
  SInterval    interval;
  SRowVal      prev;
  SRowVal      next;
  SSDataBlock* pSrcBlock;
  int32_t      alloc;  // data buffer size in rows

  SFillColInfo*    pFillCol;  // column info for fill operations
  SFillTagColInfo* pTags;     // tags value for filling gap
  const char*      id;
79 80
} SFillInfo;

5
54liuyao 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
typedef struct SResultCellData {
  bool    isNull;
  int8_t  type;
  int32_t bytes;
  char    pData[];
} SResultCellData;

typedef struct SResultRowData {
  TSKEY            key;
  SResultCellData* pRowVal;
} SResultRowData;

typedef struct SStreamFillLinearInfo {
  TSKEY   nextEnd;
  SArray* pDeltaVal;      // double. value for Fill(linear).
  SArray* pNextDeltaVal;  // double. value for Fill(linear).
  int64_t winIndex;
  bool    hasNext;
} SStreamFillLinearInfo;

typedef struct SStreamFillInfo {
  TSKEY                  start;    // startKey for fill
  TSKEY                  end;      // endKey for fill
  TSKEY                  current;  // current Key for fill
  TSKEY                  preRowKey;
  TSKEY                  nextRowKey;
  SResultRowData*        pResRow;
  SStreamFillLinearInfo* pLinearInfo;
  bool                   needFill;
  int32_t                type;  // fill type
  int32_t                pos;
  SArray*                delRanges;
  int32_t                delIndex;
} SStreamFillInfo;

int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t maxNumOfRows);
117

H
Haojun Liao 已提交
118 119 120 121 122 123
void          taosFillSetStartInfo(struct SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
void          taosResetFillInfo(struct SFillInfo* pFillInfo, TSKEY startTimestamp);
void          taosFillSetInputDataBlock(struct SFillInfo* pFillInfo, const struct SSDataBlock* pInput);
SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfFillExpr, SExprInfo* pNotFillExpr,
                                int32_t numOfNotFillCols, const struct SNodeListNode* val);
bool          taosFillHasMoreResults(struct SFillInfo* pFillInfo);
124

H
Haojun Liao 已提交
125
SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
126
                              SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t slotId,
127
                              int32_t order, const char* id);
128

5
54liuyao 已提交
129
void*   taosDestroyFillInfo(struct SFillInfo* pFillInfo);
130
int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity);
5
54liuyao 已提交
131
int64_t getFillInfoStart(struct SFillInfo* pFillInfo);
132

H
Haojun Liao 已提交
133 134
bool fillIfWindowPseudoColumn(SFillInfo* pFillInfo, SFillColInfo* pCol, SColumnInfoData* pDstColInfoData,
                                     int32_t rowIndex);
135 136 137 138 139
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TFILL_H