Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
b945a7fd
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看板
提交
b945a7fd
编写于
6月 24, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-4791] check sql function in outer query.
上级
f37de557
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
138 addition
and
69 deletion
+138
-69
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+32
-26
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+4
-4
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+0
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+27
-27
src/query/src/qPlan.c
src/query/src/qPlan.c
+7
-7
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+68
-4
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
b945a7fd
...
...
@@ -2069,33 +2069,29 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
const
char
*
name
,
int32_t
resColIdx
,
SColumnIndex
*
pColIndex
,
bool
finalResult
)
{
const
char
*
msg1
=
"not support column types"
;
int16_t
type
=
0
;
int16_t
bytes
=
0
;
int32_t
functionID
=
cvtFunc
.
execFuncId
;
if
(
functionID
==
TSDB_FUNC_SPREAD
)
{
int32_t
f
=
cvtFunc
.
execFuncId
;
if
(
f
==
TSDB_FUNC_SPREAD
)
{
int32_t
t1
=
pSchema
->
type
;
if
(
t1
==
TSDB_DATA_TYPE_BINARY
||
t1
==
TSDB_DATA_TYPE_NCHAR
||
t1
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
IS_VAR_DATA_TYPE
(
t1
)
||
t1
==
TSDB_DATA_TYPE_BOOL
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
-
1
;
}
else
{
type
=
TSDB_DATA_TYPE_DOUBLE
;
bytes
=
tDataTypes
[
type
].
bytes
;
}
}
else
{
type
=
pSchema
->
type
;
bytes
=
pSchema
->
bytes
;
}
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionID
,
pColIndex
,
type
,
bytes
,
getNewResColId
(
pCmd
),
bytes
,
false
);
int16_t
resType
=
0
;
int16_t
resBytes
=
0
;
int32_t
interBufSize
=
0
;
getResultDataInfo
(
pSchema
->
type
,
pSchema
->
bytes
,
f
,
0
,
&
resType
,
&
resBytes
,
&
interBufSize
,
0
,
false
);
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
f
,
pColIndex
,
resType
,
resBytes
,
getNewResColId
(
pCmd
),
interBufSize
,
false
);
tstrncpy
(
pExpr
->
base
.
aliasName
,
name
,
tListLen
(
pExpr
->
base
.
aliasName
));
if
(
cvtFunc
.
originFuncId
==
TSDB_FUNC_LAST_ROW
&&
cvtFunc
.
originFuncId
!=
f
unctionID
)
{
if
(
cvtFunc
.
originFuncId
==
TSDB_FUNC_LAST_ROW
&&
cvtFunc
.
originFuncId
!=
f
)
{
pExpr
->
base
.
colInfo
.
flag
|=
TSDB_COL_NULL
;
}
// set reverse order scan data blocks for last query
if
(
f
unctionID
==
TSDB_FUNC_LAST
)
{
if
(
f
==
TSDB_FUNC_LAST
)
{
pExpr
->
base
.
numOfParams
=
1
;
pExpr
->
base
.
param
[
0
].
i64
=
TSDB_ORDER_DESC
;
pExpr
->
base
.
param
[
0
].
nType
=
TSDB_DATA_TYPE_INT
;
...
...
@@ -2108,7 +2104,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
// if it is not in the final result, do not add it
SColumnList
ids
=
createColumnList
(
1
,
pColIndex
->
tableIndex
,
pColIndex
->
columnIndex
);
if
(
finalResult
)
{
insertResultField
(
pQueryInfo
,
resColIdx
,
&
ids
,
bytes
,
(
int8_t
)
type
,
pExpr
->
base
.
aliasName
,
pExpr
);
insertResultField
(
pQueryInfo
,
resColIdx
,
&
ids
,
pSchema
->
bytes
,
(
int8_t
)
pSchema
->
type
,
pExpr
->
base
.
aliasName
,
pExpr
);
}
else
{
tscColumnListInsert
(
pQueryInfo
->
colList
,
ids
.
ids
[
0
].
columnIndex
,
pExpr
->
base
.
uid
,
pSchema
);
}
...
...
@@ -2557,8 +2553,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tVariant
*
pVariant
=
&
pParamElem
[
1
].
pNode
->
value
;
int8_t
resultType
=
pSchema
->
type
;
int16_t
resultSize
=
pSchema
->
bytes
;
int16_t
resultType
=
pSchema
->
type
;
int16_t
resultSize
=
pSchema
->
bytes
;
int32_t
interResult
=
0
;
char
val
[
8
]
=
{
0
};
...
...
@@ -2571,8 +2568,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
resultSize
=
sizeof
(
double
);
resultType
=
TSDB_DATA_TYPE_DOUBLE
;
getResultDataInfo
(
pSchema
->
type
,
pSchema
->
bytes
,
functionId
,
0
,
&
resultType
,
&
resultSize
,
&
interResult
,
0
,
false
);
/*
* sql function transformation
...
...
@@ -2582,7 +2578,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pTableMetaInfo
->
pTableMeta
->
id
.
uid
);
colIndex
+=
1
;
// the first column is ts
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
resultSize
,
false
);
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
interResult
,
false
);
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
}
else
{
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_BIGINT
,
true
);
...
...
@@ -7784,8 +7780,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
const
char
*
msg3
=
"start(end) time of query range required or time range too large"
;
const
char
*
msg4
=
"interval query not supported, since the result of sub query not include valid timestamp column"
;
const
char
*
msg5
=
"only tag query not compatible with normal column filter"
;
const
char
*
msg6
=
"not support stddev/percentile
in
outer query yet"
;
const
char
*
msg7
=
"d
rivativ
e requires timestamp column exists in subquery"
;
const
char
*
msg6
=
"not support stddev/percentile
/interp in the
outer query yet"
;
const
char
*
msg7
=
"d
erivative/twa/irat
e requires timestamp column exists in subquery"
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -7828,15 +7824,17 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if
(
validateSelectNodeList
(
pCmd
,
pQueryInfo
,
pSqlNode
->
pSelNodeList
,
false
,
false
,
timeWindowQuery
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// parse the window_state
if
(
validateStateWindowNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// todo NOT support yet
for
(
int32_t
i
=
0
;
i
<
tscNumOfExprs
(
pQueryInfo
);
++
i
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
int32_t
f
=
pExpr
->
base
.
functionId
;
if
(
f
==
TSDB_FUNC_STDDEV
||
f
==
TSDB_FUNC_PERCT
)
{
if
(
f
==
TSDB_FUNC_STDDEV
||
f
==
TSDB_FUNC_PERCT
||
f
==
TSDB_FUNC_INTERP
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
...
...
@@ -7851,9 +7849,17 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
0
);
if
(
tscNumOfExprs
(
pQueryInfo
)
>
1
)
{
int32_t
numOfExprs
=
tscNumOfExprs
(
pQueryInfo
);
if
(
numOfExprs
==
1
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
0
);
int32_t
f
=
pExpr
->
base
.
functionId
;
if
(
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_TWA
||
f
==
TSDB_FUNC_IRATE
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
}
else
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
1
);
if
(
pExpr
->
base
.
functionId
==
TSDB_FUNC_DERIVATIVE
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
int32_t
f
=
pExpr
->
base
.
functionId
;
if
((
f
==
TSDB_FUNC_DERIVATIVE
||
f
==
TSDB_FUNC_TWA
||
f
==
TSDB_FUNC_IRATE
)
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
}
...
...
src/query/inc/qExecutor.h
浏览文件 @
b945a7fd
...
...
@@ -285,7 +285,7 @@ enum OPERATOR_TYPE_E {
OP_TagScan
=
4
,
OP_TableBlockInfoScan
=
5
,
OP_Aggregate
=
6
,
OP_
Arithmetic
=
7
,
OP_
Project
=
7
,
OP_Groupby
=
8
,
OP_Limit
=
9
,
OP_SLimit
=
10
,
...
...
@@ -413,13 +413,13 @@ typedef struct SAggOperatorInfo {
uint32_t
seed
;
}
SAggOperatorInfo
;
typedef
struct
S
Arith
OperatorInfo
{
typedef
struct
S
Project
OperatorInfo
{
SOptrBasicInfo
binfo
;
int32_t
bufCapacity
;
uint32_t
seed
;
SSDataBlock
*
existDataBlock
;
}
S
Arith
OperatorInfo
;
}
S
Project
OperatorInfo
;
typedef
struct
SLimitOperatorInfo
{
int64_t
limit
;
...
...
@@ -513,7 +513,7 @@ SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv*
SOperatorInfo
*
createTableSeqScanOperator
(
void
*
pTsdbQueryHandle
,
SQueryRuntimeEnv
*
pRuntimeEnv
);
SOperatorInfo
*
createAggregateOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
create
Arith
OperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
create
Project
OperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createLimitOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
);
SOperatorInfo
*
createTimeIntervalOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSWindowOperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
...
...
src/query/src/qAggMain.c
浏览文件 @
b945a7fd
...
...
@@ -74,7 +74,6 @@
} while (0);
void
noop1
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
))
{}
void
noop2
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
),
int32_t
UNUSED_PARAM
(
index
))
{}
void
doFinalizer
(
SQLFunctionCtx
*
pCtx
)
{
RESET_RESULT_INFO
(
GET_RES_INFO
(
pCtx
));
}
...
...
src/query/src/qExecutor.c
浏览文件 @
b945a7fd
...
...
@@ -184,7 +184,7 @@ static int32_t getNumOfScanTimes(SQueryAttr* pQueryAttr);
static
void
destroyBasicOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroySFillOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroyGroupbyOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroy
Arith
OperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroy
Project
OperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroyTagScanOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroySWindowOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
static
void
destroyStateWindowOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
...
...
@@ -912,7 +912,7 @@ void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlo
doSetInputDataBlockInfo
(
pOperator
,
pCtx
,
pBlock
,
order
);
}
}
else
{
if
(
/*pCtx[0].pInput == NULL && */
pBlock
->
pDataBlock
!=
NULL
)
{
if
(
pBlock
->
pDataBlock
!=
NULL
)
{
doSetInputDataBlock
(
pOperator
,
pCtx
,
pBlock
,
order
);
}
else
{
doSetInputDataBlockInfo
(
pOperator
,
pCtx
,
pBlock
,
order
);
...
...
@@ -978,7 +978,7 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SQLFunction
}
}
static
void
arithmetic
ApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
static
void
project
ApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
...
...
@@ -1806,17 +1806,17 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
break
;
}
case
OP_
Arithmetic
:
{
// TODO refactor to remove arith operator.
case
OP_
Project
:
{
// TODO refactor to remove arith operator.
SOperatorInfo
*
prev
=
pRuntimeEnv
->
proot
;
if
(
i
==
0
)
{
pRuntimeEnv
->
proot
=
create
Arith
OperatorInfo
(
pRuntimeEnv
,
prev
,
pQueryAttr
->
pExpr1
,
pQueryAttr
->
numOfOutput
);
pRuntimeEnv
->
proot
=
create
Project
OperatorInfo
(
pRuntimeEnv
,
prev
,
pQueryAttr
->
pExpr1
,
pQueryAttr
->
numOfOutput
);
if
(
pRuntimeEnv
->
proot
!=
NULL
&&
prev
->
operatorType
!=
OP_DummyInput
&&
prev
->
operatorType
!=
OP_Join
)
{
// TODO refactor
setTableScanFilterOperatorInfo
(
prev
->
info
,
pRuntimeEnv
->
proot
);
}
}
else
{
prev
=
pRuntimeEnv
->
proot
;
assert
(
pQueryAttr
->
pExpr2
!=
NULL
);
pRuntimeEnv
->
proot
=
create
Arith
OperatorInfo
(
pRuntimeEnv
,
prev
,
pQueryAttr
->
pExpr2
,
pQueryAttr
->
numOfExpr2
);
pRuntimeEnv
->
proot
=
create
Project
OperatorInfo
(
pRuntimeEnv
,
prev
,
pQueryAttr
->
pExpr2
,
pQueryAttr
->
numOfExpr2
);
}
break
;
}
...
...
@@ -4578,8 +4578,8 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf
pTableScanInfo
->
pResultRowInfo
=
&
pInfo
->
resultRowInfo
;
pTableScanInfo
->
rowCellInfoOffset
=
pInfo
->
rowCellInfoOffset
;
}
else
if
(
pDownstream
->
operatorType
==
OP_
Arithmetic
)
{
S
Arith
OperatorInfo
*
pInfo
=
pDownstream
->
info
;
}
else
if
(
pDownstream
->
operatorType
==
OP_
Project
)
{
S
Project
OperatorInfo
*
pInfo
=
pDownstream
->
info
;
pTableScanInfo
->
pCtx
=
pInfo
->
binfo
.
pCtx
;
pTableScanInfo
->
pResultRowInfo
=
&
pInfo
->
binfo
.
resultRowInfo
;
...
...
@@ -4934,23 +4934,23 @@ static SSDataBlock* doSTableAggregate(void* param, bool* newgroup) {
return
pInfo
->
pRes
;
}
static
SSDataBlock
*
do
Arithmetic
Operation
(
void
*
param
,
bool
*
newgroup
)
{
static
SSDataBlock
*
do
Project
Operation
(
void
*
param
,
bool
*
newgroup
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
S
ArithOperatorInfo
*
pArith
Info
=
pOperator
->
info
;
S
ProjectOperatorInfo
*
pProject
Info
=
pOperator
->
info
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
SOptrBasicInfo
*
pInfo
=
&
p
Arith
Info
->
binfo
;
SOptrBasicInfo
*
pInfo
=
&
p
Project
Info
->
binfo
;
SSDataBlock
*
pRes
=
pInfo
->
pRes
;
int32_t
order
=
pRuntimeEnv
->
pQueryAttr
->
order
.
order
;
pRes
->
info
.
rows
=
0
;
if
(
p
Arith
Info
->
existDataBlock
)
{
// TODO refactor
if
(
p
Project
Info
->
existDataBlock
)
{
// TODO refactor
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
current
;
SSDataBlock
*
pBlock
=
p
Arith
Info
->
existDataBlock
;
p
Arith
Info
->
existDataBlock
=
NULL
;
SSDataBlock
*
pBlock
=
p
Project
Info
->
existDataBlock
;
p
Project
Info
->
existDataBlock
=
NULL
;
*
newgroup
=
true
;
// todo dynamic set tags
...
...
@@ -4960,9 +4960,9 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
updateOutputBuf
(
&
p
ArithInfo
->
binfo
,
&
pArith
Info
->
bufCapacity
,
pBlock
->
info
.
rows
);
updateOutputBuf
(
&
p
ProjectInfo
->
binfo
,
&
pProject
Info
->
bufCapacity
,
pBlock
->
info
.
rows
);
arithmetic
ApplyFunctions
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
project
ApplyFunctions
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
if
(
pTableQueryInfo
!=
NULL
)
{
updateTableIdInfo
(
pTableQueryInfo
,
pBlock
,
pRuntimeEnv
->
pTableRetrieveTsMap
,
order
);
}
...
...
@@ -4990,7 +4990,7 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) {
// Return result of the previous group in the firstly.
if
(
*
newgroup
)
{
if
(
pRes
->
info
.
rows
>
0
)
{
p
Arith
Info
->
existDataBlock
=
pBlock
;
p
Project
Info
->
existDataBlock
=
pBlock
;
clearNumOfRes
(
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
return
pInfo
->
pRes
;
}
else
{
// init output buffer for a new group data
...
...
@@ -5010,9 +5010,9 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
updateOutputBuf
(
&
p
ArithInfo
->
binfo
,
&
pArith
Info
->
bufCapacity
,
pBlock
->
info
.
rows
);
updateOutputBuf
(
&
p
ProjectInfo
->
binfo
,
&
pProject
Info
->
bufCapacity
,
pBlock
->
info
.
rows
);
arithmetic
ApplyFunctions
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
project
ApplyFunctions
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
if
(
pTableQueryInfo
!=
NULL
)
{
updateTableIdInfo
(
pTableQueryInfo
,
pBlock
,
pRuntimeEnv
->
pTableRetrieveTsMap
,
order
);
}
...
...
@@ -5649,8 +5649,8 @@ static void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput) {
tfree
(
pInfo
->
prevData
);
}
static
void
destroy
Arith
OperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
S
ArithOperatorInfo
*
pInfo
=
(
SArith
OperatorInfo
*
)
param
;
static
void
destroy
Project
OperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
S
ProjectOperatorInfo
*
pInfo
=
(
SProject
OperatorInfo
*
)
param
;
doDestroyBasicInfo
(
&
pInfo
->
binfo
,
numOfOutput
);
}
...
...
@@ -5696,8 +5696,8 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SO
return
pOperator
;
}
SOperatorInfo
*
create
Arith
OperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
S
ArithOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SArith
OperatorInfo
));
SOperatorInfo
*
create
Project
OperatorInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
upstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
S
ProjectOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
SProject
OperatorInfo
));
pInfo
->
seed
=
rand
();
pInfo
->
bufCapacity
=
pRuntimeEnv
->
resultInfo
.
capacity
;
...
...
@@ -5710,8 +5710,8 @@ SOperatorInfo* createArithOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
setDefaultOutputBuf
(
pRuntimeEnv
,
pBInfo
,
pInfo
->
seed
,
MASTER_SCAN
);
SOperatorInfo
*
pOperator
=
calloc
(
1
,
sizeof
(
SOperatorInfo
));
pOperator
->
name
=
"
Arithmetic
Operator"
;
pOperator
->
operatorType
=
OP_
Arithmetic
;
pOperator
->
name
=
"
Project
Operator"
;
pOperator
->
operatorType
=
OP_
Project
;
pOperator
->
blockingOptr
=
false
;
pOperator
->
status
=
OP_IN_EXECUTING
;
pOperator
->
info
=
pInfo
;
...
...
@@ -5719,8 +5719,8 @@ SOperatorInfo* createArithOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
exec
=
do
Arithmetic
Operation
;
pOperator
->
cleanup
=
destroy
Arith
OperatorInfo
;
pOperator
->
exec
=
do
Project
Operation
;
pOperator
->
cleanup
=
destroy
Project
OperatorInfo
;
appendUpstream
(
pOperator
,
upstream
);
return
pOperator
;
...
...
src/query/src/qPlan.c
浏览文件 @
b945a7fd
...
...
@@ -565,7 +565,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
taosArrayPush
(
plan
,
&
op
);
if
(
pQueryAttr
->
pExpr2
!=
NULL
)
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
...
...
@@ -585,7 +585,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
}
if
(
pQueryAttr
->
pExpr2
!=
NULL
)
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
}
else
if
(
pQueryAttr
->
sw
.
gap
>
0
)
{
...
...
@@ -593,7 +593,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
taosArrayPush
(
plan
,
&
op
);
if
(
pQueryAttr
->
pExpr2
!=
NULL
)
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
}
else
if
(
pQueryAttr
->
stateWindow
)
{
...
...
@@ -601,7 +601,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
taosArrayPush
(
plan
,
&
op
);
if
(
pQueryAttr
->
pExpr2
!=
NULL
)
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
}
else
if
(
pQueryAttr
->
simpleAgg
)
{
...
...
@@ -619,7 +619,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
}
if
(
pQueryAttr
->
pExpr2
!=
NULL
&&
!
pQueryAttr
->
stableQuery
)
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
}
else
{
// diff/add/multiply/subtract/division
...
...
@@ -627,7 +627,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
op
=
OP_Filter
;
taosArrayPush
(
plan
,
&
op
);
}
else
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
}
...
...
@@ -665,7 +665,7 @@ SArray* createGlobalMergePlan(SQueryAttr* pQueryAttr) {
}
if
(
pQueryAttr
->
pExpr2
!=
NULL
)
{
op
=
OP_
Arithmetic
;
op
=
OP_
Project
;
taosArrayPush
(
plan
,
&
op
);
}
}
...
...
tests/script/general/parser/nestquery.sim
浏览文件 @
b945a7fd
...
...
@@ -180,20 +180,82 @@ if $data21 != 49.500000000 then
endi
#define TSDB_FUNC_APERCT 7
#define TSDB_FUNC_LAST_ROW 10
#define TSDB_FUNC_TWA 14
#define TSDB_FUNC_LEASTSQR 15
#define TSDB_FUNC_ARITHM 23
#define TSDB_FUNC_DIFF 24
#define TSDB_FUNC_INTERP 28
#define TSDB_FUNC_RATE 29
#define TSDB_FUNC_IRATE 30
#define TSDB_FUNC_DERIVATIVE 32
sql_error select stddev(c1) from (select c1 from nest_tb0);
sql_error select percentile(c1, 20) from (select * from nest_tb0);
sql_error select interp(c1) from (select * from nest_tb0);
sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0);
sql_error select twa(c1) from (select c1 from nest_tb0);
sql_error select irate(c1) from (select c1 from nest_tb0);
sql_error select diff(c1), twa(c1) from (select * from nest_tb0);
sql_error select irate(c1), interp(c1), twa(c1) from (select * from nest_tb0);
sql select apercentile(c1, 50) from (select * from nest_tb0) interval(1d)
sql select twa(c1) from (select * from nest_tb0);
sql select leastsquares(c1, 1, 1) from (select * from nest_tb0);
sql select irate(c1) from (select * from nest_tb0);
sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d);
if $rows != 7 then
return -1
endi
if $data00 != @20-09-15 00:00:00.000@ then
return -1
endi
if $data01 != 48.666666667 then
print expect 48.666666667, actual: $data01
return -1
endi
if $data02 != 70080.000000000 then
return -1
endi
if $data03 != 99 then
return -1
endi
if $data04 != 0 then
return -1
endi
if $data05 != 1440 then
return -1
endi
if $data06 != 0 then
print $data06
return -1
endi
if $data07 != 1 then
return -1
endi
if $data08 != 99.000000000 then
print expect 99.000000000, actual: $data08
return -1
endi
if $data10 != @20-09-16 00:00:00.000@ then
return -1
endi
if $data11 != 49.777777778 then
return -1
endi
if $data12 != 71680.000000000 then
return -1
endi
sql select top(x, 20) from (select c1 x from nest_tb0);
...
...
@@ -207,6 +269,9 @@ print ===================> group by + having
print =========================> ascending order/descending order
print =========================> nest query join
...
...
@@ -273,7 +338,6 @@ if $data03 != @20-09-15 00:00:00.000@ then
return -1
endi
sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0);
sql select diff(val) from (select c1 val from nest_tb0);
if $rows != 9999 then
return -1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录