Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
60135336
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
60135336
编写于
7月 10, 2022
作者:
dengyihao
提交者:
GitHub
7月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14703 from taosdata/enh/addTestToIdx
Enh: add ut test to idx
上级
2a8455be
578343be
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
171 addition
and
19 deletion
+171
-19
source/libs/index/inc/indexFstCommon.h
source/libs/index/inc/indexFstCommon.h
+1
-0
source/libs/index/inc/indexFstDfa.h
source/libs/index/inc/indexFstDfa.h
+3
-3
source/libs/index/inc/indexFstRegex.h
source/libs/index/inc/indexFstRegex.h
+1
-0
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+1
-3
source/libs/index/src/indexFst.c
source/libs/index/src/indexFst.c
+0
-1
source/libs/index/src/indexFstCommon.c
source/libs/index/src/indexFstCommon.c
+1
-0
source/libs/index/src/indexFstDfa.c
source/libs/index/src/indexFstDfa.c
+8
-6
source/libs/index/src/indexFstRegex.c
source/libs/index/src/indexFstRegex.c
+7
-1
source/libs/index/test/CMakeLists.txt
source/libs/index/test/CMakeLists.txt
+70
-5
source/libs/index/test/fstUtilUT.cc
source/libs/index/test/fstUtilUT.cc
+70
-0
source/libs/index/test/utilUT.cc
source/libs/index/test/utilUT.cc
+9
-0
未找到文件。
source/libs/index/inc/indexFstCommon.h
浏览文件 @
60135336
...
...
@@ -4,6 +4,7 @@
#include "tutil.h"
extern
const
uint8_t
COMMON_INPUTS
[];
extern
const
char
COMMON_INPUTS_INV
[];
extern
const
int32_t
COMMON_INPUTS_LEN
;
#ifdef __cplusplus
extern
"C"
{
...
...
source/libs/index/inc/indexFstDfa.h
浏览文件 @
60135336
...
...
@@ -29,16 +29,16 @@ extern "C" {
typedef
struct
FstDfa
FstDfa
;
typedef
struct
{
SArray
*
insts
;
SArray
*
insts
;
uint32_t
next
[
256
];
bool
isMatch
;
}
State
;
}
Dfa
State
;
/*
* dfa builder related func
**/
typedef
struct
FstDfaBuilder
{
FstDfa
*
dfa
;
FstDfa
*
dfa
;
SHashObj
*
cache
;
}
FstDfaBuilder
;
...
...
source/libs/index/inc/indexFstRegex.h
浏览文件 @
60135336
...
...
@@ -65,6 +65,7 @@ typedef struct {
}
FstRegex
;
FstRegex
*
regexCreate
(
const
char
*
str
);
void
regexDestroy
(
FstRegex
*
regex
);
uint32_t
regexAutomStart
(
FstRegex
*
regex
);
bool
regexAutomIsMatch
(
FstRegex
*
regex
,
uint32_t
state
);
...
...
source/libs/index/src/indexCache.c
浏览文件 @
60135336
...
...
@@ -22,7 +22,7 @@
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MEM_TERM_LIMIT 10 * 10000
#define MEM_THRESHOLD
64
* 1024
#define MEM_THRESHOLD
512
* 1024
#define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20
#define MEM_ESTIMATE_RADIO 1.5
...
...
@@ -204,7 +204,6 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr
if
(
0
==
strcmp
(
c
->
colVal
,
pCt
->
colVal
))
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
add
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
c
->
uid
)
...
...
@@ -309,7 +308,6 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
if
(
cond
==
MATCH
)
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
add
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
c
->
uid
)
...
...
source/libs/index/src/indexFst.c
浏览文件 @
60135336
...
...
@@ -1307,7 +1307,6 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) {
taosArrayPush
(
sws
->
inp
,
&
(
trn
.
inp
));
if
(
FST_NODE_IS_FINAL
(
nextNode
))
{
// void *eofState = sws->aut->acceptEof(nextState);
void
*
eofState
=
automFuncs
[
aut
->
type
].
acceptEof
(
aut
,
nextState
);
if
(
eofState
!=
NULL
)
{
isMatch
=
automFuncs
[
aut
->
type
].
isMatch
(
aut
,
eofState
);
...
...
source/libs/index/src/indexFstCommon.c
浏览文件 @
60135336
...
...
@@ -294,3 +294,4 @@ const char COMMON_INPUTS_INV[] = {
'\xee'
,
'\xef'
,
'\xf0'
,
'\xf1'
,
'\xf2'
,
'\xf3'
,
'\xf4'
,
'\xf5'
,
'\xf6'
,
'\xf7'
,
'\xf8'
,
'\xf9'
,
'\xfa'
,
'\xfb'
,
'\xfc'
,
'\xfd'
,
'\xfe'
,
'\xff'
,
};
const
int32_t
COMMON_INPUTS_LEN
=
sizeof
(
COMMON_INPUTS
)
/
sizeof
(
COMMON_INPUTS
[
0
]);
source/libs/index/src/indexFstDfa.c
浏览文件 @
60135336
...
...
@@ -41,7 +41,7 @@ FstDfaBuilder *dfaBuilderCreate(SArray *insts) {
return
NULL
;
}
SArray
*
states
=
taosArrayInit
(
4
,
sizeof
(
State
));
SArray
*
states
=
taosArrayInit
(
4
,
sizeof
(
Dfa
State
));
builder
->
dfa
=
dfaCreate
(
insts
,
states
);
builder
->
cache
=
taosHashInit
(
...
...
@@ -71,7 +71,7 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) {
dfaAdd
(
builder
->
dfa
,
cur
,
0
);
SArray
*
states
=
taosArrayInit
(
0
,
sizeof
(
uint32_t
));
SArray
*
states
=
taosArrayInit
(
0
,
sizeof
(
uint32_t
));
uint32_t
result
;
if
(
dfaBuilderCachedState
(
builder
,
cur
,
&
result
))
{
taosArrayPush
(
states
,
&
result
);
...
...
@@ -98,10 +98,12 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) {
return
builder
->
dfa
;
}
FstDfa
*
dfaBuilderBuild
(
FstDfaBuilder
*
builer
)
{
return
NULL
;
}
bool
dfaBuilderRunState
(
FstDfaBuilder
*
builder
,
FstSparseSet
*
cur
,
FstSparseSet
*
next
,
uint32_t
state
,
uint8_t
byte
,
uint32_t
*
result
)
{
sparSetClear
(
cur
);
State
*
t
=
taosArrayGet
(
builder
->
dfa
->
states
,
state
);
Dfa
State
*
t
=
taosArrayGet
(
builder
->
dfa
->
states
,
state
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
t
->
insts
);
i
++
)
{
uint32_t
ip
=
*
(
int32_t
*
)
taosArrayGet
(
t
->
insts
,
i
);
sparSetAdd
(
cur
,
ip
);
...
...
@@ -144,7 +146,7 @@ bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *
*
result
=
*
v
;
taosArrayDestroy
(
tinsts
);
}
else
{
State
st
;
Dfa
State
st
;
st
.
insts
=
tinsts
;
st
.
isMatch
=
isMatch
;
taosArrayPush
(
builder
->
dfa
->
states
,
&
st
);
...
...
@@ -169,14 +171,14 @@ bool dfaIsMatch(FstDfa *dfa, uint32_t si) {
if
(
dfa
->
states
==
NULL
||
si
<
taosArrayGetSize
(
dfa
->
states
))
{
return
false
;
}
State
*
st
=
taosArrayGet
(
dfa
->
states
,
si
);
Dfa
State
*
st
=
taosArrayGet
(
dfa
->
states
,
si
);
return
st
!=
NULL
?
st
->
isMatch
:
false
;
}
bool
dfaAccept
(
FstDfa
*
dfa
,
uint32_t
si
,
uint8_t
byte
,
uint32_t
*
result
)
{
if
(
dfa
->
states
==
NULL
||
si
<
taosArrayGetSize
(
dfa
->
states
))
{
return
false
;
}
State
*
st
=
taosArrayGet
(
dfa
->
states
,
si
);
Dfa
State
*
st
=
taosArrayGet
(
dfa
->
states
,
si
);
*
result
=
st
->
next
[
byte
];
return
true
;
}
...
...
source/libs/index/src/indexFstRegex.c
浏览文件 @
60135336
...
...
@@ -23,7 +23,7 @@ FstRegex *regexCreate(const char *str) {
return
NULL
;
}
int32_t
sz
=
(
int32_t
)
strlen
(
str
);
char
*
orig
=
taosMemoryCalloc
(
1
,
sz
);
char
*
orig
=
taosMemoryCalloc
(
1
,
sz
);
memcpy
(
orig
,
str
,
sz
);
regex
->
orig
=
orig
;
...
...
@@ -36,6 +36,12 @@ FstRegex *regexCreate(const char *str) {
return
regex
;
}
void
regexDestroy
(
FstRegex
*
regex
)
{
if
(
regex
==
NULL
)
return
;
taosMemoryFree
(
regex
->
orig
);
taosMemoryFree
(
regex
);
}
uint32_t
regexAutomStart
(
FstRegex
*
regex
)
{
///// no nothing
return
0
;
...
...
source/libs/index/test/CMakeLists.txt
浏览文件 @
60135336
...
...
@@ -4,6 +4,7 @@ IF(NOT TD_DARWIN)
add_executable
(
idxFstUT
""
)
add_executable
(
idxUtilUT
""
)
add_executable
(
idxJsonUT
""
)
add_executable
(
idxFstUtilUT
""
)
target_sources
(
idxTest
PRIVATE
...
...
@@ -23,6 +24,25 @@ IF(NOT TD_DARWIN)
"utilUT.cc"
)
target_sources
(
idxJsonUT
PRIVATE
"jsonUT.cc"
)
target_sources
(
idxFstUtilUT
PRIVATE
"fstUtilUT.cc"
)
target_include_directories
(
idxTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
idxFstTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_sources
(
idxJsonUT
PRIVATE
"jsonUT.cc"
...
...
@@ -50,6 +70,38 @@ IF(NOT TD_DARWIN)
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
idxJsonUT
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
idxFstUtilUT
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
idxTest
os
util
common
gtest_main
index
)
target_link_libraries
(
idxFstTest
os
util
common
gtest_main
index
)
target_link_libraries
(
idxFstUT
os
util
common
gtest_main
index
)
target_include_directories
(
idxJsonUT
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
...
...
@@ -92,15 +144,28 @@ IF(NOT TD_DARWIN)
gtest_main
index
)
add_test
(
NAME idxtest
COMMAND idxTest
target_link_libraries
(
idxFstUtilUT
os
util
common
gtest_main
index
)
add_test
(
NAME idxJsonUT
COMMAND idxJsonUT
)
add_test
(
NAME idxFstUtilUT
COMMAND idxFstUtilUT
)
add_test
(
NAME idxtest
COMMAND idxTest
)
add_test
(
NAME idxUtilUT
COMMAND idxUtilUT
...
...
@@ -109,4 +174,4 @@ IF(NOT TD_DARWIN)
NAME idxFstUT
COMMAND idxFstUT
)
ENDIF
()
\ No newline at end of file
ENDIF
()
source/libs/index/test/fstUtilUT.cc
0 → 100644
浏览文件 @
60135336
#include <gtest/gtest.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include "index.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstDfa.h"
#include "indexFstRegex.h"
#include "indexFstSparse.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "tglobal.h"
#include "tlog.h"
#include "tskiplist.h"
#include "tutil.h"
class
FstUtilEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
SArray
*
inst
=
taosArrayInit
(
4
,
sizeof
(
char
));
builder
=
dfaBuilderCreate
(
inst
);
}
virtual
void
TearDown
()
{
dfaBuilderDestroy
(
builder
);
}
FstDfaBuilder
*
builder
;
};
class
FstRegexEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
regex
=
regexCreate
(
"test"
);
}
virtual
void
TearDown
()
{
regexDestroy
(
regex
);
}
FstRegex
*
regex
;
};
class
FstSparseSetEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
set
=
sparSetCreate
(
256
);
}
virtual
void
TearDown
()
{
// tear down
sparSetDestroy
(
set
);
}
void
ReBuild
(
int32_t
sz
)
{
sparSetDestroy
(
set
);
set
=
sparSetCreate
(
sz
);
}
FstSparseSet
*
set
;
};
// test FstDfaBuilder
TEST_F
(
FstUtilEnv
,
test1
)
{}
TEST_F
(
FstUtilEnv
,
test2
)
{}
TEST_F
(
FstUtilEnv
,
test3
)
{}
TEST_F
(
FstUtilEnv
,
test4
)
{}
// test FstRegex
TEST_F
(
FstRegexEnv
,
test1
)
{}
TEST_F
(
FstRegexEnv
,
test2
)
{}
TEST_F
(
FstRegexEnv
,
test3
)
{}
TEST_F
(
FstRegexEnv
,
test4
)
{}
// test FstSparseSet
TEST_F
(
FstSparseSetEnv
,
test1
)
{}
TEST_F
(
FstSparseSetEnv
,
test2
)
{}
TEST_F
(
FstSparseSetEnv
,
test3
)
{}
TEST_F
(
FstSparseSetEnv
,
test4
)
{}
source/libs/index/test/utilUT.cc
浏览文件 @
60135336
...
...
@@ -8,6 +8,7 @@
#include "indexCache.h"
#include "indexComm.h"
#include "indexFst.h"
#include "indexFstCommon.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexTfile.h"
...
...
@@ -356,3 +357,11 @@ TEST_F(UtilEnv, TempResultExcept) {
idxTRsltMergeTo
(
relt
,
f
);
EXPECT_EQ
(
taosArrayGetSize
(
f
),
1
);
}
TEST_F
(
UtilEnv
,
testDictComm
)
{
int32_t
count
=
COMMON_INPUTS_LEN
;
for
(
int
i
=
0
;
i
<
256
;
i
++
)
{
uint8_t
v
=
COMMON_INPUTS_INV
[
i
];
EXPECT_EQ
(
COMMON_INPUTS
[
v
],
i
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录