Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
11591254
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
11591254
编写于
12月 13, 2019
作者:
L
lihui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TBASE-1339]
上级
c8ea9186
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
89 addition
and
12 deletion
+89
-12
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+89
-12
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
11591254
...
...
@@ -759,20 +759,84 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"create table only from super table is allowed"
,
sToken
.
z
);
}
char
*
tagVal
=
pTag
->
data
;
SSchema
*
pTagSchema
=
tsGetTagSchema
(
pMeterMetaInfo
->
pMeterMeta
);
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
sql
+=
index
;
SParsedDataColInfo
spd
=
{
0
};
uint8_t
numOfTags
=
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
;
spd
.
numOfCols
=
numOfTags
;
// if specify some tags column
if
(
sToken
.
type
!=
TK_LP
)
{
tscSetAssignedColumnInfo
(
&
spd
,
pTagSchema
,
numOfTags
);
}
else
{
/* insert into tablename (col1, col2,..., coln) using superTableName (tagName1, tagName2, ..., tagNamen) tags(tagVal1, tagVal2, ..., tagValn) values(v1, v2,... vn); */
int16_t
offset
[
TSDB_MAX_COLUMNS
]
=
{
0
};
for
(
int32_t
t
=
1
;
t
<
numOfTags
;
++
t
)
{
offset
[
t
]
=
offset
[
t
-
1
]
+
pTagSchema
[
t
-
1
].
bytes
;
}
while
(
1
)
{
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
sql
+=
index
;
if
(
TK_STRING
==
sToken
.
type
)
{
sToken
.
n
=
strdequote
(
sToken
.
z
);
strtrim
(
sToken
.
z
);
sToken
.
n
=
(
uint32_t
)
strlen
(
sToken
.
z
);
}
if
(
sToken
.
type
==
TK_RP
)
{
break
;
}
bool
findColumnIndex
=
false
;
// todo speedup by using hash list
for
(
int32_t
t
=
0
;
t
<
numOfTags
;
++
t
)
{
if
(
strncmp
(
sToken
.
z
,
pTagSchema
[
t
].
name
,
sToken
.
n
)
==
0
&&
strlen
(
pTagSchema
[
t
].
name
)
==
sToken
.
n
)
{
SParsedColElem
*
pElem
=
&
spd
.
elems
[
spd
.
numOfAssignedCols
++
];
pElem
->
offset
=
offset
[
t
];
pElem
->
colIndex
=
t
;
if
(
spd
.
hasVal
[
t
]
==
true
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"duplicated tag name"
,
sToken
.
z
);
}
spd
.
hasVal
[
t
]
=
true
;
findColumnIndex
=
true
;
break
;
}
}
if
(
!
findColumnIndex
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid tag name"
,
sToken
.
z
);
}
}
if
(
spd
.
numOfAssignedCols
==
0
||
spd
.
numOfAssignedCols
>
numOfTags
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"tag name expected"
,
sToken
.
z
);
}
}
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
sql
+=
index
;
if
(
sToken
.
type
!=
TK_TAGS
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword TAGS expected"
,
s
ql
);
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"keyword TAGS expected"
,
s
Token
.
z
);
}
int32_t
numOfTagValues
=
0
;
uint32_t
ignoreTokenTypes
=
TK_LP
;
uint32_t
numOfIgnoreToken
=
1
;
while
(
1
)
{
for
(
int
i
=
0
;
i
<
spd
.
numOfAssignedCols
;
++
i
)
{
char
*
tagVal
=
pTag
->
data
+
spd
.
elems
[
i
].
offset
;
int16_t
colIndex
=
spd
.
elems
[
i
].
colIndex
;
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
true
,
numOfIgnoreToken
,
&
ignoreTokenTypes
);
sql
+=
index
;
...
...
@@ -788,26 +852,39 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
sToken
.
n
-=
2
;
}
code
=
tsParseOneColumnData
(
&
pTagSchema
[
numOfTagValues
],
&
sToken
,
tagVal
,
pCmd
->
payload
,
&
sql
,
false
,
pMeterMetaInfo
->
pMeterMeta
->
precision
);
code
=
tsParseOneColumnData
(
&
pTagSchema
[
colIndex
],
&
sToken
,
tagVal
,
pCmd
->
payload
,
&
sql
,
false
,
pMeterMetaInfo
->
pMeterMeta
->
precision
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
((
pTagSchema
[
numOfTagValues
].
type
==
TSDB_DATA_TYPE_BINARY
||
pTagSchema
[
numOfTagValues
].
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
sToken
.
n
>
pTagSchema
[
numOfTagValues
].
bytes
)
{
if
((
pTagSchema
[
colIndex
].
type
==
TSDB_DATA_TYPE_BINARY
||
pTagSchema
[
colIndex
].
type
==
TSDB_DATA_TYPE_NCHAR
)
&&
sToken
.
n
>
pTagSchema
[
colIndex
].
bytes
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"string too long"
,
sToken
.
z
);
}
}
tagVal
+=
pTagSchema
[
numOfTagValues
++
].
bytes
;
index
=
0
;
sToken
=
tStrGetToken
(
sql
,
&
index
,
false
,
0
,
NULL
);
sql
+=
index
;
if
(
sToken
.
n
==
0
||
sToken
.
type
!=
TK_RP
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
") expected"
,
sToken
.
z
);
}
if
(
numOfTagValues
!=
pMeterMetaInfo
->
pMeterMeta
->
numOfTags
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"number of tags mismatch"
,
sql
);
// 2. set the null value for the columns that do not assign values
if
(
spd
.
numOfAssignedCols
<
spd
.
numOfCols
)
{
char
*
ptr
=
pTag
->
data
;
for
(
int32_t
i
=
0
;
i
<
spd
.
numOfCols
;
++
i
)
{
if
(
!
spd
.
hasVal
[
i
])
{
// current tag column do not have any value to insert, set it to null
setNull
(
ptr
,
pTagSchema
[
i
].
type
,
pTagSchema
[
i
].
bytes
);
}
ptr
+=
pTagSchema
[
i
].
bytes
;
}
}
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid table name"
,
sql
);
return
tscInvalidSQLErrMsg
(
pCmd
->
payload
,
"invalid table name"
,
*
sqlstr
);
}
int32_t
ret
=
setMeterID
(
pSql
,
&
tableToken
,
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录