From 65d72a48b476db424efad471f2ace89acc119044 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 28 Mar 2022 16:22:37 +0800 Subject: [PATCH] fst query --- source/libs/index/src/index_fst.c | 2 +- source/libs/index/src/index_fst_automation.c | 12 +++++- source/libs/index/test/fstTest.cc | 43 ++++++++++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 09f382bbdc..f35d7d39f2 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -1317,7 +1317,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) { taosArrayPop(sws->inp); } - streamStateDestroy(p); + // streamStateDestroy(p); continue; } FstTransition trn; diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/index_fst_automation.c index 668a527d4a..32623b09b4 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/index_fst_automation.c @@ -85,10 +85,20 @@ static void* prefixStart(AutomationCtx* ctx) { }; static bool prefixIsMatch(AutomationCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; - return ssv->val == strlen(ctx->data); + if (ssv == NULL) { + return false; + } + if (ssv->type == FST_INT) { + return ssv->val == strlen(ctx->data); + } else { + return false; + } } static bool prefixCanMatch(AutomationCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; + if (ssv == NULL) { + return false; + } return ssv->val >= 0; } static bool prefixWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index 94923726dd..7a8ee975c4 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -243,8 +243,7 @@ void checkFstCheckIterator() { std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; fw->Put("Hello world", 1); - fw->Put("hello world", 2); - fw->Put("hello worle", 3); + fw->Put("Hello worle", 2); fw->Put("hello worlf", 4); delete fw; @@ -258,7 +257,42 @@ void checkFstCheckIterator() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"H", AUTOMATION_PREFIX); + 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(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("Hello world", 1); + fw->Put("Hello worle", 2); + fw->Put("hello worlf", 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_PREFIX); m->Search(ctx, result); std::cout << "size: " << result.size() << std::endl; // assert(result.size() == count); @@ -332,7 +366,8 @@ int main(int argc, char* argv[]) { // path suid colName ver // iterTFileReader(argv[1], argv[2], argv[3], argv[4]); //} - checkFstCheckIterator(); + // checkFstCheckIterator(); + checkFstCheckIteratorPrefix(); // checkFstLongTerm(); // checkFstPrefixSearch();