diff --git a/include/common/trow.h b/include/common/trow.h index 6094425bbf3d65524d97f3228872578a56ac2b2c..e699031d7adeb5ce7f74802b7a66652c52ff974c 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -16,16 +16,54 @@ #ifndef _TD_COMMON_ROW_H_ #define _TD_COMMON_ROW_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif -typedef struct SRow SRow; +// types +typedef void * SRow; +typedef struct SRowBatch SRowBatch; +typedef struct SRowBuilder SRowBuilder; +typedef struct SRowBatchIter SRowBatchIter; +typedef struct SRowBatchBuilder SRowBatchBuilder; + +// SRow +#define ROW_HEADER_SIZE (sizeof(uint8_t) + 2 * sizeof(uint16_t) + sizeof(uint64_t)) +#define rowType(r) (*(uint8_t *)(r)) // row type +#define rowLen(r) (*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t))) // row length +#define rowSVer(r) \ + (*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t) + sizeof(uint16_t))) // row schema version, only for SDataRow +#define rowNCols(r) rowSVer(r) // only for SKVRow +#define rowVer(r) (*(uint64_t)POINTER_SHIFT(r, sizeof(uint8_t) + 2 * sizeof(uint16_t))) // row version +#define rowCopy(dest, r) memcpy((dest), r, rowLen(r)) + +static FORCE_INLINE SRow rowDup(SRow row) { + SRow r = malloc(rowLen(row)); + if (r == NULL) { + return NULL; + } + + rowCopy(r, row); + + return r; +} + +// SRowBatch + +// SRowBuilder +SRowBuilder *rowBuilderCreate(); +void rowBuilderDestroy(SRowBuilder *); + +// SRowBatchIter +SRowBatchIter *rowBatchIterCreate(SRowBatch *); +void rowBatchIterDestroy(SRowBatchIter *); +const SRow rowBatchIterNext(SRowBatchIter *); -#define rowType(r) -#define rowLen(r) -#define rowVersion(r) -#define rowNCols(r) +// SRowBatchBuilder +SRowBatchBuilder *rowBatchBuilderCreate(); +void rowBatchBuilderDestroy(SRowBatchBuilder *); #ifdef __cplusplus } diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 6dea4a4e57392be988126c579648f39a8270b9bf..cf1b0ecefff4309ef7a86144f412cd0fed03d181 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -11,4 +11,79 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "trow.h" + +/* ------------ 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 +}; + +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); + } +} + +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 *); \ No newline at end of file diff --git a/source/server/vnode/meta/test/metaTests.cpp b/source/server/vnode/meta/test/metaTests.cpp index c62ae0aa0224a6724839fe41fe692f2b1dae37d6..ab204455f21ba17e94de860e6541517dfbfb7e1b 100644 --- a/source/server/vnode/meta/test/metaTests.cpp +++ b/source/server/vnode/meta/test/metaTests.cpp @@ -4,5 +4,6 @@ #include "meta.h" TEST(MetaTest, meta_open_test) { + metaOpen(NULL); std::cout << "Hello META!" << std::endl; } \ No newline at end of file