Skip to content

Commit

Permalink
Merge branch 'document-fix' of github.com:polypheny/Polypheny-DB into…
Browse files Browse the repository at this point in the history
… document-fix
  • Loading branch information
datomo committed Apr 8, 2024
2 parents 021e5d6 + 94b7dc4 commit a5df4f3
Show file tree
Hide file tree
Showing 62 changed files with 408 additions and 193 deletions.
3 changes: 1 addition & 2 deletions config/src/main/java/org/polypheny/db/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,7 @@ protected void notifyConfigListeners() {
boolean validate( final Object i ) {
if ( this.validationMethod != null ) {
return this.validationMethod.validate( i );
} //else if (this.validationMethod == null ) {
else {
} else {
return true;
}
}
Expand Down
6 changes: 4 additions & 2 deletions config/src/main/java/org/polypheny/db/config/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package org.polypheny.db.config;

import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor
@Value
public class Feedback {

public final boolean successful;
public final String message;
public boolean successful;
public String message;


public static Feedback of( boolean successful ) {
Expand Down
178 changes: 98 additions & 80 deletions config/src/main/java/org/polypheny/db/webui/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,96 +84,114 @@ private void configRoutes( final Javalin http ) {
StringBuilder feedback = new StringBuilder();
boolean allValid = true;
for ( Map.Entry<String, Object> entry : changes.entrySet() ) {
Config c = cm.getConfig( entry.getKey() );
switch ( c.getConfigType() ) {
case "ConfigInteger":
Double d = (Double) entry.getValue();
if ( !c.setInt( d.intValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigDouble":
if ( !c.setDouble( (double) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigDecimal":
if ( !c.setDecimal( (BigDecimal) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigLong":
if ( !c.setLong( (long) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
case "ConfigString":
if ( !c.setString( (String) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigBoolean":
if ( !c.setBoolean( (boolean) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigClazz":
case "ConfigEnum":
if ( !c.parseStringAndSetValue( (String) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigClazzList":
case "ConfigEnumList":
try {
if ( !c.parseStringAndSetValue( mapper.writeValueAsString( entry.getValue() ) ) ) {
allValid = false;
appendError( feedback, entry, c );
}
} catch ( JsonProcessingException e ) {
allValid = false;
appendError( feedback, entry, c );
}

break;
case "ConfigList":
Feedback res = c.setConfigObjectList( (List<Object>) entry.getValue(), c.getTemplateClass() );
if ( !res.successful ) {
allValid = false;
if ( res.message.trim().isEmpty() ) {
appendError( feedback, entry, c );
} else {
feedback.append( "Could not set " )
.append( c.getKey() )
.append( " due to: " )
.append( res.message )
.append( " " );
}

}
break;
default:
allValid = false;
feedback.append( "Config with type " ).append( c.getConfigType() ).append( " is not supported yet." );
log.error( "Config with type {} is not supported yet.", c.getConfigType() );
try {
allValid = trySetConfig( entry, cm, allValid, feedback );
} catch ( Exception e ) {
allValid = false;
feedback.append( "Could not set " )
.append( entry.getKey() )
.append( " to " )
.append( entry.getValue() )
.append( " because of: " )
.append( e.getMessage() )
.append( " " );
}

}
if ( allValid ) {
ctx.result( "{\"success\":1}" );
ctx.json( new Feedback( true, "All values were saved." ) );
} else {
feedback.append( "All other values were saved." );
ctx.result( "{\"warning\": \"" + feedback + "\"}" );
ctx.json( new Feedback( false, feedback.toString() ) );
}
} );
}


private boolean trySetConfig( Entry<String, Object> entry, ConfigManager cm, boolean allValid, StringBuilder feedback ) {
Config c = cm.getConfig( entry.getKey() );
switch ( c.getConfigType() ) {
case "ConfigInteger":
Double d = (Double) entry.getValue();
if ( !c.setInt( d.intValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigDouble":
if ( !c.setDouble( (double) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigDecimal":
if ( !c.setDecimal( (BigDecimal) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigLong":
if ( !c.setLong( (long) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
case "ConfigString":
if ( !c.setString( (String) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigBoolean":
if ( !c.setBoolean( (boolean) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigClazz":
case "ConfigEnum":
if ( !c.parseStringAndSetValue( (String) entry.getValue() ) ) {
allValid = false;
appendError( feedback, entry, c );
}
break;
case "ConfigClazzList":
case "ConfigEnumList":
try {
if ( !c.parseStringAndSetValue( mapper.writeValueAsString( entry.getValue() ) ) ) {
allValid = false;
appendError( feedback, entry, c );
}
} catch ( JsonProcessingException e ) {
allValid = false;
appendError( feedback, entry, c );
}

break;
case "ConfigList":
Feedback res = c.setConfigObjectList( (List<Object>) entry.getValue(), c.getTemplateClass() );
if ( !res.successful ) {
allValid = false;
if ( res.message.trim().isEmpty() ) {
appendError( feedback, entry, c );
} else {
feedback.append( "Could not set " )
.append( c.getKey() )
.append( " due to: " )
.append( res.message )
.append( " " );
}

}
break;
default:
allValid = false;
feedback.append( "Config with type " ).append( c.getConfigType() ).append( " is not supported yet." );
log.error( "Config with type {} is not supported yet.", c.getConfigType() );
}
return allValid;
}


private static void appendError( StringBuilder feedback, Entry<String, Object> entry, Config c ) {
feedback.append( "Could not set " )
.append( c.getKey() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import org.polypheny.db.type.PolyTypeUtil;
import org.polypheny.db.type.entity.PolyBoolean;
import org.polypheny.db.type.entity.PolyList;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.category.PolyNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.polypheny.db.algebra.rules;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.polypheny.db.adapter.AdapterManager;
import org.polypheny.db.algebra.AlgNode;
Expand All @@ -25,9 +27,11 @@
import org.polypheny.db.algebra.logical.lpg.LogicalLpgScan;
import org.polypheny.db.algebra.logical.relational.LogicalRelScan;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeField;
import org.polypheny.db.catalog.entity.allocation.AllocationEntity;
import org.polypheny.db.plan.AlgOptRule;
import org.polypheny.db.plan.AlgOptRuleCall;
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.schema.trait.ModelTraitDef;
import org.polypheny.db.tools.AlgBuilder;

Expand Down Expand Up @@ -89,6 +93,10 @@ private static AlgNode handleDocumentEntity( AlgOptRuleCall call, Scan<?> scan,
private AlgNode handleRelationalEntity( AlgOptRuleCall call, Scan<?> scan, AllocationEntity alloc ) {
AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).orElseThrow().getRelScan( alloc.id, call.builder() );
if ( scan.getModel() == scan.entity.dataModel ) {
if ( scan.getTupleType().getFieldCount() != alg.getTupleType().getFieldCount() ) {
alg = reduce( alg, scan, call.builder() );
}

alg = attachReorder( alg, scan, call.builder() );
}

Expand All @@ -100,6 +108,19 @@ private AlgNode handleRelationalEntity( AlgOptRuleCall call, Scan<?> scan, Alloc
}


private AlgNode reduce( AlgNode current, Scan<?> scan, AlgBuilder builder ) {
builder.push( current );

List<RexNode> projects = new ArrayList<>();
for ( AlgDataTypeField field : scan.getTupleType().getFields() ) {
if ( current.getTupleType().getField( field.getName(), true, false ) != null ) {
projects.add( builder.field( field.getName() ) );
}
}
return builder.project( projects ).build();
}


private AlgNode attachReorder( AlgNode newAlg, Scan<?> original, AlgBuilder builder ) {
if ( newAlg.getTupleType().equals( original.getTupleType() ) ) {
return newAlg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.polypheny.db.catalog.entity.PolyObject;
import org.polypheny.db.catalog.logistic.IndexType;
import org.polypheny.db.type.entity.PolyBoolean;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.numerical.PolyInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.entity.PolyObject;
import org.polypheny.db.catalog.snapshot.Snapshot;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.PolyValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ public synchronized void commit() {


public void rollback() {
long id = snapshot.id();
restoreLastState();

log.debug( "rollback" );

updateSnapshot();
if ( id != snapshot.id() ) {
updateSnapshot();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.polypheny.db.algebra.type.GraphType;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.entity.PolyList;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.document.PolyDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
import org.polypheny.db.type.entity.PolyBoolean;
import org.polypheny.db.type.entity.PolyInterval;
import org.polypheny.db.type.entity.PolyList;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.category.PolyNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.polypheny.db.adapter.DataContext;
import org.polypheny.db.nodes.TimeUnitRange;
import org.polypheny.db.type.entity.PolyInterval;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.category.PolyNumber;
import org.polypheny.db.type.entity.category.PolyTemporal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.schema.impl.AggregateFunctionImpl;
import org.polypheny.db.type.entity.PolyBoolean;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.util.Conformance;
import org.polypheny.db.util.ImmutableBitSet;
Expand Down
18 changes: 17 additions & 1 deletion core/src/main/java/org/polypheny/db/rex/RexLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public RexLiteral( PolyValue value, AlgDataType type, PolyType polyType ) {
System.err.println( polyType );
throw new IllegalArgumentException();
}
// Preconditions.checkArgument( valueMatchesType( value, typeName, true ) );
Preconditions.checkArgument( (value != null) || type.isNullable() );
Preconditions.checkArgument( polyType != PolyType.ANY );
this.digest = computeDigest( RexDigestIncludeType.OPTIONAL );
Expand Down Expand Up @@ -647,5 +646,22 @@ public int compareTo( RexLiteral o ) {
? 1 : -1;
}


/**
* Returns the value of this literal with the possibility to handle some edge cases. Like for parameterization.
*
* @param type the type to convert the value to
* @return the value of this literal
*/
public PolyValue getValue( AlgDataType type ) {
if ( value == null ) {
return null;
}
if ( PolyType.EXACT_TYPES.contains( type.getPolyType() ) && (PolyType.APPROX_TYPES.contains( value.type ) || PolyType.DECIMAL == value.type) ) {
return PolyValue.convert( value, type.getPolyType() );
}
return value;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import org.polypheny.db.type.entity.PolyBinary;
import org.polypheny.db.type.entity.PolyBoolean;
import org.polypheny.db.type.entity.PolyList;
import org.polypheny.db.type.entity.PolyLong;
import org.polypheny.db.type.entity.numerical.PolyLong;
import org.polypheny.db.type.entity.PolyString;
import org.polypheny.db.type.entity.document.PolyDocument;
import org.polypheny.db.type.entity.numerical.PolyBigDecimal;
Expand Down
Loading

0 comments on commit a5df4f3

Please sign in to comment.