ストーリー
佐
佐藤CTO
“このデータはどこから来て、誰が管理していて、最後にいつ更新されたのか?” — こんな質問に即答できるか?
佐
佐藤CTO
データカタログは組織のデータ資産の地図だ。Apache Atlas、DataHub、そしてテクニカル/ビジネスメタデータの管理を学ぼう
メタデータの種類
| 種類 | 説明 | 例 |
|---|
| テクニカルメタデータ | データの物理的な構造情報 | スキーマ、型、パーティション、ファイル形式 |
| ビジネスメタデータ | データのビジネス的な意味 | 用語定義、KPI計算式、ビジネスルール |
| オペレーショナルメタデータ | データの運用状態 | 更新頻度、最終更新日時、行数、品質スコア |
| ソーシャルメタデータ | データの利用状況 | クエリ頻度、利用者数、評価、コメント |
データカタログの設計
// データカタログのコアモデル
interface DataAsset {
id: string;
urn: string; // Uniform Resource Name(一意識別子)
name: string;
description: string;
type: 'dataset' | 'dashboard' | 'pipeline' | 'ml_model';
platform: string;
// テクニカルメタデータ
technical: {
schema: SchemaField[];
format: string;
location: string;
partitionKeys?: string[];
sizeBytes?: number;
rowCount?: number;
};
// ビジネスメタデータ
business: {
domain: string;
tags: string[];
glossaryTerms: string[]; // ビジネス用語集への参照
classification: 'public' | 'internal' | 'confidential' | 'restricted';
piiFields: string[];
};
// オペレーショナルメタデータ
operational: {
owner: string;
steward: string;
freshness: {
lastUpdated: string;
updateFrequency: string;
sla: string;
};
qualityScore: number; // 0-100
upstreamDependencies: string[];
downstreamConsumers: string[];
};
// ソーシャルメタデータ
social: {
popularityScore: number; // クエリ頻度に基づく
topUsers: string[];
recentQueries: number;
userRatings: number;
comments: Comment[];
};
}
interface SchemaField {
name: string;
type: string;
description: string;
nullable: boolean;
isPrimaryKey: boolean;
isForeignKey: boolean;
glossaryTerm?: string;
tags: string[]; // 'pii', 'deprecated', 'derived' など
}
DataHub による実装
// DataHub: メタデータ取り込みパイプライン
// 1. スキーマ自動検出(テクニカルメタデータ)
interface DataHubIngestionConfig {
source: {
type: string;
config: Record<string, unknown>;
};
sink: {
type: 'datahub-rest';
config: { server: string };
};
transformers?: TransformerConfig[];
}
const postgresIngestion: DataHubIngestionConfig = {
source: {
type: 'postgres',
config: {
host_port: 'db.finflow.internal:5432',
database: 'production',
username: '${DATAHUB_DB_USER}',
password: '${DATAHUB_DB_PASSWORD}',
include_tables: true,
include_views: true,
profiling: {
enabled: true,
profile_table_level_only: false, // カラムレベルの統計も取得
},
stateful_ingestion: {
enabled: true, // 差分取り込み
},
},
},
sink: {
type: 'datahub-rest',
config: { server: 'http://datahub-gms:8080' },
},
transformers: [
{
type: 'simple_add_dataset_domain',
config: {
semantics: 'OVERWRITE',
domain_urn: 'urn:li:domain:finance',
},
},
],
};
// 2. dbt メタデータの連携(ビジネスメタデータ)
const dbtIngestion: DataHubIngestionConfig = {
source: {
type: 'dbt',
config: {
manifest_path: './target/manifest.json',
catalog_path: './target/catalog.json',
sources_path: './target/sources.json',
target_platform: 'snowflake',
load_schemas: true,
enable_meta_mapping: true, // dbt meta → DataHub tags
node_name_pattern: {
allow: ['.*'],
},
},
},
sink: {
type: 'datahub-rest',
config: { server: 'http://datahub-gms:8080' },
},
};
ビジネス用語集(Glossary)
// ビジネス用語集の管理
interface GlossaryTerm {
urn: string;
name: string;
definition: string;
domain: string;
owner: string;
relatedTerms: string[];
technicalMapping: {
datasets: string[];
columns: string[];
calculationLogic?: string;
};
status: 'draft' | 'approved' | 'deprecated';
}
const glossaryTerms: GlossaryTerm[] = [
{
urn: 'urn:li:glossaryTerm:monthly_active_users',
name: '月間アクティブユーザー(MAU)',
definition: '暦月内に1回以上トランザクションを実行したユニークユーザー数。退会済みユーザーは除外。',
domain: 'product-analytics',
owner: 'product-team',
relatedTerms: ['daily_active_users', 'user_retention_rate'],
technicalMapping: {
datasets: ['gold.fct_user_activity', 'gold.agg_monthly_metrics'],
columns: ['unique_active_users', 'mau_count'],
calculationLogic: 'COUNT(DISTINCT user_id) WHERE transaction_count > 0 AND user_status != "churned"',
},
status: 'approved',
},
{
urn: 'urn:li:glossaryTerm:customer_ltv',
name: '顧客生涯価値(LTV)',
definition: '顧客が生涯で企業にもたらす予測収益。手数料収入の累計から獲得コストを差し引いた値。',
domain: 'finance',
owner: 'finance-team',
relatedTerms: ['customer_acquisition_cost', 'churn_rate'],
technicalMapping: {
datasets: ['gold.dim_customer', 'gold.agg_customer_lifetime'],
columns: ['lifetime_value', 'predicted_ltv'],
calculationLogic: 'SUM(fee_revenue) - acquisition_cost + predicted_future_revenue',
},
status: 'approved',
},
];
Apache Atlas によるガバナンス統合
// Apache Atlas: 型定義とエンティティ管理
// カスタム型定義(金融データ向け拡張)
const finflowTypeDefinitions = {
entityDefs: [
{
name: 'finflow_dataset',
superTypes: ['DataSet'],
attributeDefs: [
{ name: 'dataClassification', typeName: 'string' },
{ name: 'retentionDays', typeName: 'int' },
{ name: 'regulatoryScope', typeName: 'array<string>' },
{ name: 'piiLevel', typeName: 'string' },
{ name: 'encryptionRequired', typeName: 'boolean' },
],
},
],
classificationDefs: [
{
name: 'PII',
description: '個人識別情報を含む',
attributeDefs: [
{ name: 'piiType', typeName: 'string' }, // name, email, phone, ssn
{ name: 'anonymizationMethod', typeName: 'string' },
],
superTypes: [],
},
{
name: 'FinancialData',
description: '金融取引データ',
attributeDefs: [
{ name: 'regulationType', typeName: 'string' }, // FSA, SOX, PCI-DSS
{ name: 'auditRequired', typeName: 'boolean' },
],
superTypes: [],
},
],
};
データカタログツール比較
| 機能 | DataHub | Apache Atlas | Amundsen | OpenMetadata |
|---|
| メタデータ取込 | Push/Pull両対応 | Push中心(Hook) | Pull中心(Extractor) | Push/Pull両対応 |
| リネージュ | 自動+手動 | 自動(Hive/Spark) | 限定的 | 自動+手動 |
| ビジネス用語集 | 充実 | 充実 | 基本的 | 充実 |
| データ品質統合 | Great Expectations連携 | 限定的 | 限定的 | dbt連携 |
| UIの使いやすさ | 良好 | やや複雑 | シンプル | 良好 |
| コミュニティ | 活発 | 成熟 | 縮小傾向 | 成長中 |
| 推奨シーン | モダンデータスタック | Hadoopエコシステム | シンプルな導入 | 新規導入 |
メタデータの自動収集パイプライン
// メタデータ収集の自動化パイプライン
interface MetadataCollectionPipeline {
schedule: string;
sources: MetadataSource[];
enrichment: EnrichmentStep[];
output: string;
}
const metadataPipeline: MetadataCollectionPipeline = {
schedule: '0 6 * * *', // 毎日AM6時
sources: [
{
name: 'Snowflake Schema',
type: 'technical',
method: 'INFORMATION_SCHEMA クエリ',
frequency: 'daily',
},
{
name: 'dbt Artifacts',
type: 'business',
method: 'manifest.json / catalog.json の解析',
frequency: 'on dbt run',
},
{
name: 'Airflow DAG Metadata',
type: 'operational',
method: 'Airflow REST API',
frequency: 'daily',
},
{
name: 'Query Logs',
type: 'social',
method: 'Snowflake QUERY_HISTORY',
frequency: 'daily',
},
],
enrichment: [
{
step: 'PII自動検出',
method: 'カラム名パターンマッチ + サンプルデータ分析',
patterns: ['*email*', '*phone*', '*address*', '*name*', '*ssn*'],
},
{
step: '鮮度スコア算出',
method: '最終更新日時とSLAの比較',
formula: 'max(0, 100 - (hours_since_update / sla_hours) * 100)',
},
{
step: '人気度スコア算出',
method: '直近30日のクエリ頻度とユニークユーザー数',
formula: 'log(query_count + 1) * unique_users',
},
],
output: 'DataHub REST API 経由でメタデータを更新',
};
まとめ
| ポイント | 内容 |
|---|
| メタデータの4種類 | テクニカル / ビジネス / オペレーショナル / ソーシャル |
| データカタログ | DataHub/Atlas等でデータ資産を一元管理 |
| ビジネス用語集 | 定義・計算ロジック・テクニカルマッピングを統合 |
| 自動収集 | スキーマ、dbt、Airflow、クエリログからメタデータを自動連携 |
チェックリスト
次のステップへ
次はデータプライバシーとコンプライアンスについて学びます。
推定読了時間: 40分