@Override public boolean equals(Object o) { if (o instanceof IndexInfo) { IndexInfo i = (IndexInfo) o; return Objects.equals(getTreeName(), i.getTreeName()) && Objects.equals(getAttributeName(), i.getAttributeName()) && Objects.equals(getIndexType(), i.getIndexType()) && compareMetadatas(getMetadata(), i.getMetadata()); } return false; }
@Override public void clearIndex(IndexInfo index) { indexTreeMappings.remove(index.getId()); }
public static IndexInfoEntry fromIndexInfo(IndexInfo indexInfo) { String layer = indexInfo.getTreeName(); String indexedAttribute = indexInfo.getAttributeName(); IndexType indexType = indexInfo.getIndexType(); List<String> extraAttributes = Lists.newArrayList(IndexInfo.getMaterializedAttributeNames(indexInfo)); return new IndexInfoEntry(layer, indexedAttribute, indexType, extraAttributes); }
@Override public String toString() { return String.format("Index(%s) %s on %s(%s)", indexTree.toString().substring(0, 8), indexInfo.getIndexType(), indexInfo.getTreeName(), indexInfo.getAttributeName()); } }
private void addIndex(IndexInfo index) { String treeName = index.getTreeName(); if (indexes.containsKey(treeName)) { indexes.get(treeName).add(index); } else { indexes.put(treeName, Lists.newArrayList(index)); } }
.getMaterializedAttributeNames(indexInfo); String.join(", ", indexAttributes))); return Optional.of(indexInfo.getId()); final String treeRefSpec = branchOrHead + ":" + indexInfo.getTreeName(); return Optional.of(index.info().getId()); Index index = command.setTreeRefSpec(featureTreePath).setExtraAttributes(indexAttributes) .setIndexHistory(true).call(); return Optional.of(index.info().getId());
@Override public boolean dropIndex(IndexInfo index) { checkOpen(); byte[] indexKey = indexKey(index.getTreeName(), index.getAttributeName()); try (RocksDBReference dbRef = dbhandle.getReference()) { try (RocksIterator it = dbRef.db().newIterator(indexMetadataColumn)) { it.seek(indexKey); if (it.isValid()) { byte[] key = it.key(); if (key.length == indexKey.length) { for (int i = 0; i < indexKey.length; i++) { if (indexKey[i] != key[i]) { return false; } } dbRef.db().delete(indexMetadataColumn, key); clearIndex(index); return true; } } } catch (RocksDBException e) { throw new RuntimeException(e); } } return false; }
public static @Nullable Envelope getMaxBounds(IndexInfo info) { Envelope maxBounds = (Envelope) info.getMetadata().get(IndexInfo.MD_QUAD_MAX_BOUNDS); return maxBounds; } }
@Override public IndexInfo createIndexInfo(String treeName, String attributeName, IndexType strategy, @Nullable Map<String, Object> metadata) { IndexInfo index = new IndexInfo(treeName, attributeName, strategy, metadata); final String sql = format( "INSERT INTO %s (repository, treeName, attributeName, strategy, metadata) VALUES(?, ?, ?, ?, ?)", ps.setString(3, attributeName); ps.setString(4, strategy.toString()); final Map<String, Object> indexMetadata = index.getMetadata(); if (indexMetadata.isEmpty()) { ps.setNull(5, java.sql.Types.OTHER, "bytea");
private Optional<IndexInfo> createOrUpdateIndexAndVerify(String layerName, String... extraAttributes) throws Exception { Optional<ObjectId> createOrUpdateIndex = dataStore.createOrUpdateIndex(layerName, extraAttributes); assertTrue("IndexInfo ObjectId should be present", createOrUpdateIndex.isPresent()); ObjectId id = createOrUpdateIndex.get(); Context resolveContext = dataStore.resolveContext(Transaction.AUTO_COMMIT); List<IndexInfo> indexInfos = resolveContext.indexDatabase().getIndexInfos(); assertNotNull("No IndexInfo objects found", indexInfos); assertEquals("Expected exactly 1 IndexInfo", 1, indexInfos.size()); IndexInfo index = indexInfos.get(0); assertEquals("Unexpected ObjectID for IndexInfo", id, index.getId()); // verify the index contains all the extra Attributes Set<String> materializedAttributeNames = IndexInfo.getMaterializedAttributeNames(index); for (String attribute : extraAttributes) { assertTrue("Index should have contained " + attribute, materializedAttributeNames.contains(attribute)); } return Optional.of(index); }
private void verify(IndexInfo indexInfo, List<SimpleFeature> expectedFeatures) throws IOException { String typeName = indexInfo.getTreeName(); GeogigFeatureStore source = (GeogigFeatureStore) dataStore.getFeatureSource(typeName); assertEquals(expectedFeatures.size(), source.getCount(Query.ALL)); NodeRef typeRef = source.delegate.getTypeRef(); ObjectId canonicalTreeId = typeRef.getObjectId(); Optional<ObjectId> resolveIndexedTree = repo.indexDatabase().resolveIndexedTree(indexInfo, canonicalTreeId); assertTrue(resolveIndexedTree.isPresent()); ObjectId indexTreeId = resolveIndexedTree.get(); Set<String> extraAttributes = IndexInfo.getMaterializedAttributeNames(indexInfo); String[] extraAtts = new ArrayList<>(extraAttributes).toArray(new String[0]); IndexTestSupport.verifyIndex(geogig, indexTreeId, canonicalTreeId, extraAtts); List<SimpleFeature> contents = DataUtilities.list(source.getFeatures()); Map<String, SimpleFeature> expected = Maps.uniqueIndex(expectedFeatures, (f) -> f.getID()); Map<String, SimpleFeature> actual = Maps.uniqueIndex(contents, (f) -> f.getID()); assertEquals(expected.size(), actual.size()); assertEquals(expected.keySet(), actual.keySet()); for (String fid : expected.keySet()) { SimpleFeature e = expected.get(fid); SimpleFeature a = actual.get(fid); List<Object> eatts = e.getAttributes(); List<Object> aatts = a.getAttributes(); assertEquals(eatts, aatts); } }
@Override public Optional<IndexInfo> getIndexInfo(String treeName, String attributeName) { if (indexes.containsKey(treeName)) { for (IndexInfo index : indexes.get(treeName)) { if (index.getAttributeName().equals(attributeName)) { return Optional.of(index); } } } return Optional.absent(); }
indexes.add(new IndexInfo(treeName, attributeName, strategy, metadata));
private Set<String> resolveMaterializedProperties(@NonNull IndexInfo info) { Set<String> availableAtts = IndexInfo.getMaterializedAttributeNames(info); return availableAtts; }
@Override public String toString() { return String.format("Index(%s) %s on %s(%s)", indexTree.toString().substring(0, 8), indexInfo.getIndexType(), indexInfo.getTreeName(), indexInfo.getAttributeName()); } }
private void addIndex(IndexInfo index) { String treeName = index.getTreeName(); if (indexes.containsKey(treeName)) { indexes.get(treeName).add(index); } else { indexes.put(treeName, Lists.newArrayList(index)); } }
protected void testCopyIndexesTo(IndexDatabase target) { IndexInfo index1 = createIndex("Layer1", this.indexDb); this.indexDb.copyIndexesTo(target); Optional<IndexInfo> indexInfo = target.getIndexInfo(index1.getTreeName(), index1.getAttributeName()); assertNotNull(indexInfo); assertTrue(indexInfo.isPresent()); assertEquals(index1, indexInfo.get()); Set<IndexTreeMapping> expectedMappings = toSet(this.indexDb.resolveIndexedTrees(index1)); Set<IndexTreeMapping> actualMappings = toSet(target.resolveIndexedTrees(index1)); assertEquals(expectedMappings.size(), actualMappings.size()); assertEquals(expectedMappings, actualMappings); Set<ObjectId> expectedIndexTrees = verifyAllReachableTrees(this.indexDb, expectedMappings); Set<ObjectId> actualIndexTrees = verifyAllReachableTrees(target, actualMappings); assertEquals(expectedIndexTrees.size(), actualIndexTrees.size()); assertEquals(expectedIndexTrees, actualIndexTrees); }
public static @Nullable Envelope getMaxBounds(IndexInfo info) { Envelope maxBounds = (Envelope) info.getMetadata().get(IndexInfo.MD_QUAD_MAX_BOUNDS); return maxBounds; } }
@Override public IndexInfo createIndexInfo(String treeName, String attributeName, IndexType strategy, @Nullable Map<String, Object> metadata) { IndexInfo index = new IndexInfo(treeName, attributeName, strategy, metadata); final String sql = format( "INSERT INTO %s (repository, treeName, attributeName, strategy, metadata) VALUES(?, ?, ?, ?, ?)", ps.setString(3, attributeName); ps.setString(4, strategy.toString()); final Map<String, Object> indexMetadata = index.getMetadata(); if (indexMetadata.isEmpty()) { ps.setNull(5, java.sql.Types.OTHER, "bytea");
private Optional<IndexInfo> createOrUpdateIndexAndVerify(String layerName, String... extraAttributes) throws Exception { Optional<ObjectId> createOrUpdateIndex = dataStore.createOrUpdateIndex(layerName, extraAttributes); assertTrue("IndexInfo ObjectId should be present", createOrUpdateIndex.isPresent()); ObjectId id = createOrUpdateIndex.get(); Context resolveContext = dataStore.resolveContext(Transaction.AUTO_COMMIT); List<IndexInfo> indexInfos = resolveContext.indexDatabase().getIndexInfos(); assertNotNull("No IndexInfo objects found", indexInfos); assertEquals("Expected exactly 1 IndexInfo", 1, indexInfos.size()); IndexInfo index = indexInfos.get(0); assertEquals("Unexpected ObjectID for IndexInfo", id, index.getId()); // verify the index contains all the extra Attributes Set<String> materializedAttributeNames = IndexInfo.getMaterializedAttributeNames(index); for (String attribute : extraAttributes) { assertTrue("Index should have contained " + attribute, materializedAttributeNames.contains(attribute)); } return Optional.of(index); }