diff --git a/core/src/main/java/org/polypheny/db/adapter/DataStore.java b/core/src/main/java/org/polypheny/db/adapter/DataStore.java index 3c3354ee60..826ca21caa 100644 --- a/core/src/main/java/org/polypheny/db/adapter/DataStore.java +++ b/core/src/main/java/org/polypheny/db/adapter/DataStore.java @@ -17,6 +17,7 @@ package org.polypheny.db.adapter; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.JsonObject; import com.google.gson.JsonSerializer; import java.util.ArrayList; @@ -54,7 +55,7 @@ public DataStore( final long adapterId, final String uniqueName, final Map getFunctionalIndexes( LogicalTable catalogTable ); - public record IndexMethodModel( String name, String displayName ) { + public record IndexMethodModel( @JsonProperty String name, @JsonProperty String displayName ) { } diff --git a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java index fc328fa455..8c3d3a0574 100644 --- a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java +++ b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java @@ -260,28 +260,62 @@ public void updateColumnType( Context context, long allocId, LogicalColumn newCo @Override public String addIndex( Context context, LogicalIndex index, AllocationTable allocation ) { - throw new GenericRuntimeException( "MonetDB adapter does not support adding indexes" ); + PhysicalTable physical = adapterCatalog.fromAllocation( allocation.id ); + String physicalIndexName = getPhysicalIndexName( physical.id, index.id ); + + StringBuilder builder = new StringBuilder(); + builder.append( "CREATE " ); + if ( index.unique ) { + builder.append( "UNIQUE INDEX " ); + } else { + builder.append( "INDEX " ); + } + + builder.append( dialect.quoteIdentifier( physicalIndexName ) ) + .append( " ON " ) + .append( dialect.quoteIdentifier( physical.namespaceName ) ) + .append( "." ) + .append( dialect.quoteIdentifier( physical.name ) ); + + builder.append( "(" ); + boolean first = true; + for ( long columnId : index.key.fieldIds ) { + if ( !first ) { + builder.append( ", " ); + } + first = false; + builder.append( dialect.quoteIdentifier( getPhysicalColumnName( columnId ) ) ); + } + builder.append( ")" ); + + executeUpdate( builder, context ); + + return physicalIndexName; } @Override public void dropIndex( Context context, LogicalIndex index, long allocId ) { - throw new GenericRuntimeException( "MonetDB adapter does not support dropping indexes" ); + PhysicalTable table = adapterCatalog.fromAllocation( allocId ); + + StringBuilder builder = new StringBuilder(); + builder.append( "DROP INDEX " ); + builder.append( dialect.quoteIdentifier( index.physicalName + "_" + table.id ) ); + executeUpdate( builder, context ); } @Override public List getAvailableIndexMethods() { // According to the MonetDB documentation, MonetDB takes create index statements only as an advice and often freely - // neglects them. Indexes are created and removed automatically. We therefore decided to not support manually creating - // indexes on MonetDB. - return ImmutableList.of(); + // neglects them. Indexes are created and removed automatically. + return ImmutableList.of( new IndexMethodModel( "advisory", "ADVISORY ONLY" ) ); } @Override public IndexMethodModel getDefaultIndexMethod() { - throw new GenericRuntimeException( "MonetDB adapter does not support adding indexes" ); + return getAvailableIndexMethods().get( 0 ); }