Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d5d73250
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看板
提交
d5d73250
编写于
5月 17, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: sql command 'alter table'
上级
f2693313
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
147 addition
and
50 deletion
+147
-50
include/util/taoserror.h
include/util/taoserror.h
+2
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+137
-47
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+4
-0
source/libs/parser/test/parInitialATest.cpp
source/libs/parser/test/parInitialATest.cpp
+3
-3
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+1
-0
未找到文件。
include/util/taoserror.h
浏览文件 @
d5d73250
...
...
@@ -644,6 +644,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_INVALID_TIMELINE_FUNC TAOS_DEF_ERROR_CODE(0, 0x2647)
#define TSDB_CODE_PAR_INVALID_PASSWD TAOS_DEF_ERROR_CODE(0, 0x2648)
#define TSDB_CODE_PAR_INVALID_ALTER_TABLE TAOS_DEF_ERROR_CODE(0, 0x2649)
#define TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY TAOS_DEF_ERROR_CODE(0, 0x264A)
#define TSDB_CODE_PAR_INVALID_MODIFY_COL TAOS_DEF_ERROR_CODE(0, 0x264B)
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
d5d73250
...
...
@@ -4254,7 +4254,135 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
return
rewriteToVnodeModifyOpStmt
(
pQuery
,
pBufArray
);
}
static
int32_t
buildAlterTbReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
SVAlterTbReq
*
pReq
)
{
static
SSchema
*
getColSchema
(
STableMeta
*
pTableMeta
,
const
char
*
pTagName
)
{
int32_t
numOfFields
=
getNumOfTags
(
pTableMeta
)
+
getNumOfColumns
(
pTableMeta
);
for
(
int32_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
SSchema
*
pTagSchema
=
pTableMeta
->
schema
+
i
;
if
(
0
==
strcmp
(
pTagName
,
pTagSchema
->
name
))
{
return
pTagSchema
;
}
}
return
NULL
;
}
static
int32_t
buildUpdateTagValReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
STableMeta
*
pTableMeta
,
SVAlterTbReq
*
pReq
)
{
SSchema
*
pSchema
=
getColSchema
(
pTableMeta
,
pStmt
->
colName
);
if
(
NULL
==
pSchema
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
}
pReq
->
tagName
=
strdup
(
pStmt
->
colName
);
if
(
NULL
==
pReq
->
tagName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
pStmt
->
pVal
,
schemaToDataType
(
pSchema
)))
{
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
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildAddColReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
STableMeta
*
pTableMeta
,
SVAlterTbReq
*
pReq
)
{
if
(
NULL
!=
getColSchema
(
pTableMeta
,
pStmt
->
colName
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_DUPLICATED_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
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildDropColReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
STableMeta
*
pTableMeta
,
SVAlterTbReq
*
pReq
)
{
SSchema
*
pSchema
=
getColSchema
(
pTableMeta
,
pStmt
->
colName
);
if
(
NULL
==
pSchema
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COLUMN
,
pStmt
->
colName
);
}
else
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
==
pSchema
->
colId
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY
);
}
pReq
->
colName
=
strdup
(
pStmt
->
colName
);
if
(
NULL
==
pReq
->
colName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildUpdateColReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
STableMeta
*
pTableMeta
,
SVAlterTbReq
*
pReq
)
{
pReq
->
colModBytes
=
calcTypeBytes
(
pStmt
->
dataType
);
SSchema
*
pSchema
=
getColSchema
(
pTableMeta
,
pStmt
->
colName
);
if
(
NULL
==
pSchema
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COLUMN
,
pStmt
->
colName
);
}
else
if
(
!
IS_VAR_DATA_TYPE
(
pSchema
->
type
)
||
pSchema
->
bytes
>=
pReq
->
colModBytes
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_MODIFY_COL
);
}
pReq
->
colName
=
strdup
(
pStmt
->
colName
);
if
(
NULL
==
pReq
->
colName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildRenameColReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
STableMeta
*
pTableMeta
,
SVAlterTbReq
*
pReq
)
{
if
(
NULL
==
getColSchema
(
pTableMeta
,
pStmt
->
colName
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COLUMN
,
pStmt
->
colName
);
}
if
(
NULL
!=
getColSchema
(
pTableMeta
,
pStmt
->
newColName
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_DUPLICATED_COLUMN
);
}
pReq
->
colName
=
strdup
(
pStmt
->
colName
);
pReq
->
colNewName
=
strdup
(
pStmt
->
newColName
);
if
(
NULL
==
pReq
->
colName
||
NULL
==
pReq
->
colNewName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildUpdateOptionsReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
SVAlterTbReq
*
pReq
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
-
1
!=
pStmt
->
pOptions
->
ttl
)
{
code
=
checkRangeOption
(
pCxt
,
"ttl"
,
pStmt
->
pOptions
->
ttl
,
TSDB_MIN_TABLE_TTL
,
INT32_MAX
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pReq
->
updateTTL
=
true
;
pReq
->
newTTL
=
pStmt
->
pOptions
->
ttl
;
}
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
'\0'
!=
pStmt
->
pOptions
->
comment
[
0
])
{
pReq
->
updateComment
=
true
;
pReq
->
newComment
=
strdup
(
pStmt
->
pOptions
->
comment
);
if
(
NULL
==
pReq
->
newComment
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
return
code
;
}
static
int32_t
buildAlterTbReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
STableMeta
*
pTableMeta
,
SVAlterTbReq
*
pReq
)
{
pReq
->
tbName
=
strdup
(
pStmt
->
tableName
);
if
(
NULL
==
pReq
->
tbName
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -4268,60 +4396,22 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt,
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
;
return
buildUpdateTagValReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
return
buildAddColReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
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
;
return
buildDropColReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
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
;
return
buildUpdateColReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
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
;
return
buildUpdateOptionsReq
(
pCxt
,
pStmt
,
pReq
);
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
;
return
buildRenameColReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
default:
break
;
}
return
TSDB_CODE_
SUCCESS
;
return
TSDB_CODE_
FAILED
;
}
static
int32_t
serializeAlterTbReq
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
,
SVAlterTbReq
*
pReq
,
...
...
@@ -4394,7 +4484,7 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
}
SVAlterTbReq
req
=
{
0
};
code
=
buildAlterTbReq
(
pCxt
,
pStmt
,
&
req
);
code
=
buildAlterTbReq
(
pCxt
,
pStmt
,
pTableMeta
,
&
req
);
SArray
*
pArray
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
d5d73250
...
...
@@ -154,6 +154,10 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return
"Invalid password"
;
case
TSDB_CODE_PAR_INVALID_ALTER_TABLE
:
return
"Invalid alter table statement"
;
case
TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY
:
return
"Primary timestamp column cannot be dropped"
;
case
TSDB_CODE_PAR_INVALID_MODIFY_COL
:
return
"Only binary/nchar column length could be modified"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
default:
...
...
source/libs/parser/test/parInitialATest.cpp
浏览文件 @
d5d73250
...
...
@@ -283,13 +283,13 @@ TEST_F(ParserInitialATest, alterTable) {
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
"c1"
);
run
(
"ALTER TABLE t1 DROP COLUMN c1"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
"c
1"
,
TSDB_DATA_TYPE_VARCHAR
,
2
0
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE t1 MODIFY COLUMN c
1 VARCHAR(2
0)"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
"c
2"
,
TSDB_DATA_TYPE_VARCHAR
,
3
0
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE t1 MODIFY COLUMN c
2 VARCHAR(3
0)"
);
setAlterColFunc
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
"c1"
,
0
,
0
,
"cc1"
);
run
(
"ALTER TABLE t1 RENAME COLUMN c1 cc1"
);
int
64
_t
val
=
10
;
int
32
_t
val
=
10
;
setAlterTagFunc
(
"st1s1"
,
"tag1"
,
(
const
uint8_t
*
)
&
val
,
sizeof
(
val
));
run
(
"ALTER TABLE st1s1 SET TAG tag1=10"
);
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
d5d73250
...
...
@@ -1148,6 +1148,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
if
(
NULL
==
msg
)
{
SCH_ERR_JRET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SCH_ERR_RET
(
schProcessOnTaskSuccess
(
pJob
,
pTask
));
break
;
}
case
TDMT_VND_SUBMIT_RSP
:
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录