Skip to content

Commit

Permalink
Fix error on dropping document source
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Hafner committed Jul 17, 2024
1 parent b96d772 commit d996505
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Optional;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
Expand Down Expand Up @@ -133,6 +134,13 @@ public Optional<DataStore<?>> getStore( long id ) {
return getAdapter( id ).filter( a -> a instanceof DataStore<?> ).map( a -> (DataStore<?>) a );
}

public boolean isStore(long id) {
Optional<Adapter<?>> adapter = getAdapter( id );
if (adapter.isEmpty()) {
throw new NoSuchElementException("No adapter registered under id: " + id);
}
return adapter.get() instanceof DataStore<?>;
}

public ImmutableMap<String, DataStore<?>> getStores() {
Map<String, DataStore<?>> map = new HashMap<>();
Expand Down
14 changes: 10 additions & 4 deletions dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ public void dropAdapter( String name, Statement statement ) {
}

if ( allocation.unwrap( AllocationCollection.class ).isPresent() ) {
dropCollection( catalog.getSnapshot().doc().getCollection( allocation.adapterId ).orElseThrow(), statement );
//TODO: currently each document source creates its own namespace which can be disposed of together with the source
//dropNamespace( catalog.getSnapshot().doc().getCollection( allocation.logicalId ).orElseThrow().getNamespaceName(), true, statement);
dropCollection( catalog.getSnapshot().doc().getCollection( allocation.logicalId ).orElseThrow(), statement );
} else if ( allocation.unwrap( AllocationTable.class ).isPresent() ) {

for ( LogicalForeignKey fk : catalog.getSnapshot().rel().getForeignKeys( allocation.logicalId ) ) {
Expand Down Expand Up @@ -2232,6 +2234,7 @@ private void buildRelationalNamespace( long namespaceId, LogicalTable logical, A
store.updateNamespace( logical.getNamespaceName(), namespaceId );
}


private void buildDocumentNamespace( long namespaceId, LogicalCollection logical, Adapter<?> store ) {
store.updateNamespace( logical.getNamespaceName(), namespaceId );
}
Expand Down Expand Up @@ -2295,19 +2298,22 @@ public void dropCollection( LogicalCollection collection, Statement statement )
Snapshot snapshot = catalog.getSnapshot();

AdapterManager manager = AdapterManager.getInstance();
boolean isSource = false;

List<AllocationEntity> allocations = snapshot.alloc().getFromLogical( collection.id );
for ( AllocationEntity allocation : allocations ) {
manager.getStore( allocation.adapterId ).orElseThrow().dropCollection( statement.getPrepareContext(), allocation.unwrap( AllocationCollection.class ).orElseThrow() );

if ( manager.isStore( allocation.adapterId ) ) {
manager.getStore( allocation.adapterId ).orElseThrow().dropCollection( statement.getPrepareContext(), allocation.unwrap( AllocationCollection.class ).orElseThrow() );
} else {
manager.getSource( allocation.adapterId ).orElseThrow().dropCollection( statement.getPrepareContext(), allocation.unwrap( AllocationCollection.class ).orElseThrow() );
}
catalog.getAllocDoc( allocation.namespaceId ).removeAllocation( allocation.id );
catalog.getAllocDoc( allocation.namespaceId ).removePlacement( allocation.placementId );
}
catalog.getAllocDoc( collection.namespaceId ).removePartition( snapshot.alloc().getPartitionsFromLogical( collection.id ).get( 0 ).id );
catalog.getLogicalDoc( collection.namespaceId ).deleteCollection( collection.id );

catalog.updateSnapshot();

// Reset plan cache implementation cache & routing cache
statement.getQueryProcessor().resetCaches();
}
Expand Down

0 comments on commit d996505

Please sign in to comment.