java - 迭代 MapReduce 作业出现 NumberFormatException 错误
问题描述
我的程序运行多个 Map reduce 作业,一个用于我传递给它的参数文件中的每一行参数。
主要功能如下:
public static void main(String[] args) throws Exception {
// Create configuration
Configuration conf = new Configuration();
if (args.length != 3)
{
System.err.println("Usage: KnnPattern <in> <out> <parameter file>");
System.exit(2);
}
//Reading argument using Hadoop API now
conf.set ("params", (args[2]));
String param = conf.get("params");
StringTokenizer inputLine = new StringTokenizer(param, "|");
int n = 1;
while(inputLine.hasMoreTokens())
{
conf.set("passedVal", inputLine.nextToken());
//Job Configuration here
++n;
}}
主函数读取第三个参数,即存储在 HDFS 中的参数文件,并为它运行的每个 MapReduce 作业传递 1 个参数字符串。或者至少那是我想要它做的。我不是 100% 确定这是否完全正确。
我的 Mapper 的设置如下所示:
protected void setup(Context context) throws IOException, InterruptedException
{
// Read parameter file using alias established in main()
Configuration conf = context.getConfiguration();
String knnParams = conf.get("passedVal");
StringTokenizer st = new StringTokenizer(knnParams, ",");
// Using the variables declared earlier, values are assigned to K and to the test dataset, S.
// These values will remain unchanged throughout the mapper
K = Integer.parseInt(st.nextToken());
normalisedSAge = normalisedDouble(st.nextToken(), minAge, maxAge);
normalisedSIncome = normalisedDouble(st.nextToken(), minIncome, maxIncome);
sStatus = st.nextToken();
sGender = st.nextToken();
normalisedSChildren = normalisedDouble(st.nextToken(), minChildren, maxChildren);
}
我的参数文件包含以下内容:
67, 16668, 单人, 男, 3|40, 25000, 单人, 男, 2|67, 16668, 单人, 男, 3
那是由“|”分隔的 3 组输入。
我得到的运行时错误是这样的:
错误:java.lang.NumberFormatException:对于输入字符串:“/KNN/PARAMS/paramFinal.txt”在 java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) 在 java.lang.Integer.parseInt(Integer.java: 569) 在 java.lang.Integer.parseInt(Integer.java:615) 在 KnnPattern$KnnMapper.setup(KnnPattern.java:168) 在 org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:143) 在org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787) 在 org.apache.hadoop.mapred.MapTask.run(MapTask.java:341) 在 org.apache.hadoop.mapred.YarnChild$2.run (YarnChild.java:164) 在 java.security.AccessController.doPrivileged(Native Method) 在 javax.security.auth.Subject.doAs(Subject.java:422) 在 org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation .java:1762) 在组织。apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
容器被 ApplicationMaster 杀死。容器应要求被杀死。退出代码为 143 容器以非零退出代码 143 退出
据我所知,这看起来像是一个类型转换错误(?),我不确定这是如何以及为什么会发生的。
这段代码主要是我从这里得到的 - https://github.com/matt-hicks/MapReduce-KNN/blob/master/KnnPattern.java
它对于一组参数运行得很好,但我需要它同时为多个参数或测试用例运行以供进一步应用。
有什么方法可以解决这个问题,或者至少知道为什么我会收到这个错误?很感谢任何形式的帮助。谢谢你。
解决方案
我弄清楚了为什么我会收到 NumberFormatException。
问题是我将第三个参数(args [2])作为字符串而不是 HDFS 中的文件位置读取,这就是错误日志显示的原因:
对于输入字符串:“/KNN/PARAMS/paramFinal.txt”
我现在出于测试目的所做的是,我没有给出文件位置,而是直接将输入文本作为第三个参数传递。这帮助我摆脱了这个特定的错误。
$ hadoop jar poker00.jar KnnPokerhand /Poker/train.txt /PokerOutputs/Output00 1,1,1,13,2,4,2,3,1,12,0/3,12,3,2,3,11,4,5,2,5,1/1,9,4,6,1,4,3,2,3,9,1
希望这对将来遇到此问题的任何人有所帮助。干杯。
推荐阅读
- c# - 无法启动 Kestrel。System.FormatException:无效的 URL:'http:////*:80'
- html - Angular:用户登录时隐藏元素
- java - 尝试在数组内的函数中设置数据会出错
- javascript - 如何使用没有哈希标签的jquery哈希
- sql-server - 将正确格式的参数传递给链接服务器
- java - 对 5-7 张卡片使用 recyclerview 与 scrollview
- reactjs - 永远不会调用 Reactjs 表单 onSubmit
- java - 在后台线程中获取 MultipartFormDataInput 的主体
- php - 在作曲家中插入类的路径,所以我可以在 php 的“使用”中删除它
- c# - 未找到 DiscordClient 和 LogMessageEventArgs 错误