diff --git a/core/src/main/java/org/polypheny/db/processing/WhereClauseVisitor.java b/core/src/main/java/org/polypheny/db/processing/WhereClauseVisitor.java index 6d4e7dabfd..1ea8d74f6f 100644 --- a/core/src/main/java/org/polypheny/db/processing/WhereClauseVisitor.java +++ b/core/src/main/java/org/polypheny/db/processing/WhereClauseVisitor.java @@ -27,6 +27,7 @@ import org.polypheny.db.rex.RexNode; import org.polypheny.db.rex.RexShuttle; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.type.entity.PolyValue; /** @@ -36,7 +37,7 @@ public class WhereClauseVisitor extends RexShuttle { private final Statement statement; @Getter - private final List values = new ArrayList<>(); + private final List values = new ArrayList<>(); private final long partitionColumnIndex; @Getter protected boolean valueIdentified = false; @@ -57,11 +58,11 @@ public RexNode visitCall( final RexCall call ) { if ( call.operands.size() == 2 ) { if ( call.op.getKind() == Kind.EQUALS ) { - Object value; + PolyValue value; if ( call.operands.get( 0 ) instanceof RexIndexRef ) { if ( ((RexIndexRef) call.operands.get( 0 )).getIndex() == partitionColumnIndex ) { if ( call.operands.get( 1 ) instanceof RexLiteral ) { - value = ((RexLiteral) call.operands.get( 1 )).getValueForQueryParameterizer(); + value = ((RexLiteral) call.operands.get( 1 )).value; values.add( value ); valueIdentified = true; } else if ( call.operands.get( 1 ) instanceof RexDynamicParam ) { diff --git a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java index e2bd4e22f4..a105ae08e6 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -2568,7 +2568,7 @@ private Pair, PartitionProperty> addGroupsAndPartition int j = 0; for ( AllocationPartitionGroup group : partitionGroups.keySet() ) { - List qualifiers = group.isUnbound ? null : (j < partitionInfo.qualifiers.size() + 1 ? null : partitionInfo.qualifiers.get( j++ )); + List qualifiers = group.isUnbound ? null : (j < partitionInfo.qualifiers.size() ? partitionInfo.qualifiers.get( j++ ) : null); partitionGroups.put( group, List.of( catalog.getAllocRel( partitionInfo.table.namespaceId ).addPartition( partitionInfo.table.id, partitionInfo.table.namespaceId, @@ -2577,7 +2577,8 @@ private Pair, PartitionProperty> addGroupsAndPartition group.isUnbound, PlacementType.AUTOMATIC, DataPlacementRole.REFRESHABLE, - qualifiers, PartitionType.NONE ) ) ); + qualifiers, + PartitionType.NONE ) ) ); } //get All PartitionGroups and then get all partitionIds for each PG and add them to completeList of partitionIds diff --git a/dbms/src/main/java/org/polypheny/db/partition/RangePartitionManager.java b/dbms/src/main/java/org/polypheny/db/partition/RangePartitionManager.java index b6fc84ad22..9641bf694f 100644 --- a/dbms/src/main/java/org/polypheny/db/partition/RangePartitionManager.java +++ b/dbms/src/main/java/org/polypheny/db/partition/RangePartitionManager.java @@ -50,7 +50,7 @@ public long getTargetPartitionId( LogicalTable table, PartitionProperty property // Process all accumulated CatalogPartitions for ( AllocationPartition partition : Catalog.snapshot().alloc().getPartitionsFromLogical( table.id ) ) { - if ( unboundPartitionId == -1 && partition.isUnbound ) { + if ( partition.isUnbound ) { unboundPartitionId = partition.id; break; } diff --git a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java index 9c5bc13261..54a3a66736 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java +++ b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java @@ -740,7 +740,12 @@ public void copyAllocationData( Transaction transaction, LogicalAdapter store, L i++; } }*/ - int columIndex = 0; // todo dl //snapshot.alloc().getC sourcePlacement.indexOf( targetProperty.partitionColumnId ); + int columIndex = 0; + if ( partitionColumn.tableId == table.id ) { + columIndex = source.sourceAlg.alg.getRowType().getField( partitionColumn.name, true, false ).getIndex(); + } + + //int partitionColumnIndex = -1; String parsedValue = null; diff --git a/dbms/src/main/java/org/polypheny/db/routing/routers/DmlRouterImpl.java b/dbms/src/main/java/org/polypheny/db/routing/routers/DmlRouterImpl.java index 4d8ac666ac..fd8813c2d0 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/routers/DmlRouterImpl.java +++ b/dbms/src/main/java/org/polypheny/db/routing/routers/DmlRouterImpl.java @@ -211,7 +211,7 @@ public AlgNode visit( LogicalFilter filter ) { if ( !whereClauseVisitor.getValues().isEmpty() ) { whereClauseValues = whereClauseVisitor.getValues().stream() - .map( Object::toString ) + .map( PolyValue::toJson ) .collect( Collectors.toList() ); if ( log.isDebugEnabled() ) { log.debug( "Found Where Clause Values: {}", whereClauseValues ); @@ -293,7 +293,7 @@ public AlgNode visit( LogicalFilter filter ) { if ( !operationWasRewritten ) { for ( long partitionId : accessedPartitions ) { - if ( catalog.getSnapshot().alloc().getPartitionsFromLogical( table.id ).stream().noneMatch( p -> p.id == partitionId ) ) { + if ( catalog.getSnapshot().alloc().getAlloc( pkPlacement.id, partitionId ).isEmpty() ) { continue; } @@ -367,7 +367,7 @@ private Triple handleDmlInsert( List updateColumn if ( partitionColumnIndex == -1 || currentTuple.get( partitionColumnIndex ).getValue() == null ) { partitionValue = PartitionManager.NULL_STRING; } else { - partitionValue = currentTuple.get( partitionColumnIndex ).toString().replace( "'", "" ); + partitionValue = currentTuple.get( partitionColumnIndex ).value.toJson().replace( "'", "" ); } identPart = (int) partitionManager.getTargetPartitionId( table, property, partitionValue ); accessedPartitionList.add( identPart ); @@ -453,8 +453,7 @@ private Triple handleDmlInsert( List updateColumn tempPartitionId = partitionManager.getTargetPartitionId( table, property, currentRow.get( partitionValueIndex ).toString() ); - long finalTempPartitionId = tempPartitionId; - if ( catalog.getSnapshot().alloc().getPartitionsFromLogical( table.id ).stream().noneMatch( p -> p.id == finalTempPartitionId ) ) { + if ( catalog.getSnapshot().alloc().getAlloc( pkPlacement.id, tempPartitionId ).isEmpty() ) { continue; } @@ -541,7 +540,7 @@ private Pair, String> handleDmlUpdate( List updateColumns, Log log.debug( " UPDATE: Found PartitionColumnID Match: '{}' at index: {}", property.partitionColumnId, index ); } // Routing/Locking can now be executed on certain partitions - partitionValue = sourceExpressionList.get( index ).toString().replace( "'", "" ); + partitionValue = ((RexLiteral) sourceExpressionList.get( index )).value.toJson().replace( "'", "" ); if ( log.isDebugEnabled() ) { log.debug( "UPDATE: partitionColumn-value: '{}' should be put on partition: {}", diff --git a/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java b/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java index 8b83662eab..6a726c889f 100644 --- a/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java +++ b/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java @@ -783,7 +783,7 @@ public void temperaturePartitionTest() throws SQLException { long targetId = partitionManager.getTargetPartitionId( table, partitionProperty, partitionValue ); List hotPartitionsAfterChange = Catalog.snapshot().alloc().getPartitionsFromGroup( ((TemperaturePartitionProperty) updatedProperty).getHotPartitionGroupId() ); - Assert.assertTrue( hotPartitionsAfterChange.stream().map( p -> p.id ).collect( Collectors.toList() ).contains( Catalog.snapshot().alloc().getEntity( targetId ).orElseThrow().partitionId ) ); + Assert.assertTrue( hotPartitionsAfterChange.stream().map( p -> p.id ).collect( Collectors.toList() ).contains( targetId ) ); //Todo @Hennlo check number of access } finally { @@ -1077,7 +1077,7 @@ public void hybridPartitioningTest() throws SQLException { new Object[]{ 407, "BarFoo", 67 } ) ); // Remove data - statement.executeUpdate( "DELETE FROM \"hybridpartitioningtest\" where tvarchar = 'Foo' " ); + statement.executeUpdate( "DELETE FROM \"hybridpartitioningtest\" where tvarchar = 'Foo'" ); // Assert and Check if Table has the desired entries TestHelper.checkResultSet(