schema.h 2.0 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4 5 6 7
#if !defined(_TD_SCHEMA_H_)
#define _TD_SCHEMA_H_

#include <stdint.h>

#include "type.h"

H
more  
Hongze Cheng 已提交
8 9 10 11 12 13 14
// Column definition
// TODO: if we need to align the structure
typedef struct {
  td_datatype_t type;     // Column type
  int32_t       colId;    // column ID
  int32_t       bytes;    // column bytes
  char *        colName;  // the column name
H
more  
Hongze Cheng 已提交
15 16
} SColumn;

H
more  
Hongze Cheng 已提交
17 18 19 20 21 22
// Schema definition
typedef struct {
  int32_t  version;  // schema version, it is used to change the schema
  int32_t  numOfCols;
  int32_t  numOfTags;
  int32_t  colIdCounter;
H
more  
Hongze Cheng 已提交
23 24 25
  SColumn *columns;
} SSchema;

H
more  
Hongze Cheng 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/* Inline schema definition
 * +---------+---------+---------+-----+---------+-----------+-----+-----------+
 * | int32_t |         |         |     |         |           |     |           |
 * +---------+---------+---------+-----+---------+-----------+-----+-----------+
 * |   len   | SSchema | SColumn | ... | SColumn | col1_name | ... | colN_name |
 * +---------+---------+---------+-----+---------+-----------+-----+-----------+
 */
typedef char *SISchema

// ---- operation on SColumn
#define TD_COLUMN_TYPE(pCol) ((pCol)->type)
#define TD_COLUMN_ID(pCol) ((pCol)->colId)
#define TD_COLUMN_BYTES(pCol) ((pCol)->bytes)
#define TD_COLUMN_NAME(pCol) ((pCol)->colName)

// ---- operation on SSchema
#define TD_SCHEMA_VERSION(pSchema) ((pSchema)->version)
#define TD_SCHEMA_NCOLS(pSchema) ((pSchema)->numOfCols)
#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)))
H
more  
Hongze Cheng 已提交
55

H
more  
Hongze Cheng 已提交
56
#endif  // _TD_SCHEMA_H_