Java Code Examples for org.apache.pig.impl.logicalLayer.schema.Schema#toString()

The following examples show how to use org.apache.pig.impl.logicalLayer.schema.Schema#toString() . 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 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));
    }
}
 
Example 2
Source File: SchemaToString.java    From datafu with Apache License 2.0 5 votes vote down vote up
/**
 * Hook to capture the input schema string that we will spit out later
 */
@Override
public void onReady(Schema in_schema, Schema out_schema) {
  String sch_str = in_schema.toString();
  sch_str = sch_str.replaceFirst("[\\w\\.]+: ", "");
  getInstanceProperties().put("schema_string", sch_str);
  super.onReady(in_schema, out_schema);
}
 
Example 3
Source File: PigSchemaConverter.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
/**
 * @param pigSchema the pig schema to turn into a string representation
 * @return the sctring representation of the schema
 */
static String pigSchemaToString(Schema pigSchema) {
  final String pigSchemaString = pigSchema.toString();
  return pigSchemaString.substring(1, pigSchemaString.length() - 1);
}
 
Example 4
Source File: UDFContextTestUDF.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String exec(Tuple input) throws IOException {
    Schema sch = (Schema)UDFContext.getUDFContext()
            .getUDFProperties(this.getClass()).get("pig.evalfunc.inputschema."+signature);
     return sch.toString();
}
 
Example 5
Source File: InputSchemaUDF.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String exec(Tuple input) throws IOException {
    Schema sch = (Schema)UDFContext.getUDFContext().getUDFProperties(this.getClass()).get("myschema");
    return sch.toString();
}