to_avro
function
Applies to: Databricks Runtime 16.0 and later
Returns a Avro binary value with the specified input value.
Arguments
expr
: An expression.avroSchemaSpec
: An optional target schema in JSON format. If specified it must match theexpr
type as specified in Notes.
Notes
The mapping of SQL types to Avro types is as follows:
SQL type |
Avro schema |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Not supported |
|
Not supported |
Examples
> SELECT from_avro(to_avro(5), '{ "type" : "int" }');
5
> SELECT from_avro(to_avro(5, '{ "type" : "int" }'), '{ "type" : "int" }');
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"}]}');
{"num":5,"txt":"hello"}