我有一个csv数据文件存储在HDFS上的sequenceFile中,格式为name, zip, country, fav_food1, fav_food2, fav_food3, fav_colour.可能有许多具有相同名称的条目,我需要找出他们最喜欢的食物是什么(即计算所有具有该名称的记录中的所有食物条目并返回最受欢迎的食物.我是Scala和Spark的新手并拥有彻底的多个教程和搜索论坛,但我仍然坚持如何继续.到目前为止,我已经得到了文本到字符串格式的序列文件,然后过滤了条目
以下是文件中一行的示例数据条目
Bob,123,USA,Pizza,Soda,,Blue
Bob,456,UK,Chocolate,Cheese,Soda,Green
Bob,12,USA,Chocolate,Pizza,Soda,Yellow
Mary,68,USA,Chips,Pasta,Chocolate,Blue
Run Code Online (Sandbox Code Playgroud)
所以输出应该是元组(Bob,Soda),因为苏打在Bob的条目中出现次数最多.
import org.apache.hadoop.io._
var lines = sc.sequenceFile("path",classOf[LongWritable],classOf[Text]).values.map(x => x.toString())
// converted to string since I could not get filter to run on Text and removing the longwritable
var filtered = lines.filter(_.split(",")(0) == "Bob");
// removed entries with all other users
var f_tuples = filtered.map(line => lines.split(",");
// split all the values
var f_simple = filtered.map(line => (line(0), (line(3), line(4), line(5))
// removed unnecessary fields
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,我认为我有这种[<name,[f,f,f]>] …
我正在尝试使用 Apache 的 commons-lang3 创建一个可部署的 jar。但是,我的 Hadoop 所在的 AWS 集群不包含此库,因此我收到了 classNotFoundException。我想我需要手动添加该依赖项,但我在使用 Maven Shade 插件时遇到问题(建议我使用这个)我当前的 pom 文件如下所示:
<dependency>
<groupId>org.apache.pig</groupId>
<artifactId>pig</artifactId>
<version>0.12.0-cdh5.2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifact>org.apache.commons:commons-lang3</artifact>
<includes>
<include>org/apache/commons/commons-lang3/3.4/*</include>
</includes>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我想要一个完全正常的 jar,其中嵌入了 commons-lang3 库。我做错了什么吗?