Pig: Introduction to Latin - 1

  • Relation and Field

Pig Latin is a dataflow language. Each processing step results in a new data set, or relation.

A = load 'NYSE_dividends' (exchange, symbol, date, dividends);

//A is relation      exchange,symbol,date and dividends are all fields

 

  • Case Sensitivity

Keywords in Pig Latin are not case-sensitive; for example, LOAD is equivalent to load. But relation and field names are.UDF names are also case-sensitive, thus COUNT is not the same UDF as count.

 

  • Comments

A = load 'foo'; --this is a single-line comment
/*
* This is a multiline comment.
*/
B = load /* a comment in the middle */'bar';

 

  • Load

PigStorage and TextLoader

divs = load '/data/examples/NYSE_dividends';      //tab-delimited file

divs = load 'NYSE_dividends' using HBaseStorage();  //load from hbase

divs = load 'NYSE_dividends' using PigStorage(',');    //comma-separated text data

divs = load 'NYSE_dividends' as (exchange, symbol, date, dividends);  //specify the schema

divs = load 'datadir'; // read all files recursively in the datadir

divs = load 'datadir/part-2012-*';  //read multiple files in datadir



 

  • Store

store processed into '/data/examples/processed';

store processed into 'processed' using HBaseStorage();

store processed into 'processed' using PigStorage(',');

 

Note:when writing to a filesystem, processed will be a directory with part files rather than a single file. But how many part files will be created? That depends on the parallelism of the last job before the store. If it has re-duces, it will be determined by the parallel level set for that job.  If it is a map-only job, it will be determined by the number of maps, which is controlled by Hadoop and not Pig.

 

  • Dump

dump processed;  //sent contents of processed to console

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值