Amazon EMR
Amazon EMR Release Guide

Apache HCatalog

HCatalog is a tool that allows you to access Hive metastore tables within Pig, Spark SQL, and/or custom MapReduce applications. HCatalog has a REST interface and command line client that allows you to create tables or do other operations. You then write your applications to access the tables using HCatalog libraries. For more information, see Using HCatalog.

HCatalog on Amazon EMR release 5.8.0 and later supports using AWS Glue Data Catalog as the metastore for Hive. For more information, see Using AWS Glue Data Catalog as the Metastore for Hive


HCatalog is included only in Amazon EMR versions 4.4.0 and later.

HCatalog Release Information for This Release of Amazon EMR

Application Amazon EMR Release Label Components installed with this application

HCatalog 2.3.1


aws-hm-client, emrfs, emr-ddb, emr-goodies, emr-kinesis, hadoop-client, hadoop-mapred, hadoop-hdfs-datanode, hadoop-hdfs-library, hadoop-hdfs-namenode, hadoop-kms-server, hadoop-yarn-nodemanager, hadoop-yarn-resourcemanager, hadoop-yarn-timeline-server, hcatalog-client, hcatalog-server, hcatalog-webhcat-server, hive-client, mysql-server

Creating a Cluster with HCatalog

Although HCatalog is included in the Hive project, you still must install it on EMR clusters as its own application.

To launch a cluster with HCatalog installed using the console

The following procedure creates a cluster with HCatalog installed. For more information about creating clusters using the console, including Advanced Options see Plan and Configure Clusters in the Amazon EMR Management Guide.

  1. Open the Amazon EMR console at

  2. Choose Create cluster to use Quick Create.

  3. For the Software Configuration field, choose Amazon Release Version emr-4.4.0 or later.

  4. In the Select Applications field, choose either All Applications or HCatalog.

  5. Select other options as necessary and then choose Create cluster.

To launch a cluster with HCatalog using the AWS CLI

  • Create the cluster with the following command:

    aws emr create-cluster --name "Cluster with Hcat" --release-label \ --applications Name=HCatalog --ec2-attributes KeyName=myKey \ --instance-type m3.xlarge --instance-count 3 --use-default-roles


    Linux line continuation characters (\) are included for readability. They can be removed or used in Linux commands. For Windows, remove them or replace with a caret (^).

Using HCatalog

You can use HCatalog within various applications that use the Hive metastore. The examples in this section show how to create a table and use it in the context of Pig and Spark SQL.

Disable Direct Write When Using HCatalog HStorer

Whenever an application uses HCatStorer (for example, a Pig script STORE command) to write to an HCatalog table stored in Amazon S3, disable the direct write feature of Amazon EMR. You can do this by setting the and the configurations to false. See the Pig example below for an example of setting these configurations from within a Pig script before running subsequent Pig commands. The following example demonstrates how to set these configurations using Java.

Configuration conf = new Configuration(); conf.set("", "false"); conf.set("", "false");

Create a Table Using the HCat CLI and Use That Data in Pig

Create the following script, impressions.q, on your cluster:

CREATE EXTERNAL TABLE impressions ( requestBeginTime string, adId string, impressionId string, referrer string, userAgent string, userCookie string, ip string ) PARTITIONED BY (dt string) ROW FORMAT serde '' with serdeproperties ( 'paths'='requestBeginTime, adId, impressionId, referrer, userAgent, userCookie, ip' ) LOCATION 's3://[your region].elasticmapreduce/samples/hive-ads/tables/impressions/'; ALTER TABLE impressions ADD PARTITION (dt='2009-04-13-08-05');

Execute the script using the HCat CLI:

% hcat -f impressions.q Logging initialized using configuration in file:/etc/hive/conf.dist/ OK Time taken: 4.001 seconds OK Time taken: 0.519 seconds

Open the Grunt shell and access the data in impressions:

