use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class MultiTableBatchWriterIT method testTableRenameNewWriters.
@Test
public void testTableRenameNewWriters() throws Exception {
try {
final String[] names = getUniqueNames(4);
final String table1 = names[0], table2 = names[1];
final String newTable1 = names[2], newTable2 = names[3];
TableOperations tops = connector.tableOperations();
tops.create(table1);
tops.create(table2);
BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
Mutation m1 = new Mutation("foo");
m1.put("col1", "", "val1");
m1.put("col2", "", "val2");
bw1.addMutation(m1);
bw2.addMutation(m1);
tops.rename(table1, newTable1);
// after seeing the rename
try {
bw1 = mtbw.getBatchWriter(table1);
Assert.fail("Should not be able to find this table");
} catch (TableNotFoundException e) {
// pass
}
tops.rename(table2, newTable2);
try {
bw2 = mtbw.getBatchWriter(table2);
Assert.fail("Should not be able to find this table");
} catch (TableNotFoundException e) {
// pass
}
bw1 = mtbw.getBatchWriter(newTable1);
bw2 = mtbw.getBatchWriter(newTable2);
Mutation m2 = new Mutation("bar");
m2.put("col1", "", "val1");
m2.put("col2", "", "val2");
bw1.addMutation(m2);
bw2.addMutation(m2);
mtbw.close();
Map<Entry<String, String>, String> expectations = new HashMap<>();
expectations.put(Maps.immutableEntry("foo", "col1"), "val1");
expectations.put(Maps.immutableEntry("foo", "col2"), "val2");
expectations.put(Maps.immutableEntry("bar", "col1"), "val1");
expectations.put(Maps.immutableEntry("bar", "col2"), "val2");
for (String table : Arrays.asList(newTable1, newTable2)) {
try (Scanner s = connector.createScanner(table, new Authorizations())) {
s.setRange(new Range());
Map<Entry<String, String>, String> actual = new HashMap<>();
for (Entry<Key, Value> entry : s) {
actual.put(Maps.immutableEntry(entry.getKey().getRow().toString(), entry.getKey().getColumnFamily().toString()), entry.getValue().toString());
}
Assert.assertEquals("Differing results for " + table, expectations, actual);
}
}
} finally {
if (null != mtbw) {
mtbw.close();
}
}
}
use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class MultiTableBatchWriterIT method testTableRenameNewWritersNoCaching.
@Test
public void testTableRenameNewWritersNoCaching() throws Exception {
mtbw = getMultiTableBatchWriter();
try {
final String[] names = getUniqueNames(4);
final String table1 = names[0], table2 = names[1];
final String newTable1 = names[2], newTable2 = names[3];
TableOperations tops = connector.tableOperations();
tops.create(table1);
tops.create(table2);
BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
Mutation m1 = new Mutation("foo");
m1.put("col1", "", "val1");
m1.put("col2", "", "val2");
bw1.addMutation(m1);
bw2.addMutation(m1);
tops.rename(table1, newTable1);
tops.rename(table2, newTable2);
try {
bw1 = mtbw.getBatchWriter(table1);
Assert.fail("Should not have gotten batchwriter for " + table1);
} catch (TableNotFoundException e) {
// Pass
}
try {
bw2 = mtbw.getBatchWriter(table2);
} catch (TableNotFoundException e) {
// Pass
}
} finally {
if (null != mtbw) {
mtbw.close();
}
}
}
use of org.apache.accumulo.core.client.TableNotFoundException in project presto by prestodb.
the class Indexer method flush.
/**
* Flushes all Mutations in the index writer. And all metric mutations to the metrics table.
* Note that the metrics table is not updated until this method is explicitly called (or implicitly via close).
*/
public void flush() {
try {
// Flush index writer
indexWriter.flush();
// Write out metrics mutations
BatchWriter metricsWriter = connector.createBatchWriter(table.getMetricsTableName(), writerConfig);
metricsWriter.addMutations(getMetricsMutations());
metricsWriter.close();
// Re-initialize the metrics
metrics.clear();
metrics.put(METRICS_TABLE_ROW_COUNT, new AtomicLong(0));
} catch (MutationsRejectedException e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Index mutation was rejected by server on flush", e);
} catch (TableNotFoundException e) {
throw new PrestoException(ACCUMULO_TABLE_DNE, "Accumulo table does not exist", e);
}
}
use of org.apache.accumulo.core.client.TableNotFoundException in project hive by apache.
the class AccumuloDefaultIndexScanner method getIndexRowRanges.
/**
* Get a list of rowid ranges by scanning a column index.
*
* @param column - the hive column name
* @param indexRange - Key range to scan on the index table
* @return List of matching rowid ranges or null if too many matches found
* if index values are not found a newline range is added to list to
* short-circuit the query
*/
@Override
public List<Range> getIndexRowRanges(String column, Range indexRange) {
List<Range> rowIds = new ArrayList<Range>();
Scanner scan = null;
String col = this.colMap.get(column);
if (col != null) {
try {
LOG.debug("Searching tab=" + indexTable + " column=" + column + " range=" + indexRange);
Connector conn = getConnector();
scan = conn.createScanner(indexTable, auths);
scan.setRange(indexRange);
Text cf = new Text(col);
LOG.debug("Using Column Family=" + toString());
scan.fetchColumnFamily(cf);
for (Map.Entry<Key, Value> entry : scan) {
rowIds.add(new Range(entry.getKey().getColumnQualifier()));
// if we have too many results return null for a full scan
if (rowIds.size() > maxRowIds) {
return null;
}
}
// no hits on the index so return a no match range
if (rowIds.isEmpty()) {
LOG.debug("Found 0 index matches");
} else {
LOG.debug("Found " + rowIds.size() + " index matches");
}
return rowIds;
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
LOG.error("Failed to scan index table: " + indexTable, e);
} finally {
if (scan != null) {
scan.close();
}
}
}
// assume the index is bad and do a full scan
LOG.debug("Index lookup failed for table " + indexTable);
return null;
}
use of org.apache.accumulo.core.client.TableNotFoundException in project hive by apache.
the class TestAccumuloDefaultIndexScanner method buildMockHandler.
public static AccumuloDefaultIndexScanner buildMockHandler(int maxMatches) {
try {
String table = "table";
Text emptyText = new Text("");
Configuration conf = new Configuration();
conf.set(AccumuloIndexParameters.INDEXTABLE_NAME, table);
conf.setInt(AccumuloIndexParameters.MAX_INDEX_ROWS, maxMatches);
conf.set(AccumuloIndexParameters.INDEXED_COLUMNS, "*");
conf.set(serdeConstants.LIST_COLUMNS, "rid,name,age,cars,mgr");
conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, ":rowId,name:name,age:age,cars:cars,mgr:mgr");
AccumuloDefaultIndexScanner handler = new AccumuloDefaultIndexScanner();
handler.init(conf);
MockInstance inst = new MockInstance("test_instance");
Connector conn = inst.getConnector("root", new PasswordToken(""));
if (!conn.tableOperations().exists(table)) {
conn.tableOperations().create(table);
BatchWriterConfig batchConfig = new BatchWriterConfig();
BatchWriter writer = conn.createBatchWriter(table, batchConfig);
addRow(writer, "fred", "name_name", "row1");
addRow(writer, "25", "age_age", "row1");
addRow(writer, 5, "cars_cars", "row1");
addRow(writer, true, "mgr_mgr", "row1");
addRow(writer, "bill", "name_name", "row2");
addRow(writer, "20", "age_age", "row2");
addRow(writer, 2, "cars_cars", "row2");
addRow(writer, false, "mgr_mgr", "row2");
addRow(writer, "sally", "name_name", "row3");
addRow(writer, "23", "age_age", "row3");
addRow(writer, 6, "cars_cars", "row3");
addRow(writer, true, "mgr_mgr", "row3");
addRow(writer, "rob", "name_name", "row4");
addRow(writer, "60", "age_age", "row4");
addRow(writer, 1, "cars_cars", "row4");
addRow(writer, false, "mgr_mgr", "row4");
writer.close();
}
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
handler.setConnectParams(connectionParams);
return handler;
} catch (AccumuloSecurityException | AccumuloException | TableExistsException | TableNotFoundException e) {
LOG.error(e.getLocalizedMessage(), e);
}
return null;
}
Aggregations