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

  • Decoding Database Speed: Essential Server Resources and Their Impact
  • Understanding Time Series Databases
  • Top NoSQL Databases and Use Cases
  • Zero-Latency Architecture: Database Triggers + Serverless Functions for Modern Reactive Architectures

Trending

  • Exploring Data Redaction Enhancements in Oracle Database 23ai
  • When Caches Collide: Solving Race Conditions in Fare Updates
  • Building an AI Nutrition Coach With OpenAI, Gradio, and gTTS
  • Vibe Coding: Conversational Software Development - Part 2, In Practice
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Automatically Migrate All Tables From a Database to Hadoop With No Coding

How to Automatically Migrate All Tables From a Database to Hadoop With No Coding

This is a great tool for instantly moving over tables from relational databases. This is also a great way to quickly build up a data lake.

By 
Tim Spann user avatar
Tim Spann
DZone Core CORE ·
Jul. 05, 17 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
20.0K Views

Join the DZone community and get the full member experience.

Join For Free

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 tables (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.

This is a great tool for instantly moving over tables from relational databases. This is also a great way to quickly build up a data lake.

Image title

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.

Image title

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 and see what tables were ingested and the most recent timestamp (value).

We will get back what catalog we read from, how many tables, 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+.

2. GenerateTableFetch  

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

3. Get the SQL Statement

We extract text to get the SQL statement created by GenerateTableFetch.

We add a new attribute, sql, with value, ^(.*).

4. Execute SQL  

Execute SQL with the $sql attribute.

5. Convert AVRO Files

Convert the AVRO produced by the executed SQL into performant Apache ORC files.

6. Put HDFS 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.

7. Build a SQL Statement

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

8. Execute the Statement

Put Hive SQL to execute the statement that was just dynamically created for our new table.

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

9. Look at the Data!

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 automatically ingested into HDFS and the Hive tables built.

You can download the Apache NiFi template from here.

See below:

Image title

Image title

Database Relational database hadoop Coding (social sciences)

Opinions expressed by DZone contributors are their own.

Related

  • Decoding Database Speed: Essential Server Resources and Their Impact
  • Understanding Time Series Databases
  • Top NoSQL Databases and Use Cases
  • Zero-Latency Architecture: Database Triggers + Serverless Functions for Modern Reactive Architectures

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: