cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using from_avro function

MaximeGendre
New Contributor III

Hello everyone,
I need your help with a topic that has been preoccupying me for a few days.

"from_avro" function gives me a strange result when I pass it the json schema of a Kafka topic.

====================================================================

lastVersion = schema_registry_client.get_latest_version(topic_name +"-value")
print(f"last schema structure is {lastVersion.schema.schema_str}")
 
MaximeGendre_2-1717533967736.png

The schema looks pretty simple.

====================================================================

schema_json = """{
  "namespace": "aaa.kafkaday.planedemo",
  "type": "record",
  "name": "PlaneDemo",
  "fields": [
    {"name": "FlightNumber", "type": "string"},
    {"name": "PositionTime", "type": "long"},
    {"name": "Lat", "type": "double"},
    {"name": "Long", "type": "double"},
    {"name": "Alt", "type": "double"}
  ]
}"""

display(df.select(
  from_avro( col("value"),
            schema_json, from_avro_options)
))

MaximeGendre_0-1717533089570.png

Using from_avro on the same dataset with SchemaRegistry information it works well.

====================================================================

 
display(df.select(
  from_avro(data = F.col("value"),
            subject = topic_name +"-value",
            schemaRegistryAddress = schema_registry_address,
            options = schema_registry_options).alias("value")
    ).selectExpr("*"))

MaximeGendre_1-1717533556219.png

A suggestion on where I'm going wrong ?

Thank you.

 

 

 

 

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group