Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8240b10a
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8240b10a
编写于
5月 06, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(index): support more data type
上级
e08dd100
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
149 addition
and
14 deletion
+149
-14
source/libs/index/inc/indexCache.h
source/libs/index/inc/indexCache.h
+1
-0
source/libs/index/inc/indexComm.h
source/libs/index/inc/indexComm.h
+1
-1
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+113
-6
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+27
-0
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+7
-7
未找到文件。
source/libs/index/inc/indexCache.h
浏览文件 @
8240b10a
...
...
@@ -48,6 +48,7 @@ typedef struct IndexCache {
}
IndexCache
;
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
typedef
struct
CacheTerm
{
// key
char
*
colVal
;
...
...
source/libs/index/inc/indexComm.h
浏览文件 @
8240b10a
...
...
@@ -24,7 +24,7 @@ extern char JSON_COLUMN[];
extern
char
JSON_VALUE_DELIM
;
char
*
indexPackJsonData
(
SIndexTerm
*
itm
);
char
*
indexPackJsonDataPrefix
(
SIndexTerm
*
itm
,
int32_t
*
skip
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/index/src/indexCache.c
浏览文件 @
8240b10a
...
...
@@ -86,9 +86,18 @@ static TExeCond tCompareLessThan(void* a, void* b, int8_t type) {
__compar_fn_t
func
=
getComparFunc
(
type
,
0
);
return
tDoCommpare
(
func
,
QUERY_LESS_THAN
,
a
,
b
);
}
static
TExeCond
tCompareLessEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
return
MATCH
;
}
static
TExeCond
tCompareGreaterThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
return
MATCH
;
}
static
TExeCond
tCompareGreaterEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
return
MATCH
;
}
static
TExeCond
tCompareLessEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
getComparFunc
(
type
,
0
);
return
tDoCommpare
(
func
,
QUERY_LESS_EQUAL
,
a
,
b
);
}
static
TExeCond
tCompareGreaterThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
getComparFunc
(
type
,
0
);
return
tDoCommpare
(
func
,
QUERY_GREATER_THAN
,
a
,
b
);
}
static
TExeCond
tCompareGreaterEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
getComparFunc
(
type
,
0
);
return
tDoCommpare
(
func
,
QUERY_GREATER_EQUAL
,
a
,
b
);
}
static
TExeCond
(
*
rangeCompare
[])(
void
*
a
,
void
*
b
,
int8_t
type
)
=
{
tCompareLessThan
,
tCompareLessEqual
,
tCompareGreaterThan
,
tCompareGreaterEqual
};
...
...
@@ -109,10 +118,12 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTempResult* tr
}
MemTable
*
mem
=
cache
;
IndexCache
*
pCache
=
mem
->
pCache
;
CacheTerm
ct
=
{.
colVal
=
term
->
colVal
,
.
version
=
atomic_load_32
(
&
pCache
->
version
)};
CacheTerm
*
pCt
=
&
ct
;
char
*
key
=
indexCacheTermGet
(
&
ct
);
CacheTerm
*
pCt
=
taosMemoryCalloc
(
1
,
sizeof
(
CacheTerm
));
pCt
->
colVal
=
term
->
colVal
;
pCt
->
version
=
atomic_load_32
(
&
pCache
->
version
);
char
*
key
=
indexCacheTermGet
(
pCt
);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
...
...
@@ -133,6 +144,8 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTempResult* tr
break
;
}
}
taosMemoryFree
(
pCt
);
tSkipListDestroyIter
(
iter
);
return
0
;
}
...
...
@@ -153,6 +166,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTempRes
if
(
cache
==
NULL
)
{
return
0
;
}
_cache_range_compare
cmpFn
=
rangeCompare
[
type
];
MemTable
*
mem
=
cache
;
...
...
@@ -204,6 +218,48 @@ static int32_t cacheSearchGreaterEqual(void* cache, SIndexTerm* term, SIdxTempRe
}
static
int32_t
cacheSearchTerm_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTempResult
*
tr
,
STermValueType
*
s
)
{
if
(
cache
==
NULL
)
{
return
0
;
}
MemTable
*
mem
=
cache
;
IndexCache
*
pCache
=
mem
->
pCache
;
CacheTerm
*
pCt
=
taosMemoryCalloc
(
1
,
sizeof
(
CacheTerm
));
pCt
->
colVal
=
term
->
colVal
;
pCt
->
version
=
atomic_load_32
(
&
pCache
->
version
);
char
*
exBuf
=
NULL
;
if
(
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
exBuf
=
indexPackJsonData
(
term
);
pCt
->
colVal
=
exBuf
;
}
char
*
key
=
indexCacheTermGet
(
pCt
);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
if
(
node
==
NULL
)
{
break
;
}
CacheTerm
*
c
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
0
==
strcmp
(
c
->
colVal
,
pCt
->
colVal
))
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
deled
,
tr
->
added
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
added
,
tr
->
deled
,
c
->
uid
)
}
}
else
{
break
;
}
}
taosMemoryFree
(
pCt
);
taosMemoryFree
(
exBuf
);
tSkipListDestroyIter
(
iter
);
return
0
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchPrefix_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTempResult
*
tr
,
STermValueType
*
s
)
{
...
...
@@ -233,6 +289,56 @@ static int32_t cacheSearchRange_JSON(void* cache, SIndexTerm* term, SIdxTempResu
static
int32_t
cacheSearchCompareFunc_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTempResult
*
tr
,
STermValueType
*
s
,
RangeType
type
)
{
if
(
cache
==
NULL
)
{
return
0
;
}
_cache_range_compare
cmpFn
=
rangeCompare
[
type
];
MemTable
*
mem
=
cache
;
IndexCache
*
pCache
=
mem
->
pCache
;
CacheTerm
*
pCt
=
taosMemoryCalloc
(
1
,
sizeof
(
CacheTerm
));
pCt
->
colVal
=
term
->
colVal
;
pCt
->
version
=
atomic_load_32
(
&
pCache
->
version
);
int8_t
dType
=
INDEX_TYPE_GET_TYPE
(
term
->
colType
);
int
skip
=
0
;
char
*
exBuf
=
NULL
;
if
(
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
exBuf
=
indexPackJsonDataPrefix
(
term
,
&
skip
);
pCt
->
colVal
=
exBuf
;
}
char
*
key
=
indexCacheTermGet
(
pCt
);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
if
(
node
==
NULL
)
{
break
;
}
CacheTerm
*
c
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
TExeCond
cond
=
cmpFn
(
c
->
colVal
+
skip
,
term
->
colVal
,
dType
);
if
(
cond
==
MATCH
)
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
deled
,
tr
->
added
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
added
,
tr
->
deled
,
c
->
uid
)
}
}
else
if
(
cond
==
CONTINUE
)
{
continue
;
}
else
if
(
cond
==
BREAK
)
{
break
;
}
}
taosMemoryFree
(
pCt
);
taosMemoryFree
(
exBuf
);
tSkipListDestroyIter
(
iter
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchRange
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTempResult
*
tr
,
STermValueType
*
s
)
{
...
...
@@ -408,6 +514,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
indexCacheRef
(
cache
);
cache
->
imm
=
cache
->
mem
;
cache
->
mem
=
indexInternalCacheCreate
(
cache
->
type
);
cache
->
mem
->
pCache
=
cache
;
cache
->
occupiedMem
=
0
;
// sched to merge
// unref cache in bgwork
...
...
source/libs/index/src/indexComm.c
浏览文件 @
8240b10a
...
...
@@ -46,3 +46,30 @@ char* indexPackJsonData(SIndexTerm* itm) {
return
buf
;
}
char
*
indexPackJsonDataPrefix
(
SIndexTerm
*
itm
,
int32_t
*
skip
)
{
/*
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
*/
uint8_t
ty
=
INDEX_TYPE_GET_TYPE
(
itm
->
colType
);
int32_t
sz
=
itm
->
nColName
+
itm
->
nColVal
+
sizeof
(
uint8_t
)
+
sizeof
(
JSON_VALUE_DELIM
)
*
2
+
1
;
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sz
);
char
*
p
=
buf
;
memcpy
(
p
,
itm
->
colName
,
itm
->
nColName
);
p
+=
itm
->
nColName
;
memcpy
(
p
,
&
JSON_VALUE_DELIM
,
sizeof
(
JSON_VALUE_DELIM
));
p
+=
sizeof
(
JSON_VALUE_DELIM
);
memcpy
(
p
,
&
ty
,
sizeof
(
ty
));
p
+=
sizeof
(
ty
);
memcpy
(
p
,
&
JSON_VALUE_DELIM
,
sizeof
(
JSON_VALUE_DELIM
));
p
+=
sizeof
(
JSON_VALUE_DELIM
);
*
skip
=
p
-
buf
;
return
buf
;
}
source/libs/index/src/indexTfile.c
浏览文件 @
8240b10a
...
...
@@ -308,20 +308,20 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
}
static
int32_t
tfSearchCompareFunc
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxTempResult
*
tr
,
RangeType
type
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
int
skip
=
0
;
if
(
hasJson
)
{
p
=
indexPackJsonData
(
tem
);
sz
=
strlen
(
p
);
p
=
indexPackJsonDataPrefix
(
tem
,
&
skip
);
}
SArray
*
offsets
=
taosArrayInit
(
16
,
sizeof
(
uint64_t
));
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_ALWAYS
);
FstStreamBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
FstSlice
h
=
fstSliceCreate
((
uint8_t
*
)
p
,
s
z
);
FstSlice
h
=
fstSliceCreate
((
uint8_t
*
)
p
,
s
kip
);
fstStreamBuilderSetRange
(
sb
,
&
h
,
type
);
fstSliceDestroy
(
&
h
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录