Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b0f01a98
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
未验证
提交
b0f01a98
编写于
10月 20, 2021
作者:
H
huolibo
提交者:
GitHub
10月 20, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8330 from taosdata/fix/TS_478
[TS-478]<fix>: insert status can use , or whitespace as separator in …
上级
65319ee1
150c1095
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
69 addition
and
1 deletion
+69
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java
...tor/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java
+1
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java
...jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java
+68
-0
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java
浏览文件 @
b0f01a98
...
...
@@ -121,7 +121,7 @@ public class Utils {
}
private
static
void
findValuesClauseRangeSet
(
String
preparedSql
,
RangeSet
<
Integer
>
clauseRangeSet
)
{
Matcher
matcher
=
Pattern
.
compile
(
"(values|,)\\s*(\\([^)]*\\))"
).
matcher
(
preparedSql
);
Matcher
matcher
=
Pattern
.
compile
(
"(values|
|
,)\\s*(\\([^)]*\\))"
).
matcher
(
preparedSql
);
while
(
matcher
.
find
())
{
int
start
=
matcher
.
start
(
2
);
int
end
=
matcher
.
end
(
2
);
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java
浏览文件 @
b0f01a98
...
...
@@ -73,6 +73,48 @@ public class UtilsTest {
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
multiValuesAndWhitespace
()
{
// given
String
nativeSql
=
"INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?) (?,?,?,?) (?,?,?,?)"
;
Object
[]
parameters
=
Stream
.
of
(
"d1"
,
1
,
100
,
3.14
,
"abc"
,
4
,
200
,
3.1415
,
"xyz"
,
5
,
300
,
3.141592
,
"uvw"
,
6
).
toArray
();
// when
String
actual
=
Utils
.
getNativeSql
(
nativeSql
,
parameters
);
// then
String
expected
=
"INSERT INTO d1 (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (1) VALUES (100,3.14,'abc',4) (200,3.1415,'xyz',5) (300,3.141592,'uvw',6)"
;
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
multiValuesNoSeparator
()
{
// given
String
nativeSql
=
"INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?)(?,?,?,?)(?,?,?,?)"
;
Object
[]
parameters
=
Stream
.
of
(
"d1"
,
1
,
100
,
3.14
,
"abc"
,
4
,
200
,
3.1415
,
"xyz"
,
5
,
300
,
3.141592
,
"uvw"
,
6
).
toArray
();
// when
String
actual
=
Utils
.
getNativeSql
(
nativeSql
,
parameters
);
// then
String
expected
=
"INSERT INTO d1 (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (1) VALUES (100,3.14,'abc',4)(200,3.1415,'xyz',5)(300,3.141592,'uvw',6)"
;
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
multiValuesMultiSeparator
()
{
// given
String
nativeSql
=
"INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?) (?,?,?,?), (?,?,?,?)"
;
Object
[]
parameters
=
Stream
.
of
(
"d1"
,
1
,
100
,
3.14
,
"abc"
,
4
,
200
,
3.1415
,
"xyz"
,
5
,
300
,
3.141592
,
"uvw"
,
6
).
toArray
();
// when
String
actual
=
Utils
.
getNativeSql
(
nativeSql
,
parameters
);
// then
String
expected
=
"INSERT INTO d1 (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (1) VALUES (100,3.14,'abc',4) (200,3.1415,'xyz',5), (300,3.141592,'uvw',6)"
;
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
lineTerminator
()
{
// given
...
...
@@ -100,6 +142,32 @@ public class UtilsTest {
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
lineTerminatorAndMultiValuesAndNoneOrMoreWhitespace
()
{
String
nativeSql
=
"INSERT Into ? TAGS(?) VALUES(?,?,\r\n?,?),(?,? ,\r\n?,?) t? tags (?) Values (?,?,?\r\n,?) (?,?,?,?) t? Tags(?) values (?,?,?,?) , (?,?,?,?)"
;
Object
[]
parameters
=
Stream
.
of
(
"t1"
,
"abc"
,
100
,
1.1
,
"xxx"
,
"xxx"
,
200
,
2.2
,
"xxx"
,
"xxx"
,
2
,
"bcd"
,
300
,
3.3
,
"xxx"
,
"xxx"
,
400
,
4.4
,
"xxx"
,
"xxx"
,
3
,
"cde"
,
500
,
5.5
,
"xxx"
,
"xxx"
,
600
,
6.6
,
"xxx"
,
"xxx"
).
toArray
();
// when
String
actual
=
Utils
.
getNativeSql
(
nativeSql
,
parameters
);
// then
String
expected
=
"INSERT Into t1 TAGS('abc') VALUES(100,1.1,\r\n'xxx','xxx'),(200,2.2 ,\r\n'xxx','xxx') t2 tags ('bcd') Values (300,3.3,'xxx'\r\n,'xxx') (400,4.4,'xxx','xxx') t3 Tags('cde') values (500,5.5,'xxx','xxx') , (600,6.6,'xxx','xxx')"
;
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
multiValuesAndNoneOrMoreWhitespace
()
{
String
nativeSql
=
"INSERT INTO ? USING traces TAGS (?, ?) VALUES (?, ?, ?, ?, ?, ?, ?) (?, ?, ?, ?, ?, ?, ?)"
;
Object
[]
parameters
=
Stream
.
of
(
"t1"
,
"t1"
,
"t2"
,
1632968284000L
,
111.111
,
119.001
,
0.4
,
90
,
99.1
,
"WGS84"
,
1632968285000L
,
111.21109999999999
,
120.001
,
0.5
,
91
,
99.19999999999999
,
"WGS84"
).
toArray
();
// when
String
actual
=
Utils
.
getNativeSql
(
nativeSql
,
parameters
);
// then
String
expected
=
"INSERT INTO t1 USING traces TAGS ('t1', 't2') VALUES (1632968284000, 111.111, 119.001, 0.4, 90, 99.1, 'WGS84') (1632968285000, 111.21109999999999, 120.001, 0.5, 91, 99.19999999999999, 'WGS84')"
;
Assert
.
assertEquals
(
expected
,
actual
);
}
@Test
public
void
replaceNothing
()
{
// given
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录