Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a1627c5d
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看板
提交
a1627c5d
编写于
6月 18, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support like
上级
ea497d38
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
1183 addition
and
127 deletion
+1183
-127
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+35
-68
src/client/src/tscServer.c
src/client/src/tscServer.c
+3
-2
src/kit/shell/src/shellEngine.c
src/kit/shell/src/shellEngine.c
+1
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+3
-1
src/query/src/qFilter.c
src/query/src/qFilter.c
+13
-3
tests/script/general/parser/condition.sim
tests/script/general/parser/condition.sim
+1128
-52
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
a1627c5d
...
...
@@ -185,10 +185,12 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType)
break
;
}
uint32_t
tType
=
pSub
->
token
.
type
;
toTSDBType
(
pSub
->
token
.
type
);
tVariant
var
;
tVariantCreate
(
&
var
,
&
pSub
->
token
);
pSub
->
token
.
type
=
tType
;
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_SMALLINT
||
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_INT
)
{
tbufWriteInt64
(
&
bw
,
var
.
i64
);
...
...
@@ -3465,44 +3467,28 @@ enum {
TSQL_EXPR_TBNAME
=
8
,
};
static
int32_t
extract
ColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
,
tSqlExpr
*
pExpr
,
int32_t
sqlOptr
)
{
static
int32_t
check
ColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
,
tSqlExpr
*
pExpr
,
int32_t
sqlOptr
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
pIndex
->
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
pIndex
->
columnIndex
);
int32_t
ret
=
0
;
const
char
*
msg1
=
"non binary column not support like operator"
;
const
char
*
msg2
=
"binary column not support this operator"
;
const
char
*
msg3
=
"bool column not support this operator"
;
SColumn
*
pColumn
=
tscColumnListInsert
(
pQueryInfo
->
colList
,
pIndex
->
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
SColumnFilterInfo
*
pColFilter
=
NULL
;
/*
* in case of TK_AND filter condition, we first find the corresponding column and build the query condition together
* the already existed condition.
*/
if
(
sqlOptr
==
TK_AND
)
{
// this is a new filter condition on this column
if
(
pColumn
->
info
.
flist
.
numOfFilters
==
0
)
{
pColFilter
=
addColumnFilterInfo
(
&
pColumn
->
info
.
flist
);
}
else
{
// update the existed column filter information, find the filter info here
pColFilter
=
&
pColumn
->
info
.
flist
.
filterInfo
[
0
];
}
if
(
pColFilter
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
else
if
(
sqlOptr
==
TK_OR
)
{
// TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2"
pColFilter
=
addColumnFilterInfo
(
&
pColumn
->
info
.
flist
);
if
(
pColFilter
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
else
{
// error;
if
(
sqlOptr
!=
TK_AND
&&
sqlOptr
!=
TK_OR
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
SColumnFilterInfo
*
pColFilter
=
calloc
(
1
,
sizeof
(
SColumnFilterInfo
));
pColFilter
->
filterstr
=
((
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
?
1
:
0
);
...
...
@@ -3513,17 +3499,20 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
&&
pExpr
->
tokenId
!=
TK_NOTNULL
&&
pExpr
->
tokenId
!=
TK_LIKE
&&
pExpr
->
tokenId
!=
TK_IN
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
ret
=
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
goto
_err_ret
;
}
}
else
{
if
(
pExpr
->
tokenId
==
TK_LIKE
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
ret
=
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
goto
_err_ret
;
}
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BOOL
)
{
int32_t
t
=
pExpr
->
tokenId
;
if
(
t
!=
TK_EQ
&&
t
!=
TK_NE
&&
t
!=
TK_NOTNULL
&&
t
!=
TK_ISNULL
&&
t
!=
TK_IN
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
ret
=
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
goto
_err_ret
;
}
}
}
...
...
@@ -3532,7 +3521,12 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
pColumn
->
tableUid
=
pTableMeta
->
id
.
uid
;
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
tinfo
.
precision
,
pColFilter
,
pSchema
->
type
,
pExpr
);
ret
=
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
tinfo
.
precision
,
pColFilter
,
pSchema
->
type
,
pExpr
);
_err_ret:
freeColumnFilterInfo
(
pColFilter
,
1
);
return
ret
;
}
static
int32_t
getTablenameCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pTableCond
,
SStringBuilder
*
sb
)
{
...
...
@@ -3626,25 +3620,25 @@ static int32_t getColQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlEx
}
static
int32_t
get
ColumnQueryCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pExpr
,
int32_t
relOptr
)
{
static
int32_t
check
ColumnQueryCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pExpr
,
int32_t
relOptr
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
!
tSqlExprIsParentOfLeaf
(
pExpr
))
{
// internal node
int32_t
ret
=
get
ColumnQueryCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pLeft
,
pExpr
->
tokenId
);
int32_t
ret
=
check
ColumnQueryCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pLeft
,
pExpr
->
tokenId
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
return
get
ColumnQueryCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
,
pExpr
->
tokenId
);
return
check
ColumnQueryCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
,
pExpr
->
tokenId
);
}
else
{
// handle leaf node
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
pCmd
,
&
pExpr
->
pLeft
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
return
extract
ColumnFilterInfo
(
pCmd
,
pQueryInfo
,
&
index
,
pExpr
,
relOptr
);
return
check
ColumnFilterInfo
(
pCmd
,
pQueryInfo
,
&
index
,
pExpr
,
relOptr
);
}
}
...
...
@@ -4050,7 +4044,7 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) {
// check for like expression
static
int32_t
validateLikeExpr
(
tSqlExpr
*
pExpr
,
STableMeta
*
pTableMeta
,
int32_t
index
,
char
*
msgBuf
)
{
const
char
*
msg1
=
"wildcard string should be less than 20 characters"
;
const
char
*
msg2
=
"illegal column
nam
e"
;
const
char
*
msg2
=
"illegal column
type for lik
e"
;
tSqlExpr
*
pLeft
=
pExpr
->
pLeft
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
...
...
@@ -4433,36 +4427,9 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
return
TSDB_CODE_SUCCESS
;
}
static
bool
validateFilterExpr
(
SQueryInfo
*
pQueryInfo
)
{
SArray
*
pColList
=
pQueryInfo
->
colList
;
size_t
num
=
taosArrayGetSize
(
pColList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SColumn
*
pCol
=
taosArrayGetP
(
pColList
,
i
);
for
(
int32_t
j
=
0
;
j
<
pCol
->
info
.
flist
.
numOfFilters
;
++
j
)
{
SColumnFilterInfo
*
pColFilter
=
&
pCol
->
info
.
flist
.
filterInfo
[
j
];
int32_t
lowerOptr
=
pColFilter
->
lowerRelOptr
;
int32_t
upperOptr
=
pColFilter
->
upperRelOptr
;
if
((
lowerOptr
==
TSDB_RELATION_GREATER_EQUAL
||
lowerOptr
==
TSDB_RELATION_GREATER
)
&&
(
upperOptr
==
TSDB_RELATION_LESS_EQUAL
||
upperOptr
==
TSDB_RELATION_LESS
))
{
continue
;
}
// there must be at least two range, not support yet.
if
(
lowerOptr
*
upperOptr
!=
TSDB_RELATION_INVALID
)
{
return
false
;
}
}
}
return
true
;
}
static
int32_t
getTimeRangeFromExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pExpr
)
{
const
char
*
msg0
=
"invalid timestamp"
;
const
char
*
msg0
=
"invalid timestamp
or operator for timestamp
"
;
const
char
*
msg1
=
"only one time stamp window allowed"
;
int32_t
code
=
0
;
...
...
@@ -4844,7 +4811,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq
}
const
char
*
msg1
=
"invalid expression"
;
const
char
*
msg2
=
"invalid filter expression"
;
//
const char* msg2 = "invalid filter expression";
int32_t
ret
=
TSDB_CODE_SUCCESS
;
...
...
@@ -4887,16 +4854,16 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq
goto
PARSE_WHERE_EXIT
;
}
if
((
ret
=
getColQueryCondExpr
(
&
pSql
->
cmd
,
pQueryInfo
,
&
condExpr
.
pColumnCond
))
!=
TSDB_CODE_SUCCESS
)
{
// 5. other column query condition
if
((
ret
=
checkColumnQueryCondInfo
(
&
pSql
->
cmd
,
pQueryInfo
,
condExpr
.
pColumnCond
,
TK_AND
))
!=
TSDB_CODE_SUCCESS
)
{
goto
PARSE_WHERE_EXIT
;
}
// 5. other column query condition
if
((
ret
=
getColumnQueryCondInfo
(
&
pSql
->
cmd
,
pQueryInfo
,
condExpr
.
pColumnCond
,
TK_AND
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
ret
=
getColQueryCondExpr
(
&
pSql
->
cmd
,
pQueryInfo
,
&
condExpr
.
pColumnCond
))
!=
TSDB_CODE_SUCCESS
)
{
goto
PARSE_WHERE_EXIT
;
}
// 6. join condition
if
((
ret
=
getJoinCondInfo
(
&
pSql
->
cmd
,
pQueryInfo
,
condExpr
.
pJoinExpr
))
!=
TSDB_CODE_SUCCESS
)
{
goto
PARSE_WHERE_EXIT
;
...
...
@@ -4911,10 +4878,10 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq
goto
PARSE_WHERE_EXIT
;
}
if
(
!
validateFilterExpr
(
pQueryInfo
))
{
ret
=
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
pSql
->
cmd
),
msg2
);
goto
PARSE_WHERE_EXIT
;
}
//
if (!validateFilterExpr(pQueryInfo)) {
//
ret = invalidOperationMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2);
//
goto PARSE_WHERE_EXIT;
//
}
//doAddJoinTagsColumnsIntoTagList(&pSql->cmd, pQueryInfo, &condExpr);
if
(
condExpr
.
tsJoin
)
{
...
...
@@ -4945,7 +4912,7 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t
* filter primary ts filter expression like:
* where ts in ('2015-12-12 4:8:12')
*/
if
(
pRight
->
tokenId
==
TK_SET
||
optr
==
TK_IN
)
{
if
(
pRight
->
tokenId
==
TK_SET
||
optr
==
TK_IN
||
optr
==
TK_NE
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
a1627c5d
...
...
@@ -882,10 +882,11 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tableCols
[
i
].
colId
=
htons
(
pCol
->
colId
);
pQueryMsg
->
tableCols
[
i
].
bytes
=
htons
(
pCol
->
bytes
);
pQueryMsg
->
tableCols
[
i
].
type
=
htons
(
pCol
->
type
);
pQueryMsg
->
tableCols
[
i
].
flist
.
numOfFilters
=
htons
(
pCol
->
flist
.
numOfFilters
);
//pQueryMsg->tableCols[i].flist.numOfFilters = htons(pCol->flist.numOfFilters);
pQueryMsg
->
tableCols
[
i
].
flist
.
numOfFilters
=
0
;
// append the filter information after the basic column information
serializeColFilterInfo
(
pCol
->
flist
.
filterInfo
,
pCol
->
flist
.
numOfFilters
,
&
pMsg
);
//
serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg);
}
if
(
pQueryInfo
->
colCond
&&
taosArrayGetSize
(
pQueryInfo
->
colCond
)
>
0
)
{
...
...
src/kit/shell/src/shellEngine.c
浏览文件 @
a1627c5d
...
...
@@ -248,7 +248,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
if
(
quote
==
c
)
{
quote
=
0
;
}
else
if
(
c
==
'\''
||
c
==
'"'
)
{
}
else
if
(
quote
==
0
&&
(
c
==
'\''
||
c
==
'"'
)
)
{
quote
=
c
;
}
...
...
src/query/src/qExecutor.c
浏览文件 @
a1627c5d
...
...
@@ -6445,7 +6445,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
pColInfo
->
colId
=
htons
(
pColInfo
->
colId
);
pColInfo
->
type
=
htons
(
pColInfo
->
type
);
pColInfo
->
bytes
=
htons
(
pColInfo
->
bytes
);
pColInfo
->
flist
.
numOfFilters
=
htons
(
pColInfo
->
flist
.
numOfFilters
)
;
pColInfo
->
flist
.
numOfFilters
=
0
;
if
(
!
isValidDataType
(
pColInfo
->
type
))
{
qDebug
(
"qmsg:%p, invalid data type in source column, index:%d, type:%d"
,
pQueryMsg
,
col
,
pColInfo
->
type
);
...
...
@@ -6453,6 +6453,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
goto
_cleanup
;
}
/*
int32_t numOfFilters = pColInfo->flist.numOfFilters;
if (numOfFilters > 0) {
pColInfo->flist.filterInfo = calloc(numOfFilters, sizeof(SColumnFilterInfo));
...
...
@@ -6466,6 +6467,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
if (code != TSDB_CODE_SUCCESS) {
goto _cleanup;
}
*/
}
if
(
pQueryMsg
->
colCondLen
>
0
)
{
...
...
src/query/src/qFilter.c
浏览文件 @
a1627c5d
...
...
@@ -334,7 +334,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) {
fi
->
data
=
calloc
(
1
,
sizeof
(
int64_t
));
}
ERR_LRET
(
tVariantDump
(
var
,
(
char
*
)
fi
->
data
,
type
,
fals
e
),
"dump type[%d] failed"
,
type
);
ERR_LRET
(
tVariantDump
(
var
,
(
char
*
)
fi
->
data
,
type
,
tru
e
),
"dump type[%d] failed"
,
type
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -402,8 +402,18 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) {
SFilterField
*
left
=
FILTER_GET_FIELD
(
info
,
unit
->
left
);
SFilterField
*
right
=
FILTER_GET_FIELD
(
info
,
unit
->
right
);
ures
=
filterDoCompare
(
unit
,
FILTER_GET_COL_FIELD_DATA
(
left
,
i
),
FILTER_GET_VAL_FIELD_DATA
(
right
));
if
(
isNull
(
FILTER_GET_COL_FIELD_DATA
(
left
,
i
),
FILTER_GET_COL_FIELD_TYPE
(
left
)))
{
ures
=
unit
->
compare
.
optr
==
TSDB_RELATION_ISNULL
?
true
:
false
;
}
else
{
if
(
unit
->
compare
.
optr
==
TSDB_RELATION_NOTNULL
)
{
ures
=
true
;
}
else
if
(
unit
->
compare
.
optr
==
TSDB_RELATION_ISNULL
)
{
ures
=
false
;
}
else
{
ures
=
filterDoCompare
(
unit
,
FILTER_GET_COL_FIELD_DATA
(
left
,
i
),
FILTER_GET_VAL_FIELD_DATA
(
right
));
}
}
FILTER_UNIT_SET_R
(
info
,
uidx
,
ures
);
FILTER_UNIT_SET_F
(
info
,
uidx
);
}
...
...
tests/script/general/parser/condition.sim
浏览文件 @
a1627c5d
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录