Skip to content

Commit

Permalink
fix for rollback with data sources and fix for data source column rem…
Browse files Browse the repository at this point in the history
…oval
  • Loading branch information
datomo committed Apr 7, 2024
1 parent 74d44ee commit 1f4ba2f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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 @@ -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 @@ -261,6 +261,10 @@ public static void attachAnalyzerIfSpecified( QueryContext context, InformationO

@NotNull
public static ResultBuilder<?, ?, ?, ?> getRelResult( ExecutedContext context, UIRequest request, Statement statement ) {
if ( context.getException().isPresent() ) {
return buildErrorResult( statement.getTransaction(), context, context.getException().get() );
}

Catalog catalog = Catalog.getInstance();
ResultIterator iterator = context.getIterator();
List<List<PolyValue>> rows = new ArrayList<>();
Expand Down

0 comments on commit 1f4ba2f

Please sign in to comment.