Merge pull request #13611 from taosdata/enh/jsonIdx2
enh: index support between
This commit is contained in:
commit
fd1b6a4310
|
@ -70,7 +70,7 @@ void indexCacheBroadcast(void* cache);
|
||||||
void indexCacheWait(void* cache);
|
void indexCacheWait(void* cache);
|
||||||
|
|
||||||
Iterate* indexCacheIteratorCreate(IndexCache* cache);
|
Iterate* indexCacheIteratorCreate(IndexCache* cache);
|
||||||
void indexCacheIteratorDestroy(Iterate* iiter);
|
void idxCacheIteratorDestroy(Iterate* iiter);
|
||||||
|
|
||||||
int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid);
|
int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid);
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ void indexCacheUnRef(IndexCache* cache);
|
||||||
|
|
||||||
void indexCacheDebug(IndexCache* cache);
|
void indexCacheDebug(IndexCache* cache);
|
||||||
|
|
||||||
void indexCacheDestroyImm(IndexCache* cache);
|
void idxCacheDestroyImm(IndexCache* cache);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,9 +26,9 @@ extern "C" {
|
||||||
extern char JSON_COLUMN[];
|
extern char JSON_COLUMN[];
|
||||||
extern char JSON_VALUE_DELIM;
|
extern char JSON_VALUE_DELIM;
|
||||||
|
|
||||||
char* indexPackJsonData(SIndexTerm* itm);
|
char* idxPackJsonData(SIndexTerm* itm);
|
||||||
char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip);
|
char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip);
|
||||||
char* indexPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip);
|
char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip);
|
||||||
|
|
||||||
typedef enum { MATCH, CONTINUE, BREAK } TExeCond;
|
typedef enum { MATCH, CONTINUE, BREAK } TExeCond;
|
||||||
|
|
||||||
|
@ -40,13 +40,14 @@ TExeCond tDoCompare(__compar_fn_t func, int8_t cmpType, void* a, void* b);
|
||||||
|
|
||||||
_cache_range_compare indexGetCompare(RangeType ty);
|
_cache_range_compare indexGetCompare(RangeType ty);
|
||||||
|
|
||||||
int32_t indexConvertData(void* src, int8_t type, void** dst);
|
int32_t idxConvertData(void* src, int8_t type, void** dst);
|
||||||
int32_t indexConvertDataToStr(void* src, int8_t type, void** dst);
|
int32_t idxConvertDataToStr(void* src, int8_t type, void** dst);
|
||||||
|
|
||||||
int32_t indexGetDataByteLen(int8_t type);
|
int32_t idxGetDataByteLen(int8_t type);
|
||||||
|
|
||||||
char* indexInt2str(int64_t val, char* dst, int radix);
|
char* idxInt2str(int64_t val, char* dst, int radix);
|
||||||
|
|
||||||
|
int idxUidCompare(const void* a, const void* b);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,9 +29,9 @@ extern "C" {
|
||||||
|
|
||||||
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
|
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
|
||||||
|
|
||||||
typedef struct Fst Fst;
|
typedef struct Fst Fst;
|
||||||
typedef struct FstNode FstNode;
|
typedef struct FstNode FstNode;
|
||||||
typedef struct StreamWithState StreamWithState;
|
typedef struct FStmSt FStmSt;
|
||||||
|
|
||||||
typedef enum { Included, Excluded, Unbounded } FstBound;
|
typedef enum { Included, Excluded, Unbounded } FstBound;
|
||||||
|
|
||||||
|
@ -40,12 +40,12 @@ typedef struct FstBoundWithData {
|
||||||
FstBound type;
|
FstBound type;
|
||||||
} FstBoundWithData;
|
} FstBoundWithData;
|
||||||
|
|
||||||
typedef struct FstStreamBuilder {
|
typedef struct FStmBuilder {
|
||||||
Fst* fst;
|
Fst* fst;
|
||||||
AutomationCtx* aut;
|
FAutoCtx* aut;
|
||||||
FstBoundWithData* min;
|
FstBoundWithData* min;
|
||||||
FstBoundWithData* max;
|
FstBoundWithData* max;
|
||||||
} FstStreamBuilder, FstStreamWithStateBuilder;
|
} FStmBuilder, FStmStBuilder;
|
||||||
|
|
||||||
typedef struct FstRange {
|
typedef struct FstRange {
|
||||||
uint64_t start;
|
uint64_t start;
|
||||||
|
@ -267,17 +267,17 @@ typedef struct Fst {
|
||||||
Fst* fstCreate(FstSlice* data);
|
Fst* fstCreate(FstSlice* data);
|
||||||
void fstDestroy(Fst* fst);
|
void fstDestroy(Fst* fst);
|
||||||
|
|
||||||
bool fstGet(Fst* fst, FstSlice* b, Output* out);
|
bool fstGet(Fst* fst, FstSlice* b, Output* out);
|
||||||
FstNode* fstGetNode(Fst* fst, CompiledAddr);
|
FstNode* fstGetNode(Fst* fst, CompiledAddr);
|
||||||
FstNode* fstGetRoot(Fst* fst);
|
FstNode* fstGetRoot(Fst* fst);
|
||||||
FstType fstGetType(Fst* fst);
|
FstType fstGetType(Fst* fst);
|
||||||
CompiledAddr fstGetRootAddr(Fst* fst);
|
CompiledAddr fstGetRootAddr(Fst* fst);
|
||||||
Output fstEmptyFinalOutput(Fst* fst, bool* null);
|
Output fstEmptyFinalOutput(Fst* fst, bool* null);
|
||||||
FstStreamBuilder* fstSearch(Fst* fst, AutomationCtx* ctx);
|
FStmBuilder* fstSearch(Fst* fst, FAutoCtx* ctx);
|
||||||
|
|
||||||
FstStreamWithStateBuilder* fstSearchWithState(Fst* fst, AutomationCtx* ctx);
|
FStmStBuilder* fstSearchWithState(Fst* fst, FAutoCtx* ctx);
|
||||||
// into stream to expand later
|
// into stream to expand later
|
||||||
StreamWithState* streamBuilderIntoStream(FstStreamBuilder* sb);
|
FStmSt* stmBuilderIntoStm(FStmBuilder* sb);
|
||||||
|
|
||||||
bool fstVerify(Fst* fst);
|
bool fstVerify(Fst* fst);
|
||||||
|
|
||||||
|
@ -293,41 +293,40 @@ typedef struct StreamState {
|
||||||
|
|
||||||
void streamStateDestroy(void* s);
|
void streamStateDestroy(void* s);
|
||||||
|
|
||||||
typedef struct StreamWithState {
|
typedef struct FStmSt {
|
||||||
Fst* fst;
|
Fst* fst;
|
||||||
AutomationCtx* aut;
|
FAutoCtx* aut;
|
||||||
SArray* inp;
|
SArray* inp;
|
||||||
FstOutput emptyOutput;
|
FstOutput emptyOutput;
|
||||||
SArray* stack; // <StreamState>
|
SArray* stack; // <StreamState>
|
||||||
FstBoundWithData* endAt;
|
FstBoundWithData* endAt;
|
||||||
} StreamWithState;
|
} FStmSt;
|
||||||
|
|
||||||
typedef struct StreamWithStateResult {
|
typedef struct FStmStRslt {
|
||||||
FstSlice data;
|
FstSlice data;
|
||||||
FstOutput out;
|
FstOutput out;
|
||||||
void* state;
|
void* state;
|
||||||
} StreamWithStateResult;
|
} FStmStRslt;
|
||||||
|
|
||||||
StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* state);
|
FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state);
|
||||||
void swsResultDestroy(StreamWithStateResult* result);
|
void swsResultDestroy(FStmStRslt* result);
|
||||||
|
|
||||||
typedef void* (*StreamCallback)(void*);
|
typedef void* (*StreamCallback)(void*);
|
||||||
StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstBoundWithData* min,
|
FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max);
|
||||||
FstBoundWithData* max);
|
|
||||||
|
|
||||||
void streamWithStateDestroy(StreamWithState* sws);
|
void stmStDestroy(FStmSt* sws);
|
||||||
|
|
||||||
bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min);
|
bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min);
|
||||||
|
|
||||||
StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback);
|
FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback);
|
||||||
|
|
||||||
FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut);
|
FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut);
|
||||||
|
|
||||||
void fstStreamBuilderDestroy(FstStreamBuilder* b);
|
void stmBuilderDestroy(FStmBuilder* b);
|
||||||
|
|
||||||
// set up bound range
|
// set up bound range
|
||||||
// refator later: to simple code by marco
|
// refator later: to simple code by marco
|
||||||
void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type);
|
void stmBuilderSetRange(FStmBuilder* b, FstSlice* val, RangeType type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,24 +22,24 @@ extern "C" {
|
||||||
#include "indexFstUtil.h"
|
#include "indexFstUtil.h"
|
||||||
#include "indexInt.h"
|
#include "indexInt.h"
|
||||||
|
|
||||||
typedef struct AutomationCtx AutomationCtx;
|
typedef struct FAutoCtx FAutoCtx;
|
||||||
|
|
||||||
typedef enum AutomationType { AUTOMATION_ALWAYS, AUTOMATION_PREFIX, AUTMMATION_MATCH } AutomationType;
|
typedef enum AutomationType { AUTOMATION_ALWAYS, AUTOMATION_PREFIX, AUTMMATION_MATCH } AutomationType;
|
||||||
|
|
||||||
typedef struct StartWith {
|
typedef struct StartWith {
|
||||||
AutomationCtx* autoSelf;
|
FAutoCtx* autoSelf;
|
||||||
} StartWith;
|
} StartWith;
|
||||||
|
|
||||||
typedef struct Complement {
|
typedef struct Complement {
|
||||||
AutomationCtx* autoSelf;
|
FAutoCtx* autoSelf;
|
||||||
} Complement;
|
} Complement;
|
||||||
|
|
||||||
// automation
|
// automation
|
||||||
typedef struct AutomationCtx {
|
typedef struct FAutoCtx {
|
||||||
AutomationType type;
|
AutomationType type;
|
||||||
void* stdata;
|
void* stdata;
|
||||||
char* data;
|
char* data;
|
||||||
} AutomationCtx;
|
} FAutoCtx;
|
||||||
|
|
||||||
typedef enum ValueType { FST_INT, FST_CHAR, FST_ARRAY } ValueType;
|
typedef enum ValueType { FST_INT, FST_CHAR, FST_ARRAY } ValueType;
|
||||||
typedef enum StartWithStateKind { Done, Running } StartWithStateKind;
|
typedef enum StartWithStateKind { Done, Running } StartWithStateKind;
|
||||||
|
@ -60,16 +60,16 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv);
|
||||||
void startWithStateValueDestroy(void* sv);
|
void startWithStateValueDestroy(void* sv);
|
||||||
|
|
||||||
typedef struct AutomationFunc {
|
typedef struct AutomationFunc {
|
||||||
void* (*start)(AutomationCtx* ctx);
|
void* (*start)(FAutoCtx* ctx);
|
||||||
bool (*isMatch)(AutomationCtx* ctx, void*);
|
bool (*isMatch)(FAutoCtx* ctx, void*);
|
||||||
bool (*canMatch)(AutomationCtx* ctx, void* data);
|
bool (*canMatch)(FAutoCtx* ctx, void* data);
|
||||||
bool (*willAlwaysMatch)(AutomationCtx* ctx, void* state);
|
bool (*willAlwaysMatch)(FAutoCtx* ctx, void* state);
|
||||||
void* (*accept)(AutomationCtx* ctx, void* state, uint8_t byte);
|
void* (*accept)(FAutoCtx* ctx, void* state, uint8_t byte);
|
||||||
void* (*acceptEof)(AutomationCtx* ct, void* state);
|
void* (*acceptEof)(FAutoCtx* ct, void* state);
|
||||||
} AutomationFunc;
|
} AutomationFunc;
|
||||||
|
|
||||||
AutomationCtx* automCtxCreate(void* data, AutomationType atype);
|
FAutoCtx* automCtxCreate(void* data, AutomationType atype);
|
||||||
void automCtxDestroy(AutomationCtx* ctx);
|
void automCtxDestroy(FAutoCtx* ctx);
|
||||||
|
|
||||||
extern AutomationFunc automFuncs[];
|
extern AutomationFunc automFuncs[];
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Binary file not shown.
|
@ -77,15 +77,15 @@ typedef struct SIdxColInfo {
|
||||||
|
|
||||||
static TdThreadOnce isInit = PTHREAD_ONCE_INIT;
|
static TdThreadOnce isInit = PTHREAD_ONCE_INIT;
|
||||||
// static void indexInit();
|
// static void indexInit();
|
||||||
static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result);
|
static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result);
|
||||||
|
|
||||||
static void indexInterResultsDestroy(SArray* results);
|
static void idxInterRsltDestroy(SArray* results);
|
||||||
static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out);
|
static int idxMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out);
|
||||||
|
|
||||||
static int indexGenTFile(SIndex* index, IndexCache* cache, SArray* batch);
|
static int idxGenTFile(SIndex* index, IndexCache* cache, SArray* batch);
|
||||||
|
|
||||||
// merge cache and tfile by opera type
|
// merge cache and tfile by opera type
|
||||||
static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateValue* iTfv, SIdxTRslt* helper);
|
static void idxMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateValue* iTfv, SIdxTRslt* helper);
|
||||||
|
|
||||||
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
|
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
|
||||||
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
||||||
|
@ -221,11 +221,11 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result
|
||||||
for (size_t i = 0; i < nQuery; i++) {
|
for (size_t i = 0; i < nQuery; i++) {
|
||||||
SIndexTermQuery* qterm = taosArrayGet(multiQuerys->query, i);
|
SIndexTermQuery* qterm = taosArrayGet(multiQuerys->query, i);
|
||||||
SArray* trslt = NULL;
|
SArray* trslt = NULL;
|
||||||
indexTermSearch(index, qterm, &trslt);
|
idxTermSearch(index, qterm, &trslt);
|
||||||
taosArrayPush(iRslts, (void*)&trslt);
|
taosArrayPush(iRslts, (void*)&trslt);
|
||||||
}
|
}
|
||||||
indexMergeFinalResults(iRslts, opera, result);
|
idxMergeFinalResults(iRslts, opera, result);
|
||||||
indexInterResultsDestroy(iRslts);
|
idxInterRsltDestroy(iRslts);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
|
||||||
tm->nColName = nColName;
|
tm->nColName = nColName;
|
||||||
|
|
||||||
char* buf = NULL;
|
char* buf = NULL;
|
||||||
int32_t len = indexConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf);
|
int32_t len = idxConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf);
|
||||||
assert(len != -1);
|
assert(len != -1);
|
||||||
|
|
||||||
tm->colVal = buf;
|
tm->colVal = buf;
|
||||||
|
@ -319,7 +319,7 @@ void indexMultiTermDestroy(SIndexMultiTerm* terms) {
|
||||||
taosArrayDestroy(terms);
|
taosArrayDestroy(terms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result) {
|
static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result) {
|
||||||
SIndexTerm* term = query->term;
|
SIndexTerm* term = query->term;
|
||||||
const char* colName = term->colName;
|
const char* colName = term->colName;
|
||||||
int32_t nColName = term->nColName;
|
int32_t nColName = term->nColName;
|
||||||
|
@ -374,7 +374,7 @@ END:
|
||||||
idxTRsltDestroy(tr);
|
idxTRsltDestroy(tr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
static void indexInterResultsDestroy(SArray* results) {
|
static void idxInterRsltDestroy(SArray* results) {
|
||||||
if (results == NULL) {
|
if (results == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,7 @@ static void indexInterResultsDestroy(SArray* results) {
|
||||||
taosArrayDestroy(results);
|
taosArrayDestroy(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out) {
|
static int idxMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out) {
|
||||||
// refactor, merge interResults into fResults by oType
|
// refactor, merge interResults into fResults by oType
|
||||||
for (int i = 0; i < taosArrayGetSize(in); i--) {
|
for (int i = 0; i < taosArrayGetSize(in); i--) {
|
||||||
SArray* t = taosArrayGetP(in, i);
|
SArray* t = taosArrayGetP(in, i);
|
||||||
|
@ -407,7 +407,7 @@ static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray*
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void indexMayMergeTempToFinalResult(SArray* result, TFileValue* tfv, SIdxTRslt* tr) {
|
static void idxMayMergeTempToFinalRslt(SArray* result, TFileValue* tfv, SIdxTRslt* tr) {
|
||||||
int32_t sz = taosArrayGetSize(result);
|
int32_t sz = taosArrayGetSize(result);
|
||||||
if (sz > 0) {
|
if (sz > 0) {
|
||||||
TFileValue* lv = taosArrayGetP(result, sz - 1);
|
TFileValue* lv = taosArrayGetP(result, sz - 1);
|
||||||
|
@ -427,11 +427,11 @@ static void indexMayMergeTempToFinalResult(SArray* result, TFileValue* tfv, SIdx
|
||||||
taosArrayPush(result, &tfv);
|
taosArrayPush(result, &tfv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void indexMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateValue* tv, SIdxTRslt* tr) {
|
static void idxMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateValue* tv, SIdxTRslt* tr) {
|
||||||
char* colVal = (cv != NULL) ? cv->colVal : tv->colVal;
|
char* colVal = (cv != NULL) ? cv->colVal : tv->colVal;
|
||||||
TFileValue* tfv = tfileValueCreate(colVal);
|
TFileValue* tfv = tfileValueCreate(colVal);
|
||||||
|
|
||||||
indexMayMergeTempToFinalResult(result, tfv, tr);
|
idxMayMergeTempToFinalRslt(result, tfv, tr);
|
||||||
|
|
||||||
if (cv != NULL) {
|
if (cv != NULL) {
|
||||||
uint64_t id = *(uint64_t*)taosArrayGet(cv->val, 0);
|
uint64_t id = *(uint64_t*)taosArrayGet(cv->val, 0);
|
||||||
|
@ -446,7 +446,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateVal
|
||||||
taosArrayAddAll(tr->total, tv->val);
|
taosArrayAddAll(tr->total, tv->val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void indexDestroyFinalResult(SArray* result) {
|
static void idxDestroyFinalRslt(SArray* result) {
|
||||||
int32_t sz = result ? taosArrayGetSize(result) : 0;
|
int32_t sz = result ? taosArrayGetSize(result) : 0;
|
||||||
for (size_t i = 0; i < sz; i++) {
|
for (size_t i = 0; i < sz; i++) {
|
||||||
TFileValue* tv = taosArrayGetP(result, i);
|
TFileValue* tv = taosArrayGetP(result, i);
|
||||||
|
@ -475,7 +475,7 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
|
||||||
Iterate* cacheIter = indexCacheIteratorCreate(pCache);
|
Iterate* cacheIter = indexCacheIteratorCreate(pCache);
|
||||||
if (cacheIter == NULL) {
|
if (cacheIter == NULL) {
|
||||||
indexError("%p immtable is empty, ignore merge opera", pCache);
|
indexError("%p immtable is empty, ignore merge opera", pCache);
|
||||||
indexCacheDestroyImm(pCache);
|
idxCacheDestroyImm(pCache);
|
||||||
tfileReaderUnRef(pReader);
|
tfileReaderUnRef(pReader);
|
||||||
atomic_store_32(&pCache->merging, 0);
|
atomic_store_32(&pCache->merging, 0);
|
||||||
if (quit) {
|
if (quit) {
|
||||||
|
@ -509,26 +509,26 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
|
||||||
comp = 1;
|
comp = 1;
|
||||||
}
|
}
|
||||||
if (comp == 0) {
|
if (comp == 0) {
|
||||||
indexMergeCacheAndTFile(result, cv, tv, tr);
|
idxMergeCacheAndTFile(result, cv, tv, tr);
|
||||||
cn = cacheIter->next(cacheIter);
|
cn = cacheIter->next(cacheIter);
|
||||||
tn = tfileIter->next(tfileIter);
|
tn = tfileIter->next(tfileIter);
|
||||||
} else if (comp < 0) {
|
} else if (comp < 0) {
|
||||||
indexMergeCacheAndTFile(result, cv, NULL, tr);
|
idxMergeCacheAndTFile(result, cv, NULL, tr);
|
||||||
cn = cacheIter->next(cacheIter);
|
cn = cacheIter->next(cacheIter);
|
||||||
} else {
|
} else {
|
||||||
indexMergeCacheAndTFile(result, NULL, tv, tr);
|
idxMergeCacheAndTFile(result, NULL, tv, tr);
|
||||||
tn = tfileIter->next(tfileIter);
|
tn = tfileIter->next(tfileIter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indexMayMergeTempToFinalResult(result, NULL, tr);
|
idxMayMergeTempToFinalRslt(result, NULL, tr);
|
||||||
idxTRsltDestroy(tr);
|
idxTRsltDestroy(tr);
|
||||||
|
|
||||||
int ret = indexGenTFile(sIdx, pCache, result);
|
int ret = idxGenTFile(sIdx, pCache, result);
|
||||||
indexDestroyFinalResult(result);
|
idxDestroyFinalRslt(result);
|
||||||
|
|
||||||
indexCacheDestroyImm(pCache);
|
idxCacheDestroyImm(pCache);
|
||||||
|
|
||||||
indexCacheIteratorDestroy(cacheIter);
|
idxCacheIteratorDestroy(cacheIter);
|
||||||
tfileIteratorDestroy(tfileIter);
|
tfileIteratorDestroy(tfileIter);
|
||||||
|
|
||||||
tfileReaderUnRef(pReader);
|
tfileReaderUnRef(pReader);
|
||||||
|
@ -578,7 +578,7 @@ static int64_t indexGetAvaialbleVer(SIndex* sIdx, IndexCache* cache) {
|
||||||
tfileReaderUnRef(rd);
|
tfileReaderUnRef(rd);
|
||||||
return ver;
|
return ver;
|
||||||
}
|
}
|
||||||
static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
|
static int idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
|
||||||
int64_t version = indexGetAvaialbleVer(sIdx, cache);
|
int64_t version = indexGetAvaialbleVer(sIdx, cache);
|
||||||
indexInfo("file name version: %" PRId64 "", version);
|
indexInfo("file name version: %" PRId64 "", version);
|
||||||
uint8_t colType = cache->type;
|
uint8_t colType = cache->type;
|
||||||
|
@ -625,7 +625,7 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf) {
|
||||||
|
|
||||||
char* p = buf;
|
char* p = buf;
|
||||||
char tbuf[65] = {0};
|
char tbuf[65] = {0};
|
||||||
indexInt2str((int64_t)key->suid, tbuf, 0);
|
idxInt2str((int64_t)key->suid, tbuf, 0);
|
||||||
|
|
||||||
SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf));
|
SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf));
|
||||||
SERIALIZE_VAR_TO_BUF(buf, '_', char);
|
SERIALIZE_VAR_TO_BUF(buf, '_', char);
|
||||||
|
|
|
@ -26,15 +26,15 @@
|
||||||
#define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20
|
#define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20
|
||||||
#define MEM_ESTIMATE_RADIO 1.5
|
#define MEM_ESTIMATE_RADIO 1.5
|
||||||
|
|
||||||
static void indexMemRef(MemTable* tbl);
|
static void idxMemRef(MemTable* tbl);
|
||||||
static void indexMemUnRef(MemTable* tbl);
|
static void idxMemUnRef(MemTable* tbl);
|
||||||
|
|
||||||
static void indexCacheTermDestroy(CacheTerm* ct);
|
static void idxCacheTermDestroy(CacheTerm* ct);
|
||||||
static int32_t indexCacheTermCompare(const void* l, const void* r);
|
static int32_t idxCacheTermCompare(const void* l, const void* r);
|
||||||
static int32_t indexCacheJsonTermCompare(const void* l, const void* r);
|
static int32_t idxCacheJsonTermCompare(const void* l, const void* r);
|
||||||
static char* indexCacheTermGet(const void* pData);
|
static char* idxCacheTermGet(const void* pData);
|
||||||
|
|
||||||
static MemTable* indexInternalCacheCreate(int8_t type);
|
static MemTable* idxInternalCacheCreate(int8_t type);
|
||||||
|
|
||||||
static int32_t cacheSearchTerm(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s);
|
static int32_t cacheSearchTerm(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s);
|
||||||
static int32_t cacheSearchPrefix(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s);
|
static int32_t cacheSearchPrefix(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s);
|
||||||
|
@ -82,7 +82,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe
|
||||||
pCt->colVal = term->colVal;
|
pCt->colVal = term->colVal;
|
||||||
pCt->version = atomic_load_64(&pCache->version);
|
pCt->version = atomic_load_64(&pCache->version);
|
||||||
|
|
||||||
char* key = indexCacheTermGet(pCt);
|
char* key = idxCacheTermGet(pCt);
|
||||||
|
|
||||||
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
||||||
while (tSkipListIterNext(iter)) {
|
while (tSkipListIterNext(iter)) {
|
||||||
|
@ -134,7 +134,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt*
|
||||||
pCt->colType = term->colType;
|
pCt->colType = term->colType;
|
||||||
pCt->version = atomic_load_64(&pCache->version);
|
pCt->version = atomic_load_64(&pCache->version);
|
||||||
|
|
||||||
char* key = indexCacheTermGet(pCt);
|
char* key = idxCacheTermGet(pCt);
|
||||||
|
|
||||||
SSkipListIterator* iter = tSkipListCreateIter(mem->mem);
|
SSkipListIterator* iter = tSkipListCreateIter(mem->mem);
|
||||||
while (tSkipListIterNext(iter)) {
|
while (tSkipListIterNext(iter)) {
|
||||||
|
@ -188,10 +188,10 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr
|
||||||
|
|
||||||
char* exBuf = NULL;
|
char* exBuf = NULL;
|
||||||
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||||
exBuf = indexPackJsonData(term);
|
exBuf = idxPackJsonData(term);
|
||||||
pCt->colVal = exBuf;
|
pCt->colVal = exBuf;
|
||||||
}
|
}
|
||||||
char* key = indexCacheTermGet(pCt);
|
char* key = idxCacheTermGet(pCt);
|
||||||
|
|
||||||
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
||||||
while (tSkipListIterNext(iter)) {
|
while (tSkipListIterNext(iter)) {
|
||||||
|
@ -269,20 +269,19 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
|
||||||
int8_t dType = INDEX_TYPE_GET_TYPE(term->colType);
|
int8_t dType = INDEX_TYPE_GET_TYPE(term->colType);
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
char* exBuf = NULL;
|
char* exBuf = NULL;
|
||||||
|
|
||||||
if (type == CONTAINS) {
|
if (type == CONTAINS) {
|
||||||
SIndexTerm tm = {.suid = term->suid,
|
SIndexTerm tm = {.suid = term->suid,
|
||||||
.operType = term->operType,
|
.operType = term->operType,
|
||||||
.colType = term->colType,
|
.colType = term->colType,
|
||||||
.colName = term->colVal,
|
.colName = term->colVal,
|
||||||
.nColName = term->nColVal};
|
.nColName = term->nColVal};
|
||||||
exBuf = indexPackJsonDataPrefixNoType(&tm, &skip);
|
exBuf = idxPackJsonDataPrefixNoType(&tm, &skip);
|
||||||
pCt->colVal = exBuf;
|
pCt->colVal = exBuf;
|
||||||
} else {
|
} else {
|
||||||
exBuf = indexPackJsonDataPrefix(term, &skip);
|
exBuf = idxPackJsonDataPrefix(term, &skip);
|
||||||
pCt->colVal = exBuf;
|
pCt->colVal = exBuf;
|
||||||
}
|
}
|
||||||
char* key = indexCacheTermGet(pCt);
|
char* key = idxCacheTermGet(pCt);
|
||||||
|
|
||||||
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
||||||
while (tSkipListIterNext(iter)) {
|
while (tSkipListIterNext(iter)) {
|
||||||
|
@ -341,7 +340,7 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
cache->mem = indexInternalCacheCreate(type);
|
cache->mem = idxInternalCacheCreate(type);
|
||||||
cache->mem->pCache = cache;
|
cache->mem->pCache = cache;
|
||||||
cache->colName = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? tstrdup(JSON_COLUMN) : tstrdup(colName);
|
cache->colName = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? tstrdup(JSON_COLUMN) : tstrdup(colName);
|
||||||
cache->type = type;
|
cache->type = type;
|
||||||
|
@ -364,7 +363,7 @@ void indexCacheDebug(IndexCache* cache) {
|
||||||
|
|
||||||
taosThreadMutexLock(&cache->mtx);
|
taosThreadMutexLock(&cache->mtx);
|
||||||
tbl = cache->mem;
|
tbl = cache->mem;
|
||||||
indexMemRef(tbl);
|
idxMemRef(tbl);
|
||||||
taosThreadMutexUnlock(&cache->mtx);
|
taosThreadMutexUnlock(&cache->mtx);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -380,13 +379,13 @@ void indexCacheDebug(IndexCache* cache) {
|
||||||
}
|
}
|
||||||
tSkipListDestroyIter(iter);
|
tSkipListDestroyIter(iter);
|
||||||
|
|
||||||
indexMemUnRef(tbl);
|
idxMemUnRef(tbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
taosThreadMutexLock(&cache->mtx);
|
taosThreadMutexLock(&cache->mtx);
|
||||||
tbl = cache->imm;
|
tbl = cache->imm;
|
||||||
indexMemRef(tbl);
|
idxMemRef(tbl);
|
||||||
taosThreadMutexUnlock(&cache->mtx);
|
taosThreadMutexUnlock(&cache->mtx);
|
||||||
if (tbl != NULL) {
|
if (tbl != NULL) {
|
||||||
SSkipList* slt = tbl->mem;
|
SSkipList* slt = tbl->mem;
|
||||||
|
@ -402,7 +401,7 @@ void indexCacheDebug(IndexCache* cache) {
|
||||||
tSkipListDestroyIter(iter);
|
tSkipListDestroyIter(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexMemUnRef(tbl);
|
idxMemUnRef(tbl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +426,7 @@ void indexCacheWait(void* cache) {
|
||||||
IndexCache* pCache = cache;
|
IndexCache* pCache = cache;
|
||||||
taosThreadCondWait(&pCache->finished, &pCache->mtx);
|
taosThreadCondWait(&pCache->finished, &pCache->mtx);
|
||||||
}
|
}
|
||||||
void indexCacheDestroyImm(IndexCache* cache) {
|
void idxCacheDestroyImm(IndexCache* cache) {
|
||||||
if (cache == NULL) {
|
if (cache == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -440,8 +439,8 @@ void indexCacheDestroyImm(IndexCache* cache) {
|
||||||
|
|
||||||
taosThreadMutexUnlock(&cache->mtx);
|
taosThreadMutexUnlock(&cache->mtx);
|
||||||
|
|
||||||
indexMemUnRef(tbl);
|
idxMemUnRef(tbl);
|
||||||
indexMemUnRef(tbl);
|
idxMemUnRef(tbl);
|
||||||
}
|
}
|
||||||
void indexCacheDestroy(void* cache) {
|
void indexCacheDestroy(void* cache) {
|
||||||
IndexCache* pCache = cache;
|
IndexCache* pCache = cache;
|
||||||
|
@ -449,8 +448,8 @@ void indexCacheDestroy(void* cache) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexMemUnRef(pCache->mem);
|
idxMemUnRef(pCache->mem);
|
||||||
indexMemUnRef(pCache->imm);
|
idxMemUnRef(pCache->imm);
|
||||||
taosMemoryFree(pCache->colName);
|
taosMemoryFree(pCache->colName);
|
||||||
|
|
||||||
taosThreadMutexDestroy(&pCache->mtx);
|
taosThreadMutexDestroy(&pCache->mtx);
|
||||||
|
@ -471,7 +470,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
||||||
}
|
}
|
||||||
taosThreadMutexLock(&cache->mtx);
|
taosThreadMutexLock(&cache->mtx);
|
||||||
|
|
||||||
indexMemRef(cache->imm);
|
idxMemRef(cache->imm);
|
||||||
|
|
||||||
MemTable* tbl = cache->imm;
|
MemTable* tbl = cache->imm;
|
||||||
iiter->val.val = taosArrayInit(1, sizeof(uint64_t));
|
iiter->val.val = taosArrayInit(1, sizeof(uint64_t));
|
||||||
|
@ -484,7 +483,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
||||||
|
|
||||||
return iiter;
|
return iiter;
|
||||||
}
|
}
|
||||||
void indexCacheIteratorDestroy(Iterate* iter) {
|
void idxCacheIteratorDestroy(Iterate* iter) {
|
||||||
if (iter == NULL) {
|
if (iter == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -518,7 +517,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
||||||
|
|
||||||
indexCacheRef(cache);
|
indexCacheRef(cache);
|
||||||
cache->imm = cache->mem;
|
cache->imm = cache->mem;
|
||||||
cache->mem = indexInternalCacheCreate(cache->type);
|
cache->mem = idxInternalCacheCreate(cache->type);
|
||||||
cache->mem->pCache = cache;
|
cache->mem->pCache = cache;
|
||||||
cache->occupiedMem = 0;
|
cache->occupiedMem = 0;
|
||||||
if (quit == false) {
|
if (quit == false) {
|
||||||
|
@ -546,7 +545,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
||||||
// set up key
|
// set up key
|
||||||
ct->colType = term->colType;
|
ct->colType = term->colType;
|
||||||
if (hasJson) {
|
if (hasJson) {
|
||||||
ct->colVal = indexPackJsonData(term);
|
ct->colVal = idxPackJsonData(term);
|
||||||
} else {
|
} else {
|
||||||
ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1));
|
ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1));
|
||||||
memcpy(ct->colVal, term->colVal, term->nColVal);
|
memcpy(ct->colVal, term->colVal, term->nColVal);
|
||||||
|
@ -562,9 +561,9 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
||||||
pCache->occupiedMem += estimate;
|
pCache->occupiedMem += estimate;
|
||||||
indexCacheMakeRoomForWrite(pCache);
|
indexCacheMakeRoomForWrite(pCache);
|
||||||
MemTable* tbl = pCache->mem;
|
MemTable* tbl = pCache->mem;
|
||||||
indexMemRef(tbl);
|
idxMemRef(tbl);
|
||||||
tSkipListPut(tbl->mem, (char*)ct);
|
tSkipListPut(tbl->mem, (char*)ct);
|
||||||
indexMemUnRef(tbl);
|
idxMemUnRef(tbl);
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pCache->mtx);
|
taosThreadMutexUnlock(&pCache->mtx);
|
||||||
|
|
||||||
|
@ -615,8 +614,8 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe
|
||||||
taosThreadMutexLock(&pCache->mtx);
|
taosThreadMutexLock(&pCache->mtx);
|
||||||
mem = pCache->mem;
|
mem = pCache->mem;
|
||||||
imm = pCache->imm;
|
imm = pCache->imm;
|
||||||
indexMemRef(mem);
|
idxMemRef(mem);
|
||||||
indexMemRef(imm);
|
idxMemRef(imm);
|
||||||
taosThreadMutexUnlock(&pCache->mtx);
|
taosThreadMutexUnlock(&pCache->mtx);
|
||||||
|
|
||||||
int ret = (mem && mem->mem) ? indexQueryMem(mem, query, result, s) : 0;
|
int ret = (mem && mem->mem) ? indexQueryMem(mem, query, result, s) : 0;
|
||||||
|
@ -625,8 +624,8 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe
|
||||||
ret = (imm && imm->mem) ? indexQueryMem(imm, query, result, s) : 0;
|
ret = (imm && imm->mem) ? indexQueryMem(imm, query, result, s) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexMemUnRef(mem);
|
idxMemUnRef(mem);
|
||||||
indexMemUnRef(imm);
|
idxMemUnRef(imm);
|
||||||
indexInfo("cache search, time cost %" PRIu64 "us", taosGetTimestampUs() - st);
|
indexInfo("cache search, time cost %" PRIu64 "us", taosGetTimestampUs() - st);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -649,14 +648,14 @@ void indexCacheUnRef(IndexCache* cache) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void indexMemRef(MemTable* tbl) {
|
void idxMemRef(MemTable* tbl) {
|
||||||
if (tbl == NULL) {
|
if (tbl == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int ref = T_REF_INC(tbl);
|
int ref = T_REF_INC(tbl);
|
||||||
UNUSED(ref);
|
UNUSED(ref);
|
||||||
}
|
}
|
||||||
void indexMemUnRef(MemTable* tbl) {
|
void idxMemUnRef(MemTable* tbl) {
|
||||||
if (tbl == NULL) {
|
if (tbl == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -668,18 +667,18 @@ void indexMemUnRef(MemTable* tbl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void indexCacheTermDestroy(CacheTerm* ct) {
|
static void idxCacheTermDestroy(CacheTerm* ct) {
|
||||||
if (ct == NULL) {
|
if (ct == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
taosMemoryFree(ct->colVal);
|
taosMemoryFree(ct->colVal);
|
||||||
taosMemoryFree(ct);
|
taosMemoryFree(ct);
|
||||||
}
|
}
|
||||||
static char* indexCacheTermGet(const void* pData) {
|
static char* idxCacheTermGet(const void* pData) {
|
||||||
CacheTerm* p = (CacheTerm*)pData;
|
CacheTerm* p = (CacheTerm*)pData;
|
||||||
return (char*)p;
|
return (char*)p;
|
||||||
}
|
}
|
||||||
static int32_t indexCacheTermCompare(const void* l, const void* r) {
|
static int32_t idxCacheTermCompare(const void* l, const void* r) {
|
||||||
CacheTerm* lt = (CacheTerm*)l;
|
CacheTerm* lt = (CacheTerm*)l;
|
||||||
CacheTerm* rt = (CacheTerm*)r;
|
CacheTerm* rt = (CacheTerm*)r;
|
||||||
// compare colVal
|
// compare colVal
|
||||||
|
@ -700,7 +699,7 @@ static int indexFindCh(char* a, char c) {
|
||||||
}
|
}
|
||||||
return p - a;
|
return p - a;
|
||||||
}
|
}
|
||||||
static int indexCacheJsonTermCompareImpl(char* a, char* b) {
|
static int idxCacheJsonTermCompareImpl(char* a, char* b) {
|
||||||
// int alen = indexFindCh(a, '&');
|
// int alen = indexFindCh(a, '&');
|
||||||
// int blen = indexFindCh(b, '&');
|
// int blen = indexFindCh(b, '&');
|
||||||
|
|
||||||
|
@ -720,7 +719,7 @@ static int indexCacheJsonTermCompareImpl(char* a, char* b) {
|
||||||
//}
|
//}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int32_t indexCacheJsonTermCompare(const void* l, const void* r) {
|
static int32_t idxCacheJsonTermCompare(const void* l, const void* r) {
|
||||||
CacheTerm* lt = (CacheTerm*)l;
|
CacheTerm* lt = (CacheTerm*)l;
|
||||||
CacheTerm* rt = (CacheTerm*)r;
|
CacheTerm* rt = (CacheTerm*)r;
|
||||||
// compare colVal
|
// compare colVal
|
||||||
|
@ -730,16 +729,15 @@ static int32_t indexCacheJsonTermCompare(const void* l, const void* r) {
|
||||||
}
|
}
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
static MemTable* indexInternalCacheCreate(int8_t type) {
|
static MemTable* idxInternalCacheCreate(int8_t type) {
|
||||||
int ttype = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? TSDB_DATA_TYPE_BINARY : TSDB_DATA_TYPE_BINARY;
|
int ttype = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? TSDB_DATA_TYPE_BINARY : TSDB_DATA_TYPE_BINARY;
|
||||||
int32_t (*cmpFn)(const void* l, const void* r) =
|
int32_t (*cmpFn)(const void* l, const void* r) =
|
||||||
INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? indexCacheJsonTermCompare : indexCacheTermCompare;
|
INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? idxCacheJsonTermCompare : idxCacheTermCompare;
|
||||||
|
|
||||||
MemTable* tbl = taosMemoryCalloc(1, sizeof(MemTable));
|
MemTable* tbl = taosMemoryCalloc(1, sizeof(MemTable));
|
||||||
indexMemRef(tbl);
|
idxMemRef(tbl);
|
||||||
if (ttype == TSDB_DATA_TYPE_BINARY || ttype == TSDB_DATA_TYPE_NCHAR) {
|
if (ttype == TSDB_DATA_TYPE_BINARY || ttype == TSDB_DATA_TYPE_NCHAR) {
|
||||||
tbl->mem =
|
tbl->mem = tSkipListCreate(MAX_SKIP_LIST_LEVEL, ttype, MAX_INDEX_KEY_LEN, cmpFn, SL_ALLOW_DUP_KEY, idxCacheTermGet);
|
||||||
tSkipListCreate(MAX_SKIP_LIST_LEVEL, ttype, MAX_INDEX_KEY_LEN, cmpFn, SL_ALLOW_DUP_KEY, indexCacheTermGet);
|
|
||||||
}
|
}
|
||||||
return tbl;
|
return tbl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
char JSON_COLUMN[] = "JSON";
|
char JSON_COLUMN[] = "JSON";
|
||||||
char JSON_VALUE_DELIM = '&';
|
char JSON_VALUE_DELIM = '&';
|
||||||
|
|
||||||
char* indexInt2str(int64_t val, char* dst, int radix) {
|
char* idxInt2str(int64_t val, char* dst, int radix) {
|
||||||
char buffer[65] = {0};
|
char buffer[65] = {0};
|
||||||
char* p;
|
char* p;
|
||||||
int64_t new_val;
|
int64_t new_val;
|
||||||
|
@ -207,7 +207,7 @@ static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {
|
||||||
|
|
||||||
_cache_range_compare indexGetCompare(RangeType ty) { return rangeCompare[ty]; }
|
_cache_range_compare indexGetCompare(RangeType ty) { return rangeCompare[ty]; }
|
||||||
|
|
||||||
char* indexPackJsonData(SIndexTerm* itm) {
|
char* idxPackJsonData(SIndexTerm* itm) {
|
||||||
/*
|
/*
|
||||||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||||
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
||||||
|
@ -235,7 +235,7 @@ char* indexPackJsonData(SIndexTerm* itm) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
|
char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
|
||||||
/*
|
/*
|
||||||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||||
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
||||||
|
@ -262,7 +262,7 @@ char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
char* indexPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) {
|
char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) {
|
||||||
/*
|
/*
|
||||||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||||
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
||||||
|
@ -283,7 +283,12 @@ char* indexPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t indexConvertData(void* src, int8_t type, void** dst) {
|
int idxUidCompare(const void* a, const void* b) {
|
||||||
|
uint64_t l = *(uint64_t*)a;
|
||||||
|
uint64_t r = *(uint64_t*)b;
|
||||||
|
return l - r;
|
||||||
|
}
|
||||||
|
int32_t idxConvertData(void* src, int8_t type, void** dst) {
|
||||||
int tlen = -1;
|
int tlen = -1;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
@ -368,44 +373,44 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) {
|
||||||
// indexMayFillNumbericData(*dst, tlen);
|
// indexMayFillNumbericData(*dst, tlen);
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) {
|
int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||||
int tlen = tDataTypes[type].bytes;
|
int tlen = tDataTypes[type].bytes;
|
||||||
int32_t bufSize = 64;
|
int32_t bufSize = 64;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(int64_t*)src, *dst, -1);
|
idxInt2str(*(int64_t*)src, *dst, -1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_BOOL:
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDB_DATA_TYPE_UTINYINT:
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(uint8_t*)src, *dst, 1);
|
idxInt2str(*(uint8_t*)src, *dst, 1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_TINYINT:
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(int8_t*)src, *dst, 1);
|
idxInt2str(*(int8_t*)src, *dst, 1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_SMALLINT:
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(int16_t*)src, *dst, -1);
|
idxInt2str(*(int16_t*)src, *dst, -1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_USMALLINT:
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(uint16_t*)src, *dst, -1);
|
idxInt2str(*(uint16_t*)src, *dst, -1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_INT:
|
case TSDB_DATA_TYPE_INT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(int32_t*)src, *dst, -1);
|
idxInt2str(*(int32_t*)src, *dst, -1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_UINT:
|
case TSDB_DATA_TYPE_UINT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(uint32_t*)src, *dst, 1);
|
idxInt2str(*(uint32_t*)src, *dst, 1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
@ -415,7 +420,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_UBIGINT:
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
indexInt2str(*(uint64_t*)src, *dst, 1);
|
idxInt2str(*(uint64_t*)src, *dst, 1);
|
||||||
tlen = strlen(*dst);
|
tlen = strlen(*dst);
|
||||||
case TSDB_DATA_TYPE_FLOAT:
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
*dst = taosMemoryCalloc(1, bufSize + 1);
|
*dst = taosMemoryCalloc(1, bufSize + 1);
|
||||||
|
|
|
@ -547,6 +547,8 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou
|
||||||
} else if (node->condType == LOGIC_COND_TYPE_NOT) {
|
} else if (node->condType == LOGIC_COND_TYPE_NOT) {
|
||||||
// taosArrayAddAll(output->result, params[m].result);
|
// taosArrayAddAll(output->result, params[m].result);
|
||||||
}
|
}
|
||||||
|
taosArraySort(output->result, idxUidCompare);
|
||||||
|
taosArrayRemoveDuplicate(output->result, idxUidCompare, NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int32_t m = 0; m < node->pParameterList->length; m++) {
|
for (int32_t m = 0; m < node->pParameterList->length; m++) {
|
||||||
|
|
|
@ -1087,19 +1087,19 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
||||||
*out = tOut;
|
*out = tOut;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
FstStreamBuilder* fstSearch(Fst* fst, AutomationCtx* ctx) {
|
FStmBuilder* fstSearch(Fst* fst, FAutoCtx* ctx) {
|
||||||
// refactor later
|
// refactor later
|
||||||
return fstStreamBuilderCreate(fst, ctx);
|
return stmBuilderCreate(fst, ctx);
|
||||||
}
|
}
|
||||||
StreamWithState* streamBuilderIntoStream(FstStreamBuilder* sb) {
|
FStmSt* stmBuilderIntoStm(FStmBuilder* sb) {
|
||||||
if (sb == NULL) {
|
if (sb == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return streamWithStateCreate(sb->fst, sb->aut, sb->min, sb->max);
|
return stmStCreate(sb->fst, sb->aut, sb->min, sb->max);
|
||||||
}
|
}
|
||||||
FstStreamWithStateBuilder* fstSearchWithState(Fst* fst, AutomationCtx* ctx) {
|
FStmStBuilder* fstSearchWithState(Fst* fst, FAutoCtx* ctx) {
|
||||||
// refactor later
|
// refactor later
|
||||||
return fstStreamBuilderCreate(fst, ctx);
|
return stmBuilderCreate(fst, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
FstNode* fstGetRoot(Fst* fst) {
|
FstNode* fstGetRoot(Fst* fst) {
|
||||||
|
@ -1176,9 +1176,8 @@ bool fstBoundWithDataIsIncluded(FstBoundWithData* bound) { return bound->type ==
|
||||||
|
|
||||||
void fstBoundDestroy(FstBoundWithData* bound) { taosMemoryFree(bound); }
|
void fstBoundDestroy(FstBoundWithData* bound) { taosMemoryFree(bound); }
|
||||||
|
|
||||||
StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstBoundWithData* min,
|
FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max) {
|
||||||
FstBoundWithData* max) {
|
FStmSt* sws = taosMemoryCalloc(1, sizeof(FStmSt));
|
||||||
StreamWithState* sws = taosMemoryCalloc(1, sizeof(StreamWithState));
|
|
||||||
if (sws == NULL) {
|
if (sws == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1192,11 +1191,11 @@ StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstB
|
||||||
|
|
||||||
sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState));
|
sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState));
|
||||||
sws->endAt = max;
|
sws->endAt = max;
|
||||||
streamWithStateSeekMin(sws, min);
|
stmStSeekMin(sws, min);
|
||||||
|
|
||||||
return sws;
|
return sws;
|
||||||
}
|
}
|
||||||
void streamWithStateDestroy(StreamWithState* sws) {
|
void stmStDestroy(FStmSt* sws) {
|
||||||
if (sws == NULL) {
|
if (sws == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1207,8 +1206,8 @@ void streamWithStateDestroy(StreamWithState* sws) {
|
||||||
taosMemoryFree(sws);
|
taosMemoryFree(sws);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) {
|
bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
AutomationCtx* aut = sws->aut;
|
FAutoCtx* aut = sws->aut;
|
||||||
if (fstBoundWithDataIsEmpty(min)) {
|
if (fstBoundWithDataIsEmpty(min)) {
|
||||||
if (fstBoundWithDataIsIncluded(min)) {
|
if (fstBoundWithDataIsIncluded(min)) {
|
||||||
sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null));
|
sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null));
|
||||||
|
@ -1301,9 +1300,9 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback) {
|
FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) {
|
||||||
AutomationCtx* aut = sws->aut;
|
FAutoCtx* aut = sws->aut;
|
||||||
FstOutput output = sws->emptyOutput;
|
FstOutput output = sws->emptyOutput;
|
||||||
if (output.null == false) {
|
if (output.null == false) {
|
||||||
FstSlice emptySlice = fstSliceCreate(NULL, 0);
|
FstSlice emptySlice = fstSliceCreate(NULL, 0);
|
||||||
if (fstBoundWithDataExceededBy(sws->endAt, &emptySlice)) {
|
if (fstBoundWithDataExceededBy(sws->endAt, &emptySlice)) {
|
||||||
|
@ -1367,8 +1366,8 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (FST_NODE_IS_FINAL(nextNode) && isMatch) {
|
if (FST_NODE_IS_FINAL(nextNode) && isMatch) {
|
||||||
FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)};
|
FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)};
|
||||||
StreamWithStateResult* result = swsResultCreate(&slice, fOutput, tState);
|
FStmStRslt* result = swsResultCreate(&slice, fOutput, tState);
|
||||||
taosMemoryFreeClear(buf);
|
taosMemoryFreeClear(buf);
|
||||||
fstSliceDestroy(&slice);
|
fstSliceDestroy(&slice);
|
||||||
taosArrayDestroy(nodes);
|
taosArrayDestroy(nodes);
|
||||||
|
@ -1382,8 +1381,8 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* state) {
|
FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state) {
|
||||||
StreamWithStateResult* result = taosMemoryCalloc(1, sizeof(StreamWithStateResult));
|
FStmStRslt* result = taosMemoryCalloc(1, sizeof(FStmStRslt));
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1393,7 +1392,7 @@ StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* sta
|
||||||
result->state = state;
|
result->state = state;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
void swsResultDestroy(StreamWithStateResult* result) {
|
void swsResultDestroy(FStmStRslt* result) {
|
||||||
if (NULL == result) {
|
if (NULL == result) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1411,8 +1410,8 @@ void streamStateDestroy(void* s) {
|
||||||
fstNodeDestroy(ss->node);
|
fstNodeDestroy(ss->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) {
|
FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut) {
|
||||||
FstStreamBuilder* b = taosMemoryCalloc(1, sizeof(FstStreamBuilder));
|
FStmBuilder* b = taosMemoryCalloc(1, sizeof(FStmBuilder));
|
||||||
if (NULL == b) {
|
if (NULL == b) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1423,14 +1422,14 @@ FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) {
|
||||||
b->max = fstBoundStateCreate(Unbounded, NULL);
|
b->max = fstBoundStateCreate(Unbounded, NULL);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
void fstStreamBuilderDestroy(FstStreamBuilder* b) {
|
void stmBuilderDestroy(FStmBuilder* b) {
|
||||||
fstSliceDestroy(&b->min->data);
|
fstSliceDestroy(&b->min->data);
|
||||||
fstSliceDestroy(&b->max->data);
|
fstSliceDestroy(&b->max->data);
|
||||||
taosMemoryFreeClear(b->min);
|
taosMemoryFreeClear(b->min);
|
||||||
taosMemoryFreeClear(b->max);
|
taosMemoryFreeClear(b->max);
|
||||||
taosMemoryFree(b);
|
taosMemoryFree(b);
|
||||||
}
|
}
|
||||||
void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type) {
|
void stmBuilderSetRange(FStmBuilder* b, FstSlice* val, RangeType type) {
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,19 +71,19 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate fst
|
// iterate fst
|
||||||
static void* alwaysMatchStart(AutomationCtx* ctx) { return NULL; }
|
static void* alwaysMatchStart(FAutoCtx* ctx) { return NULL; }
|
||||||
static bool alwaysMatchIsMatch(AutomationCtx* ctx, void* state) { return true; }
|
static bool alwaysMatchIsMatch(FAutoCtx* ctx, void* state) { return true; }
|
||||||
static bool alwaysMatchCanMatch(AutomationCtx* ctx, void* state) { return true; }
|
static bool alwaysMatchCanMatch(FAutoCtx* ctx, void* state) { return true; }
|
||||||
static bool alwaysMatchWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; }
|
static bool alwaysMatchWillAlwaysMatch(FAutoCtx* ctx, void* state) { return true; }
|
||||||
static void* alwaysMatchAccpet(AutomationCtx* ctx, void* state, uint8_t byte) { return NULL; }
|
static void* alwaysMatchAccpet(FAutoCtx* ctx, void* state, uint8_t byte) { return NULL; }
|
||||||
static void* alwaysMatchAccpetEof(AutomationCtx* ctx, void* state) { return NULL; }
|
static void* alwaysMatchAccpetEof(FAutoCtx* ctx, void* state) { return NULL; }
|
||||||
// prefix query, impl later
|
// prefix query, impl later
|
||||||
|
|
||||||
static void* prefixStart(AutomationCtx* ctx) {
|
static void* prefixStart(FAutoCtx* ctx) {
|
||||||
StartWithStateValue* data = (StartWithStateValue*)(ctx->stdata);
|
StartWithStateValue* data = (StartWithStateValue*)(ctx->stdata);
|
||||||
return startWithStateValueDump(data);
|
return startWithStateValueDump(data);
|
||||||
};
|
};
|
||||||
static bool prefixIsMatch(AutomationCtx* ctx, void* sv) {
|
static bool prefixIsMatch(FAutoCtx* ctx, void* sv) {
|
||||||
StartWithStateValue* ssv = (StartWithStateValue*)sv;
|
StartWithStateValue* ssv = (StartWithStateValue*)sv;
|
||||||
if (ssv == NULL) {
|
if (ssv == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -94,15 +94,15 @@ static bool prefixIsMatch(AutomationCtx* ctx, void* sv) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static bool prefixCanMatch(AutomationCtx* ctx, void* sv) {
|
static bool prefixCanMatch(FAutoCtx* ctx, void* sv) {
|
||||||
StartWithStateValue* ssv = (StartWithStateValue*)sv;
|
StartWithStateValue* ssv = (StartWithStateValue*)sv;
|
||||||
if (ssv == NULL) {
|
if (ssv == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ssv->val >= 0;
|
return ssv->val >= 0;
|
||||||
}
|
}
|
||||||
static bool prefixWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; }
|
static bool prefixWillAlwaysMatch(FAutoCtx* ctx, void* state) { return true; }
|
||||||
static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) {
|
static void* prefixAccept(FAutoCtx* ctx, void* state, uint8_t byte) {
|
||||||
StartWithStateValue* ssv = (StartWithStateValue*)state;
|
StartWithStateValue* ssv = (StartWithStateValue*)state;
|
||||||
if (ssv == NULL || ctx == NULL) {
|
if (ssv == NULL || ctx == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -125,18 +125,18 @@ static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) {
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
static void* prefixAcceptEof(AutomationCtx* ctx, void* state) { return NULL; }
|
static void* prefixAcceptEof(FAutoCtx* ctx, void* state) { return NULL; }
|
||||||
|
|
||||||
// pattern query, impl later
|
// pattern query, impl later
|
||||||
|
|
||||||
static void* patternStart(AutomationCtx* ctx) { return NULL; }
|
static void* patternStart(FAutoCtx* ctx) { return NULL; }
|
||||||
static bool patternIsMatch(AutomationCtx* ctx, void* data) { return true; }
|
static bool patternIsMatch(FAutoCtx* ctx, void* data) { return true; }
|
||||||
static bool patternCanMatch(AutomationCtx* ctx, void* data) { return true; }
|
static bool patternCanMatch(FAutoCtx* ctx, void* data) { return true; }
|
||||||
static bool patternWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; }
|
static bool patternWillAlwaysMatch(FAutoCtx* ctx, void* state) { return true; }
|
||||||
|
|
||||||
static void* patternAccept(AutomationCtx* ctx, void* state, uint8_t byte) { return NULL; }
|
static void* patternAccept(FAutoCtx* ctx, void* state, uint8_t byte) { return NULL; }
|
||||||
|
|
||||||
static void* patternAcceptEof(AutomationCtx* ctx, void* state) { return NULL; }
|
static void* patternAcceptEof(FAutoCtx* ctx, void* state) { return NULL; }
|
||||||
|
|
||||||
AutomationFunc automFuncs[] = {
|
AutomationFunc automFuncs[] = {
|
||||||
{alwaysMatchStart, alwaysMatchIsMatch, alwaysMatchCanMatch, alwaysMatchWillAlwaysMatch, alwaysMatchAccpet,
|
{alwaysMatchStart, alwaysMatchIsMatch, alwaysMatchCanMatch, alwaysMatchWillAlwaysMatch, alwaysMatchAccpet,
|
||||||
|
@ -146,8 +146,8 @@ AutomationFunc automFuncs[] = {
|
||||||
// add more search type
|
// add more search type
|
||||||
};
|
};
|
||||||
|
|
||||||
AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
|
FAutoCtx* automCtxCreate(void* data, AutomationType atype) {
|
||||||
AutomationCtx* ctx = taosMemoryCalloc(1, sizeof(AutomationCtx));
|
FAutoCtx* ctx = taosMemoryCalloc(1, sizeof(FAutoCtx));
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
|
||||||
ctx->stdata = (void*)sv;
|
ctx->stdata = (void*)sv;
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
void automCtxDestroy(AutomationCtx* ctx) {
|
void automCtxDestroy(FAutoCtx* ctx) {
|
||||||
startWithStateValueDestroy(ctx->stdata);
|
startWithStateValueDestroy(ctx->stdata);
|
||||||
taosMemoryFree(ctx->data);
|
taosMemoryFree(ctx->data);
|
||||||
taosMemoryFree(ctx);
|
taosMemoryFree(ctx);
|
||||||
|
|
|
@ -26,15 +26,14 @@
|
||||||
const static uint64_t tfileMagicNumber = 0xdb4775248b80fb57ull;
|
const static uint64_t tfileMagicNumber = 0xdb4775248b80fb57ull;
|
||||||
|
|
||||||
typedef struct TFileFstIter {
|
typedef struct TFileFstIter {
|
||||||
FstStreamBuilder* fb;
|
FStmBuilder* fb;
|
||||||
StreamWithState* st;
|
FStmSt* st;
|
||||||
AutomationCtx* ctx;
|
FAutoCtx* ctx;
|
||||||
TFileReader* rdr;
|
TFileReader* rdr;
|
||||||
} TFileFstIter;
|
} TFileFstIter;
|
||||||
|
|
||||||
#define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t))
|
#define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t))
|
||||||
|
|
||||||
static int tfileUidCompare(const void* a, const void* b);
|
|
||||||
static int tfileStrCompare(const void* a, const void* b);
|
static int tfileStrCompare(const void* a, const void* b);
|
||||||
static int tfileValueCompare(const void* a, const void* b, const void* param);
|
static int tfileValueCompare(const void* a, const void* b, const void* param);
|
||||||
static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds);
|
static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds);
|
||||||
|
@ -245,26 +244,21 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
|
||||||
char* p = tem->colVal;
|
char* p = tem->colVal;
|
||||||
uint64_t sz = tem->nColVal;
|
uint64_t sz = tem->nColVal;
|
||||||
if (hasJson) {
|
|
||||||
p = indexPackJsonData(tem);
|
|
||||||
sz = strlen(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
||||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
FStmBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
taosArrayPush(offsets, &(rt->out.out));
|
taosArrayPush(offsets, &(rt->out.out));
|
||||||
swsResultDestroy(rt);
|
swsResultDestroy(rt);
|
||||||
}
|
}
|
||||||
streamWithStateDestroy(st);
|
stmStDestroy(st);
|
||||||
fstStreamBuilderDestroy(sb);
|
stmBuilderDestroy(sb);
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int i = 0; i < taosArrayGetSize(offsets); i++) {
|
for (int i = 0; i < taosArrayGetSize(offsets); i++) {
|
||||||
|
@ -275,27 +269,14 @@ static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
return TSDB_CODE_TDB_FILE_CORRUPTED;
|
return TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasJson) {
|
|
||||||
taosMemoryFree(p);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char* p = tem->colVal;
|
char* p = tem->colVal;
|
||||||
uint64_t sz = tem->nColVal;
|
uint64_t sz = tem->nColVal;
|
||||||
if (hasJson) {
|
|
||||||
p = indexPackJsonData(tem);
|
|
||||||
sz = strlen(p);
|
|
||||||
}
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
FstSlice key = fstSliceCreate(p, sz);
|
FstSlice key = fstSliceCreate(p, sz);
|
||||||
/*impl later*/
|
|
||||||
if (hasJson) {
|
|
||||||
taosMemoryFree(p);
|
|
||||||
}
|
|
||||||
fstSliceDestroy(&key);
|
fstSliceDestroy(&key);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -306,7 +287,7 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
char* p = tem->colVal;
|
char* p = tem->colVal;
|
||||||
uint64_t sz = tem->nColVal;
|
uint64_t sz = tem->nColVal;
|
||||||
if (hasJson) {
|
if (hasJson) {
|
||||||
p = indexPackJsonData(tem);
|
p = idxPackJsonData(tem);
|
||||||
sz = strlen(p);
|
sz = strlen(p);
|
||||||
}
|
}
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
|
@ -328,16 +309,16 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr,
|
||||||
|
|
||||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_ALWAYS);
|
||||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
FStmBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||||
|
|
||||||
FstSlice h = fstSliceCreate((uint8_t*)p, skip);
|
FstSlice h = fstSliceCreate((uint8_t*)p, skip);
|
||||||
fstStreamBuilderSetRange(sb, &h, type);
|
stmBuilderSetRange(sb, &h, type);
|
||||||
fstSliceDestroy(&h);
|
fstSliceDestroy(&h);
|
||||||
|
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
FstSlice* s = &rt->data;
|
FstSlice* s = &rt->data;
|
||||||
char* ch = (char*)fstSliceData(s, NULL);
|
char* ch = (char*)fstSliceData(s, NULL);
|
||||||
// if (0 != strncmp(ch, tem->colName, tem->nColName)) {
|
// if (0 != strncmp(ch, tem->colName, tem->nColName)) {
|
||||||
|
@ -355,8 +336,8 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr,
|
||||||
}
|
}
|
||||||
swsResultDestroy(rt);
|
swsResultDestroy(rt);
|
||||||
}
|
}
|
||||||
streamWithStateDestroy(st);
|
stmStDestroy(st);
|
||||||
fstStreamBuilderDestroy(sb);
|
stmBuilderDestroy(sb);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
static int32_t tfSearchLessThan(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
static int32_t tfSearchLessThan(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
|
@ -372,37 +353,17 @@ static int32_t tfSearchGreaterEqual(void* reader, SIndexTerm* tem, SIdxTRslt* tr
|
||||||
return tfSearchCompareFunc(reader, tem, tr, GE);
|
return tfSearchCompareFunc(reader, tem, tr, GE);
|
||||||
}
|
}
|
||||||
static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char* p = tem->colVal;
|
char* p = tem->colVal;
|
||||||
uint64_t sz = tem->nColVal;
|
uint64_t sz = tem->nColVal;
|
||||||
if (hasJson) {
|
|
||||||
p = indexPackJsonData(tem);
|
|
||||||
sz = strlen(p);
|
|
||||||
}
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
FstSlice key = fstSliceCreate(p, sz);
|
FstSlice key = fstSliceCreate(p, sz);
|
||||||
// uint64_t offset;
|
|
||||||
// if (fstGet(((TFileReader*)reader)->fst, &key, &offset)) {
|
|
||||||
// int64_t et = taosGetTimestampUs();
|
|
||||||
// int64_t cost = et - st;
|
|
||||||
// indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
|
||||||
// tem->suid, tem->colName, tem->colVal, cost);
|
|
||||||
|
|
||||||
// ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total);
|
|
||||||
// cost = taosGetTimestampUs() - et;
|
|
||||||
// indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid,
|
|
||||||
// tem->colName, tem->colVal, cost);
|
|
||||||
//}
|
|
||||||
if (hasJson) {
|
|
||||||
taosMemoryFree(p);
|
|
||||||
}
|
|
||||||
fstSliceDestroy(&key);
|
fstSliceDestroy(&key);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char* p = indexPackJsonData(tem);
|
char* p = idxPackJsonData(tem);
|
||||||
int sz = strlen(p);
|
int sz = strlen(p);
|
||||||
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
|
@ -422,8 +383,6 @@ static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
}
|
}
|
||||||
fstSliceDestroy(&key);
|
fstSliceDestroy(&key);
|
||||||
return 0;
|
return 0;
|
||||||
// deprecate api
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
static int32_t tfSearchEqual_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
static int32_t tfSearchEqual_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||||
return tfSearchCompareFunc_JSON(reader, tem, tr, EQ);
|
return tfSearchCompareFunc_JSON(reader, tem, tr, EQ);
|
||||||
|
@ -467,21 +426,21 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
|
||||||
.colType = tem->colType,
|
.colType = tem->colType,
|
||||||
.colName = tem->colVal,
|
.colName = tem->colVal,
|
||||||
.nColName = tem->nColVal};
|
.nColName = tem->nColVal};
|
||||||
p = indexPackJsonDataPrefixNoType(&tm, &skip);
|
p = idxPackJsonDataPrefixNoType(&tm, &skip);
|
||||||
} else {
|
} else {
|
||||||
p = indexPackJsonDataPrefix(tem, &skip);
|
p = idxPackJsonDataPrefix(tem, &skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
_cache_range_compare cmpFn = indexGetCompare(ctype);
|
_cache_range_compare cmpFn = indexGetCompare(ctype);
|
||||||
|
|
||||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
||||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
FStmBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||||
|
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
FstSlice* s = &rt->data;
|
FstSlice* s = &rt->data;
|
||||||
|
|
||||||
int32_t sz = 0;
|
int32_t sz = 0;
|
||||||
|
@ -509,8 +468,8 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
|
||||||
}
|
}
|
||||||
swsResultDestroy(rt);
|
swsResultDestroy(rt);
|
||||||
}
|
}
|
||||||
streamWithStateDestroy(st);
|
stmStDestroy(st);
|
||||||
fstStreamBuilderDestroy(sb);
|
stmBuilderDestroy(sb);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTRslt* tr) {
|
int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTRslt* tr) {
|
||||||
|
@ -595,8 +554,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) {
|
||||||
// ugly code, refactor later
|
// ugly code, refactor later
|
||||||
for (size_t i = 0; i < sz; i++) {
|
for (size_t i = 0; i < sz; i++) {
|
||||||
TFileValue* v = taosArrayGetP((SArray*)data, i);
|
TFileValue* v = taosArrayGetP((SArray*)data, i);
|
||||||
taosArraySort(v->tableId, tfileUidCompare);
|
taosArraySort(v->tableId, idxUidCompare);
|
||||||
taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL);
|
taosArrayRemoveDuplicate(v->tableId, idxUidCompare, NULL);
|
||||||
int32_t tbsz = taosArrayGetSize(v->tableId);
|
int32_t tbsz = taosArrayGetSize(v->tableId);
|
||||||
fstOffset += TF_TABLE_TATOAL_SIZE(tbsz);
|
fstOffset += TF_TABLE_TATOAL_SIZE(tbsz);
|
||||||
}
|
}
|
||||||
|
@ -721,8 +680,8 @@ static bool tfileIteratorNext(Iterate* iiter) {
|
||||||
char* colVal = NULL;
|
char* colVal = NULL;
|
||||||
uint64_t offset = 0;
|
uint64_t offset = 0;
|
||||||
|
|
||||||
TFileFstIter* tIter = iiter->iter;
|
TFileFstIter* tIter = iiter->iter;
|
||||||
StreamWithStateResult* rt = streamWithStateNextWith(tIter->st, NULL);
|
FStmStRslt* rt = stmStNextWith(tIter->st, NULL);
|
||||||
if (rt == NULL) {
|
if (rt == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -756,7 +715,7 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) {
|
||||||
|
|
||||||
iter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS);
|
iter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS);
|
||||||
iter->fb = fstSearch(reader->fst, iter->ctx);
|
iter->fb = fstSearch(reader->fst, iter->ctx);
|
||||||
iter->st = streamBuilderIntoStream(iter->fb);
|
iter->st = stmBuilderIntoStm(iter->fb);
|
||||||
iter->rdr = reader;
|
iter->rdr = reader;
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
@ -787,8 +746,8 @@ void tfileIteratorDestroy(Iterate* iter) {
|
||||||
iterateValueDestroy(iv, true);
|
iterateValueDestroy(iv, true);
|
||||||
|
|
||||||
TFileFstIter* tIter = iter->iter;
|
TFileFstIter* tIter = iter->iter;
|
||||||
streamWithStateDestroy(tIter->st);
|
stmStDestroy(tIter->st);
|
||||||
fstStreamBuilderDestroy(tIter->fb);
|
stmBuilderDestroy(tIter->fb);
|
||||||
automCtxDestroy(tIter->ctx);
|
automCtxDestroy(tIter->ctx);
|
||||||
taosMemoryFree(tIter);
|
taosMemoryFree(tIter);
|
||||||
|
|
||||||
|
@ -808,11 +767,6 @@ TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) {
|
||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tfileUidCompare(const void* a, const void* b) {
|
|
||||||
uint64_t l = *(uint64_t*)a;
|
|
||||||
uint64_t r = *(uint64_t*)b;
|
|
||||||
return l - r;
|
|
||||||
}
|
|
||||||
static int tfileStrCompare(const void* a, const void* b) {
|
static int tfileStrCompare(const void* a, const void* b) {
|
||||||
int ret = strcmp((char*)a, (char*)b);
|
int ret = strcmp((char*)a, (char*)b);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
|
|
@ -85,11 +85,11 @@ class FstReadMemory {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
// add later
|
// add later
|
||||||
bool Search(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool Search(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
FstStreamBuilder* sb = fstSearch(_fst, ctx);
|
FStmBuilder* sb = fstSearch(_fst, ctx);
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
// result.push_back((uint64_t)(rt->out.out));
|
// result.push_back((uint64_t)(rt->out.out));
|
||||||
FstSlice* s = &rt->data;
|
FstSlice* s = &rt->data;
|
||||||
int32_t sz = 0;
|
int32_t sz = 0;
|
||||||
|
@ -99,27 +99,27 @@ class FstReadMemory {
|
||||||
result.push_back(rt->out.out);
|
result.push_back(rt->out.out);
|
||||||
swsResultDestroy(rt);
|
swsResultDestroy(rt);
|
||||||
}
|
}
|
||||||
streamWithStateDestroy(st);
|
stmStDestroy(st);
|
||||||
fstStreamBuilderDestroy(sb);
|
stmBuilderDestroy(sb);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool SearchRange(AutomationCtx* ctx, const std::string& low, RangeType lowType, const std::string& high,
|
bool SearchRange(FAutoCtx* ctx, const std::string& low, RangeType lowType, const std::string& high,
|
||||||
RangeType highType, std::vector<uint64_t>& result) {
|
RangeType highType, std::vector<uint64_t>& result) {
|
||||||
FstStreamBuilder* sb = fstSearch(_fst, ctx);
|
FStmBuilder* sb = fstSearch(_fst, ctx);
|
||||||
|
|
||||||
FstSlice l = fstSliceCreate((uint8_t*)low.c_str(), low.size());
|
FstSlice l = fstSliceCreate((uint8_t*)low.c_str(), low.size());
|
||||||
FstSlice h = fstSliceCreate((uint8_t*)high.c_str(), high.size());
|
FstSlice h = fstSliceCreate((uint8_t*)high.c_str(), high.size());
|
||||||
|
|
||||||
// range [low, high);
|
// range [low, high);
|
||||||
fstStreamBuilderSetRange(sb, &l, lowType);
|
stmBuilderSetRange(sb, &l, lowType);
|
||||||
fstStreamBuilderSetRange(sb, &h, highType);
|
stmBuilderSetRange(sb, &h, highType);
|
||||||
|
|
||||||
fstSliceDestroy(&l);
|
fstSliceDestroy(&l);
|
||||||
fstSliceDestroy(&h);
|
fstSliceDestroy(&h);
|
||||||
|
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
// result.push_back((uint64_t)(rt->out.out));
|
// result.push_back((uint64_t)(rt->out.out));
|
||||||
FstSlice* s = &rt->data;
|
FstSlice* s = &rt->data;
|
||||||
int32_t sz = 0;
|
int32_t sz = 0;
|
||||||
|
@ -129,11 +129,11 @@ class FstReadMemory {
|
||||||
result.push_back(rt->out.out);
|
result.push_back(rt->out.out);
|
||||||
swsResultDestroy(rt);
|
swsResultDestroy(rt);
|
||||||
}
|
}
|
||||||
streamWithStateDestroy(st);
|
stmStDestroy(st);
|
||||||
fstStreamBuilderDestroy(sb);
|
stmBuilderDestroy(sb);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool SearchWithTimeCostUs(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
int64_t s = taosGetTimestampUs();
|
int64_t s = taosGetTimestampUs();
|
||||||
bool ok = this->Search(ctx, result);
|
bool ok = this->Search(ctx, result);
|
||||||
int64_t e = taosGetTimestampUs();
|
int64_t e = taosGetTimestampUs();
|
||||||
|
@ -253,7 +253,7 @@ void checkFstLongTerm() {
|
||||||
// prefix search
|
// prefix search
|
||||||
// std::vector<uint64_t> result;
|
// std::vector<uint64_t> result;
|
||||||
|
|
||||||
// AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
|
// FAutoCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
|
||||||
// m->Search(ctx, result);
|
// m->Search(ctx, result);
|
||||||
// std::cout << "size: " << result.size() << std::endl;
|
// std::cout << "size: " << result.size() << std::endl;
|
||||||
// assert(result.size() == count);
|
// assert(result.size() == count);
|
||||||
|
@ -286,7 +286,7 @@ void checkFstCheckIterator1() {
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS);
|
||||||
m->Search(ctx, result);
|
m->Search(ctx, result);
|
||||||
std::cout << "size: " << result.size() << std::endl;
|
std::cout << "size: " << result.size() << std::endl;
|
||||||
// assert(result.size() == count);
|
// assert(result.size() == count);
|
||||||
|
@ -321,7 +321,7 @@ void checkFstCheckIterator2() {
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS);
|
||||||
m->Search(ctx, result);
|
m->Search(ctx, result);
|
||||||
std::cout << "size: " << result.size() << std::endl;
|
std::cout << "size: " << result.size() << std::endl;
|
||||||
// assert(result.size() == count);
|
// assert(result.size() == count);
|
||||||
|
@ -361,7 +361,7 @@ void checkFstCheckIteratorPrefix() {
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_PREFIX);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_PREFIX);
|
||||||
m->Search(ctx, result);
|
m->Search(ctx, result);
|
||||||
assert(result.size() == 1);
|
assert(result.size() == 1);
|
||||||
automCtxDestroy(ctx);
|
automCtxDestroy(ctx);
|
||||||
|
@ -370,7 +370,7 @@ void checkFstCheckIteratorPrefix() {
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"Hello", AUTOMATION_PREFIX);
|
FAutoCtx* ctx = automCtxCreate((void*)"Hello", AUTOMATION_PREFIX);
|
||||||
m->Search(ctx, result);
|
m->Search(ctx, result);
|
||||||
assert(result.size() == 2);
|
assert(result.size() == 2);
|
||||||
automCtxDestroy(ctx);
|
automCtxDestroy(ctx);
|
||||||
|
@ -378,7 +378,7 @@ void checkFstCheckIteratorPrefix() {
|
||||||
{
|
{
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"jddd", AUTOMATION_PREFIX);
|
FAutoCtx* ctx = automCtxCreate((void*)"jddd", AUTOMATION_PREFIX);
|
||||||
m->Search(ctx, result);
|
m->Search(ctx, result);
|
||||||
assert(result.size() == 1);
|
assert(result.size() == 1);
|
||||||
automCtxDestroy(ctx);
|
automCtxDestroy(ctx);
|
||||||
|
@ -412,7 +412,7 @@ void checkFstCheckIteratorRange1() {
|
||||||
{
|
{
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GE, "e", LT, result);
|
m->SearchRange(ctx, "b", GE, "e", LT, result);
|
||||||
assert(result.size() == 3);
|
assert(result.size() == 3);
|
||||||
|
@ -421,7 +421,7 @@ void checkFstCheckIteratorRange1() {
|
||||||
{
|
{
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GT, "e", LT, result);
|
m->SearchRange(ctx, "b", GT, "e", LT, result);
|
||||||
assert(result.size() == 2);
|
assert(result.size() == 2);
|
||||||
|
@ -430,7 +430,7 @@ void checkFstCheckIteratorRange1() {
|
||||||
{
|
{
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GT, "e", LE, result);
|
m->SearchRange(ctx, "b", GT, "e", LE, result);
|
||||||
assert(result.size() == 3);
|
assert(result.size() == 3);
|
||||||
|
@ -439,7 +439,7 @@ void checkFstCheckIteratorRange1() {
|
||||||
{
|
{
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GE, "e", LE, result);
|
m->SearchRange(ctx, "b", GE, "e", LE, result);
|
||||||
assert(result.size() == 4);
|
assert(result.size() == 4);
|
||||||
|
@ -473,7 +473,7 @@ void checkFstCheckIteratorRange2() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GE, "ed", LT, result);
|
m->SearchRange(ctx, "b", GE, "ed", LT, result);
|
||||||
assert(result.size() == 4);
|
assert(result.size() == 4);
|
||||||
|
@ -482,7 +482,7 @@ void checkFstCheckIteratorRange2() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "bb", GE, "ed", LT, result);
|
m->SearchRange(ctx, "bb", GE, "ed", LT, result);
|
||||||
assert(result.size() == 3);
|
assert(result.size() == 3);
|
||||||
|
@ -491,7 +491,7 @@ void checkFstCheckIteratorRange2() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GE, "ed", LE, result);
|
m->SearchRange(ctx, "b", GE, "ed", LE, result);
|
||||||
assert(result.size() == 5);
|
assert(result.size() == 5);
|
||||||
|
@ -501,7 +501,7 @@ void checkFstCheckIteratorRange2() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GT, "ed", LE, result);
|
m->SearchRange(ctx, "b", GT, "ed", LE, result);
|
||||||
assert(result.size() == 4);
|
assert(result.size() == 4);
|
||||||
|
@ -510,7 +510,7 @@ void checkFstCheckIteratorRange2() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GT, "ed", LT, result);
|
m->SearchRange(ctx, "b", GT, "ed", LT, result);
|
||||||
assert(result.size() == 3);
|
assert(result.size() == 3);
|
||||||
|
@ -544,7 +544,7 @@ void checkFstCheckIteratorRange3() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "b", GE, "", (RangeType)10, result);
|
m->SearchRange(ctx, "b", GE, "", (RangeType)10, result);
|
||||||
assert(result.size() == 5);
|
assert(result.size() == 5);
|
||||||
|
@ -553,7 +553,7 @@ void checkFstCheckIteratorRange3() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "", (RangeType)20, "ab", LE, result);
|
m->SearchRange(ctx, "", (RangeType)20, "ab", LE, result);
|
||||||
assert(result.size() == 1);
|
assert(result.size() == 1);
|
||||||
|
@ -563,7 +563,7 @@ void checkFstCheckIteratorRange3() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "", (RangeType)30, "ab", LT, result);
|
m->SearchRange(ctx, "", (RangeType)30, "ab", LT, result);
|
||||||
assert(result.size() == 0);
|
assert(result.size() == 0);
|
||||||
|
@ -572,7 +572,7 @@ void checkFstCheckIteratorRange3() {
|
||||||
{
|
{
|
||||||
// range search
|
// range search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS);
|
||||||
// [b, e)
|
// [b, e)
|
||||||
m->SearchRange(ctx, "ed", GT, "ed", (RangeType)40, result);
|
m->SearchRange(ctx, "ed", GT, "ed", (RangeType)40, result);
|
||||||
assert(result.size() == 0);
|
assert(result.size() == 0);
|
||||||
|
|
|
@ -106,11 +106,11 @@ class FstReadMemory {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
// add later
|
// add later
|
||||||
bool Search(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool Search(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
FstStreamBuilder* sb = fstSearch(_fst, ctx);
|
FStmBuilder* sb = fstSearch(_fst, ctx);
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
// result.push_back((uint64_t)(rt->out.out));
|
// result.push_back((uint64_t)(rt->out.out));
|
||||||
FstSlice* s = &rt->data;
|
FstSlice* s = &rt->data;
|
||||||
int32_t sz = 0;
|
int32_t sz = 0;
|
||||||
|
@ -122,7 +122,7 @@ class FstReadMemory {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool SearchWithTimeCostUs(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
int64_t s = taosGetTimestampUs();
|
int64_t s = taosGetTimestampUs();
|
||||||
bool ok = this->Search(ctx, result);
|
bool ok = this->Search(ctx, result);
|
||||||
int64_t e = taosGetTimestampUs();
|
int64_t e = taosGetTimestampUs();
|
||||||
|
@ -192,7 +192,7 @@ class TFst {
|
||||||
}
|
}
|
||||||
return fr->Get(k, v);
|
return fr->Get(k, v);
|
||||||
}
|
}
|
||||||
bool Search(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool Search(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
// add more
|
// add more
|
||||||
return fr->Search(ctx, result);
|
return fr->Search(ctx, result);
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ TEST_F(FstEnv, writeNormal) {
|
||||||
assert(val == 0);
|
assert(val == 0);
|
||||||
|
|
||||||
std::vector<uint64_t> rlt;
|
std::vector<uint64_t> rlt;
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
|
FAutoCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
|
||||||
assert(fst->Search(ctx, rlt) == true);
|
assert(fst->Search(ctx, rlt) == true);
|
||||||
}
|
}
|
||||||
TEST_F(FstEnv, WriteMillonrRecord) {}
|
TEST_F(FstEnv, WriteMillonrRecord) {}
|
||||||
|
|
|
@ -106,17 +106,17 @@ class FstReadMemory {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
// add later
|
// add later
|
||||||
bool Search(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool Search(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
FstStreamBuilder* sb = fstSearch(_fst, ctx);
|
FStmBuilder* sb = fstSearch(_fst, ctx);
|
||||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
FStmSt* st = stmBuilderIntoStm(sb);
|
||||||
StreamWithStateResult* rt = NULL;
|
FStmStRslt* rt = NULL;
|
||||||
|
|
||||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
while ((rt = stmStNextWith(st, NULL)) != NULL) {
|
||||||
result.push_back((uint64_t)(rt->out.out));
|
result.push_back((uint64_t)(rt->out.out));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
bool SearchWithTimeCostUs(FAutoCtx* ctx, std::vector<uint64_t>& result) {
|
||||||
int64_t s = taosGetTimestampUs();
|
int64_t s = taosGetTimestampUs();
|
||||||
bool ok = this->Search(ctx, result);
|
bool ok = this->Search(ctx, result);
|
||||||
int64_t e = taosGetTimestampUs();
|
int64_t e = taosGetTimestampUs();
|
||||||
|
@ -220,7 +220,7 @@ void checkFstPrefixSearch() {
|
||||||
// prefix search
|
// prefix search
|
||||||
std::vector<uint64_t> result;
|
std::vector<uint64_t> result;
|
||||||
|
|
||||||
AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_PREFIX);
|
FAutoCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_PREFIX);
|
||||||
m->Search(ctx, result);
|
m->Search(ctx, result);
|
||||||
assert(result.size() == count);
|
assert(result.size() == count);
|
||||||
for (int i = 0; i < result.size(); i++) {
|
for (int i = 0; i < result.size(); i++) {
|
||||||
|
|
|
@ -327,13 +327,13 @@ TEST_F(UtilEnv, testFill) {
|
||||||
for (int i = 0; i < 1000000; i++) {
|
for (int i = 0; i < 1000000; i++) {
|
||||||
int64_t val = i;
|
int64_t val = i;
|
||||||
char buf[65] = {0};
|
char buf[65] = {0};
|
||||||
indexInt2str(val, buf, 1);
|
idxInt2str(val, buf, 1);
|
||||||
EXPECT_EQ(val, taosStr2int64(buf));
|
EXPECT_EQ(val, taosStr2int64(buf));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 1000000; i++) {
|
for (int i = 0; i < 1000000; i++) {
|
||||||
int64_t val = 0 - i;
|
int64_t val = 0 - i;
|
||||||
char buf[65] = {0};
|
char buf[65] = {0};
|
||||||
indexInt2str(val, buf, -1);
|
idxInt2str(val, buf, -1);
|
||||||
EXPECT_EQ(val, taosStr2int64(buf));
|
EXPECT_EQ(val, taosStr2int64(buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ if $rows != 1 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
||||||
sql select * from db.stb where t1 < 1
|
sql select * from db.stb where t1 < 1
|
||||||
if $rows != 0 then
|
if $rows != 0 then
|
||||||
return -=1
|
return -=1
|
||||||
|
@ -56,4 +57,21 @@ if $rows != 5 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
sql select * from db.stb where t1 between 1 and 1
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select * from db.stb where t1 between 1 and 6
|
||||||
|
if $rows != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select * from db.stb where t1 between 1 and 7
|
||||||
|
if $rows != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
Loading…
Reference in New Issue