Hcatalog + Pig


$DERBY_HOME/bin/startNetworkServer

$HADOOP_HOME/sbin$ ./start-all.sh

$HIVE_HOME/bin/hiveserver2

$HIVE_HOME/bin/hive --service metastore

$HADOOP_HOME/bin/hadoop fs -mkdir hdfs://localhost/hcatalog-example

$HADOOP_HOME/bin/hadoop fs -put /tmp/test-dataset.csv hdfs://localhost/hcatalog-example

$HADOOP_HOME/bin/hadoop fs -cat hdfs://localhost/hcatalog-example/test-dataset.csv | head -n 4

playerID,yearID,gameNum,gameID,teamID,lgID,GP,startingPos
aaronha01,1955,0,NLS195507120,ML1,NL,1,
aaronha01,1956,0,ALS195607100,ML1,NL,1,
aaronha01,1957,0,NLS195707090,ML1,NL,1,9

./hcat -e "CREATE TABLE default.gamedataset (playerID STRING,yearID INT,gameNum INT ,gameID STRING ,teamID STRING ,lgID STRING ,GP INT,startingPosts INT) PARTITIONED BY (country STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';"

./hcat -e "alter table default.gamedataset add partition (country='DE') location '/hcatalog-example/'"

vim $PIG_HOME/conf/pig.properties

pig.load.default.statements=/opt/pig-0.15.0/.pigbootup

vim $PIG_HOME/.pigbootup

REGISTER /opt/apache-hive-1.2.1-bin/hcatalog/share/hcatalog/hcatalog-core-1.2.1.jar;
REGISTER /opt/apache-hive-1.2.1-bin/lib/hive-exec-1.2.1.jar;
REGISTER /opt/apache-hive-1.2.1-bin/lib/hive-metastore-1.2.1.jar;

vim $HOME/.bashrc

export PIG_OPTS=-Dhive.metastore.uris=thrift://localhost:9083
export PIG_CLASSPATH=$HCAT_HOME/share/hcatalog/*:$HIVE_HOME/lib/*

$PIG_HOME/bin/pig -useHCatalog

A = load 'default.gamedataset' using org.apache.hive.hcatalog.pig.HCatLoader();
dump A;

Advertisements