Return-Path: X-Original-To: apmail-pig-commits-archive@www.apache.org Delivered-To: apmail-pig-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 900CD10838 for ; Thu, 6 Mar 2014 00:29:45 +0000 (UTC) Received: (qmail 82706 invoked by uid 500); 6 Mar 2014 00:29:45 -0000 Delivered-To: apmail-pig-commits-archive@pig.apache.org Received: (qmail 82598 invoked by uid 500); 6 Mar 2014 00:29:44 -0000 Mailing-List: contact commits-help@pig.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pig.apache.org Delivered-To: mailing list commits@pig.apache.org Received: (qmail 82590 invoked by uid 99); 6 Mar 2014 00:29:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Mar 2014 00:29:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Mar 2014 00:29:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 37791238883D; Thu, 6 Mar 2014 00:29:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1574729 - in /pig/trunk: CHANGES.txt src/org/apache/pig/newplan/logical/relational/LogicalPlanData.java test/org/apache/pig/test/TestLogicalPlanBuilder.java Date: Thu, 06 Mar 2014 00:29:22 -0000 To: commits@pig.apache.org From: prkommireddi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140306002922.37791238883D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: prkommireddi Date: Thu Mar 6 00:29:21 2014 New Revision: 1574729 URL: http://svn.apache.org/r1574729 Log: PIG-3793: Provide info on number of LogicalRelationalOperator(s) used in the script through LogicalPlanData (prkommireddi) Modified: pig/trunk/CHANGES.txt pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlanData.java pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java Modified: pig/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1574729&r1=1574728&r2=1574729&view=diff ============================================================================== --- pig/trunk/CHANGES.txt (original) +++ pig/trunk/CHANGES.txt Thu Mar 6 00:29:21 2014 @@ -30,6 +30,8 @@ PIG-2207: Support custom counters for ag IMPROVEMENTS +PIG-3793: Provide info on number of LogicalRelationalOperator(s) used in the script through LogicalPlanData (prkommireddi) + PIG-3778: Log list of running jobs along with progress (rohini) PIG-3675: Documentation for AccumuloStorage (elserj via daijy) Modified: pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlanData.java URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlanData.java?rev=1574729&r1=1574728&r2=1574729&view=diff ============================================================================== --- pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlanData.java (original) +++ pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlanData.java Thu Mar 6 00:29:21 2014 @@ -18,44 +18,95 @@ package org.apache.pig.newplan.logical.relational; -import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import org.apache.pig.classification.InterfaceAudience; +import org.apache.pig.classification.InterfaceStability; import org.apache.pig.newplan.Operator; +import com.google.common.collect.Lists; + /** * - * This class provides information regarding the LogicalPlan. Make sure to - * avoid exposing LogicalPlan itself. Only data regarding the logical plan - * could be exposed but none of Pig internals (plans, operators etc) should - * be. - * + * This class provides information regarding the LogicalPlan. Make sure to avoid + * exposing LogicalPlan itself. Only data regarding the logical plan could be + * exposed but none of Pig internals (plans, operators etc) should be. + * */ +@InterfaceAudience.Public +@InterfaceStability.Evolving public class LogicalPlanData { // Never expose LogicalPlan private final LogicalPlan lp; + private int numLogicalRelationalOperators; + // Sources and Sinks here refer to Load and Store operators + private final List sources; + private final List sinks; public LogicalPlanData(LogicalPlan lp) { - if(lp == null) { + if (lp == null) { throw new RuntimeException("LogicalPlan is null."); } - this.lp = lp; + this.lp = lp; + this.numLogicalRelationalOperators = 0; + this.sources = Lists.newArrayList(); + this.sinks = Lists.newArrayList(); + init(); + } + + private void init() { + Iterator ops = this.lp.getOperators(); + + while (ops.hasNext()) { + Operator op = ops.next(); + if (op instanceof LogicalRelationalOperator) { + this.numLogicalRelationalOperators++; + if (op instanceof LOLoad) { + sources.add((LOLoad) op); + } else if (op instanceof LOStore) { + sinks.add((LOStore) op); + } + } + } } /** + * Returns the number of {@link LogicalRelationalOperator}s present in the + * pig script. + * + * @return number of logical relational operators (Load, Join, Store etc) * - * @return This method return the list of source paths defined - * in the script/query. */ - public List getSources() { - List sources = getLOLoads(); - if (sources == null) { - return null; - } + public int getNumLogicalRelationOperators() { + return this.numLogicalRelationalOperators; + } - List result = new ArrayList(); - for (LOLoad load : sources) { + /** + * + * @return number of Load statements in the script + */ + public int getNumSources() { + return this.sources.size(); + } + + /** + * + * @return number of Store statements in the script + */ + public int getNumSinks() { + return this.sinks.size(); + } + + /** + * + * @return This method return the list of Load paths defined in the + * script/query. + */ + public List getSources() { + List result = Lists.newArrayList(); + for (LOLoad load : this.sources) { result.add(load.getFileSpec().getFileName()); } @@ -67,12 +118,8 @@ public class LogicalPlanData { * @return This method returns the list of store paths in the script/query. */ public List getSinks() { - List sinks = getLOStores(); - if (sinks == null) { - return null; - } - List result = new ArrayList(); - for (LOStore sink : sinks) { + List result = Lists.newArrayList(); + for (LOStore sink : this.sinks) { result.add(sink.getFileSpec().getFileName()); } @@ -84,12 +131,8 @@ public class LogicalPlanData { * @return This method returns the list of LoadFunc(s) used. */ public List getLoadFuncs() { - List sources = getLOLoads(); - if (sources == null) { - return null; - } - List result = new ArrayList(); - for (LOLoad load : sources) { + List result = Lists.newArrayList(); + for (LOLoad load : this.sources) { result.add(load.getFileSpec().getFuncName()); } @@ -101,56 +144,11 @@ public class LogicalPlanData { * @return This method returns the list of StoreFunc(s) used. */ public List getStoreFuncs() { - List sinks = getLOStores(); - if (sinks == null) { - return null; - } - List storeFuncs = new ArrayList(); - for (LOStore sink : sinks) { + List storeFuncs = Lists.newArrayList(); + for (LOStore sink : this.sinks) { storeFuncs.add(sink.getFileSpec().getFuncName()); } return storeFuncs; } - - /** - * Internal to Pig. Do not expose this method - * @return - */ - private List getLOLoads() { - List sources = lp.getSources(); - if (sources == null) { - return null; - } - List result = new ArrayList(); - for (Operator source : sources) { - if (source instanceof LOLoad) { - LOLoad load = (LOLoad) source; - result.add(load); - } - } - - return result; - } - - /** - * Internal to Pig. Do not expose this method - * @return - */ - private List getLOStores() { - List sinks = lp.getSinks(); - if (sinks == null) { - return null; - } - List result = new ArrayList(); - for (Operator sink : sinks) { - if (sink instanceof LOStore) { - LOStore store = (LOStore) sink; - result.add(store); - } - } - - return result; - } - } Modified: pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=1574729&r1=1574728&r2=1574729&view=diff ============================================================================== --- pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java (original) +++ pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java Thu Mar 6 00:29:21 2014 @@ -2168,9 +2168,11 @@ public class TestLogicalPlanBuilder { LogicalPlanData lData = pigServer.getLogicalPlanData(); assertEquals("LoadFunc must be PigStorage", "org.apache.pig.builtin.PigStorage", lData.getLoadFuncs().get(0)); assertEquals("StoreFunc must be PigStorageWithSchema", "org.apache.pig.test.PigStorageWithSchema", lData.getStoreFuncs().get(0)); - assertEquals("Number of sources must be 2", lData.getSources().size(), 2); + assertEquals("Number of sources must be 2", lData.getNumSources(), 2); + assertEquals("Number of sinks must be 1", lData.getNumSinks(), 1); assertTrue("Source must end with input.txt", lData.getSources().get(0).endsWith("input.txt")); assertTrue("Sink must end with output", lData.getSinks().get(0).endsWith("output")); + assertEquals("Number of logical relational operators must be 4", lData.getNumLogicalRelationOperators(), 4); } /**