Search in sources :

Example 41 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project presto by prestodb.

the class FunctionAssertions method compileFilterProject.

private OperatorFactory compileFilterProject(Expression filter, Expression projection, ExpressionCompiler compiler) {
    filter = new SymbolToInputRewriter(INPUT_MAPPING).rewrite(filter);
    projection = new SymbolToInputRewriter(INPUT_MAPPING).rewrite(projection);
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(TEST_SESSION, metadata, SQL_PARSER, INPUT_TYPES, ImmutableList.of(filter, projection), emptyList());
    try {
        List<RowExpression> projections = ImmutableList.of(toRowExpression(projection, expressionTypes));
        Supplier<PageProcessor> processor = compiler.compilePageProcessor(toRowExpression(filter, expressionTypes), projections);
        return new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(expressionTypes.get(projection)));
    } catch (Throwable e) {
        if (e instanceof UncheckedExecutionException) {
            e = e.getCause();
        }
        throw new RuntimeException("Error compiling " + projection + ": " + e.getMessage(), e);
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) RowExpression(com.facebook.presto.sql.relational.RowExpression) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) PageProcessor(com.facebook.presto.operator.PageProcessor) GenericPageProcessor(com.facebook.presto.operator.GenericPageProcessor) RowExpression(com.facebook.presto.sql.relational.RowExpression) CanonicalizeExpressions.canonicalizeExpression(com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SymbolToInputRewriter(com.facebook.presto.sql.planner.SymbolToInputRewriter)

Example 42 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project drill by apache.

the class HBaseConnectionManager method getConnection.

public Connection getConnection(HBaseConnectionKey key) {
    checkNotNull(key);
    try {
        Connection conn = connectionCache.get(key);
        if (!isValid(conn)) {
            // invalidate the connection with a per storage plugin lock
            key.lock();
            try {
                conn = connectionCache.get(key);
                if (!isValid(conn)) {
                    connectionCache.invalidate(key);
                    conn = connectionCache.get(key);
                }
            } finally {
                key.unlock();
            }
        }
        return conn;
    } catch (ExecutionException | UncheckedExecutionException e) {
        throw UserException.dataReadError(e.getCause()).build(logger);
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Connection(org.apache.hadoop.hbase.client.Connection) ExecutionException(java.util.concurrent.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException)

Example 43 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project samza by apache.

the class TestHdfsSystemConsumer method testEmptyStagingDirectory.

/*
   * Ensure that empty staging directory will not break system admin,
   * but should fail system consumer
   */
@Test
public void testEmptyStagingDirectory() throws Exception {
    Map<String, String> configMap = new HashMap<>();
    configMap.put(String.format(HdfsConfig.CONSUMER_PARTITIONER_WHITELIST(), SYSTEM_NAME), ".*avro");
    Config config = new MapConfig(configMap);
    HdfsSystemFactory systemFactory = new HdfsSystemFactory();
    // create admin and do partitioning
    HdfsSystemAdmin systemAdmin = systemFactory.getAdmin(SYSTEM_NAME, config);
    String stream = WORKING_DIRECTORY;
    Set<String> streamNames = new HashSet<>();
    streamNames.add(stream);
    generateAvroDataFiles();
    Map<String, SystemStreamMetadata> streamMetadataMap = systemAdmin.getSystemStreamMetadata(streamNames);
    SystemStreamMetadata systemStreamMetadata = streamMetadataMap.get(stream);
    Assert.assertEquals(NUM_FILES, systemStreamMetadata.getSystemStreamPartitionMetadata().size());
    // create consumer and read from files
    HdfsSystemConsumer systemConsumer = systemFactory.getConsumer(SYSTEM_NAME, config, new NoOpMetricsRegistry());
    Partition partition = new Partition(0);
    SystemStreamPartition ssp = new SystemStreamPartition(SYSTEM_NAME, stream, partition);
    try {
        systemConsumer.register(ssp, "0");
        Assert.fail("Empty staging directory should fail system consumer");
    } catch (UncheckedExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof SamzaException);
    }
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) HashMap(java.util.HashMap) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) SystemStreamMetadata(org.apache.samza.system.SystemStreamMetadata) SamzaException(org.apache.samza.SamzaException) NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) MapConfig(org.apache.samza.config.MapConfig) HashSet(java.util.HashSet) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 44 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project cdap by caskdata.

