Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6d9a8ab0
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
6d9a8ab0
编写于
11月 11, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change arithemtic to scalar expr
上级
7da31782
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
49 addition
and
137 deletion
+49
-137
src/client/inc/tscSubquery.h
src/client/inc/tscSubquery.h
+1
-1
src/client/src/tscGlobalmerge.c
src/client/src/tscGlobalmerge.c
+3
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+13
-84
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+2
-2
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+4
-4
src/query/inc/qAggMain.h
src/query/inc/qAggMain.h
+3
-3
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+1
-1
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+10
-28
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+12
-12
未找到文件。
src/client/inc/tscSubquery.h
浏览文件 @
6d9a8ab0
...
...
@@ -42,7 +42,7 @@ int32_t tscHandleInsertRetry(SSqlObj* parent, SSqlObj* child);
void
tscBuildResFromSubqueries
(
SSqlObj
*
pSql
);
TAOS_ROW
doSetResultRowData
(
SSqlObj
*
pSql
);
char
*
get
Arithmetic
InputSrc
(
void
*
param
,
const
char
*
name
,
int32_t
colId
);
char
*
get
ScalarExpr
InputSrc
(
void
*
param
,
const
char
*
name
,
int32_t
colId
);
void
tscLockByThread
(
int64_t
*
lockedBy
);
...
...
src/client/src/tscGlobalmerge.c
浏览文件 @
6d9a8ab0
...
...
@@ -713,7 +713,7 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
char
*
pbuf
=
calloc
(
1
,
(
size_t
)(
pOutput
->
num
*
maxRowSize
));
size_t
size
=
tscNumOfFields
(
pQueryInfo
);
S
Arithmetic
Support
arithSup
=
{
0
};
S
ScalarExpr
Support
arithSup
=
{
0
};
// todo refactor
arithSup
.
offset
=
0
;
...
...
@@ -736,7 +736,8 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
arithSup
.
pExprInfo
=
pSup
->
pExpr
;
tExprOperandInfo
output
;
output
.
data
=
pbuf
+
pOutput
->
num
*
offset
;
exprTreeNodeTraverse
(
arithSup
.
pExprInfo
->
pExpr
,
(
int32_t
)
pOutput
->
num
,
&
output
,
&
arithSup
,
TSDB_ORDER_ASC
,
getArithmeticInputSrc
);
exprTreeNodeTraverse
(
arithSup
.
pExprInfo
->
pExpr
,
(
int32_t
)
pOutput
->
num
,
&
output
,
&
arithSup
,
TSDB_ORDER_ASC
,
getScalarExprInputSrc
);
}
else
{
SExprInfo
*
pExpr
=
pSup
->
pExpr
;
memcpy
(
pbuf
+
pOutput
->
num
*
offset
,
pExpr
->
base
.
offset
*
pOutput
->
num
+
pOutput
->
data
,
(
size_t
)(
pExpr
->
base
.
resBytes
*
pOutput
->
num
));
...
...
src/client/src/tscSQLParser.c
浏览文件 @
6d9a8ab0
...
...
@@ -1740,7 +1740,7 @@ void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t tableUid) {
tscColumnListInsert
(
pQueryInfo
->
colList
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
,
tableUid
,
&
s
);
}
static
int32_t
handleScalarExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
,
static
int32_t
handleScalar
Type
Expr
(
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"
;
...
...
@@ -1789,7 +1789,7 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e
}
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
TSDB_FUNC_
ARITHM
,
&
index
,
pNode
->
resultType
,
pNode
->
resultBytes
,
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
TSDB_FUNC_
SCALAR_EXPR
,
&
index
,
pNode
->
resultType
,
pNode
->
resultBytes
,
getNewResColId
(
pCmd
),
0
,
false
);
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
pItem
->
pNode
->
exprToken
.
z
;
...
...
@@ -1826,7 +1826,7 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
handleAgg
regat
eExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
,
static
int32_t
handleAgg
Typ
eExpr
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
exprIndex
,
tSqlExprItem
*
pItem
,
SColumnList
*
columnList
,
bool
finalResult
)
{
const
char
*
msg2
=
"invalid arithmetic expression in select clause"
;
...
...
@@ -1851,7 +1851,7 @@ static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_
pExprInfo
->
base
.
interBytes
=
0
;
pExprInfo
->
base
.
resType
=
TSDB_DATA_TYPE_DOUBLE
;
pExprInfo
->
base
.
functionId
=
TSDB_FUNC_
ARITHM
;
pExprInfo
->
base
.
functionId
=
TSDB_FUNC_
SCALAR_EXPR
;
pExprInfo
->
base
.
numOfParams
=
1
;
pExprInfo
->
base
.
resColId
=
getNewResColId
(
pCmd
);
strncpy
(
pExprInfo
->
base
.
aliasName
,
aliasName
,
tListLen
(
pExprInfo
->
base
.
aliasName
));
...
...
@@ -1893,18 +1893,18 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
const
char
*
msg1
=
"invalid column name, illegal column type, or columns in arithmetic expression from two tables"
;
SColumnList
columnList
=
{
0
};
int32_t
arithmetic
Type
=
SQLEXPR_TYPE_UNASSIGNED
;
int32_t
sqlExpr
Type
=
SQLEXPR_TYPE_UNASSIGNED
;
uint64_t
uid
;
if
(
validateSQLExprItem
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmetic
Type
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateSQLExprItem
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
sqlExpr
Type
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
arithmetic
Type
==
SQLEXPR_TYPE_SCALAR
)
{
code
=
handleScalarExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
if
(
sqlExpr
Type
==
SQLEXPR_TYPE_SCALAR
)
{
code
=
handleScalar
Type
Expr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
}
else
{
code
=
handleAgg
regat
eExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
code
=
handleAgg
Typ
eExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
}
return
code
;
...
...
@@ -3138,79 +3138,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_SCALAR_LOG
:
case
TSDB_FUNC_SCALAR_POW
:
{
// 1. valid the number of parameters
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
2
)
{
/* no parameters or more than one parameter for function */
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pItem
->
pNode
->
Expr
.
paramList
,
0
);
if
(
pParamElem
->
pNode
->
tokenId
!=
TK_ID
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pParamElem
->
pNode
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
index
.
columnIndex
);
// functions can not be applied to tags
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
// 2. valid the column type
if
(
!
IS_NUMERIC_TYPE
(
pSchema
->
type
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
// 3. valid the parameters
if
(
pParamElem
[
1
].
pNode
->
tokenId
==
TK_ID
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
int16_t
resultType
=
pSchema
->
type
;
int16_t
resultSize
=
pSchema
->
bytes
;
int32_t
interResult
=
0
;
tVariant
*
pVariant
=
&
pParamElem
[
1
].
pNode
->
value
;
char
val
[
8
]
=
{
0
};
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
true
);
SExprInfo
*
pExpr
=
NULL
;
getResultDataInfo
(
pSchema
->
type
,
pSchema
->
bytes
,
functionId
,
0
,
&
resultType
,
&
resultSize
,
&
interResult
,
0
,
false
,
pUdfInfo
);
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
interResult
,
false
);
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
memset
(
pExpr
->
base
.
aliasName
,
0
,
tListLen
(
pExpr
->
base
.
aliasName
));
getColumnName
(
pItem
,
pExpr
->
base
.
aliasName
,
pExpr
->
base
.
token
,
sizeof
(
pExpr
->
base
.
aliasName
)
-
1
);
SColumnList
ids
=
createColumnList
(
1
,
index
.
tableIndex
,
index
.
columnIndex
);
if
(
finalResult
)
{
int32_t
numOfOutput
=
tscNumOfFields
(
pQueryInfo
);
insertResultField
(
pQueryInfo
,
numOfOutput
,
&
ids
,
pExpr
->
base
.
resBytes
,
(
int32_t
)
pExpr
->
base
.
resType
,
pExpr
->
base
.
aliasName
,
pExpr
);
}
else
{
assert
(
ids
.
num
==
1
);
tscColumnListInsert
(
pQueryInfo
->
colList
,
ids
.
ids
[
0
].
columnIndex
,
pExpr
->
base
.
uid
,
pSchema
);
}
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pExpr
->
base
.
uid
);
return
TSDB_CODE_SUCCESS
;
}
default:
{
assert
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
));
pUdfInfo
=
isValidUdf
(
pQueryInfo
->
pUdfInfo
,
pItem
->
pNode
->
Expr
.
operand
.
z
,
pItem
->
pNode
->
Expr
.
operand
.
n
);
if
(
pUdfInfo
==
NULL
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg9
);
...
...
@@ -3763,7 +3692,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool
++
scalarFuncNum
;
}
if
(
functionId
==
TSDB_FUNC_
ARITHM
)
{
if
(
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
++
scalarFuncNum
;
}
...
...
@@ -6730,7 +6659,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
int32_t
f
=
pExpr
->
base
.
functionId
;
if
((
f
==
TSDB_FUNC_PRJ
&&
pExpr
->
base
.
numOfParams
==
0
)
||
f
==
TSDB_FUNC_DIFF
||
f
==
TSDB_FUNC_
ARITHM
||
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_DIFF
||
f
==
TSDB_FUNC_
SCALAR_EXPR
||
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_CSUM
||
f
==
TSDB_FUNC_MAVG
||
f
==
TSDB_FUNC_CEIL
||
f
==
TSDB_FUNC_FLOOR
||
f
==
TSDB_FUNC_ROUND
)
{
...
...
@@ -7362,7 +7291,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
int16_t
functionId
=
pExpr
->
base
.
functionId
;
if
(
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_
ARITHM
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
functionId
==
TSDB_FUNC_
SCALAR_EXPR
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
}
...
...
src/client/src/tscSubquery.c
浏览文件 @
6d9a8ab0
...
...
@@ -3618,8 +3618,8 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
}
}
char
*
getArithmetic
InputSrc
(
void
*
param
,
const
char
*
name
,
int32_t
colId
)
{
S
ArithmeticSupport
*
pSupport
=
(
SArithmeticSupport
*
)
param
;
char
*
getScalarExpr
InputSrc
(
void
*
param
,
const
char
*
name
,
int32_t
colId
)
{
S
ScalarExprSupport
*
pSupport
=
(
SScalarExprSupport
*
)
param
;
int32_t
index
=
-
1
;
SExprInfo
*
pExpr
=
NULL
;
...
...
src/client/src/tscUtil.c
浏览文件 @
6d9a8ab0
...
...
@@ -266,7 +266,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
functionId
!=
TSDB_FUNC_TAGPRJ
&&
functionId
!=
TSDB_FUNC_TAG
&&
functionId
!=
TSDB_FUNC_TS
&&
functionId
!=
TSDB_FUNC_
ARITHM
&&
functionId
!=
TSDB_FUNC_
SCALAR_EXPR
&&
functionId
!=
TSDB_FUNC_TS_COMP
&&
functionId
!=
TSDB_FUNC_DIFF
&&
functionId
!=
TSDB_FUNC_DERIVATIVE
&&
...
...
@@ -314,7 +314,7 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
}
if
(
f
!=
TSDB_FUNC_PRJ
&&
f
!=
TSDB_FUNC_TAGPRJ
&&
f
!=
TSDB_FUNC_TAG
&&
f
!=
TSDB_FUNC_TS
&&
f
!=
TSDB_FUNC_
ARITHM
&&
f
!=
TSDB_FUNC_DIFF
&&
f
!=
TSDB_FUNC_TS
&&
f
!=
TSDB_FUNC_
SCALAR_EXPR
&&
f
!=
TSDB_FUNC_DIFF
&&
f
!=
TSDB_FUNC_DERIVATIVE
&&
!
TSDB_FUNC_IS_SCALAR
(
f
))
{
return
false
;
}
...
...
@@ -4815,7 +4815,7 @@ int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaI
strncpy
(
pse
->
aliasName
,
pSource
->
base
.
aliasName
,
tListLen
(
pse
->
aliasName
));
strncpy
(
pse
->
token
,
pSource
->
base
.
token
,
tListLen
(
pse
->
token
));
if
(
pSource
->
base
.
functionId
!=
TSDB_FUNC_
ARITHM
)
{
// this should be switched to projection query
if
(
pSource
->
base
.
functionId
!=
TSDB_FUNC_
SCALAR_EXPR
)
{
// this should be switched to projection query
pse
->
numOfParams
=
0
;
// no params for projection query
pse
->
functionId
=
TSDB_FUNC_PRJ
;
pse
->
colInfo
.
colId
=
pSource
->
base
.
resColId
;
...
...
@@ -5059,7 +5059,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
tscExprAssign
(
&
pQueryAttr
->
pExpr1
[
i
],
pExpr
);
if
(
pQueryAttr
->
pExpr1
[
i
].
base
.
functionId
==
TSDB_FUNC_
ARITHM
)
{
if
(
pQueryAttr
->
pExpr1
[
i
].
base
.
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
for
(
int32_t
j
=
0
;
j
<
pQueryAttr
->
pExpr1
[
i
].
base
.
numOfParams
;
++
j
)
{
buildArithmeticExprFromMsg
(
&
pQueryAttr
->
pExpr1
[
i
],
NULL
);
}
...
...
src/query/inc/qAggMain.h
浏览文件 @
6d9a8ab0
...
...
@@ -57,7 +57,7 @@ extern "C" {
#define TSDB_FUNC_PRJ 21
#define TSDB_FUNC_TAGPRJ 22
#define TSDB_FUNC_
ARITHM
23
#define TSDB_FUNC_
SCALAR_EXPR
23
#define TSDB_FUNC_DIFF 24
#define TSDB_FUNC_FIRST_DST 25
...
...
@@ -129,14 +129,14 @@ enum {
#define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0)
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
typedef
struct
S
Arithmetic
Support
{
typedef
struct
S
ScalarExpr
Support
{
SExprInfo
*
pExprInfo
;
int32_t
numOfCols
;
SColumnInfo
*
colList
;
void
*
exprList
;
// client side used
int32_t
offset
;
char
**
data
;
}
S
Arithmetic
Support
;
}
S
ScalarExpr
Support
;
typedef
struct
SQLPreAggVal
{
bool
isSet
;
// statistics info set or not
...
...
src/query/inc/qExecutor.h
浏览文件 @
6d9a8ab0
...
...
@@ -304,7 +304,7 @@ typedef struct SQueryRuntimeEnv {
STSCursor
cur
;
char
*
tagVal
;
// tag value of current data block
S
ArithmeticSupport
*
sasArray
;
S
ScalarExprSupport
*
sasArray
;
SSDataBlock
*
outputBuf
;
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
...
...
src/query/src/qAggMain.c
浏览文件 @
6d9a8ab0
...
...
@@ -202,25 +202,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
switch
(
functionId
)
{
case
TSDB_FUNC_SCALAR_POW
:
{
*
type
=
TSDB_DATA_TYPE_DOUBLE
;
*
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
break
;
}
case
TSDB_FUNC_SCALAR_LOG
:
{
*
type
=
TSDB_DATA_TYPE_DOUBLE
;
*
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
break
;
}
default:
{
qError
(
"Illegal function id: %d"
,
functionId
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
return
TSDB_CODE_SUCCESS
;
}
assert
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
));
if
(
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_TS_DUMMY
||
functionId
==
TSDB_FUNC_TAG_DUMMY
||
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_TAGPRJ
||
...
...
@@ -261,7 +243,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return
TSDB_CODE_SUCCESS
;
}
if
(
functionId
==
TSDB_FUNC_
ARITHM
)
{
if
(
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
*
type
=
TSDB_DATA_TYPE_DOUBLE
;
*
bytes
=
sizeof
(
double
);
*
interBytes
=
0
;
...
...
@@ -3402,8 +3384,8 @@ static void diff_function(SQLFunctionCtx *pCtx) {
}
}
char
*
get
Arith
ColumnData
(
void
*
param
,
const
char
*
name
,
int32_t
colId
)
{
S
ArithmeticSupport
*
pSupport
=
(
SArithmetic
Support
*
)
param
;
char
*
get
ScalarExpr
ColumnData
(
void
*
param
,
const
char
*
name
,
int32_t
colId
)
{
S
ScalarExprSupport
*
pSupport
=
(
SScalarExpr
Support
*
)
param
;
int32_t
index
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pSupport
->
numOfCols
;
++
i
)
{
...
...
@@ -3417,12 +3399,12 @@ char *getArithColumnData(void *param, const char* name, int32_t colId) {
return
pSupport
->
data
[
index
]
+
pSupport
->
offset
*
pSupport
->
colList
[
index
].
bytes
;
}
static
void
arithmetic
_function
(
SQLFunctionCtx
*
pCtx
)
{
static
void
scalar_expr
_function
(
SQLFunctionCtx
*
pCtx
)
{
GET_RES_INFO
(
pCtx
)
->
numOfRes
+=
pCtx
->
size
;
S
ArithmeticSupport
*
sas
=
(
SArithmetic
Support
*
)
pCtx
->
param
[
1
].
pz
;
S
ScalarExprSupport
*
sas
=
(
SScalarExpr
Support
*
)
pCtx
->
param
[
1
].
pz
;
tExprOperandInfo
output
;
output
.
data
=
pCtx
->
pOutput
;
exprTreeNodeTraverse
(
sas
->
pExprInfo
->
pExpr
,
pCtx
->
size
,
&
output
,
sas
,
pCtx
->
order
,
get
Arith
ColumnData
);
exprTreeNodeTraverse
(
sas
->
pExprInfo
->
pExpr
,
pCtx
->
size
,
&
output
,
sas
,
pCtx
->
order
,
get
ScalarExpr
ColumnData
);
}
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
...
...
@@ -5380,11 +5362,11 @@ SAggFunctionInfo aAggs[] = {{
{
// 23
"arithmetic"
,
TSDB_FUNC_
ARITHM
,
TSDB_FUNC_
ARITHM
,
TSDB_FUNC_
SCALAR_EXPR
,
TSDB_FUNC_
SCALAR_EXPR
,
TSDB_FUNCSTATE_MO
|
TSDB_FUNCSTATE_STABLE
|
TSDB_FUNCSTATE_NEED_TS
,
function_setup
,
arithmetic
_function
,
scalar_expr
_function
,
doFinalizer
,
copy_function
,
dataBlockRequired
,
...
...
src/query/src/qExecutor.c
浏览文件 @
6d9a8ab0
...
...
@@ -1192,7 +1192,7 @@ static TSKEY getStartTsKey(SQueryAttr* pQueryAttr, STimeWindow* win, const TSKEY
return
ts
;
}
static
void
setArithParams
(
S
Arithmetic
Support
*
sas
,
SExprInfo
*
pExprInfo
,
SSDataBlock
*
pSDataBlock
)
{
static
void
setArithParams
(
S
ScalarExpr
Support
*
sas
,
SExprInfo
*
pExprInfo
,
SSDataBlock
*
pSDataBlock
)
{
sas
->
numOfCols
=
(
int32_t
)
pSDataBlock
->
info
.
numOfCols
;
sas
->
pExprInfo
=
pExprInfo
;
if
(
sas
->
colList
!=
NULL
)
{
...
...
@@ -1225,8 +1225,8 @@ static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SQLFunctionCtx* pC
}
void
setInputDataBlock
(
SOperatorInfo
*
pOperator
,
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
order
)
{
if
(
pCtx
[
0
].
functionId
==
TSDB_FUNC_
ARITHM
)
{
S
ArithmeticSupport
*
pSupport
=
(
SArithmetic
Support
*
)
pCtx
[
0
].
param
[
1
].
pz
;
if
(
pCtx
[
0
].
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
S
ScalarExprSupport
*
pSupport
=
(
SScalarExpr
Support
*
)
pCtx
[
0
].
param
[
1
].
pz
;
if
(
pSupport
->
colList
==
NULL
)
{
doSetInputDataBlock
(
pOperator
,
pCtx
,
pBlock
,
order
);
}
else
{
...
...
@@ -1249,8 +1249,8 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx,
setBlockStatisInfo
(
&
pCtx
[
i
],
pBlock
,
&
pOperator
->
pExpr
[
i
].
base
.
colInfo
);
if
(
pCtx
[
i
].
functionId
==
TSDB_FUNC_
ARITHM
)
{
setArithParams
((
S
Arithmetic
Support
*
)
pCtx
[
i
].
param
[
1
].
pz
,
&
pOperator
->
pExpr
[
i
],
pBlock
);
if
(
pCtx
[
i
].
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
setArithParams
((
S
ScalarExpr
Support
*
)
pCtx
[
i
].
param
[
1
].
pz
,
&
pOperator
->
pExpr
[
i
],
pBlock
);
}
else
{
SColIndex
*
pCol
=
&
pOperator
->
pExpr
[
i
].
base
.
colInfo
;
if
(
TSDB_COL_IS_NORMAL_COL
(
pCol
->
flag
)
||
(
pCtx
[
i
].
functionId
==
TSDB_FUNC_BLKINFO
)
||
...
...
@@ -2130,7 +2130,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr
pCtx
->
param
[
1
].
nType
=
TSDB_DATA_TYPE_BIGINT
;
pCtx
->
param
[
2
].
i64
=
pQueryAttr
->
window
.
ekey
;
pCtx
->
param
[
2
].
nType
=
TSDB_DATA_TYPE_BIGINT
;
}
else
if
(
functionId
==
TSDB_FUNC_
ARITHM
)
{
}
else
if
(
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
pCtx
->
param
[
1
].
pz
=
(
char
*
)
&
pRuntimeEnv
->
sasArray
[
i
];
}
}
...
...
@@ -2181,7 +2181,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info
pRuntimeEnv
->
pTableRetrieveTsMap
=
taosHashInit
(
numOfTables
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
pRuntimeEnv
->
sasArray
=
calloc
(
pQueryAttr
->
numOfOutput
,
sizeof
(
S
Arithmetic
Support
));
pRuntimeEnv
->
sasArray
=
calloc
(
pQueryAttr
->
numOfOutput
,
sizeof
(
S
ScalarExpr
Support
));
if
(
pRuntimeEnv
->
sasArray
==
NULL
||
pRuntimeEnv
->
pResultRowHashTable
==
NULL
||
pRuntimeEnv
->
keyBuf
==
NULL
||
pRuntimeEnv
->
prevRow
==
NULL
||
pRuntimeEnv
->
tagVal
==
NULL
)
{
...
...
@@ -8195,7 +8195,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp
int16_t
bytes
=
0
;
// parse the arithmetic expression
if
(
pExprs
[
i
].
base
.
functionId
==
TSDB_FUNC_
ARITHM
)
{
if
(
pExprs
[
i
].
base
.
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
code
=
buildArithmeticExprFromMsg
(
&
pExprs
[
i
],
pMsg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -8255,14 +8255,14 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp
}
int32_t
param
=
(
int32_t
)
pExprs
[
i
].
base
.
param
[
0
].
i64
;
if
(
pExprs
[
i
].
base
.
functionId
>
0
&&
pExprs
[
i
].
base
.
functionId
!=
TSDB_FUNC_
ARITHM
&&
if
(
pExprs
[
i
].
base
.
functionId
>
0
&&
pExprs
[
i
].
base
.
functionId
!=
TSDB_FUNC_
SCALAR_EXPR
&&
(
type
!=
pExprs
[
i
].
base
.
colType
||
bytes
!=
pExprs
[
i
].
base
.
colBytes
))
{
tfree
(
pExprs
);
return
TSDB_CODE_QRY_INVALID_MSG
;
}
// todo remove it
if
(
pExprs
[
i
].
base
.
functionId
!=
TSDB_FUNC_
ARITHM
&&
getResultDataInfo
(
type
,
bytes
,
pExprs
[
i
].
base
.
functionId
,
param
,
&
pExprs
[
i
].
base
.
resType
,
&
pExprs
[
i
].
base
.
resBytes
,
if
(
pExprs
[
i
].
base
.
functionId
!=
TSDB_FUNC_
SCALAR_EXPR
&&
getResultDataInfo
(
type
,
bytes
,
pExprs
[
i
].
base
.
functionId
,
param
,
&
pExprs
[
i
].
base
.
resType
,
&
pExprs
[
i
].
base
.
resBytes
,
&
pExprs
[
i
].
base
.
interBytes
,
0
,
isSuperTable
,
pUdfInfo
)
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pExprs
);
return
TSDB_CODE_QRY_INVALID_MSG
;
...
...
@@ -8331,7 +8331,7 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t nu
int16_t
bytes
=
0
;
// parse the arithmetic expression
if
(
pExprs
[
i
].
base
.
functionId
==
TSDB_FUNC_
ARITHM
)
{
if
(
pExprs
[
i
].
base
.
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
code
=
buildArithmeticExprFromMsg
(
&
pExprs
[
i
],
pQueryMsg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -8475,7 +8475,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) {
for
(
int32_t
k
=
0
;
k
<
pQueryAttr
->
numOfOutput
;
++
k
)
{
SSqlExpr
*
pSqlExprMsg
=
&
pQueryAttr
->
pExpr1
[
k
].
base
;
if
(
pSqlExprMsg
->
functionId
==
TSDB_FUNC_
ARITHM
)
{
if
(
pSqlExprMsg
->
functionId
==
TSDB_FUNC_
SCALAR_EXPR
)
{
continue
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录