% pig -useHCatalog -e "A = LOAD 'impressions' USING org.apache.hive.hcatalog.pig.HCatLoader(); B = LIMIT A 5; dump B;" <snip> (1239610346000,m9nwdo67Nx6q2kI25qt5On7peICfUM,omkxkaRpNhGPDucAiBErSh1cs0MThC,,Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; FunWebProducts; GTB6; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET,wcVWWTascoPbGt6bdqDbuWTPPHgOPs,,2009-04-13-08-05) (1239611000000,NjriQjdODgWBKnkGJUP6GNTbDeK4An,AWtXPkfaWGOaNeL9OOsFU8Hcj6eLHt,,Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 1.1.4322),OaMU1F2gE4CtADVHAbKjjRRks5kIgg,,2009-04-13-08-05) (1239610462000,Irpv3oiu0I5QNQiwSSTIshrLdo9cM1,i1LDq44LRSJF0hbmhB8Gk7k9gMWtBq,,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; InfoPath.1),QSb3wkLR4JAIut4Uq6FNFQIR1rCVwU,,2009-04-13-08-05) (1239611007000,q2Awfnpe0JAvhInaIp0VGx9KTs0oPO,s3HvTflPB8JIE0IuM6hOEebWWpOtJV,,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; InfoPath.1),QSb3wkLR4JAIut4Uq6FNFQIR1rCVwU,,2009-04-13-08-05) (1239610398000,c362vpAB0soPKGHRS43cj6TRwNeOGn,jeas5nXbQInGAgFB8jlkhnprN6cMw7,,Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 1.1.4322),k96n5PnUmwHKfiUI0TFP0TNMfADgh9,,2009-04-13-08-05) 7120 [main] INFO org.apache.pig.Main - Pig script completed in 7 seconds and 199 milliseconds (7199 ms) 16/03/08 23:17:10 INFO pig.Main: Pig script completed in 7 seconds and 199 milliseconds (7199 ms)

Accessing the Table using Spark SQL

This example creates a Spark DataFrame from the table created in the first example and shows the first 20 lines:

