Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
18bee12d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
18bee12d
编写于
6月 24, 2021
作者:
H
Haojun Liao
提交者:
GitHub
6月 24, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6586 from taosdata/feature/TD-4098
[TD-4098]<feature> refactor IN filter
上级
eff8ff73
6bc71839
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
80 addition
and
95 deletion
+80
-95
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+49
-64
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+1
-1
tests/pytest/insert/in_function.py
tests/pytest/insert/in_function.py
+18
-18
tests/script/general/parser/where.sim
tests/script/general/parser/where.sim
+12
-12
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
18bee12d
...
...
@@ -65,7 +65,6 @@ static char* getAccountId(SSqlObj* pSql);
static
int
convertTimestampStrToInt64
(
tVariant
*
pVar
,
int32_t
precision
);
static
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dest
,
int16_t
colType
,
uint8_t
precision
);
static
int32_t
validateParamOfRelationIn
(
tVariant
*
pVar
,
int32_t
colType
);
static
bool
has
(
SArray
*
pFieldList
,
int32_t
startIdx
,
const
char
*
name
);
static
char
*
cloneCurrentDBName
(
SSqlObj
*
pSql
);
...
...
@@ -156,78 +155,76 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType,
return
ret
;
}
tSqlExprItem
*
item
=
(
tSqlExprItem
*
)
taosArrayGet
(
pList
,
0
);
int32_t
firstTokenType
=
item
->
pNode
->
token
.
type
;
int32_t
type
=
firstTokenType
;
//nchar to binary and other xxint to bigint
toTSDBType
(
type
);
if
(
colType
!=
TSDB_DATA_TYPE_TIMESTAMP
&&
!
IS_UNSIGNED_NUMERIC_TYPE
(
colType
))
{
if
(
type
!=
colType
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
||
colType
!=
TSDB_DATA_TYPE_NCHAR
))
{
return
false
;
}
}
type
=
colType
;
tSqlExpr
*
item
=
((
tSqlExprItem
*
)(
taosArrayGet
(
pList
,
0
)))
->
pNode
;
int32_t
firstVarType
=
item
->
value
.
nType
;
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
tbufEnsureCapacity
(
&
bw
,
512
);
if
(
colType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
tbufWriteUint32
(
&
bw
,
TSDB_DATA_TYPE_BIGINT
);
}
else
{
tbufWriteUint32
(
&
bw
,
colType
);
}
tbufWriteInt32
(
&
bw
,
(
int32_t
)(
pList
->
size
));
int32_t
size
=
(
int32_t
)(
pList
->
size
);
tbufWriteUint32
(
&
bw
,
type
);
tbufWriteInt32
(
&
bw
,
size
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
(
int32_t
)
pList
->
size
;
i
++
)
{
tSqlExpr
*
pSub
=
((
tSqlExprItem
*
)(
taosArrayGet
(
pList
,
i
)))
->
pNode
;
tVariant
*
var
=
&
pSub
->
value
;
// check all the token type in expr list same or not
if
(
first
TokenType
!=
pSub
->
token
.
t
ype
)
{
if
(
first
VarType
!=
var
->
nT
ype
)
{
break
;
}
toTSDBType
(
pSub
->
token
.
type
);
tVariant
var
;
tVariantCreate
(
&
var
,
&
pSub
->
token
);
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
tbufWriteInt64
(
&
bw
,
var
.
i64
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
// ugly code, refactor later
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pSub
->
token
.
type
)
||
IS_SIGNED_NUMERIC_TYPE
(
pSub
->
token
.
type
))
{
tbufWriteUint64
(
&
bw
,
var
.
i64
);
if
((
colType
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
colType
)))
{
if
(
var
->
nType
!=
TSDB_DATA_TYPE_BOOL
&&
!
IS_SIGNED_NUMERIC_TYPE
(
var
->
nType
))
{
break
;
}
tbufWriteInt64
(
&
bw
,
var
->
i64
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
colType
))
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
var
->
nType
)
&&
IS_UNSIGNED_NUMERIC_TYPE
(
var
->
nType
))
{
break
;
}
tbufWriteUint64
(
&
bw
,
var
->
u64
);
}
else
if
(
colType
==
TSDB_DATA_TYPE_DOUBLE
||
colType
==
TSDB_DATA_TYPE_FLOAT
)
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
var
->
nType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
var
->
nType
))
{
tbufWriteDouble
(
&
bw
,
(
double
)(
var
->
i64
));
}
else
if
(
var
->
nType
==
TSDB_DATA_TYPE_DOUBLE
||
var
->
nType
==
TSDB_DATA_TYPE_FLOAT
){
tbufWriteDouble
(
&
bw
,
var
->
dKey
);
}
else
{
tVariantDestroy
(
&
var
);
break
;
}
}
else
if
(
colType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
var
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
break
;
}
tbufWriteBinary
(
&
bw
,
var
->
pz
,
var
->
nLen
);
}
else
if
(
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
var
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
break
;
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_FLOAT
)
{
tbufWriteDouble
(
&
bw
,
var
.
dKey
);
}
else
if
(
type
==
TSDB_DATA_TYPE_BINARY
){
tbufWriteBinary
(
&
bw
,
var
.
pz
,
var
.
nLen
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
buf
=
(
char
*
)
calloc
(
1
,
(
var
.
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
if
(
tVariantDump
(
&
var
,
buf
,
type
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
char
*
buf
=
(
char
*
)
calloc
(
1
,
(
var
->
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
if
(
tVariantDump
(
var
,
buf
,
colType
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
free
(
buf
);
tVariantDestroy
(
&
var
);
break
;
}
tbufWriteBinary
(
&
bw
,
buf
,
twcslen
((
wchar_t
*
)
buf
)
*
TSDB_NCHAR_SIZE
);
free
(
buf
);
}
else
if
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
var
.
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
convertTimestampStrToInt64
(
&
var
,
precision
)
<
0
)
{
tVariantDestroy
(
&
var
);
}
else
if
(
colType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
var
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
convertTimestampStrToInt64
(
var
,
precision
)
<
0
)
{
break
;
}
tbufWriteInt64
(
&
bw
,
var
.
i64
);
}
else
if
(
var
.
nType
==
TSDB_DATA_TYPE_BIGINT
)
{
tbufWriteInt64
(
&
bw
,
var
.
i64
);
tbufWriteInt64
(
&
bw
,
var
->
i64
);
}
else
if
(
var
->
nType
==
TSDB_DATA_TYPE_BIGINT
)
{
tbufWriteInt64
(
&
bw
,
var
->
i64
);
}
else
{
break
;
}
}
else
{
break
;
}
tVariantDestroy
(
&
var
);
if
(
i
==
size
-
1
)
{
ret
=
true
;}
if
(
i
==
(
int32_t
)(
pList
->
size
-
1
))
{
ret
=
true
;}
}
if
(
ret
==
true
)
{
if
((
*
dst
=
calloc
(
1
,
sizeof
(
tVariant
)))
!=
NULL
)
{
tVariantCreateFromBinary
(
*
dst
,
tbufGetData
(
&
bw
,
false
),
tbufTell
(
&
bw
),
TSDB_DATA_TYPE_BINARY
);
...
...
@@ -239,13 +236,6 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType,
return
ret
;
}
static
int32_t
validateParamOfRelationIn
(
tVariant
*
pVar
,
int32_t
colType
)
{
if
(
pVar
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
return
-
1
;
}
SBufferReader
br
=
tbufInitReader
(
pVar
->
pz
,
pVar
->
nLen
,
false
);
return
colType
==
TSDB_DATA_TYPE_NCHAR
?
0
:
(
tbufReadUint32
(
&
br
)
==
colType
?
0
:
-
1
);
}
static
uint8_t
convertOptr
(
SStrToken
*
pToken
)
{
switch
(
pToken
->
type
)
{
...
...
@@ -3374,11 +3364,6 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
if
(
pRight
->
tokenId
!=
TK_SET
||
!
serializeExprListToVariant
(
pRight
->
pParam
,
&
pVal
,
colType
,
timePrecision
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
if
(
validateParamOfRelationIn
(
pVal
,
colType
)
!=
TSDB_CODE_SUCCESS
)
{
tVariantDestroy
(
pVal
);
free
(
pVal
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
pColumnFilter
->
pz
=
(
int64_t
)
calloc
(
1
,
pVal
->
nLen
+
1
);
pColumnFilter
->
len
=
pVal
->
nLen
;
pColumnFilter
->
filterstr
=
1
;
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
18bee12d
...
...
@@ -3364,7 +3364,7 @@ static bool tableFilterFp(const void* pNode, void* param) {
GET_TYPED_DATA
(
v
,
uint64_t
,
pInfo
->
sch
.
type
,
val
);
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pInfo
->
q
,
(
char
*
)
&
v
,
sizeof
(
v
));
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_
DOUBLE
)
{
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_
FLOAT
)
{
double
v
;
GET_TYPED_DATA
(
v
,
double
,
pInfo
->
sch
.
type
,
val
);
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pInfo
->
q
,
(
char
*
)
&
v
,
sizeof
(
v
));
...
...
tests/pytest/insert/in_function.py
浏览文件 @
18bee12d
...
...
@@ -698,24 +698,24 @@ class TDTestCase:
tdSql
.
execute
(
cmd1
)
cmd2
=
'select * from normal_in_float_double_1 where in_float in (
\'
888
\'
);'
tdLog
.
info
(
cmd2
)
tdSql
.
error
(
cmd2
)
try
:
tdSql
.
execute
(
cmd2
)
tdLog
.
exit
(
"invalid operation: not supported filter condition"
)
except
Exception
as
e
:
tdLog
.
info
(
repr
(
e
))
tdLog
.
info
(
"invalid operation: not supported filter condition"
)
cmd3
=
'select * from normal_in_float_double_1 where in_double in (
\'
66666
\'
);'
tdLog
.
info
(
cmd3
)
tdSql
.
error
(
cmd3
)
try
:
tdSql
.
execute
(
cmd3
)
tdLog
.
exit
(
"invalid operation: not supported filter condition"
)
except
Exception
as
e
:
tdLog
.
info
(
repr
(
e
))
tdLog
.
info
(
"invalid operation: not supported filter condition"
)
#
tdLog.info(cmd2)
#
tdSql.error(cmd2)
#
try:
#
tdSql.execute(cmd2)
#
tdLog.exit("invalid operation: not supported filter condition")
#
except Exception as e:
#
tdLog.info(repr(e))
#
tdLog.info("invalid operation: not supported filter condition")
#
#
cmd3 = 'select * from normal_in_float_double_1 where in_double in (\'66666\');'
#
tdLog.info(cmd3)
#
tdSql.error(cmd3)
#
try:
#
tdSql.execute(cmd3)
#
tdLog.exit("invalid operation: not supported filter condition")
#
except Exception as e:
#
tdLog.info(repr(e))
#
tdLog.info("invalid operation: not supported filter condition")
def
stop
(
self
):
tdSql
.
close
()
...
...
tests/script/general/parser/where.sim
浏览文件 @
18bee12d
...
...
@@ -139,18 +139,18 @@ sql_error select * from $mt where c1 like 1
sql create table wh_mt1 (ts timestamp, c1 smallint, c2 int, c3 bigint, c4 float, c5 double, c6 tinyint, c7 binary(10), c8 nchar(10), c9 bool, c10 timestamp) tags (t1 binary(10), t2 smallint, t3 int, t4 bigint, t5 float, t6 double)
sql create table wh_mt1_tb1 using wh_mt1 tags ('tb11', 1, 1, 1, 1, 1)
sql insert into wh_mt1_tb1 values (now, 1, 1, 1, 1, 1, 1, 'binary', 'nchar', true, '2019-01-01 00:00:00.000')
sql_error select last(*) from wh_mt1 where c1 in ('1')
sql_error select last(*) from wh_mt1_tb1 where c1 in ('1')
sql_error select last(*) from wh_mt1 where c2 in ('1')
sql_error select last(*) from wh_mt1_tb1 where c2 in ('1')
sql_error select last(*) from wh_mt1 where c3 in ('1')
sql_error select last(*) from wh_mt1_tb1 where c3 in ('1')
sql_error select last(*) from wh_mt1 where c4 in ('1')
sql_error select last(*) from wh_mt1_tb1 where c4 in ('1')
sql_error select last(*) from wh_mt1 where c5 in ('1')
sql_error select last(*) from wh_mt1_tb1 where c5 in ('1')
sql_error select last(*) from wh_mt1 where c6 in ('1')
sql_error select last(*) from wh_mt1_tb1 where c6 in ('1')
#
sql_error select last(*) from wh_mt1 where c1 in ('1')
#
sql_error select last(*) from wh_mt1_tb1 where c1 in ('1')
#
sql_error select last(*) from wh_mt1 where c2 in ('1')
#
sql_error select last(*) from wh_mt1_tb1 where c2 in ('1')
#
sql_error select last(*) from wh_mt1 where c3 in ('1')
#
sql_error select last(*) from wh_mt1_tb1 where c3 in ('1')
#
sql_error select last(*) from wh_mt1 where c4 in ('1')
#
sql_error select last(*) from wh_mt1_tb1 where c4 in ('1')
#
sql_error select last(*) from wh_mt1 where c5 in ('1')
#
sql_error select last(*) from wh_mt1_tb1 where c5 in ('1')
#
sql_error select last(*) from wh_mt1 where c6 in ('1')
#
sql_error select last(*) from wh_mt1_tb1 where c6 in ('1')
#sql_error select last(*) from wh_mt1 where c7 in ('binary')
#sql_error select last(*) from wh_mt1_tb1 where c7 in ('binary')
#sql_error select last(*) from wh_mt1 where c8 in ('nchar')
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录