Ben RDD [Satır]:Scala: String değerleri için GroupBy toplamı nasıl yapılır?
|---itemId----|----Country-------|---Type----------|
| 11 | US | Movie |
| 11 | US | TV |
| 101 | France | Movie |
her satır ayrı json nesnesi (RDD her satır) nerede olduğunu json Listesi olarak kaydedebilirsiniz böylece GroupBy ItemID Nasıl yapılır?
{"itemId" : 11,
"Country": {"US" :2 },"Type": {"Movie" :1 , "TV" : 1} },
{"itemId" : 101,
"Country": {"France" :1 },"Type": {"Movie" :1} }
RDD:
denedim:
import com.mapping.data.model.MappingUtils
import com.mapping.data.model.CountryInfo
val mappingPath = "s3://.../"
val input = sc.textFile(mappingPath)
girdi listesidir
val MappingsList = input.map(x=> {
val countryInfo = MappingUtils.getCountryInfoString(x);
(countryInfo.getItemId(), countryInfo)
}).collectAsMap
MappingsList: scala.collection.Map[String,com.mapping.data.model.CountryInfo]
def showCountryInfo(x: Option[CountryInfo]) = x match {
case Some(s) => s
}
val events = sqlContext.sql("select itemId EventList")
val itemList = events.map(row => {
val itemId = row.getAs[String](1);
val çountryInfo = showTitleInfo(MappingsList.get(itemId));
val country = if (countryInfo.getCountry() == 'unknown)' "US" else countryInfo.getCountry()
val type = countryInfo.getType()
Row(itemId, country, type)
})
bazı biri bana bunu başarmak nasıl bildirin Can: Ben JSON ayrıştırma ve dönüştürme ilgilenir MappingUtils kullanarak CountryInfo POJO sınıfına eşleme ediyorum her satır json olduğu jsons?
Teşekkür ederiz!
RDD [Satır] bir DataFrame/DataSet'den mi geldi? RDD ile çalışmak [Row] hala ideal olmamasına rağmen ideal değildir. –
RDD'yi veri kümesinden oluşturdum. –
@ASpotySpot RDD'imle güncellendi –