Lược đồ ngoại, định dạng tệp và bảng

Giới thiệu về Redshift

Jason Myers

Principal Architect

Lược đồ ngoại

Thành phần cơ sở dữ liệu Thành phần cơ sở dữ liệu

  • Khi catalog siêu dữ liệu và lưu trữ không thuộc cụm, đó là ngoại

Redshift Spectrum

Lược đồ ngoại với Redshift Spectrum

  • Redshift là động cơ
  • Mặc định dùng AWS Glue Data Catalog và lưu trữ AWS S3
Giới thiệu về Redshift

Định dạng tệp dữ liệu S3

Định dạng tệp Dạng cột Hỗ trợ đọc song song
Parquet
ORC
TextFile Không Không
OpenCSV Không
JSON Không Không
Giới thiệu về Redshift

Tạo bảng CSV ngoại

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');
Giới thiệu về Redshift

Truy vấn bảng Spectrum

  • Truy vấn như bảng nội bộ
  • EXPLAIN sẽ khác
  • Không cần quan tâm DISTKEY hoặc SORTKEY
  • Cột giả (pseudocolumn)
    • $path - đường dẫn tệp của hàng
    • $size - kích thước tệp của hàng
Giới thiệu về Redshift

Dùng cột giả (pseudocolumn)

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 
Giới thiệu về Redshift

Định dạng bảng

  • Định dạng phổ biến:

    • Hive
    • Iceberg
    • Hudi
    • Deltalake
  • Chỉ đọc

  • Một số như Hive cần catalog ngoài thay vì AWS Glue
Giới thiệu về Redshift

Xem lược đồ ngoại

  • SVV_ALL_SCHEMAS - internal hoặc external
SELECT schema_name, 
       schema_type
  FROM SVV_ALL_SCHEMAS
 ORDER BY SCHEMA_NAME;
schema_name           | schema_type
======================|=============
public_intro_redshift | internal
spectrumdb            | external
Giới thiệu về Redshift

Xem bảng ngoại

  • SVV_ALL_TABLES - TABLE hoặc 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
Giới thiệu về Redshift

Ayo berlatih!

Giới thiệu về Redshift

Preparing Video For Download...