Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Convert JSON Data Files to Table DDL

DZone's Guide to

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!

· Big Data Zone ·
Free Resource

Hortonworks Sandbox for HDP and HDF is your chance to get started on learning, developing, testing and trying out new features. Each download comes preconfigured with interactive tutorials, sample data and developments from the Apache community.

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) )


Hortonworks Community Connection (HCC) is an online collaboration destination for developers, DevOps, customers and partners to get answers to questions, collaborate on technical articles and share code examples from GitHub.  Join the discussion.

Topics:
json ,sql ,apache nifi ,ddl ,big data

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}