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"
C
update  
Cary Xu 已提交
21
#include "ttypes.h"
H
more  
Hongze Cheng 已提交
22

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

H
refact  
Hongze Cheng 已提交
27 28
#if 0
typedef struct STColumn {
H
more  
Hongze Cheng 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  /// 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 已提交
48
} STColumn;
H
more  
Hongze Cheng 已提交
49

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

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

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

H
refact  
Hongze Cheng 已提交
75 76
#endif

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

81
#endif /*_TD_COMMON_SCHEMA_H_*/