Java Code Examples for org.apache.pig.impl.logicalLayer.FrontendException#printStackTrace()

The following examples show how to use org.apache.pig.impl.logicalLayer.FrontendException#printStackTrace() . 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: SchemaUtils.java    From Cubert with Apache License 2.0 6 votes vote down vote up
public static ColumnType coltypeFromFieldSchema(String colName, FieldSchema colSchema)
{
    ColumnType t = new ColumnType();
    t.setName(colName);
    t.setType(convertoRCFTypeName(DataType.findTypeName(colSchema.type)));
    if (colSchema.schema != null)
    {
        try
        {
            t.setColumnSchema(convertToBlockSchema(colSchema.schema));
        }
        catch (FrontendException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return t;
}
 
Example 2
Source File: TestStore.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidationFailure() throws Exception{
    String input[] = new String[] { "some data" };
    String outputFileName = "test-output.txt";
    boolean sawException = false;
    try {
        Util.createInputFile(pig.getPigContext(),outputFileName, input);
        String query = "a = load '" + inputFileName + "' as (c:chararray, " +
                       "i:int,d:double);" +
                       "store a into '" + outputFileName + "' using PigStorage();";
        Util.buildLp( pig, query );
    } catch (InvocationTargetException e){
        FrontendException pve = (FrontendException)e.getCause();
        pve.printStackTrace();
        // Since output file is present, validation should fail
        // and throw this exception
        assertEquals(6000,pve.getErrorCode());
        assertEquals(PigException.REMOTE_ENVIRONMENT, pve.getErrorSource());
        assertTrue(pve.getCause() instanceof IOException);
        sawException = true;
    } finally {
        assertTrue(sawException);
        Util.deleteFile(pig.getPigContext(), outputFileName);
    }
}
 
Example 3
Source File: TestGrunt.java    From spork with Apache License 2.0 6 votes vote down vote up
@Test
public void testBlockErrMessage() throws Throwable {
    PigServer server = new PigServer(cluster.getExecType(), cluster.getProperties());
    PigContext context = server.getPigContext();

    String script = "A = load 'inputdata' using PigStorage() as ( curr_searchQuery );\n" +
            "B = foreach A { domain = CONCAT(curr_searchQuery,\"^www\\.\");\n" +
            "        generate domain; };\n";
    ByteArrayInputStream cmd = new ByteArrayInputStream(script.getBytes());
    InputStreamReader reader = new InputStreamReader(cmd);

    Grunt grunt = new Grunt(new BufferedReader(reader), context);

    try {
        grunt.exec();
    } catch(FrontendException e) {
        e.printStackTrace();
        assertTrue(e.getMessage().contains("Error during parsing. <line 2, column 49>  Unexpected character '\"'"));
    }
}
 
Example 4
Source File: TupleFromBag.java    From datafu with Apache License 2.0 6 votes vote down vote up
@Override
public Schema outputSchema(Schema input)
{
	try {
		if (!(input.size() == 2 || input.size() == 3))
		{
			throw new RuntimeException("Expected input to have two or three fields");
		}

		if (input.getField(1).type != DataType.INTEGER ) {
			throw new RuntimeException("Expected an INT as second input, got: "+input.getField(1).type);
		}

		return new Schema(input.getField(0).schema);
	}

	catch (FrontendException e) {
		e.printStackTrace();
		throw new RuntimeException(e);
	}
}
 
Example 5
Source File: ReservoirSample.java    From datafu with Apache License 2.0 6 votes vote down vote up
@Override
public Schema outputSchema(Schema input) {
  try {
    Schema.FieldSchema inputFieldSchema = input.getField(0);

    if (inputFieldSchema.type != DataType.BAG) {
      throw new RuntimeException("Expected a BAG as input");
    }
    
    return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input),
                                             inputFieldSchema.schema, DataType.BAG));    
  } catch (FrontendException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}
 
