Externe schema’s, bestands- en tabelindelingen

Introductie tot Redshift

Jason Myers

Principal Architect

Externe schema’s

Databasecomponenten Databasecomponenten

  • Als metadata-catalogus en opslag niet bij de cluster horen, is het extern

Redshift Spectrum

Externe schema’s met Redshift Spectrum

  • Redshift is de engine
  • Gebruikt standaard AWS Glue Data Catalog en AWS S3-opslag
Introductie tot Redshift

S3-databestandsindelingen

Bestandsindeling Kolomgebaseerd Parallel lezen mogelijk
Parquet Ja Ja
ORC Ja Ja
TextFile Nee Nee
OpenCSV Nee Ja
JSON Nee Nee
Introductie tot Redshift

CSV-externe tabel maken

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');
Introductie tot Redshift

Spectrumtabellen query’en

  • Werkt net als query’s op interne tabellen
  • EXPLAIN ziet er anders uit
  • Geen DISTKEY of SORTKEYs nodig
  • Pseudokolommen
    • $path - toont het bestandspad voor de rij
    • $size - toont de bestandsgrootte voor de rij
Introductie tot Redshift

Pseudokolommen gebruiken

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 
Introductie tot Redshift

Tabelindelingen

  • Gangbare formats:

    • Hive
    • Iceberg
    • Hudi
    • Deltalake
  • Alleen lezen

  • Sommige, zoals Hive, hebben naast AWS Glue een externe catalogus nodig
Introductie tot Redshift

Externe schema’s bekijken

  • SVV_ALL_SCHEMAS - internal of external
SELECT schema_name, 
       schema_type
  FROM SVV_ALL_SCHEMAS
 ORDER BY SCHEMA_NAME;
schema_name           | schema_type
======================|=============
public_intro_redshift | internal
spectrumdb            | external
Introductie tot Redshift

Externe tabellen bekijken

  • SVV_ALL_TABLES - TABLE of 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
Introductie tot Redshift

Laten we oefenen!

Introductie tot Redshift

Preparing Video For Download...