Author: gates
Date: Fri May 16 14:21:14 2008
New Revision: 657216

URL: http://svn.apache.org/viewvc?rev=657216&view=rev
Log:
PIG-159 Santhosh's parser v8 patch.


Modified:
    incubator/pig/branches/types/build.xml
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/ExpressionOperator.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOBinCond.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCross.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOGenerate.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOMapLookup.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogicalPlanBuilder.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java
    
incubator/pig/branches/types/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
    incubator/pig/branches/types/test/org/apache/pig/test/TestGrunt.java
    
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java

Modified: incubator/pig/branches/types/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/build.xml?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- incubator/pig/branches/types/build.xml (original)
+++ incubator/pig/branches/types/build.xml Fri May 16 14:21:14 2008
@@ -141,7 +141,7 @@
                    
**/test/TestGTOrEqual.java,**/test/TestLessThan.java,**/test/TestLTOrEqual.java,
                    **/test/TestEqualTo.java,**/test/TestNotEqualTo.java, 
**/test/TestPOGenerate.java,
                 **/test/TestProject.java, **/test/TestLoad.java, 
**/test/TestStore.java,
-                 **/test/FakeFSOutputStream.java, **/test/TestPackage.java, 
**/test/TestForEach.java,
+                **/test/FakeFSOutputStream.java, **/test/TestPackage.java, 
**/test/TestForEach.java,
                        **/test/TestLocalRearrange.java, 
**/test/TestPOUserFunc.java,
                        **/test/TestPODistinct.java, **/test/TestPOSort.java,
                        **/test/TestSchema.java, 
**/test/TestLogicalPlanBuilder.java,**/test/TestUnion.java, 
**/test/TestMRCompiler.java,
@@ -155,7 +155,8 @@
                 **/physicalLayer/POStatus.java, **/bzip2r/*.java,
                 **/validators/*.java , 
**/test/TestInputOutputFileValidator.java ,
                                **/test/TestTypeCheckingValidator.java, 
-                **/backend/executionengine/ExecException.java"
+                **/backend/executionengine/ExecException.java,
+                **/tools/grunt/*.java, **/test/TestGrunt.java"
             destdir="${dist}" debug="${javac.debug}" 
optimize="${javac.optimize}" target="${javac.version}" 
source="${javac.version}" deprecation="${javac.deprecation}">
             <compilerarg line="${javac.args} ${javac.args.warnings}" />
             <classpath refid="${cp}" />
@@ -276,10 +277,11 @@
                        <include name="**/TestTypeCheckingValidator.java" /> 
                        <include name="**/TestSchema.java" /> 
                        <include name="**/TestLogicalPlanBuilder.java" />
-                       <include name="**/TestLocalJobSubmission.java" />
+                    <include name="**/TestLocalJobSubmission.java" />
                        <include name="**/TestPOMapLookUp.java" />
                        <include name="**/TestPOBinCond.java" />
                        <include name="**/TestPONegative.java" />
+                       <include name="**/TestGrunt.java" />
                     <!--
                     <include name="**/*Test*.java" />
                     <exclude name="**/TestLargeFile.java" />

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/ExpressionOperator.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/ExpressionOperator.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/ExpressionOperator.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/ExpressionOperator.java
 Fri May 16 14:21:14 2008
@@ -85,31 +85,33 @@
     public final void setFieldSchema(Schema.FieldSchema fs) throws 
FrontendException {
         // In general, operators don't generate their schema until they're
         // asked, so ask them to do it.
-        log.debug("Inside setFieldSchema");
+               log.debug("Inside setFieldSchema");
         try {
             getFieldSchema();
         } catch (FrontendException fee) {
             // It's fine, it just means we don't have a schema yet.
         }
-        log.debug("After getFieldSchema()");
+               log.debug("After getFieldSchema()");
         if (null == mFieldSchema) {
             log.debug("Operator schema is null; Setting it to new schema");
             mFieldSchema = fs;
         } else {
             log.debug("Reconciling schema");
-            log.debug("mFieldSchema: " + mFieldSchema + " fs: " + fs);
+                       log.debug("mFieldSchema: " + mFieldSchema + " fs: " + 
fs);
             //log.debug("mSchema: " + mSchema + " schema: " + schema);
-            try {
-                if(null != mFieldSchema.schema) {
-                    mFieldSchema.schema.reconcile(fs.schema);
-                } else {
-                    mFieldSchema.schema = fs.schema;
-                }
-                mFieldSchema.type = fs.type;
-                mFieldSchema.alias = fs.alias;
-            } catch (ParseException pe) {
-                throw new FrontendException(pe.getMessage());
-            }
+                       try {
+                               if(null != mFieldSchema.schema) {
+                       mFieldSchema.schema.reconcile(fs.schema);
+                               } else {
+                                       mFieldSchema.schema = fs.schema;
+                               }
+                               mFieldSchema.type = fs.type;
+                               mFieldSchema.alias = fs.alias;
+                               //the operator name is the name of the column 
being projected
+                               setAlias(fs.alias);
+                       } catch (ParseException pe) {
+                               throw new FrontendException(pe.getMessage());
+                       }
         }
     }
 

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOBinCond.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOBinCond.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOBinCond.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOBinCond.java
 Fri May 16 14:21:14 2008
@@ -84,15 +84,15 @@
         v.visit(this);
     }
 
