복붙노트

[SCALA] 같은 발견하고 필요한 데이터 유형과 스파크에서 : "오류 형식이 일치하지 않습니다"

SCALA

같은 발견하고 필요한 데이터 유형과 스파크에서 : "오류 형식이 일치하지 않습니다"

난 내 코드를 실행하기위한 스파크 쉘을 사용하고 있습니다. 내 코드에서 나는 함수를 정의하고 난 매개 변수와 그 함수를 호출합니다.

문제는 그 함수를 호출 할 때이 오류가 아래를 얻을 수 있다는 것입니다.

error: type mismatch;

found   : org.apache.spark.graphx.Graph[VertexProperty(in class $iwC)(in class $iwC)(in class $iwC)(in class $iwC),String]

required: org.apache.spark.graphx.Graph[VertexProperty(in class $iwC)(in class $iwC)(in class $iwC)(in class $iwC),String]

이 오류 뒤에 이유는 무엇입니까? 그것은 스파크에 그래프 데이터 타입과는 아무 상관 가지고있다?

코드 :이 기능을 "countpermissions"의 정의 및 호출을 포함 내 코드의 일부이다.

class VertexProperty(val id:Long) extends Serializable
case class User(val userId:Long, val userCode:String, val Name:String, val Surname:String) extends VertexProperty(userId)
case class Entitlement(val entitlementId:Long, val name:String) extends VertexProperty(entitlementId)

def countpermissions(es:String, sg:Graph[VertexProperty,String]):Long = {
    return 0
}

val triplets = graph.triplets
val temp = triplets.map(t => t.attr)
val distinct_edge_string = temp.distinct    
var bcast_graph = sc.broadcast(graph)        
val edge_string_subgraph = distinct_edge_string.map(es => es -> bcast_graph.value.subgraph(epred = t => t.attr == es))
val temp1 = edge_string_subgraph.map(t => t._1 -> countpermissions(t._1, t._2))

그것은 위에서 언급 한 오류를 얻는 마지막 줄까지 오류없이 코드가 실행됩니다.

해결법

  1. ==============================

    1.여기에 트릭입니다. REPL을 열고 클래스를 정의 할 수 있습니다 :

    여기에 트릭입니다. REPL을 열고 클래스를 정의 할 수 있습니다 :

    scala> case class Foo(i: Int)
    defined class Foo
    

    이 클래스에서 작동하는 간단한 기능 :

    scala> def fooToInt(foo: Foo) = foo.i
    fooToInt: (foo: Foo)Int
    

    클래스를 다시 정의 :

    scala> case class Foo(i: Int)
    defined class Foo
    

    및 인스턴스를 생성 :

    scala> val foo = Foo(1)
    foo: Foo = Foo(1)
    

    남은 것을 모두 풋 프린트를 호출하는 것입니다 :

    scala> fooToInt(foo)
    <console>:34: error: type mismatch;
     found   : Foo(in class $iwC)(in class $iwC)(in class $iwC)(in class $iwC)
     required: Foo(in class $iwC)(in class $iwC)(in class $iwC)(in class $iwC)
              fooToInt(foo)
    

    그것은 익숙한 보입니까? 또 다른 트릭에 무슨 일이 일어나고 있는지 더 나은 아이디어를 얻을 수 있습니다 :

    scala> case class Foo(i: Int)
    defined class Foo
    
    scala> val foo = Foo(1)
    foo: Foo = Foo(1)
    
    scala> case class Foo(i: Int)
    defined class Foo
    
    scala> def fooToInt(foo: Foo) = foo.i
    <console>:31: error: reference to Foo is ambiguous;
    it is imported twice in the same scope by
    import INSTANCE.Foo
    and import INSTANCE.Foo
             def fooToInt(foo: Foo) = foo.i
    

    약간, 동일한 범위에서 기존의 모호한 정의에서 발생하는 동작을 혼동하지만 이렇게 긴 이야기의 짧은이는, 기대된다.

    당신이 정기적으로 할 않는 : 리셋 REPL 상태 사용자가 만든 엔티티의 트랙과 경우 유형 정의 변경 메이크업을 유지해야 확실히 더 모호한 정의가 지속 없음 (필요한 경우 덮어 쓰기 일) 당신은 진행하기 전에.

  2. from https://stackoverflow.com/questions/37476790/error-type-mismatch-in-spark-with-same-found-and-required-datatypes by cc-by-sa and MIT license