Tuesday, July 22, 2014

Lighting a Spark With HBase Full Edition with real world examples ~ dependencies, classpaths, handling ByteArray in HBase KeyValue object

First of all, there are many resources in internet about integrating HBase and Spark

such as

Spark has their own example: https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/HBaseTest.scala

MapR has also some cool sample: http://www.mapr.com/developercentral/code/loading-hbase-tables-spark

and here, a more detailed code snippet: http://www.vidyasource.com/blog/Programming/Scala/Java/Data/Hadoop/Analytics/2014/01/25/lighting-a-spark-with-hbase

but all of them, has no information about:
  • which jar library are needed, let us say dependency problem
  • how should i set the classpath when i start my spark job/application with HBase connection
  • sc.newAPIHadoopRDD uses this holly class org.apache.hadoop.hbase.client.Result as a return value type, but objects in this Result are org.apache.hadoop.hbase.KeyValue, this is a core client-side Java API of HBase, sometimes it is really not enough to use it just with getColumn("columnFamily".getBytes(), "columnQualifier".getBytes()), and more important is, in scala, to use this KeyValue object is even more complicated.
therefore this post aims to create a "Full" Version...

assume you have already read the samples above. i will go ahead directly to solve this three problems.

if you only want to see some code, jump to the next part of this doc: http://www.abcn.net/2014/07/spark-hbase-result-keyvalue-bytearray.html

1. dependency problem

it is similar as a HBase client program

for maven:

<dependency>
        <groupid>org.apache.spark</groupid>
        <artifactid>spark-core_2.10</artifactid>
        <version>1.0.1</version>
</dependency>

<dependency>
        <groupid>org.apache.hbase</groupid>
        <artifactid>hbase</artifactid>
        <version>0.98.2-hadoop2</version>
</dependency>

<dependency>
        <groupid>org.apache.hbase</groupid>
        <artifactid>hbase-client</artifactid>
        <version>0.98.2-hadoop2</version>
</dependency>

<dependency>
        <groupid>org.apache.hbase</groupid>
        <artifactid>hbase-common</artifactid>
        <version>0.98.2-hadoop2</version>
</dependency>

<dependency>
        <groupid>org.apache.hbase</groupid>
        <artifactid>hbase-server</artifactid>
        <version>0.98.2-hadoop2</version>
</dependency>

sbt:

libraryDependencies ++= Seq(
        "org.apache.spark" % "spark-core_2.10" % "1.0.1",
        "org.apache.hbase" % "hbase" % "0.98.2-hadoop2",
        "org.apache.hbase" % "hbase-client" % "0.98.2-hadoop2",
        "org.apache.hbase" % "hbase-common" % "0.98.2-hadoop2",
        "org.apache.hbase" % "hbase-server" % "0.98.2-hadoop2"
)

change the version of spark and hbase to yours.

2. classpath

in the time of Spark 0.9.x, you just need to set this environment: SPARK_CLASSPATH with HBase's Jars, for example, start spark-shell with local mode, in CDH5 Hadoop distribution:
export SPARK_CLASSPATH=/opt/cloudera/parcels/CDH/lib/hbase/hbase-server.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-protocol.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-hadoop2-compat.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-client.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-common.jar:/opt/cloudera/parcels/CDH/lib/hbase/lib/htrace-core.jar
and then
./bin/spark-shell --master local[2]
or just
SPARK_CLASSPATH=/opt/cloudera/parcels/CDH/lib/hbase/hbase-server.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-protocol.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-hadoop2-compat.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-client.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-common.jar:/opt/cloudera/parcels/CDH/lib/hbase/lib/htrace-core.jar ./bin/spark-shell --master local[2]

in your cluster, you should change the path of those jars to your HBase's path, such as in other Hadoop distribution should be some path like /usr/lib/xxx (Hortonworks HDP) or /opt/mapr/hbase-xxx (MapR)

but, but... this lovely SPARK_CLASSPATH is deprecated in the new era of Spark 1.x  !!! -_-

so, in Spark 1.x

there is one conf property and one command line augment for this:
spark.executor.extraClassPath
and
--driver-class-path

WTF... but, yes, you must give the whole jar paths twice!... and spark.executor.extraClassPath must be set in a conf file, can not be set via command line...

so, you need to do this:

edit conf/spark-defaults.conf

add this:
spark.executor.extraClassPath  /opt/cloudera/parcels/CDH/lib/hive/lib/hive-hbase-handler.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-server.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-protocol.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-hadoop2-compat.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-client.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-common.jar:/opt/cloudera/parcels/CDH/lib/hbase/lib/htrace-core.jar
and then, start spark shell or submit your spark job with command line args for driver --driver-class-path:
./bin/spark-shell --master local[2]  --driver-class-path  /opt/cloudera/parcels/CDH/lib/hbase/hbase-server.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-protocol.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-hadoop2-compat.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-client.jar:/opt/cloudera/parcels/CDH/lib/hbase/hbase-common.jar:/opt/cloudera/parcels/CDH/lib/hbase/lib/htrace-core.jar
unbelievable, but it is so in spark 1.x ...

