Database

Introduzione al Data Engineering

Vincent Vankrunkelsven

Data Engineer, DataCamp

Cosa sono i database?

 

Immagine di un database

Di solito, una grande raccolta di dati organizzata per ricerche e recuperi rapidi.

 

  • Contiene dati
  • Organizza dati
  • Recupero/ricerca via DBMS
Introduzione al Data Engineering

Database e archiviazione file

Database

 

Immagine di un database

  • Molto organizzati
  • Funzionalità come ricerca, replica, ...

File system

 

Immagine di un file

  • Meno organizzati
  • Semplici, con poche funzionalità aggiunte
Introduzione al Data Engineering

Dati strutturati e non strutturati

Strutturati: schema del database

  • Database relazionali

 

Semi-strutturati

  • JSON

 

Non strutturati: senza schema, simili a file

  • Video, foto

Immagine di un database

 

{ "key": "value"}

 

Immagine di un file

Introduzione al Data Engineering

SQL e NoSQL

SQL

  • Tabelle
  • Schema del database
  • Database relazionali

 

Immagine MySQL

Immagine PostgreSQL

NoSQL

  • Database non relazionali
  • Strutturati o non strutturati
  • Key-value store (es. caching)
  • Document DB (es. oggetti JSON)

 

Immagine Redis/MongoDB

Introduzione al Data Engineering

SQL: Lo schema del database

-- Create Customer Table 
CREATE TABLE "Customer" (
  "id" SERIAL NOT NULL,
  "first_name" varchar,
  "last_name" varchar,
  PRIMARY KEY ("id")
);

-- Create Order Table 
CREATE TABLE "Order" (
  "id" SERIAL NOT NULL,
  "customer_id" integer REFERENCES "Customer",
  "product_name" varchar,
  "product_price" integer,
  PRIMARY KEY ("id")
);

Schema del database per Customer e Order

-- Join di entrambe le tabelle sulla chiave esterna
SELECT * FROM "Customer"
INNER JOIN "Order"
ON "customer_id" = "Customer"."id";
 id | first_name | ... | product_price
  1 | Vincent    | ... |            10
Introduzione al Data Engineering

SQL: Star schema

Lo star schema è composto da una o più tabelle dei fatti che fanno riferimento a un numero qualsiasi di tabelle delle dimensioni.

Diagramma Star Schema di Customer e Order

  • Fatti: eventi accaduti (es. ordini di prodotto)
  • Dimensioni: informazioni sul contesto (es. dati cliente)
1 https://en.wikipedia.org/wiki/Star_schema
Introduzione al Data Engineering

Esercitiamoci!

Introduzione al Data Engineering

Preparing Video For Download...