Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b9422c9
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看板
提交
5b9422c9
编写于
5月 26, 2022
作者:
P
plum-lihui
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/TDengine into 3.0
上级
a5a57c3c
c177ca2d
变更
44
展开全部
隐藏空白更改
内联
并排
Showing
44 changed file
with
1333 addition
and
382 deletion
+1333
-382
.gitignore
.gitignore
+1
-0
include/common/tmsg.h
include/common/tmsg.h
+15
-24
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+1
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+2
-1
include/libs/scheduler/scheduler.h
include/libs/scheduler/scheduler.h
+9
-17
include/util/tdigest.h
include/util/tdigest.h
+71
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+97
-0
source/client/src/clientStmt.c
source/client/src/clientStmt.c
+4
-19
source/common/src/systable.c
source/common/src/systable.c
+2
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+12
-6
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+1
-1
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+3
-2
source/dnode/mnode/impl/inc/mndScheduler.h
source/dnode/mnode/impl/inc/mndScheduler.h
+2
-1
source/dnode/mnode/impl/inc/mndVgroup.h
source/dnode/mnode/impl/inc/mndVgroup.h
+1
-0
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+1
-1
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+13
-2
source/dnode/mnode/impl/src/mndSma.c
source/dnode/mnode/impl/src/mndSma.c
+115
-7
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+14
-23
source/dnode/mnode/impl/src/mndTopic.c
source/dnode/mnode/impl/src/mndTopic.c
+1
-1
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+1
-1
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+26
-1
source/dnode/mnode/impl/test/stb/stb.cpp
source/dnode/mnode/impl/test/stb/stb.cpp
+2
-1
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+2
-2
source/dnode/vnode/src/meta/metaEntry.c
source/dnode/vnode/src/meta/metaEntry.c
+4
-4
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+19
-21
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+3
-3
source/dnode/vnode/src/vnd/vnodeQuery.c
source/dnode/vnode/src/vnd/vnodeQuery.c
+4
-4
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+5
-4
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+21
-22
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+114
-123
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+196
-31
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+5
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+4
-4
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+140
-2
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+34
-41
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+14
-2
source/libs/scheduler/src/schDbg.c
source/libs/scheduler/src/schDbg.c
+42
-0
source/libs/scheduler/src/schJob.c
source/libs/scheduler/src/schJob.c
+6
-1
source/libs/scheduler/src/schUtil.c
source/libs/scheduler/src/schUtil.c
+1
-0
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+1
-1
source/util/src/tdigest.c
source/util/src/tdigest.c
+319
-0
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+4
-7
tests/test/c/sdbDump.c
tests/test/c/sdbDump.c
+0
-1
tools/taos-tools
tools/taos-tools
+1
-1
未找到文件。
.gitignore
浏览文件 @
5b9422c9
...
...
@@ -110,3 +110,4 @@ contrib/*
!contrib/CMakeLists.txt
!contrib/test
sql
debug*/
include/common/tmsg.h
浏览文件 @
5b9422c9
...
...
@@ -300,9 +300,7 @@ typedef struct SSchema {
typedef
struct
{
int32_t
nCols
;
int32_t
sver
;
int32_t
tagVer
;
int32_t
colVer
;
int32_t
version
;
SSchema
*
pSchema
;
}
SSchemaWrapper
;
...
...
@@ -310,9 +308,7 @@ static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* p
SSchemaWrapper
*
pSW
=
(
SSchemaWrapper
*
)
taosMemoryMalloc
(
sizeof
(
SSchemaWrapper
));
if
(
pSW
==
NULL
)
return
pSW
;
pSW
->
nCols
=
pSchemaWrapper
->
nCols
;
pSW
->
sver
=
pSchemaWrapper
->
sver
;
pSW
->
tagVer
=
pSchemaWrapper
->
tagVer
;
pSW
->
colVer
=
pSchemaWrapper
->
colVer
;
pSW
->
version
=
pSchemaWrapper
->
version
;
pSW
->
pSchema
=
(
SSchema
*
)
taosMemoryCalloc
(
pSW
->
nCols
,
sizeof
(
SSchema
));
if
(
pSW
->
pSchema
==
NULL
)
{
taosMemoryFree
(
pSW
);
...
...
@@ -367,9 +363,7 @@ static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema)
static
FORCE_INLINE
int32_t
taosEncodeSSchemaWrapper
(
void
**
buf
,
const
SSchemaWrapper
*
pSW
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeVariantI32
(
buf
,
pSW
->
nCols
);
tlen
+=
taosEncodeVariantI32
(
buf
,
pSW
->
sver
);
tlen
+=
taosEncodeVariantI32
(
buf
,
pSW
->
tagVer
);
tlen
+=
taosEncodeVariantI32
(
buf
,
pSW
->
colVer
);
tlen
+=
taosEncodeVariantI32
(
buf
,
pSW
->
version
);
for
(
int32_t
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
tlen
+=
taosEncodeSSchema
(
buf
,
&
pSW
->
pSchema
[
i
]);
}
...
...
@@ -378,9 +372,7 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
static
FORCE_INLINE
void
*
taosDecodeSSchemaWrapper
(
const
void
*
buf
,
SSchemaWrapper
*
pSW
)
{
buf
=
taosDecodeVariantI32
(
buf
,
&
pSW
->
nCols
);
buf
=
taosDecodeVariantI32
(
buf
,
&
pSW
->
sver
);
buf
=
taosDecodeVariantI32
(
buf
,
&
pSW
->
tagVer
);
buf
=
taosDecodeVariantI32
(
buf
,
&
pSW
->
colVer
);
buf
=
taosDecodeVariantI32
(
buf
,
&
pSW
->
version
);
pSW
->
pSchema
=
(
SSchema
*
)
taosMemoryCalloc
(
pSW
->
nCols
,
sizeof
(
SSchema
));
if
(
pSW
->
pSchema
==
NULL
)
{
return
NULL
;
...
...
@@ -394,9 +386,7 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapp
static
FORCE_INLINE
int32_t
tEncodeSSchemaWrapper
(
SEncoder
*
pEncoder
,
const
SSchemaWrapper
*
pSW
)
{
if
(
tEncodeI32v
(
pEncoder
,
pSW
->
nCols
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pSW
->
sver
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pSW
->
tagVer
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pSW
->
colVer
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pSW
->
version
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
if
(
tEncodeSSchema
(
pEncoder
,
&
pSW
->
pSchema
[
i
])
<
0
)
return
-
1
;
}
...
...
@@ -406,9 +396,7 @@ static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSch
static
FORCE_INLINE
int32_t
tDecodeSSchemaWrapper
(
SDecoder
*
pDecoder
,
SSchemaWrapper
*
pSW
)
{
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
nCols
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
sver
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
tagVer
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
colVer
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
version
)
<
0
)
return
-
1
;
pSW
->
pSchema
=
(
SSchema
*
)
taosMemoryCalloc
(
pSW
->
nCols
,
sizeof
(
SSchema
));
if
(
pSW
->
pSchema
==
NULL
)
return
-
1
;
...
...
@@ -421,9 +409,7 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWra
static
FORCE_INLINE
int32_t
tDecodeSSchemaWrapperEx
(
SDecoder
*
pDecoder
,
SSchemaWrapper
*
pSW
)
{
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
nCols
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
sver
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
tagVer
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
colVer
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
version
)
<
0
)
return
-
1
;
pSW
->
pSchema
=
(
SSchema
*
)
tDecoderMalloc
(
pDecoder
,
pSW
->
nCols
*
sizeof
(
SSchema
));
if
(
pSW
->
pSchema
==
NULL
)
return
-
1
;
...
...
@@ -469,7 +455,8 @@ int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
typedef
struct
{
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
alterType
;
int32_t
verInBlock
;
int32_t
tagVer
;
int32_t
colVer
;
int32_t
numOfFields
;
SArray
*
pFields
;
int32_t
ttl
;
...
...
@@ -1023,6 +1010,10 @@ typedef struct {
SReplica
replicas
[
TSDB_MAX_REPLICA
];
int32_t
numOfRetensions
;
SArray
*
pRetensions
;
// SRetention
// for tsma
int8_t
isTsma
;
}
SCreateVnodeReq
;
int32_t
tSerializeSCreateVnodeReq
(
void
*
buf
,
int32_t
bufLen
,
SCreateVnodeReq
*
pReq
);
...
...
@@ -1713,7 +1704,7 @@ typedef struct SVCreateStbReq {
char
*
name
;
tb_uid_t
suid
;
int8_t
rollup
;
SSchemaWrapper
schema
;
SSchemaWrapper
schema
Row
;
SSchemaWrapper
schemaTag
;
SRSmaParam
pRSmaParam
;
}
SVCreateStbReq
;
...
...
@@ -1745,7 +1736,7 @@ typedef struct SVCreateTbReq {
uint8_t
*
pTag
;
}
ctb
;
struct
{
SSchemaWrapper
schema
;
SSchemaWrapper
schema
Row
;
}
ntb
;
};
}
SVCreateTbReq
;
...
...
include/libs/nodes/nodes.h
浏览文件 @
5b9422c9
...
...
@@ -214,6 +214,7 @@ typedef enum ENodeType {
QUERY_NODE_PHYSICAL_PLAN_FILL
,
QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW
,
QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW
,
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION_WINDOW
,
QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW
,
QUERY_NODE_PHYSICAL_PLAN_PARTITION
,
QUERY_NODE_PHYSICAL_PLAN_DISPATCH
,
...
...
include/libs/parser/parser.h
浏览文件 @
5b9422c9
...
...
@@ -48,11 +48,12 @@ typedef struct SParseContext {
}
SParseContext
;
int32_t
qParseSql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
);
bool
i
sInsertSql
(
const
char
*
pStr
,
size_t
length
);
bool
qI
sInsertSql
(
const
char
*
pStr
,
size_t
length
);
void
qDestroyQuery
(
SQuery
*
pQueryNode
);
int32_t
qExtractResultSchema
(
const
SNode
*
pRoot
,
int32_t
*
numOfCols
,
SSchema
**
pSchema
);
int32_t
qSetSTableIdForRSma
(
SNode
*
pStmt
,
int64_t
uid
);
int32_t
qBuildStmtOutput
(
SQuery
*
pQuery
,
SHashObj
*
pVgHash
,
SHashObj
*
pBlockHash
);
int32_t
qResetStmtDataBlock
(
void
*
block
,
bool
keepBuf
);
...
...
include/libs/scheduler/scheduler.h
浏览文件 @
5b9422c9
...
...
@@ -23,6 +23,8 @@ extern "C" {
#include "catalog.h"
#include "planner.h"
extern
tsem_t
schdRspSem
;
typedef
struct
SSchedulerCfg
{
uint32_t
maxJobNum
;
int32_t
maxNodeTableNum
;
...
...
@@ -62,6 +64,11 @@ typedef struct STaskInfo {
SSubQueryMsg
*
msg
;
}
STaskInfo
;
typedef
struct
SSchdFetchParam
{
void
**
pData
;
int32_t
*
code
;
}
SSchdFetchParam
;
typedef
void
(
*
schedulerExecCallback
)(
SQueryResult
*
pResult
,
void
*
param
,
int32_t
code
);
typedef
void
(
*
schedulerFetchCallback
)(
void
*
pResult
,
void
*
param
,
int32_t
code
);
...
...
@@ -113,23 +120,8 @@ void schedulerFreeJob(int64_t job);
void
schedulerDestroy
(
void
);
/**
* convert dag to task list
* @param pDag
* @param pTasks SArray**<STaskInfo>
* @return
*/
int32_t
schedulerConvertDagToTaskList
(
SQueryPlan
*
pDag
,
SArray
**
pTasks
);
/**
* make one task info's multiple copies
* @param src
* @param dst SArray**<STaskInfo>
* @return
*/
int32_t
schedulerCopyTask
(
STaskInfo
*
src
,
SArray
**
dst
,
int32_t
copyNum
);
void
schedulerFreeTaskList
(
SArray
*
taskList
);
void
schdExecCallback
(
SQueryResult
*
pResult
,
void
*
param
,
int32_t
code
);
void
schdFetchCallback
(
void
*
pResult
,
void
*
param
,
int32_t
code
);
#ifdef __cplusplus
...
...
include/util/tdigest.h
0 → 100644
浏览文件 @
5b9422c9
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* include/tdigest.c
*
* Copyright (c) 2016, Usman Masood <usmanm at fastmail dot fm>
*/
#ifndef TDIGEST_H
#define TDIGEST_H
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
/* pi */
#endif
#define DOUBLE_MAX 1.79e+308
#define ADDITION_CENTROID_NUM 2
#define COMPRESSION 300
#define GET_CENTROID(compression) (ceil(compression * M_PI / 2) + 1 + ADDITION_CENTROID_NUM)
#define GET_THRESHOLD(compression) (7.5 + 0.37 * compression - 2e-4 * pow(compression, 2))
#define TDIGEST_SIZE(compression) (sizeof(TDigest) + sizeof(SCentroid)*GET_CENTROID(compression) + sizeof(SPt)*GET_THRESHOLD(compression))
typedef
struct
SCentroid
{
double
mean
;
int64_t
weight
;
}
SCentroid
;
typedef
struct
SPt
{
double
value
;
int64_t
weight
;
}
SPt
;
typedef
struct
TDigest
{
double
compression
;
int32_t
threshold
;
int64_t
size
;
int64_t
total_weight
;
double
min
;
double
max
;
int32_t
num_buffered_pts
;
SPt
*
buffered_pts
;
int32_t
num_centroids
;
SCentroid
*
centroids
;
}
TDigest
;
TDigest
*
tdigestNewFrom
(
void
*
pBuf
,
int32_t
compression
);
void
tdigestAdd
(
TDigest
*
t
,
double
x
,
int64_t
w
);
void
tdigestMerge
(
TDigest
*
t1
,
TDigest
*
t2
);
double
tdigestQuantile
(
TDigest
*
t
,
double
q
);
void
tdigestCompress
(
TDigest
*
t
);
void
tdigestFreeFrom
(
TDigest
*
t
);
void
tdigestAutoFill
(
TDigest
*
t
,
int32_t
compression
);
#endif
/* TDIGEST_H */
source/client/src/clientImpl.c
浏览文件 @
5b9422c9
...
...
@@ -289,6 +289,52 @@ void setResPrecision(SReqResultInfo* pResInfo, int32_t precision) {
pResInfo
->
precision
=
precision
;
}
int32_t
scheduleAsyncQuery
(
SRequestObj
*
pRequest
,
SQueryPlan
*
pDag
,
SArray
*
pNodeList
,
void
**
pRes
)
{
void
*
pTransporter
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
tsem_init
(
&
schdRspSem
,
0
,
0
);
SQueryResult
res
=
{.
code
=
0
,
.
numOfRows
=
0
};
int32_t
code
=
schedulerAsyncExecJob
(
pTransporter
,
pNodeList
,
pDag
,
&
pRequest
->
body
.
queryJob
,
pRequest
->
sqlstr
,
pRequest
->
metric
.
start
,
schdExecCallback
,
&
res
);
while
(
true
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pRequest
->
body
.
queryJob
!=
0
)
{
schedulerFreeJob
(
pRequest
->
body
.
queryJob
);
}
*
pRes
=
res
.
res
;
pRequest
->
code
=
code
;
terrno
=
code
;
return
pRequest
->
code
;
}
else
{
tsem_wait
(
&
schdRspSem
);
if
(
res
.
code
)
{
code
=
res
.
code
;
}
else
{
break
;
}
}
}
if
(
TDMT_VND_SUBMIT
==
pRequest
->
type
||
TDMT_VND_CREATE_TABLE
==
pRequest
->
type
)
{
pRequest
->
body
.
resInfo
.
numOfRows
=
res
.
numOfRows
;
if
(
pRequest
->
body
.
queryJob
!=
0
)
{
schedulerFreeJob
(
pRequest
->
body
.
queryJob
);
}
}
*
pRes
=
res
.
res
;
pRequest
->
code
=
res
.
code
;
terrno
=
res
.
code
;
return
pRequest
->
code
;
}
int32_t
scheduleQuery
(
SRequestObj
*
pRequest
,
SQueryPlan
*
pDag
,
SArray
*
pNodeList
,
void
**
pRes
)
{
void
*
pTransporter
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
...
...
@@ -796,7 +842,58 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
}
}
void
*
doAsyncFetchRows
(
SRequestObj
*
pRequest
,
bool
setupOneRowPtr
,
bool
convertUcs4
)
{
assert
(
pRequest
!=
NULL
);
SReqResultInfo
*
pResultInfo
=
&
pRequest
->
body
.
resInfo
;
if
(
pResultInfo
->
pData
==
NULL
||
pResultInfo
->
current
>=
pResultInfo
->
numOfRows
)
{
// All data has returned to App already, no need to try again
if
(
pResultInfo
->
completed
)
{
pResultInfo
->
numOfRows
=
0
;
return
NULL
;
}
tsem_init
(
&
schdRspSem
,
0
,
0
);
SReqResultInfo
*
pResInfo
=
&
pRequest
->
body
.
resInfo
;
SSchdFetchParam
param
=
{.
pData
=
(
void
**
)
&
pResInfo
->
pData
,
.
code
=
&
pRequest
->
code
};
pRequest
->
code
=
schedulerAsyncFetchRows
(
pRequest
->
body
.
queryJob
,
schdFetchCallback
,
&
param
);
if
(
pRequest
->
code
!=
TSDB_CODE_SUCCESS
)
{
pResultInfo
->
numOfRows
=
0
;
return
NULL
;
}
tsem_wait
(
&
schdRspSem
);
if
(
pRequest
->
code
!=
TSDB_CODE_SUCCESS
)
{
pResultInfo
->
numOfRows
=
0
;
return
NULL
;
}
pRequest
->
code
=
setQueryResultFromRsp
(
&
pRequest
->
body
.
resInfo
,
(
SRetrieveTableRsp
*
)
pResInfo
->
pData
,
convertUcs4
);
if
(
pRequest
->
code
!=
TSDB_CODE_SUCCESS
)
{
pResultInfo
->
numOfRows
=
0
;
return
NULL
;
}
tscDebug
(
"0x%"
PRIx64
" fetch results, numOfRows:%d total Rows:%"
PRId64
", complete:%d, reqId:0x%"
PRIx64
,
pRequest
->
self
,
pResInfo
->
numOfRows
,
pResInfo
->
totalRows
,
pResInfo
->
completed
,
pRequest
->
requestId
);
if
(
pResultInfo
->
numOfRows
==
0
)
{
return
NULL
;
}
}
if
(
setupOneRowPtr
)
{
doSetOneRowPtr
(
pResultInfo
);
pResultInfo
->
current
+=
1
;
}
return
pResultInfo
->
row
;
}
void
*
doFetchRows
(
SRequestObj
*
pRequest
,
bool
setupOneRowPtr
,
bool
convertUcs4
)
{
//return doAsyncFetchRows(pRequest, setupOneRowPtr, convertUcs4);
assert
(
pRequest
!=
NULL
);
SReqResultInfo
*
pResultInfo
=
&
pRequest
->
body
.
resInfo
;
...
...
source/client/src/clientStmt.c
浏览文件 @
5b9422c9
...
...
@@ -48,7 +48,8 @@ int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) {
break
;
case
STMT_EXECUTE
:
if
(
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
)
{
if
(
STMT_STATUS_NE
(
ADD_BATCH
)
&&
STMT_STATUS_NE
(
FETCH_FIELDS
)
&&
STMT_STATUS_NE
(
BIND
)
&&
STMT_STATUS_NE
(
BIND_COL
))
{
if
(
STMT_STATUS_NE
(
ADD_BATCH
)
&&
STMT_STATUS_NE
(
FETCH_FIELDS
)
&&
STMT_STATUS_NE
(
BIND
)
&&
STMT_STATUS_NE
(
BIND_COL
))
{
code
=
TSDB_CODE_TSC_STMT_API_ERROR
;
}
}
else
{
...
...
@@ -230,22 +231,6 @@ int32_t stmtParseSql(STscStmt* pStmt) {
pStmt
->
sql
.
type
=
STMT_TYPE_QUERY
;
}
/*
switch (nodeType(pStmt->sql.pQuery->pRoot)) {
case QUERY_NODE_VNODE_MODIF_STMT:
if (0 == pStmt->sql.type) {
pStmt->sql.type = STMT_TYPE_INSERT;
}
break;
case QUERY_NODE_SELECT_STMT:
pStmt->sql.type = STMT_TYPE_QUERY;
break;
default:
tscError("not supported stmt type %d", nodeType(pStmt->sql.pQuery->pRoot));
STMT_ERR_RET(TSDB_CODE_TSC_STMT_CLAUSE_ERROR);
}
*/
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -823,7 +808,7 @@ _return:
code
=
stmtUpdateTableUid
(
pStmt
,
pRsp
);
}
}
tFreeSSubmitRsp
(
pRsp
);
++
pStmt
->
sql
.
runTimes
;
...
...
@@ -861,7 +846,7 @@ int stmtIsInsert(TAOS_STMT* stmt, int* insert) {
if
(
pStmt
->
sql
.
type
)
{
*
insert
=
(
STMT_TYPE_INSERT
==
pStmt
->
sql
.
type
||
STMT_TYPE_MULTI_INSERT
==
pStmt
->
sql
.
type
);
}
else
{
*
insert
=
i
sInsertSql
(
pStmt
->
sql
.
sqlStr
,
0
);
*
insert
=
qI
sInsertSql
(
pStmt
->
sql
.
sqlStr
,
0
);
}
return
TSDB_CODE_SUCCESS
;
...
...
source/common/src/systable.c
浏览文件 @
5b9422c9
...
...
@@ -196,12 +196,14 @@ static const SSysDbTableSchema vgroupsSchema[] = {
{.
name
=
"status"
,
.
bytes
=
12
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"nfiles"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"file_size"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"tsma"
,
.
bytes
=
1
,
.
type
=
TSDB_DATA_TYPE_TINYINT
},
};
static
const
SSysDbTableSchema
smaSchema
[]
=
{
{.
name
=
"sma_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"stable_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
};
static
const
SSysDbTableSchema
transSchema
[]
=
{
...
...
source/common/src/tmsg.c
浏览文件 @
5b9422c9
...
...
@@ -600,7 +600,8 @@ int32_t tSerializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq)
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pReq
->
name
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
alterType
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
verInBlock
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
tagVer
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
colVer
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
numOfFields
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
numOfFields
;
++
i
)
{
SField
*
pField
=
taosArrayGet
(
pReq
->
pFields
,
i
);
...
...
@@ -627,7 +628,8 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
name
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
alterType
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
verInBlock
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
tagVer
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
colVer
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
numOfFields
)
<
0
)
return
-
1
;
pReq
->
pFields
=
taosArrayInit
(
pReq
->
numOfFields
,
sizeof
(
SField
));
if
(
pReq
->
pFields
==
NULL
)
{
...
...
@@ -2915,6 +2917,8 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR
if
(
tEncodeI8
(
&
encoder
,
pRetension
->
freqUnit
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pRetension
->
keepUnit
)
<
0
)
return
-
1
;
}
if
(
tEncodeI8
(
&
encoder
,
pReq
->
isTsma
)
<
0
)
return
-
1
;
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
...
...
@@ -2977,6 +2981,8 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *
}
}
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
isTsma
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
tDecoderClear
(
&
decoder
);
return
0
;
...
...
@@ -3801,7 +3807,7 @@ int tEncodeSVCreateStbReq(SEncoder *pCoder, const SVCreateStbReq *pReq) {
if
(
tEncodeCStr
(
pCoder
,
pReq
->
name
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pReq
->
suid
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pCoder
,
pReq
->
rollup
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pReq
->
schema
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pReq
->
schema
Row
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pReq
->
schemaTag
)
<
0
)
return
-
1
;
if
(
pReq
->
rollup
)
{
if
(
tEncodeSRSmaParam
(
pCoder
,
&
pReq
->
pRSmaParam
)
<
0
)
return
-
1
;
...
...
@@ -3817,7 +3823,7 @@ int tDecodeSVCreateStbReq(SDecoder *pCoder, SVCreateStbReq *pReq) {
if
(
tDecodeCStr
(
pCoder
,
&
pReq
->
name
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
suid
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pReq
->
rollup
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pReq
->
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pReq
->
schema
Row
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pReq
->
schemaTag
)
<
0
)
return
-
1
;
if
(
pReq
->
rollup
)
{
if
(
tDecodeSRSmaParam
(
pCoder
,
&
pReq
->
pRSmaParam
)
<
0
)
return
-
1
;
...
...
@@ -3866,7 +3872,7 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
if
(
tEncodeI64
(
pCoder
,
pReq
->
ctb
.
suid
)
<
0
)
return
-
1
;
if
(
tEncodeBinary
(
pCoder
,
pReq
->
ctb
.
pTag
,
kvRowLen
(
pReq
->
ctb
.
pTag
))
<
0
)
return
-
1
;
}
else
if
(
pReq
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pReq
->
ntb
.
schema
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pReq
->
ntb
.
schema
Row
)
<
0
)
return
-
1
;
}
else
{
ASSERT
(
0
);
}
...
...
@@ -3892,7 +3898,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
ctb
.
suid
)
<
0
)
return
-
1
;
if
(
tDecodeBinary
(
pCoder
,
&
pReq
->
ctb
.
pTag
,
&
len
)
<
0
)
return
-
1
;
}
else
if
(
pReq
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pReq
->
ntb
.
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pReq
->
ntb
.
schema
Row
)
<
0
)
return
-
1
;
}
else
{
ASSERT
(
0
);
}
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
5b9422c9
...
...
@@ -183,7 +183,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return
-
1
;
}
dDebug
(
"vgId:%d, create vnode req is received
"
,
createReq
.
vgId
);
dDebug
(
"vgId:%d, create vnode req is received
, tsma:%d"
,
createReq
.
vgId
,
createReq
.
isTsma
);
SVnodeCfg
vnodeCfg
=
{
0
};
vmGenerateVnodeCfg
(
&
createReq
,
&
vnodeCfg
);
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
5b9422c9
...
...
@@ -330,6 +330,7 @@ typedef struct {
int64_t
compStorage
;
int64_t
pointsWritten
;
int8_t
compact
;
int8_t
isTsma
;
int8_t
replica
;
SVnodeGid
vnodeGid
[
TSDB_MAX_REPLICA
];
}
SVgObj
;
...
...
@@ -366,7 +367,6 @@ typedef struct {
int64_t
updateTime
;
int64_t
uid
;
int64_t
dbUid
;
int32_t
version
;
int32_t
tagVer
;
int32_t
colVer
;
int32_t
nextColId
;
...
...
@@ -589,7 +589,8 @@ typedef struct {
int8_t
status
;
int8_t
createdBy
;
// STREAM_CREATED_BY__USER or SMA
int32_t
fixedSinkVgId
;
// 0 for shuffle
int64_t
smaId
;
// 0 for unused
SVgObj
fixedSinkVg
;
int64_t
smaId
;
// 0 for unused
int8_t
trigger
;
int32_t
triggerParam
;
int64_t
waterMark
;
...
...
source/dnode/mnode/impl/inc/mndScheduler.h
浏览文件 @
5b9422c9
...
...
@@ -29,7 +29,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
int32_t
mndScheduleStream
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStreamObj
*
pStream
);
int32_t
mndConvertRSmaTask
(
const
char
*
ast
,
int8_t
triggerType
,
int64_t
watermark
,
char
**
pStr
,
int32_t
*
pLen
);
int32_t
mndConvertRSmaTask
(
const
char
*
ast
,
int64_t
uid
,
int8_t
triggerType
,
int64_t
watermark
,
char
**
pStr
,
int32_t
*
pLen
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/impl/inc/mndVgroup.h
浏览文件 @
5b9422c9
...
...
@@ -30,6 +30,7 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
SEpSet
mndGetVgroupEpset
(
SMnode
*
pMnode
,
const
SVgObj
*
pVgroup
);
int32_t
mndGetVnodesNum
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
int32_t
mndAllocSmaVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
);
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
);
SArray
*
mndBuildDnodesArray
(
SMnode
*
pMnode
);
int32_t
mndAddVnodeToVgroup
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SArray
*
pArray
);
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
5b9422c9
...
...
@@ -1155,7 +1155,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
NULL
==
pDb
||
pVgroup
->
dbUid
==
pDb
->
uid
)
{
if
(
(
NULL
==
pDb
||
pVgroup
->
dbUid
==
pDb
->
uid
)
&&
!
pVgroup
->
isTsma
)
{
SVgroupInfo
vgInfo
=
{
0
};
vgInfo
.
vgId
=
pVgroup
->
vgId
;
vgInfo
.
hashBegin
=
pVgroup
->
hashBegin
;
...
...
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
5b9422c9
...
...
@@ -28,13 +28,15 @@
#include "mndTrans.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "parser.h"
#include "tcompare.h"
#include "tname.h"
#include "tuuid.h"
extern
bool
tsStreamSchedV
;
int32_t
mndConvertRSmaTask
(
const
char
*
ast
,
int8_t
triggerType
,
int64_t
watermark
,
char
**
pStr
,
int32_t
*
pLen
)
{
int32_t
mndConvertRSmaTask
(
const
char
*
ast
,
int64_t
uid
,
int8_t
triggerType
,
int64_t
watermark
,
char
**
pStr
,
int32_t
*
pLen
)
{
SNode
*
pAst
=
NULL
;
SQueryPlan
*
pPlan
=
NULL
;
terrno
=
TSDB_CODE_SUCCESS
;
...
...
@@ -44,6 +46,11 @@ int32_t mndConvertRSmaTask(const char* ast, int8_t triggerType, int64_t watermar
goto
END
;
}
if
(
qSetSTableIdForRSma
(
pAst
,
uid
)
<
0
)
{
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
goto
END
;
}
SPlanContext
cxt
=
{
.
pAstRoot
=
pAst
,
.
topicQuery
=
false
,
...
...
@@ -230,11 +237,14 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr
taosArrayPush
(
tasks
,
&
pTask
);
pTask
->
nodeId
=
pStream
->
fixedSinkVgId
;
#if 0
SVgObj* pVgroup = mndAcquireVgroup(pMnode, pStream->fixedSinkVgId);
if (pVgroup == NULL) {
return -1;
}
pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup);
#endif
pTask
->
epSet
=
mndGetVgroupEpset
(
pMnode
,
&
pStream
->
fixedSinkVg
);
// source
pTask
->
sourceType
=
TASK_SOURCE__MERGE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
...
...
@@ -256,7 +266,8 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr
// dispatch
pTask
->
dispatchType
=
TASK_DISPATCH__NONE
;
mndPersistTaskDeployReq
(
pTrans
,
pTask
,
&
pTask
->
epSet
,
TDMT_VND_TASK_DEPLOY
,
pVgroup
->
vgId
);
/*mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);*/
mndPersistTaskDeployReq
(
pTrans
,
pTask
,
&
pTask
->
epSet
,
TDMT_VND_TASK_DEPLOY
,
pStream
->
fixedSinkVg
.
vgId
);
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndSma.c
浏览文件 @
5b9422c9
...
...
@@ -295,9 +295,9 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
}
static
void
*
mndBuildVDropSmaReq
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SSmaObj
*
pSma
,
int32_t
*
pContLen
)
{
SEncoder
encoder
=
{
0
};
int32_t
contLen
;
SName
name
=
{
0
};
SEncoder
encoder
=
{
0
};
int32_t
contLen
;
SName
name
=
{
0
};
tNameFromString
(
&
name
,
pSma
->
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
SVDropTSmaReq
req
=
{
0
};
...
...
@@ -354,6 +354,22 @@ static int32_t mndSetCreateSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj
return
0
;
}
static
int32_t
mndSetCreateSmaVgroupRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_CREATING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateSmaVgroupCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateSmaRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SSmaObj
*
pSma
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
...
...
@@ -393,6 +409,34 @@ static int32_t mndSetCreateSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
return
0
;
}
static
int32_t
mndSetCreateSmaVgroupRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
SVnodeGid
*
pVgid
=
pVgroup
->
vnodeGid
+
0
;
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pVgid
->
dnodeId
);
if
(
pDnode
==
NULL
)
return
-
1
;
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
mndReleaseDnode
(
pMnode
,
pDnode
);
// todo add sma info here
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildCreateVnodeReq
(
pMnode
,
pDnode
,
pDb
,
pVgroup
,
&
contLen
);
if
(
pReq
==
NULL
)
return
-
1
;
action
.
pCont
=
pReq
;
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_DND_CREATE_VNODE
;
action
.
acceptableCode
=
TSDB_CODE_NODE_ALREADY_DEPLOYED
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
taosMemoryFree
(
pReq
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndCreateSma
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SMCreateSmaReq
*
pCreate
,
SDbObj
*
pDb
,
SStbObj
*
pStb
)
{
SSmaObj
smaObj
=
{
0
};
memcpy
(
smaObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
...
...
@@ -448,9 +492,14 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
streamObj
.
version
=
1
;
streamObj
.
sql
=
pCreate
->
sql
;
streamObj
.
createdBy
=
STREAM_CREATED_BY__SMA
;
streamObj
.
fixedSinkVgId
=
smaObj
.
dstVgId
;
streamObj
.
smaId
=
smaObj
.
uid
;
/*streamObj.physicalPlan = "";*/
if
(
mndAllocSmaVgroup
(
pMnode
,
pDb
,
&
streamObj
.
fixedSinkVg
)
!=
0
)
{
mError
(
"sma:%s, failed to create since %s"
,
smaObj
.
name
,
terrstr
());
return
-
1
;
}
smaObj
.
dstVgId
=
streamObj
.
fixedSinkVg
.
vgId
;
streamObj
.
fixedSinkVgId
=
smaObj
.
dstVgId
;
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_TYPE_CREATE_SMA
,
pReq
);
...
...
@@ -460,8 +509,11 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
mndTransSetDbInfo
(
pTrans
,
pDb
);
if
(
mndSetCreateSmaRedoLogs
(
pMnode
,
pTrans
,
&
smaObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaVgroupRedoLogs
(
pMnode
,
pTrans
,
&
streamObj
.
fixedSinkVg
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaCommitLogs
(
pMnode
,
pTrans
,
&
smaObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaVgroupCommitLogs
(
pMnode
,
pTrans
,
&
streamObj
.
fixedSinkVg
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaRedoActions
(
pMnode
,
pTrans
,
pDb
,
&
smaObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetCreateSmaVgroupRedoActions
(
pMnode
,
pTrans
,
pDb
,
&
streamObj
.
fixedSinkVg
)
!=
0
)
goto
_OVER
;
if
(
mndAddStreamToTrans
(
pMnode
,
&
streamObj
,
pCreate
->
ast
,
STREAM_TRIGGER_AT_ONCE
,
0
,
pTrans
)
!=
0
)
goto
_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
_OVER
;
...
...
@@ -480,7 +532,6 @@ static int32_t mndCheckCreateSmaReq(SMCreateSmaReq *pCreate) {
if
(
pCreate
->
intervalUnit
<
0
)
return
-
1
;
if
(
pCreate
->
slidingUnit
<
0
)
return
-
1
;
if
(
pCreate
->
timezone
<
0
)
return
-
1
;
if
(
pCreate
->
dstVgId
<
0
)
return
-
1
;
if
(
pCreate
->
interval
<
0
)
return
-
1
;
if
(
pCreate
->
offset
<
0
)
return
-
1
;
if
(
pCreate
->
sliding
<
0
)
return
-
1
;
...
...
@@ -602,6 +653,24 @@ static int32_t mndSetDropSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *
return
0
;
}
static
int32_t
mndSetDropSmaVgroupRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_DROPPING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropSmaVgroupCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropSmaRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SSmaObj
*
pSma
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
...
...
@@ -643,23 +712,59 @@ static int32_t mndSetDropSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
return
0
;
}
static
int32_t
mndSetDropSmaVgroupRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
SVnodeGid
*
pVgid
=
pVgroup
->
vnodeGid
+
0
;
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pVgid
->
dnodeId
);
if
(
pDnode
==
NULL
)
return
-
1
;
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
mndReleaseDnode
(
pMnode
,
pDnode
);
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildDropVnodeReq
(
pMnode
,
pDnode
,
pDb
,
pVgroup
,
&
contLen
);
if
(
pReq
==
NULL
)
return
-
1
;
action
.
pCont
=
pReq
;
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_DND_DROP_VNODE
;
action
.
acceptableCode
=
TSDB_CODE_NODE_NOT_DEPLOYED
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
taosMemoryFree
(
pReq
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndDropSma
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDbObj
*
pDb
,
SSmaObj
*
pSma
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_TYPE_DROP_SMA
,
pReq
);
SVgObj
*
pVgroup
=
NULL
;
STrans
*
pTrans
=
NULL
;
pVgroup
=
mndAcquireVgroup
(
pMnode
,
pSma
->
dstVgId
);
if
(
pVgroup
==
NULL
)
goto
_OVER
;
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_TYPE_DROP_SMA
,
pReq
);
if
(
pTrans
==
NULL
)
goto
_OVER
;
mDebug
(
"trans:%d, used to drop sma:%s"
,
pTrans
->
id
,
pSma
->
name
);
mndTransSetDbInfo
(
pTrans
,
pDb
);
if
(
mndSetDropSmaRedoLogs
(
pMnode
,
pTrans
,
pSma
)
!=
0
)
goto
_OVER
;
if
(
mndSetDropSmaVgroupRedoLogs
(
pMnode
,
pTrans
,
pVgroup
)
!=
0
)
goto
_OVER
;
if
(
mndSetDropSmaCommitLogs
(
pMnode
,
pTrans
,
pSma
)
!=
0
)
goto
_OVER
;
if
(
mndSetDropSmaVgroupCommitLogs
(
pMnode
,
pTrans
,
pVgroup
)
!=
0
)
goto
_OVER
;
if
(
mndSetDropSmaRedoActions
(
pMnode
,
pTrans
,
pDb
,
pSma
)
!=
0
)
goto
_OVER
;
if
(
mndSetDropSmaVgroupRedoActions
(
pMnode
,
pTrans
,
pDb
,
pVgroup
)
!=
0
)
goto
_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
_OVER
;
code
=
0
;
_OVER:
mndTransDrop
(
pTrans
);
mndReleaseVgroup
(
pMnode
,
pVgroup
);
return
code
;
}
...
...
@@ -846,6 +951,9 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
n1
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pSma
->
dstVgId
,
false
);
numOfRows
++
;
sdbRelease
(
pSdb
,
pSma
);
}
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
5b9422c9
...
...
@@ -87,7 +87,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
updateTime
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
uid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
dbUid
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
version
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
tagVer
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
colVer
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
nextColId
,
_OVER
)
...
...
@@ -167,7 +166,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pStb
->
updateTime
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pStb
->
uid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pStb
->
dbUid
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
version
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
tagVer
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
colVer
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pStb
->
nextColId
,
_OVER
)
...
...
@@ -320,7 +318,6 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
}
pOld
->
updateTime
=
pNew
->
updateTime
;
pOld
->
version
=
pNew
->
version
;
pOld
->
tagVer
=
pNew
->
tagVer
;
pOld
->
colVer
=
pNew
->
colVer
;
pOld
->
nextColId
=
pNew
->
nextColId
;
...
...
@@ -388,25 +385,26 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
req
.
name
=
(
char
*
)
tNameGetTableName
(
&
name
);
req
.
suid
=
pStb
->
uid
;
req
.
rollup
=
pStb
->
ast1Len
>
0
?
1
:
0
;
req
.
schema
.
nCols
=
pStb
->
numOfColumns
;
req
.
schema
.
sver
=
pStb
->
version
;
req
.
schema
.
tagVer
=
pStb
->
tagVer
;
req
.
schema
.
colVer
=
pStb
->
colVer
;
req
.
schema
.
pSchema
=
pStb
->
pColumns
;
// todo
req
.
schemaRow
.
nCols
=
pStb
->
numOfColumns
;
req
.
schemaRow
.
version
=
pStb
->
colVer
;
req
.
schemaRow
.
pSchema
=
pStb
->
pColumns
;
req
.
schemaTag
.
nCols
=
pStb
->
numOfTags
;
req
.
schemaTag
.
sver
=
1
;
req
.
schemaTag
.
version
=
pStb
->
tagVer
;
req
.
schemaTag
.
pSchema
=
pStb
->
pTags
;
if
(
req
.
rollup
)
{
req
.
pRSmaParam
.
xFilesFactor
=
pStb
->
xFilesFactor
;
req
.
pRSmaParam
.
delay
=
pStb
->
delay
;
if
(
pStb
->
ast1Len
>
0
)
{
if
(
mndConvertRSmaTask
(
pStb
->
pAst1
,
0
,
0
,
&
req
.
pRSmaParam
.
qmsg1
,
&
req
.
pRSmaParam
.
qmsg1Len
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mndConvertRSmaTask
(
pStb
->
pAst1
,
pStb
->
uid
,
0
,
0
,
&
req
.
pRSmaParam
.
qmsg1
,
&
req
.
pRSmaParam
.
qmsg1Len
)
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
}
}
if
(
pStb
->
ast2Len
>
0
)
{
if
(
mndConvertRSmaTask
(
pStb
->
pAst2
,
0
,
0
,
&
req
.
pRSmaParam
.
qmsg2
,
&
req
.
pRSmaParam
.
qmsg2Len
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mndConvertRSmaTask
(
pStb
->
pAst2
,
pStb
->
uid
,
0
,
0
,
&
req
.
pRSmaParam
.
qmsg2
,
&
req
.
pRSmaParam
.
qmsg2Len
)
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
}
}
...
...
@@ -664,7 +662,6 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat
pDst
->
updateTime
=
pDst
->
createdTime
;
pDst
->
uid
=
mndGenerateUid
(
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
pDst
->
dbUid
=
pDb
->
uid
;
pDst
->
version
=
1
;
pDst
->
tagVer
=
1
;
pDst
->
colVer
=
1
;
pDst
->
nextColId
=
1
;
...
...
@@ -956,7 +953,6 @@ static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *p
mDebug
(
"stb:%s, start to add tag %s"
,
pNew
->
name
,
pSchema
->
name
);
}
pNew
->
version
++
;
pNew
->
tagVer
++
;
return
0
;
}
...
...
@@ -975,7 +971,6 @@ static int32_t mndDropSuperTableTag(const SStbObj *pOld, SStbObj *pNew, const ch
memmove
(
pNew
->
pTags
+
tag
,
pNew
->
pTags
+
tag
+
1
,
sizeof
(
SSchema
)
*
(
pNew
->
numOfTags
-
tag
-
1
));
pNew
->
numOfTags
--
;
pNew
->
version
++
;
pNew
->
tagVer
++
;
mDebug
(
"stb:%s, start to drop tag %s"
,
pNew
->
name
,
tagName
);
return
0
;
...
...
@@ -1016,7 +1011,6 @@ static int32_t mndAlterStbTagName(const SStbObj *pOld, SStbObj *pNew, SArray *pF
SSchema
*
pSchema
=
(
SSchema
*
)(
pNew
->
pTags
+
tag
);
memcpy
(
pSchema
->
name
,
newTagName
,
TSDB_COL_NAME_LEN
);
pNew
->
version
++
;
pNew
->
tagVer
++
;
mDebug
(
"stb:%s, start to modify tag %s to %s"
,
pNew
->
name
,
oldTagName
,
newTagName
);
return
0
;
...
...
@@ -1046,7 +1040,6 @@ static int32_t mndAlterStbTagBytes(const SStbObj *pOld, SStbObj *pNew, const SFi
}
pTag
->
bytes
=
pField
->
bytes
;
pNew
->
version
++
;
pNew
->
tagVer
++
;
mDebug
(
"stb:%s, start to modify tag len %s to %d"
,
pNew
->
name
,
pField
->
name
,
pField
->
bytes
);
...
...
@@ -1086,7 +1079,6 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray
mDebug
(
"stb:%s, start to add column %s"
,
pNew
->
name
,
pSchema
->
name
);
}
pNew
->
version
++
;
pNew
->
colVer
++
;
return
0
;
}
...
...
@@ -1115,7 +1107,6 @@ static int32_t mndDropSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, const
memmove
(
pNew
->
pColumns
+
col
,
pNew
->
pColumns
+
col
+
1
,
sizeof
(
SSchema
)
*
(
pNew
->
numOfColumns
-
col
-
1
));
pNew
->
numOfColumns
--
;
pNew
->
version
++
;
pNew
->
colVer
++
;
mDebug
(
"stb:%s, start to drop col %s"
,
pNew
->
name
,
colName
);
return
0
;
...
...
@@ -1154,7 +1145,6 @@ static int32_t mndAlterStbColumnBytes(const SStbObj *pOld, SStbObj *pNew, const
}
pCol
->
bytes
=
pField
->
bytes
;
pNew
->
version
++
;
pNew
->
colVer
++
;
mDebug
(
"stb:%s, start to modify col len %s to %d"
,
pNew
->
name
,
pField
->
name
,
pField
->
bytes
);
...
...
@@ -1315,9 +1305,10 @@ static int32_t mndProcessMAlterStbReq(SRpcMsg *pReq) {
goto
_OVER
;
}
if
(
alterReq
.
verInBlock
>
0
&&
alterReq
.
verInBlock
<=
pStb
->
version
)
{
mDebug
(
"stb:%s, already exist, verInBlock:%d smaller than verInStb:%d, alter success"
,
alterReq
.
name
,
alterReq
.
verInBlock
,
pStb
->
version
);
if
((
alterReq
.
tagVer
>
0
&&
alterReq
.
colVer
>
0
)
&&
(
alterReq
.
tagVer
<=
pStb
->
tagVer
||
alterReq
.
colVer
<=
pStb
->
colVer
))
{
mDebug
(
"stb:%s, already exist, tagVer:%d colVer:%d smaller than in mnode, tagVer:%d colVer:%d, alter success"
,
alterReq
.
name
,
alterReq
.
tagVer
,
alterReq
.
colVer
,
pStb
->
tagVer
,
pStb
->
colVer
);
code
=
0
;
goto
_OVER
;
}
...
...
@@ -1511,7 +1502,7 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa
pRsp
->
numOfColumns
=
pStb
->
numOfColumns
;
pRsp
->
precision
=
pDb
->
cfg
.
precision
;
pRsp
->
tableType
=
TSDB_SUPER_TABLE
;
pRsp
->
sversion
=
pStb
->
version
;
pRsp
->
sversion
=
pStb
->
colVer
;
pRsp
->
suid
=
pStb
->
uid
;
pRsp
->
tuid
=
pStb
->
uid
;
...
...
source/dnode/mnode/impl/src/mndTopic.c
浏览文件 @
5b9422c9
...
...
@@ -217,7 +217,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
}
}
else
{
pTopic
->
schema
.
nCols
=
0
;
pTopic
->
schema
.
sver
=
0
;
pTopic
->
schema
.
version
=
0
;
pTopic
->
schema
.
pSchema
=
NULL
;
}
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
5b9422c9
...
...
@@ -829,7 +829,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
sendRsp
=
true
;
}
}
else
{
if
(
pTrans
->
stage
==
TRN_STAGE_REDO_ACTION
&&
pTrans
->
failedTimes
>
0
)
{
if
(
pTrans
->
stage
==
TRN_STAGE_REDO_ACTION
&&
pTrans
->
failedTimes
>
6
)
{
if
(
code
==
0
)
code
=
TSDB_CODE_MND_TRANS_UNKNOW_ERROR
;
sendRsp
=
true
;
}
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
5b9422c9
...
...
@@ -80,6 +80,7 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgroup
->
hashEnd
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pVgroup
->
dbName
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pVgroup
->
dbUid
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pVgroup
->
isTsma
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pVgroup
->
replica
,
_OVER
)
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
...
...
@@ -127,6 +128,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pVgroup
->
hashEnd
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pVgroup
->
dbName
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pVgroup
->
dbUid
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pVgroup
->
isTsma
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pVgroup
->
replica
,
_OVER
)
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
...
...
@@ -167,6 +169,7 @@ static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOld, SVgObj *pNew) {
pOld
->
hashBegin
=
pNew
->
hashBegin
;
pOld
->
hashEnd
=
pNew
->
hashEnd
;
pOld
->
replica
=
pNew
->
replica
;
pOld
->
isTsma
=
pNew
->
isTsma
;
memcpy
(
pOld
->
vnodeGid
,
pNew
->
vnodeGid
,
TSDB_MAX_REPLICA
*
sizeof
(
SVnodeGid
));
return
0
;
}
...
...
@@ -426,6 +429,25 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr
return
0
;
}
int32_t
mndAllocSmaVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
SArray
*
pArray
=
mndBuildDnodesArray
(
pMnode
);
if
(
pArray
==
NULL
)
return
-
1
;
pVgroup
->
vgId
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_VGROUP
);
pVgroup
->
isTsma
=
1
;
pVgroup
->
createdTime
=
taosGetTimestampMs
();
pVgroup
->
updateTime
=
pVgroup
->
createdTime
;
pVgroup
->
version
=
1
;
memcpy
(
pVgroup
->
dbName
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
replica
=
1
;
if
(
mndGetAvailableDnode
(
pMnode
,
pVgroup
,
pArray
)
!=
0
)
return
-
1
;
mInfo
(
"db:%s, sma vgId:%d is alloced"
,
pDb
->
name
,
pVgroup
->
vgId
);
return
0
;
}
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
)
{
int32_t
code
=
-
1
;
SArray
*
pArray
=
NULL
;
...
...
@@ -702,9 +724,12 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppendNULL
(
pColInfo
,
numOfRows
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppendNULL
(
pColInfo
,
numOfRows
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pVgroup
->
isTsma
,
false
);
numOfRows
++
;
sdbRelease
(
pSdb
,
pVgroup
);
}
...
...
source/dnode/mnode/impl/test/stb/stb.cpp
浏览文件 @
5b9422c9
...
...
@@ -277,7 +277,8 @@ void* MndTestStb::BuildAlterStbUpdateColumnBytesReq(const char* stbname, const c
req
.
numOfFields
=
1
;
req
.
pFields
=
taosArrayInit
(
1
,
sizeof
(
SField
));
req
.
alterType
=
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
;
req
.
verInBlock
=
verInBlock
;
req
.
tagVer
=
verInBlock
;
req
.
colVer
=
verInBlock
;
SField
field
=
{
0
};
field
.
bytes
=
bytes
;
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
5b9422c9
...
...
@@ -182,7 +182,7 @@ struct SMetaEntry {
char
*
name
;
union
{
struct
{
SSchemaWrapper
schema
;
SSchemaWrapper
schema
Row
;
SSchemaWrapper
schemaTag
;
}
stbEntry
;
struct
{
...
...
@@ -195,7 +195,7 @@ struct SMetaEntry {
int64_t
ctime
;
int32_t
ttlDays
;
int32_t
ncid
;
// next column id
SSchemaWrapper
schema
;
SSchemaWrapper
schema
Row
;
}
ntbEntry
;
struct
{
STSma
*
tsma
;
...
...
source/dnode/vnode/src/meta/metaEntry.c
浏览文件 @
5b9422c9
...
...
@@ -24,7 +24,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
if
(
tEncodeCStr
(
pCoder
,
pME
->
name
)
<
0
)
return
-
1
;
if
(
pME
->
type
==
TSDB_SUPER_TABLE
)
{
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pME
->
stbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pME
->
stbEntry
.
schema
Row
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pME
->
stbEntry
.
schemaTag
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
if
(
tEncodeI64
(
pCoder
,
pME
->
ctbEntry
.
ctime
)
<
0
)
return
-
1
;
...
...
@@ -35,7 +35,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
if
(
tEncodeI64
(
pCoder
,
pME
->
ntbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pME
->
ntbEntry
.
ttlDays
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pCoder
,
pME
->
ntbEntry
.
ncid
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pME
->
ntbEntry
.
schema
Row
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_TSMA_TABLE
)
{
if
(
tEncodeTSma
(
pCoder
,
pME
->
smaEntry
.
tsma
)
<
0
)
return
-
1
;
}
else
{
...
...
@@ -56,7 +56,7 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
if
(
tDecodeCStr
(
pCoder
,
&
pME
->
name
)
<
0
)
return
-
1
;
if
(
pME
->
type
==
TSDB_SUPER_TABLE
)
{
if
(
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pME
->
stbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pME
->
stbEntry
.
schema
Row
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pME
->
stbEntry
.
schemaTag
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ctbEntry
.
ctime
)
<
0
)
return
-
1
;
...
...
@@ -67,7 +67,7 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ntbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pME
->
ntbEntry
.
ttlDays
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pCoder
,
&
pME
->
ntbEntry
.
ncid
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pME
->
ntbEntry
.
schema
Row
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_TSMA_TABLE
)
{
pME
->
smaEntry
.
tsma
=
tDecoderMalloc
(
pCoder
,
sizeof
(
STSma
));
if
(
!
pME
->
smaEntry
.
tsma
)
{
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
5b9422c9
...
...
@@ -56,7 +56,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
me
.
type
=
TSDB_SUPER_TABLE
;
me
.
uid
=
pReq
->
suid
;
me
.
name
=
pReq
->
name
;
me
.
stbEntry
.
schema
=
pReq
->
schema
;
me
.
stbEntry
.
schema
Row
=
pReq
->
schemaRow
;
me
.
stbEntry
.
schemaTag
=
pReq
->
schemaTag
;
if
(
metaHandleEntry
(
pMeta
,
&
me
)
<
0
)
goto
_err
;
...
...
@@ -182,15 +182,13 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
nStbEntry
.
type
=
TSDB_SUPER_TABLE
;
nStbEntry
.
uid
=
pReq
->
suid
;
nStbEntry
.
name
=
pReq
->
name
;
nStbEntry
.
stbEntry
.
schema
=
pReq
->
schema
;
nStbEntry
.
stbEntry
.
schema
Row
=
pReq
->
schemaRow
;
nStbEntry
.
stbEntry
.
schemaTag
=
pReq
->
schemaTag
;
metaWLock
(
pMeta
);
// compare two entry
if
(
oStbEntry
.
stbEntry
.
schema
.
sver
!=
pReq
->
schema
.
sver
)
{
if
(
oStbEntry
.
stbEntry
.
schema
.
nCols
!=
pReq
->
schema
.
nCols
)
{
metaSaveToSkmDb
(
pMeta
,
&
nStbEntry
);
}
if
(
oStbEntry
.
stbEntry
.
schemaRow
.
version
!=
pReq
->
schemaRow
.
version
)
{
metaSaveToSkmDb
(
pMeta
,
&
nStbEntry
);
}
// if (oStbEntry.stbEntry.schemaTag.sver != pReq->schemaTag.sver) {
...
...
@@ -247,8 +245,8 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
}
else
{
me
.
ntbEntry
.
ctime
=
pReq
->
ctime
;
me
.
ntbEntry
.
ttlDays
=
pReq
->
ttl
;
me
.
ntbEntry
.
schema
=
pReq
->
ntb
.
schema
;
me
.
ntbEntry
.
ncid
=
me
.
ntbEntry
.
schema
.
pSchema
[
me
.
ntbEntry
.
schema
.
nCols
-
1
].
colId
+
1
;
me
.
ntbEntry
.
schema
Row
=
pReq
->
ntb
.
schemaRow
;
me
.
ntbEntry
.
ncid
=
me
.
ntbEntry
.
schema
Row
.
pSchema
[
me
.
ntbEntry
.
schemaRow
.
nCols
-
1
].
colId
+
1
;
}
if
(
metaHandleEntry
(
pMeta
,
&
me
)
<
0
)
goto
_err
;
...
...
@@ -381,7 +379,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
}
// search the column to add/drop/update
pSchema
=
&
entry
.
ntbEntry
.
schema
;
pSchema
=
&
entry
.
ntbEntry
.
schema
Row
;
int32_t
iCol
=
0
;
for
(;;)
{
pColumn
=
NULL
;
...
...
@@ -402,16 +400,16 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
terrno
=
TSDB_CODE_VND_COL_ALREADY_EXISTS
;
goto
_err
;
}
pSchema
->
sver
++
;
pSchema
->
version
++
;
pSchema
->
nCols
++
;
pNewSchema
=
taosMemoryMalloc
(
sizeof
(
SSchema
)
*
pSchema
->
nCols
);
memcpy
(
pNewSchema
,
pSchema
->
pSchema
,
sizeof
(
SSchema
)
*
(
pSchema
->
nCols
-
1
));
pSchema
->
pSchema
=
pNewSchema
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
bytes
=
pAlterTbReq
->
bytes
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
type
=
pAlterTbReq
->
type
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
flags
=
pAlterTbReq
->
flags
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
colId
=
entry
.
ntbEntry
.
ncid
++
;
strcpy
(
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
name
,
pAlterTbReq
->
colName
);
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
Row
.
nCols
-
1
].
bytes
=
pAlterTbReq
->
bytes
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
Row
.
nCols
-
1
].
type
=
pAlterTbReq
->
type
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
Row
.
nCols
-
1
].
flags
=
pAlterTbReq
->
flags
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
Row
.
nCols
-
1
].
colId
=
entry
.
ntbEntry
.
ncid
++
;
strcpy
(
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
Row
.
nCols
-
1
].
name
,
pAlterTbReq
->
colName
);
break
;
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
if
(
pColumn
==
NULL
)
{
...
...
@@ -422,7 +420,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
terrno
=
TSDB_CODE_VND_INVALID_TABLE_ACTION
;
goto
_err
;
}
pSchema
->
sver
++
;
pSchema
->
version
++
;
tlen
=
(
pSchema
->
nCols
-
iCol
-
1
)
*
sizeof
(
SSchema
);
if
(
tlen
)
{
memmove
(
pColumn
,
pColumn
+
1
,
tlen
);
...
...
@@ -438,7 +436,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
terrno
=
TSDB_CODE_VND_INVALID_TABLE_ACTION
;
goto
_err
;
}
pSchema
->
sver
++
;
pSchema
->
version
++
;
pColumn
->
bytes
=
pAlterTbReq
->
colModBytes
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
...
...
@@ -446,7 +444,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
terrno
=
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
;
goto
_err
;
}
pSchema
->
sver
++
;
pSchema
->
version
++
;
strcpy
(
pColumn
->
name
,
pAlterTbReq
->
colNewName
);
break
;
}
...
...
@@ -813,15 +811,15 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
const
SSchemaWrapper
*
pSW
;
if
(
pME
->
type
==
TSDB_SUPER_TABLE
)
{
pSW
=
&
pME
->
stbEntry
.
schema
;
pSW
=
&
pME
->
stbEntry
.
schema
Row
;
}
else
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
pSW
=
&
pME
->
ntbEntry
.
schema
;
pSW
=
&
pME
->
ntbEntry
.
schema
Row
;
}
else
{
ASSERT
(
0
);
}
skmDbKey
.
uid
=
pME
->
uid
;
skmDbKey
.
sver
=
pSW
->
sver
;
skmDbKey
.
sver
=
pSW
->
version
;
// encode schema
int32_t
ret
=
0
;
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
5b9422c9
...
...
@@ -321,13 +321,13 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo
terrno
=
TSDB_CODE_PAR_TABLE_NOT_EXIST
;
return
-
1
;
}
strcat
(
pRsp
->
tblFName
,
mr
.
me
.
name
);
if
(
pRsp
->
tblFName
)
strcat
(
pRsp
->
tblFName
,
mr
.
me
.
name
);
if
(
mr
.
me
.
type
==
TSDB_NORMAL_TABLE
)
{
sverNew
=
mr
.
me
.
ntbEntry
.
schema
.
sver
;
sverNew
=
mr
.
me
.
ntbEntry
.
schema
Row
.
version
;
}
else
{
metaGetTableEntryByUid
(
&
mr
,
mr
.
me
.
ctbEntry
.
suid
);
sverNew
=
mr
.
me
.
stbEntry
.
schema
.
sver
;
sverNew
=
mr
.
me
.
stbEntry
.
schema
Row
.
version
;
}
metaReaderClear
(
&
mr
);
...
...
source/dnode/vnode/src/vnd/vnodeQuery.c
浏览文件 @
5b9422c9
...
...
@@ -64,7 +64,7 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
if
(
mer1
.
me
.
type
==
TSDB_SUPER_TABLE
)
{
strcpy
(
metaRsp
.
stbName
,
mer1
.
me
.
name
);
schema
=
mer1
.
me
.
stbEntry
.
schema
;
schema
=
mer1
.
me
.
stbEntry
.
schema
Row
;
schemaTag
=
mer1
.
me
.
stbEntry
.
schemaTag
;
metaRsp
.
suid
=
mer1
.
me
.
uid
;
}
else
if
(
mer1
.
me
.
type
==
TSDB_CHILD_TABLE
)
{
...
...
@@ -73,10 +73,10 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
strcpy
(
metaRsp
.
stbName
,
mer2
.
me
.
name
);
metaRsp
.
suid
=
mer2
.
me
.
uid
;
schema
=
mer2
.
me
.
stbEntry
.
schema
;
schema
=
mer2
.
me
.
stbEntry
.
schema
Row
;
schemaTag
=
mer2
.
me
.
stbEntry
.
schemaTag
;
}
else
if
(
mer1
.
me
.
type
==
TSDB_NORMAL_TABLE
)
{
schema
=
mer1
.
me
.
ntbEntry
.
schema
;
schema
=
mer1
.
me
.
ntbEntry
.
schema
Row
;
}
else
{
ASSERT
(
0
);
}
...
...
@@ -84,7 +84,7 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
metaRsp
.
numOfTags
=
schemaTag
.
nCols
;
metaRsp
.
numOfColumns
=
schema
.
nCols
;
metaRsp
.
precision
=
pVnode
->
config
.
tsdbCfg
.
precision
;
metaRsp
.
sversion
=
schema
.
sver
;
metaRsp
.
sversion
=
schema
.
version
;
metaRsp
.
pSchemas
=
(
SSchema
*
)
taosMemoryMalloc
(
sizeof
(
SSchema
)
*
(
metaRsp
.
numOfColumns
+
metaRsp
.
numOfTags
));
memcpy
(
metaRsp
.
pSchemas
,
schema
.
pSchema
,
sizeof
(
SSchema
)
*
schema
.
nCols
);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
5b9422c9
...
...
@@ -401,13 +401,12 @@ typedef struct SStreamBlockScanInfo {
}
SStreamBlockScanInfo
;
typedef
struct
SSysTableScanInfo
{
SReadHandle
readHandle
;
SRetrieveMetaTableRsp
*
pRsp
;
SRetrieveTableReq
req
;
SEpSet
epSet
;
tsem_t
ready
;
SReadHandle
readHandle
;
int32_t
accountId
;
bool
showRewrite
;
SNode
*
pCondition
;
// db_name filter condition, to discard data that are not in current database
...
...
@@ -466,6 +465,7 @@ typedef struct SStreamFinalIntervalOperatorInfo {
SAggSupporter
aggSup
;
// aggregate supporter
int32_t
order
;
// current SSDataBlock scan order
STimeWindowAggSupp
twAggSup
;
SArray
*
pChildren
;
}
SStreamFinalIntervalOperatorInfo
;
typedef
struct
SAggOperatorInfo
{
...
...
@@ -582,6 +582,7 @@ typedef struct SStreamSessionAggOperatorInfo {
SSDataBlock
*
pDelRes
;
SHashObj
*
pStDeleted
;
void
*
pDelIterator
;
SArray
*
pChildren
;
// cache for children's result;
}
SStreamSessionAggOperatorInfo
;
typedef
struct
STimeSliceOperatorInfo
{
...
...
@@ -723,7 +724,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
STimeWindowAggSupp
*
pTwAggSupp
,
const
STableGroupInfo
*
pTableGroupInfo
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createStreamFinalIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
STimeWindowAggSupp
*
pTwAggSupp
,
const
STableGroupInfo
*
pTableGroupInfo
,
SExecTaskInfo
*
pTaskInfo
);
STimeWindowAggSupp
*
pTwAggSupp
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createStreamIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
...
...
@@ -798,7 +799,7 @@ int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimary
int32_t
startPos
,
TSKEY
ekey
,
__block_search_fn_t
searchFn
,
STableQueryInfo
*
item
,
int32_t
order
);
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
int32_t
initCa
tch
Supporter
(
SCatchSupporter
*
pCatchSup
,
size_t
rowSize
,
const
char
*
pKey
,
int32_t
initCa
che
Supporter
(
SCatchSupporter
*
pCatchSup
,
size_t
rowSize
,
const
char
*
pKey
,
const
char
*
pDir
);
int32_t
initStreamAggSupporter
(
SStreamAggSupporter
*
pSup
,
const
char
*
pKey
);
SResultRow
*
getNewResultRow_rv
(
SDiskbasedBuf
*
pResultBuf
,
int64_t
tableGroupId
,
int32_t
interBufSize
);
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
5b9422c9
...
...
@@ -124,7 +124,7 @@ static void destroySysTableScannerOperatorInfo(void* param, int32_t numOfOutput)
void
doSetOperatorCompleted
(
SOperatorInfo
*
pOperator
)
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
cost
.
totalCost
=
(
taosGetTimestampUs
()
-
pOperator
->
pTaskInfo
->
cost
.
start
*
1000
)
/
1000
.
0
;
pOperator
->
cost
.
totalCost
=
(
taosGetTimestampUs
()
-
pOperator
->
pTaskInfo
->
cost
.
start
*
1000
)
/
1000
.
0
;
if
(
pOperator
->
pTaskInfo
!=
NULL
)
{
setTaskStatus
(
pOperator
->
pTaskInfo
,
TASK_COMPLETED
);
}
...
...
@@ -2717,7 +2717,7 @@ static void* setAllSourcesCompleted(SOperatorInfo* pOperator, int64_t startTs) {
SExchangeInfo
*
pExchangeInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
int64_t
el
=
taosGetTimestampUs
()
-
startTs
;
int64_t
el
=
taosGetTimestampUs
()
-
startTs
;
SLoadRemoteDataInfo
*
pLoadInfo
=
&
pExchangeInfo
->
loadInfo
;
pLoadInfo
->
totalElapsed
+=
el
;
...
...
@@ -3023,13 +3023,13 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, const SNodeList* p
tsem_init
(
&
pInfo
->
ready
,
0
,
0
);
pOperator
->
name
=
"ExchangeOperator"
;
pOperator
->
name
=
"ExchangeOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_EXCHANGE
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
numOfExprs
=
pBlock
->
info
.
numOfCols
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
numOfExprs
=
pBlock
->
info
.
numOfCols
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
prepareLoadRemoteData
,
doLoadRemoteData
,
NULL
,
NULL
,
destroyExchangeOperatorInfo
,
NULL
,
NULL
,
NULL
);
...
...
@@ -3465,7 +3465,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
initGroupedResultInfo
(
&
pAggInfo
->
groupResInfo
,
pAggInfo
->
aggSup
.
pResultRowHashTable
,
0
);
OPTR_SET_OPENED
(
pOperator
);
pOperator
->
cost
.
openCost
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
pOperator
->
cost
.
openCost
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3490,10 +3490,10 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
doSetOperatorCompleted
(
pOperator
);
}
size_t
rows
=
blockDataGetNumOfRows
(
pInfo
->
pRes
);
//
pInfo->pRes : NULL;
size_t
rows
=
blockDataGetNumOfRows
(
pInfo
->
pRes
);
//
pInfo->pRes : NULL;
pOperator
->
resultInfo
.
totalRows
+=
rows
;
return
(
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
return
(
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
}
void
aggEncodeResultRow
(
SOperatorInfo
*
pOperator
,
SAggSupporter
*
pSup
,
SOptrBasicInfo
*
pInfo
,
char
**
result
,
...
...
@@ -3778,10 +3778,10 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
pOperator
->
resultInfo
.
totalRows
+=
rows
;
if
(
pOperator
->
cost
.
openCost
==
0
)
{
pOperator
->
cost
.
openCost
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
pOperator
->
cost
.
openCost
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
}
return
(
rows
>
0
)
?
pInfo
->
pRes
:
NULL
;
return
(
rows
>
0
)
?
pInfo
->
pRes
:
NULL
;
}
static
void
doHandleRemainBlockForNewGroupImpl
(
SFillOperatorInfo
*
pInfo
,
SResultInfo
*
pResultInfo
,
bool
*
newgroup
,
...
...
@@ -4455,15 +4455,15 @@ void extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo
pTaskInfo
->
schemaVer
.
tablename
=
strdup
(
mr
.
me
.
name
);
if
(
mr
.
me
.
type
==
TSDB_SUPER_TABLE
)
{
pTaskInfo
->
schemaVer
.
sversion
=
mr
.
me
.
stbEntry
.
schema
.
sver
;
pTaskInfo
->
schemaVer
.
tversion
=
mr
.
me
.
stbEntry
.
schemaTag
.
sver
;
pTaskInfo
->
schemaVer
.
sversion
=
mr
.
me
.
stbEntry
.
schema
Row
.
version
;
pTaskInfo
->
schemaVer
.
tversion
=
mr
.
me
.
stbEntry
.
schemaTag
.
version
;
}
else
if
(
mr
.
me
.
type
==
TSDB_CHILD_TABLE
)
{
tb_uid_t
suid
=
mr
.
me
.
ctbEntry
.
suid
;
metaGetTableEntryByUid
(
&
mr
,
suid
);
pTaskInfo
->
schemaVer
.
sversion
=
mr
.
me
.
stbEntry
.
schema
.
sver
;
pTaskInfo
->
schemaVer
.
tversion
=
mr
.
me
.
stbEntry
.
schemaTag
.
sver
;
pTaskInfo
->
schemaVer
.
sversion
=
mr
.
me
.
stbEntry
.
schema
Row
.
version
;
pTaskInfo
->
schemaVer
.
tversion
=
mr
.
me
.
stbEntry
.
schemaTag
.
version
;
}
else
{
pTaskInfo
->
schemaVer
.
sversion
=
mr
.
me
.
ntbEntry
.
schema
.
sver
;
pTaskInfo
->
schemaVer
.
sversion
=
mr
.
me
.
ntbEntry
.
schema
Row
.
version
;
}
metaReaderClear
(
&
mr
);
...
...
@@ -4668,8 +4668,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
int32_t
tsSlotId
=
((
SColumnNode
*
)
pSessionNode
->
window
.
pTspk
)
->
slotId
;
pOptr
=
createStreamSessionAggOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
pSessionNode
->
gap
,
tsSlotId
,
&
as
,
pTaskInfo
);
pOptr
=
createStreamSessionAggOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
pSessionNode
->
gap
,
tsSlotId
,
&
as
,
pTaskInfo
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_PARTITION
==
type
)
{
SPartitionPhysiNode
*
pPartNode
=
(
SPartitionPhysiNode
*
)
pPhyNode
;
...
...
@@ -5162,8 +5162,7 @@ int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SExplainExecInfo
return
TSDB_CODE_SUCCESS
;
}
int32_t
initCatchSupporter
(
SCatchSupporter
*
pCatchSup
,
size_t
rowSize
,
const
char
*
pKey
,
const
char
*
pDir
)
{
int32_t
initCacheSupporter
(
SCatchSupporter
*
pCatchSup
,
size_t
rowSize
,
const
char
*
pKey
,
const
char
*
pDir
)
{
pCatchSup
->
keySize
=
sizeof
(
int64_t
)
+
sizeof
(
int64_t
)
+
sizeof
(
TSKEY
);
pCatchSup
->
pKeyBuf
=
taosMemoryCalloc
(
1
,
pCatchSup
->
keySize
);
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
5b9422c9
此差异已折叠。
点击以展开。
source/libs/executor/src/timewindowoperator.c
浏览文件 @
5b9422c9
...
...
@@ -1067,7 +1067,8 @@ void doClearWindow(SAggSupporter* pSup, SOptrBasicInfo* pBinfo, char* pData,
}
static
void
doClearWindows
(
SAggSupporter
*
pSup
,
SOptrBasicInfo
*
pBinfo
,
SInterval
*
pIntrerval
,
int32_t
tsIndex
,
int32_t
numOfOutput
,
SSDataBlock
*
pBlock
)
{
SInterval
*
pIntrerval
,
int32_t
tsIndex
,
int32_t
numOfOutput
,
SSDataBlock
*
pBlock
,
SArray
*
pUpWins
)
{
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
tsIndex
);
TSKEY
*
tsCols
=
(
TSKEY
*
)
pColDataInfo
->
pData
;
int32_t
step
=
0
;
...
...
@@ -1079,6 +1080,9 @@ static void doClearWindows(SAggSupporter* pSup, SOptrBasicInfo* pBinfo,
step
=
getNumOfRowsInTimeWindow
(
&
pBlock
->
info
,
tsCols
,
i
,
win
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
doClearWindow
(
pSup
,
pBinfo
,
(
char
*
)
&
win
.
skey
,
sizeof
(
TKEY
),
pBlock
->
info
.
groupId
,
numOfOutput
);
if
(
pUpWins
)
{
taosArrayPush
(
pUpWins
,
&
win
);
}
}
}
...
...
@@ -1119,7 +1123,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
if
(
pBlock
->
info
.
type
==
STREAM_REPROCESS
)
{
doClearWindows
(
&
pInfo
->
aggSup
,
&
pInfo
->
binfo
,
&
pInfo
->
interval
,
0
,
pOperator
->
numOfExprs
,
pBlock
);
pOperator
->
numOfExprs
,
pBlock
,
NULL
);
qDebug
(
"%s clear existed time window results for updates checked"
,
GET_TASKID
(
pTaskInfo
));
continue
;
}
...
...
@@ -1154,6 +1158,15 @@ void destroyStreamFinalIntervalOperatorInfo(void* param, int32_t numOfOutput) {
SStreamFinalIntervalOperatorInfo
*
pInfo
=
(
SStreamFinalIntervalOperatorInfo
*
)
param
;
doDestroyBasicInfo
(
&
pInfo
->
binfo
,
numOfOutput
);
cleanupAggSup
(
&
pInfo
->
aggSup
);
if
(
pInfo
->
pChildren
)
{
int32_t
size
=
taosArrayGetSize
(
pInfo
->
pChildren
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
i
);
destroyIntervalOperatorInfo
(
pChildOp
->
info
,
numOfOutput
);
taosMemoryFreeClear
(
pChildOp
->
info
);
taosMemoryFreeClear
(
pChildOp
);
}
}
}
bool
allInvertible
(
SqlFunctionCtx
*
pFCtx
,
int32_t
numOfCols
)
{
...
...
@@ -1228,32 +1241,38 @@ _error:
SOperatorInfo
*
createStreamFinalIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
STimeWindowAggSupp
*
pTwAggSupp
,
const
STableGroupInfo
*
pTableGroupInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
STimeWindowAggSupp
*
pTwAggSupp
,
SExecTaskInfo
*
pTaskInfo
)
{
SStreamFinalIntervalOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamFinalIntervalOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
}
pInfo
->
order
=
TSDB_ORDER_ASC
;
pInfo
->
interval
=
*
pInterval
;
pInfo
->
twAggSup
=
*
pTwAggSupp
;
pInfo
->
primaryTsIndex
=
primaryTsSlotId
;
size_t
keyBufSize
=
sizeof
(
int64_t
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
;
initResultSizeInfo
(
pOperator
,
4096
);
int32_t
code
=
initAggInfo
(
&
pInfo
->
binfo
,
&
pInfo
->
aggSup
,
pExprInfo
,
numOfCols
,
pResBlock
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
initExecTimeWindowInfo
(
&
pInfo
->
twAggSup
.
timeWindowData
,
&
pTaskInfo
->
window
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
,
(
int32_t
)
1
);
int32_t
numOfChild
=
8
;
// Todo(liuyao) get it from phy plan
pInfo
->
pChildren
=
taosArrayInit
(
numOfChild
,
sizeof
(
SOperatorInfo
));
for
(
int32_t
i
=
0
;
i
<
numOfChild
;
i
++
)
{
SSDataBlock
*
chRes
=
createOneDataBlock
(
pResBlock
,
false
);
SOperatorInfo
*
pChildOp
=
createIntervalOperatorInfo
(
NULL
,
pExprInfo
,
numOfCols
,
chRes
,
pInterval
,
primaryTsSlotId
,
pTwAggSupp
,
NULL
,
pTaskInfo
);
if
(
pChildOp
&&
chRes
)
{
taosArrayPush
(
pInfo
->
pChildren
,
&
pChildOp
);
continue
;
}
goto
_error
;
}
pOperator
->
name
=
"StreamFinalIntervalOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL
;
...
...
@@ -1703,6 +1722,51 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB
return
pUpdated
;
}
bool
isFinalInterval
(
SStreamFinalIntervalOperatorInfo
*
pInfo
)
{
return
pInfo
->
pChildren
!=
NULL
;
}
void
compactFunctions
(
SqlFunctionCtx
*
pDestCtx
,
SqlFunctionCtx
*
pSourceCtx
,
int32_t
numOfOutput
,
SExecTaskInfo
*
pTaskInfo
)
{
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
if
(
fmIsWindowPseudoColumnFunc
(
pDestCtx
[
k
].
functionId
))
{
continue
;
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
functionNeedToExecute
(
&
pDestCtx
[
k
])
&&
pDestCtx
[
k
].
fpSet
.
combine
!=
NULL
)
{
code
=
pDestCtx
[
k
].
fpSet
.
combine
(
&
pDestCtx
[
k
],
&
pSourceCtx
[
k
]);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"%s apply functions error, code: %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
pTaskInfo
->
code
=
code
;
longjmp
(
pTaskInfo
->
env
,
code
);
}
}
}
}
static
void
rebuildIntervalWindow
(
SStreamFinalIntervalOperatorInfo
*
pInfo
,
SArray
*
pWinArray
,
int32_t
groupId
,
int32_t
numOfOutput
,
SExecTaskInfo
*
pTaskInfo
)
{
int32_t
size
=
taosArrayGetSize
(
pWinArray
);
ASSERT
(
pInfo
->
pChildren
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
STimeWindow
*
pParentWin
=
taosArrayGet
(
pWinArray
,
i
);
SResultRow
*
pCurResult
=
NULL
;
setTimeWindowOutputBuf
(
&
pInfo
->
binfo
.
resultRowInfo
,
pParentWin
,
true
,
&
pCurResult
,
0
,
pInfo
->
binfo
.
pCtx
,
numOfOutput
,
pInfo
->
binfo
.
rowCellInfoOffset
,
&
pInfo
->
aggSup
,
pTaskInfo
);
int32_t
numOfChildren
=
taosArrayGetSize
(
pInfo
->
pChildren
);
for
(
int32_t
j
=
0
;
j
<
numOfChildren
;
j
++
)
{
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
j
);
SIntervalAggOperatorInfo
*
pChInfo
=
pChildOp
->
info
;
SResultRow
*
pChResult
=
NULL
;
setTimeWindowOutputBuf
(
&
pChInfo
->
binfo
.
resultRowInfo
,
pParentWin
,
true
,
&
pChResult
,
0
,
pChInfo
->
binfo
.
pCtx
,
pChildOp
->
numOfExprs
,
pChInfo
->
binfo
.
rowCellInfoOffset
,
&
pChInfo
->
aggSup
,
pTaskInfo
);
compactFunctions
(
pInfo
->
binfo
.
pCtx
,
pChInfo
->
binfo
.
pCtx
,
numOfOutput
,
pTaskInfo
);
}
}
}
static
SSDataBlock
*
doStreamFinalIntervalAgg
(
SOperatorInfo
*
pOperator
)
{
SStreamFinalIntervalOperatorInfo
*
pInfo
=
pOperator
->
info
;
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
...
...
@@ -1726,10 +1790,26 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
setInputDataBlock
(
pOperator
,
pInfo
->
binfo
.
pCtx
,
pBlock
,
pInfo
->
order
,
MAIN_SCAN
,
true
);
if
(
pBlock
->
info
.
type
==
STREAM_REPROCESS
)
{
SArray
*
pUpWins
=
taosArrayInit
(
8
,
sizeof
(
STimeWindow
));
doClearWindows
(
&
pInfo
->
aggSup
,
&
pInfo
->
binfo
,
&
pInfo
->
interval
,
pInfo
->
primaryTsIndex
,
pOperator
->
numOfExprs
,
pBlock
);
pInfo
->
primaryTsIndex
,
pOperator
->
numOfExprs
,
pBlock
,
pUpWins
);
if
(
isFinalInterval
(
pInfo
))
{
int32_t
childIndex
=
0
;
//Todo(liuyao) get child id from SSDataBlock
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
SIntervalAggOperatorInfo
*
pChildInfo
=
pChildOp
->
info
;
doClearWindows
(
&
pChildInfo
->
aggSup
,
&
pChildInfo
->
binfo
,
&
pChildInfo
->
interval
,
pChildInfo
->
primaryTsIndex
,
pChildOp
->
numOfExprs
,
pBlock
,
NULL
);
rebuildIntervalWindow
(
pInfo
,
pUpWins
,
pInfo
->
binfo
.
pRes
->
info
.
groupId
,
pOperator
->
numOfExprs
,
pOperator
->
pTaskInfo
);
}
taosArrayDestroy
(
pUpWins
);
continue
;
}
if
(
isFinalInterval
(
pInfo
))
{
int32_t
chIndex
=
1
;
//Todo(liuyao) get it from SSDataBlock
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
chIndex
);
doStreamIntervalAgg
(
pChildOp
);
}
pUpdated
=
doHashInterval
(
pOperator
,
pBlock
,
0
);
}
...
...
@@ -1752,6 +1832,16 @@ void destroyStreamSessionAggOperatorInfo(void* param, int32_t numOfOutput) {
doDestroyBasicInfo
(
&
pInfo
->
binfo
,
numOfOutput
);
destroyStreamAggSupporter
(
&
pInfo
->
streamAggSup
);
cleanupGroupResInfo
(
&
pInfo
->
groupResInfo
);
if
(
pInfo
->
pChildren
!=
NULL
)
{
int32_t
size
=
taosArrayGetSize
(
pInfo
->
pChildren
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
SOperatorInfo
*
pChild
=
taosArrayGetP
(
pInfo
->
pChildren
,
i
);
SStreamSessionAggOperatorInfo
*
pChInfo
=
pChild
->
info
;
destroyStreamSessionAggOperatorInfo
(
pChInfo
,
numOfOutput
);
taosMemoryFreeClear
(
pChild
);
taosMemoryFreeClear
(
pChInfo
);
}
}
}
int32_t
initBiasicInfo
(
SOptrBasicInfo
*
pBasicInfo
,
SExprInfo
*
pExprInfo
,
...
...
@@ -1780,6 +1870,7 @@ void initDownStream(SOperatorInfo* downstream, SStreamSessionAggOperatorInfo* pI
SOperatorInfo
*
createStreamSessionAggOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
int64_t
gap
,
int32_t
tsSlotId
,
STimeWindowAggSupp
*
pTwAggSupp
,
SExecTaskInfo
*
pTaskInfo
)
{
int32_t
code
=
TSDB_CODE_OUT_OF_MEMORY
;
SStreamSessionAggOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamSessionAggOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
...
...
@@ -1789,7 +1880,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream,
initResultSizeInfo
(
pOperator
,
4096
);
int32_t
code
=
initStreamAggSupporter
(
&
pInfo
->
streamAggSup
,
"StreamSessionAggOperatorInfo"
);
code
=
initStreamAggSupporter
(
&
pInfo
->
streamAggSup
,
"StreamSessionAggOperatorInfo"
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -1820,6 +1911,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream,
pInfo
->
pDelIterator
=
NULL
;
pInfo
->
pDelRes
=
createOneDataBlock
(
pResBlock
,
false
);
blockDataEnsureCapacity
(
pInfo
->
pDelRes
,
64
);
pInfo
->
pChildren
=
NULL
;
pOperator
->
name
=
"StreamSessionWindowAggOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW
;
...
...
@@ -2068,24 +2160,6 @@ int32_t getNumCompactWindow(SArray* pWinInfos, int32_t startIndex, int64_t gap)
return
size
-
startIndex
-
1
;
}
void
compactFunctions
(
SqlFunctionCtx
*
pDestCtx
,
SqlFunctionCtx
*
pSourceCtx
,
int32_t
numOfOutput
,
SExecTaskInfo
*
pTaskInfo
)
{
for
(
int32_t
k
=
0
;
k
<
numOfOutput
;
++
k
)
{
if
(
fmIsWindowPseudoColumnFunc
(
pDestCtx
[
k
].
functionId
))
{
continue
;
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
functionNeedToExecute
(
&
pDestCtx
[
k
])
&&
pDestCtx
[
k
].
fpSet
.
combine
!=
NULL
)
{
code
=
pDestCtx
[
k
].
fpSet
.
combine
(
&
pDestCtx
[
k
],
&
pSourceCtx
[
k
]);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"%s apply functions error, code: %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
pTaskInfo
->
code
=
code
;
longjmp
(
pTaskInfo
->
env
,
code
);
}
}
}
}
void
compactTimeWindow
(
SStreamSessionAggOperatorInfo
*
pInfo
,
int32_t
startIndex
,
int32_t
num
,
int32_t
groupId
,
int32_t
numOfOutput
,
SExecTaskInfo
*
pTaskInfo
,
SHashObj
*
pStUpdated
,
SHashObj
*
pStDeleted
)
{
SResultWindowInfo
*
pCurWin
=
taosArrayGet
(
pInfo
->
streamAggSup
.
pResultRows
,
startIndex
);
...
...
@@ -2164,7 +2238,7 @@ static void doStreamSessionWindowAggImpl(SOperatorInfo* pOperator,
}
static
void
doClearSessionWindows
(
SStreamAggSupporter
*
pAggSup
,
SOptrBasicInfo
*
pBinfo
,
SSDataBlock
*
pBlock
,
int32_t
tsIndex
,
int32_t
numOfOutput
,
int64_t
gap
)
{
SSDataBlock
*
pBlock
,
int32_t
tsIndex
,
int32_t
numOfOutput
,
int64_t
gap
,
SArray
*
result
)
{
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
tsIndex
);
TSKEY
*
tsCols
=
(
TSKEY
*
)
pColDataInfo
->
pData
;
int32_t
step
=
0
;
...
...
@@ -2173,7 +2247,11 @@ static void doClearSessionWindows(SStreamAggSupporter* pAggSup, SOptrBasicInfo*
SResultWindowInfo
*
pCurWin
=
getSessionTimeWindow
(
pAggSup
->
pResultRows
,
tsCols
[
i
],
gap
,
&
winIndex
);
step
=
updateSessionWindowInfo
(
pCurWin
,
tsCols
,
pBlock
->
info
.
rows
,
i
,
gap
,
NULL
);
ASSERT
(
isInWindow
(
pCurWin
,
tsCols
[
i
],
gap
));
doClearWindowImpl
(
&
pCurWin
->
pos
,
pAggSup
->
pResultBuf
,
pBinfo
,
numOfOutput
);
if
(
result
)
{
taosArrayPush
(
result
,
pCurWin
);
}
}
}
...
...
@@ -2215,6 +2293,42 @@ void doBuildDeleteDataBlock(SHashObj* pStDeleted, SSDataBlock* pBlock, void** It
}
}
static
void
rebuildTimeWindow
(
SStreamSessionAggOperatorInfo
*
pInfo
,
SArray
*
pWinArray
,
int32_t
groupId
,
int32_t
numOfOutput
,
SExecTaskInfo
*
pTaskInfo
)
{
int32_t
size
=
taosArrayGetSize
(
pWinArray
);
ASSERT
(
pInfo
->
pChildren
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
SResultWindowInfo
*
pParentWin
=
taosArrayGet
(
pWinArray
,
i
);
SResultRow
*
pCurResult
=
NULL
;
setWindowOutputBuf
(
pParentWin
,
&
pCurResult
,
pInfo
->
binfo
.
pCtx
,
groupId
,
numOfOutput
,
pInfo
->
binfo
.
rowCellInfoOffset
,
&
pInfo
->
streamAggSup
,
pTaskInfo
);
int32_t
numOfChildren
=
taosArrayGetSize
(
pInfo
->
pChildren
);
for
(
int32_t
j
=
0
;
j
<
numOfChildren
;
j
++
)
{
SOperatorInfo
*
pChild
=
taosArrayGetP
(
pInfo
->
pChildren
,
j
);
SStreamSessionAggOperatorInfo
*
pChInfo
=
pChild
->
info
;
SArray
*
pChWins
=
pChInfo
->
streamAggSup
.
pResultRows
;
int32_t
chWinSize
=
taosArrayGetSize
(
pChWins
);
int32_t
index
=
binarySearch
(
pChWins
,
chWinSize
,
pParentWin
->
win
.
skey
,
TSDB_ORDER_DESC
,
getSessionWindowEndkey
);
for
(
int32_t
k
=
index
;
k
>
0
&&
k
<
chWinSize
;
k
++
)
{
SResultWindowInfo
*
pcw
=
taosArrayGet
(
pChWins
,
k
);
if
(
pParentWin
->
win
.
skey
<=
pcw
->
win
.
skey
&&
pcw
->
win
.
ekey
<=
pParentWin
->
win
.
ekey
)
{
SResultRow
*
pChResult
=
NULL
;
setWindowOutputBuf
(
pcw
,
&
pChResult
,
pChInfo
->
binfo
.
pCtx
,
groupId
,
numOfOutput
,
pChInfo
->
binfo
.
rowCellInfoOffset
,
&
pChInfo
->
streamAggSup
,
pTaskInfo
);
compactFunctions
(
pInfo
->
binfo
.
pCtx
,
pChInfo
->
binfo
.
pCtx
,
numOfOutput
,
pTaskInfo
);
continue
;
}
break
;
}
}
}
}
bool
isFinalSession
(
SStreamSessionAggOperatorInfo
*
pInfo
)
{
return
pInfo
->
pChildren
!=
NULL
;
}
static
SSDataBlock
*
doStreamSessionWindowAgg
(
SOperatorInfo
*
pOperator
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
...
...
@@ -2247,10 +2361,25 @@ static SSDataBlock* doStreamSessionWindowAgg(SOperatorInfo* pOperator) {
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pBInfo
->
pCtx
,
pBlock
,
TSDB_ORDER_ASC
,
MAIN_SCAN
,
true
);
if
(
pBlock
->
info
.
type
==
STREAM_REPROCESS
)
{
SArray
*
pWins
=
taosArrayInit
(
16
,
sizeof
(
SResultWindowInfo
));
doClearSessionWindows
(
&
pInfo
->
streamAggSup
,
&
pInfo
->
binfo
,
pBlock
,
0
,
pOperator
->
numOfExprs
,
pInfo
->
gap
);
pOperator
->
numOfExprs
,
pInfo
->
gap
,
pWins
);
if
(
isFinalSession
(
pInfo
))
{
int32_t
childIndex
=
0
;
//Todo(liuyao) get child id from SSDataBlock
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
SStreamSessionAggOperatorInfo
*
pChildInfo
=
pChildOp
->
info
;
doClearSessionWindows
(
&
pChildInfo
->
streamAggSup
,
&
pChildInfo
->
binfo
,
pBlock
,
0
,
pChildOp
->
numOfExprs
,
pChildInfo
->
gap
,
NULL
);
rebuildTimeWindow
(
pInfo
,
pWins
,
pInfo
->
binfo
.
pRes
->
info
.
groupId
,
pOperator
->
numOfExprs
,
pOperator
->
pTaskInfo
);
}
taosArrayDestroy
(
pWins
);
continue
;
}
if
(
isFinalSession
(
pInfo
))
{
int32_t
childIndex
=
0
;
//Todo(liuyao) get child id from SSDataBlock
SOptrBasicInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
doStreamSessionWindowAggImpl
(
pOperator
,
pBlock
,
NULL
,
NULL
);
}
doStreamSessionWindowAggImpl
(
pOperator
,
pBlock
,
pStUpdated
,
pInfo
->
pStDeleted
);
}
...
...
@@ -2271,3 +2400,39 @@ static SSDataBlock* doStreamSessionWindowAgg(SOperatorInfo* pOperator) {
pInfo
->
streamAggSup
.
pResultBuf
);
return
pBInfo
->
pRes
->
info
.
rows
==
0
?
NULL
:
pBInfo
->
pRes
;
}
SOperatorInfo
*
createStreamFinalSessionAggOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
int64_t
gap
,
int32_t
tsSlotId
,
STimeWindowAggSupp
*
pTwAggSupp
,
SExecTaskInfo
*
pTaskInfo
)
{
int32_t
code
=
TSDB_CODE_OUT_OF_MEMORY
;
SStreamSessionAggOperatorInfo
*
pInfo
=
NULL
;
SOperatorInfo
*
pOperator
=
createStreamSessionAggOperatorInfo
(
downstream
,
pExprInfo
,
numOfCols
,
pResBlock
,
gap
,
tsSlotId
,
pTwAggSupp
,
pTaskInfo
);
if
(
pOperator
==
NULL
)
{
goto
_error
;
}
pOperator
->
name
=
"StreamFinalSessionWindowAggOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION_WINDOW
;
int32_t
numOfChild
=
1
;
//Todo(liuyao) get it from phy plan
pInfo
=
pOperator
->
info
;
pInfo
->
pChildren
=
taosArrayInit
(
8
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
numOfChild
;
i
++
)
{
SOperatorInfo
*
pChild
=
createStreamSessionAggOperatorInfo
(
NULL
,
pExprInfo
,
numOfCols
,
NULL
,
gap
,
tsSlotId
,
pTwAggSupp
,
pTaskInfo
);
if
(
pChild
==
NULL
)
{
goto
_error
;
}
taosArrayPush
(
pInfo
->
pChildren
,
&
pChild
);
}
return
pOperator
;
_error:
if
(
pInfo
!=
NULL
)
{
destroyStreamSessionAggOperatorInfo
(
pInfo
,
numOfCols
);
}
taosMemoryFreeClear
(
pInfo
);
taosMemoryFreeClear
(
pOperator
);
pTaskInfo
->
code
=
code
;
return
NULL
;
}
source/libs/function/inc/builtinsimpl.h
浏览文件 @
5b9422c9
...
...
@@ -73,6 +73,11 @@ bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultI
int32_t
percentileFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
percentileFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getApercentileFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
apercentileFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
apercentileFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
apercentileFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getDiffFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
diffFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResInfo
);
int32_t
diffFunction
(
SqlFunctionCtx
*
pCtx
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
5b9422c9
...
...
@@ -998,10 +998,10 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
type
=
FUNCTION_TYPE_APERCENTILE
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateApercentile
,
.
getEnvFunc
=
get
Minmax
FuncEnv
,
.
initFunc
=
minmax
FunctionSetup
,
.
processFunc
=
max
Function
,
.
finalizeFunc
=
function
Finalize
.
getEnvFunc
=
get
Apercentile
FuncEnv
,
.
initFunc
=
apercentile
FunctionSetup
,
.
processFunc
=
apercentile
Function
,
.
finalizeFunc
=
apercentile
Finalize
},
{
.
name
=
"top"
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
5b9422c9
...
...
@@ -20,6 +20,8 @@
#include "taggfunction.h"
#include "tcompare.h"
#include "tdatablock.h"
#include "tdigest.h"
#include "thistogram.h"
#include "tpercentile.h"
#define HISTOGRAM_MAX_BINS_NUM 1000
...
...
@@ -95,6 +97,19 @@ typedef struct SPercentileInfo {
int64_t
numOfElems
;
}
SPercentileInfo
;
typedef
struct
SAPercentileInfo
{
double
result
;
int8_t
algo
;
SHistogramInfo
*
pHisto
;
TDigest
*
pTDigest
;
}
SAPercentileInfo
;
typedef
enum
{
APERCT_ALGO_UNKNOWN
=
0
,
APERCT_ALGO_DEFAULT
,
APERCT_ALGO_TDIGEST
,
}
EAPerctAlgoType
;
typedef
struct
SDiffInfo
{
bool
hasPrev
;
bool
includeNull
;
...
...
@@ -1905,6 +1920,131 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
functionFinalize
(
pCtx
,
pBlock
);
}
bool
getApercentileFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
int32_t
bytesHist
=
(
int32_t
)(
sizeof
(
SAPercentileInfo
)
+
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
(
MAX_HISTOGRAM_BIN
+
1
));
int32_t
bytesDigest
=
(
int32_t
)(
sizeof
(
SAPercentileInfo
)
+
TDIGEST_SIZE
(
COMPRESSION
));
pEnv
->
calcMemSize
=
TMAX
(
bytesHist
,
bytesDigest
);
return
true
;
}
static
int8_t
getApercentileAlgo
(
char
*
algoStr
)
{
int8_t
algoType
;
if
(
strcasecmp
(
algoStr
,
"default"
)
==
0
)
{
algoType
=
APERCT_ALGO_DEFAULT
;
}
else
if
(
strcasecmp
(
algoStr
,
"t-digest"
)
==
0
)
{
algoType
=
APERCT_ALGO_TDIGEST
;
}
else
{
algoType
=
APERCT_ALGO_UNKNOWN
;
}
return
algoType
;
}
static
void
buildHistogramInfo
(
SAPercentileInfo
*
pInfo
)
{
pInfo
->
pHisto
=
(
SHistogramInfo
*
)
((
char
*
)
pInfo
+
sizeof
(
SAPercentileInfo
));
pInfo
->
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pInfo
->
pHisto
+
sizeof
(
SHistogramInfo
));
}
bool
apercentileFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
return
false
;
}
SAPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResultInfo
);
if
(
pCtx
->
numOfParams
==
2
)
{
pInfo
->
algo
=
APERCT_ALGO_DEFAULT
;
}
else
if
(
pCtx
->
numOfParams
==
3
)
{
pInfo
->
algo
=
getApercentileAlgo
(
pCtx
->
param
[
2
].
param
.
pz
);
if
(
pInfo
->
algo
==
APERCT_ALGO_UNKNOWN
)
{
return
false
;
}
}
char
*
tmp
=
(
char
*
)
pInfo
+
sizeof
(
SAPercentileInfo
);
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
pInfo
->
pTDigest
=
tdigestNewFrom
(
tmp
,
COMPRESSION
);
}
else
{
buildHistogramInfo
(
pInfo
);
pInfo
->
pHisto
=
tHistogramCreateFrom
(
tmp
,
MAX_HISTOGRAM_BIN
);
}
return
true
;
}
int32_t
apercentileFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
notNullElems
=
0
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
//SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
int32_t
type
=
pCol
->
info
.
type
;
SAPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
start
=
pInput
->
startRowIndex
;
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
for
(
int32_t
i
=
start
;
i
<
pInput
->
numOfRows
+
start
;
++
i
)
{
if
(
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
notNullElems
+=
1
;
char
*
data
=
colDataGetData
(
pCol
,
i
);
double
v
=
0
;
// value
int64_t
w
=
1
;
// weigth
GET_TYPED_DATA
(
v
,
double
,
type
,
data
);
tdigestAdd
(
pInfo
->
pTDigest
,
v
,
w
);
}
}
else
{
for
(
int32_t
i
=
start
;
i
<
pInput
->
numOfRows
+
start
;
++
i
)
{
if
(
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
notNullElems
+=
1
;
char
*
data
=
colDataGetData
(
pCol
,
i
);
double
v
=
0
;
GET_TYPED_DATA
(
v
,
double
,
type
,
data
);
tHistogramAdd
(
&
pInfo
->
pHisto
,
v
);
}
}
SET_VAL
(
pResInfo
,
notNullElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
apercentileFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SVariant
*
pVal
=
&
pCtx
->
param
[
1
].
param
;
double
percent
=
(
pVal
->
nType
==
TSDB_DATA_TYPE_BIGINT
)
?
pVal
->
i
:
pVal
->
d
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SAPercentileInfo
*
pInfo
=
(
SAPercentileInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
if
(
pInfo
->
pTDigest
->
size
>
0
)
{
pInfo
->
result
=
tdigestQuantile
(
pInfo
->
pTDigest
,
percent
/
100
);
}
else
{
// no need to free
//setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
return
TSDB_CODE_SUCCESS
;
}
}
else
{
if
(
pInfo
->
pHisto
->
numOfElems
>
0
)
{
double
ratio
[]
=
{
percent
};
double
*
res
=
tHistogramUniform
(
pInfo
->
pHisto
,
ratio
,
1
);
pInfo
->
result
=
*
res
;
//memcpy(pCtx->pOutput, res, sizeof(double));
taosMemoryFree
(
res
);
}
else
{
// no need to free
//setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
return
TSDB_CODE_SUCCESS
;
}
}
return
functionFinalize
(
pCtx
,
pBlock
);
}
bool
getFirstLastFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
SColumnNode
*
pNode
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
pEnv
->
calcMemSize
=
pNode
->
node
.
resType
.
bytes
+
sizeof
(
int64_t
);
...
...
@@ -1917,8 +2057,6 @@ bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
return
true
;
}
static
FORCE_INLINE
TSKEY
getRowPTs
(
SColumnInfoData
*
pTsColInfo
,
int32_t
rowIndex
)
{
if
(
pTsColInfo
==
NULL
)
{
return
0
;
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
5b9422c9
...
...
@@ -46,8 +46,9 @@ typedef struct SFullDatabaseName {
char
fullDbName
[
TSDB_DB_FNAME_LEN
];
}
SFullDatabaseName
;
static
int32_t
translateSubquery
(
STranslateContext
*
pCxt
,
SNode
*
pNode
);
static
int32_t
translateQuery
(
STranslateContext
*
pCxt
,
SNode
*
pNode
);
static
int32_t
translateSubquery
(
STranslateContext
*
pCxt
,
SNode
*
pNode
);
static
int32_t
translateQuery
(
STranslateContext
*
pCxt
,
SNode
*
pNode
);
static
EDealRes
translateValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
);
static
bool
afterGroupBy
(
ESqlClause
clause
)
{
return
clause
>
SQL_CLAUSE_GROUP_BY
;
}
...
...
@@ -542,17 +543,18 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
return
res
;
}
static
int32_t
parseTimeFromValueNode
(
SValueNode
*
pVal
)
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
TSDB_CODE_SUCCESS
;
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
datum
.
i
=
pVal
->
datum
.
u
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
IS_FLOAT_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
datum
.
i
=
pVal
->
datum
.
d
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
TSDB_DATA_TYPE_BOOL
==
pVal
->
node
.
resType
.
type
)
{
pVal
->
datum
.
i
=
pVal
->
datum
.
b
;
static
int32_t
parseTimeFromValueNode
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
)
{
if
(
IS_NUMERIC_TYPE
(
pVal
->
node
.
resType
.
type
)
||
TSDB_DATA_TYPE_BOOL
==
pVal
->
node
.
resType
.
type
)
{
if
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
pVal
))
{
return
pCxt
->
errCode
;
}
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
datum
.
i
=
pVal
->
datum
.
u
;
}
else
if
(
IS_FLOAT_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
datum
.
i
=
pVal
->
datum
.
d
;
}
else
if
(
TSDB_DATA_TYPE_BOOL
==
pVal
->
node
.
resType
.
type
)
{
pVal
->
datum
.
i
=
pVal
->
datum
.
b
;
}
return
TSDB_CODE_SUCCESS
;
}
else
if
(
IS_VAR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
)
||
TSDB_DATA_TYPE_TIMESTAMP
==
pVal
->
node
.
resType
.
type
)
{
if
(
TSDB_CODE_SUCCESS
==
taosParseTime
(
pVal
->
literal
,
&
pVal
->
datum
.
i
,
pVal
->
node
.
resType
.
bytes
,
...
...
@@ -588,62 +590,52 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
*
(
bool
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
b
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int8_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int16_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int32_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint8_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint16_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint32_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
&
endPtr
,
10
);
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
&
endPtr
);
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
NULL
);
*
(
float
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
d
;
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
char
*
endPtr
=
NULL
;
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
&
endPtr
);
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
NULL
);
*
(
double
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
d
;
break
;
}
...
...
@@ -659,7 +651,7 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
TSDB_CODE_SUCCESS
!=
parseTimeFromValueNode
(
pVal
))
{
if
(
TSDB_CODE_SUCCESS
!=
parseTimeFromValueNode
(
p
Cxt
,
p
Val
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
...
...
@@ -2799,6 +2791,7 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
int32_t
code
=
getDBCfg
(
pCxt
,
pStmt
->
dbName
,
&
dbCfg
);
int32_t
num
=
taosArrayGetSize
(
dbCfg
.
pRetensions
);
if
(
TSDB_CODE_SUCCESS
!=
code
||
num
<
2
)
{
taosArrayDestroy
(
dbCfg
.
pRetensions
);
return
code
;
}
for
(
int32_t
i
=
1
;
i
<
num
;
++
i
)
{
...
...
@@ -3951,7 +3944,7 @@ typedef struct SVgroupCreateTableBatch {
static
void
destroyCreateTbReq
(
SVCreateTbReq
*
pReq
)
{
taosMemoryFreeClear
(
pReq
->
name
);
taosMemoryFreeClear
(
pReq
->
ntb
.
schema
.
pSchema
);
taosMemoryFreeClear
(
pReq
->
ntb
.
schema
Row
.
pSchema
);
}
static
int32_t
buildNormalTableBatchReq
(
int32_t
acctId
,
const
SCreateTableStmt
*
pStmt
,
const
SVgroupInfo
*
pVgroupInfo
,
...
...
@@ -3964,10 +3957,10 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
SVCreateTbReq
req
=
{
0
};
req
.
type
=
TD_NORMAL_TABLE
;
req
.
name
=
strdup
(
pStmt
->
tableName
);
req
.
ntb
.
schema
.
nCols
=
LIST_LENGTH
(
pStmt
->
pCols
);
req
.
ntb
.
schema
.
sver
=
1
;
req
.
ntb
.
schema
.
pSchema
=
taosMemoryCalloc
(
req
.
ntb
.
schema
.
nCols
,
sizeof
(
SSchema
));
if
(
NULL
==
req
.
name
||
NULL
==
req
.
ntb
.
schema
.
pSchema
)
{
req
.
ntb
.
schema
Row
.
nCols
=
LIST_LENGTH
(
pStmt
->
pCols
);
req
.
ntb
.
schema
Row
.
version
=
1
;
req
.
ntb
.
schema
Row
.
pSchema
=
taosMemoryCalloc
(
req
.
ntb
.
schemaRow
.
nCols
,
sizeof
(
SSchema
));
if
(
NULL
==
req
.
name
||
NULL
==
req
.
ntb
.
schema
Row
.
pSchema
)
{
destroyCreateTbReq
(
&
req
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -3977,7 +3970,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
SNode
*
pCol
;
col_id_t
index
=
0
;
FOREACH
(
pCol
,
pStmt
->
pCols
)
{
toSchema
((
SColumnDefNode
*
)
pCol
,
index
+
1
,
req
.
ntb
.
schema
.
pSchema
+
index
);
toSchema
((
SColumnDefNode
*
)
pCol
,
index
+
1
,
req
.
ntb
.
schema
Row
.
pSchema
+
index
);
++
index
;
}
pBatch
->
info
=
*
pVgroupInfo
;
...
...
@@ -4031,7 +4024,7 @@ static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) {
taosMemoryFreeClear
(
pTableReq
->
name
);
if
(
pTableReq
->
type
==
TSDB_NORMAL_TABLE
)
{
taosMemoryFreeClear
(
pTableReq
->
ntb
.
schema
.
pSchema
);
taosMemoryFreeClear
(
pTableReq
->
ntb
.
schema
Row
.
pSchema
);
}
else
if
(
pTableReq
->
type
==
TSDB_CHILD_TABLE
)
{
taosMemoryFreeClear
(
pTableReq
->
ctb
.
pTag
);
}
...
...
source/libs/parser/src/parser.c
浏览文件 @
5b9422c9
...
...
@@ -19,7 +19,7 @@
#include "parInt.h"
#include "parToken.h"
bool
i
sInsertSql
(
const
char
*
pStr
,
size_t
length
)
{
bool
qI
sInsertSql
(
const
char
*
pStr
,
size_t
length
)
{
if
(
NULL
==
pStr
)
{
return
false
;
}
...
...
@@ -169,7 +169,7 @@ static void rewriteExprAlias(SNode* pRoot) {
int32_t
qParseSql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
i
sInsertSql
(
pCxt
->
pSql
,
pCxt
->
sqlLen
))
{
if
(
qI
sInsertSql
(
pCxt
->
pSql
,
pCxt
->
sqlLen
))
{
code
=
parseInsertSql
(
pCxt
,
pQuery
);
}
else
{
code
=
parseSqlIntoAst
(
pCxt
,
pQuery
);
...
...
@@ -184,6 +184,18 @@ int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** p
return
extractResultSchema
(
pRoot
,
numOfCols
,
pSchema
);
}
int32_t
qSetSTableIdForRSma
(
SNode
*
pStmt
,
int64_t
uid
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
SNode
*
pTable
=
((
SSelectStmt
*
)
pStmt
)
->
pFromTable
;
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
((
SRealTableNode
*
)
pTable
)
->
pMeta
->
uid
=
uid
;
((
SRealTableNode
*
)
pTable
)
->
pMeta
->
suid
=
uid
;
return
TSDB_CODE_SUCCESS
;
}
}
return
TSDB_CODE_FAILED
;
}
int32_t
qStmtBindParams
(
SQuery
*
pQuery
,
TAOS_MULTI_BIND
*
pParams
,
int32_t
colIdx
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
source/libs/scheduler/src/schDbg.c
0 → 100644
浏览文件 @
5b9422c9
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "query.h"
#include "schedulerInt.h"
tsem_t
schdRspSem
;
void
schdExecCallback
(
SQueryResult
*
pResult
,
void
*
param
,
int32_t
code
)
{
if
(
code
)
{
pResult
->
code
=
code
;
}
*
(
SQueryResult
*
)
param
=
*
pResult
;
taosMemoryFree
(
pResult
);
tsem_post
(
&
schdRspSem
);
}
void
schdFetchCallback
(
void
*
pResult
,
void
*
param
,
int32_t
code
)
{
SSchdFetchParam
*
fParam
=
(
SSchdFetchParam
*
)
param
;
*
fParam
->
pData
=
pResult
;
*
fParam
->
code
=
code
;
tsem_post
(
&
schdRspSem
);
}
source/libs/scheduler/src/schJob.c
浏览文件 @
5b9422c9
...
...
@@ -856,7 +856,12 @@ _return:
void
schProcessOnDataFetched
(
SSchJob
*
job
)
{
atomic_val_compare_exchange_32
(
&
job
->
remoteFetch
,
1
,
0
);
tsem_post
(
&
job
->
rspSem
);
if
(
job
->
attr
.
syncSchedule
)
{
tsem_post
(
&
job
->
rspSem
);
}
else
if
(
SCH_FETCH_CB
==
atomic_val_compare_exchange_32
(
&
job
->
userCb
,
SCH_FETCH_CB
,
0
))
{
schNotifyUserFetchRes
(
job
);
}
}
// Note: no more task error processing, handled in function internal
...
...
source/libs/scheduler/src/schUtil.c
浏览文件 @
5b9422c9
...
...
@@ -66,6 +66,7 @@ void schFreeRpcCtxVal(const void *arg) {
SMsgSendInfo
*
pMsgSendInfo
=
(
SMsgSendInfo
*
)
arg
;
taosMemoryFreeClear
(
pMsgSendInfo
->
param
);
taosMemoryFreeClear
(
pMsgSendInfo
->
msgInfo
.
pData
);
taosMemoryFreeClear
(
pMsgSendInfo
);
}
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
5b9422c9
...
...
@@ -124,7 +124,7 @@ int32_t schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* pa
pJob
->
userRes
.
fetchFp
=
fp
;
pJob
->
userRes
.
userParam
=
param
;
code
=
schFetchRows
(
pJob
);
code
=
sch
Async
FetchRows
(
pJob
);
schReleaseJob
(
job
);
...
...
source/util/src/tdigest.c
0 → 100644
浏览文件 @
5b9422c9
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* src/tdigest.c
*
* Implementation of the t-digest data structure used to compute accurate percentiles.
*
* It is based on the MergingDigest implementation found at:
* https://github.com/tdunning/t-digest/blob/master/src/main/java/com/tdunning/math/stats/MergingDigest.java
*
* Copyright (c) 2016, Usman Masood <usmanm at fastmail dot fm>
*/
#include "os.h"
#include "osMath.h"
#include "tdigest.h"
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (double)(q) - 1)/M_PI + (double)1/2))
#define FLOAT_EQ(f1, f2) (fabs((f1) - (f2)) <= FLT_EPSILON)
typedef
struct
SMergeArgs
{
TDigest
*
t
;
SCentroid
*
centroids
;
int32_t
idx
;
double
weight_so_far
;
double
k1
;
double
min
;
double
max
;
}
SMergeArgs
;
void
tdigestAutoFill
(
TDigest
*
t
,
int32_t
compression
)
{
t
->
centroids
=
(
SCentroid
*
)((
char
*
)
t
+
sizeof
(
TDigest
));
t
->
buffered_pts
=
(
SPt
*
)
((
char
*
)
t
+
sizeof
(
TDigest
)
+
sizeof
(
SCentroid
)
*
(
int32_t
)
GET_CENTROID
(
compression
));
}
TDigest
*
tdigestNewFrom
(
void
*
pBuf
,
int32_t
compression
)
{
memset
(
pBuf
,
0
,
(
size_t
)
TDIGEST_SIZE
(
compression
));
TDigest
*
t
=
(
TDigest
*
)
pBuf
;
tdigestAutoFill
(
t
,
compression
);
t
->
compression
=
compression
;
t
->
size
=
(
int64_t
)
GET_CENTROID
(
compression
);
t
->
threshold
=
(
int32_t
)
GET_THRESHOLD
(
compression
);
t
->
min
=
DOUBLE_MAX
;
t
->
max
=
-
DOUBLE_MAX
;
return
t
;
}
static
int32_t
cmpCentroid
(
const
void
*
a
,
const
void
*
b
)
{
SCentroid
*
c1
=
(
SCentroid
*
)
a
;
SCentroid
*
c2
=
(
SCentroid
*
)
b
;
if
(
c1
->
mean
<
c2
->
mean
)
return
-
1
;
if
(
c1
->
mean
>
c2
->
mean
)
return
1
;
return
0
;
}
static
void
mergeCentroid
(
SMergeArgs
*
args
,
SCentroid
*
merge
)
{
double
k2
;
SCentroid
*
c
=
&
args
->
centroids
[
args
->
idx
];
args
->
weight_so_far
+=
merge
->
weight
;
k2
=
INTEGRATED_LOCATION
(
args
->
t
->
size
,
args
->
weight_so_far
/
args
->
t
->
total_weight
);
//idx++
if
(
k2
-
args
->
k1
>
1
&&
c
->
weight
>
0
)
{
if
(
args
->
idx
+
1
<
args
->
t
->
size
&&
merge
->
mean
!=
args
->
centroids
[
args
->
idx
].
mean
)
{
args
->
idx
++
;
}
args
->
k1
=
k2
;
}
c
=
&
args
->
centroids
[
args
->
idx
];
if
(
c
->
mean
==
merge
->
mean
)
{
c
->
weight
+=
merge
->
weight
;
}
else
{
c
->
weight
+=
merge
->
weight
;
c
->
mean
+=
(
merge
->
mean
-
c
->
mean
)
*
merge
->
weight
/
c
->
weight
;
if
(
merge
->
weight
>
0
)
{
args
->
min
=
TMIN
(
merge
->
mean
,
args
->
min
);
args
->
max
=
TMAX
(
merge
->
mean
,
args
->
max
);
}
}
}
void
tdigestCompress
(
TDigest
*
t
)
{
SCentroid
*
unmerged_centroids
;
int64_t
unmerged_weight
=
0
;
int32_t
num_unmerged
=
t
->
num_buffered_pts
;
int32_t
i
,
j
;
SMergeArgs
args
;
if
(
t
->
num_buffered_pts
<=
0
)
return
;
unmerged_centroids
=
(
SCentroid
*
)
taosMemoryMalloc
(
sizeof
(
SCentroid
)
*
t
->
num_buffered_pts
);
for
(
i
=
0
;
i
<
num_unmerged
;
i
++
)
{
SPt
*
p
=
t
->
buffered_pts
+
i
;
SCentroid
*
c
=
&
unmerged_centroids
[
i
];
c
->
mean
=
p
->
value
;
c
->
weight
=
p
->
weight
;
unmerged_weight
+=
c
->
weight
;
}
t
->
num_buffered_pts
=
0
;
t
->
total_weight
+=
unmerged_weight
;
qsort
(
unmerged_centroids
,
num_unmerged
,
sizeof
(
SCentroid
),
cmpCentroid
);
memset
(
&
args
,
0
,
sizeof
(
SMergeArgs
));
args
.
centroids
=
(
SCentroid
*
)
taosMemoryMalloc
((
size_t
)(
sizeof
(
SCentroid
)
*
t
->
size
));
memset
(
args
.
centroids
,
0
,
(
size_t
)(
sizeof
(
SCentroid
)
*
t
->
size
));
args
.
t
=
t
;
args
.
min
=
DOUBLE_MAX
;
args
.
max
=
-
DOUBLE_MAX
;
i
=
0
;
j
=
0
;
while
(
i
<
num_unmerged
&&
j
<
t
->
num_centroids
)
{
SCentroid
*
a
=
&
unmerged_centroids
[
i
];
SCentroid
*
b
=
&
t
->
centroids
[
j
];
if
(
a
->
mean
<=
b
->
mean
)
{
mergeCentroid
(
&
args
,
a
);
assert
(
args
.
idx
<
t
->
size
);
i
++
;
}
else
{
mergeCentroid
(
&
args
,
b
);
assert
(
args
.
idx
<
t
->
size
);
j
++
;
}
}
while
(
i
<
num_unmerged
)
{
mergeCentroid
(
&
args
,
&
unmerged_centroids
[
i
++
]);
assert
(
args
.
idx
<
t
->
size
);
}
taosMemoryFree
((
void
*
)
unmerged_centroids
);
while
(
j
<
t
->
num_centroids
)
{
mergeCentroid
(
&
args
,
&
t
->
centroids
[
j
++
]);
assert
(
args
.
idx
<
t
->
size
);
}
if
(
t
->
total_weight
>
0
)
{
t
->
min
=
TMIN
(
t
->
min
,
args
.
min
);
if
(
args
.
centroids
[
args
.
idx
].
weight
<=
0
)
{
args
.
idx
--
;
}
t
->
num_centroids
=
args
.
idx
+
1
;
t
->
max
=
TMAX
(
t
->
max
,
args
.
max
);
}
memcpy
(
t
->
centroids
,
args
.
centroids
,
sizeof
(
SCentroid
)
*
t
->
num_centroids
);
taosMemoryFree
((
void
*
)
args
.
centroids
);
}
void
tdigestAdd
(
TDigest
*
t
,
double
x
,
int64_t
w
)
{
if
(
w
==
0
)
return
;
int32_t
i
=
t
->
num_buffered_pts
;
if
(
i
>
0
&&
t
->
buffered_pts
[
i
-
1
].
value
==
x
)
{
t
->
buffered_pts
[
i
].
weight
=
w
;
}
else
{
t
->
buffered_pts
[
i
].
value
=
x
;
t
->
buffered_pts
[
i
].
weight
=
w
;
t
->
num_buffered_pts
++
;
}
if
(
t
->
num_buffered_pts
>=
t
->
threshold
)
tdigestCompress
(
t
);
}
double
tdigestCDF
(
TDigest
*
t
,
double
x
)
{
if
(
t
==
NULL
)
return
0
;
int32_t
i
;
double
left
,
right
;
int64_t
weight_so_far
;
SCentroid
*
a
,
*
b
,
tmp
;
tdigestCompress
(
t
);
if
(
t
->
num_centroids
==
0
)
return
NAN
;
if
(
x
<
t
->
min
)
return
0
;
if
(
x
>
t
->
max
)
return
1
;
if
(
t
->
num_centroids
==
1
)
{
if
(
FLOAT_EQ
(
t
->
max
,
t
->
min
))
return
0
.
5
;
return
INTERPOLATE
(
x
,
t
->
min
,
t
->
max
);
}
weight_so_far
=
0
;
a
=
b
=
&
tmp
;
b
->
mean
=
t
->
min
;
b
->
weight
=
0
;
right
=
0
;
for
(
i
=
0
;
i
<
t
->
num_centroids
;
i
++
)
{
SCentroid
*
c
=
&
t
->
centroids
[
i
];
left
=
b
->
mean
-
(
a
->
mean
+
right
);
a
=
b
;
b
=
c
;
right
=
(
b
->
mean
-
a
->
mean
)
*
a
->
weight
/
(
a
->
weight
+
b
->
weight
);
if
(
x
<
a
->
mean
+
right
)
{
double
cdf
=
(
weight_so_far
+
a
->
weight
*
INTERPOLATE
(
x
,
a
->
mean
-
left
,
a
->
mean
+
right
))
/
t
->
total_weight
;
return
TMAX
(
cdf
,
0
.
0
);
}
weight_so_far
+=
a
->
weight
;
}
left
=
b
->
mean
-
(
a
->
mean
+
right
);
a
=
b
;
right
=
t
->
max
-
a
->
mean
;
if
(
x
<
a
->
mean
+
right
)
{
return
(
weight_so_far
+
a
->
weight
*
INTERPOLATE
(
x
,
a
->
mean
-
left
,
a
->
mean
+
right
))
/
t
->
total_weight
;
}
return
1
;
}
double
tdigestQuantile
(
TDigest
*
t
,
double
q
)
{
if
(
t
==
NULL
)
return
0
;
int32_t
i
;
double
left
,
right
,
idx
;
int64_t
weight_so_far
;
SCentroid
*
a
,
*
b
,
tmp
;
tdigestCompress
(
t
);
if
(
t
->
num_centroids
==
0
)
return
NAN
;
if
(
t
->
num_centroids
==
1
)
return
t
->
centroids
[
0
].
mean
;
if
(
FLOAT_EQ
(
q
,
0
.
0
))
return
t
->
min
;
if
(
FLOAT_EQ
(
q
,
1
.
0
))
return
t
->
max
;
idx
=
q
*
t
->
total_weight
;
weight_so_far
=
0
;
b
=
&
tmp
;
b
->
mean
=
t
->
min
;
b
->
weight
=
0
;
right
=
t
->
min
;
for
(
i
=
0
;
i
<
t
->
num_centroids
;
i
++
)
{
SCentroid
*
c
=
&
t
->
centroids
[
i
];
a
=
b
;
left
=
right
;
b
=
c
;
right
=
(
b
->
weight
*
a
->
mean
+
a
->
weight
*
b
->
mean
)
/
(
a
->
weight
+
b
->
weight
);
if
(
idx
<
weight_so_far
+
a
->
weight
)
{
double
p
=
(
idx
-
weight_so_far
)
/
a
->
weight
;
return
left
*
(
1
-
p
)
+
right
*
p
;
}
weight_so_far
+=
a
->
weight
;
}
left
=
right
;
a
=
b
;
right
=
t
->
max
;
if
(
idx
<
weight_so_far
+
a
->
weight
&&
a
->
weight
!=
0
)
{
double
p
=
(
idx
-
weight_so_far
)
/
a
->
weight
;
return
left
*
(
1
-
p
)
+
right
*
p
;
}
return
t
->
max
;
}
void
tdigestMerge
(
TDigest
*
t1
,
TDigest
*
t2
)
{
// SPoints
int32_t
num_pts
=
t2
->
num_buffered_pts
;
for
(
int32_t
i
=
num_pts
-
1
;
i
>=
0
;
i
--
)
{
SPt
*
p
=
t2
->
buffered_pts
+
i
;
tdigestAdd
(
t1
,
p
->
value
,
p
->
weight
);
t2
->
num_buffered_pts
--
;
}
// centroids
for
(
int32_t
i
=
0
;
i
<
t2
->
num_centroids
;
i
++
)
{
tdigestAdd
(
t1
,
t2
->
centroids
[
i
].
mean
,
t2
->
centroids
[
i
].
weight
);
}
}
tests/system-test/fulltest.sh
浏览文件 @
5b9422c9
...
...
@@ -23,10 +23,10 @@ python3 ./test.py -f 2-query/length.py
python3 ./test.py
-f
2-query/char_length.py
python3 ./test.py
-f
2-query/upper.py
python3 ./test.py
-f
2-query/lower.py
python3 ./test.py
-f
2-query/join.py
#
python3 ./test.py -f 2-query/join.py
python3 ./test.py
-f
2-query/cast.py
python3 ./test.py
-f
2-query/concat.py
python3 ./test.py
-f
2-query/concat_ws.py
#
python3 ./test.py -f 2-query/concat.py
#
python3 ./test.py -f 2-query/concat_ws.py
python3 ./test.py
-f
2-query/check_tsdb.py
# python3 ./test.py -f 2-query/union.py
# python3 ./test.py -f 2-query/union2.py
...
...
@@ -45,8 +45,6 @@ python3 ./test.py -f 2-query/To_unixtimestamp.py
python3 ./test.py
-f
2-query/timetruncate.py
# python3 ./test.py -f 2-query/diff.py
python3 ./test.py
-f
2-query/Timediff.py
#python3 ./test.py -f 2-query/cast.py
python3 ./test.py
-f
2-query/abs.py
python3 ./test.py
-f
2-query/ceil.py
...
...
@@ -62,8 +60,7 @@ python3 ./test.py -f 2-query/arcsin.py
python3 ./test.py
-f
2-query/arccos.py
python3 ./test.py
-f
2-query/arctan.py
python3 ./test.py
-f
2-query/query_cols_tags_and_or.py
python3 ./test.py
-f
2-query/nestedQuery.py
#python3 ./test.py -f 2-query/nestedQuery.py
python3 ./test.py
-f
7-tmq/basic5.py
python3 ./test.py
-f
7-tmq/subscribeDb.py
...
...
tests/test/c/sdbDump.c
浏览文件 @
5b9422c9
...
...
@@ -110,7 +110,6 @@ void dumpStb(SSdb *pSdb, SJson *json) {
tjsonAddStringToObject
(
item
,
"updateTime"
,
i642str
(
pObj
->
updateTime
));
tjsonAddStringToObject
(
item
,
"uid"
,
i642str
(
pObj
->
uid
));
tjsonAddStringToObject
(
item
,
"dbUid"
,
i642str
(
pObj
->
dbUid
));
tjsonAddIntegerToObject
(
item
,
"version"
,
pObj
->
version
);
tjsonAddIntegerToObject
(
item
,
"tagVer"
,
pObj
->
tagVer
);
tjsonAddIntegerToObject
(
item
,
"colVer"
,
pObj
->
colVer
);
tjsonAddIntegerToObject
(
item
,
"nextColId"
,
pObj
->
nextColId
);
...
...
taos-tools
@
4d83d8c6
比较
a8bb88c9
...
4d83d8c6
Subproject commit
a8bb88c9056735919fc50bf9b12d9562f17e844f
Subproject commit
4d83d8c62973506f760bcaa3a33f4665ed9046d0
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录