Apache PigとHadoopプラットフォーム,,en,データの処理方法,,en,Apache PigとHadoop,,en,高水準のスクリプト言語であり、,,en,Apache Hadoopエコシステム,,en,豚スクリプトは、主にHadoopプラットフォーム上でのデータ解析と操作に使用されます,,en,MapReduceはHadoopプラットフォームで使用されているプログラミングモデルであることがわかっています,,en,並列処理用,,en,また、PigはMapReduceメカニズムを内部的に使用して分散環境でデータを処理します,,en,Pigは実際にMapReduceモデルの上に抽象化を提供し、開発者にとってプログラミングを容易にします,,en,豚のスクリプトはSQLの構文に似ています,,en,開発者は、MapReduceを直接使用することなく、データ処理のためのSQL文を簡単に記述できます,,en,HadoopとBigデータの主要用語,,en – How to process your data?

Apache Pig and Hadoop

Apache Pig and Hadoop – How to process your data?

概要: Apache Pig is a high level scripting language and a part of Apache Hadoop Eco-system. Pig scripting is mainly used for data analysis and manipulation on top of Hadoop platform. We know that MapReduce is a programming model used in Hadoop platform (for parallel processing), Pig also uses MapReduce mechanism internally to process data on a distributed environment. Pig actually provides an abstraction on top of MapReduce model to make programming easier for the developers. Pig scripting is similar to SQL syntax, so the developers can simply write SQL like statements for data processing without using MapReduce directly.








Read more Hadoop and Big data key terms

はじめに: Pigのパワーは、データ分析タスクをデータフローとして記述する能力によって定義されています,,en,あるコンポーネントから別のコンポーネントへのトラバース,,en,ブタのもう一つの重要な特徴は、,,en,〜する,,pt,成立した,,en,独身,,en,UDF,,da,これは、Javaのような多くの一般的な高水準言語で書かれたコードにアクセスするために使用できます,,en,Rubyなど,,en,豚のスクリプトは他の言語からも実行できます,,en,複雑なビジネス上の問題を書くためにPigを活用することができます,,en,分散コンピューティングシステム上で並列に実行されるべきである,,en,異なるアプリケーションからコンポーネントとして呼び出す,,en,概念的思考,,en,豚のしくみ,,en,Pigスクリプトの作業フローを理解するための最良の例は、ETLプロセスを理解することです,,en,ETL,,en,エキス,,en,変換,,en,負荷,,en,データはソースから抽出されます,,en, traversing from one component to another component. The other important feature of Pig is its User Defined Functions (UDF), which can be used to access code written in many popular high level languages like Java, Python, and Ruby etc. On the other side, Pig scripts can also be executed from other languages. So, you can take the advantage of Pig to write complex business problems, which should be executed in a parallel way on a distributed computing system. And, then invoke it from different applications as a component.



Conceptual thinking – How Pig works

The best example of understanding the work flow of a Pig script is to understand the ETL process. In an ETL (Extract – Transform – Load) process, first, the data is extracted from the sources, second, ビジネスロジックに基づいて処理され、最終的にデータベースに格納されます,,en,同じメカニズムがPigスクリプトの実行に従います,,en,以下は、,,en,豚由来のデータを抽出する,,en,フラットファイル,,en,動的データなど,,en,UDFを使用して,,en,これが入力です,,en,豚はその操作を実行する,,en,好きなセレクト,,en,反復およびその他の変換,,en,データに,,en,これが初期処理です,,en,Pigはデータを他の複雑なシステムに渡して処理を進めます,,en,これはさらに処理しています,,en,Pigはその結果をHadoop Distributed File System,,en,これはストレージです,,en,内部的に,,en,すべてのpigタスクは、hadoopクラスタで実行される一連のMapReduceジョブです,,en,これらのジョブは、パフォーマンスを向上させるためにPigインタプリタによって最適化されています,,en,Apache Pigコンポーネント,,en,Apache Pigの主なコンポーネントは、インフラストラクチャ層と言語層です,,en,インフラストラクチャ層,,en. The same mechanism is followed in a Pig script execution. Following are the steps.

  • First, Pig extract data from sources (stream, flat file, dynamic data etc.) using UDF – This is the input.
  • Second, Pig performs its operations (like select, iterate and other transforms) on the data – This is the initial processing.
  • Third, Pig passes the data to other complex systems for more processing (using UDF) – This is further processing.
  • Finally, Pig stores the result into Hadoop Distributed File System (HDFS) – This is the storage.

Internally, all the pig tasks are series of MapReduce jobs which runs on a hadoop cluster. These jobs are optimized by Pig interpreters to improve performance.

Apache Pig components

The main components of Apache Pig are its infrastructure layer and the language layer.

