본문으로 건너뛰기

튜토리얼: Federation SQL

이 튜토리얼에서는 서로 다른 카탈로그의 테이블을 하나의 SQL로 조인하는 Federation SQL을 실습합니다.

목표

tpch 카탈로그의 TPC-H 벤치마크 데이터를 활용하여 크로스 카탈로그 조인의 원리를 이해합니다.

사전 조건

배경 지식

GenD는 Trino를 쿼리 엔진으로 사용합니다. Trino는 여러 데이터 소스를 카탈로그로 등록하고, 하나의 SQL에서 여러 카탈로그의 테이블을 조인할 수 있습니다. 이것이 Federation SQL입니다.


Step 1: 사용 가능한 카탈로그 확인

좌측 사이드바에서 Catalog을 클릭합니다.

카탈로그 목록

현재 등록된 카탈로그:

카탈로그타입용도
icebergIceberg (SeaweedFS S3)데이터 레이크
nessieNessie + Iceberg버전 관리 레이크
sourcedbPostgreSQL운영 DB
tpchTPC-H (빌트인)벤치마크 데이터
tpcdsTPC-DS (빌트인)벤치마크 데이터

Step 2: 단일 카탈로그 쿼리

SQL Editor를 열고 다음 쿼리를 실행합니다:

-- tpch 카탈로그의 고객 테이블 조회
SELECT custkey, name, mktsegment
FROM tpch.tiny.customer
LIMIT 5

tpch.tiny.customer 형식은 카탈로그.스키마.테이블입니다.


Step 3: 같은 카탈로그 내 JOIN

같은 tpch 카탈로그 안에서 customerorders를 조인합니다:

SELECT
c.name AS customer_name,
c.mktsegment,
COUNT(o.orderkey) AS order_count,
SUM(o.totalprice) AS total_spend
FROM tpch.tiny.customer c
JOIN tpch.tiny.orders o ON c.custkey = o.custkey
GROUP BY c.name, c.mktsegment
ORDER BY total_spend DESC
LIMIT 10

쿼리 결과

실행 결과: 고객별 주문 건수와 총 소비 금액이 표시됩니다.


Step 4: 크로스 카탈로그 JOIN (Federation)

서로 다른 카탈로그의 테이블을 조인합니다:

-- tpch 고객 수 vs tpcds 고객 수 비교 (Federation 예제)
SELECT
'tpch' AS source,
COUNT(*) AS customer_count
FROM tpch.tiny.customer

UNION ALL

SELECT
'tpcds' AS source,
COUNT(*) AS customer_count
FROM tpcds.tiny.customer

핵심: 하나의 SQL에서 tpchtpcds 두 개의 카탈로그를 동시에 조회했습니다. ETL 없이 실시간으로 데이터를 통합 분석할 수 있습니다.


Step 5: 다중 테이블 JOIN (tpch 카탈로그 내)

tpch 카탈로그의 여러 테이블을 조합합니다:

SELECT
r.name AS region,
n.name AS nation,
COUNT(DISTINCT c.custkey) AS tpch_customers,
COUNT(DISTINCT s.suppkey) AS tpch_suppliers
FROM tpch.tiny.region r
JOIN tpch.tiny.nation n ON r.regionkey = n.regionkey
LEFT JOIN tpch.tiny.customer c ON n.nationkey = c.nationkey
LEFT JOIN tpch.tiny.supplier s ON n.nationkey = s.nationkey
GROUP BY r.name, n.name
ORDER BY r.name, n.name

결과 확인

  • 여러 데이터 소스를 하나의 SQL로 조인할 수 있음을 확인했습니다
  • Federation SQL은 ETL 파이프라인 없이 실시간 데이터 통합을 가능하게 합니다
  • 카탈로그.스키마.테이블 형식으로 모든 데이터 소스에 접근합니다

다음 단계