提交 a5725b50 编写于 作者: H Hongze Cheng

more code

上级 151d07e8
...@@ -27,17 +27,17 @@ ...@@ -27,17 +27,17 @@
extern "C" { extern "C" {
#endif #endif
typedef struct SBuffer SBuffer; typedef struct SBuffer SBuffer;
typedef struct SSchema SSchema; typedef struct SSchema SSchema;
typedef struct STColumn STColumn; typedef struct STColumn STColumn;
typedef struct STSchema STSchema; typedef struct STSchema STSchema;
typedef struct SValue SValue; typedef struct SValue SValue;
typedef struct SColVal SColVal; typedef struct SColVal SColVal;
typedef struct STSRow2 STSRow2; typedef struct SRow SRow;
typedef struct STSRowBuilder STSRowBuilder; typedef struct SRowIter SRowIter;
typedef struct STagVal STagVal; typedef struct STagVal STagVal;
typedef struct STag STag; typedef struct STag STag;
typedef struct SColData SColData; typedef struct SColData SColData;
#define HAS_NONE ((uint8_t)0x1) #define HAS_NONE ((uint8_t)0x1)
#define HAS_NULL ((uint8_t)0x2) #define HAS_NULL ((uint8_t)0x2)
...@@ -70,8 +70,7 @@ int32_t tBufferInit(SBuffer *pBuffer, int64_t size); ...@@ -70,8 +70,7 @@ int32_t tBufferInit(SBuffer *pBuffer, int64_t size);
int32_t tBufferPut(SBuffer *pBuffer, const void *pData, int64_t nData); int32_t tBufferPut(SBuffer *pBuffer, const void *pData, int64_t nData);
// STSchema ================================ // STSchema ================================
int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t nCols, STSchema **ppTSchema); void tTSchemaDestroy(STSchema *pTSchema);
void tTSchemaDestroy(STSchema *pTSchema);
// SValue ================================ // SValue ================================
...@@ -88,26 +87,12 @@ void tTSchemaDestroy(STSchema *pTSchema); ...@@ -88,26 +87,12 @@ void tTSchemaDestroy(STSchema *pTSchema);
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL) #define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE) #define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
// STSRow2 ================================ // SRow ================================
#define TSROW_LEN(PROW, V) tGetI32v((uint8_t *)(PROW)->data, (V) ? &(V) : NULL) int32_t tTSRowPut(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer);
#define TSROW_SVER(PROW, V) tGetI32v((PROW)->data + TSROW_LEN(PROW, NULL), (V) ? &(V) : NULL) void tTSRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
int32_t tTSRowToArray(SRow *pRow, STSchema *pTSchema, SArray **ppArray);
int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow);
int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow); // SRowIter ================================
void tTSRowFree(STSRow2 *pRow);
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray);
int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow);
int32_t tGetTSRow(uint8_t *p, STSRow2 **ppRow);
// STSRowBuilder ================================
#define tsRowBuilderInit() ((STSRowBuilder){0})
#define tsRowBuilderClear(B) \
do { \
if ((B)->pBuf) { \
taosMemoryFree((B)->pBuf); \
} \
} while (0)
// STag ================================ // STag ================================
int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag); int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag);
...@@ -151,23 +136,12 @@ struct STSchema { ...@@ -151,23 +136,12 @@ struct STSchema {
STColumn columns[]; STColumn columns[];
}; };
#define TSROW_HAS_NONE ((uint8_t)0x1) struct SRow {
#define TSROW_HAS_NULL ((uint8_t)0x2U) uint8_t flag;
#define TSROW_HAS_VAL ((uint8_t)0x4U) uint8_t rsv;
#define TSROW_KV_SMALL ((uint8_t)0x10U) uint16_t sver;
#define TSROW_KV_MID ((uint8_t)0x20U) uint32_t len;
#define TSROW_KV_BIG ((uint8_t)0x40U) uint8_t data[];
#pragma pack(push, 1)
struct STSRow2 {
TSKEY ts;
uint8_t flags;
uint8_t data[];
};
#pragma pack(pop)
struct STSRowBuilder {
int32_t szBuf;
uint8_t *pBuf;
}; };
struct SValue { struct SValue {
......
...@@ -65,44 +65,42 @@ static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { ...@@ -65,44 +65,42 @@ static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) {
} }
} }
// STSRow2 ======================================================================== // SRow ========================================================================
static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) { int32_t tTSRowPut(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer) {
if (pb) { int32_t code = 0;
switch (flags & 0xf) {
case TSROW_HAS_NULL | TSROW_HAS_NONE:
case TSROW_HAS_VAL | TSROW_HAS_NONE:
if (v) {
SET_BIT1(pb, idx, (uint8_t)1);
} else {
SET_BIT1(pb, idx, (uint8_t)0);
}
break;
case TSROW_HAS_VAL | TSROW_HAS_NULL:
v = v - 1;
SET_BIT1(pb, idx, v);
break;
case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
SET_BIT2(pb, idx, v);
break;
default: ASSERT(taosArrayGetSize(aColVal) == 0);
ASSERT(0);
uint8_t flag = 0;
int32_t iColVal = 0;
SColVal *pColVal = taosArrayGet(aColVal, iColVal);
int32_t iTColumn = 0;
STColumn *pTColumn = pTSchema->columns + iTColumn;
while (pTColumn) {
if (pColVal) {
if (pColVal->cid == pTColumn->colId) {
if (COL_VAL_IS_VALUE(pColVal)) { // VALUE
flag |= HAS_VALUE;
} else if (COL_VAL_IS_NONE(pColVal)) { // NONE
flag |= HAS_NONE;
} else { // NULL
flag |= HAS_NULL;
}
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
pColVal = (++iColVal < taosArrayGetSize(aColVal)) ? taosArrayGet(aColVal, iColVal) : NULL;
} else if (pColVal->cid < pTColumn->colId) {
pColVal = (++iColVal < taosArrayGetSize(aColVal)) ? taosArrayGet(aColVal, iColVal) : NULL;
} else { // NONE
flag |= HAS_NONE;
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
}
} else { // NONE
flag |= HAS_NONE;
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
} }
} }
}
#define SET_IDX(p, i, n, f) \
do { \
if ((f)&TSROW_KV_SMALL) { \
((uint8_t *)(p))[i] = (n); \
} else if ((f)&TSROW_KV_MID) { \
((uint16_t *)(p))[i] = (n); \
} else { \
((uint32_t *)(p))[i] = (n); \
} \
} while (0)
#if 0
int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
int32_t code = 0;
#if 0 #if 0
STColumn *pTColumn; STColumn *pTColumn;
SColVal *pColVal; SColVal *pColVal;
...@@ -238,7 +236,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S ...@@ -238,7 +236,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
*ppRow = &pBuilder->tsRow; *ppRow = &pBuilder->tsRow;
} else { } else {
// create a new one // create a new one
*ppRow = (STSRow2 *)taosMemoryMalloc(sizeof(STSRow2)); *ppRow = (SRow *)taosMemoryMalloc(sizeof(SRow));
if (*ppRow == NULL) { if (*ppRow == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;
...@@ -391,33 +389,54 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S ...@@ -391,33 +389,54 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
} }
#endif #endif
_exit: _exit:
return code; return code;
} }
int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow) { #if 0
int32_t code = 0; static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) {
int32_t rLen = 0; if (pb) {
switch (flags & 0xf) {
case TSROW_HAS_NULL | TSROW_HAS_NONE:
case TSROW_HAS_VAL | TSROW_HAS_NONE:
if (v) {
SET_BIT1(pb, idx, (uint8_t)1);
} else {
SET_BIT1(pb, idx, (uint8_t)0);
}
break;
case TSROW_HAS_VAL | TSROW_HAS_NULL:
v = v - 1;
SET_BIT1(pb, idx, v);
break;
case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
SET_BIT2(pb, idx, v);
break;
TSROW_LEN(pRow, rLen); default:
(*ppRow) = (STSRow2 *)taosMemoryMalloc(rLen); ASSERT(0);
if (*ppRow == NULL) { }
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
} }
memcpy(*ppRow, pRow, rLen);
_exit:
return code;
} }
#define SET_IDX(p, i, n, f) \
do { \
if ((f)&TSROW_KV_SMALL) { \
((uint8_t *)(p))[i] = (n); \
} else if ((f)&TSROW_KV_MID) { \
((uint16_t *)(p))[i] = (n); \
} else { \
((uint32_t *)(p))[i] = (n); \
} \
} while (0)
void tTSRowFree(STSRow2 *pRow) { void tTSRowFree(SRow *pRow) {
if (pRow) { if (pRow) {
taosMemoryFree(pRow); taosMemoryFree(pRow);
} }
} }
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { void tTSRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0; uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0;
STColumn *pTColumn = &pTSchema->columns[iCol]; STColumn *pTColumn = &pTSchema->columns[iCol];
uint8_t flags = pRow->flags & (uint8_t)0xf; uint8_t flags = pRow->flags & (uint8_t)0xf;
...@@ -564,7 +583,7 @@ _return_value: ...@@ -564,7 +583,7 @@ _return_value:
return; return;
} }
int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) { int32_t tTSRowToArray(SRow *pRow, STSchema *pTSchema, SArray **ppArray) {
int32_t code = 0; int32_t code = 0;
SColVal cv; SColVal cv;
...@@ -584,62 +603,8 @@ _exit: ...@@ -584,62 +603,8 @@ _exit:
return code; return code;
} }
#endif #endif
int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow) {
int32_t n = 0;
TSROW_LEN(pRow, n);
if (p) {
memcpy(p, pRow, n);
}
return n;
}
int32_t tGetTSRow(uint8_t *p, STSRow2 **ppRow) {
int32_t n = 0;
*ppRow = (STSRow2 *)p;
TSROW_LEN(*ppRow, n);
return n;
}
// STSchema ======================================== // STSchema ========================================
int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t ncols, STSchema **ppTSchema) {
*ppTSchema = (STSchema *)taosMemoryMalloc(sizeof(STSchema) + sizeof(STColumn) * ncols);
if (*ppTSchema == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
(*ppTSchema)->numOfCols = ncols;
(*ppTSchema)->version = sver;
(*ppTSchema)->flen = 0;
(*ppTSchema)->vlen = 0;
(*ppTSchema)->tlen = 0;
for (int32_t iCol = 0; iCol < ncols; iCol++) {
SSchema *pColumn = &pSchema[iCol];
STColumn *pTColumn = &((*ppTSchema)->columns[iCol]);
pTColumn->colId = pColumn->colId;
pTColumn->type = pColumn->type;
pTColumn->flags = pColumn->flags;
pTColumn->bytes = pColumn->bytes;
pTColumn->offset = (*ppTSchema)->flen;
// skip first column
if (iCol) {
(*ppTSchema)->flen += TYPE_BYTES[pColumn->type];
if (IS_VAR_DATA_TYPE(pColumn->type)) {
(*ppTSchema)->vlen += (pColumn->bytes + 5);
}
}
}
return 0;
}
void tTSchemaDestroy(STSchema *pTSchema) { void tTSchemaDestroy(STSchema *pTSchema) {
if (pTSchema) taosMemoryFree(pTSchema); if (pTSchema) taosMemoryFree(pTSchema);
} }
......
...@@ -112,8 +112,8 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal * ...@@ -112,8 +112,8 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow); // int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
int32_t tsdbRowCmprFn(const void *p1, const void *p2); int32_t tsdbRowCmprFn(const void *p1, const void *p2);
// STSDBRowIter // STSDBRowIter
void tRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema); void tsdbRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
SColVal *tRowIterNext(STSDBRowIter *pIter); SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
// SRowMerger // SRowMerger
int32_t tRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema); int32_t tRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema);
int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema); int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
......
...@@ -596,20 +596,20 @@ int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTS ...@@ -596,20 +596,20 @@ int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTS
if (pBuilder->bi.maxKey < kRow.ts) pBuilder->bi.maxKey = kRow.ts; if (pBuilder->bi.maxKey < kRow.ts) pBuilder->bi.maxKey = kRow.ts;
STSDBRowIter iter = {0}; STSDBRowIter iter = {0};
tRowIterInit(&iter, pRow, pTSchema); tsdbRowIterInit(&iter, pRow, pTSchema);
SColVal *pColVal = tRowIterNext(&iter); SColVal *pColVal = tsdbRowIterNext(&iter);
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) { for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder); SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
while (pColVal && pColVal->cid < pDCBuilder->cid) { while (pColVal && pColVal->cid < pDCBuilder->cid) {
pColVal = tRowIterNext(&iter); pColVal = tsdbRowIterNext(&iter);
} }
if (pColVal && pColVal->cid == pDCBuilder->cid) { if (pColVal && pColVal->cid == pDCBuilder->cid) {
code = tDiskColAddVal(pDCBuilder, pColVal); code = tDiskColAddVal(pDCBuilder, pColVal);
if (code) return code; if (code) return code;
pColVal = tRowIterNext(&iter); pColVal = tsdbRowIterNext(&iter);
} else { } else {
code = tDiskColAddVal(pDCBuilder, &COL_VAL_NONE(pDCBuilder->cid, pDCBuilder->type)); code = tDiskColAddVal(pDCBuilder, &COL_VAL_NONE(pDCBuilder->cid, pDCBuilder->type));
if (code) return code; if (code) return code;
......
...@@ -580,7 +580,7 @@ int32_t tsdbRowCmprFn(const void *p1, const void *p2) { ...@@ -580,7 +580,7 @@ int32_t tsdbRowCmprFn(const void *p1, const void *p2) {
} }
// STSDBRowIter ====================================================== // STSDBRowIter ======================================================
void tRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) { void tsdbRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) {
pIter->pRow = pRow; pIter->pRow = pRow;
if (pRow->type == 0) { if (pRow->type == 0) {
ASSERT(pTSchema); ASSERT(pTSchema);
...@@ -594,7 +594,7 @@ void tRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) { ...@@ -594,7 +594,7 @@ void tRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) {
} }
} }
SColVal *tRowIterNext(STSDBRowIter *pIter) { SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
if (pIter->pRow->type == 0) { if (pIter->pRow->type == 0) {
if (pIter->i < pIter->pTSchema->numOfCols) { if (pIter->i < pIter->pTSchema->numOfCols) {
tTSRowGetVal(pIter->pRow->pTSRow, pIter->pTSchema, pIter->i, &pIter->colVal); tTSRowGetVal(pIter->pRow->pTSRow, pIter->pTSchema, pIter->i, &pIter->colVal);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册