From 0c5f2d1da95899c0b1789d4e66b47a15eac4547f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 28 Mar 2022 21:41:41 +0800 Subject: [PATCH] update index range query --- source/libs/index/src/index_fst.c | 3 +- source/libs/index/src/index_fst_automation.c | 2 +- source/libs/index/test/fstTest.cc | 82 ++++++++++++++++++-- 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 5fd8865b21..3edf5fa406 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -720,7 +720,6 @@ bool fstNodeFindInput(FstNode* node, uint8_t b, uint64_t* res) { uint64_t out = fstStateFindInput(st, node, b, &null); if (null == false) { *res = out; - } else { s = false; } } @@ -1184,7 +1183,7 @@ StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstB sws->aut = automation; sws->inp = (SArray*)taosArrayInit(256, sizeof(uint8_t)); - sws->emptyOutput.null = false; + sws->emptyOutput.null = true; sws->emptyOutput.out = 0; sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/index_fst_automation.c index cf9d88b73e..20e981559d 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/index_fst_automation.c @@ -164,7 +164,7 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { // add more search type } - ctx->data = strdup((char*)data); + ctx->data = (data != NULL ? strdup((char*)data) : NULL); ctx->type = atype; ctx->stdata = (void*)sv; return ctx; diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index 1b9acbd67e..a38a7c9701 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -258,7 +258,7 @@ void checkFstLongTerm() { // taosMemoryFree(ctx); // delete m; } -void checkFstCheckIterator() { +void checkFstCheckIterator1() { FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); int count = 2; @@ -293,6 +293,41 @@ void checkFstCheckIterator() { taosMemoryFree(ctx); delete m; } +void checkFstCheckIterator2() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("a", 1); + fw->Put("b", 2); + fw->Put("c", 4); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + + // prefix search + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); + m->Search(ctx, result); + std::cout << "size: " << result.size() << std::endl; + // assert(result.size() == count); + for (int i = 0; i < result.size(); i++) { + // assert(result[i] == i); // check result + } + + taosMemoryFree(ctx); + delete m; +} void checkFstCheckIteratorPrefix() { FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); @@ -346,7 +381,7 @@ void checkFstCheckIteratorPrefix() { } delete m; } -void checkFstCheckIteratorRange() { +void checkFstCheckIteratorRange1() { FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); int count = 2; @@ -376,7 +411,42 @@ void checkFstCheckIteratorRange() { // [b, e) m->SearchRange(ctx, "b", "e", result); - // assert(result.size() == 1); + assert(result.size() == 3); + taosMemoryFree(ctx); + } +} +void checkFstCheckIteratorRange2() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("ab", 1); + fw->Put("bd", 2); + fw->Put("cdd", 3); + fw->Put("cde", 3); + fw->Put("ddd", 4); + fw->Put("ed", 5); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + { + // prefix search + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + + // [b, e) + m->SearchRange(ctx, "b", "ed", result); + assert(result.size() == 4); taosMemoryFree(ctx); } } @@ -443,9 +513,11 @@ int main(int argc, char* argv[]) { // path suid colName ver // iterTFileReader(argv[1], argv[2], argv[3], argv[4]); //} - // checkFstCheckIterator(); + // checkFstCheckIterator1(); + // checkFstCheckIterator2(); // checkFstCheckIteratorPrefix(); - checkFstCheckIteratorRange(); + checkFstCheckIteratorRange1(); + checkFstCheckIteratorRange2(); // checkFstLongTerm(); // checkFstPrefixSearch();