diff --git a/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java b/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java index a365e47770..467586925e 100644 --- a/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java @@ -98,4 +98,10 @@ public void dropCollection( Context context, AllocationCollection allocation ) { } + @Override + public void renameLogicalColumn( long id, String newColumnName ) { + getCatalog().renameLogicalField( id, newColumnName ); + } + + } diff --git a/core/src/main/java/org/polypheny/db/adapter/GraphModifyDelegate.java b/core/src/main/java/org/polypheny/db/adapter/GraphModifyDelegate.java index b769586ee0..bc7184405d 100644 --- a/core/src/main/java/org/polypheny/db/adapter/GraphModifyDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/GraphModifyDelegate.java @@ -16,14 +16,10 @@ package org.polypheny.db.adapter; -import java.util.List; import org.polypheny.db.catalog.catalogs.GraphStoreCatalog; -import org.polypheny.db.catalog.entity.allocation.AllocationCollection; -import org.polypheny.db.catalog.entity.allocation.AllocationGraph; import org.polypheny.db.catalog.entity.allocation.AllocationTable; import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalIndex; -import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.prepare.Context; @@ -69,21 +65,4 @@ public void updateColumnType( Context context, long allocId, LogicalColumn colum } - @Override - public void restoreTable( AllocationTable alloc, List entities ) { - scannable.restoreTable( alloc, entities ); - } - - - @Override - public void restoreGraph( AllocationGraph alloc, List entities ) { - scannable.restoreGraph( alloc, entities ); - } - - - @Override - public void restoreCollection( AllocationCollection alloc, List entities ) { - Scannable.restoreCollectionSubstitute( scannable, alloc, entities ); - } - } diff --git a/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java b/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java index 7fd4a5eb76..d51f1c528d 100644 --- a/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java @@ -47,6 +47,7 @@ public List createTable( Context context, LogicalTableWrapper lo return scannable.createTable( context, logical, allocation ); } + @Override public void restoreTable( AllocationTable alloc, List entities ) { scannable.restoreTable( alloc, entities ); @@ -94,4 +95,10 @@ public void dropCollection( Context context, AllocationCollection allocation ) { Scannable.dropCollectionSubstitute( scannable, context, allocation ); } + + @Override + public void renameLogicalColumn( long id, String newColumnName ) { + getCatalog().renameLogicalField( id, newColumnName ); + } + } diff --git a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java index fb4ac5e5e0..1596b652d0 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java @@ -282,8 +282,8 @@ default AlgNode getRelModify( long allocId, RelModify modify, AlgBuilder buil table, modify.getInput(), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList() ); + modify.getUpdateColumns(), + modify.getSourceExpressions() ); } default AlgNode getDocModify( long allocId, DocumentModify modify, AlgBuilder builder ) { diff --git a/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java b/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java index d8996bf4db..bec0ee1b59 100644 --- a/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java @@ -59,7 +59,6 @@ public List createTable( Context context, LogicalTableWrapper lo } - @Override public void restoreTable( AllocationTable alloc, List entities ) { scannable.restoreTable( alloc, entities ); @@ -107,4 +106,10 @@ public void dropCollection( Context context, AllocationCollection allocation ) { Scannable.dropCollectionSubstitute( scannable, context, allocation ); } + + @Override + public void renameLogicalColumn( long id, String newColumnName ) { + scannable.renameLogicalColumn( id, newColumnName ); + } + } diff --git a/core/src/main/java/org/polypheny/db/adapter/Scannable.java b/core/src/main/java/org/polypheny/db/adapter/Scannable.java index e0c219c01b..0889ada1a5 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Scannable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Scannable.java @@ -60,17 +60,17 @@ static PhysicalTable createSubstitutionTable( Scannable scannable, Context conte columns.add( column ); i++; } - AllocationTable allocTable = new AllocationTable( builder.getNewAllocId(), allocation.placementId, allocation.partitionId, table.id, table.namespaceId, allocation.adapterId ); + AllocationTable allocSubTable = new AllocationTable( builder.getNewAllocId(), allocation.placementId, allocation.partitionId, table.id, table.namespaceId, allocation.adapterId ); List allocColumns = new ArrayList<>(); i = 1; for ( LogicalColumn column : columns ) { - AllocationColumn alloc = new AllocationColumn( logical.namespaceId, allocTable.placementId, allocTable.logicalId, column.id, PlacementType.AUTOMATIC, i++, allocation.adapterId ); + AllocationColumn alloc = new AllocationColumn( logical.namespaceId, allocSubTable.placementId, allocSubTable.logicalId, column.id, PlacementType.AUTOMATIC, i++, allocation.adapterId ); allocColumns.add( alloc ); } - scannable.createTable( context, LogicalTableWrapper.of( table, columns ), AllocationTableWrapper.of( allocTable, allocColumns ) ); - return scannable.getCatalog().getPhysicalsFromAllocs( allocation.id ).get( 0 ).unwrap( PhysicalTable.class ); + scannable.createTable( context, LogicalTableWrapper.of( table, columns ), AllocationTableWrapper.of( allocSubTable, allocColumns ) ); + return scannable.getCatalog().getPhysicalsFromAllocs( allocSubTable.id ).get( 0 ).unwrap( PhysicalTable.class ); } StoreCatalog getCatalog(); @@ -217,4 +217,6 @@ static void dropCollectionSubstitute( Scannable scannable, Context context, Allo } + void renameLogicalColumn( long id, String newColumnName ); + } diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java b/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java index 6038406b65..80c34b32ba 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java @@ -538,8 +538,8 @@ public void rewriteAlg( LogicalRelModify alg ) { alg.getEntity(), getNewForOldRel( alg.getInput() ), alg.getOperation(), - alg.getUpdateColumnList(), - alg.getSourceExpressionList(), + alg.getUpdateColumns(), + alg.getSourceExpressions(), true ); setNewForOldAlg( alg, newAlg ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/common/Transformer.java b/core/src/main/java/org/polypheny/db/algebra/core/common/Transformer.java index ddb21ee0b4..57b3f0ead7 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/common/Transformer.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/common/Transformer.java @@ -73,7 +73,7 @@ public Transformer( AlgOptCluster cluster, List inputs, @Nullable List< this.rowType = rowType; this.isCrossModel = isCrossModel; this.names = names; - assert names == null || (names.size() == 0 || names.size() == inputs.size()) : "When names are provided they have to match the amount of inputs."; + assert names == null || (names.isEmpty() || names.size() == inputs.size()) : "When names are provided they have to match the amount of inputs."; } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java index 03f23a817e..7a3b9a0b6e 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java @@ -35,7 +35,6 @@ import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.prepare.Prepare; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.trait.ModelTrait; import org.polypheny.db.type.PolyTypeUtil; @@ -56,20 +55,15 @@ public abstract class RelModify extends Modify { - /** - * The connection to the optimizing session. - */ - protected Prepare.CatalogReader catalogReader; - /** * The table definition. */ @Getter private final Operation operation; @Getter - private final List updateColumnList; + private final List updateColumns; @Getter - private final List sourceExpressionList; + private final List sourceExpressions; private AlgDataType inputRowType; @Getter private final boolean flattened; @@ -88,8 +82,8 @@ public abstract class RelModify extends Modify { * @param table Target table to modify * @param input Sub-query or filter condition * @param operation Modify operation (INSERT, UPDATE, DELETE) - * @param updateColumnList List of column identifiers to be updated (e.g. ident1, ident2); null if not UPDATE - * @param sourceExpressionList List of value expressions to be set (e.g. exp1, exp2); null if not UPDATE + * @param updateColumns List of column identifiers to be updated (e.g. ident1, ident2); null if not UPDATE + * @param sourceExpressions List of value expressions to be set (e.g. exp1, exp2); null if not UPDATE * @param flattened Whether set flattens the input row type */ protected RelModify( @@ -98,20 +92,20 @@ protected RelModify( E table, AlgNode input, Operation operation, - List updateColumnList, - List sourceExpressionList, + List updateColumns, + List sourceExpressions, boolean flattened ) { super( cluster, traitSet.replace( ModelTrait.RELATIONAL ), table, input ); this.operation = operation; - this.updateColumnList = updateColumnList; - this.sourceExpressionList = sourceExpressionList; + this.updateColumns = updateColumns; + this.sourceExpressions = sourceExpressions; if ( operation == Operation.UPDATE ) { - Objects.requireNonNull( updateColumnList ); - Objects.requireNonNull( sourceExpressionList ); - Preconditions.checkArgument( sourceExpressionList.size() == updateColumnList.size() ); + Objects.requireNonNull( updateColumns ); + Objects.requireNonNull( sourceExpressions ); + Preconditions.checkArgument( sourceExpressions.size() == updateColumns.size() ); } else { - Preconditions.checkArgument( updateColumnList == null ); - Preconditions.checkArgument( sourceExpressionList == null ); + Preconditions.checkArgument( updateColumns == null ); + Preconditions.checkArgument( sourceExpressions == null ); } this.flattened = flattened; } @@ -185,8 +179,8 @@ public AlgWriter explainTerms( AlgWriter pw ) { .item( "entity", entity.id ) .item( "layer", entity.getCatalogType() ) .item( "operation", getOperation() ) - .itemIf( "updateColumnList", updateColumnList, updateColumnList != null ) - .itemIf( "sourceExpressionList", sourceExpressionList, sourceExpressionList != null ) + .itemIf( "updateColumns", updateColumns, updateColumns != null ) + .itemIf( "sourceExpressions", sourceExpressions, sourceExpressions != null ) .item( "flattened", flattened ); } @@ -205,8 +199,8 @@ public String algCompareString() { "." + entity.id + "$" + (getInputs() != null ? getInputs().stream().map( AlgNode::algCompareString ).collect( Collectors.joining( "$" ) ) + "$" : "") + getOperation().name() + "$" + - (getUpdateColumnList() != null ? getUpdateColumnList().stream().map( c -> "c" ).collect( Collectors.joining( "$" ) ) + "$" : "") + - (getSourceExpressionList() != null ? getSourceExpressionList().stream().map( RexNode::hashCode ).map( Objects::toString ).collect( Collectors.joining( "$" ) ) : "") + "$" + + (getUpdateColumns() != null ? getUpdateColumns().stream().map( c -> "c" ).collect( Collectors.joining( "$" ) ) + "$" : "") + + (getSourceExpressions() != null ? getSourceExpressions().stream().map( RexNode::hashCode ).map( Objects::toString ).collect( Collectors.joining( "$" ) ) : "") + "$" + isFlattened() + "&"; } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableTransformer.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableTransformer.java index 7379498384..be2249c50d 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableTransformer.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableTransformer.java @@ -57,6 +57,7 @@ import org.polypheny.db.schema.trait.ModelTraitDef; import org.polypheny.db.type.entity.PolyBinary; import org.polypheny.db.type.entity.PolyString; +import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.document.PolyDocument; import org.polypheny.db.util.BuiltInMethod; import org.polypheny.db.util.Pair; @@ -323,11 +324,11 @@ private Result implementDocumentOnRelational( EnumerableAlgImplementor implement List expressions = new ArrayList<>(); - ParameterExpression target = Expressions.parameter( Object[].class ); + ParameterExpression target = Expressions.parameter( PolyValue[].class ); attachDocOnRelational( impl, expressions, target ); - MethodCallExpression res = Expressions.call( RefactorFunctions.class, "mergeDocuments", expressions ); + Expression res = Expressions.newArrayInit( PolyValue.class, Expressions.call( RefactorFunctions.class, "mergeDocuments", expressions ) ); Type outputJavaType = physType.getJavaRowType(); final Type enumeratorType = Types.of( Enumerator.class, outputJavaType ); @@ -401,7 +402,7 @@ private Result implementRelationalOnDocument( EnumerableAlgImplementor implement } - private static Result toAbstractEnumerable( EnumerableAlgImplementor implementor, BlockBuilder builder, PhysType physType, Expression old, ParameterExpression target, MethodCallExpression transformer, Type enumeratorType ) { + private static Result toAbstractEnumerable( EnumerableAlgImplementor implementor, BlockBuilder builder, PhysType physType, Expression old, ParameterExpression target, Expression transformer, Type enumeratorType ) { BlockStatement block = Expressions.block( Expressions.return_( null, Expressions.call( diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/common/LogicalStreamer.java b/core/src/main/java/org/polypheny/db/algebra/logical/common/LogicalStreamer.java index ba48d707e5..1984906c32 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/common/LogicalStreamer.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/common/LogicalStreamer.java @@ -106,10 +106,10 @@ private static LogicalStreamer getLogicalStreamer( RelModify modify, AlgBuild AlgNode query = input; - if ( modify.getUpdateColumnList() != null && modify.getSourceExpressionList() != null ) { + if ( modify.getUpdateColumns() != null && modify.getSourceExpressions() != null ) { // update and source list are not null - update.addAll( modify.getUpdateColumnList() ); - source.addAll( modify.getSourceExpressionList() ); + update.addAll( modify.getUpdateColumns() ); + source.addAll( modify.getSourceExpressions() ); // we project the needed sources out and modify them to fit the prepared query = LogicalProject.create( modify.getInput(), source, update ); @@ -132,8 +132,8 @@ private static LogicalStreamer getLogicalStreamer( RelModify modify, AlgBuild modify.getEntity(), algBuilder.build(), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList() == null ? null : createSourceList( modify, rexBuilder ), + modify.getUpdateColumns(), + modify.getSourceExpressions() == null ? null : createSourceList( modify, rexBuilder ), false ).streamed( true ); return new LogicalStreamer( modify.getCluster(), modify.getTraitSet(), query, prepared ); } @@ -153,7 +153,7 @@ public static LogicalProject getCollector( RexBuilder rexBuilder, AlgNode input private static List createSourceList( RelModify modify, RexBuilder rexBuilder ) { - return modify.getUpdateColumnList() + return modify.getUpdateColumns() .stream() .map( name -> { int size = modify.getRowType().getFieldList().size(); diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelModify.java b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelModify.java index b695cf5d45..9ad551faa8 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelModify.java @@ -45,10 +45,10 @@ public LogicalRelModify( CatalogEntity table, AlgNode input, Operation operation, - List updateColumnList, - List sourceExpressionList, + List updateColumns, + List sourceExpressions, boolean flattened ) { - super( cluster, traitSet.replace( ModelTrait.RELATIONAL ), table, input, operation, updateColumnList, sourceExpressionList, flattened ); + super( cluster, traitSet.replace( ModelTrait.RELATIONAL ), table, input, operation, updateColumns, sourceExpressions, flattened ); } @@ -70,19 +70,19 @@ public static LogicalRelModify create( CatalogEntity table, AlgNode input, Operation operation, - List updateColumnList, - List sourceExpressionList, + List updateColumns, + List sourceExpressions, boolean flattened ) { final AlgOptCluster cluster = input.getCluster(); final AlgTraitSet traitSet = cluster.traitSetOf( Convention.NONE ); - return new LogicalRelModify( cluster, traitSet, table, input, operation, updateColumnList, sourceExpressionList, flattened ); + return new LogicalRelModify( cluster, traitSet, table, input, operation, updateColumns, sourceExpressions, flattened ); } @Override public LogicalRelModify copy( AlgTraitSet traitSet, List inputs ) { assert traitSet.containsIfApplicable( Convention.NONE ); - return (LogicalRelModify) new LogicalRelModify( getCluster(), traitSet, entity, sole( inputs ), getOperation(), getUpdateColumnList(), getSourceExpressionList(), isFlattened() ).streamed( streamed ); + return (LogicalRelModify) new LogicalRelModify( getCluster(), traitSet, entity, sole( inputs ), getOperation(), getUpdateColumns(), getSourceExpressions(), isFlattened() ).streamed( streamed ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/mutable/MutableAlgs.java b/core/src/main/java/org/polypheny/db/algebra/mutable/MutableAlgs.java index a796c0d2c7..7954c47975 100644 --- a/core/src/main/java/org/polypheny/db/algebra/mutable/MutableAlgs.java +++ b/core/src/main/java/org/polypheny/db/algebra/mutable/MutableAlgs.java @@ -381,8 +381,8 @@ public static MutableAlg toMutable( AlgNode alg ) { input, modify.getEntity(), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), + modify.getUpdateColumns(), + modify.getSourceExpressions(), modify.isFlattened() ); } if ( alg instanceof Sample ) { diff --git a/core/src/main/java/org/polypheny/db/algebra/mutable/MutableTableModify.java b/core/src/main/java/org/polypheny/db/algebra/mutable/MutableTableModify.java index 6f8ad5f481..15ed286b48 100644 --- a/core/src/main/java/org/polypheny/db/algebra/mutable/MutableTableModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/mutable/MutableTableModify.java @@ -36,12 +36,10 @@ import java.util.List; import java.util.Objects; -import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.algebra.core.common.Modify.Operation; +import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.entity.CatalogEntity; -import org.polypheny.db.plan.AlgOptEntity; -import org.polypheny.db.prepare.Prepare; import org.polypheny.db.rex.RexNode; diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/CalcMergeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/CalcMergeRule.java index cb1354cede..bc805e4617 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/CalcMergeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/CalcMergeRule.java @@ -34,6 +34,7 @@ package org.polypheny.db.algebra.rules; +import java.util.Objects; import org.polypheny.db.algebra.core.AlgFactories; import org.polypheny.db.algebra.core.Calc; import org.polypheny.db.algebra.logical.relational.LogicalCalc; @@ -83,7 +84,7 @@ public void onMatch( AlgOptRuleCall call ) { topCalc.getProgram(), bottomCalc.getProgram(), topCalc.getCluster().getRexBuilder() ); - assert mergedProgram.getOutputRowType() == topProgram.getOutputRowType(); + assert Objects.equals( mergedProgram.getOutputRowType(), topProgram.getOutputRowType() ); final Calc newCalc = topCalc.copy( topCalc.getTraitSet(), diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/SimpleAllocationToPhysicalModifyRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/SimpleAllocationToPhysicalModifyRule.java deleted file mode 100644 index 65b94f1058..0000000000 --- a/core/src/main/java/org/polypheny/db/algebra/rules/SimpleAllocationToPhysicalModifyRule.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2019-2023 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.algebra.rules; - -import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.algebra.core.document.DocumentModify; -import org.polypheny.db.algebra.core.document.DocumentValues; -import org.polypheny.db.plan.AlgOptRule; -import org.polypheny.db.plan.AlgOptRuleCall; -import org.polypheny.db.plan.Convention; - -@Slf4j -public class SimpleAllocationToPhysicalModifyRule extends AlgOptRule { - - public static final SimpleAllocationToPhysicalModifyRule DOC_INSTANCE = new SimpleAllocationToPhysicalModifyRule(); - - - public SimpleAllocationToPhysicalModifyRule() { - super( operand( DocumentModify.class, operand( DocumentValues.class, Convention.NONE, none() ) ) ); - } - - - @Override - public void onMatch( AlgOptRuleCall call ) { - log.warn( "todo" ); - return; - /*DocumentModify modify = call.alg( 0 ); - DocumentValues values = call.alg( 1 ); - - AlgBuilder builder = call.builder(); - - builder.push( modify.copy( modify.getTraitSet(), List.of( values.getRelationalEquivalent() ) ) ); - AlgNode node = builder.transform( ModelTrait.DOCUMENT, modify.getRowType(), false ).build(); - call.transformTo( node );*/ - - } - -} diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactory.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactory.java index ae320fc088..b12fa6466c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactory.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactory.java @@ -37,7 +37,6 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Objects; import org.polypheny.db.nodes.IntervalQualifier; import org.polypheny.db.type.PolyType; @@ -378,7 +377,7 @@ public FieldInfoBuilder add( AlgDataTypeField field ) { @Override - public FieldInfoBuilder addAll( Iterable> fields ) { + public FieldInfoBuilder addAll( Iterable fields ) { return (FieldInfoBuilder) super.addAll( fields ); } @@ -527,10 +526,10 @@ public Builder add( AlgDataTypeField field ) { /** * Adds all fields in a collection. */ - public Builder addAll( Iterable> fields ) { - for ( Map.Entry field : fields ) { + public Builder addAll( Iterable fields ) { + for ( AlgDataTypeField field : fields ) { // TODO MV: Adding null for physical name - add( null, field.getKey(), null, field.getValue() ); + add( field.getId(), field.getName(), field.getPhysicalName(), field.getType() ); } return this; } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java index 614ba66704..7701b7794f 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java @@ -34,9 +34,6 @@ package org.polypheny.db.algebra.type; -import java.util.Map; - - /** * RelDataTypeField represents the definition of a field in a structured {@link AlgDataType}. *

@@ -44,7 +41,7 @@ * In any implementation of this interface, {@link #getKey()} must be equivalent to {@link #getName()} and {@link #getValue()} * must be equivalent to {@link #getType()}. */ -public interface AlgDataTypeField extends Map.Entry { +public interface AlgDataTypeField { /** * Gets the name of this field, which is unique within its containing type. diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java index 9f5583ab19..4f38de0781 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java @@ -35,15 +35,18 @@ import java.io.Serializable; +import lombok.Getter; import lombok.Value; import org.polypheny.db.type.PolyType; +import org.polypheny.db.util.Triple; /** * Default implementation of {@link AlgDataTypeField}. */ @Value -public class AlgDataTypeFieldImpl implements AlgDataTypeField, Serializable { +@Getter +public class AlgDataTypeFieldImpl extends Triple implements AlgDataTypeField, Serializable { AlgDataType type; String name; @@ -61,6 +64,7 @@ public AlgDataTypeFieldImpl( Long id, String name, int index, AlgDataType type ) public AlgDataTypeFieldImpl( Long id, String name, String physicalName, int index, AlgDataType type ) { + super( name, id, type ); assert name != null; assert type != null; this.id = id; @@ -92,55 +96,6 @@ public boolean equals( Object obj ) { } - // implement RelDataTypeField - @Override - public String getName() { - return name; - } - - - // implement RelDataTypeField - @Override - public String getPhysicalName() { - return physicalName; - } - - - // implement RelDataTypeField - @Override - public int getIndex() { - return index; - } - - - // implement RelDataTypeField - @Override - public AlgDataType getType() { - return type; - } - - - // implement Map.Entry - @Override - public final String getKey() { - return getName(); - } - - - // implement Map.Entry - @Override - public final AlgDataType getValue() { - return getType(); - } - - - // implement Map.Entry - @Override - public AlgDataType setValue( AlgDataType value ) { - throw new UnsupportedOperationException(); - } - - // for debugging public String toString() { return "#" + index + ": " + name + " (" + physicalName + ") " + type; diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java index 8f59746412..6a9cd408e5 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.polypheny.db.type.PolyType; import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; @@ -104,7 +105,7 @@ Pair getFieldOrInsert( String fieldName, boolean case public List getFieldNames() { - return Pair.left( fields ); + return fields.stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); } } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeImpl.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeImpl.java index d873fb0bc3..21625651cb 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeImpl.java @@ -45,7 +45,6 @@ import org.polypheny.db.type.BasicPolyType; import org.polypheny.db.type.PolyType; import org.polypheny.db.util.Collation; -import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; @@ -162,7 +161,7 @@ public List getFieldList() { @Override public List getFieldNames() { - return Pair.left( fieldList ); + return fieldList.stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java index a2baa7a83a..e8f3b37324 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java @@ -55,7 +55,7 @@ public class DocStoreCatalog extends StoreCatalog { public BinarySerializer serializer = PolySerializable.buildSerializer( DocStoreCatalog.class ); @Serialize - public ConcurrentMap, PhysicalColumn> fields; // allocId, columnId + public ConcurrentMap, PhysicalField> fields; // allocId, columnId public DocStoreCatalog( long adapterId ) { @@ -63,6 +63,18 @@ public DocStoreCatalog( long adapterId ) { } + @Override + public void renameLogicalField( long id, String newFieldName ) { + List updates = new ArrayList<>(); + for ( PhysicalField field : fields.values() ) { + if ( field.id == id ) { + updates.add( field.unwrap( PhysicalColumn.class ).toBuilder().logicalName( newFieldName ).build() ); + } + } + updates.forEach( u -> fields.put( Pair.of( u.allocId, u.id ), u ) ); + } + + public DocStoreCatalog( @Deserialize("adapterId") long adapterId, @Deserialize("physicals") Map physicals, @@ -100,7 +112,7 @@ public void addColumn( PhysicalColumn column ) { public PhysicalColumn getColumn( long columnId, long allocId ) { - return fields.get( Pair.of( allocId, columnId ) ); + return fields.get( Pair.of( allocId, columnId ) ).unwrap( PhysicalColumn.class ); } @@ -110,7 +122,7 @@ public List getFields( long allocId ) { public void dropColumn( long allocId, long columnId ) { - PhysicalColumn column = fields.get( Pair.of( allocId, columnId ) ); + PhysicalColumn column = fields.get( Pair.of( allocId, columnId ) ).unwrap( PhysicalColumn.class ); PhysicalTable table = fromAllocation( allocId, PhysicalTable.class ); List pColumns = new ArrayList<>( table.columns ); pColumns.remove( column ); diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java index 8599756c4d..bbb5438e09 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java @@ -74,6 +74,18 @@ public GraphStoreCatalog( } + @Override + public void renameLogicalField( long id, String newFieldName ) { + List updates = new ArrayList<>(); + for ( PhysicalField field : fields.values() ) { + if ( field.id == id ) { + updates.add( field.unwrap( PhysicalColumn.class ).toBuilder().logicalName( newFieldName ).build() ); + } + } + updates.forEach( u -> fields.put( Pair.of( u.allocId, u.id ), u ) ); + } + + public PhysicalTable createTable( String namespaceName, String tableName, diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java index 6a83cd4ff2..58251a682d 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java @@ -74,6 +74,17 @@ public RelStoreCatalog( } + @Override + public void renameLogicalField( long id, String newFieldName ) { + List updates = new ArrayList<>(); + for ( PhysicalColumn field : columns.values() ) { + if ( field.id == id ) { + updates.add( field.toBuilder().logicalName( newFieldName ).build() ); + } + } + updates.forEach( u -> columns.put( Pair.of( u.allocId, u.id ), u ) ); + } + public void addColumn( PhysicalColumn column ) { columns.put( Pair.of( column.allocId, column.id ), column ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/StoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/StoreCatalog.java index eba9267b26..31d1a7d7c5 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/StoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/StoreCatalog.java @@ -148,4 +148,7 @@ public void removePhysical( long allocId ) { physicals.forEach( allocToPhysicals::remove ); } + + public abstract void renameLogicalField( long id, String newFieldName ); + } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java index 0f902ad486..628bf04d1c 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java @@ -87,6 +87,7 @@ public class PhysicalColumn extends PhysicalField { public PhysicalColumn( @Deserialize("id") final long id, @Deserialize("name") final String name, + @Deserialize("logicalName") final String logicalName, @Deserialize("allocId") final long allocId, @Deserialize("entityId") final long tableId, @Deserialize("adapterId") final long adapterId, @@ -100,7 +101,7 @@ public PhysicalColumn( @Deserialize("nullable") final boolean nullable, @Deserialize("collation") final Collation collation, @Deserialize("defaultValue") CatalogDefaultValue defaultValue ) { - super( id, name, allocId, tableId, adapterId, NamespaceType.RELATIONAL, true ); + super( id, name, logicalName, allocId, tableId, adapterId, NamespaceType.RELATIONAL, true ); this.position = position; this.type = type; this.collectionsType = collectionsType; @@ -124,6 +125,7 @@ public PhysicalColumn( this( column.id, name, + column.name, allocTableId, tableId, adapterId, diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java index ad540a2c24..e60a04176f 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java @@ -41,6 +41,8 @@ public abstract class PhysicalField extends CatalogEntity { @Serialize public long entityId; + @Serialize + public String logicalName; @Serialize public long allocId; @@ -49,6 +51,7 @@ public abstract class PhysicalField extends CatalogEntity { public PhysicalField( final long id, final String name, + final String logicalName, final long allocId, final long entityId, final long adapterId, @@ -58,6 +61,7 @@ public PhysicalField( this.entityId = entityId; this.allocId = allocId; this.adapterId = adapterId; + this.logicalName = logicalName; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java index 9f763a2bca..4a8bf26e1d 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java @@ -73,7 +73,7 @@ public AlgProtoDataType buildProto() { for ( PhysicalColumn column : columns.stream().sorted( Comparator.comparingInt( a -> a.position ) ).collect( Collectors.toList() ) ) { AlgDataType sqlType = column.getAlgDataType( AlgDataTypeFactory.DEFAULT ); - fieldInfo.add( column.id, column.name, column.name, sqlType ).nullable( column.nullable ); + fieldInfo.add( column.id, column.logicalName, column.name, sqlType ).nullable( column.nullable ); } return AlgDataTypeImpl.proto( fieldInfo.build() ); diff --git a/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/AllocSnapshotImpl.java b/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/AllocSnapshotImpl.java index 7a43566b0d..6df09df8c7 100644 --- a/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/AllocSnapshotImpl.java +++ b/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/AllocSnapshotImpl.java @@ -145,6 +145,7 @@ public AllocSnapshotImpl( Map allocationCatalogs, Map batch( final DataContext context, final Enumerable

> values = new ArrayList<>( context.getParameterValues() ); - if ( values.size() == 0 ) { + if ( values.isEmpty() ) { return baz; } @@ -343,7 +343,7 @@ public static Enumerable streamRight( final DataContext context, fin List results = new ArrayList<>(); Enumerable executor = executorCall.apply(); for ( Object o : executor ) { - results.add( o ); + results.add( new PolyValue[]{ (PolyValue) o } ); } context.resetParameterValues(); @@ -3195,7 +3195,7 @@ public static List reparse( PolyType innerType, Long dimension, String string if ( stringValue == null ) { return null; } - return PolyValue.fromTypedJson( stringValue, PolyList.class ).asList(); + return PolyValue.fromTypedJson( stringValue, PolyList.class ); } diff --git a/core/src/main/java/org/polypheny/db/functions/MqlFunctions.java b/core/src/main/java/org/polypheny/db/functions/MqlFunctions.java index f09c5dfb17..02dc2fc9d8 100644 --- a/core/src/main/java/org/polypheny/db/functions/MqlFunctions.java +++ b/core/src/main/java/org/polypheny/db/functions/MqlFunctions.java @@ -177,7 +177,7 @@ public static PolyValue docRemove( PolyValue input, List> names PolyString name; for ( List split : names ) { Iterator iter = split.iterator(); - check: + while ( iter.hasNext() ) { name = iter.next(); if ( doc.containsKey( name ) ) { @@ -187,7 +187,7 @@ public static PolyValue docRemove( PolyValue input, List> names if ( doc.get( name ).isDocument() ) { doc = doc.get( name ).asDocument(); } else { - break check; + break; } } diff --git a/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java b/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java index ae607e31ab..cf7192ba27 100644 --- a/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java +++ b/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java @@ -99,7 +99,6 @@ import org.polypheny.db.algebra.rules.ProjectWindowTransposeRule; import org.polypheny.db.algebra.rules.ReduceExpressionsRules; import org.polypheny.db.algebra.rules.ScanRule; -import org.polypheny.db.algebra.rules.SimpleAllocationToPhysicalModifyRule; import org.polypheny.db.algebra.rules.SortJoinTransposeRule; import org.polypheny.db.algebra.rules.SortProjectTransposeRule; import org.polypheny.db.algebra.rules.SortRemoveConstantKeysRule; @@ -236,7 +235,6 @@ public class PolyphenyDbPrepareImpl implements PolyphenyDbPrepare { AllocationToPhysicalModifyRule.REL_INSTANCE, AllocationToPhysicalModifyRule.DOC_INSTANCE, AllocationToPhysicalModifyRule.GRAPH_INSTANCE, - SimpleAllocationToPhysicalModifyRule.DOC_INSTANCE, RuntimeConfig.JOIN_COMMUTE.getBoolean() ? JoinAssociateRule.INSTANCE : ProjectMergeRule.INSTANCE, diff --git a/core/src/main/java/org/polypheny/db/processing/ExtendedQueryParameters.java b/core/src/main/java/org/polypheny/db/processing/ExtendedQueryParameters.java index 19f80a3abc..5677c7e047 100644 --- a/core/src/main/java/org/polypheny/db/processing/ExtendedQueryParameters.java +++ b/core/src/main/java/org/polypheny/db/processing/ExtendedQueryParameters.java @@ -32,20 +32,20 @@ public class ExtendedQueryParameters extends QueryParameters { public List nodeLabels = new ArrayList<>(); public List relationshipLabels = new ArrayList<>(); @NonFinal - public Long namespaceId; + public String namespace; public boolean fullGraph; - public ExtendedQueryParameters( String query, NamespaceType namespaceType, Long namespaceId ) { + public ExtendedQueryParameters( String query, NamespaceType namespaceType, String namespace ) { super( query, namespaceType ); - this.namespaceId = namespaceId; + this.namespace = namespace; this.fullGraph = false; } - public ExtendedQueryParameters( Long namespaceId ) { + public ExtendedQueryParameters( String namespace ) { super( "*", NamespaceType.GRAPH ); - this.namespaceId = namespaceId; + this.namespace = namespace; this.fullGraph = true; } diff --git a/core/src/main/java/org/polypheny/db/rex/RexProgram.java b/core/src/main/java/org/polypheny/db/rex/RexProgram.java index 998366a406..1c210c01fd 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexProgram.java +++ b/core/src/main/java/org/polypheny/db/rex/RexProgram.java @@ -45,6 +45,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import lombok.Getter; import org.polypheny.db.algebra.AlgCollation; import org.polypheny.db.algebra.AlgCollations; import org.polypheny.db.algebra.AlgFieldCollation; @@ -89,8 +90,22 @@ public class RexProgram { */ private final RexLocalRef condition; + /** + * -- GETTER -- + * Returns the type of the input row to the program. + * + * @return input row type + */ + @Getter private final AlgDataType inputRowType; + /** + * -- GETTER -- + * Returns the type of the output row from this program. + * + * @return output row type + */ + @Getter private final AlgDataType outputRowType; /** @@ -317,7 +332,7 @@ public static RexProgram createIdentity( AlgDataType rowType ) { * Creates a program that projects its input fields but with possibly different names for the output fields. */ public static RexProgram createIdentity( AlgDataType rowType, AlgDataType outputRowType ) { - if ( rowType != outputRowType && !Pair.right( rowType.getFieldList() ).equals( Pair.right( outputRowType.getFieldList() ) ) ) { + if ( rowType != outputRowType && !rowType.getFieldNames().equals( outputRowType.getFieldNames() ) ) { throw new IllegalArgumentException( "field type mismatch: " + rowType + " vs. " + outputRowType ); } final List fields = rowType.getFieldList(); @@ -332,16 +347,6 @@ public static RexProgram createIdentity( AlgDataType rowType, AlgDataType output } - /** - * Returns the type of the input row to the program. - * - * @return input row type - */ - public AlgDataType getInputRowType() { - return inputRowType; - } - - /** * Returns whether this program contains windowed aggregate functions * @@ -352,16 +357,6 @@ public boolean containsAggs() { } - /** - * Returns the type of the output row from this program. - * - * @return output row type - */ - public AlgDataType getOutputRowType() { - return outputRowType; - } - - /** * Checks that this program is valid. * @@ -550,7 +545,7 @@ public boolean projectsIdentity( final boolean fail ) { for ( int i = 0; i < fieldCount; i++ ) { RexLocalRef project = projects.get( i ); if ( project.index != i ) { - assert !fail : "program " + toString() + "' does not project identity for input row type '" + inputRowType + "', field #" + i; + assert !fail : "program " + this + "' does not project identity for input row type '" + inputRowType + "', field #" + i; return false; } } @@ -688,7 +683,7 @@ public Permutation getPermutation() { public Set getCorrelVariableNames() { final Set paramIdSet = new HashSet<>(); RexUtil.apply( - new RexVisitorImpl( true ) { + new RexVisitorImpl<>( true ) { @Override public Void visitCorrelVariable( RexCorrelVariable correlVariable ) { paramIdSet.add( correlVariable.getName() ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexProgramBuilder.java b/core/src/main/java/org/polypheny/db/rex/RexProgramBuilder.java index 23c0e65b7a..5d0cb9f659 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexProgramBuilder.java +++ b/core/src/main/java/org/polypheny/db/rex/RexProgramBuilder.java @@ -695,7 +695,7 @@ public static RexProgram mergePrograms( RexProgram topProgram, RexProgram bottom } RexProgram mergedProg = progBuilder.getProgram( normalize ); assert mergedProg.isValid( Litmus.THROW, null ); - assert mergedProg.getOutputRowType() == topProgram.getOutputRowType(); + assert Objects.equals( mergedProg.getOutputRowType(), topProgram.getOutputRowType() ); return mergedProg; } @@ -705,7 +705,7 @@ private List registerProjectsAndCondition( RexProgram program ) { final List projectRefList = new ArrayList<>(); final RexShuttle shuttle = new RegisterOutputShuttle( exprList ); - // For each project, lookup the expr and expand it so it is in terms of bottomCalc's input fields + // For each project, lookup the expr and expand it, so it is in terms of bottomCalc's input fields for ( RexLocalRef topProject : program.getProjectList() ) { final RexNode topExpr = exprList.get( topProject.getIndex() ); final RexLocalRef expanded = (RexLocalRef) topExpr.accept( shuttle ); diff --git a/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java b/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java index 7419cb3854..7552d7f6a5 100644 --- a/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java +++ b/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java @@ -534,7 +534,7 @@ public RexIndexRef field( String fieldName ) { */ public RexIndexRef field( int inputCount, int inputOrdinal, String fieldName ) { final Frame frame = peek_( inputCount, inputOrdinal ); - final List fieldNames = Pair.left( frame.relFields() ); + final List fieldNames = frame.relFields().stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); int i = fieldNames.indexOf( fieldName ); if ( i >= 0 ) { return field( inputCount, inputOrdinal, i ); diff --git a/core/src/main/java/org/polypheny/db/tools/Programs.java b/core/src/main/java/org/polypheny/db/tools/Programs.java index b41ab2e484..936654d3f9 100644 --- a/core/src/main/java/org/polypheny/db/tools/Programs.java +++ b/core/src/main/java/org/polypheny/db/tools/Programs.java @@ -78,7 +78,6 @@ import org.polypheny.db.algebra.rules.ProjectToCalcRule; import org.polypheny.db.algebra.rules.ScanRule; import org.polypheny.db.algebra.rules.SemiJoinRules; -import org.polypheny.db.algebra.rules.SimpleAllocationToPhysicalModifyRule; import org.polypheny.db.algebra.rules.SortProjectTransposeRule; import org.polypheny.db.algebra.rules.SubQueryRemoveRule; import org.polypheny.db.config.PolyphenyDbConnectionConfig; @@ -175,7 +174,6 @@ public class Programs { AllocationToPhysicalModifyRule.REL_INSTANCE, AllocationToPhysicalModifyRule.DOC_INSTANCE, AllocationToPhysicalModifyRule.GRAPH_INSTANCE, - SimpleAllocationToPhysicalModifyRule.DOC_INSTANCE, RuntimeConfig.JOIN_COMMUTE.getBoolean() ? JoinAssociateRule.INSTANCE : ProjectMergeRule.INSTANCE, diff --git a/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java b/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java index d56e1e3049..e90e84e209 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java +++ b/core/src/main/java/org/polypheny/db/type/entity/category/PolyNumber.java @@ -17,6 +17,7 @@ package org.polypheny.db.type.entity.category; import java.math.BigDecimal; +import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.polypheny.db.type.PolyType; @@ -38,7 +39,7 @@ public static int compareTo( PolyNumber b0, PolyNumber b1 ) { if ( b0.isApprox() || b1.isApprox() ) { return b0.DoubleValue().compareTo( b1.DoubleValue() ); } - return b0.LongValue().compareTo( b1.LongValue() ); + return Objects.compare( b0.LongValue(), b1.LongValue(), Long::compareTo ); } diff --git a/core/src/main/java/org/polypheny/db/util/ReflectUtil.java b/core/src/main/java/org/polypheny/db/util/ReflectUtil.java index e4797ce38b..9753748fa5 100644 --- a/core/src/main/java/org/polypheny/db/util/ReflectUtil.java +++ b/core/src/main/java/org/polypheny/db/util/ReflectUtil.java @@ -44,6 +44,7 @@ import java.util.List; import java.util.Map; import org.apache.calcite.linq4j.function.Parameter; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; /** @@ -434,7 +435,7 @@ public T invoke( Object... args ) { final Object o = method.invoke( visitor, args ); return returnClazz.cast( o ); } catch ( IllegalAccessException | InvocationTargetException e ) { - throw new RuntimeException( "While invoking method '" + method + "'", e ); + throw new GenericRuntimeException( "While invoking method '" + method + "'", e ); } } diff --git a/core/src/main/java/org/polypheny/db/util/Triple.java b/core/src/main/java/org/polypheny/db/util/Triple.java index 11377d77d3..224894c4a2 100644 --- a/core/src/main/java/org/polypheny/db/util/Triple.java +++ b/core/src/main/java/org/polypheny/db/util/Triple.java @@ -18,9 +18,11 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import lombok.experimental.NonFinal; @Value(staticConstructor = "of") @EqualsAndHashCode +@NonFinal public class Triple implements Comparable> { public A left; @@ -28,6 +30,13 @@ public class Triple implements Comparable> { public C right; + public Triple( A left, B middle, C right ) { + this.left = left; + this.middle = middle; + this.right = right; + } + + @Override public int compareTo( Triple o ) { //noinspection unchecked diff --git a/core/src/test/java/org/polypheny/db/test/JdbcTest.java b/core/src/test/java/org/polypheny/db/test/JdbcTest.java index 62e82ee6ed..85c83622d2 100644 --- a/core/src/test/java/org/polypheny/db/test/JdbcTest.java +++ b/core/src/test/java/org/polypheny/db/test/JdbcTest.java @@ -23,7 +23,6 @@ import org.polypheny.db.algebra.logical.relational.LogicalRelModify; import org.polypheny.db.catalog.entity.CatalogEntity; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.prepare.Prepare; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.impl.AbstractEntity; import org.polypheny.db.schema.types.ModifiableTable; @@ -48,7 +47,6 @@ protected AbstractModifiableTable( String tableName ) { public RelModify toModificationAlg( AlgOptCluster cluster, CatalogEntity entity, - Prepare.CatalogReader catalogReader, AlgNode child, RelModify.Operation operation, List updateColumnList, 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 3de87f4c2d..3c9b92dee2 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -260,7 +260,6 @@ private void handleSource( DataSource adapter ) { aColumns.add( allocationColumn ); } - buildNamespace( Catalog.defaultNamespaceId, logical, adapter ); adapter.createTable( null, LogicalTableWrapper.of( logical, columns ), AllocationTableWrapper.of( allocation.unwrap( AllocationTable.class ), aColumns ) ); catalog.updateSnapshot(); @@ -1684,6 +1683,11 @@ public void renameColumn( LogicalTable table, String columnName, String newColum catalog.getLogicalRel( table.namespaceId ).renameColumn( logicalColumn.id, newColumnName ); + if ( table.entityType != EntityType.VIEW ) { + List placements = catalog.getSnapshot().alloc().getPlacementsOfColumn( logicalColumn.id ); + placements.forEach( p -> AdapterManager.getInstance().getAdapter( p.adapterId ).renameLogicalColumn( logicalColumn.id, newColumnName ) ); + } + // Reset plan cache implementation cache & routing cache statement.getQueryProcessor().resetCaches(); } @@ -1985,9 +1989,9 @@ private List getColumnInformation( List projectedColum int position = 1; for ( AlgDataTypeField alg : fieldList.getFieldList() ) { - AlgDataType type = alg.getValue(); + AlgDataType type = alg.getType(); if ( alg.getType().getPolyType() == PolyType.ARRAY ) { - type = alg.getValue().getComponentType(); + type = alg.getType().getComponentType(); } String colName = alg.getName(); if ( projectedColumns != null ) { @@ -2001,9 +2005,9 @@ private List getColumnInformation( List projectedColum alg.getType().getPolyType(), type.getRawPrecision(), type.getScale(), - alg.getValue().getPolyType() == PolyType.ARRAY ? (int) ((ArrayType) alg.getValue()).getDimension() : -1, - alg.getValue().getPolyType() == PolyType.ARRAY ? (int) ((ArrayType) alg.getValue()).getCardinality() : -1, - alg.getValue().isNullable() ), + alg.getType().getPolyType() == PolyType.ARRAY ? (int) ((ArrayType) alg.getType()).getDimension() : -1, + alg.getType().getPolyType() == PolyType.ARRAY ? (int) ((ArrayType) alg.getType()).getCardinality() : -1, + alg.getType().isNullable() ), Collation.getDefaultCollation(), null, position ) ); diff --git a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java index 08e97cc5ce..919230b40f 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -698,9 +698,9 @@ public AlgNode visit( AlgNode node ) { final Pair np = originalProject.getNamedProjects().get( i ); nameMap.put( np.right, i ); if ( ltm.isUpdate() || ltm.isMerge() ) { - int j = ltm.getUpdateColumnList().indexOf( np.right ); + int j = ltm.getUpdateColumns().indexOf( np.right ); if ( j >= 0 ) { - RexNode newValue = ltm.getSourceExpressionList().get( j ); + RexNode newValue = ltm.getSourceExpressions().get( j ); for ( int k = 0; k < originalProject.getNamedProjects().size(); ++k ) { if ( originalProject.getNamedProjects().get( k ).left.equals( newValue ) ) { newValueMap.put( np.right, k ); @@ -781,7 +781,7 @@ public AlgNode visit( AlgNode node ) { for ( final Index index : indices ) { if ( ltm.isUpdate() ) { // Index not affected by this update, skip - if ( index.getColumns().stream().noneMatch( ltm.getUpdateColumnList()::contains ) ) { + if ( index.getColumns().stream().noneMatch( ltm.getUpdateColumns()::contains ) ) { continue; } } @@ -804,7 +804,7 @@ public AlgNode visit( AlgNode node ) { if ( !ltm.isDelete() ) { for ( final Index index : indices ) { // Index not affected by this update, skip - if ( ltm.isUpdate() && index.getColumns().stream().noneMatch( ltm.getUpdateColumnList()::contains ) ) { + if ( ltm.isUpdate() && index.getColumns().stream().noneMatch( ltm.getUpdateColumns()::contains ) ) { continue; } if ( ltm.isInsert() && index.getColumns().stream().noneMatch( ltm.getInput().getRowType().getFieldNames()::contains ) ) { diff --git a/dbms/src/main/java/org/polypheny/db/processing/ConstraintEnforceAttacher.java b/dbms/src/main/java/org/polypheny/db/processing/ConstraintEnforceAttacher.java index 728a435d84..cf7fac446e 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/ConstraintEnforceAttacher.java +++ b/dbms/src/main/java/org/polypheny/db/processing/ConstraintEnforceAttacher.java @@ -362,7 +362,7 @@ public static AlgRoot enforceConstraintBeforeQuery( AlgRoot logicalRoot, Stateme } // Check if update affects this constraint boolean affected = false; - for ( final String c : root.getUpdateColumnList() ) { + for ( final String c : root.getUpdateColumns() ) { if ( constraint.key.getColumnNames().contains( c ) ) { affected = true; break; @@ -373,8 +373,8 @@ public static AlgRoot enforceConstraintBeforeQuery( AlgRoot logicalRoot, Stateme } AlgNode input = root.getInput().accept( new DeepCopyShuttle() ); Map nameMap = new HashMap<>(); - for ( int i = 0; i < root.getUpdateColumnList().size(); ++i ) { - nameMap.put( root.getUpdateColumnList().get( i ), i ); + for ( int i = 0; i < root.getUpdateColumns().size(); ++i ) { + nameMap.put( root.getUpdateColumns().get( i ), i ); } // Enforce uniqueness between updated records and already present records builder.clear(); @@ -386,8 +386,8 @@ public static AlgRoot enforceConstraintBeforeQuery( AlgRoot logicalRoot, Stateme names.add( column ); } for ( final String column : constraint.key.getColumnNames() ) { - if ( root.getUpdateColumnList().contains( column ) ) { - projects.add( root.getSourceExpressionList().get( nameMap.get( column ) ) ); + if ( root.getUpdateColumns().contains( column ) ) { + projects.add( root.getSourceExpressions().get( nameMap.get( column ) ) ); } else { // TODO(s3lph): For now, let's assume that all columns are actually present. // Otherwise this would require either some black magic project rewrites or joining against another table scan @@ -441,8 +441,8 @@ public static AlgRoot enforceConstraintBeforeQuery( AlgRoot logicalRoot, Stateme builder.push( input ); projects = new ArrayList<>(); for ( final String column : constraint.key.getColumnNames() ) { - if ( root.getUpdateColumnList().contains( column ) ) { - projects.add( root.getSourceExpressionList().get( nameMap.get( column ) ) ); + if ( root.getUpdateColumns().contains( column ) ) { + projects.add( root.getSourceExpressions().get( nameMap.get( column ) ) ); } else { // TODO(s3lph): For now, let's assume that all columns are actually present. // Otherwise this would require either some black magic project rewrites or joining against another table scan @@ -483,8 +483,8 @@ public static AlgRoot enforceConstraintBeforeQuery( AlgRoot logicalRoot, Stateme RexNode newValue; int targetIndex; if ( root.isUpdate() ) { - targetIndex = root.getUpdateColumnList().indexOf( columnName ); - newValue = root.getSourceExpressionList().get( targetIndex ); + targetIndex = root.getUpdateColumns().indexOf( columnName ); + newValue = root.getSourceExpressions().get( targetIndex ); newValue = new RexShuttle() { @Override public RexNode visitFieldAccess( RexFieldAccess fieldAccess ) { diff --git a/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java index d08c888287..fc2aadc0ed 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java @@ -49,7 +49,6 @@ import org.polypheny.db.algebra.rules.ProjectWindowTransposeRule; import org.polypheny.db.algebra.rules.ReduceExpressionsRules; import org.polypheny.db.algebra.rules.ScanRule; -import org.polypheny.db.algebra.rules.SimpleAllocationToPhysicalModifyRule; import org.polypheny.db.algebra.rules.SortJoinTransposeRule; import org.polypheny.db.algebra.rules.SortProjectTransposeRule; import org.polypheny.db.algebra.rules.SortRemoveConstantKeysRule; @@ -128,7 +127,6 @@ public class VolcanoQueryProcessor extends AbstractQueryProcessor { AllocationToPhysicalModifyRule.REL_INSTANCE, AllocationToPhysicalModifyRule.DOC_INSTANCE, AllocationToPhysicalModifyRule.GRAPH_INSTANCE, - SimpleAllocationToPhysicalModifyRule.DOC_INSTANCE, RuntimeConfig.JOIN_COMMUTE.getBoolean() ? JoinAssociateRule.INSTANCE : ProjectMergeRule.INSTANCE, diff --git a/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java b/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java index 06cc30ee0a..4d458fd425 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java +++ b/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java @@ -251,9 +251,9 @@ public AlgNode visit( LogicalRelModify initial ) { LogicalRelModify modify = (LogicalRelModify) super.visit( initial ); List newSourceExpression = null; - if ( modify.getSourceExpressionList() != null ) { + if ( modify.getSourceExpressions() != null ) { newSourceExpression = new ArrayList<>(); - for ( RexNode node : modify.getSourceExpressionList() ) { + for ( RexNode node : modify.getSourceExpressions() ) { newSourceExpression.add( node.accept( this ) ); } } @@ -273,7 +273,7 @@ public AlgNode visit( LogicalRelModify initial ) { } else { idx = idxMapping.get( i ); } - AlgDataType type = input.getRowType().getFieldList().get( i ).getValue(); + AlgDataType type = input.getRowType().getFieldList().get( i ).getType(); if ( firstRow ) { projects.add( new RexDynamicParam( type, idx ) ); } @@ -301,7 +301,7 @@ public AlgNode visit( LogicalRelModify initial ) { modify.getEntity(), input, modify.getOperation(), - modify.getUpdateColumnList(), + modify.getUpdateColumns(), newSourceExpression, modify.isFlattened() ); @@ -311,9 +311,9 @@ public AlgNode visit( LogicalRelModify initial ) { public AlgNode visitAsymmetricModify( LogicalRelModify initial ) { LogicalRelModify modify = (LogicalRelModify) super.visit( initial ); List newSourceExpression = null; - if ( modify.getSourceExpressionList() != null ) { + if ( modify.getSourceExpressions() != null ) { newSourceExpression = new ArrayList<>(); - for ( RexNode node : modify.getSourceExpressionList() ) { + for ( RexNode node : modify.getSourceExpressions() ) { newSourceExpression.add( node.accept( this ) ); } } @@ -337,7 +337,7 @@ public AlgNode visitAsymmetricModify( LogicalRelModify initial ) { } else { idx = idxMapping.get( i ); } - AlgDataType type = input.getRowType().getFieldList().get( i ).getValue(); + AlgDataType type = input.getRowType().getFieldList().get( i ).getType(); if ( firstRow ) { projects.add( new RexDynamicParam( type, idx ) ); } @@ -368,7 +368,7 @@ public AlgNode visitAsymmetricModify( LogicalRelModify initial ) { modify.getEntity(), input, modify.getOperation(), - modify.getUpdateColumnList(), + modify.getUpdateColumns(), newSourceExpression, modify.isFlattened() ); } @@ -406,7 +406,7 @@ public AlgNode visit( LogicalDocumentModify initial ) { idx = idxMapping.get( i ); } - AlgDataType type = input.getRowType().getFieldList().get( i ).getValue(); + AlgDataType type = input.getRowType().getFieldList().get( i ).getType(); if ( firstRow ) { projects.put( null, null );//new RexDynamicParam( type, idx ) ); } 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 e62b421950..1e0174b1e4 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 @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -99,12 +98,12 @@ public AlgNode routeDml( LogicalRelModify modify, Statement statement ) { AlgOptCluster cluster = modify.getCluster(); if ( modify.entity == null ) { - throw new RuntimeException( "Unexpected operator!" ); + throw new GenericRuntimeException( "Unexpected operator!" ); } LogicalTable table = modify.entity.unwrap( LogicalTable.class ); if ( table == null ) { - throw new RuntimeException( "Unexpected table. Only logical tables expected here!" ); + throw new GenericRuntimeException( "Unexpected table. Only logical tables expected here!" ); } List columns = catalog.getSnapshot().rel().getColumns( table.id ); @@ -159,13 +158,13 @@ public AlgNode routeDml( LogicalRelModify modify, Statement statement ) { List placementsOnAdapter = catalog.getSnapshot().alloc().getColumns( pkPlacement.id ); // If this is an update, check whether we need to execute on this storeId at all - List updateColumnList = modify.getUpdateColumnList(); - List sourceExpressionList = modify.getSourceExpressionList(); + List updateColumnList = modify.getUpdateColumns(); + List sourceExpressionList = modify.getSourceExpressions(); if ( placementsOnAdapter.size() != table.getColumnIds().size() ) { if ( modify.getOperation() == Operation.UPDATE ) { - updateColumnList = new LinkedList<>( modify.getUpdateColumnList() ); - sourceExpressionList = new LinkedList<>( modify.getSourceExpressionList() ); + updateColumnList = new ArrayList<>( modify.getUpdateColumns() ); + sourceExpressionList = new ArrayList<>( modify.getSourceExpressions() ); Iterator updateColumnListIterator = updateColumnList.iterator(); Iterator sourceExpressionListIterator = sourceExpressionList.iterator(); while ( updateColumnListIterator.hasNext() ) { @@ -181,7 +180,7 @@ public AlgNode routeDml( LogicalRelModify modify, Statement statement ) { sourceExpressionListIterator.remove(); } } - if ( updateColumnList.size() == 0 ) { + if ( updateColumnList.isEmpty() ) { continue; } } @@ -261,7 +260,7 @@ public AlgNode visit( LogicalFilter filter ) { } // If WHERE clause has any value for partition column - if ( identifiedPartitionsInFilter.size() > 0 ) { + if ( !identifiedPartitionsInFilter.isEmpty() ) { // Partition has been identified in SET if ( identifiedPartitionForSetValue != -1 ) { @@ -307,7 +306,7 @@ else if ( identifiedPartitionForSetValue != -1 ) { int partitionColumnIndex = -1; Map resultColMapping = new HashMap<>(); for ( int j = 0; j < (modify.getInput()).getRowType().getFieldList().size(); j++ ) { - String columnFieldName = (modify.getInput()).getRowType().getFieldList().get( j ).getKey(); + String columnFieldName = (modify.getInput()).getRowType().getFieldList().get( j ).getName(); // Retrieve columnId of fieldName and map it to its fieldList location of INSERT Stmt int columnIndex = columns.stream().map( c -> c.name ).collect( Collectors.toList() ).indexOf( columnFieldName ); @@ -467,13 +466,12 @@ else if ( identifiedPartitionForSetValue != -1 ) { } operationWasRewritten = true; - worstCaseRouting = false; } else { partitionValue = ((LogicalProject) modify.getInput()).getProjects().get( i ).toString().replace( "'", "" ); identPart = (int) partitionManager.getTargetPartitionId( table, property, partitionValue ); accessedPartitionList.add( identPart ); - worstCaseRouting = false; } + worstCaseRouting = false; break; } else { // When loop is finished @@ -581,7 +579,7 @@ else if ( identifiedPartitionForSetValue != -1 ) { @NotNull private LogicalRelModify handleSingleModify( LogicalRelModify modify, Statement statement, AllocationEntity allocation ) { AlgNode input = buildDmlNew( super.recursiveCopy( modify.getInput( 0 ) ), statement, RoutedAlgBuilder.create( statement, modify.getCluster() ) ).build(); - return LogicalRelModify.create( allocation, input, modify.getOperation(), modify.getUpdateColumnList(), modify.getSourceExpressionList(), modify.isFlattened() ); + return LogicalRelModify.create( allocation, input, modify.getOperation(), modify.getUpdateColumns(), modify.getSourceExpressions(), modify.isFlattened() ); } diff --git a/dbms/src/test/java/org/polypheny/db/TestHelper.java b/dbms/src/test/java/org/polypheny/db/TestHelper.java index a13fd90753..1d4b423375 100644 --- a/dbms/src/test/java/org/polypheny/db/TestHelper.java +++ b/dbms/src/test/java/org/polypheny/db/TestHelper.java @@ -22,7 +22,6 @@ import static org.junit.Assert.fail; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import java.lang.reflect.Field; @@ -68,6 +67,7 @@ import org.polypheny.db.type.entity.PolyString; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Pair; +import org.polypheny.db.webui.HttpServer; import org.polypheny.db.webui.models.results.DocResult; import org.polypheny.db.webui.models.results.GraphResult; @@ -338,7 +338,7 @@ public static abstract class HttpConnection { public static HttpRequest buildQuery( String route, String query, String database ) { JsonObject data = new JsonObject(); data.addProperty( "query", query ); - data.addProperty( "database", database ); + data.addProperty( "namespace", database ); return Unirest.post( "{protocol}://{host}:{port}" + route ) .header( "Content-ExpressionType", "application/json" ) @@ -363,7 +363,6 @@ public static class MongoConnection extends HttpConnection { public static final String MONGO_PREFIX = "/mongo"; public static final String MONGO_DB = "test"; - static ObjectMapper mapper = new ObjectMapper(); private MongoConnection() { @@ -382,7 +381,7 @@ public static DocResult executeGetResponse( String mongoQl, String database ) { private static DocResult getBody( HttpResponse res ) { try { - DocResult[] result = mapper.readValue( res.getBody(), DocResult[].class ); + DocResult[] result = HttpServer.mapper.readValue( res.getBody(), DocResult[].class ); if ( result.length == 1 ) { if ( result[0].error != null ) { throw new RuntimeException( result[0].error ); @@ -489,8 +488,6 @@ public static List arrayToDoc( List values, String... names ) public static class CypherConnection extends HttpConnection { - static ObjectMapper mapper = new ObjectMapper(); - public static GraphResult executeGetResponse( String query ) { return getBody( execute( "/cypher", query, "test" ) ); @@ -504,9 +501,9 @@ public static GraphResult executeGetResponse( String query, String database ) { private static GraphResult getBody( HttpResponse res ) { try { - GraphResult[] result = mapper.readValue( res.getBody(), GraphResult[].class ); + GraphResult[] result = HttpServer.mapper.readValue( res.getBody(), GraphResult[].class ); if ( result.length == 1 ) { - return mapper.readValue( res.getBody(), GraphResult[].class )[0]; + return HttpServer.mapper.readValue( res.getBody(), GraphResult[].class )[0]; } else if ( result.length == 0 ) { return GraphResult.builder().build(); } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailTableModify.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailTableModify.java index 1447fba137..06d573f6d1 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailTableModify.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailTableModify.java @@ -88,8 +88,8 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { entity, AbstractAlgNode.sole( inputs ), getOperation(), - getUpdateColumnList(), - getSourceExpressionList(), + getUpdateColumns(), + getSourceExpressions(), isFlattened() ); } @@ -160,9 +160,9 @@ private Expression buildUpdateTupleBuilder( CottontailImplementContext context ) // List> namedProjects = getNamedProjects(); - for ( int i = 0; i < getSourceExpressionList().size(); i++ ) { - RexNode rexNode = getSourceExpressionList().get( i ); - final String logicalName = getUpdateColumnList().get( i ); + for ( int i = 0; i < getSourceExpressions().size(); i++ ) { + RexNode rexNode = getSourceExpressions().get( i ); + final String logicalName = getUpdateColumns().get( i ); final int actualColumnIndex = logicalColumnNames.indexOf( logicalName ); final String originalName = physicalColumnNames.get( actualColumnIndex ); diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/rules/CottontailTableModificationRule.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/rules/CottontailTableModificationRule.java index a4d34c0062..46a702b627 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/rules/CottontailTableModificationRule.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/rules/CottontailTableModificationRule.java @@ -78,8 +78,8 @@ public AlgNode convert( AlgNode alg ) { modify.getEntity().unwrap( CottontailEntity.class ), AlgOptRule.convert( modify.getInput(), traitSet ), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), + modify.getUpdateColumns(), + modify.getSourceExpressions(), modify.isFlattened() ); } diff --git a/plugins/cql-language/src/main/java/org/polypheny/db/cql/Cql2RelConverter.java b/plugins/cql-language/src/main/java/org/polypheny/db/cql/Cql2RelConverter.java index caa5722358..dd0854e7f8 100644 --- a/plugins/cql-language/src/main/java/org/polypheny/db/cql/Cql2RelConverter.java +++ b/plugins/cql-language/src/main/java/org/polypheny/db/cql/Cql2RelConverter.java @@ -236,7 +236,7 @@ private AlgBuilder generateFilters( AlgBuilder algBuilder, RexBuilder rexBuilder AlgDataType filtersRowType = baseNode.getRowType(); List filtersRows = filtersRowType.getFieldList(); Map filterMap = new HashMap<>(); - filtersRows.forEach( ( r ) -> filterMap.put( r.getKey(), r ) ); + filtersRows.forEach( ( r ) -> filterMap.put( r.getName(), r ) ); filters.traverse( TraversalType.POSTORDER, ( treeNode, nodeType, direction, frame ) -> { if ( nodeType == NodeType.DESTINATION_NODE ) { diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherLanguagePlugin.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherLanguagePlugin.java index 5a0c5b32f8..9d05085c42 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherLanguagePlugin.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherLanguagePlugin.java @@ -105,7 +105,7 @@ public void stop() { executionTime = System.nanoTime(); Statement statement = transaction.createStatement(); - ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, request.namespaceId ); + ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, request.namespace ); if ( transaction.isAnalyze() ) { statement.getOverviewDuration().start( "Parsing" ); @@ -127,7 +127,7 @@ public void stop() { .builder() .affectedTuples( 1 ) .query( splits.get( i ) ) - .namespaceId( request.namespaceId ) + .namespace( request.namespace ) .xid( transaction.getXid().toString() ) .build(); results.add( result ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java index 08fa9b46da..0c8462c243 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/cypher2alg/CypherToAlgConverter.java @@ -107,8 +107,7 @@ public CypherToAlgConverter( Statement statement, AlgBuilder builder, RexBuilder public AlgRoot convert( CypherNode query, ExtendedQueryParameters parameters, AlgOptCluster cluster ) { - long namespaceId; - namespaceId = Objects.requireNonNullElseGet( parameters.namespaceId, () -> getNamespaceId( parameters ) ); + long namespaceId = getNamespaceId( parameters ); LogicalEntity entity = getEntity( namespaceId, parameters ); @@ -155,7 +154,7 @@ private AlgNode buildFullScan( LogicalGraph graph ) { private long getNamespaceId( ExtendedQueryParameters parameters ) { - return snapshot.getNamespace( parameters.getNamespaceId() ).orElseThrow().id; + return snapshot.getNamespace( parameters.namespace ).orElseThrow().id; } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java index 927d80e157..13b75e6061 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java @@ -69,11 +69,13 @@ public FileImplementor() { //intentionally empty } + public void setColumnNames( final List columnNames ) { this.columnNames.clear(); this.columnNames.addAll( columnNames ); } + /** * A FileProject can directly provide the projectionMapping, a FileModify will provide the columnNames only */ diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileProject.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileProject.java index 2ae99418f8..748ec038fe 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileProject.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileProject.java @@ -121,11 +121,11 @@ public void implement( FileImplementor implementor ) { implementor.project( null, mapping ); } else { for ( AlgDataTypeField field : rowType.getFieldList() ) { - if ( field.getKey().startsWith( "EXPR$" ) ) { + if ( field.getName().startsWith( "EXPR$" ) ) { //don't set EXPR-columns in FileImplementor return; } - fields.add( field.getKey() ); + fields.add( field.getName() ); } implementor.project( fields, null ); } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileRules.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileRules.java index 534a6c139d..d7f89e6f88 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileRules.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileRules.java @@ -80,8 +80,8 @@ public FileTableModificationRule( FileConvention out, AlgBuilderFactory algBuild private static boolean supports( RelModify node ) { - if ( node.getSourceExpressionList() != null ) { - return !UnsupportedRexCallVisitor.containsModelItem( node.getSourceExpressionList() ); + if ( node.getSourceExpressions() != null ) { + return !UnsupportedRexCallVisitor.containsModelItem( node.getSourceExpressions() ); } return true; } @@ -126,8 +126,8 @@ public AlgNode convert( AlgNode alg ) { modify.getEntity().unwrap( FileTranslatableEntity.class ), AlgOptRule.convert( modify.getInput(), traitSet ), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), + modify.getUpdateColumns(), + modify.getSourceExpressions(), modify.isFlattened() ); } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java index 8304dba2e4..9d5d16dc5c 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java @@ -60,8 +60,8 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { entity, AbstractAlgNode.sole( inputs ), getOperation(), - getUpdateColumnList(), - getSourceExpressionList(), + getUpdateColumns(), + getSourceExpressions(), isFlattened() ); } @@ -79,18 +79,18 @@ public void implement( final FileImplementor implementor ) { implementor.setFileTable( entity ); if ( getOperation() == Operation.UPDATE ) { - if ( getSourceExpressionList() != null ) { + if ( getSourceExpressions() != null ) { if ( implementor.getUpdates() == null ) { implementor.setUpdates( new ArrayList<>() ); } implementor.getUpdates().clear(); List values = new ArrayList<>(); int i = 0; - for ( RexNode src : getSourceExpressionList() ) { + for ( RexNode src : getSourceExpressions() ) { if ( src instanceof RexLiteral ) { - values.add( new Value( implementor.getFileTable().getColumnNamesIds().get( getUpdateColumnList().get( i ) ).intValue(), ((RexLiteral) src).value, false ) ); + values.add( new Value( implementor.getFileTable().getColumnNamesIds().get( getUpdateColumns().get( i ) ).intValue(), ((RexLiteral) src).value, false ) ); } else if ( src instanceof RexDynamicParam ) { - values.add( new Value( implementor.getFileTable().getColumnNamesIds().get( getUpdateColumnList().get( i ) ).intValue(), PolyLong.of( ((RexDynamicParam) src).getIndex() ), true ) ); + values.add( new Value( implementor.getFileTable().getColumnNamesIds().get( getUpdateColumns().get( i ) ).intValue(), PolyLong.of( ((RexDynamicParam) src).getIndex() ), true ) ); } else if ( src instanceof RexCall && src.getType().getPolyType() == PolyType.ARRAY ) { values.add( Value.fromArrayRexCall( (RexCall) src ) ); } else { @@ -101,7 +101,7 @@ public void implement( final FileImplementor implementor ) { implementor.setUpdates( values ); } //set the columns that should be updated in the projection list - implementor.project( this.getUpdateColumnList(), null ); + implementor.project( this.getUpdateColumns(), null ); } } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileValues.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileValues.java index c21c1457f8..b622b7bd72 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileValues.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileValues.java @@ -56,7 +56,7 @@ public void implement( final FileImplementor implementor ) { } List columns = new ArrayList<>(); for ( AlgDataTypeField type : recordType.getFieldList() ) { - columns.add( type.getKey() ); + columns.add( type.getName() ); } implementor.setColumnNames( columns ); diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcRules.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcRules.java index 9608319e24..69c750047f 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcRules.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcRules.java @@ -1027,8 +1027,8 @@ public AlgNode convert( AlgNode alg ) { modify.getEntity().unwrap( JdbcTable.class ), AlgOptRule.convert( modify.getInput(), traitSet ), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), + modify.getUpdateColumns(), + modify.getSourceExpressions(), modify.isFlattened() ); } @@ -1040,8 +1040,6 @@ public AlgNode convert( AlgNode alg ) { */ public static class JdbcTableModify extends RelModify implements JdbcAlg { - private final Expression expression; - public JdbcTableModify( AlgOptCluster cluster, @@ -1059,7 +1057,7 @@ public JdbcTableModify( if ( modifiableTable == null ) { throw new AssertionError(); // TODO: user error in validator } - this.expression = table.asExpression( Queryable.class ); + Expression expression = table.asExpression( Queryable.class ); if ( expression == null ) { throw new AssertionError(); // TODO: user error in validator } @@ -1081,8 +1079,8 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { entity, AbstractAlgNode.sole( inputs ), getOperation(), - getUpdateColumnList(), - getSourceExpressionList(), + getUpdateColumns(), + getSourceExpressions(), isFlattened() ); } diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcTable.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcTable.java index 938be3667c..bcd447834d 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcTable.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcTable.java @@ -92,7 +92,6 @@ */ public class JdbcTable extends PhysicalTable implements TranslatableEntity, ScannableEntity, ModifiableTable, QueryableEntity { - private final PhysicalTable table; private JdbcSchema jdbcSchema; private final TableType jdbcTableType; @@ -111,7 +110,6 @@ public JdbcTable( physical.namespaceId, physical.namespaceName, physical.adapterId ); - this.table = physical; this.jdbcSchema = jdbcSchema; this.jdbcTableType = jdbcTableType; } diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java index d61189bd61..b4990b0029 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java @@ -475,8 +475,8 @@ public Result visit( RelModify modify ) { final SqlUpdate sqlUpdate = new SqlUpdate( POS, sqlTargetTable, - physicalIdentifierList( modify.getEntity().unwrap( JdbcTable.class ), modify.getUpdateColumnList() ), - exprList( context, modify.getSourceExpressionList() ), + physicalIdentifierList( modify.getEntity().unwrap( JdbcTable.class ), modify.getUpdateColumns() ), + exprList( context, modify.getSourceExpressions() ), ((SqlSelect) input.node).getWhere(), input.asSelect(), null ); @@ -519,13 +519,14 @@ private SqlNodeList identifierList( List names ) { * Converts a list of names expressions to a list of single-part {@link SqlIdentifier}s. */ private SqlNodeList physicalIdentifierList( JdbcTable entity, List columnNames ) { - return new SqlNodeList( entity.columns.stream().map( c -> new SqlIdentifier( c.name, ParserPos.ZERO ) ).collect( Collectors.toList() ), POS ); + return new SqlNodeList( entity.columns.stream().filter( c -> columnNames.contains( c.logicalName ) ).map( c -> new SqlIdentifier( c.name, ParserPos.ZERO ) ).collect( Collectors.toList() ), POS ); } /** * @see #dispatch */ + @SuppressWarnings("unused") public Result visit( Match e ) { final AlgNode input = e.getInput(); final Result x = visitChild( 0, input ); diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java index 55f8221e72..f64538fbb8 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java @@ -20,6 +20,7 @@ import java.sql.SQLException; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import lombok.SneakyThrows; import lombok.experimental.Delegate; @@ -216,6 +217,8 @@ public void addColumn( Context context, long allocId, LogicalColumn logicalColum executeUpdate( query, context ); } + updateNativePhysical( allocId ); + } @@ -267,7 +270,7 @@ protected StringBuilder buildInsertDefaultValueQuery( PhysicalTable table, Physi } SqlLiteral literal; - switch ( column.defaultValue.type ) { + switch ( Objects.requireNonNull( column.defaultValue ).type ) { case BOOLEAN: literal = SqlLiteral.createBoolean( Boolean.parseBoolean( column.defaultValue.value ), ParserPos.ZERO ); break; @@ -318,6 +321,8 @@ public void updateColumnType( Context context, long allocId, LogicalColumn newCo } executeUpdate( builder, context ); + updateNativePhysical( allocId ); + } @@ -356,6 +361,12 @@ public void dropTable( Context context, long allocId ) { } + @Override + public void renameLogicalColumn( long id, String newColumnName ) { + storeCatalog.renameLogicalField( id, newColumnName ); + } + + @Override public void dropColumn( Context context, long allocId, long columnId ) { //for ( CatalogPartitionPlacement partitionPlacement : context.getSnapshot().alloc().getEntity( columnPlacement.tableId ) ) { @@ -369,10 +380,18 @@ public void dropColumn( Context context, long allocId, long columnId ) { builder.append( " DROP " ).append( dialect.quoteIdentifier( column.name ) ); executeUpdate( builder, context ); storeCatalog.dropColumn( allocId, columnId ); + + updateNativePhysical( allocId ); //} } + private void updateNativePhysical( long allocId ) { + PhysicalTable table = storeCatalog.fromAllocation( allocId ); + storeCatalog.replacePhysical( this.currentJdbcSchema.createJdbcTable( storeCatalog, table ) ); + } + + @Override public void truncate( Context context, long allocId ) { // We get the physical schema / table name by checking existing column placements of the same logical table placed on this store. @@ -493,6 +512,8 @@ public interface Exclude { void restoreTable( AllocationTable alloc, List entities ); + void renameLogicalColumn( long id, String newName ); + } } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java index 102f87d256..297f2d072e 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java @@ -80,7 +80,6 @@ import org.polypheny.db.algebra.core.common.Modify.Operation; import org.polypheny.db.algebra.logical.document.LogicalDocumentModify; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; -import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.CatalogEntity; import org.polypheny.db.catalog.entity.physical.PhysicalCollection; @@ -123,7 +122,6 @@ public class MongoEntity extends PhysicalEntity implements TranslatableEntity, M @Getter public MongoCollection collection; - public AlgDataType rowType; public List fields; @@ -137,7 +135,6 @@ public class MongoEntity extends PhysicalEntity implements TranslatableEntity, M this.transactionProvider = transactionProvider; this.storeId = physical.adapterId; this.collection = namespace.database.getCollection( physical.name ); - this.rowType = physical.getRowType(); this.fields = fields; } @@ -330,11 +327,6 @@ public Modify toModificationCollection( } - @Override - public AlgDataType getRowType() { - return this.rowType; - } - @Override public Serializable[] getParameterArray() { diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java index 446af82581..f17c74ee30 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java @@ -885,8 +885,8 @@ public AlgNode convert( AlgNode alg ) { mongo, AlgOptRule.convert( modify.getInput(), traitSet ), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), + modify.getUpdateColumns(), + modify.getSourceExpressions(), modify.isFlattened() ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java index 91653959d2..5dd3f311f1 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java @@ -96,8 +96,8 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { getEntity(), AbstractAlgNode.sole( inputs ), getOperation(), - getUpdateColumnList(), - getSourceExpressionList(), + getUpdateColumns(), + getSourceExpressions(), isFlattened() ); } @@ -156,31 +156,31 @@ private void handleUpdate( Implementor implementor ) { BsonDocument doc = new BsonDocument(); List docDocs = new ArrayList<>(); GridFSBucket bucket = implementor.getBucket(); - for ( RexNode el : getSourceExpressionList() ) { + for ( RexNode el : getSourceExpressions() ) { if ( el.isA( Kind.LITERAL ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumnList().get( pos ), implementor ), + rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), BsonUtil.getAsBson( (RexLiteral) el, bucket ) ); } else if ( el instanceof RexCall ) { RexCall call = ((RexCall) el); if ( Arrays.asList( Kind.PLUS, Kind.PLUS, Kind.TIMES, Kind.DIVIDE ).contains( call.op.getKind() ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumnList().get( pos ), implementor ), + rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), visitCall( implementor, (RexCall) el, call.op.getKind(), el.getType().getPolyType() ) ); } else if ( call.op.getKind().belongsTo( Kind.MQL_KIND ) ) { docDocs.add( handleDocumentUpdate( (RexCall) el, bucket, rowType ) ); } else { doc.append( - rowType.getPhysicalName( getUpdateColumnList().get( pos ), implementor ), + rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), BsonUtil.getBsonArray( call, bucket ) ); } } else if ( el.isA( Kind.DYNAMIC_PARAM ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumnList().get( pos ), implementor ), + rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), new BsonDynamic( (RexDynamicParam) el ) ); } else if ( el.isA( Kind.FIELD_ACCESS ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumnList().get( pos ), implementor ), + rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), new BsonString( "$" + rowType.getPhysicalName( ((RexFieldAccess) el).getField().getName(), implementor ) ) ); @@ -442,26 +442,6 @@ private Map getPhysicalMap( List fieldList, P } - private Map getPhysicalMap( List fieldList, LogicalTable table ) { - Map map = new HashMap<>(); - List names = table.getColumnNames(); - List ids = table.getColumnIds(); - int pos = 0; - for ( String name : Pair.left( fieldList ) ) { - map.put( pos, MongoStore.getPhysicalColumnName( ids.get( names.indexOf( name ) ) ) ); - pos++; - } - return map; - } - - - private String getPhysicalName( MongoProject input, LogicalTable table, int pos ) { - String logicalName = input.getRowType().getFieldNames().get( pos ); - int index = table.getColumnNames().indexOf( logicalName ); - return MongoStore.getPhysicalColumnName( table.getColumnIds().get( index ) ); - } - - private BsonValue getBsonArray( RexCall el, PolyType type, GridFSBucket bucket ) { if ( el.op.getKind() == Kind.ARRAY_VALUE_CONSTRUCTOR ) { BsonArray array = new BsonArray(); diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java index f6215e5407..be9a93114b 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java @@ -19,6 +19,7 @@ import com.google.common.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.eclipse.jetty.websocket.api.Session; @@ -27,6 +28,7 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.information.InformationManager; import org.polypheny.db.languages.mql.Mql.Family; @@ -97,11 +99,11 @@ public static void startup() { QueryRequest request, TransactionManager transactionManager, long userId, - long databaseId, + long defaultNamespace, Crud crud ) { QueryLanguage language = QueryLanguage.from( "mongo" ); - Transaction transaction = Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, databaseId, "HTTP Interface MQL" ); + Transaction transaction = Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, defaultNamespace, "HTTP Interface MQL" ); AutomaticDdlProcessor mqlProcessor = (AutomaticDdlProcessor) transaction.getProcessor( language ); if ( request.analyze ) { @@ -114,7 +116,7 @@ public static void startup() { String[] mqls = request.query.trim().split( "\\n(?=(use|db.|show))" ); - Long namespaceId = request.namespaceId; + Long namespaceId = request.namespace == null ? null : Catalog.snapshot().getNamespace( request.namespace ).map( n -> n.id ).orElse( null ); long executionTime = System.nanoTime(); boolean noLimit = false; @@ -132,8 +134,9 @@ public static void startup() { } if ( parsed instanceof MqlUseDatabase ) { - namespaceId = Catalog.snapshot().getNamespace( ((MqlUseDatabase) parsed).getDatabase() ).orElseThrow().id; - //continue; + Optional optionalNamespace = Catalog.snapshot().getNamespace( ((MqlUseDatabase) parsed).getDatabase() ); + namespaceId = optionalNamespace.map( logicalNamespace -> logicalNamespace.id ).orElseGet( () -> Catalog.getInstance().addNamespace( ((MqlUseDatabase) parsed).getDatabase(), NamespaceType.DOCUMENT, false ) ); + continue; } if ( parsed instanceof MqlCollectionStatement && ((MqlCollectionStatement) parsed).getLimit() != null ) { @@ -141,7 +144,7 @@ public static void startup() { } if ( parsed.getFamily() == Family.DML && mqlProcessor.needsDdlGeneration( parsed, parameters ) ) { - mqlProcessor.autoGenerateDDL( Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, databaseId, "HTTP Interface MQL (auto)" ).createStatement(), parsed, parameters ); + mqlProcessor.autoGenerateDDL( Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, namespaceId, "HTTP Interface MQL (auto)" ).createStatement(), parsed, parameters ); } if ( parsed.getFamily() == Family.DDL ) { diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessorImpl.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessorImpl.java index b09eb211b7..8e2dde6a0c 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessorImpl.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessorImpl.java @@ -27,6 +27,7 @@ import org.polypheny.db.algebra.constant.ExplainLevel; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.mql.MqlCollectionStatement; import org.polypheny.db.languages.mql.MqlCreateCollection; import org.polypheny.db.languages.mql.MqlNode; @@ -116,17 +117,15 @@ public void autoGenerateDDL( Statement statement, Node query, QueryParameters pa try { statement.getTransaction().commit(); } catch ( TransactionException e ) { - throw new RuntimeException( "There was a problem auto-generating the needed collection." ); + throw new GenericRuntimeException( "There was a problem auto-generating the needed collection." ); } - throw new RuntimeException( "No collections is used." ); + throw new GenericRuntimeException( "No collections is used." ); } new MqlCreateCollection( ParserPos.sum( Collections.singletonList( query ) ), ((MqlCollectionStatement) query).getCollection(), - null - ) - .execute( statement.getPrepareContext(), statement, parameters ); + null ).execute( statement.getPrepareContext(), statement, parameters ); try { statement.getTransaction().commit(); Catalog.getInstance().commit(); diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoEntity.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoEntity.java index 56f21deccf..8baa32c9fc 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoEntity.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoEntity.java @@ -65,8 +65,6 @@ */ public class NeoEntity extends PhysicalEntity implements TranslatableEntity, ModifiableTable, QueryableEntity { - - private final AlgDataType rowType; private final List fields; private final NeoNamespace namespace; @@ -74,7 +72,6 @@ public class NeoEntity extends PhysicalEntity implements TranslatableEntity, Mod protected NeoEntity( PhysicalEntity physical, List fields, NeoNamespace namespace ) { super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.namespaceId, physical.namespaceName, physical.namespaceType, physical.adapterId ); - this.rowType = physical.getRowType(); this.fields = fields; this.namespace = namespace; } @@ -114,11 +111,6 @@ public Modify toModificationTable( } - @Override - public AlgDataType getRowType() { - return rowType; - } - @Override public Serializable[] getParameterArray() { @@ -161,7 +153,7 @@ public static class NeoQueryable extends AbstractEntityQueryable nodes = new ArrayList<>(); int i = 0; - for ( RexNode node : neoModify.getSourceExpressionList() ) { + for ( RexNode node : neoModify.getSourceExpressions() ) { Translator translator = new Translator( last.getRowType(), last.getRowType(), mapping, this, null, true ); - nodes.add( assign_( literal_( mapping.get( neoModify.getUpdateColumnList().get( i ) ) ), literal_( node.accept( translator ) ) ) ); + nodes.add( assign_( literal_( mapping.get( neoModify.getUpdateColumns().get( i ) ) ), literal_( node.accept( translator ) ) ) ); i++; } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/NeoRules.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/NeoRules.java index f8546d55cd..ca9e5cadd5 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/NeoRules.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/NeoRules.java @@ -96,8 +96,8 @@ public AlgNode convert( AlgNode alg ) { modify.getEntity().unwrap( NeoEntity.class ), convert( modify.getInput(), NeoConvention.INSTANCE ), modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), + modify.getUpdateColumns(), + modify.getSourceExpressions(), modify.isFlattened() ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoModify.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoModify.java index 315f615696..2dd575f799 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoModify.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoModify.java @@ -102,8 +102,8 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { entity, inputs.get( 0 ), getOperation(), - getUpdateColumnList(), - getSourceExpressionList(), + getUpdateColumns(), + getSourceExpressions(), isFlattened() ); } diff --git a/plugins/notebooks/src/main/java/org/polypheny/db/notebooks/model/JupyterKernel.java b/plugins/notebooks/src/main/java/org/polypheny/db/notebooks/model/JupyterKernel.java index 523fc1c1c2..9e7004dd9f 100644 --- a/plugins/notebooks/src/main/java/org/polypheny/db/notebooks/model/JupyterKernel.java +++ b/plugins/notebooks/src/main/java/org/polypheny/db/notebooks/model/JupyterKernel.java @@ -177,7 +177,7 @@ private void handleInputRequest( JsonObject json ) { return; } Optional namespace = Catalog.snapshot().getNamespace( apc.namespace ); - String result = anyQuery( query, apc.language, namespace.orElseThrow().id ); + String result = anyQuery( query, apc.language, namespace.orElseThrow().name ); ByteBuffer request = buildInputReply( result, parentHeader ); webSocket.sendBinary( request, true ); } @@ -244,11 +244,11 @@ public void executePolyCell( * * @param query the query to be executed * @param language the query language to be used - * @param namespaceId the target namespace + * @param namespace the target namespace * @return the serialized results in JSON format */ - private String anyQuery( String query, String language, long namespaceId ) { - QueryRequest queryRequest = new QueryRequest( query, false, true, language, namespaceId ); + private String anyQuery( String query, String language, String namespace ) { + QueryRequest queryRequest = new QueryRequest( query, false, true, language, namespace ); List> results = LanguageCrud.anyQuery( QueryLanguage.from( language ), null, diff --git a/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/Rest.java b/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/Rest.java index 85a60a06b0..1740ac335b 100644 --- a/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/Rest.java +++ b/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/Rest.java @@ -338,7 +338,7 @@ List filters( Statement statement, AlgBuilder algBuilder, RexBuilder re AlgDataType filtersRowType = baseNodeForFilters.getRowType(); List filtersRows = filtersRowType.getFieldList(); Map filterMap = new HashMap<>(); - filtersRows.forEach( ( r ) -> filterMap.put( r.getKey(), r ) ); + filtersRows.forEach( ( r ) -> filterMap.put( r.getName(), r ) ); int index = 0; for ( RequestColumn column : filters.literalFilters.keySet() ) { for ( Pair filterOperationPair : filters.literalFilters.get( column ) ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlInsert.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlInsert.java index 65581b49c7..79d429ae03 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlInsert.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlInsert.java @@ -17,6 +17,7 @@ package org.polypheny.db.sql.language; import java.util.List; +import lombok.Getter; import lombok.Setter; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.logistic.NamespaceType; @@ -36,7 +37,9 @@ public class SqlInsert extends SqlCall { public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator( "INSERT", Kind.INSERT ); SqlNodeList keywords; + @Getter SqlNode targetTable; + @Getter SqlNode source; @Setter SqlNodeList columnList; @@ -109,22 +112,6 @@ public void setOperand( int i, Node operand ) { } - /** - * @return the identifier for the target table of the insertion - */ - public SqlNode getTargetTable() { - return targetTable; - } - - - /** - * @return the source expression for the data to be inserted - */ - public SqlNode getSource() { - return source; - } - - public void setSource( SqlSelect source ) { this.source = source; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUpdate.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUpdate.java index 5471f3674d..911abfbb1a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUpdate.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUpdate.java @@ -18,6 +18,7 @@ import java.util.List; +import lombok.Getter; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -31,6 +32,7 @@ /** * A SqlUpdate is a node of a parse tree which represents an UPDATE statement. */ +@Getter public class SqlUpdate extends SqlCall { public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator( "UPDATE", Kind.UPDATE ); @@ -43,14 +45,14 @@ public class SqlUpdate extends SqlCall { SqlIdentifier alias; - public SqlUpdate( ParserPos pos, SqlNode targetTable, SqlNodeList targetColumnList, SqlNodeList sourceExpressionList, SqlNode condition, SqlSelect sourceSelect, SqlIdentifier alias ) { + public SqlUpdate( ParserPos pos, SqlNode targetTable, SqlNodeList targetColumns, SqlNodeList sourceExpressions, SqlNode condition, SqlSelect sourceSelect, SqlIdentifier alias ) { super( pos ); this.targetTable = targetTable; - this.targetColumnList = targetColumnList; - this.sourceExpressionList = sourceExpressionList; + this.targetColumnList = targetColumns; + this.sourceExpressionList = sourceExpressions; this.condition = condition; this.sourceSelect = sourceSelect; - assert sourceExpressionList.size() == targetColumnList.size(); + assert sourceExpressions.size() == targetColumns.size(); this.alias = alias; } @@ -107,63 +109,11 @@ public void setOperand( int i, Node operand ) { } - /** - * @return the identifier for the target table of the update - */ - public SqlNode getTargetTable() { - return targetTable; - } - - - /** - * @return the alias for the target table of the update - */ - public SqlIdentifier getAlias() { - return alias; - } - - public void setAlias( SqlIdentifier alias ) { this.alias = alias; } - /** - * @return the list of target column names - */ - public SqlNodeList getTargetColumnList() { - return targetColumnList; - } - - - /** - * @return the list of source expressions - */ - public SqlNodeList getSourceExpressionList() { - return sourceExpressionList; - } - - - /** - * Gets the filter condition for rows to be updated. - * - * @return the condition expression for the data to be updated, or null for all rows in the table - */ - public SqlNode getCondition() { - return condition; - } - - - /** - * Gets the source SELECT expression for the data to be updated. Returns null before the statement has been expanded by {@code SqlValidatorImpl#performUnconditionalRewrites(SqlNode, boolean)}. - * - * @return the source SELECT for the data to be updated - */ - public SqlSelect getSourceSelect() { - return sourceSelect; - } - - public void setSourceSelect( SqlSelect sourceSelect ) { this.sourceSelect = sourceSelect; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java index 1139633931..9df5adb626 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; @@ -74,13 +75,17 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override public void execute( Context context, Statement statement, QueryParameters parameters ) { - LogicalTable catalogTable = searchEntity( context, view ); + LogicalTable table = searchEntity( context, view ); - if ( catalogTable.entityType != EntityType.VIEW ) { - throw new RuntimeException( "Not Possible to use ALTER VIEW because " + catalogTable.name + " is not a View." ); + if ( table == null ) { + throw new GenericRuntimeException( "Could not find view with name %s", String.join( ".", view.names ) ); } - DdlManager.getInstance().renameColumn( catalogTable, columnOldName.getSimple(), columnNewName.getSimple(), statement ); + if ( table.entityType != EntityType.VIEW ) { + throw new RuntimeException( "Not Possible to use ALTER VIEW because " + table.name + " is not a View." ); + } + + DdlManager.getInstance().renameColumn( table, columnOldName.getSimple(), columnNewName.getSimple(), statement ); } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorImpl.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorImpl.java index 9f9c9ec187..b14f6c3e7f 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorImpl.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorImpl.java @@ -40,11 +40,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.IntStream; import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -527,10 +527,10 @@ private boolean expandStar( List selectItems, Set aliases, List } if ( child.nullable ) { for ( int i = before; i < fields.size(); i++ ) { - final Entry entry = fields.get( i ); - final AlgDataType type = entry.getValue(); + final AlgDataTypeField entry = fields.get( i ); + final AlgDataType type = entry.getType(); if ( !type.isNullable() ) { - fields.set( i, new AlgDataTypeFieldImpl( 1L, entry.getKey(), i, typeFactory.createTypeWithNullability( type, true ) ) ); + fields.set( i, new AlgDataTypeFieldImpl( entry.getId(), entry.getName(), i, typeFactory.createTypeWithNullability( type, true ) ) ); } } } @@ -4210,13 +4210,13 @@ protected void checkTypeAssignment( AlgDataType sourceRowType, AlgDataType targe long targetDimension = ((ArrayType) targetType).getDimension(); long sourceDimension = ((ArrayType) sourceType).getMaxDimension(); if ( sourceDimension > targetDimension && targetDimension > -1 ) { - throw newValidationError( query, RESOURCE.exceededDimension( targetFields.get( i ).getKey(), sourceDimension, targetDimension ) ); + throw newValidationError( query, RESOURCE.exceededDimension( targetFields.get( i ).getName(), sourceDimension, targetDimension ) ); } long targetCardinality = ((ArrayType) targetType).getCardinality(); long sourceCardinality = ((ArrayType) sourceType).getMaxCardinality(); if ( sourceCardinality > targetCardinality && targetCardinality > -1 ) { - throw newValidationError( query, RESOURCE.exceededCardinality( targetFields.get( i ).getKey(), sourceCardinality, targetCardinality ) ); + throw newValidationError( query, RESOURCE.exceededCardinality( targetFields.get( i ).getName(), sourceCardinality, targetCardinality ) ); } } } @@ -4409,7 +4409,6 @@ public void validateMerge( SqlMerge call ) { private void validateAccess( SqlNode node, CatalogEntity table, AccessEnum requiredAccess ) { if ( table != null ) { AccessType access = AccessType.ALL; - ; if ( !access.allowsAccess( requiredAccess ) ) { throw newValidationError( node, RESOURCE.accessNotAllowed( requiredAccess.name(), table.name ) ); } @@ -5110,19 +5109,9 @@ public SqlNode visit( DynamicParam param ) { } } ); return typeFactory.createStructType( - List.of(), - types, new AbstractList<>() { - @Override - public String get( int index ) { - return "?" + index; - } - - - @Override - public int size() { - return types.size(); - } - } ); + types.stream().map( t -> (Long) null ).collect( Collectors.toList() ), + types, + IntStream.range( 0, types.size() ).mapToObj( i -> "?" + i ).collect( Collectors.toList() ) ); } @@ -6170,18 +6159,18 @@ public void permute( List selectItems, List fields ) final List oldSelectItems = ImmutableList.copyOf( selectItems ); selectItems.clear(); - final List> oldFields = ImmutableList.copyOf( fields ); + final List oldFields = ImmutableList.copyOf( fields ); fields.clear(); for ( ImmutableList source : sources ) { final int p0 = source.get( 0 ); - Map.Entry field = oldFields.get( p0 ); - final String name = field.getKey(); - AlgDataType type = field.getValue(); + AlgDataTypeField field = oldFields.get( p0 ); + final String name = field.getName(); + AlgDataType type = field.getType(); SqlNode selectItem = oldSelectItems.get( p0 ); for ( int p1 : Util.skip( source ) ) { - final Map.Entry field1 = oldFields.get( p1 ); + final AlgDataTypeField field1 = oldFields.get( p1 ); final SqlNode selectItem1 = oldSelectItems.get( p1 ); - final AlgDataType type1 = field1.getValue(); + final AlgDataType type1 = field1.getType(); // output is nullable only if both inputs are final boolean nullable = type.isNullable() && type1.isNullable(); final AlgDataType type2 = PolyTypeUtil.leastRestrictiveForComparison( typeFactory, type, type1 ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlToAlgConverter.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlToAlgConverter.java index 467afa056d..2a901d28b5 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlToAlgConverter.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlToAlgConverter.java @@ -410,13 +410,12 @@ private void checkConvertedType( Node query, AlgNode result ) { // Verify that conversion from SQL to relational algebra did not perturb any type information. // (We can't do this if the SQL statement is something like an INSERT which has no // validator type information associated with its result, hence the namespace check above.) - List validatedFields = validator.getValidatedNodeType( query ).getFieldList(); // TODO DL readd final + List validatedFields = validator.getValidatedNodeType( query ).getFieldList(); // TODO DL read final final AlgDataType validatedRowType = validator.getTypeFactory().createStructType( validatedFields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), - Pair.right( validatedFields ), ValidatorUtil.uniquify( - Pair.left( validatedFields ), - false ) ); + validatedFields.stream().map( AlgDataTypeField::getType ).collect( Collectors.toList() ), + ValidatorUtil.uniquify( validatedFields.stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ), false ) ); /*int diff = validatedFields.size() - result.getRowType().getFieldList().size(); if ( diff > 0 ) { for ( int i = 0; i < diff; i++ ) { diff --git a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java index a98b38ae5d..45315a0612 100644 --- a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java +++ b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java @@ -70,8 +70,25 @@ public static HttpServer getInstance() { } + public static final 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(); + } + }; + @Getter - private Javalin server; + private final Javalin server = Javalin.create( config -> { + config.jsonMapper( new JavalinJackson( mapper ) ); + config.enableCorsForAllOrigins(); + config.addStaticFiles( staticFileConfig -> staticFileConfig.directory = "webapp/" ); + } ).start( RuntimeConfig.WEBUI_SERVER_PORT.getInteger() ); private Crud crud; @@ -86,23 +103,6 @@ public void run() { long maxSizeMB = RuntimeConfig.UI_UPLOAD_SIZE_MB.getInteger(); long maxRequestSize = 1_000_000L * maxSizeMB; - this.server = Javalin.create( config -> { - config.jsonMapper( new JavalinJackson( 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(); - } - } ) ); - config.enableCorsForAllOrigins(); - config.addStaticFiles( staticFileConfig -> staticFileConfig.directory = "webapp/" ); - } ).start( RuntimeConfig.WEBUI_SERVER_PORT.getInteger() ); - /*this.server = Javalin.create( config -> { // todo dl enable, when we removed avatica and can finally bump javalin config.plugins.enableCors( cors -> cors.add( CorsPluginConfig::anyHost ) ); config.staticFiles.add( "webapp" ); diff --git a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java index 23af5f6b3d..e921e82d4e 100644 --- a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java +++ b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java @@ -107,7 +107,7 @@ public void onMessage( final WsMessageContext ctx ) { switch ( request.type ) { case "GraphRequest": GraphRequest graphRequest = ctx.messageAsClass( GraphRequest.class ); - PolyGraph graph = LanguageCrud.getGraph( graphRequest.namespaceId, crud.getTransactionManager() ); + PolyGraph graph = LanguageCrud.getGraph( Catalog.snapshot().getNamespace( graphRequest.namespace ).orElseThrow().name, crud.getTransactionManager() ); ctx.send( graph.toJson() ); @@ -152,7 +152,7 @@ public void onMessage( final WsMessageContext ctx ) { } else {//TableRequest, is equal to UIRequest UIRequest uiRequest = ctx.messageAsClass( UIRequest.class ); try { - LogicalNamespace namespace = Catalog.getInstance().getSnapshot().getNamespace( uiRequest.namespaceId ).orElseThrow(); + LogicalNamespace namespace = Catalog.getInstance().getSnapshot().getNamespace( uiRequest.namespace ).orElseThrow(); switch ( namespace.namespaceType ) { case RELATIONAL: result = crud.getTable( uiRequest ); @@ -161,7 +161,7 @@ public void onMessage( final WsMessageContext ctx ) { result = LanguageCrud.anyQuery( QueryLanguage.from( "mongo" ), ctx.session, - new QueryRequest( String.format( "db.%s.find({})", namespace.name ), false, false, "mql", namespace.id ), + new QueryRequest( String.format( "db.%s.find({})", namespace.name ), false, false, "mql", namespace.name ), crud.getTransactionManager(), Catalog.defaultUserId, Catalog.defaultNamespaceId @@ -171,7 +171,7 @@ public void onMessage( final WsMessageContext ctx ) { result = LanguageCrud.anyQuery( QueryLanguage.from( "cypher" ), ctx.session, - new QueryRequest( "MATCH (n) RETURN n", false, false, "mql", namespace.id ), + new QueryRequest( "MATCH (n) RETURN n", false, false, "mql", namespace.name ), crud.getTransactionManager(), Catalog.defaultUserId, Catalog.defaultNamespaceId 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 2d16aaf5a9..876bb4da3b 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 @@ -144,13 +144,13 @@ public static InformationManager attachAnalyzerIfSpecified( QueryRequest request } - public static PolyGraph getGraph( Long namespaceId, TransactionManager manager ) { + public static PolyGraph getGraph( String namespace, TransactionManager manager ) { Transaction transaction = Crud.getTransaction( false, false, manager, Catalog.defaultUserId, Catalog.defaultNamespaceId, "getGraph" ); Processor processor = transaction.getProcessor( QueryLanguage.from( "cypher" ) ); Statement statement = transaction.createStatement(); - ExtendedQueryParameters parameters = new ExtendedQueryParameters( namespaceId ); + ExtendedQueryParameters parameters = new ExtendedQueryParameters( namespace ); AlgRoot logicalRoot = processor.translate( statement, null, parameters ); PolyImplementation polyImplementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); @@ -249,7 +249,7 @@ public static void attachError( Transaction transaction, List> resu .header( header.toArray( new UiColumnDefinition[0] ) ) .data( data.toArray( new String[0][] ) ) .namespaceType( implementation.getNamespaceType() ) - .namespaceId( request.namespaceId ) + .namespace( request.namespace ) .language( language ) .affectedTuples( data.size() ) .hasMore( hasMoreRows ) @@ -276,7 +276,7 @@ private static GraphResult getGraphResult( Statement statement, QueryLanguage la .language( language ) .namespaceType( implementation.getNamespaceType() ) .xid( transaction.getXid().toString() ) - .namespaceId( request.namespaceId ) + .namespace( request.namespace ) .build(); } @@ -284,7 +284,7 @@ private static GraphResult getGraphResult( Statement statement, QueryLanguage la private static DocResult getDocResult( Statement statement, QueryLanguage language, QueryRequest request, String query, PolyImplementation implementation, Transaction transaction, boolean noLimit ) { ResultIterator iterator = implementation.execute( statement, noLimit ? -1 : RuntimeConfig.UI_PAGE_SIZE.getInteger() ); - List data = iterator.getSingleRows(); + List> data = iterator.getRows(); try { iterator.close(); } catch ( Exception e ) { @@ -293,12 +293,12 @@ private static DocResult getDocResult( Statement statement, QueryLanguage langua return DocResult.builder() .header( implementation.rowType.getFieldList().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) - .data( data.stream().map( LanguageCrud::toJson ).toArray( String[]::new ) ) + .data( data.stream().map( d -> d.get( 0 ).toJson() ).toArray( String[]::new ) ) .query( query ) .language( language ) .xid( transaction.getXid().toString() ) .namespaceType( implementation.getNamespaceType() ) - .namespaceId( request.namespaceId ) + .namespace( request.namespace ) .build(); } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/requests/GraphRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/requests/GraphRequest.java index ef1d6c3848..509ccb2dc4 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/requests/GraphRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/requests/GraphRequest.java @@ -42,8 +42,8 @@ public GraphRequest( @JsonProperty("analyze") boolean analyze, @JsonProperty("cache") boolean cache, @JsonProperty("language") String language, - @JsonProperty("namespaceId") Long namespaceId ) { - super( query, analyze, cache, language, namespaceId ); + @JsonProperty("namespaceId") String namespace ) { + super( query, analyze, cache, language, namespace ); this.nodeIds = nodeIds; this.edgeIds = edgeIds; } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java index 1244bf0d14..d8d3951053 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/requests/QueryRequest.java @@ -29,12 +29,12 @@ public QueryRequest( @JsonProperty("analyze") boolean analyze, @JsonProperty("cache") boolean cache, @JsonProperty("language") String language, - @JsonProperty("namespaceId") Long namespaceId ) { + @JsonProperty("namespaceId") String namespace ) { this.query = query; this.analyze = analyze; this.cache = cache; this.language = language; - this.namespaceId = namespaceId; + this.namespace = namespace; } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java index 2e1b0ec794..fe9f004ed7 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/requests/UIRequest.java @@ -32,7 +32,7 @@ public class UIRequest extends RequestModel { */ public Long entityId; - public Long namespaceId; + public String namespace; /** * Information about the pagination, diff --git a/webui/src/main/java/org/polypheny/db/webui/models/results/DocResult.java b/webui/src/main/java/org/polypheny/db/webui/models/results/DocResult.java index a9f187f3a7..25a737c689 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/results/DocResult.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/results/DocResult.java @@ -19,10 +19,12 @@ import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; import org.polypheny.db.webui.models.catalog.FieldDefinition; @EqualsAndHashCode(callSuper = true) @SuperBuilder(toBuilder = true) +@Jacksonized @Value public class DocResult extends Result { diff --git a/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java b/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java index 983a4909c7..5fb1883c0d 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/results/RelationalResult.java @@ -61,7 +61,7 @@ public class RelationalResult extends Result { @JsonCreator public RelationalResult( @JsonProperty("namespaceType") NamespaceType namespaceType, - @JsonProperty("namespaceId") Long namespaceId, + @JsonProperty("namespace") String namespace, @JsonProperty("data") String[][] data, @JsonProperty("UiColumnDefinition") UiColumnDefinition[] header, @JsonProperty("exception") Throwable exception, @@ -77,7 +77,7 @@ public RelationalResult( @JsonProperty("ResultType") ResultType type, @JsonProperty("hasMoreRows") boolean hasMore, @JsonProperty("language") QueryLanguage language ) { - super( namespaceType, namespaceId, data, header, exception, query, xid, error, currentPage, highestPage, hasMore, language, affectedTuples ); + super( namespaceType, namespace, data, header, exception, query, xid, error, currentPage, highestPage, hasMore, language, affectedTuples ); this.table = table; this.tables = tables; this.request = request; diff --git a/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java b/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java index dd0bdcd335..41640b4393 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/results/Result.java @@ -41,7 +41,7 @@ public abstract class Result { */ public NamespaceType namespaceType; - public Long namespaceId; + public String namespace; public E[] data; @@ -100,7 +100,7 @@ public static abstract class ResultBuilder, B exten this.namespaceType = instance.namespaceType; this.xid = instance.xid; this.error = instance.error; - this.namespaceId = instance.namespaceId; + this.namespace = instance.namespace; this.query = instance.query; this.exception = instance.exception; this.language$value = instance.language;