适用于:
Databricks Runtime 16.0 及更高版本
返回具有 avroBin 和 jsonSchemaStr 的结构值。
语法
from_avro(avroBin, jsonSchemaStr, options )
参数
-
avroBin:指定 Avro 数据行的BINARY表达式。 -
avroSchemaSpec:JSON 格式中的目标架构。 它必须与avroBin中指定的 中编码的架构匹配。 -
options:指定指令的MAP<STRING,STRING>文本。
返回
avroBin 必须相对于 avroSchemaSpec 和 options 格式标准,否则 Databricks 会引发异常。
选项
| 选项 | 价值观 | 说明 |
|---|---|---|
mode |
%> | 错误处理模式。 默认值:FAILFAST。 在 PERMISSIVE 模式下,损坏的记录设置为 NULL 而不是引发错误。 |
compression |
uncompressed、snappy、deflate、bzip2、xz、zstandard |
用于编码 Avro 数据的压缩编解码器。 |
avroSchemaEvolutionMode |
%> | 架构演变模式。 默认值:none。 设置为 |
recursiveFieldMaxDepth |
范围: -1 到 15 |
单个递归路径的最大递归深度。 默认值: -1不限制递归深度。当可从许多不同的架构路径访问共享类型时,架构扩展可能会导致驱动程序内存不足,因为此选项仅绑定一个路径的深度。 解决方法:
|
示例
> SELECT from_avro(to_avro(5), '{ "type" : "int" }', NULL:MAP<STRING, STRING>);
5
> SELECT from_avro(to_avro(5, '{ "type" : "int" }'), '{ "type" : "int" }', NULL:MAP<STRING, STRING>);
5
> SELECT from_avro(to_avro(named_struct('num', 5, 'txt', 'hello')), '{ "type" : "record", "name": "my_record", "fields": [{ "name": "num", "type": "int"}, { "name": "txt", "type": "string"}]}', NULL:MAP<STRING, STRING>);
{"num":5,"txt":"hello"}
> SELECT from_avro(to_avro(named_struct('num', 5, 'txt', 'hello')),
'{ "type" : "record", "name": "my_record", "fields": [{ "name": "num", "type": "int"}, { "name": "txt", "type": "double"}]}',
map('mode', 'failfast'));
Error: Avro data is not valid for the specified schema.
> SELECT from_avro(to_avro(named_struct('num', 5, 'txt', 'hello')),
'{ "type" : "record", "name": "my_record", "fields": [{ "name": "num", "type": "int"}, { "name": "txt", "type": "double"}]}',
map('mode', 'permissive'));
{"num":null,"txt":null}