Skip to content

Commit

Permalink
[docs] batch 5 updating functions (#16812)
Browse files Browse the repository at this point in the history
* batch 5

* Update docs/querying/sql-functions.md

* applying suggestions

---------

Co-authored-by: Benedict Jin <asdf2014@apache.org>
  • Loading branch information
edgar2020 and asdf2014 authored Jul 31, 2024
1 parent 85a8a1d commit 3bb6d40
Showing 1 changed file with 107 additions and 15 deletions.
122 changes: 107 additions & 15 deletions docs/querying/sql-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,36 @@ Returns the rank for a row within a window without gaps. For example, if two row

## DIV

`DIV(x, y)`
Returns the result of integer division of `x` by `y`.

**Function type:** [Scalar, numeric](sql-scalar.md#numeric-functions)
* **Syntax:** `DIV(x, y)`
* **Function type:** Scalar, numeric

Returns the result of integer division of `x` by `y`.
<!--
<details><summary>Example</summary>
The following calculates integer divisions of `78` by `10`.
```sql
SELECT DIV(78, 10) as "division"
```
Returns the following:
| `division` |
| -- |
| `7` |
</details>
-->

:::info

The `DIV` function is not implemented in Druid versions 30.0.0 or earlier. Consider using [`SAFE_DIVIDE`](./sql-functions.md/#safe_divide) instead.

:::

[Learn more](sql-scalar.md#numeric-functions)

## DS_CDF

Expand Down Expand Up @@ -1092,28 +1117,78 @@ Returns a union of HLL sketches.

## HUMAN_READABLE_BINARY_BYTE_FORMAT

`HUMAN_READABLE_BINARY_BYTE_FORMAT(value[, precision])`
Converts an integer byte size into human-readable [IEC](https://en.wikipedia.org/wiki/Binary_prefix) format.

* **Syntax:** `HUMAN_READABLE_BINARY_BYTE_FORMAT(value[, precision])`
* **Function type:** Scalar, numeric

<details><summary>Example</summary>

**Function type:** [Scalar, numeric](sql-scalar.md#numeric-functions)
The following example converts `1000000` into IEC format.

Converts an integer byte size into human-readable IEC format.
```sql
SELECT HUMAN_READABLE_BINARY_BYTE_FORMAT(1000000, 2) AS "iec_format"
```

Returns the following:

| `iec_format` |
| -- |
| `976.56 KiB` |

</details>

[Learn more](sql-scalar.md#numeric-functions)

## HUMAN_READABLE_DECIMAL_BYTE_FORMAT

`HUMAN_READABLE_DECIMAL_BYTE_FORMAT(value[, precision])`
Converts a byte size into human-readable [SI](https://en.wikipedia.org/wiki/Binary_prefix) format.

**Function type:** [Scalar, numeric](sql-scalar.md#numeric-functions)
* **Syntax:** `HUMAN_READABLE_DECIMAL_BYTE_FORMAT(value[, precision])`
* **Function type:** Scalar, numeric

<details><summary>Example</summary>

Converts a byte size into human-readable SI format.
The following example converts `1000000` into SI format.

## HUMAN_READABLE_DECIMAL_FORMAT
```sql
SELECT HUMAN_READABLE_DECIMAL_BYTE_FORMAT(1000000, 2) AS "si_format"
```

`HUMAN_READABLE_DECIMAL_FORMAT(value[, precision])`
Returns the following:

**Function type:** [Scalar, numeric](sql-scalar.md#numeric-functions)
|`si_format`|
|--|
|`1.00 MB`|

</details>

[Learn more](sql-scalar.md#numeric-functions)

## HUMAN_READABLE_DECIMAL_FORMAT

Converts a byte size into human-readable SI format with single-character units.

* **Syntax:** `HUMAN_READABLE_DECIMAL_FORMAT(value[, precision])`
* **Function type:** Scalar, numeric

<details><summary>Example</summary>

The following example converts `1000000` into single character SI format.

```sql
SELECT HUMAN_READABLE_DECIMAL_FORMAT(1000000, 2) AS "single_character_si_format"
```

Returns the following:

|`single_character_si_format`|
|--|
|`1.00 M`|
</details>

[Learn more](sql-scalar.md#numeric-functions)

## ICONTAINS_STRING

`ICONTAINS_STRING(<expr>, str)`
Expand Down Expand Up @@ -1740,11 +1815,28 @@ Trims characters from the trailing end of an expression.
## SAFE_DIVIDE
`SAFE_DIVIDE(x, y)`
Returns `x` divided by `y`, guarded on division by 0.
**Function type:** [Scalar, numeric](sql-scalar.md#numeric-functions)
* **Syntax:** `SAFE_DIVIDE(x, y)`
* **Function type:** Scalar, numeric
Returns `x` divided by `y`, guarded on division by 0.
<details><summary>Example</summary>
The following example calculates divisions of integer `78` by integer `10`.
```sql
SELECT SAFE_DIVIDE(78, 10) AS "safe_division"
```
Returns the following:
|`safe_division`|
|--|
| `7` |
</details>
[Learn more](sql-scalar.md#numeric-functions)
## SIN
Expand Down

0 comments on commit 3bb6d40

Please sign in to comment.