Search in sources :

Example 6 with VisibleForTesting

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);
        }
    }
}
Also used : Scanner(org.codehaus.janino.Scanner) InputStream(java.io.InputStream) StringReader(java.io.StringReader) CompileException(org.codehaus.commons.compiler.CompileException) IOException(java.io.IOException) Parser(org.codehaus.janino.Parser) VisibleForTesting(org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting)

Example 7 with VisibleForTesting

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()));
    }
}
Also used : PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) FragmentLeaf(org.apache.drill.exec.physical.base.FragmentLeaf) VisibleForTesting(org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting)

Example 8 with VisibleForTesting

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;
    }
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) RecordBatch(org.apache.drill.exec.record.RecordBatch) CloseableRecordBatch(org.apache.drill.exec.record.CloseableRecordBatch) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) CloseableRecordBatch(org.apache.drill.exec.record.CloseableRecordBatch) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) VisibleForTesting(org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting)8 IOException (java.io.IOException)4 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)2 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 InvalidPathException (java.nio.file.InvalidPathException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)1 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)1 QueryCancelledException (org.apache.drill.exec.ops.QueryCancelledException)1 FragmentLeaf (org.apache.drill.exec.physical.base.FragmentLeaf)1 StoragePlugins (org.apache.drill.exec.planner.logical.StoragePlugins)1