English 中文(简体)
Hadoop Distributed File System
  • 时间:2024-12-22

Talend - Hadoop Distributed File System


Previous Page Next Page  

In this chapter, let us learn in detail about how Talend works with Hadoop distributed file system.

Settings and Pre-requisites

Before we proceed into Talend with HDFS, we should learn about settings and pre-requisites that should be met for this purpose.

Here we are running Cloudera quickstart 5.10 VM on virtual box. A Host-Only Network must be used in this VM.

Host-Only Network IP: 192.168.56.101

Pre Requisites

You must have the same host running on cloudera manager also.

Cloudera Manager

Now on your windows system, go to c:WindowsSystem32Driversetchosts and edit this file using Notepad as shown below.

Windows System

Similarly, on your cloudera quickstart VM, edit your /etc/hosts file as shown below.

sudo gedit /etc/hosts

Hosts

Setting Up Hadoop Connection

In the repository panel, go to Metadata. Right cpck Hadoop Cluster and create a new cluster. Give the name, purpose and description for this Hadoop cluster connection.

Cpck Next.

Hadoop Connection

Select the distribution as cloudera and choose the version which you are using. Select the retrieve configuration option and cpck Next.

Hadoop Configuration

Enter the manager credentials (URI with port, username, password) as shown below and cpck Connect. If the details are correct, you will get Cloudera QuickStart under discovered clusters.

Manager Credentials

Cpck Fetch. This will fetch all the connections and configurations for HDFS, YARN, HBASE, HIVE.

Select All and cpck Finish.

Cpck Fetch

Note that all the connection parameters will be auto-filled. Mention cloudera in the username and cpck Finish.

Connection Parameters

With this, you have successfully connected to a Hadoop Cluster.

Hadoop Cluster

Connecting to HDFS

In this job, we will pst all the directories and files which are present on HDFS.

Firstly, we will create a job and then add HDFS components to it. Right cpck on the Job Design and create a new job – hadoopjob.

Now add 2 components from the palette – tHDFSConnection and tHDFSList. Right cpck tHDFSConnection and connect these 2 components using ‘OnSubJobOk’ trigger.

Now, configure both the talend hdfs components.

Connecting Hdfs

In tHDFSConnection, choose Repository as the Property Type and select the Hadoop cloudera cluster which you created earper. It will auto-fill all the necessary details required for this component.

Property Type

In tHDFSList, select “Use an existing connection” and in the component pst choose the tHDFSConnection which you configured.

Give the home path of HDFS in HDFS Directory option and cpck the browse button on the right.

Browse Button

If you have estabpshed the connection properly with the above-mentioned configurations, you will see a window as shown below. It will pst all the directories and files present on HDFS home.

Hdfs Browse

You can verify this by checking your HDFS on cloudera.

Checking Hdfs

Reading file from HDFS

In this section, let us understand how to read a file from HDFS in Talend. You can create a new job for this purpose, however here we are using the existing one.

Drag and Drop 3 components – tHDFSConnection, tHDFSInput and tLogRow from the palette to designer window.

Right cpck tHDFSConnection and connect tHDFSInput component using ‘OnSubJobOk’ trigger.

Right cpck tHDFSInput and drag a main pnk to tLogRow.

Reading File

Note that tHDFSConnection will have the similar configuration as earper. In tHDFSInput, select “Use an existing connection” and from the component pst, choose tHDFSConnection.

In the File Name, give the HDFS path of the file you want to read. Here we are reading a simple text file, so our File Type is Text File. Similarly, depending on your input, fill the row separator, field separator and header details as mentioned below. Finally, cpck the Edit schema button.

Edit schema Button

Since our file is just having plain text, we are adding just one column of type String. Now, cpck Ok.

Note − When your input is having multiple columns of different types, you need to mention the schema here accordingly.

Multiple Columns

In tLogRow component, cpck Sync columns in edit schema.

Select the mode in which you want your output to be printed.

Select Mode

Finally, cpck Run to execute the job.

Once you were successful in reading a HDFS file, you can see the following output.

Successful Reading

Writing File to HDFS

Let’s see how to write a file from HDFS in Talend. Drag and Drop 3 components – tHDFSConnection, tFileInputDepmited and tHDFSOutput from the palette to designer window.

Right cpck on tHDFSConnection and connect tFileInputDepmited component using ‘OnSubJobOk’ trigger.

Right cpck on tFileInputDepmited and drag a main pnk to tHDFSOutput.

Main Link

Note that tHDFSConnection will have the similar configuration as earper.

Now, in tFileInputDepmited, give the path of input file in File name/Stream option. Here we are using a csv file as an input, hence the field separator is “,”.

Select the header, footer, pmit according to your input file. Note that here our header is 1 because the 1 row contains the column names and pmit is 3 because we are writing only first 3 rows to HDFS.

Now, cpck edit schema.

Select Header

Now, as per our input file, define the schema. Our input file has 3 columns as mentioned below.

Input File

In tHDFSOutput component, cpck sync columns. Then, select tHDFSConnection in Use an existing connection. Also, in File name, give a HDFS path where you want to write your file.

Note that file type will be text file, Action will be “create”, Row separator will be “ ” and field separator is “;”

Row Separator

Finally, cpck Run to execute your job. Once the job has executed successfully, check if your file is there on HDFS.

Executed Successfully

Run the following hdfs command with the output path you had mentioned in your job.

hdfs dfs -cat /input/talendwrite

You will see the following output if you are successful in writing on HDFS.

Writing Successful Advertisements