Skip to content

Commit

Permalink
Proto Query Interface (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasHafner authored Apr 19, 2024
1 parent 07138c6 commit 45bb497
Show file tree
Hide file tree
Showing 98 changed files with 8,543 additions and 1,100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.common.collect.ImmutableMap;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.calcite.linq4j.function.Function2;
import org.jetbrains.annotations.Nullable;

/**
Expand Down Expand Up @@ -84,38 +83,6 @@ default void handle( AlgNode visitable ) {
}


interface AlgProducingVisitor2<Return, Param1> {

default Return handle( AlgNode visitable, Param1 param1 ) {
Function2<AlgNode, Param1, Return> handler = findHandler( visitable.getClass() );
if ( handler != null ) {
return handler.apply( visitable, param1 );
}

return getDefaultHandler().apply( visitable, param1 );
}


default @Nullable Function2<AlgNode, Param1, Return> findHandler( Class<?> clazz ) {
while ( clazz != null && clazz != AlgNode.class ) {
if ( getHandlers().containsKey( clazz ) ) {
return getHandlers().get( clazz );
}
clazz = clazz.getSuperclass();
}

return null;
}


ImmutableMap<Class<? extends AlgNode>, Function2<AlgNode, Param1, Return>> getHandlers();


Function2<AlgNode, Param1, Return> getDefaultHandler();

}


interface AlgProducingVisitor3<Return, Param1, Param2> {

default Return handle( AlgNode visitable, Param1 param1, Param2 param2 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
/**
* Relational expression that executes its children using an interpreter.
* <p>
* Although quite a few kinds of {@link AlgNode} can be interpreted, this is only created by default for {@link org.polypheny.db.schema.types.FilterableEntity} and
* {@link org.polypheny.db.schema.types.ProjectableFilterableEntity}.
* Although quite a few kinds of {@link AlgNode} can be interpreted, this is only created by default for {@link org.polypheny.db.schema.types.FilterableEntity}.
*/
public class EnumerableInterpreter extends SingleAlg implements EnumerableAlg {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.polypheny.db.plan.AlgTraitSet;
import org.polypheny.db.plan.volcano.VolcanoCost;
import org.polypheny.db.schema.types.FilterableEntity;
import org.polypheny.db.schema.types.ProjectableFilterableEntity;
import org.polypheny.db.schema.types.QueryableEntity;
import org.polypheny.db.schema.types.ScannableEntity;
import org.polypheny.db.schema.types.StreamableEntity;
Expand Down Expand Up @@ -138,7 +137,6 @@ public static Class<?> deduceElementType( PhysicalTable entity ) {
}
} else if ( entity instanceof ScannableEntity
|| entity instanceof FilterableEntity
|| entity instanceof ProjectableFilterableEntity
|| entity instanceof StreamableEntity ) {
return Object[].class;
} else {
Expand Down Expand Up @@ -177,8 +175,7 @@ private Expression toRows( PhysType physType, Expression expression ) {
&& Object[].class.isAssignableFrom( elementType )
&& getTupleType().getFieldCount() == 1
&& (entity.unwrap( ScannableEntity.class ).isPresent()
|| entity.unwrap( FilterableEntity.class ).isPresent()
|| entity.unwrap( ProjectableFilterableEntity.class ).isPresent()) ) {
|| entity.unwrap( FilterableEntity.class ).isPresent()) ) {
return Expressions.call( BuiltInMethod.SLICE0.method, expression );
}
JavaTupleFormat oldFormat = format();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.polypheny.db.algebra.logical.document.LogicalDocumentModify;
import org.polypheny.db.algebra.logical.lpg.LogicalLpgModify;
import org.polypheny.db.algebra.logical.relational.LogicalRelModify;
import org.polypheny.db.catalog.CatalogType.State;
import org.polypheny.db.catalog.entity.allocation.AllocationEntity;
import org.polypheny.db.catalog.refactor.CatalogType.State;
import org.polypheny.db.plan.AlgOptRule;
import org.polypheny.db.plan.AlgOptRuleCall;
import org.polypheny.db.plan.Convention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.rex.RexUtil;
import org.polypheny.db.schema.types.FilterableEntity;
import org.polypheny.db.schema.types.ProjectableFilterableEntity;
import org.polypheny.db.tools.AlgBuilderFactory;
import org.polypheny.db.util.mapping.Mapping;
import org.polypheny.db.util.mapping.Mappings;
Expand All @@ -57,12 +56,10 @@
* a {@link Filter}
* on a {@link RelScan}
* of a {@link FilterableEntity}
* or a {@link ProjectableFilterableEntity}
* to a {@link BindableScan}.
*
* The {@link #INTERPRETER} variant allows an intervening {@link EnumerableInterpreter}.
*
* @see ProjectScanRule
*/
public abstract class FilterScanRule extends AlgOptRule {

Expand Down Expand Up @@ -115,15 +112,14 @@ protected FilterScanRule( AlgOptRuleOperand operand, AlgBuilderFactory algBuilde

public static boolean test( RelScan<?> scan ) {
// We can only push filters into a FilterableTable or ProjectableFilterableTable.
return scan.entity.unwrap( FilterableEntity.class ).isPresent() || scan.entity.unwrap( ProjectableFilterableEntity.class ).isPresent();
return scan.entity.unwrap( FilterableEntity.class ).isPresent();
}


protected void apply( AlgOptRuleCall call, Filter filter, RelScan<?> scan ) {
final ImmutableList<Integer> projects;
final ImmutableList.Builder<RexNode> filters = ImmutableList.builder();
if ( scan instanceof BindableScan ) {
final BindableScan bindableScan = (BindableScan) scan;
if ( scan instanceof BindableScan bindableScan ) {
filters.addAll( bindableScan.filters );
projects = bindableScan.projects;
} else {
Expand Down
139 changes: 0 additions & 139 deletions core/src/main/java/org/polypheny/db/algebra/rules/ProjectScanRule.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.polypheny.db.catalog.refactor;
package org.polypheny.db.catalog;

public interface CatalogType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.polypheny.db.algebra.type.AlgDataTypeFactory;
import org.polypheny.db.algebra.type.DocumentType;
import org.polypheny.db.algebra.type.GraphType;
import org.polypheny.db.catalog.CatalogType;
import org.polypheny.db.catalog.logistic.DataModel;
import org.polypheny.db.catalog.logistic.EntityType;
import org.polypheny.db.catalog.refactor.CatalogType;
import org.polypheny.db.schema.Statistic;
import org.polypheny.db.schema.Statistics;
import org.polypheny.db.schema.types.Expressible;
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/org/polypheny/db/iface/QueryInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ public QueryInterfaceSettingInteger( String name, boolean canBeNull, boolean req
}


public static class QueryInterfaceSettingLong extends QueryInterfaceSetting {

public final Long defaultValue;


public QueryInterfaceSettingLong( String name, boolean canBeNull, boolean required, boolean modifiable, Long defaultValue ) {
super( name, canBeNull, required, modifiable );
this.defaultValue = defaultValue;
}

}


public static class QueryInterfaceSettingString extends QueryInterfaceSetting {

public final String defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import org.polypheny.db.rex.RexLiteral;
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.schema.types.FilterableEntity;
import org.polypheny.db.schema.types.ProjectableFilterableEntity;
import org.polypheny.db.schema.types.ScannableEntity;
import org.polypheny.db.tools.AlgBuilderFactory;
import org.polypheny.db.type.entity.PolyValue;
Expand Down Expand Up @@ -269,8 +268,7 @@ public String algCompareString() {

public static boolean canHandle( Entity entity ) {
return entity.unwrap( ScannableEntity.class ).isPresent()
|| entity.unwrap( FilterableEntity.class ).isPresent()
|| entity.unwrap( ProjectableFilterableEntity.class ).isPresent();
|| entity.unwrap( FilterableEntity.class ).isPresent();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.polypheny.db.algebra.AlgVisitor;
import org.polypheny.db.algebra.rules.CalcSplitRule;
import org.polypheny.db.algebra.rules.FilterScanRule;
import org.polypheny.db.algebra.rules.ProjectScanRule;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeFactory.Builder;
import org.polypheny.db.config.RuntimeConfig;
Expand Down Expand Up @@ -111,8 +110,6 @@ private AlgNode optimize( AlgNode rootAlg ) {
.addRuleInstance( CalcSplitRule.INSTANCE )
.addRuleInstance( FilterScanRule.INSTANCE )
.addRuleInstance( FilterScanRule.INTERPRETER )
.addRuleInstance( ProjectScanRule.INSTANCE )
.addRuleInstance( ProjectScanRule.INTERPRETER )
.build();
final HepPlanner planner = new HepPlanner( hepProgram );
planner.setRoot( rootAlg );
Expand Down
Loading

0 comments on commit 45bb497

Please sign in to comment.