Infrastructure layer: このレイヤには、PigスクリプトからMapReduceジョブのシーケンスを生成するコンパイラが含まれています,,en,これは、分散並列コンピューティングフレームワーク,,en,言語レイヤー,,en,言語レイヤには、「Pig Latin」という文字言語が含まれています。,,en,この言語の構文は、SQL文のようなものです,,en,それは以下の特徴を有する,,en,簡単なプログラミング,,en,これは、データ分析タスクの並列実行を実現するスクリプトを簡単に作成する方法を提供します,,en,また、データシーケンスの流れとして複雑なデータ変換を含む複雑なタスクを実行することもできます,,en,だから、書くのは簡単です,,en,豚ラテンのスクリプトを理解し、維持する,,en,より良い最適化,,en,すべてのタスクがエンコードされるため,,en,最適化はシステムによって自動的に行われます,,en,拡張可能,,en,言語を拡張してカスタム関数を書くことができます,,en,豚 - 演算子,,en. It works on a distributed parallel computing framework.

Language layer: The language layer contains a textual language known as ‘Pig Latin’. The syntax of this language is more like a SQL statement. It has the following features.

  • Simple programming: It provides a simple way to write scripts to achieve parallel execution of data analytics tasks. It can also perform complex tasks including complex data transformations as a flow of data sequences. So it is easy to write, understand and maintain Pig Latin scripts.
  • Better optimization: As all the tasks are encoded, optimization is automatically done by the system.
  • Extendable: The language can be extended to write custom functions.

Pig – Operators: 豚には多くのオペレーターが作業を実行しています,,en,演算子の中には 'LOAD',,en,'FOREACH,,en,豚 - ユーザー定義関数,,en,Pigは複雑なタスクを実行するためのユーザー定義関数をサポートしています,,en,これらの関数はJava言語でも記述できます,,en,Pigのインストールと実行方法,,en,このセクションでは、Pigスクリプトのインストールと実行について説明します,,en,1つずつ始めましょう,,en,前提条件,,en,すべてのUNIXおよびWindowsユーザーは、,,en,彼らのシステムにインストールされている,,en,HADOOP_HOME,,en,適切に設定する必要があります,,en,豚のダウンロード,,en,安定版のPigをダウンロードする,,en,その後、配布物を解凍し、ブタのスクリプトとブタのプロパティファイルとその場所を書き留めておきます,,en,その後、以下のようにあなたのパスに 'bin'ディレクトリを追加してください,,en,エクスポートPATH = /,,en,パスツーブタ,,en,pig-n.n.n / bin,,vi,パス,,en. Some of the operators are ‘LOAD’, ‘FOREACH’ 等.

Pig – User Defined Functions: Pig supports User Defined Functions to perform complex tasks. These functions can be written in Java language also.



How to install and execute Pig?

In this section we will discuss about the installation and execution of Pig scripts. Let’s start one by one.

  • Prerequisite: All UNIX and Windows users should have Hadoopの (Download) と ジャワ (Download) installed in their system. HADOOP_HOMEJAVA_HOME should be set properly.
  • Pig Download: First, download a stable version of Pig (Download). Then unpack the distribution and keep a note of pig script and pig properties file and their location. After this add the ‘bin’ directory to your path as shown below.

[コー​​ド] $ export PATH=/<path-to-pig>/pig-n.n.n/bin:$PATH [/コー​​ド]

次のコマンドを使用して、ブタのインストールをテストします。,,en,それは豚に関連するすべてのヘルプを表示します,,en,それが適切に来たら,,en,あなたの豚のインストールは成功です,,en,豚 - ヘルプ,,en,Pigコマンドの実行/実行,,en,豚のラテンステートメントと豚のスクリプトは、両方の 'ローカルで実行することができます,,en,と 'MapReduce,,en,ローカルモードの場合,,en,1台のマシンが必要で、,,en,Hadoopクラスタ,,en,インストールが必要です,,en,豚は2つの方法で動かすことができます,,en,あなたは豚を使うことができます,,en,'bin / pig Perl'を使ってコマンド,,en,'javaを使って,,en,コマンド 'java -cp pig.jar',,en,これらの2つのモードは、ローカルインストールやクラスタ環境などのインフラストラクチャに基づいて定義されます。,,en,ローカルモード,,en,ローカルモードでPigを実行するには,,en,ローカルファイルシステムに必要なファイルをすべてインストールし、ローカルホストから実行する,,en. It will show all the help related to pig. If it comes properly, then your pig installation is successful.

[コー​​ド] $ pig –help [/コー​​ド]

  • Run/Execute Pig commands: Pig Latin statements and Pig scripts can be run in both ‘Local’ and ‘MapReduce’ mode. For local mode, a single machine is required and for MapReduce mode, Hadoop cluster and HDFS installation is needed. Pig can be run in two ways. First, you can use ‘pig’ command by using ‘bin/pig Perl ‘ script. Second, by using ‘java’ command as ‘java -cp pig.jar’. These two modes are defined based on the infrastructure available like local installation or clustered environment etc.

