Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fb2ca78d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fb2ca78d
编写于
10月 25, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify parse to handle sql func
上级
5116a654
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
88 addition
and
96 deletion
+88
-96
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+88
-96
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
fb2ca78d
...
...
@@ -107,7 +107,8 @@ static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryIn
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
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
);
static
int32_t
validateSQLExprTerm
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
);
static
int32_t
validateEp
(
char
*
ep
);
static
int32_t
validateDNodeConfig
(
SMiscInfo
*
pOptions
);
static
int32_t
validateLocalConfig
(
SMiscInfo
*
pOptions
);
...
...
@@ -1748,7 +1749,8 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
SColumnList
columnList
=
{
0
};
int32_t
arithmeticType
=
NON_ARITHMEIC_EXPR
;
if
(
validateArithmeticSQLExpr
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmeticType
)
!=
TSDB_CODE_SUCCESS
)
{
uint64_t
uid
;
if
(
validateSQLExprTerm
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmeticType
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -4285,140 +4287,130 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
return
checkAndSetJoinCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
);
}
static
int32_t
validateSQLExpr
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
if
(
pExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
static
int32_t
validateArithmeticSQLFunc
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
int32_t
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
functionId
<
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
*
type
=
NORMAL_ARITHMETIC
;
}
else
if
(
*
type
==
AGG_ARIGHTMEIC
)
{
}
else
{
*
type
=
AGG_ARIGHTMEIC
;
}
}
else
if
(
*
type
==
NORMAL_ARITHMETIC
)
{
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
}
else
{
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
// if column is timestamp, bool, binary, nchar, not support arithmetic, so return invalid sql
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
)
+
index
.
columnIndex
;
if
((
pSchema
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
||
(
pSchema
->
type
==
TSDB_DATA_TYPE_BOOL
)
||
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
)
||
(
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
))
{
if
(
*
type
==
AGG_ARIGHTMEIC
)
{
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
};
// sql function list in selection clause.
// Append the sqlExpr into exprList of pQueryInfo structure sequentially
pExpr
->
functionId
=
functionId
;
if
(
addExprAndResultField
(
pCmd
,
pQueryInfo
,
outputIndex
,
&
item
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pList
->
ids
[
pList
->
num
++
]
=
index
;
}
else
if
((
pExpr
->
tokenId
==
TK_FLOAT
&&
(
isnan
(
pExpr
->
value
.
dKey
)
||
isinf
(
pExpr
->
value
.
dKey
)))
||
pExpr
->
tokenId
==
TK_NULL
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
int32_t
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
functionId
<
0
)
{
// It is invalid in case of more than one sqlExpr, such as first(ts, k) - last(ts, k)
int32_t
inc
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
)
-
outputIndex
;
if
(
inc
>
1
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
*
type
=
NORMAL_ARITHMETIC
;
}
else
{
*
type
=
AGG_ARIGHTMEIC
;
}
}
else
if
(
*
type
==
NORMAL_ARITHMETIC
)
{
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
else
{
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
*
type
==
AGG_ARIGHTMEIC
)
{
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
// Not supported data type in arithmetic expression
uint64_t
id
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
inc
;
++
i
)
{
SExprInfo
*
p1
=
tscExprGet
(
pQueryInfo
,
i
+
outputIndex
);
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
};
// sql function list in selection clause.
// Append the sqlExpr into exprList of pQueryInfo structure sequentially
pExpr
->
functionId
=
functionId
;
if
(
addExprAndResultField
(
pCmd
,
pQueryInfo
,
outputIndex
,
&
item
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
int16_t
t
=
p1
->
base
.
resType
;
if
(
t
==
TSDB_DATA_TYPE_BINARY
||
t
==
TSDB_DATA_TYPE_NCHAR
||
t
==
TSDB_DATA_TYPE_BOOL
||
t
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// It is invalid in case of more than one sqlExpr, such as first(ts, k) - last(ts, k)
int32_t
inc
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
)
-
outputIndex
;
if
(
inc
>
1
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
if
(
i
==
0
)
{
id
=
p1
->
base
.
uid
;
continue
;
}
// Not supported data type in arithmetic expression
uint64_t
id
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
inc
;
++
i
)
{
SExprInfo
*
p1
=
tscExprGet
(
pQueryInfo
,
i
+
outputIndex
);
int16_t
t
=
p1
->
base
.
resType
;
if
(
t
==
TSDB_DATA_TYPE_BINARY
||
t
==
TSDB_DATA_TYPE_NCHAR
||
t
==
TSDB_DATA_TYPE_BOOL
||
t
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
i
==
0
)
{
id
=
p1
->
base
.
uid
;
continue
;
}
if
(
id
!=
p1
->
base
.
uid
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
id
!=
p1
->
base
.
uid
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
*
uid
=
id
;
*
uid
=
id
;
}
else
{
size_t
numChilds
=
taosArrayGetSize
(
pExpr
->
Expr
.
paramList
);
for
(
int
i
=
0
;
i
<
numChilds
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
validateSQLExprTerm
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
type
,
uid
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
)
{
static
int32_t
validateSQLExprTerm
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
tSqlExpr
*
pLeft
=
pExpr
->
pLeft
;
uint64_t
uidLeft
=
0
;
uint64_t
uidRight
=
0
;
if
(
pLeft
->
type
==
SQL_NODE_EXPR
)
{
int32_t
ret
=
validateArithmeticSQLExpr
(
pCmd
,
pLeft
,
pQueryInfo
,
pList
,
type
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
}
else
{
int32_t
ret
=
validateSQLExpr
(
pCmd
,
pLeft
,
pQueryInfo
,
pList
,
type
,
&
uidLeft
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
}
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
type
==
SQL_NODE_EXPR
)
{
int32_t
ret
=
validateArithmeticSQLExpr
(
pCmd
,
pRight
,
pQueryInfo
,
pList
,
type
);
if
(
pExpr
->
type
==
SQL_NODE_EXPR
)
{
uint64_t
uidLeft
=
0
;
uint64_t
uidRight
=
0
;
int32_t
ret
=
validateSQLExprTerm
(
pCmd
,
pExpr
->
pLeft
,
pQueryInfo
,
pList
,
type
,
&
uidLeft
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
}
else
{
int32_t
ret
=
validateSQLExpr
(
pCmd
,
pRight
,
pQueryInfo
,
pList
,
type
,
&
uidRight
);
ret
=
validateSQLExprTerm
(
pCmd
,
pExpr
->
pRight
,
pQueryInfo
,
pList
,
type
,
&
uidRight
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
// the expression not from the same table, return error
if
(
uidLeft
!=
uidRight
&&
uidLeft
!=
0
&&
uidRight
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
*
uid
=
uidLeft
;
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
validateArithmeticSQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
}
else
if
(
pExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
*
type
=
NORMAL_ARITHMETIC
;
}
else
if
(
*
type
==
AGG_ARIGHTMEIC
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// if column is timestamp, bool, binary, nchar, not support arithmetic, so return invalid sql
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
)
+
index
.
columnIndex
;
if
((
pSchema
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
||
(
pSchema
->
type
==
TSDB_DATA_TYPE_BOOL
)
||
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
)
||
(
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pList
->
ids
[
pList
->
num
++
]
=
index
;
}
else
if
((
pExpr
->
tokenId
==
TK_FLOAT
&&
(
isnan
(
pExpr
->
value
.
dKey
)
||
isinf
(
pExpr
->
value
.
dKey
)))
||
pExpr
->
tokenId
==
TK_NULL
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
return
TSDB_CODE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录