Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9a3e1f03
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
9a3e1f03
编写于
5月 16, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: sql command 'alter table'
上级
356256ec
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
307 addition
and
24 deletion
+307
-24
source/common/src/tmsg.c
source/common/src/tmsg.c
+0
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+1
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+141
-6
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1
-1
source/libs/parser/test/parInitialATest.cpp
source/libs/parser/test/parInitialATest.cpp
+135
-15
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+2
-0
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+27
-0
未找到文件。
source/common/src/tmsg.c
浏览文件 @
9a3e1f03
...
...
@@ -4217,7 +4217,6 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
tbName
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
action
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colName
)
<
0
)
return
-
1
;
switch
(
pReq
->
action
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colName
)
<
0
)
return
-
1
;
...
...
source/libs/parser/inc/sql.y
浏览文件 @
9a3e1f03
...
...
@@ -241,7 +241,7 @@ alter_table_clause(A) ::=
alter_table_clause(A) ::=
full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); }
alter_table_clause(A) ::=
full_table_name(B) SET TAG column_name(C) NK_EQ literal(D). { A = createAlterTableSetTag(pCxt, B, &C,
D
); }
full_table_name(B) SET TAG column_name(C) NK_EQ literal(D). { A = createAlterTableSetTag(pCxt, B, &C,
releaseRawExprNode(pCxt, D)
); }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
9a3e1f03
...
...
@@ -3800,7 +3800,7 @@ static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) {
taosArrayDestroy
(
pTbBatch
->
req
.
pArray
);
}
static
int32_t
rewriteToVnodeModifOpStmt
(
SQuery
*
pQuery
,
SArray
*
pBufArray
)
{
static
int32_t
rewriteToVnodeModif
y
OpStmt
(
SQuery
*
pQuery
,
SArray
*
pBufArray
)
{
SVnodeModifOpStmt
*
pNewStmt
=
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
);
if
(
pNewStmt
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -3855,7 +3855,7 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
code
=
buildCreateTableDataBlock
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
,
&
info
,
&
pBufArray
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteToVnodeModifOpStmt
(
pQuery
,
pBufArray
);
code
=
rewriteToVnodeModif
y
OpStmt
(
pQuery
,
pBufArray
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
destroyCreateTbReqArray
(
pBufArray
);
}
...
...
@@ -4111,7 +4111,7 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
rewriteToVnodeModifOpStmt
(
pQuery
,
pBufArray
);
return
rewriteToVnodeModif
y
OpStmt
(
pQuery
,
pBufArray
);
}
typedef
struct
SVgroupDropTableBatch
{
...
...
@@ -4251,7 +4251,131 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
rewriteToVnodeModifOpStmt
(
pQuery
,
pBufArray
);
return
rewriteToVnodeModifyOpStmt
(
pQuery
,
pBufArray
);
}
static
int32_t
buildAlterTbReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
SVAlterTbReq
*
pReq
)
{
pReq
->
tbName
=
strdup
(
pStmt
->
tableName
);
if
(
NULL
==
pReq
->
tbName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pReq
->
action
=
pStmt
->
alterType
;
switch
(
pStmt
->
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_TAG
:
case
TSDB_ALTER_TABLE_DROP_TAG
:
case
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
:
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
pReq
->
tagName
=
strdup
(
pStmt
->
colName
);
if
(
NULL
==
pReq
->
tagName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
pStmt
->
pVal
))
{
return
pCxt
->
errCode
;
}
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
pReq
->
nTagVal
=
pStmt
->
pVal
->
node
.
resType
.
bytes
;
char
*
pVal
=
nodesGetValueFromNode
(
pStmt
->
pVal
);
pReq
->
pTagVal
=
IS_VAR_DATA_TYPE
(
pStmt
->
pVal
->
node
.
resType
.
type
)
?
pVal
+
VARSTR_HEADER_SIZE
:
pVal
;
break
;
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
pReq
->
colName
=
strdup
(
pStmt
->
colName
);
if
(
NULL
==
pReq
->
colName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pReq
->
type
=
pStmt
->
dataType
.
type
;
pReq
->
flags
=
COL_SMA_ON
;
pReq
->
bytes
=
pStmt
->
dataType
.
bytes
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
pReq
->
colName
=
strdup
(
pStmt
->
colName
);
if
(
NULL
==
pReq
->
colName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pReq
->
colModBytes
=
calcTypeBytes
(
pStmt
->
dataType
);
break
;
case
TSDB_ALTER_TABLE_UPDATE_OPTIONS
:
if
(
-
1
!=
pStmt
->
pOptions
->
ttl
)
{
pReq
->
updateTTL
=
true
;
pReq
->
newTTL
=
pStmt
->
pOptions
->
ttl
;
}
if
(
'\0'
!=
pStmt
->
pOptions
->
comment
[
0
])
{
pReq
->
updateComment
=
true
;
pReq
->
newComment
=
strdup
(
pStmt
->
pOptions
->
comment
);
if
(
NULL
==
pReq
->
newComment
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
pReq
->
colName
=
strdup
(
pStmt
->
colName
);
pReq
->
colNewName
=
strdup
(
pStmt
->
newColName
);
if
(
NULL
==
pReq
->
colName
||
NULL
==
pReq
->
colNewName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
break
;
default:
break
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
serializeAlterTbReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
SVAlterTbReq
*
pReq
,
SArray
*
pArray
)
{
SVgroupInfo
vg
=
{
0
};
int32_t
code
=
getTableHashVgroup
(
pCxt
,
pStmt
->
dbName
,
pStmt
->
tableName
,
&
vg
);
int
tlen
=
0
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tEncodeSize
(
tEncodeSVAlterTbReq
,
pReq
,
tlen
,
code
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tlen
+=
sizeof
(
SMsgHead
);
void
*
pMsg
=
taosMemoryMalloc
(
tlen
);
if
(
NULL
==
pMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
((
SMsgHead
*
)
pMsg
)
->
vgId
=
htonl
(
vg
.
vgId
);
((
SMsgHead
*
)
pMsg
)
->
contLen
=
htonl
(
tlen
);
void
*
pBuf
=
POINTER_SHIFT
(
pMsg
,
sizeof
(
SMsgHead
));
SEncoder
coder
=
{
0
};
tEncoderInit
(
&
coder
,
pBuf
,
tlen
-
sizeof
(
SMsgHead
));
tEncodeSVAlterTbReq
(
&
coder
,
pReq
);
tEncoderClear
(
&
coder
);
SVgDataBlocks
*
pVgData
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
pVgData
)
{
taosMemoryFree
(
pMsg
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pVgData
->
vg
=
vg
;
pVgData
->
pData
=
pMsg
;
pVgData
->
size
=
tlen
;
pVgData
->
numOfTables
=
1
;
taosArrayPush
(
pArray
,
&
pVgData
);
}
return
code
;
}
static
int32_t
buildModifyVnodeArray
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
SVAlterTbReq
*
pReq
,
SArray
**
pArray
)
{
SArray
*
pTmpArray
=
taosArrayInit
(
1
,
sizeof
(
void
*
));
if
(
NULL
==
pTmpArray
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
int32_t
code
=
serializeAlterTbReq
(
pCxt
,
pStmt
,
pReq
,
pTmpArray
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pArray
=
pTmpArray
;
}
else
{
taosArrayDestroy
(
pTmpArray
);
}
return
code
;
}
static
int32_t
rewriteAlterTable
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
...
...
@@ -4266,10 +4390,21 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
if
(
TSDB_SUPER_TABLE
==
pTableMeta
->
tableType
)
{
return
TSDB_CODE_SUCCESS
;
}
else
if
(
TSDB_CHILD_TABLE
!=
pTableMeta
->
tableType
&&
TSDB_NORMAL_TABLE
!=
pTableMeta
->
tableType
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_
DROP_S
TABLE
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_
ALTER_
TABLE
);
}
return
TSDB_CODE_SUCCESS
;
SVAlterTbReq
req
=
{
0
};
code
=
buildAlterTbReq
(
pCxt
,
pStmt
,
&
req
);
SArray
*
pArray
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildModifyVnodeArray
(
pCxt
,
pStmt
,
&
req
,
&
pArray
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pArray
);
}
return
code
;
}
static
int32_t
rewriteQuery
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
...
...
source/libs/parser/src/sql.c
浏览文件 @
9a3e1f03
...
...
@@ -3500,7 +3500,7 @@ static YYACTIONTYPE yy_reduce(
yymsp
[
-
4
].
minor
.
yy172
=
yylhsminor
.
yy172
;
break
;
case
121
:
/* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */
{
yylhsminor
.
yy172
=
createAlterTableSetTag
(
pCxt
,
yymsp
[
-
5
].
minor
.
yy172
,
&
yymsp
[
-
2
].
minor
.
yy105
,
yymsp
[
0
].
minor
.
yy172
);
}
{
yylhsminor
.
yy172
=
createAlterTableSetTag
(
pCxt
,
yymsp
[
-
5
].
minor
.
yy172
,
&
yymsp
[
-
2
].
minor
.
yy105
,
releaseRawExprNode
(
pCxt
,
yymsp
[
0
].
minor
.
yy172
)
);
}
yymsp
[
-
5
].
minor
.
yy172
=
yylhsminor
.
yy172
;
break
;
case
123
:
/* multi_create_clause ::= multi_create_clause create_subtable_clause */
...
...
source/libs/parser/test/parInitialATest.cpp
浏览文件 @
9a3e1f03
...
...
@@ -69,7 +69,7 @@ TEST_F(ParserInitialATest, alterDatabase) {
* | COMMENT 'string_value'
* }
*/
TEST_F
(
ParserInitialATest
,
alterTable
)
{
TEST_F
(
ParserInitialATest
,
alter
S
Table
)
{
useDb
(
"root"
,
"test"
);
SMAlterStbReq
expect
=
{
0
};
...
...
@@ -119,7 +119,7 @@ TEST_F(ParserInitialATest, alterTable) {
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_TABLE_STMT
);
SMAlterStbReq
req
=
{
0
};
ASSERT_
TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSMAlterStbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
)
);
ASSERT_
EQ
(
tDeserializeSMAlterStbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
name
),
std
::
string
(
expect
.
name
));
ASSERT_EQ
(
req
.
alterType
,
expect
.
alterType
);
ASSERT_EQ
(
req
.
numOfFields
,
expect
.
numOfFields
);
...
...
@@ -139,24 +139,24 @@ TEST_F(ParserInitialATest, alterTable) {
}
});
setAlterStbReqFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_OPTIONS
,
0
,
nullptr
,
0
,
0
,
nullptr
,
nullptr
,
10
);
run
(
"ALTER TABLE t1 TTL 10"
);
setAlterStbReqFunc
(
"
s
t1"
,
TSDB_ALTER_TABLE_UPDATE_OPTIONS
,
0
,
nullptr
,
0
,
0
,
nullptr
,
nullptr
,
10
);
run
(
"ALTER TABLE
s
t1 TTL 10"
);
setAlterStbReqFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_OPTIONS
,
0
,
nullptr
,
0
,
0
,
nullptr
,
"test"
);
run
(
"ALTER TABLE t1 COMMENT 'test'"
);
setAlterStbReqFunc
(
"
s
t1"
,
TSDB_ALTER_TABLE_UPDATE_OPTIONS
,
0
,
nullptr
,
0
,
0
,
nullptr
,
"test"
);
run
(
"ALTER TABLE
s
t1 COMMENT 'test'"
);
setAlterStbReqFunc
(
"t1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
1
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE t1 ADD COLUMN cc1 BIGINT"
);
setAlterStbReqFunc
(
"
s
t1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
1
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE
s
t1 ADD COLUMN cc1 BIGINT"
);
setAlterStbReqFunc
(
"t1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
1
,
"c1"
);
run
(
"ALTER TABLE t1 DROP COLUMN c1"
);
setAlterStbReqFunc
(
"
s
t1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
1
,
"c1"
);
run
(
"ALTER TABLE
s
t1 DROP COLUMN c1"
);
setAlterStbReqFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
1
,
"c1"
,
TSDB_DATA_TYPE_VARCHAR
,
setAlterStbReqFunc
(
"
s
t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
1
,
"c1"
,
TSDB_DATA_TYPE_VARCHAR
,
20
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE t1 MODIFY COLUMN c1 VARCHAR(20)"
);
run
(
"ALTER TABLE
s
t1 MODIFY COLUMN c1 VARCHAR(20)"
);
setAlterStbReqFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
2
,
"c1"
,
0
,
0
,
"cc1"
);
run
(
"ALTER TABLE t1 RENAME COLUMN c1 cc1"
);
setAlterStbReqFunc
(
"
s
t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
2
,
"c1"
,
0
,
0
,
"cc1"
);
run
(
"ALTER TABLE
s
t1 RENAME COLUMN c1 cc1"
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_TAG
,
1
,
"tag11"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE st1 ADD TAG tag11 BIGINT"
);
...
...
@@ -171,7 +171,127 @@ TEST_F(ParserInitialATest, alterTable) {
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
,
2
,
"tag1"
,
0
,
0
,
"tag11"
);
run
(
"ALTER TABLE st1 RENAME TAG tag1 tag11"
);
// run("ALTER TABLE st1s1 SET TAG tag1=10");
// todo
// ADD {FULLTEXT | SMA} INDEX index_name (col_name [, col_name] ...) [index_option]
}
TEST_F
(
ParserInitialATest
,
alterTable
)
{
useDb
(
"root"
,
"test"
);
SVAlterTbReq
expect
=
{
0
};
auto
setAlterColFunc
=
[
&
](
const
char
*
pTbname
,
int8_t
alterType
,
const
char
*
pColName
,
int8_t
dataType
=
0
,
int32_t
dataBytes
=
0
,
const
char
*
pNewColName
=
nullptr
)
{
memset
(
&
expect
,
0
,
sizeof
(
SVAlterTbReq
));
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
alterType
;
expect
.
colName
=
strdup
(
pColName
);
switch
(
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
expect
.
type
=
dataType
;
expect
.
flags
=
COL_SMA_ON
;
expect
.
bytes
=
dataBytes
>
0
?
dataBytes
:
(
dataType
>
0
?
tDataTypes
[
dataType
].
bytes
:
0
);
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
expect
.
colModBytes
=
dataBytes
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
expect
.
colNewName
=
strdup
(
pNewColName
);
break
;
default:
break
;
}
};
auto
setAlterTagFunc
=
[
&
](
const
char
*
pTbname
,
const
char
*
pTagName
,
const
uint8_t
*
pNewVal
,
uint32_t
bytes
)
{
memset
(
&
expect
,
0
,
sizeof
(
SVAlterTbReq
));
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
;
expect
.
tagName
=
strdup
(
pTagName
);
expect
.
isNull
=
(
nullptr
==
pNewVal
);
expect
.
nTagVal
=
bytes
;
expect
.
pTagVal
=
pNewVal
;
};
auto
setAlterOptionsFunc
=
[
&
](
const
char
*
pTbname
,
int32_t
ttl
,
const
char
*
pComment
=
nullptr
)
{
memset
(
&
expect
,
0
,
sizeof
(
SVAlterTbReq
));
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
TSDB_ALTER_TABLE_UPDATE_OPTIONS
;
if
(
-
1
!=
ttl
)
{
expect
.
updateTTL
=
true
;
expect
.
newTTL
=
ttl
;
}
if
(
nullptr
!=
pComment
)
{
expect
.
updateComment
=
true
;
expect
.
newComment
=
pComment
;
}
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_VNODE_MODIF_STMT
);
SVnodeModifOpStmt
*
pStmt
=
(
SVnodeModifOpStmt
*
)
pQuery
->
pRoot
;
ASSERT_EQ
(
pStmt
->
sqlNodeType
,
QUERY_NODE_ALTER_TABLE_STMT
);
ASSERT_NE
(
pStmt
->
pDataBlocks
,
nullptr
);
ASSERT_EQ
(
taosArrayGetSize
(
pStmt
->
pDataBlocks
),
1
);
SVgDataBlocks
*
pVgData
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pStmt
->
pDataBlocks
,
0
);
void
*
pBuf
=
POINTER_SHIFT
(
pVgData
->
pData
,
sizeof
(
SMsgHead
));
SVAlterTbReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
tDecoderInit
(
&
coder
,
(
const
uint8_t
*
)
pBuf
,
pVgData
->
size
);
ASSERT_EQ
(
tDecodeSVAlterTbReq
(
&
coder
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
tbName
),
std
::
string
(
expect
.
tbName
));
ASSERT_EQ
(
req
.
action
,
expect
.
action
);
if
(
nullptr
!=
expect
.
colName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
colName
),
std
::
string
(
expect
.
colName
));
}
ASSERT_EQ
(
req
.
type
,
expect
.
type
);
ASSERT_EQ
(
req
.
flags
,
expect
.
flags
);
ASSERT_EQ
(
req
.
bytes
,
expect
.
bytes
);
ASSERT_EQ
(
req
.
colModBytes
,
expect
.
colModBytes
);
if
(
nullptr
!=
expect
.
colNewName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
colNewName
),
std
::
string
(
expect
.
colNewName
));
}
if
(
nullptr
!=
expect
.
tagName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
tagName
),
std
::
string
(
expect
.
tagName
));
}
ASSERT_EQ
(
req
.
isNull
,
expect
.
isNull
);
ASSERT_EQ
(
req
.
nTagVal
,
expect
.
nTagVal
);
ASSERT_EQ
(
memcmp
(
req
.
pTagVal
,
expect
.
pTagVal
,
expect
.
nTagVal
),
0
);
ASSERT_EQ
(
req
.
updateTTL
,
expect
.
updateTTL
);
ASSERT_EQ
(
req
.
newTTL
,
expect
.
newTTL
);
ASSERT_EQ
(
req
.
updateComment
,
expect
.
updateComment
);
if
(
nullptr
!=
expect
.
newComment
)
{
ASSERT_EQ
(
std
::
string
(
req
.
newComment
),
std
::
string
(
expect
.
newComment
));
}
tDecoderClear
(
&
coder
);
});
setAlterOptionsFunc
(
"t1"
,
10
,
nullptr
);
run
(
"ALTER TABLE t1 TTL 10"
);
setAlterOptionsFunc
(
"t1"
,
-
1
,
"test"
);
run
(
"ALTER TABLE t1 COMMENT 'test'"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE t1 ADD COLUMN cc1 BIGINT"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
"c1"
);
run
(
"ALTER TABLE t1 DROP COLUMN c1"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
"c1"
,
TSDB_DATA_TYPE_VARCHAR
,
20
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE t1 MODIFY COLUMN c1 VARCHAR(20)"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
"c1"
,
0
,
0
,
"cc1"
);
run
(
"ALTER TABLE t1 RENAME COLUMN c1 cc1"
);
int64_t
val
=
10
;
setAlterTagFunc
(
"st1s1"
,
"tag1"
,
(
const
uint8_t
*
)
&
val
,
sizeof
(
val
));
run
(
"ALTER TABLE st1s1 SET TAG tag1=10"
);
// todo
// ADD {FULLTEXT | SMA} INDEX index_name (col_name [, col_name] ...) [index_option]
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
9a3e1f03
...
...
@@ -985,6 +985,8 @@ static int32_t getMsgType(ENodeType sqlType) {
return
TDMT_VND_CREATE_TABLE
;
case
QUERY_NODE_DROP_TABLE_STMT
:
return
TDMT_VND_DROP_TABLE
;
case
QUERY_NODE_ALTER_TABLE_STMT
:
return
TDMT_VND_ALTER_TABLE
;
default:
break
;
}
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
9a3e1f03
...
...
@@ -256,6 +256,7 @@ int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t m
return
TSDB_CODE_SUCCESS
;
case
TDMT_VND_CREATE_TABLE_RSP
:
case
TDMT_VND_DROP_TABLE_RSP
:
case
TDMT_VND_ALTER_TABLE_RSP
:
case
TDMT_VND_SUBMIT_RSP
:
break
;
default:
...
...
@@ -1131,6 +1132,24 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
SCH_ERR_RET
(
schProcessOnTaskSuccess
(
pJob
,
pTask
));
break
;
}
case
TDMT_VND_ALTER_TABLE_RSP
:
{
SVAlterTbRsp
rsp
=
{
0
};
if
(
msg
)
{
SDecoder
coder
=
{
0
};
tDecoderInit
(
&
coder
,
msg
,
msgSize
);
code
=
tDecodeSVAlterTbRsp
(
&
coder
,
&
rsp
);
tDecoderClear
(
&
coder
);
SCH_ERR_JRET
(
code
);
SCH_ERR_JRET
(
rsp
.
code
);
}
SCH_ERR_JRET
(
rspCode
);
if
(
NULL
==
msg
)
{
SCH_ERR_JRET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
break
;
}
case
TDMT_VND_SUBMIT_RSP
:
{
SCH_ERR_JRET
(
rspCode
);
...
...
@@ -1391,6 +1410,10 @@ int32_t schHandleDropTableCallback(void *param, const SDataBuf *pMsg, int32_t co
return
schHandleCallback
(
param
,
pMsg
,
TDMT_VND_DROP_TABLE_RSP
,
code
);
}
int32_t
schHandleAlterTableCallback
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
return
schHandleCallback
(
param
,
pMsg
,
TDMT_VND_ALTER_TABLE_RSP
,
code
);
}
int32_t
schHandleQueryCallback
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
return
schHandleCallback
(
param
,
pMsg
,
TDMT_VND_QUERY_RSP
,
code
);
}
...
...
@@ -1490,6 +1513,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) {
case
TDMT_VND_DROP_TABLE
:
*
fp
=
schHandleDropTableCallback
;
break
;
case
TDMT_VND_ALTER_TABLE
:
*
fp
=
schHandleAlterTableCallback
;
break
;
case
TDMT_VND_SUBMIT
:
*
fp
=
schHandleSubmitCallback
;
break
;
...
...
@@ -2010,6 +2036,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
switch
(
msgType
)
{
case
TDMT_VND_CREATE_TABLE
:
case
TDMT_VND_DROP_TABLE
:
case
TDMT_VND_ALTER_TABLE
:
case
TDMT_VND_SUBMIT
:
{
msgSize
=
pTask
->
msgLen
;
msg
=
taosMemoryCalloc
(
1
,
msgSize
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录