use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class FunctionInitializer method convertToCompilationUnit.
/**
* Using class name generates path to class source code (*.java),
* reads its content as string and parses it into {@link org.codehaus.janino.Java.CompilationUnit}.
*
* @param clazz function class
* @return compilation unit
* @throws IOException if did not find class or could not load it
*/
@VisibleForTesting
CompilationUnit convertToCompilationUnit(Class<?> clazz) throws IOException {
String path = clazz.getName();
path = path.replaceFirst("\\$.*", "");
path = path.replace(".", DrillFileUtils.SEPARATOR);
path = "/" + path + ".java";
logger.trace("Loading function code from the {}", path);
try (InputStream is = clazz.getResourceAsStream(path)) {
if (is == null) {
throw new IOException(String.format("Failure trying to locate source code for class %s, tried to read on classpath location %s", clazz.getName(), path));
}
String body = IO.toString(is);
// TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", "");
try {
return new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit();
} catch (CompileException e) {
throw new IOException(String.format("Failure while loading class %s.", clazz.getName()), e);
}
}
}
use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class PhysicalPlanReader method readFragmentLeaf.
@VisibleForTesting
public FragmentLeaf readFragmentLeaf(String json) throws IOException {
logger.debug("Attempting to read {}", json);
PhysicalOperator op = operatorReader.readValue(json);
if (op instanceof FragmentLeaf) {
return (FragmentLeaf) op;
} else {
throw new UnsupportedOperationException(String.format("The provided json fragment is not a FragmentLeaf. " + "The operator was %s.", op.getClass().getCanonicalName()));
}
}
use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class ImplCreator method getRecordBatch.
/**
* Create a RecordBatch and its children for given PhysicalOperator
*/
@VisibleForTesting
public RecordBatch getRecordBatch(final PhysicalOperator op, final ExecutorFragmentContext context) throws ExecutionSetupException {
Preconditions.checkNotNull(op);
final List<RecordBatch> childRecordBatches = getChildren(op, context);
if (context.isImpersonationEnabled()) {
final UserGroupInformation proxyUgi = ImpersonationUtil.createProxyUgi(op.getUserName(), context.getQueryUserName());
try {
return proxyUgi.doAs((PrivilegedExceptionAction<RecordBatch>) () -> {
@SuppressWarnings("unchecked") final CloseableRecordBatch batch = ((BatchCreator<PhysicalOperator>) getOpCreator(op, context)).getBatch(context, op, childRecordBatches);
operators.addFirst(batch);
return batch;
});
} catch (InterruptedException | IOException e) {
final String errMsg = String.format("Failed to create RecordBatch for operator with id '%d'", op.getOperatorId());
logger.error(errMsg, e);
throw new ExecutionSetupException(errMsg, e);
}
} else {
@SuppressWarnings("unchecked") final CloseableRecordBatch batch = ((BatchCreator<PhysicalOperator>) getOpCreator(op, context)).getBatch(context, op, childRecordBatches);
operators.addFirst(batch);
return batch;
}
}
Aggregations