Skip to content

Commit

Permalink
adjustment for InterpreterTests
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Jan 3, 2024
1 parent f567a2c commit b413ac0
Show file tree
Hide file tree
Showing 39 changed files with 360 additions and 252 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/adapter/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Adapter( long adapterId, String uniqueName, Map<String, String> settings,

@Override
public Expression asExpression() {
return Expressions.call( AdapterManager.ADAPTER_MANAGER_EXPRESSION, "getAdapter", Expressions.constant( adapterId ) );
return Expressions.convert_( Expressions.call( Expressions.call( AdapterManager.ADAPTER_MANAGER_EXPRESSION, "getAdapter", Expressions.constant( adapterId ) ), "orElseThrow" ), Adapter.class );
}


Expand Down
57 changes: 25 additions & 32 deletions core/src/main/java/org/polypheny/db/adapter/AdapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.jetbrains.annotations.NotNull;
import org.polypheny.db.adapter.annotations.AdapterProperties;
import org.polypheny.db.adapter.java.AdapterTemplate;
import org.polypheny.db.catalog.Catalog;
Expand Down Expand Up @@ -81,14 +83,15 @@ public static AdapterTemplate getAdapterTemplate( String name, AdapterType adapt
return Catalog.snapshot().getAdapterTemplate( name, adapterType ).orElseThrow();
}


public Adapter<?> getAdapter( String uniqueName ) {
return adapterByName.get( uniqueName.toLowerCase() );
@NotNull
public Optional<Adapter<?>> getAdapter( String uniqueName ) {
return Optional.ofNullable( adapterByName.get( uniqueName.toLowerCase() ) );
}


public Adapter<?> getAdapter( long id ) {
return adapterById.get( id );
@NotNull
public Optional<Adapter<?>> getAdapter( long id ) {
return Optional.ofNullable( adapterById.get( id ) );
}


Expand All @@ -97,21 +100,15 @@ public ImmutableMap<String, Adapter<?>> getAdapters() {
}


public DataStore<?> getStore( String uniqueName ) {
Adapter<?> adapter = getAdapter( uniqueName );
if ( adapter instanceof DataStore ) {
return (DataStore<?>) adapter;
}
return null;
}
@NotNull
public Optional<DataStore<?>> getStore( String uniqueName ) {
return getAdapter( uniqueName ).filter( a -> a instanceof DataStore<?> ).map( a -> (DataStore<?>) a );

}

public DataStore<?> getStore( long id ) {
Adapter<?> adapter = getAdapter( id );
if ( adapter instanceof DataStore ) {
return (DataStore<?>) adapter;
}
return null;
@NotNull
public Optional<DataStore<?>> getStore( long id ) {
return getAdapter( id ).filter( a -> a instanceof DataStore<?> ).map( a -> (DataStore<?>) a );
}


Expand All @@ -126,21 +123,15 @@ public ImmutableMap<String, DataStore<?>> getStores() {
}


public DataSource<?> getSource( String uniqueName ) {
Adapter<?> adapter = getAdapter( uniqueName );
if ( adapter instanceof DataSource<?> ) {
return (DataSource<?>) adapter;
}
return null;
@NotNull
public Optional<DataSource<?>> getSource( String uniqueName ) {
return getAdapter( uniqueName ).filter( a -> a instanceof DataSource<?> ).map( a -> (DataSource<?>) a );
}


public DataSource<?> getSource( long id ) {
Adapter<?> adapter = getAdapter( id );
if ( adapter instanceof DataSource<?> ) {
return (DataSource<?>) adapter;
}
return null;
@NotNull
public Optional<DataSource<?>> getSource( long id ) {
return getAdapter( id ).filter( a -> a instanceof DataSource<?> ).map( a -> (DataSource<?>) a );
}


Expand Down Expand Up @@ -204,10 +195,12 @@ public Adapter<?> addAdapter( String adapterName, String uniqueName, AdapterType


public void removeAdapter( long adapterId ) {
Adapter<?> adapterInstance = getAdapter( adapterId );
if ( adapterInstance == null ) {
Optional<Adapter<?>> optionalAdapter = getAdapter( adapterId );
if ( optionalAdapter.isEmpty() ) {
throw new GenericRuntimeException( "Unknown adapter instance with id: %s", adapterId );
}
Adapter<?> adapterInstance = optionalAdapter.get();

LogicalAdapter logicalAdapter = Catalog.getInstance().getSnapshot().getAdapter( adapterId ).orElseThrow();

// Check if the store has any placements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onMatch( AlgOptRuleCall call ) {
return;
}

AlgNode newAlg = AdapterManager.getInstance().getStore( oAlloc.get().adapterId ).getModify( oAlloc.get().id, modify, call.builder() );
AlgNode newAlg = AdapterManager.getInstance().getStore( oAlloc.get().adapterId ).orElseThrow().getModify( oAlloc.get().id, modify, call.builder() );

if ( newAlg != null ) {
call.transformTo( newAlg );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onMatch( AlgOptRuleCall call ) {


private static AlgNode handleGraphEntity( AlgOptRuleCall call, Scan<?> scan, AllocationEntity alloc ) {
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).getGraphScan( alloc.id, call.builder() );
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).orElseThrow().getGraphScan( alloc.id, call.builder() );

if ( scan.getModel() != scan.entity.dataModel ) {
// cross-model queries need a transformer first, we let another rule handle that
Expand All @@ -76,7 +76,7 @@ private static AlgNode handleGraphEntity( AlgOptRuleCall call, Scan<?> scan, All


private static AlgNode handleDocumentEntity( AlgOptRuleCall call, Scan<?> scan, AllocationEntity alloc ) {
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).getDocumentScan( alloc.id, call.builder() );
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).orElseThrow().getDocumentScan( alloc.id, call.builder() );

if ( scan.getModel() != scan.entity.dataModel ) {
// cross-model queries need a transformer first, we let another rule handle that
Expand All @@ -87,7 +87,7 @@ private static AlgNode handleDocumentEntity( AlgOptRuleCall call, Scan<?> scan,


private AlgNode handleRelationalEntity( AlgOptRuleCall call, Scan<?> scan, AllocationEntity alloc ) {
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).getRelScan( alloc.id, call.builder() );
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).orElseThrow().getRelScan( alloc.id, call.builder() );
if ( scan.getModel() == scan.entity.dataModel ) {
alg = attachReorder( alg, scan, call.builder() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void updateSnapshot() {


private void addNamespaceIfNecessary( AllocationEntity entity ) {
Adapter<?> adapter = AdapterManager.getInstance().getAdapter( entity.adapterId );
Adapter<?> adapter = AdapterManager.getInstance().getAdapter( entity.adapterId ).orElseThrow();

if ( adapter.getCurrentNamespace() == null || adapter.getCurrentNamespace().getId() != entity.namespaceId ) {
adapter.updateNamespace( entity.name, entity.namespaceId );
Expand All @@ -201,6 +201,7 @@ private void addNamespaceIfNecessary( AllocationEntity entity ) {
public void change() {
// empty for now
this.dirty.set( true );
updateSnapshot();
}


Expand Down Expand Up @@ -467,7 +468,7 @@ public void restore() {
AdapterManager.getInstance().restoreAdapters( List.copyOf( adapters.values() ) );

adapterRestore.forEach( ( id, restore ) -> {
Adapter<?> adapter = AdapterManager.getInstance().getAdapter( id );
Adapter<?> adapter = AdapterManager.getInstance().getAdapter( id ).orElseThrow();
restore.activate( adapter );
} );

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/polypheny/db/ddl/DdlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public static DdlManager getInstance() {
* @param placementType which placement type should be used for the initial placements
* @param statement the used statement
*/
public abstract void createTable( long namespaceId, String tableName, List<FieldInformation> columns, List<ConstraintInformation> constraints, boolean ifNotExists, List<DataStore<?>> stores, PlacementType placementType, Statement statement );
public abstract void createTable( long namespaceId, String tableName, List<FieldInformation> columns, List<ConstraintInformation> constraints, boolean ifNotExists, @Nullable List<DataStore<?>> stores, PlacementType placementType, Statement statement );

/**
* Create a new view
Expand Down Expand Up @@ -619,6 +619,7 @@ public ConstraintInformation( String name, ConstraintType type, List<String> col
public static class ColumnTypeInformation {

public PolyType type;
@Nullable
public PolyType collectionType;
public Integer precision;
public Integer scale;
Expand All @@ -629,7 +630,7 @@ public static class ColumnTypeInformation {

public ColumnTypeInformation(
PolyType type,
PolyType collectionType,
@Nullable PolyType collectionType,
Integer precision,
Integer scale,
Integer dimension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class QueryContext {

@EqualsAndHashCode(callSuper = true)
@Value

@SuperBuilder(toBuilder = true)
public static class ParsedQueryContext extends QueryContext {

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/rex/RexInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ enum Truthy {
FALSE, UNKNOWN, TRUE;


static Truthy of( Comparable<?> c ) {
return c.equals( true ) ? TRUE : c.equals( false ) ? FALSE : UNKNOWN;
static Truthy of( PolyValue c ) {
return c.isNull() || !c.isBoolean() ? UNKNOWN : (c.asBoolean().value ? TRUE : FALSE);
}


Expand Down
12 changes: 6 additions & 6 deletions dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ public class PolyphenyDb {
public boolean resetPlugins = false;

@Option(name = { "-memoryCatalog" }, description = "Store catalog only in-memory")
public boolean memoryCatalog = false;
public static boolean memoryCatalog = false;

@Option(name = { "-mode" }, description = "Special system configuration for running tests", typeConverterProvider = PolyModesConverter.class)
public PolyMode mode = PolyMode.PRODUCTION;
public static PolyMode mode = PolyMode.PRODUCTION;

@Option(name = { "-gui" }, description = "Show splash screen on startup and add taskbar gui")
public boolean desktopMode = false;
Expand Down Expand Up @@ -301,7 +301,6 @@ public void runPolyphenyDb() {
log.info( "Polypheny UUID: " + uuid );
RuntimeConfig.INSTANCE_UUID.setString( uuid );


class ShutdownHelper implements Runnable {

private final Serializable[] joinOnNotStartedLock = new Serializable[0];
Expand Down Expand Up @@ -518,6 +517,7 @@ public void restart( Config c ) {
} );
}


private void initializeIndexManager() {
try {
IndexManager.getInstance().initialize( transactionManager );
Expand Down Expand Up @@ -594,7 +594,7 @@ private void restore( Authenticator authenticator, Catalog catalog ) {

Catalog.defaultStore = AdapterTemplate.fromString( defaultStoreName, AdapterType.STORE );
Catalog.defaultSource = AdapterTemplate.fromString( defaultSourceName, AdapterType.SOURCE );
restoreDefaults( catalog );
restoreDefaults( catalog, mode );

QueryInterfaceManager.getInstance().restoreInterfaces( catalog.getSnapshot() );

Expand Down Expand Up @@ -622,9 +622,9 @@ private void commitRestore() {
}


private static void restoreDefaults( Catalog catalog ) {
private static void restoreDefaults( Catalog catalog, PolyMode mode ) {
catalog.updateSnapshot();
DefaultInserter.resetData( DdlManager.getInstance() );
DefaultInserter.resetData( DdlManager.getInstance(), mode );
DefaultInserter.restoreInterfacesIfNecessary();
}

Expand Down
Loading

0 comments on commit b413ac0

Please sign in to comment.