TDengine/include/common/tdataformat.h

420 lines
15 KiB
C
Raw Normal View History

2020-03-03 08:17:48 +00:00
/*
* 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/>.
*/
2022-02-28 09:39:07 +00:00
2021-10-04 12:42:53 +00:00
#ifndef _TD_COMMON_DATA_FORMAT_H_
#define _TD_COMMON_DATA_FORMAT_H_
2020-02-11 07:29:08 +00:00
2021-05-09 07:47:07 +00:00
#include "os.h"
2020-05-30 10:00:49 +00:00
#include "talgo.h"
2022-05-27 14:05:14 +00:00
#include "tarray.h"
2024-02-21 09:02:25 +00:00
#include "tbuffer.h"
2022-05-11 02:29:53 +00:00
#include "tencode.h"
2021-10-08 12:33:46 +00:00
#include "ttypes.h"
2020-04-28 02:11:22 +00:00
#include "tutil.h"
2020-03-10 06:39:11 +00:00
2020-03-03 08:17:48 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2020-03-10 06:39:11 +00:00
2024-03-15 10:22:57 +00:00
typedef struct SSchema SSchema;
typedef struct SSchema2 SSchema2;
2024-03-12 08:46:41 +00:00
typedef struct SSchemaExt SSchemaExt;
2024-03-15 10:22:57 +00:00
typedef struct STColumn STColumn;
typedef struct STSchema STSchema;
typedef struct SValue SValue;
typedef struct SColVal SColVal;
typedef struct SRow SRow;
typedef struct SRowIter SRowIter;
typedef struct STagVal STagVal;
typedef struct STag STag;
typedef struct SColData SColData;
2024-02-28 06:34:37 +00:00
2024-02-21 09:02:25 +00:00
typedef struct SRowKey SRowKey;
typedef struct SValueColumn SValueColumn;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
struct SColumnDataAgg;
typedef struct SColumnDataAgg* SColumnDataAggPtr;
2022-05-11 02:29:53 +00:00
2024-02-28 06:34:37 +00:00
#define HAS_NONE ((uint8_t)0x1)
#define HAS_NULL ((uint8_t)0x2)
#define HAS_VALUE ((uint8_t)0x4)
2022-09-13 06:21:43 +00:00
// bitmap ================================
2022-12-05 13:42:05 +00:00
const static uint8_t BIT1_MAP[8] = {0b11111110, 0b11111101, 0b11111011, 0b11110111,
0b11101111, 0b11011111, 0b10111111, 0b01111111};
const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b00111111};
2022-08-18 02:09:31 +00:00
2022-12-05 13:42:05 +00:00
#define ONE ((uint8_t)1)
#define THREE ((uint8_t)3)
#define DIV_8(i) ((i) >> 3)
#define MOD_8(i) ((i)&7)
2022-12-05 13:42:05 +00:00
#define DIV_4(i) ((i) >> 2)
#define MOD_4(i) ((i)&3)
2022-12-05 13:42:05 +00:00
#define MOD_4_TIME_2(i) (MOD_4(i) << 1)
#define BIT1_SIZE(n) (DIV_8((n)-1) + 1)
#define BIT2_SIZE(n) (DIV_4((n)-1) + 1)
#define SET_BIT1(p, i, v) ((p)[DIV_8(i)] = (p)[DIV_8(i)] & BIT1_MAP[MOD_8(i)] | ((v) << MOD_8(i)))
2022-12-21 05:47:36 +00:00
#define SET_BIT1_EX(p, i, v) \
do { \
if (MOD_8(i) == 0) { \
(p)[DIV_8(i)] = 0; \
} \
SET_BIT1(p, i, v); \
} while (0)
2022-12-05 13:42:05 +00:00
#define GET_BIT1(p, i) (((p)[DIV_8(i)] >> MOD_8(i)) & ONE)
#define SET_BIT2(p, i, v) ((p)[DIV_4(i)] = (p)[DIV_4(i)] & BIT2_MAP[MOD_4(i)] | ((v) << MOD_4_TIME_2(i)))
2022-12-21 05:47:36 +00:00
#define SET_BIT2_EX(p, i, v) \
do { \
if (MOD_4(i) == 0) { \
(p)[DIV_4(i)] = 0; \
} \
SET_BIT2(p, i, v); \
} while (0)
#define GET_BIT2(p, i) (((p)[DIV_4(i)] >> MOD_4_TIME_2(i)) & THREE)
2022-06-18 03:35:49 +00:00
2022-09-13 06:21:43 +00:00
// SColVal ================================
2022-09-23 10:55:27 +00:00
#define CV_FLAG_VALUE ((int8_t)0x0)
#define CV_FLAG_NONE ((int8_t)0x1)
#define CV_FLAG_NULL ((int8_t)0x2)
2024-02-21 06:29:10 +00:00
#define COL_VAL_NONE(CID, TYPE) ((SColVal){.cid = (CID), .flag = CV_FLAG_NONE, .value = {.type = (TYPE)}})
#define COL_VAL_NULL(CID, TYPE) ((SColVal){.cid = (CID), .flag = CV_FLAG_NULL, .value = {.type = (TYPE)}})
#define COL_VAL_VALUE(CID, V) ((SColVal){.cid = (CID), .flag = CV_FLAG_VALUE, .value = (V)})
2022-06-01 07:28:57 +00:00
2022-09-23 10:55:27 +00:00
#define COL_VAL_IS_NONE(CV) ((CV)->flag == CV_FLAG_NONE)
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#define tRowGetKey(_pRow, _pKey) \
do { \
(_pKey)->ts = taosGetInt64Aligned(&((_pRow)->ts)); \
(_pKey)->numOfPKs = 0; \
if ((_pRow)->numOfPKs > 0) { \
tRowGetPrimaryKey((_pRow), (_pKey)); \
} \
2024-05-15 01:09:20 +00:00
} while (0)
2024-02-21 09:02:25 +00:00
// SValueColumn ================================
2024-02-23 06:44:46 +00:00
typedef struct {
2024-02-28 02:58:42 +00:00
int8_t cmprAlg; // filled by caller
int8_t type;
2024-02-28 08:49:44 +00:00
int32_t dataOriginalSize;
int32_t dataCompressedSize;
int32_t offsetOriginalSize;
int32_t offsetCompressedSize;
2024-02-23 06:44:46 +00:00
} SValueColumnCompressInfo;
2024-02-21 11:26:12 +00:00
int32_t tValueColumnInit(SValueColumn *valCol);
2024-09-24 08:08:48 +00:00
void tValueColumnDestroy(SValueColumn *valCol);
2024-09-23 06:02:29 +00:00
void tValueColumnClear(SValueColumn *valCol);
2024-02-21 09:02:25 +00:00
int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value);
2024-03-08 09:04:26 +00:00
int32_t tValueColumnUpdate(SValueColumn *valCol, int32_t idx, const SValue *value);
2024-02-21 09:02:25 +00:00
int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value);
2024-02-28 02:58:42 +00:00
int32_t tValueColumnCompress(SValueColumn *valCol, SValueColumnCompressInfo *info, SBuffer *output, SBuffer *assist);
2024-03-06 08:23:02 +00:00
int32_t tValueColumnDecompress(void *input, const SValueColumnCompressInfo *compressInfo, SValueColumn *valCol,
SBuffer *buffer);
2024-03-03 08:01:12 +00:00
int32_t tValueColumnCompressInfoEncode(const SValueColumnCompressInfo *compressInfo, SBuffer *buffer);
2024-02-23 06:44:46 +00:00
int32_t tValueColumnCompressInfoDecode(SBufferReader *reader, SValueColumnCompressInfo *compressInfo);
2024-02-23 09:27:03 +00:00
int32_t tValueCompare(const SValue *tv1, const SValue *tv2);
2024-02-21 09:02:25 +00:00
2022-11-16 09:22:09 +00:00
// SRow ================================
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
2023-02-22 06:29:14 +00:00
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
2022-11-24 03:49:48 +00:00
void tRowDestroy(SRow *pRow);
2023-09-18 05:46:29 +00:00
int32_t tRowSort(SArray *aRowP);
2022-11-30 02:23:44 +00:00
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
2022-12-30 08:55:49 +00:00
int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag);
2024-05-15 01:09:20 +00:00
void tRowGetPrimaryKey(SRow *pRow, SRowKey *key);
int32_t tRowKeyCompare(const SRowKey *key1, const SRowKey *key2);
2024-07-15 15:53:12 +00:00
void tRowKeyAssign(SRowKey *pDst, SRowKey *pSrc);
2022-11-16 09:22:09 +00:00
// SRowIter ================================
2022-11-21 07:16:50 +00:00
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
void tRowIterClose(SRowIter **ppIter);
SColVal *tRowIterNext(SRowIter *pIter);
2022-05-11 03:11:52 +00:00
2022-09-13 06:21:43 +00:00
// STag ================================
2022-05-27 14:18:31 +00:00
int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag);
2022-05-17 09:50:21 +00:00
void tTagFree(STag *pTag);
2022-06-22 08:32:10 +00:00
bool tTagIsJson(const void *pTag);
bool tTagIsJsonNull(void *tagVal);
2022-05-28 09:16:04 +00:00
bool tTagGet(const STag *pTag, STagVal *pTagVal);
2022-06-01 12:42:29 +00:00
char *tTagValToData(const STagVal *pTagVal, bool isJson);
2022-05-18 08:30:39 +00:00
int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
2022-05-24 06:50:47 +00:00
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
2022-05-28 09:16:04 +00:00
int32_t tTagToValArray(const STag *pTag, SArray **ppArray);
2022-06-02 06:04:31 +00:00
void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf, void *charsetCxt);
2022-05-17 09:50:21 +00:00
2022-09-13 06:21:43 +00:00
// SColData ================================
2024-02-27 07:10:42 +00:00
typedef struct {
2024-03-15 10:22:57 +00:00
uint32_t cmprAlg; // filled by caller
2024-03-29 13:48:58 +00:00
int8_t columnFlag;
int8_t flag;
int8_t dataType;
int16_t columnId;
int32_t numOfData;
int32_t bitmapOriginalSize;
int32_t bitmapCompressedSize;
int32_t offsetOriginalSize;
int32_t offsetCompressedSize;
int32_t dataOriginalSize;
int32_t dataCompressedSize;
2024-02-27 07:10:42 +00:00
} SColDataCompressInfo;
2022-12-01 08:19:21 +00:00
typedef void *(*xMallocFn)(void *, int32_t);
2024-11-19 08:44:28 +00:00
typedef int32_t (*checkWKBGeometryFn)(const unsigned char *geoWKB, size_t nGeom);
typedef int32_t (*initGeosFn)();
2024-02-28 06:34:37 +00:00
2024-03-06 07:37:57 +00:00
void tColDataDestroy(void *ph);
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t cflag);
void tColDataClear(SColData *pColData);
void tColDataDeepClear(SColData *pColData);
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
int32_t tColDataUpdateValue(SColData *pColData, SColVal *pColVal, bool forward);
2024-12-25 03:59:48 +00:00
int32_t tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
2024-03-06 07:37:57 +00:00
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
int32_t tColDataCopy(SColData *pColDataFrom, SColData *pColData, xMallocFn xMalloc, void *arg);
2024-04-10 07:06:43 +00:00
void tColDataArrGetRowKey(SColData *aColData, int32_t nColData, int32_t iRow, SRowKey *key);
2024-03-06 07:37:57 +00:00
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
extern void (*tColDataCalcSMA[])(SColData *pColData, SColumnDataAggPtr pAggs);
2024-02-28 06:34:37 +00:00
2024-02-28 08:49:44 +00:00
int32_t tColDataCompress(SColData *colData, SColDataCompressInfo *info, SBuffer *output, SBuffer *assist);
2024-03-06 08:42:54 +00:00
int32_t tColDataDecompress(void *input, SColDataCompressInfo *info, SColData *colData, SBuffer *assist);
2022-09-13 06:21:43 +00:00
2022-11-25 09:27:04 +00:00
// for stmt bind
2024-11-19 08:44:28 +00:00
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen, initGeosFn igeos,
checkWKBGeometryFn cgeos);
int32_t tColDataSortMerge(SArray **arr);
2022-11-25 09:27:04 +00:00
2022-12-30 06:20:55 +00:00
// for raw block
int32_t tColDataAddValueByDataBlock(SColData *pColData, int8_t type, int32_t bytes, int32_t nRows, char *lengthOrbitmap,
char *data);
2022-11-29 14:06:08 +00:00
// for encode/decode
2025-01-08 10:13:10 +00:00
int32_t tEncodeColData(uint8_t version, SEncoder *pEncoder, SColData *pColData);
int32_t tDecodeColData(uint8_t version, SDecoder *pDecoder, SColData *pColData);
int32_t tEncodeRow(SEncoder *pEncoder, SRow *pRow);
int32_t tDecodeRow(SDecoder *pDecoder, SRow **ppRow);
2022-11-25 09:27:04 +00:00
2022-09-13 06:21:43 +00:00
// STRUCT ================================
2022-05-11 02:29:53 +00:00
struct STColumn {
col_id_t colId;
int8_t type;
int8_t flags;
int32_t bytes;
int32_t offset;
};
struct STSchema {
2022-05-11 02:37:52 +00:00
int32_t numOfCols;
int32_t version;
int32_t flen;
int32_t tlen;
STColumn columns[];
2022-05-11 02:29:53 +00:00
};
2024-02-29 06:50:24 +00:00
/*
2024-01-26 09:14:00 +00:00
* 1. Tuple format:
2024-02-29 06:50:24 +00:00
* SRow + [(type, offset) * numOfPKs +] [bit map +] fix-length data + [var-length data]
2024-01-26 09:14:00 +00:00
*
* 2. K-V format:
2024-02-29 06:50:24 +00:00
* SRow + [(type, offset) * numOfPKs +] offset array + ([-]cid [+ data]) * numColsNotNone
2024-01-26 09:14:00 +00:00
*/
2022-11-16 09:22:09 +00:00
struct SRow {
uint8_t flag;
2024-02-29 06:50:24 +00:00
uint8_t numOfPKs;
2022-11-16 09:22:09 +00:00
uint16_t sver;
uint32_t len;
2022-11-21 04:13:27 +00:00
TSKEY ts;
2022-11-16 09:22:09 +00:00
uint8_t data[];
2022-05-11 02:29:53 +00:00
};
2024-02-29 06:50:24 +00:00
typedef struct {
int8_t type;
uint32_t offset;
} SPrimaryKeyIndex;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
#define DATUM_MAX_SIZE 16
2022-05-31 02:48:45 +00:00
struct SValue {
2024-02-21 06:29:10 +00:00
int8_t type;
2022-05-31 02:48:45 +00:00
union {
2022-09-21 07:28:04 +00:00
int64_t val;
2022-05-31 02:48:45 +00:00
struct {
uint8_t *pData;
uint32_t nData;
2022-05-31 02:48:45 +00:00
};
};
};
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
#define VALUE_GET_DATUM(pVal, type) \
(IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) ? (pVal)->pData : (void*)&(pVal)->val
#define VALUE_GET_TRIVIAL_DATUM(pVal) ((pVal)->val)
#define VALUE_SET_TRIVIAL_DATUM(pVal, v) (pVal)->val = v
void valueSetDatum(SValue *pVal, int8_t type, void *pDatum, uint32_t len);
void valueCloneDatum(SValue *pDst, const SValue *pSrc, int8_t type);
void valueClearDatum(SValue *pVal, int8_t type);
2024-02-28 06:34:37 +00:00
#define TD_MAX_PK_COLS 2
2024-01-26 09:14:00 +00:00
struct SRowKey {
2024-02-21 07:21:46 +00:00
TSKEY ts;
2024-02-22 02:13:35 +00:00
uint8_t numOfPKs;
2024-02-28 06:34:37 +00:00
SValue pks[TD_MAX_PK_COLS];
2024-01-26 09:14:00 +00:00
};
2022-05-14 06:18:07 +00:00
struct SColVal {
2022-06-01 07:10:33 +00:00
int16_t cid;
2022-09-23 10:55:27 +00:00
int8_t flag;
2022-05-31 03:08:29 +00:00
SValue value;
2022-05-14 06:18:07 +00:00
};
2022-09-13 06:21:43 +00:00
struct SColData {
int16_t cid;
int8_t type;
2024-01-26 09:14:00 +00:00
int8_t cflag;
2023-01-03 03:34:27 +00:00
int32_t numOfNone; // # of none
int32_t numOfNull; // # of null
int32_t numOfValue; // # of vale
2022-09-13 06:21:43 +00:00
int32_t nVal;
2023-02-15 09:59:54 +00:00
int8_t flag;
2022-09-13 06:21:43 +00:00
uint8_t *pBitMap;
int32_t *aOffset;
int32_t nData;
uint8_t *pData;
};
2022-05-31 15:38:21 +00:00
#pragma pack(push, 1)
2022-05-17 09:50:21 +00:00
struct STagVal {
2022-08-18 02:09:31 +00:00
// char colName[TSDB_COL_NAME_LEN]; // only used for tmq_get_meta
2022-05-27 13:59:53 +00:00
union {
int16_t cid;
char *pKey;
};
2022-05-30 03:51:36 +00:00
int8_t type;
union {
2022-06-01 12:42:29 +00:00
int64_t i64;
2022-05-30 03:51:36 +00:00
struct {
uint32_t nData;
uint8_t *pData;
};
};
2022-05-17 09:50:21 +00:00
};
2022-06-01 12:42:29 +00:00
#define TD_TAG_JSON ((int8_t)0x40) // distinguish JSON string and JSON value with the highest bit
2022-05-31 13:05:43 +00:00
#define TD_TAG_LARGE ((int8_t)0x20)
2022-05-28 09:16:04 +00:00
struct STag {
2022-05-28 10:10:16 +00:00
int8_t flags;
2022-05-28 09:16:04 +00:00
int16_t len;
int16_t nTag;
int32_t ver;
2022-05-28 10:10:16 +00:00
int8_t idx[];
2022-05-28 09:16:04 +00:00
};
#pragma pack(pop)
2022-05-17 09:50:21 +00:00
#if 1 //================================================================================================================================================
2022-01-24 12:53:04 +00:00
// Imported since 3.0 and use bitmap to demonstrate None/Null/Norm, while use Null/Norm below 3.0 without of bitmap.
#define TD_SUPPORT_BITMAP
2022-02-03 09:01:38 +00:00
2021-01-25 03:30:41 +00:00
#define STR_TO_VARSTR(x, str) \
do { \
VarDataLenT __len = (VarDataLenT)strlen(str); \
*(VarDataLenT *)(x) = __len; \
2024-07-25 00:51:19 +00:00
(void)memcpy(varDataVal(x), (str), __len); \
2020-06-01 01:57:55 +00:00
} while (0);
2021-01-24 02:24:44 +00:00
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \
do { \
2020-06-16 07:22:58 +00:00
char *_e = stpncpy(varDataVal(x), (str), (_maxs)-VARSTR_HEADER_SIZE); \
2021-01-24 02:24:44 +00:00
varDataSetLen(x, (_e - (x)-VARSTR_HEADER_SIZE)); \
2020-06-01 01:57:55 +00:00
} while (0)
2024-07-25 00:51:19 +00:00
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) \
do { \
*(VarDataLenT *)(x) = (VarDataLenT)(_size); \
(void)memcpy(varDataVal(x), (str), (_size)); \
2020-06-01 01:57:55 +00:00
} while (0);
2020-05-02 09:41:38 +00:00
2022-11-23 12:13:27 +00:00
// STSchema ================================
2022-11-23 02:45:58 +00:00
STSchema *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version);
2023-01-30 06:24:00 +00:00
#define tDestroyTSchema(pTSchema) \
do { \
if (pTSchema) { \
taosMemoryFree(pTSchema); \
pTSchema = NULL; \
} \
} while (0)
2024-03-07 05:14:56 +00:00
const STColumn *tTSchemaSearchColumn(const STSchema *pTSchema, int16_t cid);
2022-11-23 02:45:58 +00:00
2024-02-21 11:26:12 +00:00
struct SValueColumn {
int8_t type;
uint32_t numOfValues;
SBuffer data;
SBuffer offsets;
};
2024-02-23 06:44:46 +00:00
typedef struct {
2024-03-15 10:22:57 +00:00
int32_t dataType; // filled by caller
uint32_t cmprAlg; // filled by caller
int32_t originalSize; // filled by caller
int32_t compressedSize;
2024-02-23 06:44:46 +00:00
} SCompressInfo;
2024-02-28 02:58:42 +00:00
int32_t tCompressData(void *input, // input
SCompressInfo *info, // compress info
void *output, // output
int32_t outputSize, // output size
SBuffer *buffer // assistant buffer provided by caller, can be NULL
);
int32_t tDecompressData(void *input, // input
const SCompressInfo *info, // compress info
void *output, // output
int32_t outputSize, // output size
SBuffer *buffer // assistant buffer provided by caller, can be NULL
);
2024-03-06 07:37:57 +00:00
int32_t tCompressDataToBuffer(void *input, SCompressInfo *info, SBuffer *output, SBuffer *assist);
int32_t tDecompressDataToBuffer(void *input, SCompressInfo *info, SBuffer *output, SBuffer *assist);
2024-02-23 06:44:46 +00:00
2024-06-05 09:06:36 +00:00
typedef struct {
int32_t columnId;
int32_t type;
TAOS_MULTI_BIND *bind;
} SBindInfo;
int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray, bool *pOrdered, bool *pDupTs);
2024-06-05 09:06:36 +00:00
2024-08-15 01:28:32 +00:00
// stmt2 binding
2024-11-19 08:44:28 +00:00
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen, initGeosFn igeos,
checkWKBGeometryFn cgeos);
2024-08-15 01:28:32 +00:00
typedef struct {
int32_t columnId;
int32_t type;
int32_t bytes;
2024-08-15 01:28:32 +00:00
TAOS_STMT2_BIND *bind;
} SBindInfo2;
int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray, bool *pOrdered, bool *pDupTs);
2024-08-15 01:28:32 +00:00
2022-05-11 02:29:53 +00:00
#endif
2020-03-03 08:17:48 +00:00
#ifdef __cplusplus
}
#endif
2022-01-06 10:11:28 +00:00
#endif /*_TD_COMMON_DATA_FORMAT_H_*/