more
This commit is contained in:
parent
274d115a05
commit
416e6354e9
|
@ -19,18 +19,18 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tbuffer.h"
|
#include "tbuffer.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
#include "tschema.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TD_OR_ROW 0
|
#define TD_UNDECIDED_ROW 0
|
||||||
#define TD_KV_ROW 1
|
#define TD_OR_ROW 1
|
||||||
|
#define TD_KV_ROW 2
|
||||||
typedef uint16_t col_id_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TSKEY ts;
|
// TODO
|
||||||
} SOrRow;
|
} SOrRow;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -48,21 +48,30 @@ typedef struct {
|
||||||
/// union field for encode and decode
|
/// union field for encode and decode
|
||||||
uint64_t info;
|
uint64_t info;
|
||||||
struct {
|
struct {
|
||||||
|
/// is deleted row
|
||||||
|
uint64_t del : 1;
|
||||||
/// row type
|
/// row type
|
||||||
uint64_t type : 2;
|
uint64_t type : 3;
|
||||||
/// row schema version
|
/// row schema version
|
||||||
uint64_t sver : 16;
|
uint64_t sver : 16;
|
||||||
/// row total length
|
/// row total length
|
||||||
uint64_t len : 46;
|
uint64_t len : 32;
|
||||||
|
/// reserved for back compatibility
|
||||||
|
uint64_t reserve : 12;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
/// row version
|
/// row version
|
||||||
uint64_t ver;
|
uint64_t ver;
|
||||||
/// timestamp of the row
|
/// timestamp
|
||||||
TSKEY ts;
|
TSKEY ts;
|
||||||
char content[];
|
char content[];
|
||||||
} SRow;
|
} SRow;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t nRows;
|
||||||
|
char rows[];
|
||||||
|
} SRowBatch;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/// ordinary row builder
|
/// ordinary row builder
|
||||||
TD_OR_ROW_BUILDER = 0,
|
TD_OR_ROW_BUILDER = 0,
|
||||||
|
@ -82,12 +91,32 @@ typedef struct {
|
||||||
} SRowBuilder;
|
} SRowBuilder;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* TODO */
|
SSchema *pSchema;
|
||||||
} SRowBatchBuilder;
|
SRow * pRow;
|
||||||
|
} SRowReader;
|
||||||
|
|
||||||
#define tRBInit(type, allocator, endian) \
|
typedef struct {
|
||||||
{ .type = (type), tbufInitWriter(allocator, endian), NULL }
|
uint32_t it;
|
||||||
void tRBClear(SRowBuilder *pRB);
|
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);
|
||||||
|
|
||||||
|
// SRowBatchIter
|
||||||
|
#define tRowBatchIterInit(pRB) \
|
||||||
|
{ .it = 0, .pRowBatch = (pRB) }
|
||||||
|
const SRow *tRowBatchIterNext(SRowBatchIter *pRowBatchIter);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,27 +17,61 @@
|
||||||
#define _TD_COMMON_SCHEMA_H_
|
#define _TD_COMMON_SCHEMA_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "tarray.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct SColAttr {
|
typedef uint16_t col_id_t;
|
||||||
/* data */
|
|
||||||
} SColAttr;
|
|
||||||
|
|
||||||
typedef struct SColumn {
|
typedef struct SColumn {
|
||||||
uint8_t type;
|
/// column name
|
||||||
uint16_t cid;
|
char *cname;
|
||||||
uint16_t bytes;
|
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;
|
} SColumn;
|
||||||
|
|
||||||
typedef struct SSchema {
|
typedef struct SSchema {
|
||||||
/// schema version
|
/// schema version
|
||||||
uint16_t sver;
|
uint16_t sver;
|
||||||
/* data */
|
/// number of columns
|
||||||
|
uint16_t ncols;
|
||||||
|
/// sma attributes
|
||||||
|
struct {
|
||||||
|
bool sma;
|
||||||
|
SArray *smaArray;
|
||||||
|
};
|
||||||
|
/// column info
|
||||||
|
SColumn cols[];
|
||||||
} SSchema;
|
} 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,77 +15,19 @@
|
||||||
|
|
||||||
#include "trow.h"
|
#include "trow.h"
|
||||||
|
|
||||||
#if 0
|
void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) {
|
||||||
/* ------------ 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 {
|
|
||||||
// TODO
|
// TODO
|
||||||
};
|
}
|
||||||
|
|
||||||
struct SRowBatchIter {
|
void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) {
|
||||||
int32_t counter; // row counter
|
|
||||||
SRowBatch *rb; // row batch to iter
|
|
||||||
SRow nrow; // next row
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SRowBatchBuilder {
|
|
||||||
// TODO
|
// TODO
|
||||||
};
|
}
|
||||||
|
|
||||||
/* ------------ Methods ---------- */
|
void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) {
|
||||||
|
|
||||||
// SRowBuilder
|
|
||||||
SRowBuilder *rowBuilderCreate() {
|
|
||||||
SRowBuilder *pRowBuilder = NULL;
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
return pRowBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rowBuilderDestroy(SRowBuilder *pRowBuilder) {
|
int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) {
|
||||||
if (pRowBuilder) {
|
// TODO
|
||||||
free(pRowBuilder);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SRowBatchBuilder
|
|
||||||
SRowBatchBuilder *rowBatchBuilderCreate();
|
|
||||||
void rowBatchBuilderDestroy(SRowBatchBuilder *);
|
|
||||||
#endif
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "tschema.h"
|
||||||
|
|
||||||
|
TEST(td_schema_test, build_schema_test) {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue