0% found this document useful (0 votes)
316 views25 pages

CoursBigData-TPs-Applications - 1-2

The document describes an application that uses HDFS to store and manipulate CSV files. It provides instructions to: 1. Create directories in HDFS and download a CSV file from a URL to store in HDFS 2. Check the blocks size and blocks of the downloaded file 3. Repeat the download with a specified block size of 4MB 4. Create a Bash script to automate the above steps by taking parameters as arguments

Uploaded by

HAJAR LABLAOUI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views25 pages

CoursBigData-TPs-Applications - 1-2

The document describes an application that uses HDFS to store and manipulate CSV files. It provides instructions to: 1. Create directories in HDFS and download a CSV file from a URL to store in HDFS 2. Check the blocks size and blocks of the downloaded file 3. Repeat the download with a specified block size of 4MB 4. Create a Bash script to automate the above steps by taking parameters as arguments

Uploaded by

HAJAR LABLAOUI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Cours Big Data – Les fondements

Département
Math & Info
Cours Big Data:
Filière :
II-BDCC Fondements et Architectures de stockage
Big Data –
Applications
les
Fondements

Big Data ▪ Application 1 : Manipulation du fichiers sous HDFS


Architectures
Orientées
Stockage ▪ Application 2 : Utilisation de l’ETL Hadoop pour
Démo,
Activités
l’importation sous HDFS de données issues des
pratiques et
Etudes de cas SGBDR.
Professeur
M. QBADOU
Professeur Mohammed. QBADOU
Cours Big Data – Les fondements
Département
Math & Info

Filière :
Application 1 : Activités Pratiques
II-BDCC
Manipulation des fichiers sous HDFS
Big Data –
les Hadoop
Fondements Objective: use of HDFS to understand:
Client NameNode
Big Data ▪ the hdfs file Read/Write
Architectures Read/Write blocks Accesses’ Coordination
Orientées mechanisms Read/Write blocks
Stockage blocks
▪ The split operation. DataNode
Démo,
Activités DataNode DataNode
pratiques et
Etudes de cas
▪ The replication factor

Professeur ▪ The use of HDFS HDFS blocks


HDFS blocks
M. QBADOU Commands Filesystem of Filesystem of
Filesystem of
the DataNode the DataNode the DataNode
2
Cours Big Data – Les fondements
Département Application1- Application’s Statement(1/3)
Math & Info
We want to create a new folder in HDFS storage system. In this folder, we have to
Filière : download a csv file given its URL in order to manage its content using Hadoop
II-BDCC capabilities. For instance, we want to display its content, to perform a select
operations on its content using Hive possibilities.
Big Data –
les
Fondements To do so, we have to run the following commands using a terminal console:
Big Data
1. Create the HDFS application's folders :
Architectures APP_HOME: /user/industries
Orientées
Stockage
RES_DIR: /user/industries/res
Démo,
Activités
pratiques et 2. Download a csv file using its URL and upload it to HDFS folder RES_DIR under
Etudes de cas
the name “indicCommercExter1.csv”
Professeur FILE_URL: https://www.stats.govt.nz/assets/Uploads/Overseas-trade-indexes-prices-
M. QBADOU and-volumes/Overseas-trade-indexes-prices-and-volumes-December-2019-quarter-
provisional/Download-data/overseas-trade-indexes-december-2019-quarter-provisional.csv
3
Cours Big Data – Les fondements
Département Application1- Application’s Statement (2/3)
Math & Info
3. Check the previous commands and show the blocks size value and the HDFS
Filière : blocks of the downloaded file
II-BDCC
4. Repeat the command of (2) considering a specific block size value of 4 Mo
Big Data –
and using the file name : “indicCommercExter2.csv”
les
Fondements 5. Repeat the check of the step (3)
Big Data
Architectures
6. We want to write a script bash file that groups all the commands asked from
Orientées
Stockage
step 1 to step 5. We want to execute this file with the following parameters:

Démo,
▪ APP_HOME_DIR,
Activités
pratiques et ▪ FILE_BASENAME,
Etudes de cas
▪ BLOCK_SIZE_VALUE and
Professeur ▪ FILE_URL
M. QBADOU

