Skip to content

Commit

Permalink
further adjusting mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Sep 20, 2023
1 parent 195fb35 commit 16d7b0c
Show file tree
Hide file tree
Showing 34 changed files with 928 additions and 747 deletions.
7 changes: 0 additions & 7 deletions core/src/main/java/org/polypheny/db/adapter/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ public List<AbstractAdapterSetting> getAvailableSettings( Class<?> clazz ) {
}


public static Map<String, String> getDefaultSettings( Class<DataStore<?>> clazz ) {
return AbstractAdapterSetting.fromAnnotations( clazz.getAnnotations(), clazz.getAnnotation( AdapterProperties.class ) )
.stream()
.collect( Collectors.toMap( e -> e.name, e -> e.defaultValue ) );
}


public void shutdownAndRemoveListeners() {
shutdown();
if ( deployMode == DeployMode.DOCKER ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private AdapterManager() {
}


public static void addAdapterDeploy( Class<?> clazz, String adapterName, Map<String, String> defaultSettings, Function4<Long, String, Map<String, String>, Adapter<?>> deployer ) {
public static void addAdapterTemplate( Class<?> clazz, String adapterName, Map<String, String> defaultSettings, Function4<Long, String, Map<String, String>, Adapter<?>> deployer ) {
REGISTER.put( Pair.of( adapterName.toLowerCase(), AdapterTemplate.getAdapterType( clazz ) ), new AdapterTemplate( clazz, adapterName, defaultSettings, deployer ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

package org.polypheny.db.adapter.java;

import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Value;
import org.polypheny.db.adapter.AbstractAdapterSetting;
import org.polypheny.db.adapter.Adapter;
import org.polypheny.db.adapter.AdapterManager;
import org.polypheny.db.adapter.AdapterManager.Function4;
import org.polypheny.db.adapter.DataStore;
import org.polypheny.db.adapter.annotations.AdapterProperties;
import org.polypheny.db.catalog.entity.CatalogAdapter.AdapterType;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;

@Value
public class AdapterTemplate {
Expand Down Expand Up @@ -56,4 +60,12 @@ public static AdapterTemplate fromString( String adapterName, AdapterType adapte
}


public List<AbstractAdapterSetting> getAllSettings() {
AdapterProperties properties = clazz.getAnnotation( AdapterProperties.class );
if ( clazz.getAnnotation( AdapterProperties.class ) == null ) {
throw new GenericRuntimeException( "The used adapter does not annotate its properties correctly." );
}
return AbstractAdapterSetting.fromAnnotations( clazz.getAnnotations(), properties );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.experimental.NonFinal;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.catalog.IdBuilder;
import org.polypheny.db.catalog.entity.allocation.AllocationColumn;
Expand All @@ -44,6 +45,7 @@
@EqualsAndHashCode(callSuper = true)
@Value
@Slf4j
@NonFinal
public class RelStoreCatalog extends StoreCatalog {


Expand Down Expand Up @@ -122,8 +124,7 @@ public PhysicalTable fromAllocation( long id ) {
}



public void dropColum( long allocId, long columnId ) {
public void dropColumn( long allocId, long columnId ) {
PhysicalColumn column = columns.get( Pair.of( allocId, columnId ) );
PhysicalTable table = fromAllocation( allocId );
List<PhysicalColumn> pColumns = new ArrayList<>( table.columns );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void addPhysical( AllocationEntity allocation, PhysicalEntity... physical
}

allocToPhysicals.put( allocation.id, physicals );
allocations.put( allocation.id, allocation );
List.of( physicalEntities ).forEach( p -> this.physicals.put( p.id, p ) );
}

Expand Down
5 changes: 1 addition & 4 deletions dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,10 @@ private void handleSource( DataSource<?> adapter ) {
aColumns.add( allocationColumn );
}

catalog.updateSnapshot();
logical = catalog.getSnapshot().rel().getTable( logical.id ).orElseThrow();
allocation = catalog.getSnapshot().alloc().getEntity( allocation.id ).orElseThrow();

buildNamespace( Catalog.defaultNamespaceId, logical, adapter );
adapter.createTable( null, LogicalTableWrapper.of( logical, columns ), AllocationTableWrapper.of( allocation.unwrap( AllocationTable.class ), aColumns ) );

catalog.updateSnapshot();

}
catalog.updateSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void start() {
"maxStringLength", "255"
);

AdapterManager.addAdapterDeploy( CsvSource.class, "CSV", defaults, CsvSource::new );
AdapterManager.addAdapterTemplate( CsvSource.class, "CSV", defaults, CsvSource::new );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void start() {
"trxIsolationLevel", "read_committed"
) );

AdapterManager.addAdapterDeploy( HsqldbStore.class, ADAPTER_NAME, defaults, HsqldbStore::new );
AdapterManager.addAdapterTemplate( HsqldbStore.class, ADAPTER_NAME, defaults, HsqldbStore::new );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void dropColumn( Context context, long allocId, long columnId ) {
.append( dialect.quoteIdentifier( table.name ) );
builder.append( " DROP " ).append( dialect.quoteIdentifier( column.name ) );
executeUpdate( builder, context );
storeCatalog.dropColum( allocId, columnId );
storeCatalog.dropColumn( allocId, columnId );
//}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void start() {
"maxConnections", "25"
);

AdapterManager.addAdapterDeploy( MonetdbStore.class, ADAPTER_NAME, settings, MonetdbStore::new );
AdapterManager.addAdapterDeploy( MonetdbSource.class, ADAPTER_NAME, settings, MonetdbSource::new );
AdapterManager.addAdapterTemplate( MonetdbStore.class, ADAPTER_NAME, settings, MonetdbStore::new );
AdapterManager.addAdapterTemplate( MonetdbSource.class, ADAPTER_NAME, settings, MonetdbSource::new );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public interface MongoAlg extends AlgNode {
*/
class Implementor extends AlgShuttleImpl implements Serializable {

final List<Pair<String, String>> list = new ArrayList<>();
public final List<Pair<String, String>> list = new ArrayList<>();
public List<BsonDocument> operations = new ArrayList<>();
public BsonArray filter = new BsonArray();
@Getter
Expand All @@ -93,7 +93,7 @@ class Implementor extends AlgShuttleImpl implements Serializable {
public boolean onlyOne = false;
public boolean isDocumentUpdate = false;

CatalogEntity table;
public CatalogEntity entity;
@Setter
@Getter
public boolean hasProject = false;
Expand Down Expand Up @@ -211,8 +211,8 @@ public List<String> getNecessaryPhysicalFields() {
public List<String> reorderPhysical() {
// this is only needed if there is a basic scan without project or group,
// where we cannot be sure if the fields are all ordered as intended
assert table.getRowType().getFieldCount() == physicalMapper.size();
return table.getRowType().getFieldNames();
assert entity.getRowType().getFieldCount() == physicalMapper.size();
return entity.getRowType().getFieldNames();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.polypheny.db.adapter.mongodb;

import org.polypheny.db.adapter.mongodb.rules.MongoRules;
import org.polypheny.db.plan.AlgOptPlanner;
import org.polypheny.db.plan.AlgOptRule;
import org.polypheny.db.plan.Convention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.polypheny.db.adapter.AdapterManager;
import org.polypheny.db.adapter.DataContext;
import org.polypheny.db.adapter.mongodb.MongoPlugin.MongoStore;
import org.polypheny.db.adapter.mongodb.rules.MongoScan;
import org.polypheny.db.adapter.mongodb.util.MongoDynamic;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.core.common.Modify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void start() {
"trxLifetimeLimit", "1209600"
);

AdapterManager.addAdapterDeploy( MongoStore.class, ADAPTER_NAME, settings, MongoStore::new );
AdapterManager.addAdapterTemplate( MongoStore.class, ADAPTER_NAME, settings, MongoStore::new );
}


Expand Down Expand Up @@ -369,9 +369,7 @@ public void dropCollection( Context context, AllocationCollection allocation ) {
PhysicalCollection collection = storeCatalog.fromAllocation( allocation.id ).unwrap( PhysicalCollection.class );
this.currentNamespace.database.getCollection( collection.name ).drop();

catalog.dropCollection( allocation.id );
catalog.getAllocRelations().remove( allocation.id );

storeCatalog.removePhysical( allocation.id );
}


Expand All @@ -382,7 +380,7 @@ public void dropTable( Context context, long allocId ) {
PhysicalTable physical = storeCatalog.fromAllocation( allocId ).unwrap( PhysicalTable.class );

this.currentNamespace.database.getCollection( physical.name ).drop();
storeCatalog.dropTable( allocId );
storeCatalog.removePhysical( allocId );
}


Expand All @@ -391,8 +389,9 @@ public void addColumn( Context context, long allocId, LogicalColumn logicalColum
commitAll();
context.getStatement().getTransaction().registerInvolvedAdapter( this );
PhysicalTable physical = storeCatalog.fromAllocation( allocId ).unwrap( PhysicalTable.class );
String physicalName = getPhysicalColumnName( logicalColumn );
// updates all columns with this field if a default value is provided
PhysicalColumn column = storeCatalog.addColumn( physicalColumnName, allocId, adapterId, table.columns.size() - 1, logicalColumn );
PhysicalColumn column = storeCatalog.addColumn( physicalName, allocId, adapterId, physical.columns.size() - 1, logicalColumn );

Document field;
if ( logicalColumn.defaultValue != null ) {
Expand Down Expand Up @@ -514,16 +513,6 @@ private void addCompositeIndex( LogicalIndex index, List<String> columns, Physic
}


@Override
public void dropIndex( Context context, LogicalIndex logicalIndex, long allocId ) {
commitAll();
context.getStatement().getTransaction().registerInvolvedAdapter( this );
PhysicalTable physical = storeCatalog.fromAllocation( allocId ).unwrap( PhysicalTable.class );

this.currentNamespace.database.getCollection( physical.name ).dropIndex( catalogIndex.physicalName + "_" + partitionPlacement.partitionId );
}


@Override
public void updateColumnType( Context context, long allocId, LogicalColumn newCol ) {
PhysicalColumn column = storeCatalog.updateColumnType( allocId, newCol );
Expand Down Expand Up @@ -552,7 +541,6 @@ public IndexMethodModel getDefaultIndexMethod() {
}



@Override
public List<FunctionalIndexInfo> getFunctionalIndexes( LogicalTable catalogTable ) {
return ImmutableList.of();
Expand Down Expand Up @@ -644,14 +632,14 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio
@Override
public void refreshTable( long allocId ) {
PhysicalTable physical = storeCatalog.fromAllocation( allocId ).unwrap( PhysicalTable.class );
storeCatalog.addTable( currentNamespace.createEntity( storeCatalog, physical ) );
storeCatalog.replacePhysical( currentNamespace.createEntity( storeCatalog, physical ) );
}


@Override
public void refreshCollection( long allocId ) {
PhysicalCollection physical = storeCatalog.fromAllocation( allocId ).unwrap( PhysicalCollection.class );
storeCatalog.addTable( this.currentNamespace.createEntity( storeCatalog, physical ) );
storeCatalog.replacePhysical( this.currentNamespace.createEntity( storeCatalog, physical ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.polypheny.db.algebra.type.AlgDataTypeField;
import org.polypheny.db.algebra.type.AlgRecordType;
import org.polypheny.db.algebra.type.StructKind;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;

public class MongoRowType extends AlgRecordType {

Expand All @@ -33,7 +33,7 @@ public class MongoRowType extends AlgRecordType {

public MongoRowType( StructKind kind, List<AlgDataTypeField> fields, MongoEntity mongoEntity ) {
super( kind, fields );
Catalog.getInstance().getColumns( mongoEntity.getId() ).forEach( column -> {
mongoEntity.physical.unwrap( PhysicalTable.class ).columns.forEach( column -> {
idToName.put( column.id, column.name );
nameToId.put( column.name, column.id );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.polypheny.db.adapter.mongodb;

import org.polypheny.db.catalog.catalogs.StoreCatalog;
import org.polypheny.db.catalog.catalogs.RelStoreCatalog;

public class MongoStoreCatalog extends StoreCatalog {
public class MongoStoreCatalog extends RelStoreCatalog {

public MongoStoreCatalog( long adapterId ) {
super( adapterId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,15 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file incorporates code covered by the following terms:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.adapter.mongodb;
package org.polypheny.db.adapter.mongodb.rules;


import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import org.polypheny.db.adapter.mongodb.MongoAlg;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.InvalidAlgException;
import org.polypheny.db.algebra.core.Aggregate;
Expand All @@ -49,10 +36,6 @@
import org.polypheny.db.util.ImmutableBitSet;
import org.polypheny.db.util.Util;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;


/**
* Implementation of {@link Aggregate} relational expression in MongoDB.
Expand Down
Loading

0 comments on commit 16d7b0c

Please sign in to comment.