index.h 6.0 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/>.
 */

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

dengyihao's avatar
dengyihao 已提交
19
#include "nodes.h"
dengyihao's avatar
dengyihao 已提交
20
#include "os.h"
dengyihao's avatar
dengyihao 已提交
21
#include "taoserror.h"
dengyihao's avatar
dengyihao 已提交
22
#include "tarray.h"
dengyihao's avatar
dengyihao 已提交
23
#include "tglobal.h"
dengyihao's avatar
dengyihao 已提交
24

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

29 30
typedef struct SIndex               SIndex;
typedef struct SIndexTerm           SIndexTerm;
dengyihao's avatar
dengyihao 已提交
31 32
typedef struct SIndexMultiTermQuery SIndexMultiTermQuery;
typedef struct SArray               SIndexMultiTerm;
dengyihao's avatar
dengyihao 已提交
33

dengyihao's avatar
dengyihao 已提交
34 35 36 37 38 39
typedef struct SIndex               SIndexJson;
typedef struct SIndexTerm           SIndexJsonTerm;
typedef struct SIndexOpts           SIndexJsonOpts;
typedef struct SIndexMultiTermQuery SIndexJsonMultiTermQuery;
typedef struct SArray               SIndexJsonMultiTerm;

40 41 42 43 44 45
typedef enum {
  ADD_VALUE,     // add index colume value
  DEL_VALUE,     // delete index column value
  UPDATE_VALUE,  // update index column value
  ADD_INDEX,     // add index on specify column
  DROP_INDEX,    // drop existed index
dengyihao's avatar
dengyihao 已提交
46 47
  DROP_SATBLE,   // drop stable
  DEFAULT        // query
dengyihao's avatar
dengyihao 已提交
48
} SIndexOperOnColumn;
dengyihao's avatar
dengyihao 已提交
49

dengyihao's avatar
dengyihao 已提交
50
typedef enum { MUST = 0, SHOULD, NOT } EIndexOperatorType;
dengyihao's avatar
dengyihao 已提交
51 52 53 54 55 56 57 58 59
typedef enum {
  QUERY_TERM = 0,
  QUERY_PREFIX,
  QUERY_SUFFIX,
  QUERY_REGEX,
  QUERY_LESS_THAN,
  QUERY_LESS_EQUAL,
  QUERY_GREATER_THAN,
  QUERY_GREATER_EQUAL,
dengyihao's avatar
dengyihao 已提交
60 61
  QUERY_RANGE,
  QUERY_MAX
dengyihao's avatar
dengyihao 已提交
62
} EIndexQueryType;
dengyihao's avatar
dengyihao 已提交
63

dengyihao's avatar
dengyihao 已提交
64 65 66
typedef struct SIndexOpts {
  int32_t cacheSize;  // MB
} SIndexOpts;
dengyihao's avatar
dengyihao 已提交
67
/*
dengyihao's avatar
dengyihao 已提交
68 69
 * create multi query
 * @param oper (input, relation between querys)
70
 */
dengyihao's avatar
dengyihao 已提交
71
SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType oper);
dengyihao's avatar
dengyihao 已提交
72

73
/*
dengyihao's avatar
dengyihao 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
 * destroy multi query
 * @param pQuery (input, multi-query-object to be destory)
 */

void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery);
/*
 * add query to multi query
 * @param pQuery (input, multi-query-object)
 * @param term (input, single query term)
 * @param type (input, single query type)
 * @return error code
 */
int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType type);
/*
 * open index
 * @param opt (input, index opt)
 * @param path (input, index path)
 * @param index (output, index object)
 * @return error code
 */
int indexOpen(SIndexOpts* opt, const char* path, SIndex** index);
/*
 * close index
 * @param index (input, index to be closed)
 * @return error code
dengyihao's avatar
dengyihao 已提交
99
 */
dengyihao's avatar
dengyihao 已提交
100
void indexClose(SIndex* index);
dengyihao's avatar
dengyihao 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

/*
 * insert terms into index
 * @param index (input, index object)
 * @param term (input, terms inserted into index)
 * @param uid  (input, uid of terms)
 * @return error code
 */
int indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
/*
 * delete terms that meet query condition
 * @param index (input, index object)
 * @param query (input, condition query to deleted)
 * @return error code
 */

int indexDelete(SIndex* index, SIndexMultiTermQuery* query);
/*
 * search index
 * @param index (input, index object)
 * @param query (input, multi query condition)
 * @param result(output, query result)
 * @return error code
 */
int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
/*
 * rebuild index
 * @param index (input, index object)
 * @parma opt   (input, rebuild index opts)
 * @return error code
 */
dengyihao's avatar
dengyihao 已提交
132
// int indexRebuild(SIndex* index, SIndexOpts* opt);
dengyihao's avatar
dengyihao 已提交
133 134 135 136 137 138 139 140

