중첩 데이터 병합하기
HR 팀은 직원 데이터를 두 개의 별도 JSON 파일에 보관하고 있어요. 하나는 기본 정보, 다른 하나는 추가 속성을 담고 있죠. 전체 직원 프로필을 만들려면 공통 식별자를 사용해 이 테이블들을 조인해야 해요.
INNER JOIN은 조인 열이 일치하는 두 테이블의 행을 결합해요. 예를 들어 이름으로 두 개의 초대자 명단을 합치는 것과 같아요. JsonReader, JsonReadOptions, Table 클래스는 이미 임포트되어 있어요.
이 연습은 강의의 일부입니다
Java에서 데이터 가져오기
연습 안내
- 첫 번째 JSON 파일의 테이블 이름을 설정하세요.
- 두 번째 파일의 빌더 체인을 완성하세요.
"id"열을 기준으로 테이블을 조인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
public class NestedEmployees {
public static void main(String[] args) {
// Set table name for first JSON
JsonReadOptions opts1 = JsonReadOptions
.builder("employees.json")
.____("Main")
.build();
Table main = new JsonReader().read(opts1);
// Complete builder chain for second JSON
JsonReadOptions opts2 = JsonReadOptions
.builder("employees_extra.json")
.tableName("Extra")
.____();
Table extra = new JsonReader().read(opts2);
System.out.println("Main columns: " + main.columnNames());
System.out.println("Extra columns: " + extra.columnNames());
// Join tables on id column
Table joined = main.____("id").____(extra);
System.out.println("\nJoined table (inner join on id):");
System.out.println(joined.print());
}
}