Java Code Examples for org.apache.pig.impl.util.Utils#getSchemaFromBagSchemaString()

The following examples show how to use org.apache.pig.impl.util.Utils#getSchemaFromBagSchemaString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSchema.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapWithoutAlias() throws FrontendException {
    List<FieldSchema> innerFields = new ArrayList<FieldSchema>();
    innerFields.add(new FieldSchema(null, DataType.LONG));
    List<FieldSchema> fields = new ArrayList<FieldSchema>();
    fields.add(new FieldSchema("mapAlias", new Schema(innerFields), DataType.MAP));

    Schema inputSchema = new Schema(fields);
    Schema fromString = Utils.getSchemaFromBagSchemaString(inputSchema.toString());
    assertTrue(Schema.equals(inputSchema, fromString, false, false));
}
 
Example 2
Source File: TestSchema.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapWithAlias() throws FrontendException {
    List<FieldSchema> innerFields = new ArrayList<FieldSchema>();
    innerFields.add(new FieldSchema("valueAlias", DataType.LONG));
    List<FieldSchema> fields = new ArrayList<FieldSchema>();
    fields.add(new FieldSchema("mapAlias", new Schema(innerFields), DataType.MAP));

    Schema inputSchema = new Schema(fields);
    Schema fromString = Utils.getSchemaFromBagSchemaString(inputSchema.toString());
    assertTrue(Schema.equals(inputSchema, fromString, false, false));
}
 
Example 3
Source File: TestSchema.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStringFromSchema() throws ParserException {
    String[] schemaStrings = {
        "a:int",
        "a:long",
        "a:chararray",
        "a:double",
        "a:float",
        "a:bytearray",
        "b:bag{tuple(x:int,y:int,z:int)}",
        "b:bag{t:tuple(x:int,y:int,z:int)}",
        "a:int,b:chararray,c:Map[int]",
        "a:double,b:float,t:tuple(x:int,y:double,z:bytearray)",
        "a:double,b:float,t:tuple(x:int,b:bag{t:tuple(a:int,b:float,c:double,x:tuple(z:bag{r:tuple(z:bytearray)}))},z:bytearray)",
        "a,b,t:tuple(x,b:bag{t:tuple(a,b,c,x:tuple(z:bag{r:tuple(z)}))},z)",
        "a:bag{t:tuple(a:bag{t:tuple(a:bag{t:tuple(a:bag{t:tuple(a:bag{t:tuple(a:bag{t:tuple(a:int,b:float)})})})})})}",
        "a:bag{}",
        "b:{null:(a:int)}",
        "int,int,int,int,int,int,int,int,int,int",
        "long,long,long,long,long,long,long,long,long,long",
        "float,float,float,float,float,float,float,float,float,float",
        "double,double,double,double,double,double,double,double,double,double",
        "boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean",
        "datetime,datetime,datetime,datetime,datetime,datetime,datetime,datetime,datetime,datetime",
        "{},{},{},{},{},{},{},{},{},{}",
        "map[],map[],map[],map[],map[],map[],map[],map[],map[],map[]",
        "int,int,long,long,float,float,double,double,boolean,boolean,datetime,datetime,(int,long,float,double,boolean,datetime),{(int,long,float,double,boolean,datetime)},map[(int,long,float,double,boolean,datetime)]"
    };
    for (String schemaString : schemaStrings) {
        Schema s1 = Utils.getSchemaFromString(schemaString);
        String s=s1.toString();
        Schema s2 = Utils.getSchemaFromBagSchemaString(s); // removes outer curly-braces added by Schema#toString
        assertTrue(Schema.equals(s1,s2,false,true));
    }
}