tscUtil.h 5.4 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*
 * 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_TSCUTIL_H
#define TDENGINE_TSCUTIL_H

#ifdef __cplusplus
extern "C" {
#endif

/*
 * @date   2018/09/30
 */
#include <stdio.h>
#include "tsdb.h"
#include "tsclient.h"
#include "textbuffer.h"

#define UTIL_METER_IS_METRIC(cmd) (((cmd)->pMeterMeta != NULL) && ((cmd)->pMeterMeta->meterType == TSDB_METER_METRIC))

#define UTIL_METER_IS_NOMRAL_METER(cmd) (!(UTIL_METER_IS_METRIC(cmd)))

#define UTIL_METER_IS_CREATE_FROM_METRIC(cmd) \
  (((cmd)->pMeterMeta != NULL) && ((cmd)->pMeterMeta->meterType == TSDB_METER_MTABLE))

typedef struct SParsedColElem {
  int16_t colIndex;
  int16_t offset;
} SParsedColElem;

typedef struct SParsedDataColInfo {
44 45
  int16_t        numOfCols;
  int16_t        numOfAssignedCols;
H
hzcheng 已提交
46 47 48 49
  SParsedColElem elems[TSDB_MAX_COLUMNS];
  bool           hasVal[TSDB_MAX_COLUMNS];
} SParsedDataColInfo;

S
slguan 已提交
50 51 52
STableDataBlocks* tscCreateDataBlock(int32_t size);
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
H
hzcheng 已提交
53 54

SDataBlockList* tscCreateBlockArrayList();
S
slguan 已提交
55 56
void* tscDestroyBlockArrayList(SDataBlockList* pList);
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
H
hzcheng 已提交
57
void tscFreeUnusedDataBlocks(SDataBlockList* pList);
S
slguan 已提交
58 59 60 61
void tscMergeTableDataBlocks(SSqlCmd* pCmd, SDataBlockList* pDataList);
STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
                                          int32_t startOffset, int32_t rowSize, char* tableId);
STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t startOffset, char* name);
H
hzcheng 已提交
62 63 64 65 66 67 68 69 70 71

SVnodeSidList* tscGetVnodeSidList(SMetricMeta* pMetricmeta, int32_t vnodeIdx);
SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);

bool tscProjectionQueryOnMetric(SSqlObj* pSql);
bool tscIsTwoStageMergeMetricQuery(SSqlObj* pSql);

/**
 *
 * for the projection query on metric or point interpolation query on metric,
S
slguan 已提交
72
 * we iterate all the meters, instead of invoke query on all qualified meters simultaneously.
H
hzcheng 已提交
73 74 75 76 77 78 79 80 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 117 118 119 120 121 122 123 124 125 126 127 128
 *
 * @param pSql  sql object
 * @return
 *
 */
bool tscIsFirstProjQueryOnMetric(SSqlObj* pSql);
bool tscIsPointInterpQuery(SSqlCmd* pCmd);
void tscClearInterpInfo(SSqlCmd* pCmd);

int32_t setMeterID(SSqlObj* pSql, SSQLToken* pzTableName);

bool tscIsInsertOrImportData(char* sqlstr);

/* use for keep current db info temporarily, for handle table with db prefix */
void tscGetDBInfoFromMeterId(char* meterId, char* db);

void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* keyStr);
bool tscQueryOnMetric(SSqlCmd* pCmd);

int tscAllocPayloadWithSize(SSqlCmd* pCmd, int size);

void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema);
void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField);
void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, char* name, int16_t bytes);

void tscFieldInfoCalOffset(SSqlCmd* pCmd);
void tscFieldInfoRenewOffsetForInterResult(SSqlCmd* pCmd);
void tscFieldInfoClone(SFieldInfo* src, SFieldInfo* dst);

TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index);
int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index);
int32_t tscGetResRowLength(SSqlCmd* pCmd);
void tscClearFieldInfo(SSqlCmd* pCmd);

void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes);

SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
                           int16_t size);
SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
                           int16_t size);

SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index);
void tscSqlExprClone(SSqlExprInfo* src, SSqlExprInfo* dst);

SColumnBase* tscColumnInfoInsert(SSqlCmd* pCmd, int32_t colIndex);

void tscColumnInfoClone(SColumnsInfo* src, SColumnsInfo* dst);
SColumnBase* tscColumnInfoGet(SSqlCmd* pCmd, int32_t index);
void tscColumnInfoReserve(SSqlCmd* pCmd, int32_t size);

int32_t tscValidateName(SSQLToken* pToken);

void tscIncStreamExecutionCount(void* pStream);

bool tscValidateColumnId(SSqlCmd* pCmd, int32_t colId);

S
slguan 已提交
129
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
H
hzcheng 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142
char* tsGetMetricQueryCondPos(STagCond* pCond);
void tscTagCondAssign(STagCond* pDst, STagCond* pSrc);
void tscTagCondRelease(STagCond* pCond);
void tscTagCondSetQueryCondType(STagCond* pCond, int16_t type);

void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SSqlCmd* pCmd);

void tscSetFreeHeatBeat(STscObj* pObj);
bool tscShouldFreeHeatBeat(SSqlObj* pHb);
void tscCleanSqlCmd(SSqlCmd* pCmd);
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql);
void tscDoQuery(SSqlObj* pSql);

S
slguan 已提交
143
int32_t sortRemoveDuplicates(STableDataBlocks* dataBuf, int32_t numOfRows);
H
hzcheng 已提交
144 145 146 147 148
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TSCUTIL_H