refact
This commit is contained in:
parent
98ae04e7e6
commit
9728ec02fe
|
@ -16,86 +16,10 @@
|
|||
#ifndef _TD_COMMON_SCHEMA_H_
|
||||
#define _TD_COMMON_SCHEMA_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -27,33 +27,34 @@ extern "C" {
|
|||
typedef uint64_t tuid_t;
|
||||
|
||||
// Types exported
|
||||
typedef struct SMeta SMeta;
|
||||
typedef struct SMetaOptions SMetaOptions;
|
||||
typedef struct SMetaQueryHandle SMetaQueryHandle;
|
||||
typedef struct SMetaQueryOptions SMetaQueryOptions;
|
||||
typedef struct SMeta SMeta;
|
||||
typedef struct SMetaOpts SMetaOpts;
|
||||
typedef struct SMetaQueryHandle SMetaQueryHandle;
|
||||
typedef struct SMetaQueryOpts SMetaQueryOpts;
|
||||
typedef struct STableOpts STableOpts;
|
||||
|
||||
// SMeta operations
|
||||
int metaCreate(const char *path);
|
||||
void metaDestroy(const char *path);
|
||||
SMeta *metaOpen(SMetaOptions *);
|
||||
SMeta *metaOpen(SMetaOpts *);
|
||||
void metaClose(SMeta *);
|
||||
int metaCreateTable(SMeta *, void *);
|
||||
int metaCreateTable(SMeta *, STableOpts *);
|
||||
int metaDropTable(SMeta *, uint64_t tuid_t);
|
||||
int metaAlterTable(SMeta *, void *);
|
||||
int metaCommit(SMeta *);
|
||||
|
||||
// Options
|
||||
SMetaOptions *metaOptionsCreate();
|
||||
void metaOptionsDestroy(SMetaOptions *);
|
||||
void metaOptionsSetCache(SMetaOptions *, size_t capacity);
|
||||
SMetaOpts *metaOptionsCreate();
|
||||
void metaOptionsDestroy(SMetaOpts *);
|
||||
void metaOptionsSetCache(SMetaOpts *, size_t capacity);
|
||||
|
||||
// SMetaQueryHandle
|
||||
SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOptions *);
|
||||
SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOpts *);
|
||||
void metaQueryHandleDestroy(SMetaQueryHandle *);
|
||||
|
||||
// SMetaQueryOptions
|
||||
SMetaQueryOptions *metaQueryOptionsCreate();
|
||||
void metaQueryOptionsDestroy(SMetaQueryOptions *);
|
||||
// SMetaQueryOpts
|
||||
SMetaQueryOpts *metaQueryOptionsCreate();
|
||||
void metaQueryOptionsDestroy(SMetaQueryOpts *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -51,9 +51,15 @@ struct SMeta {
|
|||
size_t totalUsed;
|
||||
};
|
||||
|
||||
struct STableOpts {
|
||||
int8_t type;
|
||||
char * name;
|
||||
STSchema *pSchema;
|
||||
};
|
||||
|
||||
/* -------------------- Methods -------------------- */
|
||||
|
||||
SMeta *metaOpen(SMetaOptions *options) {
|
||||
SMeta *metaOpen(SMetaOpts *options) {
|
||||
SMeta *pMeta = NULL;
|
||||
char * err = NULL;
|
||||
|
||||
|
@ -104,6 +110,11 @@ void metaClose(SMeta *pMeta) {
|
|||
}
|
||||
}
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaDestroy(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
int metaCommit(SMeta *meta) { return 0; }
|
Loading…
Reference in New Issue