다음을 통해 공유


from_avro 기능

적용 대상:유효성 검사 체크 후 예, Databricks Runtime 16.0 이상

avroBinjsonSchemaStr가 있는 구조체 값을 반환합니다.

구문

from_avro(avroBin, jsonSchemaStr, options )

논쟁

  • avroBin BINARY: Avro 데이터의 행을 지정하는 식입니다.
  • avroSchemaSpec: JSON 형식의 대상 스키마입니다. to_avro()avroBin 지정된 대로 인코딩된 스키마와 일치해야 합니다.
  • options: 지시문을 지정하는 MAP<STRING,STRING> 리터럴입니다.

반품

schema_of_json(jsonStr)STRUCT결과를 기반으로 필드 이름 및 형식이 있는 A 입니다.

avroBinavroSchemaSpecoptions에 대해 잘 구성되어야 하며, 그렇지 않으면 Databricks가 예외를 발생시킵니다.

비고

가장 일반적으로 지원되는 옵션은 다음과 같습니다.

옵션 가치 설명
'mode' 'PERMISSIVE', 'FAILFAST' PERMISSIVE 모드에서는 개체의 손상된 개체나 필드가 오류를 발생시키는 대신 NULL로 설정됩니다.
compression 'uncompressed', 'snappy''deflade', 'bzip2', 'xz''zstandard' Avro 데이터를 인코딩하는 데 사용되는 압축 코덱을 지정합니다.

자세한 옵션은 스트리밍 Avro 데이터 읽기 및 쓰기를 참조 하세요.

예제

> 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}