외부 스키마, 파일 및 테이블 형식

Redshift 입문

Jason Myers

Principal Architect

외부 스키마

데이터베이스 구성 요소 데이터베이스 구성 요소

  • 메타데이터 카탈로그와 스토리지가 클러스터 외부이면 외부로 간주합니다

Redshift Spectrum

Redshift Spectrum의 외부 스키마

  • Redshift가 엔진입니다
  • 기본으로 AWS Glue Data Catalog와 AWS S3 스토리지를 사용
Redshift 입문

S3 데이터 파일 형식

File format Columnar Supports parallel reads
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 입문

스펙트럼 테이블 쿼리

  • 내부 테이블 조회와 동일하게 동작
  • 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 입문

Let's practice!

Redshift 입문

Preparing Video For Download...