Merge pull request #17102 from taosdata/feat/stream_compression
feat: stream compression
This commit is contained in:
commit
856c990fbc
|
@ -162,17 +162,7 @@ struct STSRowBuilder {
|
|||
|
||||
struct SValue {
|
||||
union {
|
||||
int8_t i8; // TSDB_DATA_TYPE_BOOL||TSDB_DATA_TYPE_TINYINT
|
||||
uint8_t u8; // TSDB_DATA_TYPE_UTINYINT
|
||||
int16_t i16; // TSDB_DATA_TYPE_SMALLINT
|
||||
uint16_t u16; // TSDB_DATA_TYPE_USMALLINT
|
||||
int32_t i32; // TSDB_DATA_TYPE_INT
|
||||
uint32_t u32; // TSDB_DATA_TYPE_UINT
|
||||
int64_t i64; // TSDB_DATA_TYPE_BIGINT
|
||||
uint64_t u64; // TSDB_DATA_TYPE_UBIGINT
|
||||
TSKEY ts; // TSDB_DATA_TYPE_TIMESTAMP
|
||||
float f; // TSDB_DATA_TYPE_FLOAT
|
||||
double d; // TSDB_DATA_TYPE_DOUBLE
|
||||
int64_t val;
|
||||
struct {
|
||||
uint32_t nData;
|
||||
uint8_t *pData;
|
||||
|
|
|
@ -333,10 +333,10 @@ typedef struct tDataTypeDescriptor {
|
|||
char *name;
|
||||
int64_t minValue;
|
||||
int64_t maxValue;
|
||||
int32_t (*compFunc)(const char *const input, int32_t inputSize, const int32_t nelements, char *const output,
|
||||
int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
|
||||
int32_t (*decompFunc)(const char *const input, int32_t compressedSize, const int32_t nelements, char *const output,
|
||||
int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
|
||||
int32_t (*compFunc)(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t (*decompFunc)(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
void (*statisFunc)(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numofrow, int64_t *min,
|
||||
int64_t *max, int64_t *sum, int16_t *minindex, int16_t *maxindex, int16_t *numofnull);
|
||||
} tDataTypeDescriptor;
|
||||
|
@ -356,7 +356,6 @@ void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type);
|
|||
void *getDataMin(int32_t type);
|
||||
void *getDataMax(int32_t type);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define ENCODE_LIMIT (((uint8_t)1) << 7)
|
||||
#define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode
|
||||
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
|
||||
#define ZIGZAGE(T, v) (((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1)) // zigzag encode
|
||||
#define ZIGZAGD(T, v) (((v) >> 1) ^ -((T)((v)&1))) // zigzag decode
|
||||
|
||||
/* ------------------------ LEGACY CODES ------------------------ */
|
||||
#if 1
|
||||
|
@ -70,7 +70,7 @@ static FORCE_INLINE int32_t taosEncodeFixedBool(void **buf, bool value) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE void *taosDecodeFixedBool(const void *buf, bool *value) {
|
||||
*value = ( (((int8_t *)buf)[0] == 0) ? false : true );
|
||||
*value = ((((int8_t *)buf)[0] == 0) ? false : true);
|
||||
return POINTER_SHIFT(buf, sizeof(int8_t));
|
||||
}
|
||||
|
||||
|
|
|
@ -51,287 +51,12 @@ extern "C" {
|
|||
#define HEAD_MODE(x) x % 2
|
||||
#define HEAD_ALGO(x) x / 2
|
||||
|
||||
extern int32_t tsCompressINTImp(const char *const input, const int32_t nelements, char *const output, const char type);
|
||||
extern int32_t tsDecompressINTImp(const char *const input, const int32_t nelements, char *const output,
|
||||
const char type);
|
||||
extern int32_t tsCompressBoolImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsDecompressBoolImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsCompressStringImp(const char *const input, int32_t inputSize, char *const output, int32_t outputSize);
|
||||
extern int32_t tsDecompressStringImp(const char *const input, int32_t compressedSize, char *const output,
|
||||
int32_t outputSize);
|
||||
extern int32_t tsCompressTimestampImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsDecompressTimestampImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsCompressDoubleImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsDecompressDoubleImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsCompressFloatImp(const char *const input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsDecompressFloatImp(const char *const input, const int32_t nelements, char *const output);
|
||||
// lossy
|
||||
extern int32_t tsCompressFloatLossyImp(const char *input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsDecompressFloatLossyImp(const char *input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output);
|
||||
extern int32_t tsCompressDoubleLossyImp(const char *input, const int32_t nelements, char *const output);
|
||||
extern int32_t tsDecompressDoubleLossyImp(const char *input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output);
|
||||
|
||||
#ifdef TD_TSZ
|
||||
extern bool lossyFloat;
|
||||
extern bool lossyDouble;
|
||||
int32_t tsCompressInit();
|
||||
void tsCompressExit();
|
||||
#endif
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressTinyint(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_TINYINT);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressTinyint(const char *const input, int32_t compressedSize,
|
||||
const int32_t nelements, char *const output, int32_t outputSize,
|
||||
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressINTImp(buffer, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressSmallint(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_SMALLINT);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressSmallint(const char *const input, int32_t compressedSize,
|
||||
const int32_t nelements, char *const output, int32_t outputSize,
|
||||
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressINTImp(buffer, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressInt(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_INT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_INT);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressInt(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_INT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressINTImp(buffer, nelements, output, TSDB_DATA_TYPE_INT);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressBigint(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_BIGINT);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressBigint(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressINTImp(buffer, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressBool(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressBoolImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressBoolImp(input, nelements, buffer);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressBool(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressBoolImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressBoolImp(buffer, nelements, output);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressString(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
return tsCompressStringImp(input, inputSize, output, outputSize);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressString(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
return tsDecompressStringImp(input, compressedSize, output, outputSize);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressFloat(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
#ifdef TD_TSZ
|
||||
// lossy mode
|
||||
if (lossyFloat) {
|
||||
return tsCompressFloatLossyImp(input, nelements, output);
|
||||
// lossless mode
|
||||
} else {
|
||||
#endif
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressFloatImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressFloatImp(input, nelements, buffer);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TD_TSZ
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressFloat(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
#ifdef TD_TSZ
|
||||
if (HEAD_ALGO(input[0]) == ALGO_SZ_LOSSY) {
|
||||
// decompress lossy
|
||||
return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
|
||||
} else {
|
||||
#endif
|
||||
// decompress lossless
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressFloatImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressFloatImp(buffer, nelements, output);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TD_TSZ
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressDouble(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||
int32_t bufferSize) {
|
||||
#ifdef TD_TSZ
|
||||
if (lossyDouble) {
|
||||
// lossy mode
|
||||
return tsCompressDoubleLossyImp(input, nelements, output);
|
||||
} else {
|
||||
#endif
|
||||
// lossless mode
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressDoubleImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressDoubleImp(input, nelements, buffer);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TD_TSZ
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressDouble(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
#ifdef TD_TSZ
|
||||
if (HEAD_ALGO(input[0]) == ALGO_SZ_LOSSY) {
|
||||
// decompress lossy
|
||||
return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
|
||||
} else {
|
||||
#endif
|
||||
// decompress lossless
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressDoubleImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressDoubleImp(buffer, nelements, output);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TD_TSZ
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TD_TSZ
|
||||
//
|
||||
// lossy float double
|
||||
//
|
||||
static FORCE_INLINE int32_t tsCompressFloatLossy(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
|
@ -358,33 +83,56 @@ static FORCE_INLINE int32_t tsDecompressDoubleLossy(const char *const input, int
|
|||
|
||||
#endif
|
||||
|
||||
static FORCE_INLINE int32_t tsCompressTimestamp(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||
char *const output, int32_t outputSize, char algorithm,
|
||||
char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsCompressTimestampImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressTimestampImp(input, nelements, buffer);
|
||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/*************************************************************************
|
||||
* REGULAR COMPRESSION
|
||||
*************************************************************************/
|
||||
int32_t tsCompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg,
|
||||
void *pBuf, int32_t nBuf);
|
||||
int32_t tsCompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsCompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsCompressString(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressString(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsCompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsCompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg,
|
||||
void *pBuf, int32_t nBuf);
|
||||
int32_t tsCompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsCompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
int32_t tsDecompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
|
||||
int32_t nBuf);
|
||||
|
||||
static FORCE_INLINE int32_t tsDecompressTimestamp(const char *const input, int32_t compressedSize,
|
||||
const int32_t nelements, char *const output, int32_t outputSize,
|
||||
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||
if (algorithm == ONE_STAGE_COMP) {
|
||||
return tsDecompressTimestampImp(input, nelements, output);
|
||||
} else if (algorithm == TWO_STAGE_COMP) {
|
||||
if (tsDecompressStringImp(input, compressedSize, buffer, bufferSize) < 0) return -1;
|
||||
return tsDecompressTimestampImp(buffer, nelements, output);
|
||||
} else {
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/*************************************************************************
|
||||
* STREAM COMPRESSION
|
||||
*************************************************************************/
|
||||
typedef struct SCompressor SCompressor;
|
||||
|
||||
int32_t tCompressorCreate(SCompressor **ppCmprsor);
|
||||
int32_t tCompressorDestroy(SCompressor *pCmprsor);
|
||||
int32_t tCompressStart(SCompressor *pCmprsor, int8_t type, int8_t cmprAlg);
|
||||
int32_t tCompressEnd(SCompressor *pCmprsor, const uint8_t **ppOut, int32_t *nOut, int32_t *nOrigin);
|
||||
int32_t tCompress(SCompressor *pCmprsor, const void *pData, int64_t nData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -33,105 +33,21 @@ typedef struct {
|
|||
|
||||
// SValue
|
||||
int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) {
|
||||
int32_t n = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
n += tPutBinary(p ? p + n : p, pValue->pData, pValue->nData);
|
||||
return tPutBinary(p, pValue->pData, pValue->nData);
|
||||
} else {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
n += tPutI8(p ? p + n : p, pValue->i8 ? 1 : 0);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
n += tPutI8(p ? p + n : p, pValue->i8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
n += tPutI16(p ? p + n : p, pValue->i16);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
n += tPutI32(p ? p + n : p, pValue->i32);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
n += tPutI64(p ? p + n : p, pValue->i64);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
n += tPutFloat(p ? p + n : p, pValue->f);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
n += tPutDouble(p ? p + n : p, pValue->d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
n += tPutI64(p ? p + n : p, pValue->ts);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
n += tPutU8(p ? p + n : p, pValue->u8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
n += tPutU16(p ? p + n : p, pValue->u16);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
n += tPutU32(p ? p + n : p, pValue->u32);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
n += tPutU64(p ? p + n : p, pValue->u64);
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
if (p) memcpy(p, &pValue->val, tDataTypes[type].bytes);
|
||||
return tDataTypes[type].bytes;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) {
|
||||
int32_t n = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
n += tGetBinary(p, &pValue->pData, pValue ? &pValue->nData : NULL);
|
||||
return tGetBinary(p, &pValue->pData, pValue ? &pValue->nData : NULL);
|
||||
} else {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
n += tGetI8(p, &pValue->i8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
n += tGetI8(p, &pValue->i8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
n += tGetI16(p, &pValue->i16);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
n += tGetI32(p, &pValue->i32);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
n += tGetI64(p, &pValue->i64);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
n += tGetFloat(p, &pValue->f);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
n += tGetDouble(p, &pValue->d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
n += tGetI64(p, &pValue->ts);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
n += tGetU8(p, &pValue->u8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
n += tGetU16(p, &pValue->u16);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
n += tGetU32(p, &pValue->u32);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
n += tGetU64(p, &pValue->u64);
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
memcpy(&pValue->val, p, tDataTypes[type].bytes);
|
||||
return tDataTypes[type].bytes;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type) {
|
||||
|
@ -1219,288 +1135,397 @@ static FORCE_INLINE int32_t tColDataPutValue(SColData *pColData, SColVal *pColVa
|
|||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue0(SColData *pColData, SColVal *pColVal) { // 0
|
||||
static FORCE_INLINE int32_t tColDataAppendValue00(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
pColData->flag = HAS_NONE;
|
||||
} else if (COL_VAL_IS_NULL(pColVal)) {
|
||||
pColData->flag = HAS_NULL;
|
||||
} else {
|
||||
pColData->flag = HAS_VALUE;
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue1(SColData *pColData, SColVal *pColVal) { // HAS_NONE
|
||||
int32_t code = 0;
|
||||
|
||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) goto _exit;
|
||||
|
||||
memset(pColData->pBitMap, 0, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
if (COL_VAL_IS_NULL(pColVal)) {
|
||||
pColData->flag |= HAS_NULL;
|
||||
} else {
|
||||
pColData->flag |= HAS_VALUE;
|
||||
|
||||
if (pColData->nVal) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) {
|
||||
int32_t nOffset = sizeof(int32_t) * pColData->nVal;
|
||||
code = tRealloc((uint8_t **)(&pColData->aOffset), nOffset);
|
||||
if (code) goto _exit;
|
||||
memset(pColData->aOffset, 0, nOffset);
|
||||
} else {
|
||||
pColData->nData = tDataTypes[pColData->type].bytes * pColData->nVal;
|
||||
code = tRealloc(&pColData->pData, pColData->nData);
|
||||
if (code) goto _exit;
|
||||
memset(pColData->pData, 0, pColData->nData);
|
||||
}
|
||||
}
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
}
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue2(SColData *pColData, SColVal *pColVal) { // HAS_NULL
|
||||
int32_t code = 0;
|
||||
|
||||
if (!COL_VAL_IS_NULL(pColVal)) {
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) goto _exit;
|
||||
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
pColData->flag |= HAS_NONE;
|
||||
|
||||
memset(pColData->pBitMap, 255, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
} else {
|
||||
pColData->flag |= HAS_VALUE;
|
||||
|
||||
memset(pColData->pBitMap, 0, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
if (pColData->nVal) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) {
|
||||
int32_t nOffset = sizeof(int32_t) * pColData->nVal;
|
||||
code = tRealloc((uint8_t **)(&pColData->aOffset), nOffset);
|
||||
if (code) goto _exit;
|
||||
memset(pColData->aOffset, 0, nOffset);
|
||||
} else {
|
||||
pColData->nData = tDataTypes[pColData->type].bytes * pColData->nVal;
|
||||
code = tRealloc(&pColData->pData, pColData->nData);
|
||||
if (code) goto _exit;
|
||||
memset(pColData->pData, 0, pColData->nData);
|
||||
}
|
||||
}
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
}
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue3(SColData *pColData, SColVal *pColVal) { // HAS_NULL|HAS_NONE
|
||||
int32_t code = 0;
|
||||
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
} else if (COL_VAL_IS_NULL(pColVal)) {
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
} else {
|
||||
pColData->flag |= HAS_VALUE;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal));
|
||||
}
|
||||
SET_BIT2(pBitMap, pColData->nVal, 2);
|
||||
|
||||
tFree(pColData->pBitMap);
|
||||
pColData->pBitMap = pBitMap;
|
||||
|
||||
if (pColData->nVal) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) {
|
||||
int32_t nOffset = sizeof(int32_t) * pColData->nVal;
|
||||
code = tRealloc((uint8_t **)(&pColData->aOffset), nOffset);
|
||||
if (code) goto _exit;
|
||||
memset(pColData->aOffset, 0, nOffset);
|
||||
} else {
|
||||
pColData->nData = tDataTypes[pColData->type].bytes * pColData->nVal;
|
||||
code = tRealloc(&pColData->pData, pColData->nData);
|
||||
if (code) goto _exit;
|
||||
memset(pColData->pData, 0, pColData->nData);
|
||||
}
|
||||
}
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue4(SColData *pColData, SColVal *pColVal) { // HAS_VALUE
|
||||
int32_t code = 0;
|
||||
|
||||
if (!COL_VAL_IS_VALUE(pColVal)) {
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
pColData->flag |= HAS_NONE;
|
||||
} else {
|
||||
pColData->flag |= HAS_NULL;
|
||||
}
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) goto _exit;
|
||||
|
||||
memset(pColData->pBitMap, 255, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue5(SColData *pColData, SColVal *pColVal) { // HAS_VALUE|HAS_NONE
|
||||
int32_t code = 0;
|
||||
|
||||
if (COL_VAL_IS_NULL(pColVal)) {
|
||||
pColData->flag |= HAS_NULL;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal) ? 2 : 0);
|
||||
}
|
||||
SET_BIT2(pBitMap, pColData->nVal, 1);
|
||||
|
||||
tFree(pColData->pBitMap);
|
||||
pColData->pBitMap = pBitMap;
|
||||
} else {
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
} else {
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
}
|
||||
}
|
||||
pColData->flag = HAS_VALUE;
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
|
||||
if (code) return code;
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue6(SColData *pColData, SColVal *pColVal) { // HAS_VALUE|HAS_NULL
|
||||
static FORCE_INLINE int32_t tColDataAppendValue01(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
pColData->flag = HAS_NONE;
|
||||
pColData->nVal++;
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue02(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
pColData->flag = HAS_NULL;
|
||||
pColData->nVal++;
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue10(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
pColData->flag |= HAS_NONE;
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
memset(pColData->pBitMap, 0, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal) ? 2 : 1);
|
||||
}
|
||||
SET_BIT2(pBitMap, pColData->nVal, 0);
|
||||
pColData->flag |= HAS_VALUE;
|
||||
|
||||
tFree(pColData->pBitMap);
|
||||
pColData->pBitMap = pBitMap;
|
||||
} else {
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
|
||||
if (COL_VAL_IS_NULL(pColVal)) {
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
if (pColData->nVal) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) {
|
||||
int32_t nOffset = sizeof(int32_t) * pColData->nVal;
|
||||
code = tRealloc((uint8_t **)(&pColData->aOffset), nOffset);
|
||||
if (code) return code;
|
||||
memset(pColData->aOffset, 0, nOffset);
|
||||
} else {
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
pColData->nData = tDataTypes[pColData->type].bytes * pColData->nVal;
|
||||
code = tRealloc(&pColData->pData, pColData->nData);
|
||||
if (code) return code;
|
||||
memset(pColData->pData, 0, pColData->nData);
|
||||
}
|
||||
}
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
if (code) return code;
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue11(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
pColData->nVal++;
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue12(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pColData->pBitMap, 0, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
pColData->flag |= HAS_NULL;
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue20(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pColData->pBitMap, 0, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
pColData->flag |= HAS_VALUE;
|
||||
|
||||
if (pColData->nVal) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) {
|
||||
int32_t nOffset = sizeof(int32_t) * pColData->nVal;
|
||||
code = tRealloc((uint8_t **)(&pColData->aOffset), nOffset);
|
||||
if (code) return code;
|
||||
memset(pColData->aOffset, 0, nOffset);
|
||||
} else {
|
||||
pColData->nData = tDataTypes[pColData->type].bytes * pColData->nVal;
|
||||
code = tRealloc(&pColData->pData, pColData->nData);
|
||||
if (code) return code;
|
||||
memset(pColData->pData, 0, pColData->nData);
|
||||
}
|
||||
}
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue21(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pColData->pBitMap, 255, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
pColData->flag |= HAS_NONE;
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue22(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
pColData->nVal++;
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue30(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pColData->flag |= HAS_VALUE;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal));
|
||||
}
|
||||
SET_BIT2(pBitMap, pColData->nVal, 2);
|
||||
|
||||
tFree(pColData->pBitMap);
|
||||
pColData->pBitMap = pBitMap;
|
||||
|
||||
if (pColData->nVal) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) {
|
||||
int32_t nOffset = sizeof(int32_t) * pColData->nVal;
|
||||
code = tRealloc((uint8_t **)(&pColData->aOffset), nOffset);
|
||||
if (code) return code;
|
||||
memset(pColData->aOffset, 0, nOffset);
|
||||
} else {
|
||||
pColData->nData = tDataTypes[pColData->type].bytes * pColData->nVal;
|
||||
code = tRealloc(&pColData->pData, pColData->nData);
|
||||
if (code) return code;
|
||||
memset(pColData->pData, 0, pColData->nData);
|
||||
}
|
||||
}
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue31(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue32(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue40(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue41(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pColData->flag |= HAS_NONE;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pColData->pBitMap, 255, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue7(SColData *pColData,
|
||||
SColVal *pColVal) { // HAS_VALUE|HAS_NULL|HAS_NONE
|
||||
static FORCE_INLINE int32_t tColDataAppendValue42(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pColData->flag |= HAS_NULL;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pColData->nVal + 1);
|
||||
code = tRealloc(&pColData->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pColData->pBitMap, 255, nBit);
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue50(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue51(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue52(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pColData->flag |= HAS_NULL;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal) ? 2 : 0);
|
||||
}
|
||||
SET_BIT2(pBitMap, pColData->nVal, 1);
|
||||
|
||||
tFree(pColData->pBitMap);
|
||||
pColData->pBitMap = pBitMap;
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue60(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue61(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pColData->flag |= HAS_NONE;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pColData->pBitMap, iVal) ? 2 : 1);
|
||||
}
|
||||
SET_BIT2(pBitMap, pColData->nVal, 0);
|
||||
|
||||
tFree(pColData->pBitMap);
|
||||
pColData->pBitMap = pBitMap;
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue62(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT1_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue70(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) goto _exit;
|
||||
if (code) return code;
|
||||
SET_BIT2(pColData->pBitMap, pColData->nVal, 2);
|
||||
|
||||
if (COL_VAL_IS_NONE(pColVal)) {
|
||||
SET_BIT2(pColData->pBitMap, pColData->nVal, 0);
|
||||
} else if (COL_VAL_IS_NULL(pColVal)) {
|
||||
SET_BIT2(pColData->pBitMap, pColData->nVal, 1);
|
||||
} else {
|
||||
SET_BIT2(pColData->pBitMap, pColData->nVal, 2);
|
||||
}
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) goto _exit;
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
static int32_t (*tColDataAppendValueImpl[])(SColData *pColData, SColVal *pColVal) = {
|
||||
tColDataAppendValue0, // 0
|
||||
tColDataAppendValue1, // HAS_NONE
|
||||
tColDataAppendValue2, // HAS_NULL
|
||||
tColDataAppendValue3, // HAS_NULL|HAS_NONE
|
||||
tColDataAppendValue4, // HAS_VALUE
|
||||
tColDataAppendValue5, // HAS_VALUE|HAS_NONE
|
||||
tColDataAppendValue6, // HAS_VALUE|HAS_NULL
|
||||
tColDataAppendValue7 // HAS_VALUE|HAS_NULL|HAS_NONE
|
||||
static FORCE_INLINE int32_t tColDataAppendValue71(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT2(pColData->pBitMap, pColData->nVal, 0);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tColDataAppendValue72(SColData *pColData, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pColData->pBitMap, BIT2_SIZE(pColData->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT2(pColData->pBitMap, pColData->nVal, 1);
|
||||
|
||||
code = tColDataPutValue(pColData, pColVal);
|
||||
if (code) return code;
|
||||
|
||||
pColData->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
static int32_t (*tColDataAppendValueImpl[8][3])(SColData *pColData, SColVal *pColVal) = {
|
||||
{tColDataAppendValue00, tColDataAppendValue01, tColDataAppendValue02}, // 0
|
||||
{tColDataAppendValue10, tColDataAppendValue11, tColDataAppendValue12}, // HAS_NONE
|
||||
{tColDataAppendValue20, tColDataAppendValue21, tColDataAppendValue22}, // HAS_NULL
|
||||
{tColDataAppendValue30, tColDataAppendValue31, tColDataAppendValue32}, // HAS_NULL|HAS_NONE
|
||||
{tColDataAppendValue40, tColDataAppendValue41, tColDataAppendValue42}, // HAS_VALUE
|
||||
{tColDataAppendValue50, tColDataAppendValue51, tColDataAppendValue52}, // HAS_VALUE|HAS_NONE
|
||||
{tColDataAppendValue60, tColDataAppendValue61, tColDataAppendValue62}, // HAS_VALUE|HAS_NULL
|
||||
{tColDataAppendValue70, tColDataAppendValue71, tColDataAppendValue72}, // HAS_VALUE|HAS_NULL|HAS_NONE
|
||||
};
|
||||
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) {
|
||||
ASSERT(pColData->cid == pColVal->cid && pColData->type == pColVal->type);
|
||||
return tColDataAppendValueImpl[pColData->flag](pColData, pColVal);
|
||||
return tColDataAppendValueImpl[pColData->flag][pColVal->flag](pColData, pColVal);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tColDataGetValue1(SColData *pColData, int32_t iVal, SColVal *pColVal) { // HAS_NONE
|
||||
|
|
|
@ -689,7 +689,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) {
|
|||
memcpy(varDataVal(varBuf), pColVal->value.pData, pColVal->value.nData);
|
||||
val = varBuf;
|
||||
} else {
|
||||
val = (const void *)&pColVal->value.i64;
|
||||
val = (const void *)&pColVal->value.val;
|
||||
}
|
||||
} else {
|
||||
pColVal = NULL;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <taoserror.h>
|
||||
|
@ -476,4 +477,5 @@ TEST(testCase, NoneTest) {
|
|||
taosArrayDestroy(pArray);
|
||||
taosMemoryFree(pTSchema);
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -38,39 +38,43 @@ extern "C" {
|
|||
goto LABEL; \
|
||||
}
|
||||
|
||||
typedef struct TSDBROW TSDBROW;
|
||||
typedef struct TABLEID TABLEID;
|
||||
typedef struct TSDBKEY TSDBKEY;
|
||||
typedef struct SDelData SDelData;
|
||||
typedef struct SDelIdx SDelIdx;
|
||||
typedef struct STbData STbData;
|
||||
typedef struct SMemTable SMemTable;
|
||||
typedef struct STbDataIter STbDataIter;
|
||||
typedef struct SMapData SMapData;
|
||||
typedef struct SBlockIdx SBlockIdx;
|
||||
typedef struct SDataBlk SDataBlk;
|
||||
typedef struct SSttBlk SSttBlk;
|
||||
typedef struct SDiskDataHdr SDiskDataHdr;
|
||||
typedef struct SBlockData SBlockData;
|
||||
typedef struct SDelFile SDelFile;
|
||||
typedef struct SHeadFile SHeadFile;
|
||||
typedef struct SDataFile SDataFile;
|
||||
typedef struct SSttFile SSttFile;
|
||||
typedef struct SSmaFile SSmaFile;
|
||||
typedef struct SDFileSet SDFileSet;
|
||||
typedef struct SDataFWriter SDataFWriter;
|
||||
typedef struct SDataFReader SDataFReader;
|
||||
typedef struct SDelFWriter SDelFWriter;
|
||||
typedef struct SDelFReader SDelFReader;
|
||||
typedef struct SRowIter SRowIter;
|
||||
typedef struct STsdbFS STsdbFS;
|
||||
typedef struct SRowMerger SRowMerger;
|
||||
typedef struct STsdbReadSnap STsdbReadSnap;
|
||||
typedef struct SBlockInfo SBlockInfo;
|
||||
typedef struct SSmaInfo SSmaInfo;
|
||||
typedef struct SBlockCol SBlockCol;
|
||||
typedef struct SVersionRange SVersionRange;
|
||||
typedef struct SLDataIter SLDataIter;
|
||||
typedef struct TSDBROW TSDBROW;
|
||||
typedef struct TABLEID TABLEID;
|
||||
typedef struct TSDBKEY TSDBKEY;
|
||||
typedef struct SDelData SDelData;
|
||||
typedef struct SDelIdx SDelIdx;
|
||||
typedef struct STbData STbData;
|
||||
typedef struct SMemTable SMemTable;
|
||||
typedef struct STbDataIter STbDataIter;
|
||||
typedef struct SMapData SMapData;
|
||||
typedef struct SBlockIdx SBlockIdx;
|
||||
typedef struct SDataBlk SDataBlk;
|
||||
typedef struct SSttBlk SSttBlk;
|
||||
typedef struct SDiskDataHdr SDiskDataHdr;
|
||||
typedef struct SBlockData SBlockData;
|
||||
typedef struct SDelFile SDelFile;
|
||||
typedef struct SHeadFile SHeadFile;
|
||||
typedef struct SDataFile SDataFile;
|
||||
typedef struct SSttFile SSttFile;
|
||||
typedef struct SSmaFile SSmaFile;
|
||||
typedef struct SDFileSet SDFileSet;
|
||||
typedef struct SDataFWriter SDataFWriter;
|
||||
typedef struct SDataFReader SDataFReader;
|
||||
typedef struct SDelFWriter SDelFWriter;
|
||||
typedef struct SDelFReader SDelFReader;
|
||||
typedef struct SRowIter SRowIter;
|
||||
typedef struct STsdbFS STsdbFS;
|
||||
typedef struct SRowMerger SRowMerger;
|
||||
typedef struct STsdbReadSnap STsdbReadSnap;
|
||||
typedef struct SBlockInfo SBlockInfo;
|
||||
typedef struct SSmaInfo SSmaInfo;
|
||||
typedef struct SBlockCol SBlockCol;
|
||||
typedef struct SVersionRange SVersionRange;
|
||||
typedef struct SLDataIter SLDataIter;
|
||||
typedef struct SDiskCol SDiskCol;
|
||||
typedef struct SDiskData SDiskData;
|
||||
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
||||
typedef struct SBlkInfo SBlkInfo;
|
||||
|
||||
#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F)
|
||||
#define TSDB_MAX_SUBBLOCKS 8
|
||||
|
@ -170,7 +174,7 @@ int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut
|
|||
int32_t aBufN[]);
|
||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]);
|
||||
// SDiskDataHdr
|
||||
int32_t tPutDiskDataHdr(uint8_t *p, void *ph);
|
||||
int32_t tPutDiskDataHdr(uint8_t *p, const SDiskDataHdr *pHdr);
|
||||
int32_t tGetDiskDataHdr(uint8_t *p, void *ph);
|
||||
// SDelIdx
|
||||
int32_t tPutDelIdx(uint8_t *p, void *ph);
|
||||
|
@ -267,6 +271,7 @@ int32_t tsdbWriteDataBlk(SDataFWriter *pWriter, SMapData *mDataBlk, SBlockIdx *p
|
|||
int32_t tsdbWriteSttBlk(SDataFWriter *pWriter, SArray *aSttBlk);
|
||||
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo,
|
||||
int8_t cmprAlg, int8_t toLast);
|
||||
int32_t tsdbWriteDiskData(SDataFWriter *pWriter, const SDiskData *pDiskData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo);
|
||||
|
||||
int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo);
|
||||
// SDataFReader
|
||||
|
@ -300,7 +305,7 @@ int32_t tsdbMerge(STsdb *pTsdb);
|
|||
#define TSDB_CACHE_LAST_ROW(c) (((c).cacheLast & 1) > 0)
|
||||
#define TSDB_CACHE_LAST(c) (((c).cacheLast & 2) > 0)
|
||||
|
||||
// tsdbCache
|
||||
// tsdbCache ==============================================================================================
|
||||
int32_t tsdbOpenCache(STsdb *pTsdb);
|
||||
void tsdbCloseCache(STsdb *pTsdb);
|
||||
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb);
|
||||
|
@ -318,6 +323,15 @@ size_t tsdbCacheGetCapacity(SVnode *pVnode);
|
|||
|
||||
int32_t tsdbCacheLastArray2Row(SArray *pLastArray, STSRow **ppRow, STSchema *pSchema);
|
||||
|
||||
// tsdbDiskData ==============================================================================================
|
||||
int32_t tDiskDataBuilderCreate(SDiskDataBuilder **ppBuilder);
|
||||
void *tDiskDataBuilderDestroy(SDiskDataBuilder *pBuilder);
|
||||
int32_t tDiskDataBuilderInit(SDiskDataBuilder *pBuilder, STSchema *pTSchema, TABLEID *pId, uint8_t cmprAlg,
|
||||
uint8_t calcSma);
|
||||
int32_t tDiskDataBuilderClear(SDiskDataBuilder *pBuilder);
|
||||
int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTSchema, TABLEID *pId);
|
||||
int32_t tGnrtDiskData(SDiskDataBuilder *pBuilder, const SDiskData **ppDiskData, const SBlkInfo **ppBlkInfo);
|
||||
|
||||
// structs =======================
|
||||
struct STsdbFS {
|
||||
SDelFile *pDelFile;
|
||||
|
@ -438,6 +452,17 @@ struct SSmaInfo {
|
|||
int32_t size;
|
||||
};
|
||||
|
||||
struct SBlkInfo {
|
||||
int64_t minUid;
|
||||
int64_t maxUid;
|
||||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
TSDBKEY minTKey;
|
||||
TSDBKEY maxTKey;
|
||||
};
|
||||
|
||||
struct SDataBlk {
|
||||
TSDBKEY minKey;
|
||||
TSDBKEY maxKey;
|
||||
|
@ -661,6 +686,38 @@ typedef struct {
|
|||
STSchema *pTSchema;
|
||||
} SSkmInfo;
|
||||
|
||||
struct SDiskCol {
|
||||
SBlockCol bCol;
|
||||
const uint8_t *pBit;
|
||||
const uint8_t *pOff;
|
||||
const uint8_t *pVal;
|
||||
SColumnDataAgg agg;
|
||||
};
|
||||
|
||||
struct SDiskData {
|
||||
SDiskDataHdr hdr;
|
||||
const uint8_t *pUid;
|
||||
const uint8_t *pVer;
|
||||
const uint8_t *pKey;
|
||||
SArray *aDiskCol; // SArray<SDiskCol>
|
||||
};
|
||||
|
||||
struct SDiskDataBuilder {
|
||||
int64_t suid;
|
||||
int64_t uid;
|
||||
int32_t nRow;
|
||||
uint8_t cmprAlg;
|
||||
uint8_t calcSma;
|
||||
SCompressor *pUidC;
|
||||
SCompressor *pVerC;
|
||||
SCompressor *pKeyC;
|
||||
int32_t nBuilder;
|
||||
SArray *aBuilder; // SArray<SDiskColBuilder>
|
||||
uint8_t *aBuf[2];
|
||||
SDiskData dd;
|
||||
SBlkInfo bi;
|
||||
};
|
||||
|
||||
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
|
||||
STimeWindow *pTimeWindow, SVersionRange *pVerRange, SSttBlockLoadInfo *pBlockLoadInfo,
|
||||
bool destroyLoadInfo, const char *idStr);
|
||||
|
|
|
@ -260,7 +260,7 @@ int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb
|
|||
SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||
if (keyTs > tTsVal->ts) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = keyTs});
|
||||
SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = keyTs});
|
||||
|
||||
taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = tColVal});
|
||||
}
|
||||
|
@ -1052,7 +1052,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo
|
|||
lastRowTs = TSDBROW_TS(pRow);
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = lastRowTs});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = lastRowTs});
|
||||
if (taosArrayPush(pColArray, pColVal) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
|
@ -1151,7 +1151,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) {
|
|||
lastRowTs = rowTs;
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = lastRowTs});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = lastRowTs});
|
||||
if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,69 +16,682 @@
|
|||
#include "tsdb.h"
|
||||
|
||||
typedef struct SDiskColBuilder SDiskColBuilder;
|
||||
|
||||
struct SDiskColBuilder {
|
||||
uint8_t flags;
|
||||
uint8_t *pBitMap;
|
||||
int32_t *aOffset;
|
||||
int32_t nData;
|
||||
uint8_t *pData;
|
||||
int16_t cid;
|
||||
int8_t type;
|
||||
uint8_t cmprAlg;
|
||||
uint8_t calcSma;
|
||||
int8_t flag;
|
||||
int32_t nVal;
|
||||
uint8_t *pBitMap;
|
||||
int32_t offset;
|
||||
SCompressor *pOffC;
|
||||
SCompressor *pValC;
|
||||
SColumnDataAgg sma;
|
||||
uint8_t minSet;
|
||||
uint8_t maxSet;
|
||||
uint8_t *aBuf[2];
|
||||
};
|
||||
|
||||
int32_t tDiskColAddVal(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
// SDiskData ================================================
|
||||
static int32_t tDiskDataDestroy(SDiskData *pDiskData) {
|
||||
int32_t code = 0;
|
||||
// TODO
|
||||
pDiskData->aDiskCol = taosArrayDestroy(pDiskData->aDiskCol);
|
||||
return code;
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
||||
struct SDiskDataBuilder {
|
||||
SDiskDataHdr hdr;
|
||||
SArray *aBlockCol; // SArray<SBlockCol>
|
||||
};
|
||||
// SDiskColBuilder ================================================
|
||||
#define tDiskColBuilderCreate() \
|
||||
(SDiskColBuilder) { 0 }
|
||||
|
||||
int32_t tDiskDataBuilderCreate(SDiskDataBuilder **ppBuilder) {
|
||||
int32_t code = 0;
|
||||
// TODO
|
||||
return code;
|
||||
}
|
||||
|
||||
void tDiskDataBuilderDestroy(SDiskDataBuilder *pBuilder) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void tDiskDataBuilderInit(SDiskDataBuilder *pBuilder, int64_t suid, int64_t uid, STSchema *pTSchema, int8_t cmprAlg) {
|
||||
pBuilder->hdr = (SDiskDataHdr){.delimiter = TSDB_FILE_DLMT, //
|
||||
.fmtVer = 0,
|
||||
.suid = suid,
|
||||
.uid = uid,
|
||||
.cmprAlg = cmprAlg};
|
||||
}
|
||||
|
||||
void tDiskDataBuilderReset(SDiskDataBuilder *pBuilder) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
int32_t tDiskDataBuilderAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTSchema, int64_t uid) {
|
||||
static int32_t tDiskColBuilderDestroy(SDiskColBuilder *pBuilder) {
|
||||
int32_t code = 0;
|
||||
|
||||
// uid (todo)
|
||||
|
||||
// version (todo)
|
||||
|
||||
// TSKEY (todo)
|
||||
|
||||
SRowIter iter = {0};
|
||||
tRowIterInit(&iter, pRow, pTSchema);
|
||||
|
||||
for (int32_t iDiskCol = 0; iDiskCol < 0; iDiskCol++) {
|
||||
tFree(pBuilder->pBitMap);
|
||||
if (pBuilder->pOffC) tCompressorDestroy(pBuilder->pOffC);
|
||||
if (pBuilder->pValC) tCompressorDestroy(pBuilder->pValC);
|
||||
for (int32_t iBuf = 0; iBuf < sizeof(pBuilder->aBuf) / sizeof(pBuilder->aBuf[0]); iBuf++) {
|
||||
tFree(pBuilder->aBuf[iBuf]);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tDiskDataBuilderGet(SDiskDataBuilder *pBuilder, uint8_t **ppData) {
|
||||
static int32_t tDiskColBuilderInit(SDiskColBuilder *pBuilder, int16_t cid, int8_t type, uint8_t cmprAlg,
|
||||
uint8_t calcSma) {
|
||||
int32_t code = 0;
|
||||
// TODO
|
||||
|
||||
pBuilder->cid = cid;
|
||||
pBuilder->type = type;
|
||||
pBuilder->cmprAlg = cmprAlg;
|
||||
pBuilder->calcSma = IS_VAR_DATA_TYPE(type) ? 0 : calcSma;
|
||||
pBuilder->flag = 0;
|
||||
pBuilder->nVal = 0;
|
||||
pBuilder->offset = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
if (pBuilder->pOffC == NULL && (code = tCompressorCreate(&pBuilder->pOffC))) return code;
|
||||
code = tCompressStart(pBuilder->pOffC, TSDB_DATA_TYPE_INT, cmprAlg);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
if (pBuilder->pValC == NULL && (code = tCompressorCreate(&pBuilder->pValC))) return code;
|
||||
code = tCompressStart(pBuilder->pValC, type, cmprAlg);
|
||||
if (code) return code;
|
||||
|
||||
if (pBuilder->calcSma) {
|
||||
pBuilder->sma = (SColumnDataAgg){.colId = cid};
|
||||
pBuilder->minSet = 0;
|
||||
pBuilder->maxSet = 0;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t tGnrtDiskCol(SDiskColBuilder *pBuilder, SDiskCol *pDiskCol) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(pBuilder->flag && pBuilder->flag != HAS_NONE);
|
||||
|
||||
*pDiskCol = (SDiskCol){(SBlockCol){.cid = pBuilder->cid,
|
||||
.type = pBuilder->type,
|
||||
.smaOn = pBuilder->calcSma,
|
||||
.flag = pBuilder->flag,
|
||||
.szOrigin = 0,
|
||||
.szBitmap = 0,
|
||||
.szOffset = 0,
|
||||
.szValue = 0,
|
||||
.offset = 0},
|
||||
.pBit = NULL, .pOff = NULL, .pVal = NULL, .agg = pBuilder->sma};
|
||||
|
||||
if (pBuilder->flag == HAS_NULL) return code;
|
||||
|
||||
// BITMAP
|
||||
if (pBuilder->flag != HAS_VALUE) {
|
||||
int32_t nBit;
|
||||
if (pBuilder->flag == (HAS_VALUE | HAS_NULL | HAS_NONE)) {
|
||||
nBit = BIT2_SIZE(pBuilder->nVal);
|
||||
} else {
|
||||
nBit = BIT1_SIZE(pBuilder->nVal);
|
||||
}
|
||||
|
||||
code = tRealloc(&pBuilder->aBuf[0], nBit + COMP_OVERFLOW_BYTES);
|
||||
if (code) return code;
|
||||
|
||||
code = tRealloc(&pBuilder->aBuf[1], nBit + COMP_OVERFLOW_BYTES);
|
||||
if (code) return code;
|
||||
|
||||
pDiskCol->bCol.szBitmap =
|
||||
tsCompressTinyint(pBuilder->pBitMap, nBit, nBit, pBuilder->aBuf[0], nBit + COMP_OVERFLOW_BYTES,
|
||||
pBuilder->cmprAlg, pBuilder->aBuf[1], nBit + COMP_OVERFLOW_BYTES);
|
||||
pDiskCol->pBit = pBuilder->aBuf[0];
|
||||
}
|
||||
|
||||
// OFFSET
|
||||
if (IS_VAR_DATA_TYPE(pBuilder->type)) {
|
||||
code = tCompressEnd(pBuilder->pOffC, &pDiskCol->pOff, &pDiskCol->bCol.szOffset, NULL);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
// VALUE
|
||||
if (pBuilder->flag != (HAS_NULL | HAS_NONE)) {
|
||||
code = tCompressEnd(pBuilder->pValC, &pDiskCol->pVal, &pDiskCol->bCol.szValue, &pDiskCol->bCol.szOrigin);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDiskColPutValue(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||
code = tCompress(pBuilder->pOffC, &pBuilder->offset, sizeof(int32_t));
|
||||
if (code) return code;
|
||||
pBuilder->offset += pColVal->value.nData;
|
||||
|
||||
code = tCompress(pBuilder->pValC, pColVal->value.pData, pColVal->value.nData);
|
||||
if (code) return code;
|
||||
} else {
|
||||
code = tCompress(pBuilder->pValC, &pColVal->value.val, tDataTypes[pColVal->type].bytes);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal00(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
pBuilder->flag = HAS_VALUE;
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal01(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
pBuilder->flag = HAS_NONE;
|
||||
return 0;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal02(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
pBuilder->flag = HAS_NULL;
|
||||
return 0;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal10(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
// bit map
|
||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pBuilder->pBitMap, 0, nBit);
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
// value
|
||||
pBuilder->flag |= HAS_VALUE;
|
||||
|
||||
SColVal cv = COL_VAL_VALUE(pColVal->cid, pColVal->type, (SValue){0});
|
||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
||||
code = tDiskColPutValue(pBuilder, &cv);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal12(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pBuilder->pBitMap, 0, nBit);
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
pBuilder->flag |= HAS_NULL;
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal20(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
pBuilder->flag |= HAS_VALUE;
|
||||
|
||||
memset(pBuilder->pBitMap, 0, nBit);
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
SColVal cv = COL_VAL_VALUE(pColVal->cid, pColVal->type, (SValue){0});
|
||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
||||
code = tDiskColPutValue(pBuilder, &cv);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal21(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
pBuilder->flag |= HAS_NONE;
|
||||
|
||||
memset(pBuilder->pBitMap, 255, nBit);
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal30(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pBuilder->flag |= HAS_VALUE;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pBuilder->pBitMap, iVal));
|
||||
}
|
||||
SET_BIT2(pBitMap, pBuilder->nVal, 2);
|
||||
|
||||
tFree(pBuilder->pBitMap);
|
||||
pBuilder->pBitMap = pBitMap;
|
||||
|
||||
SColVal cv = COL_VAL_VALUE(pColVal->cid, pColVal->type, (SValue){0});
|
||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
||||
code = tDiskColPutValue(pBuilder, &cv);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal31(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal32(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
return code;
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal40(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal41(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pBuilder->flag |= HAS_NONE;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pBuilder->pBitMap, 255, nBit);
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal42(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pBuilder->flag |= HAS_NULL;
|
||||
|
||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
||||
if (code) return code;
|
||||
|
||||
memset(pBuilder->pBitMap, 255, nBit);
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal50(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal51(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal52(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pBuilder->flag |= HAS_NULL;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pBuilder->pBitMap, iVal) ? 2 : 0);
|
||||
}
|
||||
SET_BIT2(pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
tFree(pBuilder->pBitMap);
|
||||
pBuilder->pBitMap = pBitMap;
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal60(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal61(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
pBuilder->flag |= HAS_NONE;
|
||||
|
||||
uint8_t *pBitMap = NULL;
|
||||
code = tRealloc(&pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
|
||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pBuilder->pBitMap, iVal) ? 2 : 1);
|
||||
}
|
||||
SET_BIT2(pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
tFree(pBuilder->pBitMap);
|
||||
pBuilder->pBitMap = pBitMap;
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal62(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal70(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT2(pBuilder->pBitMap, pBuilder->nVal, 2);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal71(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT2(pBuilder->pBitMap, pBuilder->nVal, 0);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDiskColAddVal72(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tRealloc(&pBuilder->pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
||||
if (code) return code;
|
||||
SET_BIT2(pBuilder->pBitMap, pBuilder->nVal, 1);
|
||||
|
||||
return tDiskColPutValue(pBuilder, pColVal);
|
||||
}
|
||||
static int32_t (*tDiskColAddValImpl[8][3])(SDiskColBuilder *pBuilder, SColVal *pColVal) = {
|
||||
{tDiskColAddVal00, tDiskColAddVal01, tDiskColAddVal02}, // 0
|
||||
{tDiskColAddVal10, NULL, tDiskColAddVal12}, // HAS_NONE
|
||||
{tDiskColAddVal20, tDiskColAddVal21, NULL}, // HAS_NULL
|
||||
{tDiskColAddVal30, tDiskColAddVal31, tDiskColAddVal32}, // HAS_NULL|HAS_NONE
|
||||
{tDiskColAddVal40, tDiskColAddVal41, tDiskColAddVal42}, // HAS_VALUE
|
||||
{tDiskColAddVal50, tDiskColAddVal51, tDiskColAddVal52}, // HAS_VALUE|HAS_NONE
|
||||
{tDiskColAddVal60, tDiskColAddVal61, tDiskColAddVal62}, // HAS_VALUE|HAS_NULL
|
||||
{tDiskColAddVal70, tDiskColAddVal71, tDiskColAddVal72} // HAS_VALUE|HAS_NULL|HAS_NONE
|
||||
};
|
||||
extern void (*tSmaUpdateImpl[])(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet);
|
||||
static int32_t tDiskColAddVal(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (pBuilder->calcSma) {
|
||||
if (COL_VAL_IS_VALUE(pColVal)) {
|
||||
tSmaUpdateImpl[pBuilder->type](&pBuilder->sma, pColVal, &pBuilder->minSet, &pBuilder->maxSet);
|
||||
} else {
|
||||
pBuilder->sma.numOfNull++;
|
||||
}
|
||||
}
|
||||
|
||||
if (tDiskColAddValImpl[pBuilder->flag][pColVal->flag]) {
|
||||
code = tDiskColAddValImpl[pBuilder->flag][pColVal->flag](pBuilder, pColVal);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
pBuilder->nVal++;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
// SDiskDataBuilder ================================================
|
||||
int32_t tDiskDataBuilderCreate(SDiskDataBuilder **ppBuilder) {
|
||||
int32_t code = 0;
|
||||
|
||||
*ppBuilder = (SDiskDataBuilder *)taosMemoryCalloc(1, sizeof(SDiskDataBuilder));
|
||||
if (*ppBuilder == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void *tDiskDataBuilderDestroy(SDiskDataBuilder *pBuilder) {
|
||||
if (pBuilder == NULL) return NULL;
|
||||
|
||||
if (pBuilder->pUidC) tCompressorDestroy(pBuilder->pUidC);
|
||||
if (pBuilder->pVerC) tCompressorDestroy(pBuilder->pVerC);
|
||||
if (pBuilder->pKeyC) tCompressorDestroy(pBuilder->pKeyC);
|
||||
|
||||
if (pBuilder->aBuilder) {
|
||||
for (int32_t iBuilder = 0; iBuilder < taosArrayGetSize(pBuilder->aBuilder); iBuilder++) {
|
||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
|
||||
tDiskColBuilderDestroy(pDCBuilder);
|
||||
}
|
||||
taosArrayDestroy(pBuilder->aBuilder);
|
||||
}
|
||||
for (int32_t iBuf = 0; iBuf < sizeof(pBuilder->aBuf) / sizeof(pBuilder->aBuf[0]); iBuf++) {
|
||||
tFree(pBuilder->aBuf[iBuf]);
|
||||
}
|
||||
tDiskDataDestroy(&pBuilder->dd);
|
||||
taosMemoryFree(pBuilder);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t tDiskDataBuilderInit(SDiskDataBuilder *pBuilder, STSchema *pTSchema, TABLEID *pId, uint8_t cmprAlg,
|
||||
uint8_t calcSma) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(pId->suid || pId->uid);
|
||||
|
||||
pBuilder->suid = pId->suid;
|
||||
pBuilder->uid = pId->uid;
|
||||
pBuilder->nRow = 0;
|
||||
pBuilder->cmprAlg = cmprAlg;
|
||||
pBuilder->calcSma = calcSma;
|
||||
pBuilder->bi = (SBlkInfo){.minUid = INT64_MAX,
|
||||
.maxUid = INT64_MIN,
|
||||
.minKey = TSKEY_MAX,
|
||||
.maxKey = TSKEY_MIN,
|
||||
.minVer = VERSION_MAX,
|
||||
.maxVer = VERSION_MIN,
|
||||
.minTKey = TSDBKEY_MAX,
|
||||
.maxTKey = TSDBKEY_MIN};
|
||||
|
||||
if (pBuilder->pUidC == NULL && (code = tCompressorCreate(&pBuilder->pUidC))) return code;
|
||||
code = tCompressStart(pBuilder->pUidC, TSDB_DATA_TYPE_BIGINT, cmprAlg);
|
||||
if (code) return code;
|
||||
|
||||
if (pBuilder->pVerC == NULL && (code = tCompressorCreate(&pBuilder->pVerC))) return code;
|
||||
code = tCompressStart(pBuilder->pVerC, TSDB_DATA_TYPE_BIGINT, cmprAlg);
|
||||
if (code) return code;
|
||||
|
||||
if (pBuilder->pKeyC == NULL && (code = tCompressorCreate(&pBuilder->pKeyC))) return code;
|
||||
code = tCompressStart(pBuilder->pKeyC, TSDB_DATA_TYPE_TIMESTAMP, cmprAlg);
|
||||
if (code) return code;
|
||||
|
||||
if (pBuilder->aBuilder == NULL) {
|
||||
pBuilder->aBuilder = taosArrayInit(pTSchema->numOfCols - 1, sizeof(SDiskColBuilder));
|
||||
if (pBuilder->aBuilder == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
pBuilder->nBuilder = 0;
|
||||
for (int32_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) {
|
||||
STColumn *pTColumn = &pTSchema->columns[iCol];
|
||||
|
||||
if (pBuilder->nBuilder >= taosArrayGetSize(pBuilder->aBuilder)) {
|
||||
SDiskColBuilder dc = tDiskColBuilderCreate();
|
||||
if (taosArrayPush(pBuilder->aBuilder, &dc) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, pBuilder->nBuilder);
|
||||
|
||||
code = tDiskColBuilderInit(pDCBuilder, pTColumn->colId, pTColumn->type, cmprAlg,
|
||||
(calcSma && (pTColumn->flags & COL_SMA_ON)));
|
||||
if (code) return code;
|
||||
|
||||
pBuilder->nBuilder++;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tDiskDataBuilderClear(SDiskDataBuilder *pBuilder) {
|
||||
int32_t code = 0;
|
||||
pBuilder->suid = 0;
|
||||
pBuilder->uid = 0;
|
||||
pBuilder->nRow = 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTSchema, TABLEID *pId) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(pBuilder->suid || pBuilder->uid);
|
||||
ASSERT(pId->suid == pBuilder->suid);
|
||||
|
||||
TSDBKEY kRow = TSDBROW_KEY(pRow);
|
||||
if (tsdbKeyCmprFn(&pBuilder->bi.minTKey, &kRow) > 0) pBuilder->bi.minTKey = kRow;
|
||||
if (tsdbKeyCmprFn(&pBuilder->bi.maxTKey, &kRow) < 0) pBuilder->bi.maxTKey = kRow;
|
||||
|
||||
// uid
|
||||
if (pBuilder->uid && pBuilder->uid != pId->uid) {
|
||||
ASSERT(pBuilder->suid);
|
||||
for (int32_t iRow = 0; iRow < pBuilder->nRow; iRow++) {
|
||||
code = tCompress(pBuilder->pUidC, &pBuilder->uid, sizeof(int64_t));
|
||||
if (code) return code;
|
||||
}
|
||||
pBuilder->uid = 0;
|
||||
}
|
||||
if (pBuilder->uid == 0) {
|
||||
code = tCompress(pBuilder->pUidC, &pId->uid, sizeof(int64_t));
|
||||
if (code) return code;
|
||||
}
|
||||
if (pBuilder->bi.minUid > pId->uid) pBuilder->bi.minUid = pId->uid;
|
||||
if (pBuilder->bi.maxUid < pId->uid) pBuilder->bi.maxUid = pId->uid;
|
||||
|
||||
// version
|
||||
code = tCompress(pBuilder->pVerC, &kRow.version, sizeof(int64_t));
|
||||
if (code) return code;
|
||||
if (pBuilder->bi.minVer > kRow.version) pBuilder->bi.minVer = kRow.version;
|
||||
if (pBuilder->bi.maxVer < kRow.version) pBuilder->bi.maxVer = kRow.version;
|
||||
|
||||
// TSKEY
|
||||
code = tCompress(pBuilder->pKeyC, &kRow.ts, sizeof(int64_t));
|
||||
if (code) return code;
|
||||
if (pBuilder->bi.minKey > kRow.ts) pBuilder->bi.minKey = kRow.ts;
|
||||
if (pBuilder->bi.maxKey < kRow.ts) pBuilder->bi.maxKey = kRow.ts;
|
||||
|
||||
SRowIter iter = {0};
|
||||
tRowIterInit(&iter, pRow, pTSchema);
|
||||
|
||||
SColVal *pColVal = tRowIterNext(&iter);
|
||||
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
|
||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
|
||||
|
||||
while (pColVal && pColVal->cid < pDCBuilder->cid) {
|
||||
pColVal = tRowIterNext(&iter);
|
||||
}
|
||||
|
||||
if (pColVal && pColVal->cid == pDCBuilder->cid) {
|
||||
code = tDiskColAddVal(pDCBuilder, pColVal);
|
||||
if (code) return code;
|
||||
pColVal = tRowIterNext(&iter);
|
||||
} else {
|
||||
code = tDiskColAddVal(pDCBuilder, &COL_VAL_NONE(pDCBuilder->cid, pDCBuilder->type));
|
||||
if (code) return code;
|
||||
}
|
||||
}
|
||||
pBuilder->nRow++;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tGnrtDiskData(SDiskDataBuilder *pBuilder, const SDiskData **ppDiskData, const SBlkInfo **ppBlkInfo) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(pBuilder->nRow);
|
||||
|
||||
*ppDiskData = NULL;
|
||||
*ppBlkInfo = NULL;
|
||||
|
||||
SDiskData *pDiskData = &pBuilder->dd;
|
||||
// reset SDiskData
|
||||
pDiskData->hdr = (SDiskDataHdr){.delimiter = TSDB_FILE_DLMT,
|
||||
.fmtVer = 0,
|
||||
.suid = pBuilder->suid,
|
||||
.uid = pBuilder->uid,
|
||||
.szUid = 0,
|
||||
.szVer = 0,
|
||||
.szKey = 0,
|
||||
.szBlkCol = 0,
|
||||
.nRow = pBuilder->nRow,
|
||||
.cmprAlg = pBuilder->cmprAlg};
|
||||
pDiskData->pUid = NULL;
|
||||
pDiskData->pVer = NULL;
|
||||
pDiskData->pKey = NULL;
|
||||
|
||||
// UID
|
||||
if (pBuilder->uid == 0) {
|
||||
code = tCompressEnd(pBuilder->pUidC, &pDiskData->pUid, &pDiskData->hdr.szUid, NULL);
|
||||
if (code) return code;
|
||||
}
|
||||
|
||||
// VERSION
|
||||
code = tCompressEnd(pBuilder->pVerC, &pDiskData->pVer, &pDiskData->hdr.szVer, NULL);
|
||||
if (code) return code;
|
||||
|
||||
// TSKEY
|
||||
code = tCompressEnd(pBuilder->pKeyC, &pDiskData->pKey, &pDiskData->hdr.szKey, NULL);
|
||||
if (code) return code;
|
||||
|
||||
// aDiskCol
|
||||
if (pDiskData->aDiskCol) {
|
||||
taosArrayClear(pDiskData->aDiskCol);
|
||||
} else {
|
||||
pDiskData->aDiskCol = taosArrayInit(pBuilder->nBuilder, sizeof(SDiskCol));
|
||||
if (pDiskData->aDiskCol == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t offset = 0;
|
||||
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
|
||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
|
||||
|
||||
if (pDCBuilder->flag == HAS_NONE) continue;
|
||||
|
||||
SDiskCol dCol;
|
||||
|
||||
code = tGnrtDiskCol(pDCBuilder, &dCol);
|
||||
if (code) return code;
|
||||
|
||||
dCol.bCol.offset = offset;
|
||||
offset = offset + dCol.bCol.szBitmap + dCol.bCol.szOffset + dCol.bCol.szValue;
|
||||
|
||||
if (taosArrayPush(pDiskData->aDiskCol, &dCol) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
pDiskData->hdr.szBlkCol += tPutBlockCol(NULL, &dCol.bCol);
|
||||
}
|
||||
|
||||
*ppDiskData = pDiskData;
|
||||
*ppBlkInfo = &pBuilder->bi;
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size) {
|
||||
static int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size) {
|
||||
int32_t code = 0;
|
||||
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
||||
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
|
||||
|
@ -522,9 +522,6 @@ static int32_t tsdbWriteBlockSma(SDataFWriter *pWriter, SBlockData *pBlockData,
|
|||
|
||||
// write
|
||||
if (pSmaInfo->size) {
|
||||
code = tRealloc(&pWriter->aBuf[0], pSmaInfo->size);
|
||||
if (code) goto _err;
|
||||
|
||||
code = tsdbWriteFile(pWriter->pSmaFD, pWriter->fSma.size, pWriter->aBuf[0], pSmaInfo->size);
|
||||
if (code) goto _err;
|
||||
|
||||
|
@ -607,6 +604,132 @@ _err:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbWriteDiskData(SDataFWriter *pWriter, const SDiskData *pDiskData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
STsdbFD *pFD = NULL;
|
||||
if (pSmaInfo) {
|
||||
pFD = pWriter->pDataFD;
|
||||
pBlkInfo->offset = pWriter->fData.size;
|
||||
} else {
|
||||
pFD = pWriter->pSttFD;
|
||||
pBlkInfo->offset = pWriter->fStt[pWriter->wSet.nSttF - 1].size;
|
||||
}
|
||||
pBlkInfo->szBlock = 0;
|
||||
pBlkInfo->szKey = 0;
|
||||
|
||||
// hdr
|
||||
int32_t n = tPutDiskDataHdr(NULL, &pDiskData->hdr);
|
||||
code = tRealloc(&pWriter->aBuf[0], n);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
tPutDiskDataHdr(pWriter->aBuf[0], &pDiskData->hdr);
|
||||
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset, pWriter->aBuf[0], n);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pBlkInfo->szKey += n;
|
||||
pBlkInfo->szBlock += n;
|
||||
|
||||
// uid + ver + key
|
||||
if (pDiskData->pUid) {
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pDiskData->pUid, pDiskData->hdr.szUid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pBlkInfo->szKey += pDiskData->hdr.szUid;
|
||||
pBlkInfo->szBlock += pDiskData->hdr.szUid;
|
||||
}
|
||||
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pDiskData->pVer, pDiskData->hdr.szVer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pBlkInfo->szKey += pDiskData->hdr.szVer;
|
||||
pBlkInfo->szBlock += pDiskData->hdr.szVer;
|
||||
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pDiskData->pKey, pDiskData->hdr.szKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pBlkInfo->szKey += pDiskData->hdr.szKey;
|
||||
pBlkInfo->szBlock += pDiskData->hdr.szKey;
|
||||
|
||||
// aBlockCol
|
||||
if (pDiskData->hdr.szBlkCol) {
|
||||
code = tRealloc(&pWriter->aBuf[0], pDiskData->hdr.szBlkCol);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
n = 0;
|
||||
for (int32_t iDiskCol = 0; iDiskCol < taosArrayGetSize(pDiskData->aDiskCol); iDiskCol++) {
|
||||
SDiskCol *pDiskCol = (SDiskCol *)taosArrayGet(pDiskData->aDiskCol, iDiskCol);
|
||||
n += tPutBlockCol(pWriter->aBuf[0] + n, pDiskCol);
|
||||
}
|
||||
ASSERT(n == pDiskData->hdr.szBlkCol);
|
||||
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pWriter->aBuf[0], pDiskData->hdr.szBlkCol);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pBlkInfo->szBlock += pDiskData->hdr.szBlkCol;
|
||||
}
|
||||
|
||||
// aDiskCol
|
||||
for (int32_t iDiskCol = 0; iDiskCol < taosArrayGetSize(pDiskData->aDiskCol); iDiskCol++) {
|
||||
SDiskCol *pDiskCol = (SDiskCol *)taosArrayGet(pDiskData->aDiskCol, iDiskCol);
|
||||
|
||||
if (pDiskCol->pBit) {
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pDiskCol->pBit, pDiskCol->bCol.szBitmap);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pBlkInfo->szBlock += pDiskCol->bCol.szBitmap;
|
||||
}
|
||||
|
||||
if (pDiskCol->pOff) {
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pDiskCol->pOff, pDiskCol->bCol.szOffset);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pBlkInfo->szBlock += pDiskCol->bCol.szOffset;
|
||||
}
|
||||
|
||||
if (pDiskCol->pVal) {
|
||||
code = tsdbWriteFile(pFD, pBlkInfo->offset + pBlkInfo->szBlock, pDiskCol->pVal, pDiskCol->bCol.szValue);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pBlkInfo->szBlock += pDiskCol->bCol.szValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (pSmaInfo) {
|
||||
pWriter->fData.size += pBlkInfo->szBlock;
|
||||
} else {
|
||||
pWriter->fStt[pWriter->wSet.nSttF - 1].size += pBlkInfo->szBlock;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pSmaInfo->offset = 0;
|
||||
pSmaInfo->size = 0;
|
||||
for (int32_t iDiskCol = 0; iDiskCol < taosArrayGetSize(pDiskData->aDiskCol); iDiskCol++) {
|
||||
SDiskCol *pDiskCol = (SDiskCol *)taosArrayGet(pDiskData->aDiskCol, iDiskCol);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pDiskCol->bCol.type)) continue;
|
||||
if (pDiskCol->bCol.flag == HAS_NULL || pDiskCol->bCol.flag == (HAS_NULL | HAS_NONE)) continue;
|
||||
if (!pDiskCol->bCol.smaOn) continue;
|
||||
|
||||
code = tRealloc(&pWriter->aBuf[0], pSmaInfo->size + tPutColumnDataAgg(NULL, &pDiskCol->agg));
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pSmaInfo->size += tPutColumnDataAgg(pWriter->aBuf[0] + pSmaInfo->size, &pDiskCol->agg);
|
||||
}
|
||||
|
||||
if (pSmaInfo->size) {
|
||||
pSmaInfo->offset = pWriter->fSma.size;
|
||||
|
||||
code = tsdbWriteFile(pWriter->pSmaFD, pSmaInfo->offset, pWriter->aBuf[0], pSmaInfo->size);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pWriter->fSma.size += pSmaInfo->size;
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo) {
|
||||
int32_t code = 0;
|
||||
int64_t n;
|
||||
|
@ -946,8 +1069,8 @@ static int32_t tsdbReadBlockDataImpl(SDataFReader *pReader, SBlockInfo *pBlkInfo
|
|||
|
||||
ASSERT(hdr.delimiter == TSDB_FILE_DLMT);
|
||||
ASSERT(pBlockData->suid == hdr.suid);
|
||||
ASSERT(pBlockData->uid == hdr.uid);
|
||||
|
||||
pBlockData->uid = hdr.uid;
|
||||
pBlockData->nRow = hdr.nRow;
|
||||
|
||||
// uid
|
||||
|
|
|
@ -649,7 +649,7 @@ int32_t tRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRo
|
|||
|
||||
ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = key.ts});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = key.ts});
|
||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
|
@ -690,7 +690,7 @@ int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
|||
STColumn *pTColumn;
|
||||
int32_t iCol, jCol = 1;
|
||||
|
||||
ASSERT(((SColVal *)pMerger->pArray->pData)->value.ts == key.ts);
|
||||
ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
|
||||
|
||||
for (iCol = 1; iCol < pMerger->pTSchema->numOfCols && jCol < pTSchema->numOfCols; ++iCol) {
|
||||
pTColumn = &pMerger->pTSchema->columns[iCol];
|
||||
|
@ -744,7 +744,7 @@ int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
|||
|
||||
ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = key.ts});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = key.ts});
|
||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
|
@ -770,7 +770,7 @@ int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
|||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
SColVal *pColVal = &(SColVal){0};
|
||||
|
||||
ASSERT(((SColVal *)pMerger->pArray->pData)->value.ts == key.ts);
|
||||
ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
|
||||
|
||||
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
||||
tsdbRowGetColVal(pRow, pMerger->pTSchema, iCol, pColVal);
|
||||
|
@ -1105,9 +1105,8 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
|
|||
pColVal = tRowIterNext(&rIter);
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
pBlockData->nRow++;
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
|
@ -1455,9 +1454,8 @@ _exit:
|
|||
}
|
||||
|
||||
// SDiskDataHdr ==============================
|
||||
int32_t tPutDiskDataHdr(uint8_t *p, void *ph) {
|
||||
int32_t n = 0;
|
||||
SDiskDataHdr *pHdr = (SDiskDataHdr *)ph;
|
||||
int32_t tPutDiskDataHdr(uint8_t *p, const SDiskDataHdr *pHdr) {
|
||||
int32_t n = 0;
|
||||
|
||||
n += tPutU32(p ? p + n : p, pHdr->delimiter);
|
||||
n += tPutU32v(p ? p + n : p, pHdr->fmtVer);
|
||||
|
@ -1516,174 +1514,107 @@ int32_t tGetColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg) {
|
|||
return n;
|
||||
}
|
||||
|
||||
#define SMA_UPDATE(SUM_V, MIN_V, MAX_V, VAL, MINSET, MAXSET) \
|
||||
do { \
|
||||
(SUM_V) += (VAL); \
|
||||
if (!(MINSET)) { \
|
||||
(MIN_V) = (VAL); \
|
||||
(MINSET) = 1; \
|
||||
} else if ((MIN_V) > (VAL)) { \
|
||||
(MIN_V) = (VAL); \
|
||||
} \
|
||||
if (!(MAXSET)) { \
|
||||
(MAX_V) = (VAL); \
|
||||
(MAXSET) = 1; \
|
||||
} else if ((MAX_V) < (VAL)) { \
|
||||
(MAX_V) = (VAL); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static FORCE_INLINE void tSmaUpdateBool(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) {
|
||||
int8_t val = *(int8_t *)&pColVal->value.val ? 1 : 0;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateTinyint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet,
|
||||
uint8_t *maxSet) {
|
||||
int8_t val = *(int8_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateSmallint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet,
|
||||
uint8_t *maxSet) {
|
||||
int16_t val = *(int16_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateInt(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) {
|
||||
int32_t val = *(int32_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateBigint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) {
|
||||
int64_t val = *(int64_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateFloat(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) {
|
||||
float val = *(float *)&pColVal->value.val;
|
||||
SMA_UPDATE(*(double *)&pColAgg->sum, *(double *)&pColAgg->min, *(double *)&pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateDouble(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) {
|
||||
double val = *(double *)&pColVal->value.val;
|
||||
SMA_UPDATE(*(double *)&pColAgg->sum, *(double *)&pColAgg->min, *(double *)&pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateUTinyint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet,
|
||||
uint8_t *maxSet) {
|
||||
uint8_t val = *(uint8_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateUSmallint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet,
|
||||
uint8_t *maxSet) {
|
||||
uint16_t val = *(uint16_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateUInt(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) {
|
||||
uint32_t val = *(uint32_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
static FORCE_INLINE void tSmaUpdateUBigint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet,
|
||||
uint8_t *maxSet) {
|
||||
uint64_t val = *(uint64_t *)&pColVal->value.val;
|
||||
SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet);
|
||||
}
|
||||
void (*tSmaUpdateImpl[])(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) = {
|
||||
NULL,
|
||||
tSmaUpdateBool, // TSDB_DATA_TYPE_BOOL
|
||||
tSmaUpdateTinyint, // TSDB_DATA_TYPE_TINYINT
|
||||
tSmaUpdateSmallint, // TSDB_DATA_TYPE_SMALLINT
|
||||
tSmaUpdateInt, // TSDB_DATA_TYPE_INT
|
||||
tSmaUpdateBigint, // TSDB_DATA_TYPE_BIGINT
|
||||
tSmaUpdateFloat, // TSDB_DATA_TYPE_FLOAT
|
||||
tSmaUpdateDouble, // TSDB_DATA_TYPE_DOUBLE
|
||||
NULL, // TSDB_DATA_TYPE_VARCHAR
|
||||
tSmaUpdateBigint, // TSDB_DATA_TYPE_TIMESTAMP
|
||||
NULL, // TSDB_DATA_TYPE_NCHAR
|
||||
tSmaUpdateUTinyint, // TSDB_DATA_TYPE_UTINYINT
|
||||
tSmaUpdateUSmallint, // TSDB_DATA_TYPE_USMALLINT
|
||||
tSmaUpdateUInt, // TSDB_DATA_TYPE_UINT
|
||||
tSmaUpdateUBigint, // TSDB_DATA_TYPE_UBIGINT
|
||||
NULL, // TSDB_DATA_TYPE_JSON
|
||||
NULL, // TSDB_DATA_TYPE_VARBINARY
|
||||
NULL, // TSDB_DATA_TYPE_DECIMAL
|
||||
NULL, // TSDB_DATA_TYPE_BLOB
|
||||
NULL, // TSDB_DATA_TYPE_MEDIUMBLOB
|
||||
};
|
||||
void tsdbCalcColDataSMA(SColData *pColData, SColumnDataAgg *pColAgg) {
|
||||
SColVal colVal;
|
||||
SColVal *pColVal = &colVal;
|
||||
|
||||
memset(pColAgg, 0, sizeof(*pColAgg));
|
||||
bool minAssigned = false;
|
||||
bool maxAssigned = false;
|
||||
|
||||
*pColAgg = (SColumnDataAgg){.colId = pColData->cid};
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
tColDataGetValue(pColData, iVal, pColVal);
|
||||
uint8_t minSet = 0;
|
||||
uint8_t maxSet = 0;
|
||||
|
||||
if (!COL_VAL_IS_VALUE(pColVal)) {
|
||||
pColAgg->numOfNull++;
|
||||
SColVal cv;
|
||||
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
|
||||
tColDataGetValue(pColData, iVal, &cv);
|
||||
|
||||
if (COL_VAL_IS_VALUE(&cv)) {
|
||||
tSmaUpdateImpl[pColData->type](pColAgg, &cv, &minSet, &maxSet);
|
||||
} else {
|
||||
switch (pColData->type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
pColAgg->sum += colVal.value.i8;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.i8) {
|
||||
pColAgg->min = colVal.value.i8;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.i8) {
|
||||
pColAgg->max = colVal.value.i8;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
pColAgg->sum += colVal.value.i16;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.i16) {
|
||||
pColAgg->min = colVal.value.i16;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.i16) {
|
||||
pColAgg->max = colVal.value.i16;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
pColAgg->sum += colVal.value.i32;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.i32) {
|
||||
pColAgg->min = colVal.value.i32;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.i32) {
|
||||
pColAgg->max = colVal.value.i32;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
pColAgg->sum += colVal.value.i64;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.i64) {
|
||||
pColAgg->min = colVal.value.i64;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.i64) {
|
||||
pColAgg->max = colVal.value.i64;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
*(double *)(&pColAgg->sum) += colVal.value.f;
|
||||
if (!minAssigned || *(double *)(&pColAgg->min) > colVal.value.f) {
|
||||
*(double *)(&pColAgg->min) = colVal.value.f;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || *(double *)(&pColAgg->max) < colVal.value.f) {
|
||||
*(double *)(&pColAgg->max) = colVal.value.f;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
*(double *)(&pColAgg->sum) += colVal.value.d;
|
||||
if (!minAssigned || *(double *)(&pColAgg->min) > colVal.value.d) {
|
||||
*(double *)(&pColAgg->min) = colVal.value.d;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || *(double *)(&pColAgg->max) < colVal.value.d) {
|
||||
*(double *)(&pColAgg->max) = colVal.value.d;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
if (!minAssigned || pColAgg->min > colVal.value.i64) {
|
||||
pColAgg->min = colVal.value.i64;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.i64) {
|
||||
pColAgg->max = colVal.value.i64;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
pColAgg->sum += colVal.value.u8;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.u8) {
|
||||
pColAgg->min = colVal.value.u8;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.u8) {
|
||||
pColAgg->max = colVal.value.u8;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
pColAgg->sum += colVal.value.u16;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.u16) {
|
||||
pColAgg->min = colVal.value.u16;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.u16) {
|
||||
pColAgg->max = colVal.value.u16;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
pColAgg->sum += colVal.value.u32;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.u32) {
|
||||
pColAgg->min = colVal.value.u32;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!minAssigned || pColAgg->max < colVal.value.u32) {
|
||||
pColAgg->max = colVal.value.u32;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
pColAgg->sum += colVal.value.u64;
|
||||
if (!minAssigned || pColAgg->min > colVal.value.u64) {
|
||||
pColAgg->min = colVal.value.u64;
|
||||
minAssigned = true;
|
||||
}
|
||||
if (!maxAssigned || pColAgg->max < colVal.value.u64) {
|
||||
pColAgg->max = colVal.value.u64;
|
||||
maxAssigned = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
pColAgg->numOfNull++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue