Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
92671a20
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
92671a20
编写于
6月 26, 2021
作者:
H
Haojun Liao
提交者:
GitHub
6月 26, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6636 from taosdata/feature/query
Feature/query
上级
59d207c8
14d9473b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
185 addition
and
82 deletion
+185
-82
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+33
-27
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
+33
-39
src/query/src/qPlan.c
src/query/src/qPlan.c
+7
-7
tests/script/general/parser/groupby.sim
tests/script/general/parser/groupby.sim
+40
-0
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+68
-4
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
92671a20
...
...
@@ -2071,33 +2071,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
;
...
...
@@ -2110,7 +2106,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
)
t
ype
,
pExpr
->
base
.
aliasName
,
pExpr
);
insertResultField
(
pQueryInfo
,
resColIdx
,
&
ids
,
resBytes
,
(
int8_t
)
resT
ype
,
pExpr
->
base
.
aliasName
,
pExpr
);
}
else
{
tscColumnListInsert
(
pQueryInfo
->
colList
,
ids
.
ids
[
0
].
columnIndex
,
pExpr
->
base
.
uid
,
pSchema
);
}
...
...
@@ -2559,8 +2555,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
};
...
...
@@ -2573,8 +2570,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
...
...
@@ -2584,7 +2580,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
);
...
...
@@ -2619,7 +2615,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SColumnList
ids
=
createColumnList
(
1
,
index
.
tableIndex
,
index
.
columnIndex
);
if
(
finalResult
)
{
insertResultField
(
pQueryInfo
,
colIndex
,
&
ids
,
resultSize
,
resultType
,
pExpr
->
base
.
aliasName
,
pExpr
);
insertResultField
(
pQueryInfo
,
colIndex
,
&
ids
,
resultSize
,
(
int8_t
)
resultType
,
pExpr
->
base
.
aliasName
,
pExpr
);
}
else
{
assert
(
ids
.
num
==
1
);
tscColumnListInsert
(
pQueryInfo
->
colList
,
ids
.
ids
[
0
].
columnIndex
,
pExpr
->
base
.
uid
,
pSchema
);
...
...
@@ -7786,8 +7782,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
;
...
...
@@ -7830,15 +7826,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
);
}
...
...
@@ -7853,9 +7851,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
=
(
int32_t
)
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
浏览文件 @
92671a20
...
...
@@ -286,7 +286,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
,
...
...
@@ -414,13 +414,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
;
...
...
@@ -514,7 +514,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
浏览文件 @
92671a20
...
...
@@ -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
浏览文件 @
92671a20
...
...
@@ -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
)
{
...
...
@@ -1282,11 +1282,8 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
return
;
}
int64_t
*
tsList
=
NULL
;
SColumnInfoData
*
pFirstColData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
0
);
if
(
pFirstColData
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
tsList
=
(
int64_t
*
)
pFirstColData
->
pData
;
}
int64_t
*
tsList
=
(
pFirstColData
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
?
(
int64_t
*
)
pFirstColData
->
pData
:
NULL
;
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
...
...
@@ -1319,12 +1316,10 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
}
if
(
pQueryAttr
->
stableQuery
&&
pQueryAttr
->
stabledev
&&
(
pRuntimeEnv
->
prevResult
!=
NULL
))
{
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
pInfo
->
prevData
,
bytes
);
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
pInfo
->
prevData
,
bytes
);
}
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
pInfo
->
prevData
,
type
,
bytes
,
item
->
groupIndex
);
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
pInfo
->
prevData
,
type
,
bytes
,
item
->
groupIndex
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
...
...
@@ -1340,17 +1335,16 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
memcpy
(
pInfo
->
prevData
,
val
,
bytes
);
if
(
pQueryAttr
->
stableQuery
&&
pQueryAttr
->
stabledev
&&
(
pRuntimeEnv
->
prevResult
!=
NULL
))
{
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
val
,
bytes
);
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
val
,
bytes
);
}
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
val
,
type
,
bytes
,
item
->
groupIndex
);
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
val
,
type
,
bytes
,
item
->
groupIndex
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
doApplyFunctions
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
&
w
,
pSDataBlock
->
info
.
rows
-
num
,
num
,
tsList
,
pSDataBlock
->
info
.
rows
,
pOperator
->
numOfOutput
);
tfree
(
pInfo
->
prevData
);
}
}
...
...
@@ -1806,17 +1800,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 +4572,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 +4928,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 +4954,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 +4984,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 +5004,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 +5643,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 +5690,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 +5704,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 +5713,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
浏览文件 @
92671a20
...
...
@@ -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/groupby.sim
浏览文件 @
92671a20
...
...
@@ -741,4 +741,44 @@ if $data14 != 2 then
return -1
endi
sql create table m1 (ts timestamp, k int, f1 int) tags(a int);
sql create table tm0 using m1 tags(0);
sql create table tm1 using m1 tags(1);
sql insert into tm0 values('2020-1-1 1:1:1', 1, 10);
sql insert into tm0 values('2020-1-1 1:1:2', 1, 20);
sql insert into tm1 values('2020-2-1 1:1:1', 2, 10);
sql insert into tm1 values('2020-2-1 1:1:2', 2, 20);
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 100
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
sleep 100
sql use group_db0;
print =========================>TD-4894
sql select count(*),k from m1 group by k;
if $rows != 2 then
return -1
endi
if $data00 != 2 then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data10 != 2 then
return -1
endi
if $data11 != 2 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/general/parser/nestquery.sim
浏览文件 @
92671a20
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录