Search in sources :

Example 6 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project incubator-rya by apache.

the class PcjTables method createPcjTable.

/**
 * Create a new PCJ table within an Accumulo instance for a SPARQL query.
 * For example, calling the function like this:
 * <pre>
 * PcjTables.createPcjTable(
 *     accumuloConn,
 *
 *     "foo_INDEX_query1234",
 *
 *     Sets.newHashSet(
 *         new VariableOrder("city;worker;customer"),
 *         new VariableOrder("worker;customer;city") ,
 *         new VariableOrder("customer;city;worker")),
 *
 *     "SELECT ?customer ?worker ?city { " +
 *            "?customer &lt;http://talksTo> ?worker. " +
 *            "?worker &lt;http://livesIn> ?city. " +
 *            "?worker &lt;http://worksAt> &lt;http://Home>. " +
 *     "}");
 * </pre>
 * </p>
 * Will result in an Accumulo table named "foo_INDEX_query1234" with the following entries:
 * <table border="1" style="width:100%">
 *   <tr> <th>Row ID</td>  <th>Column</td>  <th>Value</td> </tr>
 *   <tr> <td>pcjMetadata</td> <td>metadata:sparql</td> <td> ... UTF-8 bytes encoding the query string ... </td> </tr>
 *   <tr> <td>pcjMetadata</td> <td>metadata:cardinality</td> <td> The query's cardinality </td> </tr>
 *   <tr> <td>pcjMetadata</td> <td>metadata:variableOrders</td> <td> The variable orders the results are written to </td> </tr>
 * </table>
 *
 * @param accumuloConn - A connection to the Accumulo that hosts the PCJ table. (not null)
 * @param pcjTableName - The name of the table that will be created. (not null)
 * @param varOrders - The variable orders the results within the table will be written to. (not null)
 * @param sparql - The query this table's results solves. (not null)
 * @throws PCJStorageException Could not create a new PCJ table either because Accumulo
 *   would not let us create it or the PCJ metadata was not able to be written to it.
 */
