外部スキーマ、ファイル、テーブル形式

Redshift入門

Jason Myers

Principal Architect

外部スキーマ

データベース構成要素 データベース構成要素

  • メタデータカタログとストレージがクラスター外にある場合は外部とみなす

Redshift Spectrum

Redshift Spectrum の外部スキーマ

  • Redshift がエンジン
  • 既定で AWS Glue Data Catalog と AWS S3 ストレージを使用
Redshift入門

S3 のデータファイル形式

ファイル形式 列指向 並列読み取り対応
Parquet Yes Yes
ORC Yes Yes
TextFile No No
OpenCSV No Yes
JSON No No
Redshift入門

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');
Redshift入門

Spectrum テーブルのクエリ

  • 内部テーブルと同様にクエリ可能
  • EXPLAIN の結果は異なる
  • DISTKEYSORTKEY は不要
  • 疑似列
    • $path - 行のファイルパス
    • $size - 行のファイルサイズ
Redshift入門

疑似列の使用

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入門

テーブル形式

  • 代表的な形式:

    • Hive
    • Iceberg
    • Hudi
    • Deltalake
  • 読み取り専用

  • Hive などは AWS Glue 以外の外部カタログが必要
Redshift入門

外部スキーマの確認

  • SVV_ALL_SCHEMAS - internal または 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入門

外部テーブルの確認

  • SVV_ALL_TABLES - TABLE または 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入門

Passons à la pratique !

Redshift入門

Preparing Video For Download...