Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
2fcf2e0f
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2fcf2e0f
编写于
10月 05, 2020
作者:
A
alexey-milovidov
提交者:
GitHub
10月 05, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15443 from ucasFL/pretty_row_numbers
Add setting `output_format_pretty_row_numbers`
上级
674d8d44
ac1f0b99
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
313 addition
and
0 deletion
+313
-0
src/Core/Settings.h
src/Core/Settings.h
+1
-0
src/Formats/FormatFactory.cpp
src/Formats/FormatFactory.cpp
+1
-0
src/Formats/FormatSettings.h
src/Formats/FormatSettings.h
+2
-0
src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp
src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp
+43
-0
src/Processors/Formats/Impl/PrettyBlockOutputFormat.h
src/Processors/Formats/Impl/PrettyBlockOutputFormat.h
+2
-0
src/Processors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp
...rocessors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp
+23
-0
src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp
src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp
+14
-0
tests/queries/0_stateless/01509_output_format_pretty_row_numbers.reference
...tateless/01509_output_format_pretty_row_numbers.reference
+212
-0
tests/queries/0_stateless/01509_output_format_pretty_row_numbers.sql
...es/0_stateless/01509_output_format_pretty_row_numbers.sql
+15
-0
未找到文件。
src/Core/Settings.h
浏览文件 @
2fcf2e0f
...
...
@@ -469,6 +469,7 @@ class IColumn;
M(Bool, output_format_enable_streaming, false, "Enable streaming in output formats that support it.", 0) \
M(Bool, output_format_write_statistics, true, "Write statistics about read rows, bytes, time elapsed in suitable output formats.", 0) \
M(Bool, allow_non_metadata_alters, true, "Allow to execute alters which affects not only tables metadata, but also data on disk", 0) \
M(Bool, output_format_pretty_row_numbers, false, "Add row numbers before each row for pretty output format", 0) \
#define LIST_OF_SETTINGS(M) \
COMMON_SETTINGS(M) \
...
...
src/Formats/FormatFactory.cpp
浏览文件 @
2fcf2e0f
...
...
@@ -107,6 +107,7 @@ static FormatSettings getOutputFormatSetting(const Settings & settings, const Co
format_settings
.
pretty
.
charset
=
settings
.
output_format_pretty_grid_charset
.
toString
()
==
"ASCII"
?
FormatSettings
::
Pretty
::
Charset
::
ASCII
:
FormatSettings
::
Pretty
::
Charset
::
UTF8
;
format_settings
.
pretty
.
output_format_pretty_row_numbers
=
settings
.
output_format_pretty_row_numbers
;
format_settings
.
template_settings
.
resultset_format
=
settings
.
format_template_resultset
;
format_settings
.
template_settings
.
row_format
=
settings
.
format_template_row
;
format_settings
.
template_settings
.
row_between_delimiter
=
settings
.
format_template_rows_between_delimiter
;
...
...
src/Formats/FormatSettings.h
浏览文件 @
2fcf2e0f
...
...
@@ -45,6 +45,8 @@ struct FormatSettings
UInt64
max_value_width
=
10000
;
bool
color
=
true
;
bool
output_format_pretty_row_numbers
=
false
;
enum
class
Charset
{
UTF8
,
...
...
src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp
浏览文件 @
2fcf2e0f
...
...
@@ -33,6 +33,10 @@ void PrettyBlockOutputFormat::calculateWidths(
WidthsPerColumn
&
widths
,
Widths
&
max_padded_widths
,
Widths
&
name_widths
)
{
size_t
num_rows
=
std
::
min
(
chunk
.
getNumRows
(),
format_settings
.
pretty
.
max_rows
);
/// len(num_rows) + len(". ")
row_number_width
=
std
::
floor
(
std
::
log10
(
num_rows
))
+
3
;
size_t
num_columns
=
chunk
.
getNumColumns
();
const
auto
&
columns
=
chunk
.
getColumns
();
...
...
@@ -196,9 +200,20 @@ void PrettyBlockOutputFormat::write(const Chunk & chunk, PortKind port_kind)
std
::
string
middle_values_separator_s
=
middle_values_separator
.
str
();
std
::
string
bottom_separator_s
=
bottom_separator
.
str
();
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
/// Output the block
writeString
(
top_separator_s
,
out
);
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
/// Names
writeCString
(
grid_symbols
.
bold_bar
,
out
);
writeCString
(
" "
,
out
);
...
...
@@ -238,12 +253,35 @@ void PrettyBlockOutputFormat::write(const Chunk & chunk, PortKind port_kind)
writeCString
(
grid_symbols
.
bold_bar
,
out
);
writeCString
(
"
\n
"
,
out
);
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
writeString
(
middle_names_separator_s
,
out
);
for
(
size_t
i
=
0
;
i
<
num_rows
&&
total_rows
+
i
<
max_rows
;
++
i
)
{
if
(
i
!=
0
)
{
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
writeString
(
middle_values_separator_s
,
out
);
}
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
// Write row number;
auto
row_num_string
=
std
::
to_string
(
i
+
1
)
+
". "
;
for
(
size_t
j
=
0
;
j
<
row_number_width
-
row_num_string
.
size
();
++
j
)
{
writeCString
(
" "
,
out
);
}
writeString
(
row_num_string
,
out
);
}
writeCString
(
grid_symbols
.
bar
,
out
);
...
...
@@ -262,6 +300,11 @@ void PrettyBlockOutputFormat::write(const Chunk & chunk, PortKind port_kind)
writeCString
(
"
\n
"
,
out
);
}
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
writeString
(
bottom_separator_s
,
out
);
total_rows
+=
num_rows
;
...
...
src/Processors/Formats/Impl/PrettyBlockOutputFormat.h
浏览文件 @
2fcf2e0f
...
...
@@ -33,6 +33,8 @@ protected:
size_t
terminal_width
=
0
;
bool
suffix_written
=
false
;
size_t
row_number_width
=
7
;
// "10000. "
const
FormatSettings
format_settings
;
using
Widths
=
PODArray
<
size_t
>
;
...
...
src/Processors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp
浏览文件 @
2fcf2e0f
...
...
@@ -69,6 +69,12 @@ void PrettyCompactBlockOutputFormat::writeHeader(
const
Widths
&
max_widths
,
const
Widths
&
name_widths
)
{
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
const
GridSymbols
&
grid_symbols
=
format_settings
.
pretty
.
charset
==
FormatSettings
::
Pretty
::
Charset
::
UTF8
?
utf8_grid_symbols
:
ascii_grid_symbols
;
...
...
@@ -117,6 +123,12 @@ void PrettyCompactBlockOutputFormat::writeHeader(
void
PrettyCompactBlockOutputFormat
::
writeBottom
(
const
Widths
&
max_widths
)
{
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
/// Write left blank
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
const
GridSymbols
&
grid_symbols
=
format_settings
.
pretty
.
charset
==
FormatSettings
::
Pretty
::
Charset
::
UTF8
?
utf8_grid_symbols
:
ascii_grid_symbols
;
...
...
@@ -144,6 +156,17 @@ void PrettyCompactBlockOutputFormat::writeRow(
const
WidthsPerColumn
&
widths
,
const
Widths
&
max_widths
)
{
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
// Write row number;
auto
row_num_string
=
std
::
to_string
(
row_num
+
1
)
+
". "
;
for
(
size_t
i
=
0
;
i
<
row_number_width
-
row_num_string
.
size
();
++
i
)
{
writeCString
(
" "
,
out
);
}
writeString
(
row_num_string
,
out
);
}
const
GridSymbols
&
grid_symbols
=
format_settings
.
pretty
.
charset
==
FormatSettings
::
Pretty
::
Charset
::
UTF8
?
utf8_grid_symbols
:
ascii_grid_symbols
;
...
...
src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp
浏览文件 @
2fcf2e0f
...
...
@@ -29,6 +29,10 @@ void PrettySpaceBlockOutputFormat::write(const Chunk & chunk, PortKind port_kind
Widths
name_widths
;
calculateWidths
(
header
,
chunk
,
widths
,
max_widths
,
name_widths
);
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
writeString
(
String
(
row_number_width
,
' '
),
out
);
}
/// Names
for
(
size_t
i
=
0
;
i
<
num_columns
;
++
i
)
{
...
...
@@ -66,6 +70,16 @@ void PrettySpaceBlockOutputFormat::write(const Chunk & chunk, PortKind port_kind
for
(
size_t
row
=
0
;
row
<
num_rows
&&
total_rows
+
row
<
max_rows
;
++
row
)
{
if
(
format_settings
.
pretty
.
output_format_pretty_row_numbers
)
{
// Write row number;
auto
row_num_string
=
std
::
to_string
(
row
+
1
)
+
". "
;
for
(
size_t
i
=
0
;
i
<
row_number_width
-
row_num_string
.
size
();
++
i
)
{
writeCString
(
" "
,
out
);
}
writeString
(
row_num_string
,
out
);
}
for
(
size_t
column
=
0
;
column
<
num_columns
;
++
column
)
{
if
(
column
!=
0
)
...
...
tests/queries/0_stateless/01509_output_format_pretty_row_numbers.reference
0 → 100644
浏览文件 @
2fcf2e0f
┏━━━━━━━━┓
┃ [1mnumber[0m ┃
┡━━━━━━━━┩
│ 0 │
├────────┤
│ 1 │
├────────┤
│ 2 │
├────────┤
│ 3 │
├────────┤
│ 4 │
├────────┤
│ 5 │
├────────┤
│ 6 │
├────────┤
│ 7 │
├────────┤
│ 8 │
├────────┤
│ 9 │
└────────┘
┌─[1mnumber[0m─┐
│ 0 │
│ 1 │
│ 2 │
│ 3 │
│ 4 │
│ 5 │
│ 6 │
│ 7 │
│ 8 │
│ 9 │
└────────┘
┌─[1mnumber[0m─┐
│ 0 │
│ 1 │
│ 2 │
│ 3 │
│ 4 │
│ 5 │
│ 6 │
│ 7 │
│ 8 │
│ 9 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
│ 0 │
├────────┤
│ 1 │
├────────┤
│ 2 │
├────────┤
│ 3 │
├────────┤
│ 4 │
├────────┤
│ 5 │
├────────┤
│ 6 │
├────────┤
│ 7 │
├────────┤
│ 8 │
├────────┤
│ 9 │
└────────┘
┌─number─┐
│ 0 │
│ 1 │
│ 2 │
│ 3 │
│ 4 │
│ 5 │
│ 6 │
│ 7 │
│ 8 │
│ 9 │
└────────┘
number
0
1
2
3
4
5
6
7
8
9
[1mnumber[0m
0
1
2
3
4
5
6
7
8
9
┏━━━━━━━━┓
┃ [1mnumber[0m ┃
┡━━━━━━━━┩
1. │ 0 │
├────────┤
2. │ 1 │
├────────┤
3. │ 2 │
├────────┤
4. │ 3 │
├────────┤
5. │ 4 │
├────────┤
6. │ 5 │
├────────┤
7. │ 6 │
├────────┤
8. │ 7 │
├────────┤
9. │ 8 │
├────────┤
10. │ 9 │
└────────┘
┌─[1mnumber[0m─┐
1. │ 0 │
2. │ 1 │
3. │ 2 │
4. │ 3 │
5. │ 4 │
6. │ 5 │
7. │ 6 │
8. │ 7 │
9. │ 8 │
10. │ 9 │
└────────┘
┌─[1mnumber[0m─┐
1. │ 0 │
2. │ 1 │
3. │ 2 │
4. │ 3 │
5. │ 4 │
6. │ 5 │
7. │ 6 │
8. │ 7 │
9. │ 8 │
10. │ 9 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
1. │ 0 │
├────────┤
2. │ 1 │
├────────┤
3. │ 2 │
├────────┤
4. │ 3 │
├────────┤
5. │ 4 │
├────────┤
6. │ 5 │
├────────┤
7. │ 6 │
├────────┤
8. │ 7 │
├────────┤
9. │ 8 │
├────────┤
10. │ 9 │
└────────┘
┌─number─┐
1. │ 0 │
2. │ 1 │
3. │ 2 │
4. │ 3 │
5. │ 4 │
6. │ 5 │
7. │ 6 │
8. │ 7 │
9. │ 8 │
10. │ 9 │
└────────┘
number
1. 0
2. 1
3. 2
4. 3
5. 4
6. 5
7. 6
8. 7
9. 8
10. 9
[1mnumber[0m
1. 0
2. 1
3. 2
4. 3
5. 4
6. 5
7. 6
8. 7
9. 8
10. 9
tests/queries/0_stateless/01509_output_format_pretty_row_numbers.sql
0 → 100644
浏览文件 @
2fcf2e0f
SELECT
*
FROM
numbers
(
10
)
FORMAT
Pretty
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyCompact
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyCompactMonoBlock
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyNoEscapes
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyCompactNoEscapes
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettySpaceNoEscapes
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettySpace
;
SET
output_format_pretty_row_numbers
=
1
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
Pretty
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyCompact
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyCompactMonoBlock
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyNoEscapes
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettyCompactNoEscapes
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettySpaceNoEscapes
;
SELECT
*
FROM
numbers
(
10
)
FORMAT
PrettySpace
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录