Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
电商架构修炼
TDengine
提交
cc0110d3
TDengine
项目概览
电商架构修炼
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cc0110d3
编写于
3月 10, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-2895] refactor.
上级
40cafb49
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
58 addition
and
52 deletion
+58
-52
src/inc/ttype.h
src/inc/ttype.h
+4
-4
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+2
-2
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+1
-6
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+51
-40
未找到文件。
src/inc/ttype.h
浏览文件 @
cc0110d3
...
...
@@ -174,7 +174,7 @@ bool isValidDataType(int32_t type);
void
setVardataNull
(
char
*
val
,
int32_t
type
);
void
setNull
(
char
*
val
,
int32_t
type
,
int32_t
bytes
);
void
setNullN
(
char
*
val
,
int32_t
type
,
int32_t
bytes
,
int32_t
numOfElems
);
void
*
getNullValue
(
int32_t
type
);
void
*
getNullValue
(
int32_t
type
);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
);
...
...
src/query/inc/qExecutor.h
浏览文件 @
cc0110d3
...
...
@@ -86,7 +86,7 @@ typedef struct SResultRow {
bool
closed
;
// this result status: closed or opened
uint32_t
numOfRows
;
// number of rows of current time window
SResultRowCellInfo
*
pCellInfo
;
// For each result column, there is a resultInfo
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current
time wind
ow
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current
result r
ow
}
SResultRow
;
typedef
struct
SGroupResInfo
{
...
...
@@ -131,7 +131,6 @@ typedef struct SSingleColumnFilterInfo {
typedef
struct
STableQueryInfo
{
TSKEY
lastKey
;
int32_t
groupIndex
;
// group id in table list
int16_t
queryRangeSet
;
// denote if the query range is set, only available for interval query
tVariant
tag
;
STimeWindow
win
;
STSCursor
cur
;
...
...
@@ -409,6 +408,7 @@ typedef struct SFillOperatorInfo {
typedef
struct
SGroupbyOperatorInfo
{
SOptrBasicInfo
binfo
;
int32_t
colIndex
;
char
*
prevData
;
// previous group by value
}
SGroupbyOperatorInfo
;
void
freeParam
(
SQueryParam
*
param
);
...
...
src/query/src/qAggMain.c
浏览文件 @
cc0110d3
...
...
@@ -2167,12 +2167,7 @@ static void last_row_finalizer(SQLFunctionCtx *pCtx) {
// do nothing at the first stage
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
if
(
pResInfo
->
hasResult
!=
DATA_SET_FLAG
)
{
if
(
pCtx
->
outputType
==
TSDB_DATA_TYPE_BINARY
||
pCtx
->
outputType
==
TSDB_DATA_TYPE_NCHAR
)
{
setVardataNull
(
pCtx
->
pOutput
,
pCtx
->
outputType
);
}
else
{
setNull
(
pCtx
->
pOutput
,
pCtx
->
outputType
,
pCtx
->
outputBytes
);
}
return
;
}
...
...
src/query/src/qExecutor.c
浏览文件 @
cc0110d3
...
...
@@ -190,9 +190,8 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator);
static
int32_t
doCopyToSDataBlock
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
,
int32_t
orderType
,
SSDataBlock
*
pBlock
);
static
int32_t
getGroupbyColumnIndex
(
SSqlGroupbyExpr
*
pGroupbyExpr
,
SSDataBlock
*
pDataBlock
);
static
int32_t
setGroupResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupbyOperatorInfo
*
pInfo
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
);
static
int32_t
setGroupResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
,
int32_t
*
offset
);
static
void
initCtxOutputBuffer
(
SQLFunctionCtx
*
pCtx
,
int32_t
size
);
static
void
getAlignQueryTimeWindow
(
SQuery
*
pQuery
,
int64_t
key
,
int64_t
keyFirst
,
int64_t
keyLast
,
STimeWindow
*
win
);
static
bool
isPointInterpoQuery
(
SQuery
*
pQuery
);
...
...
@@ -1283,27 +1282,38 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
}
}
static
void
hashGroupbyAgg
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
pOperator
,
SGroupbyOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
STableQueryInfo
*
item
=
pQuery
->
current
;
static
void
doHashGroupbyAgg
(
SOperatorInfo
*
pOperator
,
SGroupbyOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
pOperator
->
pRuntimeEnv
;
STableQueryInfo
*
item
=
pRuntimeEnv
->
pQuery
->
current
;
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
colIndex
);
int16_t
bytes
=
pColInfoData
->
info
.
bytes
;
int16_t
type
=
pColInfoData
->
info
.
type
;
if
(
type
==
TSDB_DATA_TYPE_FLOAT
||
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
qError
(
"QInfo:%p group by not supported on double/float columns, abort"
,
pRuntimeEnv
->
qinfo
);
return
;
}
for
(
int32_t
j
=
0
;
j
<
pSDataBlock
->
info
.
rows
;
++
j
)
{
char
*
val
=
pColInfoData
->
pData
+
bytes
*
j
;
if
(
isNull
(
val
,
type
))
{
// TODO: ignore the null value
char
*
val
=
pColInfoData
->
pData
+
bytes
*
j
;
if
(
isNull
(
val
,
type
))
{
continue
;
}
// TODO compare with the previous value to speedup the query processing
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
val
,
type
,
bytes
,
item
->
groupIndex
,
pInfo
->
binfo
.
rowCellInfoOffset
);
if
(
pInfo
->
prevData
==
NULL
||
(
memcmp
(
pInfo
->
prevData
,
val
,
bytes
)
!=
0
))
{
if
(
pInfo
->
prevData
==
NULL
)
{
pInfo
->
prevData
=
malloc
(
bytes
);
}
memcpy
(
pInfo
->
prevData
,
val
,
bytes
);
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
pInfo
,
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
);
}
}
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfOutput
;
++
k
)
{
pInfo
->
binfo
.
pCtx
[
k
].
size
=
1
;
// TODO refactor: extract from here
...
...
@@ -1315,25 +1325,7 @@ static void hashGroupbyAgg(SQueryRuntimeEnv *pRuntimeEnv, SOperatorInfo* pOperat
}
}
static
int32_t
setGroupResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
,
int32_t
*
rowCellInfoOffset
)
{
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
// not assign result buffer yet, add new result buffer, TODO remove it
char
*
d
=
pData
;
int16_t
len
=
bytes
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
d
=
varDataVal
(
pData
);
len
=
varDataLen
(
pData
);
}
else
if
(
type
==
TSDB_DATA_TYPE_FLOAT
||
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
SQInfo
*
pQInfo
=
pRuntimeEnv
->
qinfo
;
qError
(
"QInfo:%p group by not supported on double/float columns, abort"
,
pQInfo
);
return
-
1
;
}
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pResultRowInfo
,
d
,
len
,
true
,
groupIndex
);
assert
(
pResultRow
!=
NULL
);
static
void
setResultRowKey
(
SResultRow
*
pResultRow
,
char
*
pData
,
int16_t
type
)
{
int64_t
v
=
-
1
;
GET_TYPED_DATA
(
v
,
int64_t
,
type
,
pData
);
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
@@ -1347,7 +1339,27 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow
pResultRow
->
win
.
skey
=
v
;
pResultRow
->
win
.
ekey
=
v
;
}
}
static
int32_t
setGroupResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupbyOperatorInfo
*
pInfo
,
int32_t
numOfCols
,
char
*
pData
,
int16_t
type
,
int16_t
bytes
,
int32_t
groupIndex
)
{
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
int32_t
*
rowCellInfoOffset
=
pInfo
->
binfo
.
rowCellInfoOffset
;
SResultRowInfo
*
pResultRowInfo
=
&
pInfo
->
binfo
.
resultRowInfo
;
SQLFunctionCtx
*
pCtx
=
pInfo
->
binfo
.
pCtx
;
// not assign result buffer yet, add new result buffer, TODO remove it
char
*
d
=
pData
;
int16_t
len
=
bytes
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
d
=
varDataVal
(
pData
);
len
=
varDataLen
(
pData
);
}
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pResultRowInfo
,
d
,
len
,
true
,
groupIndex
);
assert
(
pResultRow
!=
NULL
);
setResultRowKey
(
pResultRow
,
pData
,
type
);
if
(
pResultRow
->
pageId
==
-
1
)
{
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pResultBuf
,
groupIndex
,
pRuntimeEnv
->
pQuery
->
resultRowSize
);
if
(
ret
!=
0
)
{
...
...
@@ -4654,7 +4666,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param) {
return
pIntervalInfo
->
pRes
;
}
static
SSDataBlock
*
doHashGroupbyAgg
(
void
*
param
)
{
static
SSDataBlock
*
hashGroupbyAggregate
(
void
*
param
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
...
...
@@ -4688,16 +4700,14 @@ static SSDataBlock* doHashGroupbyAgg(void* param) {
pInfo
->
colIndex
=
getGroupbyColumnIndex
(
pRuntimeEnv
->
pQuery
->
pGroupbyExpr
,
pBlock
);
}
hashGroupbyAgg
(
pRuntimeEnv
,
pOperator
,
pInfo
,
pBlock
);
doHashGroupbyAgg
(
pOperator
,
pInfo
,
pBlock
);
}
pOperator
->
status
=
OP_RES_TO_RETURN
;
closeAllResultRows
(
&
pInfo
->
binfo
.
resultRowInfo
);
setQueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
// todo need finalize the result
if
(
!
pRuntimeEnv
->
pQuery
->
stableQuery
)
{
// finalize include the update of result rows
if
(
!
pRuntimeEnv
->
pQuery
->
stableQuery
)
{
// finalize include the update of result rows
finalizeQueryResult
(
pOperator
,
pInfo
->
binfo
.
pCtx
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
rowCellInfoOffset
);
}
else
{
updateNumOfRowsInResultRows
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
&
pInfo
->
binfo
.
resultRowInfo
,
pInfo
->
binfo
.
rowCellInfoOffset
);
...
...
@@ -4830,6 +4840,7 @@ static void destroySFillOperatorInfo(void* param, int32_t numOfOutput) {
static
void
destroyGroupbyOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SGroupbyOperatorInfo
*
pInfo
=
(
SGroupbyOperatorInfo
*
)
param
;
doDestroyBasicInfo
(
&
pInfo
->
binfo
,
numOfOutput
);
tfree
(
pInfo
->
prevData
);
}
static
void
destroyArithOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
...
...
@@ -5000,7 +5011,7 @@ SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
info
=
pInfo
;
pOperator
->
pRuntimeEnv
=
pRuntimeEnv
;
pOperator
->
exec
=
doHashGroupbyAgg
;
pOperator
->
exec
=
hashGroupbyAggregate
;
pOperator
->
cleanup
=
destroyGroupbyOperatorInfo
;
return
pOperator
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录