배열의 열 articleId
값을 집계해야합니다. 이것은 내가 groupBy
으로 미리 작성한 그룹 내에서 수행되어야합니다.Spark SQL : 그룹 내의 열 값 집계
내 표는 다음과 같습니다
| customerId | articleId | articleText | ...
| 1 | 1 | ... | ...
| 1 | 2 | ... | ...
| 2 | 1 | ... | ...
| 2 | 2 | ... | ...
| 2 | 3 | ... | ...
그리고 지금까지
| customerId | articleIds |
| 1 | [1, 2] |
| 2 | [1, 2, 3] |
내 코드 같은 것을 구축하려는 :
DataFrame test = dfFiltered.groupBy("CUSTOMERID").agg(dfFiltered.col("ARTICLEID"));
을하지만, 여기에 내가 AnalysisException
를 얻을 :
Exception in thread "main" org.apache.spark.sql.AnalysisException: expression 'ARTICLEID' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
누군가 올바른 진술을 작성할 수 있습니까?
당신을 수행 'SQLContext' 또는'HiveContext'를 사용합니까? –
SQLContext를 사용 중입니다 ... –