unable to create dataframe from sequence file in Spark created by Sqoop









up vote
1
down vote

favorite
1












I want to read orders data and create RDD out of it which is stored as sequence file in hadoop fs in cloudera vm. Below are my steps:



1) Importing orders data as sequence file:



sqoop import --connect jdbc:mysql://localhost/retail_db --username retail_dba --password cloudera --table orders -m 1 --target-dir /ordersDataSet --as-sequencefile 


2) Reading file in spark scala:



Spark 1.6



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec => rec.toString()) 


3) When I try to read data from above RDD it throws below error:



Caused by: java.io.IOException: WritableName can't load class: orders
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:77)
at org.apache.hadoop.io.SequenceFile$Reader.getValueClass(SequenceFile.java:2108)
... 17 more
Caused by: java.lang.ClassNotFoundException: Class orders not found
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2185)
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:75)
... 18 more


I don't know why it says that it can't find orders. Where am I going wrong ?



I referred codes from these two links as well but no luck:

1) Refer sequence part

2) Refer step no. 8










share|improve this question























  • scala> import org.apache.hadoop.io.Text scala> import org.apache.hadoop.io.IntWritable Please import these and try. Basic syntax is: scala> val result = sc.sequenceFile("/filepath/filename", classOf[Text], classOf[IntWritable]). mapcase (x, y) => (x.toString, y.get())
    – KP M
    9 hours ago











  • Do you have to use Sqoop? Why not use SparkSQL JDBC?
    – cricket_007
    6 hours ago










  • How can it be achieved ?
    – RushHour
    5 hours ago















up vote
1
down vote

favorite
1












I want to read orders data and create RDD out of it which is stored as sequence file in hadoop fs in cloudera vm. Below are my steps:



1) Importing orders data as sequence file:



sqoop import --connect jdbc:mysql://localhost/retail_db --username retail_dba --password cloudera --table orders -m 1 --target-dir /ordersDataSet --as-sequencefile 


2) Reading file in spark scala:



Spark 1.6



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec => rec.toString()) 


3) When I try to read data from above RDD it throws below error:



Caused by: java.io.IOException: WritableName can't load class: orders
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:77)
at org.apache.hadoop.io.SequenceFile$Reader.getValueClass(SequenceFile.java:2108)
... 17 more
Caused by: java.lang.ClassNotFoundException: Class orders not found
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2185)
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:75)
... 18 more


I don't know why it says that it can't find orders. Where am I going wrong ?



I referred codes from these two links as well but no luck:

1) Refer sequence part

2) Refer step no. 8










share|improve this question























  • scala> import org.apache.hadoop.io.Text scala> import org.apache.hadoop.io.IntWritable Please import these and try. Basic syntax is: scala> val result = sc.sequenceFile("/filepath/filename", classOf[Text], classOf[IntWritable]). mapcase (x, y) => (x.toString, y.get())
    – KP M
    9 hours ago











  • Do you have to use Sqoop? Why not use SparkSQL JDBC?
    – cricket_007
    6 hours ago










  • How can it be achieved ?
    – RushHour
    5 hours ago













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I want to read orders data and create RDD out of it which is stored as sequence file in hadoop fs in cloudera vm. Below are my steps:



1) Importing orders data as sequence file:



sqoop import --connect jdbc:mysql://localhost/retail_db --username retail_dba --password cloudera --table orders -m 1 --target-dir /ordersDataSet --as-sequencefile 


2) Reading file in spark scala:



Spark 1.6



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec => rec.toString()) 


3) When I try to read data from above RDD it throws below error:



Caused by: java.io.IOException: WritableName can't load class: orders
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:77)
at org.apache.hadoop.io.SequenceFile$Reader.getValueClass(SequenceFile.java:2108)
... 17 more
Caused by: java.lang.ClassNotFoundException: Class orders not found
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2185)
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:75)
... 18 more


I don't know why it says that it can't find orders. Where am I going wrong ?



I referred codes from these two links as well but no luck:

1) Refer sequence part

2) Refer step no. 8










share|improve this question















I want to read orders data and create RDD out of it which is stored as sequence file in hadoop fs in cloudera vm. Below are my steps:



1) Importing orders data as sequence file:



sqoop import --connect jdbc:mysql://localhost/retail_db --username retail_dba --password cloudera --table orders -m 1 --target-dir /ordersDataSet --as-sequencefile 


2) Reading file in spark scala:



Spark 1.6



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec => rec.toString()) 


3) When I try to read data from above RDD it throws below error:



Caused by: java.io.IOException: WritableName can't load class: orders
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:77)
at org.apache.hadoop.io.SequenceFile$Reader.getValueClass(SequenceFile.java:2108)
... 17 more
Caused by: java.lang.ClassNotFoundException: Class orders not found
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2185)
at org.apache.hadoop.io.WritableName.getClass(WritableName.java:75)
... 18 more


I don't know why it says that it can't find orders. Where am I going wrong ?



I referred codes from these two links as well but no luck:

1) Refer sequence part

2) Refer step no. 8







scala apache-spark hadoop sqoop sequencefile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 hours ago









cricket_007

75.4k1042105




75.4k1042105










asked 11 hours ago









RushHour

778




778











  • scala> import org.apache.hadoop.io.Text scala> import org.apache.hadoop.io.IntWritable Please import these and try. Basic syntax is: scala> val result = sc.sequenceFile("/filepath/filename", classOf[Text], classOf[IntWritable]). mapcase (x, y) => (x.toString, y.get())
    – KP M
    9 hours ago











  • Do you have to use Sqoop? Why not use SparkSQL JDBC?
    – cricket_007
    6 hours ago










  • How can it be achieved ?
    – RushHour
    5 hours ago

















  • scala> import org.apache.hadoop.io.Text scala> import org.apache.hadoop.io.IntWritable Please import these and try. Basic syntax is: scala> val result = sc.sequenceFile("/filepath/filename", classOf[Text], classOf[IntWritable]). mapcase (x, y) => (x.toString, y.get())
    – KP M
    9 hours ago











  • Do you have to use Sqoop? Why not use SparkSQL JDBC?
    – cricket_007
    6 hours ago










  • How can it be achieved ?
    – RushHour
    5 hours ago
















scala> import org.apache.hadoop.io.Text scala> import org.apache.hadoop.io.IntWritable Please import these and try. Basic syntax is: scala> val result = sc.sequenceFile("/filepath/filename", classOf[Text], classOf[IntWritable]). mapcase (x, y) => (x.toString, y.get())
– KP M
9 hours ago





scala> import org.apache.hadoop.io.Text scala> import org.apache.hadoop.io.IntWritable Please import these and try. Basic syntax is: scala> val result = sc.sequenceFile("/filepath/filename", classOf[Text], classOf[IntWritable]). mapcase (x, y) => (x.toString, y.get())
– KP M
9 hours ago













Do you have to use Sqoop? Why not use SparkSQL JDBC?
– cricket_007
6 hours ago




Do you have to use Sqoop? Why not use SparkSQL JDBC?
– cricket_007
6 hours ago












How can it be achieved ?
– RushHour
5 hours ago





How can it be achieved ?
– RushHour
5 hours ago













2 Answers
2






active

oldest

votes

















up vote
1
down vote













The sqoop has little to do with it, here is an example of a more realistic scenario, whereby saveAsSequenceFile always assumes k, v pairs - this may help you:



import org.apache.hadoop.io._

val RDD = sc.parallelize( List( (1, List("A", "B")) , (2, List("B", "C")) , (3, List("C", "D", "E")) ) )
val RDD2 = RDD.map(x => (x._1, x._2.mkString("/")))
RDD2.saveAsSequenceFile("/rushhour/seq-directory/2")

val sequence_data = sc.sequenceFile("/rushhour/seq-directory/*", classOf[IntWritable], classOf[Text])
.mapcase (x, y) => (x.get(), y.toString().split("/")(0), y.toString().split("/")(1))

sequence_data.collect


returns:



res20: Array[(Int, String, String)] = Array((1,A,B), (2,B,C), (3,C,D), (1,A,B), (2,B,C), (3,C,D))


I am not sure if you want an RDD or DF, but converting RDD to DF is of course trivial.






share|improve this answer




















  • In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
    – RushHour
    4 hours ago










  • You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
    – thebluephantom
    4 hours ago

















up vote
0
down vote













I figured out the solution to my own problem. Well, I am going to write a lengthy solution but I hope it will make some sense.



1) When I tried to read the data which was imported in HDFS using SQOOP, it gives an error because of following reasons:



A) Sequence file is all about key-value pair. So when I import it using sqoop, the data which is imported it is not in key value pair that is why while reading it throws an error.

B) If you try to read few characters from which you can figure out the two classes required for passing as input while reading sequence file you ll get data as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/pa* | head -c 300
SEQ!org.apache.hadoop.io.LongWritableorders�;�M��c�K�����@���-OCLOSED@���PENDING_PAYMENT@���/COMPLETE@���"{CLOSED@���cat: Unable to write to output stream.


Above you can see only one class i.e org.apache.hadoop.io.LongWritable and when I pass this while reading the sequence data it throws an error which is mentioned in the post.



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.LongWritable],classOf[org.apache.hadoop.io.LongWritable]).map(rec => rec.toString()) 


I don't think that the B point is the main reason of that error but I am very much sure that A point is the real culprit of that error.



2) Below is the way how I solved my problem.



I imported data as avro data file in other destination using SQOOP. Then I created the dataframe from avro using below ways:



scala> import com.databricks.spark.avro._;
scala> val avroData=sqlContext.read.avro("path")


Now I created key-value pair and saved it as sequence file



avroData.map(p=>(p(0).toString,(p(0)+"t"+p(1)+"t"+p(2)+"t"+p(3)))).saveAsSequenceFile("/user/cloudera/problem5/sequence") 


Now when I try to read few characters of the above written file it gives me two classes which I need while reading the file as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/part-00000 | head -c 300
SEQorg.apache.hadoop.io.Textorg.apache.hadoop.io.Text^#%���8P���11 1374735600000 11599 CLOSED&2#2 1374735600000 256 PENDING_PAYMENT!33 1374735600000 12111 COMPLETE44 1374735600000 8827 CLOSED!55 1374735600000 11318 COMPLETE 66 1374cat: Unable to write to output stream.

scala> val sequenceData=sc.sequenceFile("/user/cloudera/problem5/sequence",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec=>rec.toString)
sequenceData: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[26] at map at <console>:30


Now when I try to print data it displays data as below:



scala> sequenceData.take(4).foreach(println)
(1,1 1374735600000 11599 CLOSED)
(2,2 1374735600000 256 PENDING_PAYMENT)
(3,3 1374735600000 12111 COMPLETE)
(4,4 1374735600000 8827 CLOSED)


Last but not the least, Thank you everyone for your much appreciated efforts. Cheers!!






share|improve this answer




















  • Same is the case for ORC type of data. It should be saved in key-value pair format
    – RushHour
    3 hours ago










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236922%2funable-to-create-dataframe-from-sequence-file-in-spark-created-by-sqoop%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













The sqoop has little to do with it, here is an example of a more realistic scenario, whereby saveAsSequenceFile always assumes k, v pairs - this may help you:



import org.apache.hadoop.io._

val RDD = sc.parallelize( List( (1, List("A", "B")) , (2, List("B", "C")) , (3, List("C", "D", "E")) ) )
val RDD2 = RDD.map(x => (x._1, x._2.mkString("/")))
RDD2.saveAsSequenceFile("/rushhour/seq-directory/2")

val sequence_data = sc.sequenceFile("/rushhour/seq-directory/*", classOf[IntWritable], classOf[Text])
.mapcase (x, y) => (x.get(), y.toString().split("/")(0), y.toString().split("/")(1))

sequence_data.collect


returns:



res20: Array[(Int, String, String)] = Array((1,A,B), (2,B,C), (3,C,D), (1,A,B), (2,B,C), (3,C,D))


I am not sure if you want an RDD or DF, but converting RDD to DF is of course trivial.






share|improve this answer




















  • In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
    – RushHour
    4 hours ago










  • You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
    – thebluephantom
    4 hours ago














up vote
1
down vote













The sqoop has little to do with it, here is an example of a more realistic scenario, whereby saveAsSequenceFile always assumes k, v pairs - this may help you:



import org.apache.hadoop.io._

val RDD = sc.parallelize( List( (1, List("A", "B")) , (2, List("B", "C")) , (3, List("C", "D", "E")) ) )
val RDD2 = RDD.map(x => (x._1, x._2.mkString("/")))
RDD2.saveAsSequenceFile("/rushhour/seq-directory/2")

val sequence_data = sc.sequenceFile("/rushhour/seq-directory/*", classOf[IntWritable], classOf[Text])
.mapcase (x, y) => (x.get(), y.toString().split("/")(0), y.toString().split("/")(1))

sequence_data.collect


returns:



res20: Array[(Int, String, String)] = Array((1,A,B), (2,B,C), (3,C,D), (1,A,B), (2,B,C), (3,C,D))


I am not sure if you want an RDD or DF, but converting RDD to DF is of course trivial.






share|improve this answer




















  • In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
    – RushHour
    4 hours ago










  • You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
    – thebluephantom
    4 hours ago












up vote
1
down vote










up vote
1
down vote









The sqoop has little to do with it, here is an example of a more realistic scenario, whereby saveAsSequenceFile always assumes k, v pairs - this may help you:



import org.apache.hadoop.io._

val RDD = sc.parallelize( List( (1, List("A", "B")) , (2, List("B", "C")) , (3, List("C", "D", "E")) ) )
val RDD2 = RDD.map(x => (x._1, x._2.mkString("/")))
RDD2.saveAsSequenceFile("/rushhour/seq-directory/2")

val sequence_data = sc.sequenceFile("/rushhour/seq-directory/*", classOf[IntWritable], classOf[Text])
.mapcase (x, y) => (x.get(), y.toString().split("/")(0), y.toString().split("/")(1))

sequence_data.collect


returns:



res20: Array[(Int, String, String)] = Array((1,A,B), (2,B,C), (3,C,D), (1,A,B), (2,B,C), (3,C,D))


I am not sure if you want an RDD or DF, but converting RDD to DF is of course trivial.






share|improve this answer












The sqoop has little to do with it, here is an example of a more realistic scenario, whereby saveAsSequenceFile always assumes k, v pairs - this may help you:



import org.apache.hadoop.io._

val RDD = sc.parallelize( List( (1, List("A", "B")) , (2, List("B", "C")) , (3, List("C", "D", "E")) ) )
val RDD2 = RDD.map(x => (x._1, x._2.mkString("/")))
RDD2.saveAsSequenceFile("/rushhour/seq-directory/2")

val sequence_data = sc.sequenceFile("/rushhour/seq-directory/*", classOf[IntWritable], classOf[Text])
.mapcase (x, y) => (x.get(), y.toString().split("/")(0), y.toString().split("/")(1))

sequence_data.collect


returns:



res20: Array[(Int, String, String)] = Array((1,A,B), (2,B,C), (3,C,D), (1,A,B), (2,B,C), (3,C,D))


I am not sure if you want an RDD or DF, but converting RDD to DF is of course trivial.







share|improve this answer












share|improve this answer



share|improve this answer










answered 5 hours ago









thebluephantom

1,9682822




1,9682822











  • In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
    – RushHour
    4 hours ago










  • You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
    – thebluephantom
    4 hours ago
















  • In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
    – RushHour
    4 hours ago










  • You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
    – thebluephantom
    4 hours ago















In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
– RushHour
4 hours ago




In orders table i have four columns. Then how can i modify your code. Can you please do it for me ?
– RushHour
4 hours ago












You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
– thebluephantom
4 hours ago




You needto provide definition and it may well be comna delimited. Not so hard really. I gave a more realistic example
– thebluephantom
4 hours ago












up vote
0
down vote













I figured out the solution to my own problem. Well, I am going to write a lengthy solution but I hope it will make some sense.



1) When I tried to read the data which was imported in HDFS using SQOOP, it gives an error because of following reasons:



A) Sequence file is all about key-value pair. So when I import it using sqoop, the data which is imported it is not in key value pair that is why while reading it throws an error.

B) If you try to read few characters from which you can figure out the two classes required for passing as input while reading sequence file you ll get data as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/pa* | head -c 300
SEQ!org.apache.hadoop.io.LongWritableorders�;�M��c�K�����@���-OCLOSED@���PENDING_PAYMENT@���/COMPLETE@���"{CLOSED@���cat: Unable to write to output stream.


Above you can see only one class i.e org.apache.hadoop.io.LongWritable and when I pass this while reading the sequence data it throws an error which is mentioned in the post.



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.LongWritable],classOf[org.apache.hadoop.io.LongWritable]).map(rec => rec.toString()) 


I don't think that the B point is the main reason of that error but I am very much sure that A point is the real culprit of that error.



2) Below is the way how I solved my problem.



I imported data as avro data file in other destination using SQOOP. Then I created the dataframe from avro using below ways:



scala> import com.databricks.spark.avro._;
scala> val avroData=sqlContext.read.avro("path")


Now I created key-value pair and saved it as sequence file



avroData.map(p=>(p(0).toString,(p(0)+"t"+p(1)+"t"+p(2)+"t"+p(3)))).saveAsSequenceFile("/user/cloudera/problem5/sequence") 


Now when I try to read few characters of the above written file it gives me two classes which I need while reading the file as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/part-00000 | head -c 300
SEQorg.apache.hadoop.io.Textorg.apache.hadoop.io.Text^#%���8P���11 1374735600000 11599 CLOSED&2#2 1374735600000 256 PENDING_PAYMENT!33 1374735600000 12111 COMPLETE44 1374735600000 8827 CLOSED!55 1374735600000 11318 COMPLETE 66 1374cat: Unable to write to output stream.

scala> val sequenceData=sc.sequenceFile("/user/cloudera/problem5/sequence",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec=>rec.toString)
sequenceData: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[26] at map at <console>:30


Now when I try to print data it displays data as below:



scala> sequenceData.take(4).foreach(println)
(1,1 1374735600000 11599 CLOSED)
(2,2 1374735600000 256 PENDING_PAYMENT)
(3,3 1374735600000 12111 COMPLETE)
(4,4 1374735600000 8827 CLOSED)


Last but not the least, Thank you everyone for your much appreciated efforts. Cheers!!






share|improve this answer




















  • Same is the case for ORC type of data. It should be saved in key-value pair format
    – RushHour
    3 hours ago














up vote
0
down vote













I figured out the solution to my own problem. Well, I am going to write a lengthy solution but I hope it will make some sense.



1) When I tried to read the data which was imported in HDFS using SQOOP, it gives an error because of following reasons:



A) Sequence file is all about key-value pair. So when I import it using sqoop, the data which is imported it is not in key value pair that is why while reading it throws an error.

B) If you try to read few characters from which you can figure out the two classes required for passing as input while reading sequence file you ll get data as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/pa* | head -c 300
SEQ!org.apache.hadoop.io.LongWritableorders�;�M��c�K�����@���-OCLOSED@���PENDING_PAYMENT@���/COMPLETE@���"{CLOSED@���cat: Unable to write to output stream.


Above you can see only one class i.e org.apache.hadoop.io.LongWritable and when I pass this while reading the sequence data it throws an error which is mentioned in the post.



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.LongWritable],classOf[org.apache.hadoop.io.LongWritable]).map(rec => rec.toString()) 


I don't think that the B point is the main reason of that error but I am very much sure that A point is the real culprit of that error.



2) Below is the way how I solved my problem.



I imported data as avro data file in other destination using SQOOP. Then I created the dataframe from avro using below ways:



scala> import com.databricks.spark.avro._;
scala> val avroData=sqlContext.read.avro("path")


Now I created key-value pair and saved it as sequence file



avroData.map(p=>(p(0).toString,(p(0)+"t"+p(1)+"t"+p(2)+"t"+p(3)))).saveAsSequenceFile("/user/cloudera/problem5/sequence") 


Now when I try to read few characters of the above written file it gives me two classes which I need while reading the file as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/part-00000 | head -c 300
SEQorg.apache.hadoop.io.Textorg.apache.hadoop.io.Text^#%���8P���11 1374735600000 11599 CLOSED&2#2 1374735600000 256 PENDING_PAYMENT!33 1374735600000 12111 COMPLETE44 1374735600000 8827 CLOSED!55 1374735600000 11318 COMPLETE 66 1374cat: Unable to write to output stream.

scala> val sequenceData=sc.sequenceFile("/user/cloudera/problem5/sequence",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec=>rec.toString)
sequenceData: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[26] at map at <console>:30


Now when I try to print data it displays data as below:



scala> sequenceData.take(4).foreach(println)
(1,1 1374735600000 11599 CLOSED)
(2,2 1374735600000 256 PENDING_PAYMENT)
(3,3 1374735600000 12111 COMPLETE)
(4,4 1374735600000 8827 CLOSED)


Last but not the least, Thank you everyone for your much appreciated efforts. Cheers!!






share|improve this answer




















  • Same is the case for ORC type of data. It should be saved in key-value pair format
    – RushHour
    3 hours ago












up vote
0
down vote










up vote
0
down vote









I figured out the solution to my own problem. Well, I am going to write a lengthy solution but I hope it will make some sense.



1) When I tried to read the data which was imported in HDFS using SQOOP, it gives an error because of following reasons:



A) Sequence file is all about key-value pair. So when I import it using sqoop, the data which is imported it is not in key value pair that is why while reading it throws an error.

B) If you try to read few characters from which you can figure out the two classes required for passing as input while reading sequence file you ll get data as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/pa* | head -c 300
SEQ!org.apache.hadoop.io.LongWritableorders�;�M��c�K�����@���-OCLOSED@���PENDING_PAYMENT@���/COMPLETE@���"{CLOSED@���cat: Unable to write to output stream.


Above you can see only one class i.e org.apache.hadoop.io.LongWritable and when I pass this while reading the sequence data it throws an error which is mentioned in the post.



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.LongWritable],classOf[org.apache.hadoop.io.LongWritable]).map(rec => rec.toString()) 


I don't think that the B point is the main reason of that error but I am very much sure that A point is the real culprit of that error.



2) Below is the way how I solved my problem.



I imported data as avro data file in other destination using SQOOP. Then I created the dataframe from avro using below ways:



scala> import com.databricks.spark.avro._;
scala> val avroData=sqlContext.read.avro("path")


Now I created key-value pair and saved it as sequence file



avroData.map(p=>(p(0).toString,(p(0)+"t"+p(1)+"t"+p(2)+"t"+p(3)))).saveAsSequenceFile("/user/cloudera/problem5/sequence") 


Now when I try to read few characters of the above written file it gives me two classes which I need while reading the file as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/part-00000 | head -c 300
SEQorg.apache.hadoop.io.Textorg.apache.hadoop.io.Text^#%���8P���11 1374735600000 11599 CLOSED&2#2 1374735600000 256 PENDING_PAYMENT!33 1374735600000 12111 COMPLETE44 1374735600000 8827 CLOSED!55 1374735600000 11318 COMPLETE 66 1374cat: Unable to write to output stream.

scala> val sequenceData=sc.sequenceFile("/user/cloudera/problem5/sequence",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec=>rec.toString)
sequenceData: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[26] at map at <console>:30


