您如何看待本网站提到的问题4的答案是什么?
答案是对还是错
问题:4
In the standard word count MapReduce algorithm, why might using a combiner reduce theoverall Job running time?
A. Because combiners perform local aggregation of word counts, thereby allowing the mappers to process input data faster.
B. Because combinersperform local aggregation of word counts, thereby reducing the number of mappers that need to run.
C. Because combiners perform local aggregation of word counts, and then transfer that data toreducers without writing the intermediate data to disk. …Run Code Online (Sandbox Code Playgroud) 我正在尝试为存储在SortedSet中的双值创建间隔.
以下是我的代码:
public class Trail {
public static void main(String[] args) {
SortedSet<Double> val = new TreeSet<Double>();
val.add(1.0);
val.add(2.0);
val.add(11.0);
val.add(12.0);
ArrayList<String> arr = new ArrayList<String>();
double posinf = Double.POSITIVE_INFINITY;
double neginf = Double.NEGATIVE_INFINITY;
arr.add(neginf+ " - " +val.first());
Iterator<Double> it = val.iterator();
while (it.hasNext()) {
// Get element
Object lowerBound = it.next();
Object upperBound = it.next();
arr.add(lowerBound+" - "+upperBound);
}
arr.add(val.last() + " - "+ posinf);
System.out.println("Range array: "+arr);
}
}
Run Code Online (Sandbox Code Playgroud)
我目前的输出是:
Range array: [-Infinity - 1.0, 1.0 - …Run Code Online (Sandbox Code Playgroud) 我需要使用 shell 脚本打开和关闭文件。
myshell.sh
vi adc.c
Run Code Online (Sandbox Code Playgroud)
当我执行 myshell.sh 时,它会打开一个文件。
我需要使用 shell 脚本关闭该文件。
我应该在 myshell.sh 中包含什么命令
我试图发出4个数值作为键.我为同一个写了自定义可写Comparable类,但我遇到了compare()方法,stackoverflow站点中提到了几个解决方案.但这并没有解决我的问题.
我的writableCoparable类是
public class DimensionWritable implements WritableComparable {
private double keyRow;
private double keyCol;
private double valRow;
private double valCol;
public DimensionWritable(double keyRow, double keyCol,double valRow, double valCol) {
set(keyRow, keyCol,valRow,valCol);
}
public void set(double keyRow, double keyCol,double valRow, double valCol) {
//row dimension
this.keyRow = keyRow;
this.keyCol = keyCol;
//column dimension
this.valRow = valRow;
this.valCol = valCol;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeDouble(keyRow);
out.writeDouble(keyCol);
out.writeDouble(valRow);
out.writeDouble(valCol);
}
@Override
public void readFields(DataInput in) throws IOException { …Run Code Online (Sandbox Code Playgroud) 我试图在最小值和最大值之间添加值1.12
Min = 1.3
Max = 6.9
Run Code Online (Sandbox Code Playgroud)
即
1.3 + 1.12 = 2.42
2.42 + 1.12 = 3.54
Run Code Online (Sandbox Code Playgroud)
直到它达到最大值.
我做的是
double sum = 0,BucWidth = 1.12;
sum = min + BucWidth ;
while(sum != max){
sum = sum +BucWidth ;
System.out.println("SUmmmmm" + sum);
}
Run Code Online (Sandbox Code Playgroud)
但是当总和达到最大值时它并没有停止.
我做错了什么.
请建议
我想删除最后一个元素
Map<String, List<String>> map = new HashMap<String, List<String>>();
Run Code Online (Sandbox Code Playgroud)
我的代码是
StringTokenizer stheader = new StringTokenizer(value.toString(),",");
while (stheader.hasMoreTokens()){
String tmp = stheader.nextToken();
header.add(tmp);
System.out.println("tmp"+header);
map.put(tmp, new ArrayList<String>());
}
System.out.println(map.size());
Run Code Online (Sandbox Code Playgroud)
输出:
tmp[Sepal_Length, Sepal_Width, Petal_Length, Petal_Width, Class]
map{Petal_Width=[], Class=[], Petal_Length=[], Sepal_Length=[], Sepal_Width=[]}
Run Code Online (Sandbox Code Playgroud)
我想从map或删除键Class [] tmp.
我尝试过使用.remove()但没有任何反映.
我有
Map<String, List<Attribute>> binList = new HashMap<String, List<Attribute>>();
Run Code Online (Sandbox Code Playgroud)
我想遍历列表中的每个值通过执行此操作,我能够获取密钥及其整个值.但是如何获取密钥的每个单值.
BinList {3=[index=0 {from=1.3,to=2.42}, index=1 {from=2.42,to=3.54}, index=2 {from=3.54,to=4.66}, index=3 {from=4.66,to=5.78}, index=4 {from=5.78,to=6.9}], 2=[index=0 {from=2.3,to=2.76}, index=1 {from=2.76,to=3.2199999999999998}, index=2 {from=3.2199999999999998,to=3.6799999999999997}, index=3 {from=3.6799999999999997,to=4.14}, index=4 {from=4.14,to=4.6}], 1=[index=0 {from=4.3,to=5.02}, index=1 {from=5.02,to=5.739999999999999}, index=2 {from=5.739999999999999,to=6.459999999999999}, index=3 {from=6.459999999999999,to=7.179999999999999}, index=4 {from=7.179999999999999,to=7.899999999999999}], 4=[index=0 {from=0.3,to=0.76}, index=1 {from=0.76,to=1.2200000000000002}, index=2 {from=1.2200000000000002,to=1.6800000000000002}, index=3 {from=1.6800000000000002,to=2.14}, index=4 {from=2.14,to=2.6}]}
Map<String, List<Attribute>> binList = new HashMap<String, List<Attribute>>();
System.out.println("BinList "+binList);
//Iterating binList
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println("->>>>"+pairs.getKey() + " = " + pairs.getValue());
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT
->>>>3 = [index=0 …Run Code Online (Sandbox Code Playgroud) 0 0 2 2 6 5 0.61 1
14 2 15 3 6 1 0.123 -1
Run Code Online (Sandbox Code Playgroud)
我想要得到
0 0 2 2 6 5 0.61
14 2 15 3 6 1 0.123
Run Code Online (Sandbox Code Playgroud)
为此我做了
String predictLine = line.substring(0, line.length() - 1);
Run Code Online (Sandbox Code Playgroud)
对于第一行,它是可以的,但对于最后一行它显示
14 2 15 3 6 1 0.123 -
Run Code Online (Sandbox Code Playgroud)
我做错了什么
我有两个案例
获取向量中的最后一个值.所以Vector cls包含1.因此,为了进一步处理,我将其转换为整数
int c = Integer.parseInt(cls.get(0));
Run Code Online (Sandbox Code Playgroud)
这工作正常但是对于第二种情况它失败了.
向量cls包含1.0,在转换为int时,它失败并带有NumberFormatException
int c= Integer.parseInt(cls.get(0));
Run Code Online (Sandbox Code Playgroud)
引起:java.lang.NumberFormatException:对于输入字符串:java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)中的"1.0"
通过将Vector保持为String本身,我可以做什么作为解决方法.编辑我需要为两个案例处理我的代码.