Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1f54d6aa
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看板
提交
1f54d6aa
编写于
8月 23, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6145]<feature>:support tag filtering with regex
上级
03c9253d
变更
14
展开全部
显示空白变更内容
内联
并排
Showing
14 changed file
with
887 addition
and
1204 deletion
+887
-1204
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+111
-53
src/common/inc/texpr.h
src/common/inc/texpr.h
+2
-0
src/common/inc/tglobal.h
src/common/inc/tglobal.h
+1
-0
src/common/src/texpr.c
src/common/src/texpr.c
+11
-0
src/common/src/tglobal.c
src/common/src/tglobal.c
+1
-0
src/inc/taosdef.h
src/inc/taosdef.h
+2
-0
src/inc/ttokendef.h
src/inc/ttokendef.h
+153
-153
src/query/inc/sql.y
src/query/inc/sql.y
+4
-1
src/query/src/qFilter.c
src/query/src/qFilter.c
+12
-4
src/query/src/sql.c
src/query/src/sql.c
+533
-987
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+8
-2
src/util/inc/tcompare.h
src/util/inc/tcompare.h
+2
-0
src/util/src/tcompare.c
src/util/src/tcompare.c
+46
-4
src/util/src/ttokenizer.c
src/util/src/ttokenizer.c
+1
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
1f54d6aa
...
...
@@ -279,6 +279,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) {
return
TSDB_BINARY_OP_REMAINDER
;
case
TK_LIKE
:
return
TSDB_RELATION_LIKE
;
case
TK_MATCH
:
return
TSDB_RELATION_MATCH
;
case
TK_ISNULL
:
return
TSDB_RELATION_ISNULL
;
case
TK_NOTNULL
:
...
...
@@ -3788,6 +3790,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
case
TK_LIKE
:
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_LIKE
;
break
;
case
TK_MATCH
:
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_MATCH
;
break
;
case
TK_ISNULL
:
pColumnFilter
->
lowerRelOptr
=
TSDB_RELATION_ISNULL
;
break
;
...
...
@@ -3851,9 +3856,15 @@ static int32_t tablenameListToString(tSqlExpr* pExpr, SStringBuilder* sb) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tablenameCondToString
(
tSqlExpr
*
pExpr
,
SStringBuilder
*
sb
)
{
static
int32_t
tablenameCondToString
(
tSqlExpr
*
pExpr
,
uint32_t
opToken
,
SStringBuilder
*
sb
)
{
assert
(
opToken
==
TK_LIKE
||
opToken
==
TK_MATCH
);
if
(
opToken
==
TK_LIKE
)
{
taosStringBuilderAppendStringLen
(
sb
,
QUERY_COND_REL_PREFIX_LIKE
,
QUERY_COND_REL_PREFIX_LIKE_LEN
);
taosStringBuilderAppendString
(
sb
,
pExpr
->
value
.
pz
);
}
else
if
(
opToken
==
TK_MATCH
)
{
taosStringBuilderAppendStringLen
(
sb
,
QUERY_COND_REL_PREFIX_MATCH
,
QUERY_COND_REL_PREFIX_MATCH_LEN
);
taosStringBuilderAppendString
(
sb
,
pExpr
->
value
.
pz
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3874,7 +3885,7 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol
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
*
msg1
=
"non binary column not support like
/match
operator"
;
const
char
*
msg2
=
"binary column not support this operator"
;
const
char
*
msg3
=
"bool column not support this operator"
;
const
char
*
msg4
=
"primary key not support this operator"
;
...
...
@@ -3902,12 +3913,13 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol
&&
pExpr
->
tokenId
!=
TK_ISNULL
&&
pExpr
->
tokenId
!=
TK_NOTNULL
&&
pExpr
->
tokenId
!=
TK_LIKE
&&
pExpr
->
tokenId
!=
TK_MATCH
&&
pExpr
->
tokenId
!=
TK_IN
)
{
ret
=
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
goto
_err_ret
;
}
}
else
{
if
(
pExpr
->
tokenId
==
TK_LIKE
)
{
if
(
pExpr
->
tokenId
==
TK_LIKE
||
pExpr
->
tokenId
==
TK_MATCH
)
{
ret
=
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
goto
_err_ret
;
}
...
...
@@ -3955,12 +3967,12 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
if
(
pTableCond
->
tokenId
==
TK_IN
)
{
ret
=
tablenameListToString
(
pRight
,
sb
);
}
else
if
(
pTableCond
->
tokenId
==
TK_LIKE
)
{
}
else
if
(
pTableCond
->
tokenId
==
TK_LIKE
||
pTableCond
->
tokenId
==
TK_MATCH
)
{
if
(
pRight
->
tokenId
!=
TK_STRING
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
ret
=
tablenameCondToString
(
pRight
,
sb
);
ret
=
tablenameCondToString
(
pRight
,
pTableCond
->
tokenId
,
sb
);
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -4409,7 +4421,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
}
static
bool
validTableNameOptr
(
tSqlExpr
*
pExpr
)
{
const
char
nameFilterOptr
[]
=
{
TK_IN
,
TK_LIKE
};
const
char
nameFilterOptr
[]
=
{
TK_IN
,
TK_LIKE
,
TK_MATCH
};
for
(
int32_t
i
=
0
;
i
<
tListLen
(
nameFilterOptr
);
++
i
)
{
if
(
pExpr
->
tokenId
==
nameFilterOptr
[
i
])
{
...
...
@@ -4501,6 +4513,44 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t
return
TSDB_CODE_SUCCESS
;
}
// check for match expression
static
int32_t
validateMatchExpr
(
tSqlExpr
*
pExpr
,
STableMeta
*
pTableMeta
,
int32_t
index
,
char
*
msgBuf
)
{
const
char
*
msg1
=
"regular expression string should be less than %d characters"
;
const
char
*
msg2
=
"illegal column type for match"
;
const
char
*
msg3
=
"invalid regular expression"
;
tSqlExpr
*
pLeft
=
pExpr
->
pLeft
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pExpr
->
tokenId
==
TK_MATCH
)
{
if
(
pRight
->
value
.
nLen
>
tsMaxRegexStringLen
)
{
char
tmp
[
64
]
=
{
0
};
sprintf
(
tmp
,
msg1
,
tsMaxRegexStringLen
);
return
invalidOperationMsg
(
msgBuf
,
tmp
);
}
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
if
((
!
isTablenameToken
(
&
pLeft
->
columnName
))
&&
!
IS_VAR_DATA_TYPE
(
pSchema
[
index
].
type
))
{
return
invalidOperationMsg
(
msgBuf
,
msg2
);
}
int
errCode
=
0
;
regex_t
regex
;
char
regErrBuf
[
256
]
=
{
0
};
const
char
*
pattern
=
pRight
->
value
.
pz
;
int
cflags
=
REG_EXTENDED
|
REG_ICASE
;
if
((
errCode
=
regcomp
(
&
regex
,
pattern
,
cflags
))
!=
0
)
{
regerror
(
errCode
,
&
regex
,
regErrBuf
,
sizeof
(
regErrBuf
));
tscError
(
"Failed to compile regex pattern %s. reason %s"
,
pattern
,
regErrBuf
);
return
invalidOperationMsg
(
msgBuf
,
msg3
);
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
handleNeOptr
(
tSqlExpr
**
rexpr
,
tSqlExpr
*
expr
)
{
tSqlExpr
*
left
=
tSqlExprClone
(
expr
);
tSqlExpr
*
right
=
expr
;
...
...
@@ -4552,6 +4602,12 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
return
code
;
}
// validate the match expression
code
=
validateMatchExpr
(
*
pExpr
,
pTableMeta
,
index
.
columnIndex
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
&&
index
.
columnIndex
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
// query on time range
if
(
!
validateJoinExprNode
(
pCmd
,
pQueryInfo
,
*
pExpr
,
&
index
))
{
...
...
@@ -4879,16 +4935,16 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
STagCond
*
pTagCond
=
&
pQueryInfo
->
tagCond
;
pTagCond
->
tbnameCond
.
uid
=
pTableMetaInfo
->
pTableMeta
->
id
.
uid
;
assert
(
pExpr
->
tokenId
==
TK_LIKE
||
pExpr
->
tokenId
==
TK_IN
);
assert
(
pExpr
->
tokenId
==
TK_LIKE
||
pExpr
->
tokenId
==
TK_
MATCH
||
pExpr
->
tokenId
==
TK_
IN
);
if
(
pExpr
->
tokenId
==
TK_LIKE
)
{
if
(
pExpr
->
tokenId
==
TK_LIKE
||
pExpr
->
tokenId
==
TK_MATCH
)
{
char
*
str
=
taosStringBuilderGetResult
(
sb
,
NULL
);
pQueryInfo
->
tagCond
.
tbnameCond
.
cond
=
strdup
(
str
);
pQueryInfo
->
tagCond
.
tbnameCond
.
len
=
(
int32_t
)
strlen
(
str
);
return
TSDB_CODE_SUCCESS
;
}
SStringBuilder
sb1
;
memset
(
&
sb1
,
0
,
sizeof
(
sb1
));
}
else
{
SStringBuilder
sb1
;
memset
(
&
sb1
,
0
,
sizeof
(
sb1
));
taosStringBuilderAppendStringLen
(
&
sb1
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
);
// remove the duplicated input table names
...
...
@@ -4908,7 +4964,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
char
name
[
TSDB_DB_NAME_LEN
]
=
{
0
};
tNameGetDbName
(
&
pTableMetaInfo
->
name
,
name
);
SStrToken
dbToken
=
{
.
type
=
TK_STRING
,
.
z
=
name
,
.
n
=
(
uint32_t
)
strlen
(
name
)
};
SStrToken
dbToken
=
{.
type
=
TK_STRING
,
.
z
=
name
,
.
n
=
(
uint32_t
)
strlen
(
name
)
};
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
if
(
i
>=
1
)
{
...
...
@@ -4933,11 +4989,12 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
char
*
str
=
taosStringBuilderGetResult
(
&
sb1
,
NULL
);
pQueryInfo
->
tagCond
.
tbnameCond
.
cond
=
strdup
(
str
);
pQueryInfo
->
tagCond
.
tbnameCond
.
len
=
(
int32_t
)
strlen
(
str
);
pQueryInfo
->
tagCond
.
tbnameCond
.
len
=
(
int32_t
)
strlen
(
str
);
taosStringBuilderDestroy
(
&
sb1
);
tfree
(
segments
);
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
mergeTimeRange
(
SSqlCmd
*
pCmd
,
STimeWindow
*
res
,
STimeWindow
*
win
,
int32_t
optr
)
{
...
...
@@ -8114,7 +8171,7 @@ int32_t tscGetExprFilters(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelect
}
static
int32_t
handleExprInHavingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelectNodeList
,
tSqlExpr
*
pExpr
,
int32_t
sqlOptr
)
{
const
char
*
msg1
=
"non binary column not support like operator"
;
const
char
*
msg1
=
"non binary column not support like
/match
operator"
;
const
char
*
msg2
=
"invalid operator for binary column in having clause"
;
const
char
*
msg3
=
"invalid operator for bool column in having clause"
;
...
...
@@ -8166,11 +8223,12 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, S
&&
pExpr
->
tokenId
!=
TK_ISNULL
&&
pExpr
->
tokenId
!=
TK_NOTNULL
&&
pExpr
->
tokenId
!=
TK_LIKE
&&
pExpr
->
tokenId
!=
TK_MATCH
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
else
{
if
(
pExpr
->
tokenId
==
TK_LIKE
)
{
if
(
pExpr
->
tokenId
==
TK_LIKE
||
pExpr
->
tokenId
==
TK_MATCH
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
src/common/inc/texpr.h
浏览文件 @
1f54d6aa
...
...
@@ -33,9 +33,11 @@ struct SSchema;
#define QUERY_COND_REL_PREFIX_IN "IN|"
#define QUERY_COND_REL_PREFIX_LIKE "LIKE|"
#define QUERY_COND_REL_PREFIX_MATCH "MATCH|"
#define QUERY_COND_REL_PREFIX_IN_LEN 3
#define QUERY_COND_REL_PREFIX_LIKE_LEN 5
#define QUERY_COND_REL_PREFIX_MATCH_LEN 6
typedef
bool
(
*
__result_filter_fn_t
)(
const
void
*
,
void
*
);
typedef
void
(
*
__do_filter_suppl_fn_t
)(
void
*
,
void
*
);
...
...
src/common/inc/tglobal.h
浏览文件 @
1f54d6aa
...
...
@@ -74,6 +74,7 @@ extern int8_t tsKeepOriginalColumnName;
// client
extern
int32_t
tsMaxSQLStringLen
;
extern
int32_t
tsMaxWildCardsLen
;
extern
int32_t
tsMaxRegexStringLen
;
extern
int8_t
tsTscEnableRecordSql
;
extern
int32_t
tsMaxNumOfOrderedResults
;
extern
int32_t
tsMinSlidingTime
;
...
...
src/common/src/texpr.c
浏览文件 @
1f54d6aa
...
...
@@ -430,6 +430,17 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
pVal
->
nType
=
TSDB_DATA_TYPE_BINARY
;
pVal
->
nLen
=
(
int32_t
)
len
;
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_MATCH
,
QUERY_COND_REL_PREFIX_MATCH_LEN
)
==
0
)
{
right
->
nodeType
=
TSQL_NODE_VALUE
;
expr
->
_node
.
optr
=
TSDB_RELATION_MATCH
;
tVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
tVariant
));
right
->
pVal
=
pVal
;
size_t
len
=
strlen
(
tbnameCond
+
QUERY_COND_REL_PREFIX_MATCH_LEN
)
+
1
;
pVal
->
pz
=
exception_malloc
(
len
);
memcpy
(
pVal
->
pz
,
tbnameCond
+
QUERY_COND_REL_PREFIX_MATCH_LEN
,
len
);
pVal
->
nType
=
TSDB_DATA_TYPE_BINARY
;
pVal
->
nLen
=
(
int32_t
)
len
;
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
)
==
0
)
{
right
->
nodeType
=
TSQL_NODE_VALUE
;
expr
->
_node
.
optr
=
TSDB_RELATION_IN
;
...
...
src/common/src/tglobal.c
浏览文件 @
1f54d6aa
...
...
@@ -85,6 +85,7 @@ int32_t tsCompressColData = -1;
// client
int32_t
tsMaxSQLStringLen
=
TSDB_MAX_ALLOWED_SQL_LEN
;
int32_t
tsMaxWildCardsLen
=
TSDB_PATTERN_STRING_MAX_LEN
;
int32_t
tsMaxRegexStringLen
=
TSDB_REGEX_STRING_MAX_LEN
;
int8_t
tsTscEnableRecordSql
=
0
;
// the maximum number of results for projection query on super table that are returned from
...
...
src/inc/taosdef.h
浏览文件 @
1f54d6aa
...
...
@@ -164,6 +164,8 @@ do { \
#define TSDB_RELATION_OR 12
#define TSDB_RELATION_NOT 13
#define TSDB_RELATION_MATCH 14
#define TSDB_BINARY_OP_ADD 30
#define TSDB_BINARY_OP_SUBTRACT 31
#define TSDB_BINARY_OP_MULTIPLY 32
...
...
src/inc/ttokendef.h
浏览文件 @
1f54d6aa
...
...
@@ -37,159 +37,159 @@
#define TK_NOTNULL 19
#define TK_IS 20
#define TK_LIKE 21
#define TK_
GLOB
22
#define TK_
BETWEEN
23
#define TK_
IN
24
#define TK_
GT
25
#define TK_G
E
26
#define TK_
LT
27
#define TK_L
E
28
#define TK_
BITAND
29
#define TK_BIT
OR
30
#define TK_
LSHIFT
31
#define TK_
R
SHIFT 32
#define TK_
PLUS
33
#define TK_
MINUS
34
#define TK_
DIVIDE
35
#define TK_
TIMES
36
#define TK_
STAR
37
#define TK_S
LASH
38
#define TK_
REM
39
#define TK_
CONCAT
40
#define TK_
UMINUS
41
#define TK_U
PLUS
42
#define TK_
BITNOT
43
#define TK_
SHOW
44
#define TK_
DATABASES
45
#define TK_
TOPICS
46
#define TK_
FUNCTIONS
47
#define TK_
MNODES
48
#define TK_
D
NODES 49
#define TK_
ACCOUNTS
50
#define TK_
USERS
51
#define TK_
MODULES
52
#define TK_
QUERI
ES 53
#define TK_
CONNECTIONS
54
#define TK_
STREAMS
55
#define TK_
VARIABLES
56
#define TK_
SCORES
57
#define TK_
GRANT
S 58
#define TK_
VNODE
S 59
#define TK_
DOT
60
#define TK_
CREATE
61
#define TK_
TABLE
62
#define TK_
STABLE
63
#define TK_
DATABASE
64
#define TK_
TABLES
65
#define TK_
STABLES
66
#define TK_
VGROUP
S 67
#define TK_
DROP
68
#define TK_
TOPIC
69
#define TK_
FUNCTION
70
#define TK_
DNODE
71
#define TK_
USER
72
#define TK_
ACCOUNT
73
#define TK_
USE
74
#define TK_
DESCRIBE
75
#define TK_
ALTER
76
#define TK_
PASS
77
#define TK_P
RIVILEGE
78
#define TK_
LOCAL
79
#define TK_
COMPACT
80
#define TK_
LP
81
#define TK_
R
P 82
#define TK_
IF
83
#define TK_
EXISTS
84
#define TK_
AS
85
#define TK_
OUTPUTTYPE
86
#define TK_
AGGREGATE
87
#define TK_
BUFSIZE
88
#define TK_
PPS
89
#define TK_
TSERIES
90
#define TK_
DBS
91
#define TK_
STORAGE
92
#define TK_
QTIME
93
#define TK_
CONNS
94
#define TK_
STATE
95
#define TK_
COMMA
96
#define TK_
KEEP
97
#define TK_
CACHE
98
#define TK_
REPLICA
99
#define TK_
QUORUM
100
#define TK_
DAYS
101
#define TK_
MINROWS
102
#define TK_M
AX
ROWS 103
#define TK_
BLOCKS
104
#define TK_
CTIME
105
#define TK_
WAL
106
#define TK_
FSYNC
107
#define TK_
COMP
108
#define TK_
PRECISION
109
#define TK_
UPDATE
110
#define TK_
CACHELAST
111
#define TK_
PARTITIONS
112
#define TK_
UNSIGNED
113
#define TK_
TAGS
114
#define TK_
USING
115
#define TK_
NULL
116
#define TK_N
OW
117
#define TK_
SELECT
118
#define TK_
UNION
119
#define TK_
ALL
120
#define TK_
DISTINCT
121
#define TK_
FROM
122
#define TK_
VARIABLE
123
#define TK_
INTERVAL
124
#define TK_
SESSION
125
#define TK_S
TATE_WINDOW
126
#define TK_
FILL
127
#define TK_
SLIDING
128
#define TK_
ORDER
129
#define TK_
BY
130
#define TK_
ASC
131
#define TK_
DESC
132
#define TK_
GROUP
133
#define TK_
HAVING
134
#define TK_
LIMIT
135
#define TK_
OFFSET
136
#define TK_
SLIMI
T 137
#define TK_S
OFFSET
138
#define TK_
WHERE
139
#define TK_
RESET
140
#define TK_
QUERY
141
#define TK_
SYNCDB
142
#define TK_
ADD
143
#define TK_
COLUMN
144
#define TK_
MODIFY
145
#define TK_
TAG
146
#define TK_
CHANGE
147
#define TK_
SET
148
#define TK_
KILL
149
#define TK_
CONNECTION
150
#define TK_
STREAM
151
#define TK_
COLON
152
#define TK_
ABORT
153
#define TK_A
FTER
154
#define TK_A
TTACH
155
#define TK_
BEFORE
156
#define TK_BE
GIN
157
#define TK_
CASCADE
158
#define TK_C
LUSTER
159
#define TK_C
ONFLICT
160
#define TK_CO
PY
161
#define TK_
DEFERRED
162
#define TK_DE
LIMITERS
163
#define TK_DE
TACH
164
#define TK_
EACH
165
#define TK_E
ND
166
#define TK_E
XPLAIN
167
#define TK_
FAIL
168
#define TK_F
OR
169
#define TK_
IGNORE
170
#define TK_I
MMEDIATE
171
#define TK_I
NITIALLY
172
#define TK_IN
STEAD
173
#define TK_
MATCH
174
#define TK_
MATCH
22
#define TK_
GLOB
23
#define TK_
BETWEEN
24
#define TK_
IN
25
#define TK_G
T
26
#define TK_
GE
27
#define TK_L
T
28
#define TK_
LE
29
#define TK_BIT
AND
30
#define TK_
BITOR
31
#define TK_
L
SHIFT 32
#define TK_
RSHIFT
33
#define TK_
PLUS
34
#define TK_
MINUS
35
#define TK_
DIVIDE
36
#define TK_
TIMES
37
#define TK_S
TAR
38
#define TK_
SLASH
39
#define TK_
REM
40
#define TK_
CONCAT
41
#define TK_U
MINUS
42
#define TK_
UPLUS
43
#define TK_
BITNOT
44
#define TK_
SHOW
45
#define TK_
DATABASES
46
#define TK_
TOPICS
47
#define TK_
FUNCTIONS
48
#define TK_
M
NODES 49
#define TK_
DNODES
50
#define TK_
ACCOUNTS
51
#define TK_
USERS
52
#define TK_
MODUL
ES 53
#define TK_
QUERIES
54
#define TK_
CONNECTIONS
55
#define TK_
STREAMS
56
#define TK_
VARIABLES
57
#define TK_
SCORE
S 58
#define TK_
GRANT
S 59
#define TK_
VNODES
60
#define TK_
DOT
61
#define TK_
CREATE
62
#define TK_
TABLE
63
#define TK_
STABLE
64
#define TK_
DATABASE
65
#define TK_
TABLES
66
#define TK_
STABLE
S 67
#define TK_
VGROUPS
68
#define TK_
DROP
69
#define TK_
TOPIC
70
#define TK_
FUNCTION
71
#define TK_
DNODE
72
#define TK_
USER
73
#define TK_
ACCOUNT
74
#define TK_
USE
75
#define TK_
DESCRIBE
76
#define TK_
ALTER
77
#define TK_P
ASS
78
#define TK_
PRIVILEGE
79
#define TK_
LOCAL
80
#define TK_
COMPACT
81
#define TK_
L
P 82
#define TK_
RP
83
#define TK_
IF
84
#define TK_
EXISTS
85
#define TK_
AS
86
#define TK_
OUTPUTTYPE
87
#define TK_
AGGREGATE
88
#define TK_
BUFSIZE
89
#define TK_
PPS
90
#define TK_
TSERIES
91
#define TK_
DBS
92
#define TK_
STORAGE
93
#define TK_
QTIME
94
#define TK_
CONNS
95
#define TK_
STATE
96
#define TK_
COMMA
97
#define TK_
KEEP
98
#define TK_
CACHE
99
#define TK_
REPLICA
100
#define TK_
QUORUM
101
#define TK_
DAYS
102
#define TK_M
IN
ROWS 103
#define TK_
MAXROWS
104
#define TK_
BLOCKS
105
#define TK_
CTIME
106
#define TK_
WAL
107
#define TK_
FSYNC
108
#define TK_
COMP
109
#define TK_
PRECISION
110
#define TK_
UPDATE
111
#define TK_
CACHELAST
112
#define TK_
PARTITIONS
113
#define TK_
UNSIGNED
114
#define TK_
TAGS
115
#define TK_
USING
116
#define TK_N
ULL
117
#define TK_
NOW
118
#define TK_
SELECT
119
#define TK_
UNION
120
#define TK_
ALL
121
#define TK_
DISTINCT
122
#define TK_
FROM
123
#define TK_
VARIABLE
124
#define TK_
INTERVAL
125
#define TK_S
ESSION
126
#define TK_
STATE_WINDOW
127
#define TK_
FILL
128
#define TK_
SLIDING
129
#define TK_
ORDER
130
#define TK_
BY
131
#define TK_
ASC
132
#define TK_
DESC
133
#define TK_
GROUP
134
#define TK_
HAVING
135
#define TK_
LIMIT
136
#define TK_
OFFSE
T 137
#define TK_S
LIMIT
138
#define TK_
SOFFSET
139
#define TK_
WHERE
140
#define TK_
RESET
141
#define TK_
QUERY
142
#define TK_
SYNCDB
143
#define TK_
ADD
144
#define TK_
COLUMN
145
#define TK_
MODIFY
146
#define TK_
TAG
147
#define TK_
CHANGE
148
#define TK_
SET
149
#define TK_
KILL
150
#define TK_
CONNECTION
151
#define TK_
STREAM
152
#define TK_
COLON
153
#define TK_A
BORT
154
#define TK_A
FTER
155
#define TK_
ATTACH
156
#define TK_BE
FORE
157
#define TK_
BEGIN
158
#define TK_C
ASCADE
159
#define TK_C
LUSTER
160
#define TK_CO
NFLICT
161
#define TK_
COPY
162
#define TK_DE
FERRED
163
#define TK_DE
LIMITERS
164
#define TK_
DETACH
165
#define TK_E
ACH
166
#define TK_E
ND
167
#define TK_
EXPLAIN
168
#define TK_F
AIL
169
#define TK_
FOR
170
#define TK_I
GNORE
171
#define TK_I
MMEDIATE
172
#define TK_IN
ITIALLY
173
#define TK_
INSTEAD
174
#define TK_KEY 175
#define TK_OF 176
#define TK_RAISE 177
...
...
src/query/inc/sql.y
浏览文件 @
1f54d6aa
...
...
@@ -11,7 +11,7 @@
%left OR.
%left AND.
%right NOT.
%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
%left EQ NE ISNULL NOTNULL IS LIKE
MATCH
GLOB BETWEEN IN.
%left GT GE LT LE.
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
...
...
@@ -743,6 +743,9 @@ expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); }
// like expression
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
// match expression
expr(A) ::= expr(X) MATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_MATCH); }
//in expression
expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSqlExpr*)Y, TK_IN); }
...
...
src/query/src/qFilter.c
浏览文件 @
1f54d6aa
...
...
@@ -28,6 +28,7 @@ OptrStr gOptrStr[] = {
{
TSDB_RELATION_GREATER_EQUAL
,
">="
},
{
TSDB_RELATION_NOT_EQUAL
,
"!="
},
{
TSDB_RELATION_LIKE
,
"like"
},
{
TSDB_RELATION_MATCH
,
"match"
},
{
TSDB_RELATION_ISNULL
,
"is null"
},
{
TSDB_RELATION_NOTNULL
,
"not null"
},
{
TSDB_RELATION_IN
,
"in"
},
...
...
@@ -156,7 +157,7 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
__compar_fn_t
gDataCompare
[]
=
{
compareInt32Val
,
compareInt8Val
,
compareInt16Val
,
compareInt64Val
,
compareFloatVal
,
compareDoubleVal
,
compareLenPrefixedStr
,
compareStrPatternComp
,
compareFindItemInSet
,
compareWStrPatternComp
,
compareLenPrefixedWStr
,
compareUint8Val
,
compareUint16Val
,
compareUint32Val
,
compareUint64Val
,
setCompareBytes1
,
setCompareBytes2
,
setCompareBytes4
,
setCompareBytes8
setCompareBytes1
,
setCompareBytes2
,
setCompareBytes4
,
setCompareBytes8
,
compareStrRegexComp
,
};
int8_t
filterGetCompFuncIdx
(
int32_t
type
,
int32_t
optr
)
{
...
...
@@ -195,7 +196,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_FLOAT
:
comparFn
=
4
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
comparFn
=
5
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
if
(
optr
==
TSDB_RELATION_MATCH
)
{
comparFn
=
19
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
7
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
8
;
...
...
@@ -207,7 +210,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
}
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
optr
==
TSDB_RELATION_LIKE
)
{
if
(
optr
==
TSDB_RELATION_MATCH
)
{
comparFn
=
19
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
comparFn
=
9
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
8
;
...
...
@@ -1871,6 +1876,9 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
case
TSDB_RELATION_LIKE
:
{
return
ret
==
0
;
}
case
TSDB_RELATION_MATCH
:
{
return
ret
==
0
;
}
case
TSDB_RELATION_IN
:
{
return
ret
==
1
;
}
...
...
@@ -2641,7 +2649,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t
}
if
(
cunit
->
optr
==
TSDB_RELATION_ISNULL
||
cunit
->
optr
==
TSDB_RELATION_NOTNULL
||
cunit
->
optr
==
TSDB_RELATION_IN
||
cunit
->
optr
==
TSDB_RELATION_LIKE
||
cunit
->
optr
==
TSDB_RELATION_IN
||
cunit
->
optr
==
TSDB_RELATION_LIKE
||
cunit
->
optr
==
TSDB_RELATION_MATCH
||
cunit
->
optr
==
TSDB_RELATION_NOT_EQUAL
)
{
continue
;
}
...
...
src/query/src/sql.c
浏览文件 @
1f54d6aa
此差异已折叠。
点击以展开。
src/tsdb/src/tsdbRead.c
浏览文件 @
1f54d6aa
...
...
@@ -3708,6 +3708,9 @@ static bool tableFilterFp(const void* pNode, void* param) {
case
TSDB_RELATION_LIKE
:
{
return
ret
==
0
;
}
case
TSDB_RELATION_MATCH
:
{
return
ret
==
0
;
}
case
TSDB_RELATION_IN
:
{
return
ret
==
1
;
}
...
...
@@ -4041,6 +4044,8 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) {
pCond
->
start
->
v
=
queryColInfo
->
q
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
assert
(
0
);
}
else
if
(
optr
==
TSDB_RELATION_MATCH
)
{
assert
(
0
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -4198,7 +4203,7 @@ static void queryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, S
if
(
pQueryInfo
->
sch
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
pQueryInfo
->
optr
==
TSDB_RELATION_IN
)
{
addToResult
=
pQueryInfo
->
compare
(
name
,
pQueryInfo
->
q
);
}
else
if
(
pQueryInfo
->
optr
==
TSDB_RELATION_LIKE
)
{
}
else
if
(
pQueryInfo
->
optr
==
TSDB_RELATION_LIKE
||
pQueryInfo
->
optr
==
TSDB_RELATION_MATCH
)
{
addToResult
=
!
pQueryInfo
->
compare
(
name
,
pQueryInfo
->
q
);
}
}
else
{
...
...
@@ -4230,7 +4235,8 @@ void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *re
param
->
setupInfoFn
(
pExpr
,
param
->
pExtInfo
);
tQueryInfo
*
pQueryInfo
=
pExpr
->
_node
.
info
;
if
(
pQueryInfo
->
indexed
&&
(
pQueryInfo
->
optr
!=
TSDB_RELATION_LIKE
&&
pQueryInfo
->
optr
!=
TSDB_RELATION_IN
))
{
if
(
pQueryInfo
->
indexed
&&
(
pQueryInfo
->
optr
!=
TSDB_RELATION_LIKE
&&
pQueryInfo
->
optr
==
TSDB_RELATION_MATCH
&&
pQueryInfo
->
optr
!=
TSDB_RELATION_IN
))
{
queryIndexedColumn
(
pSkipList
,
pQueryInfo
,
result
);
}
else
{
queryIndexlessColumn
(
pSkipList
,
pQueryInfo
,
result
,
param
->
nodeFilterFn
);
...
...
src/util/inc/tcompare.h
浏览文件 @
1f54d6aa
...
...
@@ -26,6 +26,7 @@ extern "C" {
#define TSDB_PATTERN_NOMATCH 1
#define TSDB_PATTERN_NOWILDCARDMATCH 2
#define TSDB_PATTERN_STRING_MAX_LEN 100
#define TSDB_REGEX_STRING_MAX_LEN 128
#define FLT_COMPAR_TOL_FACTOR 4
#define FLT_EQUAL(_x, _y) (fabs((_x) - (_y)) <= (FLT_COMPAR_TOL_FACTOR * FLT_EPSILON))
...
...
@@ -82,6 +83,7 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight);
int32_t
compareLenPrefixedWStr
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrRegexComp
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareFindItemInSet
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareWStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
);
...
...
src/util/src/tcompare.c
浏览文件 @
1f54d6aa
...
...
@@ -13,10 +13,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "ttype.h"
#include "tcompare.h"
#include <tulog.h>
#include "hash.h"
#include "os.h"
#include "ttype.h"
int32_t
setCompareBytes1
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
1
)
?
1
:
0
;
...
...
@@ -343,6 +344,43 @@ int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
int32_t
compareStrRegexComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
size_t
sz
=
varDataLen
(
pRight
);
char
*
pattern
=
malloc
(
sz
+
1
);
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
pattern
[
sz
]
=
0
;
sz
=
varDataLen
(
pLeft
);
char
*
str
=
malloc
(
sz
+
1
);
memcpy
(
str
,
varDataVal
(
pLeft
),
sz
);
str
[
sz
]
=
0
;
int
errCode
=
0
;
regex_t
regex
;
char
msgbuf
[
256
]
=
{
0
};
int
cflags
=
REG_EXTENDED
|
REG_ICASE
;
if
((
errCode
=
regcomp
(
&
regex
,
pattern
,
cflags
))
!=
0
)
{
regerror
(
errCode
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
uError
(
"Failed to compile regex pattern %s. reason %s"
,
pattern
,
msgbuf
);
regfree
(
&
regex
);
free
(
str
);
free
(
pattern
);
return
1
;
}
errCode
=
regexec
(
&
regex
,
str
,
0
,
NULL
,
0
);
if
(
errCode
!=
0
&&
errCode
!=
REG_NOMATCH
)
{
regerror
(
errCode
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
uError
(
"Failed to match %s with pattern %s, reason %s"
,
str
,
pattern
,
msgbuf
)
}
int32_t
result
=
(
errCode
==
0
)
?
0
:
1
;
regfree
(
&
regex
);
free
(
str
);
free
(
pattern
);
return
result
;
}
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
)
{
const
char
*
x
=
*
(
const
char
**
)
a
;
const
char
*
y
=
*
(
const
char
**
)
b
;
...
...
@@ -403,7 +441,9 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_FLOAT
:
comparFn
=
compareFloatVal
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
comparFn
=
compareDoubleVal
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
if
(
optr
==
TSDB_RELATION_MATCH
)
{
comparFn
=
compareStrRegexComp
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compareStrPatternComp
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
compareFindItemInSet
;
...
...
@@ -415,7 +455,9 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
}
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
optr
==
TSDB_RELATION_LIKE
)
{
if
(
optr
==
TSDB_RELATION_MATCH
)
{
comparFn
=
compareStrRegexComp
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
comparFn
=
compareWStrPatternComp
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
compareFindItemInSet
;
...
...
src/util/src/ttokenizer.c
浏览文件 @
1f54d6aa
...
...
@@ -53,6 +53,7 @@ static SKeyword keywordTable[] = {
{
"NOTNULL"
,
TK_NOTNULL
},
{
"IS"
,
TK_IS
},
{
"LIKE"
,
TK_LIKE
},
{
"MATCH"
,
TK_MATCH
},
{
"GLOB"
,
TK_GLOB
},
{
"BETWEEN"
,
TK_BETWEEN
},
{
"IN"
,
TK_IN
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录