From 7ec14a72f0fa219e655ce2c670ddedb386f6b091 Mon Sep 17 00:00:00 2001 From: Tobias Weber Date: Tue, 16 Jul 2024 13:11:58 +0200 Subject: [PATCH] Remove the QueryPlanBuilder and AlgProcessor --- .../java/org/polypheny/db/PolyphenyDb.java | 17 -- .../polypheny/db/processing/AlgProcessor.java | 96 ---------- .../polypheny/db/webui/QueryPlanBuilder.java | 177 ------------------ .../polypheny/db/webui/models/UIAlgNode.java | 101 ---------- 4 files changed, 391 deletions(-) delete mode 100644 dbms/src/main/java/org/polypheny/db/processing/AlgProcessor.java delete mode 100644 webui/src/main/java/org/polypheny/db/webui/QueryPlanBuilder.java delete mode 100644 webui/src/main/java/org/polypheny/db/webui/models/UIAlgNode.java diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index 88148bf8e3..8157bb3e8d 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -30,7 +30,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.List; import java.util.Optional; import java.util.TimeZone; import java.util.UUID; @@ -46,7 +45,6 @@ import org.polypheny.db.catalog.entity.LogicalAdapter.AdapterType; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.impl.PolyCatalog; -import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.cli.PolyModesConverter; import org.polypheny.db.config.Config; import org.polypheny.db.config.Config.ConfigListener; @@ -63,8 +61,6 @@ import org.polypheny.db.iface.Authenticator; import org.polypheny.db.iface.QueryInterfaceManager; import org.polypheny.db.information.StatusService; -import org.polypheny.db.languages.LanguageManager; -import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.monitoring.core.MonitoringServiceProvider; import org.polypheny.db.monitoring.information.HostInformation; import org.polypheny.db.monitoring.information.JavaInformation; @@ -75,7 +71,6 @@ import org.polypheny.db.partition.PartitionManagerFactory; import org.polypheny.db.partition.PartitionManagerFactoryImpl; import org.polypheny.db.plugins.PolyPluginManager; -import org.polypheny.db.processing.AlgProcessor; import org.polypheny.db.processing.AuthenticatorImpl; import org.polypheny.db.processing.ConstraintEnforceAttacher.ConstraintTracker; import org.polypheny.db.routing.RoutingManager; @@ -382,18 +377,6 @@ public void join( final long millis ) throws InterruptedException { PartitionManagerFactory.setAndGetInstance( new PartitionManagerFactoryImpl() ); FrequencyMap.setAndGetInstance( new FrequencyMapImpl( catalog ) ); - // temporary add sql and rel here - QueryLanguage language = new QueryLanguage( - DataModel.RELATIONAL, - "alg", - List.of( "alg", "algebra" ), - null, - AlgProcessor::new, - null, - q -> null, - c -> c ); - LanguageManager.getINSTANCE().addQueryLanguage( language ); - // Initialize index manager initializeIndexManager(); diff --git a/dbms/src/main/java/org/polypheny/db/processing/AlgProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/AlgProcessor.java deleted file mode 100644 index 124577f30f..0000000000 --- a/dbms/src/main/java/org/polypheny/db/processing/AlgProcessor.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019-2024 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.processing; - -import com.fasterxml.jackson.core.JsonProcessingException; -import java.util.List; -import org.polypheny.db.PolyImplementation; -import org.polypheny.db.algebra.AlgRoot; -import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.languages.QueryParameters; -import org.polypheny.db.nodes.ExecutableStatement; -import org.polypheny.db.nodes.Node; -import org.polypheny.db.processing.QueryContext.ParsedQueryContext; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.util.DeadlockException; -import org.polypheny.db.util.Pair; -import org.polypheny.db.webui.QueryPlanBuilder; - -public class AlgProcessor extends Processor { - - - @Override - public List parse( String query ) { - throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " does not support string representation!" ); - } - - - @Override - public Pair validate( Transaction transaction, Node parsed, boolean addDefaultValues ) { - throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " does not support validation!" ); - } - - - @Override - public AlgRoot translate( Statement statement, ParsedQueryContext context ) { - try { - return AlgRoot.of( QueryPlanBuilder.buildFromJsonAlg( statement, context.getQuery() ), Kind.SELECT ); - } catch ( JsonProcessingException e ) { - throw new GenericRuntimeException( e ); - } - } - - - @Override - public PolyImplementation prepareDdl( Statement statement, ExecutableStatement node, ParsedQueryContext context ) { - throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " AlgProcessor does not support DDLs!" ); - } - - - @Override - public void unlock( Statement statement ) { - throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " does not support DML or DDLs and should therefore not lock." ); - } - - - @Override - public void lock( Statement statement ) throws DeadlockException { - throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " does not support DML or DDLs and should therefore not lock." ); - } - - - @Override - public String getQuery( Node parsed, QueryParameters parameters ) { - return parameters.getQuery(); - } - - - @Override - public AlgDataType getParameterRowType( Node left ) { - throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " does not support getParameterRowType!" ); - } - - - @Override - public List splitStatements( String statements ) { - throw new GenericRuntimeException( "not implemented" ); - } - -} diff --git a/webui/src/main/java/org/polypheny/db/webui/QueryPlanBuilder.java b/webui/src/main/java/org/polypheny/db/webui/QueryPlanBuilder.java deleted file mode 100644 index fc1e37c0ff..0000000000 --- a/webui/src/main/java/org/polypheny/db/webui/QueryPlanBuilder.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2019-2024 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.webui; - - -import com.fasterxml.jackson.core.JsonProcessingException; -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.lang3.math.NumberUtils; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.operators.OperatorName; -import org.polypheny.db.languages.OperatorRegistry; -import org.polypheny.db.nodes.Operator; -import org.polypheny.db.rex.RexNode; -import org.polypheny.db.tools.AlgBuilder; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.webui.models.SortDirection; -import org.polypheny.db.webui.models.SortState; -import org.polypheny.db.webui.models.UIAlgNode; - - -public class QueryPlanBuilder { - - private QueryPlanBuilder() { - // This is a utility class - } - - - private static AlgBuilder createAlgBuilder( final Statement statement ) { - return AlgBuilder.create( statement ); - } - - - /** - * Build a tree using the AlgBuilder - * - * @param topNode top node from the tree from the user interface, with its children - * @param statement transaction - */ - public static AlgNode buildFromTree( final UIAlgNode topNode, final Statement statement ) { - AlgBuilder b = createAlgBuilder( statement ); - buildStep( b, topNode ); - return b.build(); - } - - - public static AlgNode buildFromJsonAlg( Statement statement, String json ) throws JsonProcessingException { - AlgBuilder b = createAlgBuilder( statement ); - return buildFromTree( HttpServer.mapper.readValue( json, UIAlgNode.class ), statement ); - } - - - /** - * Set up the{@link AlgBuilder} recursively - */ - private static AlgBuilder buildStep( AlgBuilder builder, final UIAlgNode node ) { - if ( node.children != null ) { - for ( UIAlgNode n : node.children ) { - builder = buildStep( builder, n ); - } - } - - String[] field1 = null; - String[] field2 = null; - if ( node.col1 != null ) { - field1 = node.col1.split( "\\." ); - } - if ( node.col2 != null ) { - field2 = node.col2.split( "\\." ); - } - switch ( node.type ) { - case "Scan": - return builder.relScan( node.entityName.split( "\\." ) ).as( node.entityName.split( "\\." )[1] ); - case "Join": - return builder.join( node.join, builder.call( getOperator( node.operator ), builder.field( node.inputCount, field1[0], field1[1] ), builder.field( node.inputCount, field2[0], field2[1] ) ) ); - case "Filter": - String[] field = node.field.split( "\\." ); - if ( NumberUtils.isCreatable( node.filter ) ) { - Number filter; - double dbl = Double.parseDouble( node.filter ); - filter = dbl; - if ( dbl % 1 == 0 ) { - filter = Integer.parseInt( node.filter ); - } - return builder.filter( builder.call( getOperator( node.operator ), builder.field( node.inputCount, field[0], field[1] ), builder.literal( filter ) ) ); - } else { - return builder.filter( builder.call( getOperator( node.operator ), builder.field( node.inputCount, field[0], field[1] ), builder.literal( node.filter ) ) ); - } - case "Project": - List fields = getFields( node.fields, node.inputCount, builder ); - builder.project( fields ); - return builder; - case "Aggregate": - AlgBuilder.AggCall aggregation; - String[] aggFields = node.field.split( "\\." ); - aggregation = switch ( node.aggregation ) { - case "SUM" -> builder.sum( false, node.alias, builder.field( node.inputCount, aggFields[0], aggFields[1] ) ); - case "COUNT" -> builder.count( false, node.alias, builder.field( node.inputCount, aggFields[0], aggFields[1] ) ); - case "AVG" -> builder.avg( false, node.alias, builder.field( node.inputCount, aggFields[0], aggFields[1] ) ); - case "MAX" -> builder.max( node.alias, builder.field( node.inputCount, aggFields[0], aggFields[1] ) ); - case "MIN" -> builder.min( node.alias, builder.field( node.inputCount, aggFields[0], aggFields[1] ) ); - default -> throw new IllegalArgumentException( "unknown aggregate type" ); - }; - if ( node.groupBy == null || node.groupBy.equals( "" ) ) { - return builder.aggregate( builder.groupKey(), aggregation ); - } else { - return builder.aggregate( builder.groupKey( node.groupBy ), aggregation ); - } - case "Sort": - ArrayList columns = new ArrayList<>(); - for ( SortState s : node.sortColumns ) { - String[] sortField = s.column.split( "\\." ); - if ( s.direction == SortDirection.DESC ) { - columns.add( builder.desc( builder.field( node.inputCount, sortField[0], sortField[1] ) ) ); - } else { - columns.add( builder.field( node.inputCount, sortField[0], sortField[1] ) ); - } - } - return builder.sort( columns ); - case "Union": - return builder.union( node.all, node.inputCount ); - case "Minus": - return builder.minus( node.all ); - case "Intersect": - return builder.intersect( node.all, node.inputCount ); - default: - throw new IllegalArgumentException( "PlanBuilder node of type '" + node.type + "' is not supported yet." ); - } - } - - - private static List getFields( String[] fields, int inputCount, AlgBuilder builder ) { - List nodes = new ArrayList<>(); - for ( String f : fields ) { - if ( f.isEmpty() ) { - continue; - } - String[] field = f.split( "\\." ); - nodes.add( builder.field( inputCount, field[0], field[1] ) ); - } - return nodes; - } - - - /** - * Parse an operator and return it as SqlOperator - * - * @param operator operator for a filter condition - * @return parsed operator as SqlOperator - */ - private static Operator getOperator( final String operator ) { - return switch ( operator ) { - case "=" -> OperatorRegistry.get( OperatorName.EQUALS ); - case "!=", "<>" -> OperatorRegistry.get( OperatorName.NOT_EQUALS ); - case "<" -> OperatorRegistry.get( OperatorName.LESS_THAN ); - case "<=" -> OperatorRegistry.get( OperatorName.LESS_THAN_OR_EQUAL ); - case ">" -> OperatorRegistry.get( OperatorName.GREATER_THAN ); - case ">=" -> OperatorRegistry.get( OperatorName.GREATER_THAN_OR_EQUAL ); - default -> throw new IllegalArgumentException( "Operator '" + operator + "' is not supported." ); - }; - } - -} diff --git a/webui/src/main/java/org/polypheny/db/webui/models/UIAlgNode.java b/webui/src/main/java/org/polypheny/db/webui/models/UIAlgNode.java deleted file mode 100644 index 1e831b51cd..0000000000 --- a/webui/src/main/java/org/polypheny/db/webui/models/UIAlgNode.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2019-2024 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.webui.models; - - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.core.JoinAlgType; - - -/** - * Model for a {@link AlgNode} coming from the Alg-Builder in the UI - */ -public class UIAlgNode { - - @JsonProperty("class") - public String clazz; - - /** - * ExpressionType of the AlgNode, e.g. Scan - */ - @JsonProperty - public String type; - - /** - * ExpressionType of Table, e.g. Table, View - */ - @JsonProperty - public String entityType; - - //tableScan - @JsonProperty - public String entityName; - - /** - * Children of this node in the tree - */ - @JsonProperty - public UIAlgNode[] children; - - /** - * Number of inputs of a node. - * Required by the AlgBuilder - */ - @JsonProperty - public int inputCount; - - - //join - @JsonProperty - public JoinAlgType join; - //join condition - @JsonProperty - public String operator; - @JsonProperty - public String col1; - @JsonProperty - public String col2; - - //filter - //(String operator) - @JsonProperty - public String field; - @JsonProperty - public String filter; - - //project - @JsonProperty - public String[] fields; - - //aggregate - @JsonProperty - public String groupBy; - @JsonProperty - public String aggregation; - @JsonProperty - public String alias; - //(String field) - - //sort - @JsonProperty - public SortState[] sortColumns; - - //union, minus - public boolean all; - -}