% spark-shell --jars /usr/lib/hive-hcatalog/share/hcatalog/hive-hcatalog-core-1.0.0-amzn-3.jar <snip> scala> val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc); scala> val df = hiveContext.sql("SELECT * FROM impressions") scala> <snip> 16/03/09 17:18:46 INFO DAGScheduler: ResultStage 0 (show at <console>:32) finished in 10.702 s 16/03/09 17:18:46 INFO DAGScheduler: Job 0 finished: show at <console>:32, took 10.839905 s +----------------+--------------------+--------------------+------------------+--------------------+--------------------+--------------+----------------+ |requestbegintime| adid| impressionid| referrer| useragent| usercookie| ip| dt| +----------------+--------------------+--------------------+------------------+--------------------+--------------------+--------------+----------------+ | 1239610346000|m9nwdo67Nx6q2kI25...|omkxkaRpNhGPDucAi...||Mozilla/4.0 (comp...|wcVWWTascoPbGt6bd...||2009-04-13-08-05| | 1239611000000|NjriQjdODgWBKnkGJ...|AWtXPkfaWGOaNeL9O...||Mozilla/4.0 (comp...|OaMU1F2gE4CtADVHA...||2009-04-13-08-05| | 1239610462000|Irpv3oiu0I5QNQiwS...|i1LDq44LRSJF0hbmh...||Mozilla/4.0 (comp...|QSb3wkLR4JAIut4Uq...||2009-04-13-08-05| | 1239611007000|q2Awfnpe0JAvhInaI...|s3HvTflPB8JIE0IuM...||Mozilla/4.0 (comp...|QSb3wkLR4JAIut4Uq...||2009-04-13-08-05| | 1239610398000|c362vpAB0soPKGHRS...|jeas5nXbQInGAgFB8...||Mozilla/4.0 (comp...|k96n5PnUmwHKfiUI0...||2009-04-13-08-05| | 1239610600000|cjBTpruoaiEtqLuMX...|XwlohBSs8Ipxs1bRa...||Mozilla/4.0 (comp...|k96n5PnUmwHKfiUI0...||2009-04-13-08-05| | 1239610804000|Ms3eJHNAEItpxvimd...|4SIj4pGmgVLl625BD...||Mozilla/4.0 (comp...|k96n5PnUmwHKfiUI0...||2009-04-13-08-05| | 1239610872000|h5bccHX6wJReDi1jL...|EFAWIiBdVfnxwAMWP...||Mozilla/4.0 (comp...|k96n5PnUmwHKfiUI0...||2009-04-13-08-05| | 1239610365000|874NBpGmxNFfxEPKM...|xSvE4XtGbdtXPF2Lb...||Mozilla/5.0 (Maci...|eWDEVVUphlnRa273j...||2009-04-13-08-05| | 1239610348000|X8gISpUTSqh1A5reS...|TrFblGT99AgE75vuj...||Mozilla/4.0 (comp...|tX1sMpnhJUhmAF7AS...||2009-04-13-08-05| | 1239610743000|kbKreLWB6QVueFrDm...|kVnxx9Ie2i3OLTxFj...||Mozilla/4.0 (comp...|tX1sMpnhJUhmAF7AS...||2009-04-13-08-05| | 1239610812000|9lxOSRpEi3bmEeTCu...|1B2sff99AEIwSuLVV...||Mozilla/4.0 (comp...|tX1sMpnhJUhmAF7AS...||2009-04-13-08-05| | 1239610876000|lijjmCf2kuxfBTnjL...|AjvufgUtakUFcsIM9...||Mozilla/4.0 (comp...|tX1sMpnhJUhmAF7AS...||2009-04-13-08-05| | 1239610941000|t8t8trgjNRPIlmxuD...|agu2u2TCdqWP08rAA...||Mozilla/4.0 (comp...|tX1sMpnhJUhmAF7AS...||2009-04-13-08-05| | 1239610490000|OGRLPVNGxiGgrCmWL...|mJg2raBUpPrC8OlUm...||Mozilla/4.0 (comp...|r2k96t1CNjSU9fJKN...||2009-04-13-08-05| | 1239610556000|OnJID12x0RXKPUgrD...|P7Pm2mPdW6wO8KA3R...||Mozilla/4.0 (comp...|r2k96t1CNjSU9fJKN...||2009-04-13-08-05| | 1239610373000|WflsvKIgOqfIE5KwR...|TJHd1VBspNcua0XPn...||Mozilla/5.0 (Maci...|fj2L1ILTFGMfhdrt3...||2009-04-13-08-05| | 1239610768000|4MJR0XxiVCU1ueXKV...|1OhGWmbvKf8ajoU8a...||Mozilla/5.0 (Maci...|fj2L1ILTFGMfhdrt3...||2009-04-13-08-05| | 1239610832000|gWIrpDiN57i3sHatv...|RNL4C7xPi3tdar2Uc...||Mozilla/5.0 (Maci...|fj2L1ILTFGMfhdrt3...||2009-04-13-08-05| | 1239610789000|pTne9k62kJ14QViXI...|RVxJVIQousjxUVI3r...||Mozilla/5.0 (Maci...|1bGOKiBD2xmui9OkF...||2009-04-13-08-05| +----------------+--------------------+--------------------+------------------+--------------------+--------------------+--------------+----------------+ only showing top 20 rows scala>

Example: Create an HCatalog Table and Write to it Using Pig

You can create an HCatalog table and use Apache Pig to write to it by way of HCatStorer using a data source in Amazon S3. HCatalog requires that you disable direct write, or the operation fails silently. Set both the and the configurations to false either using the mapred-site classification, or manually from within the Grunt shell. The following example shows a table created using the HCat CLI, followed by commands executed in the Grunt shell to populate the table from a sample data file in Amazon S3.

To run this example, connect to the Master node using SSH.

Create an HCatalog script file, wikicount.q, with the following contents, which creates an HCatalog table nameed wikicount.

CREATE EXTERNAL TABLE IF NOT EXISTS wikicount( col1 string, col2 bigint ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' STORED AS ORC LOCATION 's3://MyBucket/hcat/wikicount';

Use an HCat CLI command to execute the script from the file.

hcat -f wikicount.q

Next, start the Grunt shell with the -useHCatalog option, set configurations to disable direct write, load data from an S3 location, and then write the results to the wikicount table.

pig -useHCatalog SET false; SET false; A = LOAD 's3://support.elasticmapreduce/training/datasets/wikistats_tiny/' USING PigStorage(' ') AS (Site:chararray, page:chararray, views:int, total_bytes:long); B = GROUP A BY Site; C = FOREACH B GENERATE group as col1, COUNT(A) as col2; STORE C INTO 'wikicount' USING org.apache.hive.hcatalog.pig.HCatStorer();