Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1f71ce94
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
1f71ce94
编写于
7月 06, 2023
作者:
W
wangjiaming0909
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: get last timestamp before create sma index
上级
85782bbf
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
104 addition
and
14 deletion
+104
-14
include/common/tmsg.h
include/common/tmsg.h
+1
-0
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+12
-9
source/common/src/tmsg.c
source/common/src/tmsg.c
+2
-0
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+5
-0
source/libs/parser/inc/parInt.h
source/libs/parser/inc/parInt.h
+1
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+59
-5
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+2
-0
source/libs/parser/test/parInitialCTest.cpp
source/libs/parser/test/parInitialCTest.cpp
+12
-0
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+10
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
1f71ce94
...
...
@@ -3025,6 +3025,7 @@ typedef struct {
char
*
sql
;
char
*
ast
;
int64_t
deleteMark
;
int64_t
lastTs
;
}
SMCreateSmaReq
;
int32_t
tSerializeSMCreateSmaReq
(
void
*
buf
,
int32_t
bufLen
,
SMCreateSmaReq
*
pReq
);
...
...
include/libs/nodes/cmdnodes.h
浏览文件 @
1f71ce94
...
...
@@ -319,19 +319,22 @@ typedef struct SIndexOptions {
SNode
*
pInterval
;
SNode
*
pOffset
;
SNode
*
pSliding
;
int8_t
tsPrecision
;
SNode
*
pStreamOptions
;
}
SIndexOptions
;
typedef
struct
SCreateIndexStmt
{
ENodeType
type
;
EIndexType
indexType
;
bool
ignoreExists
;
char
indexDbName
[
TSDB_DB_NAME_LEN
];
char
indexName
[
TSDB_INDEX_NAME_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
SNodeList
*
pCols
;
SIndexOptions
*
pOptions
;
ENodeType
type
;
EIndexType
indexType
;
bool
ignoreExists
;
char
indexDbName
[
TSDB_DB_NAME_LEN
];
char
indexName
[
TSDB_INDEX_NAME_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
SNodeList
*
pCols
;
SIndexOptions
*
pOptions
;
SNode
*
pPrevQuery
;
SMCreateSmaReq
*
pReq
;
}
SCreateIndexStmt
;
typedef
struct
SDropIndexStmt
{
...
...
source/common/src/tmsg.c
浏览文件 @
1f71ce94
...
...
@@ -835,6 +835,7 @@ int32_t tSerializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq
if
(
tEncodeBinary
(
&
encoder
,
pReq
->
ast
,
pReq
->
astLen
)
<
0
)
return
-
1
;
}
if
(
tEncodeI64
(
&
encoder
,
pReq
->
deleteMark
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
&
encoder
,
pReq
->
lastTs
)
<
0
)
return
-
1
;
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
...
...
@@ -884,6 +885,7 @@ int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pR
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
ast
)
<
0
)
return
-
1
;
}
if
(
tDecodeI64
(
&
decoder
,
&
pReq
->
deleteMark
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
&
decoder
,
&
pReq
->
lastTs
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
tDecoderClear
(
&
decoder
);
return
0
;
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
1f71ce94
...
...
@@ -907,6 +907,10 @@ void nodesDestroyNode(SNode* pNode) {
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pNode
;
nodesDestroyNode
((
SNode
*
)
pStmt
->
pOptions
);
nodesDestroyList
(
pStmt
->
pCols
);
if
(
pStmt
->
pReq
)
{
tFreeSMCreateSmaReq
(
pStmt
->
pReq
);
taosMemoryFreeClear
(
pStmt
->
pReq
);
}
break
;
}
case
QUERY_NODE_DROP_INDEX_STMT
:
// no pointer field
...
...
@@ -1053,6 +1057,7 @@ void nodesDestroyNode(SNode* pNode) {
}
case
QUERY_NODE_QUERY
:
{
SQuery
*
pQuery
=
(
SQuery
*
)
pNode
;
nodesDestroyNode
(
pQuery
->
pPrevRoot
);
nodesDestroyNode
(
pQuery
->
pRoot
);
nodesDestroyNode
(
pQuery
->
pPostRoot
);
taosMemoryFreeClear
(
pQuery
->
pResSchema
);
...
...
source/libs/parser/inc/parInt.h
浏览文件 @
1f71ce94
...
...
@@ -35,6 +35,7 @@ int32_t translate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMe
int32_t
extractResultSchema
(
const
SNode
*
pRoot
,
int32_t
*
numOfCols
,
SSchema
**
pSchema
);
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
int32_t
translatePostCreateStream
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
,
void
**
pResRow
);
int32_t
translatePostCreateSmaIndex
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
,
void
**
pResRow
);
#ifdef __cplusplus
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
1f71ce94
...
...
@@ -5803,6 +5803,15 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
getSmaIndexAst
(
pCxt
,
pStmt
,
&
pReq
->
ast
,
&
pReq
->
astLen
,
&
pReq
->
expr
,
&
pReq
->
exprLen
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
STableMeta
*
pMetaCache
=
NULL
;
code
=
getTableMeta
(
pCxt
,
pStmt
->
dbName
,
pStmt
->
tableName
,
&
pMetaCache
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pStmt
->
pOptions
->
tsPrecision
=
pMetaCache
->
tableInfo
.
precision
;
code
=
createLastTsSelectStmt
(
pStmt
->
dbName
,
pStmt
->
tableName
,
pMetaCache
,
&
pStmt
->
pPrevQuery
);
}
taosMemoryFreeClear
(
pMetaCache
);
}
return
code
;
}
...
...
@@ -5828,15 +5837,60 @@ static int32_t checkCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pS
}
static
int32_t
translateCreateSmaIndex
(
STranslateContext
*
pCxt
,
SCreateIndexStmt
*
pStmt
)
{
SMCreateSmaReq
createSmaReq
=
{
0
};
int32_t
code
=
checkCreateSmaIndex
(
pCxt
,
pStmt
);
pStmt
->
pReq
=
taosMemoryCalloc
(
1
,
sizeof
(
SMCreateSmaReq
));
if
(
pStmt
->
pReq
==
NULL
)
code
=
TSDB_CODE_OUT_OF_MEMORY
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCreateSmaReq
(
pCxt
,
pStmt
,
&
createSma
Req
);
code
=
buildCreateSmaReq
(
pCxt
,
pStmt
,
pStmt
->
p
Req
);
}
TSWAP
(
pCxt
->
pPrevRoot
,
pStmt
->
pPrevQuery
);
return
code
;
}
int32_t
createIntervalFromCreateSmaIndexStmt
(
SCreateIndexStmt
*
pStmt
,
SInterval
*
pInterval
)
{
pInterval
->
interval
=
((
SValueNode
*
)
pStmt
->
pOptions
->
pInterval
)
->
datum
.
i
;
pInterval
->
intervalUnit
=
((
SValueNode
*
)
pStmt
->
pOptions
->
pInterval
)
->
unit
;
pInterval
->
offset
=
NULL
!=
pStmt
->
pOptions
->
pOffset
?
((
SValueNode
*
)
pStmt
->
pOptions
->
pOffset
)
->
datum
.
i
:
0
;
pInterval
->
sliding
=
NULL
!=
pStmt
->
pOptions
->
pSliding
?
((
SValueNode
*
)
pStmt
->
pOptions
->
pSliding
)
->
datum
.
i
:
pInterval
->
interval
;
pInterval
->
slidingUnit
=
NULL
!=
pStmt
->
pOptions
->
pSliding
?
((
SValueNode
*
)
pStmt
->
pOptions
->
pSliding
)
->
unit
:
pInterval
->
intervalUnit
;
pInterval
->
precision
=
pStmt
->
pOptions
->
tsPrecision
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
translatePostCreateSmaIndex
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
,
void
**
pResRow
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pQuery
->
pRoot
;
int64_t
lastTs
=
0
;
SInterval
interval
=
{
0
};
STranslateContext
pCxt
=
{
0
};
code
=
initTranslateContext
(
pParseCxt
,
NULL
,
&
pCxt
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCmdMsg
(
pCxt
,
TDMT_MND_CREATE_SMA
,
(
FSerializeFunc
)
tSerializeSMCreateSmaReq
,
&
createSmaReq
);
code
=
createIntervalFromCreateSmaIndexStmt
(
pStmt
,
&
interval
);
}
tFreeSMCreateSmaReq
(
&
createSmaReq
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
pResRow
&&
pResRow
[
0
])
{
lastTs
=
*
(
int64_t
*
)
pResRow
[
0
];
}
else
if
(
interval
.
interval
>
0
)
{
lastTs
=
convertTimePrecision
(
taosGetTimestampMs
(),
TSDB_TIME_PRECISION_MILLI
,
interval
.
precision
);
}
else
{
lastTs
=
taosGetTimestampMs
();
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
interval
.
interval
>
0
)
{
pStmt
->
pReq
->
lastTs
=
taosTimeTruncate
(
lastTs
,
&
interval
);
}
else
{
pStmt
->
pReq
->
lastTs
=
lastTs
;
}
code
=
buildCmdMsg
(
&
pCxt
,
TDMT_MND_CREATE_SMA
,
(
FSerializeFunc
)
tSerializeSMCreateSmaReq
,
pStmt
->
pReq
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
setQuery
(
&
pCxt
,
pQuery
);
}
setRefreshMate
(
&
pCxt
,
pQuery
);
destroyTranslateContext
(
&
pCxt
);
tFreeSMCreateSmaReq
(
pStmt
->
pReq
);
taosMemoryFreeClear
(
pStmt
->
pReq
);
return
code
;
}
...
...
@@ -6989,7 +7043,7 @@ static int32_t translateCreateStream(STranslateContext* pCxt, SCreateStreamStmt*
return
code
;
}
int32_t
buildIntervalForCreateStream
(
SCreateStreamStmt
*
pStmt
,
SInterval
*
pInterval
)
{
static
int32_t
buildIntervalForCreateStream
(
SCreateStreamStmt
*
pStmt
,
SInterval
*
pInterval
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
QUERY_NODE_SELECT_STMT
!=
nodeType
(
pStmt
->
pQuery
))
{
return
code
;
...
...
source/libs/parser/src/parser.c
浏览文件 @
1f71ce94
...
...
@@ -227,6 +227,8 @@ int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, void** pRes
case
QUERY_NODE_CREATE_STREAM_STMT
:
code
=
translatePostCreateStream
(
pCxt
,
pQuery
,
pResRow
);
break
;
case
QUERY_NODE_CREATE_INDEX_STMT
:
code
=
translatePostCreateSmaIndex
(
pCxt
,
pQuery
,
pResRow
);
default:
break
;
}
...
...
source/libs/parser/test/parInitialCTest.cpp
浏览文件 @
1f71ce94
...
...
@@ -542,6 +542,18 @@ TEST_F(ParserInitialCTest, createSmaIndex) {
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_CREATE_INDEX_STMT
);
SMCreateSmaReq
req
=
{
0
};
ASSERT_TRUE
(
pQuery
->
pPrevRoot
);
ASSERT_EQ
(
QUERY_NODE_SELECT_STMT
,
nodeType
(
pQuery
->
pPrevRoot
));
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pQuery
->
pRoot
;
SCmdMsgInfo
*
pCmdMsg
=
(
SCmdMsgInfo
*
)
taosMemoryMalloc
(
sizeof
(
SCmdMsgInfo
));
if
(
NULL
==
pCmdMsg
)
FAIL
();
pCmdMsg
->
msgType
=
TDMT_MND_CREATE_SMA
;
pCmdMsg
->
msgLen
=
tSerializeSMCreateSmaReq
(
NULL
,
0
,
pStmt
->
pReq
);
pCmdMsg
->
pMsg
=
taosMemoryMalloc
(
pCmdMsg
->
msgLen
);
if
(
!
pCmdMsg
->
pMsg
)
FAIL
();
tSerializeSMCreateSmaReq
(
pCmdMsg
->
pMsg
,
pCmdMsg
->
msgLen
,
pStmt
->
pReq
);
((
SQuery
*
)
pQuery
)
->
pCmdMsg
=
pCmdMsg
;
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSMCreateSmaReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
ASSERT_EQ
(
std
::
string
(
req
.
name
),
std
::
string
(
expect
.
name
));
...
...
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
1f71ce94
...
...
@@ -441,6 +441,16 @@ class PlannerTestBaseImpl {
pCxt
->
topicQuery
=
true
;
}
else
if
(
QUERY_NODE_CREATE_INDEX_STMT
==
nodeType
(
pQuery
->
pRoot
))
{
SMCreateSmaReq
req
=
{
0
};
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pQuery
->
pRoot
;
SCmdMsgInfo
*
pCmdMsg
=
(
SCmdMsgInfo
*
)
taosMemoryMalloc
(
sizeof
(
SCmdMsgInfo
));
if
(
NULL
==
pCmdMsg
)
FAIL
();
pCmdMsg
->
msgType
=
TDMT_MND_CREATE_SMA
;
pCmdMsg
->
msgLen
=
tSerializeSMCreateSmaReq
(
NULL
,
0
,
pStmt
->
pReq
);
pCmdMsg
->
pMsg
=
taosMemoryMalloc
(
pCmdMsg
->
msgLen
);
if
(
!
pCmdMsg
->
pMsg
)
FAIL
();
tSerializeSMCreateSmaReq
(
pCmdMsg
->
pMsg
,
pCmdMsg
->
msgLen
,
pStmt
->
pReq
);
((
SQuery
*
)
pQuery
)
->
pCmdMsg
=
pCmdMsg
;
tDeserializeSMCreateSmaReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
);
g_mockCatalogService
->
createSmaIndex
(
&
req
);
nodesStringToNode
(
req
.
ast
,
&
pCxt
->
pAstRoot
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录