indexJson.c 2.2 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
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/>.
 */
#include "index.h"
dengyihao's avatar
dengyihao 已提交
16
#include "indexInt.h"
dengyihao's avatar
dengyihao 已提交
17 18 19

int tIndexJsonOpen(SIndexJsonOpts *opts, const char *path, SIndexJson **index) {
  // handle
dengyihao's avatar
dengyihao 已提交
20
  return indexOpen(opts, path, index);
dengyihao's avatar
dengyihao 已提交
21 22 23 24
}
int tIndexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) {
  for (int i = 0; i < taosArrayGetSize(terms); i++) {
    SIndexJsonTerm *p = taosArrayGetP(terms, i);
dengyihao's avatar
dengyihao 已提交
25 26 27 28 29 30 31 32
    if (p->colType == TSDB_DATA_TYPE_BOOL) {
      p->colType = TSDB_DATA_TYPE_INT;
    } else if (p->colType == TSDB_DATA_TYPE_VARCHAR || p->colType == TSDB_DATA_TYPE_NCHAR ||
               p->colType == TSDB_DATA_TYPE_BINARY) {
      // p->colType = TSDB_DATA_TYPE_NCHAR;
    } else {
      p->colType = TSDB_DATA_TYPE_DOUBLE;
    }
dengyihao's avatar
dengyihao 已提交
33 34 35
    INDEX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
  }
  // handle put
dengyihao's avatar
dengyihao 已提交
36
  return indexPut(index, terms, uid);
dengyihao's avatar
dengyihao 已提交
37 38
}

dengyihao's avatar
dengyihao 已提交
39 40
int tIndexJsonSearch(SIndexJson *index, SIndexJsonMultiTermQuery *tq, SArray *result) {
  SArray *terms = tq->query;
dengyihao's avatar
dengyihao 已提交
41 42
  for (int i = 0; i < taosArrayGetSize(terms); i++) {
    SIndexJsonTerm *p = taosArrayGetP(terms, i);
dengyihao's avatar
dengyihao 已提交
43 44 45 46 47 48 49 50
    if (p->colType == TSDB_DATA_TYPE_BOOL) {
      p->colType = TSDB_DATA_TYPE_INT;
    } else if (p->colType == TSDB_DATA_TYPE_VARCHAR || p->colType == TSDB_DATA_TYPE_NCHAR ||
               p->colType == TSDB_DATA_TYPE_BINARY) {
      // p->colType = TSDB_DATA_TYPE_NCHAR;
    } else {
      p->colType = TSDB_DATA_TYPE_DOUBLE;
    }
dengyihao's avatar
dengyihao 已提交
51 52 53
    INDEX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
  }
  // handle search
dengyihao's avatar
dengyihao 已提交
54
  return indexSearch(index, tq, result);
dengyihao's avatar
dengyihao 已提交
55 56
}

dengyihao's avatar
dengyihao 已提交
57
void tIndexJsonClose(SIndexJson *index) {
dengyihao's avatar
dengyihao 已提交
58
  // handle close
dengyihao's avatar
dengyihao 已提交
59
  return indexClose(index);
dengyihao's avatar
dengyihao 已提交
60
}