public void createPcjTable(final Connector accumuloConn, final String pcjTableName, final Set<VariableOrder> varOrders, final String sparql) throws PCJStorageException {
    checkNotNull(accumuloConn);
    checkNotNull(pcjTableName);
    checkNotNull(varOrders);
    checkNotNull(sparql);
    final TableOperations tableOps = accumuloConn.tableOperations();
    if (!tableOps.exists(pcjTableName)) {
        BatchWriter writer = null;
        try {
            // Create the new table in Accumulo.
            tableOps.create(pcjTableName);
            // Write the PCJ Metadata to the newly created table.
            final PcjMetadata pcjMetadata = new PcjMetadata(sparql, 0L, varOrders);
            final List<Mutation> mutations = makeWriteMetadataMutations(pcjMetadata);
            writer = accumuloConn.createBatchWriter(pcjTableName, new BatchWriterConfig());
            writer.addMutations(mutations);
        } catch (final TableExistsException e) {
            log.warn("Something else just created the Rya PCJ export table named '" + pcjTableName + "'. This is unexpected, but we will continue as normal.");
        } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
            throw new PCJStorageException("Could not create a new PCJ named: " + pcjTableName, e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (final MutationsRejectedException e) {
                    log.error("Mutations rejected while creating the PCJ table.", e);
                }
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 7 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project teiid by teiid.

the class AccumuloUpdateExecution method createBatchWriter.

private BatchWriter createBatchWriter(Table table, Connector connector) throws TranslatorException, TableNotFoundException {
    String tableName = SQLStringVisitor.getRecordName(table);
    BatchWriter writer;
    try {
        writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
    } catch (TableNotFoundException e) {
        try {
            connector.tableOperations().create(tableName, true, TimeType.LOGICAL);
        } catch (AccumuloException e1) {
            throw new TranslatorException(e1);
        } catch (AccumuloSecurityException e1) {
            throw new TranslatorException(e1);
        } catch (TableExistsException e1) {
            throw new TranslatorException(e1);
        }
        writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
    }
    return writer;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) TranslatorException(org.teiid.translator.TranslatorException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 8 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class MockTableOperations method rename.

@Override
public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException, TableExistsException {
    if (!exists(oldTableName))
        throw new TableNotFoundException(oldTableName, oldTableName, "");
    if (exists(newTableName))
        throw new TableExistsException(newTableName, newTableName, "");
    MockTable t = acu.tables.remove(oldTableName);
    String namespace = Tables.qualify(newTableName).getFirst();
    MockNamespace n = acu.namespaces.get(namespace);
    if (n == null) {
        n = new MockNamespace();
    }
    t.setNamespaceName(namespace);
    t.setNamespace(n);
    acu.namespaces.put(namespace, n);
    acu.tables.put(newTableName, t);
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Example 9 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class MockTableOperations method create.

@Override
public void create(String tableName, NewTableConfiguration ntc) throws AccumuloException, AccumuloSecurityException, TableExistsException {
    String namespace = Tables.qualify(tableName).getFirst();
    checkArgument(tableName.matches(Tables.VALID_NAME_REGEX));
    if (exists(tableName))
        throw new TableExistsException(tableName, tableName, "");
    checkArgument(namespaceExists(namespace), "Namespace (" + namespace + ") does not exist, create it first");
    acu.createTable(username, tableName, ntc.getTimeType(), ntc.getProperties());
}
Also used : TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Example 10 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class TableOperationsImpl method compact.

@Override
public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
    checkArgument(tableName != null, "tableName is null");
    ByteBuffer EMPTY = ByteBuffer.allocate(0);
    // Ensure compaction iterators exist on a tabletserver
    final String skviName = SortedKeyValueIterator.class.getName();
    for (IteratorSetting setting : config.getIterators()) {
        String iteratorClass = setting.getIteratorClass();
        if (!testClassLoad(tableName, iteratorClass, skviName)) {
            throw new AccumuloException("TabletServer could not load iterator class " + iteratorClass);
        }
    }
    // Make sure the specified compaction strategy exists on a tabletserver
    final String compactionStrategyName = config.getCompactionStrategy().getClassName();
    if (!CompactionStrategyConfigUtil.DEFAULT_STRATEGY.getClassName().equals(compactionStrategyName)) {
        if (!testClassLoad(tableName, compactionStrategyName, "org.apache.accumulo.tserver.compaction.CompactionStrategy")) {
            throw new AccumuloException("TabletServer could not load CompactionStrategy class " + compactionStrategyName);
        }
    }
    Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
    Text start = config.getStartRow();
    Text end = config.getEndRow();
    if (config.getFlush())
        _flush(tableId, start, end, true);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY : TextUtil.getByteBuffer(end), ByteBuffer.wrap(IteratorUtil.encodeIteratorSettings(config.getIterators())), ByteBuffer.wrap(CompactionStrategyConfigUtil.encode(config.getCompactionStrategy())));
    Map<String, String> opts = new HashMap<>();
    try {
        doFateOperation(FateOperation.TABLE_COMPACT, args, opts, tableName, config.getWait());
    } catch (TableExistsException | NamespaceExistsException e) {
        // should not happen
        throw new AssertionError(e);
    } catch (NamespaceNotFoundException e) {
        throw new TableNotFoundException(null, tableName, "Namespace not found", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Aggregations

TableExistsException (org.apache.accumulo.core.client.TableExistsException)32 AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)17 Connector (org.apache.accumulo.core.client.Connector)9 IOException (java.io.IOException)8 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 Value (org.apache.accumulo.core.data.Value)7 HashMap (java.util.HashMap)6 Mutation (org.apache.accumulo.core.data.Mutation)6 ByteBuffer (java.nio.ByteBuffer)5 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)4 Key (org.apache.accumulo.core.data.Key)4 Text (org.apache.hadoop.io.Text)4 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)3