4
Cours Big Data – Les fondements
Département Application1- Application’s Statement (3/3)
Math & Info
a. Under Linux file system, create a workspace directory named “myscripts” as a subdirectory
of the HOME directory
Filière :
II-BDCC b. Create a new file named “hdfs_manip1.sh”
c. Edit this file using VIM and add all the commands
Big Data – d. Change its mode to make it an executable file
les
Fondements
e. Execute the file using the following command line :
Big Data ./hdfs_manip1.sh /usr/indus txt 4m https://www.stats.govt.nz/assets/Uploads/Overseas-
Architectures trade-indexes-prices-and-volumes/Overseas-trade-indexes-prices-and-volumes-December-2019-
Orientées
Stockage quarter-provisional/Download-data/overseas-trade-indexes-december-2019-quarter-
provisional.csv
Démo,
Activités f. Check the results.
pratiques et
Etudes de cas

Professeur
M. QBADOU

5
Cours Big Data – Les fondements
Département Application1 – Correction(1/5)
Math & Info
1. Create the HDFS application's folders :
Filière : APP_HOME=/user/industries
II-BDCC RES_DIR=$APP_HOME/res
hdfs dfs -mkdir $APP_HOME
Big Data – hdfs dfs -mkdir $RES_DIR
les
Fondements
2. Download a csv file using its URL and upload it to HDFS folder RES_DIR under
Big Data
Architectures
the name “indicCommercExtern1.csv”
Orientées FILE_URL=https://www.stats.govt.nz/assets/Uploads/Overseas-trade-indexes-
Stockage
prices-and-volumes/Overseas-trade-indexes-prices-and-volumes-December-2019-
Démo, quarter-provisional/Download-data/overseas-trade-indexes-december-2019-
Activités
pratiques et quarter-provisional.csv
Etudes de cas
FILE_BASENAME=indicCommercExtern1.csv
Professeur FILE_NAME="$RES_DIR"/"$FILE_BASENAME"
M. QBADOU
wget -O - $FILE_URL | hdfs dfs -put - "$FILE_NAME"
6
Cours Big Data – Les fondements
Département Application1 - Correction (2/5)
Math & Info
3. Check the two last commands and show the blocks size value and the blocks
Filière : of thedfsdownloaded
hdfs file
-ls -R $APP_HOME
II-BDCC hdfs dfs -cat "$FILE_NAME"
hdfs dfs -tail "$FILE_NAME"
Big Data – #display the default value ofblock size parameter
les
Fondements hdfs getconf -confKey dfs.blocksize
# list the hdfs file blocks
Big Data hdfs fsck $RES_DIR -files -blocks
Architectures
Orientées
Stockage
4. Repeat the command of (2) for a specific block size value (4 Mo) and the file
Démo,
Activités
name : ““indicCommercExtern2.csv”
pratiques et
Etudes de cas FILE_BASENAME=indicCommercExtern2.csv
FILE_NAME="$RES_DIR"/"$FILE_BASENAME"
Professeur wget -O - $FILE_URL |hdfs dfs -D dfs.blocksize=$BLOCK_SIZE_VALUE -put -
M. QBADOU
"$FILE_NAME"2.csv
7
Cours Big Data – Les fondements
Département Application1 - Correction (3/5)
Math & Info
5. Repeat the check of the step (3)
Filière : hdfs dfs -ls -R $APP_HOME
II-BDCC hdfs dfs -cat "$FILE_NAME"
hdfs dfs -tail "$FILE_NAME"
Big Data – # list the hdfs file blocks
les
Fondements hdfs fsck $RES_DIR -files -blocks

Big Data 6. Create, edit and execute a script file:


Architectures
Orientées a. create a workspace directory as a subdirectory of the HOME directory
Stockage
myhostdir=/home/uti/qb/scripts
Démo,
Activités sudo mkdir $myhostdir
pratiques et
Etudes de cas cd $myhostdir

Professeur b. + C. Create and edit the file named “hdfs_manip1.sh”


