more code
This commit is contained in:
parent
b0b71bc3c2
commit
844a563295
|
@ -19,6 +19,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "talgo.h"
|
#include "talgo.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
#include "tbuffer.h"
|
||||||
#include "tencode.h"
|
#include "tencode.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
@ -39,6 +40,7 @@ typedef struct STagVal STagVal;
|
||||||
typedef struct STag STag;
|
typedef struct STag STag;
|
||||||
typedef struct SColData SColData;
|
typedef struct SColData SColData;
|
||||||
typedef struct SRowKey SRowKey;
|
typedef struct SRowKey SRowKey;
|
||||||
|
typedef struct SValueColumn SValueColumn;
|
||||||
|
|
||||||
#define HAS_NONE ((uint8_t)0x1)
|
#define HAS_NONE ((uint8_t)0x1)
|
||||||
#define HAS_NULL ((uint8_t)0x2)
|
#define HAS_NULL ((uint8_t)0x2)
|
||||||
|
@ -54,9 +56,9 @@ const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b001111
|
||||||
#define ONE ((uint8_t)1)
|
#define ONE ((uint8_t)1)
|
||||||
#define THREE ((uint8_t)3)
|
#define THREE ((uint8_t)3)
|
||||||
#define DIV_8(i) ((i) >> 3)
|
#define DIV_8(i) ((i) >> 3)
|
||||||
#define MOD_8(i) ((i)&7)
|
#define MOD_8(i) ((i) & 7)
|
||||||
#define DIV_4(i) ((i) >> 2)
|
#define DIV_4(i) ((i) >> 2)
|
||||||
#define MOD_4(i) ((i)&3)
|
#define MOD_4(i) ((i) & 3)
|
||||||
#define MOD_4_TIME_2(i) (MOD_4(i) << 1)
|
#define MOD_4_TIME_2(i) (MOD_4(i) << 1)
|
||||||
#define BIT1_SIZE(n) (DIV_8((n)-1) + 1)
|
#define BIT1_SIZE(n) (DIV_8((n)-1) + 1)
|
||||||
#define BIT2_SIZE(n) (DIV_4((n)-1) + 1)
|
#define BIT2_SIZE(n) (DIV_4((n)-1) + 1)
|
||||||
|
@ -92,6 +94,15 @@ const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b001111
|
||||||
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
|
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
|
||||||
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
|
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
|
||||||
|
|
||||||
|
// SValueColumn ================================
|
||||||
|
int32_t tValueColumnInit(SValueColumn *valCol, int8_t type);
|
||||||
|
int32_t tValueColumnDestroy(SValueColumn *valCol);
|
||||||
|
int32_t tValueColumnClear(SValueColumn *valCol);
|
||||||
|
int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value);
|
||||||
|
int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value);
|
||||||
|
int32_t tValueColumnCompress(SValueColumn *valCol, SBuffer *buffer);
|
||||||
|
int32_t tValueColumnDecompress(SBuffer *buffer, SValueColumn *valCol);
|
||||||
|
|
||||||
// SRow ================================
|
// SRow ================================
|
||||||
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
||||||
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||||
|
|
|
@ -35,7 +35,7 @@ static int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capacity);
|
||||||
static int32_t tBufferAppend(SBuffer *buffer, const void *data, uint32_t size);
|
static int32_t tBufferAppend(SBuffer *buffer, const void *data, uint32_t size);
|
||||||
#define tBufferGetSize(buffer) ((buffer)->size)
|
#define tBufferGetSize(buffer) ((buffer)->size)
|
||||||
#define tBufferGetCapacity(buffer) ((buffer)->capacity)
|
#define tBufferGetCapacity(buffer) ((buffer)->capacity)
|
||||||
#define tBufferGetData(buffer) ((const void *)(buffer)->data)
|
#define tBufferGetData(buffer) ((buffer)->data)
|
||||||
|
|
||||||
// SBufferWriter
|
// SBufferWriter
|
||||||
#define BUFFER_WRITER_INITIALIZER(forward, offset, buffer) ((SBufferWriter){forward, offset, buffer})
|
#define BUFFER_WRITER_INITIALIZER(forward, offset, buffer) ((SBufferWriter){forward, offset, buffer})
|
||||||
|
|
|
@ -3784,3 +3784,90 @@ void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_
|
||||||
NULL, // TSDB_DATA_TYPE_MEDIUMBLOB
|
NULL, // TSDB_DATA_TYPE_MEDIUMBLOB
|
||||||
tColDataCalcSMAVarType // TSDB_DATA_TYPE_GEOMETRY
|
tColDataCalcSMAVarType // TSDB_DATA_TYPE_GEOMETRY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SValueColumn ================================
|
||||||
|
struct SValueColumn {
|
||||||
|
int8_t type;
|
||||||
|
uint32_t numOfValues;
|
||||||
|
SBuffer data;
|
||||||
|
SBuffer offsets;
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t tValueColumnInit(SValueColumn *valCol, int8_t type) {
|
||||||
|
valCol->type = type;
|
||||||
|
valCol->numOfValues = 0;
|
||||||
|
tBufferInit(&valCol->data);
|
||||||
|
tBufferInit(&valCol->offsets);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tValueColumnDestroy(SValueColumn *valCol) {
|
||||||
|
valCol->type = TSDB_DATA_TYPE_NULL;
|
||||||
|
valCol->numOfValues = 0;
|
||||||
|
tBufferDestroy(&valCol->data);
|
||||||
|
tBufferDestroy(&valCol->offsets);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tValueColumnClear(SValueColumn *valCol) {
|
||||||
|
valCol->numOfValues = 0;
|
||||||
|
tBufferClear(&valCol->data);
|
||||||
|
tBufferClear(&valCol->offsets);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value) {
|
||||||
|
int32_t code;
|
||||||
|
|
||||||
|
ASSERT(value->type == valCol->type);
|
||||||
|
if (IS_VAR_DATA_TYPE(value->type)) {
|
||||||
|
int32_t offset = tBufferGetSize(&valCol->data);
|
||||||
|
if ((code = tBufferAppend(&valCol->offsets, &offset, sizeof(offset)))) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
if ((code = tBufferAppend(&valCol->data, value->pData, value->nData))) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return tBufferAppend(&valCol->data, &value->val, tDataTypes[value->type].bytes);
|
||||||
|
}
|
||||||
|
valCol->numOfValues++;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value) {
|
||||||
|
if (idx < 0 || idx >= valCol->numOfValues) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
value->type = valCol->type;
|
||||||
|
if (IS_VAR_DATA_TYPE(value->type)) {
|
||||||
|
int32_t offset, nextOffset;
|
||||||
|
|
||||||
|
memcpy(&offset, tBufferGetData(&valCol->data) + idx * sizeof(offset), sizeof(offset));
|
||||||
|
if (idx == valCol->numOfValues - 1) {
|
||||||
|
nextOffset = tBufferGetSize(&valCol->data);
|
||||||
|
} else {
|
||||||
|
memcpy(&nextOffset, tBufferGetData(&valCol->data) + (idx + 1) * sizeof(offset), sizeof(nextOffset));
|
||||||
|
}
|
||||||
|
value->nData = nextOffset - offset;
|
||||||
|
value->pData = (uint8_t *)((char *)tBufferGetData(&valCol->data) + offset);
|
||||||
|
} else {
|
||||||
|
memcpy(&value->val, (char *)tBufferGetData(&valCol->data) + idx * tDataTypes[value->type].bytes,
|
||||||
|
tDataTypes[value->type].bytes);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tValueColumnCompress(SValueColumn *valCol, SBuffer *buffer) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tValueColumnDecompress(SBuffer *buffer, SValueColumn *valCol) {
|
||||||
|
ASSERT(0);
|
||||||
|
// TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue