Review Board 1.7.22


Introduce a syntax making declared aliases optional

Review Request #9496 - Created Feb. 18, 2013 and updated

Jonathan Coveney
jcoveney/PIG3136
PIG-3136
Reviewers
pig
daijy, gates
pig-git
https://issues.apache.org/jira/browse/PIG-3136
ant -Dtestcase=TestBuiltin test, and ant test-commit

I made them TestBuiltin use it
src/org/apache/pig/PigServer.java
Revision a46cc2a New Change
[20] 193 lines
[+20] [+] private String constructScope() {
194
    }
194
    }
195

    
   
195

   
196
    public PigServer(ExecType execType, Properties properties) throws ExecException {
196
    public PigServer(ExecType execType, Properties properties) throws ExecException {
197
        this(new PigContext(execType, properties));
197
        this(new PigContext(execType, properties));
198
    }
198
    }
199
    
199

   
200
    public PigServer(ExecType execType, Configuration conf) throws ExecException {
200
    public PigServer(ExecType execType, Configuration conf) throws ExecException {
201
        this(new PigContext(execType, conf));
201
        this(new PigContext(execType, conf));
202
    }
202
    }
203

    
   
203

   
204
    public PigServer(PigContext context) throws ExecException {
204
    public PigServer(PigContext context) throws ExecException {
[+20] [20] 558 lines
[+20] [+] public void printAliases () throws FrontendException {
763
     * @return Schema of alias dumped
763
     * @return Schema of alias dumped
764
     * @throws IOException
764
     * @throws IOException
765
     */
765
     */
766
    public Schema dumpSchema(String alias) throws IOException {
766
    public Schema dumpSchema(String alias) throws IOException {
767
        try {
767
        try {

    
   
768
        	if ("@".equals(alias)) {

    
   
769
                alias = getLastRel();

    
   
770
            }
768
            LogicalRelationalOperator op = getOperatorForAlias( alias );
771
            LogicalRelationalOperator op = getOperatorForAlias( alias );
769
            LogicalSchema schema = op.getSchema();
772
            LogicalSchema schema = op.getSchema();
770

    
   
773

   
771
            boolean pretty = "true".equals(pigContext.getProperties()
774
            boolean pretty = "true".equals(pigContext.getProperties()
772
                                   .getProperty(PRETTY_PRINT_SCHEMA_PROPERTY));
775
                                   .getProperty(PRETTY_PRINT_SCHEMA_PROPERTY));
[+20] [20] 21 lines
[+20] public Schema dumpSchema(String alias) throws IOException {
794
     * @param nestedAlias Alias whose schema will be written out
797
     * @param nestedAlias Alias whose schema will be written out
795
     * @return Schema of alias dumped
798
     * @return Schema of alias dumped
796
     * @throws IOException
799
     * @throws IOException
797
     */
800
     */
798
    public Schema dumpSchemaNested(String alias, String nestedAlias) throws IOException {
801
    public Schema dumpSchemaNested(String alias, String nestedAlias) throws IOException {

    
   
802
    	if ("@".equals(alias)) {

    
   
803
            alias = getLastRel();

    
   
804
        }
799
        Operator op = getOperatorForAlias( alias );
805
        Operator op = getOperatorForAlias( alias );
800
        if( op instanceof LOForEach ) {
806
        if( op instanceof LOForEach ) {
801
            LogicalSchema nestedSc = ((LOForEach)op).dumpNestedSchema(alias, nestedAlias);
807
            LogicalSchema nestedSc = ((LOForEach)op).dumpNestedSchema(alias, nestedAlias);
802
            if (nestedSc!=null) {
808
            if (nestedSc!=null) {
803
                Schema s = org.apache.pig.newplan.logical.Util.translateSchema(nestedSc);
809
                Schema s = org.apache.pig.newplan.logical.Util.translateSchema(nestedSc);
[+20] [20] 163 lines
[+20] [+] public ExecJob store(String id, String filename, String func)
967
        }
973
        }
968
    }
974
    }
969

    
   
975

   
970
    private PigStats storeEx(String alias, String filename, String func)
976
    private PigStats storeEx(String alias, String filename, String func)
971
    throws IOException {
977
    throws IOException {

    
   
978
        if ("@".equals(alias)) {

    
   
979
            alias = getLastRel();

    
   
980
        }
972
        currDAG.parseQuery();
981
        currDAG.parseQuery();
973
        currDAG.buildPlan( alias );
982
        currDAG.buildPlan( alias );
974

    
   
983

   
975
        try {
984
        try {
976
            QueryParserUtils.attachStorePlan(scope, currDAG.lp, filename, func, currDAG.getOperator( alias ), alias, pigContext);
985
            QueryParserUtils.attachStorePlan(scope, currDAG.lp, filename, func, currDAG.getOperator( alias ), alias, pigContext);
[+20] [20] 410 lines
[+20] [+] private LogicalRelationalOperator getOperatorForAlias(String alias) throws IOException {
1387
    protected class Graph {
1396
    protected class Graph {
1388

    
   
1397

   
1389
        private final Map<LogicalRelationalOperator, LogicalPlan> aliases = new HashMap<LogicalRelationalOperator, LogicalPlan>();
1398
        private final Map<LogicalRelationalOperator, LogicalPlan> aliases = new HashMap<LogicalRelationalOperator, LogicalPlan>();
1390

    
   
1399

   
1391
        private Map<String, Operator> operators = new HashMap<String, Operator>();
1400
        private Map<String, Operator> operators = new HashMap<String, Operator>();

    
   
1401
        private String lastRel;
1392

    
   
1402

   
1393
        private final List<String> scriptCache = new ArrayList<String>();
1403
        private final List<String> scriptCache = new ArrayList<String>();
1394

    
   
1404

   
1395
        // the fileNameMap contains filename to canonical filename
1405
        // the fileNameMap contains filename to canonical filename
1396
        // mappings. This is done so we can reparse the cached script
1406
        // mappings. This is done so we can reparse the cached script
[+20] [20] 250 lines
[+20] [+] private void parseQuery() throws FrontendException {
1647

    
   
1657

   
1648
            try {
1658
            try {
1649
                QueryParserDriver parserDriver = new QueryParserDriver( pigContext, scope, fileNameMap );
1659
                QueryParserDriver parserDriver = new QueryParserDriver( pigContext, scope, fileNameMap );
1650
                lp = parserDriver.parse( query );
1660
                lp = parserDriver.parse( query );
1651
                operators = parserDriver.getOperators();
1661
                operators = parserDriver.getOperators();

    
   
1662
                lastRel = parserDriver.getLastRel();
1652
            } catch(Exception ex) {
1663
            } catch(Exception ex) {
1653
                scriptCache.remove( scriptCache.size() -1 ); // remove the bad script from the cache.
1664
                scriptCache.remove( scriptCache.size() -1 ); // remove the bad script from the cache.
1654
                PigException pe = LogUtils.getPigException(ex);
1665
                PigException pe = LogUtils.getPigException(ex);
1655
                int errCode = 1000;
1666
                int errCode = 1000;
1656
                String msg = "Error during parsing. "
1667
                String msg = "Error during parsing. "
1657
                        + (pe == null ? ex.getMessage() : pe.getMessage());
1668
                        + (pe == null ? ex.getMessage() : pe.getMessage());
1658
                throw new FrontendException (msg, errCode, PigException.INPUT , ex );
1669
                throw new FrontendException (msg, errCode, PigException.INPUT , ex );
1659
            }
1670
            }
1660
        }
1671
        }
1661

    
   
1672

   

    
   
1673
        public String getLastRel() {

    
   
1674
            return lastRel;

    
   
1675
        }

    
   
1676

   
1662
        private String buildQuery() {
1677
        private String buildQuery() {
1663
            StringBuilder accuQuery = new StringBuilder();
1678
            StringBuilder accuQuery = new StringBuilder();
1664
            for( String line : scriptCache ) {
1679
            for( String line : scriptCache ) {
1665
                accuQuery.append( line + "\n" );
1680
                accuQuery.append( line + "\n" );
1666
            }
1681
            }
[+20] [20] 147 lines
[+20] [+] protected Graph duplicate() {
1814
     * @param validateEachStatement
1829
     * @param validateEachStatement
1815
     */
1830
     */
1816
    public void setValidateEachStatement(boolean validateEachStatement) {
1831
    public void setValidateEachStatement(boolean validateEachStatement) {
1817
        this.validateEachStatement = validateEachStatement;
1832
        this.validateEachStatement = validateEachStatement;
1818
    }
1833
    }

    
   
1834

   

    
   
1835
    public String getLastRel() {

    
   
1836
        return currDAG.getLastRel();

    
   
1837
    }
1819
}
1838
}
src/org/apache/pig/parser/LogicalPlanBuilder.java
Revision b705686 New Change
 
src/org/apache/pig/parser/LogicalPlanGenerator.g
Revision 01dc570 New Change
 
src/org/apache/pig/parser/QueryLexer.g
Revision bdd0836 New Change
 
src/org/apache/pig/parser/QueryParser.g
Revision ba2fec9 New Change
 
src/org/apache/pig/parser/QueryParserDriver.java
Revision a250b73 New Change
 
src/org/apache/pig/tools/grunt/GruntParser.java
Revision 2658466 New Change
 
src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
Revision 109a3b2 New Change
 
test/org/apache/pig/test/TestBuiltin.java
Revision 9c5d408 New Change
 
test/org/apache/pig/test/TestShortcuts.java
Revision 7d66ef7 New Change
 
  1. src/org/apache/pig/PigServer.java: Loading...
  2. src/org/apache/pig/parser/LogicalPlanBuilder.java: Loading...
  3. src/org/apache/pig/parser/LogicalPlanGenerator.g: Loading...
  4. src/org/apache/pig/parser/QueryLexer.g: Loading...
  5. src/org/apache/pig/parser/QueryParser.g: Loading...
  6. src/org/apache/pig/parser/QueryParserDriver.java: Loading...
  7. src/org/apache/pig/tools/grunt/GruntParser.java: Loading...
  8. src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj: Loading...
  9. test/org/apache/pig/test/TestBuiltin.java: Loading...
  10. test/org/apache/pig/test/TestShortcuts.java: Loading...