You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by th...@apache.org on 2012/10/13 04:17:28 UTC

svn commit: r1397760 - in /pig/trunk: CHANGES.txt src/org/apache/pig/impl/util/Utils.java test/org/apache/pig/test/TestSchema.java

Author: thejas
Date: Sat Oct 13 02:17:27 2012
New Revision: 1397760

URL: http://svn.apache.org/viewvc?rev=1397760&view=rev
Log:
PIG-2910: Add function to read schema from outout of Schema.toString() (initialcontext via thejas)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/impl/util/Utils.java
    pig/trunk/test/org/apache/pig/test/TestSchema.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1397760&r1=1397759&r2=1397760&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Sat Oct 13 02:17:27 2012
@@ -35,6 +35,8 @@ PIG-1891 Enable StoreFunc to make intell
 
 IMPROVEMENTS
 
+PIG-2910: Add function to read schema from outout of Schema.toString() (initialcontext via thejas)
+
 PIG-2965: RANDOM should allow seed initialization for ease of testing (jcoveney)
 
 PIG-2964: Add helper method getJobList() to PigStats.JobGraph. Extend visibility of couple methods on same class (prkommireddi via billgraham)

Modified: pig/trunk/src/org/apache/pig/impl/util/Utils.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/util/Utils.java?rev=1397760&r1=1397759&r2=1397760&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/util/Utils.java (original)
+++ pig/trunk/src/org/apache/pig/impl/util/Utils.java Sat Oct 13 02:17:27 2012
@@ -174,7 +174,9 @@ public class Utils {
     }
 
     /**
-     * @param schemaString
+     * @param schemaString a String representation of the Schema <b>without</b>
+     *                     any enclosing curly-braces.<b>Not</b> for use with
+     *                     <code>Schema#toString</code>
      * @return Schema instance
      * @throws ParserException
      */
@@ -185,6 +187,23 @@ public class Utils {
         return result;
     }
 
+    /**
+     * getSchemaFromBagSchemaString
+     * <b>NOTE: use this call</b> when you need to generate a Schema object
+     * from the representation generated by <code>Schema#toString</code>.
+     * This call strips the enclosing outer curly braces from the <code>toString</code>
+     * representation, which are placed there because the actual representation of
+     * the schema data is as a Bag-type relation.
+     * @param schemaString a String representation of the Schema to instantiate,
+     *                     in the form generated by <code>Schema.toString()</code>
+     * @return Schema instance
+     * @throws ParserException
+     */
+    public static Schema getSchemaFromBagSchemaString(String schemaString) throws ParserException {
+        String unwrappedSchemaString = schemaString.substring(1, schemaString.length() - 1);
+        return getSchemaFromString(unwrappedSchemaString);
+    }
+
 	public static LogicalSchema parseSchema(String schemaString) throws ParserException {
 		QueryParserDriver queryParser = new QueryParserDriver( new PigContext(), 
         		"util", new HashMap<String, String>() ) ;

Modified: pig/trunk/test/org/apache/pig/test/TestSchema.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSchema.java?rev=1397760&r1=1397759&r2=1397760&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSchema.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSchema.java Sat Oct 13 02:17:27 2012
@@ -879,7 +879,7 @@ public class TestSchema {
         for (String schemaString : schemaStrings) {
             Schema s1 = Utils.getSchemaFromString(schemaString);
             String s=s1.toString();
-            Schema s2 = Utils.getSchemaFromString(s.substring(1,s.length()-1)); //have to cut out the brackets that surround it
+            Schema s2 = Utils.getSchemaFromBagSchemaString(s); // removes outer curly-braces added by Schema#toString
             Assert.assertTrue(Schema.equals(s1,s2,false,true));
         }
     }