more code
This commit is contained in:
parent
96b4fbc2bc
commit
895b48f834
|
@ -90,7 +90,6 @@ void tTSchemaDestroy(STSchema *pTSchema);
|
||||||
// SRow ================================
|
// SRow ================================
|
||||||
int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer);
|
int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer);
|
||||||
void tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
void tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||||
int32_t tRowToArr(SRow *pRow, STSchema *pTSchema, SArray **aColValP);
|
|
||||||
|
|
||||||
// SRowIter ================================
|
// SRowIter ================================
|
||||||
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
|
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
|
||||||
|
|
|
@ -47,17 +47,14 @@ int32_t tBufferPut(SBuffer *pBuffer, const void *pData, int64_t nData) {
|
||||||
static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson);
|
static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson);
|
||||||
|
|
||||||
// SRow ========================================================================
|
// SRow ========================================================================
|
||||||
#define ROW_FLG_KV ((uint8_t)0x10)
|
#define KV_FLG_LIT ((uint8_t)0x10)
|
||||||
|
#define KV_FLG_MID ((uint8_t)0x20)
|
||||||
#define KV_TYPE_LIT 0
|
#define KV_FLG_BIG ((uint8_t)0x30)
|
||||||
#define KV_TYPE_MID 1
|
|
||||||
#define KV_TYPE_BIG 2
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t kvType;
|
|
||||||
int16_t nCol;
|
int16_t nCol;
|
||||||
char idx[];
|
char idx[]; // uint8_t * | uint16_t * | uint32_t *
|
||||||
} SKVIdx;
|
} SKVIdx;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
@ -75,27 +72,29 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer) {
|
||||||
SColVal *pColVal = (iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
SColVal *pColVal = (iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||||
int32_t iTColumn = 1;
|
int32_t iTColumn = 1;
|
||||||
STColumn *pTColumn = pTSchema->columns + iTColumn;
|
STColumn *pTColumn = pTSchema->columns + iTColumn;
|
||||||
int32_t ntp = sizeof(SRow);
|
int32_t ntp = 0;
|
||||||
int32_t nkv = sizeof(SRow);
|
int32_t nkv = 0;
|
||||||
|
int32_t maxIdx = 0;
|
||||||
int32_t nidx = 0;
|
int32_t nidx = 0;
|
||||||
while (pTColumn) {
|
while (pTColumn) {
|
||||||
if (pColVal) {
|
if (pColVal) {
|
||||||
ntp += TYPE_BYTES[pTColumn->type];
|
|
||||||
|
|
||||||
if (pColVal->cid == pTColumn->colId) {
|
if (pColVal->cid == pTColumn->colId) {
|
||||||
|
ntp += TYPE_BYTES[pTColumn->type];
|
||||||
if (COL_VAL_IS_VALUE(pColVal)) { // VALUE
|
if (COL_VAL_IS_VALUE(pColVal)) { // VALUE
|
||||||
flag |= HAS_VALUE;
|
flag |= HAS_VALUE;
|
||||||
|
maxIdx = nkv;
|
||||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||||
ntp = ntp + tPutU32v(NULL, pColVal->value.nData) + pColVal->value.nData;
|
ntp = ntp + tPutU32v(NULL, pColVal->value.nData) + pColVal->value.nData;
|
||||||
nkv = nkv + tPutI16v(NULL, pTColumn->colId) + tPutU32v(NULL, pColVal->value.nData) + pColVal->value.nData;
|
nkv = nkv + tPutI16v(NULL, pTColumn->colId) + tPutU32v(NULL, pColVal->value.nData) + pColVal->value.nData;
|
||||||
} else {
|
} else {
|
||||||
nkv = nkv + TYPE_BYTES[pTColumn->type];
|
nkv = nkv + tPutI16v(NULL, pTColumn->colId) + TYPE_BYTES[pTColumn->type];
|
||||||
}
|
}
|
||||||
nidx++;
|
nidx++;
|
||||||
} else if (COL_VAL_IS_NONE(pColVal)) { // NONE
|
} else if (COL_VAL_IS_NONE(pColVal)) { // NONE
|
||||||
flag |= HAS_NONE;
|
flag |= HAS_NONE;
|
||||||
} else if (COL_VAL_IS_NULL(pColVal)) { // NULL
|
} else if (COL_VAL_IS_NULL(pColVal)) { // NULL
|
||||||
flag |= HAS_NULL;
|
flag |= HAS_NULL;
|
||||||
|
maxIdx = nkv;
|
||||||
nkv += tPutI16v(NULL, -pTColumn->colId);
|
nkv += tPutI16v(NULL, -pTColumn->colId);
|
||||||
nidx++;
|
nidx++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,43 +118,45 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare ---------------
|
// compare ---------------
|
||||||
int32_t nRow = 0;
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case HAS_NONE:
|
case HAS_NONE:
|
||||||
case HAS_NULL:
|
case HAS_NULL:
|
||||||
nRow = sizeof(SRow);
|
ntp = sizeof(SRow);
|
||||||
break;
|
break;
|
||||||
case HAS_VALUE:
|
case HAS_VALUE:
|
||||||
nRow = ntp;
|
ntp = sizeof(SRow) + ntp;
|
||||||
break;
|
break;
|
||||||
case (HAS_NULL | HAS_NONE):
|
case (HAS_NULL | HAS_NONE):
|
||||||
// TODO
|
ntp = sizeof(SRow) + BIT1_SIZE(pTSchema->numOfCols - 1);
|
||||||
break;
|
break;
|
||||||
case (HAS_VALUE | HAS_NONE):
|
case (HAS_VALUE | HAS_NONE):
|
||||||
case (HAS_VALUE | HAS_NULL):
|
case (HAS_VALUE | HAS_NULL):
|
||||||
ntp = ntp + BIT1_SIZE(pTSchema->numOfCols);
|
ntp = sizeof(SRow) + BIT1_SIZE(pTSchema->numOfCols - 1) + ntp;
|
||||||
nkv = nkv + sizeof(int32_t) * nidx;
|
|
||||||
if (ntp <= nkv) {
|
|
||||||
nRow = ntp;
|
|
||||||
} else {
|
|
||||||
nRow = nkv;
|
|
||||||
flag |= ROW_FLG_KV;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case (HAS_VALUE | HAS_NULL | HAS_NONE):
|
case (HAS_VALUE | HAS_NULL | HAS_NONE):
|
||||||
ntp = ntp + BIT2_SIZE(pTSchema->numOfCols);
|
ntp = sizeof(SRow) + BIT2_SIZE(pTSchema->numOfCols - 1) + ntp;
|
||||||
nkv = nkv + sizeof(int32_t) * nidx;
|
|
||||||
if (ntp <= nkv) {
|
|
||||||
nRow = ntp;
|
|
||||||
} else {
|
|
||||||
nRow = nkv;
|
|
||||||
flag |= ROW_FLG_KV;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (maxIdx <= UINT8_MAX) {
|
||||||
|
nkv = sizeof(SRow) + sizeof(SKVIdx) + sizeof(uint8_t) * nidx + nkv;
|
||||||
|
flag |= KV_FLG_LIT;
|
||||||
|
} else if (maxIdx <= UINT16_MAX) {
|
||||||
|
nkv = sizeof(SRow) + sizeof(SKVIdx) + sizeof(uint16_t) * nidx + nkv;
|
||||||
|
flag |= KV_FLG_MID;
|
||||||
|
} else {
|
||||||
|
nkv = sizeof(SRow) + sizeof(SKVIdx) + sizeof(uint32_t) * nidx + nkv;
|
||||||
|
flag |= KV_FLG_BIG;
|
||||||
|
}
|
||||||
|
int32_t nRow;
|
||||||
|
if (nkv < ntp) {
|
||||||
|
nRow = nkv;
|
||||||
|
} else {
|
||||||
|
nRow = ntp;
|
||||||
|
flag &= ((uint8_t)0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
// alloc --------------
|
// alloc --------------
|
||||||
SRow *pRow = NULL; // todo
|
SRow *pRow = NULL; // todo
|
||||||
|
@ -177,7 +178,7 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer) {
|
||||||
pColVal = (iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
pColVal = (iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||||
iTColumn = 1;
|
iTColumn = 1;
|
||||||
pTColumn = pTSchema->columns + iTColumn;
|
pTColumn = pTSchema->columns + iTColumn;
|
||||||
if (flag & ROW_FLG_KV) { // KV
|
if (flag & 0xf0) { // KV
|
||||||
SKVIdx *pIdx = (SKVIdx *)pRow->data;
|
SKVIdx *pIdx = (SKVIdx *)pRow->data;
|
||||||
uint8_t *pv = NULL; // todo
|
uint8_t *pv = NULL; // todo
|
||||||
|
|
||||||
|
@ -278,7 +279,7 @@ void tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRow->flag & ROW_FLG_KV) { // KV Row
|
if (pRow->flag & 0xf0) { // KV Row
|
||||||
SKVIdx *pIdx = (SKVIdx *)pRow->data;
|
SKVIdx *pIdx = (SKVIdx *)pRow->data;
|
||||||
uint8_t *pv = pRow->data + sizeof(*pIdx) + sizeof(int32_t) * pIdx->nCol;
|
uint8_t *pv = pRow->data + sizeof(*pIdx) + sizeof(int32_t) * pIdx->nCol;
|
||||||
|
|
||||||
|
@ -327,8 +328,6 @@ void tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tRowToArr(SRow *pRow, STSchema *pTSchema, SArray **aColValP) { return 0; }
|
|
||||||
|
|
||||||
// SRowIter ========================================
|
// SRowIter ========================================
|
||||||
struct SRowIter {
|
struct SRowIter {
|
||||||
SRow *pRow;
|
SRow *pRow;
|
||||||
|
@ -405,7 +404,7 @@ SColVal *tRowIterNext(SRowIter *pIter) {
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pIter->pRow->flag & ROW_FLG_KV) { // KV
|
if (pIter->pRow->flag & 0xf0) { // KV
|
||||||
if (pIter->iCol < pIter->pIdx->nCol) {
|
if (pIter->iCol < pIter->pIdx->nCol) {
|
||||||
uint8_t *pData = pIter->pv + pIter->pIdx->idx[pIter->iCol]; // todo
|
uint8_t *pData = pIter->pv + pIter->pIdx->idx[pIter->iCol]; // todo
|
||||||
int16_t cid;
|
int16_t cid;
|
||||||
|
|
|
@ -61,7 +61,7 @@ tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX] = {
|
||||||
static float floatMin = -FLT_MAX, floatMax = FLT_MAX;
|
static float floatMin = -FLT_MAX, floatMax = FLT_MAX;
|
||||||
static double doubleMin = -DBL_MAX, doubleMax = DBL_MAX;
|
static double doubleMin = -DBL_MAX, doubleMax = DBL_MAX;
|
||||||
|
|
||||||
FORCE_INLINE void *getDataMin(int32_t type, void* value) {
|
FORCE_INLINE void *getDataMin(int32_t type, void *value) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_FLOAT:
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
*(float *)value = floatMin;
|
*(float *)value = floatMin;
|
||||||
|
@ -77,7 +77,7 @@ FORCE_INLINE void *getDataMin(int32_t type, void* value) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE void *getDataMax(int32_t type, void* value) {
|
FORCE_INLINE void *getDataMax(int32_t type, void *value) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_FLOAT:
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
*(float *)value = floatMax;
|
*(float *)value = floatMax;
|
||||||
|
|
Loading…
Reference in New Issue