Skip to content

Commit

Permalink
reformated code
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Dec 14, 2024
1 parent 9381b5f commit a42c64c
Show file tree
Hide file tree
Showing 45 changed files with 103 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
run: ./gradlew assemblePlugins -PwithoutpullingUi=true
- name: Execute tests
timeout-minutes: 30
run: ./gradlew check -PwithoutpullingUi=true -i
run: ./gradlew check -PwithoutpullingUi=true
7 changes: 4 additions & 3 deletions core/src/main/java/org/polypheny/db/algebra/AlgNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ default void buildPolyAlgebra( StringBuilder sb ) {
buildPolyAlgebra( sb, null );
}

default String buildPolyAlgebra(String prefix) {
default String buildPolyAlgebra( String prefix ) {
StringBuilder sb = new StringBuilder();
buildPolyAlgebra(sb, prefix);
buildPolyAlgebra( sb, prefix );
return sb.toString();
}

Expand All @@ -273,10 +273,11 @@ default String buildPolyAlgebra(String prefix) {

/**
* Serialize this node without generating metadata.
*
* @param mapper the ObjectMapper used for creating JsonNodes.
* @return a ObjectNode representing the AlgNode tree rooted at this node.
*/
default ObjectNode serializePolyAlgebra( ObjectMapper mapper) {
default ObjectNode serializePolyAlgebra( ObjectMapper mapper ) {
return serializePolyAlgebra( mapper, null );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package org.polypheny.db.algebra.convert;


import java.util.Optional;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.SingleAlg;
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
Expand All @@ -42,7 +43,6 @@
import org.polypheny.db.plan.AlgPlanner;
import org.polypheny.db.plan.AlgTraitDef;
import org.polypheny.db.plan.AlgTraitSet;
import java.util.Optional;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private boolean typeMatchesInferred( final AggregateCall aggCall, final Litmus l
AggCallBinding callBinding = aggCall.createBinding( this );
AlgDataType type = aggFunction.inferReturnType( callBinding );
AlgDataType expectedType = aggCall.type;
if (type.isNullable() != expectedType.isNullable()) {
if ( type.isNullable() != expectedType.isNullable() ) {
// During PolyAlgebra parsing, the type might become non-nullable. We do not want to throw an error in this case.
AlgDataTypeFactory factory = AlgDataTypeFactory.DEFAULT;
expectedType = factory.createTypeWithNullability( expectedType, type.isNullable() );
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/algebra/core/Calc.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static RexProgram getProgramFromArgs( PolyAlgArgs args, AlgNode input, Re
if ( condition != null ) {
builder.addCondition( condition );
}
return builder.getProgram(false);
return builder.getProgram( false );
}


Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/polypheny/db/algebra/core/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) {
Optional<Double> dRows = mq.getTupleCount( this );
Optional<Double> dCpu = mq.getTupleCount( getInput() );
double dIo = 0;
if(dRows.isEmpty() || dCpu.isEmpty()) {
if ( dRows.isEmpty() || dCpu.isEmpty() ) {
return planner.getCostFactory().makeInfiniteCost();
}
return planner.getCostFactory().makeCost( dRows.get(), dCpu.get(), dIo );
Expand All @@ -160,6 +160,7 @@ public String algCompareString() {
(condition != null ? condition.hashCode() : "") + "&";
}


@Override
public PolyAlgArgs bindArguments() {
PolyAlgArgs args = new PolyAlgArgs( getPolyAlgDeclaration() );
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/polypheny/db/algebra/core/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ public String algCompareString() {
(joinType != null ? joinType.name() : "") + "&";
}


protected static Triple<RexNode, Set<CorrelationId>, JoinAlgType> extractArgs( PolyAlgArgs args ) {
RexArg condition = args.getArg( "condition", RexArg.class );
EnumArg<JoinAlgType> type = args.getEnumArg( "type", JoinAlgType.class );
List<CorrelationId> variables = args.getListArg( "variables", CorrelationArg.class ).map( CorrelationArg::getCorrId );
return Triple.of( condition.getNode(), new HashSet<>( variables ), type.getArg() );
}


@Override
public PolyAlgArgs bindArguments() {
PolyAlgArgs args = new PolyAlgArgs( getPolyAlgDeclaration() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ public NodeType getNodeType() {
return NodeType.AGGREGATE;
}

public static AlgDataType deriveTupleType(AlgCluster cluster, AlgDataType inputType, List<RexNameRef> groups, List<LaxAggregateCall> aggCalls) {

public static AlgDataType deriveTupleType( AlgCluster cluster, AlgDataType inputType, List<RexNameRef> groups, List<LaxAggregateCall> aggCalls ) {
final AlgDataTypeFactory.Builder builder = cluster.getTypeFactory().builder();
for ( LaxAggregateCall aggCall : aggCalls ) {
builder.add( aggCall.name, null, aggCall.getType( cluster ));
builder.add( aggCall.name, null, aggCall.getType( cluster ) );
}
List<AlgDataTypeField> fields = inputType.getFields();
for (RexNameRef group : groups) {
for ( RexNameRef group : groups ) {
int idx = group.getIndex().orElseThrow();
builder.add( fields.get( idx ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ public String algCompareString() {
isFlattened() + "&";
}

protected static Quadruple<Operation, List<String>, List<? extends RexNode>, Boolean> extractArgs(PolyAlgArgs args) {

protected static Quadruple<Operation, List<String>, List<? extends RexNode>, Boolean> extractArgs( PolyAlgArgs args ) {
EnumArg<Operation> op = args.getEnumArg( "operation", Operation.class );
List<String> updateColumns = args.getListArg( "targets", StringArg.class ).map( StringArg::getArg );
List<? extends RexNode> sourceExpressions = args.getListArg( "sources", RexArg.class ).map( RexArg::getNode );
Expand All @@ -213,6 +214,7 @@ protected static Quadruple<Operation, List<String>, List<? extends RexNode>, Boo
return Quadruple.of( op.getArg(), updateColumns, sourceExpressions, flattened.toBool() );
}


@Override
public PolyAlgArgs bindArguments() {
PolyAlgArgs args = new PolyAlgArgs( getPolyAlgDeclaration() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public EnumerableIntersect( AlgCluster cluster, AlgTraitSet traitSet, List<AlgNo
assert !all;
}


public static EnumerableIntersect create( PolyAlgArgs args, List<AlgNode> children, AlgCluster cluster ) {
return new EnumerableIntersect( cluster, cluster.traitSet(), children, args.getArg( "all", BooleanArg.class ).toBool() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.polypheny.db.algebra.AlgCollationTraitDef;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.core.Project;
import org.polypheny.db.algebra.logical.relational.LogicalRelProject;
import org.polypheny.db.algebra.metadata.AlgMdCollation;
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
import org.polypheny.db.algebra.polyalg.arguments.ListArg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.calcite.linq4j.tree.MethodCallExpression;
import org.apache.calcite.linq4j.tree.Types;
import org.polypheny.db.adapter.java.JavaTypeFactory;
import org.polypheny.db.algebra.metadata.CyclicMetadataException;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.interpreter.Row;
import org.polypheny.db.runtime.Unit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public LogicalLpgAggregate( AlgCluster cluster, AlgTraitSet traits, AlgNode chil
public static LogicalLpgAggregate create( final AlgNode input, @NotNull List<RexNameRef> groups, List<LaxAggregateCall> aggCalls ) {
AlgCluster cluster = input.getCluster();
AlgTraitSet traitSet = input.getTraitSet();
AlgDataType type = deriveTupleType(cluster, input.getTupleType(), groups, aggCalls);
return new LogicalLpgAggregate( cluster, traitSet, input, groups, aggCalls, type);
AlgDataType type = deriveTupleType( cluster, input.getTupleType(), groups, aggCalls );
return new LogicalLpgAggregate( cluster, traitSet, input, groups, aggCalls, type );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public LogicalLpgFilter( AlgCluster cluster, AlgTraitSet traits, AlgNode input,
super( cluster, traits, input, condition );
}


public static LogicalLpgFilter create( AlgNode input, RexNode condition ) {
// TODO: modify traitset
return new LogicalLpgFilter( input.getCluster(), input.getTraitSet(), input, condition );
}


public static LogicalLpgFilter create( PolyAlgArgs args, List<AlgNode> children, AlgCluster cluster ) {
RexArg condition = args.getArg( "condition", RexArg.class );
return create( children.get( 0 ), condition.getNode() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.polypheny.db.algebra.metadata.AlgMdCollation;
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
import org.polypheny.db.algebra.polyalg.arguments.ListArg;
import org.polypheny.db.algebra.polyalg.arguments.PolyAlgArg;
import org.polypheny.db.algebra.polyalg.arguments.PolyAlgArgs;
import org.polypheny.db.algebra.polyalg.arguments.RexArg;
import org.polypheny.db.algebra.type.AlgDataType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public Double getDistinctRowCount( AlgNode alg, AlgMetadataQuery mq, ImmutableBi
return null;
}


@SuppressWarnings("unused")//used by codegen
public Double getDistinctRowCount( Union alg, AlgMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate ) {
double rowCount = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package org.polypheny.db.algebra.metadata;


import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.SingleAlg;
Expand All @@ -59,7 +60,6 @@
import org.polypheny.db.util.ImmutableBitSet;
import org.polypheny.db.util.NumberUtil;
import org.polypheny.db.util.Util;
import java.util.Optional;


/**
Expand Down Expand Up @@ -132,7 +132,7 @@ public Double getTupleCount( Project alg, AlgMetadataQuery mq ) {

public Double getTupleCount( Sort alg, AlgMetadataQuery mq ) {
Optional<Double> count = mq.getTupleCount( alg.getInput() );
if ( count.isEmpty()) {
if ( count.isEmpty() ) {
return null;
}
double rowCount = count.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public Optional<Double> getTupleCount( AlgNode alg ) {
}
}


/**
* Returns the {@link BuiltInMetadata.MaxRowCount#getMaxRowCount()} statistic.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static AlgMetadataProvider reflectiveSource( final MetadataHandler<?> ta
}
Object value = mq.map.put( key1, NullSentinel.INSTANCE );
if ( value != null ) {
throw new CyclicMetadataException( String.format("Already found key %s with value %s", key1, value ) );
throw new CyclicMetadataException( String.format( "Already found key %s with value %s", key1, value ) );
}
try {
return handlerMethod.invoke( target, args1 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public boolean supportsNumberOfChildren( int n ) {
return numInputs == -1 || numInputs == n;
}


public boolean mightRequireAuxiliaryProject() {
return (numInputs == -1 || numInputs > 1) &&
!opTags.contains( OperatorTag.PHYSICAL ) &&
Expand Down Expand Up @@ -262,7 +263,7 @@ public ObjectNode serialize( ObjectMapper mapper ) {
}
node.set( "kwParams", kwArr );

if (isNotFullyImplemented) {
if ( isNotFullyImplemented ) {
node.put( "notRegistered", true ); // disables editing for this node in the UI
}

Expand Down Expand Up @@ -437,7 +438,7 @@ public enum ParamType {
/**
* Window.Group
*/
WINDOW_GROUP( WindowGroupArg.class);
WINDOW_GROUP( WindowGroupArg.class );

private final Class<? extends PolyAlgArg> argClass;
private final Class<? extends Enum<?>> enumClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public class AnyArg implements PolyAlgArg {

private final Object arg;

public AnyArg(Object arg) {

public AnyArg( Object arg ) {
this.arg = arg;
}


@Override
public ParamType getType() {
return ParamType.ANY;
Expand All @@ -47,6 +49,7 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return arg.toString();
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return mapper.createObjectNode().put( "arg", arg.toString() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return Boolean.toString( bool );
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return mapper.createObjectNode().put( "arg", bool );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return str;
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return serialize( coll, inputFieldNames, mapper );
}


public static ObjectNode serialize( AlgFieldCollation coll, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
ObjectNode node = mapper.createObjectNode();
if (coll != null) {
if ( coll != null ) {
int idx = coll.getFieldIndex();
node.put("field", inputFieldNames.size() > idx ? inputFieldNames.get( idx ) : Integer.toString( idx ));
node.put("direction", coll.direction.shortString);
node.put("nullDirection", coll.nullDirection.toString());
node.put( "field", inputFieldNames.size() > idx ? inputFieldNames.get( idx ) : Integer.toString( idx ) );
node.put( "direction", coll.direction.shortString );
node.put( "nullDirection", coll.nullDirection.toString() );
}
return node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return String.valueOf( corrId.getId() );
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return mapper.createObjectNode().put( "arg", corrId.getId() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return Double.toString( arg );
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return mapper.createObjectNode().put( "arg", arg );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public EntityArg( Entity entity, Snapshot snapshot, DataModel model ) {
if ( entity instanceof AllocationEntity e ) {
if ( e.dataModel != DataModel.GRAPH ) {
this.entityName = snapshot.getLogicalEntity( e.logicalId ).orElseThrow().name;
} else if (!e.name.startsWith( AllocationEntity.PREFIX )) {
} else if ( !e.name.startsWith( AllocationEntity.PREFIX ) ) {
this.entityName = e.name;
}
this.partitionName = snapshot.alloc().getPartition( e.partitionId ).orElseThrow().name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return Integer.toString( field );
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return mapper.createObjectNode().put( "arg", toPolyAlg( context, inputFieldNames ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
return Integer.toString( arg );
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
return mapper.createObjectNode().put( "arg", arg );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.polypheny.db.algebra.polyalg.PolyAlgDeclaration.ParamType;
import org.polypheny.db.algebra.polyalg.PolyAlgUtils;

public class LaxAggArg implements PolyAlgArg{
public class LaxAggArg implements PolyAlgArg {

@Getter
private final LaxAggregateCall agg;
Expand All @@ -53,19 +53,20 @@ public String toPolyAlg( AlgNode context, @NonNull List<String> inputFieldNames
private String aggToString( List<String> inputFieldNames ) {
StringBuilder sb = new StringBuilder( agg.function.toString() );
sb.append( "(" );
if (agg.getInput().isPresent()) {
if ( agg.getInput().isPresent() ) {
sb.append( PolyAlgUtils.digestWithNames( agg.getInput().get(), inputFieldNames ) );
}
sb.append( ")" );
return sb.toString();
}


@Override
public ObjectNode serialize( AlgNode context, @NonNull List<String> inputFieldNames, ObjectMapper mapper ) {
ObjectNode node = mapper.createObjectNode();
node.put("function", agg.function.toString());
if (agg.getInput().isPresent()) {
node.put("input", PolyAlgUtils.digestWithNames( agg.getInput().get(), inputFieldNames ));
node.put( "function", agg.function.toString() );
if ( agg.getInput().isPresent() ) {
node.put( "input", PolyAlgUtils.digestWithNames( agg.getInput().get(), inputFieldNames ) );
}
node.put( "alias", agg.name );
return node;
Expand Down
Loading

0 comments on commit a42c64c

Please sign in to comment.