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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • The Generic Way To Convert Between Java and PostgreSQL Enums
  • JSON-Based Serialized LOB Pattern
  • SQL Commands: A Brief Guide
  • Modify JSON Data in Postgres and Hibernate 6

Trending

  • How to Build Your First Generative AI App With Langflow: A Step-by-Step Guide
  • The Cybersecurity Blind Spot in DevOps Pipelines
  • The Battle of the Frameworks: Choosing the Right Tech Stack
  • Designing Microservices Architecture With a Custom Spring Boot Starter and Auto-Configuration Framework
  1. DZone
  2. Data Engineering
  3. Data
  4. Convert JSON Data Files to Table DDL

Convert JSON Data Files to Table DDL

In this post, we quickly introduce a new, open source processor for creating table definitions from JSON data files. Read on for more!

By 
Tim Spann user avatar
Tim Spann
DZone Core CORE ·
Mar. 20, 18 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
13.7K Views

Join the DZone community and get the full member experience.

Join For Free

NiFi JSON to DDL Custom Processor

Java ClassJUnit

This is a further enhanced version of the idea started here.

There was some discussion on LinkedIn about the previous article being a good processor, so I decided to do that. This is pretty basic, but it handles most types okay. Date and number processing is a bit hacky but guesses some types.

To install, copy the NAR file that you build or download from GitHub to your NiFi/lib directories and restart those servers.

Add the New Processor to Your Flow

Configure the Processor with a table type (that is ignored in this version)

Configure the Processor with a table name (this is important)

JsonToDDLProcessor Generated Docs

I configured my table name to be the filename without an extension for JSON.

Output in NiFi

Example Flow

Enhancements In Consideration:

  • Apache OpenNLP
  • Apache Tika
  • Attribute Cleaner Enhancement
  • Deep Learning for Determining Types
  • Machine Learning for Type Inference
  • MITIE
  • Apache MXNet
  • TensorFlow
  • Stanford CoreNLP
  • Kite SDK
  • Hive Tools
  • Spark Tools
  • Make Fields Even Sized or Learn What Sizes Are Common Profiling Data

Call to the community, if this is interesting, please join. If you don't want to code, please suggest enhancements, open tickets on bugs, spread the word. Thanks.

Source Code:

https://github.com/tspannhw/nifi-convertjsontoddl-processor

mvn archetype:generate

Install the Pre-Built Nar

https://github.com/tspannhw/nifi-convertjsontoddl-processor/releases/tag/v1.0

Test JSON Files

https://github.com/tspannhw/nifi-convertjsontoddl-processor/tree/master/nifi-convertjsontoddl-processors/src/test/resources

Table Create DDL

generatedddl

CREATE TABLE simple ( EMPID INT, GENDER CHAR(1), DEPTID INT, FIRSTNAME VARCHAR(17), LASTNAME VARCHAR(15), TOTALSPENT INT )

generatedddl

CREATE TABLE complex ( EMPID INT, GENDER CHAR(1), DEPTID INT, FIRSTNAME VARCHAR(17), LASTNAME VARCHAR(15), TOTALSPENT INT, ALONGFIELDNAME VARCHAR(33), MYFIELDISALARGESTRINGGUESSWHATTYPE VARCHAR(141), day9 INT, day0 INT, day1 INT, day2 INT, day3 INT, day4 INT, day5 INT, day6 INT, day7 INT, day8 INT, day9 INT, day0 INT, day1 INT, day INT, day INT, day INT, day INT, day INT, day INT, day INT, day INT, day INT, day0 INT, day1 INT, day2 INT, day3 INT, day4 INT, day5 INT, day6 INT, day7 INT, day8 INT, swver VARCHAR(41), hwver VARCHAR(15), mac VARCHAR(29), type VARCHAR(31), hwId VARCHAR(44), fwId VARCHAR(44), oemId VARCHAR(44), devname VARCHAR(51), model VARCHAR(21), deviceId VARCHAR(52), alias VARCHAR(59), iconhash CHAR(1), relaystate INT, ontime INT, activemode VARCHAR(20), feature VARCHAR(19), updating INT, rssi INT, ledoff INT, latitude INT, longitude INT, index INT, zonestr VARCHAR(59), tzstr VARCHAR(34), dstoffset INT, month INT, month INT, month INT, current INT, voltage INT, power INT, total INT, time DATETIME, ledon BOOLEAN, systemtime DATETIME )

generatedddl

CREATE TABLE inception ( uuid VARCHAR(41), toppct VARCHAR(25), top VARCHAR(29), toppct VARCHAR(25), top VARCHAR(32), toppct VARCHAR(25), top VARCHAR(47), toppct VARCHAR(25), top VARCHAR(28), toppct VARCHAR(25), top VARCHAR(25), imagefilename VARCHAR(51), runtime CHAR(1) )

generatedddl

CREATE TABLE weather ( version VARCHAR(15), xsinoNamespaceSchemaLocation VARCHAR(63), credit VARCHAR(43), creditURL VARCHAR(31), url VARCHAR(50), title VARCHAR(43), link VARCHAR(30), suggestedpickup VARCHAR(37), suggestedpickup_period VARCHAR(14), location VARCHAR(58), stationid VARCHAR(16), latitude VARCHAR(19), longitude VARCHAR(20), observationtime VARCHAR(52), observationtime_rfc822 DATETIME, weather VARCHAR(20), windstring VARCHAR(74), winddir VARCHAR(16), winddegrees VARCHAR(15), windmph VARCHAR(16), windgust_mph VARCHAR(16), windkt CHAR(1), windgust_kt VARCHAR(14), pressurein VARCHAR(17), visibilitymi VARCHAR(17), iconurl_base VARCHAR(57), twoday_history_url VARCHAR(59), iconurl_name VARCHAR(19), oburl VARCHAR(56), disclaimerurl VARCHAR(46), copyrighturl VARCHAR(46), privacypolicy_url VARCHAR(42) )


JSON Data Types Data definition language Database Data (computing) Convert (command)

Published at DZone with permission of Tim Spann, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The Generic Way To Convert Between Java and PostgreSQL Enums
  • JSON-Based Serialized LOB Pattern
  • SQL Commands: A Brief Guide
  • Modify JSON Data in Postgres and Hibernate 6

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: