1

I have data in the form of Array[Byte] which I want to convert into Spark RDD or DataFrame so that I can write my data directly into a Google bucket in the form of a file. I am not able to write Array[Byte] data into Google bucket directly. So looking for this conversion.

My below code is able to write data into Local FS, but not Google bucket

val encrypted = encrypt(original, readPublicKey(pubKey), outFile, true, true)
val dfis = new FileOutputStream(outFile)
dfis.write(encrypted)
dfis.close()

def encrypt(clearData: Array[Byte], encKey: PGPPublicKey, fileName: String, withIntegrityCheck: Boolean, armor: Boolean): Array[Byte] = {
...
}

So how can I convert Array[Byte] data to RDD or DataFrame? I am using Scala.

1 Answer 1

2

just use .toDF() or .toDF().rdd

scala> val arr: Array[Byte] = Array(192.toByte, 168.toByte, 1.toByte, 4.toByte)
arr: Array[Byte] = Array(-64, -88, 1, 4)

scala> val df = arr.toSeq.toDF()
df: org.apache.spark.sql.DataFrame = [value: tinyint]

scala> df.show()
+-----+
|value|
+-----+
|  -64|
|  -88|
|    1|
|    4|
+-----+


scala> df.printSchema()
root
 |-- value: byte (nullable = false)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for your input.scala> val arr: Array[Byte] = Array(192.toByte, 168.toByte, 1.toByte, 4.toByte) arr: Array[Byte] = Array(-64, -88, 1, 4) scala> val df = arr.toSeq.toDF() <console>:19: error: value toDF is not a member of Seq[Byte] val df = arr.toSeq.toDF() ^ When tried on my env facing this issue. Any idea how can I get rid of this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.