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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
  1. DZone
  2. Data Engineering
  3. Data
  4. Ingesting RDBMS Data as New Tables Arrive in Hive

Ingesting RDBMS Data as New Tables Arrive in Hive

Learn about loading all relational database data into new Hive tables automatically, or — dare we say it — autoMAGICally.

Tim Spann user avatar by
Tim Spann
CORE ·
Nov. 30, 17 · Tutorial
Like (2)
Save
Tweet
Share
7.19K Views

Join the DZone community and get the full member experience.

Join For Free

Let's say that a company wants to know when new tables are added to a JDBC source (say, an RDBMS). Using the ListDatabaseTables processor, we can get a list of TABLE s, and also views, system tables, and other database objects, but for our purposes, we want tables with data. I have used the ngdbc.jar from SAP HANA to connect and query tables with ease.

For today's example, I am connecting to MySQL, as I have a MySQL database available for use and modification.

Pre-step

mysql -u root -p test < person.sql
CREATE USER 'nifi'@'%' IDENTIFIED BY 'reallylongDifficultPassDF&^D&F^Dwird';
GRANT ALL PRIVILEGES ON *.* TO 'nifi'@'%' WITH GRANT OPTION;
COMMIT;
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| MOCK_DATA      |
| mock2          |
| personReg      |
| visitor        |
+----------------+
4 rows in set (0.00 sec)

I created a user to use for my JDBC Connection Pool in NiFi to read the metadata and data.

These table names will show up in NiFi in the db.table.name attribute.

Step 1

ListDatabaseTables: Let's get a list of all the tables in MySQL for the database we have chosen.

After it starts running, you can check its state, see what tables were ingested, and see the most recent timestamp (Value).

We will get back what catalog we read from, how many tables there are, and each table name and it's full name.

HDF NiFi supports generic JDBC drivers and specific coding for Oracle, MS SQL Server 2008, and MS SQL Server 2012+.

Step 2

GenerateTableFetch using the table name returned from the list returned by the database control.

Step 3

We use extract text to get the SQL statement created by generate table fetch.

We add a new attribute, sql.

Step 4

Execute SQL with that $sql attribute.

Step 5

Convert AVRO files produced by ExecuteSQL into performant Apache ORC files:

Step 6

PutHDFS to store these ORC files in Hadoop.

I added the table name as part of the directory structure, so a new directory is created for each transferred table. Now, we have dynamic HDFS directory structure creation.

Step 7

Replace the text to build a SQL statement that will generate an external Hive table on our new ORC directory.

Step 8

PutHiveQL to execute the statement that was just dynamically created for our new table.

We now have instantly queryable Hadoop data available to Hive, SparkSQL, Zeppelin, ODBC, JDBC, and a ton of BI tools and interfaces.

Step 9

Finally, we can look at the data that we have ingested from MySQL into new Hive tables.

That was easy! The best part is that as new tables are added to MySQL, they will be auto-ingested into HDFS and Hive tables.

Future Updates

Use Hive merge capabilities to update changed data. We can also ingest to Phoenix/HBase and use the upsert DML.

Test with other databases. Tested with MySQL.

Quick tip (HANA): In NiFi, refer to tables with their full name in quotes: "SAP_"."ASDSAD.SDASD.ASDAD".

Database Data (computing)

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • PHP vs React
  • The Importance of Delegation in Management Teams
  • RabbitMQ vs. Memphis.dev
  • The Data Leakage Nightmare in AI

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: