index.h 5.6 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 31
typedef struct SIndex               SIndex;
typedef struct SIndexTerm           SIndexTerm;
typedef struct SIndexOpts           SIndexOpts;
dengyihao's avatar
dengyihao 已提交
32 33
typedef struct SIndexMultiTermQuery SIndexMultiTermQuery;
typedef struct SArray               SIndexMultiTerm;
dengyihao's avatar
dengyihao 已提交
34

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

41 42 43 44 45 46
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 已提交
47 48
  DROP_SATBLE,   // drop stable
  DEFAULT        // query
dengyihao's avatar
dengyihao 已提交
49
} SIndexOperOnColumn;
dengyihao's avatar
dengyihao 已提交
50

dengyihao's avatar
dengyihao 已提交
51
typedef enum { MUST = 0, SHOULD, NOT } EIndexOperatorType;
dengyihao's avatar
dengyihao 已提交
52 53 54 55 56 57 58 59 60
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 已提交
61 62
  QUERY_RANGE,
  QUERY_MAX
dengyihao's avatar
dengyihao 已提交
63
} EIndexQueryType;
dengyihao's avatar
dengyihao 已提交
64

dengyihao's avatar
dengyihao 已提交
65
/*
dengyihao's avatar
dengyihao 已提交
66 67
 * create multi query
 * @param oper (input, relation between querys)
68
 */
dengyihao's avatar
dengyihao 已提交
69
SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType oper);
dengyihao's avatar
dengyihao 已提交
70

71
/*
dengyihao's avatar
dengyihao 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
 * 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 已提交
97
 */
dengyihao's avatar
dengyihao 已提交
98
void indexClose(SIndex* index);
dengyihao's avatar
dengyihao 已提交
99 100 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 132 133 134 135 136 137 138 139 140 141 142

/*
 * 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
 */
int indexRebuild(SIndex* index, SIndexOpts* opt);

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

dengyihao's avatar
dengyihao 已提交
146
void tIndexJsonClose(SIndexJson* index);
dengyihao's avatar
dengyihao 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

/*
 * 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 tIndexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
/*
 * search index
 * @param index (input, index object)
 * @param query (input, multi query condition)
 * @param result(output, query result)
 * @return error code
 */

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

dengyihao's avatar
dengyihao 已提交
179 180 181 182 183
/*
 * @param:
 * @param:
 */

dengyihao's avatar
dengyihao 已提交
184 185
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 已提交
186
void        indexTermDestroy(SIndexTerm* p);
dengyihao's avatar
dengyihao 已提交
187

dengyihao's avatar
dengyihao 已提交
188
/*
dengyihao's avatar
dengyihao 已提交
189
 * init index env
dengyihao's avatar
dengyihao 已提交
190 191
 *
 */
dengyihao's avatar
dengyihao 已提交
192 193
void indexInit();

dengyihao's avatar
dengyihao 已提交
194
/* index filter */
dengyihao's avatar
dengyihao 已提交
195 196 197 198 199
typedef struct SIndexMetaArg {
  void*    metaHandle;
  uint64_t suid;
} SIndexMetaArg;

dengyihao's avatar
dengyihao 已提交
200 201 202 203
typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltStatus;

SIdxFltStatus idxGetFltStatus(SNode* pFilterNode);

dengyihao's avatar
dengyihao 已提交
204
int32_t doFilterTag(const SNode* pFilterNode, SIndexMetaArg* metaArg, SArray* result);
dengyihao's avatar
dengyihao 已提交
205
/*
dengyihao's avatar
dengyihao 已提交
206
 * destory index env
dengyihao's avatar
dengyihao 已提交
207 208 209 210
 *
 */
void indexCleanUp();

H
refact  
Hongze Cheng 已提交
211 212 213 214
#ifdef __cplusplus
}
#endif

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