Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
091b5124
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
091b5124
编写于
4月 19, 2022
作者:
C
cpwu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into cpwu/3.0
上级
36abf6e0
72735810
变更
49
展开全部
显示空白变更内容
内联
并排
Showing
49 changed file
with
1850 addition
and
1670 deletion
+1850
-1670
include/common/tmsg.h
include/common/tmsg.h
+10
-20
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+3
-0
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-0
include/libs/planner/planner.h
include/libs/planner/planner.h
+5
-0
include/os/osThread.h
include/os/osThread.h
+4
-9
source/client/src/clientMain.c
source/client/src/clientMain.c
+1
-0
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+5
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+8
-10
source/common/src/ttime.c
source/common/src/ttime.c
+10
-2
source/dnode/mgmt/implement/src/dmHandle.c
source/dnode/mgmt/implement/src/dmHandle.c
+4
-4
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+3
-9
source/dnode/mgmt/test/vnode/CMakeLists.txt
source/dnode/mgmt/test/vnode/CMakeLists.txt
+10
-10
source/dnode/mnode/impl/src/mndInfoSchema.c
source/dnode/mnode/impl/src/mndInfoSchema.c
+23
-25
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+19
-54
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+0
-11
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+3
-0
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+2
-0
source/dnode/vnode/src/meta/metaTDBImpl.c
source/dnode/vnode/src/meta/metaTDBImpl.c
+13
-13
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+101
-1
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+0
-74
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+1
-4
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+8
-7
source/libs/nodes/src/nodesTraverseFuncs.c
source/libs/nodes/src/nodesTraverseFuncs.c
+285
-64
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+2
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+2
-2
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+10
-9
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+0
-1
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+138
-133
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+68
-54
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+470
-924
source/libs/parser/test/parserTestUtil.h
source/libs/parser/test/parserTestUtil.h
+6
-1
source/libs/planner/src/planner.c
source/libs/planner/src/planner.c
+104
-0
source/libs/planner/test/planStmtTest.cpp
source/libs/planner/test/planStmtTest.cpp
+54
-0
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+205
-0
source/libs/planner/test/planTestUtil.h
source/libs/planner/test/planTestUtil.h
+35
-0
source/libs/planner/test/plannerTest.cpp
source/libs/planner/test/plannerTest.cpp
+4
-4
source/libs/scalar/inc/sclvector.h
source/libs/scalar/inc/sclvector.h
+5
-0
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+15
-12
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+15
-36
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+10
-2
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+10
-16
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+1
-1
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+57
-17
source/os/src/osThread.c
source/os/src/osThread.c
+25
-33
tests/script/tmp/data.sim
tests/script/tmp/data.sim
+1
-0
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+1
-1
tools/shell/src/shellCommand.c
tools/shell/src/shellCommand.c
+5
-6
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+31
-32
tools/shell/src/shellMain.c
tools/shell/src/shellMain.c
+57
-68
未找到文件。
include/common/tmsg.h
浏览文件 @
091b5124
...
...
@@ -253,22 +253,16 @@ typedef struct {
SSubmitRspBlock
failedBlocks
[];
}
SSubmitRsp
;
#define SCHEMA_SMA_ON 0x1
#define SCHEMA_IDX_ON 0x2
typedef
struct
SSchema
{
int8_t
type
;
int8_t
index
;
// default is 0, not index created
int8_t
flags
;
col_id_t
colId
;
int32_t
bytes
;
char
name
[
TSDB_COL_NAME_LEN
];
}
SSchema
;
typedef
struct
{
int8_t
type
;
int8_t
sma
;
// ETsdbBSmaType and default is TSDB_BSMA_TYPE_I
col_id_t
colId
;
int32_t
bytes
;
char
name
[
TSDB_COL_NAME_LEN
];
}
SSchemaEx
;
#define SSCHMEA_TYPE(s) ((s)->type)
#define SSCHMEA_SMA(s) ((s)->sma)
#define SSCHMEA_COLID(s) ((s)->colId)
...
...
@@ -1438,7 +1432,6 @@ typedef struct {
typedef
struct
SVCreateTbReq
{
int64_t
ver
;
// use a general definition
char
*
dbFName
;
char
*
name
;
uint32_t
ttl
;
uint32_t
keep
;
...
...
@@ -1454,7 +1447,7 @@ typedef struct SVCreateTbReq {
tb_uid_t
suid
;
col_id_t
nCols
;
col_id_t
nBSmaCols
;
SSchema
Ex
*
pSchema
;
SSchema
*
pSchema
;
col_id_t
nTagCols
;
SSchema
*
pTagSchema
;
SRSmaParam
*
pRSmaParam
;
...
...
@@ -1466,7 +1459,7 @@ typedef struct SVCreateTbReq {
struct
{
col_id_t
nCols
;
col_id_t
nBSmaCols
;
SSchema
Ex
*
pSchema
;
SSchema
*
pSchema
;
SRSmaParam
*
pRSmaParam
;
}
ntbCfg
;
};
...
...
@@ -2031,16 +2024,13 @@ int32_t tDecodeSMqCMCommitOffsetReq(SCoder* decoder, SMqCMCommitOffsetReq* pReq)
typedef
struct
{
uint32_t
nCols
;
union
{
SSchema
*
pSchema
;
SSchemaEx
*
pSchemaEx
;
};
}
SSchemaWrapper
;
static
FORCE_INLINE
int32_t
taosEncodeSSchema
(
void
**
buf
,
const
SSchema
*
pSchema
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
type
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
index
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
flags
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSchema
->
bytes
);
tlen
+=
taosEncodeFixedI16
(
buf
,
pSchema
->
colId
);
tlen
+=
taosEncodeString
(
buf
,
pSchema
->
name
);
...
...
@@ -2049,7 +2039,7 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema
static
FORCE_INLINE
void
*
taosDecodeSSchema
(
void
*
buf
,
SSchema
*
pSchema
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
pSchema
->
type
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSchema
->
index
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSchema
->
flags
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pSchema
->
bytes
);
buf
=
taosDecodeFixedI16
(
buf
,
&
pSchema
->
colId
);
buf
=
taosDecodeStringTo
(
buf
,
pSchema
->
name
);
...
...
@@ -2058,7 +2048,7 @@ static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
static
FORCE_INLINE
int32_t
tEncodeSSchema
(
SCoder
*
pEncoder
,
const
SSchema
*
pSchema
)
{
if
(
tEncodeI8
(
pEncoder
,
pSchema
->
type
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pSchema
->
index
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pSchema
->
flags
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pSchema
->
bytes
)
<
0
)
return
-
1
;
if
(
tEncodeI16
(
pEncoder
,
pSchema
->
colId
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pSchema
->
name
)
<
0
)
return
-
1
;
...
...
@@ -2067,7 +2057,7 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch
static
FORCE_INLINE
int32_t
tDecodeSSchema
(
SCoder
*
pDecoder
,
SSchema
*
pSchema
)
{
if
(
tDecodeI8
(
pDecoder
,
&
pSchema
->
type
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pSchema
->
index
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pSchema
->
flags
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pSchema
->
bytes
)
<
0
)
return
-
1
;
if
(
tDecodeI16
(
pDecoder
,
&
pSchema
->
colId
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pSchema
->
name
)
<
0
)
return
-
1
;
...
...
include/libs/nodes/plannodes.h
浏览文件 @
091b5124
...
...
@@ -355,8 +355,11 @@ typedef struct SQueryPlan {
int32_t
numOfSubplans
;
SNodeList
*
pSubplans
;
// Element is SNodeListNode. The execution level of subplan, starting from 0.
SExplainInfo
explainInfo
;
SNodeList
*
pPlaceholderValues
;
}
SQueryPlan
;
void
nodesWalkPhysiPlan
(
SNode
*
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
#ifdef __cplusplus
}
#endif
...
...
include/libs/nodes/querynodes.h
浏览文件 @
091b5124
...
...
@@ -82,6 +82,7 @@ typedef struct SValueNode {
bool
isDuration
;
bool
translate
;
bool
genByCalc
;
int16_t
placeholderNo
;
union
{
bool
b
;
int64_t
i
;
...
...
include/libs/planner/planner.h
浏览文件 @
091b5124
...
...
@@ -21,6 +21,7 @@ extern "C" {
#endif
#include "plannodes.h"
#include "taos.h"
typedef
struct
SPlanContext
{
uint64_t
queryId
;
...
...
@@ -32,6 +33,7 @@ typedef struct SPlanContext {
bool
showRewrite
;
int8_t
triggerType
;
int64_t
watermark
;
bool
isStmtQuery
;
}
SPlanContext
;
// Create the physical plan for the query, according to the AST.
...
...
@@ -43,6 +45,9 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
// @pSource one execution location of this group of datasource subplans
int32_t
qSetSubplanExecutionNode
(
SSubplan
*
pSubplan
,
int32_t
groupId
,
SDownstreamSourceNode
*
pSource
);
typedef
TAOS_MULTI_BIND
TAOS_BIND_v2
;
// todo remove
int32_t
qStmtBindParam
(
SQueryPlan
*
pPlan
,
TAOS_BIND_v2
*
pParams
);
// Convert to subplan to string for the scheduler to send to the executor
int32_t
qSubPlanToString
(
const
SSubplan
*
pSubplan
,
char
**
pStr
,
int32_t
*
pLen
);
int32_t
qStringToSubplan
(
const
char
*
pStr
,
SSubplan
**
pSubplan
);
...
...
include/os/osThread.h
浏览文件 @
091b5124
...
...
@@ -22,6 +22,10 @@
extern
"C"
{
#endif
#ifndef __USE_XOPEN2K
typedef
pthread_mutex_t
pthread_spinlock_t
;
#endif
typedef
pthread_t
TdThread
;
typedef
pthread_spinlock_t
TdThreadSpinlock
;
typedef
pthread_mutex_t
TdThreadMutex
;
...
...
@@ -33,8 +37,6 @@ typedef pthread_rwlockattr_t TdThreadRwlockAttr;
typedef
pthread_cond_t
TdThreadCond
;
typedef
pthread_condattr_t
TdThreadCondAttr
;
typedef
pthread_key_t
TdThreadKey
;
typedef
pthread_barrier_t
TdThreadBarrier
;
typedef
pthread_barrierattr_t
TdThreadBarrierAttr
;
#define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop
...
...
@@ -156,13 +158,6 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_para
int32_t
taosThreadAttrSetSchedPolicy
(
TdThreadAttr
*
attr
,
int32_t
policy
);
int32_t
taosThreadAttrSetScope
(
TdThreadAttr
*
attr
,
int32_t
contentionscope
);
int32_t
taosThreadAttrSetStackSize
(
TdThreadAttr
*
attr
,
size_t
stacksize
);
int32_t
taosThreadBarrierDestroy
(
TdThreadBarrier
*
barrier
);
int32_t
taosThreadBarrierInit
(
TdThreadBarrier
*
barrier
,
const
TdThreadBarrierAttr
*
attr
,
uint32_t
count
);
int32_t
taosThreadBarrierWait
(
TdThreadBarrier
*
barrier
);
int32_t
taosThreadBarrierAttrDestroy
(
TdThreadBarrierAttr
*
attr
);
int32_t
taosThreadBarrierAttrGetPshared
(
const
TdThreadBarrierAttr
*
attr
,
int32_t
*
pshared
);
int32_t
taosThreadBarrierAttrInit
(
TdThreadBarrierAttr
*
attr
);
int32_t
taosThreadBarrierAttrSetPshared
(
TdThreadBarrierAttr
*
attr
,
int32_t
pshared
);
int32_t
taosThreadCancel
(
TdThread
thread
);
int32_t
taosThreadCondDestroy
(
TdThreadCond
*
cond
);
int32_t
taosThreadCondInit
(
TdThreadCond
*
cond
,
const
TdThreadCondAttr
*
attr
);
...
...
source/client/src/clientMain.c
浏览文件 @
091b5124
...
...
@@ -71,6 +71,7 @@ void taos_cleanup(void) {
schedulerDestroy
();
tscInfo
(
"all local resources released"
);
taosCleanupCfg
();
taosCloseLog
();
}
...
...
source/common/src/tdatablock.c
浏览文件 @
091b5124
...
...
@@ -1100,6 +1100,11 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows)
pColumn
->
nullbitmap
=
tmp
;
memset
(
pColumn
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
if
(
pColumn
->
info
.
type
==
TSDB_DATA_TYPE_NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
assert
(
pColumn
->
info
.
bytes
);
tmp
=
taosMemoryRealloc
(
pColumn
->
pData
,
numOfRows
*
pColumn
->
info
.
bytes
);
if
(
tmp
==
NULL
)
{
...
...
source/common/src/tmsg.c
浏览文件 @
091b5124
...
...
@@ -398,7 +398,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
ver
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
dbFName
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
name
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pReq
->
ttl
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pReq
->
keep
);
...
...
@@ -411,7 +410,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
tlen
+=
taosEncodeFixedI16
(
buf
,
pReq
->
stbCfg
.
nBSmaCols
);
for
(
col_id_t
i
=
0
;
i
<
pReq
->
stbCfg
.
nCols
;
++
i
)
{
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
type
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
sma
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
flags
);
tlen
+=
taosEncodeFixedI16
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
colId
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
bytes
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
name
);
...
...
@@ -419,7 +418,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
tlen
+=
taosEncodeFixedI16
(
buf
,
pReq
->
stbCfg
.
nTagCols
);
for
(
col_id_t
i
=
0
;
i
<
pReq
->
stbCfg
.
nTagCols
;
++
i
)
{
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
type
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
index
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
flags
);
tlen
+=
taosEncodeFixedI16
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
colId
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
bytes
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
name
);
...
...
@@ -443,7 +442,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
tlen
+=
taosEncodeFixedI16
(
buf
,
pReq
->
ntbCfg
.
nBSmaCols
);
for
(
col_id_t
i
=
0
;
i
<
pReq
->
ntbCfg
.
nCols
;
++
i
)
{
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
type
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
sma
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
flags
);
tlen
+=
taosEncodeFixedI16
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
colId
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
bytes
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
name
);
...
...
@@ -467,7 +466,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
void
*
tDeserializeSVCreateTbReq
(
void
*
buf
,
SVCreateTbReq
*
pReq
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pReq
->
ver
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
dbFName
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
name
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pReq
->
ttl
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pReq
->
keep
));
...
...
@@ -478,10 +476,10 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pReq
->
stbCfg
.
suid
));
buf
=
taosDecodeFixedI16
(
buf
,
&
(
pReq
->
stbCfg
.
nCols
));
buf
=
taosDecodeFixedI16
(
buf
,
&
(
pReq
->
stbCfg
.
nBSmaCols
));
pReq
->
stbCfg
.
pSchema
=
(
SSchema
Ex
*
)
taosMemoryMalloc
(
pReq
->
stbCfg
.
nCols
*
sizeof
(
SSchemaEx
));
pReq
->
stbCfg
.
pSchema
=
(
SSchema
*
)
taosMemoryMalloc
(
pReq
->
stbCfg
.
nCols
*
sizeof
(
SSchema
));
for
(
col_id_t
i
=
0
;
i
<
pReq
->
stbCfg
.
nCols
;
++
i
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
stbCfg
.
pSchema
[
i
].
type
));
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
stbCfg
.
pSchema
[
i
].
sma
));
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
stbCfg
.
pSchema
[
i
].
flags
));
buf
=
taosDecodeFixedI16
(
buf
,
&
(
pReq
->
stbCfg
.
pSchema
[
i
].
colId
));
buf
=
taosDecodeFixedI32
(
buf
,
&
(
pReq
->
stbCfg
.
pSchema
[
i
].
bytes
));
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
stbCfg
.
pSchema
[
i
].
name
);
...
...
@@ -490,7 +488,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
pReq
->
stbCfg
.
pTagSchema
=
(
SSchema
*
)
taosMemoryMalloc
(
pReq
->
stbCfg
.
nTagCols
*
sizeof
(
SSchema
));
for
(
col_id_t
i
=
0
;
i
<
pReq
->
stbCfg
.
nTagCols
;
++
i
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
stbCfg
.
pTagSchema
[
i
].
type
));
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
stbCfg
.
pTagSchema
[
i
].
index
));
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
stbCfg
.
pTagSchema
[
i
].
flags
));
buf
=
taosDecodeFixedI16
(
buf
,
&
pReq
->
stbCfg
.
pTagSchema
[
i
].
colId
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pReq
->
stbCfg
.
pTagSchema
[
i
].
bytes
);
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
stbCfg
.
pTagSchema
[
i
].
name
);
...
...
@@ -520,10 +518,10 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
case
TD_NORMAL_TABLE
:
buf
=
taosDecodeFixedI16
(
buf
,
&
pReq
->
ntbCfg
.
nCols
);
buf
=
taosDecodeFixedI16
(
buf
,
&
(
pReq
->
ntbCfg
.
nBSmaCols
));
pReq
->
ntbCfg
.
pSchema
=
(
SSchema
Ex
*
)
taosMemoryMalloc
(
pReq
->
ntbCfg
.
nCols
*
sizeof
(
SSchemaEx
));
pReq
->
ntbCfg
.
pSchema
=
(
SSchema
*
)
taosMemoryMalloc
(
pReq
->
ntbCfg
.
nCols
*
sizeof
(
SSchema
));
for
(
col_id_t
i
=
0
;
i
<
pReq
->
ntbCfg
.
nCols
;
++
i
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
pReq
->
ntbCfg
.
pSchema
[
i
].
type
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pReq
->
ntbCfg
.
pSchema
[
i
].
sma
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pReq
->
ntbCfg
.
pSchema
[
i
].
flags
);
buf
=
taosDecodeFixedI16
(
buf
,
&
pReq
->
ntbCfg
.
pSchema
[
i
].
colId
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pReq
->
ntbCfg
.
pSchema
[
i
].
bytes
);
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
ntbCfg
.
pSchema
[
i
].
name
);
...
...
source/common/src/ttime.c
浏览文件 @
091b5124
...
...
@@ -415,7 +415,11 @@ int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec
if
(
type
==
TSDB_DATA_TYPE_BINARY
)
{
newColData
=
taosMemoryCalloc
(
1
,
charLen
+
1
);
memcpy
(
newColData
,
varDataVal
(
inputData
),
charLen
);
taosParseTime
(
newColData
,
timeVal
,
charLen
,
(
int32_t
)
timePrec
,
0
);
bool
ret
=
taosParseTime
(
newColData
,
timeVal
,
charLen
,
(
int32_t
)
timePrec
,
0
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
newColData
);
return
ret
;
}
taosMemoryFree
(
newColData
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
newColData
=
taosMemoryCalloc
(
1
,
charLen
/
TSDB_NCHAR_SIZE
+
1
);
...
...
@@ -425,7 +429,11 @@ int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec
return
TSDB_CODE_FAILED
;
}
newColData
[
len
]
=
0
;
taosParseTime
(
newColData
,
timeVal
,
len
+
1
,
(
int32_t
)
timePrec
,
0
);
bool
ret
=
taosParseTime
(
newColData
,
timeVal
,
len
+
1
,
(
int32_t
)
timePrec
,
0
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
newColData
);
return
ret
;
}
taosMemoryFree
(
newColData
);
}
else
{
return
TSDB_CODE_FAILED
;
...
...
source/dnode/mgmt/implement/src/dmHandle.c
浏览文件 @
091b5124
...
...
@@ -36,12 +36,12 @@ static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) {
}
}
else
{
SStatusRsp
statusRsp
=
{
0
};
if
(
pRsp
->
pCont
!=
NULL
&&
pRsp
->
contLen
>
0
&&
tDeserializeSStatusRsp
(
pRsp
->
pCont
,
pRsp
->
contLen
,
&
statusRsp
)
==
0
)
{
if
(
pRsp
->
pCont
!=
NULL
&&
pRsp
->
contLen
>
0
&&
tDeserializeSStatusRsp
(
pRsp
->
pCont
,
pRsp
->
contLen
,
&
statusRsp
)
==
0
)
{
pDnode
->
data
.
dnodeVer
=
statusRsp
.
dnodeVer
;
dmUpdateDnodeCfg
(
pDnode
,
&
statusRsp
.
dnodeCfg
);
dmUpdateEps
(
pDnode
,
statusRsp
.
pDnodeEps
);
}
rpcFreeCont
(
pRsp
->
pCont
);
tFreeSStatusRsp
(
&
statusRsp
);
}
...
...
@@ -76,7 +76,7 @@ void dmSendStatusReq(SDnode *pDnode) {
req
.
pVloads
=
info
.
pVloads
;
int32_t
contLen
=
tSerializeSStatusReq
(
NULL
,
0
,
&
req
);
void
*
pHead
=
rpcMallocCont
(
contLen
);
void
*
pHead
=
rpcMallocCont
(
contLen
);
tSerializeSStatusReq
(
pHead
,
contLen
,
&
req
);
tFreeSStatusReq
(
&
req
);
...
...
@@ -101,7 +101,7 @@ int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg) {
}
int32_t
dmProcessConfigReq
(
SDnode
*
pDnode
,
SNodeMsg
*
pMsg
)
{
SRpcMsg
*
pReq
=
&
pMsg
->
rpcMsg
;
SRpcMsg
*
pReq
=
&
pMsg
->
rpcMsg
;
SDCfgDnodeReq
*
pCfg
=
pReq
->
pCont
;
dError
(
"config req is received, but not supported yet"
);
return
TSDB_CODE_OPS_NOT_SUPPORT
;
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
091b5124
...
...
@@ -82,13 +82,13 @@ int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) {
}
static
void
vmGenerateVnodeCfg
(
SCreateVnodeReq
*
pCreate
,
SVnodeCfg
*
pCfg
)
{
memcpy
(
pCfg
,
&
vnodeCfgDefault
,
sizeof
(
SVnodeCfg
));
pCfg
->
vgId
=
pCreate
->
vgId
;
strcpy
(
pCfg
->
dbname
,
pCreate
->
db
);
pCfg
->
wsize
=
pCreate
->
cacheBlockSize
*
1024
*
1024
;
pCfg
->
ssize
=
1024
;
pCfg
->
lsize
=
1024
*
1024
;
pCfg
->
isHeapAllocator
=
true
;
pCfg
->
ttl
=
4
;
pCfg
->
keep
=
pCreate
->
daysToKeep0
;
pCfg
->
streamMode
=
pCreate
->
streamMode
;
pCfg
->
isWeak
=
true
;
pCfg
->
tsdbCfg
.
keep2
=
pCreate
->
daysToKeep0
;
...
...
@@ -96,12 +96,6 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
pCfg
->
tsdbCfg
.
keep1
=
pCreate
->
daysToKeep0
;
pCfg
->
tsdbCfg
.
lruCacheSize
=
pCreate
->
cacheBlockSize
;
pCfg
->
tsdbCfg
.
retentions
=
pCreate
->
pRetensions
;
pCfg
->
walCfg
.
level
=
TAOS_WAL_WRITE
;
pCfg
->
walCfg
.
fsyncPeriod
=
0
;
pCfg
->
walCfg
.
retentionPeriod
=
0
;
pCfg
->
walCfg
.
retentionSize
=
0
;
pCfg
->
walCfg
.
rollPeriod
=
0
;
pCfg
->
walCfg
.
segSize
=
0
;
pCfg
->
walCfg
.
vgId
=
pCreate
->
vgId
;
pCfg
->
hashBegin
=
pCreate
->
hashBegin
;
pCfg
->
hashEnd
=
pCreate
->
hashEnd
;
...
...
source/dnode/mgmt/test/vnode/CMakeLists.txt
浏览文件 @
091b5124
aux_source_directory
(
. DND_VNODE_TEST_SRC
)
add_executable
(
dvnodeTest
${
DND_VNODE_TEST_SRC
}
)
target_link_libraries
(
dvnodeTest
PUBLIC sut
)
#
aux_source_directory(. DND_VNODE_TEST_SRC)
#
add_executable(dvnodeTest ${DND_VNODE_TEST_SRC})
#
target_link_libraries(
#
dvnodeTest
#
PUBLIC sut
#
)
add_test
(
NAME dvnodeTest
COMMAND dvnodeTest
)
#
add_test(
#
NAME dvnodeTest
#
COMMAND dvnodeTest
#
)
source/dnode/mnode/impl/src/mndInfoSchema.c
浏览文件 @
091b5124
...
...
@@ -41,8 +41,8 @@ static const SInfosTableSchema mnodesSchema[] = {
static
const
SInfosTableSchema
modulesSchema
[]
=
{
{.
name
=
"id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"endpoint"
,
.
bytes
=
134
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"module"
,
.
bytes
=
10
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"endpoint"
,
.
bytes
=
134
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"module"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
};
static
const
SInfosTableSchema
qnodesSchema
[]
=
{
...
...
@@ -145,9 +145,9 @@ static const SInfosTableSchema userTblsSchema[] = {
};
static
const
SInfosTableSchema
userTblDistSchema
[]
=
{
{.
name
=
"db_name"
,
.
bytes
=
32
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"db_name"
,
.
bytes
=
32
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"table_name"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"distributed_histogram"
,
.
bytes
=
500
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"distributed_histogram"
,
.
bytes
=
500
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"min_of_rows"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"max_of_rows"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"avg_of_rows"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
...
...
@@ -168,35 +168,33 @@ static const SInfosTableSchema userUsersSchema[] = {
};
static
const
SInfosTableSchema
grantsSchema
[]
=
{
{.
name
=
"version"
,
.
bytes
=
8
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"expire time"
,
.
bytes
=
19
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"expired"
,
.
bytes
=
5
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"storage(GB)"
,
.
bytes
=
21
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"timeseries"
,
.
bytes
=
21
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"databases"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"users"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"accounts"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"dnodes"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"connections"
,
.
bytes
=
11
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"streams"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"cpu cores"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"speed(PPS)"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"querytime"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
BINARY
},
{.
name
=
"version"
,
.
bytes
=
8
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"expire time"
,
.
bytes
=
19
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"expired"
,
.
bytes
=
5
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"storage(GB)"
,
.
bytes
=
21
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"timeseries"
,
.
bytes
=
21
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"databases"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"users"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"accounts"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"dnodes"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"connections"
,
.
bytes
=
11
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"streams"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"cpu cores"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"speed(PPS)"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
{.
name
=
"querytime"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_
VARCHAR
},
};
static
const
SInfosTableSchema
vgroupsSchema
[]
=
{
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"db_name"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"tables"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"status"
,
.
bytes
=
12
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"onlines"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"v1_dnode"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"v1_status"
,
.
bytes
=
10
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"v1_status"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"v2_dnode"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"v2_status"
,
.
bytes
=
10
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"v2_status"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"v3_dnode"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"v3_status"
,
.
bytes
=
10
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"
compacting"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"v3_status"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
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
},
};
...
...
@@ -206,7 +204,7 @@ static const SInfosTableSchema topicSchema[] = {
{.
name
=
"topic_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"db_name"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"sql"
,
.
bytes
=
1024
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"sql"
,
.
bytes
=
1024
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"row_len"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
};
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
091b5124
...
...
@@ -18,8 +18,8 @@
#include "mndDb.h"
#include "mndDnode.h"
#include "mndInfoSchema.h"
#include "mndPerfSchema.h"
#include "mndMnode.h"
#include "mndPerfSchema.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndUser.h"
...
...
@@ -40,7 +40,7 @@ static int32_t mndProcessVCreateStbRsp(SNodeMsg *pRsp);
static
int32_t
mndProcessVAlterStbRsp
(
SNodeMsg
*
pRsp
);
static
int32_t
mndProcessVDropStbRsp
(
SNodeMsg
*
pRsp
);
static
int32_t
mndProcessTableMetaReq
(
SNodeMsg
*
pReq
);
static
int32_t
mndRetrieveStb
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
);
static
int32_t
mndRetrieveStb
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
);
static
void
mndCancelGetNextStb
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitStb
(
SMnode
*
pMnode
)
{
...
...
@@ -333,9 +333,9 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) {
}
static
FORCE_INLINE
int
schemaExColIdCompare
(
const
void
*
colId
,
const
void
*
pSchema
)
{
if
(
*
(
col_id_t
*
)
colId
<
((
SSchema
Ex
*
)
pSchema
)
->
colId
)
{
if
(
*
(
col_id_t
*
)
colId
<
((
SSchema
*
)
pSchema
)
->
colId
)
{
return
-
1
;
}
else
if
(
*
(
col_id_t
*
)
colId
>
((
SSchema
Ex
*
)
pSchema
)
->
colId
)
{
}
else
if
(
*
(
col_id_t
*
)
colId
>
((
SSchema
*
)
pSchema
)
->
colId
)
{
return
1
;
}
return
0
;
...
...
@@ -349,7 +349,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
SVCreateTbReq
req
=
{
0
};
req
.
ver
=
0
;
req
.
dbFName
=
dbFName
;
req
.
name
=
(
char
*
)
tNameGetTableName
(
&
name
);
req
.
ttl
=
0
;
req
.
keep
=
0
;
...
...
@@ -360,49 +359,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
req
.
stbCfg
.
nTagCols
=
pStb
->
numOfTags
;
req
.
stbCfg
.
pTagSchema
=
pStb
->
pTags
;
req
.
stbCfg
.
nBSmaCols
=
pStb
->
numOfSmas
;
req
.
stbCfg
.
pSchema
=
(
SSchema
Ex
*
)
taosMemoryCalloc
(
pStb
->
numOfColumns
,
sizeof
(
SSchemaEx
));
req
.
stbCfg
.
pSchema
=
(
SSchema
*
)
taosMemoryCalloc
(
pStb
->
numOfColumns
,
sizeof
(
SSchema
));
if
(
req
.
stbCfg
.
pSchema
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
int
bSmaStat
=
0
;
// no column has bsma
if
(
pStb
->
numOfSmas
==
pStb
->
numOfColumns
)
{
// assume pColumns > 0
bSmaStat
=
1
;
// all columns have bsma
}
else
if
(
pStb
->
numOfSmas
!=
0
)
{
bSmaStat
=
2
;
// partial columns have bsma
TASSERT
(
pStb
->
pSmas
!=
NULL
);
// TODO: remove the assert
}
for
(
int32_t
i
=
0
;
i
<
req
.
stbCfg
.
nCols
;
++
i
)
{
SSchemaEx
*
pSchemaEx
=
req
.
stbCfg
.
pSchema
+
i
;
SSchema
*
pSchema
=
pStb
->
pColumns
+
i
;
pSchemaEx
->
type
=
pSchema
->
type
;
pSchemaEx
->
sma
=
(
bSmaStat
==
1
)
?
TSDB_BSMA_TYPE_LATEST
:
TSDB_BSMA_TYPE_NONE
;
pSchemaEx
->
colId
=
pSchema
->
colId
;
pSchemaEx
->
bytes
=
pSchema
->
bytes
;
memcpy
(
pSchemaEx
->
name
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
}
if
(
bSmaStat
==
2
)
{
if
(
pStb
->
pSmas
==
NULL
)
{
mError
(
"stb:%s, sma options is empty"
,
pStb
->
name
);
taosMemoryFreeClear
(
req
.
stbCfg
.
pSchema
);
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfSmas
;
++
i
)
{
SSchema
*
pSmaSchema
=
pStb
->
pSmas
+
i
;
SSchemaEx
*
pColSchema
=
taosbsearch
(
&
pSmaSchema
->
colId
,
req
.
stbCfg
.
pSchema
,
req
.
stbCfg
.
nCols
,
sizeof
(
SSchemaEx
),
schemaExColIdCompare
,
TD_EQ
);
if
(
pColSchema
==
NULL
)
{
terrno
=
TSDB_CODE_MND_INVALID_STB_OPTION
;
taosMemoryFreeClear
(
req
.
stbCfg
.
pSchema
);
mError
(
"stb:%s, sma col:%s not found in columns"
,
pStb
->
name
,
pSmaSchema
->
name
);
return
NULL
;
}
pColSchema
->
sma
=
TSDB_BSMA_TYPE_LATEST
;
}
memcpy
(
req
.
stbCfg
.
pSchema
,
pStb
->
pColumns
,
sizeof
(
SSchema
)
*
pStb
->
numOfColumns
);
for
(
int
i
=
0
;
i
<
pStb
->
numOfColumns
;
i
++
)
{
req
.
stbCfg
.
pSchema
[
i
].
flags
=
SCHEMA_SMA_ON
;
}
SRSmaParam
*
pRSmaParam
=
NULL
;
...
...
@@ -1644,14 +1609,14 @@ static void mndExtractTableName(char *tableId, char *name) {
}
}
static
int32_t
mndRetrieveStb
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
)
{
static
int32_t
mndRetrieveStb
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pReq
->
pNode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SStbObj
*
pStb
=
NULL
;
int32_t
cols
=
0
;
SDbObj
*
pDb
=
NULL
;
SDbObj
*
pDb
=
NULL
;
if
(
strlen
(
pShow
->
db
)
>
0
)
{
pDb
=
mndAcquireDb
(
pMnode
,
pShow
->
db
);
if
(
pDb
==
NULL
)
return
terrno
;
...
...
@@ -1673,16 +1638,16 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlo
mndExtractTableName
(
pStb
->
name
,
&
stbName
[
VARSTR_HEADER_SIZE
]);
varDataSetLen
(
stbName
,
strlen
(
&
stbName
[
VARSTR_HEADER_SIZE
]));
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
stbName
,
false
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
stbName
,
false
);
char
db
[
TSDB_DB_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
name
,
pStb
->
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameFromString
(
&
name
,
pStb
->
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameGetDbName
(
&
name
,
varDataVal
(
db
));
varDataSetLen
(
db
,
strlen
(
varDataVal
(
db
)));
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
db
,
false
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
db
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pStb
->
createdTime
,
false
);
...
...
@@ -1696,7 +1661,7 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlo
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pStb
->
updateTime
,
false
);
// number of tables
char
*
p
=
taosMemoryMalloc
(
pStb
->
commentLen
+
VARSTR_HEADER_SIZE
);
// check malloc failures
char
*
p
=
taosMemoryMalloc
(
pStb
->
commentLen
+
VARSTR_HEADER_SIZE
);
// check malloc failures
if
(
p
!=
NULL
)
{
if
(
pStb
->
commentLen
!=
0
)
{
STR_TO_VARSTR
(
p
,
pStb
->
comment
);
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
091b5124
...
...
@@ -537,17 +537,6 @@ static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pVgroup
->
numOfTables
,
false
);
// status
char
buf
[
10
]
=
{
0
};
STR_TO_VARSTR
(
buf
,
"ready"
);
// TODO
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
buf
,
false
);
// onlines
int32_t
onlines
=
pVgroup
->
replica
;
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
onlines
,
false
);
// default 3 replica
for
(
int32_t
i
=
0
;
i
<
3
;
++
i
)
{
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
091b5124
...
...
@@ -40,6 +40,8 @@ typedef struct SVnode SVnode;
typedef
struct
STsdbCfg
STsdbCfg
;
// todo: remove
typedef
struct
SVnodeCfg
SVnodeCfg
;
extern
const
SVnodeCfg
vnodeCfgDefault
;
int
vnodeInit
(
int
nthreads
);
void
vnodeCleanup
();
int
vnodeCreate
(
const
char
*
path
,
SVnodeCfg
*
pCfg
,
STfs
*
pTfs
);
...
...
@@ -133,6 +135,7 @@ struct STsdbCfg {
struct
SVnodeCfg
{
int32_t
vgId
;
char
dbname
[
TSDB_DB_NAME_LEN
];
uint64_t
dbId
;
uint64_t
wsize
;
uint64_t
ssize
;
...
...
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
091b5124
...
...
@@ -31,6 +31,8 @@ extern "C" {
// clang-format on
// vnodeCfg ====================
int
vnodeEncodeConfig
(
const
void
*
pObj
,
SJson
*
pJson
);
int
vnodeDecodeConfig
(
const
SJson
*
pJson
,
void
*
pObj
);
// vnodeModule ====================
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
);
...
...
source/dnode/vnode/src/meta/metaTDBImpl.c
浏览文件 @
091b5124
...
...
@@ -299,10 +299,10 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
schemaWrapper
.
nCols
=
pTbCfg
->
stbCfg
.
nCols
;
schemaWrapper
.
pSchema
Ex
=
pTbCfg
->
stbCfg
.
pSchema
;
schemaWrapper
.
pSchema
=
pTbCfg
->
stbCfg
.
pSchema
;
}
else
{
schemaWrapper
.
nCols
=
pTbCfg
->
ntbCfg
.
nCols
;
schemaWrapper
.
pSchema
Ex
=
pTbCfg
->
ntbCfg
.
pSchema
;
schemaWrapper
.
pSchema
=
pTbCfg
->
ntbCfg
.
pSchema
;
}
pVal
=
pBuf
=
buf
;
metaEncodeSchemaEx
(
&
pBuf
,
&
schemaWrapper
);
...
...
@@ -464,7 +464,7 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
tb_uid_t
quid
;
SSchemaWrapper
*
pSW
;
STSchemaBuilder
sb
;
SSchema
Ex
*
pSchema
;
SSchema
*
pSchema
;
STSchema
*
pTSchema
;
STbCfg
*
pTbCfg
;
...
...
@@ -482,8 +482,8 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
tdInitTSchemaBuilder
(
&
sb
,
0
);
for
(
int
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
pSchema
=
pSW
->
pSchema
Ex
+
i
;
tdAddColToSchema
(
&
sb
,
pSchema
->
type
,
pSchema
->
sma
,
pSchema
->
colId
,
pSchema
->
bytes
);
pSchema
=
pSW
->
pSchema
+
i
;
tdAddColToSchema
(
&
sb
,
pSchema
->
type
,
pSchema
->
flags
,
pSchema
->
colId
,
pSchema
->
bytes
);
}
pTSchema
=
tdGetSchemaFromBuilder
(
&
sb
);
tdDestroyTSchemaBuilder
(
&
sb
);
...
...
@@ -939,7 +939,7 @@ static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
for
(
int
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
pSchema
=
pSW
->
pSchema
+
i
;
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
type
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
index
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
flags
);
tlen
+=
taosEncodeFixedI16
(
buf
,
pSchema
->
colId
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSchema
->
bytes
);
tlen
+=
taosEncodeString
(
buf
,
pSchema
->
name
);
...
...
@@ -967,13 +967,13 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) {
static
int
metaEncodeSchemaEx
(
void
**
buf
,
SSchemaWrapper
*
pSW
)
{
int
tlen
=
0
;
SSchema
Ex
*
pSchema
;
SSchema
*
pSchema
;
tlen
+=
taosEncodeFixedU32
(
buf
,
pSW
->
nCols
);
for
(
int
i
=
0
;
i
<
pSW
->
nCols
;
++
i
)
{
pSchema
=
pSW
->
pSchema
Ex
+
i
;
pSchema
=
pSW
->
pSchema
+
i
;
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
type
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
sma
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSchema
->
flags
);
tlen
+=
taosEncodeFixedI16
(
buf
,
pSchema
->
colId
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSchema
->
bytes
);
tlen
+=
taosEncodeString
(
buf
,
pSchema
->
name
);
...
...
@@ -985,11 +985,11 @@ static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW) {
static
void
*
metaDecodeSchemaEx
(
void
*
buf
,
SSchemaWrapper
*
pSW
,
bool
isGetEx
)
{
buf
=
taosDecodeFixedU32
(
buf
,
&
pSW
->
nCols
);
if
(
isGetEx
)
{
pSW
->
pSchema
Ex
=
(
SSchemaEx
*
)
taosMemoryMalloc
(
sizeof
(
SSchemaEx
)
*
pSW
->
nCols
);
pSW
->
pSchema
=
(
SSchema
*
)
taosMemoryMalloc
(
sizeof
(
SSchema
)
*
pSW
->
nCols
);
for
(
int
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
SSchema
Ex
*
pSchema
=
pSW
->
pSchemaEx
+
i
;
SSchema
*
pSchema
=
pSW
->
pSchema
+
i
;
buf
=
taosDecodeFixedI8
(
buf
,
&
pSchema
->
type
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSchema
->
sma
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSchema
->
flags
);
buf
=
taosDecodeFixedI16
(
buf
,
&
pSchema
->
colId
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pSchema
->
bytes
);
buf
=
taosDecodeStringTo
(
buf
,
pSchema
->
name
);
...
...
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
091b5124
...
...
@@ -16,13 +16,113 @@
#include "vnodeInt.h"
const
SVnodeCfg
vnodeCfgDefault
=
{
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
walCfg
=
{.
level
=
TAOS_WAL_WRITE
}};
.
vgId
=
-
1
,
.
dbname
=
""
,
.
dbId
=
0
,
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
isHeapAllocator
=
false
,
.
ttl
=
0
,
.
keep
=
0
,
.
streamMode
=
0
,
.
isWeak
=
0
,
.
tsdbCfg
=
{.
precision
=
TWO_STAGE_COMP
,
.
update
=
0
,
.
compression
=
2
,
.
days
=
10
,
.
minRows
=
100
,
.
maxRows
=
4096
,
.
keep2
=
3650
,
.
keep0
=
3650
,
.
keep1
=
3650
},
.
walCfg
=
{.
vgId
=
-
1
,
.
fsyncPeriod
=
0
,
.
retentionPeriod
=
0
,
.
rollPeriod
=
0
,
.
segSize
=
0
,
.
level
=
TAOS_WAL_WRITE
},
.
hashBegin
=
0
,
.
hashEnd
=
0
,
.
hashMethod
=
0
};
int
vnodeCheckCfg
(
const
SVnodeCfg
*
pCfg
)
{
// TODO
return
0
;
}
int
vnodeEncodeConfig
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SVnodeCfg
*
pCfg
=
(
SVnodeCfg
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"vgId"
,
pCfg
->
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddStringToObject
(
pJson
,
"dbname"
,
pCfg
->
dbname
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"dbId"
,
pCfg
->
dbId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wsize"
,
pCfg
->
wsize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"ssize"
,
pCfg
->
ssize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"lsize"
,
pCfg
->
lsize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isHeap"
,
pCfg
->
isHeapAllocator
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"ttl"
,
pCfg
->
ttl
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep"
,
pCfg
->
keep
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"update"
,
pCfg
->
tsdbCfg
.
update
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"compression"
,
pCfg
->
tsdbCfg
.
compression
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"daysPerFile"
,
pCfg
->
tsdbCfg
.
days
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"minRows"
,
pCfg
->
tsdbCfg
.
minRows
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"maxRows"
,
pCfg
->
tsdbCfg
.
maxRows
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"lruCacheSize"
,
pCfg
->
tsdbCfg
.
lruCacheSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.rollPeriod"
,
pCfg
->
walCfg
.
rollPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.retentionSize"
,
pCfg
->
walCfg
.
retentionSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.segSize"
,
pCfg
->
walCfg
.
segSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.level"
,
pCfg
->
walCfg
.
level
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"hashBegin"
,
pCfg
->
hashBegin
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"hashEnd"
,
pCfg
->
hashEnd
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"hashMethod"
,
pCfg
->
hashMethod
)
<
0
)
return
-
1
;
return
0
;
}
int
vnodeDecodeConfig
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SVnodeCfg
*
pCfg
=
(
SVnodeCfg
*
)
pObj
;
if
(
tjsonGetNumberValue
(
pJson
,
"vgId"
,
pCfg
->
vgId
)
<
0
)
return
-
1
;
if
(
tjsonGetStringValue
(
pJson
,
"dbname"
,
pCfg
->
dbname
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"dbId"
,
pCfg
->
dbId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wsize"
,
pCfg
->
wsize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"ssize"
,
pCfg
->
ssize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"lsize"
,
pCfg
->
lsize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isHeap"
,
pCfg
->
isHeapAllocator
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"ttl"
,
pCfg
->
ttl
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep"
,
pCfg
->
keep
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"update"
,
pCfg
->
tsdbCfg
.
update
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"compression"
,
pCfg
->
tsdbCfg
.
compression
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"daysPerFile"
,
pCfg
->
tsdbCfg
.
days
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"minRows"
,
pCfg
->
tsdbCfg
.
minRows
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"maxRows"
,
pCfg
->
tsdbCfg
.
maxRows
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"lruCacheSize"
,
pCfg
->
tsdbCfg
.
lruCacheSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.rollPeriod"
,
pCfg
->
walCfg
.
rollPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.retentionSize"
,
pCfg
->
walCfg
.
retentionSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.segSize"
,
pCfg
->
walCfg
.
segSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.level"
,
pCfg
->
walCfg
.
level
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"hashBegin"
,
pCfg
->
hashBegin
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"hashEnd"
,
pCfg
->
hashEnd
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"hashMethod"
,
pCfg
->
hashMethod
)
<
0
)
return
-
1
;
return
0
;
}
int
vnodeValidateTableHash
(
SVnodeCfg
*
pVnodeOptions
,
char
*
tableFName
)
{
uint32_t
hashValue
=
0
;
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
091b5124
...
...
@@ -181,80 +181,6 @@ static int vnodeEndCommit(SVnode *pVnode) {
static
FORCE_INLINE
void
vnodeWaitCommit
(
SVnode
*
pVnode
)
{
tsem_wait
(
&
pVnode
->
canCommit
);
}
static
int
vnodeEncodeConfig
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SVnodeCfg
*
pCfg
=
(
SVnodeCfg
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"vgId"
,
pCfg
->
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"dbId"
,
pCfg
->
dbId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wsize"
,
pCfg
->
wsize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"ssize"
,
pCfg
->
ssize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"lsize"
,
pCfg
->
lsize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isHeap"
,
pCfg
->
isHeapAllocator
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"ttl"
,
pCfg
->
ttl
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep"
,
pCfg
->
keep
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"update"
,
pCfg
->
tsdbCfg
.
update
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"compression"
,
pCfg
->
tsdbCfg
.
compression
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"daysPerFile"
,
pCfg
->
tsdbCfg
.
days
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"minRows"
,
pCfg
->
tsdbCfg
.
minRows
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"maxRows"
,
pCfg
->
tsdbCfg
.
maxRows
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"lruCacheSize"
,
pCfg
->
tsdbCfg
.
lruCacheSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.rollPeriod"
,
pCfg
->
walCfg
.
rollPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.retentionSize"
,
pCfg
->
walCfg
.
retentionSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.segSize"
,
pCfg
->
walCfg
.
segSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.level"
,
pCfg
->
walCfg
.
level
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"hashBegin"
,
pCfg
->
hashBegin
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"hashEnd"
,
pCfg
->
hashEnd
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"hashMethod"
,
pCfg
->
hashMethod
)
<
0
)
return
-
1
;
return
0
;
}
static
int
vnodeDecodeConfig
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SVnodeCfg
*
pCfg
=
(
SVnodeCfg
*
)
pObj
;
if
(
tjsonGetNumberValue
(
pJson
,
"vgId"
,
pCfg
->
vgId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"dbId"
,
pCfg
->
dbId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wsize"
,
pCfg
->
wsize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"ssize"
,
pCfg
->
ssize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"lsize"
,
pCfg
->
lsize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isHeap"
,
pCfg
->
isHeapAllocator
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"ttl"
,
pCfg
->
ttl
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep"
,
pCfg
->
keep
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"update"
,
pCfg
->
tsdbCfg
.
update
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"compression"
,
pCfg
->
tsdbCfg
.
compression
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"daysPerFile"
,
pCfg
->
tsdbCfg
.
days
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"minRows"
,
pCfg
->
tsdbCfg
.
minRows
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"maxRows"
,
pCfg
->
tsdbCfg
.
maxRows
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"lruCacheSize"
,
pCfg
->
tsdbCfg
.
lruCacheSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.rollPeriod"
,
pCfg
->
walCfg
.
rollPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.retentionSize"
,
pCfg
->
walCfg
.
retentionSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.segSize"
,
pCfg
->
walCfg
.
segSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.level"
,
pCfg
->
walCfg
.
level
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"hashBegin"
,
pCfg
->
hashBegin
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"hashEnd"
,
pCfg
->
hashEnd
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"hashMethod"
,
pCfg
->
hashMethod
)
<
0
)
return
-
1
;
return
0
;
}
static
int
vnodeEncodeState
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SVState
*
pState
=
(
SVState
*
)
pObj
;
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
091b5124
...
...
@@ -217,7 +217,6 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
->
pFuncIds
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
);
}
taosMemoryFree
(
vCreateTbReq
.
dbFName
);
taosMemoryFree
(
vCreateTbReq
.
name
);
return
0
;
...
...
@@ -233,7 +232,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
char
tableFName
[
TSDB_TABLE_FNAME_LEN
];
SMsgHead
*
pHead
=
(
SMsgHead
*
)
pMsg
->
pCont
;
sprintf
(
tableFName
,
"%s.%s"
,
p
CreateTbReq
->
dbFN
ame
,
pCreateTbReq
->
name
);
sprintf
(
tableFName
,
"%s.%s"
,
p
Vnode
->
config
.
dbn
ame
,
pCreateTbReq
->
name
);
int32_t
code
=
vnodeValidateTableHash
(
&
pVnode
->
config
,
tableFName
);
if
(
code
)
{
...
...
@@ -249,7 +248,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
}
// TODO: to encapsule a free API
taosMemoryFree
(
pCreateTbReq
->
name
);
taosMemoryFree
(
pCreateTbReq
->
dbFName
);
if
(
pCreateTbReq
->
type
==
TD_SUPER_TABLE
)
{
taosMemoryFree
(
pCreateTbReq
->
stbCfg
.
pSchema
);
taosMemoryFree
(
pCreateTbReq
->
stbCfg
.
pTagSchema
);
...
...
@@ -298,7 +296,6 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
taosMemoryFree
(
vAlterTbReq
.
stbCfg
.
pRSmaParam
->
pFuncIds
);
taosMemoryFree
(
vAlterTbReq
.
stbCfg
.
pRSmaParam
);
}
taosMemoryFree
(
vAlterTbReq
.
dbFName
);
taosMemoryFree
(
vAlterTbReq
.
name
);
return
0
;
}
...
...
source/libs/function/src/builtins.c
浏览文件 @
091b5124
...
...
@@ -330,7 +330,7 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l
}
uint8_t
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
!
IS_
VAR_DATA
_TYPE
(
paraType
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
paraType
)
{
if
(
!
IS_
INTEGER
_TYPE
(
paraType
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
paraType
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
...
...
@@ -358,7 +358,7 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
uint8_t
para2Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
;
if
((
!
IS_VAR_DATA_TYPE
(
para1Type
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
para1Type
)
||
!
IS_INTEGER_TYPE
(
para2Type
))
{
if
((
!
IS_VAR_DATA_TYPE
(
para1Type
)
&&
!
IS_INTEGER_TYPE
(
para1Type
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
para1Type
)
||
!
IS_INTEGER_TYPE
(
para2Type
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
...
...
@@ -372,12 +372,13 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
uint8_t
para2Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
;
if
((
!
IS_VAR_DATA_TYPE
(
para1Type
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
para1Type
)
||
(
!
IS_VAR_DATA_TYPE
(
para2Type
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
para2Type
))
{
for
(
int32_t
i
=
0
;
i
<
2
;
++
i
)
{
uint8_t
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
i
))
->
resType
.
type
;
if
(
!
IS_VAR_DATA_TYPE
(
paraType
)
&&
!
IS_INTEGER_TYPE
(
paraType
)
&&
TSDB_DATA_TYPE_TIMESTAMP
!=
paraType
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
if
(
3
==
paraNum
)
{
if
(
!
IS_INTEGER_TYPE
(((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
resType
.
type
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
...
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
091b5124
此差异已折叠。
点击以展开。
source/libs/parser/inc/parAst.h
浏览文件 @
091b5124
...
...
@@ -32,6 +32,7 @@ typedef struct SAstCreateContext {
bool
notSupport
;
bool
valid
;
SNode
*
pRootNode
;
int16_t
placeholderNo
;
}
SAstCreateContext
;
typedef
enum
EDatabaseOptionType
{
...
...
@@ -86,7 +87,7 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC
SNode
*
createValueNode
(
SAstCreateContext
*
pCxt
,
int32_t
dataType
,
const
SToken
*
pLiteral
);
SNode
*
createDurationValueNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLiteral
);
SNode
*
createDefaultDatabaseCondValue
(
SAstCreateContext
*
pCxt
);
SNode
*
createPlaceholderValueNode
(
SAstCreateContext
*
pCxt
);
SNode
*
createPlaceholderValueNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLiteral
);
SNode
*
setProjectionAlias
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
,
const
SToken
*
pAlias
);
SNode
*
createLogicConditionNode
(
SAstCreateContext
*
pCxt
,
ELogicConditionType
type
,
SNode
*
pParam1
,
SNode
*
pParam2
);
SNode
*
createOperatorNode
(
SAstCreateContext
*
pCxt
,
EOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
091b5124
...
...
@@ -465,8 +465,8 @@ literal(A) ::= NK_STRING(B).
literal(A) ::= NK_BOOL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B)); }
literal(A) ::= TIMESTAMP(B) NK_STRING(C). { A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); }
literal(A) ::= duration_literal(B). { A = B; }
literal(A) ::= NULL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_NULL,
NULL
)); }
literal(A) ::= NK_QUESTION(B). { A = createRawExprNode(pCxt, &B, createPlaceholderValueNode(pCxt)); }
literal(A) ::= NULL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_NULL,
&B
)); }
literal(A) ::= NK_QUESTION(B). { A = createRawExprNode(pCxt, &B, createPlaceholderValueNode(pCxt
, &B
)); }
duration_literal(A) ::= NK_VARIABLE(B). { A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
091b5124
...
...
@@ -44,6 +44,7 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
pCxt
->
notSupport
=
false
;
pCxt
->
valid
=
true
;
pCxt
->
pRootNode
=
NULL
;
pCxt
->
placeholderNo
=
1
;
}
static
void
trimEscape
(
SToken
*
pName
)
{
...
...
@@ -258,14 +259,12 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC
SNode
*
createValueNode
(
SAstCreateContext
*
pCxt
,
int32_t
dataType
,
const
SToken
*
pLiteral
)
{
SValueNode
*
val
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
CHECK_OUT_OF_MEM
(
val
);
if
(
NULL
!=
pLiteral
)
{
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
if
(
TK_NK_ID
!=
pLiteral
->
type
&&
TK_TIMEZONE
!=
pLiteral
->
type
&&
(
IS_VAR_DATA_TYPE
(
dataType
)
||
TSDB_DATA_TYPE_TIMESTAMP
==
dataType
))
{
trimString
(
pLiteral
->
z
,
pLiteral
->
n
,
val
->
literal
,
pLiteral
->
n
);
}
CHECK_OUT_OF_MEM
(
val
->
literal
);
}
val
->
node
.
resType
.
type
=
dataType
;
val
->
node
.
resType
.
bytes
=
IS_VAR_DATA_TYPE
(
dataType
)
?
strlen
(
val
->
literal
)
:
tDataTypes
[
dataType
].
bytes
;
if
(
TSDB_DATA_TYPE_TIMESTAMP
==
dataType
)
{
...
...
@@ -306,10 +305,12 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
return
(
SNode
*
)
val
;
}
SNode
*
createPlaceholderValueNode
(
SAstCreateContext
*
pCxt
)
{
SNode
*
createPlaceholderValueNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLiteral
)
{
SValueNode
*
val
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
CHECK_OUT_OF_MEM
(
val
);
// todo
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
CHECK_OUT_OF_MEM
(
val
->
literal
);
val
->
placeholderNo
=
pCxt
->
placeholderNo
++
;
return
(
SNode
*
)
val
;
}
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
091b5124
...
...
@@ -50,7 +50,6 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
goto
abort_parse
;
}
case
TK_NK_QUESTION
:
case
TK_NK_ILLEGAL
:
{
snprintf
(
cxt
.
pQueryCxt
->
pMsg
,
cxt
.
pQueryCxt
->
msgLen
,
"unrecognized token:
\"
%s
\"
"
,
t0
.
z
);
cxt
.
valid
=
false
;
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
091b5124
...
...
@@ -15,8 +15,8 @@
#include "parInsertData.h"
#include "parInt.h"
#include "parUtil.h"
#include "parToken.h"
#include "parUtil.h"
#include "tglobal.h"
#include "ttime.h"
#include "ttypes.h"
...
...
@@ -50,7 +50,7 @@
typedef
struct
SInsertParseContext
{
SParseContext
*
pComCxt
;
// input
char
*
pSql
;
// input
char
*
pSql
;
// input
SMsgBuf
msg
;
// input
STableMeta
*
pTableMeta
;
// each table
SParsedDataColInfo
tags
;
// each table
...
...
@@ -65,7 +65,7 @@ typedef struct SInsertParseContext {
SVnodeModifOpStmt
*
pOutput
;
}
SInsertParseContext
;
typedef
int32_t
(
*
_row_append_fn_t
)(
SMsgBuf
*
pMsgBuf
,
const
void
*
value
,
int32_t
len
,
void
*
param
);
typedef
int32_t
(
*
_row_append_fn_t
)(
SMsgBuf
*
pMsgBuf
,
const
void
*
value
,
int32_t
len
,
void
*
param
);
static
uint8_t
TRUE_VALUE
=
(
uint8_t
)
TSDB_TRUE
;
static
uint8_t
FALSE_VALUE
=
(
uint8_t
)
TSDB_FALSE
;
...
...
@@ -187,7 +187,7 @@ static int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pPar
int32_t
tbLen
=
pTableName
->
n
-
dbLen
-
1
;
char
tbname
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
strncpy
(
tbname
,
p
+
1
,
tbLen
);
/*tbLen = */
strdequote
(
tbname
);
/*tbLen = */
strdequote
(
tbname
);
code
=
tNameFromString
(
pName
,
tbname
,
T_NAME_TABLE
);
if
(
code
!=
0
)
{
...
...
@@ -228,25 +228,23 @@ static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool
SName
name
=
{
0
};
createSName
(
&
name
,
pTname
,
pBasicCtx
,
&
pCxt
->
msg
);
if
(
isStb
)
{
CHECK_CODE
(
catalogGetSTableMeta
(
pBasicCtx
->
pCatalog
,
pBasicCtx
->
pTransporter
,
&
pBasicCtx
->
mgmtEpSet
,
&
name
,
&
pCxt
->
pTableMeta
));
CHECK_CODE
(
catalogGetSTableMeta
(
pBasicCtx
->
pCatalog
,
pBasicCtx
->
pTransporter
,
&
pBasicCtx
->
mgmtEpSet
,
&
name
,
&
pCxt
->
pTableMeta
));
}
else
{
CHECK_CODE
(
catalogGetTableMeta
(
pBasicCtx
->
pCatalog
,
pBasicCtx
->
pTransporter
,
&
pBasicCtx
->
mgmtEpSet
,
&
name
,
&
pCxt
->
pTableMeta
));
CHECK_CODE
(
catalogGetTableMeta
(
pBasicCtx
->
pCatalog
,
pBasicCtx
->
pTransporter
,
&
pBasicCtx
->
mgmtEpSet
,
&
name
,
&
pCxt
->
pTableMeta
));
}
SVgroupInfo
vg
;
CHECK_CODE
(
catalogGetTableHashVgroup
(
pBasicCtx
->
pCatalog
,
pBasicCtx
->
pTransporter
,
&
pBasicCtx
->
mgmtEpSet
,
&
name
,
&
vg
));
CHECK_CODE
(
catalogGetTableHashVgroup
(
pBasicCtx
->
pCatalog
,
pBasicCtx
->
pTransporter
,
&
pBasicCtx
->
mgmtEpSet
,
&
name
,
&
vg
));
CHECK_CODE
(
taosHashPut
(
pCxt
->
pVgroupsHashObj
,
(
const
char
*
)
&
vg
.
vgId
,
sizeof
(
vg
.
vgId
),
(
char
*
)
&
vg
,
sizeof
(
vg
)));
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
getTableMeta
(
SInsertParseContext
*
pCxt
,
SToken
*
pTname
)
{
return
getTableMetaImpl
(
pCxt
,
pTname
,
false
);
}
static
int32_t
getSTableMeta
(
SInsertParseContext
*
pCxt
,
SToken
*
pTname
)
{
return
getTableMetaImpl
(
pCxt
,
pTname
,
true
);
}
static
int32_t
getTableMeta
(
SInsertParseContext
*
pCxt
,
SToken
*
pTname
)
{
return
getTableMetaImpl
(
pCxt
,
pTname
,
false
);
}
static
int32_t
getSTableMeta
(
SInsertParseContext
*
pCxt
,
SToken
*
pTname
)
{
return
getTableMetaImpl
(
pCxt
,
pTname
,
true
);
}
static
int32_t
findCol
(
SToken
*
pColname
,
int32_t
start
,
int32_t
end
,
SSchema
*
pSchema
)
{
while
(
start
<
end
)
{
...
...
@@ -301,13 +299,13 @@ static int32_t buildOutput(SInsertParseContext* pCxt) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
checkTimestamp
(
STableDataBlocks
*
pDataBlocks
,
const
char
*
start
)
{
static
int32_t
checkTimestamp
(
STableDataBlocks
*
pDataBlocks
,
const
char
*
start
)
{
// once the data block is disordered, we do NOT keep previous timestamp any more
if
(
!
pDataBlocks
->
ordered
)
{
return
TSDB_CODE_SUCCESS
;
}
TSKEY
k
=
*
(
TSKEY
*
)
start
;
TSKEY
k
=
*
(
TSKEY
*
)
start
;
if
(
k
<=
pDataBlocks
->
prevTS
)
{
pDataBlocks
->
ordered
=
false
;
}
...
...
@@ -316,7 +314,7 @@ static int32_t checkTimestamp(STableDataBlocks *pDataBlocks, const char *start)
return
TSDB_CODE_SUCCESS
;
}
static
int
parseTime
(
char
**
end
,
SToken
*
pToken
,
int16_t
timePrec
,
int64_t
*
time
,
SMsgBuf
*
pMsgBuf
)
{
static
int
parseTime
(
char
**
end
,
SToken
*
pToken
,
int16_t
timePrec
,
int64_t
*
time
,
SMsgBuf
*
pMsgBuf
)
{
int32_t
index
=
0
;
SToken
sToken
;
int64_t
interval
;
...
...
@@ -340,7 +338,7 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
for
(
int
k
=
pToken
->
n
;
pToken
->
z
[
k
]
!=
'\0'
;
k
++
)
{
if
(
pToken
->
z
[
k
]
==
' '
||
pToken
->
z
[
k
]
==
'\t'
)
continue
;
if
(
pToken
->
z
[
k
]
==
'('
&&
pToken
->
z
[
k
+
1
]
==
')'
)
{
//
for insert NOW()/TODAY()
if
(
pToken
->
z
[
k
]
==
'('
&&
pToken
->
z
[
k
+
1
]
==
')'
)
{
//
for insert NOW()/TODAY()
*
end
=
pTokenEnd
=
&
pToken
->
z
[
k
+
2
];
k
++
;
continue
;
...
...
@@ -391,8 +389,10 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
}
static
FORCE_INLINE
int32_t
checkAndTrimValue
(
SToken
*
pToken
,
uint32_t
type
,
char
*
tmpTokenBuf
,
SMsgBuf
*
pMsgBuf
)
{
if
((
pToken
->
type
!=
TK_NOW
&&
pToken
->
type
!=
TK_TODAY
&&
pToken
->
type
!=
TK_NK_INTEGER
&&
pToken
->
type
!=
TK_NK_STRING
&&
pToken
->
type
!=
TK_NK_FLOAT
&&
pToken
->
type
!=
TK_NK_BOOL
&&
pToken
->
type
!=
TK_NULL
&&
pToken
->
type
!=
TK_NK_HEX
&&
pToken
->
type
!=
TK_NK_OCT
&&
pToken
->
type
!=
TK_NK_BIN
)
||
if
((
pToken
->
type
!=
TK_NOW
&&
pToken
->
type
!=
TK_TODAY
&&
pToken
->
type
!=
TK_NK_INTEGER
&&
pToken
->
type
!=
TK_NK_STRING
&&
pToken
->
type
!=
TK_NK_FLOAT
&&
pToken
->
type
!=
TK_NK_BOOL
&&
pToken
->
type
!=
TK_NULL
&&
pToken
->
type
!=
TK_NK_HEX
&&
pToken
->
type
!=
TK_NK_OCT
&&
pToken
->
type
!=
TK_NK_BIN
)
||
(
pToken
->
n
==
0
)
||
(
pToken
->
type
==
TK_NK_RP
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"invalid data or symbol"
,
pToken
->
z
);
}
...
...
@@ -431,12 +431,12 @@ static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, cha
return
TSDB_CODE_SUCCESS
;
}
static
bool
isNullStr
(
SToken
*
pToken
)
{
static
bool
isNullStr
(
SToken
*
pToken
)
{
return
(
pToken
->
type
==
TK_NULL
)
||
((
pToken
->
type
==
TK_NK_STRING
)
&&
(
pToken
->
n
!=
0
)
&&
(
strncasecmp
(
TSDB_DATA_NULL_STR_L
,
pToken
->
z
,
pToken
->
n
)
==
0
));
}
static
FORCE_INLINE
int32_t
toDouble
(
SToken
*
pToken
,
double
*
value
,
char
**
endPtr
)
{
static
FORCE_INLINE
int32_t
toDouble
(
SToken
*
pToken
,
double
*
value
,
char
**
endPtr
)
{
errno
=
0
;
*
value
=
strtold
(
pToken
->
z
,
endPtr
);
...
...
@@ -448,9 +448,10 @@ static FORCE_INLINE int32_t toDouble(SToken *pToken, double *value, char **endPt
return
pToken
->
type
;
}
static
int32_t
parseValueToken
(
char
**
end
,
SToken
*
pToken
,
SSchema
*
pSchema
,
int16_t
timePrec
,
char
*
tmpTokenBuf
,
_row_append_fn_t
func
,
void
*
param
,
SMsgBuf
*
pMsgBuf
)
{
static
int32_t
parseValueToken
(
char
**
end
,
SToken
*
pToken
,
SSchema
*
pSchema
,
int16_t
timePrec
,
char
*
tmpTokenBuf
,
_row_append_fn_t
func
,
void
*
param
,
SMsgBuf
*
pMsgBuf
)
{
int64_t
iv
;
char
*
endptr
=
NULL
;
char
*
endptr
=
NULL
;
bool
isSigned
=
false
;
int32_t
code
=
checkAndTrimValue
(
pToken
,
pSchema
->
type
,
tmpTokenBuf
,
pMsgBuf
);
...
...
@@ -497,7 +498,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
return
func
(
pMsgBuf
,
&
tmpVal
,
pSchema
->
bytes
,
param
);
}
case
TSDB_DATA_TYPE_UTINYINT
:{
case
TSDB_DATA_TYPE_UTINYINT
:
{
if
(
TSDB_CODE_SUCCESS
!=
toInteger
(
pToken
->
z
,
pToken
->
n
,
10
,
&
iv
,
&
isSigned
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"invalid unsigned tinyint data"
,
pToken
->
z
);
}
else
if
(
!
IS_VALID_UTINYINT
(
iv
))
{
...
...
@@ -571,7 +572,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
if
(
TK_NK_ILLEGAL
==
toDouble
(
pToken
,
&
dv
,
&
endptr
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"illegal float data"
,
pToken
->
z
);
}
if
(((
dv
==
HUGE_VAL
||
dv
==
-
HUGE_VAL
)
&&
errno
==
ERANGE
)
||
dv
>
FLT_MAX
||
dv
<
-
FLT_MAX
||
isinf
(
dv
)
||
isnan
(
dv
))
{
if
(((
dv
==
HUGE_VAL
||
dv
==
-
HUGE_VAL
)
&&
errno
==
ERANGE
)
||
dv
>
FLT_MAX
||
dv
<
-
FLT_MAX
||
isinf
(
dv
)
||
isnan
(
dv
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"illegal float data"
,
pToken
->
z
);
}
float
tmpVal
=
(
float
)
dv
;
...
...
@@ -729,13 +731,13 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
}
typedef
struct
SKvParam
{
SKVRowBuilder
*
builder
;
SSchema
*
schema
;
SKVRowBuilder
*
builder
;
SSchema
*
schema
;
char
buf
[
TSDB_MAX_TAGS_LEN
];
}
SKvParam
;
static
int32_t
KvRowAppend
(
SMsgBuf
*
pMsgBuf
,
const
void
*
value
,
int32_t
len
,
void
*
param
)
{
SKvParam
*
pa
=
(
SKvParam
*
)
param
;
static
int32_t
KvRowAppend
(
SMsgBuf
*
pMsgBuf
,
const
void
*
value
,
int32_t
len
,
void
*
param
)
{
SKvParam
*
pa
=
(
SKvParam
*
)
param
;
int8_t
type
=
pa
->
schema
->
type
;
int16_t
colId
=
pa
->
schema
->
colId
;
...
...
@@ -749,7 +751,8 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi
if
(
!
taosMbsToUcs4
(
value
,
len
,
(
TdUcs4
*
)
varDataVal
(
pa
->
buf
),
pa
->
schema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
char
buf
[
512
]
=
{
0
};
snprintf
(
buf
,
tListLen
(
buf
),
"%s"
,
strerror
(
errno
));
return
buildSyntaxErrMsg
(
pMsgBuf
,
buf
,
value
);;
return
buildSyntaxErrMsg
(
pMsgBuf
,
buf
,
value
);
;
}
varDataSetLen
(
pa
->
buf
,
output
);
...
...
@@ -765,7 +768,6 @@ static int32_t buildCreateTbReq(SInsertParseContext* pCxt, const SName* pName, S
char
dbFName
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
pName
,
dbFName
);
pCxt
->
createTblReq
.
type
=
TD_CHILD_TABLE
;
pCxt
->
createTblReq
.
dbFName
=
strdup
(
dbFName
);
pCxt
->
createTblReq
.
name
=
strdup
(
pName
->
tname
);
pCxt
->
createTblReq
.
ctbCfg
.
suid
=
pCxt
->
pTableMeta
->
suid
;
pCxt
->
createTblReq
.
ctbCfg
.
pTag
=
row
;
...
...
@@ -786,7 +788,8 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
NEXT_TOKEN_WITH_PREV
(
pCxt
->
pSql
,
sToken
);
SSchema
*
pTagSchema
=
&
pSchema
[
pCxt
->
tags
.
boundColumns
[
i
]
-
1
];
// colId starts with 1
param
.
schema
=
pTagSchema
;
CHECK_CODE
(
parseValueToken
(
&
pCxt
->
pSql
,
&
sToken
,
pTagSchema
,
precision
,
tmpTokenBuf
,
KvRowAppend
,
&
param
,
&
pCxt
->
msg
));
CHECK_CODE
(
parseValueToken
(
&
pCxt
->
pSql
,
&
sToken
,
pTagSchema
,
precision
,
tmpTokenBuf
,
KvRowAppend
,
&
param
,
&
pCxt
->
msg
));
}
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
pCxt
->
tagsBuilder
);
...
...
@@ -864,7 +867,8 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
return
TSDB_CODE_SUCCESS
;
}
static
int
parseOneRow
(
SInsertParseContext
*
pCxt
,
STableDataBlocks
*
pDataBlocks
,
int16_t
timePrec
,
int32_t
*
len
,
char
*
tmpTokenBuf
)
{
static
int
parseOneRow
(
SInsertParseContext
*
pCxt
,
STableDataBlocks
*
pDataBlocks
,
int16_t
timePrec
,
int32_t
*
len
,
char
*
tmpTokenBuf
)
{
SParsedDataColInfo
*
spd
=
&
pDataBlocks
->
boundColumnInfo
;
SRowBuilder
*
pBuilder
=
&
pDataBlocks
->
rowBuilder
;
STSRow
*
row
=
(
STSRow
*
)(
pDataBlocks
->
pData
+
pDataBlocks
->
size
);
// skip the SSubmitBlk header
...
...
@@ -885,7 +889,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks,
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
==
pSchema
->
colId
)
{
TSKEY
tsKey
=
TD_ROW_KEY
(
row
);
if
(
checkTimestamp
(
pDataBlocks
,
(
const
char
*
)
&
tsKey
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
checkTimestamp
(
pDataBlocks
,
(
const
char
*
)
&
tsKey
)
!=
TSDB_CODE_SUCCESS
)
{
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
"client time/server time can not be mixed up"
,
sToken
.
z
);
return
TSDB_CODE_TSC_INVALID_TIME_STAMP
;
}
...
...
@@ -934,7 +938,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo
int32_t
len
=
0
;
CHECK_CODE
(
parseOneRow
(
pCxt
,
pDataBlock
,
tinfo
.
precision
,
&
len
,
tmpTokenBuf
));
pDataBlock
->
size
+=
extendedRowSize
;
//
len;
pDataBlock
->
size
+=
extendedRowSize
;
//
len;
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
if
(
TK_NK_RP
!=
sToken
.
type
)
{
...
...
@@ -957,7 +961,7 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da
int32_t
numOfRows
=
0
;
CHECK_CODE
(
parseValues
(
pCxt
,
dataBuf
,
maxNumOfRows
,
&
numOfRows
));
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)(
dataBuf
->
pData
);
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)(
dataBuf
->
pData
);
if
(
TSDB_CODE_SUCCESS
!=
setBlockInfo
(
pBlocks
,
dataBuf
,
numOfRows
))
{
return
buildInvalidOperationMsg
(
&
pCxt
->
msg
,
"too many rows in sql, total number of rows should be less than 32767"
);
}
...
...
@@ -968,7 +972,6 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da
}
static
void
destroyCreateSubTbReq
(
SVCreateTbReq
*
pReq
)
{
taosMemoryFreeClear
(
pReq
->
dbFName
);
taosMemoryFreeClear
(
pReq
->
name
);
taosMemoryFreeClear
(
pReq
->
ctbCfg
.
pTag
);
}
...
...
@@ -1023,7 +1026,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
// no data in the sql string anymore.
if
(
sToken
.
n
==
0
)
{
if
(
0
==
pCxt
->
totalNum
)
{
return
buildInvalidOperationMsg
(
&
pCxt
->
msg
,
"no data in sql"
);;
return
buildInvalidOperationMsg
(
&
pCxt
->
msg
,
"no data in sql"
);
;
}
break
;
}
...
...
@@ -1039,9 +1043,10 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
CHECK_CODE
(
getTableMeta
(
pCxt
,
&
tbnameToken
));
}
STableDataBlocks
*
dataBuf
=
NULL
;
STableDataBlocks
*
dataBuf
=
NULL
;
CHECK_CODE
(
getDataBlockFromList
(
pCxt
->
pTableBlockHashObj
,
pCxt
->
pTableMeta
->
uid
,
TSDB_DEFAULT_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
getTableInfo
(
pCxt
->
pTableMeta
).
rowSize
,
pCxt
->
pTableMeta
,
&
dataBuf
,
NULL
,
&
pCxt
->
createTblReq
));
sizeof
(
SSubmitBlk
),
getTableInfo
(
pCxt
->
pTableMeta
).
rowSize
,
pCxt
->
pTableMeta
,
&
dataBuf
,
NULL
,
&
pCxt
->
createTblReq
));
if
(
TK_NK_LP
==
sToken
.
type
)
{
// pSql -> field1_name, ...)
...
...
@@ -1071,7 +1076,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
"keyword VALUES or FILE is expected"
,
sToken
.
z
);
}
// merge according to vgId
if
(
!
TSDB_QUERY_HAS_TYPE
(
pCxt
->
pOutput
->
insertType
,
TSDB_QUERY_TYPE_STMT_INSERT
)
&&
taosHashGetSize
(
pCxt
->
pTableBlockHashObj
)
>
0
)
{
if
(
!
TSDB_QUERY_HAS_TYPE
(
pCxt
->
pOutput
->
insertType
,
TSDB_QUERY_TYPE_STMT_INSERT
)
&&
taosHashGetSize
(
pCxt
->
pTableBlockHashObj
)
>
0
)
{
CHECK_CODE
(
mergeTableDataBlocks
(
pCxt
->
pTableBlockHashObj
,
pCxt
->
pOutput
->
payloadType
,
&
pCxt
->
pVgDataBlocks
));
}
return
buildOutput
(
pCxt
);
...
...
@@ -1086,18 +1092,17 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
)
{
SInsertParseContext
context
=
{
.
pComCxt
=
pContext
,
.
pSql
=
(
char
*
)
pContext
->
pSql
,
.
pSql
=
(
char
*
)
pContext
->
pSql
,
.
msg
=
{.
buf
=
pContext
->
pMsg
,
.
len
=
pContext
->
msgLen
},
.
pTableMeta
=
NULL
,
.
pVgroupsHashObj
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
false
),
.
pTableBlockHashObj
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
),
.
pSubTableHashObj
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_VARCHAR
),
true
,
false
),
.
totalNum
=
0
,
.
pOutput
=
(
SVnodeModifOpStmt
*
)
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
)
};
.
pOutput
=
(
SVnodeModifOpStmt
*
)
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
)};
if
(
NULL
==
context
.
pVgroupsHashObj
||
NULL
==
context
.
pTableBlockHashObj
||
NULL
==
context
.
p
SubTableHashObj
||
NULL
==
context
.
p
Output
)
{
if
(
NULL
==
context
.
pVgroupsHashObj
||
NULL
==
context
.
pTableBlockHashObj
||
NULL
==
context
.
pSubTableHashObj
||
NULL
==
context
.
pOutput
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
091b5124
...
...
@@ -403,6 +403,9 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
static
EDealRes
translateValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
)
{
uint8_t
precision
=
(
NULL
!=
pCxt
->
pCurrStmt
?
pCxt
->
pCurrStmt
->
precision
:
pVal
->
node
.
resType
.
precision
);
pVal
->
node
.
resType
.
precision
=
precision
;
if
(
pVal
->
placeholderNo
>
0
)
{
return
DEAL_RES_CONTINUE
;
}
if
(
pVal
->
isDuration
)
{
if
(
parseNatualDuration
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
&
pVal
->
datum
.
i
,
&
pVal
->
unit
,
precision
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -492,8 +495,10 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pRight
))
->
aliasName
);
}
if
((
TSDB_DATA_TYPE_TIMESTAMP
==
ldt
.
type
&&
TSDB_DATA_TYPE_BIGINT
==
rdt
.
type
)
||
(
TSDB_DATA_TYPE_TIMESTAMP
==
rdt
.
type
&&
TSDB_DATA_TYPE_BIGINT
==
ldt
.
type
))
{
if
((
TSDB_DATA_TYPE_TIMESTAMP
==
ldt
.
type
&&
IS_INTEGER_TYPE
(
rdt
.
type
))
||
(
TSDB_DATA_TYPE_TIMESTAMP
==
rdt
.
type
&&
IS_INTEGER_TYPE
(
ldt
.
type
))
||
(
TSDB_DATA_TYPE_TIMESTAMP
==
ldt
.
type
&&
TSDB_DATA_TYPE_BOOL
==
rdt
.
type
)
||
(
TSDB_DATA_TYPE_TIMESTAMP
==
rdt
.
type
&&
TSDB_DATA_TYPE_BOOL
==
ldt
.
type
))
{
pOp
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
;
}
else
{
...
...
@@ -833,7 +838,8 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) {
return
NULL
;
}
pFunc
->
pParameterList
=
nodesMakeList
();
if
(
NULL
==
pFunc
->
pParameterList
||
TSDB_CODE_SUCCESS
!=
nodesListStrictAppend
(
pFunc
->
pParameterList
,
nodesCloneNode
(
pExpr
)))
{
if
(
NULL
==
pFunc
->
pParameterList
||
TSDB_CODE_SUCCESS
!=
nodesListStrictAppend
(
pFunc
->
pParameterList
,
nodesCloneNode
(
pExpr
)))
{
nodesDestroyNode
(
pFunc
);
return
NULL
;
}
...
...
@@ -884,11 +890,13 @@ static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SN
}
static
bool
isStar
(
SNode
*
pNode
)
{
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
&&
(
'\0'
==
((
SColumnNode
*
)
pNode
)
->
tableAlias
[
0
])
&&
(
0
==
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
"*"
));
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
&&
(
'\0'
==
((
SColumnNode
*
)
pNode
)
->
tableAlias
[
0
])
&&
(
0
==
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
"*"
));
}
static
bool
isTableStar
(
SNode
*
pNode
)
{
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
&&
(
'\0'
!=
((
SColumnNode
*
)
pNode
)
->
tableAlias
[
0
])
&&
(
0
==
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
"*"
));
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
&&
(
'\0'
!=
((
SColumnNode
*
)
pNode
)
->
tableAlias
[
0
])
&&
(
0
==
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
"*"
));
}
static
int32_t
createMultiResFuncsParas
(
STranslateContext
*
pCxt
,
SNodeList
*
pSrcParas
,
SNodeList
**
pOutput
)
{
...
...
@@ -1123,9 +1131,7 @@ static int32_t translateGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
return
translateExprList
(
pCxt
,
pSelect
->
pGroupByList
);
}
static
bool
isValTimeUnit
(
char
unit
)
{
return
(
'n'
==
unit
||
'y'
==
unit
);
}
static
bool
isValTimeUnit
(
char
unit
)
{
return
(
'n'
==
unit
||
'y'
==
unit
);
}
static
int64_t
getMonthsFromTimeVal
(
int64_t
val
,
int32_t
fromPrecision
,
char
unit
)
{
int64_t
days
=
convertTimeFromPrecisionToUnit
(
val
,
fromPrecision
,
'd'
);
...
...
@@ -1169,7 +1175,8 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode*
}
bool
fixed
=
!
isValTimeUnit
(
pOffset
->
unit
)
&&
!
valInter
;
if
((
fixed
&&
pOffset
->
datum
.
i
>=
pInter
->
datum
.
i
)
||
(
!
fixed
&&
getMonthsFromTimeVal
(
pOffset
->
datum
.
i
,
precision
,
pOffset
->
unit
)
>=
getMonthsFromTimeVal
(
pInter
->
datum
.
i
,
precision
,
pInter
->
unit
)))
{
(
!
fixed
&&
getMonthsFromTimeVal
(
pOffset
->
datum
.
i
,
precision
,
pOffset
->
unit
)
>=
getMonthsFromTimeVal
(
pInter
->
datum
.
i
,
precision
,
pInter
->
unit
)))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG
);
}
}
...
...
@@ -1362,7 +1369,8 @@ static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, SVal
if
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
pVal
))
{
return
pCxt
->
errCode
;
}
if
(
pVal
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pVal
->
unit
&&
TIME_UNIT_HOUR
!=
pVal
->
unit
&&
TIME_UNIT_DAY
!=
pVal
->
unit
))
{
if
(
pVal
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pVal
->
unit
&&
TIME_UNIT_HOUR
!=
pVal
->
unit
&&
TIME_UNIT_DAY
!=
pVal
->
unit
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_OPTION_UNIT
,
pName
,
pVal
->
unit
);
}
int64_t
val
=
getBigintFromValueNode
(
pVal
);
...
...
@@ -1457,9 +1465,12 @@ static int32_t checkKeepOption(STranslateContext* pCxt, SNodeList* pKeep) {
SValueNode
*
pKeep0
=
(
SValueNode
*
)
nodesListGetNode
(
pKeep
,
0
);
SValueNode
*
pKeep1
=
(
SValueNode
*
)
nodesListGetNode
(
pKeep
,
1
);
SValueNode
*
pKeep2
=
(
SValueNode
*
)
nodesListGetNode
(
pKeep
,
2
);
if
((
pKeep0
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pKeep0
->
unit
&&
TIME_UNIT_HOUR
!=
pKeep0
->
unit
&&
TIME_UNIT_DAY
!=
pKeep0
->
unit
))
||
(
pKeep1
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pKeep1
->
unit
&&
TIME_UNIT_HOUR
!=
pKeep1
->
unit
&&
TIME_UNIT_DAY
!=
pKeep1
->
unit
))
||
(
pKeep2
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pKeep2
->
unit
&&
TIME_UNIT_HOUR
!=
pKeep2
->
unit
&&
TIME_UNIT_DAY
!=
pKeep2
->
unit
)))
{
if
((
pKeep0
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pKeep0
->
unit
&&
TIME_UNIT_HOUR
!=
pKeep0
->
unit
&&
TIME_UNIT_DAY
!=
pKeep0
->
unit
))
||
(
pKeep1
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pKeep1
->
unit
&&
TIME_UNIT_HOUR
!=
pKeep1
->
unit
&&
TIME_UNIT_DAY
!=
pKeep1
->
unit
))
||
(
pKeep2
->
isDuration
&&
(
TIME_UNIT_MINUTE
!=
pKeep2
->
unit
&&
TIME_UNIT_HOUR
!=
pKeep2
->
unit
&&
TIME_UNIT_DAY
!=
pKeep2
->
unit
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_KEEP_UNIT
,
pKeep0
->
unit
,
pKeep1
->
unit
,
pKeep2
->
unit
);
}
...
...
@@ -1516,7 +1527,8 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, SDatabaseOptions* p
code
=
checkRangeOption
(
pCxt
,
"compression"
,
pOptions
->
pCompressionLevel
,
TSDB_MIN_COMP_LEVEL
,
TSDB_MAX_COMP_LEVEL
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkRangeOption
(
pCxt
,
"daysPerFile"
,
pOptions
->
pDaysPerFile
,
TSDB_MIN_DAYS_PER_FILE
,
TSDB_MAX_DAYS_PER_FILE
);
code
=
checkRangeOption
(
pCxt
,
"daysPerFile"
,
pOptions
->
pDaysPerFile
,
TSDB_MIN_DAYS_PER_FILE
,
TSDB_MAX_DAYS_PER_FILE
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkRangeOption
(
pCxt
,
"fsyncPeriod"
,
pOptions
->
pFsyncPeriod
,
TSDB_MIN_FSYNC_PERIOD
,
TSDB_MAX_FSYNC_PERIOD
);
...
...
@@ -1569,7 +1581,7 @@ static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt*
return
checkDatabaseOptions
(
pCxt
,
pStmt
->
pOptions
);
}
typedef
int32_t
(
*
FSerializeFunc
)(
void
*
pBuf
,
int32_t
bufLen
,
void
*
pReq
);
typedef
int32_t
(
*
FSerializeFunc
)(
void
*
pBuf
,
int32_t
bufLen
,
void
*
pReq
);
static
int32_t
buildCmdMsg
(
STranslateContext
*
pCxt
,
int16_t
msgType
,
FSerializeFunc
func
,
void
*
pReq
)
{
pCxt
->
pCmdMsg
=
taosMemoryMalloc
(
sizeof
(
SCmdMsgInfo
));
...
...
@@ -2174,7 +2186,8 @@ static int16_t getCreateComponentNodeMsgType(ENodeType type) {
static
int32_t
translateCreateComponentNode
(
STranslateContext
*
pCxt
,
SCreateComponentNodeStmt
*
pStmt
)
{
SMCreateQnodeReq
createReq
=
{.
dnodeId
=
pStmt
->
dnodeId
};
return
buildCmdMsg
(
pCxt
,
getCreateComponentNodeMsgType
(
nodeType
(
pStmt
)),
(
FSerializeFunc
)
tSerializeSCreateDropMQSBNodeReq
,
&
createReq
);
return
buildCmdMsg
(
pCxt
,
getCreateComponentNodeMsgType
(
nodeType
(
pStmt
)),
(
FSerializeFunc
)
tSerializeSCreateDropMQSBNodeReq
,
&
createReq
);
}
static
int16_t
getDropComponentNodeMsgType
(
ENodeType
type
)
{
...
...
@@ -2195,7 +2208,8 @@ static int16_t getDropComponentNodeMsgType(ENodeType type) {
static
int32_t
translateDropComponentNode
(
STranslateContext
*
pCxt
,
SDropComponentNodeStmt
*
pStmt
)
{
SDDropQnodeReq
dropReq
=
{.
dnodeId
=
pStmt
->
dnodeId
};
return
buildCmdMsg
(
pCxt
,
getDropComponentNodeMsgType
(
nodeType
(
pStmt
)),
(
FSerializeFunc
)
tSerializeSCreateDropMQSBNodeReq
,
&
dropReq
);
return
buildCmdMsg
(
pCxt
,
getDropComponentNodeMsgType
(
nodeType
(
pStmt
)),
(
FSerializeFunc
)
tSerializeSCreateDropMQSBNodeReq
,
&
dropReq
);
}
static
int32_t
translateCreateTopic
(
STranslateContext
*
pCxt
,
SCreateTopicStmt
*
pStmt
)
{
...
...
@@ -2299,11 +2313,13 @@ static int32_t translateCreateStream(STranslateContext* pCxt, SCreateStreamStmt*
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pStmt
->
pOptions
->
pWatermark
)
{
code
=
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
(
SValueNode
*
)
pStmt
->
pOptions
->
pWatermark
))
?
pCxt
->
errCode
:
TSDB_CODE_SUCCESS
;
code
=
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
(
SValueNode
*
)
pStmt
->
pOptions
->
pWatermark
))
?
pCxt
->
errCode
:
TSDB_CODE_SUCCESS
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
createReq
.
triggerType
=
pStmt
->
pOptions
->
triggerType
;
createReq
.
watermark
=
(
NULL
!=
pStmt
->
pOptions
->
pWatermark
?
((
SValueNode
*
)
pStmt
->
pOptions
->
pWatermark
)
->
datum
.
i
:
0
);
createReq
.
watermark
=
(
NULL
!=
pStmt
->
pOptions
->
pWatermark
?
((
SValueNode
*
)
pStmt
->
pOptions
->
pWatermark
)
->
datum
.
i
:
0
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -2455,9 +2471,7 @@ static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* nu
return
TSDB_CODE_SUCCESS
;
}
static
int8_t
extractResultTsPrecision
(
const
SSelectStmt
*
pSelect
)
{
return
pSelect
->
precision
;
}
static
int8_t
extractResultTsPrecision
(
const
SSelectStmt
*
pSelect
)
{
return
pSelect
->
precision
;
}
static
int32_t
extractExplainResultSchema
(
int32_t
*
numOfCols
,
SSchema
**
pSchema
)
{
*
numOfCols
=
1
;
...
...
@@ -2720,16 +2734,19 @@ typedef struct SVgroupTablesBatch {
char
dbName
[
TSDB_DB_NAME_LEN
];
}
SVgroupTablesBatch
;
static
void
toSchemaEx
(
const
SColumnDefNode
*
pCol
,
col_id_t
colId
,
SSchemaEx
*
pSchema
)
{
static
void
toSchemaEx
(
const
SColumnDefNode
*
pCol
,
col_id_t
colId
,
SSchema
*
pSchema
)
{
int8_t
flags
=
0
;
if
(
pCol
->
sma
)
{
flags
|=
SCHEMA_SMA_ON
;
}
pSchema
->
colId
=
colId
;
pSchema
->
type
=
pCol
->
dataType
.
type
;
pSchema
->
bytes
=
calcTypeBytes
(
pCol
->
dataType
);
pSchema
->
sma
=
pCol
->
sma
?
TSDB_BSMA_TYPE_LATEST
:
TSDB_BSMA_TYPE_NONE
;
pSchema
->
flags
=
flags
;
strcpy
(
pSchema
->
name
,
pCol
->
colName
);
}
static
void
destroyCreateTbReq
(
SVCreateTbReq
*
pReq
)
{
taosMemoryFreeClear
(
pReq
->
dbFName
);
taosMemoryFreeClear
(
pReq
->
name
);
taosMemoryFreeClear
(
pReq
->
ntbCfg
.
pSchema
);
}
...
...
@@ -2766,10 +2783,9 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
SVCreateTbReq
req
=
{
0
};
req
.
type
=
TD_NORMAL_TABLE
;
req
.
dbFName
=
strdup
(
dbFName
);
req
.
name
=
strdup
(
pStmt
->
tableName
);
req
.
ntbCfg
.
nCols
=
LIST_LENGTH
(
pStmt
->
pCols
);
req
.
ntbCfg
.
pSchema
=
taosMemoryCalloc
(
req
.
ntbCfg
.
nCols
,
sizeof
(
SSchema
Ex
));
req
.
ntbCfg
.
pSchema
=
taosMemoryCalloc
(
req
.
ntbCfg
.
nCols
,
sizeof
(
SSchema
));
if
(
NULL
==
req
.
name
||
NULL
==
req
.
ntbCfg
.
pSchema
)
{
destroyCreateTbReq
(
&
req
);
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -2825,7 +2841,6 @@ static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) {
size_t
size
=
taosArrayGetSize
(
pTbBatch
->
req
.
pArray
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SVCreateTbReq
*
pTableReq
=
taosArrayGet
(
pTbBatch
->
req
.
pArray
,
i
);
taosMemoryFreeClear
(
pTableReq
->
dbFName
);
taosMemoryFreeClear
(
pTableReq
->
name
);
if
(
pTableReq
->
type
==
TSDB_NORMAL_TABLE
)
{
...
...
@@ -2911,7 +2926,6 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, c
struct
SVCreateTbReq
req
=
{
0
};
req
.
type
=
TD_CHILD_TABLE
;
req
.
dbFName
=
strdup
(
dbFName
);
req
.
name
=
strdup
(
pTableName
);
req
.
ctbCfg
.
suid
=
suid
;
req
.
ctbCfg
.
pTag
=
row
;
...
...
@@ -3174,7 +3188,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pQuery
->
precision
=
extractResultTsPrecision
((
SSelectStmt
*
)
pQuery
->
pRoot
);
pQuery
->
precision
=
extractResultTsPrecision
((
SSelectStmt
*
)
pQuery
->
pRoot
);
}
if
(
NULL
!=
pCxt
->
pDbs
)
{
...
...
source/libs/parser/src/sql.c
浏览文件 @
091b5124
此差异已折叠。
点击以展开。
source/libs/parser/test/parserTestUtil.h
浏览文件 @
091b5124
...
...
@@ -13,4 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PARSER_TEST_UTIL_H
#define PARSER_TEST_UTIL_H
extern
bool
g_isDump
;
#endif // PARSER_TEST_UTIL_H
source/libs/planner/src/planner.c
浏览文件 @
091b5124
...
...
@@ -17,6 +17,31 @@
#include "planInt.h"
typedef
struct
SCollectPlaceholderValuesCxt
{
int32_t
errCode
;
SNodeList
*
pValues
;
}
SCollectPlaceholderValuesCxt
;
static
EDealRes
collectPlaceholderValuesImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
pNode
)
&&
((
SValueNode
*
)
pNode
)
->
placeholderNo
>
0
)
{
SCollectPlaceholderValuesCxt
*
pCxt
=
pContext
;
pCxt
->
errCode
=
nodesListMakeAppend
(
&
pCxt
->
pValues
,
pNode
);
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
collectPlaceholderValues
(
SPlanContext
*
pCxt
,
SQueryPlan
*
pPlan
)
{
SCollectPlaceholderValuesCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pValues
=
NULL
};
nodesWalkPhysiPlan
((
SNode
*
)
pPlan
,
collectPlaceholderValuesImpl
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
==
cxt
.
errCode
)
{
pPlan
->
pPlaceholderValues
=
cxt
.
pValues
;
}
else
{
nodesDestroyList
(
cxt
.
pValues
);
}
return
cxt
.
errCode
;
}
int32_t
qCreateQueryPlan
(
SPlanContext
*
pCxt
,
SQueryPlan
**
pPlan
,
SArray
*
pExecNodeList
)
{
SLogicNode
*
pLogicNode
=
NULL
;
SLogicSubplan
*
pLogicSubplan
=
NULL
;
...
...
@@ -35,6 +60,9 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createPhysiPlan
(
pCxt
,
pLogicPlan
,
pPlan
,
pExecNodeList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
pCxt
->
isStmtQuery
)
{
code
=
collectPlaceholderValues
(
pCxt
,
*
pPlan
);
}
nodesDestroyNode
(
pLogicNode
);
nodesDestroyNode
(
pLogicSubplan
);
...
...
@@ -73,6 +101,82 @@ int32_t qSetSubplanExecutionNode(SSubplan* subplan, int32_t groupId, SDownstream
return
setSubplanExecutionNode
(
subplan
->
pNode
,
groupId
,
pSource
);
}
static
int32_t
setValueByBindParam
(
SValueNode
*
pVal
,
TAOS_BIND_v2
*
pParam
)
{
if
(
1
==
*
(
pParam
->
is_null
))
{
pVal
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
pVal
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_NULL
].
bytes
;
return
TSDB_CODE_SUCCESS
;
}
pVal
->
node
.
resType
.
type
=
pParam
->
buffer_type
;
pVal
->
node
.
resType
.
bytes
=
*
(
pParam
->
length
);
switch
(
pParam
->
buffer_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
pVal
->
datum
.
b
=
*
((
bool
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
pVal
->
datum
.
i
=
*
((
int8_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pVal
->
datum
.
i
=
*
((
int16_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_INT
:
pVal
->
datum
.
i
=
*
((
int32_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pVal
->
datum
.
i
=
*
((
int64_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
pVal
->
datum
.
d
=
*
((
float
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pVal
->
datum
.
d
=
*
((
double
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
pVal
->
node
.
resType
.
bytes
+
VARSTR_HEADER_SIZE
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
varDataSetLen
(
pVal
->
datum
.
p
,
pVal
->
node
.
resType
.
bytes
);
strncpy
(
varDataVal
(
pVal
->
datum
.
p
),
(
const
char
*
)
pParam
->
buffer
,
pVal
->
node
.
resType
.
bytes
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
pVal
->
datum
.
i
=
*
((
int64_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
pVal
->
datum
.
u
=
*
((
uint8_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
pVal
->
datum
.
u
=
*
((
uint16_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_UINT
:
pVal
->
datum
.
u
=
*
((
uint32_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
pVal
->
datum
.
u
=
*
((
uint64_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_MEDIUMBLOB
:
// todo
default:
break
;
}
pVal
->
translate
=
true
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
qStmtBindParam
(
SQueryPlan
*
pPlan
,
TAOS_BIND_v2
*
pParams
)
{
int32_t
index
=
0
;
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pPlan
->
pPlaceholderValues
)
{
setValueByBindParam
((
SValueNode
*
)
pNode
,
pParams
+
index
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
qSubPlanToString
(
const
SSubplan
*
pSubplan
,
char
**
pStr
,
int32_t
*
pLen
)
{
if
(
SUBPLAN_TYPE_MODIFY
==
pSubplan
->
subplanType
)
{
SDataInserterNode
*
insert
=
(
SDataInserterNode
*
)
pSubplan
->
pDataSink
;
...
...
source/libs/planner/test/planStmtTest.cpp
0 → 100644
浏览文件 @
091b5124
/*
* 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 "planTestUtil.h"
#include "planner.h"
using
namespace
std
;
class
PlanStmtTest
:
public
PlannerTestBase
{
public:
void
prepare
(
const
string
&
sql
)
{
run
(
sql
);
// todo calloc pBindParams_
}
void
bindParam
(
int32_t
val
)
{
TAOS_BIND_v2
*
pBind
=
pBindParams_
+
paramNo_
++
;
pBind
->
buffer_type
=
TSDB_DATA_TYPE_INT
;
pBind
->
num
=
1
;
pBind
->
buffer_length
=
sizeof
(
int32_t
);
pBind
->
buffer
=
taosMemoryCalloc
(
1
,
pBind
->
buffer_length
);
pBind
->
length
=
(
int32_t
*
)
taosMemoryCalloc
(
1
,
sizeof
(
int32_t
));
pBind
->
is_null
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
));
*
((
int32_t
*
)
pBind
->
buffer
)
=
val
;
*
(
pBind
->
length
)
=
sizeof
(
int32_t
);
*
(
pBind
->
is_null
)
=
0
;
}
void
exec
()
{
// todo
}
private:
TAOS_BIND_v2
*
pBindParams_
;
int32_t
paramNo_
;
};
TEST_F
(
PlanStmtTest
,
stmt
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT * FROM t1 where c1 = ?"
);
}
source/libs/planner/test/planTestUtil.cpp
0 → 100644
浏览文件 @
091b5124
/*
* 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 "planTestUtil.h"
#include <algorithm>
#include "cmdnodes.h"
#include "parser.h"
#include "planInt.h"
using
namespace
std
;
using
namespace
testing
;
#define DO_WITH_THROW(func, ...) \
do { \
int32_t code__ = func(__VA_ARGS__); \
if (TSDB_CODE_SUCCESS != code__) { \
throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + ", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \
} \
} while(0);
class
PlannerTestBaseImpl
{
public:
void
useDb
(
const
string
&
acctId
,
const
string
&
db
)
{
caseEnv_
.
acctId_
=
acctId
;
caseEnv_
.
db_
=
db
;
}
void
run
(
const
string
&
sql
)
{
reset
();
try
{
SQuery
*
pQuery
=
nullptr
;
doParseSql
(
sql
,
&
pQuery
);
SPlanContext
cxt
=
{
0
};
setPlanContext
(
pQuery
,
&
cxt
);
SLogicNode
*
pLogicNode
=
nullptr
;
doCreateLogicPlan
(
&
cxt
,
&
pLogicNode
);
doOptimizeLogicPlan
(
&
cxt
,
pLogicNode
);
SLogicSubplan
*
pLogicSubplan
=
nullptr
;
doSplitLogicPlan
(
&
cxt
,
pLogicNode
,
&
pLogicSubplan
);
SQueryLogicPlan
*
pLogicPlan
=
nullptr
;
doScaleOutLogicPlan
(
&
cxt
,
pLogicSubplan
,
&
pLogicPlan
);
SQueryPlan
*
pPlan
=
nullptr
;
doCreatePhysiPlan
(
&
cxt
,
pLogicPlan
,
&
pPlan
,
NULL
);
}
catch
(...)
{
dump
();
throw
;
}
}
private:
struct
caseEnv
{
string
acctId_
;
string
db_
;
};
struct
stmtEnv
{
string
sql_
;
array
<
char
,
1024
>
msgBuf_
;
};
struct
stmtRes
{
string
ast_
;
string
rawLogicPlan_
;
string
optimizedLogicPlan_
;
string
splitLogicPlan_
;
string
scaledLogicPlan_
;
string
physiPlan_
;
};
void
reset
()
{
stmtEnv_
.
sql_
.
clear
();
stmtEnv_
.
msgBuf_
.
fill
(
0
);
res_
.
ast_
.
clear
();
res_
.
rawLogicPlan_
.
clear
();
res_
.
optimizedLogicPlan_
.
clear
();
res_
.
splitLogicPlan_
.
clear
();
res_
.
scaledLogicPlan_
.
clear
();
res_
.
physiPlan_
.
clear
();
}
void
dump
()
{
cout
<<
"==========================================sql : ["
<<
stmtEnv_
.
sql_
<<
"]"
<<
endl
;
cout
<<
"syntax tree : "
<<
endl
;
cout
<<
res_
.
ast_
<<
endl
;
cout
<<
"raw logic plan : "
<<
endl
;
cout
<<
res_
.
rawLogicPlan_
<<
endl
;
cout
<<
"optimized logic plan : "
<<
endl
;
cout
<<
res_
.
optimizedLogicPlan_
<<
endl
;
cout
<<
"split logic plan : "
<<
endl
;
cout
<<
res_
.
splitLogicPlan_
<<
endl
;
cout
<<
"scaled logic plan : "
<<
endl
;
cout
<<
res_
.
scaledLogicPlan_
<<
endl
;
cout
<<
"physical plan : "
<<
endl
;
cout
<<
res_
.
physiPlan_
<<
endl
;
}
void
doParseSql
(
const
string
&
sql
,
SQuery
**
pQuery
)
{
stmtEnv_
.
sql_
=
sql
;
transform
(
stmtEnv_
.
sql_
.
begin
(),
stmtEnv_
.
sql_
.
end
(),
stmtEnv_
.
sql_
.
begin
(),
::
tolower
);
SParseContext
cxt
=
{
0
};
cxt
.
acctId
=
atoi
(
caseEnv_
.
acctId_
.
c_str
());
cxt
.
db
=
caseEnv_
.
db_
.
c_str
();
cxt
.
pSql
=
stmtEnv_
.
sql_
.
c_str
();
cxt
.
sqlLen
=
stmtEnv_
.
sql_
.
length
();
cxt
.
pMsg
=
stmtEnv_
.
msgBuf_
.
data
();
cxt
.
msgLen
=
stmtEnv_
.
msgBuf_
.
max_size
();
DO_WITH_THROW
(
qParseQuerySql
,
&
cxt
,
pQuery
);
res_
.
ast_
=
toString
((
*
pQuery
)
->
pRoot
);
}
void
doCreateLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
**
pLogicNode
)
{
DO_WITH_THROW
(
createLogicPlan
,
pCxt
,
pLogicNode
);
res_
.
rawLogicPlan_
=
toString
((
SNode
*
)(
*
pLogicNode
));
}
void
doOptimizeLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
DO_WITH_THROW
(
optimizeLogicPlan
,
pCxt
,
pLogicNode
);
res_
.
optimizedLogicPlan_
=
toString
((
SNode
*
)
pLogicNode
);
}
void
doSplitLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
,
SLogicSubplan
**
pLogicSubplan
)
{
DO_WITH_THROW
(
splitLogicPlan
,
pCxt
,
pLogicNode
,
pLogicSubplan
);
res_
.
splitLogicPlan_
=
toString
((
SNode
*
)(
*
pLogicSubplan
));
}
void
doScaleOutLogicPlan
(
SPlanContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SQueryLogicPlan
**
pLogicPlan
)
{
DO_WITH_THROW
(
scaleOutLogicPlan
,
pCxt
,
pLogicSubplan
,
pLogicPlan
);
res_
.
scaledLogicPlan_
=
toString
((
SNode
*
)(
*
pLogicPlan
));
}
void
doCreatePhysiPlan
(
SPlanContext
*
pCxt
,
SQueryLogicPlan
*
pLogicPlan
,
SQueryPlan
**
pPlan
,
SArray
*
pExecNodeList
)
{
DO_WITH_THROW
(
createPhysiPlan
,
pCxt
,
pLogicPlan
,
pPlan
,
pExecNodeList
);
res_
.
physiPlan_
=
toString
((
SNode
*
)(
*
pPlan
));
}
void
setPlanContext
(
SQuery
*
pQuery
,
SPlanContext
*
pCxt
)
{
if
(
QUERY_NODE_CREATE_TOPIC_STMT
==
nodeType
(
pQuery
->
pRoot
))
{
pCxt
->
pAstRoot
=
((
SCreateTopicStmt
*
)
pQuery
->
pRoot
)
->
pQuery
;
pCxt
->
topicQuery
=
true
;
}
else
if
(
QUERY_NODE_CREATE_INDEX_STMT
==
nodeType
(
pQuery
->
pRoot
))
{
SMCreateSmaReq
req
=
{
0
};
tDeserializeSMCreateSmaReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
);
nodesStringToNode
(
req
.
ast
,
&
pCxt
->
pAstRoot
);
pCxt
->
streamQuery
=
true
;
}
else
if
(
QUERY_NODE_CREATE_STREAM_STMT
==
nodeType
(
pQuery
->
pRoot
))
{
SCreateStreamStmt
*
pStmt
=
(
SCreateStreamStmt
*
)
pQuery
->
pRoot
;
pCxt
->
pAstRoot
=
pStmt
->
pQuery
;
pCxt
->
streamQuery
=
true
;
pCxt
->
triggerType
=
pStmt
->
pOptions
->
triggerType
;
pCxt
->
watermark
=
(
NULL
!=
pStmt
->
pOptions
->
pWatermark
?
((
SValueNode
*
)
pStmt
->
pOptions
->
pWatermark
)
->
datum
.
i
:
0
);
}
else
{
pCxt
->
pAstRoot
=
pQuery
->
pRoot
;
}
}
string
toString
(
const
SNode
*
pRoot
)
{
char
*
pStr
=
NULL
;
int32_t
len
=
0
;
DO_WITH_THROW
(
nodesNodeToString
,
pRoot
,
false
,
&
pStr
,
&
len
)
string
str
(
pStr
);
taosMemoryFreeClear
(
pStr
);
return
str
;
}
caseEnv
caseEnv_
;
stmtEnv
stmtEnv_
;
stmtRes
res_
;
};
PlannerTestBase
::
PlannerTestBase
()
:
impl_
(
new
PlannerTestBaseImpl
())
{
}
PlannerTestBase
::~
PlannerTestBase
()
{
}
void
PlannerTestBase
::
useDb
(
const
std
::
string
&
acctId
,
const
std
::
string
&
db
)
{
impl_
->
useDb
(
acctId
,
db
);
}
void
PlannerTestBase
::
run
(
const
std
::
string
&
sql
)
{
return
impl_
->
run
(
sql
);
}
source/libs/planner/test/planTestUtil.h
0 → 100644
浏览文件 @
091b5124
/*
* 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/>.
*/
#ifndef PLAN_TEST_UTIL_H
#define PLAN_TEST_UTIL_H
#include <gtest/gtest.h>
class
PlannerTestBaseImpl
;
class
PlannerTestBase
:
public
testing
::
Test
{
public:
PlannerTestBase
();
virtual
~
PlannerTestBase
();
void
useDb
(
const
std
::
string
&
acctId
,
const
std
::
string
&
db
);
void
run
(
const
std
::
string
&
sql
);
private:
std
::
unique_ptr
<
PlannerTestBaseImpl
>
impl_
;
};
#endif // PLAN_TEST_UTIL_H
source/libs/planner/test/plannerTest.cpp
浏览文件 @
091b5124
...
...
@@ -90,17 +90,16 @@ protected:
return
false
;
}
SQueryPlan
*
pPlan
=
nullptr
;
code
=
createPhysiPlan
(
&
cxt
,
pLogicPlan
,
&
pPlan
,
NULL
);
code
=
createPhysiPlan
(
&
cxt
,
pLogicPlan
,
&
plan_
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
cout
<<
"sql:["
<<
cxt_
.
pSql
<<
"] createPhysiPlan code:"
<<
code
<<
", strerror:"
<<
tstrerror
(
code
)
<<
endl
;
return
false
;
}
cout
<<
"unformatted physical plan : "
<<
endl
;
cout
<<
toString
((
const
SNode
*
)
p
Plan
,
false
)
<<
endl
;
cout
<<
toString
((
const
SNode
*
)
p
lan_
,
false
)
<<
endl
;
SNode
*
pNode
;
FOREACH
(
pNode
,
p
Plan
->
pSubplans
)
{
FOREACH
(
pNode
,
p
lan_
->
pSubplans
)
{
SNode
*
pSubplan
;
FOREACH
(
pSubplan
,
((
SNodeListNode
*
)
pNode
)
->
pNodeList
)
{
cout
<<
"unformatted physical subplan : "
<<
endl
;
...
...
@@ -160,6 +159,7 @@ private:
string
sqlBuf_
;
SParseContext
cxt_
;
SQuery
*
query_
;
SQueryPlan
*
plan_
;
};
TEST_F
(
PlannerTest
,
selectBasic
)
{
...
...
source/libs/scalar/inc/sclvector.h
浏览文件 @
091b5124
...
...
@@ -52,6 +52,9 @@ static FORCE_INLINE double getVectorDoubleValue_FLOAT(void *src, int32_t index)
static
FORCE_INLINE
double
getVectorDoubleValue_DOUBLE
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
double
*
)
src
+
index
);
}
static
FORCE_INLINE
double
getVectorDoubleValue_BOOL
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
bool
*
)
src
+
index
);
}
static
FORCE_INLINE
_getDoubleValue_fn_t
getVectorDoubleValueFn
(
int32_t
srcType
)
{
_getDoubleValue_fn_t
p
=
NULL
;
...
...
@@ -77,6 +80,8 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType)
p
=
getVectorDoubleValue_DOUBLE
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
p
=
getVectorDoubleValue_BIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_BOOL
)
{
p
=
getVectorDoubleValue_BOOL
;
}
else
{
assert
(
0
);
}
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
091b5124
...
...
@@ -440,8 +440,10 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
return
DEAL_RES_ERROR
;
}
if
(
colDataIsNull_s
(
output
.
columnData
,
0
))
{
res
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
}
else
{
res
->
node
.
resType
=
node
->
node
.
resType
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
res
->
datum
.
p
=
output
.
columnData
->
pData
;
...
...
@@ -449,6 +451,7 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
}
else
{
memcpy
(
nodesGetValueFromNode
(
res
),
output
.
columnData
->
pData
,
tDataTypes
[
type
].
bytes
);
}
}
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
091b5124
...
...
@@ -795,13 +795,6 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
type
!=
TSDB_DATA_TYPE_BIGINT
&&
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
TSDB_CODE_FAILED
;
}
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
char
*
input
=
pInput
[
0
].
columnData
->
pData
;
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
...
...
@@ -867,13 +860,6 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
int32_t
timePrec
=
GET_PARAM_PRECISON
(
pInput
);
if
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
char
*
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
0
];
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
...
...
@@ -883,7 +869,11 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
}
int64_t
timeVal
=
0
;
convertStringToTimestamp
(
type
,
input
,
timePrec
,
&
timeVal
);
int32_t
ret
=
convertStringToTimestamp
(
type
,
input
,
timePrec
,
&
timeVal
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
colDataAppend
(
pOutput
->
columnData
,
i
,
(
char
*
)
&
timeVal
,
false
);
input
+=
varDataTLen
(
input
);
...
...
@@ -897,18 +887,6 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
0
]);
int32_t
timePrec
=
GET_PARAM_PRECISON
(
&
pInput
[
0
]);
if
(
inputNum
!=
2
)
{
return
TSDB_CODE_FAILED
;
}
if
(
type
!=
TSDB_DATA_TYPE_BIGINT
&&
type
!=
TSDB_DATA_TYPE_TIMESTAMP
&&
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
GET_PARAM_TYPE
(
&
pInput
[
1
])
!=
TSDB_DATA_TYPE_BIGINT
)
{
//time_unit
return
TSDB_CODE_FAILED
;
}
int64_t
timeUnit
,
timeVal
=
0
;
GET_TYPED_DATA
(
timeUnit
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
1
]),
pInput
[
1
].
columnData
->
pData
);
...
...
@@ -930,7 +908,11 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
}
if
(
IS_VAR_DATA_TYPE
(
type
))
{
/* datetime format strings */
convertStringToTimestamp
(
type
,
input
,
TSDB_TIME_PRECISION_NANO
,
&
timeVal
);
int32_t
ret
=
convertStringToTimestamp
(
type
,
input
,
TSDB_TIME_PRECISION_NANO
,
&
timeVal
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
//If converted value is less than 10digits in second, use value in second instead
int64_t
timeValSec
=
timeVal
/
1000000000
;
if
(
timeValSec
<
1000000000
)
{
...
...
@@ -1096,16 +1078,9 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
}
int32_t
timeDiffFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
if
(
inputNum
!=
2
&&
inputNum
!=
3
)
{
return
TSDB_CODE_FAILED
;
}
int32_t
timePrec
=
GET_PARAM_PRECISON
(
&
pInput
[
0
]);
int64_t
timeUnit
=
-
1
,
timeVal
[
2
]
=
{
0
};
if
(
inputNum
==
3
)
{
if
(
GET_PARAM_TYPE
(
&
pInput
[
2
])
!=
TSDB_DATA_TYPE_BIGINT
)
{
return
TSDB_CODE_FAILED
;
}
GET_TYPED_DATA
(
timeUnit
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
}
...
...
@@ -1133,7 +1108,11 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
k
]);
if
(
IS_VAR_DATA_TYPE
(
type
))
{
/* datetime format strings */
convertStringToTimestamp
(
type
,
input
[
k
],
TSDB_TIME_PRECISION_NANO
,
&
timeVal
[
k
]);
int32_t
ret
=
convertStringToTimestamp
(
type
,
input
[
k
],
TSDB_TIME_PRECISION_NANO
,
&
timeVal
[
k
]);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
/* unix timestamp or ts column*/
GET_TYPED_DATA
(
timeVal
[
k
],
int64_t
,
type
,
input
[
k
]);
if
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
091b5124
...
...
@@ -57,6 +57,10 @@ int64_t getVectorBigintValue_FLOAT(void *src, int32_t index) {
int64_t
getVectorBigintValue_DOUBLE
(
void
*
src
,
int32_t
index
)
{
return
(
int64_t
)
*
((
double
*
)
src
+
index
);
}
int64_t
getVectorBigintValue_BOOL
(
void
*
src
,
int32_t
index
)
{
return
(
int64_t
)
*
((
bool
*
)
src
+
index
);
}
_getBigintValue_fn_t
getVectorBigintValueFn
(
int32_t
srcType
)
{
_getBigintValue_fn_t
p
=
NULL
;
if
(
srcType
==
TSDB_DATA_TYPE_TINYINT
)
{
...
...
@@ -81,6 +85,8 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
p
=
getVectorBigintValue_DOUBLE
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
p
=
getVectorBigintValue_BIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_BOOL
)
{
p
=
getVectorBigintValue_BOOL
;
}
else
{
assert
(
0
);
}
...
...
@@ -620,8 +626,10 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
SColumnInfoData
*
pLeftCol
=
doVectorConvert
(
pLeft
,
&
leftConvert
);
SColumnInfoData
*
pRightCol
=
doVectorConvert
(
pRight
,
&
rightConvert
);
if
((
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_BIGINT
)
||
(
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_BIGINT
))
{
//timestamp plus duration
if
((
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
IS_INTEGER_TYPE
(
GET_PARAM_TYPE
(
pRight
)))
||
(
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
IS_INTEGER_TYPE
(
GET_PARAM_TYPE
(
pLeft
)))
||
(
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_BOOL
)
||
(
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_BOOL
))
{
//timestamp plus duration
int64_t
*
output
=
(
int64_t
*
)
pOutputCol
->
pData
;
_getBigintValue_fn_t
getVectorBigintValueFnLeft
=
getVectorBigintValueFn
(
pLeftCol
->
info
.
type
);
_getBigintValue_fn_t
getVectorBigintValueFnRight
=
getVectorBigintValueFn
(
pRightCol
->
info
.
type
);
...
...
source/libs/transport/src/transCli.c
浏览文件 @
091b5124
...
...
@@ -212,10 +212,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
} \
} while (0)
#define CONN_NO_PERSIST_BY_APP(conn) \
(((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
#define CONN_RELEASE_BY_SERVER(conn) \
(((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
#define CONN_NO_PERSIST_BY_APP(conn) (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
#define CONN_RELEASE_BY_SERVER(conn) (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1)
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1)
...
...
@@ -290,9 +288,8 @@ void cliHandleResp(SCliConn* conn) {
tDebug
(
"%s cli conn %p ref by app"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
}
tDebug
(
"%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
pTransInst
->
label
,
conn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
conn
->
addr
.
sin_addr
),
ntohs
(
conn
->
addr
.
sin_port
),
taosInetNtoa
(
conn
->
locaddr
.
sin_addr
),
ntohs
(
conn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
tDebug
(
"%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
pTransInst
->
label
,
conn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
conn
->
addr
.
sin_addr
),
ntohs
(
conn
->
addr
.
sin_port
),
taosInetNtoa
(
conn
->
locaddr
.
sin_addr
),
ntohs
(
conn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
conn
->
secured
=
pHead
->
secured
;
...
...
@@ -358,12 +355,10 @@ void cliHandleExcept(SCliConn* pConn) {
if
(
pMsg
==
NULL
&&
!
CONN_NO_PERSIST_BY_APP
(
pConn
))
{
transMsg
.
ahandle
=
transCtxDumpVal
(
&
pConn
->
ctx
,
transMsg
.
msgType
);
tDebug
(
"%s cli conn %p construct ahandle %p by %s"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
transMsg
.
ahandle
,
TMSG_INFO
(
transMsg
.
msgType
));
tDebug
(
"%s cli conn %p construct ahandle %p by %s"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
transMsg
.
ahandle
,
TMSG_INFO
(
transMsg
.
msgType
));
if
(
transMsg
.
ahandle
==
NULL
)
{
transMsg
.
ahandle
=
transCtxDumpBrokenlinkVal
(
&
pConn
->
ctx
,
(
int32_t
*
)
&
(
transMsg
.
msgType
));
tDebug
(
"%s cli conn %p construct ahandle %p due to brokenlink"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
transMsg
.
ahandle
);
tDebug
(
"%s cli conn %p construct ahandle %p due to brokenlink"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
transMsg
.
ahandle
);
}
}
else
{
transMsg
.
ahandle
=
pCtx
?
pCtx
->
ahandle
:
NULL
;
...
...
@@ -546,6 +541,7 @@ static void cliDestroy(uv_handle_t* handle) {
transCtxCleanup
(
&
conn
->
ctx
);
transQueueDestroy
(
&
conn
->
cliMsgs
);
tTrace
(
"%s cli conn %p destroy successfully"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
transDestroyBuffer
(
&
conn
->
readBuf
);
taosMemoryFree
(
conn
);
}
static
bool
cliHandleNoResp
(
SCliConn
*
conn
)
{
...
...
@@ -635,9 +631,8 @@ void cliSend(SCliConn* pConn) {
pHead
->
release
=
REQUEST_RELEASE_HANDLE
(
pCliMsg
)
?
1
:
0
;
uv_buf_t
wb
=
uv_buf_init
((
char
*
)
pHead
,
msgLen
);
tDebug
(
"%s cli conn %p %s is send to %s:%d, local info %s:%d"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
tDebug
(
"%s cli conn %p %s is send to %s:%d, local info %s:%d"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
if
(
pHead
->
persist
==
1
)
{
CONN_SET_PERSIST_BY_APP
(
pConn
);
...
...
@@ -675,10 +670,9 @@ static void cliHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd) {
tDebug
(
"cli work thread %p start to quit"
,
pThrd
);
destroyCmsg
(
pMsg
);
destroyConnPool
(
pThrd
->
pool
);
uv_timer_stop
(
&
pThrd
->
timer
);
pThrd
->
quit
=
true
;
uv_stop
(
pThrd
->
loop
);
}
static
void
cliHandleRelease
(
SCliMsg
*
pMsg
,
SCliThrdObj
*
pThrd
)
{
...
...
source/libs/transport/src/transComm.c
浏览文件 @
091b5124
...
...
@@ -195,7 +195,7 @@ SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb)
void
transDestroyAsyncPool
(
SAsyncPool
*
pool
)
{
for
(
int
i
=
0
;
i
<
pool
->
nAsync
;
i
++
)
{
uv_async_t
*
async
=
&
(
pool
->
asyncs
[
i
]);
uv_close
((
uv_handle_t
*
)
async
,
NULL
);
SAsyncItem
*
item
=
async
->
data
;
taosThreadMutexDestroy
(
&
item
->
mtx
);
taosMemoryFree
(
item
);
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
091b5124
...
...
@@ -126,6 +126,11 @@ static void uvWorkerAsyncCb(uv_async_t* handle);
static
void
uvAcceptAsyncCb
(
uv_async_t
*
handle
);
static
void
uvShutDownCb
(
uv_shutdown_t
*
req
,
int
status
);
static
void
uvFreeCb
(
uv_handle_t
*
handle
)
{
//
taosMemoryFree
(
handle
);
}
static
void
uvStartSendRespInternal
(
SSrvMsg
*
smsg
);
static
void
uvPrepareSendData
(
SSrvMsg
*
msg
,
uv_buf_t
*
wb
);
static
void
uvStartSendResp
(
SSrvMsg
*
msg
);
...
...
@@ -141,8 +146,7 @@ static void uvHandleQuit(SSrvMsg* msg, SWorkThrdObj* thrd);
static
void
uvHandleRelease
(
SSrvMsg
*
msg
,
SWorkThrdObj
*
thrd
);
static
void
uvHandleResp
(
SSrvMsg
*
msg
,
SWorkThrdObj
*
thrd
);
static
void
uvHandleRegister
(
SSrvMsg
*
msg
,
SWorkThrdObj
*
thrd
);
static
void
(
*
transAsyncHandle
[])(
SSrvMsg
*
msg
,
SWorkThrdObj
*
thrd
)
=
{
uvHandleResp
,
uvHandleQuit
,
uvHandleRelease
,
uvHandleRegister
};
static
void
(
*
transAsyncHandle
[])(
SSrvMsg
*
msg
,
SWorkThrdObj
*
thrd
)
=
{
uvHandleResp
,
uvHandleQuit
,
uvHandleRelease
,
uvHandleRegister
};
static
void
uvDestroyConn
(
uv_handle_t
*
handle
);
...
...
@@ -205,13 +209,12 @@ static void uvHandleReq(SSrvConn* pConn) {
}
if
(
pConn
->
status
==
ConnNormal
&&
pHead
->
noResp
==
0
)
{
transRefSrvHandle
(
pConn
);
tDebug
(
"server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
tDebug
(
"server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
}
else
{
tDebug
(
"server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d "
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
t
aosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
),
t
ransMsg
.
contLen
,
pHead
->
noResp
);
tDebug
(
"server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d "
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
loc
addr
.
sin_port
),
transMsg
.
contLen
,
pHead
->
noResp
);
// no ref here
}
...
...
@@ -318,6 +321,8 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) {
}
else
{
tError
(
"fail to dispatch conn to work thread"
);
}
uv_close
((
uv_handle_t
*
)
req
->
data
,
uvFreeCb
);
// taosMemoryFree(req->data);
taosMemoryFree
(
req
);
}
...
...
@@ -349,9 +354,8 @@ static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
char
*
msg
=
(
char
*
)
pHead
;
int32_t
len
=
transMsgLenFromCont
(
pMsg
->
contLen
);
tDebug
(
"server conn %p %s is sent to %s:%d, local info: %s:%d"
,
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
tDebug
(
"server conn %p %s is sent to %s:%d, local info: %s:%d"
,
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
pHead
->
msgLen
=
htonl
(
len
);
wb
->
base
=
msg
;
...
...
@@ -429,11 +433,39 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
(
*
transAsyncHandle
[
msg
->
type
])(
msg
,
pThrd
);
}
}
static
void
uvWalkCb
(
uv_handle_t
*
handle
,
void
*
arg
)
{
if
(
!
uv_is_closing
(
handle
))
{
uv_close
(
handle
,
NULL
);
// uv_unref(handle);
tDebug
(
"handle: %p -----test----"
,
handle
);
}
}
#define MAKE_VALGRIND_HAPPY(loop) \
do { \
uv_walk(loop, uvWalkCb, NULL); \
uv_run(loop, UV_RUN_DEFAULT); \
uv_loop_close(loop); \
} while (0);
static
void
uvAcceptAsyncCb
(
uv_async_t
*
async
)
{
SServerObj
*
srv
=
async
->
data
;
tDebug
(
"close server port %d"
,
srv
->
port
);
uv_close
((
uv_handle_t
*
)
&
srv
->
server
,
NULL
);
uv_stop
(
srv
->
loop
);
uv_walk
(
srv
->
loop
,
uvWalkCb
,
NULL
);
// uv_close((uv_handle_t*)async, NULL);
// uv_close((uv_handle_t*)&srv->server, NULL);
// uv_stop(srv->loop);
// uv_print_all_handles(srv->loop, stderr);
// int ref = uv_loop_alive(srv->loop);
// assert(ref == 0);
// tError("active size %d", ref);
// uv_stop(srv->loop);
// uv_run(srv->loop, UV_RUN_DEFAULT);
// fprintf(stderr, "------------------------------------");
// uv_print_all_handles(srv->loop, stderr);
// int ret = uv_loop_close(srv->loop);
// tError("(loop)->active_reqs.count: %d, ret: %d", (srv->loop)->active_reqs.count, ret);
// assert(ret == 0);
}
static
void
uvShutDownCb
(
uv_shutdown_t
*
req
,
int
status
)
{
...
...
@@ -455,16 +487,16 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) {
if
(
uv_accept
(
stream
,
(
uv_stream_t
*
)
cli
)
==
0
)
{
uv_write_t
*
wr
=
(
uv_write_t
*
)
taosMemoryMalloc
(
sizeof
(
uv_write_t
));
wr
->
data
=
cli
;
uv_buf_t
buf
=
uv_buf_init
((
char
*
)
notify
,
strlen
(
notify
));
pObj
->
workerIdx
=
(
pObj
->
workerIdx
+
1
)
%
pObj
->
numOfThreads
;
tTrace
(
"new conntion accepted by main server, dispatch to %dth worker-thread"
,
pObj
->
workerIdx
);
uv_write2
(
wr
,
(
uv_stream_t
*
)
&
(
pObj
->
pipe
[
pObj
->
workerIdx
][
0
]),
&
buf
,
1
,
(
uv_stream_t
*
)
cli
,
uvOnPipeWriteCb
);
}
else
{
uv_close
((
uv_handle_t
*
)
cli
,
NULL
);
taosMemoryFree
(
cli
);
}
}
void
uvOnConnectionCb
(
uv_stream_t
*
q
,
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
...
...
@@ -474,7 +506,10 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
tError
(
"read error %s"
,
uv_err_name
(
nread
));
}
// TODO(log other failure reason)
// uv_close((uv_handle_t*)q, NULL);
tError
(
"failed to create connect: %p"
,
q
);
taosMemoryFree
(
buf
->
base
);
uv_close
((
uv_handle_t
*
)
q
,
NULL
);
// taosMemoryFree(q);
return
;
}
// free memory allocated by
...
...
@@ -650,6 +685,7 @@ static void uvDestroyConn(uv_handle_t* handle) {
if
(
thrd
->
quit
&&
QUEUE_IS_EMPTY
(
&
thrd
->
conn
))
{
tTrace
(
"work thread quit"
);
// uv_walk(thrd->loop, uvWalkCb, NULL);
uv_loop_close
(
thrd
->
loop
);
uv_stop
(
thrd
->
loop
);
}
...
...
@@ -713,6 +749,7 @@ End:
void
uvHandleQuit
(
SSrvMsg
*
msg
,
SWorkThrdObj
*
thrd
)
{
thrd
->
quit
=
true
;
if
(
QUEUE_IS_EMPTY
(
&
thrd
->
conn
))
{
// uv_walk(thrd->loop, uvWalkCb, NULL);
uv_loop_close
(
thrd
->
loop
);
uv_stop
(
thrd
->
loop
);
}
else
{
...
...
@@ -765,8 +802,9 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
return
;
}
taosThreadJoin
(
pThrd
->
thread
,
NULL
);
taosMemoryFree
(
pThrd
->
loop
);
// MAKE_VALGRIND_HAPPY
(pThrd->loop);
transDestroyAsyncPool
(
pThrd
->
asyncPool
);
taosMemoryFree
(
pThrd
->
loop
);
taosMemoryFree
(
pThrd
);
}
void
sendQuitToWorkThrd
(
SWorkThrdObj
*
pThrd
)
{
...
...
@@ -784,6 +822,8 @@ void transCloseServer(void* arg) {
uv_async_send
(
srv
->
pAcceptAsync
);
taosThreadJoin
(
srv
->
thread
,
NULL
);
MAKE_VALGRIND_HAPPY
(
srv
->
loop
);
for
(
int
i
=
0
;
i
<
srv
->
numOfThreads
;
i
++
)
{
sendQuitToWorkThrd
(
srv
->
pThreadObj
[
i
]);
destroyWorkThrd
(
srv
->
pThreadObj
[
i
]);
...
...
source/os/src/osThread.c
浏览文件 @
091b5124
...
...
@@ -77,34 +77,6 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) {
return
pthread_attr_setstacksize
(
attr
,
stacksize
);
}
int32_t
taosThreadBarrierDestroy
(
TdThreadBarrier
*
barrier
)
{
return
pthread_barrier_destroy
(
barrier
);
}
int32_t
taosThreadBarrierInit
(
TdThreadBarrier
*
barrier
,
const
TdThreadBarrierAttr
*
attr
,
uint32_t
count
)
{
return
pthread_barrier_init
(
barrier
,
attr
,
count
);
}
int32_t
taosThreadBarrierWait
(
TdThreadBarrier
*
barrier
)
{
return
pthread_barrier_wait
(
barrier
);
}
int32_t
taosThreadBarrierAttrDestroy
(
TdThreadBarrierAttr
*
attr
)
{
return
pthread_barrierattr_destroy
(
attr
);
}
int32_t
taosThreadBarrierAttrGetPshared
(
const
TdThreadBarrierAttr
*
attr
,
int32_t
*
pshared
)
{
return
pthread_barrierattr_getpshared
(
attr
,
pshared
);
}
int32_t
taosThreadBarrierAttrInit
(
TdThreadBarrierAttr
*
attr
)
{
return
pthread_barrierattr_init
(
attr
);
}
int32_t
taosThreadBarrierAttrSetPshared
(
TdThreadBarrierAttr
*
attr
,
int32_t
pshared
)
{
return
pthread_barrierattr_setpshared
(
attr
,
pshared
);
}
int32_t
taosThreadCancel
(
TdThread
thread
)
{
return
pthread_cancel
(
thread
);
}
...
...
@@ -322,23 +294,43 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
}
int32_t
taosThreadSpinDestroy
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_destroy
(
lock
);
#ifndef __USE_XOPEN2K
return
pthread_mutex_destroy
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_destroy
((
pthread_spinlock_t
*
)
lock
);
#endif
}
int32_t
taosThreadSpinInit
(
TdThreadSpinlock
*
lock
,
int32_t
pshared
)
{
return
pthread_spin_init
(
lock
,
pshared
);
#ifndef __USE_XOPEN2K
return
pthread_mutex_init
((
pthread_mutex_t
*
)
lock
,
pshared
);
#else
return
pthread_spin_init
((
pthread_spinlock_t
*
)
lock
,
pshared
);
#endif
}
int32_t
taosThreadSpinLock
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_lock
(
lock
);
#ifndef __USE_XOPEN2K
return
pthread_mutex_lock
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_lock
((
pthread_spinlock_t
*
)
lock
);
#endif
}
int32_t
taosThreadSpinTrylock
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_trylock
(
lock
);
#ifndef __USE_XOPEN2K
return
pthread_mutex_trylock
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_trylock
((
pthread_spinlock_t
*
)
lock
);
#endif
}
int32_t
taosThreadSpinUnlock
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_unlock
(
lock
);
#ifndef __USE_XOPEN2K
return
pthread_mutex_unlock
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_unlock
((
pthread_spinlock_t
*
)
lock
);
#endif
}
void
taosThreadTestCancel
(
void
)
{
...
...
tests/script/tmp/data.sim
浏览文件 @
091b5124
...
...
@@ -3,6 +3,7 @@ system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect
return
sql create database db
sql create table db.tb (ts timestamp, i int)
sql insert into db.tb values(now, 1)
...
...
tests/system-test/fulltest.sh
100644 → 100755
浏览文件 @
091b5124
python3 ./test.py
-f
2-query/
function_elapsed
.py
python3 ./test.py
-f
2-query/
between
.py
...
...
tools/shell/src/shellCommand.c
浏览文件 @
091b5124
...
...
@@ -15,9 +15,9 @@
#define __USE_XOPEN
#include "shellCommand.h"
#include "os.h"
#include "shell.h"
#include "shellCommand.h"
#include <regex.h>
...
...
@@ -48,7 +48,7 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
while
(
--
pos
>=
0
)
{
*
size
+=
1
;
if
(
str
[
pos
]
>
0
||
countPrefixOnes
((
unsigned
char
)
str
[
pos
])
>
1
)
break
;
if
(
str
[
pos
]
>
0
||
countPrefixOnes
((
unsigned
char
)
str
[
pos
])
>
1
)
break
;
}
int
rc
=
taosMbToWchar
(
&
wc
,
str
+
pos
,
MB_CUR_MAX
);
...
...
@@ -106,8 +106,7 @@ void clearLineBefore(Command *cmd) {
assert
(
cmd
->
cursorOffset
<=
cmd
->
commandSize
&&
cmd
->
endOffset
>=
cmd
->
screenOffset
);
clearScreen
(
cmd
->
endOffset
+
prompt_size
,
cmd
->
screenOffset
+
prompt_size
);
memmove
(
cmd
->
command
,
cmd
->
command
+
cmd
->
cursorOffset
,
cmd
->
commandSize
-
cmd
->
cursorOffset
);
memmove
(
cmd
->
command
,
cmd
->
command
+
cmd
->
cursorOffset
,
cmd
->
commandSize
-
cmd
->
cursorOffset
);
cmd
->
commandSize
-=
cmd
->
cursorOffset
;
cmd
->
cursorOffset
=
0
;
cmd
->
screenOffset
=
0
;
...
...
tools/shell/src/shellEngine.c
浏览文件 @
091b5124
...
...
@@ -23,31 +23,34 @@
#include "shellCommand.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "ttypes.h"
#include "tutil.h"
#include "tconfig.h"
#include <regex.h>
#include <wordexp.h>
/**************** Global variables ****************/
#ifdef _TD_POWER_
char
CLIENT_VERSION
[]
=
"Welcome to the PowerDB shell from %s, Client Version:%s
\n
"
char
CLIENT_VERSION
[]
=
"Welcome to the PowerDB shell from %s, Client Version:%s
\n
"
"Copyright (c) 2020 by PowerDB, Inc. All rights reserved.
\n\n
"
;
char
PROMPT_HEADER
[]
=
"power> "
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
7
;
#elif (_TD_TQ_ == true)
char
CLIENT_VERSION
[]
=
"Welcome to the TQ shell from %s, Client Version:%s
\n
"
char
CLIENT_VERSION
[]
=
"Welcome to the TQ shell from %s, Client Version:%s
\n
"
"Copyright (c) 2020 by TQ, Inc. All rights reserved.
\n\n
"
;
char
PROMPT_HEADER
[]
=
"tq> "
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
4
;
#else
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from %s, Client Version:%s
\n
"
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from %s, Client Version:%s
\n
"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
char
PROMPT_HEADER
[]
=
"taos> "
;
...
...
@@ -91,11 +94,6 @@ TAOS *shellInit(SShellArguments *_args) {
_args
->
user
=
TSDB_DEFAULT_USER
;
}
SConfig
*
pCfg
=
cfgInit
();
if
(
NULL
==
pCfg
)
return
NULL
;
if
(
0
!=
taosAddClientLogCfg
(
pCfg
))
return
NULL
;
// Connect to the database.
TAOS
*
con
=
NULL
;
if
(
_args
->
auth
==
NULL
)
{
...
...
@@ -349,7 +347,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
return
;
}
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pSql
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pSql
);
if
(
pFields
!=
NULL
)
{
// select and show kinds of commands
int
error_no
=
0
;
...
...
@@ -526,7 +524,8 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
}
// FILE *fp = fopen(full_path.we_wordv[0], "w");
TdFilePtr
pFile
=
taosOpenFile
(
full_path
.
we_wordv
[
0
],
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
full_path
.
we_wordv
[
0
],
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
fprintf
(
stderr
,
"ERROR: failed to open file: %s
\n
"
,
full_path
.
we_wordv
[
0
]);
wordfree
(
&
full_path
);
...
...
@@ -934,7 +933,7 @@ void read_history() {
}
}
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
taosCloseFile
(
&
pFile
);
}
...
...
@@ -1031,7 +1030,7 @@ void source_file(TAOS *con, char *fptr) {
}
taosMemoryFree
(
cmd
);
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
wordfree
(
&
full_path
);
taosCloseFile
(
&
pFile
);
}
...
...
tools/shell/src/shellMain.c
浏览文件 @
091b5124
...
...
@@ -14,27 +14,20 @@
*/
#define __USE_XOPEN
#include "os.h"
#include "shell.h"
#include "tglobal.h"
#include "tconfig.h"
#include "shellCommand.h"
#include "t
base64
.h"
#include "t
global
.h"
#include "tlog.h"
#include "version.h"
#include <wordexp.h>
#include <argp.h>
#include <termio.h>
#include <wordexp.h>
#define OPT_ABORT 1
/* abort */
int
indicator
=
1
;
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
void
taosNetTest
(
char
*
role
,
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
);
void
taosNetTest
(
char
*
role
,
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
);
const
char
*
argp_program_version
=
version
;
const
char
*
argp_program_bug_address
=
"<support@taosdata.com>"
;
static
char
doc
[]
=
""
;
...
...
@@ -45,14 +38,14 @@ static tsem_t cancelSem;
static
struct
argp_option
options
[]
=
{
{
"host"
,
'h'
,
"HOST"
,
0
,
"TDengine server FQDN to connect. The default host is localhost."
},
{
"password"
,
'p'
,
0
,
0
,
"The password to use when connecting to the server."
},
{
"password"
,
'p'
,
NULL
,
0
,
"The password to use when connecting to the server."
},
{
"port"
,
'P'
,
"PORT"
,
0
,
"The TCP/IP port number to use for the connection."
},
{
"user"
,
'u'
,
"USER"
,
0
,
"The user name to use when connecting to the server."
},
{
"auth"
,
'A'
,
"Auth"
,
0
,
"The auth string to use when connecting to the server."
},
{
"config-dir"
,
'c'
,
"CONFIG_DIR"
,
0
,
"Configuration directory."
},
{
"dump-config"
,
'C'
,
0
,
0
,
"Dump configuration."
},
{
"dump-config"
,
'C'
,
NULL
,
0
,
"Dump configuration."
},
{
"commands"
,
's'
,
"COMMANDS"
,
0
,
"Commands to run without enter the shell."
},
{
"raw-time"
,
'r'
,
0
,
0
,
"Output time as uint64_t."
},
{
"raw-time"
,
'r'
,
NULL
,
0
,
"Output time as uint64_t."
},
{
"file"
,
'f'
,
"FILE"
,
0
,
"Script to run without enter the shell."
},
{
"directory"
,
'D'
,
"DIRECTORY"
,
0
,
"Use multi-thread to import all SQL files in the directory separately."
},
{
"thread"
,
'T'
,
"THREADNUM"
,
0
,
"Number of threads when using multi-thread to import data."
},
...
...
@@ -182,18 +175,16 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
/* Our argp parser. */
static
struct
argp
argp
=
{
options
,
parse_opt
,
args_doc
,
doc
};
char
LINUXCLIENT_VERSION
[]
=
"Welcome to the TDengine shell from %s, Client Version:%s
\n
"
char
LINUXCLIENT_VERSION
[]
=
"Welcome to the TDengine shell from %s, Client Version:%s
\n
"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
char
g_password
[
SHELL_MAX_PASSWORD_LEN
];
static
void
parse_args
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
static
void
parse_args
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
LINUXCLIENT_VERSION
,
tsOsName
,
taos_get_client_info
());
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%20s"
,
g_password
)
>
1
)
{
...
...
@@ -225,13 +216,13 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
arguments
);
if
(
arguments
->
abort
)
{
#ifndef _ALPINE
#if 0
#ifndef _ALPINE
#if 0
error(10, 0, "ABORTED");
#endif
#else
#endif
#else
abort
();
#endif
#endif
}
}
...
...
@@ -406,7 +397,7 @@ void *shellLoopQuery(void *arg) {
taosThreadCleanupPush
(
cleanup_handler
,
NULL
);
char
*
command
=
taosMemoryMalloc
(
MAX_COMMAND_SIZE
);
if
(
command
==
NULL
){
if
(
command
==
NULL
)
{
uError
(
"failed to malloc command"
);
return
NULL
;
}
...
...
@@ -437,7 +428,7 @@ void get_history_path(char *_history) { snprintf(_history, TSDB_FILENAME_LEN, "%
void
clearScreen
(
int
ecmd_pos
,
int
cursor_pos
)
{
struct
winsize
w
;
if
(
ioctl
(
0
,
TIOCGWINSZ
,
&
w
)
<
0
||
w
.
ws_col
==
0
||
w
.
ws_row
==
0
)
{
//fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n");
//
fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n");
w
.
ws_col
=
120
;
w
.
ws_row
=
30
;
}
...
...
@@ -458,7 +449,7 @@ void clearScreen(int ecmd_pos, int cursor_pos) {
void
showOnScreen
(
Command
*
cmd
)
{
struct
winsize
w
;
if
(
ioctl
(
0
,
TIOCGWINSZ
,
&
w
)
<
0
||
w
.
ws_col
==
0
||
w
.
ws_row
==
0
)
{
//fprintf(stderr, "No stream device\n");
//
fprintf(stderr, "No stream device\n");
w
.
ws_col
=
120
;
w
.
ws_row
=
30
;
}
...
...
@@ -531,13 +522,11 @@ void showOnScreen(Command *cmd) {
void
cleanup_handler
(
void
*
arg
)
{
resetTerminalMode
();
}
void
exitShell
()
{
/*int32_t ret =*/
resetTerminalMode
();
/*int32_t ret =*/
resetTerminalMode
();
taos_cleanup
();
exit
(
EXIT_SUCCESS
);
}
void
shellQueryInterruptHandler
(
int32_t
signum
,
void
*
sigInfo
,
void
*
context
)
{
tsem_post
(
&
cancelSem
);
}
void
shellQueryInterruptHandler
(
int32_t
signum
,
void
*
sigInfo
,
void
*
context
)
{
tsem_post
(
&
cancelSem
);
}
void
*
cancelHandler
(
void
*
arg
)
{
setThreadName
(
"cancelHandler"
);
...
...
@@ -640,11 +629,11 @@ int main(int argc, char *argv[]) {
con
=
taos_connect_auth
(
args
.
host
,
args
.
user
,
args
.
auth
,
args
.
database
,
args
.
port
);
}
/*
if (taos_init()) {
printf("Failed to init taos");
exit(EXIT_FAILURE);
}
*/
//
if (taos_init()) {
//
printf("Failed to init taos");
//
exit(EXIT_FAILURE);
//
}
taosNetTest
(
args
.
netTestRole
,
args
.
host
,
args
.
port
,
args
.
pktLen
,
args
.
pktNum
,
args
.
pktType
);
taos_close
(
con
);
exit
(
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录