处理spark数据帧中的数组[Byte]

时间:2018-04-25 19:26:19

标签: scala apache-spark hadoop

我有一个如下的数据帧df1 with schema:

scala> df1.printSchema
root
 |-- filecontent: binary (nullable = true)
 |-- filename: string (nullable = true)

DF有文件名及其内容。内容是GZIPped。我可以使用类似下面的内容解压缩filecontent中的数据并将其保存到HDFS。

def decompressor(origRow: Row) = {
    val filename = origRow.getString(1)
    val filecontent = serialise(origRow.getString(0))

    val unzippedData = new GZIPInputStream(new ByteArrayInputStream(filecontent))

    val hadoop_fs = FileSystem.get(sc.hadoopConfiguration)
    val filenamePath = new Path(filename)

    val fos = hadoop_fs.create(filenamePath)

    org.apache.hadoop.io.IOUtils.copyBytes(unzippedData, fos, sc.hadoopConfiguration)
    fos.close()
  } 

我的目标:

由于df1中的filecontent列数据是二进制的,即Array [byte],我不应该分配数据并将它们放在一起并将其传递给函数,以便它可以解压缩并将其保存到文件中。

我的问题:

  1. 如何不分发数据(列数据)?
  2. 如何确保一次处理1行?

0 个答案:

没有答案