mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
7.4 KiB
7.4 KiB
machine_translated, machine_translated_rev, toc_priority, toc_title
| machine_translated | machine_translated_rev | toc_priority | toc_title |
|---|---|---|---|
| true | 72537a2d527c63c07aa5d2361a8829f3895cf2bd | 58 | 外部辞書の操作 |
外部辞書を操作するための関数
情報の接続や設定の外部辞書参照 外部辞書.
dictGet
外部ディクショナリから値を取得します。
dictGet('dict_name', 'attr_name', id_expr)
dictGetOrDefault('dict_name', 'attr_name', id_expr, default_value_expr)
パラメータ
dict_name— Name of the dictionary. 文字列リテラル.attr_name— Name of the column of the dictionary. 文字列リテラル.id_expr— Key value. 式 aを返す UInt64 または タプル-辞書構成に応じて値を入力します。default_value_expr— Value returned if the dictionary doesn't contain a row with theid_exprキー 式 データ型の値を返します。attr_name属性。
戻り値
-
ClickHouseが属性を正常に解析した場合、 属性のデータ型,関数は、に対応する辞書属性の値を返します
id_expr. -
キーがない場合、対応する
id_expr、辞書では、:- `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は、属性の値を解析できない場合、または値が属性データ型と一致しない場合に例外をスローします。
例
テキストファイルの作成 ext-dict-text.csv 以下を含む:
1,1
2,2
最初の列は次のとおりです id 二つ目の列は c1.
外部辞書の構成:
<clickhouse>
<dictionary>
<name>ext-dict-test</name>
<source>
<file>
<path>/path-to/ext-dict-test.csv</path>
<format>CSV</format>
</file>
</source>
<layout>
<flat />
</layout>
<structure>
<id>
<name>id</name>
</id>
<attribute>
<name>c1</name>
<type>UInt32</type>
<null_value></null_value>
</attribute>
</structure>
<lifetime>0</lifetime>
</dictionary>
</clickhouse>
クエリの実行:
SELECT
dictGetOrDefault('ext-dict-test', 'c1', number + 1, toUInt32(number * 10)) AS val,
toTypeName(val) AS type
FROM system.numbers
LIMIT 3
┌─val─┬─type───┐
│ 1 │ UInt32 │
│ 2 │ UInt32 │
│ 20 │ UInt32 │
└─────┴────────┘
も参照。
ディクタス
キーが辞書に存在するかどうかを確認します。
dictHas('dict_name', id_expr)
パラメータ
戻り値
- キーがない場合は0。
- 1、キーがある場合。
タイプ: UInt8.
dictGetHierarchy
キーのすべての親を含む配列を作成します。 階層辞書.
構文
dictGetHierarchy('dict_name', key)
パラメータ
戻り値
- 鍵の親。
タイプ: 配列(UInt64).
ジクチシン
辞書の階層チェーン全体を通して、キーの祖先をチェックします。
dictIsIn('dict_name', child_id_expr, ancestor_id_expr)
パラメータ
dict_name— Name of the dictionary. 文字列リテラル.child_id_expr— Key to be checked. 式 aを返す UInt64-タイプ値。ancestor_id_expr— Alleged ancestor of thechild_id_exprキー 式 aを返す UInt64-タイプ値。
戻り値
- 0の場合
child_id_exprの子ではありませんancestor_id_expr. - 1の場合
child_id_exprの子であるancestor_id_exprまたはchild_id_exprはancestor_id_expr.
タイプ: UInt8.
その他の機能
ClickHouseは、辞書構成に関係なく、辞書属性の値を特定のデータ型に変換する特殊な関数をサポートしています。
関数:
dictGetInt8,dictGetInt16,dictGetInt32,dictGetInt64dictGetUInt8,dictGetUInt16,dictGetUInt32,dictGetUInt64dictGetFloat32,dictGetFloat64dictGetDatedictGetDateTimedictGetUUIDdictGetString
これらの関数はすべて、 OrDefault 修正 例えば, dictGetDateOrDefault.
構文:
dictGet[Type]('dict_name', 'attr_name', id_expr)
dictGet[Type]OrDefault('dict_name', 'attr_name', id_expr, default_value_expr)
パラメータ
dict_name— Name of the dictionary. 文字列リテラル.attr_name— Name of the column of the dictionary. 文字列リテラル.id_expr— Key value. 式 aを返す UInt64-タイプ値。default_value_expr— Value which is returned if the dictionary doesn't contain a row with theid_exprキー 式 データ型に設定された値を返すattr_name属性。
戻り値
-
ClickHouseが属性を正常に解析した場合、 属性のデータ型,関数は、に対応する辞書属性の値を返します
id_expr. -
要求がない場合
id_expr辞書では:- `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は、属性の値を解析できない場合、または値が属性データ型と一致しない場合に例外をスローします。