여러 개의 json 파일이 있습니다. 아파치 스파크를 사용하여 구문 분석해야합니다. 그것은 중첩 된 키 초기화를 가지고있다. 중첩 된 키와 함께 모든 열을 인쇄해야합니다.Java에서 apache spark를 사용하여 json 파일에서 중첩 열을 얻는 방법
파일에도 중첩 키가 있습니다. 중첩 된 열 이름과 함께 모든 열 이름을 가져 오려고합니다. 어떻게 얻을 수 있니?
Age | Designation | Email | Name | City | State
------------------------------------------------------------
22 |Programmer |[email protected] | Vipin Suman| Ahmedabad |Gujarat
: 나는 등의 데이터를 원하는
people.show(50, false);
Age | Designation | Email | Name | Location
------------------------------------------------------------
22 |Programmer |[email protected] | Vipin Suman|[Ahmedabad,Gujarat]
: 나는이 결과를 얻고있다
{
"Name":"Vipin Suman",
"Email":"[email protected]",
"Designation":"Programmer",
"Age":22 ,
"location":
{
"City":"Ahmedabad",
"State":"Gujarat"
}
}
: 같은 파일에
String jsonFilePath = "/home/vipin/workspace/Smarten/jsonParsing/Employee/Employee-01.json,/home/vipin/workspace/Smarten/jsonParsing/Employee/Employee-02.json";
String[] jsonFiles = jsonFilePath.split(",");
Dataset<Row> people = sparkSession.read().json(jsonFiles);
JSON 구조 :
내가이 시도또는 같은 : -
Age | Designation | Email | Name | Location
---------------------------------------------------------------
22 |Programmer |[email protected] | Vipin Suman| Ahmedabad,Gujarat
scema 내가 중첩 된 키를 찾을 수있는 방법을
{
"Name":"Vipin Suman",
"Email":"[email protected]",
"Designation":"Trainee Programmer",
"Age":22 ,
"location":
{"City":
{
"Pin":324009,
"City Name":"Ahmedabad"
},
"State":"Gujarat"
},
"Company":
{
"Company Name":"Elegant",
"Domain":"Java"
},
"Test":["Test1","Test2"]
}
다음이
root
|-- Age: long (nullable = true)
|-- Company: struct (nullable = true)
| |-- Company Name: string (nullable = true)
| |-- Domain: string (nullable = true)
|-- Designation: string (nullable = true)
|-- Email: string (nullable = true)
|-- Name: string (nullable = true)
|-- Test: array (nullable = true)
| |-- element: string (containsNull = true)
|-- location: struct (nullable = true)
| |-- City: struct (nullable = true)
| | |-- City Name: string (nullable = true)
| | |-- Pin: long (nullable = true)
| |-- State: string (nullable = true)
및 JSON 구조처럼 보이게합니다. 및
준비하십시오 : 그것은 다음과 같은 출력 줄 것이다
입력 데이터 예를 들어, 당신은 무엇을했고 질문은 무엇입니까? –