

{"id":20012,"date":"2018-06-27T14:23:15","date_gmt":"2018-06-27T14:23:15","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=20012"},"modified":"2018-06-27T14:23:15","modified_gmt":"2018-06-27T14:23:15","slug":"hcatalog-loader-and-storer","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/","title":{"rendered":"HCatalog Loader and Storer &#8211; Usage &amp; Example"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In our last <strong>HCatalog tutorial<\/strong>, we discussed <strong>HCatalog Commands<\/strong>. Today, we will see HCatalog Loader and Storer. Moreover, we will also discuss the examples of HCatalog loader and storer.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> Basically, to read and write data in HCatalog-managed tables, the HCatLoader and HCatStorer interfaces are used with Pig scripts.<\/span><\/p>\n<p>So, let&#8217;s learn both\u00a0HCatalog Loader\u00a0and Storer in detail:<\/p>\n<h2><span style=\"font-weight: 400\">HCatLoader<\/span><\/h2>\n<p><span style=\"font-weight: 400\">In order to read data from HCatalog-managed tables, we use HCatLoader with Pig scripts.<\/span><\/p>\n<h3>a. Usage<\/h3>\n<p><span style=\"font-weight: 400\">Via a Pig load statement, we can access HCatLoader. <\/span><\/p>\n<pre class=\"EnlighterJSRAW\">A = LOAD 'tablename' USING org.apache.hive.hcatalog.pig.HCatLoader();<\/pre>\n<h3>b. Assumptions<\/h3>\n<p><span style=\"font-weight: 400\">However, make sure the table name is specified in single quotes: LOAD &#8216;tablename&#8217;. Also, we must specify our input as &#8216;dbname.tablename&#8217;, if we are using a non-default database. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we must create our database and table prior to running the <strong>Pig script<\/strong>, if we are using Pig 0.9.2 or earlier. In addition, we can issue these create commands in <strong>Pig<\/strong> using the SQL command, beginning with Pig 0.10. \u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Furthermore, without specifying a database, the <strong>Hive <\/strong>metastore lets us create tables; however,\u00a0the database name is &#8216;default&#8217;, if\u00a0we create the tables this way.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Although, make sure we can indicate which partitions to scan by immediately following the load statement with a partition filter statement if the table is partitioned.<\/span><\/p>\n<h3>c. HCatLoader Data Types<\/h3>\n<p><span style=\"font-weight: 400\">Also, make sure HCatLoader can only read the <strong>Hive data types<\/strong>, such as:<\/span><\/p>\n<p><strong>Types in Hive 0.12.0 and Earlier<\/strong><br \/>\n1.\u00a0boolean<br \/>\n2. int<br \/>\n3. long<br \/>\n<span style=\"font-weight: 400\">4. float<\/span><br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">5. double<\/span><br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">6. string<\/span><br \/>\n7. binary<br \/>\nsome complex data types:<br \/>\n8. map \u2013 here key type\u00a0must be the string<br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">9. ARRAY&lt;any type&gt;<\/span><br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">10. struct&lt;any type fields&gt;<\/span><\/p>\n<p><strong>Types in Hive 0.13.0 and Later<\/strong><br \/>\n<span style=\"font-weight: 400\">11. tinyint<\/span><br \/>\n12. smallint<br \/>\n13. date<br \/>\n<span style=\"font-weight: 400\">14. timestamp<\/span><br \/>\n<span style=\"font-weight: 400\">15. decimal<\/span><br \/>\n<span style=\"font-weight: 400\">16. char(x)<\/span><br \/>\n<span style=\"font-weight: 400\">17. varchar(x)<\/span><\/p>\n<h2><span style=\"font-weight: 400\">HCatStorer <\/span><\/h2>\n<p><span style=\"font-weight: 400\">Further, in order to write data to HCatalog-managed tables, we use HCatStorer with Pig scripts.<\/span><\/p>\n<div id=\"attachment_20260\" style=\"width: 1090px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20260\" class=\"wp-image-20260 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer.png\" alt=\"HCatalog Loader and Storer\" width=\"1080\" height=\"1080\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer.png 1080w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer-300x300.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer-768x768.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer-1024x1024.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatStorer-100x100.png 100w\" sizes=\"auto, (max-width: 1080px) 100vw, 1080px\" \/><\/a><p id=\"caption-attachment-20260\" class=\"wp-caption-text\">HCatalog Loader and Storer<\/p><\/div>\n<h3>a. Usage<\/h3>\n<p><span style=\"font-weight: 400\">via a Pig store statement, we access HCatStorer.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">A = LOAD ...\nB = FOREACH A ...\n...\n...\nmy_processed_data = ...\nSTORE my_processed_data INTO 'tablename'\n  USING org.apache.hive.hcatalog.pig.HCatStorer();<\/pre>\n<h3>b. Assumptions<\/h3>\n<p><span style=\"font-weight: 400\">As similar as HCatStorer, here also table name must be in single quotes, like LOAD &#8216;tablename&#8217;. Moreover, to run script make sure that both the database and table must be created prior. Also, we must specify our input as &#8216;dbname.tablename&#8217;, if\u00a0we are using a non-default database. <\/span><\/p>\n<p><span style=\"font-weight: 400\">And,\u00a0we need to create our database and table prior to running the Pig script, if\u00a0we are using Pig 0.9.2 or earlier. Further,\u00a0we can issue these create commands in Pig using the SQL command, beginning with Pig 0.10.<\/span><\/p>\n<p><span style=\"font-weight: 400\">As the best feature, without even specifying a database, the <strong>Hive metastore<\/strong> lets\u00a0us create tables. So, after that, the database name is &#8216;default&#8217; if\u00a0we create tables this way, and also\u00a0there is no need to specify the database name in the store statement.<\/span><\/p>\n<h3>c. Store Examples<\/h3>\n<p><span style=\"font-weight: 400\">By using HCatStorer we can write to a non-partitioned table simply.\u00a0Also, the table contents will be overwritten:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">store z into 'web_data' using org.apache.hive.hcatalog.pig.HCatStorer();<\/pre>\n<p><span style=\"font-weight: 400\">In addition, specify the partition value in the store function, to add one new partition to a partitioned table. Make sure that the whole string should be single-quoted as well as separated with an equals sign:<\/span><br \/>\n<strong>store z into &#8216;web_data&#8217; using org.apache.hive.hcatalog.pig.HCatStorer(&#8216;datestamp=20110924&#8217;);<\/strong><br \/>\n<span style=\"font-weight: 400\">Ensure that the partition column is present in our data,\u00a0then only call HCatStorer with no argument, to write into multiple partitions at once:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">store z into 'web_data' using org.apache.hive.hcatalog.pig.HCatStorer();\n -- datestamp must be a field in the relation z<\/pre>\n<p>d. HCatStorer Data Types<\/p>\n<p><strong>Types in Hive 0.12.0 and Earlier<\/strong><br \/>\n1.\u00a0Boolean<br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">2. int<\/span><br \/>\n3. long<br \/>\n<span style=\"font-weight: 400\">4. float<\/span><br \/>\n<span style=\"font-family: Verdana, Geneva, sans-serif\">5. double<\/span><br \/>\n<span style=\"color: inherit;font-size: inherit;font-family: Verdana, Geneva, sans-serif\">6. chararray<\/span><br \/>\n7. bytearray<br \/>\n<span style=\"font-weight: 400\">Some complex data types:<\/span><br \/>\n<span style=\"font-weight: 400\">8. map<\/span><br \/>\n<span style=\"font-weight: 400\">9. bag<\/span><br \/>\n<span style=\"font-weight: 400\">10. tuple<\/span><\/p>\n<p><strong>Types in Hive 0.13.0 and Later<\/strong><br \/>\n11. short<br \/>\n<span style=\"font-weight: 400\">12. datetime<\/span><br \/>\n<span style=\"font-weight: 400\">13. bigdecimal<\/span><br \/>\nSo, this was all about HCatalog Loader and Storer. Hope you like our explanation.<\/p>\n<h2>Conclusion: HCatalog Loader and Storer<\/h2>\n<p>Hence, we have seen the concept of HCatalog Loader and Storer. So, this article will definitely help to clear all doubts regarding HCatalog loader and storer. Still, if any doubt, ask in the comment tab.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last HCatalog tutorial, we discussed HCatalog Commands. Today, we will see HCatalog Loader and Storer. Moreover, we will also discuss the examples of HCatalog loader and storer. Basically, to read and write&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":20257,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[5524,5535,5541,5542,5546,5701,13865,15007],"class_list":["post-20012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hcatalog","tag-hcatalog-loader-storer","tag-hcatalog-tutorial","tag-hcatloader","tag-hcatloader-data-types","tag-hcatstorer","tag-hive-data-types","tag-store-examples","tag-types-in-hive-0-12-0-and-earlier"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>HCatalog Loader and Storer - Usage &amp; Example - DataFlair<\/title>\n<meta name=\"description\" content=\"HCatalog Loader and Storer, HCatLoader, HCatStorer, usage, assumption, HCatalog example, Hcatalog tutorial, what is HCatalog loader and storer\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HCatalog Loader and Storer - Usage &amp; Example - DataFlair\" \/>\n<meta property=\"og:description\" content=\"HCatalog Loader and Storer, HCatLoader, HCatStorer, usage, assumption, HCatalog example, Hcatalog tutorial, what is HCatalog loader and storer\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-27T14:23:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatalog-Loader-and-Storer-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HCatalog Loader and Storer - Usage &amp; Example - DataFlair","description":"HCatalog Loader and Storer, HCatLoader, HCatStorer, usage, assumption, HCatalog example, Hcatalog tutorial, what is HCatalog loader and storer","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/","og_locale":"en_US","og_type":"article","og_title":"HCatalog Loader and Storer - Usage &amp; Example - DataFlair","og_description":"HCatalog Loader and Storer, HCatLoader, HCatStorer, usage, assumption, HCatalog example, Hcatalog tutorial, what is HCatalog loader and storer","og_url":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-06-27T14:23:15+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatalog-Loader-and-Storer-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"HCatalog Loader and Storer &#8211; Usage &amp; Example","datePublished":"2018-06-27T14:23:15+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/"},"wordCount":628,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatalog-Loader-and-Storer-01.jpg","keywords":["HCatalog Loader &amp; Storer","HCatalog Tutorial","HCatloader","HCatLoader Data Types","HCatStorer","Hive Data Types","Store Examples","Types in Hive 0.12.0 and Earlier"],"articleSection":["HCatalog Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/","url":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/","name":"HCatalog Loader and Storer - Usage &amp; Example - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatalog-Loader-and-Storer-01.jpg","datePublished":"2018-06-27T14:23:15+00:00","description":"HCatalog Loader and Storer, HCatLoader, HCatStorer, usage, assumption, HCatalog example, Hcatalog tutorial, what is HCatalog loader and storer","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatalog-Loader-and-Storer-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/HCatalog-Loader-and-Storer-01.jpg","width":1200,"height":628,"caption":"HCatalog Loader and Storer - Usage &amp; Example"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/hcatalog-loader-and-storer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"HCatalog Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/hcatalog\/"},{"@type":"ListItem","position":3,"name":"HCatalog Loader and Storer &#8211; Usage &amp; Example"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/20012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=20012"}],"version-history":[{"count":0,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/20012\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/20257"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=20012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=20012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=20012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}