/*
 * open index
 * @param opt (input,index json opt)
 * @param path (input, index json path)
 * @param index (output, index json object)
 * @return error code
 */
dengyihao's avatar
dengyihao 已提交
141
int indexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index);
dengyihao's avatar
dengyihao 已提交
142 143 144
/*
 * close index
 * @param index (input, index to be closed)
dengyihao's avatar
dengyihao 已提交
145
 * @return void
dengyihao's avatar
dengyihao 已提交
146 147
 */

dengyihao's avatar
dengyihao 已提交
148
void indexJsonClose(SIndexJson* index);
dengyihao's avatar
dengyihao 已提交
149 150 151 152 153 154 155 156

/*
 * insert terms into index
 * @param index (input, index object)
 * @param term (input, terms inserted into index)
 * @param uid  (input, uid of terms)
 * @return error code
 */
dengyihao's avatar
dengyihao 已提交
157
int indexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
dengyihao's avatar
dengyihao 已提交
158 159 160 161 162 163 164 165
/*
 * search index
 * @param index (input, index object)
 * @param query (input, multi query condition)
 * @param result(output, query result)
 * @return error code
 */

dengyihao's avatar
dengyihao 已提交
166
int indexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result);
dengyihao's avatar
dengyihao 已提交
167 168 169 170
/*
 * @param
 * @param
 */
dengyihao's avatar
dengyihao 已提交
171 172 173
SIndexMultiTerm* indexMultiTermCreate();
int              indexMultiTermAdd(SIndexMultiTerm* terms, SIndexTerm* term);
void             indexMultiTermDestroy(SIndexMultiTerm* terms);
dengyihao's avatar
dengyihao 已提交
174
/*
175
 * @param:
dengyihao's avatar
dengyihao 已提交
176 177
 * @param:
 */
dengyihao's avatar
dengyihao 已提交
178
SIndexOpts* indexOptsCreate(int32_t cacheSize);
dengyihao's avatar
dengyihao 已提交
179
void        indexOptsDestroy(SIndexOpts* opts);
dengyihao's avatar
dengyihao 已提交
180

dengyihao's avatar
dengyihao 已提交
181 182 183 184 185
/*
 * @param:
 * @param:
 */

dengyihao's avatar
dengyihao 已提交
186 187
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType, const char* colName,
                            int32_t nColName, const char* colVal, int32_t nColVal);
dengyihao's avatar
dengyihao 已提交
188
void        indexTermDestroy(SIndexTerm* p);
dengyihao's avatar
dengyihao 已提交
189

dengyihao's avatar
dengyihao 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
/*
 * rebuild index
 */
void indexRebuild(SIndexJson* idx, void* iter);

/*
 * check index json status
 **/
bool indexIsRebuild(SIndex* idx);
/*
 * rebuild index json
 */
void indexJsonRebuild(SIndexJson* idx, void* iter);

/*
 * check index json status
 **/
bool indexJsonIsRebuild(SIndexJson* idx);

dengyihao's avatar
dengyihao 已提交
209
/*
dengyihao's avatar
dengyihao 已提交
210
 * init index env
dengyihao's avatar
dengyihao 已提交
211 212
 *
 */
dengyihao's avatar
dengyihao 已提交
213 214
void indexInit();

dengyihao's avatar
dengyihao 已提交
215
/* index filter */
dengyihao's avatar
dengyihao 已提交
216
typedef struct SIndexMetaArg {
dengyihao's avatar
dengyihao 已提交
217
  void*    metaEx;
dengyihao's avatar
dengyihao 已提交
218 219
  void*    idx;
  void*    ivtIdx;
dengyihao's avatar
dengyihao 已提交
220 221 222
  uint64_t suid;
} SIndexMetaArg;

dengyihao's avatar
dengyihao 已提交
223 224 225 226
typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltStatus;

SIdxFltStatus idxGetFltStatus(SNode* pFilterNode);

dengyihao's avatar
dengyihao 已提交
227
int32_t doFilterTag(SNode* pFilterNode, SIndexMetaArg* metaArg, SArray* result, SIdxFltStatus* status);
dengyihao's avatar
dengyihao 已提交
228
/*
dengyihao's avatar
dengyihao 已提交
229
 * destory index env
dengyihao's avatar
dengyihao 已提交
230 231
 *
 */
dengyihao's avatar
dengyihao 已提交
232
void indexCleanup();
dengyihao's avatar
dengyihao 已提交
233

H
refact  
Hongze Cheng 已提交
234 235 236 237
#ifdef __cplusplus
}
#endif

dengyihao's avatar
dengyihao 已提交
238
#endif /*_TD_INDEX_H_*/