the class SingleThreadDatasetCache method getDataset.

@Override
public <T extends Dataset> T getDataset(DatasetCacheKey key, boolean bypass) throws DatasetInstantiationException {
    Dataset dataset;
    try {
        if (bypass) {
            dataset = datasetLoader.load(key);
        } else {
            try {
                dataset = datasetCache.get(key);
            } catch (ExecutionException | UncheckedExecutionException e) {
                throw e.getCause();
            }
        }
    } catch (DatasetInstantiationException | ServiceUnavailableException e) {
        throw e;
    } catch (Throwable t) {
        throw new DatasetInstantiationException(String.format("Could not instantiate dataset '%s:%s'", key.getNamespace(), key.getName()), t);
    }
    // make sure the dataset exists and is of the right type
    if (dataset == null) {
        throw new DatasetInstantiationException(String.format("Dataset '%s' does not exist", key.getName()));
    }
    T typedDataset;
    try {
        @SuppressWarnings("unchecked") T t = (T) dataset;
        typedDataset = t;
    } catch (Throwable t) {
        // must be ClassCastException
        throw new DatasetInstantiationException(String.format("Could not cast dataset '%s' to requested type. Actual type is %s.", key.getName(), dataset.getClass().getName()), t);
    }
    // any transaction aware that is not in the active tx-awares is added to the current tx context (if there is one).
    if (!bypass && dataset instanceof TransactionAware) {
        TransactionAware txAware = (TransactionAware) dataset;
        TransactionAware existing = activeTxAwares.get(key);
        if (existing == null) {
            activeTxAwares.put(key, txAware);
            if (txContext != null) {
                txContext.addTransactionAware(txAware);
            }
        } else if (existing != dataset) {
            // this better be the same dataset, otherwise the cache did not work
            throw new IllegalStateException(String.format("Unexpected state: Cache returned %s for %s, which is different from the " + "active transaction aware %s for the same key. This should never happen.", dataset, key, existing));
        }
    }
    return typedDataset;
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) MeteredDataset(co.cask.cdap.api.dataset.metrics.MeteredDataset) Dataset(co.cask.cdap.api.dataset.Dataset) TransactionAware(org.apache.tephra.TransactionAware) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DatasetInstantiationException(co.cask.cdap.api.data.DatasetInstantiationException)

Example 45 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project Essentials by drtshock.

the class UserMap method getUser.

public User getUser(final String name) {
    try {
        final String sanitizedName = StringUtil.safeString(name);
        if (names.containsKey(sanitizedName)) {
            final UUID uuid = names.get(sanitizedName);
            return getUser(uuid);
        }
        final File userFile = getUserFileFromString(sanitizedName);
        if (userFile.exists()) {
            ess.getLogger().info("Importing user " + name + " to usermap.");
            User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
            trackUUID(user.getBase().getUniqueId(), user.getName(), true);
            return user;
        }
        return null;
    } catch (UncheckedExecutionException ex) {
        return null;
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) File(java.io.File)

Aggregations

UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)45 ExecutionException (java.util.concurrent.ExecutionException)33 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)22 IOException (java.io.IOException)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 GenericPageProcessor (com.facebook.presto.operator.GenericPageProcessor)3 PageProcessor (com.facebook.presto.operator.PageProcessor)3 Type (com.facebook.presto.spi.type.Type)3 SymbolToInputRewriter (com.facebook.presto.sql.planner.SymbolToInputRewriter)3 CanonicalizeExpressions.canonicalizeExpression (com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression)3 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)3 RowExpression (com.facebook.presto.sql.relational.RowExpression)3 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)3 Expression (com.facebook.presto.sql.tree.Expression)3 ExecutionError (com.google.common.util.concurrent.ExecutionError)3 NoSuchElementException (java.util.NoSuchElementException)3 Test (org.junit.Test)3 Stopwatch (com.google.common.base.Stopwatch)2 UnsupportedLoadingOperationException (com.google.common.cache.CacheLoader.UnsupportedLoadingOperationException)2