提交 492ff11f 编写于 作者: H hzcheng

TD-34

上级 b01e8b8d
...@@ -105,24 +105,30 @@ SDataRow tdDataRowDup(SDataRow row); ...@@ -105,24 +105,30 @@ SDataRow tdDataRowDup(SDataRow row);
// ----------------- Data column structure // ----------------- Data column structure
typedef struct SDataCol { typedef struct SDataCol {
int32_t len; int8_t type;
void * pData; int bytes;
int len;
void * pData;
} SDataCol; } SDataCol;
typedef struct { typedef struct {
TSKEY firstKey; int maxRowSize;
TSKEY lastKey; int maxCols; // max number of columns
int maxPoints; // max number of points
int numOfPoints; int numOfPoints;
int numOfCols; int numOfCols; // Total number of cols
void * buf; void * buf;
SDataCol cols[]; SDataCol cols[];
} SDataCols; } SDataCols;
#define keyCol(cols) (&((cols)->cols[0])) // Key column #define keyCol(cols) (&((cols)->cols[0])) // Key column
#define dataColsKeyFirst(cols) ((int64_t *)(keyCol(cols)->pData))[0]
#define dataColsKeyLast(cols) ((int64_t *)(keyCol(cols)->pData))[(cols)->numOfPoints - 1]
SDataCols *tdNewDataCols(STSchema *pSchema, int nRows); SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows);
void tdFreeDataCols(SDataCols *pCols);
void tdResetDataCols(SDataCols *pCols); void tdResetDataCols(SDataCols *pCols);
void tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
void tdFreeDataCols(SDataCols *pCols);
void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols, STSchema *pSchema); void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols, STSchema *pSchema);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -294,27 +294,34 @@ SDataRow tdDataRowDup(SDataRow row) { ...@@ -294,27 +294,34 @@ SDataRow tdDataRowDup(SDataRow row) {
return trow; return trow;
} }
SDataCols *tdNewDataCols(STSchema *pSchema, int nRows) { SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows) {
int nCols = schemaNCols(pSchema); SDataCols *pCols = (SDataCols *)calloc(1, sizeof(SDataCols) + sizeof(SDataCol) * maxCols);
if (pCols == NULL) return NULL;
SDataCols *pInfo = (SDataCols *)calloc(1, sizeof(SDataCols) + sizeof(SDataCol) * nCols);
if (pInfo == NULL) return NULL; pCols->maxRowSize = maxRowSize;
pCols->maxCols = maxCols;
pInfo->numOfCols = nCols; pCols->maxPoints = maxRows;
pInfo->firstKey = INT64_MIN;
pInfo->lastKey = INT64_MAX; pCols->buf = malloc(maxRowSize * maxRows);
pInfo->buf = malloc(tdMaxRowBytesFromSchema(pSchema) * nRows); if (pCols->buf == NULL) {
if (pInfo->buf == NULL) { free(pCols);
free(pInfo);
return NULL; return NULL;
} }
pInfo->cols[0].pData = pInfo->buf; return pCols;
for (int i = 1; i < nCols; i++) { }
pInfo->cols[i].pData = (char *)(pInfo->cols[i - 1].pData) + schemaColAt(pSchema, i - 1)->bytes * nRows;
void tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
// assert(schemaNCols(pSchema) <= pCols->numOfCols);
tdResetDataCols(pCols);
pCols->numOfCols = schemaNCols(pSchema);
pCols->cols[0].pData = pCols->buf;
for (int i = 1; i < schemaNCols(pSchema); i++) {
pCols->cols[i].pData = (char *)(pCols->cols[i - 1].pData) + schemaColAt(pSchema, i - 1)->bytes * pCols->maxPoints;
} }
return pInfo; return pCols;
} }
void tdFreeDataCols(SDataCols *pCols) { void tdFreeDataCols(SDataCols *pCols) {
...@@ -325,18 +332,14 @@ void tdFreeDataCols(SDataCols *pCols) { ...@@ -325,18 +332,14 @@ void tdFreeDataCols(SDataCols *pCols) {
} }
void tdResetDataCols(SDataCols *pCols) { void tdResetDataCols(SDataCols *pCols) {
pCols->firstKey = INT64_MAX;
pCols->lastKey = INT64_MIN;
pCols->numOfPoints = 0; pCols->numOfPoints = 0;
for (int i = 0; i < pCols->numOfCols; i++) { for (int i = 0; i < pCols->maxCols; i++) {
pCols->cols[i].len = 0; pCols->cols[i].len = 0;
} }
} }
void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols, STSchema *pSchema) { void tdAppendDataRowToDataCol(SDataRow row, SDataCols *pCols, STSchema *pSchema) {
TSKEY key = dataRowKey(row); TSKEY key = dataRowKey(row);
if (pCols->numOfPoints == 0) pCols->firstKey = key;
pCols->lastKey = key;
for (int i = 0; i < pCols->numOfCols; i++) { for (int i = 0; i < pCols->numOfCols; i++) {
SDataCol *pCol = pCols->cols + i; SDataCol *pCol = pCols->cols + i;
memcpy((void *)((char *)(pCol->pData) + pCol->len), dataRowAt(row, colOffset(schemaColAt(pSchema, i))), memcpy((void *)((char *)(pCol->pData) + pCol->len), dataRowAt(row, colOffset(schemaColAt(pSchema, i))),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册