DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Freshness as a First-Class Schema Concern: Modeling Data Staleness Across 83 Data Sources
  • Schema Evolution in Event-Driven Systems: Avro/Protobuf Strategies That Don’t Break Consumers
  • AI-Driven Schema Evolution and Adaptive Pipelines
  • Scaling Real-Time Data Systems With DataOps: Principles, Practices, and Use Cases

Trending

  • Exactly-Once Stream Processing With Apache Flink
  • AI-Assisted Product Discovery
  • Understanding Vector Databases: Concepts, Similarity Search, and Trade-offs for Enterprise Applications
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. Generating AVRO Schemas for Data and Making Sure Names Are Correct

Generating AVRO Schemas for Data and Making Sure Names Are Correct

Learn how to use Apache NiFi to generate AVRO schemas while ensuring that the field names meet strict naming conventions.

By 
Tim Spann
DZone Core CORE ·
Dec. 13, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
20.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Building schemas is tedious work and is often fraught with errors. The InferAvroSchema processor can get you started. It generates a compliant schema for use. There is one caveat: you have to make sure you are using Apache Avro-safe field names. I have a custom processor that will clean your attributes if you need them to be Avro-safe. See the processor listed below.

Example flow utilizing InferAvroSchema:

InferAvroSchema details:

The steps are as follows:

  1. Use Apache NiFi to convert data to JSON or CSV.

  2. Send JSON or CSV data to InferAvroSchema. I recommend setting the output destination to flowfile-attribute, input content type to json, and the pretty Avro output to true.

  3. The new schema is now in the following attribute format: inferred.avro.schema.

inferred.avro.schema    
{ "type" : "record", "name" : "schema1", 
 "fields" : [ { 
   "name" : "table", "type" : "string", 
   "doc" : "Type inferred from '\"schema1.tableName\"'" } ] 
}   

This schema can then be used for conversions directly or can be stored in Hortonworks Schema Registry or Apache NiFi's built-in Avro Registry.

Now, you can use it for ConvertRecord, QueryRecord, and other Record processing.

Example generated schema in Avro-JSON format stored in Hortonworks Schema Registry:

Source

And that's it!

Schema Data (computing) avro

Opinions expressed by DZone contributors are their own.

Related

  • Freshness as a First-Class Schema Concern: Modeling Data Staleness Across 83 Data Sources
  • Schema Evolution in Event-Driven Systems: Avro/Protobuf Strategies That Don’t Break Consumers
  • AI-Driven Schema Evolution and Adaptive Pipelines
  • Scaling Real-Time Data Systems With DataOps: Principles, Practices, and Use Cases

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook