Update docs

This commit is contained in:
Francisco Javier Jurado Moreno 2024-05-24 17:08:29 +02:00
parent 97f03ad242
commit 0b7ef00161
2 changed files with 53 additions and 1 deletions

View File

@ -777,6 +777,37 @@ Alias: `FORMAT_BYTES`.
└────────────────┴────────────┘
```
## fromReadableSize(x)
Given a string containing the readable respresentation of a byte size, this function returns the corrseponding number of bytes.
- As the conversion might lead to decimal bytes the result will be rounded up to the next integer to represent the minimum number of bytes that can fit the passed size.
- Accepts up to the Exabyte/Exabibyte (EB/EiB)
**Arguments**
- `val` : readable size. [String](../data-types/string)
**Returned value**
- Number of bytes represented by the readable size [UInt64](../data-types/int-uint.md).
Example:
```sql
SELECT
arrayJoin(['1 B', '1 KiB', '3 MiB', '5.314 KB']) AS readable_sizes,
fromReadableSize(readable_sizes) AS sizes
```
```text
┌─readable_sizes─┬───sizes─┐
│ 1 B │ 1 │
│ 1 KiB │ 1024 │
│ 3 MiB │ 3145728 │
│ 5.314 KB │ 5314 │
└────────────────┴─────────┘
```
## formatReadableQuantity(x)
Given a number, this function returns a rounded number with suffix (thousand, million, billion, etc.) as string.

View File

@ -225,7 +225,28 @@ namespace
REGISTER_FUNCTION(FromReadableSize)
{
factory.registerFunction<FunctionFromReadableSize>();
factory.registerFunction<FunctionFromReadableSize>(FunctionDocumentation
{
.description=R"(
Given a string containing the readable respresentation of a byte size, this function returns the corrseponding number of bytes:
[example:basic_binary]
[example:basic_decimal]
If the resulting number of bytes has a non-zero decimal part, the result is rounded up to indicate the number of bytes necessary to accommodate the provided size.
[example:round]
Accepts readable sizes up to the ExaByte (EB/EiB).
It always returns an UInt64 value.
)",
.examples{
{"basic_binary", "SELECT fromReadableSize('1 KiB')", "1024"},
{"basic_decimal", "SELECT fromReadableSize('1.523 KB')", "1523"},
{"round", "SELECT fromReadableSize('1.0001 KiB')", "1025"},
},
.categories{"OtherFunctions"}
}
);
}
}