to_protobuf 函數

適用於:勾選為是 Databricks SQL 勾選為是 Databricks Runtime 16.1 和更新版本

利用指定的 Protobuf 訊息定義,將 a STRUCT 轉換成 Protobuf 編碼 BINARY 的值。

Syntax

to_protobuf(data, messageName [, descFilePath [, options] ])
to_protobuf(data, messageName, options)

Arguments

  • data:一個 STRUCT 需要編碼的表達式。
  • messageName: 一個常數 STRING 表達式,將 Protobuf 訊息命名為 encode。
  • descFilePath: 為 Protobuf 描述符檔案的可選常數 STRING 路徑,或包含描述符檔案的常數 BINARY 值。 產生描述符檔,與 protoc --descriptor_set_out--include_imports。 只有在設定結構登錄檔時options才省略descFilePath。
  • options:一個包含轉換選項的可選常數 MAP<STRING, STRING> 表達式。

Returns

一個由 Protobuf 編碼 BINARY 的值。

如果 data 是 NULL,結果就是 NULL。

的 data 結構必須符合指定的 Protobuf 訊息定義。

選項

完整選項列表請參見 Protobuf。

Examples

以下範例使用由此 Protobuf 訊息產生的描述符檔案:

message Person {
  string name = 1;
  int32 id = 2;
}

將結構體編碼為二進位 Protobuf 值:

> SELECT hex(to_protobuf(
    named_struct('name', 'Alice', 'id', 42),
    'Person',
    '/path/to/person.desc'));
  0A05416C696365102A