support json
This commit is contained in:
parent
4be79789ca
commit
6a6f31c4a7
|
@ -222,7 +222,7 @@ static char* indexCachePackJsonData(SIndexTerm* itm) {
|
||||||
char* buf = (char*)calloc(1, sz);
|
char* buf = (char*)calloc(1, sz);
|
||||||
char* p = buf;
|
char* p = buf;
|
||||||
|
|
||||||
memcpy(p, itm->colVal, itm->nColName);
|
memcpy(p, itm->colName, itm->nColName);
|
||||||
p += itm->nColName;
|
p += itm->nColName;
|
||||||
|
|
||||||
memcpy(p, &JSON_VALUE_DELIM, sizeof(JSON_VALUE_DELIM));
|
memcpy(p, &JSON_VALUE_DELIM, sizeof(JSON_VALUE_DELIM));
|
||||||
|
@ -329,13 +329,22 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
|
||||||
|
|
||||||
SIndexTerm* term = query->term;
|
SIndexTerm* term = query->term;
|
||||||
EIndexQueryType qtype = query->qType;
|
EIndexQueryType qtype = query->qType;
|
||||||
CacheTerm ct = {.colVal = term->colVal, .version = atomic_load_32(&pCache->version)};
|
|
||||||
|
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON);
|
||||||
|
char* p = term->colVal;
|
||||||
|
if (hasJson) {
|
||||||
|
p = indexCachePackJsonData(term);
|
||||||
|
}
|
||||||
|
CacheTerm ct = {.colVal = p, .version = atomic_load_32(&pCache->version)};
|
||||||
|
|
||||||
int ret = indexQueryMem(mem, &ct, qtype, result, s);
|
int ret = indexQueryMem(mem, &ct, qtype, result, s);
|
||||||
if (ret == 0 && *s != kTypeDeletion) {
|
if (ret == 0 && *s != kTypeDeletion) {
|
||||||
// continue search in imm
|
// continue search in imm
|
||||||
ret = indexQueryMem(imm, &ct, qtype, result, s);
|
ret = indexQueryMem(imm, &ct, qtype, result, s);
|
||||||
}
|
}
|
||||||
|
if (hasJson) {
|
||||||
|
tfree(p);
|
||||||
|
}
|
||||||
|
|
||||||
indexMemUnRef(mem);
|
indexMemUnRef(mem);
|
||||||
indexMemUnRef(imm);
|
indexMemUnRef(imm);
|
||||||
|
|
|
@ -2,6 +2,7 @@ add_executable(indexTest "")
|
||||||
add_executable(fstTest "")
|
add_executable(fstTest "")
|
||||||
add_executable(fstUT "")
|
add_executable(fstUT "")
|
||||||
add_executable(UtilUT "")
|
add_executable(UtilUT "")
|
||||||
|
add_executable(jsonUT "")
|
||||||
|
|
||||||
target_sources(indexTest
|
target_sources(indexTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
@ -21,6 +22,10 @@ target_sources(UtilUT
|
||||||
"utilUT.cc"
|
"utilUT.cc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_sources(jsonUT
|
||||||
|
PRIVATE
|
||||||
|
"jsonUT.cc"
|
||||||
|
)
|
||||||
target_include_directories ( indexTest
|
target_include_directories ( indexTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/index"
|
"${CMAKE_SOURCE_DIR}/include/libs/index"
|
||||||
|
@ -43,6 +48,12 @@ target_include_directories ( UtilUT
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/index"
|
"${CMAKE_SOURCE_DIR}/include/libs/index"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_include_directories (jsonUT
|
||||||
|
PUBLIC
|
||||||
|
"${CMAKE_SOURCE_DIR}/include/libs/index"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
target_link_libraries (indexTest
|
target_link_libraries (indexTest
|
||||||
os
|
os
|
||||||
util
|
util
|
||||||
|
@ -73,6 +84,13 @@ target_link_libraries (UtilUT
|
||||||
index
|
index
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries (jsonUT
|
||||||
|
os
|
||||||
|
util
|
||||||
|
common
|
||||||
|
gtest_main
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
#add_test(
|
#add_test(
|
||||||
# NAME index_test
|
# NAME index_test
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
#include "index.h"
|
||||||
|
#include "indexInt.h"
|
||||||
|
#include "index_cache.h"
|
||||||
|
#include "index_fst.h"
|
||||||
|
#include "index_fst_counting_writer.h"
|
||||||
|
#include "index_fst_util.h"
|
||||||
|
#include "index_tfile.h"
|
||||||
|
#include "index_util.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "tskiplist.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
|
||||||
|
static std::string dir = "/tmp/json";
|
||||||
|
class JsonEnv : public ::testing::Test {
|
||||||
|
protected:
|
||||||
|
virtual void SetUp() {
|
||||||
|
taosRemoveDir(dir.c_str());
|
||||||
|
opts = indexOptsCreate();
|
||||||
|
int ret = tIndexJsonOpen(opts, dir.c_str(), &index);
|
||||||
|
assert(ret == 0);
|
||||||
|
}
|
||||||
|
virtual void TearDown() {
|
||||||
|
tIndexJsonClose(index);
|
||||||
|
indexOptsDestroy(opts);
|
||||||
|
}
|
||||||
|
SIndexJsonOpts* opts;
|
||||||
|
SIndexJson* index;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(JsonEnv, testWrite) {
|
||||||
|
{
|
||||||
|
std::string colName("voltage");
|
||||||
|
std::string colVal("ab");
|
||||||
|
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||||
|
colVal.c_str(), colVal.size());
|
||||||
|
|
||||||
|
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||||
|
indexMultiTermAdd(terms, term);
|
||||||
|
for (size_t i = 0; i < 100; i++) {
|
||||||
|
tIndexJsonPut(index, terms, i);
|
||||||
|
}
|
||||||
|
indexMultiTermDestroy(terms);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string colName("voltage");
|
||||||
|
std::string colVal("ab1");
|
||||||
|
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||||
|
colVal.c_str(), colVal.size());
|
||||||
|
|
||||||
|
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||||
|
indexMultiTermAdd(terms, term);
|
||||||
|
for (size_t i = 0; i < 100; i++) {
|
||||||
|
tIndexJsonPut(index, terms, i);
|
||||||
|
}
|
||||||
|
indexMultiTermDestroy(terms);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string colName("voltage");
|
||||||
|
std::string colVal("123");
|
||||||
|
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||||
|
colVal.c_str(), colVal.size());
|
||||||
|
|
||||||
|
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||||
|
indexMultiTermAdd(terms, term);
|
||||||
|
for (size_t i = 0; i < 100; i++) {
|
||||||
|
tIndexJsonPut(index, terms, i);
|
||||||
|
}
|
||||||
|
indexMultiTermDestroy(terms);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string colName("voltage");
|
||||||
|
std::string colVal("ab");
|
||||||
|
|
||||||
|
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
|
||||||
|
SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||||
|
colVal.c_str(), colVal.size());
|
||||||
|
|
||||||
|
SArray* result = taosArrayInit(1, sizeof(uint64_t));
|
||||||
|
indexMultiTermQueryAdd(mq, q, QUERY_TERM);
|
||||||
|
tIndexJsonSearch(index, mq, result);
|
||||||
|
assert(100 == taosArrayGetSize(result));
|
||||||
|
indexMultiTermQueryDestroy(mq);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SIndexTermQuery query = {.term = term, .qType = QUERY_TERM};
|
||||||
|
}
|
Loading…
Reference in New Issue