【Pig一】Pig入門
7258 ワード
Pigの取り付け
1.pigをダウンロードする
2.ストレス解消配置環境変数
PigがMap/Reduceモードを使用する場合は、環境変数にHADOOP_を配置する必要があります。ホーム環境変数
3.本編ではデフォルトのPigプロファイルを使用して、Pig属性を設定するなら、下記のファイルを設定します。
4.Pigを起動する
起動の結果:
Pig基本使用
1.Hadoop 2.5.2を起動する
2.データセットvim$PIG_を準備する。HOME/data/sampledata.txt
2014:11:23
2014:11:61
2014:12:32
2014:8:11
3.次のコマンドでpigを起動します。
4.Pigでsampledata.txtデータをHFSにアップロードする
説明:/user/hadoopはHFSにアップロードされたターゲットディレクトリであり、使用できます。
5.PigでHFSの状態を確認する
77はsampledata.txtのバイト数を表します。
6.sampledata.txtの内容を確認する
7.sampledata.txtをPigにロードし、分割、指定の三列A、B、C
実行結果
8.Aタスクの説明を見る
PigはMap Reduce Jobを起動しました。結果として10020ポートの接続に失敗しました。端末でtelnet local host 10020を使って接続拒否を発見しました。端末は5分近くの頻繁な接続を試みた後、最後のMapタスクはやはり終了しました。
9.次の操作を実行するための条件フィルタリングを行います。
常に試行錯誤を繰り返して10020ポートに接続しましたが、結局は出力されました。
10.下記の操作でAをグループ化する。
常に試行錯誤を繰り返して10020ポートに接続しましたが、結局は出力されました。
11.結果をHFSに保存する
常に試行錯誤を繰り返して10020ポートに接続しましたが、結局は出力されました。
エイリアス(Alias)
上記の例では、使用しました。
grunt>後のAは別名を表しますが、この別名は誰の別名ですか? dumpコマンドは、都aliasに対して計算を行い、結果をコンソールに表示する 。 describeコマンドは、aliasのモード(schema) を表示するために使用されます。
締め括りをつける
この文章は失敗しました。Pig入門に対する効果に達していません。Pigは何ができますか?Hiveと何の違いがありますか?直感的な感じがありません。また、配置に問題があります。Pig命令を実行する時、絶えずエラーが発生します。
10020ポートの接続拒否について
Hadoop 2.xの設定とJob History Serverの起動が必要です。
1.Job Historyに関する配置
下記の内容を追加します。
2.JobHistoryServerを起動する
1.pigをダウンロードする
wget http://mirror.bit.edu.cn/apache/pig/pig-0.14.0/pig-0.14.0.tar.gz
2.ストレス解消配置環境変数
PigがMap/Reduceモードを使用する場合は、環境変数にHADOOP_を配置する必要があります。ホーム環境変数
export PIG_HOME=/home/hadoop/pig-0.14.0
export PIG_CLASSPATH=/home/hadoop/hadoop-2.5.2/etc/hadoop/conf
export PATH=$PIG_HOME/bin:$PATH
3.本編ではデフォルトのPigプロファイルを使用して、Pig属性を設定するなら、下記のファイルを設定します。
/home/hadoop/pig-0.14.0/conf/pig.properties
4.Pigを起動する
/home/hadoop/pig-0.14.0/bin/pig
起動の結果:
hadoop@tom-Inspiron-3521:~/pig-0.14.0/bin$ ./pig
14/12/28 12:31:03 INFO pig.ExecTypeProvider: Trying ExecType : LOCAL
14/12/28 12:31:03 INFO pig.ExecTypeProvider: Trying ExecType : MAPREDUCE
14/12/28 12:31:03 INFO pig.ExecTypeProvider: Picked MAPREDUCE as the ExecType
2014-12-28 12:31:03,217 [main] INFO org.apache.pig.Main - Apache Pig version 0.14.0 (r1640057) compiled Nov 16 2014, 18:02:05
2014-12-28 12:31:03,217 [main] INFO org.apache.pig.Main - Logging error messages to: /home/hadoop/pig-0.14.0/bin/pig_1419741063215.log
2014-12-28 12:31:03,279 [main] INFO org.apache.pig.impl.util.Utils - Default bootup file /home/hadoop/.pigbootup not found
2014-12-28 12:31:04,154 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
2014-12-28 12:31:04,154 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2014-12-28 12:31:04,154 [main] INFO org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: hdfs://yuzhitao-Inspiron-3521:9000
2014-12-28 12:31:06,100 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
grunt>
Pig基本使用
1.Hadoop 2.5.2を起動する
2.データセットvim$PIG_を準備する。HOME/data/sampledata.txt
2014:11:23
2014:11:61
2014:12:32
2014:8:11
3.次のコマンドでpigを起動します。
pig
4.Pigでsampledata.txtデータをHFSにアップロードする
grunt> fs -copyFromLocal /home/hadoop/pig-0.14.0/data/sampledata.txt /user/hadoop
説明:/user/hadoopはHFSにアップロードされたターゲットディレクトリであり、使用できます。
5.PigでHFSの状態を確認する
grunt> ls
hdfs://tom-Inspiron-3521:9000/user/hadoop/sampledata.txt<r 1> 77
77はsampledata.txtのバイト数を表します。
6.sampledata.txtの内容を確認する
grunt> fs -cat /user/hadoop/sampledata.txt
7.sampledata.txtをPigにロードし、分割、指定の三列A、B、C
grunt> A = LOAD 'sampledata.txt' USING PigStorage(':') AS (A:int,B:int, C:int);
実行結果
grunt> A = LOAD 'sampledata.txt' USING PigStorage(':') AS (A:int,B:int, C:int);
2014-12-28 13:19:44,205 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2014-12-28 13:19:44,299 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
grunt>
8.Aタスクの説明を見る
grunt> describe A;
A: {A: int,B: int,C: int}
grunt> dump A;
PigはMap Reduce Jobを起動しました。結果として10020ポートの接続に失敗しました。端末でtelnet local host 10020を使って接続拒否を発見しました。端末は5分近くの頻繁な接続を試みた後、最後のMapタスクはやはり終了しました。
2014-12-28 15:10:55,732 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Success!
2014-12-28 15:10:55,739 [main] INFO org.apache.pig.data.SchemaTupleBackend - Key [pig.schematuple] was not set... will not generate code.
2014-12-28 15:10:55,763 [main] INFO org.apache.hadoop.mapreduce.lib.input.FileInputFormat - Total input paths to process : 1
2014-12-28 15:10:55,764 [main] INFO org.apache.pig.backend.hadoop.executionengine.util.MapRedUtil - Total input paths to process : 1
(2014,11,23)
(2014,11,61)
(2014,12,32)
(2014,8,11)
9.次の操作を実行するための条件フィルタリングを行います。
grunt> B = FILTER A BY B ! = 12;
grunt>dump B;
常に試行錯誤を繰り返して10020ポートに接続しましたが、結局は出力されました。
(2014,11,23)
(2014,11,61)
(2014,8,11)
10.下記の操作でAをグループ化する。
grunt> B = GROUP A BY B; //BY B
grunt>dump B;
常に試行錯誤を繰り返して10020ポートに接続しましたが、結局は出力されました。
(8,{(2014,8,11)})
(11,{(2014,11,61),(2014,11,23)})
(12,{(2014,12,32)})
11.結果をHFSに保存する
grunt> STORE A INTO 'pigStorageA' USING PigStorage(':');
常に試行錯誤を繰り返して10020ポートに接続しましたが、結局は出力されました。
grunt> ls
hdfs://tom-Inspiron-3521:9000/user/hadoop/pig <dir>
hdfs://tom-Inspiron-3521:9000/user/hadoop/pigStorageA <dir> ////
hdfs://tom-Inspiron-3521:9000/user/hadoop/wordcount <dir>
grunt> fs -l /user/hadoop/pigStorageA
-l: Unknown command
grunt> fs -ls /user/hadoop/pigStorageA
Found 2 items
-rw-r--r-- 1 hadoop supergroup 0 2014-12-28 15:53 /user/hadoop/pigStorageA/_SUCCESS
-rw-r--r-- 1 hadoop supergroup 43 2014-12-28 15:53 /user/hadoop/pigStorageA/part-m-00000
grunt> fs -cat /user/hadoop/pigStorageA/part-m-00000 ///
2014:11:23
2014:11:61
2014:12:32
2014:8:11
grunt>
エイリアス(Alias)
上記の例では、使用しました。
grunt> A = LOAD 'sampledata.txt' USING PigStorage(':') AS (A:int,B:int, C:int);
grunt>後のAは別名を表しますが、この別名は誰の別名ですか?
締め括りをつける
この文章は失敗しました。Pig入門に対する効果に達していません。Pigは何ができますか?Hiveと何の違いがありますか?直感的な感じがありません。また、配置に問題があります。Pig命令を実行する時、絶えずエラーが発生します。
10020ポートの接続拒否について
Hadoop 2.xの設定とJob History Serverの起動が必要です。
1.Job Historyに関する配置
vim mapred-site.xml
下記の内容を追加します。
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop.master:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop.master:19888</value>
</property>
2.JobHistoryServerを起動する
sbin/mr-jobhistory-daemon.sh start historyserver