scala의 collection에서 [error]  required: scala.collection.GenTraversableOnce[?] 에러가 나는 경우가 있다..




예)


scala> List(1, "x").flatten

<console>:12: error: No implicit view available from Any => scala.collection.GenTraversableOnce[B].

       List(1, "x").flatten




scala> List(1, "x").flatMap(a => a)

<console>:12: error: type mismatch;

 found   : Any

 required: scala.collection.GenTraversableOnce[?]

       List(1, "x").flatMap(a => a)

                                 ^



실제 api를 보면  다음과 같이 A => GenTraversableOnce라는 타입을 받는다. 


def flatten[B](implicit asTraversable: A => /*<:<!!!*/ GenTraversableOnce[B]): CC[B] = {


final override def flatMap[B, That](f: A => GenTraversableOnce[B])
                       (implicit bf: CanBuildFrom[List[A], B, That]): That = {



재미있는 것은 Option은 GenTraversableOnce으로 implicit으로 변환할 수 있다. 




이전에 에러를 수정하려면 다음처럼 수정하면 될 것이다.



scala> List(Some(1), Some("x"), None).flatten

res9: List[Any] = List(1, x)



scala> List(1, "x").flatMap(a => Some(a))

res8: List[Any] = List(1, x)



Posted by '김용환'
,


kafka를 재시작하더라도 kafka의 토픽과 메시지는 모두 남아 있는데, 


테스트를 위해 kafka를 재시작할 때 모든 토픽과 메시지를 삭제하고 싶을 수 있다. 


이 때, kafka를 재시작 하기 전에 config/server.properties의 log.dirs의 파일들을 모두 지우고 재시작한다. 


# A comma seperated list of directories under which to store log files

log.dirs=/tmp/kafka-logs



재시작 스크립트는 아래와 같이 사용할 것이다. 


// stop

 rm -rf /tmp/kafka-logs

// start


Posted by '김용환'
,


fine grained transformation와 coarse grained transformation의 의미를 잘설명한 쿼라가 있어서 공유한다.



https://www.quora.com/What-is-the-difference-between-fine-grained-and-coarse-grained-transformation-in-context-of-Spark


If there is a dataset with a billion rows, A fine grained transaction is one applied on smaller set, may be a single row.

A coarse grained one is an operation applied on an entire dataset. 




코오스 그레인드 기법은 전체 데이터에 특정 오퍼레이션을 적용한 기법이며, time based 에서 자주 사용된다.


파인 그레인드 기법은 작은 집합에 적용되는 기법이며 한 엔티티당 기준으로 자주 사용된다.


'데이터 분석' 카테고리의 다른 글

apache zepplin 0.6.2 설치 - python, hive 연동  (0) 2016.10.22
Posted by '김용환'
,