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

  • The Generic Way To Convert Between Java and PostgreSQL Enums
  • JSON-Based Serialized LOB Pattern
  • SQL Commands: A Brief Guide
  • Five Nonprofit & Charity APIs That Make Due Diligence Way Less Painful for Developers

Trending

  • How to Write for DZone Publications: Trend Reports and Refcards
  • Build Production-Ready AI Phone Agents: Infrastructure, Models, and Telephony
  • Kafka vs Flink vs Spark: Do You Really Need Real-Time?
  • Securing AI Agents in Production: A Developer’s Guide To Prompt Injection, RAG Leaks, and Tool Abuse

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. 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
DZone Core CORE ·
Mar. 20, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
14.1K 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

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. 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
  • Five Nonprofit & Charity APIs That Make Due Diligence Way Less Painful for Developers

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