Local Mode: To run Pig in local mode, install all required files in your local file system and then run it from local host.








Listing 1: ローカルモードで実行しているブタの表示,,en,ローカルモードでPigを実行する,,en,豚-xローカル,,en,Mapreduceモード,,en,マップリダクションモード,,en,HadoopクラスタとHDFSをインストールする必要があります,,en,それはデフォルトモードです,,en,あなたは '-xを指定しないかもしれません,,en,フラグ,,en,地図作成モードで豚を表示する,,en,MapreduceモードでPigを実行する,,en,これがデフォルトモード* /,,en,豚,,en,豚-x mapreduce,,en,一般的には、Pigは対話モードまたはバッチモードを使用して実行できます,,en,インタラクティブモード,,en,グラン,,en,シェルは、個々の豚ラテン語ステートメントを入力するために使用されます,,en,バッチモード,,en,豚ラテンのステートメントは、スクリプトファイルに入れられます。,,en,拡張機能とコマンドラインからの実行,,en,これはSQL文とスクリプトに似ています,,en,豚のラテンステートメントと豚のスクリプトを実行する方法,,en,このセクションでは、Pig Latin文とPigスクリプトを実行するいくつかの例を試します,,en,従業員はストレージからロードされます,,en

[コー​​ド]

/* Run Pig in local mode */

$ pig -x local

[/コー​​ド]

Mapreduce Mode: For mapreduce mode, you need to install Hadoop cluster and HDFS. It is the default mode, so you may not specify ‘-x’ flag.

Listing 2: Showing Pig running in mapreduce mode

[コー​​ド]

/* Run Pig in mapreduce mode – This is the default mode*/

$ pig

OR

$ pig -x mapreduce

[/コー​​ド]

In general Pig can be run by using interactive or batch mode. In interactive mode, ‘ Grunt’ shell is used to enter individual Pig Latin statements. And in batch mode, Pig Latin statements are put in a script file with (.pig) extension and run from command line. This is similar to SQL statements and scripts.

How to run Pig Latin statements and Pig script?

In this section we will try some examples to run Pig Latin statements and Pig scripts. In the following example, employees are loaded from the storage, 名前が抽出され、出力としてダンプされます,,en,豚の声明を表示する,,en,E = LOADの従業員,,en,N = FOREACH E GENERATEの名前,,en,ダンプN,,en,以下は出力です,,en,ニール,,en,同じタスクは、スクリプトファイルを使用して行うことができます,,en,example.pig,,en,コードスニペットは以下のとおりです,,en,豚のスクリプトを表示,,en,スクリプトの終わり,,en,pig -x local example.pig,,en,この記事では、PigがHadoopエコシステムとMapReduceプログラミングに基づいた非常に強力なスクリプト言語であることを確認しました,,en,分散環境で大量のデータを処理するために使用できます,,en,豚のステートメントとスクリプトはSQLステートメントに似ています,,en,開発者は根本的な仕組みにあまり集中することなく使用することができます,,en,Apache Pigは今後の進化を遂げ、より効率的なコンピューティングをサポートします,,en,続きを読む,,en,HadoopとBigデータの記事,,en,Apache PIG,,en.

Listing 3: Showing Pig statements

[コー​​ド]
grunt> E = LOAD ’employees’ USING PigStorage() AS (名前:chararray, 年齢:int型);

grunt> N = FOREACH E GENERATE name;

grunt> DUMP N;

[/コー​​ド]

Following is the output:

(ジョン)

(Nicholas)

(Dan)

(Neel)

Now, the same task can be done by using a script file (example.pig). The code snippet is shown below.

Listing 4: Showing Pig script

[コー​​ド]

/* example.pig */

E = LOAD ’employees’ USING PigStorage() AS (名前:chararray, 年齢:int型);

N = FOREACH E GENERATE name;

DUMP N;

/* End of script */

[/コー​​ド]

Now run the script file as shown below

[コー​​ド]

$ pig -x local example.pig

[/コー​​ド]

Following is the output:

(ジョン)

(Nicholas)

(Dan)

(Neel)



結論: In this article we have seen that Pig is a very powerful scripting language based on Hadoop eco-system and MapReduce programming. It can be used to process large volume of data in a distributed environment. Pig statements and scripts are similar to SQL statements, so developers can use it without focusing much on the underlying mechanism. Hope Apache Pig will evolve in coming days and support more efficient computing.

You may like to read How to process your data using Apache Pig?

Another interesting article for you Hadoop key terms, Simplified

Read More Hadoop and Big data articles

============================================= ============================================== Amazonで最高のTechAlpine Booksを購入してください,en,電気技師CT栗,en
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share