Skip to content

Commit

Permalink
fixes incorrect loading of configs, replaced Runtime with our exception
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Oct 28, 2023
1 parent 9cb266b commit d30deff
Show file tree
Hide file tree
Showing 51 changed files with 178 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private com.typesafe.config.Config parseConfigObject( String configKey, Object u
myList.add( v );
}
}
if ( myMap.size() > 0 ) {
if ( !myMap.isEmpty() ) {
modifiedConfig = configFile.withValue( configKey, ConfigValueFactory.fromAnyRef( myMap ) );
} else {
modifiedConfig = configFile.withValue( configKey, ConfigValueFactory.fromAnyRef( myList ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
package org.polypheny.db.config;


import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.javalin.Javalin;
import io.javalin.plugin.json.JavalinJackson;
import java.util.Arrays;
import java.util.Random;
import java.util.Timer;
Expand All @@ -27,8 +34,26 @@
public class ConfigServerTest {



public static void main( String[] args ) {
ConfigService s = new ConfigService( null );
ObjectMapper mapper = new ObjectMapper() {
{
setSerializationInclusion( JsonInclude.Include.NON_NULL );
configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
setVisibility( getSerializationConfig().getDefaultVisibilityChecker()
.withIsGetterVisibility( Visibility.NONE )
.withGetterVisibility( Visibility.NONE )
.withSetterVisibility( Visibility.NONE ) );
configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false );
writerWithDefaultPrettyPrinter();
}
};
Javalin server = Javalin.create( config -> {
config.jsonMapper( new JavalinJackson( mapper ) );
config.enableCorsForAllOrigins();
config.addStaticFiles( staticFileConfig -> staticFileConfig.directory = "webapp/" );
} ).start( 7659 );
ConfigService s = new ConfigService( server );
demoData( s );
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/polypheny/db/PolyImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static Meta.StatementType toStatementType( Kind kind ) {
return Meta.StatementType.IS_DML;
}

throw new RuntimeException( "Statement type does not exist." );
throw new GenericRuntimeException( "Statement type does not exist." );
}


Expand All @@ -286,9 +286,9 @@ public int getRowsChanged( Statement statement ) throws Exception {
rowsChanged = getRowsChanged( statement, iterator, MonitoringType.from( getKind() ) );
} catch ( RuntimeException e ) {
if ( e.getCause() != null ) {
throw new Exception( e.getCause().getMessage(), e );
throw new GenericRuntimeException( e.getCause().getMessage(), e );
} else {
throw new Exception( e.getMessage(), e );
throw new GenericRuntimeException( e.getMessage(), e );
}
}
return rowsChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.polypheny.db.algebra.rules.SemiJoinRules;
import org.polypheny.db.algebra.rules.SortRemoveRule;
import org.polypheny.db.algebra.rules.UnionToDistinctRule;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.plan.AbstractRelOptPlanner;
import org.polypheny.db.plan.AlgOptCost;
Expand Down Expand Up @@ -393,7 +394,7 @@ public boolean addRule( AlgOptRule rule ) {
if ( ruleNames.put( ruleName, rule.getClass() ) ) {
Set<Class<?>> x = ruleNames.get( ruleName );
if ( x.size() > 1 ) {
throw new RuntimeException( "Rule description '" + ruleName + "' is not unique; classes: " + x );
throw new GenericRuntimeException( "Rule description '" + ruleName + "' is not unique; classes: " + x );
}
}

Expand Down
4 changes: 4 additions & 0 deletions dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.polypheny.db.processing.AuthenticatorImpl;
import org.polypheny.db.processing.ConstraintEnforceAttacher.ConstraintTracker;
import org.polypheny.db.processing.JsonRelProcessorImpl;
import org.polypheny.db.routing.RoutingManager;
import org.polypheny.db.transaction.PUID;
import org.polypheny.db.transaction.Transaction;
import org.polypheny.db.transaction.TransactionException;
Expand Down Expand Up @@ -371,6 +372,7 @@ public void join( final long millis ) throws InterruptedException {
new ConfigService( server.getServer() );
new InformationService( server.getServer() );


try {
new JavaInformation();
} catch ( Exception e ) {
Expand Down Expand Up @@ -457,6 +459,8 @@ public void join( final long millis ) throws InterruptedException {
}

PolyPluginManager.initAfterCatalog();
//noinspection ResultOfMethodCallIgnored
RoutingManager.getInstance();

PolyPluginManager.initAfterTransaction( transactionManager );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ private void acquireLock( boolean isAnalyze, AlgRoot logicalRoot, Map<Integer, L
idAccessMap.addAll( accessMap.getAccessedEntityPair() );
LockManager.INSTANCE.lock( idAccessMap, (TransactionImpl) statement.getTransaction() );
} catch ( DeadlockException e ) {
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
}

Expand Down Expand Up @@ -662,9 +662,9 @@ public AlgNode visit( AlgNode node ) {
//
// TODO: This is dynamic parameter. We need to do the index update in the generated code!
//
throw new RuntimeException( "Index updates are not yet supported for prepared statements" );
throw new GenericRuntimeException( "Index updates are not yet supported for prepared statements" );
} else {
throw new RuntimeException( "Unexpected rex type: " + fieldValue.getClass() );
throw new GenericRuntimeException( "Unexpected rex type: " + fieldValue.getClass() );
}
}
for ( final String column : index.getTargetColumns() ) {
Expand All @@ -677,9 +677,9 @@ public AlgNode visit( AlgNode node ) {
//
// TODO: This is dynamic parameter. We need to do the index update in the generated code!
//
throw new RuntimeException( "Index updates are not yet supported for prepared statements" );
throw new GenericRuntimeException( "Index updates are not yet supported for prepared statements" );
} else {
throw new RuntimeException( "Unexpected rex type: " + fieldValue.getClass() );
throw new GenericRuntimeException( "Unexpected rex type: " + fieldValue.getClass() );
}
}
tuplesToInsert.add( new Pair<>( rowValues, targetRowValues ) );
Expand Down Expand Up @@ -1000,7 +1000,7 @@ private List<ProposedRoutingPlan> route( AlgRoot logicalRoot, Statement statemen
final List<ProposedRoutingPlan> distinctPlans = proposedPlans.stream().distinct().collect( Collectors.toList() );

if ( distinctPlans.isEmpty() ) {
throw new RuntimeException( "No routing of query found" );
throw new GenericRuntimeException( "No routing of query found" );
}

if ( statement.getTransaction().isAnalyze() ) {
Expand Down Expand Up @@ -1584,7 +1584,7 @@ public void lock( Statement statement ) {
try {
LockManager.INSTANCE.lock( Collections.singletonList( Pair.of( LockManager.GLOBAL_LOCK, LockMode.SHARED ) ), (TransactionImpl) statement.getTransaction() );
} catch ( DeadlockException e ) {
throw new RuntimeException( "DeadLock while locking to reevaluate statistics", e );
throw new GenericRuntimeException( "DeadLock while locking to reevaluate statistics", e );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public void copySelectiveData( Transaction transaction, LogicalAdapter store, Lo
targetStatement.getDataContext().resetParameterValues();
}
} catch ( Throwable t ) {
throw new RuntimeException( t );
throw new GenericRuntimeException( t );
}
}

Expand Down Expand Up @@ -877,7 +877,7 @@ private AlgRoot getScan( Statement statement, LogicalTable table, AllocationTabl

public void copyPartitionDataOld( Transaction transaction, LogicalAdapter store, LogicalTable sourceTable, LogicalTable targetTable, List<LogicalColumn> columns, List<Long> sourcePartitionIds, List<Long> targetPartitionIds ) {
if ( sourceTable.id != targetTable.id ) {
throw new RuntimeException( "Unsupported migration scenario. Table ID mismatch" );
throw new GenericRuntimeException( "Unsupported migration scenario. Table ID mismatch" );
}
Snapshot snapshot = Catalog.getInstance().getSnapshot();
LogicalPrimaryKey primaryKey = snapshot.rel().getPrimaryKey( sourceTable.primaryKey ).orElseThrow();
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public void copyPartitionDataOld( Transaction transaction, LogicalAdapter store,
}
}
} catch ( Throwable t ) {
throw new RuntimeException( t );
throw new GenericRuntimeException( t );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected List<RoutedAlgBuilder> handleGeneric( AlgNode node, List<RoutedAlgBuil
);
break;
default:
throw new RuntimeException( "Unexpected number of input elements: " + node.getInputs().size() );
throw new GenericRuntimeException( "Unexpected number of input elements: " + node.getInputs().size() );
}
return builders;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.polypheny.db.catalog.entity.logical.LogicalPrimaryKey.CatalogPrimaryKeyColumn.PrimitiveCatalogPrimaryKeyColumn;
import org.polypheny.db.catalog.entity.logical.LogicalTable;
import org.polypheny.db.catalog.entity.logical.LogicalTable.PrimitiveCatalogTable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.catalog.logistic.EntityType;
import org.polypheny.db.catalog.logistic.EntityType.PrimitiveTableType;
import org.polypheny.db.catalog.logistic.NamespaceType;
Expand Down Expand Up @@ -187,7 +188,7 @@ private static Object addProperty( final Map<DatabaseProperty, Object> map, fina
try {
propertyValue = p.method.invoke( metaData );
} catch ( IllegalAccessException | InvocationTargetException e ) {
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
} else {
propertyValue = p.defaultValue;
Expand Down Expand Up @@ -240,7 +241,7 @@ private <E> MetaResultSet createMetaResultSet( final ConnectionHandle ch, final
try {
field = clazz.getField( fieldName );
} catch ( NoSuchFieldException e ) {
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
columns.add( MetaImpl.columnMetaData( name, index, field.getType(), false ) );
fields.add( field );
Expand Down Expand Up @@ -989,11 +990,11 @@ public StatementHandle prepare( final ConnectionHandle ch, final String sql, fin
}

StatementHandle h = createStatement( ch );
PolyphenyDbStatementHandle polyphenyDbStatement;
PolyphenyDbStatementHandle<?> polyphenyDbStatement;
try {
polyphenyDbStatement = getPolyphenyDbStatementHandle( h );
} catch ( NoSuchStatementException e ) {
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
polyphenyDbStatement.setPreparedQuery( sql );

Expand Down Expand Up @@ -1236,7 +1237,7 @@ private ExecuteResult execute( StatementHandle h, List<TypedValue> parameterValu
} catch ( Exception e ) {
rollback( connection.getHandle() );

throw new RuntimeException( "Error on auto-commit, transaction was rolled back.\n\n" + e );
throw new GenericRuntimeException( "Error on auto-commit, transaction was rolled back.\n\n" + e );
}
}

Expand Down Expand Up @@ -1588,7 +1589,7 @@ public void closeConnection( ConnectionHandle ch ) {
try {
transaction.rollback();
} catch ( TransactionException e ) {
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
}

Expand Down Expand Up @@ -1733,7 +1734,7 @@ private RuntimeException propagate( Throwable e ) {
} else if ( e instanceof Error ) {
throw (Error) e;
} else {
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ private void dumpData( String message ) {
rowNum++;
}

throw new RuntimeException( fullMessage.toString() );
throw new GenericRuntimeException( fullMessage.toString() );
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void addColumn( Context context, long allocId, LogicalColumn logicalColum
.addAllColumns( columns ) ).build();

if ( !this.wrapper.createEntityBlocking( message ) ) {
throw new RuntimeException( "Unable to create table." );
throw new GenericRuntimeException( "Unable to create table." );
}

PolyType actualDefaultType;
Expand Down Expand Up @@ -399,7 +399,7 @@ public void dropColumn( Context context, long allocId, long columnId ) {
.build();

if ( !this.wrapper.createEntityBlocking( message ) ) {
throw new RuntimeException( "Unable to create table." );
throw new GenericRuntimeException( "Unable to create table." );
}
final QueryMessage query = QueryMessage.newBuilder()
.setMetadata( Metadata.newBuilder().setTransactionId( txId ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.adapter.cottontail.CottontailPlugin.CottontailStore;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.transaction.PolyXid;
import org.polypheny.db.transaction.Transaction;
import org.vitrivr.cottontail.client.SimpleClient;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void commit( PolyXid xid ) {
this.transactions.remove( xid );
} catch ( StatusRuntimeException e ) {
log.error( "Could not COMMIT Cottontail DB transaction {} due to error; trying rollback", txId, e );
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
} else {
log.warn( "No Cottontail DB transaction for Xid {} could be found.", xid );
Expand All @@ -142,7 +143,7 @@ public void rollback( PolyXid xid ) {
this.transactions.remove( xid );
} catch ( StatusRuntimeException e ) {
log.error( "Could not ROLLBACK Cottontail DB transaction {} due to error.", txId, e );
throw new RuntimeException( e );
throw new GenericRuntimeException( e );
}
} else {
log.warn( "No Cottontail DB transaction for Xid {} could be found.", xid );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.polypheny.db.algebra.core.Filter;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeField;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.AlgTraitSet;
import org.polypheny.db.rex.RexCall;
Expand Down Expand Up @@ -323,7 +324,7 @@ public static Where generateWhere( Object filterExpression ) {
return Where.newBuilder().setCompound( (CompoundBooleanPredicate) filterExpression ).build();
}

throw new RuntimeException( "Not a proper filter expression!" );
throw new GenericRuntimeException( "Not a proper filter expression!" );
}

}
Expand Down Expand Up @@ -595,7 +596,7 @@ public Op inverse() {
case ROOT:
return this;
}
throw new RuntimeException( "Unreachable code!" );
throw new GenericRuntimeException( "Unreachable code!" );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.core.Sort;
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.AlgOptCost;
import org.polypheny.db.plan.AlgOptPlanner;
Expand Down Expand Up @@ -133,7 +134,7 @@ private static Expression numberBuilderBuilder( RexNode node ) {
} else if ( node instanceof RexDynamicParam ) {
expr = Expressions.call( dynamicParameterMap_, BuiltInMethod.MAP_GET.method, Expressions.constant( ((RexDynamicParam) node).getIndex() ) );
} else {
throw new RuntimeException( "Node statement is neither a Literal nor a Dynamic Parameter." );
throw new GenericRuntimeException( "Node statement is neither a Literal nor a Dynamic Parameter." );
}

inner.add( Expressions.return_( null, expr ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.polypheny.db.algebra.core.relational.RelModify;
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
import org.polypheny.db.algebra.type.AlgDataTypeField;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.plan.AlgOptCost;
import org.polypheny.db.plan.AlgOptPlanner;
import org.polypheny.db.plan.AlgTraitSet;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void implement( CottontailImplementContext context ) {
// context.visitChild( 0, getInput() );
break;
case MERGE:
throw new RuntimeException( "Merge is not supported." );
throw new GenericRuntimeException( "Merge is not supported." );
}

}
Expand Down Expand Up @@ -174,7 +175,7 @@ private Expression buildUpdateTupleBuilder( CottontailImplementContext context )
} else if ( (rexNode instanceof RexCall) && (((RexCall) rexNode).getOperator() instanceof SqlArrayValueConstructor) ) {
source_ = CottontailTypeUtil.rexArrayConstructorToExpression( (RexCall) rexNode, columnTypes.get( actualColumnIndex ) );
} else {
throw new RuntimeException( "unable to convert expression." );
throw new GenericRuntimeException( "unable to convert expression." );
}

inner.add( Expressions.statement(
Expand Down
Loading

0 comments on commit d30deff

Please sign in to comment.