복붙노트

[HADOOP] Spark에서 NLineInputFormat이 작동하지 않습니다.

HADOOP

Spark에서 NLineInputFormat이 작동하지 않습니다.

내가 원한 것은 기본적으로 데이터의 각 요소를 10 개의 라인으로 구성하는 것입니다. 그러나 다음 코드에서는 각 요소가 여전히 한 줄입니다. 내가 여기서 실수하고있는거야?

val conf = new SparkConf().setAppName("MyApp")
conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
conf.registerKryoClasses(Array[Class[_]](classOf[NLineInputFormat], classOf[LongWritable], 
 classOf[Text]))
val sc = new SparkContext(conf)

val c = new Configuration(sc.hadoopConfiguration)
c.set("lineinputformat.linespermap", 10);
val data = sc.newAPIHadoopFile(fname, classOf[NLineInputFormat], classOf[LongWritable], 
 classOf[Text], c)

해결법

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

    1.NLineInputFormat은 의도 한대로 작업을 수행하지 않습니다.

    NLineInputFormat은 의도 한대로 작업을 수행하지 않습니다.

    보시다시피, 레코드가 결정되는 방식이 아니라 Spark 명명법의 분할 방식이 계산되는 방식을 수정합니다.

    설명이 명확하지 않으면 다음 예를 통해 설명 할 수 있습니다.

    def nline(n: Int, path: String) = {
      val sc = SparkContext.getOrCreate
      val conf = new Configuration(sc.hadoopConfiguration)
      conf.setInt("mapreduce.input.lineinputformat.linespermap", n);
    
      sc.newAPIHadoopFile(path,
        classOf[NLineInputFormat], classOf[LongWritable], classOf[Text], conf
      )
    }
    
    require(nline(1, "README.md").glom.map(_.size).first == 1)
    require(nline(2, "README.md").glom.map(_.size).first == 2)
    require(nline(3, "README.md").glom.map(_.size).first == 3)
    

    위의 각 파티션 (마지막 파티션 제외)은 정확히 n 개의 라인을 포함합니다.

    귀하의 케이스에 맞도록 이것을 개조 할 수는 있지만 linepermap 매개 변수의 작은 값에는 권장되지 않습니다.

  2. from https://stackoverflow.com/questions/40320325/nlineinputformat-not-working-in-spark by cc-by-sa and MIT license