to_protobuf function

适用于:检查标记为“是”的 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: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