tdatablock.h 5.3 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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 _TD_COMMON_EP_H_
#define _TD_COMMON_EP_H_

S
common  
Shengliang Guan 已提交
19
#include "tcommon.h"
S
Shengliang Guan 已提交
20
#include "tmsg.h"
21

H
Haojun Liao 已提交
22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

26 27 28 29 30
typedef struct SCorEpSet {
  int32_t version;
  SEpSet  epSet;
} SCorEpSet;

H
Haojun Liao 已提交
31
typedef struct SBlockOrderInfo {
H
Haojun Liao 已提交
32 33
  int32_t          order;
  int32_t          colIndex;
S
Shengliang Guan 已提交
34
  SColumnInfoData* pColData;
H
Haojun Liao 已提交
35 36
} SBlockOrderInfo;

S
Shengliang Guan 已提交
37 38
int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp);
void    addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
H
Haojun Liao 已提交
39

S
Shengliang Guan 已提交
40
bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2);
41

S
Shengliang Guan 已提交
42 43
void   updateEpSet_s(SCorEpSet* pEpSet, SEpSet* pNewEpSet);
SEpSet getEpSet_s(SCorEpSet* pEpSet);
44

H
Haojun Liao 已提交
45
#define NBIT                     (3u)
H
Haojun Liao 已提交
46
#define BitPos(_n)               ((_n) & ((1 << NBIT) - 1))
H
Haojun Liao 已提交
47 48
#define BMCharPos(bm_, r_)       ((bm_)[(r_) >> NBIT])
#define colDataIsNull_f(bm_, r_) ((BMCharPos(bm_, r_) & (1u << (7u - BitPos(r_)))) == (1u << (7u - BitPos(r_))))
49

H
Haojun Liao 已提交
50 51 52 53
#define colDataSetNull_f(bm_, r_)                    \
  do {                                               \
    BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
  } while (0)
H
Haojun Liao 已提交
54

L
Liu Jicong 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) {
  if (!pColumnInfoData->hasNull) {
    return false;
  }
  if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
    return pColumnInfoData->varmeta.offset[row] == -1;
  } else {
    if (pColumnInfoData->nullbitmap == NULL) {
      return false;
    }

    return colDataIsNull_f(pColumnInfoData->nullbitmap, row);
  }
}

S
Shengliang Guan 已提交
70 71
static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, uint32_t totalRows, uint32_t row,
                                       SColumnDataAgg* pColAgg) {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  if (!pColumnInfoData->hasNull) {
    return false;
  }

  if (pColAgg != NULL) {
    if (pColAgg->numOfNull == totalRows) {
      ASSERT(pColumnInfoData->nullbitmap == NULL);
      return true;
    } else if (pColAgg->numOfNull == 0) {
      ASSERT(pColumnInfoData->nullbitmap == NULL);
      return false;
    }
  }

  if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
    return pColumnInfoData->varmeta.offset[row] == -1;
  } else {
    if (pColumnInfoData->nullbitmap == NULL) {
      return false;
    }

    return colDataIsNull_f(pColumnInfoData->nullbitmap, row);
  }
}

L
Liu Jicong 已提交
97
#define BitmapLen(_n) (((_n) + ((1 << NBIT) - 1)) >> NBIT)
D
dapan 已提交
98

L
Liu Jicong 已提交
99 100
// SColumnInfoData, rowNumber
#define colDataGetData(p1_, r_)                                                        \
D
dapan1121 已提交
101 102
  ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \
                                        : ((p1_)->pData + ((r_) * (p1_)->info.bytes)))
H
Haojun Liao 已提交
103 104

int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull);
L
Liu Jicong 已提交
105 106
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource,
                        uint32_t numOfRow2);
107
int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows);
H
Haojun Liao 已提交
108
int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock);
H
Haojun Liao 已提交
109

110 111
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows);
void    colDataTrim(SColumnInfoData* pColumnInfoData);
H
Haojun Liao 已提交
112

H
Haojun Liao 已提交
113 114
size_t blockDataGetNumOfCols(const SSDataBlock* pBlock);
size_t blockDataGetNumOfRows(const SSDataBlock* pBlock);
H
Haojun Liao 已提交
115

116
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc);
L
Liu Jicong 已提交
117 118
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,
                           int32_t pageSize);
H
Haojun Liao 已提交
119
int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock);
120
int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf);
H
Haojun Liao 已提交
121

122 123
SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount);

H
Haojun Liao 已提交
124
size_t blockDataGetSize(const SSDataBlock* pBlock);
125
size_t blockDataGetRowSize(SSDataBlock* pBlock);
H
Haojun Liao 已提交
126 127 128
double blockDataGetSerialRowSize(const SSDataBlock* pBlock);
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock);

129
SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols);
130

H
Haojun Liao 已提交
131
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
H
Haojun Liao 已提交
132
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
H
Haojun Liao 已提交
133

134
int32_t      blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows);
S
Shengliang Guan 已提交
135
int32_t      blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);
136
void         blockDataCleanup(SSDataBlock* pDataBlock);
137
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
S
Shengliang Guan 已提交
138 139
size_t       blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
void*        blockDataDestroy(SSDataBlock* pBlock);
140

L
Liu Jicong 已提交
141 142
void blockDebugShowData(SArray* dataBlocks);

H
Haojun Liao 已提交
143 144 145 146
#ifdef __cplusplus
}
#endif

L
Liu Jicong 已提交
147
#endif /*_TD_COMMON_EP_H_*/