Now when I try to print data it displays data as below:



scala> sequenceData.take(4).foreach(println)
(1,1 1374735600000 11599 CLOSED)
(2,2 1374735600000 256 PENDING_PAYMENT)
(3,3 1374735600000 12111 COMPLETE)
(4,4 1374735600000 8827 CLOSED)


Last but not the least, Thank you everyone for your much appreciated efforts. Cheers!!






share|improve this answer












I figured out the solution to my own problem. Well, I am going to write a lengthy solution but I hope it will make some sense.



1) When I tried to read the data which was imported in HDFS using SQOOP, it gives an error because of following reasons:



A) Sequence file is all about key-value pair. So when I import it using sqoop, the data which is imported it is not in key value pair that is why while reading it throws an error.

B) If you try to read few characters from which you can figure out the two classes required for passing as input while reading sequence file you ll get data as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/pa* | head -c 300
SEQ!org.apache.hadoop.io.LongWritableorders�;�M��c�K�����@���-OCLOSED@���PENDING_PAYMENT@���/COMPLETE@���"{CLOSED@���cat: Unable to write to output stream.


Above you can see only one class i.e org.apache.hadoop.io.LongWritable and when I pass this while reading the sequence data it throws an error which is mentioned in the post.



val sequenceData=sc.sequenceFile("/ordersDataSet",classOf[org.apache.hadoop.io.LongWritable],classOf[org.apache.hadoop.io.LongWritable]).map(rec => rec.toString()) 


I don't think that the B point is the main reason of that error but I am very much sure that A point is the real culprit of that error.



2) Below is the way how I solved my problem.



I imported data as avro data file in other destination using SQOOP. Then I created the dataframe from avro using below ways:



scala> import com.databricks.spark.avro._;
scala> val avroData=sqlContext.read.avro("path")


Now I created key-value pair and saved it as sequence file



avroData.map(p=>(p(0).toString,(p(0)+"t"+p(1)+"t"+p(2)+"t"+p(3)))).saveAsSequenceFile("/user/cloudera/problem5/sequence") 


Now when I try to read few characters of the above written file it gives me two classes which I need while reading the file as below:



[cloudera@quickstart ~]$ hadoop fs -cat /user/cloudera/problem5/sequence/part-00000 | head -c 300
SEQorg.apache.hadoop.io.Textorg.apache.hadoop.io.Text^#%���8P���11 1374735600000 11599 CLOSED&2#2 1374735600000 256 PENDING_PAYMENT!33 1374735600000 12111 COMPLETE44 1374735600000 8827 CLOSED!55 1374735600000 11318 COMPLETE 66 1374cat: Unable to write to output stream.

scala> val sequenceData=sc.sequenceFile("/user/cloudera/problem5/sequence",classOf[org.apache.hadoop.io.Text],classOf[org.apache.hadoop.io.Text]).map(rec=>rec.toString)
sequenceData: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[26] at map at <console>:30


Now when I try to print data it displays data as below:



scala> sequenceData.take(4).foreach(println)
(1,1 1374735600000 11599 CLOSED)
(2,2 1374735600000 256 PENDING_PAYMENT)
(3,3 1374735600000 12111 COMPLETE)
(4,4 1374735600000 8827 CLOSED)


Last but not the least, Thank you everyone for your much appreciated efforts. Cheers!!







share|improve this answer












share|improve this answer



share|improve this answer










answered 3 hours ago









RushHour

778




778











  • Same is the case for ORC type of data. It should be saved in key-value pair format
    – RushHour
    3 hours ago
















  • Same is the case for ORC type of data. It should be saved in key-value pair format
    – RushHour
    3 hours ago















Same is the case for ORC type of data. It should be saved in key-value pair format
– RushHour
3 hours ago




Same is the case for ORC type of data. It should be saved in key-value pair format
– RushHour
3 hours ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236922%2funable-to-create-dataframe-from-sequence-file-in-spark-created-by-sqoop%23new-answer', 'question_page');

);

Post as a guest














































































這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands