Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
481f8aa6
I
Iotdb
项目概览
apache
/
Iotdb
12 个月 前同步成功
通知
25
Star
3344
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iotdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
481f8aa6
编写于
1月 21, 2022
作者:
X
Xuan Ronaldo
提交者:
GitHub
1月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IOTDB-2281][IOTDB-2286] fix bugs of csv tools (#4941)
上级
4310c457
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
12 deletion
+20
-12
cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
+20
-12
未找到文件。
cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
浏览文件 @
481f8aa6
...
...
@@ -83,6 +83,9 @@ public class ImportCsv extends AbstractCsvTool {
private
static
String
failedFileDirectory
=
null
;
private
static
Boolean
aligned
=
false
;
private
static
String
timeColumn
=
"Time"
;
private
static
String
deviceColumn
=
"Device"
;
/**
* create the commandline options.
*
...
...
@@ -263,7 +266,7 @@ public class ImportCsv extends AbstractCsvTool {
System
.
out
.
println
(
"Empty file!"
);
return
;
}
if
(!
"TIME"
.
equalsIgnoreCase
(
headerNames
.
get
(
0
)))
{
if
(!
timeColumn
.
equalsIgnoreCase
(
headerNames
.
get
(
0
)))
{
System
.
out
.
println
(
"No headers!"
);
return
;
}
...
...
@@ -277,7 +280,7 @@ public class ImportCsv extends AbstractCsvTool {
}
else
{
failedFilePath
=
failedFileDirectory
+
file
.
getName
()
+
".failed"
;
}
if
(!
"DEVICE"
.
equalsIgnoreCase
(
headerNames
.
get
(
1
)))
{
if
(!
deviceColumn
.
equalsIgnoreCase
(
headerNames
.
get
(
1
)))
{
writeDataAlignedByTime
(
headerNames
,
records
,
failedFilePath
);
}
else
{
writeDataAlignedByDevice
(
headerNames
,
records
,
failedFilePath
);
...
...
@@ -312,7 +315,7 @@ public class ImportCsv extends AbstractCsvTool {
e
.
printStackTrace
();
}
SimpleDateFormat
timeFormatter
=
formatterInit
(
records
.
get
(
0
).
get
(
"Time"
));
SimpleDateFormat
timeFormatter
=
formatterInit
(
records
.
get
(
0
).
get
(
timeColumn
));
ArrayList
<
List
<
Object
>>
failedRecords
=
new
ArrayList
<>();
...
...
@@ -377,14 +380,14 @@ public class ImportCsv extends AbstractCsvTool {
try
{
if
(
timeFormatter
==
null
)
{
try
{
times
.
add
(
Long
.
valueOf
(
record
.
get
(
"Time"
)));
times
.
add
(
Long
.
valueOf
(
record
.
get
(
timeColumn
)));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Meet error when insert csv because the format of time is not supported"
);
System
.
exit
(
0
);
}
}
else
{
times
.
add
(
timeFormatter
.
parse
(
record
.
get
(
"Time"
)).
getTime
());
times
.
add
(
timeFormatter
.
parse
(
record
.
get
(
timeColumn
)).
getTime
());
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
...
...
@@ -421,7 +424,7 @@ public class ImportCsv extends AbstractCsvTool {
HashMap
<
String
,
String
>
headerNameMap
=
new
HashMap
<>();
parseHeaders
(
headerNames
,
null
,
headerTypeMap
,
headerNameMap
);
Set
<
String
>
devices
=
records
.
stream
().
map
(
record
->
record
.
get
(
"Device"
)).
collect
(
Collectors
.
toSet
());
records
.
stream
().
map
(
record
->
record
.
get
(
deviceColumn
)).
collect
(
Collectors
.
toSet
());
String
devicesStr
=
StringUtils
.
join
(
devices
,
","
);
try
{
queryType
(
devicesStr
,
headerTypeMap
,
"Device"
);
...
...
@@ -429,7 +432,7 @@ public class ImportCsv extends AbstractCsvTool {
e
.
printStackTrace
();
}
SimpleDateFormat
timeFormatter
=
formatterInit
(
records
.
get
(
0
).
get
(
"Time"
));
SimpleDateFormat
timeFormatter
=
formatterInit
(
records
.
get
(
0
).
get
(
timeColumn
));
Set
<
String
>
measurementNames
=
headerNameMap
.
keySet
();
ArrayList
<
List
<
Object
>>
failedRecords
=
new
ArrayList
<>();
...
...
@@ -445,7 +448,7 @@ public class ImportCsv extends AbstractCsvTool {
final
int
BATCH_SIZE
=
1000
;
AtomicInteger
recordSize
=
new
AtomicInteger
();
records
.
stream
()
.
filter
(
record
->
record
.
get
(
"Device"
).
equals
(
device
))
.
filter
(
record
->
record
.
get
(
deviceColumn
).
equals
(
device
))
.
forEach
(
record
->
{
ArrayList
<
TSDataType
>
types
=
new
ArrayList
<>();
...
...
@@ -500,14 +503,14 @@ public class ImportCsv extends AbstractCsvTool {
try
{
if
(
timeFormatter
==
null
)
{
try
{
times
.
add
(
Long
.
valueOf
(
record
.
get
(
"Time"
)));
times
.
add
(
Long
.
valueOf
(
record
.
get
(
timeColumn
)));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Meet error when insert csv because the format of time is not supported"
);
System
.
exit
(
0
);
}
}
else
{
times
.
add
(
timeFormatter
.
parse
(
record
.
get
(
"Time"
)).
getTime
());
times
.
add
(
timeFormatter
.
parse
(
record
.
get
(
timeColumn
)).
getTime
());
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
...
...
@@ -598,7 +601,11 @@ public class ImportCsv extends AbstractCsvTool {
String
regex
=
"(?<=\\()\\S+(?=\\))"
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
for
(
String
headerName
:
headerNames
)
{
if
(
"Time"
.
equals
(
headerName
)
||
"Device"
.
equals
(
headerName
))
{
if
(
"Time"
.
equalsIgnoreCase
(
headerName
))
{
timeColumn
=
headerName
;
continue
;
}
else
if
(
"Device"
.
equalsIgnoreCase
(
headerName
))
{
deviceColumn
=
headerName
;
continue
;
}
Matcher
matcher
=
pattern
.
matcher
(
headerName
);
...
...
@@ -746,7 +753,8 @@ public class ImportCsv extends AbstractCsvTool {
try
{
switch
(
type
)
{
case
TEXT:
return
value
.
substring
(
1
,
value
.
length
()
-
1
);
if
(
value
.
startsWith
(
"\""
)
&&
value
.
endsWith
(
"\""
))
return
value
.
substring
(
1
,
value
.
length
()
-
1
);
else
return
null
;
case
BOOLEAN:
if
(!
"true"
.
equals
(
value
)
&&
!
"false"
.
equals
(
value
))
{
return
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录