Example 6
Source File: BagToString.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public Schema outputSchema(Schema inputSchema) {
	try {
		if ((inputSchema == null) || ((inputSchema.size() != 1) && (inputSchema.size() != 2))) {
			throw new RuntimeException("Expecting 2 inputs, found: " + 
					((inputSchema == null) ? 0 : inputSchema.size()));
		}

		FieldSchema inputFieldSchema = inputSchema.getField(0);
		if (inputFieldSchema.type != DataType.BAG) {
			throw new RuntimeException("Expecting a bag of tuples: {()}, found data type: " + 
					DataType.findTypeName(inputFieldSchema.type));
		}

		// first field in the bag schema
		FieldSchema firstFieldSchema = inputFieldSchema.schema.getField(0);
		if ((firstFieldSchema == null) || (firstFieldSchema.schema == null)
				|| firstFieldSchema.schema.size() < 1) {
			throw new RuntimeException("Expecting a bag and a delimeter, found: " + inputSchema);
		}

		if (firstFieldSchema.type != DataType.TUPLE) {
			throw new RuntimeException("Expecting a bag and a delimeter, found: " + inputSchema);
		}
		
		if (inputSchema.size() == 2) {
			FieldSchema secondInputFieldSchema = inputSchema.getField(1);

			if (secondInputFieldSchema.type != DataType.CHARARRAY) {
				throw new RuntimeException("Expecting a bag and a delimeter, found: " + inputSchema);
			}
		}

		return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
	} catch (FrontendException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example 7
Source File: BagToTuple.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public Schema outputSchema(Schema inputSchema) {
	try {
		if ((inputSchema == null) || inputSchema.size() != 1) {
			throw new RuntimeException("Expecting 1 input, found " + 
					((inputSchema == null) ? 0 : inputSchema.size()));
		}

		Schema.FieldSchema inputFieldSchema = inputSchema.getField(0);
		if (inputFieldSchema.type != DataType.BAG) {
			throw new RuntimeException("Expecting a bag of tuples: {()}");
		}

		// first field in the bag schema
		Schema.FieldSchema firstFieldSchema = inputFieldSchema.schema.getField(0);
		if ((firstFieldSchema == null) || (firstFieldSchema.schema == null)
				|| firstFieldSchema.schema.size() < 1) {
			throw new RuntimeException("Expecting a bag of tuples: {()}, found: " + inputSchema);
		}

		if (firstFieldSchema.type != DataType.TUPLE) {
			throw new RuntimeException("Expecting a bag of tuples: {()}, found: " + inputSchema);
		}

		// now for output schema
		Schema tupleOutputSchema = new Schema();
		for (int i = 0; i < firstFieldSchema.schema.size(); ++i) {
			tupleOutputSchema.add(firstFieldSchema.schema.getField(i));
		}
		return new Schema(new Schema.FieldSchema(getSchemaName(this
				.getClass().getName().toLowerCase(), inputSchema), tupleOutputSchema,
				DataType.TUPLE));
	} catch (FrontendException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example 8
Source File: WeightedSample.java    From datafu with Apache License 2.0 5 votes vote down vote up
@Override
public Schema outputSchema(Schema input) {
  try {
    if (!(input.size() == 2 || input.size() == 3))
    {
      throw new RuntimeException("Expected input to have two or three fields");
    }
    
    Schema.FieldSchema inputFieldSchema = input.getField(0);

    if (inputFieldSchema.type != DataType.BAG) {
      throw new RuntimeException("Expected a BAG as first input, got: "+inputFieldSchema.type);
    }
    
    if (input.getField(1).type != DataType.INTEGER) {
      throw new RuntimeException("Expected an INT as second input, got: "+input.getField(1).type);
    }      
    
    if (input.size() == 3 && !(input.getField(2).type == DataType.INTEGER || input.getField(2).type == DataType.LONG)) {
      throw new RuntimeException("Expected an INT or LONG as second input, got: "+input.getField(2).type);
    }
    
    return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input),
                                             inputFieldSchema.schema, DataType.BAG));    
  } catch (FrontendException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}
 
Example 9
Source File: WeightedReservoirSample.java    From datafu with Apache License 2.0 4 votes vote down vote up
@Override
public Schema outputSchema(Schema input) {
  try {
    Schema.FieldSchema inputFieldSchema = input.getField(0);

    if (inputFieldSchema.type != DataType.BAG) {
      throw new RuntimeException("Expected a BAG as input");
    }
    
    Schema inputBagSchema = inputFieldSchema.schema;
    
    if (inputBagSchema.getField(0).type != DataType.TUPLE)
    {
        throw new RuntimeException(String.format("Expected input bag to contain a TUPLE, but instead found %s",
                                               DataType.findTypeName(inputBagSchema.getField(0).type)));
    }
    
    Schema tupleSchema = inputBagSchema.getField(0).schema;
    
    if(tupleSchema == null) {
        throw new RuntimeException("The tuple of input bag has no schema");
    }
    
    List<Schema.FieldSchema> fieldSchemaList = tupleSchema.getFields();
    
    if(fieldSchemaList == null || fieldSchemaList.size() <= Math.max(0, this.weightIdx)) {
        throw new RuntimeException("The field schema of the input tuple is null " +
        		                   "or the tuple size is no more than the weight field index: "
                                   + this.weightIdx);
    }
    
    if(fieldSchemaList.get(this.weightIdx).type != DataType.INTEGER &&
       fieldSchemaList.get(this.weightIdx).type != DataType.LONG &&
       fieldSchemaList.get(this.weightIdx).type != DataType.FLOAT &&
       fieldSchemaList.get(this.weightIdx).type != DataType.DOUBLE)
    {
        String[] expectedTypes = new String[] {DataType.findTypeName(DataType.INTEGER),
                                               DataType.findTypeName(DataType.LONG),
                                               DataType.findTypeName(DataType.FLOAT),
                                               DataType.findTypeName(DataType.DOUBLE)};
        throw new RuntimeException("Expect the type of the weight field of the input tuple to be of (" +
                java.util.Arrays.toString(expectedTypes) + "), but instead found (" + 
                DataType.findTypeName(fieldSchemaList.get(this.weightIdx).type) + "), weight field: " + 
                this.weightIdx);
    } 
    
    return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input),
                                             inputFieldSchema.schema, DataType.BAG));    
  } catch (FrontendException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}