ScriptState.start(scriptState);
ScriptState.get().setScript(query);
ScriptState.get().registerListener(adaptor);
PigServer pigServer = new PigServer(ctx, true);
pigServer.setBatchOn();
GruntParser grunt = new GruntParser(new StringReader(query), pigServer);
grunt.setInteractive(false);
try {
grunt.parseStopOnError(true);
} catch (ParseException e) {
throw new IOException("Failed to parse script", e);
}
pigServer.executeBatch();
return PigStats.get();