未验证 提交 a930713a 编写于 作者: F FeehanG 提交者: GitHub

Update ext_dict_functions.md

上级 807bfa91
......@@ -15,29 +15,29 @@ dictGetOrDefault('dict_name', 'attr_name', id_expr, default_value_expr)
- `dict_name` — Name of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `attr_name` — Name of the column of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returning [UInt64](../../data_types/int_uint.md)-typed value or [Tuple](../../data_types/tuple.md) depending on the dictionary configuration.
- `default_value_expr` — Value which is returned if the dictionary doesn't contain a row with the `id_expr` key. [Expression](../syntax.md#syntax-expressions) returning the value of the data type configured for the `attr_name` attribute.
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returns a [UInt64](../../data_types/int_uint.md) or [Tuple](../../data_types/tuple.md)-type value depending on the dictionary configuration.
- `default_value_expr` — Value returned if the dictionary doesn't contain a row with the `id_expr` key. [Expression](../syntax.md#syntax-expressions) returns the value in the data type configured for the `attr_name` attribute.
**Returned value**
- If ClickHouse parses the attribute successfully with the [attribute's data type](../dicts/external_dicts_dict_structure.md#ext_dict_structure-attributes), functions return the value of the dictionary attribute that corresponds to `id_expr`.
- If there is no requested `id_expr` in the dictionary then:
- If ClickHouse parses the attribute successfully in the [attribute's data type](../dicts/external_dicts_dict_structure.md#ext_dict_structure-attributes), functions return the value of the dictionary attribute that corresponds to `id_expr`.
- If there is no requested `id_expr` in the dictionary, then:
- `dictGet` returns the content of the `<null_value>` element which is specified for the attribute in the dictionary configuration.
- `dictGet` returns the content of the `<null_value>` element specified for the attribute in the dictionary configuration.
- `dictGetOrDefault` returns the value passed as the `default_value_expr` parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value doesn't match the attribute data type.
**Example of Use**
**Example**
Create the text file `ext-dict-text.csv` with the following content:
Create a text file `ext-dict-text.csv` containing the following:
```text
1,1
2,2
```
The first column is `id`, the second column is `c1`
The first column is `id`, the second column is `c1`.
Configure the external dictionary:
......@@ -93,7 +93,7 @@ LIMIT 3
## dictHas
Checks whether the dictionary has the key.
Checks whether a key is present in a dictionary.
```
dictHas('dict_name', id)
......@@ -102,7 +102,7 @@ dictHas('dict_name', id)
**Parameters**
- `dict_name` — Name of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returning [UInt64](../../data_types/int_uint.md)-typed value.
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returns a [UInt64](../../data_types/int_uint.md)-type value.
**Returned value**
......@@ -113,7 +113,7 @@ Type: `UInt8`.
## dictGetHierarchy
For the hierarchical dictionary, returns an array of dictionary keys starting from passed `id_expr` and continuing along the chain of parent elements.
For the hierarchical dictionary, returns an array of dictionary keys starting from the passed `id_expr` and continuing along the chain of parent elements.
```
dictGetHierarchy('dict_name', id)
......@@ -122,7 +122,7 @@ dictGetHierarchy('dict_name', id)
**Parameters**
- `dict_name` — Name of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returning [UInt64](../../data_types/int_uint.md)-typed value.
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returns a [UInt64](../../data_types/int_uint.md)-type value.
**Returned value**
......@@ -139,8 +139,8 @@ Checks the ancestor of a key in the hierarchical dictionary.
**Parameters**
- `dict_name` — Name of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `child_id_expr` — Key that should be checked. [Expression](../syntax.md#syntax-expressions) returning [UInt64](../../data_types/int_uint.md)-typed value.
- `ancestor_id_expr` — Alleged ancestor of the `child_id_expr` key. [Expression](../syntax.md#syntax-expressions) returning [UInt64](../../data_types/int_uint.md)-typed value.
- `child_id_expr` — Key to be checked. [Expression](../syntax.md#syntax-expressions) returns a [UInt64](../../data_types/int_uint.md)-type value.
- `ancestor_id_expr` — Alleged ancestor of the `child_id_expr` key. [Expression](../syntax.md#syntax-expressions) returns a [UInt64](../../data_types/int_uint.md)-type value.
**Returned value**
......@@ -151,7 +151,7 @@ Type: `UInt8`.
## Other functions {#ext_dict_functions-other}
ClickHouse supports the specialized functions that convert the dictionary attribute values to the strict data type independently of the configuration of the dictionary.
ClickHouse supports specialized functions that convert dictionary attribute values to a specific data type regardless of the dictionary configuration.
Functions:
......@@ -163,7 +163,7 @@ Functions:
- `dictGetUUID`
- `dictGetString`
All these functions have the `OrDefault` modification. For example, `dictGetDateOrDefault`.
All these functions take the `OrDefault` modifier. For example, `dictGetDateOrDefault`.
Syntax:
......@@ -176,17 +176,17 @@ dictGet[Type]OrDefault('dict_name', 'attr_name', id_expr, default_value_expr)
- `dict_name` — Name of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `attr_name` — Name of the column of the dictionary. [String literal](../syntax.md#syntax-string-literal).
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returning [UInt64](../../data_types/int_uint.md)-typed value.
- `default_value_expr` — Value which is returned if the dictionary doesn't contain a row with the `id_expr` key. [Expression](../syntax.md#syntax-expressions) returning the value of the data type configured for the `attr_name` attribute.
- `id_expr` — Key value. [Expression](../syntax.md#syntax-expressions) returns a [UInt64](../../data_types/int_uint.md)-type value.
- `default_value_expr` — Value which is returned if the dictionary doesn't contain a row with the `id_expr` key. [Expression](../syntax.md#syntax-expressions) returns a value in the data type configured for the `attr_name` attribute.
**Returned value**
- If ClickHouse parses the attribute successfully with the [attribute's data type](../dicts/external_dicts_dict_structure.md#ext_dict_structure-attributes), functions return the value of the dictionary attribute that corresponds to `id_expr`.
- If ClickHouse parses the attribute successfully in the [attribute's data type](../dicts/external_dicts_dict_structure.md#ext_dict_structure-attributes), functions return the value of the dictionary attribute that corresponds to `id_expr`.
- If there is no requested `id_expr` in the dictionary then:
- `dictGet[Type]` returns the content of the `<null_value>` element which is specified for the attribute in the dictionary configuration.
- `dictGet[Type]` returns the content of the `<null_value>` element specified for the attribute in the dictionary configuration.
- `dictGet[Type]OrDefault` returns the value passed as the `default_value_expr` parameter.
ClickHouse throws an exception, if it cannot parse the value of the attribute or the value doesn't match the attribute data type.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value doesn't match the attribute data type.
[Original article](https://clickhouse.yandex/docs/en/query_language/functions/ext_dict_functions/) <!--hide-->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册