Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2eb7174f
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看板
提交
2eb7174f
编写于
3月 26, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact code
上级
1f02bee6
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
68 addition
and
96 deletion
+68
-96
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+48
-79
src/inc/ttokendef.h
src/inc/ttokendef.h
+1
-0
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+5
-6
src/query/inc/sql.y
src/query/inc/sql.y
+1
-1
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+11
-8
src/query/src/sql.c
src/query/src/sql.c
+1
-1
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
2eb7174f
...
@@ -132,7 +132,7 @@ typedef struct SSqlExpr {
...
@@ -132,7 +132,7 @@ typedef struct SSqlExpr {
}
SSqlExpr
;
}
SSqlExpr
;
typedef
struct
SExprFilter
{
typedef
struct
SExprFilter
{
tS
QL
Expr
*
pExpr
;
//used for having parse
tS
ql
Expr
*
pExpr
;
//used for having parse
SSqlExpr
*
pSqlExpr
;
SSqlExpr
*
pSqlExpr
;
SArray
*
fp
;
SArray
*
fp
;
SColumn
*
pFilters
;
//having filter info
SColumn
*
pFilters
;
//having filter info
...
...
src/client/src/tscSQLParser.c
浏览文件 @
2eb7174f
...
@@ -1098,40 +1098,6 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
...
@@ -1098,40 +1098,6 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
return
true
;
return
true
;
}
}
static
void
exchangeExpr
(
tSQLExpr
*
pExpr
)
{
tSQLExpr
*
pLeft
=
pExpr
->
pLeft
;
tSQLExpr
*
pRight
=
pExpr
->
pRight
;
if
((
pRight
->
nSQLOptr
==
TK_ID
||
(
pRight
->
nSQLOptr
>=
TK_COUNT
&&
pRight
->
nSQLOptr
<=
TK_AVG_IRATE
))
&&
(
pLeft
->
nSQLOptr
==
TK_INTEGER
||
pLeft
->
nSQLOptr
==
TK_FLOAT
||
pLeft
->
nSQLOptr
==
TK_STRING
||
pLeft
->
nSQLOptr
==
TK_BOOL
))
{
/*
* exchange value of the left handside and the value of the right-handside
* to make sure that the value of filter expression always locates in
* right-handside and
* the column-id/function is at the left handside.
*/
uint32_t
optr
=
0
;
switch
(
pExpr
->
nSQLOptr
)
{
case
TK_LE
:
optr
=
TK_GE
;
break
;
case
TK_LT
:
optr
=
TK_GT
;
break
;
case
TK_GT
:
optr
=
TK_LT
;
break
;
case
TK_GE
:
optr
=
TK_LE
;
break
;
default:
optr
=
pExpr
->
nSQLOptr
;
}
pExpr
->
nSQLOptr
=
optr
;
SWAP
(
pExpr
->
pLeft
,
pExpr
->
pRight
,
void
*
);
}
}
static
bool
validateTagParams
(
SArray
*
pTagsList
,
SArray
*
pFieldList
,
SSqlCmd
*
pCmd
)
{
static
bool
validateTagParams
(
SArray
*
pTagsList
,
SArray
*
pFieldList
,
SSqlCmd
*
pCmd
)
{
assert
(
pTagsList
!=
NULL
);
assert
(
pTagsList
!=
NULL
);
...
@@ -3118,6 +3084,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
...
@@ -3118,6 +3084,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
columnIndex
->
tableIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
columnIndex
->
tableIndex
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
columnIndex
->
columnIndex
);
int16_t
colType
=
pSchema
->
type
;
int16_t
colType
=
pSchema
->
type
;
...
@@ -3325,9 +3292,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
...
@@ -3325,9 +3292,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
pColumn
->
colIndex
=
*
pIndex
;
pColumn
->
colIndex
=
*
pIndex
;
int16_t
colType
=
pSchema
->
type
;
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
pIndex
,
pExpr
);
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
colType
,
pExpr
);
}
}
static
int32_t
getTablenameCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pTableCond
,
SStringBuilder
*
sb
)
{
static
int32_t
getTablenameCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pTableCond
,
SStringBuilder
*
sb
)
{
...
@@ -6766,7 +6731,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
...
@@ -6766,7 +6731,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
}
}
int32_t
tscInsertExprFields
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
,
SInternalField
**
interField
)
{
int32_t
tscInsertExprFields
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
,
SInternalField
**
interField
)
{
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
,
.
distinct
=
false
};
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
,
.
distinct
=
false
};
int32_t
outputIndex
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
int32_t
outputIndex
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
...
@@ -6811,7 +6776,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
...
@@ -6811,7 +6776,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
tscGetExprFilters
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
,
SInternalField
**
pField
)
{
int32_t
tscGetExprFilters
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
,
SInternalField
**
pField
)
{
SInternalField
*
pInfo
=
NULL
;
SInternalField
*
pInfo
=
NULL
;
for
(
int32_t
i
=
pQueryInfo
->
havingFieldNum
-
1
;
i
>=
0
;
--
i
)
{
for
(
int32_t
i
=
pQueryInfo
->
havingFieldNum
-
1
;
i
>=
0
;
--
i
)
{
...
@@ -6861,7 +6826,7 @@ static int32_t genExprFilter(SExprFilter * exprFilter) {
...
@@ -6861,7 +6826,7 @@ static int32_t genExprFilter(SExprFilter * exprFilter) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
handleExprInHavingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
,
int32_t
sqlOptr
)
{
static
int32_t
handleExprInHavingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
,
int32_t
sqlOptr
)
{
const
char
*
msg1
=
"non binary column not support like operator"
;
const
char
*
msg1
=
"non binary column not support like operator"
;
const
char
*
msg2
=
"invalid operator for binary column in having clause"
;
const
char
*
msg2
=
"invalid operator for binary column in having clause"
;
const
char
*
msg3
=
"invalid operator for bool column in having clause"
;
const
char
*
msg3
=
"invalid operator for bool column in having clause"
;
...
@@ -6913,27 +6878,32 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
...
@@ -6913,27 +6878,32 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
((
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_BINARY
||
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
)
?
1
:
0
);
((
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_BINARY
||
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
)
?
1
:
0
);
if
(
pColFilter
->
filterstr
)
{
if
(
pColFilter
->
filterstr
)
{
if
(
pExpr
->
nSQLOptr
!=
TK_EQ
if
(
pExpr
->
tokenId
!=
TK_EQ
&&
pExpr
->
nSQLOptr
!=
TK_NE
&&
pExpr
->
tokenId
!=
TK_NE
&&
pExpr
->
nSQLOptr
!=
TK_ISNULL
&&
pExpr
->
tokenId
!=
TK_ISNULL
&&
pExpr
->
nSQLOptr
!=
TK_NOTNULL
&&
pExpr
->
tokenId
!=
TK_NOTNULL
&&
pExpr
->
nSQLOptr
!=
TK_LIKE
&&
pExpr
->
tokenId
!=
TK_LIKE
)
{
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
}
else
{
}
else
{
if
(
pExpr
->
nSQLOptr
==
TK_LIKE
)
{
if
(
pExpr
->
tokenId
==
TK_LIKE
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
if
(
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
pExpr
->
nSQLOptr
!=
TK_EQ
&&
pExpr
->
nSQLOptr
!=
TK_NE
)
{
if
(
pExpr
->
tokenId
!=
TK_EQ
&&
pExpr
->
tokenId
!=
TK_NE
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
}
}
}
}
int32_t
ret
=
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
pInfo
->
field
.
type
,
pExpr
);
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
pCmd
,
&
pExpr
->
pLeft
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
int32_t
ret
=
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
&
index
,
pExpr
);
if
(
ret
)
{
if
(
ret
)
{
return
ret
;
return
ret
;
}
}
...
@@ -6941,38 +6911,30 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
...
@@ -6941,38 +6911,30 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
return
genExprFilter
(
pInfo
->
pFieldFilters
);
return
genExprFilter
(
pInfo
->
pFieldFilters
);
}
}
int32_t
getHavingExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
,
int32_t
parentOptr
)
{
int32_t
getHavingExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
,
int32_t
parentOptr
)
{
if
(
pExpr
==
NULL
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
const
char
*
msg1
=
"invalid having clause"
;
const
char
*
msg1
=
"invalid having clause"
;
tS
QL
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
ql
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
if
(
pExpr
->
nSQLOptr
==
TK_AND
||
pExpr
->
nSQLOptr
==
TK_OR
)
{
if
(
pExpr
->
tokenId
==
TK_AND
||
pExpr
->
tokenId
==
TK_OR
)
{
int32_t
ret
=
getHavingExpr
(
pCmd
,
pQueryInfo
,
pExpr
->
pLeft
,
pExpr
->
nSQLOptr
);
int32_t
ret
=
getHavingExpr
(
pCmd
,
pQueryInfo
,
pExpr
->
pLeft
,
pExpr
->
tokenId
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
return
getHavingExpr
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
,
pExpr
->
nSQLOptr
);
return
getHavingExpr
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
,
pExpr
->
tokenId
);
}
}
if
(
pLeft
==
NULL
||
pRight
==
NULL
)
{
if
(
pLeft
==
NULL
||
pRight
==
NULL
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
if
((
pLeft
->
nSQLOptr
>=
TK_COUNT
&&
pLeft
->
nSQLOptr
<=
TK_AVG_IRATE
)
&&
if
(
pLeft
->
type
==
pRight
->
type
)
{
(
pRight
->
nSQLOptr
>=
TK_COUNT
&&
pRight
->
nSQLOptr
<=
TK_AVG_IRATE
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pLeft
->
nSQLOptr
>=
TK_BOOL
&&
pLeft
->
nSQLOptr
<=
TK_BINARY
&&
pRight
->
nSQLOptr
>=
TK_BOOL
&&
pRight
->
nSQLOptr
<=
TK_BINARY
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
...
@@ -6981,15 +6943,16 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, in
...
@@ -6981,15 +6943,16 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, in
pLeft
=
pExpr
->
pLeft
;
pLeft
=
pExpr
->
pLeft
;
pRight
=
pExpr
->
pRight
;
pRight
=
pExpr
->
pRight
;
if
(
!
(
pLeft
->
nSQLOptr
>=
TK_COUNT
&&
pLeft
->
nSQLOptr
<=
TK_AVG_IRATE
))
{
if
(
pLeft
->
type
!=
SQL_NODE_SQLFUNCTION
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
if
(
!
(
pRight
->
nSQLOptr
>=
TK_BOOL
&&
pRight
->
nSQLOptr
<=
TK_BINARY
)
)
{
if
(
pRight
->
type
!=
SQL_NODE_VALUE
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
if
(
pExpr
->
nSQLOptr
>=
TK_BITAND
)
{
if
(
pExpr
->
tokenId
>=
TK_BITAND
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
...
@@ -6998,21 +6961,22 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, in
...
@@ -6998,21 +6961,22 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, in
//}
//}
if
(
pLeft
->
pParam
)
{
if
(
pLeft
->
pParam
)
{
for
(
int32_t
i
=
0
;
i
<
pLeft
->
pParam
->
nExpr
;
i
++
)
{
size_t
size
=
taosArrayGetSize
(
pLeft
->
pParam
);
tSqlExprItem
*
pParamElem
=
&
(
pLeft
->
pParam
->
a
[
i
]);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
if
(
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ALL
&&
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pLeft
->
pParam
,
i
);
pParamElem
->
pNode
->
nSQLOptr
!=
TK_ID
&&
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ALL
&&
pParamElem
->
pNode
->
nSQLOptr
!=
TK_STRING
&&
pParamElem
->
pNode
->
tokenId
!=
TK_ID
&&
pParamElem
->
pNode
->
nSQLOptr
!=
TK_INTEGER
&&
pParamElem
->
pNode
->
tokenId
!=
TK_STRING
&&
pParamElem
->
pNode
->
nSQLOptr
!=
TK_FLOAT
)
{
pParamElem
->
pNode
->
tokenId
!=
TK_INTEGER
&&
pParamElem
->
pNode
->
tokenId
!=
TK_FLOAT
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
if
(
pParamElem
->
pNode
->
nSQLOptr
==
TK_ID
&&
(
pParamElem
->
pNode
->
colInfo
.
z
==
NULL
&&
pParamElem
->
pNode
->
colInfo
.
n
==
0
))
{
if
(
pParamElem
->
pNode
->
tokenId
==
TK_ID
&&
(
pParamElem
->
pNode
->
colInfo
.
z
==
NULL
&&
pParamElem
->
pNode
->
colInfo
.
n
==
0
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
}
if
(
pParamElem
->
pNode
->
nSQLOptr
==
TK_ID
)
{
if
(
pParamElem
->
pNode
->
tokenId
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
((
getColumnIndexByName
(
pCmd
,
&
pParamElem
->
pNode
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
))
{
if
((
getColumnIndexByName
(
pCmd
,
&
pParamElem
->
pNode
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
...
@@ -7029,12 +6993,17 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, in
...
@@ -7029,12 +6993,17 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, in
}
}
}
}
pLeft
->
functionId
=
isValidFunction
(
pLeft
->
operand
.
z
,
pLeft
->
operand
.
n
);
if
(
pLeft
->
functionId
<
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
return
handleExprInHavingClause
(
pCmd
,
pQueryInfo
,
pExpr
,
parentOptr
);
return
handleExprInHavingClause
(
pCmd
,
pQueryInfo
,
pExpr
,
parentOptr
);
}
}
int32_t
parseHavingClause
(
SQueryInfo
*
pQueryInfo
,
tS
QLExpr
*
pExpr
,
SSqlCmd
*
pCmd
,
bool
isSTable
,
int32_t
joinQuery
,
int32_t
interval
Query
)
{
int32_t
parseHavingClause
(
SQueryInfo
*
pQueryInfo
,
tS
qlExpr
*
pExpr
,
SSqlCmd
*
pCmd
,
bool
isSTable
,
int32_t
joinQuery
,
int32_t
timeWindow
Query
)
{
const
char
*
msg1
=
"having only works with group by"
;
const
char
*
msg1
=
"having only works with group by"
;
const
char
*
msg2
=
"functions or others can not be mixed up"
;
const
char
*
msg2
=
"functions or others can not be mixed up"
;
const
char
*
msg3
=
"invalid expression in having clause"
;
const
char
*
msg3
=
"invalid expression in having clause"
;
...
@@ -7062,7 +7031,7 @@ int32_t parseHavingClause(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SSqlCmd* pCmd
...
@@ -7062,7 +7031,7 @@ int32_t parseHavingClause(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SSqlCmd* pCmd
}
}
//REDO function check
//REDO function check
if
(
!
functionCompatibleCheck
(
pQueryInfo
,
joinQuery
,
interval
Query
))
{
if
(
!
functionCompatibleCheck
(
pQueryInfo
,
joinQuery
,
timeWindow
Query
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
...
@@ -7239,7 +7208,7 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i
...
@@ -7239,7 +7208,7 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i
}
}
// parse the having clause in the first place
// parse the having clause in the first place
if
(
parseHavingClause
(
pQueryInfo
,
pQuerySql
->
pHaving
,
pCmd
,
isSTable
,
joinQuery
,
interval
Query
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseHavingClause
(
pQueryInfo
,
pQuerySql
Node
->
pHaving
,
pCmd
,
isSTable
,
joinQuery
,
timeWindow
Query
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
...
...
src/inc/ttokendef.h
浏览文件 @
2eb7174f
...
@@ -208,6 +208,7 @@
...
@@ -208,6 +208,7 @@
#define TK_SPACE 300
#define TK_SPACE 300
#define TK_COMMENT 301
#define TK_COMMENT 301
#define TK_ILLEGAL 302
#define TK_ILLEGAL 302
...
...
src/query/inc/qSqlparser.h
浏览文件 @
2eb7174f
...
@@ -98,7 +98,7 @@ typedef struct SQuerySqlNode {
...
@@ -98,7 +98,7 @@ typedef struct SQuerySqlNode {
SLimitVal
limit
;
// limit offset [optional]
SLimitVal
limit
;
// limit offset [optional]
SLimitVal
slimit
;
// group limit offset [optional]
SLimitVal
slimit
;
// group limit offset [optional]
SStrToken
sqlstr
;
// sql string in select clause
SStrToken
sqlstr
;
// sql string in select clause
struct
tS
QLExpr
*
pHaving
;
// having clause [optional]
struct
tS
qlExpr
*
pHaving
;
// having clause [optional]
}
SQuerySqlNode
;
}
SQuerySqlNode
;
typedef
struct
STableNamePair
{
typedef
struct
STableNamePair
{
...
@@ -118,7 +118,6 @@ typedef struct SFromInfo {
...
@@ -118,7 +118,6 @@ typedef struct SFromInfo {
SArray
*
tableList
;
// SArray<STableNamePair>
SArray
*
tableList
;
// SArray<STableNamePair>
};
};
}
SFromInfo
;
}
SFromInfo
;
>>>>>>>
develop
typedef
struct
SCreatedTableInfo
{
typedef
struct
SCreatedTableInfo
{
SStrToken
name
;
// table name token
SStrToken
name
;
// table name token
...
@@ -255,11 +254,11 @@ SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
...
@@ -255,11 +254,11 @@ SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
tS
QLExpr
*
tSqlExprCreate
(
tSQLExpr
*
pLeft
,
tSQL
Expr
*
pRight
,
int32_t
optrType
);
tS
qlExpr
*
tSqlExprCreate
(
tSqlExpr
*
pLeft
,
tSql
Expr
*
pRight
,
int32_t
optrType
);
int32_t
tSqlExprCompare
(
tS
QLExpr
*
left
,
tSQL
Expr
*
right
);
int32_t
tSqlExprCompare
(
tS
qlExpr
*
left
,
tSql
Expr
*
right
);
tS
QLExpr
*
tSqlExprClone
(
tSQL
Expr
*
pSrc
);
tS
qlExpr
*
tSqlExprClone
(
tSql
Expr
*
pSrc
);
SFromInfo
*
setTableNameList
(
SFromInfo
*
pFromInfo
,
SStrToken
*
pName
,
SStrToken
*
pAlias
);
SFromInfo
*
setTableNameList
(
SFromInfo
*
pFromInfo
,
SStrToken
*
pName
,
SStrToken
*
pAlias
);
SFromInfo
*
setSubquery
(
SFromInfo
*
pFromInfo
,
SQuerySqlNode
*
pSqlNode
);
SFromInfo
*
setSubquery
(
SFromInfo
*
pFromInfo
,
SQuerySqlNode
*
pSqlNode
);
void
*
destroyFromInfo
(
SFromInfo
*
pFromInfo
);
void
*
destroyFromInfo
(
SFromInfo
*
pFromInfo
);
...
@@ -279,7 +278,7 @@ void tSqlExprListDestroy(SArray *pList);
...
@@ -279,7 +278,7 @@ void tSqlExprListDestroy(SArray *pList);
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SFromInfo
*
pFrom
,
tSqlExpr
*
pWhere
,
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SFromInfo
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
ps
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
ps
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pgLimit
,
tS
QL
Expr
*
pHaving
);
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pgLimit
,
tS
ql
Expr
*
pHaving
);
SCreateTableSql
*
tSetCreateTableInfo
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySqlNode
*
pSelect
,
int32_t
type
);
SCreateTableSql
*
tSetCreateTableInfo
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySqlNode
*
pSelect
,
int32_t
type
);
...
...
src/query/inc/sql.y
浏览文件 @
2eb7174f
...
@@ -471,7 +471,7 @@ cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
...
@@ -471,7 +471,7 @@ cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
// select client_version()
// select client_version()
// select server_state()
// select server_state()
select(A) ::= SELECT(T) selcollist(W). {
select(A) ::= SELECT(T) selcollist(W). {
A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
, NULL
);
}
}
// selcollist is a list of expressions that are to become the return
// selcollist is a list of expressions that are to become the return
...
...
src/query/src/qSqlParser.c
浏览文件 @
2eb7174f
...
@@ -310,12 +310,12 @@ static FORCE_INLINE int32_t tStrTokenCompare(SStrToken* left, SStrToken* right)
...
@@ -310,12 +310,12 @@ static FORCE_INLINE int32_t tStrTokenCompare(SStrToken* left, SStrToken* right)
}
}
int32_t
tSqlExprCompare
(
tS
QLExpr
*
left
,
tSQL
Expr
*
right
)
{
int32_t
tSqlExprCompare
(
tS
qlExpr
*
left
,
tSql
Expr
*
right
)
{
if
((
left
==
NULL
&&
right
)
||
(
left
&&
right
==
NULL
))
{
if
((
left
==
NULL
&&
right
)
||
(
left
&&
right
==
NULL
))
{
return
1
;
return
1
;
}
}
if
(
left
->
nSQLOptr
!=
right
->
nSQLOptr
)
{
if
(
left
->
type
!=
right
->
type
)
{
return
1
;
return
1
;
}
}
...
@@ -328,7 +328,7 @@ int32_t tSqlExprCompare(tSQLExpr *left, tSQLExpr *right) {
...
@@ -328,7 +328,7 @@ int32_t tSqlExprCompare(tSQLExpr *left, tSQLExpr *right) {
return
1
;
return
1
;
}
}
if
(
tVariantCompare
(
&
left
->
val
,
&
right
->
val
))
{
if
(
tVariantCompare
(
&
left
->
val
ue
,
&
right
->
value
))
{
return
1
;
return
1
;
}
}
...
@@ -336,14 +336,17 @@ int32_t tSqlExprCompare(tSQLExpr *left, tSQLExpr *right) {
...
@@ -336,14 +336,17 @@ int32_t tSqlExprCompare(tSQLExpr *left, tSQLExpr *right) {
return
1
;
return
1
;
}
}
if
(
left
->
pParam
&&
left
->
pParam
->
nExpr
!=
right
->
pParam
->
nExpr
)
{
size_t
size
=
taosArrayGetSize
(
right
->
pParam
);
if
(
left
->
pParam
&&
taosArrayGetSize
(
left
->
pParam
)
!=
size
)
{
return
1
;
return
1
;
}
}
if
(
right
->
pParam
&&
left
->
pParam
)
{
if
(
right
->
pParam
&&
left
->
pParam
)
{
for
(
int32_t
i
=
0
;
i
<
right
->
pParam
->
nExpr
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
tSQLExpr
*
pSubLeft
=
left
->
pParam
->
a
[
i
].
pNode
;
tSqlExprItem
*
pLeftElem
=
taosArrayGet
(
left
->
pParam
,
i
);
tSQLExpr
*
pSubRight
=
right
->
pParam
->
a
[
i
].
pNode
;
tSqlExpr
*
pSubLeft
=
pLeftElem
->
pNode
;
tSqlExprItem
*
pRightElem
=
taosArrayGet
(
left
->
pParam
,
i
);
tSqlExpr
*
pSubRight
=
pRightElem
->
pNode
;
if
(
tSqlExprCompare
(
pSubLeft
,
pSubRight
))
{
if
(
tSqlExprCompare
(
pSubLeft
,
pSubRight
))
{
return
1
;
return
1
;
...
@@ -690,7 +693,7 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
...
@@ -690,7 +693,7 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SFromInfo
*
pFrom
,
tSqlExpr
*
pWhere
,
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SFromInfo
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
psLimit
,
tS
QL
Expr
*
pHaving
)
{
SLimitVal
*
psLimit
,
tS
ql
Expr
*
pHaving
)
{
assert
(
pSelectList
!=
NULL
);
assert
(
pSelectList
!=
NULL
);
SQuerySqlNode
*
pSqlNode
=
calloc
(
1
,
sizeof
(
SQuerySqlNode
));
SQuerySqlNode
*
pSqlNode
=
calloc
(
1
,
sizeof
(
SQuerySqlNode
));
...
...
src/query/src/sql.c
浏览文件 @
2eb7174f
...
@@ -2905,7 +2905,7 @@ static YYACTIONTYPE yy_reduce(
...
@@ -2905,7 +2905,7 @@ static YYACTIONTYPE yy_reduce(
break
;
break
;
case
161
:
/* select ::= SELECT selcollist */
case
161
:
/* select ::= SELECT selcollist */
{
{
yylhsminor
.
yy254
=
tSetQuerySqlNode
(
&
yymsp
[
-
1
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy429
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
yylhsminor
.
yy254
=
tSetQuerySqlNode
(
&
yymsp
[
-
1
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy429
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
}
}
yymsp
[
-
1
].
minor
.
yy254
=
yylhsminor
.
yy254
;
yymsp
[
-
1
].
minor
.
yy254
=
yylhsminor
.
yy254
;
break
;
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录