Merge pull request #9082 from taosdata/feature/fst
update search framework
This commit is contained in:
commit
2aaa43a457
|
@ -20,6 +20,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "index_fst_util.h"
|
||||
|
||||
|
||||
typedef struct AutomationCtx AutomationCtx;
|
||||
|
||||
typedef enum AutomationType {
|
||||
|
@ -42,14 +44,23 @@ typedef struct AutomationCtx {
|
|||
} AutomationCtx;
|
||||
|
||||
|
||||
|
||||
typedef enum ValueType { FST_INT, FST_CHAR, FST_ARRAY} ValueType;
|
||||
typedef enum StartWithStateKind { Done, Running } StartWithStateKind;
|
||||
|
||||
typedef struct StartWithStateValue {
|
||||
StartWithStateKind kind;
|
||||
void *value;
|
||||
ValueType type;
|
||||
union {
|
||||
int val;
|
||||
char *ptr;
|
||||
SArray *arr;
|
||||
// add more type
|
||||
} ;
|
||||
} StartWithStateValue;
|
||||
|
||||
StartWithStateValue *startWithStateValueDump(StartWithStateValue *sv);
|
||||
|
||||
|
||||
typedef struct AutomationFunc {
|
||||
void* (*start)(AutomationCtx *ctx) ;
|
||||
bool (*isMatch)(AutomationCtx *ctx, void *);
|
||||
|
|
|
@ -1322,6 +1322,7 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
|
|||
return swsResultCreate(&s, output, callback(start));
|
||||
}
|
||||
}
|
||||
SArray *nodes = taosArrayInit(8, sizeof(FstNode *));
|
||||
while (taosArrayGetSize(sws->stack) > 0) {
|
||||
StreamState *p = (StreamState *)taosArrayPop(sws->stack);
|
||||
if (p->trans >= FST_NODE_LEN(p->node) || automFuncs[aut->type].canMatch(aut, p->autState)) {
|
||||
|
@ -1337,8 +1338,8 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
|
|||
void* nextState = automFuncs[aut->type].accept(aut, p->autState, trn.inp);
|
||||
void* tState = callback(nextState);
|
||||
bool isMatch = automFuncs[aut->type].isMatch(aut, nextState);
|
||||
//bool isMatch = sws->aut->isMatch(nextState);
|
||||
FstNode *nextNode = fstGetNode(sws->fst, trn.addr);
|
||||
taosArrayPush(nodes, &nextNode);
|
||||
taosArrayPush(sws->inp, &(trn.inp));
|
||||
|
||||
if (FST_NODE_IS_FINAL(nextNode)) {
|
||||
|
@ -1354,26 +1355,35 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
|
|||
StreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState};
|
||||
taosArrayPush(sws->stack, &s2);
|
||||
|
||||
uint8_t *buf = (uint8_t *)malloc(taosArrayGetSize(sws->inp) * sizeof(uint8_t));
|
||||
for (uint32_t i = 0; i < taosArrayGetSize(sws->inp); i++) {
|
||||
uint8_t *t = (uint8_t *)taosArrayGet(sws->inp, i);
|
||||
buf[i] = *t;
|
||||
|
||||
size_t isz = taosArrayGetSize(sws->inp);
|
||||
uint8_t *buf = (uint8_t *)malloc(isz * sizeof(uint8_t));
|
||||
for (uint32_t i = 0; i < isz; i++) {
|
||||
buf[i] = *(uint8_t *)taosArrayGet(sws->inp, i);
|
||||
}
|
||||
FstSlice slice = fstSliceCreate(buf, taosArrayGetSize(sws->inp));
|
||||
if (fstBoundWithDataExceededBy(sws->endAt, &slice)) {
|
||||
taosArrayDestroyEx(sws->stack, streamStateDestroy);
|
||||
sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState));
|
||||
free(buf);
|
||||
fstSliceDestroy(&slice);
|
||||
return NULL;
|
||||
}
|
||||
if (FST_NODE_IS_FINAL(nextNode) && isMatch) {
|
||||
FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)};
|
||||
StreamWithStateResult *result = swsResultCreate(&slice, fOutput , tState);
|
||||
StreamWithStateResult *result = swsResultCreate(&slice, fOutput, tState);
|
||||
free(buf);
|
||||
fstSliceDestroy(&slice);
|
||||
return result;
|
||||
}
|
||||
free(buf);
|
||||
fstSliceDestroy(&slice);
|
||||
}
|
||||
for (size_t i = 0; i < taosArrayGetSize(nodes); i++) {
|
||||
FstNode** node = (FstNode **)taosArrayGet(nodes, i);
|
||||
fstNodeDestroy(*node);
|
||||
}
|
||||
taosArrayDestroy(nodes);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
|
|
@ -16,9 +16,59 @@
|
|||
#include "index_fst_automation.h"
|
||||
|
||||
|
||||
StartWithStateValue *startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void *val) {
|
||||
StartWithStateValue *nsv = calloc(1, sizeof(StartWithStateValue));
|
||||
if (nsv == NULL) { return NULL; }
|
||||
|
||||
nsv->kind = kind;
|
||||
nsv->type = ty;
|
||||
if (ty == FST_INT) {
|
||||
nsv->val = *(int *)val;
|
||||
} else if (ty == FST_CHAR) {
|
||||
size_t len = strlen((char *)val);
|
||||
nsv->ptr = (char *)calloc(1, len + 1);
|
||||
memcpy(nsv->ptr, val, len);
|
||||
} else if (ty == FST_ARRAY) {
|
||||
//TODO,
|
||||
//nsv->arr = taosArrayFromList()
|
||||
}
|
||||
return nsv;
|
||||
}
|
||||
void startWithStateValueDestroy(StartWithStateValue *sv) {
|
||||
if (sv == NULL) { return; }
|
||||
|
||||
if (sv->type == FST_INT) {
|
||||
//
|
||||
} else if (sv->type == FST_CHAR) {
|
||||
free(sv->ptr);
|
||||
} else if (sv->type == FST_ARRAY) {
|
||||
taosArrayDestroy(sv->arr);
|
||||
}
|
||||
free(sv);
|
||||
}
|
||||
StartWithStateValue *startWithStateValueDump(StartWithStateValue *sv) {
|
||||
StartWithStateValue *nsv = calloc(1, sizeof(StartWithStateValue));
|
||||
if (nsv == NULL) { return NULL; }
|
||||
|
||||
nsv->kind = sv->kind;
|
||||
nsv->type= sv->type;
|
||||
if (nsv->type == FST_INT) {
|
||||
nsv->val = sv->val;
|
||||
} else if (nsv->type == FST_CHAR) {
|
||||
size_t len = strlen(sv->ptr);
|
||||
nsv->ptr = (char *)calloc(1, len + 1);
|
||||
memcpy(nsv->ptr, sv->ptr, len);
|
||||
} else if (nsv->type == FST_ARRAY) {
|
||||
}
|
||||
return nsv;
|
||||
}
|
||||
|
||||
|
||||
// prefix query, impl later
|
||||
|
||||
static void* prefixStart(AutomationCtx *ctx) {
|
||||
StartWithStateValue *data = (StartWithStateValue *)(ctx->data);
|
||||
|
||||
return data;
|
||||
};
|
||||
static bool prefixIsMatch(AutomationCtx *ctx, void *data) {
|
||||
|
@ -86,7 +136,7 @@ AutomationCtx* automCtxCreate(void *data, AutomationType type) {
|
|||
if (type == AUTOMATION_PREFIX) {
|
||||
StartWithStateValue *swsv = (StartWithStateValue *)calloc(1, sizeof(StartWithStateValue));
|
||||
swsv->kind = Done;
|
||||
swsv->value = NULL;
|
||||
//swsv->value = NULL;
|
||||
ctx->data = (void *)swsv;
|
||||
} else if (type == AUTMMATION_MATCH) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue