Merge pull request #12455 from taosdata/enh/add_more_index_ut
enh(index): add more UT
This commit is contained in:
commit
9dc392d321
|
@ -200,11 +200,37 @@ TEST(testCase, index_filter) {
|
||||||
doFilterTag(opNode, result);
|
doFilterTag(opNode, result);
|
||||||
EXPECT_EQ(1, taosArrayGetSize(result));
|
EXPECT_EQ(1, taosArrayGetSize(result));
|
||||||
|
|
||||||
|
taosArrayDestroy(result);
|
||||||
|
nodesDestroyNode(res);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||||
|
sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT);
|
||||||
|
sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV);
|
||||||
|
sifMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_INT, pLeft, pRight);
|
||||||
|
SArray *result = taosArrayInit(4, sizeof(uint64_t));
|
||||||
|
doFilterTag(opNode, result);
|
||||||
|
EXPECT_EQ(0, taosArrayGetSize(result));
|
||||||
|
taosArrayDestroy(result);
|
||||||
|
nodesDestroyNode(res);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||||
|
sifMakeColumnNode(&pLeft, "test", "col", COLUMN_TYPE_TAG, TSDB_DATA_TYPE_INT);
|
||||||
|
sifMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &sifRightV);
|
||||||
|
sifMakeOpNode(&opNode, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
|
||||||
|
|
||||||
|
SArray *result = taosArrayInit(4, sizeof(uint64_t));
|
||||||
|
doFilterTag(opNode, result);
|
||||||
|
EXPECT_EQ(0, taosArrayGetSize(result));
|
||||||
|
|
||||||
taosArrayDestroy(result);
|
taosArrayDestroy(result);
|
||||||
nodesDestroyNode(res);
|
nodesDestroyNode(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add other greater/lower/equal/in compare func test
|
||||||
|
|
||||||
TEST(testCase, index_filter_varify) {
|
TEST(testCase, index_filter_varify) {
|
||||||
{
|
{
|
||||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||||
|
|
|
@ -27,10 +27,33 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define INDEX_NUM_OF_THREADS 4
|
#define INDEX_NUM_OF_THREADS 4
|
||||||
#define INDEX_QUEUE_SIZE 200
|
#define INDEX_QUEUE_SIZE 200
|
||||||
|
|
||||||
void* indexQhandle = NULL;
|
void* indexQhandle = NULL;
|
||||||
|
|
||||||
|
#define INDEX_DATA_BOOL_NULL 0x02
|
||||||
|
#define INDEX_DATA_TINYINT_NULL 0x80
|
||||||
|
#define INDEX_DATA_SMALLINT_NULL 0x8000
|
||||||
|
#define INDEX_DATA_INT_NULL 0x80000000L
|
||||||
|
#define INDEX_DATA_BIGINT_NULL 0x8000000000000000L
|
||||||
|
#define INDEX_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
||||||
|
|
||||||
|
#define INDEX_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
||||||
|
#define INDEX_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
||||||
|
#define INDEX_DATA_NCHAR_NULL 0xFFFFFFFF
|
||||||
|
#define INDEX_DATA_BINARY_NULL 0xFF
|
||||||
|
#define INDEX_DATA_JSON_NULL 0xFFFFFFFF
|
||||||
|
#define INDEX_DATA_JSON_null 0xFFFFFFFE
|
||||||
|
#define INDEX_DATA_JSON_NOT_NULL 0x01
|
||||||
|
|
||||||
|
#define INDEX_DATA_UTINYINT_NULL 0xFF
|
||||||
|
#define INDEX_DATA_USMALLINT_NULL 0xFFFF
|
||||||
|
#define INDEX_DATA_UINT_NULL 0xFFFFFFFF
|
||||||
|
#define INDEX_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
||||||
|
|
||||||
|
#define INDEX_DATA_NULL_STR "NULL"
|
||||||
|
#define INDEX_DATA_NULL_STR_L "null"
|
||||||
|
|
||||||
void indexInit() {
|
void indexInit() {
|
||||||
// refactor later
|
// refactor later
|
||||||
indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, INDEX_NUM_OF_THREADS, "index");
|
indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, INDEX_NUM_OF_THREADS, "index");
|
||||||
|
@ -67,12 +90,6 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_LUCENE
|
|
||||||
index_t* index = index_open(path);
|
|
||||||
sIdx->index = index;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_INVERTED_INDEX
|
|
||||||
// sIdx->cache = (void*)indexCacheCreate(sIdx);
|
// sIdx->cache = (void*)indexCacheCreate(sIdx);
|
||||||
sIdx->tindex = indexTFileCreate(path);
|
sIdx->tindex = indexTFileCreate(path);
|
||||||
if (sIdx->tindex == NULL) {
|
if (sIdx->tindex == NULL) {
|
||||||
|
@ -85,7 +102,6 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
||||||
taosThreadMutexInit(&sIdx->mtx, NULL);
|
taosThreadMutexInit(&sIdx->mtx, NULL);
|
||||||
*index = sIdx;
|
*index = sIdx;
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
END:
|
END:
|
||||||
if (sIdx != NULL) {
|
if (sIdx != NULL) {
|
||||||
|
@ -97,12 +113,6 @@ END:
|
||||||
}
|
}
|
||||||
|
|
||||||
void indexClose(SIndex* sIdx) {
|
void indexClose(SIndex* sIdx) {
|
||||||
#ifdef USE_LUCENE
|
|
||||||
index_close(sIdex->index);
|
|
||||||
sIdx->index = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_INVERTED_INDEX
|
|
||||||
void* iter = taosHashIterate(sIdx->colObj, NULL);
|
void* iter = taosHashIterate(sIdx->colObj, NULL);
|
||||||
while (iter) {
|
while (iter) {
|
||||||
IndexCache** pCache = iter;
|
IndexCache** pCache = iter;
|
||||||
|
@ -114,31 +124,12 @@ void indexClose(SIndex* sIdx) {
|
||||||
taosHashCleanup(sIdx->colObj);
|
taosHashCleanup(sIdx->colObj);
|
||||||
taosThreadMutexDestroy(&sIdx->mtx);
|
taosThreadMutexDestroy(&sIdx->mtx);
|
||||||
indexTFileDestroy(sIdx->tindex);
|
indexTFileDestroy(sIdx->tindex);
|
||||||
#endif
|
|
||||||
taosMemoryFree(sIdx->path);
|
taosMemoryFree(sIdx->path);
|
||||||
taosMemoryFree(sIdx);
|
taosMemoryFree(sIdx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
||||||
#ifdef USE_LUCENE
|
|
||||||
index_document_t* doc = index_document_create();
|
|
||||||
|
|
||||||
char buf[16] = {0};
|
|
||||||
sprintf(buf, "%d", uid);
|
|
||||||
|
|
||||||
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
|
|
||||||
SIndexTerm* p = taosArrayGetP(fVals, i);
|
|
||||||
index_document_add(doc, (const char*)(p->key), p->nKey, (const char*)(p->val), p->nVal, 1);
|
|
||||||
}
|
|
||||||
index_document_add(doc, NULL, 0, buf, strlen(buf), 0);
|
|
||||||
|
|
||||||
index_put(index->index, doc);
|
|
||||||
index_document_destroy(doc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_INVERTED_INDEX
|
|
||||||
|
|
||||||
// TODO(yihao): reduce the lock range
|
// TODO(yihao): reduce the lock range
|
||||||
taosThreadMutexLock(&index->mtx);
|
taosThreadMutexLock(&index->mtx);
|
||||||
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
|
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
|
||||||
|
@ -170,12 +161,9 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result) {
|
int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result) {
|
||||||
#ifdef USE_INVERTED_INDEX
|
|
||||||
EIndexOperatorType opera = multiQuerys->opera; // relation of querys
|
EIndexOperatorType opera = multiQuerys->opera; // relation of querys
|
||||||
|
|
||||||
SArray* iRslts = taosArrayInit(4, POINTER_BYTES);
|
SArray* iRslts = taosArrayInit(4, POINTER_BYTES);
|
||||||
|
@ -188,35 +176,14 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result
|
||||||
}
|
}
|
||||||
indexMergeFinalResults(iRslts, opera, result);
|
indexMergeFinalResults(iRslts, opera, result);
|
||||||
indexInterResultsDestroy(iRslts);
|
indexInterResultsDestroy(iRslts);
|
||||||
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexDelete(SIndex* index, SIndexMultiTermQuery* query) {
|
int indexDelete(SIndex* index, SIndexMultiTermQuery* query) { return 1; }
|
||||||
#ifdef USE_INVERTED_INDEX
|
int indexRebuild(SIndex* index, SIndexOpts* opts) { return 0; }
|
||||||
|
|
||||||
#endif
|
SIndexOpts* indexOptsCreate() { return NULL; }
|
||||||
|
void indexOptsDestroy(SIndexOpts* opts) { return; }
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int indexRebuild(SIndex* index, SIndexOpts* opts) {
|
|
||||||
#ifdef USE_INVERTED_INDEX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SIndexOpts* indexOptsCreate() {
|
|
||||||
#ifdef USE_LUCENE
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
void indexOptsDestroy(SIndexOpts* opts) {
|
|
||||||
#ifdef USE_LUCENE
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* @param: oper
|
* @param: oper
|
||||||
*
|
*
|
||||||
|
|
|
@ -403,6 +403,19 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache) {
|
||||||
EXPECT_EQ(1000, taosArrayGetSize(result));
|
EXPECT_EQ(1000, taosArrayGetSize(result));
|
||||||
indexMultiTermQueryDestroy(mq);
|
indexMultiTermQueryDestroy(mq);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
std::string colName("other_column");
|
||||||
|
std::string colVal("100");
|
||||||
|
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
|
||||||
|
colVal.c_str(), colVal.size());
|
||||||
|
|
||||||
|
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||||
|
indexMultiTermAdd(terms, term);
|
||||||
|
for (size_t i = 0; i < 1000; i++) {
|
||||||
|
tIndexJsonPut(index, terms, i);
|
||||||
|
}
|
||||||
|
indexMultiTermDestroy(terms);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
std::string colName("test1");
|
std::string colName("test1");
|
||||||
std::string colVal("10");
|
std::string colVal("10");
|
||||||
|
|
|
@ -145,9 +145,9 @@ static void cliWalkCb(uv_handle_t* handle, void* arg);
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
#define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
||||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||||
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
||||||
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label)
|
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label)
|
||||||
#define CONN_SHOULD_RELEASE(conn, head) \
|
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||||
do { \
|
do { \
|
||||||
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
||||||
|
@ -223,11 +223,11 @@ static void cliWalkCb(uv_handle_t* handle, void* arg);
|
||||||
#define CONN_RELEASE_BY_SERVER(conn) \
|
#define CONN_RELEASE_BY_SERVER(conn) \
|
||||||
(((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
(((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||||
|
|
||||||
#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1)
|
#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1)
|
||||||
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1)
|
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1)
|
||||||
#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release)
|
#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release)
|
||||||
|
|
||||||
#define EPSET_GET_INUSE_IP(epSet) ((epSet)->eps[(epSet)->inUse].fqdn)
|
#define EPSET_GET_INUSE_IP(epSet) ((epSet)->eps[(epSet)->inUse].fqdn)
|
||||||
#define EPSET_GET_INUSE_PORT(epSet) ((epSet)->eps[(epSet)->inUse].port)
|
#define EPSET_GET_INUSE_PORT(epSet) ((epSet)->eps[(epSet)->inUse].port)
|
||||||
|
|
||||||
static void* cliWorkThread(void* arg);
|
static void* cliWorkThread(void* arg);
|
||||||
|
|
Loading…
Reference in New Issue