from_protobuf function
Applies to: Databricks SQL
Databricks Runtime 16.1 and above
Converts a binary Protobuf value into a STRUCT using the specified Protobuf message definition.
Syntax
from_protobuf(data, messageName [, descFilePath [, options] ])
from_protobuf(data, messageName, options)
Arguments
data: ABINARYexpression containing a Protobuf message.messageName: A constantSTRINGexpression naming the Protobuf message to decode.descFilePath: An optional constantSTRINGpath to a Protobuf descriptor file or a constantBINARYvalue containing the descriptor file. Generate the descriptor file withprotoc --descriptor_set_outand--include_imports. OmitdescFilePathonly whenoptionsconfigures a Schema Registry.options: An optional constantMAP<STRING, STRING>expression containing conversion options.
Returns
A STRUCT whose fields and types match the Protobuf message definition.
If data is NULL, the result is NULL.
The Protobuf message definition must match the schema of data. If the schemas do not match, the function can fail or return an arbitrary result.
Options
For a complete list of options, see Protobuf.
Examples
The following example uses a descriptor file generated from this Protobuf message:
Protobuf
message Person {
string name = 1;
int32 id = 2;
}
Decode a binary Protobuf value:
SQL
> SELECT from_protobuf(
unhex('0A05416C696365102A'),
'Person',
'/path/to/person.desc');
{"name":"Alice","id":42}