3. how to use org.apache.hadoop.hbase.KeyValue in scala with Spark

it seems this post is already long enough, let us take a break, to see the code of real world examples, you can go to the next part of this doc: http://www.abcn.net/2014/07/spark-hbase-result-keyvalue-bytearray.html

87 comments:

  1. Thanks
    Great article...

    ReplyDelete
  2. This is what I want to know. Thanks!

    ReplyDelete
  3. These are only a few ideas and there are lots more available online. I hope I've given you some inspiration on what you can do to make your Halloween party a spooky success. Bath mirror lamps

    ReplyDelete
  4. This is really very nice post you shared, i like the post, thanks for sharing..

    Data Science Course

    ReplyDelete
  5. Very awesome!!! When I seek for this I found this website at the top of all blogs in search engine.

    Data Science Training

    ReplyDelete
  6. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
    Data Science Training Institute in Bangalore

    ReplyDelete
  7. wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.
    Data Science Training in Bangalore

    ReplyDelete
  8. Never too late to start learning at Salesforce Training in Australia even though you don't have any programming knowledge you can excell in Salesforce Training in London United Kingdom (UK) because it is all about your customers, so this time find the best Salesforce Training in Europe. This way we will learn Salesforce CRM.

    ReplyDelete
  9. Myself so glad to establish your blog entry since it's actually quite instructive. If it's not too much trouble continue composing this sort of web journal and I normally visit this blog. Examine my administrations.  
    Read these Salesforce Admin Certification Topics which are really helpful. I read these Salesforce Admin and Developer Certification Dumps and very much useful for me. 

    ReplyDelete
  10. I'd love to thank you for the efforts you've made in composing this post. I hope the same best work out of you later on too. I wished to thank you with this particular sites! Thank you for sharing. Fantastic sites!
    360DigiTMG Data Science Course in Bangalore

    ReplyDelete
  11. This is a great post. This post gives a truly quality information. I am certainly going to look into it. Really very helpful tips are supplied here. Thank you so much. Keep up the great works
    360DigiTMG Data Science Training in Bangalore

    ReplyDelete
  12. Get real time project based and job oriented Salesforce training India course materials for Salesforce Certification with securing a practice org, database terminology, admin and user interface navigation and custom fields creation, reports & analytics, security, customization, automation and web to lead forms.  

    ReplyDelete
  13. I see some amazingly important and kept up to length of your strength searching for in your on the sitedata science course

    ReplyDelete

  14. I'm really thankful that I read this. It's extremely valuable and quite informative and I truly learned a great deal from it.
    360DigiTMG Data Science Training Institute in Bangalore

    ReplyDelete
  15. Additionally, this is an excellent article which I truly like studying. It's not everyday I have the option to see something similar to this.
    Data Science Course In Bangalore With Placement

    ReplyDelete
  16. This is a great post I saw thanks to sharing. I really want to hope that you will continue to share great posts in the future.
    artificial intelligence course in noida

    ReplyDelete
  17. If you don't mind, then continue this excellent work and expect more from your great blog posts
    hrdf training course

    ReplyDelete
  18. I was looking at a portion of your posts on this site and I consider this site is really enlightening! Keep setting up..
    360DigiTMG supply chain analytics using r

    ReplyDelete
  19. I feel extremely glad to have seen your site page and anticipate such a large number of additionally engaging occasions perusing here. Much obliged again for all the subtleties.
    hrdf scheme

    ReplyDelete
  20. Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you!
    business analytics course

    ReplyDelete
  21. Many sales managers tell me that their salespeople don't meet their expectations. The sales manager pleads, begs and even threatens, but the salesperson just goes through the motions of selling and following through on proposals and sales calls. Salesforce training in Chennai

    ReplyDelete

  22. Thank you quite much for discussing this type of helpful informative article. Will certainly stored and reevaluate your Website.

    Cyber Security Course In Bangalore

    ReplyDelete
  23. Excellent blog thanks for sharing the valuable information..it becomes easy to read and easily understand the information.
    Useful article which was very helpful. also interesting and contains good information.
    to know about python training course , use the below link.

    Python Training in chennai

    Python Course in chennai

    ReplyDelete
  24. This post is very simple to read and appreciate without leaving any details out. Great work!
    data scientist courses in gurgaon

    ReplyDelete
  25. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.I want to share aboutdata analytics courses in yelahanka

    ReplyDelete
  26. Wonderful post. Thanks for taking time to share this information with us.
    Primavera course in Chennai | Primavera p6 training online

    ReplyDelete
  27. My spouse and I stumbled over here by a different web page and thought I should check things out. usamagazine writersevoke pathofex oftenit dsnews I like what I see so i am just following you. Look forward to looking over your web page yet again.

    ReplyDelete
  28. i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
    data science courses in hyderabad

    ReplyDelete
  29. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    Data Science Training in Bangalore

    ReplyDelete
  30. I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
    data analytics training in bangalore

    ReplyDelete
  31. I read your article it is very interesting and every concept is very clear, thank you so much for sharing. AWS Certification Course in Chennai


    ReplyDelete
  32. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    Data Science Course in Bangalore

    ReplyDelete
  33. It is amazing and wonderful to see your blog. Thanks for sharing this information, this is useful to me.
    Data Science Training in Hyderabad
    Data Science Course in Hyderabad

    ReplyDelete
  34. หาคุณกำลังหาเกมส์ออนไลน์ที่สามารถสร้างรายได้ให้กับคุณ เรามีเกมส์แนะนำ เกมยิงปลา รูปแบบใหม่เล่นง่ายบนมือถือ คาสิโนออนไลน์ บนคอม เล่นได้ทุกอุปกรณ์รองรับทุกเครื่องมือ มีให้เลือกเล่นหลายเกมส์ เล่นได้ทั่วโลกเพราะนี้คือเกมส์ออนไลน์แบบใหม่ เกมยิงปลา

    ReplyDelete
  35. Online football betting ufabet will definitely get the price of water more than anywhere else. When compared with other companies such as other water 1.90, we water 1.94 or more, depending on the pair. We guarantee the price of 4 sets of football betting with us, starting with a minimum of only 10 baht, because our website has no minimum deposit with an automatic system

    ReplyDelete
  36. Online slots (Slot Online) may be the release of a gambling machine. Slot computer As stated before Used to produce electrical games known as online slots, on account of the development era, folks have looked to gamble through computer systems. Will achieve slot video games making internet gambling video games Via the world wide web network device Which players can have fun with through the slot plan or will have fun with Slots with the system provider's site Which internet slots games are actually available within the kind of participating in guidelines. It's similar to participating in on a slot machine. The two practical photos as well as sounds are equally thrilling since they go to lounge in the casino on the globe.บาคาร่า
    ufa
    ufabet
    แทงบอล
    แทงบอล
    แทงบอล

    ReplyDelete
  37. I just found this blog and have high hopes for it to continue. Keep up the great work, its hard to find good ones. I have added to my favorites. Thank You.
    best data science online course

    ReplyDelete
  38. Wow, happy to see this awesome post. I hope this think help any newbie for their awesome work and by the way thanks for share this awesomeness, i thought this was a pretty interesting read when it comes to this topic. Thank you..

    Data Science Training in Hyderabad

    ReplyDelete
  39. Very awesome!!! When I seek for this I found this website at the top of all blogs in search engine.
    data science training in malaysia

    ReplyDelete
  40. I am impressed by the information that you have on this blog. It shows how well you understand this subject.
    data scientist training in malaysia

    ReplyDelete
  41. Your work is very good and I appreciate you and hopping for some more informative posts
    data science training

    ReplyDelete
  42. I am impressed by the information that you have on this blog. It shows how well you understand this subject.
    data science course


    ReplyDelete
  43. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    data science course

    ReplyDelete
  44. This post is very simple to read and appreciate without leaving any details out. Great work!
    data scientist course in aurangabad

    ReplyDelete
  45. That's why we also keep improving our safety management skills to counter the top security companies in London
    new threats our clients may face. The number of times leading media outlets refer to us as experts in security matters is a clear testimony that we are a highly effective and
    innovative service provider that does a better job than any other security company in London.

    ReplyDelete
  46. Thanks for the informative and helpful post, obviously in your blog everything is good..
    data science course in malaysia

    ReplyDelete
  47. Please share this more. Thanks for sharing useful information and don't forget to share useful information.If you are flying to your destination and transiting through Turkey, you will need to obtain a Visa Transit Turkey. This visa allows you to travel through Turkey.

    ReplyDelete
  48. This is a wonderful inspiring article. I am practically satisfied with your great work. You have really put together extremely helpful data. Keep it up.. Are you planning to visit Kenya?For this, you need to fill the Kenya evisa application and pay the fee online.

    ReplyDelete
  49. Nice info..... South Africa e Visa to be launched in 2022 you can read all info related to South Africa e Visa 2022 via South Africa e visa website.

    ReplyDelete
  50. What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up.
    data science course

    ReplyDelete
  51. Hello! I thought I had been to this site before, but after looking through some of the posts, I realized it was new to me. Anyway, I'm glad I found it and I'll definitely be bookmarking it and checking back often. How to apply for Indian visa? Yes you can apply for an online visa for India through the India electronic visa website.

    ReplyDelete
  52. Hi! I thought I had been to this site before, but after looking through some of the posts, I realized it was new to me. Anyway, I'm glad I found it and I'll definitely be bookmarking it and checking back often. How to apply for Indian visa? Yes you can apply for an online visa for India via the India electronic visa portal.

    ReplyDelete
  53. Good article. I enjoyed reading your articles. This can be really a good scan for me. Wanting forward to reading new articles. Maintain the nice work!
    Servicenow Training In Hyderabad

    ReplyDelete
  54. Thanks for your great article which is both informative and innovative: with the latest updates. It was highly invaluable. Travelers can apply India tourist visa for US citizens directly for e-visas online. Therefore, the Indian government has developed an easy-to-use online Indian visa application form that makes it easy to apply for a visa.

    ReplyDelete
  55. Thanks for your post. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks.
    cyber security course malaysia

    ReplyDelete
  56. Good afternoon guys, Nice blog. Thanks for sharing. Do you know how to apply India visa online application? You can apply for India Visa Online. You can read all the details on our Indian Visa Blog. All information available here..

    ReplyDelete
  57. Very happy to find a good place for many here in the post, the writing is just great, thanks for the post.
    Software Testing Tools Training in Hyderabad

    ReplyDelete

  58. Hello sir, thanks for the amazing post. Planning a holiday in India. Is Indian e visa open ,yes India visa open you can now apply for India visa online.

    ReplyDelete
  59. Mule masters Hyderabad,provides 100% job assistance, extending real time projects for practical knowledge this is best course you have interest visit my website link https://mulemasters.in/

    ReplyDelete
  60. Hey guys! Amazing post! Many people ask, How to apply for a Turkey e visa? Citizens of eligible countries are allowed to apply and obtain a Turkey evisa after the submission of an online application. Eligible travelers only need a good internet connection and a computer, laptop or tablet to complete and submit a visa application

    ReplyDelete
  61. This comment has been removed by the author.

    ReplyDelete
  62. our Portal Provided Punjab 11th Class Revised new Syllabus 2022 So, the Students can Download the as early as possible without late. So, the Students have Less Time for Exam Preparation. But These Much of time is Enough for Exam Preparation. Punjab 11th Class Syllabus Punjab 11th Syllabus 2022 Subject wise will be available at Official Website. Students Those who are Going to Appear Public Exam march 2022 can Download Punjab 11th Syllabus 2022 Subject wise important Question pdf Format Download.

    ReplyDelete
  63. I found so much interesting stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here to keep up the good work. Travelers who want to travel to Turkey. They need a Turkey evisa which is designed for tourism purposes.

    ReplyDelete
  64. NCERT Exam Question Papers are Strictly Based on the Syllabus issued by NCERT Board so, before Starting Preparation of NCERT Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Examination 2023 one Must need to go Through the Complete NCERT Syllabus of Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 of all the Subjects. Students of NCERT Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 can Check other Important Articles for Board Exam Preparation. NCERT 7th Class Revised Syllabus Students need to go Through Updated NCERT Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Syllabus 2023, Students are also Advised to official site of NCERT d to get new NCERT Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 new Syllabus 2023.

    ReplyDelete
  65. First class data, modify everybody mind basically reference designate assistance to it. I could be placed in a larger invincible state. XXClone Make Bootable

    ReplyDelete
  66. First class data, modify everybody mind basically reference designate assistance to it. I could be placed in a larger invincible state. XXClone 2022 x64 Download

    ReplyDelete
  67. First class data, modify everybody mind basically reference designate assistance to it. I could be placed in a larger invincible state. https://cyberspc.com/xxclone-pro-crack/

    ReplyDelete
  68. Your article is easy to read and understand. I would like to read more articles like this. Getting an evisa Turkey online is a hassle free process. It saves time and money as well.

    ReplyDelete
  69. These are the perfect birthday quotes for brother from sister, and so fun to share. 1. Happy birthday, bro .Happy Birthday Wishes For My Brother

    ReplyDelete
  70. Nice thanks for sharing informative post like this keep posting if like more details visit my website linkhttps://azuretrainings.in/azure-devops/

    ReplyDelete
  71. This comment has been removed by the author.

    ReplyDelete
  72. The best facility for every prepaid mobile customer is online recharge to feel proud for managing recharges from own hands with new offers provided by Bharat Sanchar Nigam Limited. This may possible through a new website call as BSNL Quick Recharge Portal or with My BSNL App. BSNL Online Recharge This is one of the best service to avail Full Talktime Top Up, STV’s or any latest prepaid mobile plan recharges online. It is like an instant service, but from anywhere on just log in to BSNL Recharge Portal.

    ReplyDelete

© Chutium / Teng Qiu @ ABC Netz Group