Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5116a654
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5116a654
编写于
10月 25, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add TSQL_NODE_FUNC. before arithmetic traverse modification
上级
ec9fcda9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
56 deletion
+123
-56
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+90
-56
src/common/inc/texpr.h
src/common/inc/texpr.h
+8
-0
src/common/src/texpr.c
src/common/src/texpr.c
+25
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
5116a654
...
...
@@ -4313,54 +4313,68 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQuer
pExpr
->
tokenId
==
TK_NULL
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
*
type
=
AGG_ARIGHTMEIC
;
}
else
if
(
*
type
==
NORMAL_ARITHMETIC
)
{
int32_t
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
functionId
<
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
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
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
pExpr
->
functionId
<
0
)
{
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
(
addExprAndResultField
(
pCmd
,
pQueryInfo
,
outputIndex
,
&
item
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
*
type
==
AGG_ARIGHTMEIC
)
{
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
// 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
;
}
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
};
// 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
);
// sql function list in selection clause.
// Append the sqlExpr into exprList of pQueryInfo structure sequentially
pExpr
->
functionId
=
functionId
;
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
)
{
if
(
addExprAndResultField
(
pCmd
,
pQueryInfo
,
outputIndex
,
&
item
,
false
,
NULL
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
i
==
0
)
{
id
=
p1
->
base
.
uid
;
continue
;
// 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
(
id
!=
p1
->
base
.
uid
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
// 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
;
}
}
}
*
uid
=
id
;
*
uid
=
id
;
}
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -9310,30 +9324,50 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
}
return
ret
;
}
else
if
(
pSqlExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
// arithmetic expression on the results of aggregation functions
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
pSqlExpr
->
exprToken
.
z
,
pSqlExpr
->
exprToken
.
n
);
// set the input column data byte and type.
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
exprList
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SExprInfo
*
p1
=
taosArrayGetP
(
pQueryInfo
->
exprList
,
i
);
if
(
strcmp
((
*
pExpr
)
->
pSchema
->
name
,
p1
->
base
.
aliasName
)
==
0
)
{
(
*
pExpr
)
->
pSchema
->
type
=
(
uint8_t
)
p1
->
base
.
resType
;
(
*
pExpr
)
->
pSchema
->
bytes
=
p1
->
base
.
resBytes
;
(
*
pExpr
)
->
pSchema
->
colId
=
p1
->
base
.
resColId
;
if
(
uid
!=
NULL
)
{
*
uid
=
p1
->
base
.
uid
;
if
(
TSDB_FUNC_IS_SCALAR
(
pSqlExpr
->
functionId
))
{
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_FUNC
;
(
*
pExpr
)
->
_func
.
functionId
=
pSqlExpr
->
functionId
;
SArray
*
paramList
=
pSqlExpr
->
Expr
.
paramList
;
size_t
paramSize
=
taosArrayGetSize
(
paramList
);
if
(
paramSize
>
0
)
{
(
*
pExpr
)
->
_func
.
numChilds
=
paramSize
;
(
*
pExpr
)
->
_func
.
pChilds
=
(
tExprNode
**
)
calloc
(
paramSize
,
sizeof
(
tExprNode
*
));
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
paramList
);
++
i
)
{
tSqlExprItem
*
param
=
taosArrayGet
(
paramList
,
i
);
tSqlExpr
*
paramNode
=
param
->
pNode
;
int32_t
ret
=
exprTreeFromSqlExpr
(
pCmd
,
(
*
pExpr
)
->
_func
.
pChilds
+
i
,
paramNode
,
pQueryInfo
,
pCols
,
uid
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
break
;
}
}
}
else
{
// arithmetic expression on the results of aggregation functions
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_COL
;
(
*
pExpr
)
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
strncpy
((
*
pExpr
)
->
pSchema
->
name
,
pSqlExpr
->
exprToken
.
z
,
pSqlExpr
->
exprToken
.
n
);
// set the input column data byte and type.
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
exprList
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SExprInfo
*
p1
=
taosArrayGetP
(
pQueryInfo
->
exprList
,
i
);
if
(
strcmp
((
*
pExpr
)
->
pSchema
->
name
,
p1
->
base
.
aliasName
)
==
0
)
{
(
*
pExpr
)
->
pSchema
->
type
=
(
uint8_t
)
p1
->
base
.
resType
;
(
*
pExpr
)
->
pSchema
->
bytes
=
p1
->
base
.
resBytes
;
(
*
pExpr
)
->
pSchema
->
colId
=
p1
->
base
.
resColId
;
if
(
uid
!=
NULL
)
{
*
uid
=
p1
->
base
.
uid
;
}
break
;
}
}
// endfor each expr
}
// end not scalar function
}
else
if
(
pSqlExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
// column name, normal column arithmetic expression
int32_t
ret
=
getColumnIndexByName
(
&
pSqlExpr
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
));
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
...
...
src/common/inc/texpr.h
浏览文件 @
5116a654
...
...
@@ -49,6 +49,7 @@ enum {
TSQL_NODE_EXPR
=
0x1
,
TSQL_NODE_COL
=
0x2
,
TSQL_NODE_VALUE
=
0x4
,
TSQL_NODE_FUNC
=
0x8
};
/**
...
...
@@ -74,7 +75,14 @@ typedef struct tExprNode {
}
_node
;
struct
SSchema
*
pSchema
;
tVariant
*
pVal
;
struct
{
int16_t
functionId
;
uint8_t
numChilds
;
struct
tExprNode
**
pChilds
;
}
_func
;
};
}
tExprNode
;
...
...
src/common/src/texpr.c
浏览文件 @
5116a654
...
...
@@ -119,6 +119,8 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
tVariantDestroy
(
pNode
->
pVal
);
}
else
if
(
pNode
->
nodeType
==
TSQL_NODE_COL
)
{
tfree
(
pNode
->
pSchema
);
}
else
if
(
pNode
->
nodeType
==
TSQL_NODE_FUNC
)
{
doExprTreeDestroy
(
&
pNode
,
fp
);
}
free
(
pNode
);
...
...
@@ -141,6 +143,10 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
free
((
*
pExpr
)
->
pVal
);
}
else
if
((
*
pExpr
)
->
nodeType
==
TSQL_NODE_COL
)
{
free
((
*
pExpr
)
->
pSchema
);
}
else
if
((
*
pExpr
)
->
nodeType
==
TSQL_NODE_FUNC
)
{
for
(
int
i
=
0
;
i
<
(
*
pExpr
)
->
_func
.
numChilds
;
++
i
)
{
doExprTreeDestroy
((
*
pExpr
)
->
_func
.
pChilds
+
i
,
fp
);
}
}
free
(
*
pExpr
);
...
...
@@ -307,6 +313,12 @@ static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
tbufWriteUint8
(
bw
,
expr
->
_node
.
hasPK
);
exprTreeToBinaryImpl
(
bw
,
expr
->
_node
.
pLeft
);
exprTreeToBinaryImpl
(
bw
,
expr
->
_node
.
pRight
);
}
else
if
(
expr
->
nodeType
==
TSQL_NODE_FUNC
)
{
tbufWriteInt16
(
bw
,
expr
->
_func
.
functionId
);
tbufWriteUint8
(
bw
,
expr
->
_func
.
numChilds
);
for
(
int
i
=
0
;
i
<
expr
->
_func
.
numChilds
;
++
i
)
{
exprTreeToBinaryImpl
(
bw
,
expr
->
_func
.
pChilds
[
i
]);
}
}
}
...
...
@@ -372,6 +384,13 @@ static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) {
pExpr
->
_node
.
pLeft
=
exprTreeFromBinaryImpl
(
br
);
pExpr
->
_node
.
pRight
=
exprTreeFromBinaryImpl
(
br
);
assert
(
pExpr
->
_node
.
pLeft
!=
NULL
&&
pExpr
->
_node
.
pRight
!=
NULL
);
}
else
if
(
pExpr
->
nodeType
==
TSQL_NODE_FUNC
)
{
pExpr
->
_func
.
functionId
=
tbufReadInt16
(
br
);
pExpr
->
_func
.
numChilds
=
tbufReadUint8
(
br
);
pExpr
->
_func
.
pChilds
=
(
tExprNode
**
)
calloc
(
pExpr
->
_func
.
numChilds
,
sizeof
(
tExprNode
*
));
for
(
int
i
=
0
;
i
<
pExpr
->
_func
.
numChilds
;
++
i
)
{
pExpr
->
_func
.
pChilds
[
i
]
=
exprTreeFromBinaryImpl
(
br
);
}
}
CLEANUP_EXECUTE_TO
(
anchor
,
false
);
...
...
@@ -620,6 +639,12 @@ tExprNode* exprdup(tExprNode* pNode) {
}
else
if
(
pNode
->
nodeType
==
TSQL_NODE_COL
)
{
pCloned
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
*
pCloned
->
pSchema
=
*
pNode
->
pSchema
;
}
else
if
(
pNode
->
nodeType
==
TSQL_NODE_FUNC
)
{
pCloned
->
_func
.
functionId
=
pNode
->
_func
.
functionId
;
pCloned
->
_func
.
numChilds
=
pNode
->
_func
.
numChilds
;
for
(
int
i
=
0
;
i
<
pNode
->
_func
.
numChilds
;
++
i
)
{
pCloned
->
_func
.
pChilds
[
i
]
=
exprdup
(
pNode
->
_func
.
pChilds
[
i
]);
}
}
pCloned
->
nodeType
=
pNode
->
nodeType
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录