Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9453f80d
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看板
提交
9453f80d
编写于
5月 16, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(index): fix index condition error
上级
e8a63769
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
136 addition
and
88 deletion
+136
-88
source/libs/index/inc/indexComm.h
source/libs/index/inc/indexComm.h
+4
-4
source/libs/index/src/index.c
source/libs/index/src/index.c
+1
-1
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+119
-69
source/libs/index/test/.utilUT.cc.swn
source/libs/index/test/.utilUT.cc.swn
+0
-0
source/libs/index/test/jsonUT.cc
source/libs/index/test/jsonUT.cc
+1
-1
source/libs/index/test/utilUT.cc
source/libs/index/test/utilUT.cc
+11
-13
未找到文件。
source/libs/index/inc/indexComm.h
浏览文件 @
9453f80d
...
...
@@ -33,17 +33,17 @@ typedef enum { MATCH, CONTINUE, BREAK } TExeCond;
typedef
TExeCond
(
*
_cache_range_compare
)(
void
*
a
,
void
*
b
,
int8_t
type
);
TExeCond
tDoCommpare
(
__compar_fn_t
func
,
int8_t
comType
,
void
*
a
,
void
*
b
);
TExeCond
tCompare
(
__compar_fn_t
func
,
int8_t
cmpType
,
void
*
a
,
void
*
b
,
int8_t
dType
);
TExeCond
tDoCompare
(
__compar_fn_t
func
,
int8_t
cmpType
,
void
*
a
,
void
*
b
);
_cache_range_compare
indexGetCompare
(
RangeType
ty
);
int32_t
indexConvertData
(
void
*
src
,
int8_t
type
,
void
**
dst
);
int32_t
indexConvertDataToStr
(
void
*
src
,
int8_t
type
,
void
**
dst
);
int32_t
indexGetDataByteLen
(
int8_t
type
);
int32_t
indexMayFillNumbericData
(
void
*
number
,
int32_t
tlen
);
int32_t
indexMayUnfillNumbericData
(
void
*
number
,
int32_t
tlen
);
char
*
indexInt2str
(
int64_t
val
,
char
*
dst
,
int
radix
);
#ifdef __cplusplus
}
...
...
source/libs/index/src/index.c
浏览文件 @
9453f80d
...
...
@@ -271,7 +271,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
tm
->
nColName
=
nColName
;
char
*
buf
=
NULL
;
int32_t
len
=
indexConvertData
((
void
*
)
colVal
,
INDEX_TYPE_GET_TYPE
(
colType
),
(
void
**
)
&
buf
);
int32_t
len
=
indexConvertData
ToStr
((
void
*
)
colVal
,
INDEX_TYPE_GET_TYPE
(
colType
),
(
void
**
)
&
buf
);
assert
(
len
!=
-
1
);
tm
->
colVal
=
buf
;
...
...
source/libs/index/src/indexComm.c
浏览文件 @
9453f80d
...
...
@@ -19,10 +19,38 @@
#include "tcoding.h"
#include "tcompare.h"
#include "tdataformat.h"
#include "ttypes.h"
char
JSON_COLUMN
[]
=
"JSON"
;
char
JSON_VALUE_DELIM
=
'&'
;
char
*
indexInt2str
(
int64_t
val
,
char
*
dst
,
int
radix
)
{
char
buffer
[
65
];
char
*
p
;
int64_t
new_val
;
uint64_t
uval
=
(
uint64_t
)
val
;
if
(
radix
<
0
)
{
if
(
val
<
0
)
{
*
dst
++
=
'-'
;
uval
=
(
uint64_t
)
0
-
uval
;
/* Avoid integer overflow in (-val) for LLONG_MIN (BUG#31799). */
}
}
p
=
&
buffer
[
sizeof
(
buffer
)
-
1
];
*
p
=
'\0'
;
new_val
=
(
int64_t
)(
uval
/
10
);
*--
p
=
'0'
+
(
char
)(
uval
-
(
uint64_t
)
new_val
*
10
);
val
=
new_val
;
while
(
val
!=
0
)
{
new_val
=
val
/
10
;
*--
p
=
'0'
+
(
char
)(
val
-
new_val
*
10
);
val
=
new_val
;
}
while
((
*
dst
++
=
*
p
++
)
!=
0
)
;
return
dst
-
1
;
}
static
__compar_fn_t
indexGetCompar
(
int8_t
type
)
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
return
(
__compar_fn_t
)
strcmp
;
...
...
@@ -31,41 +59,49 @@ static __compar_fn_t indexGetCompar(int8_t type) {
}
static
TExeCond
tCompareLessThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
indexGetCompar
(
type
);
int32_t
tlen
=
indexGetDataByteLen
(
type
);
indexMayUnfillNumbericData
(
a
,
tlen
);
indexMayUnfillNumbericData
(
b
,
tlen
);
return
tDoCommpare
(
func
,
QUERY_LESS_THAN
,
a
,
b
);
return
tCompare
(
func
,
QUERY_LESS_THAN
,
a
,
b
,
type
);
}
static
TExeCond
tCompareLessEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
indexGetCompar
(
type
);
int32_t
tlen
=
indexGetDataByteLen
(
type
);
indexMayUnfillNumbericData
(
a
,
tlen
);
indexMayUnfillNumbericData
(
b
,
tlen
);
return
tDoCommpare
(
func
,
QUERY_LESS_EQUAL
,
a
,
b
);
return
tCompare
(
func
,
QUERY_LESS_EQUAL
,
a
,
b
,
type
);
}
static
TExeCond
tCompareGreaterThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
indexGetCompar
(
type
);
int32_t
tlen
=
indexGetDataByteLen
(
type
);
indexMayUnfillNumbericData
(
a
,
tlen
);
indexMayUnfillNumbericData
(
b
,
tlen
);
return
tDoCommpare
(
func
,
QUERY_GREATER_THAN
,
a
,
b
);
return
tCompare
(
func
,
QUERY_GREATER_THAN
,
a
,
b
,
type
);
}
static
TExeCond
tCompareGreaterEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
indexGetCompar
(
type
);
int32_t
tlen
=
indexGetDataByteLen
(
type
);
indexMayUnfillNumbericData
(
a
,
tlen
);
indexMayUnfillNumbericData
(
b
,
tlen
);
return
tDoCommpare
(
func
,
QUERY_GREATER_EQUAL
,
a
,
b
);
return
tCompare
(
func
,
QUERY_GREATER_EQUAL
,
a
,
b
,
type
);
}
TExeCond
tDoCommpare
(
__compar_fn_t
func
,
int8_t
comType
,
void
*
a
,
void
*
b
)
{
TExeCond
tCompare
(
__compar_fn_t
func
,
int8_t
cmptype
,
void
*
a
,
void
*
b
,
int8_t
dtype
)
{
if
(
dtype
==
TSDB_DATA_TYPE_BINARY
||
dtype
==
TSDB_DATA_TYPE_NCHAR
)
{
return
tDoCompare
(
func
,
cmptype
,
a
,
b
);
}
#if 1
int8_t
bytes
=
tDataTypes
[
dtype
].
bytes
;
if
(
bytes
==
1
)
{
int8_t
va
=
taosStr2int64
(
a
);
int8_t
vb
=
taosStr2int64
(
b
);
return
tDoCompare
(
func
,
cmptype
,
&
va
,
&
vb
);
}
else
if
(
bytes
==
2
)
{
int16_t
va
=
taosStr2int64
(
a
);
int16_t
vb
=
taosStr2int64
(
b
);
return
tDoCompare
(
func
,
cmptype
,
&
va
,
&
vb
);
}
else
if
(
bytes
==
4
)
{
int32_t
va
=
taosStr2int64
(
a
);
int32_t
vb
=
taosStr2int64
(
b
);
return
tDoCompare
(
func
,
cmptype
,
&
va
,
&
vb
);
}
else
{
int64_t
va
=
taosStr2int64
(
a
);
int64_t
vb
=
taosStr2int64
(
b
);
return
tDoCompare
(
func
,
cmptype
,
&
va
,
&
vb
);
}
#endif
}
TExeCond
tDoCompare
(
__compar_fn_t
func
,
int8_t
comparType
,
void
*
a
,
void
*
b
)
{
// optime later
int32_t
ret
=
func
(
a
,
b
);
switch
(
comType
)
{
switch
(
com
par
Type
)
{
case
QUERY_LESS_THAN
:
{
if
(
ret
<
0
)
return
MATCH
;
}
break
;
...
...
@@ -231,78 +267,92 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) {
break
;
}
*
dst
=
*
dst
-
tlen
;
indexMayFillNumbericData
(
*
dst
,
tlen
);
// if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR && type != TSDB_DATA_TYPE_VARBINARY &&
// type != TSDB_DATA_TYPE_VARCHAR) { uint8_t* p = *dst;
// for (int i = 0; i < tlen; i++) {
// if (p[i] == 0) {
// p[i] = (uint8_t)'0';
// }
// }
//}
// indexMayFillNumbericData(*dst, tlen);
return
tlen
;
}
int32_t
indexGetDataByteLen
(
int8_t
type
)
{
int32_t
tlen
=
-
1
;
int32_t
indexConvertDataToStr
(
void
*
src
,
int8_t
type
,
void
**
dst
)
{
int
tlen
=
tDataTypes
[
type
].
bytes
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_TIMESTAMP
:
tlen
=
sizeof
(
int64_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
int64_t
*
)
src
,
*
dst
,
-
1
);
break
;
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_UTINYINT
:
tlen
=
sizeof
(
uint8_t
);
// tlen = taosEncodeFixedU8(NULL, *(uint8_t*)src);
//*dst = taosMemoryCalloc(1, tlen + 1);
// tlen = taosEncodeFixedU8(dst, *(uint8_t*)src);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
uint8_t
*
)
src
,
*
dst
,
1
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
tlen
=
sizeof
(
uint8_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
int8_t
*
)
src
,
*
dst
,
1
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
tlen
=
sizeof
(
int16_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
int16_t
*
)
src
,
*
dst
,
-
1
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
tlen
=
sizeof
(
uint16_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
uint16_t
*
)
src
,
*
dst
,
-
1
);
break
;
case
TSDB_DATA_TYPE_INT
:
tlen
=
sizeof
(
int32_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
int32_t
*
)
src
,
*
dst
,
-
1
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
tlen
=
taosEncodeBinary
(
NULL
,
src
,
sizeof
(
float
));
*
dst
=
taosMemoryCalloc
(
1
,
tlen
+
1
);
tlen
=
taosEncodeBinary
(
dst
,
src
,
sizeof
(
float
));
break
;
case
TSDB_DATA_TYPE_UINT
:
tlen
=
sizeof
(
uint32_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
uint32_t
*
)
src
,
*
dst
,
1
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
tlen
=
sizeof
(
int64_t
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
int64_t
*
)
src
,
*
dst
,
1
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
tlen
=
taosEncodeBinary
(
NULL
,
src
,
sizeof
(
double
));
*
dst
=
taosMemoryCalloc
(
1
,
tlen
+
1
);
tlen
=
taosEncodeBinary
(
dst
,
src
,
sizeof
(
double
));
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
tlen
=
sizeof
(
uint64_t
);
assert
(
0
);
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
1
);
indexInt2str
(
*
(
uint64_t
*
)
src
,
*
dst
,
1
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
tlen
=
sizeof
(
float
);
case
TSDB_DATA_TYPE_NCHAR
:
{
tlen
=
taosEncodeBinary
(
NULL
,
varDataVal
(
src
),
varDataLen
(
src
));
*
dst
=
taosMemoryCalloc
(
1
,
tlen
+
1
);
tlen
=
taosEncodeBinary
(
dst
,
varDataVal
(
src
),
varDataLen
(
src
));
*
dst
=
*
dst
-
tlen
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
tlen
=
sizeof
(
double
);
}
case
TSDB_DATA_TYPE_VARCHAR
:
{
// TSDB_DATA_TYPE_BINARY
#if 1
tlen
=
taosEncodeBinary
(
NULL
,
src
,
strlen
(
src
));
*
dst
=
taosMemoryCalloc
(
1
,
tlen
+
1
);
tlen
=
taosEncodeBinary
(
dst
,
src
,
strlen
(
src
));
*
dst
=
*
dst
-
tlen
;
break
;
#endif
}
case
TSDB_DATA_TYPE_VARBINARY
:
#if 1
tlen
=
taosEncodeBinary
(
NULL
,
src
,
strlen
(
src
));
*
dst
=
taosMemoryCalloc
(
1
,
tlen
+
1
);
tlen
=
taosEncodeBinary
(
dst
,
src
,
strlen
(
src
));
*
dst
=
*
dst
-
tlen
;
break
;
#endif
default:
TASSERT
(
0
);
break
;
}
return
tlen
;
}
int32_t
indexMayFillNumbericData
(
void
*
number
,
int32_t
tlen
)
{
for
(
int
i
=
0
;
i
<
tlen
;
i
++
)
{
int8_t
*
p
=
number
;
if
(
p
[
i
]
==
0
)
{
p
[
i
]
=
(
uint8_t
)
'0'
;
}
}
return
0
;
}
int32_t
indexMayUnfillNumbericData
(
void
*
number
,
int32_t
tlen
)
{
for
(
int
i
=
0
;
i
<
tlen
;
i
++
)
{
int8_t
*
p
=
number
;
if
(
p
[
i
]
==
(
uint8_t
)
'0'
)
{
p
[
i
]
=
0
;
}
}
return
0
;
}
source/libs/index/test/.utilUT.cc.swn
已删除
100644 → 0
浏览文件 @
e8a63769
文件已删除
source/libs/index/test/jsonUT.cc
浏览文件 @
9453f80d
...
...
@@ -465,7 +465,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache) {
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
indexMultiTermAdd
(
terms
,
term
);
for
(
size_t
i
=
0
;
i
<
1000
;
i
++
)
{
tIndexJsonPut
(
index
,
terms
,
i
);
tIndexJsonPut
(
index
,
terms
,
i
+
1000
);
}
indexMultiTermDestroy
(
terms
);
}
...
...
source/libs/index/test/utilUT.cc
浏览文件 @
9453f80d
...
...
@@ -308,18 +308,16 @@ TEST_F(UtilEnv, 01Except) {
ASSERT_EQ
(
*
(
uint64_t
*
)
taosArrayGet
(
total
,
1
),
100
);
}
TEST_F
(
UtilEnv
,
testFill
)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
char
buf
[
10
]
=
{
0
};
void
*
pBuf
=
(
void
*
)
buf
;
int
val
=
i
;
int
v
;
taosEncodeFixedI32
((
void
**
)(
&
pBuf
),
val
);
// memcpy(buf, &val, sizeof(int));
indexMayFillNumbericData
((
void
*
)
buf
,
sizeof
(
val
));
indexMayUnfillNumbericData
((
void
*
)
buf
,
sizeof
(
val
));
taosDecodeFixedI32
(
buf
,
&
v
);
ASSERT_EQ
(
val
,
v
);
for
(
int
i
=
0
;
i
<
10000000
;
i
++
)
{
int64_t
val
=
i
;
char
buf
[
65
]
=
{
0
};
indexInt2str
(
val
,
buf
,
1
);
EXPECT_EQ
(
val
,
taosStr2int64
(
buf
));
}
for
(
int
i
=
0
;
i
<
10000000
;
i
++
)
{
int64_t
val
=
0
-
i
;
char
buf
[
65
]
=
{
0
};
indexInt2str
(
val
,
buf
,
-
1
);
EXPECT_EQ
(
val
,
taosStr2int64
(
buf
));
}
assert
(
0
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录