Harici Şemalar, Dosya ve Tablo Biçimleri

Redshift’e Giriş

Jason Myers

Principal Architect

Harici şemalar

Veritabanı Bileşenleri Veritabanı Bileşenleri

  • Üstveri kataloğu ve depolama kümenin parçası değilse harici sayılır

Redshift Spectrum

Redshift Spectrum ile Harici Şemalar

  • Redshift motorudur
  • Varsayılan olarak AWS Glue Data Catalog ve AWS S3 depolamayı kullanır
Redshift’e Giriş

S3 veri dosyası biçimleri

Dosya biçimi Sütunlu Paralel okuma desteği
Parquet Evet Evet
ORC Evet Evet
TextFile Hayır Hayır
OpenCSV Hayır Evet
JSON Hayır Hayır
Redshift’e Giriş

CSV Harici Tablo Oluşturma

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');
Redshift’e Giriş

Spectrum tablolarını sorgulama

  • İç tablolara sorgu gibi çalışır
  • EXPLAIN farklı görünür
  • DISTKEY veya SORTKEY yok
  • Sözde sütunlar
    • $path - satırın dosya yolunu gösterir
    • $size - satırın dosya boyutunu gösterir
Redshift’e Giriş

Sözde sütunları kullanma

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 
Redshift’e Giriş

Tablo biçimleri

  • Yaygın biçimler:

    • Hive
    • Iceberg
    • Hudi
    • Deltalake
  • Yalnızca okuma

  • Hive gibi bazıları AWS Glue dışında harici bir katalog ister
Redshift’e Giriş

Harici şemaları görüntüleme

  • SVV_ALL_SCHEMAS - internal veya external
SELECT schema_name, 
       schema_type
  FROM SVV_ALL_SCHEMAS
 ORDER BY SCHEMA_NAME;
schema_name           | schema_type
======================|=============
public_intro_redshift | internal
spectrumdb            | external
Redshift’e Giriş

Harici tabloları görüntüleme

  • SVV_ALL_TABLES - TABLE veya 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
Redshift’e Giriş

Hadi pratik yapalım!

Redshift’e Giriş

Preparing Video For Download...