-- 글로벌 기업의 리전별 데이터 격리 정책
-- 그룹 설계: region_kr, region_eu, region_us, region_apac, region_global
CREATE OR REPLACE FUNCTION production.policies.gdpr_region_filter(
data_region_col STRING
)
RETURNS BOOLEAN
COMMENT 'GDPR/개인정보보호법 준수를 위한 리전별 데이터 격리'
RETURN
-- 글로벌 관리자: 모든 데이터 접근
IS_ACCOUNT_GROUP_MEMBER('region_global')
OR IS_ACCOUNT_GROUP_MEMBER('admin')
-- 한국 팀: 한국 데이터만
OR (IS_ACCOUNT_GROUP_MEMBER('region_kr')
AND data_region_col IN ('KR', 'Korea', 'South Korea'))
-- EU 팀: EU 국가 데이터만 (GDPR 적용 대상)
OR (IS_ACCOUNT_GROUP_MEMBER('region_eu')
AND data_region_col IN ('DE', 'FR', 'IT', 'ES', 'NL', 'BE',
'AT', 'PL', 'SE', 'DK', 'FI', 'IE',
'PT', 'GR', 'CZ', 'RO', 'HU', 'BG'))
-- US 팀: 미국 데이터만
OR (IS_ACCOUNT_GROUP_MEMBER('region_us')
AND data_region_col IN ('US', 'USA', 'United States'));
-- 고객 테이블에 적용
ALTER TABLE production.ecommerce.customers
SET ROW FILTER production.policies.gdpr_region_filter ON (country_code);
-- 주문 테이블에도 동일한 필터 적용
ALTER TABLE production.ecommerce.orders
SET ROW FILTER production.policies.gdpr_region_filter ON (customer_country);