-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
CASSANDRA-19546: Add to_human_size and to_human_duration function #3741
Open
chengw-netflix
wants to merge
4
commits into
apache:trunk
Choose a base branch
from
chengw-netflix:chengw/CASSANDRA-19546
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,159 @@ A number of functions allow to obtain the similarity score between vectors of fl | |
|
||
include::cassandra:partial$vector-search/vector_functions.adoc[] | ||
|
||
[[human-helper-functions]] | ||
==== Human helper functions | ||
|
||
For user's convenience, there are currently two functions which are converting values to more human-friendly | ||
represetations. | ||
|
||
==== format_bytes | ||
|
||
This function looks at values in a column as if it was in bytes, and it will convert it to whatever a user pleases. There are three ways how to call this function | ||
|
||
Let's have this table: | ||
|
||
[source,cql] | ||
---- | ||
cqlsh> select * from ks.tb ; | ||
|
||
id | val | ||
----+---------------- | ||
5 | 60000 | ||
1 | 1234234 | ||
2 | 12342341234234 | ||
4 | 60001 | ||
7 | null | ||
6 | 43 | ||
3 | 123423 | ||
|
||
---- | ||
|
||
with schema | ||
|
||
[source,cql] | ||
---- | ||
CREATE TABLE ks.tb ( | ||
id int PRIMARY KEY, | ||
val bigint | ||
) | ||
---- | ||
|
||
Imagine that we wanted to look at `val` values as if they were in mebibytes. We would like to have more human-friendly output in order to not visually divide the values by 1024 in order to get them in respective bigger units. The following function call may take just a column itself as an argument, and it will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL what a mebibyte is :-) |
||
automatically convert it. | ||
|
||
[NOTE] | ||
==== | ||
the default source unit for `format_bytes` function is _bytes_, (`B`). | ||
==== | ||
|
||
[source,cql] | ||
---- | ||
cqlsh> select format_bytes(val) from ks.tb ; | ||
|
||
system.format_bytes(val) | ||
--------------------------- | ||
58 KiB | ||
1 MiB | ||
11494 GiB | ||
58 KiB | ||
null | ||
43 B | ||
120 KiB | ||
---- | ||
|
||
The second way to call `format_bytes` functions is to specify into what size unit we would like to see all | ||
values to be converted to. For example, we want all size to be represented in mebibytes, hence we do: | ||
|
||
[source,cql] | ||
---- | ||
cqlsh> select format_bytes(val, 'MiB') from ks.tb ; | ||
|
||
system.format_bytes(val, 'MiB') | ||
---------------------------------- | ||
0 MiB | ||
1 MiB | ||
11770573 MiB | ||
0 MiB | ||
null | ||
0 MiB | ||
0 MiB | ||
---- | ||
|
||
Lastly, we can specify a source unit and a target unit. A source unit tells what unit that column is logically of, the target unit tells what unit we want these values to be converted to. For example, | ||
if we know that our column is logically in kibibytes and we want them to be converted into mebibytes, we would do: | ||
|
||
[source,cql] | ||
---- | ||
cqlsh> select format_bytes(val, 'Kib', 'MiB') from ks.tb ; | ||
|
||
system.format_bytes(val, 'Kib', 'MiB') | ||
----------------------------------------- | ||
58 MiB | ||
1205 MiB | ||
12053067611 MiB | ||
58 MiB | ||
null | ||
0 MiB | ||
120 MiB | ||
---- | ||
|
||
==== format_time | ||
|
||
Similarly to `format_bytes`, we can do transformations on duration-like columns. | ||
|
||
[NOTE] | ||
==== | ||
the default source unit for `format_time` function is _milliseconds_, (`ms`). | ||
==== | ||
|
||
[source,cql] | ||
---- | ||
cqlsh> select format_time(val) from ks.tb ; | ||
|
||
system.format_time(val) | ||
------------------------------- | ||
1 m | ||
20 m | ||
142851 d | ||
1 m | ||
null | ||
43 ms | ||
2 m | ||
---- | ||
|
||
We may specify what unit we want that value to be converted to, give the column's values are in millisecods: | ||
|
||
[source,cql] | ||
---- | ||
system.format_time(val, 'm') | ||
------------------------------------ | ||
1 m | ||
20 m | ||
205705687 m | ||
1 m | ||
null | ||
0 m | ||
2 m | ||
---- | ||
|
||
Lastly, we can specify both source and target values: | ||
|
||
[source,cql] | ||
---- | ||
cqlsh> select format_time(val, 's', 'h') from ks.tb ; | ||
|
||
system.format_time(val, 's', 'h') | ||
----------------------------------------- | ||
16 h | ||
342 h | ||
3428428120 h | ||
16 h | ||
null | ||
0 h | ||
34 h | ||
---- | ||
|
||
[[user-defined-scalar-functions]] | ||
=== User-defined functions | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: final
.