-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add bar function #5993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bar function #5993
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Looks good. Some comments below:
src/include/duckdb/common/vector_operations/quaternary_executor.hpp
Outdated
Show resolved
Hide resolved
Also fixed a bug in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes! Looks good - some more minor comments:
src/function/scalar/string/bar.cpp
Outdated
static const char *FULL_BLOCK = UnicodeBar::FullBlock(); | ||
static const char *const *PARTIAL_BLOCKS = UnicodeBar::PartialBlocks(); | ||
static const idx_t PARTIAL_BLOCKS_COUNT = UnicodeBar::PartialBlocksCount(); | ||
static const idx_t UNICODE_BLOCK_CHAR_SIZE = strlen(FULL_BLOCK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work for the space character, no? As it is only a single byte.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed UNICODE_BLOCK_CHAR_SIZE
src/function/scalar/string/bar.cpp
Outdated
int32_t width_as_int = static_cast<int32_t>(width * PARTIAL_BLOCKS_COUNT); | ||
idx_t full_blocks_count = (width_as_int / PARTIAL_BLOCKS_COUNT); | ||
for (idx_t i = 0; i < full_blocks_count; i++) { | ||
result.insert(result.end(), FULL_BLOCK, FULL_BLOCK + UNICODE_BLOCK_CHAR_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this to be a vector<char>
? Can this not be a std::string
instead? It seems like that would simplify the code, as we could then just use string appends (e.g. result += FULL_BLOCK;
). Then we wouldn't need UNICODE_BLOCK_CHAR_SIZE
either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.
Fixed to use string
Thanks for the changes! Looks good. |
#5981
This PR adds
BAR
function like ClickHouse's BAR function.It draws unicode-art bar chart and is useful for instant visualization of numerical data in CLI.
Cited from ClickHouse's documentation
e.g.
Two overloads are included.
In the former overload,
width
is set to 80 implicitly.