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 <http://talksTo> ?worker. " +
* "?worker <http://livesIn> ?city. " +
* "?worker <http://worksAt> <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);
}
}
}
}
}
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;
}
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);
}
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());
}
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);
}
}
Aggregations