-
Notifications
You must be signed in to change notification settings - Fork 2.8k
ZEPPELIN-335: Apache Pig interpreter #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| layout: page | ||
| title: "Pig Interpreter" | ||
| description: "" | ||
| group: manual | ||
| --- | ||
| {% include JB/setup %} | ||
|
|
||
|
|
||
| ## Pig interpreter for Apache Zeppelin | ||
| [Apache Pig](https://pig.apache.org/) is a platform for analyzing large data sets that consists of a high-level language for expressing data analysis programs, coupled with infrastructure for evaluating these programs. The salient property of Pig programs is that their structure is amenable to substantial parallelization, which in turns enables them to handle very large data sets. | ||
|
|
||
| - Supported operations through Zeppelin | ||
| - Play button: Run multiple lines of pig latin (delimited by semi-colon) entered into Zeppelin cell | ||
| - Pause button: Cancel the exection of pig | ||
| - Output: Output of jobs are displayed in Zeppelin (for both jobs that were sucessful and those that failed) | ||
|
|
||
| - Unsupported operations | ||
| - Progress bar | ||
|
|
||
| ### How to setup Pig | ||
| Install Pig as you would normally do on the same node where Zeppelin is running - see [documentation](https://pig.apache.org/). If installing through Ambari, you just need to install the client on the Zeppelin node. | ||
|
|
||
| ### How to configure interpreter | ||
| At the "Interpreters" menu, you have to create a new Pig interpreter and provide next properties: | ||
|
|
||
| property | value | Description | ||
| ---------|----------|----- | ||
| executable | pig | Path to pig executable. If pig is part of PATH, then just pig will work | ||
| args | -useHCatalog -exectype local | Arguments to pass pig when starting. Launch 'pig -help' for list of supported options. For example, the options for exectype: local|mapreduce|tez | ||
| timeout | 600000 | Time (in milliseconds) to wait for pig job before timing out | ||
|
|
||
| ### How to test it's working | ||
|
|
||
| Run below example taken from [this tutorial](http://hortonworks.com/hadoop-tutorial/how-to-use-basic-pig-commands/) | ||
|
|
||
| ``` | ||
| %sh | ||
| rm -f infochimps_dataset_4778_download_16677-csv.zip | ||
| wget https://s3.amazonaws.com/hw-sandbox/tutorial1/infochimps_dataset_4778_download_16677-csv.zip -O /tmp/infochimps_dataset_4778_download_16677-csv.zip | ||
| unzip /tmp/infochimps_dataset_4778_download_16677-csv.zip -d /tmp | ||
| ``` | ||
| ``` | ||
| %pig | ||
| DIV_A = LOAD 'file:///tmp/infochimps_dataset_4778_download_16677/NYSE/NYSE_dividends_A.csv' using PigStorage(',') AS (exchange:chararray, symbol:chararray, date:chararray, dividend:float); | ||
| B = FILTER DIV_A BY symbol=='AZZ'; | ||
| C = GROUP B BY dividend; | ||
| dump C; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
| ~ contributor license agreements. See the NOTICE file distributed with | ||
| ~ this work for additional information regarding copyright ownership. | ||
| ~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| ~ (the "License"); you may not use this file except in compliance with | ||
| ~ the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <artifactId>zeppelin</artifactId> | ||
| <groupId>org.apache.zeppelin</groupId> | ||
| <version>0.6.0-incubating-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <groupId>org.apache.zeppelin</groupId> | ||
| <artifactId>zeppelin-pig</artifactId> | ||
| <packaging>jar</packaging> | ||
| <version>0.6.0-incubating-SNAPSHOT</version> | ||
| <name>Zeppelin: Apache Pig Interpreter</name> | ||
| <description>Zeppelin interprter for Apache Pig</description> | ||
| <url>http://zeppelin.incubator.apache.org</url> | ||
|
|
||
| <properties> | ||
| <pig.version>0.15.0</pig.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.zeppelin</groupId> | ||
| <artifactId>zeppelin-interpreter</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.pig</groupId> | ||
| <artifactId>pig</artifactId> | ||
| <version>${pig.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.commons</groupId> | ||
| <artifactId>commons-io</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-all</artifactId> | ||
| <version>1.9.5</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.mockrunner</groupId> | ||
| <artifactId>mockrunner-jdbc</artifactId> | ||
| <version>1.0.8</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-deploy-plugin</artifactId> | ||
| <version>2.7</version> | ||
| <configuration> | ||
| <skip>true</skip> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <artifactId>maven-enforcer-plugin</artifactId> | ||
| <version>1.3.1</version> | ||
| <executions> | ||
| <execution> | ||
| <id>enforce</id> | ||
| <phase>none</phase> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| <version>2.8</version> | ||
| <executions> | ||
| <execution> | ||
| <id>copy-dependencies</id> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>copy-dependencies</goal> | ||
| </goals> | ||
| <configuration> | ||
| <outputDirectory>${project.build.directory}/../../interpreter/pig</outputDirectory> | ||
| <overWriteReleases>false</overWriteReleases> | ||
| <overWriteSnapshots>false</overWriteSnapshots> | ||
| <overWriteIfNewer>true</overWriteIfNewer> | ||
| <includeScope>runtime</includeScope> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>copy-artifact</id> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>copy</goal> | ||
| </goals> | ||
| <configuration> | ||
| <outputDirectory>${project.build.directory}/../../interpreter/pig</outputDirectory> | ||
| <overWriteReleases>false</overWriteReleases> | ||
| <overWriteSnapshots>false</overWriteSnapshots> | ||
| <overWriteIfNewer>true</overWriteIfNewer> | ||
| <includeScope>runtime</includeScope> | ||
| <artifactItems> | ||
| <artifactItem> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>${project.artifactId}</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>${project.packaging}</type> | ||
| </artifactItem> | ||
| </artifactItems> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
|
|
||
| </plugins> | ||
| </build> | ||
| </project> |
156 changes: 156 additions & 0 deletions
156
pig/src/main/java/org/apache/zeppelin/pig/PigInterpreter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.zeppelin.pig; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
| import java.util.Arrays; | ||
| import org.apache.commons.exec.CommandLine; | ||
| import org.apache.commons.exec.DefaultExecutor; | ||
| import org.apache.commons.exec.ExecuteException; | ||
| import org.apache.commons.exec.ExecuteWatchdog; | ||
| import org.apache.commons.exec.PumpStreamHandler; | ||
| import org.apache.zeppelin.interpreter.Interpreter; | ||
| import org.apache.zeppelin.interpreter.InterpreterContext; | ||
| import org.apache.zeppelin.interpreter.InterpreterResult; | ||
| import org.apache.zeppelin.interpreter.InterpreterResult.Code; | ||
| import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder; | ||
| import org.apache.zeppelin.scheduler.Scheduler; | ||
| import org.apache.zeppelin.scheduler.SchedulerFactory; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Pig interpreter for Zeppelin. | ||
| * Closely follows code for shell interpreter | ||
| */ | ||
| public class PigInterpreter extends Interpreter { | ||
| Logger logger = LoggerFactory.getLogger(PigInterpreter.class); | ||
|
|
||
| private static final String NEWLINE = "\n"; | ||
|
|
||
| //Executable name used to start grunt shell | ||
| public static final String PIG_START_EXE = "pig.executable"; | ||
| public static final String DEFAULT_START_EXE = "pig"; | ||
|
|
||
| //Arguments to start pig with. More details available via 'pig -help' | ||
| public static final String PIG_START_ARGS = "pig.start.args"; | ||
| public static final String DEFAULT_START_ARGS = "-useHCatalog -exectype local"; | ||
|
|
||
| //How long to wait before timing out (ms) | ||
| public static final String PIG_TIMEOUT_MS = "pig.timeout.ms"; | ||
| public static final String DEFAULT_TIMEOUT_MS = "600000"; | ||
|
|
||
| DefaultExecutor executor = null; | ||
| static { | ||
| Interpreter.register( | ||
| "pig", | ||
| "pig", | ||
| PigInterpreter.class.getName(), | ||
| new InterpreterPropertyBuilder() | ||
| .add(PIG_START_EXE, DEFAULT_START_EXE, "Pig executable used to start grunt shell") | ||
| .add(PIG_START_ARGS, DEFAULT_START_ARGS, "Starting arguments") | ||
| .add(PIG_TIMEOUT_MS, DEFAULT_TIMEOUT_MS, "Timeout (ms)") | ||
| .build() | ||
| ); | ||
| } | ||
|
|
||
| public PigInterpreter(Properties property) { | ||
| super(property); | ||
| } | ||
|
|
||
| @Override | ||
| public void open() {} | ||
|
|
||
| @Override | ||
| public void close() {} | ||
|
|
||
|
|
||
| @Override | ||
| public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { | ||
| // use commandline to store string corresponding to pig shell command | ||
| // start with pig exectable name (or full path if provided)... | ||
| CommandLine cmdLine = CommandLine.parse(getProperty(PIG_START_EXE).trim()); | ||
|
|
||
| // ...add any CLI arguments specified by user in interpreter settings | ||
| String startArgs = getProperty(PIG_START_ARGS).trim(); | ||
| if (startArgs.length() > 0){ | ||
| logger.info("Start arguments passed to pig: " + startArgs); | ||
| List<String> argList = Arrays.asList(startArgs.split("\\s+")); | ||
| for (String arg : argList) { | ||
| cmdLine.addArgument(arg, false); | ||
| } | ||
| } | ||
| // ...finally add contents of pig cell after the -e flag | ||
| logger.info("Run pig command '" + cmd + "'"); | ||
| long start = System.currentTimeMillis(); | ||
| cmdLine.addArgument("-e", false); | ||
| cmdLine.addArgument(cmd, false); | ||
|
|
||
| // execute command and return success/failure based on its exit value | ||
| executor = new DefaultExecutor(); | ||
| ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
| executor.setStreamHandler(new PumpStreamHandler(outputStream)); | ||
|
|
||
| int commandTimeOut = Integer.parseInt(getProperty(PIG_TIMEOUT_MS)); | ||
| executor.setWatchdog(new ExecuteWatchdog(commandTimeOut)); | ||
| try { | ||
| int exitValue = executor.execute(cmdLine); | ||
| return new InterpreterResult(InterpreterResult.Code.SUCCESS, outputStream.toString()); | ||
| } catch (ExecuteException e) { | ||
| logger.error("Can not run " + cmd, e); | ||
| return new InterpreterResult(Code.ERROR, e.getMessage() + NEWLINE + outputStream.toString()); | ||
| } catch (IOException e) { | ||
| logger.error("Can not run " + cmd, e); | ||
| return new InterpreterResult(Code.ERROR, e.getMessage() + NEWLINE + outputStream.toString()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void cancel(InterpreterContext context) { | ||
| if (executor != null) { | ||
| executor.getWatchdog().destroyProcess(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public FormType getFormType() { | ||
| return FormType.SIMPLE; | ||
| } | ||
|
|
||
| @Override | ||
| public int getProgress(InterpreterContext context) { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Scheduler getScheduler() { | ||
| return SchedulerFactory.singleton().createOrGetFIFOScheduler( | ||
| PigInterpreter.class.getName() + this.hashCode()); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> completion(String buf, int cursor) { | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to add task cancel\progress indicator\completion later on? Otherwise we better explicitly document the supported features, as users might expect this behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these could take a while to run it might be important to have some sort of progress indicator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the feedback. Updated as below:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the CI Test failed because pig is probably not installed on the test env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could update the travis script to pull that from some where else...