这个scala错误意味着什么:"类型不匹配;发现:(((长,长),长),)要求:(((长,长),长))⇒字符串"

时间:2016-02-26 21:32:38

标签: scala apache-spark

我是Scala的新手。我知道错误是与Tuple1,Tuple2初始化有关的东西,但不能完全抓住确切的原因。

以下是我收到的语法错误消息: 类型不匹配;发现:((长,长),长)必需:(((长,长),长))⇒字符串

这是导致它的代码片段。

dedupedRDD = iterateRDD.mapPartitions(p => {
        var minVal = 0L
        p.map {
            val tpl = p.next()
            val key = tpl._1._1
            val value = tpl._2
            var outputTuple : Tuple2[Tuple2[Long, Long],Long] = null
            if(key != prevKey){
              if(value < key){
                minVal = value;
                outputTuple = ((minVal, key) , key)
                newEdgeCounter.add(1L);
              }else{
                minVal = key;
                outputTuple = ((minVal,value), value)
              }
            }else{
              outputTuple = ((minVal, value), value)
            }
            prevKey = key;
            outputTuple
          }
      })

如何创建(((Long,Long),Long)的输出元组。 任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:3)

你创建了outputTuples就好了,但是你没有从输出元组到字符串创建一个函数。

它说它想要类型from copy import copy from functools import wraps from rest_framework.metadata import SimpleMetadata from rest_framework.relations import RelatedField class MyMetadata(SimpleMetadata): def get_field_info(self, field): if isinstance(field, RelatedField): def kill_queryset(f): @wraps(f) def wrapped(*args, **kwargs): qs = f(*args, **kwargs) if qs is not None: qs = qs.none() return qs return wrapped field = copy(field) field.get_queryset = kill_queryset(field.get_queryset) result = super(MyMetadata, self).get_field_info(field) if not result.get('choices'): result.pop('choices', None) ,这意味着它是一个以(((Long, Long), Long)) => String为参数并生成字符串的函数。这是一个这样的功能:

((Long, Long), Long)

在我看来,这应该是val lll2s = (lll: ((Long, Long), Long)) => { (lll._1._1 + lll._1._2 + lll._2).toString } 的论据。

E.g。你可以写

p.map