You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're planning to add a format function that turns a number into human readable format.
Motivation
One of our use cases is to use Druid as part of application monitoring system. Most of data stored in Druid are related to byte, such as memory size, disk size, network IO byte. In most cases, theses values are very large especially after aggregation, so we have to convert these data into human readable format to make it easy to recognize when querying.
Druid does not provide such a format function, so now we have to do it in the following ways:
a middleware service does the conversion
front-end projects do the conversion
The downside of above solutions is obvious -- we have to write extra code to do the conversion along side the Druid SQL itself, or we have to tell our frontend engineers that they have to do the conversion on some fields.
So if this format ability is shipped with Druid itself, I think it could simplify the whole development and deployment of our system.
Requirement
These requirements are based on what we have implemented in our project.
Support to format number in IEC format(binary format, such as KiB, MiB, GiB)
Support to format number in SI format(decimal format, such as KB, MB, GB)
Support to format value in simplified IEC or SI format (such as K, M, G)
Support customer precision from 0 to 3
flexible format
When displaying data in a table, it's more readable to format the value as '5.00 GB', a space between the number and the unit, so that it is easy to recognize the unit. when displaying data in a card(a kind of frontend component, usually displays text in a large size), it's better to show it as '5.17G' in abbreviated unit format, no space between the number and unit
Proposed Change
MySQL has provided a similar function named format_bytes, which satisfies the requirement 1 above.
We're planning to add a SQL function named as size_format(same style as string_format) to serve the needs above, and some alternatives we come up with are listed below
From the view of implementation, the format argument of alternative 1 is not easy to control. And What if user does not provide B as suffix instead of other strings ? So there are rules imposed on this argument that might make it a little bit complex both for users and developers.
unit: unlike the definition in alternative 1, the unit here divides into 4 categories: binary, binary_byte, decimal, decimal_byte. The default is binary_byte.
precision: the same as alternative 1, ranging from 0 to 3, default is 2.
has_space: whether or not there's a space between the number and the unit. Default is true
Description
We're planning to add a format function that turns a number into human readable format.
Motivation
One of our use cases is to use Druid as part of application monitoring system. Most of data stored in Druid are related to byte, such as memory size, disk size, network IO byte. In most cases, theses values are very large especially after aggregation, so we have to convert these data into human readable format to make it easy to recognize when querying.
Druid does not provide such a format function, so now we have to do it in the following ways:
The downside of above solutions is obvious -- we have to write extra code to do the conversion along side the Druid SQL itself, or we have to tell our frontend engineers that they have to do the conversion on some fields.
So if this format ability is shipped with Druid itself, I think it could simplify the whole development and deployment of our system.
Requirement
These requirements are based on what we have implemented in our project.
When displaying data in a table, it's more readable to format the value as '5.00 GB', a space between the number and the unit, so that it is easy to recognize the unit. when displaying data in a card(a kind of frontend component, usually displays text in a large size), it's better to show it as '5.17G' in abbreviated unit format, no space between the number and unit
Proposed Change
MySQL has provided a similar function named format_bytes, which satisfies the requirement 1 above.
We're planning to add a SQL function named as
size_format
(same style asstring_format
) to serve the needs above, and some alternatives we come up with are listed belowAlternative 1
Prototype
bin
(standing for binary, IEC format) ordec
(decimal, SI format). Default isbin
B
(indicating byte) suffixExamples
Alternative 2
From the view of implementation, the
format
argument of alternative 1 is not easy to control. And What if user does not provideB
as suffix instead of other strings ? So there are rules imposed on this argument that might make it a little bit complex both for users and developers.Prototype
binary
,binary_byte
,decimal
,decimal_byte
. The default isbinary_byte
.Examples
Note: The use cases of
binary
in practice I think are rare, we don't plan to implement it.Currently, we tend to do it in the way of alternative 2. Want to hear what you think @gianm @jihoonson @asdf2014
The text was updated successfully, but these errors were encountered: