Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7d34d0a4
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看板
提交
7d34d0a4
编写于
11月 01, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
separate scalar function with aggregate function
上级
9ee2e032
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
133 addition
and
97 deletion
+133
-97
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+133
-97
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
7d34d0a4
...
...
@@ -1740,27 +1740,18 @@ void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t tableUid) {
tscColumnListInsert
(
pQueryInfo
->
colList
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
,
tableUid
,
&
s
);
}
static
int32_t
handle
ArithmeticExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
)
{
const
char
*
msg1
=
"invalid column name, illegal column type, or columns in arithmetic expression from two tables"
;
static
int32_t
handle
ScalarExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
,
SColumnList
*
columnList
,
bool
finalResult
)
{
const
char
*
msg2
=
"invalid arithmetic expression in select clause"
;
const
char
*
msg3
=
"tag columns can not be used in arithmetic expression"
;
const
char
*
msg4
=
"columns from different table mixed up in arithmetic expression"
;
SColumnList
columnList
=
{
0
};
int32_t
arithmeticType
=
NON_ARITHMEIC_EXPR
;
uint64_t
uid
;
if
(
validateSQLExprTerm
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmeticType
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
tableIndex
=
columnList
.
ids
[
0
].
tableIndex
;
if
(
arithmeticType
==
NORMAL_ARITHMETIC
)
{
int32_t
tableIndex
=
columnList
->
ids
[
0
].
tableIndex
;
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_PROJECTION_QUERY
;
// all columns in arithmetic expression must belong to the same table
for
(
int32_t
f
=
1
;
f
<
columnList
.
num
;
++
f
)
{
if
(
columnList
.
ids
[
f
].
tableIndex
!=
tableIndex
)
{
for
(
int32_t
f
=
1
;
f
<
columnList
->
num
;
++
f
)
{
if
(
columnList
->
ids
[
f
].
tableIndex
!=
tableIndex
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
}
...
...
@@ -1812,7 +1803,10 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
// set the serialized binary string as the parameter of arithmetic expression
tscExprAddParams
(
&
pExpr
->
base
,
c
,
TSDB_DATA_TYPE_BINARY
,
(
int32_t
)
len
);
insertResultField
(
pQueryInfo
,
exprIndex
,
&
columnList
,
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
pExpr
->
base
.
aliasName
,
pExpr
);
if
(
finalResult
)
{
insertResultField
(
pQueryInfo
,
exprIndex
,
columnList
,
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
pExpr
->
base
.
aliasName
,
pExpr
);
}
// add ts column
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pExpr
->
base
.
uid
);
...
...
@@ -1820,15 +1814,20 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
tbufCloseWriter
(
&
bw
);
taosArrayDestroy
(
colList
);
tExprTreeDestroy
(
pNode
,
NULL
);
}
else
{
columnList
.
num
=
0
;
columnList
.
ids
[
0
]
=
(
SColumnIndex
)
{
0
,
0
};
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
handleAggregateExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
,
SColumnList
*
columnList
,
bool
finalResult
)
{
columnList
->
num
=
0
;
columnList
->
ids
[
0
]
=
(
SColumnIndex
)
{
0
,
0
};
char
rawName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
char
aliasName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
getColumnName
(
pItem
,
aliasName
,
rawName
,
TSDB_COL_NAME_LEN
);
insertResultField
(
pQueryInfo
,
exprIndex
,
&
columnList
,
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
aliasName
,
NULL
);
insertResultField
(
pQueryInfo
,
exprIndex
,
columnList
,
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
aliasName
,
NULL
);
int32_t
slot
=
tscNumOfFields
(
pQueryInfo
)
-
1
;
SInternalField
*
pInfo
=
tscFieldInfoGetInternalField
(
&
pQueryInfo
->
fieldsInfo
,
slot
);
...
...
@@ -1871,6 +1870,25 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
pSqlExpr
->
param
[
0
].
nType
=
TSDB_DATA_TYPE_BINARY
;
// tbufCloseWriter(&bw); // TODO there is a memory leak
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
handleArithmeticExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
)
{
const
char
*
msg1
=
"invalid column name, illegal column type, or columns in arithmetic expression from two tables"
;
SColumnList
columnList
=
{
0
};
int32_t
arithmeticType
=
NON_ARITHMEIC_EXPR
;
uint64_t
uid
;
if
(
validateSQLExprTerm
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmeticType
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
arithmeticType
==
NORMAL_ARITHMETIC
)
{
handleScalarExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
}
else
{
handleAggregateExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -4321,6 +4339,7 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
static
int32_t
validateArithmeticSQLFunc
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
functionId
<
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
@@ -4335,20 +4354,31 @@ static int32_t validateArithmeticSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
*
type
=
AGG_ARIGHTMEIC
;
}
}
else
{
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
pExpr
->
functionId
=
functionId
;
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
);
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
)
&&
(
pParamElem
->
pNode
->
type
==
SQL_NODE_EXPR
||
pParamElem
->
pNode
->
type
==
SQL_NODE_SQLFUNCTION
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
code
=
validateSQLExprTerm
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
type
,
uid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
for
(
int
i
=
0
;
i
<
numChilds
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
if
(
pParamElem
->
pNode
->
type
==
SQL_NODE_EXPR
||
pParamElem
->
pNode
->
type
==
SQL_NODE_SQLFUNCTION
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
*
type
==
AGG_ARIGHTMEIC
)
{
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
};
...
...
@@ -4406,6 +4436,9 @@ static int32_t validateSQLExprTerm(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
if
(
pExpr
->
type
==
SQL_NODE_EXPR
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
*
type
=
NORMAL_ARITHMETIC
;
}
uint64_t
uidLeft
=
0
;
uint64_t
uidRight
=
0
;
int32_t
ret
=
validateSQLExprTerm
(
pCmd
,
pExpr
->
pLeft
,
pQueryInfo
,
pList
,
type
,
&
uidLeft
);
...
...
@@ -4423,7 +4456,10 @@ static int32_t validateSQLExprTerm(SSqlCmd* pCmd, tSqlExpr* pExpr,
*
uid
=
uidLeft
;
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
validateArithmeticSQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
int32_t
ret
=
validateArithmeticSQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
}
else
if
(
pExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pExpr
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录