Schémas externes, formats de fichiers et de tables

Introduction à Redshift

Jason Myers

Principal Architect

Schémas externes

Composants d'une base de données Composants d'une base de données

  • Quand le catalogue de métadonnées et le stockage ne font pas partie du cluster, on parle d'externe

Redshift Spectrum

Schémas externes avec Redshift Spectrum

  • Redshift est le moteur
  • Utilise par défaut AWS Glue Data Catalog et le stockage AWS S3
Introduction à Redshift

Formats de fichiers S3

Format de fichier Colonnaire Lecture parallèle
Parquet Oui Oui
ORC Oui Oui
TextFile Non Non
OpenCSV Non Oui
JSON Non Non
Introduction à Redshift

Créer une table externe CSV

CREATE TABLE spectrumdb.IDAHO_SITE_ID
(
    'pk_siteid' INTEGER PRIMARY KEY,
    -- Cutting the rest of columns for space
)

-- CSV rows are comma delimited ROW FORMAT DELIMITED
-- CSV fields are terminated by a comma FIELDS TERMINATED BY ','
-- CSVs are a type of text file STORED AS TEXTFILE
-- This is where the data is in AWS S3 LOCATION 's3://spectrum-id/idaho_sites/'
-- This file has headers that we want to skip TABLE PROPERTIES ('skip.header.line.count'='1');
Introduction à Redshift

Interroger des tables Spectrum

  • Se requête comme une table interne
  • EXPLAIN sera différent
  • Aucun souci de DISTKEY ou SORTKEYs
  • Pseudocolonnes
    • $path : affiche le chemin de stockage du fichier pour la ligne
    • $size : affiche la taille du fichier pour la ligne
Introduction à Redshift

Utiliser les pseudocolonnes

SELECT "$path", 
       "$size",
       pk_siteid
  FROM spectrumdb.idaho_site_id;
$path                           | $size | pk_siteid
================================|=======|==========
's3://spectrum-id/idaho_sites/' | 1616  | 1 
's3://spectrum-id/idaho_sites/' | 1616  | 2 
's3://spectrum-id/idaho_sites/' | 1616  | 3 
Introduction à Redshift

Formats de tables

  • Formats courants :

    • Hive
    • Iceberg
    • Hudi
    • Deltalake
  • Lecture seulement

  • Certains, comme Hive, exigent un catalogue externe autre que AWS Glue
Introduction à Redshift

Afficher les schémas externes

  • SVV_ALL_SCHEMAS : internal ou external
SELECT schema_name, 
       schema_type
  FROM SVV_ALL_SCHEMAS
 ORDER BY SCHEMA_NAME;
schema_name           | schema_type
======================|=============
public_intro_redshift | internal
spectrumdb            | external
Introduction à Redshift

Afficher les tables externes

  • SVV_ALL_TABLES : TABLE ou EXTERNAL TABLE
SELECT table_name, 
       table_type
  FROM SVV_ALL_TABLES
 WHERE schema_name = 'public_intro_redshift';
table_name                | table_type
==========================|================
coffee_county_weather     | TABLE
idaho_monitoring_location | TABLE
idaho_samples             | TABLE
ecommerce_sales           | EXTERNAL_TABLE
Introduction à Redshift

Passons à la pratique !

Introduction à Redshift

Preparing Video For Download...