Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
a6d0bf4f
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a6d0bf4f
编写于
3月 14, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225]refactor
上级
45acc9d3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
489 addition
and
490 deletion
+489
-490
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+1
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+183
-174
src/client/src/tscServer.c
src/client/src/tscServer.c
+7
-7
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+92
-94
src/query/inc/sql.y
src/query/inc/sql.y
+64
-64
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+67
-72
src/query/src/sql.c
src/query/src/sql.c
+75
-78
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
a6d0bf4f
...
...
@@ -1359,7 +1359,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
}
}
}
else
{
SSqlInfo
SQLInfo
=
qS
QL
Parse
(
pSql
->
sqlstr
);
SSqlInfo
SQLInfo
=
qS
ql
Parse
(
pSql
->
sqlstr
);
ret
=
tscToSQLCmd
(
pSql
,
&
SQLInfo
);
if
(
ret
==
TSDB_CODE_TSC_INVALID_SQL
&&
pSql
->
parseRetry
==
0
&&
SQLInfo
.
type
==
TSDB_SQL_NULL
)
{
tscResetSqlCmd
(
pCmd
,
true
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
a6d0bf4f
...
...
@@ -77,29 +77,29 @@ static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SC
static
uint8_t
convertOptr
(
SStrToken
*
pToken
);
static
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
tSQLExprList
*
pSelection
,
bool
isSTable
,
bool
joinQuery
,
bool
timeWindowQuery
);
static
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
SArray
*
pSelectList
,
bool
isSTable
,
bool
joinQuery
,
bool
timeWindowQuery
);
static
bool
validateIpAddress
(
const
char
*
ip
,
size_t
size
);
static
bool
hasUnsupportFunctionsForSTableQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
bool
functionCompatibleCheck
(
SQueryInfo
*
pQueryInfo
,
bool
joinQuery
,
bool
interval
Query
);
static
bool
functionCompatibleCheck
(
SQueryInfo
*
pQueryInfo
,
bool
joinQuery
,
bool
tw
Query
);
static
int32_t
parseGroupbyClause
(
SQueryInfo
*
pQueryInfo
,
SArray
*
pList
,
SSqlCmd
*
pCmd
);
static
int32_t
parseIntervalClause
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
);
static
int32_t
parseIntervalClause
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
);
static
int32_t
parseIntervalOffset
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SStrToken
*
offsetToken
);
static
int32_t
parseSlidingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SStrToken
*
pSliding
);
static
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExprItem
*
pItem
);
static
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
**
pExpr
,
SSqlObj
*
pSql
);
static
int32_t
parseFillClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySQL
);
static
int32_t
parseOrderbyClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
,
SSchema
*
pSchema
);
static
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
**
pExpr
,
SSqlObj
*
pSql
);
static
int32_t
parseFillClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySQL
);
static
int32_t
parseOrderbyClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
,
SSchema
*
pSchema
);
static
int32_t
tsRewriteFieldNameIfNecessary
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
setAlterTableInfo
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
);
static
int32_t
validateSqlFunctionInStreamSql
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
validateFunctionsInIntervalOrGroupbyQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tS
QL
Expr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
);
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tS
ql
Expr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
);
static
int32_t
validateEp
(
char
*
ep
);
static
int32_t
validateDNodeConfig
(
SMiscInfo
*
pOptions
);
static
int32_t
validateLocalConfig
(
SMiscInfo
*
pOptions
);
...
...
@@ -110,15 +110,15 @@ static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
static
bool
hasTimestampForPointInterpQuery
(
SQueryInfo
*
pQueryInfo
);
static
bool
hasNormalColumnFilter
(
SQueryInfo
*
pQueryInfo
);
static
int32_t
parseLimitClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
SQueryS
QL
*
pQuerySql
,
SSqlObj
*
pSql
);
static
int32_t
parseLimitClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
SQueryS
qlNode
*
pQuerySqlNode
,
SSqlObj
*
pSql
);
static
int32_t
parseCreateDBOptions
(
SSqlCmd
*
pCmd
,
SCreateDbInfo
*
pCreateDbSql
);
static
int32_t
getColumnIndexByName
(
SSqlCmd
*
pCmd
,
const
SStrToken
*
pToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
getTableIndexByName
(
SStrToken
*
pToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
optrToString
(
tS
QL
Expr
*
pExpr
,
char
**
exprString
);
static
int32_t
optrToString
(
tS
ql
Expr
*
pExpr
,
char
**
exprString
);
static
int32_t
getTableIndexImpl
(
SStrToken
*
pTableToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
doFunctionsCompatibleCheck
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
);
static
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
);
static
int32_t
tscCheckCreateDbParams
(
SSqlCmd
*
pCmd
,
SCreateDbMsg
*
pCreate
);
static
SColumnList
getColumnList
(
int32_t
num
,
int16_t
tableIndex
,
int32_t
columnIndex
);
...
...
@@ -126,8 +126,8 @@ static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t column
static
int32_t
doCheckForCreateTable
(
SSqlObj
*
pSql
,
int32_t
subClauseIndex
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForCreateFromStable
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
doCheckForStream
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
do
CheckForQuery
(
SSqlObj
*
pSql
,
SQuerySQL
*
pQuerySql
,
int32_t
index
);
static
int32_t
exprTreeFromSqlExpr
(
SSqlCmd
*
pCmd
,
tExprNode
**
pExpr
,
const
tS
QL
Expr
*
pSqlExpr
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
,
int64_t
*
uid
);
static
int32_t
do
ValidateSqlNode
(
SSqlObj
*
pSql
,
SQuerySqlNode
*
pQuerySqlNode
,
int32_t
index
);
static
int32_t
exprTreeFromSqlExpr
(
SSqlCmd
*
pCmd
,
tExprNode
**
pExpr
,
const
tS
ql
Expr
*
pSqlExpr
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
,
int64_t
*
uid
);
static
bool
validateDebugFlag
(
int32_t
v
);
static
bool
isTimeWindowQuery
(
SQueryInfo
*
pQueryInfo
)
{
...
...
@@ -592,7 +592,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case
TSDB_SQL_CREATE_TABLE
:
{
SCreateTableS
QL
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
if
(
pCreateTable
->
type
==
TSQL_CREATE_TABLE
||
pCreateTable
->
type
==
TSQL_CREATE_STABLE
)
{
if
((
code
=
doCheckForCreateTable
(
pSql
,
0
,
pInfo
))
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -627,9 +627,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
assert
(
pCmd
->
numOfClause
==
pInfo
->
subclauseInfo
.
numOfClause
);
for
(
int32_t
i
=
pCmd
->
clauseIndex
;
i
<
pInfo
->
subclauseInfo
.
numOfClause
;
++
i
)
{
SQueryS
QL
*
pQuerySql
=
pInfo
->
subclauseInfo
.
pClause
[
i
];
SQueryS
qlNode
*
pQuerySqlNode
=
pInfo
->
subclauseInfo
.
pClause
[
i
];
tscTrace
(
"%p start to parse %dth subclause, total:%d"
,
pSql
,
i
,
pInfo
->
subclauseInfo
.
numOfClause
);
if
((
code
=
do
CheckForQuery
(
pSql
,
pQuerySql
,
i
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
do
ValidateSqlNode
(
pSql
,
pQuerySqlNode
,
i
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -771,7 +771,7 @@ static int32_t checkInvalidExprForTimeWindow(SSqlCmd* pCmd, SQueryInfo* pQueryIn
return
addPrimaryTsColumnForTimeWindowQuery
(
pQueryInfo
);
}
int32_t
parseIntervalClause
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
)
{
int32_t
parseIntervalClause
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
)
{
const
char
*
msg2
=
"interval cannot be less than 10 ms"
;
const
char
*
msg3
=
"sliding cannot be used without interval"
;
...
...
@@ -780,8 +780,8 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
pQuerySql
->
interval
.
interval
.
type
==
0
||
pQuerySql
->
interval
.
interval
.
n
==
0
)
{
if
(
pQuerySql
->
sliding
.
n
>
0
)
{
if
(
pQuerySql
Node
->
interval
==
NULL
)
{
if
(
pQuerySql
Node
->
sliding
!=
NULL
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -794,7 +794,7 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
}
// interval is not null
SStrToken
*
t
=
&
pQuerySql
->
interval
.
interval
;
SStrToken
*
t
=
&
pQuerySqlNode
->
interval
->
interval
;
if
(
parseNatualDuration
(
t
->
z
,
t
->
n
,
&
pQueryInfo
->
interval
.
interval
,
&
pQueryInfo
->
interval
.
intervalUnit
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -811,11 +811,11 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
}
}
if
(
parseIntervalOffset
(
pCmd
,
pQueryInfo
,
&
pQuerySql
->
interval
.
offset
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseIntervalOffset
(
pCmd
,
pQueryInfo
,
&
pQuerySql
Node
->
interval
->
offset
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
(
parseSlidingClause
(
pCmd
,
pQueryInfo
,
&
pQuerySql
->
sliding
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseSlidingClause
(
pCmd
,
pQueryInfo
,
pQuerySqlNode
->
sliding
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -823,19 +823,19 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
return
checkInvalidExprForTimeWindow
(
pCmd
,
pQueryInfo
);
}
int32_t
parseSessionClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
)
{
int32_t
parseSessionClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
)
{
const
char
*
msg1
=
"gap should be fixed time window"
;
const
char
*
msg2
=
"only one type time window allowed"
;
const
char
*
msg3
=
"invalid column name"
;
const
char
*
msg4
=
"invalid time window"
;
// no session window
if
(
pQuerySql
->
sessionVal
.
gap
.
n
==
0
||
pQuerySql
->
sessionVal
.
col
.
n
==
0
)
{
if
(
pQuerySql
Node
->
sessionVal
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
SStrToken
*
col
=
&
pQuerySql
->
sessionVal
.
col
;
SStrToken
*
gap
=
&
pQuerySql
->
sessionVal
.
gap
;
SStrToken
*
col
=
&
pQuerySql
Node
->
sessionVal
->
col
;
SStrToken
*
gap
=
&
pQuerySql
Node
->
sessionVal
->
gap
;
char
timeUnit
=
0
;
if
(
parseNatualDuration
(
gap
->
z
,
gap
->
n
,
&
pQueryInfo
->
sessionWindow
.
gap
,
&
timeUnit
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -1588,8 +1588,8 @@ bool isValidDistinctSql(SQueryInfo* pQueryInfo) {
return
false
;
}
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
tSQLExprList
*
pSelection
,
bool
isSTable
,
bool
joinQuery
,
bool
timeWindowQuery
)
{
assert
(
pSelect
ion
!=
NULL
&&
pCmd
!=
NULL
);
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
SArray
*
pSelectList
,
bool
isSTable
,
bool
joinQuery
,
bool
timeWindowQuery
)
{
assert
(
pSelect
List
!=
NULL
&&
pCmd
!=
NULL
);
const
char
*
msg2
=
"functions or others can not be mixed up"
;
const
char
*
msg3
=
"not support query expression"
;
...
...
@@ -1603,9 +1603,10 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
}
bool
hasDistinct
=
false
;
for
(
int32_t
i
=
0
;
i
<
pSelection
->
nExpr
;
++
i
)
{
int32_t
numOfExpr
=
taosArrayGetSize
(
pSelectList
);
for
(
int32_t
i
=
0
;
i
<
numOfExpr
;
++
i
)
{
int32_t
outputIndex
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
tSqlExprItem
*
pItem
=
&
pSelection
->
a
[
i
]
;
tSqlExprItem
*
pItem
=
taosArrayGet
(
pSelectList
,
i
)
;
if
(
hasDistinct
==
false
)
{
hasDistinct
=
(
pItem
->
distinct
==
true
);
...
...
@@ -1951,12 +1952,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
char
*
msg6
=
"function applied to tags not allowed"
;
const
char
*
msg7
=
"normal table can not apply this function"
;
const
char
*
msg8
=
"multi-columns selection does not support alias column name"
;
const
char
*
msg
10
=
"diff can no be applied to unsigned numeric type"
;
const
char
*
msg
9
=
"diff can no be applied to unsigned numeric type"
;
switch
(
functionId
)
{
case
TSDB_FUNC_COUNT
:
{
/* more than one parameter for count() function */
if
(
pItem
->
pNode
->
pParam
!=
NULL
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
1
)
{
if
(
pItem
->
pNode
->
pParam
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -1964,7 +1965,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
pItem
->
pNode
->
pParam
!=
NULL
)
{
tSqlExprItem
*
pParamElem
=
&
pItem
->
pNode
->
pParam
->
a
[
0
]
;
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
)
;
SStrToken
*
pToken
=
&
pParamElem
->
pNode
->
colInfo
;
int16_t
sqlOptr
=
pParamElem
->
pNode
->
tokenId
;
if
((
pToken
->
z
==
NULL
||
pToken
->
n
==
0
)
...
...
@@ -2059,13 +2060,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case
TSDB_FUNC_STDDEV
:
case
TSDB_FUNC_LEASTSQR
:
{
// 1. valid the number of parameters
if
(
pItem
->
pNode
->
pParam
==
NULL
||
(
functionId
!=
TSDB_FUNC_LEASTSQR
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
1
)
||
(
functionId
==
TSDB_FUNC_LEASTSQR
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
3
))
{
if
(
pItem
->
pNode
->
pParam
==
NULL
||
(
functionId
!=
TSDB_FUNC_LEASTSQR
&&
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
1
)
||
(
functionId
==
TSDB_FUNC_LEASTSQR
&&
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
3
))
{
/* no parameters or more than one parameter for function */
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSqlExprItem
*
pParamElem
=
&
(
pItem
->
pNode
->
pParam
->
a
[
0
]
);
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ALL
&&
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2087,7 +2088,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if
(
!
IS_NUMERIC_TYPE
(
colType
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
colType
)
&&
functionId
==
TSDB_FUNC_DIFF
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
10
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
9
);
}
int16_t
resultType
=
0
;
...
...
@@ -2167,17 +2168,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
if
(
!
requireAllFields
)
{
if
(
pItem
->
pNode
->
pParam
->
nExpr
<
1
)
{
if
(
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
<
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
pItem
->
pNode
->
pParam
->
nExpr
>
1
&&
(
pItem
->
aliasName
!=
NULL
&&
strlen
(
pItem
->
aliasName
)
>
0
))
{
if
(
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
>
1
&&
(
pItem
->
aliasName
!=
NULL
&&
strlen
(
pItem
->
aliasName
)
>
0
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
/* in first/last function, multiple columns can be add to resultset */
for
(
int32_t
i
=
0
;
i
<
pItem
->
pNode
->
pParam
->
nExpr
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
&
(
pItem
->
pNode
->
pParam
->
a
[
i
]
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
i
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ALL
&&
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
@@ -2220,7 +2221,7 @@ 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
=
pItem
->
pNode
->
pParam
->
nExpr
>
1
;
bool
multiColOutput
=
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
>
1
;
setResultColName
(
name
,
pItem
,
cvtFunc
.
originFuncId
,
&
pParamElem
->
pNode
->
colInfo
,
multiColOutput
);
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
cvtFunc
,
name
,
colIndex
+
i
,
&
index
,
finalResult
)
!=
0
)
{
...
...
@@ -2267,12 +2268,12 @@ 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
||
pItem
->
pNode
->
pParam
->
nExpr
!=
2
)
{
if
(
pItem
->
pNode
->
pParam
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
2
)
{
/* no parameters or more than one parameter for function */
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSqlExprItem
*
pParamElem
=
&
(
pItem
->
pNode
->
pParam
->
a
[
0
]
);
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2382,12 +2383,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
pParam
==
NULL
||
pItem
->
pNode
->
pParam
->
nExpr
!=
1
)
{
if
(
pItem
->
pNode
->
pParam
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSQLExpr
*
pParam
=
pItem
->
pNode
->
pParam
->
a
[
0
].
pNode
;
tSqlExprItem
*
pParamItem
=
taosArrayGet
(
pItem
->
pNode
->
pParam
,
0
);
tSqlExpr
*
pParam
=
pParamItem
->
pNode
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
pCmd
,
&
pParam
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
...
@@ -2445,7 +2447,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
case
TSDB_FUNC_BLKINFO
:
{
// no parameters or more than one parameter for function
if
(
pItem
->
pNode
->
pParam
!=
NULL
&&
pItem
->
pNode
->
pParam
->
nExpr
!=
0
)
{
if
(
pItem
->
pNode
->
pParam
!=
NULL
&&
taosArrayGetSize
(
pItem
->
pNode
->
pParam
)
!=
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -3070,10 +3072,10 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumn* pColumn) {
}
static
int32_t
doExtractColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SColumnFilterInfo
*
pColumnFilter
,
SColumnIndex
*
columnIndex
,
tS
QL
Expr
*
pExpr
)
{
SColumnIndex
*
columnIndex
,
tS
ql
Expr
*
pExpr
)
{
const
char
*
msg
=
"not supported filter condition"
;
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
columnIndex
->
tableIndex
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
columnIndex
->
columnIndex
);
...
...
@@ -3151,23 +3153,23 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
}
typedef
struct
SCondExpr
{
tS
QL
Expr
*
pTagCond
;
tS
QL
Expr
*
pTimewindow
;
tS
ql
Expr
*
pTagCond
;
tS
ql
Expr
*
pTimewindow
;
tS
QL
Expr
*
pColumnCond
;
tS
ql
Expr
*
pColumnCond
;
tS
QL
Expr
*
pTableCond
;
tS
ql
Expr
*
pTableCond
;
int16_t
relType
;
// relation between table name in expression and other tag
// filter condition expression, TK_AND or TK_OR
int16_t
tableCondIndex
;
tS
QL
Expr
*
pJoinExpr
;
// join condition
tS
ql
Expr
*
pJoinExpr
;
// join condition
bool
tsJoin
;
}
SCondExpr
;
static
int32_t
getTimeRange
(
STimeWindow
*
win
,
tS
QL
Expr
*
pRight
,
int32_t
optr
,
int16_t
timePrecision
);
static
int32_t
getTimeRange
(
STimeWindow
*
win
,
tS
ql
Expr
*
pRight
,
int32_t
optr
,
int16_t
timePrecision
);
static
int32_t
tSQLExprNodeToString
(
tS
QL
Expr
*
pExpr
,
char
**
str
)
{
static
int32_t
tSQLExprNodeToString
(
tS
ql
Expr
*
pExpr
,
char
**
str
)
{
if
(
pExpr
->
tokenId
==
TK_ID
)
{
// column name
strncpy
(
*
str
,
pExpr
->
colInfo
.
z
,
pExpr
->
colInfo
.
n
);
*
str
+=
pExpr
->
colInfo
.
n
;
...
...
@@ -3189,23 +3191,23 @@ static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, char** str) {
}
// pExpr->tokenId == 0 while handling "is null" query
static
bool
isExprLeafNode
(
tS
QL
Expr
*
pExpr
)
{
static
bool
isExprLeafNode
(
tS
ql
Expr
*
pExpr
)
{
return
(
pExpr
->
pRight
==
NULL
&&
pExpr
->
pLeft
==
NULL
)
&&
(
pExpr
->
tokenId
==
0
||
pExpr
->
tokenId
==
TK_ID
||
(
pExpr
->
tokenId
>=
TK_BOOL
&&
pExpr
->
tokenId
<=
TK_NCHAR
)
||
pExpr
->
tokenId
==
TK_SET
);
}
static
bool
isExprDirectParentOfLeafNode
(
tS
QL
Expr
*
pExpr
)
{
static
bool
isExprDirectParentOfLeafNode
(
tS
ql
Expr
*
pExpr
)
{
return
(
pExpr
->
pLeft
!=
NULL
&&
pExpr
->
pRight
!=
NULL
)
&&
(
isExprLeafNode
(
pExpr
->
pLeft
)
&&
isExprLeafNode
(
pExpr
->
pRight
));
}
static
int32_t
tSQLExprLeafToString
(
tS
QL
Expr
*
pExpr
,
bool
addParentheses
,
char
**
output
)
{
static
int32_t
tSQLExprLeafToString
(
tS
ql
Expr
*
pExpr
,
bool
addParentheses
,
char
**
output
)
{
if
(
!
isExprDirectParentOfLeafNode
(
pExpr
))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
tS
QL
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
tS
ql
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
if
(
addParentheses
)
{
*
(
*
output
)
=
'('
;
...
...
@@ -3227,7 +3229,7 @@ static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char**
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
optrToString
(
tS
QL
Expr
*
pExpr
,
char
**
exprString
)
{
static
int32_t
optrToString
(
tS
ql
Expr
*
pExpr
,
char
**
exprString
)
{
const
char
*
le
=
"<="
;
const
char
*
ge
=
">="
;
const
char
*
ne
=
"<>"
;
...
...
@@ -3288,25 +3290,29 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tablenameListToString
(
tSQLExpr
*
pExpr
,
SStringBuilder
*
sb
)
{
tSQLExprList
*
pList
=
pExpr
->
pParam
;
if
(
pList
->
nExpr
<=
0
)
{
static
int32_t
tablenameListToString
(
tSqlExpr
*
pExpr
,
SStringBuilder
*
sb
)
{
SArray
*
pList
=
pExpr
->
pParam
;
int32_t
size
=
(
int32_t
)
taosArrayGetSize
(
pList
);
if
(
size
<=
0
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
(
pList
->
nExpr
>
0
)
{
if
(
size
>
0
)
{
taosStringBuilderAppendStringLen
(
sb
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
);
}
for
(
int32_t
i
=
0
;
i
<
pList
->
nExpr
;
++
i
)
{
tSQLExpr
*
pSub
=
pList
->
a
[
i
].
pNode
;
taosStringBuilderAppendStringLen
(
sb
,
pSub
->
value
.
pz
,
pSub
->
value
.
nLen
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
tSqlExprItem
*
pSub
=
taosArrayGet
(
pList
,
i
);
tVariant
*
pVar
=
&
pSub
->
pNode
->
value
;
taosStringBuilderAppendStringLen
(
sb
,
pVar
->
pz
,
pVar
->
nLen
);
if
(
i
<
pList
->
nExpr
-
1
)
{
if
(
i
<
size
-
1
)
{
taosStringBuilderAppendString
(
sb
,
TBNAME_LIST_SEP
);
}
if
(
p
Sub
->
value
.
nLen
<=
0
||
!
tscValidateTableNameLength
(
pSub
->
value
.
nLen
))
{
if
(
p
Var
->
nLen
<=
0
||
!
tscValidateTableNameLength
(
pVar
->
nLen
))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
...
...
@@ -3314,7 +3320,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tablenameCondToString
(
tS
QL
Expr
*
pExpr
,
SStringBuilder
*
sb
)
{
static
int32_t
tablenameCondToString
(
tS
ql
Expr
*
pExpr
,
SStringBuilder
*
sb
)
{
taosStringBuilderAppendStringLen
(
sb
,
QUERY_COND_REL_PREFIX_LIKE
,
QUERY_COND_REL_PREFIX_LIKE_LEN
);
taosStringBuilderAppendString
(
sb
,
pExpr
->
value
.
pz
);
...
...
@@ -3328,7 +3334,7 @@ enum {
TSQL_EXPR_TBNAME
=
3
,
};
static
int32_t
extractColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
,
tS
QL
Expr
*
pExpr
,
int32_t
sqlOptr
)
{
static
int32_t
extractColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
,
tS
ql
Expr
*
pExpr
,
int32_t
sqlOptr
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
pIndex
->
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
...
...
@@ -3394,7 +3400,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
pIndex
,
pExpr
);
}
static
void
relToString
(
tS
QL
Expr
*
pExpr
,
char
**
str
)
{
static
void
relToString
(
tS
ql
Expr
*
pExpr
,
char
**
str
)
{
assert
(
pExpr
->
tokenId
==
TK_AND
||
pExpr
->
tokenId
==
TK_OR
);
const
char
*
or
=
"OR"
;
...
...
@@ -3411,7 +3417,7 @@ static void relToString(tSQLExpr* pExpr, char** str) {
}
UNUSED_FUNC
static
int32_t
getTagCondString
(
tS
QL
Expr
*
pExpr
,
char
**
str
)
{
static
int32_t
getTagCondString
(
tS
ql
Expr
*
pExpr
,
char
**
str
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3438,7 +3444,7 @@ static int32_t getTagCondString(tSQLExpr* pExpr, char** str) {
return
tSQLExprLeafToString
(
pExpr
,
true
,
str
);
}
static
int32_t
getTablenameCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pTableCond
,
SStringBuilder
*
sb
)
{
static
int32_t
getTablenameCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pTableCond
,
SStringBuilder
*
sb
)
{
const
char
*
msg0
=
"invalid table name list"
;
const
char
*
msg1
=
"not string following like"
;
...
...
@@ -3446,8 +3452,8 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
return
TSDB_CODE_SUCCESS
;
}
tS
QL
Expr
*
pLeft
=
pTableCond
->
pLeft
;
tS
QL
Expr
*
pRight
=
pTableCond
->
pRight
;
tS
ql
Expr
*
pLeft
=
pTableCond
->
pLeft
;
tS
ql
Expr
*
pRight
=
pTableCond
->
pRight
;
if
(
!
isTablenameToken
(
&
pLeft
->
colInfo
))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
...
...
@@ -3472,7 +3478,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
return
ret
;
}
static
int32_t
getColumnQueryCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
,
int32_t
relOptr
)
{
static
int32_t
getColumnQueryCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
,
int32_t
relOptr
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3494,7 +3500,7 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQ
}
}
static
int32_t
getJoinCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
)
{
static
int32_t
getJoinCondInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
)
{
const
char
*
msg1
=
"invalid join query condition"
;
const
char
*
msg2
=
"invalid table name in join query"
;
const
char
*
msg3
=
"type of join columns must be identical"
;
...
...
@@ -3552,7 +3558,7 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
validateSQLExpr
(
SSqlCmd
*
pCmd
,
tS
QL
Expr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
static
int32_t
validateSQLExpr
(
SSqlCmd
*
pCmd
,
tS
ql
Expr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
if
(
pExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
...
...
@@ -3628,12 +3634,12 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tS
QL
Expr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
)
{
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tS
ql
Expr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
tS
QL
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
ql
Expr
*
pLeft
=
pExpr
->
pLeft
;
uint64_t
uidLeft
=
0
;
uint64_t
uidRight
=
0
;
...
...
@@ -3649,7 +3655,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI
}
}
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
type
==
SQL_NODE_EXPR
)
{
int32_t
ret
=
validateArithmeticSQLExpr
(
pCmd
,
pRight
,
pQueryInfo
,
pList
,
type
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -3670,7 +3676,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI
return
TSDB_CODE_SUCCESS
;
}
static
bool
isValidExpr
(
tS
QLExpr
*
pLeft
,
tSQL
Expr
*
pRight
,
int32_t
optr
)
{
static
bool
isValidExpr
(
tS
qlExpr
*
pLeft
,
tSql
Expr
*
pRight
,
int32_t
optr
)
{
if
(
pLeft
==
NULL
||
(
pRight
==
NULL
&&
optr
!=
TK_IN
))
{
return
false
;
}
...
...
@@ -3698,9 +3704,9 @@ static bool isValidExpr(tSQLExpr* pLeft, tSQLExpr* pRight, int32_t optr) {
return
true
;
}
static
void
exchangeExpr
(
tS
QL
Expr
*
pExpr
)
{
tS
QL
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
static
void
exchangeExpr
(
tS
ql
Expr
*
pExpr
)
{
tS
ql
Expr
*
pLeft
=
pExpr
->
pLeft
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
tokenId
==
TK_ID
&&
(
pLeft
->
tokenId
==
TK_INTEGER
||
pLeft
->
tokenId
==
TK_FLOAT
||
pLeft
->
tokenId
==
TK_STRING
||
pLeft
->
tokenId
==
TK_BOOL
))
{
...
...
@@ -3733,14 +3739,14 @@ static void exchangeExpr(tSQLExpr* pExpr) {
}
}
static
bool
validateJoinExprNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
,
SColumnIndex
*
pLeftIndex
)
{
static
bool
validateJoinExprNode
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
,
SColumnIndex
*
pLeftIndex
)
{
const
char
*
msg1
=
"illegal column name"
;
const
char
*
msg2
=
"= is expected in join expression"
;
const
char
*
msg3
=
"join column must have same type"
;
const
char
*
msg4
=
"self join is not allowed"
;
const
char
*
msg5
=
"join table must be the same type(table to table, super table to super table)"
;
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
tokenId
!=
TK_ID
)
{
return
true
;
...
...
@@ -3784,7 +3790,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr
return
true
;
}
static
bool
validTableNameOptr
(
tS
QL
Expr
*
pExpr
)
{
static
bool
validTableNameOptr
(
tS
ql
Expr
*
pExpr
)
{
const
char
nameFilterOptr
[]
=
{
TK_IN
,
TK_LIKE
};
for
(
int32_t
i
=
0
;
i
<
tListLen
(
nameFilterOptr
);
++
i
)
{
...
...
@@ -3796,7 +3802,7 @@ static bool validTableNameOptr(tSQLExpr* pExpr) {
return
false
;
}
static
int32_t
setExprToCond
(
tS
QLExpr
**
parent
,
tSQL
Expr
*
pExpr
,
const
char
*
msg
,
int32_t
parentOptr
,
char
*
msgBuf
)
{
static
int32_t
setExprToCond
(
tS
qlExpr
**
parent
,
tSql
Expr
*
pExpr
,
const
char
*
msg
,
int32_t
parentOptr
,
char
*
msgBuf
)
{
if
(
*
parent
!=
NULL
)
{
if
(
parentOptr
==
TK_OR
&&
msg
!=
NULL
)
{
return
invalidSqlErrMsg
(
msgBuf
,
msg
);
...
...
@@ -3810,7 +3816,7 @@ static int32_t setExprToCond(tSQLExpr** parent, tSQLExpr* pExpr, const char* msg
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
handleExprInQueryCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
**
pExpr
,
SCondExpr
*
pCondExpr
,
static
int32_t
handleExprInQueryCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
**
pExpr
,
SCondExpr
*
pCondExpr
,
int32_t
*
type
,
int32_t
parentOptr
)
{
const
char
*
msg1
=
"table query cannot use tags filter"
;
const
char
*
msg2
=
"illegal column name"
;
...
...
@@ -3821,8 +3827,8 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
const
char
*
msg7
=
"only in/like allowed in filter table name"
;
const
char
*
msg8
=
"wildcard string should be less than 20 characters"
;
tS
QL
Expr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tS
QL
Expr
*
pRight
=
(
*
pExpr
)
->
pRight
;
tS
ql
Expr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tS
ql
Expr
*
pRight
=
(
*
pExpr
)
->
pRight
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
...
...
@@ -3933,7 +3939,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
return
ret
;
}
int32_t
getQueryCondExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
**
pExpr
,
SCondExpr
*
pCondExpr
,
int32_t
getQueryCondExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
**
pExpr
,
SCondExpr
*
pCondExpr
,
int32_t
*
type
,
int32_t
parentOptr
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3941,8 +3947,8 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
const
char
*
msg1
=
"query condition between different columns must use 'AND'"
;
tS
QL
Expr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tS
QL
Expr
*
pRight
=
(
*
pExpr
)
->
pRight
;
tS
ql
Expr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tS
ql
Expr
*
pRight
=
(
*
pExpr
)
->
pRight
;
if
(
!
isValidExpr
(
pLeft
,
pRight
,
(
*
pExpr
)
->
tokenId
))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
...
...
@@ -3981,7 +3987,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
return
handleExprInQueryCond
(
pCmd
,
pQueryInfo
,
pExpr
,
pCondExpr
,
type
,
parentOptr
);
}
static
void
doCompactQueryExpr
(
tS
QL
Expr
**
pExpr
)
{
static
void
doCompactQueryExpr
(
tS
ql
Expr
**
pExpr
)
{
if
(
*
pExpr
==
NULL
||
isExprDirectParentOfLeafNode
(
*
pExpr
))
{
return
;
}
...
...
@@ -3996,25 +4002,25 @@ static void doCompactQueryExpr(tSQLExpr** pExpr) {
if
((
*
pExpr
)
->
pLeft
==
NULL
&&
(
*
pExpr
)
->
pRight
==
NULL
&&
((
*
pExpr
)
->
tokenId
==
TK_OR
||
(
*
pExpr
)
->
tokenId
==
TK_AND
))
{
tSqlExpr
Node
Destroy
(
*
pExpr
);
tSqlExprDestroy
(
*
pExpr
);
*
pExpr
=
NULL
;
}
else
if
((
*
pExpr
)
->
pLeft
==
NULL
&&
(
*
pExpr
)
->
pRight
!=
NULL
)
{
tS
QL
Expr
*
tmpPtr
=
(
*
pExpr
)
->
pRight
;
tSqlExpr
Node
Destroy
(
*
pExpr
);
tS
ql
Expr
*
tmpPtr
=
(
*
pExpr
)
->
pRight
;
tSqlExprDestroy
(
*
pExpr
);
(
*
pExpr
)
=
tmpPtr
;
}
else
if
((
*
pExpr
)
->
pRight
==
NULL
&&
(
*
pExpr
)
->
pLeft
!=
NULL
)
{
tS
QL
Expr
*
tmpPtr
=
(
*
pExpr
)
->
pLeft
;
tSqlExpr
Node
Destroy
(
*
pExpr
);
tS
ql
Expr
*
tmpPtr
=
(
*
pExpr
)
->
pLeft
;
tSqlExprDestroy
(
*
pExpr
);
(
*
pExpr
)
=
tmpPtr
;
}
}
static
void
doExtractExprForSTable
(
SSqlCmd
*
pCmd
,
tS
QLExpr
**
pExpr
,
SQueryInfo
*
pQueryInfo
,
tSQL
Expr
**
pOut
,
int32_t
tableIndex
)
{
static
void
doExtractExprForSTable
(
SSqlCmd
*
pCmd
,
tS
qlExpr
**
pExpr
,
SQueryInfo
*
pQueryInfo
,
tSql
Expr
**
pOut
,
int32_t
tableIndex
)
{
if
(
isExprDirectParentOfLeafNode
(
*
pExpr
))
{
tS
QL
Expr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tS
ql
Expr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
pCmd
,
&
pLeft
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -4036,8 +4042,8 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo*
}
}
static
tS
QLExpr
*
extractExprForSTable
(
SSqlCmd
*
pCmd
,
tSQL
Expr
**
pExpr
,
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
)
{
tS
QL
Expr
*
pResExpr
=
NULL
;
static
tS
qlExpr
*
extractExprForSTable
(
SSqlCmd
*
pCmd
,
tSql
Expr
**
pExpr
,
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
)
{
tS
ql
Expr
*
pResExpr
=
NULL
;
if
(
*
pExpr
!=
NULL
)
{
doExtractExprForSTable
(
pCmd
,
pExpr
,
pQueryInfo
,
&
pResExpr
,
tableIndex
);
...
...
@@ -4061,7 +4067,7 @@ int tableNameCompar(const void* lhs, const void* rhs) {
}
static
int32_t
setTableCondForSTableQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
const
char
*
account
,
tS
QL
Expr
*
pExpr
,
int16_t
tableCondIndex
,
SStringBuilder
*
sb
)
{
tS
ql
Expr
*
pExpr
,
int16_t
tableCondIndex
,
SStringBuilder
*
sb
)
{
const
char
*
msg
=
"table name too long"
;
if
(
pExpr
==
NULL
)
{
...
...
@@ -4162,7 +4168,7 @@ static bool validateFilterExpr(SQueryInfo* pQueryInfo) {
return
true
;
}
static
int32_t
getTimeRangeFromExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
*
pExpr
)
{
static
int32_t
getTimeRangeFromExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
*
pExpr
)
{
const
char
*
msg0
=
"invalid timestamp"
;
const
char
*
msg1
=
"only one time stamp window allowed"
;
...
...
@@ -4187,7 +4193,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLE
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
tS
QL
Expr
*
pRight
=
pExpr
->
pRight
;
tS
ql
Expr
*
pRight
=
pExpr
->
pRight
;
STimeWindow
win
=
{.
skey
=
INT64_MIN
,
.
ekey
=
INT64_MAX
};
if
(
getTimeRange
(
&
win
,
pRight
,
pExpr
->
tokenId
,
tinfo
.
precision
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -4351,7 +4357,7 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
getTagQueryCondExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SCondExpr
*
pCondExpr
,
tS
QL
Expr
**
pExpr
)
{
static
int32_t
getTagQueryCondExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SCondExpr
*
pCondExpr
,
tS
ql
Expr
**
pExpr
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
if
(
pCondExpr
->
pTagCond
==
NULL
)
{
...
...
@@ -4359,7 +4365,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
}
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
tS
QL
Expr
*
p1
=
extractExprForSTable
(
pCmd
,
pExpr
,
pQueryInfo
,
i
);
tS
ql
Expr
*
p1
=
extractExprForSTable
(
pCmd
,
pExpr
,
pQueryInfo
,
i
);
if
(
p1
==
NULL
)
{
// no query condition on this table
continue
;
}
...
...
@@ -4414,7 +4420,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
return
ret
;
}
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tS
QL
Expr
**
pExpr
,
SSqlObj
*
pSql
)
{
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tS
ql
Expr
**
pExpr
,
SSqlObj
*
pSql
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4488,7 +4494,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
return
ret
;
}
int32_t
getTimeRange
(
STimeWindow
*
win
,
tS
QL
Expr
*
pRight
,
int32_t
optr
,
int16_t
timePrecision
)
{
int32_t
getTimeRange
(
STimeWindow
*
win
,
tS
ql
Expr
*
pRight
,
int32_t
optr
,
int16_t
timePrecision
)
{
// this is join condition, do nothing
if
(
pRight
->
tokenId
==
TK_ID
)
{
return
TSDB_CODE_SUCCESS
;
...
...
@@ -4608,7 +4614,7 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseFillClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySQL
)
{
int32_t
parseFillClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySQL
)
{
SArray
*
pFillToken
=
pQuerySQL
->
fillType
;
tVariantListItem
*
pItem
=
taosArrayGet
(
pFillToken
,
0
);
...
...
@@ -4730,7 +4736,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
}
}
int32_t
parseOrderbyClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
,
SSchema
*
pSchema
)
{
int32_t
parseOrderbyClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
,
SSchema
*
pSchema
)
{
const
char
*
msg0
=
"only support order by primary timestamp"
;
const
char
*
msg1
=
"invalid column name"
;
const
char
*
msg2
=
"order by primary timestamp or first tag in groupby clause allowed"
;
...
...
@@ -4745,11 +4751,11 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
pQueryInfo
->
order
.
orderColId
=
0
;
return
TSDB_CODE_SUCCESS
;
}
if
(
pQuerySql
->
pSortOrder
==
NULL
)
{
if
(
pQuerySql
Node
->
pSortOrder
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
SArray
*
pSortorder
=
pQuerySql
->
pSortOrder
;
SArray
*
pSortorder
=
pQuerySql
Node
->
pSortOrder
;
/*
* for table query, there is only one or none order option is allowed, which is the
...
...
@@ -4817,7 +4823,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
if
(
orderByTags
)
{
pQueryInfo
->
groupbyExpr
.
orderIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
0
);
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
0
);
pQueryInfo
->
groupbyExpr
.
orderType
=
p1
->
sortOrder
;
}
else
if
(
isTopBottomQuery
(
pQueryInfo
))
{
/* order of top/bottom query in interval is not valid */
...
...
@@ -4829,12 +4835,12 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
0
);
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
0
);
pQueryInfo
->
order
.
order
=
p1
->
sortOrder
;
pQueryInfo
->
order
.
orderColId
=
pSchema
[
index
.
columnIndex
].
colId
;
return
TSDB_CODE_SUCCESS
;
}
else
{
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
0
);
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
0
);
pQueryInfo
->
order
.
order
=
p1
->
sortOrder
;
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
...
...
@@ -4847,7 +4853,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
}
if
(
s
==
2
)
{
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
0
);
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
0
);
if
(
orderByTags
)
{
pQueryInfo
->
groupbyExpr
.
orderIndex
=
index
.
columnIndex
-
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
pQueryInfo
->
groupbyExpr
.
orderType
=
pItem
->
sortOrder
;
...
...
@@ -4856,7 +4862,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
pQueryInfo
->
order
.
orderColId
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
}
pItem
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
1
);
pItem
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
1
);
tVariant
*
pVar2
=
&
pItem
->
pVar
;
SStrToken
cname
=
{
pVar2
->
nLen
,
pVar2
->
nType
,
pVar2
->
pz
};
if
(
getColumnIndexByName
(
pCmd
,
&
cname
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -4891,13 +4897,13 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
0
);
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
0
);
pQueryInfo
->
order
.
order
=
pItem
->
sortOrder
;
pQueryInfo
->
order
.
orderColId
=
pSchema
[
index
.
columnIndex
].
colId
;
return
TSDB_CODE_SUCCESS
;
}
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
->
pSortOrder
,
0
);
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
Node
->
pSortOrder
,
0
);
pQueryInfo
->
order
.
order
=
pItem
->
sortOrder
;
}
...
...
@@ -5425,7 +5431,7 @@ bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo) {
return
(
pQueryInfo
->
window
.
skey
==
pQueryInfo
->
window
.
ekey
)
&&
(
pQueryInfo
->
window
.
skey
!=
0
);
}
int32_t
parseLimitClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
clauseIndex
,
SQueryS
QL
*
pQuerySql
,
SSqlObj
*
pSql
)
{
int32_t
parseLimitClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
clauseIndex
,
SQueryS
qlNode
*
pQuerySqlNode
,
SSqlObj
*
pSql
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
const
char
*
msg0
=
"soffset/offset can not be less than 0"
;
...
...
@@ -5433,9 +5439,9 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
const
char
*
msg2
=
"slimit/soffset can not apply to projection query"
;
// handle the limit offset value, validate the limit
pQueryInfo
->
limit
=
pQuerySql
->
limit
;
pQueryInfo
->
limit
=
*
pQuerySqlNode
->
limit
;
pQueryInfo
->
clauseLimit
=
pQueryInfo
->
limit
.
limit
;
pQueryInfo
->
slimit
=
pQuerySql
->
slimit
;
pQueryInfo
->
slimit
=
*
pQuerySqlNode
->
slimit
;
tscDebug
(
"%p limit:%"
PRId64
", offset:%"
PRId64
" slimit:%"
PRId64
", soffset:%"
PRId64
,
pSql
,
pQueryInfo
->
limit
.
limit
,
pQueryInfo
->
limit
.
offset
,
pQueryInfo
->
slimit
.
limit
,
pQueryInfo
->
slimit
.
offset
);
...
...
@@ -6094,17 +6100,20 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return
checkUpdateTagPrjFunctions
(
pQueryInfo
,
pCmd
);
}
}
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
QL
*
pQuerySql
)
{
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQueryS
qlNode
*
pQuerySqlNode
)
{
const
char
*
msg1
=
"only one expression allowed"
;
const
char
*
msg2
=
"invalid expression in select clause"
;
const
char
*
msg3
=
"invalid function"
;
tSQLExprList
*
pExprList
=
pQuerySql
->
pSelection
;
if
(
pExprList
->
nExpr
!=
1
)
{
SArray
*
pExprList
=
pQuerySqlNode
->
pSelectList
;
size_t
size
=
taosArrayGetSize
(
pExprList
);
if
(
size
!=
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
bool
server_status
=
false
;
tSQLExpr
*
pExpr
=
pExprList
->
a
[
0
].
pNode
;
tSqlExprItem
*
pExprItem
=
taosArrayGet
(
pExprList
,
0
);
tSqlExpr
*
pExpr
=
pExprItem
->
pNode
;
if
(
pExpr
->
operand
.
z
==
NULL
)
{
//handle 'select 1'
if
(
pExpr
->
token
.
n
==
1
&&
0
==
strncasecmp
(
pExpr
->
token
.
z
,
"1"
,
1
))
{
...
...
@@ -6150,8 +6159,9 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
SColumnIndex
ind
=
{
0
};
SSqlExpr
*
pExpr1
=
tscSqlExprAppend
(
pQueryInfo
,
TSDB_FUNC_TAG_DUMMY
,
&
ind
,
TSDB_DATA_TYPE_INT
,
tDataTypes
[
TSDB_DATA_TYPE_INT
].
bytes
,
getNewResColId
(
pQueryInfo
),
tDataTypes
[
TSDB_DATA_TYPE_INT
].
bytes
,
false
);
const
char
*
name
=
(
pExprList
->
a
[
0
].
aliasName
!=
NULL
)
?
pExprList
->
a
[
0
].
aliasName
:
functionsInfo
[
index
].
name
;
tSqlExprItem
*
item
=
taosArrayGet
(
pExprList
,
0
);
const
char
*
name
=
(
item
->
aliasName
!=
NULL
)
?
item
->
aliasName
:
functionsInfo
[
index
].
name
;
tstrncpy
(
pExpr1
->
aliasName
,
name
,
tListLen
(
pExpr1
->
aliasName
));
return
TSDB_CODE_SUCCESS
;
...
...
@@ -6286,7 +6296,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
subClauseIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
SCreateTableS
QL
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SArray
*
pFieldList
=
pCreateTable
->
colInfo
.
pColumns
;
SArray
*
pTagList
=
pCreateTable
->
colInfo
.
pTagColumns
;
...
...
@@ -6341,7 +6351,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SCreateTableS
QL
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
// two table: the first one is for current table, and the secondary is for the super table.
...
...
@@ -6550,12 +6560,12 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
SCreateTableS
QL
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
// if sql specifies db, use it, otherwise use default db
SStrToken
*
pName
=
&
(
pCreateTable
->
name
);
SQueryS
QL
*
pQuerySql
=
pCreateTable
->
pSelect
;
SQueryS
qlNode
*
pQuerySqlNode
=
pCreateTable
->
pSelect
;
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
...
...
@@ -6583,18 +6593,18 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
}
bool
isSTable
=
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
);
if
(
parseSelectClause
(
&
pSql
->
cmd
,
0
,
pQuerySql
->
pSelection
,
isSTable
,
false
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseSelectClause
(
&
pSql
->
cmd
,
0
,
pQuerySql
Node
->
pSelectList
,
isSTable
,
false
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
(
pQuerySql
->
pWhere
!=
NULL
)
{
// query condition in stream computing
if
(
parseWhereClause
(
pQueryInfo
,
&
pQuerySql
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
pQuerySql
Node
->
pWhere
!=
NULL
)
{
// query condition in stream computing
if
(
parseWhereClause
(
pQueryInfo
,
&
pQuerySql
Node
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
// set interval value
if
(
parseIntervalClause
(
pSql
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseIntervalClause
(
pSql
,
pQueryInfo
,
pQuerySql
Node
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -6612,7 +6622,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return
code
;
}
if
(
pQuerySql
->
selectToken
.
n
>
TSDB_MAX_SAVED_SQL_LEN
)
{
if
(
pQuerySql
Node
->
sqlstr
.
n
>
TSDB_MAX_SAVED_SQL_LEN
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
...
...
@@ -6630,12 +6640,12 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
* check if fill operation is available, the fill operation is parsed and executed during query execution,
* not here.
*/
if
(
pQuerySql
->
fillType
!=
NULL
)
{
if
(
pQuerySql
Node
->
fillType
!=
NULL
)
{
if
(
pQueryInfo
->
interval
.
interval
==
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
->
fillType
,
0
);
tVariantListItem
*
pItem
=
taosArrayGet
(
pQuerySql
Node
->
fillType
,
0
);
if
(
pItem
->
pVar
.
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
!
((
strncmp
(
pItem
->
pVar
.
pz
,
"none"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)
||
(
strncmp
(
pItem
->
pVar
.
pz
,
"null"
,
4
)
==
0
&&
pItem
->
pVar
.
nLen
==
4
)))
{
...
...
@@ -6684,10 +6694,10 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
do
CheckForQuery
(
SSqlObj
*
pSql
,
SQuerySQL
*
pQuerySql
,
int32_t
index
)
{
assert
(
pQuerySql
!=
NULL
&&
(
pQuerySql
->
from
==
NULL
||
taosArrayGetSize
(
pQuerySql
->
from
)
>
0
));
int32_t
do
ValidateSqlNode
(
SSqlObj
*
pSql
,
SQuerySqlNode
*
pQuerySqlNode
,
int32_t
index
)
{
assert
(
pQuerySql
Node
!=
NULL
&&
(
pQuerySqlNode
->
from
==
NULL
||
taosArrayGetSize
(
pQuerySqlNode
->
from
)
>
0
));
const
char
*
msg0
=
"invalid table name"
;
const
char
*
msg0
=
"invalid table name"
;
const
char
*
msg1
=
"point interpolation query needs timestamp"
;
const
char
*
msg2
=
"fill only available for interval query"
;
const
char
*
msg3
=
"start(end) time of query range required or time range too large"
;
...
...
@@ -6709,7 +6719,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
assert
(
pCmd
->
clauseIndex
==
index
);
// too many result columns not support order by in query
if
(
pQuerySql
->
pSelection
->
nExpr
>
TSDB_MAX_COLUMNS
)
{
if
(
taosArrayGetSize
(
pQuerySqlNode
->
pSelectList
)
>
TSDB_MAX_COLUMNS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
...
...
@@ -6720,13 +6730,13 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
* select client_version();
* select server_state();
*/
if
(
pQuerySql
->
from
==
NULL
)
{
assert
(
pQuerySql
->
fillType
==
NULL
&&
pQuerySql
->
pGroupby
==
NULL
&&
pQuerySql
->
pWhere
==
NULL
&&
pQuerySql
->
pSortOrder
==
NULL
);
return
doLocalQueryProcess
(
pCmd
,
pQueryInfo
,
pQuerySql
);
if
(
pQuerySql
Node
->
from
==
NULL
)
{
assert
(
pQuerySql
Node
->
fillType
==
NULL
&&
pQuerySqlNode
->
pGroupby
==
NULL
&&
pQuerySqlNode
->
pWhere
==
NULL
&&
pQuerySql
Node
->
pSortOrder
==
NULL
);
return
doLocalQueryProcess
(
pCmd
,
pQueryInfo
,
pQuerySql
Node
);
}
size_t
fromSize
=
taosArrayGetSize
(
pQuerySql
->
from
);
size_t
fromSize
=
taosArrayGetSize
(
pQuerySql
Node
->
from
);
if
(
fromSize
>
TSDB_MAX_JOIN_TABLE_NUM
*
2
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
...
...
@@ -6739,7 +6749,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
// set all query tables, which are maybe more than one.
for
(
int32_t
i
=
0
;
i
<
fromSize
;
)
{
tVariantListItem
*
item
=
taosArrayGet
(
pQuerySql
->
from
,
i
);
tVariantListItem
*
item
=
taosArrayGet
(
pQuerySql
Node
->
from
,
i
);
tVariant
*
pTableItem
=
&
item
->
pVar
;
if
(
pTableItem
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
...
...
@@ -6765,7 +6775,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
code
;
}
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
->
from
,
i
+
1
);
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySql
Node
->
from
,
i
+
1
);
if
(
p1
->
pVar
.
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
...
...
@@ -6790,7 +6800,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
i
+=
2
;
}
assert
(
pQueryInfo
->
numOfTables
==
taosArrayGetSize
(
pQuerySql
->
from
)
/
2
);
assert
(
pQueryInfo
->
numOfTables
==
taosArrayGetSize
(
pQuerySql
Node
->
from
)
/
2
);
bool
isSTable
=
false
;
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
...
...
@@ -6806,44 +6816,43 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
// parse the group by clause in the first place
if
(
parseGroupbyClause
(
pQueryInfo
,
pQuerySql
->
pGroupby
,
pCmd
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseGroupbyClause
(
pQueryInfo
,
pQuerySql
Node
->
pGroupby
,
pCmd
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
// set where info
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
pQuerySql
->
pWhere
!=
NULL
)
{
if
(
parseWhereClause
(
pQueryInfo
,
&
pQuerySql
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
pQuerySql
Node
->
pWhere
!=
NULL
)
{
if
(
parseWhereClause
(
pQueryInfo
,
&
pQuerySql
Node
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
pQuerySql
->
pWhere
=
NULL
;
pQuerySql
Node
->
pWhere
=
NULL
;
if
(
tinfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
)
{
pQueryInfo
->
window
.
skey
=
pQueryInfo
->
window
.
skey
/
1000
;
pQueryInfo
->
window
.
ekey
=
pQueryInfo
->
window
.
ekey
/
1000
;
}
}
else
{
// set the time rang
if
(
taosArrayGetSize
(
pQuerySql
->
from
)
>
2
)
{
// it is a join query, no wher clause is not allowed.
if
(
taosArrayGetSize
(
pQuerySql
Node
->
from
)
>
2
)
{
// it is a join query, no wher clause is not allowed.
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"condition missing for join query "
);
}
}
int32_t
joinQuery
=
(
pQuerySql
->
from
!=
NULL
&&
taosArrayGetSize
(
pQuerySql
->
from
)
>
2
);
int32_t
timeWindowQuery
=
!
(
pQuerySql
->
interval
.
interval
.
type
==
0
||
pQuerySql
->
interval
.
interval
.
n
==
0
||
pQuerySql
->
sessionVal
.
gap
.
n
==
0
);
int32_t
joinQuery
=
(
pQuerySqlNode
->
from
!=
NULL
&&
taosArrayGetSize
(
pQuerySqlNode
->
from
)
>
2
);
int32_t
timeWindowQuery
=
!
(
pQuerySqlNode
->
interval
==
NULL
||
pQuerySqlNode
->
sessionVal
==
NULL
);
if
(
parseSelectClause
(
pCmd
,
index
,
pQuerySql
->
pSelection
,
isSTable
,
joinQuery
,
timeWindowQuery
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseSelectClause
(
pCmd
,
index
,
pQuerySql
Node
->
pSelectList
,
isSTable
,
joinQuery
,
timeWindowQuery
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
// set order by info
if
(
parseOrderbyClause
(
pCmd
,
pQueryInfo
,
pQuerySql
,
tscGetTableSchema
(
pTableMetaInfo
->
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseOrderbyClause
(
pCmd
,
pQueryInfo
,
pQuerySql
Node
,
tscGetTableSchema
(
pTableMetaInfo
->
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
// set interval value
if
(
parseIntervalClause
(
pSql
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseIntervalClause
(
pSql
,
pQueryInfo
,
pQuerySql
Node
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
else
{
if
(
isTimeWindowQuery
(
pQueryInfo
)
&&
...
...
@@ -6852,7 +6861,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
}
if
(
parseSessionClause
(
pCmd
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseSessionClause
(
pCmd
,
pQueryInfo
,
pQuerySql
Node
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -6874,7 +6883,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
}
if
((
code
=
parseLimitClause
(
pCmd
,
pQueryInfo
,
index
,
pQuerySql
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
parseLimitClause
(
pCmd
,
pQueryInfo
,
index
,
pQuerySql
Node
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -6885,7 +6894,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
updateLastScanOrderIfNeeded
(
pQueryInfo
);
tscFieldInfoUpdateOffset
(
pQueryInfo
);
if
(
pQuerySql
->
fillType
!=
NULL
)
{
if
(
pQuerySql
Node
->
fillType
!=
NULL
)
{
if
(
pQueryInfo
->
interval
.
interval
==
0
&&
(
!
tscIsPointInterpQuery
(
pQueryInfo
)))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -6898,7 +6907,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
code
;
}
if
((
code
=
parseFillClause
(
pCmd
,
pQueryInfo
,
pQuerySql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
parseFillClause
(
pCmd
,
pQueryInfo
,
pQuerySql
Node
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
...
...
@@ -6906,7 +6915,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
TSDB_CODE_SUCCESS
;
// Does not build query message here
}
int32_t
exprTreeFromSqlExpr
(
SSqlCmd
*
pCmd
,
tExprNode
**
pExpr
,
const
tS
QL
Expr
*
pSqlExpr
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
,
int64_t
*
uid
)
{
int32_t
exprTreeFromSqlExpr
(
SSqlCmd
*
pCmd
,
tExprNode
**
pExpr
,
const
tS
ql
Expr
*
pSqlExpr
,
SQueryInfo
*
pQueryInfo
,
SArray
*
pCols
,
int64_t
*
uid
)
{
tExprNode
*
pLeft
=
NULL
;
tExprNode
*
pRight
=
NULL
;
...
...
src/client/src/tscServer.c
浏览文件 @
a6d0bf4f
...
...
@@ -1350,7 +1350,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd
*
pCmd
=
&
(
pSql
->
cmd
);
int32_t
size
=
minMsgSize
()
+
sizeof
(
SCMCreateTableMsg
)
+
sizeof
(
SCreateTableMsg
);
SCreateTableS
QL
*
pCreateTableInfo
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTableInfo
=
pInfo
->
pCreateTableInfo
;
if
(
pCreateTableInfo
->
type
==
TSQL_CREATE_TABLE_FROM_STABLE
)
{
int32_t
numOfTables
=
(
int32_t
)
taosArrayGetSize
(
pInfo
->
pCreateTableInfo
->
childTableInfo
);
size
+=
numOfTables
*
(
sizeof
(
SCreateTableMsg
)
+
TSDB_MAX_TAGS_LEN
);
...
...
@@ -1359,7 +1359,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
}
if
(
pCreateTableInfo
->
pSelect
!=
NULL
)
{
size
+=
(
pCreateTableInfo
->
pSelect
->
s
electToken
.
n
+
1
);
size
+=
(
pCreateTableInfo
->
pSelect
->
s
qlstr
.
n
+
1
);
}
return
size
+
TSDB_EXTRA_PAYLOAD_SIZE
;
...
...
@@ -1417,7 +1417,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t
code
=
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pCreateMsg
->
tableName
);
assert
(
code
==
0
);
SCreateTableS
QL
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
pCreateMsg
->
igExists
=
pCreateTable
->
existCheck
?
1
:
0
;
pCreateMsg
->
numOfColumns
=
htons
(
pCmd
->
numOfCols
);
...
...
@@ -1440,11 +1440,11 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
(
char
*
)
pSchema
;
if
(
type
==
TSQL_CREATE_STREAM
)
{
// check if it is a stream sql
SQueryS
QL
*
pQuerySql
=
pInfo
->
pCreateTableInfo
->
pSelect
;
SQueryS
qlNode
*
pQuerySql
=
pInfo
->
pCreateTableInfo
->
pSelect
;
strncpy
(
pMsg
,
pQuerySql
->
s
electToken
.
z
,
pQuerySql
->
selectToken
.
n
+
1
);
pCreateMsg
->
sqlLen
=
htons
(
pQuerySql
->
s
electToken
.
n
+
1
);
pMsg
+=
pQuerySql
->
s
electToken
.
n
+
1
;
strncpy
(
pMsg
,
pQuerySql
->
s
qlstr
.
z
,
pQuerySql
->
sqlstr
.
n
+
1
);
pCreateMsg
->
sqlLen
=
htons
(
pQuerySql
->
s
qlstr
.
n
+
1
);
pMsg
+=
pQuerySql
->
s
qlstr
.
n
+
1
;
}
}
...
...
src/query/inc/qSqlparser.h
浏览文件 @
a6d0bf4f
...
...
@@ -27,6 +27,18 @@ extern "C" {
#include "tvariant.h"
#define ParseTOKENTYPE SStrToken
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
enum
SQL_NODE_TYPE
{
SQL_NODE_TABLE_COLUMN
=
1
,
SQL_NODE_SQLFUNCTION
=
2
,
SQL_NODE_VALUE
=
3
,
SQL_NODE_EXPR
=
4
,
};
extern
char
tTokenTypeSwitcher
[
13
];
#define toTSDBType(x) \
...
...
@@ -63,20 +75,20 @@ typedef struct SSessionWindowVal {
SStrToken
gap
;
}
SSessionWindowVal
;
typedef
struct
SQueryS
QL
{
struct
tSQLExprList
*
pSelection
;
// select clause
SArray
*
from
;
// from clause SArray<tVariantListItem
>
struct
tS
QLExpr
*
pWhere
;
// where clause [optional]
SArray
*
pGroupby
;
// groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional], SArray<tVariantListItem>
SIntervalVal
interval
;
// (interval, interval_offset) [optional]
SSessionWindowVal
sessionVal
;
// session window [optional]
SStrToken
sliding
;
// sliding window [optional]
SLimitVal
limit
;
// limit offset [optional]
SLimitVal
slimit
;
// group limit offset [optional]
SArray
*
fillType
;
// fill type[optional], SArray<tVariantListItem>
SStrToken
selectToken
;
// sql string
}
SQueryS
QL
;
typedef
struct
SQueryS
qlNode
{
struct
SArray
*
pSelectList
;
// select clause
SArray
*
from
;
// from clause SArray<SQuerySqlNode
>
struct
tS
qlExpr
*
pWhere
;
// where clause [optional]
SArray
*
pGroupby
;
// groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional], SArray<tVariantListItem>
SIntervalVal
*
interval
;
// (interval, interval_offset) [optional]
SSessionWindowVal
*
sessionVal
;
// session window [optional]
SStrToken
*
sliding
;
// sliding window [optional]
SLimitVal
*
limit
;
// limit offset [optional]
SLimitVal
*
slimit
;
// group limit offset [optional]
SArray
*
fillType
;
// fill type[optional], SArray<tVariantListItem>
SStrToken
sqlstr
;
// sql string in select clause
}
SQueryS
qlNode
;
typedef
struct
SCreatedTableInfo
{
SStrToken
name
;
// table name token
...
...
@@ -88,7 +100,7 @@ typedef struct SCreatedTableInfo {
int8_t
igExist
;
// ignore if exists
}
SCreatedTableInfo
;
typedef
struct
SCreateTableS
QL
{
typedef
struct
SCreateTableS
ql
{
SStrToken
name
;
// table name, create table [name] xxx
int8_t
type
;
// create normal table/from super table/ stream
bool
existCheck
;
...
...
@@ -99,16 +111,16 @@ typedef struct SCreateTableSQL {
}
colInfo
;
SArray
*
childTableInfo
;
// SArray<SCreatedTableInfo>
SQueryS
QL
*
pSelect
;
}
SCreateTableS
QL
;
SQueryS
qlNode
*
pSelect
;
}
SCreateTableS
ql
;
typedef
struct
SAlterTableInfo
{
SStrToken
name
;
int16_t
tableType
;
int16_t
type
;
STagData
tagData
;
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
SArray
*
varList
;
// set t=val or: change src dst, SArray<tVariantListItem>
SStrToken
name
;
int16_t
tableType
;
int16_t
type
;
STagData
tagData
;
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
SArray
*
varList
;
// set t=val or: change src dst, SArray<tVariantListItem>
}
SAlterTableInfo
;
typedef
struct
SCreateDbInfo
{
...
...
@@ -147,9 +159,9 @@ typedef struct SCreateAcctInfo {
}
SCreateAcctInfo
;
typedef
struct
SShowInfo
{
uint8_t
showType
;
SStrToken
prefix
;
SStrToken
pattern
;
uint8_t
showType
;
SStrToken
prefix
;
SStrToken
pattern
;
}
SShowInfo
;
typedef
struct
SUserInfo
{
...
...
@@ -174,7 +186,7 @@ typedef struct SMiscInfo {
}
SMiscInfo
;
typedef
struct
SSubclauseInfo
{
// "UNION" multiple select sub-clause
SQueryS
QL
**
pClause
;
SQueryS
qlNode
**
pClause
;
int32_t
numOfClause
;
}
SSubclauseInfo
;
...
...
@@ -184,26 +196,15 @@ typedef struct SSqlInfo {
SSubclauseInfo
subclauseInfo
;
char
msg
[
256
];
union
{
SCreateTableS
QL
*
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTableInfo
;
SAlterTableInfo
*
pAlterInfo
;
SMiscInfo
*
pMiscInfo
;
};
}
SSqlInfo
;
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
enum
SQL_NODE_TYPE
{
SQL_NODE_TABLE_COLUMN
=
1
,
SQL_NODE_SQLFUNCTION
=
2
,
SQL_NODE_VALUE
=
3
,
SQL_NODE_EXPR
=
4
,
};
typedef
struct
tSQLExpr
{
typedef
struct
tSqlExpr
{
uint16_t
type
;
// sql node type
uint32_t
tokenId
;
// TK_
FUNCTION: sql function, TK_
LE: less than(binary expr)
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
SStrToken
operand
;
...
...
@@ -213,70 +214,47 @@ typedef struct tSQLExpr {
tVariant
value
;
// the use input value
SStrToken
token
;
// original sql expr string
struct
tS
QL
Expr
*
pLeft
;
// left child
struct
tS
QL
Expr
*
pRight
;
// right child
struct
tSQLExprList
*
pParam
;
// function parameters list
}
tS
QL
Expr
;
struct
tS
ql
Expr
*
pLeft
;
// left child
struct
tS
ql
Expr
*
pRight
;
// right child
struct
SArray
*
pParam
;
// function parameters list
}
tS
ql
Expr
;
// used in select clause. select <
tSQLExprList
> from xxx
// used in select clause. select <
SArray
> from xxx
typedef
struct
tSqlExprItem
{
tS
QL
Expr
*
pNode
;
// The list of expressions
tS
ql
Expr
*
pNode
;
// The list of expressions
char
*
aliasName
;
// alias name, null-terminated string
bool
distinct
;
}
tSqlExprItem
;
// todo refactor by using SArray
typedef
struct
tSQLExprList
{
int32_t
nExpr
;
/* Number of expressions on the list */
int32_t
nAlloc
;
/* Number of entries allocated below */
tSqlExprItem
*
a
;
/* One entry for each expression */
}
tSQLExprList
;
/**
*
* @param yyp The parser
* @param yymajor The major token code number
* @param yyminor The value for the token
*/
void
Parse
(
void
*
yyp
,
int
yymajor
,
ParseTOKENTYPE
yyminor
,
SSqlInfo
*
);
/**
*
* @param p The parser to be deleted
* @param freeProc Function used to reclaim memory
*/
void
ParseFree
(
void
*
p
,
void
(
*
freeProc
)(
void
*
));
SArray
*
tVariantListAppend
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
);
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
tSQLExpr
*
tSqlExprCreate
(
tSQLExpr
*
pLeft
,
tSQLExpr
*
pRight
,
int32_t
optrType
);
// sql expr leaf node
tSqlExpr
*
tSqlExprCreateIdValue
(
SStrToken
*
pToken
,
int32_t
optrType
);
tSqlExpr
*
tSqlExprCreateFunction
(
SArray
*
pParam
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
);
tSQLExpr
*
tSqlExprClone
(
tSQLExpr
*
pSrc
);
tSqlExpr
*
tSqlExprCreate
(
tSqlExpr
*
pLeft
,
tSqlExpr
*
pRight
,
int32_t
optrType
);
tSqlExpr
*
tSqlExprClone
(
tSqlExpr
*
pSrc
);
void
tSqlExprDestroy
(
tSqlExpr
*
pExpr
);
SArray
*
tSqlExprListAppend
(
SArray
*
pList
,
tSqlExpr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
);
void
tSqlExprListDestroy
(
SArray
*
pList
);
void
tSqlExprDestroy
(
tSQLExpr
*
pExpr
);
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SArray
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
);
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQLExpr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
);
SCreateTableSql
*
tSetCreateTableInfo
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySqlNode
*
pSelect
,
int32_t
type
);
void
tSqlExprListDestroy
(
tSQLExprList
*
pList
);
SQuerySQL
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
SArray
*
pFrom
,
tSQLExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
);
SCreateTableSQL
*
tSetCreateSqlElems
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySQL
*
pSelect
,
int32_t
type
);
void
tSqlExprNodeDestroy
(
tSQLExpr
*
pExpr
);
SAlterTableInfo
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableTable
);
SAlterTableInfo
*
tSetAlterTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableTable
);
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTagNames
,
SArray
*
pTagVals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
);
void
destroyAllSelectClause
(
SSubclauseInfo
*
pSql
);
void
doDestroyQuerySql
(
SQueryS
QL
*
pSql
);
void
doDestroyQuerySql
(
SQueryS
qlNode
*
pSql
);
void
freeCreateTableInfo
(
void
*
p
);
SSqlInfo
*
setSqlInfo
(
SSqlInfo
*
pInfo
,
void
*
pSqlExprInfo
,
SStrToken
*
pTableName
,
int32_t
type
);
SSqlInfo
*
setSqlInfo
(
SSqlInfo
*
pInfo
,
void
*
pSqlExprInfo
,
SStrToken
*
pTableName
,
int32_t
type
);
SSubclauseInfo
*
setSubclause
(
SSubclauseInfo
*
pClause
,
void
*
pSqlExprInfo
);
SSubclauseInfo
*
appendSelectClause
(
SSubclauseInfo
*
pInfo
,
void
*
pSubclause
);
...
...
@@ -285,7 +263,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
void
SqlInfoDestroy
(
SSqlInfo
*
pInfo
);
void
setDCLS
QL
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParams
,
...);
void
setDCLS
ql
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParams
,
...);
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
,
int16_t
dbType
,
int16_t
tableType
);
void
setShowOptions
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
prefix
,
SStrToken
*
pPatterns
);
...
...
@@ -300,19 +278,39 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
void
setDefaultCreateTopicOption
(
SCreateDbInfo
*
pDBInfo
);
// prefix show db.tables;
void
s
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
);
void
tS
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
);
tSQLExpr
*
tSqlExprIdValueCreate
(
SStrToken
*
pToken
,
int32_t
optrType
);
void
tSetColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
);
void
tSetColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
);
tSQLExpr
*
tSqlExprCreateFunction
(
tSQLExprList
*
pList
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
);
void
tSqlSetColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
);
/**
*
* @param yyp The parser
* @param yymajor The major token code number
* @param yyminor The value for the token
*/
void
Parse
(
void
*
yyp
,
int
yymajor
,
ParseTOKENTYPE
yyminor
,
SSqlInfo
*
);
void
tSqlSetColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
);
/**
*
* @param p The parser to be deleted
* @param freeProc Function used to reclaim memory
*/
void
ParseFree
(
void
*
p
,
void
(
*
freeProc
)(
void
*
));
/**
*
* @param mallocProc The parser allocator
* @return
*/
void
*
ParseAlloc
(
void
*
(
*
mallocProc
)(
size_t
));
SSqlInfo
qSQLParse
(
const
char
*
str
);
/**
*
* @param str sql string
* @return sql ast
*/
SSqlInfo
qSqlParse
(
const
char
*
str
);
#ifdef __cplusplus
}
...
...
src/query/inc/sql.y
浏览文件 @
a6d0bf4f
无法预览此类型文件
src/query/src/q
ParserImpl
.c
→
src/query/src/q
SqlParser
.c
浏览文件 @
a6d0bf4f
...
...
@@ -23,7 +23,7 @@
#include "ttokendef.h"
#include "tutil.h"
SSqlInfo
qS
QL
Parse
(
const
char
*
pStr
)
{
SSqlInfo
qS
ql
Parse
(
const
char
*
pStr
)
{
void
*
pParser
=
ParseAlloc
(
malloc
);
SSqlInfo
sqlInfo
=
{
0
};
...
...
@@ -80,53 +80,48 @@ abort_parse:
return
sqlInfo
;
}
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQL
Expr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
)
{
SArray
*
tSqlExprListAppend
(
SArray
*
pList
,
tSql
Expr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
)
{
if
(
pList
==
NULL
)
{
pList
=
calloc
(
1
,
sizeof
(
tSQLExprList
));
pList
=
taosArrayInit
(
4
,
sizeof
(
tSqlExprItem
));
}
if
(
pList
->
nAlloc
<=
pList
->
nExpr
)
{
pList
->
nAlloc
=
(
pList
->
nAlloc
<<
1u
)
+
4
;
pList
->
a
=
realloc
(
pList
->
a
,
pList
->
nAlloc
*
sizeof
(
pList
->
a
[
0
]));
if
(
pList
->
a
==
0
)
{
pList
->
nExpr
=
pList
->
nAlloc
=
0
;
return
pList
;
}
}
assert
(
pList
->
a
!=
0
);
if
(
pNode
||
pToken
)
{
struct
tSqlExprItem
*
pItem
=
&
pList
->
a
[
pList
->
nExpr
++
];
memset
(
pItem
,
0
,
sizeof
(
*
pItem
));
pItem
->
pNode
=
pNode
;
struct
tSqlExprItem
item
=
{
0
};
item
.
pNode
=
pNode
;
item
.
distinct
=
(
pDistinct
!=
NULL
);
if
(
pToken
)
{
// set the as clause
pItem
->
aliasName
=
malloc
(
pToken
->
n
+
1
);
strncpy
(
pItem
->
aliasName
,
pToken
->
z
,
pToken
->
n
);
pItem
->
aliasName
[
pToken
->
n
]
=
0
;
item
.
aliasName
=
malloc
(
pToken
->
n
+
1
);
strncpy
(
item
.
aliasName
,
pToken
->
z
,
pToken
->
n
);
item
.
aliasName
[
pToken
->
n
]
=
0
;
strdequote
(
pItem
->
aliasName
);
strdequote
(
item
.
aliasName
);
}
pItem
->
distinct
=
(
pDistinct
!=
NULL
);
taosArrayPush
(
pList
,
&
item
);
}
return
pList
;
}
void
tSqlExprListDestroy
(
tSQLExprList
*
pList
)
{
if
(
pList
==
NULL
)
return
;
static
void
freeExprElem
(
void
*
item
)
{
tSqlExprItem
*
exprItem
=
item
;
for
(
int32_t
i
=
0
;
i
<
pList
->
nExpr
;
++
i
)
{
if
(
pList
->
a
[
i
].
aliasName
!=
NULL
)
{
free
(
pList
->
a
[
i
].
aliasName
);
}
tSqlExprDestroy
(
pList
->
a
[
i
].
pNode
);
tfree
(
exprItem
->
aliasName
);
tSqlExprDestroy
(
exprItem
->
pNode
);
}
void
tSqlExprListDestroy
(
SArray
*
pList
)
{
if
(
pList
==
NULL
)
{
return
;
}
free
(
pList
->
a
);
free
(
pList
);
taosArrayDestroyEx
(
pList
,
freeExprElem
);
}
tS
QLExpr
*
tSqlExprIdValueCreat
e
(
SStrToken
*
pToken
,
int32_t
optrType
)
{
tS
QLExpr
*
pSqlExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
tSqlExprCreateIdValu
e
(
SStrToken
*
pToken
,
int32_t
optrType
)
{
tS
qlExpr
*
pSqlExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
if
(
pToken
!=
NULL
)
{
pSqlExpr
->
token
=
*
pToken
;
...
...
@@ -171,15 +166,15 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) {
* pList is the parameters for function with id(optType)
* function name is denoted by pFunctionToken
*/
tS
QLExpr
*
tSqlExprCreateFunction
(
tSQLExprList
*
pList
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
)
{
tS
qlExpr
*
tSqlExprCreateFunction
(
SArray
*
pParam
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
)
{
if
(
pFuncToken
==
NULL
)
{
return
NULL
;
}
tS
QLExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
pExpr
->
tokenId
=
optType
;
pExpr
->
type
=
SQL_NODE_SQLFUNCTION
;
pExpr
->
pParam
=
p
List
;
pExpr
->
pParam
=
p
Param
;
int32_t
len
=
(
int32_t
)((
endToken
->
z
+
endToken
->
n
)
-
pFuncToken
->
z
);
pExpr
->
operand
=
(
*
pFuncToken
);
...
...
@@ -193,10 +188,10 @@ tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SSt
/*
* create binary expression in this procedure
* if the expr is arithmetic, calculate the result and set it to tS
QL
Expr Object
* if the expr is arithmetic, calculate the result and set it to tS
ql
Expr Object
*/
tS
QLExpr
*
tSqlExprCreate
(
tSQLExpr
*
pLeft
,
tSQL
Expr
*
pRight
,
int32_t
optrType
)
{
tS
QLExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
tSqlExprCreate
(
tSqlExpr
*
pLeft
,
tSql
Expr
*
pRight
,
int32_t
optrType
)
{
tS
qlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
pExpr
->
type
=
SQL_NODE_EXPR
;
if
(
pLeft
!=
NULL
&&
pRight
!=
NULL
&&
(
optrType
!=
TK_IN
))
{
...
...
@@ -291,9 +286,9 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
pExpr
->
tokenId
=
optrType
;
pExpr
->
pLeft
=
pLeft
;
tS
QLExpr
*
pRSub
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
pRSub
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
pRSub
->
tokenId
=
TK_SET
;
// TODO refactor .....
pRSub
->
pParam
=
(
tSQLExprList
*
)
pRight
;
pRSub
->
pParam
=
(
SArray
*
)
pRight
;
pExpr
->
pRight
=
pRSub
;
}
else
{
...
...
@@ -301,7 +296,7 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
pExpr
->
pLeft
=
pLeft
;
if
(
pLeft
!=
NULL
&&
pRight
==
NULL
)
{
pRight
=
calloc
(
1
,
sizeof
(
tS
QL
Expr
));
pRight
=
calloc
(
1
,
sizeof
(
tS
ql
Expr
));
}
pExpr
->
pRight
=
pRight
;
...
...
@@ -312,8 +307,8 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
tS
QLExpr
*
tSqlExprClone
(
tSQL
Expr
*
pSrc
)
{
tS
QLExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
tSqlExprClone
(
tSql
Expr
*
pSrc
)
{
tS
qlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
memcpy
(
pExpr
,
pSrc
,
sizeof
(
*
pSrc
));
...
...
@@ -332,7 +327,7 @@ tSQLExpr *tSqlExprClone(tSQLExpr *pSrc) {
}
void
tSqlExprNodeDestroy
(
tSQL
Expr
*
pExpr
)
{
void
doDestroySqlExprNode
(
tSql
Expr
*
pExpr
)
{
if
(
pExpr
==
NULL
)
{
return
;
}
...
...
@@ -342,11 +337,10 @@ void tSqlExprNodeDestroy(tSQLExpr *pExpr) {
}
tSqlExprListDestroy
(
pExpr
->
pParam
);
free
(
pExpr
);
}
void
tSqlExprDestroy
(
tS
QL
Expr
*
pExpr
)
{
void
tSqlExprDestroy
(
tS
ql
Expr
*
pExpr
)
{
if
(
pExpr
==
NULL
)
{
return
;
}
...
...
@@ -355,7 +349,8 @@ void tSqlExprDestroy(tSQLExpr *pExpr) {
pExpr
->
pLeft
=
NULL
;
tSqlExprDestroy
(
pExpr
->
pRight
);
pExpr
->
pRight
=
NULL
;
tSqlExprNodeDestroy
(
pExpr
);
doDestroySqlExprNode
(
pExpr
);
}
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pToken
,
uint8_t
order
)
{
...
...
@@ -411,13 +406,13 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
return
pList
;
}
void
s
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
)
{
void
tS
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
)
{
pCpxName
->
type
=
pDb
->
type
;
pCpxName
->
z
=
pDb
->
z
;
pCpxName
->
n
=
pDb
->
n
;
}
void
tS
qlS
etColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
)
{
void
tSetColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
)
{
int32_t
maxLen
=
sizeof
(
pField
->
name
)
/
sizeof
(
pField
->
name
[
0
]);
// truncate the column name
...
...
@@ -485,7 +480,7 @@ static int32_t tryParseNameTwoParts(SStrToken *type) {
}
}
void
tS
qlS
etColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
)
{
void
tSetColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
)
{
// set the field type invalid
pField
->
type
=
-
1
;
pField
->
name
[
0
]
=
0
;
...
...
@@ -550,39 +545,39 @@ void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
/*
* extract the select info out of sql string
*/
SQueryS
QL
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
SArray
*
pFrom
,
tSQL
Expr
*
pWhere
,
SQueryS
qlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SArray
*
pFrom
,
tSql
Expr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
)
{
assert
(
pSelect
ion
!=
NULL
);
assert
(
pSelect
List
!=
NULL
);
SQueryS
QL
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuerySQL
));
pQuery
->
s
electToken
=
*
pSelectToken
;
pQuery
->
s
electToken
.
n
=
(
uint32_t
)
strlen
(
pQuery
->
selectToken
.
z
);
// all later sql string are belonged to the stream sql
SQueryS
qlNode
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuerySqlNode
));
pQuery
->
s
qlstr
=
*
pSelectToken
;
pQuery
->
s
qlstr
.
n
=
(
uint32_t
)
strlen
(
pQuery
->
sqlstr
.
z
);
// all later sql string are belonged to the stream sql
pQuery
->
pSelect
ion
=
pSelection
;
pQuery
->
pSelect
List
=
pSelectList
;
pQuery
->
from
=
pFrom
;
pQuery
->
pGroupby
=
pGroupby
;
pQuery
->
pSortOrder
=
pSortOrder
;
pQuery
->
pWhere
=
pWhere
;
if
(
pLimit
!=
NULL
)
{
pQuery
->
limit
=
*
pLimit
;
pQuery
->
limit
=
pLimit
;
}
if
(
pGLimit
!=
NULL
)
{
pQuery
->
slimit
=
*
pGLimit
;
pQuery
->
slimit
=
pGLimit
;
}
if
(
pInterval
!=
NULL
)
{
pQuery
->
interval
=
*
pInterval
;
pQuery
->
interval
=
pInterval
;
}
if
(
pSliding
!=
NULL
)
{
pQuery
->
sliding
=
*
pSliding
;
pQuery
->
sliding
=
pSliding
;
}
if
(
pSession
!=
NULL
)
{
pQuery
->
sessionVal
=
*
pSession
;
pQuery
->
sessionVal
=
pSession
;
}
pQuery
->
fillType
=
pFill
;
...
...
@@ -602,14 +597,14 @@ void freeCreateTableInfo(void* p) {
tfree
(
pInfo
->
tagdata
.
data
);
}
void
doDestroyQuerySql
(
SQueryS
QL
*
pQuerySql
)
{
void
doDestroyQuerySql
(
SQueryS
qlNode
*
pQuerySql
)
{
if
(
pQuerySql
==
NULL
)
{
return
;
}
tSqlExprListDestroy
(
pQuerySql
->
pSelect
ion
);
tSqlExprListDestroy
(
pQuerySql
->
pSelect
List
);
pQuerySql
->
pSelect
ion
=
NULL
;
pQuerySql
->
pSelect
List
=
NULL
;
tSqlExprDestroy
(
pQuerySql
->
pWhere
);
pQuerySql
->
pWhere
=
NULL
;
...
...
@@ -635,15 +630,15 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
}
for
(
int32_t
i
=
0
;
i
<
pClause
->
numOfClause
;
++
i
)
{
SQueryS
QL
*
pQuerySql
=
pClause
->
pClause
[
i
];
SQueryS
qlNode
*
pQuerySql
=
pClause
->
pClause
[
i
];
doDestroyQuerySql
(
pQuerySql
);
}
tfree
(
pClause
->
pClause
);
}
SCreateTableS
QL
*
tSetCreateSqlElems
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySQL
*
pSelect
,
int32_t
type
)
{
SCreateTableS
QL
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateTableSQL
));
SCreateTableS
ql
*
tSetCreateTableInfo
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySqlNode
*
pSelect
,
int32_t
type
)
{
SCreateTableS
ql
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateTableSql
));
switch
(
type
)
{
case
TSQL_CREATE_TABLE
:
{
...
...
@@ -687,7 +682,7 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNam
return
info
;
}
SAlterTableInfo
*
t
AlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableType
)
{
SAlterTableInfo
*
t
SetAlterTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableType
)
{
SAlterTableInfo
*
pAlterTable
=
calloc
(
1
,
sizeof
(
SAlterTableInfo
));
pAlterTable
->
name
=
*
pTableName
;
...
...
@@ -709,7 +704,7 @@ SAlterTableInfo *tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArra
return
pAlterTable
;
}
void
*
destroyCreateTableSql
(
SCreateTableS
QL
*
pCreate
)
{
void
*
destroyCreateTableSql
(
SCreateTableS
ql
*
pCreate
)
{
doDestroyQuerySql
(
pCreate
->
pSelect
);
taosArrayDestroy
(
pCreate
->
colInfo
.
pColumns
);
...
...
@@ -757,7 +752,7 @@ SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) {
return
pSubclause
;
}
pSubclause
->
pClause
=
(
SQueryS
QL
**
)
tmp
;
pSubclause
->
pClause
=
(
SQueryS
qlNode
**
)
tmp
;
pSubclause
->
pClause
[
newSize
-
1
]
=
pSqlExprInfo
;
pSubclause
->
numOfClause
++
;
...
...
@@ -788,7 +783,7 @@ SSubclauseInfo* appendSelectClause(SSubclauseInfo *pQueryInfo, void *pSubclause)
return
pQueryInfo
;
}
pQueryInfo
->
pClause
=
(
SQueryS
QL
**
)
tmp
;
pQueryInfo
->
pClause
=
(
SQueryS
qlNode
**
)
tmp
;
pQueryInfo
->
pClause
[
pQueryInfo
->
numOfClause
++
]
=
pSubclause
;
return
pQueryInfo
;
...
...
@@ -799,7 +794,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
pInfo
->
pCreateTableInfo
->
existCheck
=
(
pIfNotExists
->
n
!=
0
);
}
void
setDCLS
QL
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParam
,
...)
{
void
setDCLS
ql
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParam
,
...)
{
pInfo
->
type
=
type
;
if
(
nParam
==
0
)
{
return
;
...
...
src/query/src/sql.c
浏览文件 @
a6d0bf4f
...
...
@@ -104,15 +104,14 @@ typedef union {
int
yyinit
;
ParseTOKENTYPE
yy0
;
SCreatedTableInfo
yy96
;
tS
QL
Expr
*
yy178
;
tS
ql
Expr
*
yy178
;
SCreateAcctInfo
yy187
;
SQuerySQL
*
yy216
;
SCreateTableSQL
*
yy230
;
SCreateTableSql
*
yy230
;
SArray
*
yy285
;
TAOS_FIELD
yy295
;
SQuerySqlNode
*
yy342
;
tVariant
yy362
;
SIntervalVal
yy376
;
tSQLExprList
*
yy434
;
SLimitVal
yy438
;
int
yy460
;
SSubclauseInfo
*
yy513
;
...
...
@@ -1426,14 +1425,14 @@ destroyCreateTableSql((yypminor->yy230));
break
;
case
235
:
/* select */
{
doDestroyQuerySql
((
yypminor
->
yy
216
));
doDestroyQuerySql
((
yypminor
->
yy
342
));
}
break
;
case
238
:
/* selcollist */
case
251
:
/* sclp */
case
262
:
/* exprlist */
{
tSqlExprListDestroy
((
yypminor
->
yy
434
));
tSqlExprListDestroy
((
yypminor
->
yy
285
));
}
break
;
case
240
:
/* where_opt */
...
...
@@ -2156,12 +2155,12 @@ static void yy_reduce(
case
20
:
/* cmd ::= SHOW CREATE TABLE ids cpxName */
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_SHOW_CREATE_TABLE
,
1
,
&
yymsp
[
-
1
].
minor
.
yy0
);
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_SHOW_CREATE_TABLE
,
1
,
&
yymsp
[
-
1
].
minor
.
yy0
);
}
break
;
case
21
:
/* cmd ::= SHOW CREATE DATABASE ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_SHOW_CREATE_DATABASE
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_SHOW_CREATE_DATABASE
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
22
:
/* cmd ::= SHOW dbPrefix TABLES */
...
...
@@ -2182,21 +2181,21 @@ static void yy_reduce(
case
25
:
/* cmd ::= SHOW dbPrefix STABLES LIKE ids */
{
SStrToken
token
;
s
etDbName
(
&
token
,
&
yymsp
[
-
3
].
minor
.
yy0
);
tS
etDbName
(
&
token
,
&
yymsp
[
-
3
].
minor
.
yy0
);
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_METRIC
,
&
token
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
26
:
/* cmd ::= SHOW dbPrefix VGROUPS */
{
SStrToken
token
;
s
etDbName
(
&
token
,
&
yymsp
[
-
1
].
minor
.
yy0
);
tS
etDbName
(
&
token
,
&
yymsp
[
-
1
].
minor
.
yy0
);
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_VGROUP
,
&
token
,
0
);
}
break
;
case
27
:
/* cmd ::= SHOW dbPrefix VGROUPS ids */
{
SStrToken
token
;
s
etDbName
(
&
token
,
&
yymsp
[
-
2
].
minor
.
yy0
);
tS
etDbName
(
&
token
,
&
yymsp
[
-
2
].
minor
.
yy0
);
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_VGROUP
,
&
token
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
...
...
@@ -2219,21 +2218,21 @@ static void yy_reduce(
{
setDropDbTableInfo
(
pInfo
,
TSDB_SQL_DROP_DB
,
&
yymsp
[
0
].
minor
.
yy0
,
&
yymsp
[
-
1
].
minor
.
yy0
,
TSDB_DB_TYPE_TOPIC
,
-
1
);
}
break
;
case
32
:
/* cmd ::= DROP DNODE ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_DROP_DNODE
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_DROP_DNODE
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
33
:
/* cmd ::= DROP USER ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_DROP_USER
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_DROP_USER
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
34
:
/* cmd ::= DROP ACCOUNT ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_DROP_ACCT
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_DROP_ACCT
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
35
:
/* cmd ::= USE ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_USE_DB
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_USE_DB
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);}
break
;
case
36
:
/* cmd ::= DESCRIBE ids cpxName */
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_DESCRIBE_TABLE
,
1
,
&
yymsp
[
-
1
].
minor
.
yy0
);
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_DESCRIBE_TABLE
,
1
,
&
yymsp
[
-
1
].
minor
.
yy0
);
}
break
;
case
37
:
/* cmd ::= ALTER USER ids PASS ids */
...
...
@@ -2243,16 +2242,16 @@ static void yy_reduce(
{
setAlterUserSql
(
pInfo
,
TSDB_ALTER_USER_PRIVILEGES
,
&
yymsp
[
-
2
].
minor
.
yy0
,
NULL
,
&
yymsp
[
0
].
minor
.
yy0
);}
break
;
case
39
:
/* cmd ::= ALTER DNODE ids ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_CFG_DNODE
,
2
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_CFG_DNODE
,
2
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
40
:
/* cmd ::= ALTER DNODE ids ids ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_CFG_DNODE
,
3
,
&
yymsp
[
-
2
].
minor
.
yy0
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_CFG_DNODE
,
3
,
&
yymsp
[
-
2
].
minor
.
yy0
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
41
:
/* cmd ::= ALTER LOCAL ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_CFG_LOCAL
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_CFG_LOCAL
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
42
:
/* cmd ::= ALTER LOCAL ids ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_CFG_LOCAL
,
2
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
);
}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_CFG_LOCAL
,
2
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
);
}
break
;
case
43
:
/* cmd ::= ALTER DATABASE ids alter_db_optr */
case
44
:
/* cmd ::= ALTER TOPIC ids alter_topic_optr */
yytestcase
(
yyruleno
==
44
);
...
...
@@ -2281,7 +2280,7 @@ static void yy_reduce(
{
yymsp
[
-
2
].
minor
.
yy0
.
n
=
1
;}
break
;
case
53
:
/* cmd ::= CREATE DNODE ids */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_CREATE_DNODE
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_CREATE_DNODE
,
1
,
&
yymsp
[
0
].
minor
.
yy0
);}
break
;
case
54
:
/* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */
{
setCreateAcctSql
(
pInfo
,
TSDB_SQL_CREATE_ACCT
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy187
);}
...
...
@@ -2437,7 +2436,7 @@ static void yy_reduce(
case
123
:
/* typename ::= ids */
{
yymsp
[
0
].
minor
.
yy0
.
type
=
0
;
tS
qlS
etColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
0
].
minor
.
yy0
);
tSetColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
0
].
minor
.
yy0
);
}
yymsp
[
0
].
minor
.
yy295
=
yylhsminor
.
yy295
;
break
;
...
...
@@ -2445,10 +2444,10 @@ static void yy_reduce(
{
if
(
yymsp
[
-
1
].
minor
.
yy525
<=
0
)
{
yymsp
[
-
3
].
minor
.
yy0
.
type
=
0
;
tS
qlS
etColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
3
].
minor
.
yy0
);
tSetColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
3
].
minor
.
yy0
);
}
else
{
yymsp
[
-
3
].
minor
.
yy0
.
type
=
-
yymsp
[
-
1
].
minor
.
yy525
;
// negative value of name length
tS
qlS
etColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
3
].
minor
.
yy0
);
tSetColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
3
].
minor
.
yy0
);
}
}
yymsp
[
-
3
].
minor
.
yy295
=
yylhsminor
.
yy295
;
...
...
@@ -2457,7 +2456,7 @@ static void yy_reduce(
{
yymsp
[
-
1
].
minor
.
yy0
.
type
=
0
;
yymsp
[
-
1
].
minor
.
yy0
.
n
=
((
yymsp
[
0
].
minor
.
yy0
.
z
+
yymsp
[
0
].
minor
.
yy0
.
n
)
-
yymsp
[
-
1
].
minor
.
yy0
.
z
);
tS
qlS
etColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
1
].
minor
.
yy0
);
tSetColumnType
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
1
].
minor
.
yy0
);
}
yymsp
[
-
1
].
minor
.
yy295
=
yylhsminor
.
yy295
;
break
;
...
...
@@ -2476,7 +2475,7 @@ static void yy_reduce(
break
;
case
133
:
/* create_table_list ::= create_from_stable */
{
SCreateTableS
QL
*
pCreateTable
=
calloc
(
1
,
sizeof
(
SCreateTableSQL
));
SCreateTableS
ql
*
pCreateTable
=
calloc
(
1
,
sizeof
(
SCreateTableSql
));
pCreateTable
->
childTableInfo
=
taosArrayInit
(
4
,
sizeof
(
SCreatedTableInfo
));
taosArrayPush
(
pCreateTable
->
childTableInfo
,
&
yymsp
[
0
].
minor
.
yy96
);
...
...
@@ -2494,7 +2493,7 @@ static void yy_reduce(
break
;
case
135
:
/* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */
{
yylhsminor
.
yy230
=
tSetCreate
SqlElems
(
yymsp
[
-
1
].
minor
.
yy285
,
NULL
,
NULL
,
TSQL_CREATE_TABLE
);
yylhsminor
.
yy230
=
tSetCreate
TableInfo
(
yymsp
[
-
1
].
minor
.
yy285
,
NULL
,
NULL
,
TSQL_CREATE_TABLE
);
setSqlInfo
(
pInfo
,
yylhsminor
.
yy230
,
NULL
,
TSDB_SQL_CREATE_TABLE
);
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
...
...
@@ -2504,7 +2503,7 @@ static void yy_reduce(
break
;
case
136
:
/* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */
{
yylhsminor
.
yy230
=
tSetCreate
SqlElems
(
yymsp
[
-
5
].
minor
.
yy285
,
yymsp
[
-
1
].
minor
.
yy285
,
NULL
,
TSQL_CREATE_STABLE
);
yylhsminor
.
yy230
=
tSetCreate
TableInfo
(
yymsp
[
-
5
].
minor
.
yy285
,
yymsp
[
-
1
].
minor
.
yy285
,
NULL
,
TSQL_CREATE_STABLE
);
setSqlInfo
(
pInfo
,
yylhsminor
.
yy230
,
NULL
,
TSDB_SQL_CREATE_TABLE
);
yymsp
[
-
8
].
minor
.
yy0
.
n
+=
yymsp
[
-
7
].
minor
.
yy0
.
n
;
...
...
@@ -2538,7 +2537,7 @@ static void yy_reduce(
break
;
case
141
:
/* create_table_args ::= ifnotexists ids cpxName AS select */
{
yylhsminor
.
yy230
=
tSetCreate
SqlElems
(
NULL
,
NULL
,
yymsp
[
0
].
minor
.
yy216
,
TSQL_CREATE_STREAM
);
yylhsminor
.
yy230
=
tSetCreate
TableInfo
(
NULL
,
NULL
,
yymsp
[
0
].
minor
.
yy342
,
TSQL_CREATE_STREAM
);
setSqlInfo
(
pInfo
,
yylhsminor
.
yy230
,
NULL
,
TSDB_SQL_CREATE_TABLE
);
yymsp
[
-
3
].
minor
.
yy0
.
n
+=
yymsp
[
-
2
].
minor
.
yy0
.
n
;
...
...
@@ -2556,7 +2555,7 @@ static void yy_reduce(
break
;
case
144
:
/* column ::= ids typename */
{
tS
qlS
etColumnInfo
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy295
);
tSetColumnInfo
(
&
yylhsminor
.
yy295
,
&
yymsp
[
-
1
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy295
);
}
yymsp
[
-
1
].
minor
.
yy295
=
yylhsminor
.
yy295
;
break
;
...
...
@@ -2593,23 +2592,23 @@ static void yy_reduce(
break
;
case
156
:
/* select ::= SELECT selcollist from where_opt interval_opt session_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{
yylhsminor
.
yy
216
=
tSetQuerySqlNode
(
&
yymsp
[
-
12
].
minor
.
yy0
,
yymsp
[
-
11
].
minor
.
yy434
,
yymsp
[
-
10
].
minor
.
yy285
,
yymsp
[
-
9
].
minor
.
yy178
,
yymsp
[
-
4
].
minor
.
yy285
,
yymsp
[
-
3
].
minor
.
yy285
,
&
yymsp
[
-
8
].
minor
.
yy376
,
&
yymsp
[
-
7
].
minor
.
yy523
,
&
yymsp
[
-
5
].
minor
.
yy0
,
yymsp
[
-
6
].
minor
.
yy285
,
&
yymsp
[
0
].
minor
.
yy438
,
&
yymsp
[
-
1
].
minor
.
yy438
);
yylhsminor
.
yy
342
=
tSetQuerySqlNode
(
&
yymsp
[
-
12
].
minor
.
yy0
,
yymsp
[
-
11
].
minor
.
yy285
,
yymsp
[
-
10
].
minor
.
yy285
,
yymsp
[
-
9
].
minor
.
yy178
,
yymsp
[
-
4
].
minor
.
yy285
,
yymsp
[
-
3
].
minor
.
yy285
,
&
yymsp
[
-
8
].
minor
.
yy376
,
&
yymsp
[
-
7
].
minor
.
yy523
,
&
yymsp
[
-
5
].
minor
.
yy0
,
yymsp
[
-
6
].
minor
.
yy285
,
&
yymsp
[
0
].
minor
.
yy438
,
&
yymsp
[
-
1
].
minor
.
yy438
);
}
yymsp
[
-
12
].
minor
.
yy
216
=
yylhsminor
.
yy216
;
yymsp
[
-
12
].
minor
.
yy
342
=
yylhsminor
.
yy342
;
break
;
case
157
:
/* union ::= select */
{
yylhsminor
.
yy513
=
setSubclause
(
NULL
,
yymsp
[
0
].
minor
.
yy
216
);
}
{
yylhsminor
.
yy513
=
setSubclause
(
NULL
,
yymsp
[
0
].
minor
.
yy
342
);
}
yymsp
[
0
].
minor
.
yy513
=
yylhsminor
.
yy513
;
break
;
case
158
:
/* union ::= LP union RP */
{
yymsp
[
-
2
].
minor
.
yy513
=
yymsp
[
-
1
].
minor
.
yy513
;
}
break
;
case
159
:
/* union ::= union UNION ALL select */
{
yylhsminor
.
yy513
=
appendSelectClause
(
yymsp
[
-
3
].
minor
.
yy513
,
yymsp
[
0
].
minor
.
yy
216
);
}
{
yylhsminor
.
yy513
=
appendSelectClause
(
yymsp
[
-
3
].
minor
.
yy513
,
yymsp
[
0
].
minor
.
yy
342
);
}
yymsp
[
-
3
].
minor
.
yy513
=
yylhsminor
.
yy513
;
break
;
case
160
:
/* union ::= union UNION ALL LP select RP */
{
yylhsminor
.
yy513
=
appendSelectClause
(
yymsp
[
-
5
].
minor
.
yy513
,
yymsp
[
-
1
].
minor
.
yy
216
);
}
{
yylhsminor
.
yy513
=
appendSelectClause
(
yymsp
[
-
5
].
minor
.
yy513
,
yymsp
[
-
1
].
minor
.
yy
342
);
}
yymsp
[
-
5
].
minor
.
yy513
=
yylhsminor
.
yy513
;
break
;
case
161
:
/* cmd ::= union */
...
...
@@ -2617,29 +2616,30 @@ static void yy_reduce(
break
;
case
162
:
/* select ::= SELECT selcollist */
{
yylhsminor
.
yy
216
=
tSetQuerySqlNode
(
&
yymsp
[
-
1
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy434
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
yylhsminor
.
yy
342
=
tSetQuerySqlNode
(
&
yymsp
[
-
1
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
}
yymsp
[
-
1
].
minor
.
yy
216
=
yylhsminor
.
yy216
;
yymsp
[
-
1
].
minor
.
yy
342
=
yylhsminor
.
yy342
;
break
;
case
163
:
/* sclp ::= selcollist COMMA */
{
yylhsminor
.
yy
434
=
yymsp
[
-
1
].
minor
.
yy434
;}
yymsp
[
-
1
].
minor
.
yy
434
=
yylhsminor
.
yy434
;
{
yylhsminor
.
yy
285
=
yymsp
[
-
1
].
minor
.
yy285
;}
yymsp
[
-
1
].
minor
.
yy
285
=
yylhsminor
.
yy285
;
break
;
case
164
:
/* sclp ::= */
{
yymsp
[
1
].
minor
.
yy434
=
0
;}
case
188
:
/* orderby_opt ::= */
yytestcase
(
yyruleno
==
188
);
{
yymsp
[
1
].
minor
.
yy285
=
0
;}
break
;
case
165
:
/* selcollist ::= sclp distinct expr as */
{
yylhsminor
.
yy
434
=
tSqlExprListAppend
(
yymsp
[
-
3
].
minor
.
yy434
,
yymsp
[
-
1
].
minor
.
yy178
,
yymsp
[
-
2
].
minor
.
yy0
.
n
?
&
yymsp
[
-
2
].
minor
.
yy0
:
0
,
yymsp
[
0
].
minor
.
yy0
.
n
?&
yymsp
[
0
].
minor
.
yy0
:
0
);
yylhsminor
.
yy
285
=
tSqlExprListAppend
(
yymsp
[
-
3
].
minor
.
yy285
,
yymsp
[
-
1
].
minor
.
yy178
,
yymsp
[
-
2
].
minor
.
yy0
.
n
?
&
yymsp
[
-
2
].
minor
.
yy0
:
0
,
yymsp
[
0
].
minor
.
yy0
.
n
?&
yymsp
[
0
].
minor
.
yy0
:
0
);
}
yymsp
[
-
3
].
minor
.
yy
434
=
yylhsminor
.
yy434
;
yymsp
[
-
3
].
minor
.
yy
285
=
yylhsminor
.
yy285
;
break
;
case
166
:
/* selcollist ::= sclp STAR */
{
tS
QLExpr
*
pNode
=
tSqlExprIdValueCreat
e
(
NULL
,
TK_ALL
);
yylhsminor
.
yy
434
=
tSqlExprListAppend
(
yymsp
[
-
1
].
minor
.
yy434
,
pNode
,
0
,
0
);
tS
qlExpr
*
pNode
=
tSqlExprCreateIdValu
e
(
NULL
,
TK_ALL
);
yylhsminor
.
yy
285
=
tSqlExprListAppend
(
yymsp
[
-
1
].
minor
.
yy285
,
pNode
,
0
,
0
);
}
yymsp
[
-
1
].
minor
.
yy
434
=
yylhsminor
.
yy434
;
yymsp
[
-
1
].
minor
.
yy
285
=
yylhsminor
.
yy285
;
break
;
case
167
:
/* as ::= AS ids */
{
yymsp
[
-
1
].
minor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;
}
...
...
@@ -2744,9 +2744,6 @@ static void yy_reduce(
case
187
:
/* sliding_opt ::= */
{
yymsp
[
1
].
minor
.
yy0
.
n
=
0
;
yymsp
[
1
].
minor
.
yy0
.
z
=
NULL
;
yymsp
[
1
].
minor
.
yy0
.
type
=
0
;
}
break
;
case
188
:
/* orderby_opt ::= */
{
yymsp
[
1
].
minor
.
yy285
=
0
;}
break
;
case
189
:
/* orderby_opt ::= ORDER BY sortlist */
{
yymsp
[
-
2
].
minor
.
yy285
=
yymsp
[
0
].
minor
.
yy285
;}
break
;
...
...
@@ -2832,53 +2829,53 @@ static void yy_reduce(
yymsp
[
-
2
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
213
:
/* expr ::= ID */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_ID
);}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_ID
);}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
214
:
/* expr ::= ID DOT ID */
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ID
);}
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ID
);}
yymsp
[
-
2
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
215
:
/* expr ::= ID DOT STAR */
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ALL
);}
{
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
(
1
+
yymsp
[
0
].
minor
.
yy0
.
n
);
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
-
2
].
minor
.
yy0
,
TK_ALL
);}
yymsp
[
-
2
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
216
:
/* expr ::= INTEGER */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_INTEGER
);}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_INTEGER
);}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
217
:
/* expr ::= MINUS INTEGER */
case
218
:
/* expr ::= PLUS INTEGER */
yytestcase
(
yyruleno
==
218
);
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_INTEGER
;
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_INTEGER
);}
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_INTEGER
;
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_INTEGER
);}
yymsp
[
-
1
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
219
:
/* expr ::= FLOAT */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_FLOAT
);}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_FLOAT
);}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
220
:
/* expr ::= MINUS FLOAT */
case
221
:
/* expr ::= PLUS FLOAT */
yytestcase
(
yyruleno
==
221
);
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_FLOAT
;
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_FLOAT
);}
{
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yymsp
[
-
1
].
minor
.
yy0
.
type
=
TK_FLOAT
;
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
-
1
].
minor
.
yy0
,
TK_FLOAT
);}
yymsp
[
-
1
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
222
:
/* expr ::= STRING */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_STRING
);}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_STRING
);}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
223
:
/* expr ::= NOW */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_NOW
);
}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_NOW
);
}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
224
:
/* expr ::= VARIABLE */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_VARIABLE
);}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_VARIABLE
);}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
225
:
/* expr ::= BOOL */
{
yylhsminor
.
yy178
=
tSqlExpr
IdValueCreat
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_BOOL
);}
{
yylhsminor
.
yy178
=
tSqlExpr
CreateIdValu
e
(
&
yymsp
[
0
].
minor
.
yy0
,
TK_BOOL
);}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
226
:
/* expr ::= ID LP exprlist RP */
{
yylhsminor
.
yy178
=
tSqlExprCreateFunction
(
yymsp
[
-
1
].
minor
.
yy
434
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
,
yymsp
[
-
3
].
minor
.
yy0
.
type
);
}
{
yylhsminor
.
yy178
=
tSqlExprCreateFunction
(
yymsp
[
-
1
].
minor
.
yy
285
,
&
yymsp
[
-
3
].
minor
.
yy0
,
&
yymsp
[
0
].
minor
.
yy0
,
yymsp
[
-
3
].
minor
.
yy0
.
type
);
}
yymsp
[
-
3
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
227
:
/* expr ::= ID LP STAR RP */
...
...
@@ -2918,7 +2915,7 @@ static void yy_reduce(
yymsp
[
-
2
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
236
:
/* expr ::= expr BETWEEN expr AND expr */
{
tS
QL
Expr
*
X2
=
tSqlExprClone
(
yymsp
[
-
4
].
minor
.
yy178
);
yylhsminor
.
yy178
=
tSqlExprCreate
(
tSqlExprCreate
(
yymsp
[
-
4
].
minor
.
yy178
,
yymsp
[
-
2
].
minor
.
yy178
,
TK_GE
),
tSqlExprCreate
(
X2
,
yymsp
[
0
].
minor
.
yy178
,
TK_LE
),
TK_AND
);}
{
tS
ql
Expr
*
X2
=
tSqlExprClone
(
yymsp
[
-
4
].
minor
.
yy178
);
yylhsminor
.
yy178
=
tSqlExprCreate
(
tSqlExprCreate
(
yymsp
[
-
4
].
minor
.
yy178
,
yymsp
[
-
2
].
minor
.
yy178
,
TK_GE
),
tSqlExprCreate
(
X2
,
yymsp
[
0
].
minor
.
yy178
,
TK_LE
),
TK_AND
);}
yymsp
[
-
4
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
237
:
/* expr ::= expr AND expr */
...
...
@@ -2954,28 +2951,28 @@ static void yy_reduce(
yymsp
[
-
2
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
245
:
/* expr ::= expr IN LP exprlist RP */
{
yylhsminor
.
yy178
=
tSqlExprCreate
(
yymsp
[
-
4
].
minor
.
yy178
,
(
tS
QLExpr
*
)
yymsp
[
-
1
].
minor
.
yy434
,
TK_IN
);
}
{
yylhsminor
.
yy178
=
tSqlExprCreate
(
yymsp
[
-
4
].
minor
.
yy178
,
(
tS
qlExpr
*
)
yymsp
[
-
1
].
minor
.
yy285
,
TK_IN
);
}
yymsp
[
-
4
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
246
:
/* exprlist ::= exprlist COMMA expritem */
{
yylhsminor
.
yy
434
=
tSqlExprListAppend
(
yymsp
[
-
2
].
minor
.
yy434
,
yymsp
[
0
].
minor
.
yy178
,
0
,
0
);}
yymsp
[
-
2
].
minor
.
yy
434
=
yylhsminor
.
yy434
;
{
yylhsminor
.
yy
285
=
tSqlExprListAppend
(
yymsp
[
-
2
].
minor
.
yy285
,
yymsp
[
0
].
minor
.
yy178
,
0
,
0
);}
yymsp
[
-
2
].
minor
.
yy
285
=
yylhsminor
.
yy285
;
break
;
case
247
:
/* exprlist ::= expritem */
{
yylhsminor
.
yy
434
=
tSqlExprListAppend
(
0
,
yymsp
[
0
].
minor
.
yy178
,
0
,
0
);}
yymsp
[
0
].
minor
.
yy
434
=
yylhsminor
.
yy434
;
{
yylhsminor
.
yy
285
=
tSqlExprListAppend
(
0
,
yymsp
[
0
].
minor
.
yy178
,
0
,
0
);}
yymsp
[
0
].
minor
.
yy
285
=
yylhsminor
.
yy285
;
break
;
case
248
:
/* expritem ::= expr */
{
yylhsminor
.
yy178
=
yymsp
[
0
].
minor
.
yy178
;}
yymsp
[
0
].
minor
.
yy178
=
yylhsminor
.
yy178
;
break
;
case
250
:
/* cmd ::= RESET QUERY CACHE */
{
setDCLS
QL
Elems
(
pInfo
,
TSDB_SQL_RESET_CACHE
,
0
);}
{
setDCLS
ql
Elems
(
pInfo
,
TSDB_SQL_RESET_CACHE
,
0
);}
break
;
case
251
:
/* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
-
1
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2986,14 +2983,14 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
SArray
*
K
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
-
1
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
case
253
:
/* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
,
-
1
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -3004,7 +3001,7 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
,
-
1
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -3018,7 +3015,7 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
A
=
tVariantListAppendToken
(
A
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
5
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
5
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
,
-
1
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -3030,14 +3027,14 @@ static void yy_reduce(
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
A
=
tVariantListAppend
(
A
,
&
yymsp
[
0
].
minor
.
yy362
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
6
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
6
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
,
-
1
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
case
257
:
/* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
TSDB_SUPER_TABLE
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
TSDB_SUPER_TABLE
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -3048,14 +3045,14 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
SArray
*
K
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
TSDB_SUPER_TABLE
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
TSDB_SUPER_TABLE
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
case
259
:
/* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
,
TSDB_SUPER_TABLE
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy285
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
,
TSDB_SUPER_TABLE
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -3066,7 +3063,7 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
,
TSDB_SUPER_TABLE
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
,
TSDB_SUPER_TABLE
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -3080,7 +3077,7 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
A
=
tVariantListAppendToken
(
A
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableInfo
*
pAlterTable
=
t
AlterTableSqlElems
(
&
yymsp
[
-
5
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
,
TSDB_SUPER_TABLE
);
SAlterTableInfo
*
pAlterTable
=
t
SetAlterTableInfo
(
&
yymsp
[
-
5
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
,
TSDB_SUPER_TABLE
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录