M. QBADOU sudo touch hdfs_manip1.sh
sudo vim hdfs_manip1.sh
8
Cours Big Data – Les fondements
Département Application1 - Correction (4/5)
Math & Info
hdfs_manip1.sh
APP_HOME="$1“;RES_DIR=$APP_HOME/res;FILE_NAME="$RES_DIR"/"$2"
Filière :
II-BDCC hdfs dfs -mkdir $APP_HOME;hdfs dfs -mkdir $RES_DIR
wget -O - "$4" | hdfs dfs -put - "$FILE_NAME"1.csv
hdfs dfs -ls -R $APP_HOME;sleep 10;clear;
Big Data – hdfs dfs -cat "$FILE_NAME"1.csv;sleep 10;clear
les
Fondements hdfs dfs -tail "$FILE_NAME"1.csv;sleep 10;clear
hdfs getconf -confKey dfs.blocksize;sleep 10;clear
Big Data hdfs fsck $RES_DIR -files –blocks;sleep 10;clear
Architectures
Orientées BLOCK_SIZE_VALUE="$3“;wget -O - "$4" |hdfs dfs -D dfs.blocksize=$BLOCK_SIZE_VALUE -put -
Stockage
"$FILE_NAME"2.csv;hdfs dfs -ls -R $APP_HOME;sleep 10;clear
Démo, hdfs dfs -cat "$FILE_NAME"2.csv;sleep 10;clear;hdfs dfs -tail "$FILE_NAME"2.csv;sleep
Activités 10;clear;hdfs fsck $RES_DIR -files -blocks
pratiques et
Etudes de cas d. Change its mode to make it an executable file
Professeur sudo chmod +x hdfs_manip1.sh
M. QBADOU e. Execute the file using the following command line :
9 ./hdfs_manip1.sh /usr/indus indComExt 4m $FILE_URL
Cours Big Data – Les fondements
Département Application1 - Correction (5/5)
Math & Info
f. Check the results:
Filière :
APP_HOME =/usr/indus
II-BDCC RES_DIR=$APP_HOME/res
FILE_BASENAME= indComExt1.csv
Big Data – FILE_NAME="$RES_DIR"/"$FILE_BASENAME"
les
Fondements
hdfs dfs -ls -R $APP_HOME
hdfs dfs -cat "$FILE_NAME"
Big Data hdfs dfs -tail "$FILE_NAME“
Architectures
Orientées hdfs dfs -cat "$FILE_NAME"
Stockage hdfs dfs -tail "$FILE_NAME"
Démo, FILE_BASENAME= indComExt2.csv
Activités FILE_NAME="$RES_DIR"/"$FILE_BASENAME"
pratiques et
Etudes de cas # list the hdfs file blocks
hdfs fsck $RES_DIR -files –blocks
Professeur
M. QBADOU

10
Cours Big Data – Les fondements
Département Practical work to do
Math & Info
Objective:
Filière : Download of semi-structured thematic data in JSON format available on the Web
II-BDCC
(open data) and placement of this data in the HDFS system. All the files must
serve to illustrate the possibilities of Serialization and deserialization of semi-
Big Data –
les structured data under Hive and their analysis under Impala.
Fondements
We consider open data on the weather data provided in the form of a JSON file at
Big Data the URL:
Architectures
Orientées
Stockage https://openweathermap.org/history
Démo,
Activités Visit this website and give a Bash script to retrieve and organize all of the files
pratiques et
Etudes de cas provided.
Professeur The commented results of this work and the necessary explanations must be
M. QBADOU returned, before 03/31/2020 in pdf format, to the following email address:
[email protected]
11
Cours Big Data – Les fondements
Département
Math & Info

Filière :
II-BDCC Activités Pratiques : Application 2
Big Data –
Hadoop ETL pour les données des SGBDR
les
Fondements
Objective : use of Apache Sqoop (SQL To Hadoop)
Big Data
Architectures ▪ Enoncé du besoin métier en terme d’analyse de données
Orientées
Stockage ▪ Utiliser Apache Hadoop pour répondre à ce besoin et garantir une analyse rapide et à une
plus grande échelle que pour le cas des SGBDR.
Démo,
Activités ▪ Permettre une migration et une intégration transparentes des données relationnelles vers
pratiques et le système Hadoop.
Etudes de cas
• Comment fonctionne Sqoop ?
Professeur • Connecteurs et JDBCDriver Sqoop
M. QBADOU
• Importation de données dans Sqoop
12
Cours Big Data – Les fondements
Département Application 2 - Sqoop
Math & Info

Filière : 1 Cloudera QuickStart VM- An Overview


II-BDCC

2 Problems with RDBMS


Big Data –
les
Fondements
3 Need for Sqoop
Big Data
Architectures
Orientées 4 Introduction to Sqoop
Stockage

