Skip to content

Commit

Permalink
some fixes for jdbc queries and non-relational queries
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Oct 8, 2023
1 parent 1cbbd76 commit a41dc04
Show file tree
Hide file tree
Showing 87 changed files with 394 additions and 543 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ public void dropCollection( Context context, AllocationCollection allocation ) {
}


@Override
public void renameLogicalColumn( long id, String newColumnName ) {
getCatalog().renameLogicalField( id, newColumnName );
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,21 +65,4 @@ public void updateColumnType( Context context, long allocId, LogicalColumn colum
}


@Override
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
scannable.restoreGraph( alloc, entities );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Scannable.restoreCollectionSubstitute( scannable, alloc, entities );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public List<PhysicalEntity> createTable( Context context, LogicalTableWrapper lo
return scannable.createTable( context, logical, allocation );
}


@Override
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
Expand Down Expand Up @@ -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 );
}

}
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/adapter/Modifiable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public List<PhysicalEntity> createTable( Context context, LogicalTableWrapper lo
}



@Override
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
Expand Down Expand Up @@ -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 );
}

}
10 changes: 6 additions & 4 deletions core/src/main/java/org/polypheny/db/adapter/Scannable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<AllocationColumn> 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();
Expand Down Expand Up @@ -217,4 +217,6 @@ static void dropCollectionSubstitute( Scannable scannable, Context context, Allo
}


void renameLogicalColumn( long id, String newColumnName );

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Transformer( AlgOptCluster cluster, List<AlgNode> 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.";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,20 +55,15 @@
public abstract class RelModify<E extends CatalogEntity> extends Modify<E> {


/**
* The connection to the optimizing session.
*/
protected Prepare.CatalogReader catalogReader;

/**
* The table definition.
*/
@Getter
private final Operation operation;
@Getter
private final List<String> updateColumnList;
private final List<String> updateColumns;
@Getter
private final List<? extends RexNode> sourceExpressionList;
private final List<? extends RexNode> sourceExpressions;
private AlgDataType inputRowType;
@Getter
private final boolean flattened;
Expand All @@ -88,8 +82,8 @@ public abstract class RelModify<E extends CatalogEntity> extends Modify<E> {
* @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(
Expand All @@ -98,20 +92,20 @@ protected RelModify(
E table,
AlgNode input,
Operation operation,
List<String> updateColumnList,
List<? extends RexNode> sourceExpressionList,
List<String> updateColumns,
List<? extends RexNode> 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;
}
Expand Down Expand Up @@ -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 );
}

Expand All @@ -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() + "&";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -323,11 +324,11 @@ private Result implementDocumentOnRelational( EnumerableAlgImplementor implement

List<Expression> 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 );
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
}
Expand All @@ -153,7 +153,7 @@ public static LogicalProject getCollector( RexBuilder rexBuilder, AlgNode input


private static List<RexNode> createSourceList( RelModify<?> modify, RexBuilder rexBuilder ) {
return modify.getUpdateColumnList()
return modify.getUpdateColumns()
.stream()
.map( name -> {
int size = modify.getRowType().getFieldList().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public LogicalRelModify(
CatalogEntity table,
AlgNode input,
Operation operation,
List<String> updateColumnList,
List<? extends RexNode> sourceExpressionList,
List<String> updateColumns,
List<? extends RexNode> 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 );
}


Expand All @@ -70,19 +70,19 @@ public static LogicalRelModify create(
CatalogEntity table,
AlgNode input,
Operation operation,
List<String> updateColumnList,
List<? extends RexNode> sourceExpressionList,
List<String> updateColumns,
List<? extends RexNode> 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<AlgNode> 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 );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit a41dc04

Please sign in to comment.