Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aec3a064
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看板
提交
aec3a064
编写于
8月 30, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: shell csv rfc 4180
上级
508be776
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
30 deletion
+52
-30
tools/shell/inc/shellInt.h
tools/shell/inc/shellInt.h
+1
-1
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+37
-19
tools/shell/src/shellWebsocket.c
tools/shell/src/shellWebsocket.c
+14
-10
未找到文件。
tools/shell/inc/shellInt.h
浏览文件 @
aec3a064
...
...
@@ -113,7 +113,7 @@ int32_t shellExecute();
int32_t
shellCalcColWidth
(
TAOS_FIELD
*
field
,
int32_t
precision
);
void
shellPrintHeader
(
TAOS_FIELD
*
fields
,
int32_t
*
width
,
int32_t
num_fields
);
void
shellPrintField
(
const
char
*
val
,
TAOS_FIELD
*
field
,
int32_t
width
,
int32_t
length
,
int32_t
precision
);
void
shellDumpFieldToFile
(
TdFilePtr
pFile
,
const
char
*
val
,
TAOS_FIELD
*
field
,
int32_t
length
,
int32_t
precis
ion
);
void
shellDumpFieldToFile
(
TdFilePtr
pFile
,
const
char
*
val
,
TAOS_FIELD
*
field
,
int32_t
length
,
int32_t
precision
,
bool
quotat
ion
);
// shellUtil.c
int32_t
shellCheckIntSize
();
void
shellPrintVersion
();
...
...
tools/shell/src/shellEngine.c
浏览文件 @
aec3a064
...
...
@@ -264,9 +264,15 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) {
return
buf
;
}
void
shellDumpFieldToFile
(
TdFilePtr
pFile
,
const
char
*
val
,
TAOS_FIELD
*
field
,
int32_t
length
,
int32_t
precision
)
{
void
shellDumpFieldToFile
(
TdFilePtr
pFile
,
const
char
*
val
,
TAOS_FIELD
*
field
,
int32_t
length
,
int32_t
precision
,
bool
quotation
)
{
char
quotationStr
[
2
];
quotationStr
[
0
]
=
0
;
quotationStr
[
1
]
=
0
;
if
(
quotation
)
{
quotationStr
[
0
]
=
'\"'
;
}
if
(
val
==
NULL
)
{
taosFprintfFile
(
pFile
,
"%s
"
,
TSDB_DATA_NULL_STR
);
taosFprintfFile
(
pFile
,
"%s
%s%s"
,
quotationStr
,
TSDB_DATA_NULL_STR
,
quotationStr
);
return
;
}
...
...
@@ -274,39 +280,39 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
char
buf
[
TSDB_MAX_BYTES_PER_ROW
];
switch
(
field
->
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
taosFprintfFile
(
pFile
,
"%
d"
,
((((
int32_t
)(
*
((
char
*
)
val
)))
==
1
)
?
1
:
0
)
);
taosFprintfFile
(
pFile
,
"%
s%d%s"
,
quotationStr
,
((((
int32_t
)(
*
((
char
*
)
val
)))
==
1
)
?
1
:
0
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
taosFprintfFile
(
pFile
,
"%
d"
,
*
((
int8_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%d%s"
,
quotationStr
,
*
((
int8_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
taosFprintfFile
(
pFile
,
"%
u"
,
*
((
uint8_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%u%s"
,
quotationStr
,
*
((
uint8_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
taosFprintfFile
(
pFile
,
"%
d"
,
*
((
int16_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%d%s"
,
quotationStr
,
*
((
int16_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
taosFprintfFile
(
pFile
,
"%
u"
,
*
((
uint16_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%u%s"
,
quotationStr
,
*
((
uint16_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_INT
:
taosFprintfFile
(
pFile
,
"%
d"
,
*
((
int32_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%d%s"
,
quotationStr
,
*
((
int32_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_UINT
:
taosFprintfFile
(
pFile
,
"%
u"
,
*
((
uint32_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%u%s"
,
quotationStr
,
*
((
uint32_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
taosFprintfFile
(
pFile
,
"%
"
PRId64
,
*
((
int64_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%"
PRId64
"%s"
,
quotationStr
,
*
((
int64_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
taosFprintfFile
(
pFile
,
"%
"
PRIu64
,
*
((
uint64_t
*
)
val
)
);
taosFprintfFile
(
pFile
,
"%
s%"
PRIu64
"%s"
,
quotationStr
,
*
((
uint64_t
*
)
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
taosFprintfFile
(
pFile
,
"%
.5f"
,
GET_FLOAT_VAL
(
val
)
);
taosFprintfFile
(
pFile
,
"%
s%.5f%s"
,
quotationStr
,
GET_FLOAT_VAL
(
val
),
quotationStr
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
n
=
snprintf
(
buf
,
TSDB_MAX_BYTES_PER_ROW
,
"%
*.9f"
,
length
,
GET_DOUBLE_VAL
(
val
)
);
n
=
snprintf
(
buf
,
TSDB_MAX_BYTES_PER_ROW
,
"%
s%*.9f%s"
,
quotationStr
,
length
,
GET_DOUBLE_VAL
(
val
),
quotationStr
);
if
(
n
>
TMAX
(
25
,
length
))
{
taosFprintfFile
(
pFile
,
"%
*.15e"
,
length
,
GET_DOUBLE_VAL
(
val
)
);
taosFprintfFile
(
pFile
,
"%
s%*.15e%s"
,
quotationStr
,
length
,
GET_DOUBLE_VAL
(
val
),
quotationStr
);
}
else
{
taosFprintfFile
(
pFile
,
"%s"
,
buf
);
}
...
...
@@ -314,13 +320,21 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_JSON
:
memcpy
(
buf
,
val
,
length
);
buf
[
length
]
=
0
;
taosFprintfFile
(
pFile
,
"
\'
%s
\'
"
,
buf
);
int32_t
bufIndex
=
0
;
for
(
int32_t
i
=
0
;
i
<
length
;
i
++
)
{
buf
[
bufIndex
]
=
val
[
i
];
bufIndex
++
;
if
(
val
[
i
]
==
'\"'
)
{
buf
[
bufIndex
]
=
val
[
i
];
bufIndex
++
;
}
}
buf
[
bufIndex
]
=
0
;
taosFprintfFile
(
pFile
,
"%s%s%s"
,
quotationStr
,
buf
,
quotationStr
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
shellFormatTimestamp
(
buf
,
*
(
int64_t
*
)
val
,
precision
);
taosFprintfFile
(
pFile
,
"
'%s'"
,
buf
);
taosFprintfFile
(
pFile
,
"
%s%s%s"
,
quotationStr
,
buf
,
quotationStr
);
break
;
default:
break
;
...
...
@@ -347,12 +361,16 @@ int32_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) {
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tres
);
int32_t
num_fields
=
taos_num_fields
(
tres
);
int32_t
precision
=
taos_result_precision
(
tres
);
bool
quotation
=
false
;
for
(
int32_t
col
=
0
;
col
<
num_fields
;
col
++
)
{
if
(
col
>
0
)
{
taosFprintfFile
(
pFile
,
","
);
}
taosFprintfFile
(
pFile
,
"%s"
,
fields
[
col
].
name
);
if
(
fields
[
col
].
type
==
TSDB_DATA_TYPE_BINARY
||
fields
[
col
].
type
==
TSDB_DATA_TYPE_NCHAR
||
fields
[
col
].
type
==
TSDB_DATA_TYPE_JSON
)
{
quotation
=
true
;
}
}
taosFprintfFile
(
pFile
,
"
\r\n
"
);
...
...
@@ -363,7 +381,7 @@ int32_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) {
if
(
i
>
0
)
{
taosFprintfFile
(
pFile
,
","
);
}
shellDumpFieldToFile
(
pFile
,
(
const
char
*
)
row
[
i
],
fields
+
i
,
length
[
i
],
precision
);
shellDumpFieldToFile
(
pFile
,
(
const
char
*
)
row
[
i
],
fields
+
i
,
length
[
i
],
precision
,
quotation
);
}
taosFprintfFile
(
pFile
,
"
\r\n
"
);
...
...
tools/shell/src/shellWebsocket.c
浏览文件 @
aec3a064
...
...
@@ -132,17 +132,21 @@ static int dumpWebsocketToFile(const char* fname, WS_RES* wres, double* pexecute
*
pexecute_time
+=
(
double
)(
ws_take_timing
(
wres
)
/
1E6
);
if
(
!
rows
)
{
taosCloseFile
(
&
pFile
);
return
0
;
return
0
;
}
int
numOfRows
=
0
;
TAOS_FIELD
*
fields
=
(
TAOS_FIELD
*
)
ws_fetch_fields
(
wres
);
int
num_fields
=
ws_field_count
(
wres
);
int
precision
=
ws_result_precision
(
wres
);
bool
quotation
=
false
;
for
(
int
col
=
0
;
col
<
num_fields
;
col
++
)
{
if
(
col
>
0
)
{
taosFprintfFile
(
pFile
,
","
);
}
taosFprintfFile
(
pFile
,
"%s"
,
fields
[
col
].
name
);
if
(
fields
[
col
].
type
==
TSDB_DATA_TYPE_BINARY
||
fields
[
col
].
type
==
TSDB_DATA_TYPE_NCHAR
||
fields
[
col
].
type
==
TSDB_DATA_TYPE_JSON
)
{
quotation
=
true
;
}
}
taosFprintfFile
(
pFile
,
"
\r\n
"
);
do
{
...
...
@@ -155,7 +159,7 @@ static int dumpWebsocketToFile(const char* fname, WS_RES* wres, double* pexecute
taosFprintfFile
(
pFile
,
","
);
}
const
void
*
value
=
ws_get_value_in_block
(
wres
,
i
,
j
,
&
ty
,
&
len
);
shellDumpFieldToFile
(
pFile
,
(
const
char
*
)
value
,
fields
+
j
,
len
,
precision
);
shellDumpFieldToFile
(
pFile
,
(
const
char
*
)
value
,
fields
+
j
,
len
,
precision
,
quotation
);
}
taosFprintfFile
(
pFile
,
"
\r\n
"
);
}
...
...
@@ -233,17 +237,17 @@ void shellRunSingleCommandWebsocketImp(char *command) {
if
(
shellRegexMatch
(
command
,
"^
\\
s*use
\\
s+[a-zA-Z0-9_]+
\\
s*;
\\
s*$"
,
REG_EXTENDED
|
REG_ICASE
))
{
fprintf
(
stdout
,
"Database changed.
\r\n\r\n
"
);
fflush
(
stdout
);
ws_free_result
(
res
);
ws_free_result
(
res
);
return
;
}
int
numOfRows
=
0
;
if
(
ws_is_update_query
(
res
))
{
numOfRows
=
ws_affected_rows
(
res
);
et
=
taosGetTimestampUs
();
numOfRows
=
ws_affected_rows
(
res
);
et
=
taosGetTimestampUs
();
double
total_time
=
(
et
-
st
)
/
1E3
;
double
net_time
=
total_time
-
(
double
)
execute_time
;
printf
(
"Query Ok, %d of %d row(s) in database
\n
"
,
numOfRows
,
numOfRows
);
printf
(
"Query Ok, %d of %d row(s) in database
\n
"
,
numOfRows
,
numOfRows
);
printf
(
"Execute: %.2f ms Network: %.2f ms Total: %.2f ms
\n
"
,
execute_time
,
net_time
,
total_time
);
}
else
{
int
error_no
=
0
;
...
...
@@ -253,15 +257,15 @@ void shellRunSingleCommandWebsocketImp(char *command) {
return
;
}
et
=
taosGetTimestampUs
();
double
total_time
=
(
et
-
st
)
/
1E3
;
double
net_time
=
total_time
-
execute_time
;
double
total_time
=
(
et
-
st
)
/
1E3
;
double
net_time
=
total_time
-
execute_time
;
if
(
error_no
==
0
&&
!
shell
.
stop_query
)
{
printf
(
"Query OK, %d row(s) in set
\n
"
,
numOfRows
);
printf
(
"Execute: %.2f ms Network: %.2f ms Total: %.2f ms
\n
"
,
execute_time
,
net_time
,
total_time
);
printf
(
"Execute: %.2f ms Network: %.2f ms Total: %.2f ms
\n
"
,
execute_time
,
net_time
,
total_time
);
}
else
{
printf
(
"Query interrupted, %d row(s) in set (%.6fs)
\n
"
,
numOfRows
,
(
et
-
st
)
/
1E6
);
printf
(
"Execute: %.2f ms Network: %.2f ms Total: %.2f ms
\n
"
,
execute_time
,
net_time
,
total_time
);
printf
(
"Execute: %.2f ms Network: %.2f ms Total: %.2f ms
\n
"
,
execute_time
,
net_time
,
total_time
);
}
}
printf
(
"
\n
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录