Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7532ab9a
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7532ab9a
编写于
2月 01, 2023
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: the problem of creating a stream with tag define
上级
fecd2f58
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
68 addition
and
8 deletion
+68
-8
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+68
-8
未找到文件。
source/libs/parser/src/parTranslater.c
浏览文件 @
7532ab9a
...
...
@@ -5671,10 +5671,6 @@ static SNode* createNullValue() {
}
static
int32_t
addNullTagsForExistTable
(
STranslateContext
*
pCxt
,
STableMeta
*
pMeta
,
SSelectStmt
*
pSelect
)
{
if
(
NULL
==
pMeta
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
numOfTags
=
getNumOfTags
(
pMeta
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
for
(
int32_t
i
=
0
;
TSDB_CODE_SUCCESS
==
code
&&
i
<
numOfTags
;
++
i
)
{
...
...
@@ -5728,12 +5724,27 @@ static int32_t addSubtableNameToCreateStreamQuery(STranslateContext* pCxt, SCrea
return
pCxt
->
errCode
;
}
static
int32_t
addNullTagsForCreateTable
(
STranslateContext
*
pCxt
,
SCreateStreamStmt
*
pStmt
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
for
(
int32_t
i
=
0
;
TSDB_CODE_SUCCESS
==
code
&&
i
<
LIST_LENGTH
(
pStmt
->
pTags
);
++
i
)
{
code
=
nodesListMakeStrictAppend
(
&
((
SSelectStmt
*
)
pStmt
->
pQuery
)
->
pTags
,
createNullValue
());
}
return
code
;
}
static
int32_t
addNullTagsToCreateStreamQuery
(
STranslateContext
*
pCxt
,
STableMeta
*
pMeta
,
SCreateStreamStmt
*
pStmt
)
{
if
(
NULL
==
pMeta
)
{
return
addNullTagsForCreateTable
(
pCxt
,
pStmt
);
}
return
addNullTagsForExistTable
(
pCxt
,
pMeta
,
(
SSelectStmt
*
)
pStmt
->
pQuery
);
}
static
int32_t
addSubtableInfoToCreateStreamQuery
(
STranslateContext
*
pCxt
,
STableMeta
*
pMeta
,
SCreateStreamStmt
*
pStmt
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSelectStmt
*
pSelect
=
(
SSelectStmt
*
)
pStmt
->
pQuery
;
if
(
NULL
==
pSelect
->
pPartitionByList
)
{
code
=
addNullTags
ForExistTable
(
pCxt
,
pMeta
,
pSelec
t
);
code
=
addNullTags
ToCreateStreamQuery
(
pCxt
,
pMeta
,
pStm
t
);
}
else
{
code
=
addTagsToCreateStreamQuery
(
pCxt
,
pStmt
,
pSelect
);
}
...
...
@@ -6011,17 +6022,66 @@ static int32_t adjustTagsForExistTable(STranslateContext* pCxt, SCreateStreamStm
return
adjustOrderOfTags
(
pCxt
,
pStmt
->
pTags
,
pMeta
,
&
pSelect
->
pTags
,
pReq
);
}
static
int32_t
adjustTagsForCreateTable
(
STranslateContext
*
pCxt
,
SCreateStreamStmt
*
pStmt
,
SCMCreateStreamReq
*
pReq
)
{
SSelectStmt
*
pSelect
=
(
SSelectStmt
*
)
pStmt
->
pQuery
;
if
(
NULL
==
pSelect
->
pPartitionByList
||
NULL
==
pSelect
->
pTags
)
{
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pTagDef
=
NULL
;
SNode
*
pTagExpr
=
NULL
;
FORBOTH
(
pTagDef
,
pStmt
->
pTags
,
pTagExpr
,
pSelect
->
pTags
)
{
SColumnDefNode
*
pDef
=
(
SColumnDefNode
*
)
pTagDef
;
if
(
!
dataTypeEqual
(
&
pDef
->
dataType
,
&
((
SExprNode
*
)
pTagExpr
)
->
resType
))
{
SNode
*
pFunc
=
NULL
;
int32_t
code
=
createCastFunc
(
pCxt
,
pTagExpr
,
pDef
->
dataType
,
&
pFunc
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
REPLACE_LIST2_NODE
(
pFunc
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
adjustTags
(
STranslateContext
*
pCxt
,
SCreateStreamStmt
*
pStmt
,
const
STableMeta
*
pMeta
,
SCMCreateStreamReq
*
pReq
)
{
if
(
NULL
==
pMeta
)
{
return
adjustTagsForCreateTable
(
pCxt
,
pStmt
,
pReq
);
}
return
adjustTagsForExistTable
(
pCxt
,
pStmt
,
pMeta
,
pReq
);
}
static
bool
isTagDef
(
SNodeList
*
pTags
)
{
if
(
NULL
==
pTags
)
{
return
false
;
}
return
QUERY_NODE_COLUMN_DEF
==
nodeType
(
nodesListGetNode
(
pTags
,
0
));
}
static
bool
isTagBound
(
SNodeList
*
pTags
)
{
if
(
NULL
==
pTags
)
{
return
false
;
}
return
QUERY_NODE_COLUMN
==
nodeType
(
nodesListGetNode
(
pTags
,
0
));
}
static
int32_t
translateStreamTargetTable
(
STranslateContext
*
pCxt
,
SCreateStreamStmt
*
pStmt
,
SCMCreateStreamReq
*
pReq
,
STableMeta
**
pMeta
)
{
int32_t
code
=
getTableMeta
(
pCxt
,
pStmt
->
targetDbName
,
pStmt
->
targetTabName
,
pMeta
);
if
(
TSDB_CODE_PAR_TABLE_NOT_EXIST
==
code
)
{
if
(
NULL
!=
pStmt
->
pCols
)
{
if
(
NULL
!=
pStmt
->
pCols
||
isTagBound
(
pStmt
->
pTags
)
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
pStmt
->
targetTabName
);
}
pReq
->
createStb
=
STREAM_CREATE_STABLE_TRUE
;
pReq
->
targetStbUid
=
0
;
return
TSDB_CODE_SUCCESS
;
}
else
{
if
(
isTagDef
(
pStmt
->
pTags
))
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_STREAM_QUERY
,
"Table already exist: %s"
,
pStmt
->
targetTabName
);
}
pReq
->
createStb
=
STREAM_CREATE_STABLE_FALSE
;
pReq
->
targetStbUid
=
(
*
pMeta
)
->
suid
;
}
...
...
@@ -6047,8 +6107,8 @@ static int32_t buildCreateStreamQuery(STranslateContext* pCxt, SCreateStreamStmt
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pMeta
)
{
code
=
adjustProjectionsForExistTable
(
pCxt
,
pStmt
,
pMeta
,
pReq
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pMeta
)
{
code
=
adjustTags
ForExistTable
(
pCxt
,
pStmt
,
pMeta
,
pReq
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
adjustTags
(
pCxt
,
pStmt
,
pMeta
,
pReq
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
getSourceDatabase
(
pStmt
->
pQuery
,
pCxt
->
pParseCxt
->
acctId
,
pReq
->
sourceDB
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录