Error: java.lang.NumberFormatException: For input string: “time”
Im trying to write java MapReduce code and keep getting the error:
Error: java.lang.NumberFormatException: For input string: "time"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at TokenizerMapper.map(Unknown Source)
at TokenizerMapper.map(Unknown Source)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1917)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
The mapper code in question is the following
public class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final IntWritable one = new IntWritable(1);
private Text data = new Text();
String transactionData = new String[5];
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(), ",");
while (itr.hasMoreTokens()) {
for (int i = 0; i < 5; i++) {
transactionData[i] = itr.nextToken();
}
Long timestamp = Long.parseLong(transactionData[2]);
Instant instant = Instant.ofEpochSecond(timestamp);
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.of("GMT"));
int year = ldt.getYear(); //e.g 2009
Month month = ldt.getMonth(); //e.g JANUARY
String time = month.toString() + ":" + Integer.toString(year);
data.set(time);
context.write(data, one);
}
}
}
It is supposed to take the 3rd value in each line of a csv dataset, which is a number, convert this to string, convert that to long and use the long to find the month and year.
where am i going wrong? thanks.
edit// Sample entry:
0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098,00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048,1231469665,1,1
java hadoop mapreduce
add a comment |
Im trying to write java MapReduce code and keep getting the error:
Error: java.lang.NumberFormatException: For input string: "time"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at TokenizerMapper.map(Unknown Source)
at TokenizerMapper.map(Unknown Source)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1917)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
The mapper code in question is the following
public class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final IntWritable one = new IntWritable(1);
private Text data = new Text();
String transactionData = new String[5];
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(), ",");
while (itr.hasMoreTokens()) {
for (int i = 0; i < 5; i++) {
transactionData[i] = itr.nextToken();
}
Long timestamp = Long.parseLong(transactionData[2]);
Instant instant = Instant.ofEpochSecond(timestamp);
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.of("GMT"));
int year = ldt.getYear(); //e.g 2009
Month month = ldt.getMonth(); //e.g JANUARY
String time = month.toString() + ":" + Integer.toString(year);
data.set(time);
context.write(data, one);
}
}
}
It is supposed to take the 3rd value in each line of a csv dataset, which is a number, convert this to string, convert that to long and use the long to find the month and year.
where am i going wrong? thanks.
edit// Sample entry:
0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098,00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048,1231469665,1,1
java hadoop mapreduce
We love having you here: what does your data look like?
– nicomp
Nov 25 '18 at 17:47
Your data has the wordtime
in the column where you're expecting a number. Is this text from the header row perhaps? Did you forget to skip the header row of your data?
– Dawood ibn Kareem
Nov 25 '18 at 17:50
Thanks, added sample entry, the data is a list of bitcoin transactions and im trying to use hadoop to find number of transactions each month.
– SE Project
Nov 25 '18 at 17:55
Is there a header row in your data set that you're not ignoring?
– Joe C
Nov 25 '18 at 17:59
add a comment |
Im trying to write java MapReduce code and keep getting the error:
Error: java.lang.NumberFormatException: For input string: "time"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at TokenizerMapper.map(Unknown Source)
at TokenizerMapper.map(Unknown Source)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1917)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
The mapper code in question is the following
public class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final IntWritable one = new IntWritable(1);
private Text data = new Text();
String transactionData = new String[5];
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(), ",");
while (itr.hasMoreTokens()) {
for (int i = 0; i < 5; i++) {
transactionData[i] = itr.nextToken();
}
Long timestamp = Long.parseLong(transactionData[2]);
Instant instant = Instant.ofEpochSecond(timestamp);
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.of("GMT"));
int year = ldt.getYear(); //e.g 2009
Month month = ldt.getMonth(); //e.g JANUARY
String time = month.toString() + ":" + Integer.toString(year);
data.set(time);
context.write(data, one);
}
}
}
It is supposed to take the 3rd value in each line of a csv dataset, which is a number, convert this to string, convert that to long and use the long to find the month and year.
where am i going wrong? thanks.
edit// Sample entry:
0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098,00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048,1231469665,1,1
java hadoop mapreduce
Im trying to write java MapReduce code and keep getting the error:
Error: java.lang.NumberFormatException: For input string: "time"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at TokenizerMapper.map(Unknown Source)
at TokenizerMapper.map(Unknown Source)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1917)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
The mapper code in question is the following
public class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final IntWritable one = new IntWritable(1);
private Text data = new Text();
String transactionData = new String[5];
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(), ",");
while (itr.hasMoreTokens()) {
for (int i = 0; i < 5; i++) {
transactionData[i] = itr.nextToken();
}
Long timestamp = Long.parseLong(transactionData[2]);
Instant instant = Instant.ofEpochSecond(timestamp);
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.of("GMT"));
int year = ldt.getYear(); //e.g 2009
Month month = ldt.getMonth(); //e.g JANUARY
String time = month.toString() + ":" + Integer.toString(year);
data.set(time);
context.write(data, one);
}
}
}
It is supposed to take the 3rd value in each line of a csv dataset, which is a number, convert this to string, convert that to long and use the long to find the month and year.
where am i going wrong? thanks.
edit// Sample entry:
0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098,00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048,1231469665,1,1
java hadoop mapreduce
java hadoop mapreduce
edited Nov 25 '18 at 17:54
SE Project
asked Nov 25 '18 at 17:45
SE ProjectSE Project
113
113
We love having you here: what does your data look like?
– nicomp
Nov 25 '18 at 17:47
Your data has the wordtime
in the column where you're expecting a number. Is this text from the header row perhaps? Did you forget to skip the header row of your data?
– Dawood ibn Kareem
Nov 25 '18 at 17:50
Thanks, added sample entry, the data is a list of bitcoin transactions and im trying to use hadoop to find number of transactions each month.
– SE Project
Nov 25 '18 at 17:55
Is there a header row in your data set that you're not ignoring?
– Joe C
Nov 25 '18 at 17:59
add a comment |
We love having you here: what does your data look like?
– nicomp
Nov 25 '18 at 17:47
Your data has the wordtime
in the column where you're expecting a number. Is this text from the header row perhaps? Did you forget to skip the header row of your data?
– Dawood ibn Kareem
Nov 25 '18 at 17:50
Thanks, added sample entry, the data is a list of bitcoin transactions and im trying to use hadoop to find number of transactions each month.
– SE Project
Nov 25 '18 at 17:55
Is there a header row in your data set that you're not ignoring?
– Joe C
Nov 25 '18 at 17:59
We love having you here: what does your data look like?
– nicomp
Nov 25 '18 at 17:47
We love having you here: what does your data look like?
– nicomp
Nov 25 '18 at 17:47
Your data has the word
time
in the column where you're expecting a number. Is this text from the header row perhaps? Did you forget to skip the header row of your data?– Dawood ibn Kareem
Nov 25 '18 at 17:50
Your data has the word
time
in the column where you're expecting a number. Is this text from the header row perhaps? Did you forget to skip the header row of your data?– Dawood ibn Kareem
Nov 25 '18 at 17:50
Thanks, added sample entry, the data is a list of bitcoin transactions and im trying to use hadoop to find number of transactions each month.
– SE Project
Nov 25 '18 at 17:55
Thanks, added sample entry, the data is a list of bitcoin transactions and im trying to use hadoop to find number of transactions each month.
– SE Project
Nov 25 '18 at 17:55
Is there a header row in your data set that you're not ignoring?
– Joe C
Nov 25 '18 at 17:59
Is there a header row in your data set that you're not ignoring?
– Joe C
Nov 25 '18 at 17:59
add a comment |
1 Answer
1
active
oldest
votes
If the problem is a header, just replace the line that causes the problem:
Long timestamp = Long.parseLong(transactionData[2]);
with
Long timestamp = 0L;
try {
timestamp = Long.parseLong(transactionData[2]);
} catch (NumberFormatException e) {
return;
}
So if the value is invalid the method will terminate without crashing.
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, thereturn;
statement causes their method to end without mapping any data.
– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470191%2ferror-java-lang-numberformatexception-for-input-string-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If the problem is a header, just replace the line that causes the problem:
Long timestamp = Long.parseLong(transactionData[2]);
with
Long timestamp = 0L;
try {
timestamp = Long.parseLong(transactionData[2]);
} catch (NumberFormatException e) {
return;
}
So if the value is invalid the method will terminate without crashing.
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, thereturn;
statement causes their method to end without mapping any data.
– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
add a comment |
If the problem is a header, just replace the line that causes the problem:
Long timestamp = Long.parseLong(transactionData[2]);
with
Long timestamp = 0L;
try {
timestamp = Long.parseLong(transactionData[2]);
} catch (NumberFormatException e) {
return;
}
So if the value is invalid the method will terminate without crashing.
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, thereturn;
statement causes their method to end without mapping any data.
– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
add a comment |
If the problem is a header, just replace the line that causes the problem:
Long timestamp = Long.parseLong(transactionData[2]);
with
Long timestamp = 0L;
try {
timestamp = Long.parseLong(transactionData[2]);
} catch (NumberFormatException e) {
return;
}
So if the value is invalid the method will terminate without crashing.
If the problem is a header, just replace the line that causes the problem:
Long timestamp = Long.parseLong(transactionData[2]);
with
Long timestamp = 0L;
try {
timestamp = Long.parseLong(transactionData[2]);
} catch (NumberFormatException e) {
return;
}
So if the value is invalid the method will terminate without crashing.
answered Nov 25 '18 at 18:12
forpasforpas
17.3k3628
17.3k3628
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, thereturn;
statement causes their method to end without mapping any data.
– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
add a comment |
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, thereturn;
statement causes their method to end without mapping any data.
– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
So if there's a line of header data, then no data at all should get mapped? This solution makes no sense to me.
– Dawood ibn Kareem
Nov 25 '18 at 18:28
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
@DawoodibnKareem no it skips only that line. The method works for 1 line. Isn't this obvious? Why do you think OP accepted the answer?
– forpas
Nov 25 '18 at 18:30
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, the
return;
statement causes their method to end without mapping any data.– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer. But if you put YOUR code into THEIR method, the
return;
statement causes their method to end without mapping any data.– Dawood ibn Kareem
Nov 25 '18 at 18:34
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
Well, I don't know why OP accepted your answer then why don't you ask him first if you have any doubts? Why does anyone accept an answer if this is not the solution for him?
– forpas
Nov 25 '18 at 18:36
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
My apologies for not responding earlier, This solution worked for myself and several others stuck on the same assignment question. - Thanks for help
– SE Project
Dec 5 '18 at 14:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470191%2ferror-java-lang-numberformatexception-for-input-string-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
We love having you here: what does your data look like?
– nicomp
Nov 25 '18 at 17:47
Your data has the word
time
in the column where you're expecting a number. Is this text from the header row perhaps? Did you forget to skip the header row of your data?– Dawood ibn Kareem
Nov 25 '18 at 17:50
Thanks, added sample entry, the data is a list of bitcoin transactions and im trying to use hadoop to find number of transactions each month.
– SE Project
Nov 25 '18 at 17:55
Is there a header row in your data set that you're not ignoring?
– Joe C
Nov 25 '18 at 17:59