tschema.h 1.9 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

16 17
#ifndef _TD_COMMON_SCHEMA_H_
#define _TD_COMMON_SCHEMA_H_
H
refact  
Hongze Cheng 已提交
18

H
more  
Hongze Cheng 已提交
19
#include "os.h"
H
more  
Hongze Cheng 已提交
20
#include "tarray.h"
H
more  
Hongze Cheng 已提交
21

H
refact  
Hongze Cheng 已提交
22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

H
more  
Hongze Cheng 已提交
26
typedef uint16_t col_id_t;
H
more  
Hongze Cheng 已提交
27

H
refact  
Hongze Cheng 已提交
28 29
#if 0
typedef struct STColumn {
H
more  
Hongze Cheng 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  /// column name
  char *cname;
  union {
    /// for encode purpose
    uint64_t info;
    struct {
      uint64_t sma : 1;
      /// column data type
      uint64_t type : 7;
      /// column id
      uint64_t cid : 16;
      /// max bytes of the column
      uint64_t bytes : 32;
      /// reserved
      uint64_t reserve : 8;
    };
  };
  /// comment about the column
  char *comment;
H
refact  
Hongze Cheng 已提交
49
} STColumn;
H
more  
Hongze Cheng 已提交
50

H
refact  
Hongze Cheng 已提交
51
typedef struct STSchema {
H
more  
Hongze Cheng 已提交
52 53
  /// schema version
  uint16_t sver;
H
more  
Hongze Cheng 已提交
54 55 56 57 58 59 60 61
  /// number of columns
  uint16_t ncols;
  /// sma attributes
  struct {
    bool    sma;
    SArray *smaArray;
  };
  /// column info
H
refact  
Hongze Cheng 已提交
62 63
  STColumn cols[];
} STSchema;
H
more  
Hongze Cheng 已提交
64

H
more  
Hongze Cheng 已提交
65
typedef struct {
H
refact  
Hongze Cheng 已提交
66 67 68
  uint64_t  size;
  STSchema *pSchema;
} STShemaBuilder;
H
more  
Hongze Cheng 已提交
69 70 71

#define tSchemaBuilderInit(target, capacity) \
  { .size = (capacity), .pSchema = (target) }
H
refact  
Hongze Cheng 已提交
72
void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver);
H
more  
Hongze Cheng 已提交
73 74 75
void tSchemaBuilderSetSMA(bool sma, SArray *smaArray);
int  tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment);

H
refact  
Hongze Cheng 已提交
76 77
#endif

H
refact  
Hongze Cheng 已提交
78 79 80 81
#ifdef __cplusplus
}
#endif

82
#endif /*_TD_COMMON_SCHEMA_H_*/