-    @Override
-    public Schema getSchema() throws FrontendException {
-        return mSchema;
-    }
+       @Override
+       public Schema getSchema() throws FrontendException {
+               return mSchema;
+       }
 
     @Override
     public Schema.FieldSchema getFieldSchema() throws FrontendException {
-        //TODO
-        //We need a check of LHS and RHS schemas
+               //TODO
+               //We need a check of LHS and RHS schemas
         if (!mIsFieldSchemaComputed && (null == mFieldSchema)) {
             try {
                 mFieldSchema = mLhsOp.getFieldSchema();

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
 Fri May 16 14:21:14 2008
@@ -234,20 +234,6 @@
                 byte groupByType = groupByFss.get(0).type;
                 Schema groupSchema = groupByFss.get(0).schema;
                 log.debug("Type == " + DataType.findTypeName(groupByType));
-                /*
-                if(DataType.TUPLE == groupByType || DataType.BAG == 
groupByType) { 
-                    if(null != groupSchema) {
-                        Schema innerSchema = 
groupSchema.getFields().get(0).schema;
-                        fss.add(new Schema.FieldSchema("group", innerSchema, 
groupByType));
-                        log.debug("Printing the aliases of the single group by 
column");
-                        groupSchema.printAliases();
-                    } else {
-                        fss.add(new Schema.FieldSchema("group", groupSchema, 
groupByType));
-                    }
-                } else {
-                    fss.add(new Schema.FieldSchema("group", groupByType));
-                }
-                */
                 fss.add(new Schema.FieldSchema("group", groupSchema, 
groupByType));
             } else {
                 fss.add(new Schema.FieldSchema("group", groupBySchema));

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCross.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCross.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCross.java 
(original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCross.java 
Fri May 16 14:21:14 2008
@@ -89,13 +89,13 @@
                             Integer count;
                             count = aliases.get(fs.alias);
                             if(null == count) {
-                                aliases.put(fs.alias, 0);
+                                aliases.put(fs.alias, 1);
                             } else {
                                 aliases.put(fs.alias, ++count);
                             }
                             count = aliases.get(disambiguatorAlias);
                             if(null == count) {
-                                aliases.put(disambiguatorAlias, 0);
+                                aliases.put(disambiguatorAlias, 1);
                             } else {
                                 aliases.put(disambiguatorAlias, ++count);
                             }
@@ -126,7 +126,7 @@
             Set<String> duplicateAliases = new HashSet<String>();
             for(String alias: aliases.keySet()) {
                 Integer count = aliases.get(alias);
-                if(count > 0) {
+                if(count > 1) {
                     Boolean inFlatten = false;
                     log.debug("inFlatten: " + inFlatten + " 
inverseFlattenAlias: " + inverseFlattenAlias);
                     inFlatten = inverseFlattenAlias.get(alias);
@@ -153,9 +153,9 @@
             for(Schema.FieldSchema fs: mSchema.getFields()) {
                 String alias = flattenAlias.get(fs);
                 Integer count = aliases.get(alias);
-                if (null == count) count = 0;
+                if (null == count) count = 1;
                 log.debug("alias: " + alias);
-                if((null != alias) && (count == 0)) {
+                if((null != alias) && (count == 1)) {
                     mSchema.addAlias(alias, fs);
                 }
             }

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOGenerate.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOGenerate.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOGenerate.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOGenerate.java
 Fri May 16 14:21:14 2008
@@ -129,123 +129,129 @@
                 LogicalPlan plan = mGeneratePlans.get(planCtr);
                 LogicalOperator op = plan.getLeaves().get(0);
                 log.debug("op: " + op.getClass().getName() + " " + op);
-                //Set<String> aliases;
-                //Iterator<String> iter = null;
-                //String opSchemaAlias = null;
-                //Schema s = null;
                 Schema.FieldSchema planFs;
 
                 try {
-                    planFs = ((ExpressionOperator)op).getFieldSchema();
-                    if(null != planFs) {
-                        log.debug("planFs alias: " + planFs.alias);
-                        if(mFlatten.get(planCtr)) {
-                            //need to extract the children and create the 
aliases
-                            //assumption here is that flatten is only for one 
column
-                            //i.e., flatten(A), flatten(A.x) and NOT
-                            //flatten(B.(x,y,z))
-                            Schema s = planFs.schema;
-                            if(null != s) {
-                                for(Schema.FieldSchema fs: s.getFields()) {
-                                    log.debug("fs: " + fs);
-                                    log.debug("fs.alias: " + fs.alias);
-                                    if(null != fs.alias) {
-                                        String disambiguatorAlias = 
planFs.alias + "::" + fs.alias;
-                                        Schema.FieldSchema newFs = new 
Schema.FieldSchema(disambiguatorAlias, fs.schema, fs.type);
-                                        fss.add(newFs);
-                                        Integer count;
-                                        count = aliases.get(fs.alias);
-                                        if(null == count) {
-                                            aliases.put(fs.alias, 0);
-                                        } else {
-                                            aliases.put(fs.alias, ++count);
-                                        }
-                                        count = 
aliases.get(disambiguatorAlias);
-                                        if(null == count) {
-                                            aliases.put(disambiguatorAlias, 0);
-                                        } else {
-                                            aliases.put(disambiguatorAlias, 
++count);
-                                        }
-                                        flattenAlias.put(newFs, fs.alias);
-                                        inverseFlattenAlias.put(fs.alias, 
true);
-                                        //it's fine if there are duplicates
-                                        //we just need to record if its due to
-                                        //flattening
-                                    } else {
-                                        Schema.FieldSchema newFs = new 
Schema.FieldSchema(null, DataType.BYTEARRAY);
-                                        fss.add(newFs);
-                                    }
-                                }
-                            } else {
-                                Schema.FieldSchema newFs = new 
Schema.FieldSchema(null, DataType.BYTEARRAY);
-                                fss.add(newFs);
-                            }
-                        } else {
-                            //just populate the schema with the field schema 
of the expression operator
-                               fss.add(planFs);
-                            if(null != planFs.alias) {
-                                Integer count = aliases.get(planFs.alias);
-                                if(null == count) {
-                                    aliases.put(planFs.alias, 0);
-                                } else {
-                                    aliases.put(planFs.alias, ++count);
-                                }
-                            }
-                        }
-                    } else {
-                        //did not get a valid list of field schemas
-                        fss.add(new Schema.FieldSchema(null, 
DataType.BYTEARRAY));
-                    }
+                       planFs = ((ExpressionOperator)op).getFieldSchema();
+                                       if(null != planFs) {
+                                               String outerCanonicalAlias = 
op.getAlias();
+                                               if(null == outerCanonicalAlias) 
{
+                                                       outerCanonicalAlias = 
planFs.alias;
+                                               }
+                                               log.debug("Outer canonical 
alias: " + outerCanonicalAlias);
+                                               if(mFlatten.get(planCtr)) {
+                                                       //need to extract the 
children and create the aliases
+                                                       //assumption here is 
that flatten is only for one column
+                                                       //i.e., flatten(A), 
flatten(A.x) and NOT
+                                                       //flatten(B.(x,y,z))
+                                                       Schema s = 
planFs.schema;
+                                                       if(null != s) {
+                                                               
for(Schema.FieldSchema fs: s.getFields()) {
+                                                                       
log.debug("fs: " + fs);
+                                                                       
log.debug("fs.alias: " + fs.alias);
+                                                                       String 
innerCanonicalAlias = fs.alias;
+                                                                       
if((null != outerCanonicalAlias) && (null != innerCanonicalAlias)) {
+                                                                               
String disambiguatorAlias = outerCanonicalAlias + "::" + innerCanonicalAlias;
+                                                                               
Schema.FieldSchema newFs = new Schema.FieldSchema(disambiguatorAlias, 
fs.schema, fs.type);
+                                                                               
fss.add(newFs);
+                                                                               
Integer count;
+                                                                               
count = aliases.get(innerCanonicalAlias);
+                                                                               
if(null == count) {
+                                                                               
        aliases.put(innerCanonicalAlias, 1);
+                                                                               
} else {
+                                                                               
        aliases.put(innerCanonicalAlias, ++count);
+                                                                               
}
+                                                                               
count = aliases.get(disambiguatorAlias);
+                                                                               
if(null == count) {
+                                                                               
        aliases.put(disambiguatorAlias, 1);
+                                                                               
} else {
+                                                                               
        aliases.put(disambiguatorAlias, ++count);
+                                                                               
}
+                                                                               
flattenAlias.put(newFs, innerCanonicalAlias);
+                                                                               
inverseFlattenAlias.put(innerCanonicalAlias, true);
+                                                                               
//it's fine if there are duplicates
+                                                                               
//we just need to record if its due to
+                                                                               
//flattening
+                                                                       } else {
+                                                                               
Schema.FieldSchema newFs = new Schema.FieldSchema(null, DataType.BYTEARRAY);
+                                                                               
fss.add(newFs);
+                                                                       }
+                                                               }
+                                                       } else {
+                                                               
Schema.FieldSchema newFs = new Schema.FieldSchema(null, DataType.BYTEARRAY);
+                                                               fss.add(newFs);
+                                                       }
+                                               } else {
+                                                       //just populate the 
schema with the field schema of the expression operator
+                                       fss.add(planFs);
+                                                       if(null != 
outerCanonicalAlias) {
+                                                               Integer count = 
aliases.get(outerCanonicalAlias);
+                                                               if(null == 
count) {
+                                                                       
aliases.put(outerCanonicalAlias, 1);
+                                                               } else {
+                                                                       
aliases.put(outerCanonicalAlias, ++count);
+                                                               }
+                                                       }
+                                               }
+                                       } else {
+                                               //did not get a valid list of 
field schemas
+                                               fss.add(new 
Schema.FieldSchema(null, DataType.BYTEARRAY));
+                                       }
                 } catch (FrontendException fee) {
                     mSchema = null;
                     mIsSchemaComputed = false;
                     throw fee;
                 }
             }
-            //check for duplicate column names and throw an error if there are 
duplicates
-            //ensure that flatten gets rid of duplicate column names when the 
checks are
-            //being done
-            log.debug(" flattenAlias: " + flattenAlias);
-            log.debug(" inverseFlattenAlias: " + inverseFlattenAlias);
-            log.debug(" aliases: " + aliases);
-            log.debug(" fss.size: " + fss.size());
-            boolean duplicates = false;
-            Set<String> duplicateAliases = new HashSet<String>();
-            for(String alias: aliases.keySet()) {
-                Integer count = aliases.get(alias);
-                if(count > 0) {
-                    Boolean inFlatten = false;
-                    log.debug("inFlatten: " + inFlatten + " 
inverseFlattenAlias: " + inverseFlattenAlias);
-                    inFlatten = inverseFlattenAlias.get(alias);
-                    log.debug("inFlatten: " + inFlatten + " 
inverseFlattenAlias: " + inverseFlattenAlias);
-                    if((null != inFlatten) && (!inFlatten)) {
-                        duplicates = true;
-                        duplicateAliases.add(alias);
-                    }
-                }
-            }
-            if(duplicates) {
-                String errMessage = "Found duplicates in schema ";
-                if(duplicateAliases.size() > 0) {
-                    Iterator<String> iter = duplicateAliases.iterator();
-                    errMessage += ": " + iter.next();
-                    while(iter.hasNext()) {
-                        errMessage += ", " + iter.next();
-                    }
-                }
-                throw new FrontendException(errMessage);
-            }
+                       //check for duplicate column names and throw an error 
if there are duplicates
+                       //ensure that flatten gets rid of duplicate column 
names when the checks are
+                       //being done
+                       log.debug(" flattenAlias: " + flattenAlias);
+                       log.debug(" inverseFlattenAlias: " + 
inverseFlattenAlias);
+                       log.debug(" aliases: " + aliases);
+                       log.debug(" fss.size: " + fss.size());
+                       boolean duplicates = false;
+                       Map<String, Integer> duplicateAliases = new 
HashMap<String, Integer>();
+                       for(String alias: aliases.keySet()) {
+                               Integer count = aliases.get(alias);
+                               if(count > 1) {//not checking for null here as 
counts are intitalized to 1
+                                       Boolean inFlatten = false;
+                                       log.debug("inFlatten: " + inFlatten + " 
inverseFlattenAlias: " + inverseFlattenAlias);
+                                       inFlatten = 
inverseFlattenAlias.get(alias);
+                                       log.debug("inFlatten: " + inFlatten + " 
inverseFlattenAlias: " + inverseFlattenAlias);
+                                       if((null == inFlatten) || (!inFlatten)) 
{
+                                               duplicates = true;
+                                               duplicateAliases.put(alias, 
count);
+                                       }
+                               }
+                       }
+                       if(duplicates) {
+                               String errMessage = "Found duplicates in 
schema! ";
+                               if(duplicateAliases.size() > 0) {
+                                       Set<String> duplicateCols = 
duplicateAliases.keySet();
+                                       Iterator<String> iter = 
duplicateCols.iterator();
+                                       String col = iter.next();
+                                       errMessage += col + ": " + 
duplicateAliases.get(col) + " columns";
+                                       while(iter.hasNext()) {
+                                               col = iter.next();
+                                               errMessage += ", " + col + ": " 
+ duplicateAliases.get(col) + " columns";
+                                       }
+                               }
+                               errMessage += ". Please alias the columns with 
unique names.";
+                               log.debug(errMessage);
+                               throw new FrontendException(errMessage);
+                       }
             mSchema = new Schema(fss);
-            //add the aliases that are unique after flattening
-            for(Schema.FieldSchema fs: mSchema.getFields()) {
-                String alias = flattenAlias.get(fs);
-                Integer count = aliases.get(alias);
-                if (null == count) count = 0;
-                log.debug("alias: " + alias);
-                if((null != alias) && (count == 0)) {
-                    mSchema.addAlias(alias, fs);
-                }
-            }
+                       //add the aliases that are unique after flattening
+                       for(Schema.FieldSchema fs: mSchema.getFields()) {
+                               String alias = flattenAlias.get(fs);
+                               Integer count = aliases.get(alias);
+                               if (null == count) count = 1;
+                               log.debug("alias: " + alias);
+                               if((null != alias) && (count == 1)) {
+                                       mSchema.addAlias(alias, fs);
+                               }
+                       }
             mIsSchemaComputed = true;
         }
         log.debug("Exiting getSchema");

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOMapLookup.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOMapLookup.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOMapLookup.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOMapLookup.java
 Fri May 16 14:21:14 2008
@@ -61,9 +61,9 @@
             throws ParseException {
         super(plan, key);
 
-        if (!DataType.isAtomic(mapKey)) {
-            throw new ParseException("Map key" + mapKey.toString()
-                    + "is not atomic");
+        if (!DataType.isAtomic(DataType.findType(mapKey))) {
+            throw new ParseException("Map key " + mapKey.toString()
+                    + " is not atomic");
         }
         mMap = map;
         mMapKey = mapKey;

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogicalPlanBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogicalPlanBuilder.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogicalPlanBuilder.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogicalPlanBuilder.java
 Fri May 16 14:21:14 2008
@@ -45,11 +45,12 @@
                              String query, 
                              Map<String, LogicalPlan> aliases,
                              Map<OperatorKey, LogicalOperator> opTable,
-                             Map<String, LogicalOperator> aliasOp)
+                             Map<String, LogicalOperator> aliasOp,
+                             Map<String, ExpressionOperator> defineAliases)
         throws IOException, ParseException {
         ByteArrayInputStream in = new ByteArrayInputStream(query.getBytes());  
      
         //QueryParser parser = new QueryParser(in, pigContext, scope, aliases, 
opTable);
-        QueryParser parser = new QueryParser(in, pigContext, scope, aliases, 
opTable, aliasOp);
+        QueryParser parser = new QueryParser(in, pigContext, scope, aliases, 
opTable, aliasOp, defineAliases);
         return parser.Parse();        
     }
 

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
 Fri May 16 14:21:14 2008
@@ -44,6 +44,10 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.pig.impl.plan.MultiMap;
 import org.apache.pig.impl.plan.PlanException;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.BagFactory;
+import org.apache.pig.data.DataBag;
 
 
 public class QueryParser {
@@ -54,6 +58,7 @@
        private NodeIdGenerator nodeIdGen;
        //a map of alias to logical operator for a quick lookup
        private Map<String, LogicalOperator> mapAliasOp;
+       private Map<String, ExpressionOperator> defineAliases;
        private static Log log = LogFactory.getLog(QueryParser.class);
        
        private long getNextId() {
@@ -65,7 +70,8 @@
                                           String scope, 
                                           Map<String, LogicalPlan> aliases,
                                           Map<OperatorKey, LogicalOperator> 
opTable,
-                                          Map<String, LogicalOperator> 
aliasOp) {
+                                          Map<String, LogicalOperator> aliasOp,
+                                          Map<String, ExpressionOperator> 
defineAliases) {
                this(in);
                this.pigContext = pigContext;
                this.aliases = aliases;
@@ -73,6 +79,7 @@
                this.scope = scope;
                this.nodeIdGen = NodeIdGenerator.getGenerator();
                this.mapAliasOp = aliasOp;
+               this.defineAliases = defineAliases;
        }
 
        public class CogroupInput {
@@ -283,6 +290,10 @@
         LogicalOperator getOp(String alias) {
                return mapAliasOp.get(alias);
         }
+
+        ExpressionOperator getDefineOp(String alias) {
+               return defineAliases.get(alias);
+        }
         
         //BEGIN
         //I am maintaining state about the operators that should
@@ -381,6 +392,7 @@
 TOKEN : { <BAG : "bag"> }
 TOKEN : { <TUPLE : "tuple"> }
 TOKEN : { <MAP : "map"> }
+TOKEN : { <DEFINE : "define"> }
 
 TOKEN:
 {
@@ -393,9 +405,12 @@
 // Define Numeric Constants
 TOKEN :
 {
-       < NUMBER: <INTEGER> | <FLOATINGPOINT> | <FLOATINGPOINT> ( ["e","E"] ([ 
"-","+"])? <FLOATINGPOINT> )?>
-|      < #FLOATINGPOINT: <INTEGER> ( "." <INTEGER> )? | "." <INTEGER> >
+//     < NUMBER: <INTEGER> | <LONGINTEGER> | <DOUBLENUMBER> | <FLOATNUMBER> >
+       < #FLOATINGPOINT: <INTEGER> ( "." <INTEGER> )? | "." <INTEGER> >
 |      < INTEGER: ( <DIGIT> )+ >
+|      < LONGINTEGER: <INTEGER> (["l","L"])? >
+|   < DOUBLENUMBER: <FLOATINGPOINT> ( ["e","E"] ([ "-","+"])? <FLOATINGPOINT> 
)?>
+|   < FLOATNUMBER: <DOUBLENUMBER> (["f","F"])? >
 }
 
 TOKEN : { <QUOTEDSTRING : "'" (~["'"])* "'"> }
@@ -405,7 +420,7 @@
 // Parse is the Starting function.
 LogicalPlan Parse() : 
 {
-       LogicalOperator root; 
+       LogicalOperator root = null; 
        Token t1; 
        LogicalPlan lp = new LogicalPlan();
        log.trace("Entering Parse");
@@ -416,11 +431,14 @@
        (t1 = <IDENTIFIER> "=" root = Expr(lp) ";" {root.setAlias(t1.image); 
addAlias(t1.image, root);})
 |      (root = Expr(lp) ";")
 |      (<SPLIT> root = SplitClause(lp) ";")
+|      (<DEFINE> DefineClause(lp) ";")
        )
        { 
-               if(null != root.getSchema()) {
-                       log.debug("Root: " + root.getClass().getName() + " 
schema aliases");
-                       root.getSchema().printAliases();
+               if(null != root) {
+                       if(null != root.getSchema()) {
+                               log.debug("Root: " + root.getClass().getName() 
+ " schema aliases");
+                               root.getSchema().printAliases();
+                       }
                }
                
                log.trace("Exiting Parse");
@@ -464,6 +482,20 @@
        {log.trace("Exiting SplitClause"); return splitOp;}
 } 
 
+void DefineClause(LogicalPlan lp) :
+{
+       Token t;
+       ExpressionOperator exOp;
+       log.trace("Entering DefineClause");
+}
+{
+       (t = <IDENTIFIER> "=" exOp = FuncDeclareSpec(lp))
+       {
+               defineAliases.put(t.image, exOp);
+               log.trace("Exiting DefineClause");
+       }
+}
+
 
 LogicalOperator Expr(LogicalPlan lp) : 
 {
@@ -533,7 +565,7 @@
 {
        (
        (
-       (<LOAD> op = LoadClause(lp) [<AS> (LOOKAHEAD(2) "(" schema = 
TupleSchema() ")" {op.setSchema(schema);log.debug("Load as 
schema()");schema.printAliases();} | fs = AtomSchema() {schema = new 
Schema(fs); op.setSchema(schema); log.debug("Load as 
atomschema()");schema.printAliases();}) ])
+       (<LOAD> op = LoadClause(lp) [<AS> (LOOKAHEAD(2) "(" schema = 
TupleSchema() ")" {op.setSchema(schema);log.debug("Load as 
schema()");schema.printAliases();} | fs = AtomSchema() {schema = new 
Schema(fs); op.setSchema(schema); log.info("Load as 
atomschema()");schema.printAliases();}) ])
 |      ((<GROUP> | <COGROUP>) op = CogroupClause(lp))
 |      (<FILTER> op = FilterClause(lp))
 |   (<ORDER> op = OrderClause(lp))
@@ -550,7 +582,7 @@
 |      (<UNION> op = UnionClause(lp))
 |      (<FOREACH> op = ForEachClause(lp))
        )
-    [<PARALLEL> t2=<NUMBER> { 
op.setRequestedParallelism(Integer.parseInt(t2.image));} ]
+    [<PARALLEL> t2=<INTEGER> { 
op.setRequestedParallelism(Integer.parseInt(t2.image));} ]
        )       
        {log.trace("Exiting BaseExpr"); return op;}
 }
@@ -1526,11 +1558,12 @@
        ExpressionOperator projection; 
        Schema subSchema = null; 
        Token t; 
+    Object key = new Object();
        log.trace("Entering BaseEvalSpec");
 }
 {
        (
-       item = Const(lp)
+    LOOKAHEAD(Const(lp)) item = Const(lp)
 |      (
        (
                LOOKAHEAD(FuncEvalSpec(over,specs,lp,input))
@@ -1570,9 +1603,9 @@
                                item = projection;
                        }
                )
-|              ( "#" t = <QUOTEDSTRING> { 
+|              ( "#" key = AtomDatum() { 
                        assertAtomic(item, false);
-                       ExpressionOperator mapLookup = new LOMapLookup(lp, new 
OperatorKey(scope, getNextId()), item, unquote(t.image), DataType.BYTEARRAY, 
null);
+                       ExpressionOperator mapLookup = new LOMapLookup(lp, new 
OperatorKey(scope, getNextId()), item, key, DataType.BYTEARRAY, null);
                        lp.add(mapLookup);
                        log.debug("BaseEvalSpec: Added operator " + 
mapLookup.getClass().getName() + " " + mapLookup + " to logical plan " + lp);
                        lp.connect(item, mapLookup);
@@ -1622,12 +1655,33 @@
 {
        String funcName; 
        List<ExpressionOperator> args;
+       ExpressionOperator userFunc;
        log.trace("Entering FuncEvalSpec");
 }
 {
        funcName=EvalFunction() "(" args=EvalArgs(over,specs,lp,input) ")" 
        {
-               ExpressionOperator userFunc = new LOUserFunc(lp, new 
OperatorKey(scope, getNextId()), funcName, args, DataType.BYTEARRAY);
+               //check if the function name is an alias
+               //if the user has defined an alias then 
+               //verify if the number of of arguments match
+               //and create a new LOUserFunc with the information
+               //from the lookup table
+
+               LOUserFunc userAliasFunc = (LOUserFunc)getDefineOp(funcName);
+
+               if(null == userAliasFunc) {
+
+                       userFunc = new LOUserFunc(lp, new OperatorKey(scope, 
getNextId()), funcName, args, DataType.BYTEARRAY);
+               } else {
+                       //we have an alias
+                       int expectedNumArgs = 
userAliasFunc.getArguments().size();
+                       int numArgs = args.size();
+                       if(expectedNumArgs != numArgs) {
+                               throw new ParseException("Expected " + 
expectedNumArgs + " argument(s) found " + numArgs + " argument(s)");
+                       }
+                       userFunc = new LOUserFunc(lp, new OperatorKey(scope, 
getNextId()), userAliasFunc.getFuncName(), userAliasFunc.getArguments(), 
userAliasFunc.getType());
+
+               }
                lp.add(userFunc);
                log.debug("FuncEvalSpec: Added operator " + 
userFunc.getClass().getName() + " " + userFunc + " to logical plan " + lp);
                for(ExpressionOperator exprOp: args) {
@@ -1678,6 +1732,71 @@
        {log.trace("Exiting EvalArgsItem");return item;}
 }
 
+ExpressionOperator FuncDeclareSpec(LogicalPlan lp) : 
+{
+       String funcName; 
+       List<ExpressionOperator> args;
+       byte type = DataType.BYTEARRAY;
+       log.trace("Entering FuncDeclareSpec");
+}
+{
+       [type = Type()] funcName=EvalFunction() "(" args=FuncDeclareArgs(lp) 
")" 
+       {
+               ExpressionOperator userFunc = new LOUserFunc(lp, new 
OperatorKey(scope, getNextId()), funcName, args, type);
+               //lp.add(userFunc);
+               //log.debug("FuncDeclareSpec: Added operator " + 
userFunc.getClass().getName() + " " + userFunc + " to logical plan " + lp);
+               //for(ExpressionOperator exprOp: args) {
+                       //lp.connect(exprOp, userFunc);
+                       //log.debug("FuncDeclareSpec: Connected operator " + 
exprOp.getClass().getName() + " " + exprOp+ " to " + userFunc + " logical plan 
" + lp);
+               //}
+               log.trace("Exiting FuncDeclareSpec");
+               return userFunc;
+       }
+}
+
+List<ExpressionOperator> FuncDeclareArgs(LogicalPlan lp) : 
+{
+       ArrayList<ExpressionOperator> specList = new 
ArrayList<ExpressionOperator>(); 
+       ExpressionOperator item;
+       log.trace("Entering FuncDeclareEvalArgs");
+}
+{
+       (
+       (item=FuncDeclareArgsItem(lp)   {specList.add(item);}
+       ("," item=FuncDeclareArgsItem(lp) {specList.add(item);})*)
+       
+       | {}
+       )
+       {
+               log.trace("Exiting EvalArgs");
+               return specList;
+       }
+}
+
+ExpressionOperator FuncDeclareArgsItem(LogicalPlan lp):
+{
+       ExpressionOperator item;
+       byte type = DataType.BYTEARRAY;
+       Token t = null;
+       log.trace("Entering FuncDeclareArgsItem");
+}
+{
+       (
+       type = Type() [t = <IDENTIFIER>]
+       {
+               LOProject project = new LOProject(lp, new OperatorKey(scope, 
getNextId()), null, -1); 
+               project.setType(type);
+               if(null != t) {
+                       project.setAlias(t.image); 
+               }
+               item = project;
+               //lp.add(project);
+               log.debug("FuncDeclareArgsItem: Added operator " + 
project.getClass().getName() + " " + project + " to logical plan " + lp);
+       }
+       )
+       {log.trace("Exiting FuncDeclareArgsItem");return item;}
+}
+
 byte Type() : 
 { 
        log.trace("Entering Type");
@@ -1735,6 +1854,7 @@
        (
        LOOKAHEAD(SchemaTuple()) fs = SchemaTuple()
 |      LOOKAHEAD(SchemaBag()) fs = SchemaBag()
+|      LOOKAHEAD(SchemaMap()) fs = SchemaMap()
 |      LOOKAHEAD(AtomSchema()) fs = AtomSchema()
        )
        //{log.debug("Printing Aliases"); 
item.printAliases();log.trace("Exiting Schema");return item;}
@@ -1764,21 +1884,41 @@
        )
 }
 
+Schema.FieldSchema SchemaMap() :
+{
+       Token t1 = null; 
+       Schema.FieldSchema fs;
+       log.trace("Entering SchemaMap");
+}
+{
+       ( t1 = <IDENTIFIER> )  [":" <MAP>] "[" "]"
+       {
+               if (null != t1) {
+                       log.debug("MAP alias " + t1.image);
+                       fs = new Schema.FieldSchema(t1.image, DataType.MAP);
+               } else {
+                       fs = new Schema.FieldSchema(null, DataType.MAP);
+               }
+               log.trace("Exiting SchemaMap");
+               return fs;
+       } 
+}
+
 Schema.FieldSchema SchemaTuple() : 
 {
        Token t1 = null; 
-       Schema list;
+       Schema s;
        Schema.FieldSchema fs;
        log.trace("Entering SchemaTuple");
 }
 { 
-       ( t1 = <IDENTIFIER> )  [":" <TUPLE>] "(" list = TupleSchema() ")" 
+       ( t1 = <IDENTIFIER> )  [":" <TUPLE>] "(" s = TupleSchema() ")" 
        {
                if (null != t1) {
                        log.debug("TUPLE alias " + t1.image);
-                       fs = new Schema.FieldSchema(t1.image, list, 
DataType.TUPLE);
+                       fs = new Schema.FieldSchema(t1.image, s, 
DataType.TUPLE);
                } else {
-                       fs = new Schema.FieldSchema(null, list, DataType.TUPLE);
+                       fs = new Schema.FieldSchema(null, s, DataType.TUPLE);
                }
                log.trace("Exiting SchemaTuple");
                return fs;
@@ -1788,18 +1928,19 @@
 Schema.FieldSchema SchemaBag() : 
 {
        Token t1 = null; 
-       Schema list;
+       Schema s;
        Schema.FieldSchema fs;
        log.trace("Entering SchemaBag");
 }
 { 
-       ( t1 = <IDENTIFIER> ) [":" <BAG>] "{" list = TupleSchema() "}" 
+       ( t1 = <IDENTIFIER> ) [":" <BAG>] "{" (fs = SchemaTuple() | {} {fs = 
new Schema.FieldSchema(null, new Schema());}) "}" 
        {
+        s = new Schema(fs);
                if (null != t1) {
                        log.debug("BAG alias " + t1.image);
-                       fs = new Schema.FieldSchema(t1.image, list, 
DataType.BAG);
+                       fs = new Schema.FieldSchema(t1.image, s, DataType.BAG);
                } else {
-                       fs = new Schema.FieldSchema(null, list, DataType.BAG);
+                       fs = new Schema.FieldSchema(null, s, DataType.BAG);
                }
                log.trace("Exiting SchemaBag");
                return fs;
@@ -1836,13 +1977,20 @@
 {
        funcName = QualifiedFunction()
        {
-               try{
-                       LOUserFunc ef = (LOUserFunc) 
pigContext.instantiateFuncFromAlias(funcName);
-               }catch (Exception e){
-                       throw new ParseException(e.getMessage());
+               ExpressionOperator userFunc = getDefineOp(funcName);
+               if(null == userFunc) {
+               //TODO
+               //Commented out the code for instaniateFunc as it's failing
+               /*
+                       try{
+                               LOUserFunc ef = (LOUserFunc) 
pigContext.instantiateFuncFromAlias(funcName);
+                       }catch (Exception e){
+                               throw new ParseException(e.getMessage());
+                       }
+               */
                }
-               
                log.trace("Exiting EvalFunction");
+               
                return funcName;
        }
 }
@@ -1904,20 +2052,137 @@
        }
 }
 
+DataBag Bag() :
+{
+       byte type = DataType.BYTEARRAY;
+       BagFactory bagFactory = BagFactory.getInstance();
+    DataBag bag = bagFactory.newDefaultBag();
+    Tuple t = null;
+    log.trace("Entering bag");
+}
+{
+ ("(" t = Tuple() {bag.add(t);} ")" ("," "(" t = Tuple() {bag.add(t);} ")" )* )
+ {
+    log.trace("Exiting bag");
+    return bag;
+ }
+}
+
+Tuple Tuple() : 
+{
+       byte type = DataType.BYTEARRAY;
+       Object obj = null;
+       TupleFactory tupleFactory = TupleFactory.getInstance();
+       ArrayList<Object> objList = new ArrayList<Object>(); 
+       log.trace("Entering Tuple");
+}
+{
+       (       
+       (       
+            (
+                obj = Datum() {log.debug("Adding " + obj + " to the list: " + 
objList); objList.add(obj);} 
+                       ( LOOKAHEAD(2) "," obj = Datum() {log.debug("Adding " + 
obj + " to the list: " + objList); objList.add(obj);})* 
+            )
+            |          {}
+       )
+       )
+       {
+               Tuple tuple = tupleFactory.newTuple(objList);
+               log.trace("Exiting Tuple");
+               return tuple;
+       }
+}
+
+Map<Object, Object> Map() :
+{
+       Map<Object, Object> keyValues = new HashMap<Object, Object>();
+       log.trace("Entering Map");
+       
+}
+{
+       ( KeyValuePair(keyValues) ("," KeyValuePair(keyValues))* )
+       {
+               log.trace("Exiting Map");
+               return keyValues;
+       }
+}
+
+void KeyValuePair(Map<Object, Object> keyValues) :
+{
+       Object key = null;
+       Object value = null;
+       log.trace("Entering KeyValuePair");
+}
+{
+       (key = AtomDatum() "#" value = Datum())
+       {
+               keyValues.put(key, value);
+               log.trace("Exiting KeyValuePair");
+       }
+       
+}
+
+Object AtomDatum():
+{
+    Object obj = null;
+       Token t;
+       log.trace("Entering AtomDatum");
+}
+{
+       (
+       t = <INTEGER> {obj = new Integer(Integer.parseInt(t.image));}
+|      t = <LONGINTEGER> 
+    {
+        String num = t.image.substring(0, t.image.length() - 2);
+        obj = new Long(Long.parseLong(num));
+    }
+|      t = <FLOATNUMBER> {obj = new Float(Float.parseFloat(t.image));}
+|      t = <DOUBLENUMBER> {obj = new Double(Double.parseDouble(t.image));}
+|      t = <QUOTEDSTRING> {obj = unquote(t.image);}
+       )
+       {
+        log.debug("Number: " + t.image + " obj type: " + 
DataType.findTypeName(DataType.findType(obj)));
+               log.trace("Exiting AtomDatum");
+               return obj;
+       }
+}
+
+Object Datum(): 
+{
+    Object obj = null;
+       log.trace("Entering Datum");
+}
+{
+       (
+       obj = "[" Map() "]"
+|      obj = "{" Bag() "}"
+|      obj = "(" Tuple() ")"
+|      obj = AtomDatum()
+       )
+       {
+               log.trace("Exiting Datum");
+               return obj;
+       }
+}
 
 ExpressionOperator Const(LogicalPlan lp) : 
 {
        Token t1; 
        String s;
+       Object obj = null;
+       byte type = DataType.BYTEARRAY;
        log.trace("Entering Const");
 }
 {
        (
-       t1=<QUOTEDSTRING> {s = unquote(t1.image);}
-|      t1 = <NUMBER> {s = t1.image;}
+       LOOKAHEAD(AtomDatum()) obj = AtomDatum ()
+|      obj= Datum()
        )
        {
-               ExpressionOperator lConst = new LOConst(lp, new 
OperatorKey(scope, getNextId()), s);
+               ExpressionOperator lConst = new LOConst(lp, new 
OperatorKey(scope, getNextId()), obj);
+        type = DataType.findType(obj);
+        log.debug("type: " + DataType.findTypeName(type));
+               lConst.setType(type);
                lp.add(lConst);
                log.debug("Const: Added operator " + 
lConst.getClass().getName() + " " + lConst + " to logical plan " + lp);
                log.trace("Exiting Const");
@@ -1987,6 +2252,7 @@
                                item = new LOProject(lp, new OperatorKey(scope, 
getNextId()), op, -1);
                                ((LOProject)item).setStar(true);
                                log.debug("Set star to true");
+                               item.setAlias(t1.image);
                                
                                if(insideGenerate()) {
                                        log.debug("AliasFieldOrSpec: Inside 
generate");
@@ -2019,6 +2285,7 @@
                                over.printAliases();
                        }       
                        item = new LOProject(lp, new OperatorKey(scope, 
getNextId()), eOp, i);
+                       item.setAlias(t1.image);
                        try {
                                lp.add(item);
                                log.debug("AliasFieldOrSpec: Added operator " + 
item.getClass().getName() + " " + item + " to logical plan " + lp);

Modified: incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java 
(original)
+++ incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java Fri 
May 16 14:21:14 2008
@@ -52,13 +52,14 @@
     parser.parseContOnError();
     }
 
-    public void exec() {
+    public void exec() throws Throwable {
         try {
         parser.setInteractive(false);
         parser.parseStopOnError();
         } catch (Throwable e) {
             log.error(e.getMessage());
-    }
+            throw e;
+        }
     
     }
 }

Modified: 
incubator/pig/branches/types/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
 Fri May 16 14:21:14 2008
@@ -112,7 +112,6 @@
 TOKEN: {<COPY: "cp">}
 TOKEN: {<COPYFROMLOCAL: "copyFromLocal">}
 TOKEN: {<COPYTOLOCAL: "copyToLocal">}
-TOKEN: {<DEFINE: "define">}
 TOKEN: {<DUMP: "dump">}
 TOKEN: {<DESCRIBE: "describe">}
 TOKEN: {<EXPLAIN: "explain">}
@@ -289,13 +288,6 @@
        t2 = GetPath()
        {processCopyToLocal(t1.image, t2.image);}       
        |
-       <DEFINE>
-       t1 = <IDENTIFIER>
-       (
-       val = QualifiedFunction()
-       )
-       {processRegisterFunc(t1.image, val);}
-       |
        <DUMP>
        t1 = <IDENTIFIER>
        {processDump(t1.image);}
@@ -448,8 +440,6 @@
        |
        t = <COPYTOLOCAL>
        |
-       t = <DEFINE>
-       |
        t = <DUMP>
        |
        t = <DESCRIBE>
@@ -503,4 +493,4 @@
        } else {
                throw e;
        }
-}
\ No newline at end of file
+}

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestGrunt.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestGrunt.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestGrunt.java 
(original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestGrunt.java Fri 
May 16 14:21:14 2008
@@ -19,7 +19,10 @@
 
 import org.junit.Test;
 import junit.framework.TestCase;
+import junit.framework.AssertionFailedError;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pig.PigServer;
 import org.apache.pig.impl.PigContext;
 import org.apache.pig.tools.grunt.Grunt;
@@ -31,13 +34,14 @@
 public class TestGrunt extends TestCase {
     MiniCluster cluster = MiniCluster.buildCluster();
 
+    private final Log log = LogFactory.getLog(getClass());
     
     @Test 
     public void testCopyFromLocal() throws Throwable {
         PigServer server = new PigServer("MAPREDUCE");
         PigContext context = server.getPigContext();
         
-        String strCmd = "copyFromLocal /tmp/TestMe;";
+        String strCmd = "copyFromLocal /bin/sh . ;";
         
         ByteArrayInputStream cmd = new ByteArrayInputStream(strCmd.getBytes());
         InputStreamReader reader = new InputStreamReader(cmd);
@@ -46,4 +50,23 @@
     
         grunt.exec();
     }
+
+    @Test 
+    public void testDefineFail() throws Throwable {
+        PigServer server = new PigServer("MAPREDUCE");
+        PigContext context = server.getPigContext();
+        
+        String strCmd = "define myudf org.apache.pig.myudf();";
+        
+        ByteArrayInputStream cmd = new ByteArrayInputStream(strCmd.getBytes());
+        InputStreamReader reader = new InputStreamReader(cmd);
+        
+        Grunt grunt = new Grunt(new BufferedReader(reader), context);
+    
+        try {
+            grunt.exec();
+        } catch (Exception e) {
+            assertTrue(e.getMessage().contains("Encountered \"define\""));
+        }
+    }
 }

Modified: 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=657216&r1=657215&r2=657216&view=diff
==============================================================================
--- 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
 (original)
+++ 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
 Fri May 16 14:21:14 2008
@@ -50,6 +50,7 @@
 import org.apache.pig.impl.logicalLayer.LOLoad;
 //import org.apache.pig.impl.logicalLayer.LOEval;
 import org.apache.pig.impl.logicalLayer.LogicalOperator;
+import org.apache.pig.impl.logicalLayer.ExpressionOperator;
 import org.apache.pig.impl.logicalLayer.LogicalPlan;
 import org.apache.pig.impl.logicalLayer.LogicalPlanBuilder;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
@@ -525,6 +526,19 @@
     }
 
     @Test
+    public void testQueryFail43() {
+        buildPlan("a = load 'a' as (name, age, gpa);");
+        buildPlan("b = load 'b' as (name, height);");
+        try {
+            String query = "c = cogroup a by (name, age), b by (height);";
+            buildPlan(query);
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Exception"));
+        }
+    } 
+
+
+    @Test
     public void testQuery44() {
         buildPlan("a = load 'a' as (url, pagerank);");
         buildPlan("b = load 'b' as (url, query, rank);");
@@ -647,6 +661,17 @@
         buildPlan(query);
     } 
 
+       @Test
+    public void testQueryFail58(){
+        buildPlan("a = load 'a' as (url, host, rank);");
+        buildPlan("b = group a by url; ");
+        try {
+               LogicalPlan lp = buildPlan("c = foreach b generate group.url;");
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Exception"));
+        }
+    }
+
     @Test
     public void testQuery59() {
         buildPlan("a = load 'a' as (name, age, gpa);");
@@ -683,23 +708,13 @@
     }
 
     @Test
-    public void testQueryFail6() {
+    public void testQueryFail62() {
         buildPlan("a = load 'a' as (name, age, gpa);");
         buildPlan("b = load 'b' as (name, height);");
+        String query = "c = cross a,b;";
+        buildPlan(query);
         try {
-            String query = "c = cogroup a by (name, age), b by (height);";
-            buildPlan(query);
-        } catch (AssertionFailedError e) {
-            assertTrue(e.getMessage().contains("Exception"));
-        }
-    } 
-
-    @Test
-    public void testQueryFail17(){
-        buildPlan("a = load 'a' as (url, host, rank);");
-        buildPlan("b = group a by url; ");
-        try {
-            LogicalPlan lp = buildPlan("c = foreach b generate group.url;");
+               buildPlan("d = order c by name, b::name, height, a::gpa;");
         } catch (AssertionFailedError e) {
             assertTrue(e.getMessage().contains("Exception"));
         }
@@ -710,46 +725,124 @@
         buildPlan("a = load 'a' as (name, details: tuple(age, gpa));");
         buildPlan("b = group a by details;");
         String query = "d = foreach b generate group.age;";
-        //buildPlan("b = group a by 2*3;");
-        //String query = "d = foreach b generate group;";
         buildPlan(query);
         buildPlan("e = foreach a generate name, details;");
     }
 
     @Test
+    public void testQueryFail63() {
+        String query = "foreach (load 'myfile' as (col1, col2 : (sub1, sub2), 
col3 : (bag1))) generate col1 ;";
+        try {
+               buildPlan(query);
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Exception"));
+        }
+    }
+    
+    @Test
     public void testQuery64() {
-        buildPlan("a = load 'a' as (name: chararray, details: tuple(age, 
gpa));");
-        buildPlan("c = load 'a' as (name, details: bag{age: integer, gpa});");
+        buildPlan("a = load 'a' as (name: chararray, details: tuple(age, gpa), 
mymap: map[]);");
+        buildPlan("c = load 'a' as (name, details: bag{mytuple: tuple(age: 
integer, gpa)});");
         buildPlan("b = group a by details;");
         String query = "d = foreach b generate group.age;";
         buildPlan(query);
-        buildPlan("e = foreach a generate name, details;");
-        buildPlan("f = LOAD 'myfile' AS (garage: bag{num_tools: integer}, 
links: bag{websites: chararray}, page: bag{something_stupid: tuple(yeah_double: 
double)}, coordinates: bag{another_tuple: tuple(ok_float: float, 
bite_the_array: bytearray), bag_of_unknown: bag{}});");
+               buildPlan("e = foreach a generate name, details;");
+               buildPlan("f = LOAD 'myfile' AS (garage: bag{tuple1: 
tuple(num_tools: integer)}, links: bag{tuple2: tuple(websites: chararray)}, 
page: bag{something_stupid: tuple(yeah_double: double)}, coordinates: 
bag{another_tuple: tuple(ok_float: float, bite_the_array: bytearray, 
bag_of_unknown: bag{})});");
     }
 
     @Test
-    public void testQueryFail18() {
-        String query = "foreach (load 'myfile' as (col1, col2 : (sub1, sub2), 
col3 : (bag1))) generate col1 ;";
+    public void testQueryFail64() {
+        String query = "foreach (load 'myfile' as (col1, col2 : bag{age: 
integer})) generate col1 ;";
         try {
-            buildPlan(query);
+               buildPlan(query);
         } catch (AssertionFailedError e) {
             assertTrue(e.getMessage().contains("Exception"));
         }
     }
     
     @Test
-    public void testQueryFail19() {
+    public void testQuery65() {
         buildPlan("a = load 'a' as (name, age, gpa);");
         buildPlan("b = load 'b' as (name, height);");
-        String query = "c = cross a,b;";
-        buildPlan(query);
+               buildPlan("c = cogroup a by (name, age), b by (name, height);");
+               buildPlan("d = foreach c generate group.name, a.name as aName, 
b.name as b::name;");
+       }
+
+    @Test
+    public void testQueryFail65() {
+        buildPlan("a = load 'a' as (name, age, gpa);");
+        buildPlan("b = load 'b' as (name, height);");
+               buildPlan("c = cogroup a by (name, age), b by (name, height);");
         try {
-            buildPlan("d = order c by name, b::name, height, a::gpa;");
+                       buildPlan("d = foreach c generate group.name, a.name, 
b.height as age, a.age;");
         } catch (AssertionFailedError e) {
             assertTrue(e.getMessage().contains("Exception"));
         }
+       }
+
+    @Test
+    public void testQuery66() {
+        buildPlan("define myFunc = com.mycompany.myudfs.myfunc(integer i, 
chararray c);");
+        buildPlan("a = load 'input1' as (name, age, gpa);");
+        buildPlan("b = foreach a generate myFunc($0, $1);");
+       }
+
+    @Test
+    public void testQueryFail66() {
+        buildPlan("define myFunc = com.mycompany.myudfs.myfunc(integer i, 
chararray c);");
+        buildPlan("a = load 'input1' as (name, age, gpa);");
+        try {
+               buildPlan("b = foreach a generate myFunc($0, $1, $2);");
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Exception"));
+        }
+       }
+
+    @Test
+    public void testQuery67() {
+        buildPlan(" a = load 'input1' as (name, age, gpa);");
+        buildPlan(" b = foreach a generate age, age * 10L, gpa/0.2f, {(16, 
4.0e-2, 'hello')};");
+    }
+
+    @Test
+    public void testQuery68() {
+        buildPlan(" a = load 'input1';");
+        buildPlan(" b = foreach a generate {(16, 4.0e-2, 'hello'), (0.5f, 
'another tuple', 12l, {()})};");
     }
 
+    @Test
+    public void testQuery69() {
+        buildPlan(" a = load 'input1';");
+        buildPlan(" b = foreach a generate {(16, 4.0e-2, 'hello'), (0.5f, 
'another tuple', 12L, (1), ())};");
+    }
+
+    @Test
+    public void testQuery70() {
+        buildPlan(" a = load 'input1';");
+        buildPlan(" b = foreach a generate [10L#'hello', 4.0e-2#10L, 0.5f#(1), 
'world'#42, 42#{('guide')}] as mymap;");
+        buildPlan(" c = foreach b generate mymap#10L;");
+    }
+
+    @Test
+    public void testQueryFail67() {
+        buildPlan(" a = load 'input1' as (name, age, gpa);");
+        try {
+            buildPlan(" b = foreach a generate age, age * 10L, gpa/0.2f, {16, 
4.0e-2, 'hello'};");
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Exception"));
+        }
+    }
+    
+    @Test
+    public void testQueryFail68() {
+        buildPlan(" a = load 'input1' as (name, age, gpa);");
+        try {
+            buildPlan(" b = foreach a generate {(16 L, 4.0e-2, 'hello'), 
(0.5f, 'another tuple', 12L, {()})};");
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Exception"));
+        }
+    }
+    
     // Helper Functions
     // =================
     public LogicalPlan buildPlan(String query) {
@@ -766,7 +859,8 @@
                                            query,
                                            aliases,
                                            logicalOpTable,
-                                           aliasOp);
+                                           aliasOp,
+                                           defineAliases);
             List<LogicalOperator> roots = lp.getRoots();
             
             if(roots.size() > 0) {
@@ -817,4 +911,5 @@
     Map<String, LogicalPlan> aliases = new HashMap<String, LogicalPlan>();
     Map<OperatorKey, LogicalOperator> logicalOpTable = new 
HashMap<OperatorKey, LogicalOperator>();
     Map<String, LogicalOperator> aliasOp = new HashMap<String, 
LogicalOperator>();
+    Map<String, ExpressionOperator> defineAliases = new HashMap<String, 
ExpressionOperator>();
 }


Reply via email to