L’interface Spark

Introduction à Spark SQL en Python

Mark Plutowski

Data Scientist

Utiliser l’UI Spark pour inspecter l’exécution

  • Une tâche Spark est une unité d’exécution sur un seul CPU

  • Un stage Spark est un groupe de tâches effectuant le même calcul en parallèle, chacune sur un sous-ensemble de données

  • Un job Spark est un calcul déclenché par une action, découpé en un ou plusieurs stages.

Introduction à Spark SQL en Python

Trouver l’UI Spark

  1. http://[DRIVER_HOST]:4040
  2. http://[DRIVER_HOST]:4041
  3. http://[DRIVER_HOST]:4042
  4. http://[DRIVER_HOST]:4043
    ...
Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Opérations du catalogue Spark

  • spark.catalog.cacheTable('table1')
  • spark.catalog.uncacheTable('table1')
  • spark.catalog.isCached('table1')
  • spark.catalog.dropTempView('table1')
Introduction à Spark SQL en Python

Catalogue Spark

spark.catalog.listTables()
[Table(name='text', database=None, description=None, tableType='TEMPORARY', isTemporary=True)]
Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Onglet Storage de l’UI Spark

Indique où se trouvent les partitions

  • en mémoire,
  • sur disque,
  • dans le cluster,
  • à un instant donné.
Introduction à Spark SQL en Python

Onglet SQL de l’UI Spark

query3agg = """
SELECT w1, w2, w3, COUNT(*) as count FROM (
   SELECT 
   word AS w1,
   LEAD(word,1) OVER(PARTITION BY part ORDER BY id ) AS w2,
   LEAD(word,2) OVER(PARTITION BY part ORDER BY id ) AS w3
   FROM df
)
GROUP BY w1, w2, w3 
ORDER BY count DESC
""" 

spark.sql(query3agg).show()
Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Introduction à Spark SQL en Python

Passons à la pratique !

Introduction à Spark SQL en Python

Preparing Video For Download...