提交 9728ec02 编写于 作者: H Hongze Cheng

refact

上级 98ae04e7
...@@ -16,86 +16,10 @@ ...@@ -16,86 +16,10 @@
#ifndef _TD_COMMON_SCHEMA_H_ #ifndef _TD_COMMON_SCHEMA_H_
#define _TD_COMMON_SCHEMA_H_ #define _TD_COMMON_SCHEMA_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// ----------------- TSDB COLUMN DEFINITION
typedef struct {
int8_t type; // Column type
int16_t colId; // column ID
int16_t bytes; // column bytes (restore to int16_t in case of misuse)
uint16_t offset; // point offset in SDataRow after the header part.
} STColumn;
#define colType(col) ((col)->type)
#define colColId(col) ((col)->colId)
#define colBytes(col) ((col)->bytes)
#define colOffset(col) ((col)->offset)
#define colSetType(col, t) (colType(col) = (t))
#define colSetColId(col, id) (colColId(col) = (id))
#define colSetBytes(col, b) (colBytes(col) = (b))
#define colSetOffset(col, o) (colOffset(col) = (o))
// ----------------- TSDB SCHEMA DEFINITION
typedef struct {
int version; // version
int numOfCols; // Number of columns appended
int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + //
// (bytes))
uint16_t flen; // First part length in a SDataRow after the header part
uint16_t vlen; // pure value part length, excluded the overhead (bytes only)
STColumn columns[];
} STSchema;
#define schemaNCols(s) ((s)->numOfCols)
#define schemaVersion(s) ((s)->version)
#define schemaTLen(s) ((s)->tlen)
#define schemaFLen(s) ((s)->flen)
#define schemaVLen(s) ((s)->vlen)
#define schemaColAt(s, i) ((s)->columns + i)
#define tdFreeSchema(s) tfree((s))
STSchema *tdDupSchema(STSchema *pSchema);
int tdEncodeSchema(void **buf, STSchema *pSchema);
void * tdDecodeSchema(void *buf, STSchema **pRSchema);
static FORCE_INLINE int comparColId(const void *key1, const void *key2) {
if (*(int16_t *)key1 > ((STColumn *)key2)->colId) {
return 1;
} else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) {
return -1;
} else {
return 0;
}
}
static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) {
void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId);
if (ptr == NULL) return NULL;
return (STColumn *)ptr;
}
// ----------------- SCHEMA BUILDER DEFINITION
typedef struct {
int tCols;
int nCols;
int tlen;
uint16_t flen;
uint16_t vlen;
int version;
STColumn *columns;
} STSchemaBuilder;
int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder);
void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes);
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -27,33 +27,34 @@ extern "C" { ...@@ -27,33 +27,34 @@ extern "C" {
typedef uint64_t tuid_t; typedef uint64_t tuid_t;
// Types exported // Types exported
typedef struct SMeta SMeta; typedef struct SMeta SMeta;
typedef struct SMetaOptions SMetaOptions; typedef struct SMetaOpts SMetaOpts;
typedef struct SMetaQueryHandle SMetaQueryHandle; typedef struct SMetaQueryHandle SMetaQueryHandle;
typedef struct SMetaQueryOptions SMetaQueryOptions; typedef struct SMetaQueryOpts SMetaQueryOpts;
typedef struct STableOpts STableOpts;
// SMeta operations // SMeta operations
int metaCreate(const char *path); int metaCreate(const char *path);
void metaDestroy(const char *path); void metaDestroy(const char *path);
SMeta *metaOpen(SMetaOptions *); SMeta *metaOpen(SMetaOpts *);
void metaClose(SMeta *); void metaClose(SMeta *);
int metaCreateTable(SMeta *, void *); int metaCreateTable(SMeta *, STableOpts *);
int metaDropTable(SMeta *, uint64_t tuid_t); int metaDropTable(SMeta *, uint64_t tuid_t);
int metaAlterTable(SMeta *, void *); int metaAlterTable(SMeta *, void *);
int metaCommit(SMeta *); int metaCommit(SMeta *);
// Options // Options
SMetaOptions *metaOptionsCreate(); SMetaOpts *metaOptionsCreate();
void metaOptionsDestroy(SMetaOptions *); void metaOptionsDestroy(SMetaOpts *);
void metaOptionsSetCache(SMetaOptions *, size_t capacity); void metaOptionsSetCache(SMetaOpts *, size_t capacity);
// SMetaQueryHandle // SMetaQueryHandle
SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOptions *); SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOpts *);
void metaQueryHandleDestroy(SMetaQueryHandle *); void metaQueryHandleDestroy(SMetaQueryHandle *);
// SMetaQueryOptions // SMetaQueryOpts
SMetaQueryOptions *metaQueryOptionsCreate(); SMetaQueryOpts *metaQueryOptionsCreate();
void metaQueryOptionsDestroy(SMetaQueryOptions *); void metaQueryOptionsDestroy(SMetaQueryOpts *);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -51,9 +51,15 @@ struct SMeta { ...@@ -51,9 +51,15 @@ struct SMeta {
size_t totalUsed; size_t totalUsed;
}; };
struct STableOpts {
int8_t type;
char * name;
STSchema *pSchema;
};
/* -------------------- Methods -------------------- */ /* -------------------- Methods -------------------- */
SMeta *metaOpen(SMetaOptions *options) { SMeta *metaOpen(SMetaOpts *options) {
SMeta *pMeta = NULL; SMeta *pMeta = NULL;
char * err = NULL; char * err = NULL;
...@@ -104,6 +110,11 @@ void metaClose(SMeta *pMeta) { ...@@ -104,6 +110,11 @@ void metaClose(SMeta *pMeta) {
} }
} }
int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
// TODO
return 0;
}
void metaDestroy(const char *path) { taosRemoveDir(path); } void metaDestroy(const char *path) { taosRemoveDir(path); }
int metaCommit(SMeta *meta) { return 0; } int metaCommit(SMeta *meta) { return 0; }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册