more
This commit is contained in:
parent
e8d96d437e
commit
bf5586b4de
|
@ -3,40 +3,54 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "tstring.h"
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
|
|
||||||
typedef struct _scolumn {
|
// Column definition
|
||||||
tstring_t colName; // column name
|
// TODO: if we need to align the structure
|
||||||
td_datatype_t type; // data type
|
typedef struct {
|
||||||
int32_t bytes; // number of bytes
|
td_datatype_t type; // Column type
|
||||||
|
int32_t colId; // column ID
|
||||||
|
int32_t bytes; // column bytes
|
||||||
|
char * colName; // the column name
|
||||||
} SColumn;
|
} SColumn;
|
||||||
|
|
||||||
typedef struct SSchema {
|
// Schema definition
|
||||||
int32_t numOfCols;
|
typedef struct {
|
||||||
|
int32_t version; // schema version, it is used to change the schema
|
||||||
|
int32_t numOfCols;
|
||||||
|
int32_t numOfTags;
|
||||||
|
int32_t colIdCounter;
|
||||||
SColumn *columns;
|
SColumn *columns;
|
||||||
} SSchema;
|
} SSchema;
|
||||||
|
|
||||||
// Column with version
|
/* Inline schema definition
|
||||||
typedef struct {
|
* +---------+---------+---------+-----+---------+-----------+-----+-----------+
|
||||||
tstring_t colName;
|
* | int32_t | | | | | | | |
|
||||||
td_datatype_t type;
|
* +---------+---------+---------+-----+---------+-----------+-----+-----------+
|
||||||
int32_t colId;
|
* | len | SSchema | SColumn | ... | SColumn | col1_name | ... | colN_name |
|
||||||
int32_t bytes;
|
* +---------+---------+---------+-----+---------+-----------+-----+-----------+
|
||||||
} SVColumn;
|
*/
|
||||||
|
typedef char *SISchema
|
||||||
|
|
||||||
// Schema with version
|
// ---- operation on SColumn
|
||||||
typedef struct {
|
#define TD_COLUMN_TYPE(pCol) ((pCol)->type)
|
||||||
int32_t version; // Schema with version
|
#define TD_COLUMN_ID(pCol) ((pCol)->colId)
|
||||||
int32_t numOfCols;
|
#define TD_COLUMN_BYTES(pCol) ((pCol)->bytes)
|
||||||
int32_t numOfTags;
|
#define TD_COLUMN_NAME(pCol) ((pCol)->colName)
|
||||||
SVColumn *columns;
|
|
||||||
} SVSchema;
|
|
||||||
|
|
||||||
int32_t tdAddColumnToSchema(tstring_t pSchema, SColumn col);
|
// ---- operation on SSchema
|
||||||
|
#define TD_SCHEMA_VERSION(pSchema) ((pSchema)->version)
|
||||||
td_datatype_t tdGetTypeOfCol(SSchema *pSchema, int32_t col);
|
#define TD_SCHEMA_NCOLS(pSchema) ((pSchema)->numOfCols)
|
||||||
int32_t tdGetLengthOfCol(SSchema *pSchema, int32_t col);
|
#define TD_SCHEMA_NTAGS(pSchema) ((pSchema)->numOfTags)
|
||||||
|
#define TD_SCHEMA_TOTAL_COLS(pSchema) (TD_SCHEMA_NCOLS(pSchema) + TD_SCHEMA_NTAGS(pSchema))
|
||||||
|
#define TD_SCHEMA_NEXT_COLID(pSchema) ((pSchema)->colIdCounter++)
|
||||||
|
#define TD_SCHEMA_COLS(pSchema) ((pSchema)->columns)
|
||||||
|
#define TD_SCHEMA_TAGS(pSchema) (TD_SCHEMA_COLS(pSchema) + TD_SCHEMA_NCOLS(pSchema))
|
||||||
|
#define TD_SCHEMA_COLUMN_AT(pSchema, idx) TD_SCHEMA_COLS(pSchema)[idx]
|
||||||
|
#define TD_SCHEMA_TAG_AT(pSchema, idx) TD_SCHEMA_TAGS(pSchema)[idx]
|
||||||
|
|
||||||
|
// ---- operation on SISchema
|
||||||
|
#define TD_ISCHEMA_LEN(pISchema) *((int32_t *)(pISchema))
|
||||||
|
#define TD_ISCHEMA_SCHEMA(pISchema) ((SSchema *)((pISchema) + sizeof(int32_t)))
|
||||||
|
|
||||||
#endif // _TD_SCHEMA_H_
|
#endif // _TD_SCHEMA_H_
|
||||||
|
|
|
@ -29,4 +29,6 @@ typedef enum : uint8_t {
|
||||||
#define TD_DATATYPE_NCHAR_NULL
|
#define TD_DATATYPE_NCHAR_NULL
|
||||||
#define TD_DATATYPE_BINARY_NULL
|
#define TD_DATATYPE_BINARY_NULL
|
||||||
|
|
||||||
|
#define TD_IS_VALID_DATATYPE(type) (((type) > TD_DATA_TYPE_INVLD) && ((type) <= TD_DATATYPE_BINARY))
|
||||||
|
|
||||||
#endif // _TD_TYPE_H_
|
#endif // _TD_TYPE_H_
|
||||||
|
|
Loading…
Reference in New Issue