Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzh_me
TDengine
提交
f8c3135f
TDengine
项目概览
lzh_me
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f8c3135f
编写于
7月 06, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-255] refactor.
上级
a3848a14
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
112 addition
and
66 deletion
+112
-66
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+102
-63
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+5
-1
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+2
-2
tests/script/general/parser/having.sim
tests/script/general/parser/having.sim
+3
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
f8c3135f
...
...
@@ -20,7 +20,12 @@
#define _GNU_SOURCE
#endif // __APPLE__
#include <qSqlparser.h>
#include "os.h"
#include "qPlan.h"
#include "qSqlparser.h"
#include "qTableMeta.h"
#include "qUtil.h"
#include "taos.h"
#include "taosmsg.h"
#include "tcompare.h"
...
...
@@ -28,14 +33,11 @@
#include "tname.h"
#include "tscLog.h"
#include "tscUtil.h"
#include "qTableMeta.h"
#include "tsclient.h"
#include "tstrbuild.h"
#include "ttoken.h"
#include "ttokendef.h"
#include "ttype.h"
#include "qUtil.h"
#include "qPlan.h"
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
...
...
@@ -1992,7 +1994,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_PROJECTION_QUERY
);
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getTableIndexByName
(
&
pItem
->
pNode
->
columnN
ame
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
getTableIndexByName
(
&
pItem
->
pNode
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2029,7 +2031,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
}
else
if
(
optr
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2193,7 +2195,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if
(
pItem
->
pNode
->
Expr
.
paramList
!=
NULL
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
0
);
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
columnN
ame
;
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
ColumnName
.
n
ame
;
int16_t
tokenId
=
pParamElem
->
pNode
->
tokenId
;
if
((
pToken
->
z
==
NULL
||
pToken
->
n
==
0
)
&&
(
TK_INTEGER
!=
tokenId
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
...
@@ -2202,7 +2204,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
// select count(table.*), select count(1), count(2)
if
(
tokenId
==
TK_ALL
||
tokenId
==
TK_INTEGER
)
{
// check if the table name is valid or not
SStrToken
tmpToken
=
pParamElem
->
pNode
->
columnN
ame
;
SStrToken
tmpToken
=
pParamElem
->
pNode
->
ColumnName
.
n
ame
;
if
(
getTableIndexByName
(
&
tmpToken
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
...
...
@@ -2257,8 +2259,10 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pTableMetaInfo
->
pTableMeta
->
id
.
uid
);
}
pItem
->
pNode
->
ColumnName
.
stdName
.
z
=
strndup
(
pExpr
->
base
.
colInfo
.
name
,
tListLen
(
pExpr
->
base
.
colInfo
.
name
));
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_SUM
:
case
TSDB_FUNC_AVG
:
case
TSDB_FUNC_RATE
:
...
...
@@ -2286,7 +2290,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
((
getColumnIndexByName
(
&
pParamElem
->
pNode
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
if
((
getColumnIndexByName
(
&
pParamElem
->
pNode
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2394,8 +2398,10 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pExpr
->
base
.
uid
);
pItem
->
pNode
->
ColumnName
.
stdName
.
z
=
strndup
(
pExpr
->
base
.
colInfo
.
name
,
tListLen
(
pExpr
->
base
.
colInfo
.
name
));
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_FIRST
:
case
TSDB_FUNC_LAST
:
case
TSDB_FUNC_SPREAD
:
...
...
@@ -2430,7 +2436,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
pParamElem
->
pNode
->
tokenId
==
TK_ALL
)
{
// select table.*
SStrToken
tmpToken
=
pParamElem
->
pNode
->
columnN
ame
;
SStrToken
tmpToken
=
pParamElem
->
pNode
->
ColumnName
.
n
ame
;
if
(
getTableIndexByName
(
&
tmpToken
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
...
...
@@ -2451,7 +2457,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
}
else
{
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2466,15 +2472,14 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
index
.
columnIndex
);
bool
multiColOutput
=
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
>
1
;
setResultColName
(
name
,
pItem
,
cvtFunc
.
originFuncId
,
&
pParamElem
->
pNode
->
columnN
ame
,
multiColOutput
);
setResultColName
(
name
,
pItem
,
cvtFunc
.
originFuncId
,
&
pParamElem
->
pNode
->
ColumnName
.
n
ame
,
multiColOutput
);
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
cvtFunc
,
name
,
colIndex
++
,
&
index
,
finalResult
)
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
return
TSDB_CODE_SUCCESS
;
}
else
{
// select * from xxx
int32_t
numOfFields
=
0
;
...
...
@@ -2502,9 +2507,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
numOfFields
+=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
}
return
TSDB_CODE_SUCCESS
;
}
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_TOP
:
...
...
@@ -2523,7 +2527,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2617,8 +2621,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tscColumnListInsert
(
pQueryInfo
->
colList
,
ids
.
ids
[
0
].
columnIndex
,
pExpr
->
base
.
uid
,
pSchema
);
}
pItem
->
pNode
->
ColumnName
.
stdName
.
z
=
strndup
(
pExpr
->
base
.
colInfo
.
name
,
tListLen
(
pExpr
->
base
.
colInfo
.
name
));
return
TSDB_CODE_SUCCESS
;
}
;
}
case
TSDB_FUNC_TID_TAG
:
{
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
...
@@ -2635,7 +2640,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tSqlExpr
*
pParam
=
pParamItem
->
pNode
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pParam
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pParam
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2690,6 +2695,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_BLKINFO
:
{
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
Expr
.
paramList
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
0
)
{
...
...
@@ -2704,7 +2710,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
int16_t
bytes
=
0
;
getResultDataInfo
(
TSDB_DATA_TYPE_INT
,
4
,
TSDB_FUNC_BLKINFO
,
0
,
&
resType
,
&
bytes
,
&
inter
,
0
,
0
);
SSchema
s
=
{.
name
=
"block_dist"
,
.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
bytes
,
.
type
=
(
uint8_t
)
resType
};
SSchema
s
=
{.
name
=
"block_dist"
,
.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
bytes
};
SExprInfo
*
pExpr
=
tscExprInsert
(
pQueryInfo
,
0
,
TSDB_FUNC_BLKINFO
,
&
index
,
resType
,
bytes
,
getNewResColId
(
pCmd
),
bytes
,
0
);
...
...
@@ -3580,7 +3586,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
tSqlExpr
*
pLeft
=
pTableCond
->
pLeft
;
tSqlExpr
*
pRight
=
pTableCond
->
pRight
;
if
(
!
isTablenameToken
(
&
pLeft
->
columnN
ame
))
{
if
(
!
isTablenameToken
(
&
pLeft
->
ColumnName
.
n
ame
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3617,7 +3623,7 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSq
return
getColumnQueryCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
,
pExpr
->
tokenId
);
}
else
{
// handle leaf node
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3646,7 +3652,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -3679,7 +3685,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
int16_t
leftIdx
=
index
.
tableIndex
;
index
=
(
SColumnIndex
)
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
pRight
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pRight
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -3749,7 +3755,7 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQuer
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3945,7 +3951,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
SColumnIndex
rightIndex
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pRight
->
columnN
ame
,
pQueryInfo
,
&
rightIndex
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pRight
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
rightIndex
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
false
;
}
...
...
@@ -4031,7 +4037,7 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t
}
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
if
((
!
isTablenameToken
(
&
pLeft
->
columnN
ame
))
&&
!
IS_VAR_DATA_TYPE
(
pSchema
[
index
].
type
))
{
if
((
!
isTablenameToken
(
&
pLeft
->
ColumnName
.
n
ame
))
&&
!
IS_VAR_DATA_TYPE
(
pSchema
[
index
].
type
))
{
return
invalidOperationMsg
(
msgBuf
,
msg2
);
}
}
...
...
@@ -4055,7 +4061,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
int32_t
ret
=
TSDB_CODE_SUCCESS
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pLeft
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pLeft
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -4098,7 +4104,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
int16_t
leftIdx
=
index
.
tableIndex
;
if
(
getColumnIndexByName
(
&
pRight
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pRight
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -4261,7 +4267,7 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSqlExpr** pExpr, SQueryInfo*
tSqlExpr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pLeft
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pLeft
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
...
...
@@ -4428,7 +4434,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlE
return
getTimeRangeFromExpr
(
pCmd
,
pQueryInfo
,
pExpr
->
pRight
);
}
else
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -7233,46 +7239,79 @@ int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
// TODO normalize the function expression and compare it
int32_t
tscGetExprFilters
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelectNodeList
,
tSqlExpr
*
pSqlExpr
,
SExprInfo
**
pExpr
)
{
*
pExpr
=
NULL
;
size_t
num
=
taosArrayGetSize
(
pSelectNodeList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
tSqlExprItem
*
pItem
=
taosArrayGet
(
pSelectNodeList
,
i
);
if
(
tSqlExprCompare
(
pItem
->
pNode
,
pSqlExpr
)
==
0
)
{
// exists, not added it,
const
char
*
msg1
=
"invalid sql expression in having"
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
int32_t
functionId
=
pSqlExpr
->
functionId
;
if
(
pSqlExpr
->
Expr
.
paramList
==
NULL
)
{
index
.
columnIndex
=
0
;
index
.
tableIndex
=
0
;
}
else
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pSqlExpr
->
Expr
.
paramList
,
0
);
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
columnName
;
getColumnIndexByName
(
pToken
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
}
*
pExpr
=
NULL
;
size_t
nx
=
tscNumOfExprs
(
pQueryInfo
);
size_t
numOfNodeInSel
=
tscNumOfExprs
(
pQueryInfo
);
for
(
int32_t
k
=
0
;
k
<
numOfNodeInSel
;
++
k
)
{
SExprInfo
*
pExpr1
=
tscExprGet
(
pQueryInfo
,
k
);
// parameters is needed for functions
if
(
pSqlExpr
->
Expr
.
paramList
==
NULL
&&
pSqlExpr
->
functionId
!=
TSDB_FUNC_COUNT
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pExpr1
->
base
.
functionId
!=
functionId
)
{
continue
;
}
tSqlExprItem
*
pParam
=
NULL
;
SSchema
schema
=
{
0
};
if
(
pExpr1
->
base
.
colInfo
.
colIndex
!=
index
.
columnIndex
)
{
continue
;
}
if
(
pSqlExpr
->
Expr
.
paramList
!=
NULL
)
{
pParam
=
taosArrayGet
(
pSqlExpr
->
Expr
.
paramList
,
0
)
;
SStrToken
*
pToken
=
&
pParam
->
pNode
->
ColumnName
.
name
;
++
pQueryInfo
->
havingFieldNum
;
*
pExpr
=
pExpr1
;
break
;
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
getColumnIndexByName
(
pToken
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
schema
=
*
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
index
.
columnIndex
);
}
else
{
schema
=
(
SSchema
)
{.
colId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
,
.
bytes
=
TSDB_KEYSIZE
};
}
assert
(
*
pExpr
!=
NULL
);
for
(
int32_t
i
=
0
;
i
<
nx
;
++
i
)
{
SExprInfo
*
pExprInfo
=
tscExprGet
(
pQueryInfo
,
i
);
if
(
pExprInfo
->
base
.
functionId
==
pSqlExpr
->
functionId
&&
pExprInfo
->
base
.
colInfo
.
colId
==
schema
.
colId
)
{
++
pQueryInfo
->
havingFieldNum
;
*
pExpr
=
pExprInfo
;
return
TSDB_CODE_SUCCESS
;
}
}
// size_t num = taosArrayGetSize(pSelectNodeList);
// for(int32_t i = 0; i < num; ++i) {
// tSqlExprItem* pItem = taosArrayGet(pSelectNodeList, i);
//
// if (tSqlExprCompare(pItem->pNode, pSqlExpr) == 0) { // exists, not added it,
//
// SColumnIndex index = COLUMN_INDEX_INITIALIZER;
// int32_t functionId = pSqlExpr->functionId;
// if (pSqlExpr->Expr.paramList == NULL) {
// index.columnIndex = 0;
// index.tableIndex = 0;
// } else {
// tSqlExprItem* pParamElem = taosArrayGet(pSqlExpr->Expr.paramList, 0);
// SStrToken* pToken = &pParamElem->pNode->ColumnName.name;
// getColumnIndexByName(pToken, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd));
// }
//
// size_t numOfNodeInSel = tscNumOfExprs(pQueryInfo);
// for(int32_t k = 0; k < numOfNodeInSel; ++k) {
// SExprInfo* pExpr1 = tscExprGet(pQueryInfo, k);
//
// if (pExpr1->base.functionId != functionId) {
// continue;
// }
//
// if (pExpr1->base.colInfo.colIndex != index.columnIndex) {
// continue;
// }
//
// ++pQueryInfo->havingFieldNum;
// *pExpr = pExpr1;
// break;
// }
//
// assert(*pExpr != NULL);
// return TSDB_CODE_SUCCESS;
// }
// }
tSqlExprItem
item
=
{.
pNode
=
pSqlExpr
,
.
aliasName
=
NULL
,
.
distinct
=
false
};
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
...
...
@@ -7430,13 +7469,13 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelectNode
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pExpr1
->
tokenId
==
TK_ID
&&
(
pExpr1
->
columnName
.
z
==
NULL
&&
pExpr1
->
columnN
ame
.
n
==
0
))
{
if
(
pExpr1
->
tokenId
==
TK_ID
&&
(
pExpr1
->
ColumnName
.
name
.
z
==
NULL
&&
pExpr1
->
ColumnName
.
n
ame
.
n
==
0
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pExpr1
->
tokenId
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
((
getColumnIndexByName
(
&
pExpr1
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
if
((
getColumnIndexByName
(
&
pExpr1
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -8207,7 +8246,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
}
}
else
if
(
pSqlExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
// column name, normal column arithmetic expression
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
int32_t
ret
=
getColumnIndexByName
(
&
pSqlExpr
->
columnN
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
int32_t
ret
=
getColumnIndexByName
(
&
pSqlExpr
->
ColumnName
.
n
ame
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
src/query/inc/qSqlparser.h
浏览文件 @
f8c3135f
...
...
@@ -244,7 +244,11 @@ typedef struct tSqlExpr {
}
Expr
;
uint32_t
functionId
;
// function id, todo remove it
SStrToken
columnName
;
// table column info
struct
{
SStrToken
name
;
SStrToken
stdName
;
}
ColumnName
;
// SStrToken columnName; // table column info
tVariant
value
;
// the use input value
SStrToken
exprToken
;
// original sql expr string
uint32_t
flags
;
// todo remove it
...
...
src/query/src/qSqlParser.c
浏览文件 @
f8c3135f
...
...
@@ -161,7 +161,7 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
// Here it must be the column name (tk_id) if it is not a number or string.
assert
(
optrType
==
TK_ID
||
optrType
==
TK_ALL
);
if
(
pToken
!=
NULL
)
{
pSqlExpr
->
columnN
ame
=
*
pToken
;
pSqlExpr
->
ColumnName
.
n
ame
=
*
pToken
;
}
pSqlExpr
->
tokenId
=
optrType
;
...
...
@@ -355,7 +355,7 @@ int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right) {
return
1
;
}
if
(
tStrTokenCompare
(
&
left
->
columnName
,
&
right
->
columnN
ame
))
{
if
(
tStrTokenCompare
(
&
left
->
ColumnName
.
name
,
&
right
->
ColumnName
.
n
ame
))
{
return
1
;
}
...
...
tests/script/general/parser/having.sim
浏览文件 @
f8c3135f
...
...
@@ -1835,5 +1835,8 @@ if $data04 != 1 then
endi
sql_error select top(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select count(*) from tb1 group by f1 having last(*) > 0;
print bug for select count(*) k from tb1 group by f1 having k > 0;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录