> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ネイティブクライアントのパケット

> ネイティブプロトコルのクライアント

| 値 | 名前               | 説明               |
| - | ---------------- | ---------------- |
| 0 | [Hello](#hello)  | クライアントハンドシェイクの開始 |
| 1 | [Query](#query)  | クエリリクエスト         |
| 2 | [Data](#data)    | データを含むブロック       |
| 3 | [キャンセル](#cancel) | クエリのキャンセル        |
| 4 | [Ping](#ping)    | Ping リクエスト       |
| 5 | TableStatus      | テーブルステータスのリクエスト  |

`Data` は圧縮できます。

<div id="hello">
  ## Hello
</div>

たとえば、`54451` のプロトコルバージョンに対応した `Go Client` v1.10 を使用し、
`default` ユーザーと `secret` パスワードで `default` データベースに接続するとします。

| フィールド             | 型       | 値             | 説明               |
| ----------------- | ------- | ------------- | ---------------- |
| client\_name      | String  | `"Go Client"` | クライアント実装名        |
| version\_major    | UVarInt | `1`           | クライアントのメジャーバージョン |
| version\_minor    | UVarInt | `10`          | クライアントのマイナーバージョン |
| protocol\_version | UVarInt | `54451`       | TCP プロトコルのバージョン  |
| database          | String  | `"default"`   | データベース名          |
| username          | String  | `"default"`   | ユーザー名            |
| password          | String  | `"secret"`    | パスワード            |

<div id="protocol-version">
  ### プロトコルバージョン
</div>

プロトコルバージョンは、クライアントのTCPプロトコルのバージョンです。

通常、これは最新の互換性のあるサーバーリビジョンと同じですが、
これと混同しないでください。

<div id="defaults">
  ### デフォルト
</div>

すべての値は**明示的に設定**する必要があります。サーバー側にはデフォルト値はありません。
クライアント側では、デフォルトとして `"default"` データベース、`"default"` ユーザー名、`""` (空文字列) の
パスワードを使用します。

<div id="query">
  ## クエリ
</div>

| フィールド           | 型                          | 値          | 説明                   |
| --------------- | -------------------------- | ---------- | -------------------- |
| query\_id       | String                     | `1ff-a123` | Query ID。UUIDv4も使用可能 |
| client\_info    | [ClientInfo](#client-info) | 型を参照       | クライアントに関するデータ        |
| settings        | [Settings](#settings)      | 型を参照       | 設定の一覧                |
| secret          | String                     | `secret`   | サーバー間のシークレット         |
| [stage](#stage) | UVarInt                    | `2`        | クエリステージまで実行する        |
| compression     | UVarInt                    | `0`        | 無効=0、有効=1            |
| body            | String                     | `SELECT 1` | クエリテキスト              |

<div id="client-info">
  ### クライアント情報
</div>

| フィールド              | 型               | 説明                           |
| ------------------ | --------------- | ---------------------------- |
| query\_kind        | byte            | None=0、Initial=1、Secondary=2 |
| initial\_user      | String          | 初期ユーザー                       |
| initial\_query\_id | String          | 初期クエリ ID                     |
| initial\_address   | String          | 初期アドレス                       |
| initial\_time      | Int64           | 初期時刻                         |
| interface          | byte            | TCP=1、HTTP=2                 |
| os\_user           | String          | OSユーザー                       |
| client\_hostname   | String          | クライアントのホスト名                  |
| client\_name       | String          | クライアント名                      |
| version\_major     | UVarInt         | クライアントのメジャーバージョン             |
| version\_minor     | UVarInt         | クライアントのマイナーバージョン             |
| protocol\_version  | UVarInt         | クライアントのプロトコルバージョン            |
| quota\_key         | String          | クォータキー                       |
| distributed\_depth | UVarInt         | Distributed の深度              |
| version\_patch     | UVarInt         | クライアントのパッチバージョン              |
| otel               | Bool            | トレース関連フィールドが存在する             |
| trace\_id          | FixedString(16) | トレース ID                      |
| span\_id           | FixedString(8)  | スパン ID                       |
| trace\_state       | String          | トレース状態                       |
| trace\_flags       | Byte            | トレースフラグ                      |

<div id="settings">
  ### 設定
</div>

| フィールド     | 型      | 値                 | 説明        |
| --------- | ------ | ----------------- | --------- |
| key       | String | `send_logs_level` | 設定のキー     |
| value     | String | `trace`           | 設定の値      |
| important | Bool   | `true`            | 無視できるかどうか |

リストとしてエンコードされ、キーと値が空であればリストの終端を示します。

<div id="stage">
  ### Stage
</div>

| 値 | 名前                 | 説明                   |
| - | ------------------ | -------------------- |
| 0 | FetchColumns       | カラムの型のみ取得            |
| 1 | WithMergeableState | マージ可能な状態まで           |
| 2 | Complete           | 完全な状態まで (デフォルトにするべき) |

<div id="data">
  ## Data
</div>

| フィールド   | 型                  | 説明             |
| ------- | ------------------ | -------------- |
| info    | BlockInfo          | エンコード済みのブロック情報 |
| columns | UVarInt            | カラム数           |
| rows    | UVarInt            | 行数             |
| columns | [\[\]カラム](#column) | データを含むカラム      |

<div id="column">
  ### カラム
</div>

| フィールド | 型      | 値               | 説明     |
| ----- | ------ | --------------- | ------ |
| name  | String | `foo`           | カラム名   |
| type  | String | `DateTime64(9)` | カラムの型  |
| data  | bytes  | \~              | カラムデータ |

<div id="cancel">
  ## キャンセル
</div>

パケット本文はありません。サーバーはクエリをキャンセルする必要があります。

<div id="ping">
  ## Ping
</div>

パケット本文はありません。サーバーは[pong を返す](/ja/resources/develop-contribute/native-protocol/server#pong)必要があります。
