Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1643b5e4
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
1643b5e4
编写于
8月 02, 2021
作者:
W
wpan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug and case issue
上级
07f7b9ac
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
382 addition
and
26 deletion
+382
-26
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+2
-2
src/common/inc/texpr.h
src/common/inc/texpr.h
+0
-1
src/common/inc/tvariant.h
src/common/inc/tvariant.h
+2
-0
src/common/src/tvariant.c
src/common/src/tvariant.c
+68
-10
src/query/inc/qFilter.h
src/query/inc/qFilter.h
+5
-3
src/query/src/qFilter.c
src/query/src/qFilter.c
+249
-8
tests/pytest/query/queryBetweenAnd.py
tests/pytest/query/queryBetweenAnd.py
+2
-2
tests/script/general/parser/condition_query.sim
tests/script/general/parser/condition_query.sim
+54
-0
未找到文件。
src/client/src/tscUtil.c
浏览文件 @
1643b5e4
...
@@ -62,11 +62,11 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le
...
@@ -62,11 +62,11 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le
break
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_FLOAT
:
n
=
sprintf
(
str
,
"%
f
"
,
GET_FLOAT_VAL
(
buf
));
n
=
sprintf
(
str
,
"%
e
"
,
GET_FLOAT_VAL
(
buf
));
break
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_DOUBLE
:
n
=
sprintf
(
str
,
"%
f
"
,
GET_DOUBLE_VAL
(
buf
));
n
=
sprintf
(
str
,
"%
e
"
,
GET_DOUBLE_VAL
(
buf
));
break
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_BINARY
:
...
...
src/common/inc/texpr.h
浏览文件 @
1643b5e4
...
@@ -95,7 +95,6 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
...
@@ -95,7 +95,6 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
char
*
(
*
cb
)(
void
*
,
const
char
*
,
int32_t
));
char
*
(
*
cb
)(
void
*
,
const
char
*
,
int32_t
));
void
buildFilterSetFromBinary
(
void
**
q
,
const
char
*
buf
,
int32_t
len
);
void
buildFilterSetFromBinary
(
void
**
q
,
const
char
*
buf
,
int32_t
len
);
void
convertFilterSetFromBinary
(
void
**
q
,
const
char
*
buf
,
int32_t
len
,
uint32_t
tType
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/common/inc/tvariant.h
浏览文件 @
1643b5e4
...
@@ -53,6 +53,8 @@ int32_t tVariantToString(tVariant *pVar, char *dst);
...
@@ -53,6 +53,8 @@ int32_t tVariantToString(tVariant *pVar, char *dst);
int32_t
tVariantDump
(
tVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
);
int32_t
tVariantDump
(
tVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
);
int32_t
tVariantDumpEx
(
tVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
,
bool
*
converted
,
char
*
extInfo
);
int32_t
tVariantTypeSetType
(
tVariant
*
pVariant
,
char
type
);
int32_t
tVariantTypeSetType
(
tVariant
*
pVariant
,
char
type
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
src/common/src/tvariant.c
浏览文件 @
1643b5e4
...
@@ -23,6 +23,13 @@
...
@@ -23,6 +23,13 @@
#include "tutil.h"
#include "tutil.h"
#include "tvariant.h"
#include "tvariant.h"
#define SET_EXT_INFO(converted, res, minv, maxv, exti) do { \
if (converted == NULL || exti == NULL || *converted == false) { break; } \
if ((res) < (minv)) { *exti = -1; break; } \
if ((res) > (maxv)) { *exti = 1; break; } \
assert(0); \
} while (0)
void
tVariantCreate
(
tVariant
*
pVar
,
SStrToken
*
token
)
{
void
tVariantCreate
(
tVariant
*
pVar
,
SStrToken
*
token
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
int32_t
type
=
token
->
type
;
int32_t
type
=
token
->
type
;
...
@@ -462,7 +469,7 @@ static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *val
...
@@ -462,7 +469,7 @@ static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *val
return
0
;
return
0
;
}
}
static
FORCE_INLINE
int32_t
convertToInteger
(
tVariant
*
pVariant
,
int64_t
*
result
,
int32_t
type
,
bool
issigned
,
bool
releaseVariantPtr
)
{
static
FORCE_INLINE
int32_t
convertToInteger
(
tVariant
*
pVariant
,
int64_t
*
result
,
int32_t
type
,
bool
issigned
,
bool
releaseVariantPtr
,
bool
*
converted
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
setNull
((
char
*
)
result
,
type
,
tDataTypes
[
type
].
bytes
);
setNull
((
char
*
)
result
,
type
,
tDataTypes
[
type
].
bytes
);
return
0
;
return
0
;
...
@@ -552,6 +559,10 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
...
@@ -552,6 +559,10 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
}
}
}
}
if
(
converted
)
{
*
converted
=
true
;
}
bool
code
=
false
;
bool
code
=
false
;
uint64_t
ui
=
0
;
uint64_t
ui
=
0
;
...
@@ -614,6 +625,18 @@ static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) {
...
@@ -614,6 +625,18 @@ static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) {
* to column type defined in schema
* to column type defined in schema
*/
*/
int32_t
tVariantDump
(
tVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
)
{
int32_t
tVariantDump
(
tVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
)
{
return
tVariantDumpEx
(
pVariant
,
payload
,
type
,
includeLengthPrefix
,
NULL
,
NULL
);
}
/*
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
* to column type defined in schema
*/
int32_t
tVariantDumpEx
(
tVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
,
bool
*
converted
,
char
*
extInfo
)
{
if
(
converted
)
{
*
converted
=
false
;
}
if
(
pVariant
==
NULL
||
(
pVariant
->
nType
!=
0
&&
!
isValidDataType
(
pVariant
->
nType
)))
{
if
(
pVariant
==
NULL
||
(
pVariant
->
nType
!=
0
&&
!
isValidDataType
(
pVariant
->
nType
)))
{
return
-
1
;
return
-
1
;
}
}
...
@@ -632,7 +655,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -632,7 +655,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_TINYINT
:
{
case
TSDB_DATA_TYPE_TINYINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT8_MIN
+
1
,
INT8_MAX
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
int8_t
*
)
payload
)
=
(
int8_t
)
result
;
*
((
int8_t
*
)
payload
)
=
(
int8_t
)
result
;
...
@@ -640,7 +664,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -640,7 +664,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
case
TSDB_DATA_TYPE_UTINYINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT8_MAX
-
1
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
uint8_t
*
)
payload
)
=
(
uint8_t
)
result
;
*
((
uint8_t
*
)
payload
)
=
(
uint8_t
)
result
;
...
@@ -648,7 +673,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -648,7 +673,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
case
TSDB_DATA_TYPE_SMALLINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT16_MIN
+
1
,
INT16_MAX
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
int16_t
*
)
payload
)
=
(
int16_t
)
result
;
*
((
int16_t
*
)
payload
)
=
(
int16_t
)
result
;
...
@@ -656,7 +682,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -656,7 +682,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
case
TSDB_DATA_TYPE_USMALLINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT16_MAX
-
1
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
uint16_t
*
)
payload
)
=
(
uint16_t
)
result
;
*
((
uint16_t
*
)
payload
)
=
(
uint16_t
)
result
;
...
@@ -664,7 +691,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -664,7 +691,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_INT
:
{
case
TSDB_DATA_TYPE_INT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT32_MIN
+
1
,
INT32_MAX
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
int32_t
*
)
payload
)
=
(
int32_t
)
result
;
*
((
int32_t
*
)
payload
)
=
(
int32_t
)
result
;
...
@@ -672,7 +700,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -672,7 +700,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_UINT
:
{
case
TSDB_DATA_TYPE_UINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT32_MAX
-
1
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
uint32_t
*
)
payload
)
=
(
uint32_t
)
result
;
*
((
uint32_t
*
)
payload
)
=
(
uint32_t
)
result
;
...
@@ -680,7 +709,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -680,7 +709,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_BIGINT
:
{
case
TSDB_DATA_TYPE_BIGINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
(
int64_t
)
result
,
INT64_MIN
+
1
,
INT64_MAX
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
int64_t
*
)
payload
)
=
(
int64_t
)
result
;
*
((
int64_t
*
)
payload
)
=
(
int64_t
)
result
;
...
@@ -688,7 +718,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -688,7 +718,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
}
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
case
TSDB_DATA_TYPE_UBIGINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
)
<
0
)
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
(
uint64_t
)
result
,
0
,
UINT64_MAX
-
1
,
extInfo
);
return
-
1
;
return
-
1
;
}
}
*
((
uint64_t
*
)
payload
)
=
(
uint64_t
)
result
;
*
((
uint64_t
*
)
payload
)
=
(
uint64_t
)
result
;
...
@@ -708,11 +739,37 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -708,11 +739,37 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
return
-
1
;
return
-
1
;
}
}
if
(
converted
)
{
*
converted
=
true
;
}
if
(
value
>
FLT_MAX
||
value
<
-
FLT_MAX
)
{
SET_EXT_INFO
(
converted
,
value
,
-
FLT_MAX
,
FLT_MAX
,
extInfo
);
return
-
1
;
}
SET_FLOAT_VAL
(
payload
,
value
);
SET_FLOAT_VAL
(
payload
,
value
);
}
}
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
if
(
converted
)
{
*
converted
=
true
;
}
if
(
pVariant
->
i64
>
FLT_MAX
||
pVariant
->
i64
<
-
FLT_MAX
)
{
SET_EXT_INFO
(
converted
,
pVariant
->
i64
,
-
FLT_MAX
,
FLT_MAX
,
extInfo
);
return
-
1
;
}
SET_FLOAT_VAL
(
payload
,
pVariant
->
i64
);
SET_FLOAT_VAL
(
payload
,
pVariant
->
i64
);
}
else
if
(
IS_FLOAT_TYPE
(
pVariant
->
nType
))
{
}
else
if
(
IS_FLOAT_TYPE
(
pVariant
->
nType
))
{
if
(
converted
)
{
*
converted
=
true
;
}
if
(
pVariant
->
dKey
>
FLT_MAX
||
pVariant
->
dKey
<
-
FLT_MAX
)
{
SET_EXT_INFO
(
converted
,
pVariant
->
dKey
,
-
FLT_MAX
,
FLT_MAX
,
extInfo
);
return
-
1
;
}
SET_FLOAT_VAL
(
payload
,
pVariant
->
dKey
);
SET_FLOAT_VAL
(
payload
,
pVariant
->
dKey
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
((
uint32_t
*
)
payload
)
=
TSDB_DATA_FLOAT_NULL
;
*
((
uint32_t
*
)
payload
)
=
TSDB_DATA_FLOAT_NULL
;
...
@@ -836,6 +893,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
...
@@ -836,6 +893,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
return
0
;
return
0
;
}
}
/*
/*
* In variant, bool/smallint/tinyint/int/bigint share the same attribution of
* In variant, bool/smallint/tinyint/int/bigint share the same attribution of
* structure, also ignore the convert the type required
* structure, also ignore the convert the type required
...
@@ -860,7 +918,7 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
...
@@ -860,7 +918,7 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
{
case
TSDB_DATA_TYPE_SMALLINT
:
{
convertToInteger
(
pVariant
,
&
(
pVariant
->
i64
),
type
,
true
,
true
);
convertToInteger
(
pVariant
,
&
(
pVariant
->
i64
),
type
,
true
,
true
,
NULL
);
pVariant
->
nType
=
TSDB_DATA_TYPE_BIGINT
;
pVariant
->
nType
=
TSDB_DATA_TYPE_BIGINT
;
break
;
break
;
}
}
...
...
src/query/inc/qFilter.h
浏览文件 @
1643b5e4
...
@@ -30,6 +30,8 @@ extern "C" {
...
@@ -30,6 +30,8 @@ extern "C" {
#define FILTER_DEFAULT_VALUE_SIZE 4
#define FILTER_DEFAULT_VALUE_SIZE 4
#define FILTER_DEFAULT_GROUP_UNIT_SIZE 2
#define FILTER_DEFAULT_GROUP_UNIT_SIZE 2
#define FILTER_DUMMY_EMPTY_OPTR 127
#define MAX_NUM_STR_SIZE 40
#define MAX_NUM_STR_SIZE 40
enum
{
enum
{
...
@@ -214,12 +216,12 @@ typedef struct SFilterInfo {
...
@@ -214,12 +216,12 @@ typedef struct SFilterInfo {
#define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t))
#define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t))
#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR)
#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR)
#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL)
#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL
|| (o) == FILTER_DUMMY_EMPTY_OPTR
)
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
#define SET_AND_OPTR(ctx, o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0)
#define SET_AND_OPTR(ctx, o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else
if (o != FILTER_DUMMY_EMPTY_OPTR)
{ (ctx)->isrange = true; (ctx)->notnull = false; } } while (0)
#define SET_OR_OPTR(ctx,o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0)
#define SET_OR_OPTR(ctx,o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else
if (o != FILTER_DUMMY_EMPTY_OPTR)
{ if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0)
#define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true)
#define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true)
#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true)))
#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true)))
...
...
src/query/src/qFilter.c
浏览文件 @
1643b5e4
...
@@ -236,7 +236,7 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b
...
@@ -236,7 +236,7 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b
if
(
optr
==
TSDB_RELATION_AND
)
{
if
(
optr
==
TSDB_RELATION_AND
)
{
SET_AND_OPTR
(
ctx
,
raOptr
);
SET_AND_OPTR
(
ctx
,
raOptr
);
if
(
CHK_AND_OPTR
(
ctx
))
{
if
(
CHK_AND_OPTR
(
ctx
)
||
(
raOptr
==
FILTER_DUMMY_EMPTY_OPTR
)
)
{
FILTER_SET_FLAG
(
ctx
->
status
,
MR_ST_EMPTY
);
FILTER_SET_FLAG
(
ctx
->
status
,
MR_ST_EMPTY
);
*
empty
=
true
;
*
empty
=
true
;
}
}
...
@@ -815,6 +815,214 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) {
...
@@ -815,6 +815,214 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
filterConvertSetFromBinary
(
void
**
q
,
const
char
*
buf
,
int32_t
len
,
uint32_t
tType
)
{
SBufferReader
br
=
tbufInitReader
(
buf
,
len
,
false
);
uint32_t
sType
=
tbufReadUint32
(
&
br
);
SHashObj
*
pObj
=
taosHashInit
(
256
,
taosGetDefaultHashFunction
(
tType
),
true
,
false
);
int32_t
code
=
0
;
taosHashSetEqualFp
(
pObj
,
taosGetDefaultEqualFunction
(
tType
));
int
dummy
=
-
1
;
tVariant
tmpVar
=
{
0
};
size_t
t
=
0
;
int32_t
sz
=
tbufReadInt32
(
&
br
);
void
*
pvar
=
NULL
;
int64_t
val
=
0
;
int32_t
bufLen
=
0
;
if
(
IS_NUMERIC_TYPE
(
sType
))
{
bufLen
=
60
;
// The maximum length of string that a number is converted to.
}
else
{
bufLen
=
128
;
}
char
*
tmp
=
calloc
(
1
,
bufLen
*
TSDB_NCHAR_SIZE
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
switch
(
sType
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
{
*
(
uint8_t
*
)
&
val
=
(
uint8_t
)
tbufReadInt64
(
&
br
);
t
=
sizeof
(
val
);
pvar
=
&
val
;
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
{
*
(
uint16_t
*
)
&
val
=
(
uint16_t
)
tbufReadInt64
(
&
br
);
t
=
sizeof
(
val
);
pvar
=
&
val
;
break
;
}
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_INT
:
{
*
(
uint32_t
*
)
&
val
=
(
uint32_t
)
tbufReadInt64
(
&
br
);
t
=
sizeof
(
val
);
pvar
=
&
val
;
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
{
*
(
uint64_t
*
)
&
val
=
(
uint64_t
)
tbufReadInt64
(
&
br
);
t
=
sizeof
(
val
);
pvar
=
&
val
;
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
*
(
double
*
)
&
val
=
tbufReadDouble
(
&
br
);
t
=
sizeof
(
val
);
pvar
=
&
val
;
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
*
(
float
*
)
&
val
=
(
float
)
tbufReadDouble
(
&
br
);
t
=
sizeof
(
val
);
pvar
=
&
val
;
break
;
}
case
TSDB_DATA_TYPE_BINARY
:
{
pvar
=
(
char
*
)
tbufReadBinary
(
&
br
,
&
t
);
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
pvar
=
(
char
*
)
tbufReadBinary
(
&
br
,
&
t
);
break
;
}
default:
taosHashCleanup
(
pObj
);
*
q
=
NULL
;
assert
(
0
);
}
tVariantCreateFromBinary
(
&
tmpVar
,
(
char
*
)
pvar
,
t
,
sType
);
if
(
bufLen
<
t
)
{
tmp
=
realloc
(
tmp
,
t
*
TSDB_NCHAR_SIZE
);
bufLen
=
t
;
}
bool
converted
=
false
;
char
extInfo
=
0
;
switch
(
tType
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
{
if
(
tVariantDumpEx
(
&
tmpVar
,
(
char
*
)
&
val
,
tType
,
false
,
&
converted
,
&
extInfo
))
{
if
(
converted
)
{
tVariantDestroy
(
&
tmpVar
);
memset
(
&
tmpVar
,
0
,
sizeof
(
tmpVar
));
continue
;
}
goto
_err_return
;
}
pvar
=
&
val
;
t
=
sizeof
(
val
);
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
{
if
(
tVariantDumpEx
(
&
tmpVar
,
(
char
*
)
&
val
,
tType
,
false
,
&
converted
,
&
extInfo
))
{
if
(
converted
)
{
tVariantDestroy
(
&
tmpVar
);
memset
(
&
tmpVar
,
0
,
sizeof
(
tmpVar
));
continue
;
}
goto
_err_return
;
}
pvar
=
&
val
;
t
=
sizeof
(
val
);
break
;
}
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_INT
:
{
if
(
tVariantDumpEx
(
&
tmpVar
,
(
char
*
)
&
val
,
tType
,
false
,
&
converted
,
&
extInfo
))
{
if
(
converted
)
{
tVariantDestroy
(
&
tmpVar
);
memset
(
&
tmpVar
,
0
,
sizeof
(
tmpVar
));
continue
;
}
goto
_err_return
;
}
pvar
=
&
val
;
t
=
sizeof
(
val
);
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
{
if
(
tVariantDump
(
&
tmpVar
,
(
char
*
)
&
val
,
tType
,
false
))
{
goto
_err_return
;
}
pvar
=
&
val
;
t
=
sizeof
(
val
);
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
if
(
tVariantDump
(
&
tmpVar
,
(
char
*
)
&
val
,
tType
,
false
))
{
goto
_err_return
;
}
pvar
=
&
val
;
t
=
sizeof
(
val
);
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
if
(
tVariantDumpEx
(
&
tmpVar
,
(
char
*
)
&
val
,
tType
,
false
,
&
converted
,
&
extInfo
))
{
if
(
converted
)
{
tVariantDestroy
(
&
tmpVar
);
memset
(
&
tmpVar
,
0
,
sizeof
(
tmpVar
));
continue
;
}
goto
_err_return
;
}
pvar
=
&
val
;
t
=
sizeof
(
val
);
break
;
}
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
tVariantDump
(
&
tmpVar
,
tmp
,
tType
,
true
))
{
goto
_err_return
;
}
t
=
varDataLen
(
tmp
);
pvar
=
varDataVal
(
tmp
);
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
tVariantDump
(
&
tmpVar
,
tmp
,
tType
,
true
))
{
goto
_err_return
;
}
t
=
varDataLen
(
tmp
);
pvar
=
varDataVal
(
tmp
);
break
;
}
default:
goto
_err_return
;
}
taosHashPut
(
pObj
,
(
char
*
)
pvar
,
t
,
&
dummy
,
sizeof
(
dummy
));
tVariantDestroy
(
&
tmpVar
);
memset
(
&
tmpVar
,
0
,
sizeof
(
tmpVar
));
}
CHK_JMP
(
taosHashGetSize
(
pObj
)
<=
0
);
*
q
=
(
void
*
)
pObj
;
pObj
=
NULL
;
_err_return:
tVariantDestroy
(
&
tmpVar
);
taosHashCleanup
(
pObj
);
tfree
(
tmp
);
return
code
;
}
int32_t
filterAddGroupUnitFromNode
(
SFilterInfo
*
info
,
tExprNode
*
tree
,
SArray
*
group
)
{
int32_t
filterAddGroupUnitFromNode
(
SFilterInfo
*
info
,
tExprNode
*
tree
,
SArray
*
group
)
{
...
@@ -829,7 +1037,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
...
@@ -829,7 +1037,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
if
(
tree
->
_node
.
optr
==
TSDB_RELATION_IN
&&
(
!
IS_VAR_DATA_TYPE
(
type
)))
{
if
(
tree
->
_node
.
optr
==
TSDB_RELATION_IN
&&
(
!
IS_VAR_DATA_TYPE
(
type
)))
{
void
*
data
=
NULL
;
void
*
data
=
NULL
;
convertFilter
SetFromBinary
((
void
**
)
&
data
,
var
->
pz
,
var
->
nLen
,
type
);
filterConvert
SetFromBinary
((
void
**
)
&
data
,
var
->
pz
,
var
->
nLen
,
type
);
CHK_LRET
(
data
==
NULL
,
TSDB_CODE_QRY_APP_ERROR
,
"failed to convert in param"
);
CHK_LRET
(
data
==
NULL
,
TSDB_CODE_QRY_APP_ERROR
,
"failed to convert in param"
);
void
*
p
=
taosHashIterate
((
SHashObj
*
)
data
,
NULL
);
void
*
p
=
taosHashIterate
((
SHashObj
*
)
data
,
NULL
);
...
@@ -1100,7 +1308,7 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) {
...
@@ -1100,7 +1308,7 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
filterAddGroupUnitFromNode
(
info
,
tree
,
group
);
code
=
filterAddGroupUnitFromNode
(
info
,
tree
,
group
);
_err_return:
_err_return:
...
@@ -1156,7 +1364,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
...
@@ -1156,7 +1364,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
int32_t
type
=
FILTER_UNIT_DATA_TYPE
(
unit
);
int32_t
type
=
FILTER_UNIT_DATA_TYPE
(
unit
);
int32_t
len
=
0
;
int32_t
len
=
0
;
int32_t
tlen
=
0
;
int32_t
tlen
=
0
;
char
str
[
128
]
=
{
0
};
char
str
[
256
]
=
{
0
};
SFilterField
*
left
=
FILTER_UNIT_LEFT_FIELD
(
info
,
unit
);
SFilterField
*
left
=
FILTER_UNIT_LEFT_FIELD
(
info
,
unit
);
SSchema
*
sch
=
left
->
desc
;
SSchema
*
sch
=
left
->
desc
;
...
@@ -1169,7 +1377,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
...
@@ -1169,7 +1377,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
tlen
=
varDataLen
(
data
);
tlen
=
varDataLen
(
data
);
data
+=
VARSTR_HEADER_SIZE
;
data
+=
VARSTR_HEADER_SIZE
;
}
}
converToStr
(
str
+
len
,
type
,
data
,
tlen
,
&
tlen
);
converToStr
(
str
+
len
,
type
,
data
,
tlen
>
32
?
32
:
tlen
,
&
tlen
);
}
else
{
}
else
{
strcat
(
str
,
"NULL"
);
strcat
(
str
,
"NULL"
);
}
}
...
@@ -1341,6 +1549,28 @@ void filterFreeInfo(SFilterInfo *info) {
...
@@ -1341,6 +1549,28 @@ void filterFreeInfo(SFilterInfo *info) {
}
}
}
}
int32_t
filterHandleValueExtInfo
(
SFilterUnit
*
unit
,
char
extInfo
)
{
assert
(
extInfo
>
0
||
extInfo
<
0
);
uint8_t
optr
=
FILTER_UNIT_OPTR
(
unit
);
switch
(
optr
)
{
case
TSDB_RELATION_GREATER
:
case
TSDB_RELATION_GREATER_EQUAL
:
unit
->
compare
.
optr
=
(
extInfo
>
0
)
?
FILTER_DUMMY_EMPTY_OPTR
:
TSDB_RELATION_NOTNULL
;
break
;
case
TSDB_RELATION_LESS
:
case
TSDB_RELATION_LESS_EQUAL
:
unit
->
compare
.
optr
=
(
extInfo
>
0
)
?
TSDB_RELATION_NOTNULL
:
FILTER_DUMMY_EMPTY_OPTR
;
break
;
case
TSDB_RELATION_EQUAL
:
unit
->
compare
.
optr
=
FILTER_DUMMY_EMPTY_OPTR
;
break
;
default:
assert
(
0
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
filterInitValFieldData
(
SFilterInfo
*
info
)
{
int32_t
filterInitValFieldData
(
SFilterInfo
*
info
)
{
...
@@ -1366,7 +1596,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
...
@@ -1366,7 +1596,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
}
}
if
(
unit
->
compare
.
optr
==
TSDB_RELATION_IN
)
{
if
(
unit
->
compare
.
optr
==
TSDB_RELATION_IN
)
{
convertFilter
SetFromBinary
((
void
**
)
&
fi
->
data
,
var
->
pz
,
var
->
nLen
,
type
);
filterConvert
SetFromBinary
((
void
**
)
&
fi
->
data
,
var
->
pz
,
var
->
nLen
,
type
);
CHK_LRET
(
fi
->
data
==
NULL
,
TSDB_CODE_QRY_APP_ERROR
,
"failed to convert in param"
);
CHK_LRET
(
fi
->
data
==
NULL
,
TSDB_CODE_QRY_APP_ERROR
,
"failed to convert in param"
);
FILTER_SET_FLAG
(
fi
->
flag
,
FLD_DATA_IS_HASH
);
FILTER_SET_FLAG
(
fi
->
flag
,
FLD_DATA_IS_HASH
);
...
@@ -1394,7 +1624,17 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
...
@@ -1394,7 +1624,17 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
}
}
}
}
ERR_LRET
(
tVariantDump
(
var
,
(
char
*
)
fi
->
data
,
type
,
true
),
"dump type[%d] failed"
,
type
);
bool
converted
=
false
;
char
extInfo
=
0
;
if
(
tVariantDumpEx
(
var
,
(
char
*
)
fi
->
data
,
type
,
true
,
&
converted
,
&
extInfo
))
{
if
(
converted
)
{
filterHandleValueExtInfo
(
unit
,
extInfo
);
continue
;
}
qError
(
"dump value to type[%d] failed"
,
type
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -1594,7 +1834,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
...
@@ -1594,7 +1834,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
for
(
uint16_t
l
=
0
;
l
<
colIdxi
;
++
l
)
{
for
(
uint16_t
l
=
0
;
l
<
colIdxi
;
++
l
)
{
int32_t
type
=
gRes
[
gResIdx
]
->
colInfo
[
colIdx
[
l
]].
dataType
;
int32_t
type
=
gRes
[
gResIdx
]
->
colInfo
[
colIdx
[
l
]].
dataType
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
FILTER_NO_MERGE_DATA_TYPE
(
type
)
)
{
continue
;
continue
;
}
}
...
@@ -1606,6 +1846,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
...
@@ -1606,6 +1846,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
}
}
if
(
empty
)
{
if
(
empty
)
{
FILTER_SET_FLAG
(
info
->
status
,
FI_STATUS_REWRITE
);
filterFreeGroupCtx
(
gRes
[
gResIdx
]);
filterFreeGroupCtx
(
gRes
[
gResIdx
]);
gRes
[
gResIdx
]
=
NULL
;
gRes
[
gResIdx
]
=
NULL
;
...
...
tests/pytest/query/queryBetweenAnd.py
浏览文件 @
1643b5e4
...
@@ -101,7 +101,7 @@ class TDTestCase:
...
@@ -101,7 +101,7 @@ class TDTestCase:
# tdSql.query(f"select * from t1 where c2 between {pow(10,38)*3.4} and {pow(10,38)*3.4+1}")
# tdSql.query(f"select * from t1 where c2 between {pow(10,38)*3.4} and {pow(10,38)*3.4+1}")
# tdSql.checkRows(1)
# tdSql.checkRows(1)
tdSql
.
query
(
f
"select * from t2 where c2 between
{
-
3.4
*
10
**
38
-
1
}
and
{
-
3.4
*
10
**
38
}
"
)
tdSql
.
query
(
f
"select * from t2 where c2 between
{
-
3.4
*
10
**
38
-
1
}
and
{
-
3.4
*
10
**
38
}
"
)
tdSql
.
checkRows
(
0
)
tdSql
.
checkRows
(
2
)
tdSql
.
error
(
f
"select * from t2 where c2 between null and
{
-
3.4
*
10
**
38
}
"
)
tdSql
.
error
(
f
"select * from t2 where c2 between null and
{
-
3.4
*
10
**
38
}
"
)
# tdSql.checkRows(3)
# tdSql.checkRows(3)
...
@@ -203,4 +203,4 @@ class TDTestCase:
...
@@ -203,4 +203,4 @@ class TDTestCase:
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdLog
.
success
(
f
"
{
__file__
}
successfully executed"
)
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
\ No newline at end of file
tests/script/general/parser/condition_query.sim
浏览文件 @
1643b5e4
...
@@ -1816,6 +1816,59 @@ if $data20 != @21-05-05 18:19:28.000@ then
...
@@ -1816,6 +1816,59 @@ if $data20 != @21-05-05 18:19:28.000@ then
return -1
return -1
endi
endi
sql select * from stb1 where c1 between 60 and 9999999999;
if $rows != 4 then
return -1
endi
if $data00 != @21-05-05 18:19:24.000@ then
return -1
endi
if $data10 != @21-05-05 18:19:25.000@ then
return -1
endi
if $data20 != @21-05-05 18:19:26.000@ then
return -1
endi
if $data30 != @21-05-05 18:19:27.000@ then
return -1
endi
sql select * from stb1 where c1 > 9999999999;
if $rows != 0 then
return -1
endi
sql select * from stb1 where c1 < 9999999999;
if $rows != 28 then
return -1
endi
sql select * from stb1 where c1 = 9999999999;
if $rows != 0 then
return -1
endi
sql select * from stb1 where c1 <> 9999999999;
if $rows != 28 then
return -1
endi
sql select * from stb1 where c4 < -9999999999;
if $rows != 0 then
return -1
endi
sql select * from stb1 where c4 > -9999999999;
if $rows != 28 then
return -1
endi
sql select * from stb1 where c4 = -9999999999;
if $rows != 0 then
return -1
endi
sql select * from stb1 where c4 <> -9999999999;
if $rows != 28 then
return -1
endi
sql select * from stb1 where c5 in (-9999999999);
#sql select * from stb1 where c5 in (9999999999);
#sql select * from stb1 where c5 in (-9999999999,3,4,9999999999);
sql select * from stb3 where c1 > 3 and c1 < 2;
sql select * from stb3 where c1 > 3 and c1 < 2;
if $rows != 0 then
if $rows != 0 then
return -1
return -1
...
@@ -1891,6 +1944,7 @@ if $rows != 14 then
...
@@ -1891,6 +1944,7 @@ if $rows != 14 then
endi
endi
print "ts test"
print "ts test"
sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27'
sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27'
sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000';
sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000';
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录