protected PigServer createPigInstance() throws Exception {
final PigContext ctx = (pigContext != null ? pigContext : new PigContext());
// apparently if not connected, pig can cause all kind of errors
PigServer pigServer = null;
try {
if (StringUtils.hasText(user)) {
UserGroupInformation ugi = UserGroupInformation.createProxyUser(user,
UserGroupInformation.getLoginUser());
pigServer = ugi.doAs(new PrivilegedExceptionAction<PigServer>() {
@Override
public PigServer run() throws Exception {
return new PigServer(ctx, true);
}
});
}
else {
pigServer = new PigServer(ctx, true);
}
} catch (ExecException ex) {
throw PigUtils.convert(ex);
}
if (!CollectionUtils.isEmpty(pathToSkip)) {
for (String path : pathToSkip) {
pigServer.addPathToSkip(path);
}
}
if (parallelism != null) {
pigServer.setDefaultParallel(parallelism);
}
if (StringUtils.hasText(jobName)) {
pigServer.setJobName(jobName);
}
else {
if (StringUtils.hasText(beanName)) {
pigServer.setJobName(beanName);
}
}
if (StringUtils.hasText(jobPriority)) {
pigServer.setJobPriority(jobPriority);
}
if (validateEachStatement != null) {
PigUtils.validateEachStatement(pigServer, validateEachStatement);
}