use of org.apache.hadoop.hive.metastore.api.Index in project hive by apache.
the class HBaseImport method copyIndexes.
private void copyIndexes() throws MetaException, InvalidObjectException, InterruptedException {
screen("Copying indexes");
// Start the parallel threads that will copy the indexes
Thread[] copiers = new Thread[parallel];
writingToQueue = true;
for (int i = 0; i < parallel; i++) {
copiers[i] = new IndexCopier();
copiers[i].start();
}
// Put indexes from the databases we copied into the queue
for (Database db : dbs) {
screen("Coyping indexes in database " + db.getName());
for (String tableName : rdbmsStore.get().getAllTables(db.getName())) {
for (Index index : rdbmsStore.get().getIndexes(db.getName(), tableName, -1)) {
indexNameQueue.put(new String[] { db.getName(), tableName, index.getIndexName() });
}
}
}
// Now put any specifically requested tables into the queue
if (tablesToImport != null) {
for (String compoundTableName : tablesToImport) {
String[] tn = compoundTableName.split("\\.");
if (tn.length != 2) {
error(compoundTableName + " not in proper form. Must be in form dbname.tablename. " + "Ignoring this table and continuing.");
} else {
for (Index index : rdbmsStore.get().getIndexes(tn[0], tn[1], -1)) {
indexNameQueue.put(new String[] { tn[0], tn[1], index.getIndexName() });
}
}
}
}
writingToQueue = false;
// Wait until we've finished adding all the tables
for (Thread copier : copiers) copier.join();
}
use of org.apache.hadoop.hive.metastore.api.Index in project hive by apache.
the class IndexWhereProcessor method rewriteForIndexes.
/**
* Get a list of Tasks to activate use of tsToIndices.
* Generate the tasks for the index query (where we store results of
* querying the index in a tmp file) inside the IndexHandler
* @param predicate Predicate of query to rewrite
* @param index Index to use for rewrite
* @param pctx
* @param task original task before rewrite
* @param queryContext stores return values
*/
private void rewriteForIndexes(ExprNodeDesc predicate, List<Index> indexes, ParseContext pctx, Task<MapredWork> task, HiveIndexQueryContext queryContext) throws SemanticException {
HiveIndexHandler indexHandler;
// All tsToIndices in the list are of the same type, and therefore can use the
// same handler to generate the index query tasks
Index index = indexes.get(0);
try {
indexHandler = HiveUtils.getIndexHandler(pctx.getConf(), index.getIndexHandlerClass());
} catch (HiveException e) {
LOG.error("Exception while loading IndexHandler: " + index.getIndexHandlerClass(), e);
throw new SemanticException("Failed to load indexHandler: " + index.getIndexHandlerClass(), e);
}
// check the size
try {
ContentSummary inputSummary = Utilities.getInputSummary(pctx.getContext(), task.getWork().getMapWork(), null);
long inputSize = inputSummary.getLength();
if (!indexHandler.checkQuerySize(inputSize, pctx.getConf())) {
queryContext.setQueryTasks(null);
return;
}
} catch (IOException e) {
throw new SemanticException("Failed to get task size", e);
}
// use the IndexHandler to generate the index query
indexHandler.generateIndexQuery(indexes, predicate, pctx, queryContext);
return;
}
use of org.apache.hadoop.hive.metastore.api.Index in project hive by apache.
the class TestDbNotificationListener method alterIndex.
@Test
public void alterIndex() throws Exception {
String indexName = "alterIndex";
String dbName = "default";
String tableName = "alterIndexTable";
String indexTableName = tableName + "__" + indexName + "__";
int startTime = (int) (System.currentTimeMillis() / 1000);
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(new FieldSchema("col1", "int", ""));
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
Map<String, String> params = new HashMap<String, String>();
params.put("key", "value");
StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 17, serde, Arrays.asList("bucketcol"), Arrays.asList(new Order("sortcol", 1)), params);
Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
Index oldIndex = new Index(indexName, null, "default", tableName, startTime, startTime, indexTableName, sd, emptyParameters, false);
Table oldIndexTable = new Table(indexTableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 2, 3
// creates index and index table
msClient.createIndex(oldIndex, oldIndexTable);
Index newIndex = new Index(indexName, null, "default", tableName, startTime, startTime + 1, indexTableName, sd, emptyParameters, false);
// Event 4
msClient.alter_index(dbName, tableName, indexName, newIndex);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(4, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(3);
assertEquals(firstEventId + 4, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.ALTER_INDEX.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
// Parse the message field
AlterIndexMessage alterIdxMsg = md.getAlterIndexMessage(event.getMessage());
Index indexObj = alterIdxMsg.getIndexObjAfter();
assertEquals(dbName, indexObj.getDbName());
assertEquals(indexName, indexObj.getIndexName());
assertEquals(tableName, indexObj.getOrigTableName());
assertEquals(indexTableName, indexObj.getIndexTableName());
assertTrue(indexObj.getCreateTime() < indexObj.getLastAccessTime());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.alter_index(dbName, tableName, indexName, newIndex);
fail("Error: alter index should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(4, rsp.getEventsSize());
}
use of org.apache.hadoop.hive.metastore.api.Index in project hive by apache.
the class TestDbNotificationListener method dropIndex.
@Test
public void dropIndex() throws Exception {
String indexName = "dropIndex";
String dbName = "default";
String tableName = "dropIndexTable";
String indexTableName = tableName + "__" + indexName + "__";
int startTime = (int) (System.currentTimeMillis() / 1000);
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(new FieldSchema("col1", "int", ""));
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
Map<String, String> params = new HashMap<String, String>();
params.put("key", "value");
StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 17, serde, Arrays.asList("bucketcol"), Arrays.asList(new Order("sortcol", 1)), params);
Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
Index index = new Index(indexName, null, "default", tableName, startTime, startTime, indexTableName, sd, emptyParameters, false);
Table indexTable = new Table(indexTableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 2, 3 (index table and index)
msClient.createIndex(index, indexTable);
// Event 4 (drops index and indexTable)
msClient.dropIndex(dbName, tableName, indexName, true);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(4, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(3);
assertEquals(firstEventId + 4, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.DROP_INDEX.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
// Parse the message field
DropIndexMessage dropIdxMsg = md.getDropIndexMessage(event.getMessage());
assertEquals(dbName, dropIdxMsg.getDB());
assertEquals(indexName.toLowerCase(), dropIdxMsg.getIndexName());
assertEquals(indexTableName.toLowerCase(), dropIdxMsg.getIndexTableName());
assertEquals(tableName.toLowerCase(), dropIdxMsg.getOrigTableName());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
index = new Index("dropIndexTable2", null, "default", tableName, startTime, startTime, "dropIndexTable__dropIndexTable2__", sd, emptyParameters, false);
Table indexTable2 = new Table("dropIndexTable__dropIndexTable2__", dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
msClient.createIndex(index, indexTable2);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
// drops index and indexTable
msClient.dropIndex(dbName, tableName, "dropIndex2", true);
fail("Error: drop index should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(6, rsp.getEventsSize());
}
use of org.apache.hadoop.hive.metastore.api.Index in project hive by apache.
the class BitmapIndexHandler method getIndexPredicateAnalyzer.
/**
* Instantiate a new predicate analyzer suitable for determining
* whether we can use an index, based on rules for indexes in
* WHERE clauses that we support
*
* @return preconfigured predicate analyzer for WHERE queries
*/
private IndexPredicateAnalyzer getIndexPredicateAnalyzer(List<Index> indexes, Set<Partition> queryPartitions) {
IndexPredicateAnalyzer analyzer = new IndexPredicateAnalyzer();
analyzer.addComparisonOp(GenericUDFOPEqual.class.getName());
analyzer.addComparisonOp(GenericUDFOPLessThan.class.getName());
analyzer.addComparisonOp(GenericUDFOPEqualOrLessThan.class.getName());
analyzer.addComparisonOp(GenericUDFOPGreaterThan.class.getName());
analyzer.addComparisonOp(GenericUDFOPEqualOrGreaterThan.class.getName());
// only return results for columns in the list of indexes
for (Index index : indexes) {
List<FieldSchema> columnSchemas = index.getSd().getCols();
for (FieldSchema column : columnSchemas) {
analyzer.allowColumnName(column.getName());
}
}
// are used during the index query generation
for (Partition part : queryPartitions) {
if (part.getSpec().isEmpty()) {
// empty partitions are from whole tables, so we don't want to add them in
continue;
}
for (String column : part.getSpec().keySet()) {
analyzer.allowColumnName(column);
}
}
return analyzer;
}
Aggregations