提交 416e6354 编写于 作者: H Hongze Cheng

more

上级 274d115a
......@@ -19,18 +19,18 @@
#include "os.h"
#include "tbuffer.h"
#include "tdef.h"
#include "tschema.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TD_OR_ROW 0
#define TD_KV_ROW 1
typedef uint16_t col_id_t;
#define TD_UNDECIDED_ROW 0
#define TD_OR_ROW 1
#define TD_KV_ROW 2
typedef struct {
TSKEY ts;
// TODO
} SOrRow;
typedef struct {
......@@ -48,21 +48,30 @@ typedef struct {
/// union field for encode and decode
uint64_t info;
struct {
/// is deleted row
uint64_t del : 1;
/// row type
uint64_t type : 2;
uint64_t type : 3;
/// row schema version
uint64_t sver : 16;
/// row total length
uint64_t len : 46;
uint64_t len : 32;
/// reserved for back compatibility
uint64_t reserve : 12;
};
};
/// row version
uint64_t ver;
/// timestamp of the row
TSKEY ts;
char content[];
/// timestamp
TSKEY ts;
char content[];
} SRow;
typedef struct {
uint32_t nRows;
char rows[];
} SRowBatch;
typedef enum {
/// ordinary row builder
TD_OR_ROW_BUILDER = 0,
......@@ -82,12 +91,32 @@ typedef struct {
} SRowBuilder;
typedef struct {
/* TODO */
} SRowBatchBuilder;
SSchema *pSchema;
SRow * pRow;
} SRowReader;
typedef struct {
uint32_t it;
SRowBatch *pRowBatch;
} SRowBatchIter;
// SRowBuilder
#define trbInit(rt, allocator, endian, target, size) \
{ .type = (rt), .bw = tbufInitWriter(allocator, endian), .pRow = (target) }
void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver);
void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver);
void trbSetRowTS(SRowBuilder *pRB, TSKEY ts);
int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid);
// SRowReader
#define tRowReaderInit(schema, row) \
{ .schema = (schema), .row = (row) }
int tRowReaderRead(SRowReader *pRowReader, col_id_t cid, void *target, uint64_t size);
#define tRBInit(type, allocator, endian) \
{ .type = (type), tbufInitWriter(allocator, endian), NULL }
void tRBClear(SRowBuilder *pRB);
// SRowBatchIter
#define tRowBatchIterInit(pRB) \
{ .it = 0, .pRowBatch = (pRB) }
const SRow *tRowBatchIterNext(SRowBatchIter *pRowBatchIter);
#ifdef __cplusplus
}
......
......@@ -17,27 +17,61 @@
#define _TD_COMMON_SCHEMA_H_
#include "os.h"
#include "tarray.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SColAttr {
/* data */
} SColAttr;
typedef uint16_t col_id_t;
typedef struct SColumn {
uint8_t type;
uint16_t cid;
uint16_t bytes;
/// column name
char *cname;
union {
/// for encode purpose
uint64_t info;
struct {
uint64_t sma : 1;
/// column data type
uint64_t type : 7;
/// column id
uint64_t cid : 16;
/// max bytes of the column
uint64_t bytes : 32;
/// reserved
uint64_t reserve : 8;
};
};
/// comment about the column
char *comment;
} SColumn;
typedef struct SSchema {
/// schema version
uint16_t sver;
/* data */
/// number of columns
uint16_t ncols;
/// sma attributes
struct {
bool sma;
SArray *smaArray;
};
/// column info
SColumn cols[];
} SSchema;
typedef struct {
uint64_t size;
SSchema *pSchema;
} SShemaBuilder;
#define tSchemaBuilderInit(target, capacity) \
{ .size = (capacity), .pSchema = (target) }
void tSchemaBuilderSetSver(SShemaBuilder *pSchemaBuilder, uint16_t sver);
void tSchemaBuilderSetSMA(bool sma, SArray *smaArray);
int tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment);
#ifdef __cplusplus
}
#endif
......
......@@ -15,77 +15,19 @@
#include "trow.h"
#if 0
/* ------------ Structures ---------- */
struct SRowBatch {
int32_t compress : 1; // if batch row is compressed
int32_t nrows : 31; // number of rows
int32_t tlen; // total length (including `nrows` and `tlen`)
char rows[];
};
struct SRowBuilder {
void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) {
// TODO
};
struct SRowBatchIter {
int32_t counter; // row counter
SRowBatch *rb; // row batch to iter
SRow nrow; // next row
};
struct SRowBatchBuilder {
// TODO
};
/* ------------ Methods ---------- */
// SRowBuilder
SRowBuilder *rowBuilderCreate() {
SRowBuilder *pRowBuilder = NULL;
// TODO
return pRowBuilder;
}
void rowBuilderDestroy(SRowBuilder *pRowBuilder) {
if (pRowBuilder) {
free(pRowBuilder);
}
}
// SRowBatchIter
SRowBatchIter *rowBatchIterCreate(SRowBatch *pRowBatch) {
SRowBatchIter *pRowBatchIter = (SRowBatchIter *)malloc(sizeof(*pRowBatchIter));
if (pRowBatchIter == NULL) {
return NULL;
}
pRowBatchIter->counter = 0;
pRowBatchIter->rb = pRowBatch;
pRowBatchIter->nrow = pRowBatch->rows;
return pRowBatchIter;
};
void rowBatchIterDestroy(SRowBatchIter *pRowBatchIter) {
if (pRowBatchIter) {
free(pRowBatchIter);
}
void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) {
// TODO
}
const SRow rowBatchIterNext(SRowBatchIter *pRowBatchIter) {
SRow r = NULL;
if (pRowBatchIter->counter < pRowBatchIter->rb->nrows) {
r = pRowBatchIter->nrow;
pRowBatchIter->counter += 1;
pRowBatchIter->nrow = (SRow)POINTER_SHIFT(r, rowLen(r));
}
return r;
void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) {
// TODO
}
// SRowBatchBuilder
SRowBatchBuilder *rowBatchBuilderCreate();
void rowBatchBuilderDestroy(SRowBatchBuilder *);
#endif
\ No newline at end of file
int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) {
// TODO
return 0;
}
\ No newline at end of file
#include <gtest/gtest.h>
#include "trow.h"
TEST(td_row_test, build_row_to_target) {
char dst[1024];
SRow* pRow = (SRow*)dst;
int ncols = 10;
col_id_t cid;
void* pData;
SRowBuilder rb = trbInit(TD_OR_ROW_BUILDER, NULL, 0, pRow, 1024);
trbSetRowInfo(&rb, false, 0);
trbSetRowTS(&rb, 1637550210000);
for (int c = 0; c < ncols; c++) {
cid = c;
if (trbWriteCol(&rb, pData, cid) < 0) {
// TODO
}
}
}
\ No newline at end of file
#include <gtest/gtest.h>
#include "tschema.h"
TEST(td_schema_test, build_schema_test) {
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册