適用於:
Databricks SQL
Databricks Runtime 16.1 和更新版本
利用指定的 Protobuf 訊息定義,將二進位 Protobuf 值轉換為 。STRUCT
Syntax
from_protobuf(data, messageName [, descFilePath [, options] ])
from_protobuf(data, messageName, options)
Arguments
-
data:包含BINARYProtobuf 訊息的表達式。 -
messageName:一個常數STRING表達式,將 Protobuf 訊息命名為要解碼。 -
descFilePath: 為 Protobuf 描述符檔案的可選常數STRING路徑,或包含描述符檔案的常數BINARY值。 產生描述符檔,與protoc --descriptor_set_out--include_imports。 只有在設定結構登錄檔時options才省略descFilePath。 -
options:一個包含轉換選項的可選常數MAP<STRING, STRING>表達式。
Returns
一個 STRUCT 欄位與類型與 Protobuf 訊息定義相符的 Ap。
如果 data 是 NULL,結果就是 NULL。
Protobuf 訊息定義必須與 的 data結構相符。 若結構不匹配,函式可能失敗或回傳任意結果。
選項
完整選項列表請參見 Protobuf。
Examples
以下範例使用由此 Protobuf 訊息產生的描述符檔案:
message Person {
string name = 1;
int32 id = 2;
}
解碼一個二元Protobuf值:
> SELECT from_protobuf(
unhex('0A05416C696365102A'),
'Person',
'/path/to/person.desc');
{"name":"Alice","id":42}