Démo,
Activités 5 Features to Sqoop
pratiques et
Etudes de cas
6 Sqoop Architecture
Professeur
M. QBADOU
7 Sqoop Commands & Demo using MySQL
13
Cours Big Data – Les fondements
Département Application 2 – ETL Hadoop – Sqoop|Flume
Math & Info
❑ Données Structurées vs non structurées
Filière : ▪ Données non structurées sont des données :
II-BDCC
• Ne sont pas décrites par un modèle prédéfini et ne sont pas organisées dans une manière
prédéfinie
Big Data –
les ▪ Types de données non structurées
Fondements
• Texte : Document Word, PDF, RTF, emails, blog, wiki, …
Big Data • Fichiers Audio/Vidéo
Architectures
Orientées
Stockage
Données structurées Données non structurées
Démo,
Activités
pratiques et
Etudes de cas

Professeur
M. QBADOU

14
Cours Big Data – Les fondements
Département Application 2: ETL Hadoop – Sqoop|Flume
Math & Info
❑ Intégration de donnée
Filière :
II-BDCC

Big Data –
les
Fondements

Big Data
Architectures
Orientées
Stockage

Démo,
Activités
pratiques et
Etudes de cas

Professeur
M. QBADOU

15
Cours Big Data – Les fondements
Département Application 2: Sqoop – The features
Math & Info

Filière :
II-BDCC

Big Data –
les
Fondements

Big Data
Architectures
Orientées
Stockage

Démo,
Activités
pratiques et
Etudes de cas

Professeur
M. QBADOU

16
Cours Big Data – Les fondements
Département Application 2: Comment fonctionne le composant Sqoop
Math & Info
❑ Caractéristiques de :
Filière : ▪ Principalement exploité et testé sous le système Linux (Package rpm pour Red
II-BDCC
Hat, CentOS, SUSE, et packages deb pour Ubuntu et Debian).
Big Data –
▪ N’est pas un service de Cluster. Il suffit qu’il soit installé sur un ordinateur ou
les
Fondements
sur n'importe quel nœud du cluster Hadoop.
▪ Apache fournit une distribution pour chaque version de Hadoop ( Sqoop-
Big Data
Architectures hadoop 2.x.x.tar  Hadoop 2.x.x, Sqoop-hadoop 2.x.x.tar  Hadoop 2.x.x )
Orientées
Stockage ▪ Avant de pouvoir utiliser Sqoop, Hadoop doit être installée et configurée.
Démo, ▪ Utilise MapReduce pour l’importation/exportation de données. Ce qui
Activités
pratiques et garantit la parallélisation de l’opération ainsi que la tolérance au pannes.
Etudes de cas

Professeur Name Node (NN)


M. QBADOU Job Tracker (JT)
Configurations Data Node (DN)
Task Tracker (TT)
17
Cours Big Data – Les fondements
Département Application 2: Sqoop – principe de fonctionnement
Math & Info
❑ = SQL TO Hadoop
Filière : ▪ Permet l’importation et l’exportation de données.
II-BDCC

Big Data – PB
les
Fondements

Big Data
Architectures
Orientées
Stockage PB

Démo,
Activités PB
pratiques et
Etudes de cas BigTable (Google)
Dynamo (Amazon) NoSQL
Professeur Cassandra(Facebook)
Hbase (Facebook)
M. QBADOU
MongoDB (SourceForge) PB
HyperTable(Baidu)
18
Cours Big Data – Les fondements
Département Application 2 – Sqoop – Etude de cas
Math & Info
❑ Enoncé du besoin en matière d’analyse de données
Filière : ▪ Une société internationale (cas de Amazon) de vente de produits souhaite
II-BDCC
répondre aux questions suivantes :
• Quels sont les produits achetés actuellement par nos clients ?
Big Data –
les • Quels sont les produits que nos clients souhaiterons acheter dans le futur ?
Fondements

Big Data
Architectures
Orientées
Stockage

Démo,
Activités
pratiques et
Etudes de cas

Professeur
M. QBADOU

19
Cours Big Data – Les fondements
Département Application 2: Sqoop – Etude ce cas - Système actuel
Math & Info
Système actuel : Bases de données classiques (SGBDR) :
Filière :
II-BDCC
Liste des tables
Big Data –
les
Fondements

Big Data
Architectures
Orientées
Stockage

