Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
67671328
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,发现更多精彩内容 >>
未验证
提交
67671328
编写于
2月 19, 2021
作者:
H
haojun Liao
提交者:
GitHub
2月 19, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5214 from taosdata/feature/TD-2423
[TD-2423]support create child table with specified tag list
上级
8e891f78
ab28ecd0
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
1459 addition
and
881 deletion
+1459
-881
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+99
-26
src/inc/ttokendef.h
src/inc/ttokendef.h
+3
-2
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+2
-1
src/query/inc/sql.y
src/query/inc/sql.y
+12
-1
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+4
-2
src/query/src/sql.c
src/query/src/sql.c
+1177
-849
tests/script/general/parser/create_tb_with_tag_name.sim
tests/script/general/parser/create_tb_with_tag_name.sim
+162
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
67671328
...
...
@@ -6375,16 +6375,14 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
// get table meta from mnode
code
=
tNameExtractFullName
(
&
pStableMetaInfo
->
name
,
pCreateTableInfo
->
tagdata
.
name
);
SArray
*
pList
=
pCreateTableInfo
->
pTagVals
;
SArray
*
p
Val
List
=
pCreateTableInfo
->
pTagVals
;
code
=
tscGetTableMeta
(
pSql
,
pStableMetaInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
size_t
size
=
taosArrayGetSize
(
pList
);
if
(
tscGetNumOfTags
(
pStableMetaInfo
->
pTableMeta
)
!=
size
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
size_t
valSize
=
taosArrayGetSize
(
pValList
);
// too long tag values will return invalid sql, not be truncated automatically
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pStableMetaInfo
->
pTableMeta
);
...
...
@@ -6395,36 +6393,111 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
SArray
*
pNameList
=
NULL
;
size_t
nameSize
=
0
;
int32_t
schemaSize
=
tscGetNumOfTags
(
pStableMetaInfo
->
pTableMeta
);
int32_t
ret
=
TSDB_CODE_SUCCESS
;
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SSchema
*
pSchema
=
&
pTagSchema
[
i
];
tVariantListItem
*
pItem
=
taosArrayGet
(
pList
,
i
);
char
tagVal
[
TSDB_MAX_TAGS_LEN
];
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pItem
->
pVar
.
nLen
>
pSchema
->
bytes
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
pCreateTableInfo
->
pTagNames
)
{
pNameList
=
pCreateTableInfo
->
pTagNames
;
nameSize
=
taosArrayGetSize
(
pNameList
);
if
(
valSize
!=
nameSize
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
ret
=
tVariantDump
(
&
(
pItem
->
pVar
),
tagVal
,
pSchema
->
type
,
true
);
if
(
schemaSize
<
valSize
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
// check again after the convert since it may be converted from binary to nchar.
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int16_t
len
=
varDataTLen
(
tagVal
);
if
(
len
>
pSchema
->
bytes
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
bool
findColumnIndex
=
false
;
for
(
int32_t
i
=
0
;
i
<
nameSize
;
++
i
)
{
SStrToken
*
sToken
=
taosArrayGet
(
pNameList
,
i
);
if
(
TK_STRING
==
sToken
->
type
)
{
tscDequoteAndTrimToken
(
sToken
);
}
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
tVariantListItem
*
pItem
=
taosArrayGet
(
pValList
,
i
);
findColumnIndex
=
false
;
// todo speedup by using hash list
for
(
int32_t
t
=
0
;
t
<
schemaSize
;
++
t
)
{
if
(
strncmp
(
sToken
->
z
,
pTagSchema
[
t
].
name
,
sToken
->
n
)
==
0
&&
strlen
(
pTagSchema
[
t
].
name
)
==
sToken
->
n
)
{
SSchema
*
pSchema
=
&
pTagSchema
[
t
];
char
tagVal
[
TSDB_MAX_TAGS_LEN
];
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pItem
->
pVar
.
nLen
>
pSchema
->
bytes
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
ret
=
tVariantDump
(
&
(
pItem
->
pVar
),
tagVal
,
pSchema
->
type
,
true
);
// check again after the convert since it may be converted from binary to nchar.
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int16_t
len
=
varDataTLen
(
tagVal
);
if
(
len
>
pSchema
->
bytes
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
tdAddColToKVRow
(
&
kvRowBuilder
,
pSchema
->
colId
,
pSchema
->
type
,
tagVal
);
findColumnIndex
=
true
;
break
;
}
}
if
(
!
findColumnIndex
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid tag name"
,
sToken
->
z
);
}
}
}
else
{
if
(
schemaSize
!=
valSize
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
tdAddColToKVRow
(
&
kvRowBuilder
,
pSchema
->
colId
,
pSchema
->
type
,
tagVal
);
for
(
int32_t
i
=
0
;
i
<
valSize
;
++
i
)
{
SSchema
*
pSchema
=
&
pTagSchema
[
i
];
tVariantListItem
*
pItem
=
taosArrayGet
(
pValList
,
i
);
char
tagVal
[
TSDB_MAX_TAGS_LEN
];
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pItem
->
pVar
.
nLen
>
pSchema
->
bytes
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
ret
=
tVariantDump
(
&
(
pItem
->
pVar
),
tagVal
,
pSchema
->
type
,
true
);
// check again after the convert since it may be converted from binary to nchar.
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int16_t
len
=
varDataTLen
(
tagVal
);
if
(
len
>
pSchema
->
bytes
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
tdAddColToKVRow
(
&
kvRowBuilder
,
pSchema
->
colId
,
pSchema
->
type
,
tagVal
);
}
}
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
kvRowBuilder
);
...
...
src/inc/ttokendef.h
浏览文件 @
67671328
...
...
@@ -122,8 +122,8 @@
#define TK_UNSIGNED 103
#define TK_TAGS 104
#define TK_USING 105
#define TK_
AS
106
#define TK_
COMMA
107
#define TK_
COMMA
106
#define TK_
AS
107
#define TK_NULL 108
#define TK_SELECT 109
#define TK_UNION 110
...
...
@@ -228,6 +228,7 @@
#define TK_VALUES 209
#define TK_SPACE 300
#define TK_COMMENT 301
#define TK_ILLEGAL 302
...
...
src/query/inc/qSqlparser.h
浏览文件 @
67671328
...
...
@@ -76,6 +76,7 @@ typedef struct SQuerySQL {
typedef
struct
SCreatedTableInfo
{
SStrToken
name
;
// table name token
SStrToken
stableName
;
// super table name token , for using clause
SArray
*
pTagNames
;
// create by using super table, tag name
SArray
*
pTagVals
;
// create by using super table, tag value
char
*
fullname
;
// table full name
STagData
tagdata
;
// true tag data, super table full name is in STagData
...
...
@@ -246,7 +247,7 @@ SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSe
void
tSqlExprNodeDestroy
(
tSQLExpr
*
pExpr
);
SAlterTableInfo
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableTable
);
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTagVals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
);
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTag
Names
,
SArray
*
pTag
Vals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
);
void
destroyAllSelectClause
(
SSubclauseInfo
*
pSql
);
void
doDestroyQuerySql
(
SQuerySQL
*
pSql
);
...
...
src/query/inc/sql.y
浏览文件 @
67671328
...
...
@@ -356,9 +356,20 @@ create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP T
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. {
X.n += F.n;
V.n += Z.n;
A = createNewChildTableInfo(&X, Y, &V, &U);
A = createNewChildTableInfo(&X,
NULL,
Y, &V, &U);
}
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) LP tagNamelist(P) RP TAGS LP tagitemlist(Y) RP. {
X.n += F.n;
V.n += Z.n;
A = createNewChildTableInfo(&X, P, Y, &V, &U);
}
%type tagNamelist{SArray*}
%destructor tagNamelist {taosArrayDestroy($$);}
tagNamelist(A) ::= tagNamelist(X) COMMA ids(Y). {taosArrayPush(X, &Y); A = X; }
tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(A, &X);}
// create stream
// create table table_name as select count(*) from super_table_name interval(time)
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). {
...
...
src/query/src/qParserImpl.c
浏览文件 @
67671328
...
...
@@ -496,7 +496,8 @@ static void freeVariant(void *pItem) {
}
void
freeCreateTableInfo
(
void
*
p
)
{
SCreatedTableInfo
*
pInfo
=
(
SCreatedTableInfo
*
)
p
;
SCreatedTableInfo
*
pInfo
=
(
SCreatedTableInfo
*
)
p
;
taosArrayDestroy
(
pInfo
->
pTagNames
);
taosArrayDestroyEx
(
pInfo
->
pTagVals
,
freeVariant
);
tfree
(
pInfo
->
fullname
);
tfree
(
pInfo
->
tagdata
.
data
);
...
...
@@ -574,11 +575,12 @@ SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSe
return
pCreate
;
}
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTagVals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
)
{
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTag
Names
,
SArray
*
pTag
Vals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
)
{
SCreatedTableInfo
info
;
memset
(
&
info
,
0
,
sizeof
(
SCreatedTableInfo
));
info
.
name
=
*
pToken
;
info
.
pTagNames
=
pTagNames
;
info
.
pTagVals
=
pTagVals
;
info
.
stableName
=
*
pTableName
;
info
.
igExist
=
(
igExists
->
n
>
0
)
?
1
:
0
;
...
...
src/query/src/sql.c
浏览文件 @
67671328
此差异已折叠。
点击以展开。
tests/script/general/parser/create_tb_with_tag_name.sim
0 → 100644
浏览文件 @
67671328
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 0
system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
print ======================== dnode1 start
$db = testdb
sql create database $db
sql use $db
sql create stable st2 (ts timestamp, f1 int) tags (id int, t1 int, t2 nchar(4), t3 double)
sql insert into tb1 using st2 (id, t1) tags(1,2) values (now, 1)
sql select id,t1,t2,t3 from tb1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != NULL then
return -1
endi
if $data03 != NULL then
return -1
endi
sql create table tb2 using st2 (t2,t3) tags ("12",22.0)
sql select id,t1,t2,t3 from tb2;
if $rows != 1 then
return -1
endi
if $data00 != NULL then
return -1
endi
if $data01 != NULL then
return -1
endi
if $data02 != 12 then
return -1
endi
if $data03 != 22.000000000 then
return -1
endi
sql create table tb3 using st2 tags (1,2,"3",33.0);
sql select id,t1,t2,t3 from tb3;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != 3 then
return -1
endi
if $data03 != 33.000000000 then
return -1
endi
sql insert into tb4 using st2 tags(1,2,"33",44.0) values (now, 1);
sql select id,t1,t2,t3 from tb4;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != 33 then
return -1
endi
if $data03 != 44.000000000 then
return -1
endi
sql_error create table tb5 using st2() tags (3,3,"3",33.0);
sql_error create table tb6 using st2 (id,t1) tags (3,3,"3",33.0);
sql_error create table tb7 using st2 (id,t1) tags (3);
sql_error create table tb8 using st2 (ide) tags (3);
sql_error create table tb9 using st2 (id);
sql_error create table tb10 using st2 (id t1) tags (1,1);
sql_error create table tb10 using st2 (id,,t1) tags (1,1,1);
sql_error create table tb11 using st2 (id,t1,) tags (1,1,1);
sql create table tb12 using st2 (t1,id) tags (2,1);
sql select id,t1,t2,t3 from tb12;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != NULL then
return -1
endi
if $data03 != NULL then
return -1
endi
sql create table tb13 using st2 ("t1",'id') tags (2,1);
sql select id,t1,t2,t3 from tb13;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != NULL then
return -1
endi
if $data03 != NULL then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录