From 1f4ba2f255139439612bfa33244970ec127abceb Mon Sep 17 00:00:00 2001 From: datomo Date: Sun, 7 Apr 2024 16:53:48 +0200 Subject: [PATCH] fix for rollback with data sources and fix for data source column removal --- .../rules/AllocationToPhysicalScanRule.java | 21 +++++++++++++++++++ .../db/catalog/impl/PolyCatalog.java | 5 ++++- .../polypheny/db/webui/crud/LanguageCrud.java | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java index 1c379df8a2..468042c5e8 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java @@ -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; @@ -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; @@ -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() ); } @@ -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 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; diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java b/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java index b96d5dae61..4b36738aa3 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java @@ -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(); + } } diff --git a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java index ad13011970..027943f220 100644 --- a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java @@ -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> rows = new ArrayList<>();