階層的な再帰データをフラットなCSV形式に変換する
Data Shaping Query LanguageのRECURSIVE ON句とPARENT句を使用して、従業員の階層的なJSON構造をCSV形式にフラット化します。
このタスクについて
この例では、社長を最上位として、管理者や従業員のネストされたチームを持つ、レポート構造によって編成された従業員データを含む階層的なJSON構造があります。この構造を、従業員番号、従業員名、役職、マネージャーID、給与のカラムを含むCSVファイルにフラット化します。
入力JSONは、次のようにネストされたteam要素を含む組織階層に従います。
{
"employees": [
{
"id": "E001",
"name": "Alice Johnson",
"role": "President",
"salary": 150000,
"team": [
{
"id": "E002",
"name": "Bob Smith",
"role": "VP Engineering",
"salary": 120000,
"team": [
{
"id": "E003",
"name": "Carol Williams",
"role": "Engineering Manager",
"salary": 95000,
"team": [
{
"id": "E004",
"name": "David Brown",
"role": "Senior Developer",
"salary": 85000,
"team": []
},
{
"id": "E005",
"name": "Emma Davis",
"role": "Developer",
"salary": 75000,
"team": []
}
]
}
]
},
{
"id": "E006",
"name": "Frank Miller",
"role": "VP Sales",
"salary": 115000,
"team": [
{
"id": "E007",
"name": "Grace Lee",
"role": "Sales Manager",
"salary": 85000,
"team": [
{
"id": "E008",
"name": "Henry Chen",
"role": "Sales Representative",
"salary": 65000,
"team": []
}
]
}
]
}
]
}
]
}出力は、次のカラムを持つフラットなCSV構造になります。
EMPNO,ENAME,JOB,MGR,SAL手順
タスクの結果
EMPNO,ENAME,JOB,MGR,SAL
E001,Alice Johnson,President,,150000
E002,Bob Smith,VP Engineering,E001,120000
E003,Carol Williams,Engineering Manager,E002,95000
E004,David Brown,Senior Developer,E003,85000
E005,Emma Davis,Developer,E003,75000
E006,Frank Miller,VP Sales,E001,115000
E007,Grace Lee,Sales Manager,E006,85000
E008,Henry Chen,Sales Representative,E007,65000