Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9dd40166
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看板
未验证
提交
9dd40166
编写于
7月 07, 2021
作者:
H
Haojun Liao
提交者:
GitHub
7月 07, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6756 from taosdata/feature/query
[td-255] refactor.
上级
ce0a24ca
e7cad3db
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
302 addition
and
210 deletion
+302
-210
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+216
-133
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+12
-11
src/common/inc/tname.h
src/common/inc/tname.h
+1
-1
src/common/src/tglobal.c
src/common/src/tglobal.c
+9
-9
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-1
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+18
-16
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+9
-7
src/query/inc/sql.y
src/query/inc/sql.y
+1
-1
src/query/src/qPlan.c
src/query/src/qPlan.c
+2
-1
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+27
-27
src/query/src/sql.c
src/query/src/sql.c
+1
-1
src/util/src/tlog.c
src/util/src/tlog.c
+1
-1
tests/script/general/parser/having.sim
tests/script/general/parser/having.sim
+3
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
9dd40166
...
...
@@ -187,7 +187,7 @@ int32_t tscGetResRowLength(SArray* pExprList);
SExprInfo
*
tscExprInsert
(
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
resColId
,
int16_t
interSize
,
bool
isTagCol
);
SExprInfo
*
tscExprCreate
(
S
QueryInfo
*
pQuery
Info
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
SExprInfo
*
tscExprCreate
(
S
TableMetaInfo
*
pTableMeta
Info
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
resColId
,
int16_t
interSize
,
int32_t
colType
);
void
tscExprAddParams
(
SSqlExpr
*
pExpr
,
char
*
argument
,
int32_t
type
,
int32_t
bytes
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
9dd40166
...
...
@@ -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"
...
...
@@ -64,7 +66,7 @@ static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
static
char
*
getAccountId
(
SSqlObj
*
pSql
);
static
int
convertTimestampStrToInt64
(
tVariant
*
pVar
,
int32_t
precision
);
static
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
d
e
st
,
int16_t
colType
,
uint8_t
precision
);
static
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dst
,
int16_t
colType
,
uint8_t
precision
);
static
bool
has
(
SArray
*
pFieldList
,
int32_t
startIdx
,
const
char
*
name
);
static
char
*
cloneCurrentDBName
(
SSqlObj
*
pSql
);
...
...
@@ -79,7 +81,7 @@ static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int3
static
int32_t
insertResultField
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
SColumnList
*
pIdList
,
int16_t
bytes
,
int8_t
type
,
char
*
fieldName
,
SExprInfo
*
pSqlExpr
);
static
uint8_t
convert
Opt
r
(
SStrToken
*
pToken
);
static
uint8_t
convert
RelationalOperato
r
(
SStrToken
*
pToken
);
static
int32_t
validateSelectNodeList
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelNodeList
,
bool
isSTable
,
bool
joinQuery
,
bool
timeWindowQuery
);
...
...
@@ -92,7 +94,7 @@ static int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCm
static
int32_t
validateIntervalNode
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
);
static
int32_t
parseIntervalOffset
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SStrToken
*
offsetToken
);
static
int32_t
parseSlidingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SStrToken
*
pSliding
);
static
int32_t
validateStateWindowNode
(
SSqlCmd
*
p
Sql
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
,
bool
isStable
);
static
int32_t
validateStateWindowNode
(
SSqlCmd
*
p
Cmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
,
bool
isStable
);
static
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
);
...
...
@@ -132,6 +134,7 @@ static int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSql
static
int32_t
doCheckForCreateFromStable
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForStream
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
validateSqlNode
(
SSqlObj
*
pSql
,
SSqlNode
*
pSqlNode
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
exprTreeFromSqlExpr
(
SSqlCmd
*
pCmd
,
tExprNode
**
pExpr
,
const
tSqlExpr
*
pSqlExpr
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
,
uint64_t
*
uid
);
static
bool
validateDebugFlag
(
int32_t
v
);
static
int32_t
checkQueryRangeForFill
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
...
...
@@ -147,7 +150,7 @@ int16_t getNewResColId(SSqlCmd* pCmd) {
}
// serialize expr in exprlist to binary
// format
e
"type | size | value"
// format "type | size | value"
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dst
,
int16_t
colType
,
uint8_t
precision
)
{
bool
ret
=
false
;
if
(
!
pList
||
pList
->
size
<=
0
||
colType
<
0
)
{
...
...
@@ -171,7 +174,7 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType,
tSqlExpr
*
pSub
=
((
tSqlExprItem
*
)(
taosArrayGet
(
pList
,
i
)))
->
pNode
;
tVariant
*
var
=
&
pSub
->
value
;
// check all the
t
oken type in expr list same or not
// check all the
exprT
oken type in expr list same or not
if
(
firstVarType
!=
var
->
nType
)
{
break
;
}
...
...
@@ -238,7 +241,7 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType,
}
static
uint8_t
convert
Opt
r
(
SStrToken
*
pToken
)
{
static
uint8_t
convert
RelationalOperato
r
(
SStrToken
*
pToken
)
{
switch
(
pToken
->
type
)
{
case
TK_LT
:
return
TSDB_RELATION_LESS
;
...
...
@@ -753,6 +756,8 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSqlNode
*
pSqlNode
=
taosArrayGetP
(
pInfo
->
list
,
i
);
tscTrace
(
"%p start to parse %dth subclause, total:%"
PRIzu
,
pSql
,
i
,
size
);
// normalizeSqlNode(pSqlNode); // normalize the column name in each function
if
((
code
=
validateSqlNode
(
pSql
,
pSqlNode
,
pQueryInfo
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -1622,8 +1627,8 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
TSDB_FUNC_ARITHM
,
&
index
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
),
getNewResColId
(
pCmd
),
sizeof
(
double
),
false
);
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
pItem
->
pNode
->
t
oken
.
z
;
size_t
len
=
MIN
(
sizeof
(
pExpr
->
base
.
aliasName
),
pItem
->
pNode
->
t
oken
.
n
+
1
);
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
pItem
->
pNode
->
exprT
oken
.
z
;
size_t
len
=
MIN
(
sizeof
(
pExpr
->
base
.
aliasName
),
pItem
->
pNode
->
exprT
oken
.
n
+
1
);
tstrncpy
(
pExpr
->
base
.
aliasName
,
name
,
len
);
tExprNode
*
pNode
=
NULL
;
...
...
@@ -1835,7 +1840,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
int32_t
type
=
pItem
->
pNode
->
type
;
if
(
type
==
SQL_NODE_SQLFUNCTION
)
{
pItem
->
pNode
->
functionId
=
isValidFunction
(
pItem
->
pNode
->
operand
.
z
,
pItem
->
pNode
->
operand
.
n
);
pItem
->
pNode
->
functionId
=
isValidFunction
(
pItem
->
pNode
->
Expr
.
operand
.
z
,
pItem
->
pNode
->
Expr
.
operand
.
n
);
if
(
pItem
->
pNode
->
functionId
<
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
...
...
@@ -1868,6 +1873,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
if
(
!
isValidDistinctSql
(
pQueryInfo
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
pQueryInfo
->
distinctTag
=
true
;
}
...
...
@@ -1983,8 +1989,8 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
}
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
)
{
const
char
*
msg0
=
"invalid column name"
;
const
char
*
msg1
=
"tag for normal table query is not allowed"
;
const
char
*
msg2
=
"invalid column name"
;
int32_t
startPos
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
int32_t
optr
=
pItem
->
pNode
->
tokenId
;
...
...
@@ -1993,8 +1999,8 @@ 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
->
col
Info
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
0
);
if
(
getTableIndexByName
(
&
pItem
->
pNode
->
col
umnName
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
2
);
}
// all meters columns are required
...
...
@@ -2020,7 +2026,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
index
.
columnIndex
=
(
pQueryInfo
->
udColumnId
--
);
index
.
tableIndex
=
0
;
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
&
pItem
->
pNode
->
value
,
&
pItem
->
pNode
->
t
oken
,
pItem
->
aliasName
);
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
&
pItem
->
pNode
->
value
,
&
pItem
->
pNode
->
exprT
oken
,
pItem
->
aliasName
);
SExprInfo
*
pExpr
=
tscAddFuncInSelectClause
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
,
getNewResColId
(
pCmd
));
...
...
@@ -2030,8 +2036,8 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
}
else
if
(
optr
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
0
);
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
2
);
}
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
...
...
@@ -2130,8 +2136,8 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
tstrncpy
(
name
,
tmp
,
TSDB_COL_NAME_LEN
);
}
}
else
{
// use the user-input result column name
int32_t
len
=
MIN
(
pItem
->
pNode
->
t
oken
.
n
+
1
,
TSDB_COL_NAME_LEN
);
tstrncpy
(
name
,
pItem
->
pNode
->
t
oken
.
z
,
len
);
int32_t
len
=
MIN
(
pItem
->
pNode
->
exprT
oken
.
n
+
1
,
TSDB_COL_NAME_LEN
);
tstrncpy
(
name
,
pItem
->
pNode
->
exprT
oken
.
z
,
len
);
}
}
...
...
@@ -2185,26 +2191,25 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
switch
(
functionId
)
{
case
TSDB_FUNC_COUNT
:
{
/* more than one parameter for count() function */
if
(
pItem
->
pNode
->
pParam
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
1
)
{
if
(
pItem
->
pNode
->
Expr
.
paramList
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
SExprInfo
*
pExpr
=
NULL
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
pItem
->
pNode
->
pParam
!=
NULL
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
col
Info
;
if
(
pItem
->
pNode
->
Expr
.
paramList
!=
NULL
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
0
);
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
col
umnName
;
int16_t
tokenId
=
pParamElem
->
pNode
->
tokenId
;
if
((
pToken
->
z
==
NULL
||
pToken
->
n
==
0
)
&&
(
TK_INTEGER
!=
tokenId
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
// select count(table.*)
// select count(1)|count(2)
// 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
->
col
Info
;
SStrToken
tmpToken
=
pParamElem
->
pNode
->
col
umnName
;
if
(
getTableIndexByName
(
&
tmpToken
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
...
...
@@ -2261,6 +2266,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_SUM
:
case
TSDB_FUNC_AVG
:
case
TSDB_FUNC_RATE
:
...
...
@@ -2273,22 +2279,22 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case
TSDB_FUNC_STDDEV
:
case
TSDB_FUNC_LEASTSQR
:
{
// 1. valid the number of parameters
int32_t
numOfParams
=
(
pItem
->
pNode
->
pParam
==
NULL
)
?
0
:
(
int32_t
)
taosArrayGetSize
(
pItem
->
pNode
->
pParam
);
int32_t
numOfParams
=
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
)
?
0
:
(
int32_t
)
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
);
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
pParam
==
NULL
||
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
||
(
functionId
!=
TSDB_FUNC_LEASTSQR
&&
functionId
!=
TSDB_FUNC_DERIVATIVE
&&
numOfParams
!=
1
)
||
((
functionId
==
TSDB_FUNC_LEASTSQR
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
&&
numOfParams
!=
3
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
0
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ALL
&&
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
((
getColumnIndexByName
(
&
pParamElem
->
pNode
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
if
((
getColumnIndexByName
(
&
pParamElem
->
pNode
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2398,12 +2404,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pExpr
->
base
.
uid
);
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_FIRST
:
case
TSDB_FUNC_LAST
:
case
TSDB_FUNC_SPREAD
:
case
TSDB_FUNC_LAST_ROW
:
case
TSDB_FUNC_INTERP
:
{
bool
requireAllFields
=
(
pItem
->
pNode
->
pParam
==
NULL
);
bool
requireAllFields
=
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
);
// NOTE: has time range condition or normal column filter condition, the last_row query will be transferred to last query
SConvertFunc
cvtFunc
=
{.
originFuncId
=
functionId
,
.
execFuncId
=
functionId
};
...
...
@@ -2414,17 +2421,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
if
(
!
requireAllFields
)
{
if
(
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
<
1
)
{
if
(
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
<
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
>
1
&&
(
pItem
->
aliasName
!=
NULL
&&
strlen
(
pItem
->
aliasName
)
>
0
))
{
if
(
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
>
1
&&
(
pItem
->
aliasName
!=
NULL
&&
strlen
(
pItem
->
aliasName
)
>
0
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
/* in first/last function, multiple columns can be add to resultset */
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pItem
->
pNode
->
pParam
);
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
i
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
);
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
i
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ALL
&&
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2432,7 +2439,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
->
col
Info
;
SStrToken
tmpToken
=
pParamElem
->
pNode
->
col
umnName
;
if
(
getTableIndexByName
(
&
tmpToken
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
...
...
@@ -2453,7 +2460,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
}
else
{
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2467,8 +2474,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
index
.
columnIndex
);
bool
multiColOutput
=
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
>
1
;
setResultColName
(
name
,
pItem
,
cvtFunc
.
originFuncId
,
&
pParamElem
->
pNode
->
col
Info
,
multiColOutput
);
bool
multiColOutput
=
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
>
1
;
setResultColName
(
name
,
pItem
,
cvtFunc
.
originFuncId
,
&
pParamElem
->
pNode
->
col
umnName
,
multiColOutput
);
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
cvtFunc
,
name
,
colIndex
++
,
&
index
,
finalResult
)
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
@@ -2476,7 +2483,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
}
return
TSDB_CODE_SUCCESS
;
}
else
{
// select * from xxx
int32_t
numOfFields
=
0
;
...
...
@@ -2504,9 +2510,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
:
...
...
@@ -2514,18 +2519,18 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case
TSDB_FUNC_PERCT
:
case
TSDB_FUNC_APERCT
:
{
// 1. valid the number of parameters
if
(
pItem
->
pNode
->
pParam
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
2
)
{
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
2
)
{
/* no parameters or more than one parameter for function */
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
0
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2620,7 +2625,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
return
TSDB_CODE_SUCCESS
;
}
;
}
case
TSDB_FUNC_TID_TAG
:
{
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
...
...
@@ -2629,15 +2634,15 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
pParam
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
1
)
{
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSqlExprItem
*
pParamItem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
tSqlExprItem
*
pParamItem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
0
);
tSqlExpr
*
pParam
=
pParamItem
->
pNode
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pParam
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pParam
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2692,25 +2697,25 @@ 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
->
pParam
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
0
)
{
if
(
pItem
->
pNode
->
Expr
.
paramList
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
SColumnIndex
index
=
{.
tableIndex
=
0
,
.
columnIndex
=
0
,};
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
SSchema
s
=
{.
name
=
"block_dist"
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
int32_t
inter
=
0
;
int16_t
resType
=
0
;
int16_t
bytes
=
0
;
getResultDataInfo
(
TSDB_DATA_TYPE_INT
,
4
,
TSDB_FUNC_BLKINFO
,
0
,
&
resType
,
&
bytes
,
&
inter
,
0
,
0
);
s
.
bytes
=
bytes
;
s
.
type
=
(
uint8_t
)
resType
;
SExprInfo
*
pExpr
=
tscExprInsert
(
pQueryInfo
,
0
,
TSDB_FUNC_BLKINFO
,
&
index
,
resType
,
bytes
,
getNewResColId
(
pCmd
),
bytes
,
0
);
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
);
tstrncpy
(
pExpr
->
base
.
aliasName
,
s
.
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
SColumnList
ids
=
createColumnList
(
1
,
index
.
tableIndex
,
index
.
columnIndex
);
...
...
@@ -2744,8 +2749,8 @@ static SColumnList createColumnList(int32_t num, int16_t tableIndex, int32_t col
}
void
getColumnName
(
tSqlExprItem
*
pItem
,
char
*
resultFieldName
,
char
*
rawName
,
int32_t
nameLength
)
{
int32_t
len
=
((
int32_t
)
pItem
->
pNode
->
token
.
n
<
nameLength
)
?
(
int32_t
)
pItem
->
pNode
->
t
oken
.
n
:
nameLength
;
strncpy
(
rawName
,
pItem
->
pNode
->
t
oken
.
z
,
len
);
int32_t
len
=
((
int32_t
)
pItem
->
pNode
->
exprToken
.
n
<
nameLength
)
?
(
int32_t
)
pItem
->
pNode
->
exprT
oken
.
n
:
nameLength
;
strncpy
(
rawName
,
pItem
->
pNode
->
exprT
oken
.
z
,
len
);
if
(
pItem
->
aliasName
!=
NULL
)
{
int32_t
aliasNameLen
=
(
int32_t
)
strlen
(
pItem
->
aliasName
);
...
...
@@ -3368,7 +3373,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
// TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd
}
else
if
(
pExpr
->
tokenId
==
TK_IN
)
{
tVariant
*
pVal
;
if
(
pRight
->
tokenId
!=
TK_SET
||
!
serializeExprListToVariant
(
pRight
->
pParam
,
&
pVal
,
colType
,
timePrecision
))
{
if
(
pRight
->
tokenId
!=
TK_SET
||
!
serializeExprListToVariant
(
pRight
->
Expr
.
paramList
,
&
pVal
,
colType
,
timePrecision
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
pColumnFilter
->
pz
=
(
int64_t
)
calloc
(
1
,
pVal
->
nLen
+
1
);
...
...
@@ -3455,7 +3460,7 @@ typedef struct SCondExpr {
static
int32_t
getTimeRange
(
STimeWindow
*
win
,
tSqlExpr
*
pRight
,
int32_t
optr
,
int16_t
timePrecision
);
static
int32_t
tablenameListToString
(
tSqlExpr
*
pExpr
,
SStringBuilder
*
sb
)
{
SArray
*
pList
=
pExpr
->
pParam
;
SArray
*
pList
=
pExpr
->
Expr
.
paramList
;
int32_t
size
=
(
int32_t
)
taosArrayGetSize
(
pList
);
if
(
size
<=
0
)
{
...
...
@@ -3583,7 +3588,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
tSqlExpr
*
pLeft
=
pTableCond
->
pLeft
;
tSqlExpr
*
pRight
=
pTableCond
->
pRight
;
if
(
!
isTablenameToken
(
&
pLeft
->
col
Info
))
{
if
(
!
isTablenameToken
(
&
pLeft
->
col
umnName
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3620,7 +3625,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
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3649,7 +3654,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -3682,7 +3687,7 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS
int16_t
leftIdx
=
index
.
tableIndex
;
index
=
(
SColumnIndex
)
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
pRight
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pRight
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -3752,7 +3757,7 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQuer
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3782,7 +3787,7 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQuer
// sql function list in selection clause.
// Append the sqlExpr into exprList of pQueryInfo structure sequentially
pExpr
->
functionId
=
isValidFunction
(
pExpr
->
operand
.
z
,
pExpr
->
operand
.
n
);
pExpr
->
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
pExpr
->
functionId
<
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -3948,7 +3953,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
SColumnIndex
rightIndex
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pRight
->
col
Info
,
pQueryInfo
,
&
rightIndex
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pRight
->
col
umnName
,
pQueryInfo
,
&
rightIndex
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
false
;
}
...
...
@@ -4034,7 +4039,7 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t
}
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
if
((
!
isTablenameToken
(
&
pLeft
->
col
Info
))
&&
!
IS_VAR_DATA_TYPE
(
pSchema
[
index
].
type
))
{
if
((
!
isTablenameToken
(
&
pLeft
->
col
umnName
))
&&
!
IS_VAR_DATA_TYPE
(
pSchema
[
index
].
type
))
{
return
invalidOperationMsg
(
msgBuf
,
msg2
);
}
}
...
...
@@ -4058,7 +4063,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
int32_t
ret
=
TSDB_CODE_SUCCESS
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pLeft
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pLeft
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -4101,7 +4106,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
int16_t
leftIdx
=
index
.
tableIndex
;
if
(
getColumnIndexByName
(
&
pRight
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pRight
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -4264,7 +4269,7 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSqlExpr** pExpr, SQueryInfo*
tSqlExpr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pLeft
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pLeft
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
...
...
@@ -4431,7 +4436,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
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
pExpr
->
pLeft
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -4514,7 +4519,7 @@ static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SQueryInfo* pQueryInf
if (QUERY_IS_JOIN_QUERY(pQueryInfo->type) && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(pCmd, &pCondExpr->pJoinExpr->pLeft->
colInfo
, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
if (getColumnIndexByName(pCmd, &pCondExpr->pJoinExpr->pLeft->
ColName
, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
tscError("%p: invalid column name (left)", pQueryInfo);
}
...
...
@@ -4524,7 +4529,7 @@ static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SQueryInfo* pQueryInf
SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
tscColumnListInsert(pTableMetaInfo->tagColList, &index, &pSchema[index.columnIndex]);
if (getColumnIndexByName(pCmd, &pCondExpr->pJoinExpr->pRight->
colInfo
, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
if (getColumnIndexByName(pCmd, &pCondExpr->pJoinExpr->pRight->
ColName
, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
tscError("%p: invalid column name (right)", pQueryInfo);
}
...
...
@@ -6645,9 +6650,9 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
bool
server_status
=
false
;
tSqlExprItem
*
pExprItem
=
taosArrayGet
(
pExprList
,
0
);
tSqlExpr
*
pExpr
=
pExprItem
->
pNode
;
if
(
pExpr
->
operand
.
z
==
NULL
)
{
if
(
pExpr
->
Expr
.
operand
.
z
==
NULL
)
{
//handle 'select 1'
if
(
pExpr
->
token
.
n
==
1
&&
0
==
strncasecmp
(
pExpr
->
t
oken
.
z
,
"1"
,
1
))
{
if
(
pExpr
->
exprToken
.
n
==
1
&&
0
==
strncasecmp
(
pExpr
->
exprT
oken
.
z
,
"1"
,
1
))
{
server_status
=
true
;
}
else
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
...
...
@@ -6665,8 +6670,8 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
index
=
2
;
}
else
{
for
(
int32_t
i
=
0
;
i
<
tListLen
(
functionsInfo
);
++
i
)
{
if
(
strncasecmp
(
functionsInfo
[
i
].
name
,
pExpr
->
t
oken
.
z
,
functionsInfo
[
i
].
len
)
==
0
&&
functionsInfo
[
i
].
len
==
pExpr
->
t
oken
.
n
)
{
if
(
strncasecmp
(
functionsInfo
[
i
].
name
,
pExpr
->
exprT
oken
.
z
,
functionsInfo
[
i
].
len
)
==
0
&&
functionsInfo
[
i
].
len
==
pExpr
->
exprT
oken
.
n
)
{
index
=
i
;
break
;
}
...
...
@@ -7262,48 +7267,80 @@ 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
;
int32_t
tscGetExprFilters
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pSelectNodeList
,
tSqlExpr
*
pSqlExpr
,
SExprInfo
**
pExpr
)
{
const
char
*
msg1
=
"invalid sql expression in having"
;
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,
*
pExpr
=
NULL
;
size_t
nx
=
tscNumOfExprs
(
pQueryInfo
);
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
int32_t
functionId
=
pSqlExpr
->
functionId
;
if
(
pSqlExpr
->
pParam
==
NULL
)
{
index
.
columnIndex
=
0
;
index
.
tableIndex
=
0
;
}
else
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pSqlExpr
->
pParam
,
0
);
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
colInfo
;
getColumnIndexByName
(
pToken
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
// parameters is needed for functions
if
(
pSqlExpr
->
Expr
.
paramList
==
NULL
&&
pSqlExpr
->
functionId
!=
TSDB_FUNC_COUNT
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
size_t
numOfNodeInSel
=
tscNumOfExprs
(
pQueryInfo
);
for
(
int32_t
k
=
0
;
k
<
numOfNodeInSel
;
++
k
)
{
SExprInfo
*
pExpr1
=
tscExprGet
(
pQueryInfo
,
k
);
tSqlExprItem
*
pParam
=
NULL
;
SSchema
schema
=
{
0
};
if
(
pExpr1
->
base
.
functionId
!=
functionId
)
{
continue
;
}
if
(
pSqlExpr
->
Expr
.
paramList
!=
NULL
)
{
pParam
=
taosArrayGet
(
pSqlExpr
->
Expr
.
paramList
,
0
)
;
SStrToken
*
pToken
=
&
pParam
->
pNode
->
columnName
;
if
(
pExpr1
->
base
.
colInfo
.
colIndex
!=
index
.
columnIndex
)
{
continue
;
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
};
}
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
=
pExpr1
;
break
;
}
assert
(
*
pExpr
!=
NULL
);
*
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;
// 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
);
...
...
@@ -7447,10 +7484,10 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelectNode
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pLeft
->
pParam
)
{
size_t
size
=
taosArrayGetSize
(
pLeft
->
pParam
);
if
(
pLeft
->
Expr
.
paramList
)
{
size_t
size
=
taosArrayGetSize
(
pLeft
->
Expr
.
paramList
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
tSqlExprItem
*
pParamItem
=
taosArrayGet
(
pLeft
->
pParam
,
i
);
tSqlExprItem
*
pParamItem
=
taosArrayGet
(
pLeft
->
Expr
.
paramList
,
i
);
tSqlExpr
*
pExpr1
=
pParamItem
->
pNode
;
if
(
pExpr1
->
tokenId
!=
TK_ALL
&&
...
...
@@ -7461,13 +7498,13 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelectNode
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pExpr1
->
tokenId
==
TK_ID
&&
(
pExpr1
->
col
Info
.
z
==
NULL
&&
pExpr1
->
colInfo
.
n
==
0
))
{
if
(
pExpr1
->
tokenId
==
TK_ID
&&
(
pExpr1
->
col
umnName
.
z
==
NULL
&&
pExpr1
->
columnName
.
n
==
0
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pExpr1
->
tokenId
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
((
getColumnIndexByName
(
&
pExpr1
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
if
((
getColumnIndexByName
(
&
pExpr1
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7482,7 +7519,7 @@ int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelectNode
}
}
pLeft
->
functionId
=
isValidFunction
(
pLeft
->
operand
.
z
,
pLeft
->
operand
.
n
);
pLeft
->
functionId
=
isValidFunction
(
pLeft
->
Expr
.
operand
.
z
,
pLeft
->
Expr
.
operand
.
n
);
if
(
pLeft
->
functionId
<
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7905,11 +7942,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// parse the window_state
if
(
validateStateWindowNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// todo NOT support yet
for
(
int32_t
i
=
0
;
i
<
tscNumOfExprs
(
pQueryInfo
);
++
i
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
...
...
@@ -7960,6 +7992,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// parse the window_state
if
(
validateStateWindowNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
isTimeWindowQuery
(
pQueryInfo
))
{
// check if the first column of the nest query result is timestamp column
SColumn
*
pCol
=
taosArrayGetP
(
pQueryInfo
->
colList
,
0
);
...
...
@@ -7980,6 +8017,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
((
code
=
validateLimitNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
// set order by info
if
(
validateOrderbyNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
tscGetTableSchema
(
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
@@ -7991,6 +8032,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
// updateFunctionInterBuf(pQueryInfo, false);
updateLastScanOrderIfNeeded
(
pQueryInfo
);
if
((
code
=
validateFillNode
(
pCmd
,
pQueryInfo
,
pSqlNode
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
else
{
pQueryInfo
->
command
=
TSDB_SQL_SELECT
;
...
...
@@ -8036,10 +8081,12 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// parse the window_state
if
(
validateStateWindowNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
isSTable
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// set order by info
if
(
validateOrderbyNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
tscGetTableSchema
(
pTableMetaInfo
->
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -8206,7 +8253,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
pSqlExpr
->
token
.
z
,
pSqlExpr
->
t
oken
.
n
);
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
pSqlExpr
->
exprToken
.
z
,
pSqlExpr
->
exprT
oken
.
n
);
// set the input column data byte and type.
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
exprList
);
...
...
@@ -8228,7 +8275,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
->
col
Info
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
int32_t
ret
=
getColumnIndexByName
(
&
pSqlExpr
->
col
umnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -8272,7 +8319,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
serializeExprListToVariant
(
pSqlExpr
->
pParam
,
&
pVal
,
colType
,
tinfo
.
precision
)
==
false
)
{
if
(
serializeExprListToVariant
(
pSqlExpr
->
Expr
.
paramList
,
&
pVal
,
colType
,
tinfo
.
precision
)
==
false
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"not support filter expression"
);
}
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
...
...
@@ -8291,7 +8338,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
(
*
pExpr
)
->
_node
.
pRight
=
pRight
;
SStrToken
t
=
{.
type
=
pSqlExpr
->
tokenId
};
(
*
pExpr
)
->
_node
.
optr
=
convert
Opt
r
(
&
t
);
(
*
pExpr
)
->
_node
.
optr
=
convert
RelationalOperato
r
(
&
t
);
assert
((
*
pExpr
)
->
_node
.
optr
!=
0
);
...
...
@@ -8330,3 +8377,39 @@ bool hasNormalColumnFilter(SQueryInfo* pQueryInfo) {
return
false
;
}
#if 0
void normalizeSqlNode(SSqlNode* pSqlNode, const char* dbName) {
assert(pSqlNode != NULL);
if (pSqlNode->from->type == SQL_NODE_FROM_TABLELIST) {
// SRelElementPair *item = taosArrayGet(pSqlNode->from->list, 0);
// item->TableName.name;
}
// 1. pSqlNode->pSelNodeList
if (pSqlNode->pSelNodeList != NULL && taosArrayGetSize(pSqlNode->pSelNodeList) > 0) {
SArray* pSelNodeList = pSqlNode->pSelNodeList;
size_t numOfExpr = taosArrayGetSize(pSelNodeList);
for (int32_t i = 0; i < numOfExpr; ++i) {
tSqlExprItem* pItem = taosArrayGet(pSelNodeList, i);
int32_t type = pItem->pNode->type;
if (type == SQL_NODE_VALUE || type == SQL_NODE_EXPR) {
continue;
}
if (type == SQL_NODE_TABLE_COLUMN) {
}
}
}
// 2. pSqlNode->pWhere
// 3. pSqlNode->pHaving
// 4. pSqlNode->pSortOrder
// pSqlNode->from
}
#endif
src/client/src/tscUtil.c
浏览文件 @
9dd40166
...
...
@@ -661,7 +661,7 @@ void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBloc
setResRawPtrImpl
(
pRes
,
pInfo
,
i
,
convertNchar
);
/*
// generated the user-defined column result
if (pInfo->pExpr->pExpr == NULL && TSDB_COL_IS_UD_COL(pInfo->pExpr->base.
colInfo
.flag)) {
if (pInfo->pExpr->pExpr == NULL && TSDB_COL_IS_UD_COL(pInfo->pExpr->base.
ColName
.flag)) {
if (pInfo->pExpr->base.param[1].nType == TSDB_DATA_TYPE_NULL) {
setNullN(pRes->urow[i], pInfo->field.type, pInfo->field.bytes, (int32_t) pRes->numOfRows);
} else {
...
...
@@ -2096,10 +2096,8 @@ void tscFieldInfoCopy(SFieldInfo* pFieldInfo, const SFieldInfo* pSrc, const SArr
}
SExprInfo
*
tscExprCreate
(
S
QueryInfo
*
pQuery
Info
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
SExprInfo
*
tscExprCreate
(
S
TableMetaInfo
*
pTableMeta
Info
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
resColId
,
int16_t
interSize
,
int32_t
colType
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
pColIndex
->
tableIndex
);
SExprInfo
*
pExpr
=
calloc
(
1
,
sizeof
(
SExprInfo
));
if
(
pExpr
==
NULL
)
{
return
NULL
;
...
...
@@ -2123,19 +2121,20 @@ SExprInfo* tscExprCreate(SQueryInfo* pQueryInfo, int16_t functionId, SColumnInde
p
->
colBytes
=
TSDB_MAX_BINARY_LEN
;
p
->
colType
=
TSDB_DATA_TYPE_BINARY
;
}
else
{
int32_t
len
=
tListLen
(
p
->
colInfo
.
name
);
if
(
TSDB_COL_IS_TAG
(
colType
))
{
SSchema
*
pSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
p
->
colInfo
.
colId
=
pSchema
[
pColIndex
->
columnIndex
].
colId
;
p
->
colBytes
=
pSchema
[
pColIndex
->
columnIndex
].
bytes
;
p
->
colType
=
pSchema
[
pColIndex
->
columnIndex
].
type
;
tstrncpy
(
p
->
colInfo
.
name
,
pSchema
[
pColIndex
->
columnIndex
].
name
,
sizeof
(
p
->
colInfo
.
name
)
);
snprintf
(
p
->
colInfo
.
name
,
len
,
"%s.%s"
,
pTableMetaInfo
->
aliasName
,
pSchema
[
pColIndex
->
columnIndex
].
name
);
}
else
if
(
pTableMetaInfo
->
pTableMeta
!=
NULL
)
{
// in handling select database/version/server_status(), the pTableMeta is NULL
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pColIndex
->
columnIndex
);
p
->
colInfo
.
colId
=
pSchema
->
colId
;
p
->
colBytes
=
pSchema
->
bytes
;
p
->
colType
=
pSchema
->
type
;
tstrncpy
(
p
->
colInfo
.
name
,
pSchema
->
name
,
sizeof
(
p
->
colInfo
.
name
)
);
snprintf
(
p
->
colInfo
.
name
,
len
,
"%s.%s"
,
pTableMetaInfo
->
aliasName
,
pSchema
->
name
);
}
}
...
...
@@ -2161,14 +2160,16 @@ SExprInfo* tscExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t function
return
tscExprAppend
(
pQueryInfo
,
functionId
,
pColIndex
,
type
,
size
,
resColId
,
interSize
,
isTagCol
);
}
SExprInfo
*
pExpr
=
tscExprCreate
(
pQueryInfo
,
functionId
,
pColIndex
,
type
,
size
,
resColId
,
interSize
,
isTagCol
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
pColIndex
->
tableIndex
);
SExprInfo
*
pExpr
=
tscExprCreate
(
pTableMetaInfo
,
functionId
,
pColIndex
,
type
,
size
,
resColId
,
interSize
,
isTagCol
);
taosArrayInsert
(
pQueryInfo
->
exprList
,
index
,
&
pExpr
);
return
pExpr
;
}
SExprInfo
*
tscExprAppend
(
SQueryInfo
*
pQueryInfo
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
resColId
,
int16_t
interSize
,
bool
isTagCol
)
{
SExprInfo
*
pExpr
=
tscExprCreate
(
pQueryInfo
,
functionId
,
pColIndex
,
type
,
size
,
resColId
,
interSize
,
isTagCol
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
pColIndex
->
tableIndex
);
SExprInfo
*
pExpr
=
tscExprCreate
(
pTableMetaInfo
,
functionId
,
pColIndex
,
type
,
size
,
resColId
,
interSize
,
isTagCol
);
taosArrayPush
(
pQueryInfo
->
exprList
,
&
pExpr
);
return
pExpr
;
}
...
...
src/common/inc/tname.h
浏览文件 @
9dd40166
...
...
@@ -46,7 +46,7 @@ typedef struct SSqlExpr {
char
aliasName
[
TSDB_COL_NAME_LEN
];
// as aliasName
char
token
[
TSDB_COL_NAME_LEN
];
// original token
SColIndex
colInfo
;
uint64_t
uid
;
// refactor use the pointer
uint64_t
uid
;
//
table uid, todo
refactor use the pointer
int16_t
functionId
;
// function id in aAgg array
...
...
src/common/src/tglobal.c
浏览文件 @
9dd40166
...
...
@@ -180,15 +180,15 @@ int8_t tsEnableStream = 1;
int8_t
tsCompactMnodeWal
=
0
;
int8_t
tsPrintAuth
=
0
;
int8_t
tscEmbedded
=
0
;
char
configDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsVnodeDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsDnodeDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsMnodeDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsMnodeTmpDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsMnodeBakDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsDataDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsScriptDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tsTempDir
[
TSDB_FILENAME_LEN
]
=
"/tmp/"
;
char
configDir
[
PATH_MAX
]
=
{
0
};
char
tsVnodeDir
[
PATH_MAX
]
=
{
0
};
char
tsDnodeDir
[
PATH_MAX
]
=
{
0
};
char
tsMnodeDir
[
PATH_MAX
]
=
{
0
};
char
tsMnodeTmpDir
[
PATH_MAX
]
=
{
0
};
char
tsMnodeBakDir
[
PATH_MAX
]
=
{
0
};
char
tsDataDir
[
PATH_MAX
]
=
{
0
};
char
tsScriptDir
[
PATH_MAX
]
=
{
0
};
char
tsTempDir
[
PATH_MAX
]
=
"/tmp/"
;
int32_t
tsDiskCfgNum
=
0
;
...
...
src/inc/taosmsg.h
浏览文件 @
9dd40166
...
...
@@ -402,7 +402,7 @@ typedef struct SColIndex {
int16_t
colId
;
// column id
int16_t
colIndex
;
// column index in colList if it is a normal column or index in tagColList if a tag
uint16_t
flag
;
// denote if it is a tag or a normal column
char
name
[
TSDB_COL_NAME_LEN
];
// TODO remove it
char
name
[
TSDB_COL_NAME_LEN
+
TSDB_DB_NAME_LEN
+
1
];
}
SColIndex
;
typedef
struct
SColumnFilterInfo
{
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
9dd40166
...
...
@@ -1035,6 +1035,20 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
return
code
;
}
static
uint64_t
mnodeCreateSuperTableUid
()
{
int64_t
us
=
taosGetTimestampUs
();
uint64_t
x
=
(
us
&
((((
uint64_t
)
1
)
<<
40
)
-
1
));
x
=
x
<<
24
;
return
x
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
}
static
uint64_t
mnodeCreateTableUid
(
int32_t
vgId
,
int32_t
tid
)
{
uint64_t
uid
=
(((
uint64_t
)
vgId
)
<<
48
)
+
((((
uint64_t
)
tid
)
&
((
1ul
<<
24
)
-
1ul
))
<<
24
)
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
return
uid
;
}
static
int32_t
mnodeProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
==
NULL
)
return
TSDB_CODE_MND_APP_ERROR
;
...
...
@@ -1064,15 +1078,10 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
int64_t
us
=
taosGetTimestampUs
();
pStable
->
info
.
tableId
=
strdup
(
pCreate
->
tableName
);
pStable
->
info
.
type
=
TSDB_SUPER_TABLE
;
pStable
->
createdTime
=
taosGetTimestampMs
();
uint64_t
x
=
(
us
&
((((
uint64_t
)
1
)
<<
40
)
-
1
));
// todo refactor
x
=
x
<<
24
;
pStable
->
uid
=
x
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
pStable
->
uid
=
mnodeCreateSuperTableUid
();
pStable
->
sversion
=
0
;
pStable
->
tversion
=
0
;
pStable
->
numOfColumns
=
numOfColumns
;
...
...
@@ -2075,20 +2084,13 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
}
pTable
->
suid
=
pMsg
->
pSTable
->
uid
;
pTable
->
uid
=
(((
uint64_t
)
pTable
->
vgId
)
<<
48
)
+
((((
uint64_t
)
pTable
->
tid
)
&
((
1ul
<<
24
)
-
1ul
))
<<
24
)
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
pTable
->
uid
=
mnodeCreateTableUid
(
pTable
->
vgId
,
pTable
->
tid
);
pTable
->
superTable
=
pMsg
->
pSTable
;
}
else
{
if
(
pTable
->
info
.
type
==
TSDB_SUPER_TABLE
)
{
uint64_t
us
=
(
uint64_t
)
taosGetTimestampUs
();
uint64_t
x
=
(
us
&
((((
uint64_t
)
1
)
<<
40
)
-
1
));
x
=
x
<<
24
;
pTable
->
uid
=
x
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
pTable
->
uid
=
mnodeCreateSuperTableUid
();
}
else
{
pTable
->
uid
=
(((
uint64_t
)
pTable
->
vgId
)
<<
48
)
+
((((
uint64_t
)
pTable
->
tid
)
&
((
1ul
<<
24
)
-
1ul
))
<<
24
)
+
((
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
))
<<
8
)
+
(
taosRand
()
&
((
1ul
<<
8
)
-
1ul
));
pTable
->
uid
=
mnodeCreateTableUid
(
pTable
->
vgId
,
pTable
->
tid
);
}
pTable
->
sversion
=
0
;
...
...
src/query/inc/qSqlparser.h
浏览文件 @
9dd40166
...
...
@@ -237,18 +237,20 @@ typedef struct tSqlExpr {
uint16_t
type
;
// sql node type
uint32_t
tokenId
;
// TK_LE: less than(binary expr)
// the whole string of the function(col, param), while the function name is kept in token
// the whole string of the function(col, param), while the function name is kept in exprToken
struct
{
SStrToken
operand
;
uint32_t
functionId
;
// function id
struct
SArray
*
paramList
;
// function parameters list
}
Expr
;
SStrToken
colInfo
;
// table column info
uint32_t
functionId
;
// function id, todo remove it
SStrToken
columnName
;
// table column info
tVariant
value
;
// the use input value
SStrToken
token
;
// original sql expr string
uint32_t
flags
;
SStrToken
exprToken
;
// original sql expr string
uint32_t
flags
;
// todo remove it
struct
tSqlExpr
*
pLeft
;
// left child
struct
tSqlExpr
*
pRight
;
// right child
struct
SArray
*
pParam
;
// function parameters list
}
tSqlExpr
;
// used in select clause. select <SArray> from xxx
...
...
src/query/inc/sql.y
浏览文件 @
9dd40166
...
...
@@ -681,7 +681,7 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
%type expr {tSqlExpr*}
%destructor expr {tSqlExprDestroy($$);}
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->
token.z = X.z; A->t
oken.n = (Z.z - X.z + 1);}
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->
exprToken.z = X.z; A->exprT
oken.n = (Z.z - X.z + 1);}
expr(A) ::= ID(X). { A = tSqlExprCreateIdValue(&X, TK_ID);}
expr(A) ::= ID(X) DOT ID(Y). { X.n += (1+Y.n); A = tSqlExprCreateIdValue(&X, TK_ID);}
...
...
src/query/src/qPlan.c
浏览文件 @
9dd40166
...
...
@@ -127,7 +127,8 @@ static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo*
SColumn
*
pCol
=
taosArrayGetP
(
tableCols
,
i
);
SColumnIndex
index
=
{.
tableIndex
=
0
,
.
columnIndex
=
pCol
->
columnIndex
};
SExprInfo
*
p
=
tscExprCreate
(
pQueryInfo
,
TSDB_FUNC_PRJ
,
&
index
,
pCol
->
info
.
type
,
pCol
->
info
.
bytes
,
STableMetaInfo
*
pTableMetaInfo1
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
SExprInfo
*
p
=
tscExprCreate
(
pTableMetaInfo1
,
TSDB_FUNC_PRJ
,
&
index
,
pCol
->
info
.
type
,
pCol
->
info
.
bytes
,
pCol
->
info
.
colId
,
0
,
TSDB_COL_NORMAL
);
strncpy
(
p
->
base
.
aliasName
,
pSchema
[
pCol
->
columnIndex
].
name
,
tListLen
(
p
->
base
.
aliasName
));
...
...
src/query/src/qSqlParser.c
浏览文件 @
9dd40166
...
...
@@ -124,7 +124,7 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
tSqlExpr
*
pSqlExpr
=
calloc
(
1
,
sizeof
(
tSqlExpr
));
if
(
pToken
!=
NULL
)
{
pSqlExpr
->
t
oken
=
*
pToken
;
pSqlExpr
->
exprT
oken
=
*
pToken
;
}
if
(
optrType
==
TK_NULL
)
{
...
...
@@ -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
->
col
Info
=
*
pToken
;
pSqlExpr
->
col
umnName
=
*
pToken
;
}
pSqlExpr
->
tokenId
=
optrType
;
...
...
@@ -183,14 +183,14 @@ tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToke
tSqlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSqlExpr
));
pExpr
->
tokenId
=
optType
;
pExpr
->
type
=
SQL_NODE_SQLFUNCTION
;
pExpr
->
pParam
=
pParam
;
pExpr
->
Expr
.
paramList
=
pParam
;
int32_t
len
=
(
int32_t
)((
endToken
->
z
+
endToken
->
n
)
-
pFuncToken
->
z
);
pExpr
->
operand
=
(
*
pFuncToken
);
pExpr
->
Expr
.
operand
=
(
*
pFuncToken
);
pExpr
->
t
oken
.
n
=
len
;
pExpr
->
t
oken
.
z
=
pFuncToken
->
z
;
pExpr
->
t
oken
.
type
=
pFuncToken
->
type
;
pExpr
->
exprT
oken
.
n
=
len
;
pExpr
->
exprT
oken
.
z
=
pFuncToken
->
z
;
pExpr
->
exprT
oken
.
type
=
pFuncToken
->
type
;
return
pExpr
;
}
...
...
@@ -204,16 +204,16 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr
->
type
=
SQL_NODE_EXPR
;
if
(
pLeft
!=
NULL
&&
pRight
!=
NULL
&&
(
optrType
!=
TK_IN
))
{
char
*
endPos
=
pRight
->
token
.
z
+
pRight
->
t
oken
.
n
;
pExpr
->
token
.
z
=
pLeft
->
t
oken
.
z
;
pExpr
->
token
.
n
=
(
uint32_t
)(
endPos
-
pExpr
->
t
oken
.
z
);
pExpr
->
token
.
type
=
pLeft
->
t
oken
.
type
;
char
*
endPos
=
pRight
->
exprToken
.
z
+
pRight
->
exprT
oken
.
n
;
pExpr
->
exprToken
.
z
=
pLeft
->
exprT
oken
.
z
;
pExpr
->
exprToken
.
n
=
(
uint32_t
)(
endPos
-
pExpr
->
exprT
oken
.
z
);
pExpr
->
exprToken
.
type
=
pLeft
->
exprT
oken
.
type
;
}
if
((
pLeft
!=
NULL
&&
pRight
!=
NULL
)
&&
(
optrType
==
TK_PLUS
||
optrType
==
TK_MINUS
||
optrType
==
TK_STAR
||
optrType
==
TK_DIVIDE
||
optrType
==
TK_REM
))
{
/*
* if a
t
oken is noted as the TK_TIMESTAMP, the time precision is microsecond
* if a
exprT
oken is noted as the TK_TIMESTAMP, the time precision is microsecond
* Otherwise, the time precision is adaptive, determined by the time precision from databases.
*/
if
((
pLeft
->
tokenId
==
TK_INTEGER
&&
pRight
->
tokenId
==
TK_INTEGER
)
||
...
...
@@ -304,7 +304,7 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
tSqlExpr
*
pRSub
=
calloc
(
1
,
sizeof
(
tSqlExpr
));
pRSub
->
tokenId
=
TK_SET
;
// TODO refactor .....
pRSub
->
pParam
=
(
SArray
*
)
pRight
;
pRSub
->
Expr
.
paramList
=
(
SArray
*
)
pRight
;
pExpr
->
pRight
=
pRSub
;
}
else
{
...
...
@@ -346,8 +346,8 @@ int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right) {
||
(
left
->
pLeft
==
NULL
&&
right
->
pLeft
)
||
(
left
->
pRight
&&
right
->
pRight
==
NULL
)
||
(
left
->
pRight
==
NULL
&&
right
->
pRight
)
||
(
left
->
pParam
&&
right
->
pParam
==
NULL
)
||
(
left
->
pParam
==
NULL
&&
right
->
pParam
))
{
||
(
left
->
Expr
.
paramList
&&
right
->
Expr
.
paramList
==
NULL
)
||
(
left
->
Expr
.
paramList
==
NULL
&&
right
->
Expr
.
paramList
))
{
return
1
;
}
...
...
@@ -355,20 +355,20 @@ int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right) {
return
1
;
}
if
(
tStrTokenCompare
(
&
left
->
col
Info
,
&
right
->
colInfo
))
{
if
(
tStrTokenCompare
(
&
left
->
col
umnName
,
&
right
->
columnName
))
{
return
1
;
}
if
(
right
->
pParam
&&
left
->
pParam
)
{
size_t
size
=
taosArrayGetSize
(
right
->
pParam
);
if
(
left
->
pParam
&&
taosArrayGetSize
(
left
->
pParam
)
!=
size
)
{
if
(
right
->
Expr
.
paramList
&&
left
->
Expr
.
paramList
)
{
size_t
size
=
taosArrayGetSize
(
right
->
Expr
.
paramList
);
if
(
left
->
Expr
.
paramList
&&
taosArrayGetSize
(
left
->
Expr
.
paramList
)
!=
size
)
{
return
1
;
}
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
tSqlExprItem
*
pLeftElem
=
taosArrayGet
(
left
->
pParam
,
i
);
tSqlExprItem
*
pLeftElem
=
taosArrayGet
(
left
->
Expr
.
paramList
,
i
);
tSqlExpr
*
pSubLeft
=
pLeftElem
->
pNode
;
tSqlExprItem
*
pRightElem
=
taosArrayGet
(
right
->
pParam
,
i
);
tSqlExprItem
*
pRightElem
=
taosArrayGet
(
right
->
Expr
.
paramList
,
i
);
tSqlExpr
*
pSubRight
=
pRightElem
->
pNode
;
if
(
tSqlExprCompare
(
pSubLeft
,
pSubRight
))
{
...
...
@@ -401,8 +401,8 @@ tSqlExpr *tSqlExprClone(tSqlExpr *pSrc) {
pExpr
->
pRight
=
tSqlExprClone
(
pSrc
->
pRight
);
}
//we don't clone p
Param
now because clone is only used for between/and
assert
(
pSrc
->
pParam
==
NULL
);
//we don't clone p
aramList
now because clone is only used for between/and
assert
(
pSrc
->
Expr
.
paramList
==
NULL
);
return
pExpr
;
}
...
...
@@ -460,7 +460,7 @@ static void doDestroySqlExprNode(tSqlExpr *pExpr) {
tVariantDestroy
(
&
pExpr
->
value
);
}
tSqlExprListDestroy
(
pExpr
->
pParam
);
tSqlExprListDestroy
(
pExpr
->
Expr
.
paramList
);
free
(
pExpr
);
}
...
...
src/query/src/sql.c
浏览文件 @
9dd40166
...
...
@@ -2921,7 +2921,7 @@ static void yy_reduce(
{
yymsp
[
-
3
].
minor
.
yy414
.
limit
=
yymsp
[
0
].
minor
.
yy369
;
yymsp
[
-
3
].
minor
.
yy414
.
offset
=
yymsp
[
-
2
].
minor
.
yy369
;}
break
;
case
223
:
/* expr ::= LP expr RP */
{
yylhsminor
.
yy166
=
yymsp
[
-
1
].
minor
.
yy166
;
yylhsminor
.
yy166
->
token
.
z
=
yymsp
[
-
2
].
minor
.
yy0
.
z
;
yylhsminor
.
yy166
->
t
oken
.
n
=
(
yymsp
[
0
].
minor
.
yy0
.
z
-
yymsp
[
-
2
].
minor
.
yy0
.
z
+
1
);}
{
yylhsminor
.
yy166
=
yymsp
[
-
1
].
minor
.
yy166
;
yylhsminor
.
yy166
->
exprToken
.
z
=
yymsp
[
-
2
].
minor
.
yy0
.
z
;
yylhsminor
.
yy166
->
exprT
oken
.
n
=
(
yymsp
[
0
].
minor
.
yy0
.
z
-
yymsp
[
-
2
].
minor
.
yy0
.
z
+
1
);}
yymsp
[
-
2
].
minor
.
yy166
=
yylhsminor
.
yy166
;
break
;
case
224
:
/* expr ::= ID */
...
...
src/util/src/tlog.c
浏览文件 @
9dd40166
...
...
@@ -86,7 +86,7 @@ char tsLogDir[TSDB_FILENAME_LEN] = "/var/log/power";
#elif (_TD_TQ_ == true)
char
tsLogDir
[
TSDB_FILENAME_LEN
]
=
"/var/log/tq"
;
#else
char
tsLogDir
[
TSDB_FILENAME_LEN
]
=
"/var/log/taos"
;
char
tsLogDir
[
PATH_MAX
]
=
"/var/log/taos"
;
#endif
static
SLogObj
tsLogObj
=
{
.
fileNum
=
1
};
...
...
tests/script/general/parser/having.sim
浏览文件 @
9dd40166
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录