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消息命名为要编码。
  • descFilePath: 一个可选的常数 STRING 路径指向Protobuf描述符文件或包含描述符文件的常数 BINARY 值。 生成描述符文件,且 protoc --descriptor_set_out--include_imports。 只有在配置模式注册表时options才省略descFilePath。
  • options:一个包含转换选项的可选常数 MAP<STRING, STRING> 表达式。

Returns

一个由Protobuf编码 BINARY 的值。

如果 data 为 NULL,则结果为 NULL。

的 data 模式必须符合指定的 Protobuf 消息定义。

选项

有关选项的完整列表,请参阅 Protobuf。

示例

以下示例使用了从该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