의 구성원이 아닙니다. 파일을로드하고 데이터 프레임으로 변환되었지만 평균을 파싱하는 동안 오류가 발생했습니다. 샘플 요청이 우리를 위해 평균에 대한 = 2.8오류 : 값이 선택은 내가 파일의 모든 JSON 객체의 등급 평균 얻기 위해 노력하고 org.apache.spark.sql.Row
{
"country": "Egypt",
"customerId": "Egypt009",
"visited": [
{
"placeName": "US",
"rating": "1.3",
"famousRest": "McDonald",
"placeId": "Dedcf3"
},
{
"placeName": "US",
"rating": "3.3",
"famousRest": "EagleNest",
"placeId": "CDfet3"
},
}
{
"country": "Canada",
"customerId": "Canada012",
"visited": [
{
"placeName": "UK",
"rating": "3.3",
"famousRest": "N/A",
"placeId": "XSdce2"
},
]
}
이 JSON에 대한 그래서
{
"country": "France",
"customerId": "France001",
"visited": [
{
"placeName": "US",
"rating": "2.3",
"famousRest": "N/A",
"placeId": "AVBS34"
},
{
"placeName": "US",
"rating": "3.3",
"famousRest": "SeriousPie",
"placeId": "VBSs34"
},
{
"placeName": "Canada",
"rating": "4.3",
"famousRest": "TimHortons",
"placeId": "AVBv4d"
}
]
}
은 미국 평균 평가 될 것 (2.3 + 3.3)/2 = (3.3 1.3)/2 =
2.3 그래서 모든 이상, 평균 평점은 다음과 같습니다
(2.8 + 2.3)/2 = 2.55내 스키마 (두 개의 요청이 자신의 방문 목록에 '미국'이)
root
|-- country: string(nullable=true)
|-- customerId:string(nullable=true)
|-- visited: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- placeId: string (nullable = true)
| | |-- placeName: string (nullable = true)
| | |-- famousRest: string (nullable = true)
| | |-- rating: string (nullable = true)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val df = sqlContext.jsonFile("temp.txt")
df.show()
수행 할 때 :
val app = df.select("strategies"); app.registerTempTable("app"); app.printSchema(); app.show()
app.foreach({
t => t.select("placeName", "rating").where(t("placeName") == "US")
}).show()
I am getting :
<console>:31: error: value select is not a member of org.apache.spark.sql.Row t => t.select("placeName", "rating").where(t("placeName") == "US")^
누군가가 내가 잘못 여기서 뭐하는 거지 말씀해 주시겠습니까?
발 응용 프로그램 = df.select ("전략"); app.registerTempTable ("app"); app.printSchema(); app.show는() –
앱이 테이블을 제공합니다 (구조체의 배열) –
당신이 날 모든 장소 이름의 평균을 찾기 위해 방향을 수정 가리킬 수 있습니다 목록을보고 각 사용하는 이유 이잖아 방문의 목록으로 구성 = US –