- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将 HashMap 声明为 Spark (v0.9.1) 累加器。文档指出“Spark 本身支持数值类型的累加器和标准可变集合...”( link )。
但是,当我尝试创建 HashMap[String, Boolean] 时,这似乎对我不起作用:
scala> import collection.mutable.HashMap
import collection.mutable.HashMap
scala> val accum = sc.accumulator("test" -> true)(HashMap)
<console>:13: error: type mismatch;
found : scala.collection.mutable.HashMap.type
required: org.apache.spark.AccumulatorParam[(String, Boolean)]
val accum = sc.accumulator("test" -> true)(HashMap)
最佳答案
首先,您应该传递一个实际的 HashMap[String, String]
而不是 (String, String)
:
sc.accumulator(HashMap("t"-> true))
并且您可能需要编写自己的累加器,因为我没有找到 HashMap
的开箱即用的隐式:
implicit object iHashMap extends AccumulatorParam[HashMap[String, Boolean]] {
def zero(m: HashMap[String, String]) = HashMap()
def addInPlace(m1: HashMap[String, Boolean], m2: HashMap[String, Boolean]) = m1 ++ m2
}
这种行为可能不是您个人所期望的,但我希望您能捕获要点。
您还可以在这里找到一些非常有用的示例:https://github.com/apache/spark/blob/60abc252545ec7a5d59957a32e764cd18f6c16b4/core/src/test/scala/org/apache/spark/AccumulatorSuite.scala
关于scala - Apache Spark : Hashmap accumulators give type mismatch error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23414238/
我只是在阅读有关 HQ9+ 编程语言的一些内容: https://esolangs.org/wiki/HQ9+ , https://en.wikipedia.org/wiki/HQ9+ , 和 htt
首先,我是 Mongo DB 的新手。一直在遵循一些指南和示例,例如 https://www.programcreek.com/java-api-examples/index.php?api=com.
当我写作时 long long sum = accumulate(a.begin(), a.end(), 0); 或者 long long sum = accumulate(a.begin(), a.
当我写作时 long long sum = accumulate(a.begin(), a.end(), 0); 或者 long long sum = accumulate(a.begin(), a.
我有一个关于 accumulate() 和运算符重载的问题。 我有一个类 Order 包含 private: Customer cust; std::vector vP; 和一个类 Purchase
我在 C++ 中使用 opencv 库,我正在尝试计算 vector difference 中包含的点的总和 Point 类具有 x 属性,即 float . float pointSumX(Poin
我试图将以下循环转换为 accumulate() 调用,但我失败了: total = 0 for h in heat_values: total += h total -= total
如果我像下面这样在 C++ 中使用 accumulate 函数 std::vector v2{1, 2, 3, 4, 5}; int sum = 0; std::cout values{ 1,
有没有办法按名称获取已注册的 Spark 累加器,而无需传递实际引用?期望的行为: val cnt1 = sc.longAccumulator("cnt1") val cnt2 = something
std::accumulate 的 C++ 引用没有提到 std::accumulate 可能抛出的任何异常,仍然它的定义不包含 noexcept。假设一个人使用不抛出的类型和操作,在声明为 noex
尝试“滥用”std::accumulate 算法(为什么它出现在“数字” header 中?;)) template std::string strjoin(Range&& range, Sepera
这让我很困惑,如果有人能帮助我,我将不胜感激。 (编辑:以为这是一个模板化问题,我误会了) 我想使用 gnu 的并行累积算法(存储在 #include 中)添加以下类的多个拷贝 类故意不做太多,我觉
错误似乎与 std::accumulate() 或迭代器有关,或者我是否访问了无效指针? int m = 0; std::vector v{4,-3,0,-5}; for(std::vector::i
此代码是从另一个用户问题复制而来的,我很好奇这里的 accumulate 是如何工作的。我从这段代码中得到了正确的结果,但想知道 lcm 在“累积”时采用什么参数。初始化为 A,范围之和为 b?请帮忙
如何统计满足 lower_bound(42), upper_bound(137) 的元素数量从这段代码?? accumulate(values.lower_bound(42), values.uppe
我在测试代码中使用 std::accumulate 得到了意想不到的结果。我正在尝试添加一个大的 double vector ,但由于某种原因,该值溢出了: #include #include #
我试着编写一个基本的编译时版本的std::accumulate()通过定义一个类模板,该模板将递归迭代给定范围并在每次迭代时添加元素。 在 Ubuntu 14.04 上使用 gcc 4.8.4 编译测
我刚刚写了一个小的辅助函数作为 std::accumulate 的包装: template inline auto accumulate(FwdIter begin, FwdIter end) ->
需要以下示例的更漂亮的解决方案,但需要使用 std::accumulate。 #include #include #include class Object { public: Obje
是否可以指示 Redis 累积一组操作,然后发出“publish all”命令来发布整组操作(按线性顺序)? 所以你会以某种方式设置一个标记(startpublish ?)并且缓存会累积从中接收到的所
我是一名优秀的程序员,十分优秀!