Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bb1639d4
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看板
提交
bb1639d4
编写于
5月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more alter table
上级
94cea61c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
142 addition
and
18 deletion
+142
-18
include/common/tmsg.h
include/common/tmsg.h
+5
-8
include/util/taoserror.h
include/util/taoserror.h
+2
-1
source/common/src/tmsg.c
source/common/src/tmsg.c
+2
-8
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+131
-1
source/util/src/terror.c
source/util/src/terror.c
+2
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
bb1639d4
...
@@ -1764,18 +1764,15 @@ int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
...
@@ -1764,18 +1764,15 @@ int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
typedef
struct
{
typedef
struct
{
const
char
*
tbName
;
const
char
*
tbName
;
int8_t
action
;
int8_t
action
;
const
char
*
colName
;
// TSDB_ALTER_TABLE_ADD_COLUMN
// TSDB_ALTER_TABLE_ADD_COLUMN
int8_t
type
;
int8_t
type
;
int8_t
flags
;
int8_t
flags
;
int32_t
bytes
;
int32_t
bytes
;
const
char
*
colAddName
;
// TSDB_ALTER_TABLE_DROP_COLUMN
// TSDB_ALTER_TABLE_DROP_COLUMN
const
char
*
colDropName
;
// TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
// TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
const
char
*
colModName
;
int32_t
colModBytes
;
int32_t
colModBytes
;
// TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
// TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
const
char
*
colOldName
;
const
char
*
colNewName
;
const
char
*
colNewName
;
// TSDB_ALTER_TABLE_UPDATE_TAG_VAL
// TSDB_ALTER_TABLE_UPDATE_TAG_VAL
const
char
*
tagName
;
const
char
*
tagName
;
...
...
include/util/taoserror.h
浏览文件 @
bb1639d4
...
@@ -324,7 +324,8 @@ int32_t* taosGetErrno();
...
@@ -324,7 +324,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0517)
#define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0517)
#define TSDB_CODE_VND_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0518)
#define TSDB_CODE_VND_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0518)
#define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0519)
#define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0519)
#define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051a)
#define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051a)
#define TSDB_CODE_VND_TABLE_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051b)
// tsdb
// tsdb
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
...
...
source/common/src/tmsg.c
浏览文件 @
bb1639d4
...
@@ -4169,22 +4169,19 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
...
@@ -4169,22 +4169,19 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
tbName
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
tbName
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pReq
->
action
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pReq
->
action
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colName
)
<
0
)
return
-
1
;
switch
(
pReq
->
action
)
{
switch
(
pReq
->
action
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
if
(
tEncodeI8
(
pEncoder
,
pReq
->
type
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pReq
->
type
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pReq
->
flags
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pReq
->
flags
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pReq
->
bytes
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pReq
->
bytes
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colAddName
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colDropName
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colModName
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pReq
->
colModBytes
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pEncoder
,
pReq
->
colModBytes
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colOldName
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colNewName
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pReq
->
colNewName
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
...
@@ -4217,22 +4214,19 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
...
@@ -4217,22 +4214,19 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
tbName
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
tbName
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
action
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
action
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colName
)
<
0
)
return
-
1
;
switch
(
pReq
->
action
)
{
switch
(
pReq
->
action
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
type
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
type
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
flags
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pReq
->
flags
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pReq
->
bytes
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pReq
->
bytes
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colAddName
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colDropName
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colModName
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pReq
->
colModBytes
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pReq
->
colModBytes
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colOldName
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colNewName
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
&
pReq
->
colNewName
)
<
0
)
return
-
1
;
break
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
bb1639d4
...
@@ -376,8 +376,138 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
...
@@ -376,8 +376,138 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
}
}
static
int
metaAlterTableColumn
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
static
int
metaAlterTableColumn
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
// TODO
void
*
pVal
=
NULL
;
int
nVal
=
0
;
const
void
*
pData
=
NULL
;
int
nData
=
0
;
int
ret
=
0
;
tb_uid_t
uid
;
int64_t
oversion
;
SSchema
*
pColumn
=
NULL
;
SMetaEntry
entry
=
{
0
};
SSchemaWrapper
*
pSchema
;
int
c
;
// search name index
ret
=
tdbDbGet
(
pMeta
->
pNameIdx
,
pAlterTbReq
->
tbName
,
strlen
(
pAlterTbReq
->
tbName
)
+
1
,
&
pVal
,
&
nVal
);
if
(
ret
<
0
)
{
terrno
=
TSDB_CODE_VND_TABLE_NOT_EXIST
;
return
-
1
;
}
uid
=
*
(
tb_uid_t
*
)
pVal
;
tdbFree
(
pVal
);
pVal
=
NULL
;
// search uid index
TDBC
*
pUidIdxc
=
NULL
;
tdbDbcOpen
(
pMeta
->
pUidIdx
,
&
pUidIdxc
,
&
pMeta
->
txn
);
tdbDbcMoveTo
(
pUidIdxc
,
&
uid
,
sizeof
(
uid
),
&
c
);
ASSERT
(
c
==
0
);
tdbDbcGet
(
pUidIdxc
,
NULL
,
NULL
,
&
pData
,
&
nData
);
oversion
=
*
(
int64_t
*
)
pData
;
// search table.db
TDBC
*
pTbDbc
=
NULL
;
tdbDbcOpen
(
pMeta
->
pTbDb
,
&
pTbDbc
,
&
pMeta
->
txn
);
tdbDbcMoveTo
(
pTbDbc
,
&
((
STbDbKey
){.
uid
=
uid
,
.
version
=
oversion
}),
sizeof
(
STbDbKey
),
&
c
);
ASSERT
(
c
==
0
);
tdbDbcGet
(
pTbDbc
,
NULL
,
NULL
,
&
pData
,
&
nData
);
// get table entry
SDecoder
dc
=
{
0
};
tDecoderInit
(
&
dc
,
pData
,
nData
);
metaDecodeEntry
(
&
dc
,
&
entry
);
if
(
entry
.
type
!=
TSDB_NORMAL_TABLE
)
{
terrno
=
TSDB_CODE_VND_INVALID_TABLE_ACTION
;
goto
_err
;
}
// search the column to add/drop/update
pSchema
=
&
entry
.
ntbEntry
.
schema
;
int32_t
iCol
=
0
;
for
(;;)
{
pColumn
=
NULL
;
if
(
iCol
>=
pSchema
->
nCols
)
break
;
pColumn
=
&
pSchema
->
pSchema
[
iCol
];
if
(
strcmp
(
pColumn
->
name
,
pAlterTbReq
->
colName
)
==
0
)
break
;
iCol
++
;
}
entry
.
version
=
version
;
int
tlen
;
switch
(
pAlterTbReq
->
action
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
if
(
pColumn
)
{
terrno
=
TSDB_CODE_VND_COL_ALREADY_EXISTS
;
goto
_err
;
}
pSchema
->
sver
++
;
pSchema
->
nCols
++
;
pSchema
->
pSchema
=
taosMemoryRealloc
(
entry
.
ntbEntry
.
schema
.
pSchema
,
sizeof
(
SSchema
)
*
entry
.
ntbEntry
.
schema
.
nCols
);
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
bytes
=
pAlterTbReq
->
bytes
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
type
=
pAlterTbReq
->
type
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
flags
=
pAlterTbReq
->
flags
;
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
colId
=
entry
.
ntbEntry
.
ncid
++
;
strcpy
(
pSchema
->
pSchema
[
entry
.
ntbEntry
.
schema
.
nCols
-
1
].
name
,
pAlterTbReq
->
colName
);
break
;
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
if
(
pColumn
==
NULL
)
{
terrno
=
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
;
goto
_err
;
}
if
(
pColumn
->
colId
==
0
)
{
terrno
=
TSDB_CODE_VND_INVALID_TABLE_ACTION
;
goto
_err
;
}
pSchema
->
sver
++
;
pSchema
->
nCols
--
;
tlen
=
(
pSchema
->
nCols
-
iCol
-
1
)
*
sizeof
(
SSchema
);
if
(
tlen
)
{
memmove
(
pColumn
,
pColumn
+
1
,
tlen
);
}
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
if
(
pColumn
==
NULL
)
{
terrno
=
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
;
goto
_err
;
}
if
(
!
IS_VAR_DATA_TYPE
(
pColumn
->
type
)
||
pColumn
->
bytes
<=
pAlterTbReq
->
bytes
)
{
terrno
=
TSDB_CODE_VND_INVALID_TABLE_ACTION
;
goto
_err
;
}
pSchema
->
sver
++
;
pColumn
->
bytes
=
pAlterTbReq
->
bytes
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
if
(
pColumn
==
NULL
)
{
terrno
=
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
;
goto
_err
;
}
pSchema
->
sver
++
;
strcpy
(
pColumn
->
name
,
pAlterTbReq
->
colNewName
);
break
;
}
entry
.
version
=
version
;
tDecoderClear
(
&
dc
);
tdbDbcClose
(
pTbDbc
);
tdbDbcClose
(
pUidIdxc
);
return
0
;
return
0
;
_err:
tDecoderClear
(
&
dc
);
tdbDbcClose
(
pTbDbc
);
tdbDbcClose
(
pUidIdxc
);
return
-
1
;
}
}
static
int
metaUpdateTableTagVal
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
static
int
metaUpdateTableTagVal
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
...
...
source/util/src/terror.c
浏览文件 @
bb1639d4
...
@@ -324,6 +324,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_HASH_MISMATCH, "Hash value mismatch")
...
@@ -324,6 +324,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_HASH_MISMATCH, "Hash value mismatch")
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_TABLE_NOT_EXIST
,
"Table does not exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_TABLE_NOT_EXIST
,
"Table does not exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_INVALID_TABLE_ACTION
,
"Invalid table action"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_INVALID_TABLE_ACTION
,
"Invalid table action"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_COL_ALREADY_EXISTS
,
"Table column already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_COL_ALREADY_EXISTS
,
"Table column already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
,
"Table column not exists"
)
// tsdb
// tsdb
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_TABLE_ID
,
"Invalid table ID"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_TABLE_ID
,
"Invalid table ID"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录