Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
{
"title": "QUANTILE_STATE_FROM_BASE64",
"language": "en"
}
---

## Description

Converts a base64 encoded string (usually generated by `QUANTILE_STATE_TO_BASE64`) to a QUANTILE_STATE type. Returns NULL if the input string is invalid or NULL.

## Syntax

```sql
QUANTILE_STATE_FROM_BASE64(<input>)
```

## Parameters

| Parameter | Description |
| --------- | ----------- |
| `<input>` | A base64 encoded string, usually generated by `QUANTILE_STATE_TO_BASE64`. Returns NULL if the string is invalid. |

## Return Value

Returns the quantile_state parsed from the base64 encoding. Returns NULL if the string is invalid.

## Examples

```sql
select
quantile_state_to_base64(
quantile_state_from_base64(
quantile_state_to_base64(to_quantile_state(1.0, 2048))
)
) = quantile_state_to_base64(to_quantile_state(1.0, 2048)) AS equal_test;
```
```text
+------------+
| equal_test |
+------------+
| 1 |
+------------+
```

```sql
select quantile_state_from_base64('not_base64!');
```

```text
+-------------------------------------------+
| quantile_state_from_base64('not_base64!') |
+-------------------------------------------+
| NULL |
+-------------------------------------------+
```

```sql
select quantile_state_from_base64(NULL);
```

```text
+----------------------------------+
| quantile_state_from_base64(NULL) |
+----------------------------------+
| NULL |
+----------------------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
{
"title": "QUANTILE_STATE_TO_BASE64",
"language": "en"
}
---

## Description

Converts a QUANTILE_STATE type to a base64 encoded string.

## Syntax

```sql
QUANTILE_STATE_TO_BASE64(<quantile_state_input>)
```

## Parameters

| Parameter | Description |
| --------- | ----------- |
| `<quantile_state_input>` | Data of QUANTILE_STATE type. |

## Return Value

The Base64 encoded string of the QUANTILE_STATE.
Returns `NULL` if the QUANTILE_STATE is `NULL`.

::: note

Since the order of elements in QUANTILE_STATE cannot be guaranteed, the base64 result generated from the same QUANTILE_STATE content is not guaranteed to be always the same, but the QUANTILE_STATE decoded by quantile_state_from_base64 is guaranteed to be the same.

:::

## Examples

```sql
select quantile_state_to_base64(quantile_state_empty());
```

```text
+--------------------------------------------------+
| quantile_state_to_base64(quantile_state_empty()) |
+--------------------------------------------------+
| AAAARQA= |
+--------------------------------------------------+
```

```sql
select quantile_state_to_base64(to_quantile_state(1, 2048));
```

```text
+------------------------------------------------------+
| quantile_state_to_base64(to_quantile_state(1, 2048)) |
+------------------------------------------------------+
| AAAARQEAAAAAAADwPw== |
+------------------------------------------------------+
```

```sql
select
quantile_percent(
quantile_union(
quantile_state_from_base64(
quantile_state_to_base64(to_quantile_state(1, 2048))
)
),
0.5
) as nested_test;
```

```text
+-------------+
| nested_test |
+-------------+
| 1 |
+-------------+
```

```sql
select quantile_state_to_base64(NULL);
```

```text
+--------------------------------+
| quantile_state_to_base64(NULL) |
+--------------------------------+
| NULL |
+--------------------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
{
"title": "QUANTILE_STATE_FROM_BASE64",
"language": "zh-CN",
"description": "将一个 base64 编码的字符串(通常由 QUANTILE_STATE_TO_BASE64 函数生成)转换为 QUANTILE_STATE 类型。如果输入字符串不合法或为 NULL,则返回 NULL。"
}
---

## 描述

将一个 base64 编码的字符串(通常由 `QUANTILE_STATE_TO_BASE64` 函数生成)转换为 QUANTILE_STATE 类型。如果输入字符串不合法或为 NULL,则返回 NULL。

## 语法

```sql
QUANTILE_STATE_FROM_BASE64(<input>)
```

## 参数

| 参数 | 说明 |
| -------- | ------------------------------------------------------------------------ |
| `<input>` | base64 编码的字符串,通常由 `QUANTILE_STATE_TO_BASE64` 函数生成。如果字符串不合法,则返回 NULL。 |

## 返回值
返回由 base64 编码解析后得到的 quantile_state参数,若字符串不合法,则返回 NULL。

## 示例

```sql
select
quantile_state_to_base64(
quantile_state_from_base64(
quantile_state_to_base64(to_quantile_state(1.0, 2048))
)
) = quantile_state_to_base64(to_quantile_state(1.0, 2048)) AS equal_test;
```
```text
+------------+
| equal_test |
+------------+
| 1 |
+------------+
```

```sql
select quantile_state_from_base64('not_base64!');
```

```text
+-------------------------------------------+
| quantile_state_from_base64('not_base64!') |
+-------------------------------------------+
| NULL |
+-------------------------------------------+
```

```sql
select quantile_state_from_base64(NULL);
```
```text
+----------------------------------+
| quantile_state_from_base64(NULL) |
+----------------------------------+
| NULL |
+----------------------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
{
"title": "QUANTILE_STATE_TO_BASE64",
"language": "zh-CN",
"description": "将一个 QUANTILE_STATE 类型转换为一个 base64 编码的字符串。"
}
---

## 描述

将一个 QUANTILE_STATE 类型转换为一个 base64 编码的字符串。

## 语法

```sql
QUANTILE_STATE_TO_BASE64(<quantile_state_input>)
```

## 参数

| 参数 | 说明 |
|---------------|-----------|
| `<quantile_state_input>` | QUANTILE_STATE 类型数据。 |

## 返回值

QUANTILE_STATE 基于 Base64 编码后的字符串。
若 QUANTILE_STATE 为 `NULL` 时,返回值为 `NULL`。

::: note

由于不能保证 QUANTILE_STATE 中元素的顺序,因此不能保证相同内容的 QUANTILE_STATE 生成的 base64 结果始终相同,但可以保证 quantile_state_from_base64 解码后的 QUANTILE_STATE 相同。

:::

## 示例

```sql
select quantile_state_to_base64(quantile_state_empty());
```

```text
+--------------------------------------------------+
| quantile_state_to_base64(quantile_state_empty()) |
+--------------------------------------------------+
| AAAARQA= |
+--------------------------------------------------+
```

```sql
select quantile_state_to_base64(to_quantile_state(1, 2048));
```

```text
+------------------------------------------------------+
| quantile_state_to_base64(to_quantile_state(1, 2048)) |
+------------------------------------------------------+
| AAAARQEAAAAAAADwPw== |
+------------------------------------------------------+
```

```sql
select
quantile_percent(
quantile_union(
quantile_state_from_base64(
quantile_state_to_base64(to_quantile_state(1, 2048))
)
),
0.5
) as nested_test;
```

```text
+-------------+
| nested_test |
+-------------+
| 1 |
+-------------+
```

```sql
select quantile_state_to_base64(NULL);
```

```text
+--------------------------------+
| quantile_state_to_base64(NULL) |
+--------------------------------+
| NULL |
+--------------------------------+
```