代码之家  ›  专栏  ›  技术社区  ›  wipman

使用spark流从HDF中消耗大量xml

  •  0
  • wipman  · 技术社区  · 8 年前

    我是 listening hdfs 的目录 xml 带有 spark-streaming - textFileStream() . 问题是我的记录很大(而且只有一行);它们的大小可以接近1G。

    我愿意:

    val xmlStream = ssc.textFileStream(monitoredDirectory).map { ("",_) }
    

    我怎么能告诉spark不要分割我的文件?或者有其他方法来处理大型xml文件吗?

    2 回复  |  直到 8 年前
        1
  •  0
  •   CarloV    8 年前

    在我看来,流媒体并不是管理大文件的最佳解决方案。简单的方法是用简单的

    sc.textfile("newfileinthefolder", partition=1)
    

    另一个解决方案是管理StreamingContext的batchDuration,但我对此不太有信心。 在这种情况下,请注意流媒体产生的血统。 最后,看看 this ,databricks资源有时是最合适的解决方案

        2
  •  0
  •   wipman    8 年前

    具有 spark-xml ,如建议 gtosto公司 ,如下所示:

    import org.apache.hadoop.io.{LongWritable, Text}
    import com.databricks.spark.xml.XmlInputFormat
    
    val conf = sc.hadoopConfiguration
    conf.set(XmlInputFormat.START_TAG_KEY, "<xxx>")
    conf.set(XmlInputFormat.END_TAG_KEY, "</xxx>")
    org.apache.hadoop.fs.FileSystem.get(conf)
    
    val xml = ssc.fileStream[LongWritable,Text,XmlInputFormat](monitoredDirectory,true,false)