Démo,
Activités
pratiques et
Etudes de cas Nombre de lignes dans chaque table
Professeur
M. QBADOU

20
Cours Big Data – Les fondements
Département Application 2: Sqoop – Etude de cas - Système actuel
Math & Info
❑ Système actuel - Schéma relationnel
Filière :
II-BDCC

Big Data –
les
Fondements

Big Data
Architectures
Orientées
Stockage

Démo,
Activités
pratiques et
Etudes de cas

Professeur
M. QBADOU

21
Cours Big Data – Les fondements
Département Application 2: Sqoop – principe de l’importation
Math & Info
❑ Etapes de la commande import :
Filière : ▪ Utilise MapReduce pour l’importation/exportation de données. Ce qui
II-BDCC
garantit la parallélisation de l’opération ainsi que la tolérance au pannes.
Big Data – Générer
les 1 import Orders … 4
Fondements MapOnly Job
Hadoop cluster
5
Big Data
Architectures Switch Switch Envoyer les
Orientées Examiner
Stockage 2 Extraire Switch
MapOnly Job
la table
Orders 3 Meta-Data
Switch
Démo,
Activités Switch
pratiques et
Etudes de cas Rack 1
6 Rack 2
Professeur Rack n
M. QBADOU Exécuter
MySQL Mapper pour
22 extraire 100/n %
Cours Big Data – Les fondements
Département Application 2: Sqoop – Les commandes import et import-all-tables
Math & Info
❑ Commandes sqoop :
Filière : ▪ Pour importer une seule table
II-BDCC
[cloudera@quickstart ~]$ sqoop import
--connect jdbc:mysql://192.168.52.130:3306/NomDeLaBase
Big Data –
les --username root --password cloudera
Fondements --table NomTable
--warehouse-dir=/user/hive/warehouse
Big Data
Architectures -m 1
Orientées
Stockage ▪ Pour importer l’ensemble des tables de la base de données
Démo, [cloudera@quickstart ~]$ sqoop import-all-tables \
Activités --connect jdbc:mysql://192.168.52.130:3306/retail_db \
pratiques et
Etudes de cas --username root --password cloudera \
--warehouse-dir=/user/hive/warehouse \
Professeur -m 1 \
M. QBADOU --as-parquetfile \
--hive-import
23
Cours Big Data – Les fondements
Département Application 2: Sqoop – Vérification sur HDFS
Math & Info
❑ Vérification de l’importation :
Filière : ▪ Après l’exécution de la commande import, on peut vérifier que les fichiers
II-BDCC
HDFS ont été créés par :
Big Data –
[cloudera@quickstart ~]$ hadoop fs -ls /user/hive/warehouse/
les
Fondements [cloudera@quickstart ~]$ hadoop fs -ls /user/hive/warehouse/categories/

Big Data
▪ On peut aussi consulter les tables grâce à l’outil impala depuis l’interface Web
Architectures Hue à l’URL :
Orientées
Stockage
http://quickstart.cloudera:8888/
Démo, User = cloudera
Activités
pratiques et ▪ Pour forcer impala à actualiser ces méta données
Etudes de cas Password = cloudera , il est nécessaire d’exécuter les commandes :

Professeur Invalidate metadata;


M. QBADOU Shows tables;

24
Cours Big Data – Les fondements
Département Application 2: Exploitation sur Hive|impala
Math & Info
❑ Requête qui répond à la question posée :
Filière : ▪ Les catégories de produits les plus populaires :
II-BDCC
select c.category_name, count(order_item_quantity) as count
Big Data –
from order_items oi inner join products p on oi.order_item_product_id = p.product_id
les inner join categories c on c.category_id = p.product_category_id
Fondements
group by c.category_name
Big Data order by count desc limit 10;
Architectures
Orientées
Stockage ▪ Les 10 produits les plus intéressants en chiffre de vente
Démo, select p.product_id, p.product_name, r.revenue from products p inner join
Activités
pratiques et (select oi.order_item_product_id, sum(cast(oi.order_item_subtotal as float)) as revenue
Etudes de cas
from order_items oi inner join orders o on oi.order_item_order_id = o.order_id
Professeur where o.order_status <> 'CANCELED' and o.order_status <> 'SUSPECTED_FRAUD'
M. QBADOU group by order_item_product_id) r on p.product_id = r.order_item_product_id
order by r.revenue desc limit 10;
25

You might also like