From 52040cf9da129ea6a4d1542899886ceb6c15e430 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 21 Nov 2023 23:20:03 +0100 Subject: [PATCH 01/15] fixes for cross model queries --- .../language/validate/IdentifierNamespace.java | 15 ++++++++++++++- .../org/polypheny/db/webui/crud/CatalogCrud.java | 12 +++++++----- .../polypheny/db/webui/models/AlgNodeModel.java | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java index b4f133250f..9d0a86b4e2 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java @@ -23,14 +23,17 @@ import java.util.List; import java.util.Objects; import javax.annotation.Nullable; +import org.apache.commons.lang3.NotImplementedException; import org.polypheny.db.algebra.constant.Modality; import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.sql.language.SqlCall; @@ -165,7 +168,17 @@ private SqlValidatorNamespace resolveImpl( SqlIdentifier id ) { return new EntityNamespace( validator, validator.snapshot.rel().getTables( null, Pattern.of( ns.get( 0 ) ) ).get( 0 ) ); } } else if ( ns.size() == 2 ) { - return new EntityNamespace( validator, validator.snapshot.rel().getTable( ns.get( 0 ), ns.get( 1 ) ).orElseThrow() ); + LogicalNamespace namespace = validator.snapshot.getNamespace( ns.get( 0 ) ).orElseThrow(); + LogicalEntity entity = null; + if ( namespace.namespaceType == NamespaceType.RELATIONAL ) { + entity = validator.snapshot.rel().getTable( namespace.id, ns.get( 1 ) ).orElse( null ); + } else if ( namespace.namespaceType == NamespaceType.DOCUMENT ) { + entity = validator.snapshot.doc().getCollection( namespace.id, ns.get( 1 ) ).orElse( null ); + } else if ( namespace.namespaceType == NamespaceType.GRAPH ) { + throw new NotImplementedException(); + } + + return new EntityNamespace( validator, entity ); } throw new GenericRuntimeException( "Table not found" ); } diff --git a/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java b/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java index b197b7dd5c..624ec63eb5 100644 --- a/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java @@ -222,14 +222,16 @@ public void getAssetsDefinition( Context context ) { public void getAlgebraNodes( Context context ) { Reflections reflections = new Reflections( "org.polypheny" ); Map> nodes = Map.of( - "common", new ArrayList<>(), - "relational", new ArrayList<>(), - "document", new ArrayList<>(), - "graph", new ArrayList<>() ); + //"common", new ArrayList<>(), + "relational", new ArrayList<>() + //"document", new ArrayList<>(), + /*"graph", new ArrayList<>()*/ ); reflections.getSubTypesOf( AlgNode.class ).stream() .filter( c -> c.getSimpleName().startsWith( "Logical" ) ).forEach( c -> { AlgNodeModel model = AlgNodeModel.from( c ); - nodes.get( model.getModel() ).add( model ); + if ( nodes.containsKey( model.getModel() ) ) { + nodes.get( model.getModel() ).add( model ); + } } ); context.json( nodes ); diff --git a/webui/src/main/java/org/polypheny/db/webui/models/AlgNodeModel.java b/webui/src/main/java/org/polypheny/db/webui/models/AlgNodeModel.java index 85538f20e1..e82b4c8a4f 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/AlgNodeModel.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/AlgNodeModel.java @@ -65,7 +65,7 @@ public class AlgNodeModel { public AlgNodeModel( String name ) { - this.name = name; + this.name = name.replace( "Logical", "" ).replace( "Rel", "" ); } From 0b22e1e83a358f2a7514006d9d665111976347cd Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 21 Nov 2023 23:52:48 +0100 Subject: [PATCH 02/15] removing unused classes --- .../algebra/AlgStructuredTypeFlattener.java | 15 +- .../db/algebra/core/AlgFactories.java | 4 +- .../algebra/rules/LoptSemiJoinOptimizer.java | 10 +- .../polypheny/db/algebra/rules/ScanRule.java | 5 +- .../db/prepare/AlgOptEntityImpl.java | 375 ------------------ .../db/prepare/LixToAlgTranslator.java | 5 - .../org/polypheny/db/prepare/Prepare.java | 24 +- .../db/prepare/QueryableAlgBuilder.java | 2 +- .../polypheny/db/schema/ColumnStrategy.java | 2 - .../db/schema/types/TranslatableEntity.java | 4 +- .../db/util/InitializerExpressionFactory.java | 2 - .../db/processing/AbstractQueryProcessor.java | 2 +- .../db/processing/DataMigratorImpl.java | 6 +- .../adapter/cottontail/CottontailEntity.java | 5 +- .../db/adapter/csv/CsvTranslatableTable.java | 6 +- .../adapter/excel/ExcelTranslatableTable.java | 6 +- .../adapter/file/FileTranslatableEntity.java | 7 +- .../adapter/googlesheet/GoogleSheetTable.java | 6 +- .../polypheny/db/adapter/jdbc/JdbcTable.java | 7 +- .../db/adapter/mongodb/MongoEntity.java | 4 +- .../polypheny/db/adapter/neo4j/NeoEntity.java | 4 +- .../polypheny/db/adapter/neo4j/NeoGraph.java | 4 +- .../language/validate/DelegatingScope.java | 2 +- .../language/validate/EntityNamespace.java | 3 +- .../language/validate/SqlValidatorUtil.java | 3 +- .../db/sql/sql2alg/SqlToAlgConverter.java | 43 +- 26 files changed, 63 insertions(+), 493 deletions(-) delete mode 100644 core/src/main/java/org/polypheny/db/prepare/AlgOptEntityImpl.java 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 80c34b32ba..ff8eb6f759 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java @@ -101,7 +101,6 @@ import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.nodes.Operator; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexCall; import org.polypheny.db.rex.RexCorrelVariable; @@ -173,17 +172,17 @@ public class AlgStructuredTypeFlattener implements ReflectiveVisitor { private int iRestructureInput; private AlgDataType flattenedRootType; boolean restructured; - private final ToAlgContext toAlgContext; + private final AlgOptCluster cluster; public AlgStructuredTypeFlattener( AlgBuilder algBuilder, RexBuilder rexBuilder, - ToAlgContext toAlgContext, + AlgOptCluster cluster, boolean restructure ) { this.algBuilder = algBuilder; this.rexBuilder = rexBuilder; - this.toAlgContext = toAlgContext; + this.cluster = cluster; this.restructure = restructure; } @@ -456,7 +455,7 @@ public void rewriteAlg( LogicalDocumentSort alg ) { public void rewriteAlg( LogicalDocumentScan scan ) { AlgNode alg = scan; if ( scan.entity.isPhysical() ) { - alg = scan.entity.unwrap( TranslatableEntity.class ).toAlg( toAlgContext, scan.traitSet ); + alg = scan.entity.unwrap( TranslatableEntity.class ).toAlg( cluster, scan.traitSet ); } setNewForOldAlg( scan, alg ); } @@ -489,7 +488,7 @@ public void rewriteAlg( LogicalLpgModify alg ) { public void rewriteAlg( LogicalLpgScan scan ) { AlgNode alg = scan; if ( scan.entity.isPhysical() ) { - alg = scan.entity.unwrap( TranslatableEntity.class ).toAlg( toAlgContext, scan.traitSet ); + alg = scan.entity.unwrap( TranslatableEntity.class ).toAlg( cluster, scan.traitSet ); } setNewForOldAlg( scan, alg ); } @@ -874,7 +873,7 @@ public void rewriteAlg( LogicalRelScan alg ) { rewriteGeneric( alg ); return; } - AlgNode newAlg = alg.entity.unwrap( TranslatableEntity.class ).toAlg( toAlgContext, alg.traitSet ); + AlgNode newAlg = alg.entity.unwrap( TranslatableEntity.class ).toAlg( cluster, alg.traitSet ); if ( !PolyTypeUtil.isFlat( alg.getRowType() ) ) { final List> flattenedExpList = new ArrayList<>(); flattenInputs( @@ -1058,7 +1057,7 @@ public RexNode visitCall( RexCall rexCall ) { @Override public RexNode visitSubQuery( RexSubQuery subQuery ) { subQuery = (RexSubQuery) super.visitSubQuery( subQuery ); - AlgStructuredTypeFlattener flattener = new AlgStructuredTypeFlattener( algBuilder, rexBuilder, toAlgContext, restructure ); + AlgStructuredTypeFlattener flattener = new AlgStructuredTypeFlattener( algBuilder, rexBuilder, cluster, restructure ); AlgNode alg = flattener.rewrite( subQuery.alg ); return subQuery.clone( alg ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java b/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java index c87ff03a43..d02d2db39a 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java @@ -69,7 +69,6 @@ import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.Contexts; import org.polypheny.db.rex.RexLiteral; import org.polypheny.db.rex.RexNode; @@ -572,8 +571,7 @@ public static ScanFactory expandingScanFactory( @Nonnull ScanFactory scanFactory return ( cluster, entity ) -> { final TranslatableEntity translatableTable = entity.unwrap( TranslatableEntity.class ); if ( translatableTable != null ) { - final ToAlgContext toAlgContext = () -> cluster; - return translatableTable.toAlg( toAlgContext, cluster.traitSet() ); + return translatableTable.toAlg( cluster, cluster.traitSet() ); } return scanFactory.createScan( cluster, entity ); }; diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java b/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java index 74014960a7..37e5508872 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java @@ -228,9 +228,9 @@ private SemiJoin findSemiJoinIndexByCost( LoptMultiJoin multiJoin, List factIdx, dimIdx ); - AlgNode factRel = multiJoin.getJoinFactor( factIdx ); + AlgNode factAlg = multiJoin.getJoinFactor( factIdx ); AlgNode dimRel = multiJoin.getJoinFactor( dimIdx ); - final JoinInfo joinInfo = JoinInfo.of( factRel, dimRel, semiJoinCondition ); + final JoinInfo joinInfo = JoinInfo.of( factAlg, dimRel, semiJoinCondition ); assert joinInfo.leftKeys.size() > 0; // mutable copies @@ -239,14 +239,14 @@ private SemiJoin findSemiJoinIndexByCost( LoptMultiJoin multiJoin, List // Make sure all the fact table keys originate from the same table and are simple column references final List actualLeftKeys = new ArrayList<>(); - LcsEntity factTable = validateKeys( factRel, leftKeys, rightKeys, actualLeftKeys ); + LcsEntity factTable = validateKeys( factAlg, leftKeys, rightKeys, actualLeftKeys ); if ( factTable == null ) { return null; } // Find the best index final List bestKeyOrder = new ArrayList<>(); - LcsScan tmpFactRel = (LcsScan) factTable.unwrap( TranslatableEntity.class ).toAlg( factRel::getCluster, factRel.getTraitSet() ); + LcsScan tmpFactRel = (LcsScan) factTable.unwrap( TranslatableEntity.class ).toAlg( factAlg.getCluster(), factAlg.getTraitSet() ); LcsIndexOptimizer indexOptimizer = new LcsIndexOptimizer( tmpFactRel ); FemLocalIndex bestIndex = @@ -281,7 +281,7 @@ private SemiJoin findSemiJoinIndexByCost( LoptMultiJoin multiJoin, List semiJoinCondition ); } return SemiJoin.create( - factRel, + factAlg, dimRel, semiJoinCondition, ImmutableList.copyOf( truncatedLeftKeys ), diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java index fe065fdbbe..cdf69bd7f9 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java @@ -20,7 +20,6 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.AlgFactories; import org.polypheny.db.algebra.logical.relational.LogicalRelScan; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgOptRule; import org.polypheny.db.plan.AlgOptRuleCall; import org.polypheny.db.plan.AlgTraitSet; @@ -29,7 +28,7 @@ /** - * Planner rule that converts a {@link LogicalRelScan} to the result of calling {@link TranslatableEntity#toAlg(ToAlgContext, AlgTraitSet)}. + * Planner rule that converts a {@link LogicalRelScan} to the result of calling {@link TranslatableEntity#toAlg(org.polypheny.db.plan.AlgOptCluster, AlgTraitSet)}. */ public class ScanRule extends AlgOptRule { @@ -52,7 +51,7 @@ public void onMatch( AlgOptRuleCall call ) { if ( oldAlg.getEntity().unwrap( TranslatableEntity.class ) == null ) { return; } - AlgNode newAlg = oldAlg.getEntity().unwrap( TranslatableEntity.class ).toAlg( oldAlg::getCluster, oldAlg.getTraitSet() ); + AlgNode newAlg = oldAlg.getEntity().unwrap( TranslatableEntity.class ).toAlg( oldAlg.getCluster(), oldAlg.getTraitSet() ); call.transformTo( newAlg ); } diff --git a/core/src/main/java/org/polypheny/db/prepare/AlgOptEntityImpl.java b/core/src/main/java/org/polypheny/db/prepare/AlgOptEntityImpl.java deleted file mode 100644 index 864704a9c8..0000000000 --- a/core/src/main/java/org/polypheny/db/prepare/AlgOptEntityImpl.java +++ /dev/null @@ -1,375 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.prepare; - - -import java.util.AbstractList; -import java.util.List; -import java.util.Objects; -import javax.annotation.Nullable; -import lombok.Getter; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.polypheny.db.StatisticsManager; -import org.polypheny.db.algebra.AlgCollation; -import org.polypheny.db.algebra.AlgDistribution; -import org.polypheny.db.algebra.AlgDistributionTraitDef; -import org.polypheny.db.algebra.AlgFieldCollation; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.constant.Monotonicity; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.algebra.type.AlgDataTypeFactoryImpl; -import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.algebra.type.AlgRecordType; -import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; -import org.polypheny.db.catalog.entity.allocation.AllocationPartition; -import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity; -import org.polypheny.db.plan.AlgOptSchema; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.prepare.Prepare.AbstractPreparingEntity; -import org.polypheny.db.runtime.Hook; -import org.polypheny.db.schema.ColumnStrategy; -import org.polypheny.db.schema.Entity; -import org.polypheny.db.schema.PolyphenyDbSchema; -import org.polypheny.db.schema.Schemas; -import org.polypheny.db.schema.Wrapper; -import org.polypheny.db.schema.types.FilterableEntity; -import org.polypheny.db.schema.types.ModifiableTable; -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.TranslatableEntity; -import org.polypheny.db.util.InitializerExpressionFactory; -import org.polypheny.db.util.NullInitializerExpressionFactory; -import org.polypheny.db.util.Util; - - -/** - * Implementation of {@link AlgOptEntity}. - */ -public class AlgOptEntityImpl extends AbstractPreparingEntity { - - private final transient AlgOptSchema schema; - private final AlgDataType rowType; - @Getter - @Nullable - private final Entity entity; - - @Getter - @Nullable - private final LogicalEntity catalogEntity; - - /** - * Estimate for the row count, or null. - *

- * If not null, overrides the estimate from the actual table. - */ - private final Double rowCount; - //@Getter - @Nullable - private final AllocationPartition partitionPlacement; - - - private AlgOptEntityImpl( - AlgOptSchema schema, - AlgDataType rowType, - @Nullable Entity entity, - @Nullable LogicalEntity catalogEntity, - @Nullable AllocationPartition placement, - @Nullable Double rowCount ) { - this.schema = schema; - this.rowType = Objects.requireNonNull( rowType ); - this.entity = entity; - this.partitionPlacement = placement; - this.catalogEntity = catalogEntity; - this.rowCount = rowCount; - } - - - public static AlgOptEntityImpl create( AlgOptSchema schema, AlgDataType rowType ) { - return new AlgOptEntityImpl( schema, rowType, null, null, null, null ); - } - - - public static AlgOptEntityImpl create( AlgOptSchema schema, AlgDataType rowType, LogicalEntity catalogEntity, AllocationPartition placement, Double count ) { - Double rowCount; - if ( count == null ) { - rowCount = Double.valueOf( StatisticsManager.getInstance().rowCountPerTable( catalogEntity.id ) ); - } else { - rowCount = count; - } - - return new AlgOptEntityImpl( schema, rowType, null, catalogEntity, placement, rowCount ); - } - - - /** - * Creates a copy of this RelOptTable. The new RelOptTable will have newRowType. - */ - public AlgOptEntityImpl copy( AlgDataType newRowType ) { - return new AlgOptEntityImpl( this.schema, newRowType, this.entity, this.catalogEntity, this.partitionPlacement, this.rowCount ); - } - - - public static AlgOptEntityImpl create( AlgOptSchema schema, AlgDataType rowType, Entity entity, LogicalEntity catalogEntity, AllocationPartition placement ) { - assert entity instanceof TranslatableEntity - || entity instanceof ScannableEntity - || entity instanceof ModifiableTable; - return new AlgOptEntityImpl( schema, rowType, entity, catalogEntity, placement, null ); - } - - - @Override - public T unwrap( Class clazz ) { - if ( clazz.isInstance( this ) ) { - return clazz.cast( this ); - } - if ( clazz.isInstance( entity ) ) { - return clazz.cast( entity ); - } - if ( entity instanceof Wrapper ) { - final T t = ((Wrapper) entity).unwrap( clazz ); - if ( t != null ) { - return t; - } - } - if ( clazz == PolyphenyDbSchema.class ) { - return clazz.cast( Schemas.subSchema( ((PolyphenyDbCatalogReader) schema).snapshot, List.of( Catalog.getInstance().getSnapshot().getNamespace( catalogEntity.namespaceId ).orElseThrow().name, catalogEntity.name ) ) ); - } - return null; - } - - - @Override - public Expression getExpression( Class clazz ) { - if ( partitionPlacement != null ) { - return Expressions.call( - Expressions.call( Catalog.class, "getInstance" ), - "getPartitionPlacement", - Expressions.constant( partitionPlacement.id ), - Expressions.constant( partitionPlacement.id ) ); - } else if ( catalogEntity != null ) { - return Expressions.call( - Expressions.call( Catalog.class, "getInstance" ), - "getTable", - Expressions.constant( catalogEntity.id ) ); - } - - return null; - } - - - @Override - public boolean equals( Object obj ) { - return obj instanceof AlgOptEntityImpl - && this.rowType.equals( ((AlgOptEntityImpl) obj).getRowType() ) - && this.entity == ((AlgOptEntityImpl) obj).entity; - } - - - @Override - public int hashCode() { - return (this.entity == null) ? super.hashCode() : this.entity.hashCode(); - } - - - @Override - public double getRowCount() { - if ( rowCount != null ) { - return rowCount; - } - if ( entity != null ) { - final Double rowCount = entity.getStatistic().getRowCount(); - if ( rowCount != null ) { - return rowCount; - } - } - return 100d; - } - - - @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - // Make sure rowType's list is immutable. If rowType is DynamicRecordType, creates a new RelOptTable by replacing with - // immutable RelRecordType using the same field list. - if ( this.getRowType().isDynamicStruct() ) { - final AlgDataType staticRowType = new AlgRecordType( getRowType().getFieldList() ); - final AlgOptEntity algOptEntity = this.copy( staticRowType ); - return algOptEntity.toAlg( context, traitSet ); - } - - // If there are any virtual columns, create a copy of this table without those virtual columns. - final List strategies = getColumnStrategies(); - if ( strategies.contains( ColumnStrategy.VIRTUAL ) ) { - final AlgDataTypeFactory.Builder b = context.getCluster().getTypeFactory().builder(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { - if ( strategies.get( field.getIndex() ) != ColumnStrategy.VIRTUAL ) { - b.add( null, field.getName(), null, field.getType() ); - } - } - final AlgOptEntity algOptEntity = - new AlgOptEntityImpl( this.schema, b.build(), this.entity, this.catalogEntity, this.partitionPlacement, this.rowCount ) { - @Override - public T unwrap( Class clazz ) { - if ( clazz.isAssignableFrom( InitializerExpressionFactory.class ) ) { - return clazz.cast( NullInitializerExpressionFactory.INSTANCE ); - } - return super.unwrap( clazz ); - } - }; - return algOptEntity.toAlg( context, traitSet ); - } - - if ( entity instanceof TranslatableEntity ) { - return ((TranslatableEntity) entity).toAlg( context, traitSet ); - } - final AlgOptCluster cluster = context.getCluster(); - if ( Hook.ENABLE_BINDABLE.get( false ) ) { - //return LogicalRelScan.create( cluster, this ); - } - if ( PolyphenyDbPrepareImpl.ENABLE_ENUMERABLE && entity instanceof QueryableEntity ) { - // return EnumerableScan.create( cluster, this ); - } - if ( entity instanceof ScannableEntity - || entity instanceof FilterableEntity - || entity instanceof ProjectableFilterableEntity ) { - //return LogicalRelScan.create( cluster, this ); - } - if ( PolyphenyDbPrepareImpl.ENABLE_ENUMERABLE ) { - //return EnumerableScan.create( cluster, this ); - } - throw new AssertionError(); - } - - - @Override - public AlgDistribution getDistribution() { - if ( entity != null ) { - return entity.getStatistic().getDistribution(); - } - return AlgDistributionTraitDef.INSTANCE.getDefault(); - } - - - @Override - public AlgDataType getRowType() { - return rowType; - } - - - @Override - public List getQualifiedName() { - return List.of( Catalog.getInstance().getSnapshot().getNamespace( catalogEntity.namespaceId ).orElseThrow().name, catalogEntity.name ); - } - - - @Override - public Monotonicity getMonotonicity( String columnName ) { - assert entity != null; - for ( AlgCollation collation : entity.getStatistic().getCollations() ) { - final AlgFieldCollation fieldCollation = collation.getFieldCollations().get( 0 ); - final int fieldIndex = fieldCollation.getFieldIndex(); - if ( fieldIndex < rowType.getFieldCount() && rowType.getFieldNames().get( fieldIndex ).equals( columnName ) ) { - return fieldCollation.direction.monotonicity(); - } - } - return Monotonicity.NOT_MONOTONIC; - } - - - /** - * Helper for {@link #getColumnStrategies()}. - */ - public static List columnStrategies( final LogicalEntity table ) { - final int fieldCount = table.getRowType().getFieldCount(); - final InitializerExpressionFactory ief = Util.first( - table.unwrap( InitializerExpressionFactory.class ), - NullInitializerExpressionFactory.INSTANCE ); - return new AbstractList<>() { - @Override - public int size() { - return fieldCount; - } - - - @Override - public ColumnStrategy get( int index ) { - return ief.generationStrategy( table, index ); - } - }; - } - - - /** - * Converts the ordinal of a field into the ordinal of a stored field. - * That is, it subtracts the number of virtual fields that come before it. - */ - public static int realOrdinal( final LogicalEntity table, int i ) { - List strategies = table.unwrap( LogicalTable.class ).getColumnStrategies(); - int n = 0; - for ( int j = 0; j < i; j++ ) { - switch ( strategies.get( j ) ) { - case VIRTUAL: - ++n; - } - } - return i - n; - } - - - /** - * Returns the row type of a table after any {@link ColumnStrategy#VIRTUAL} columns have been removed. This is the type - * of the records that are actually stored. - */ - public static AlgDataType realRowType( LogicalEntity table ) { - final AlgDataType rowType = table.getRowType(); - final List strategies = columnStrategies( table ); - if ( !strategies.contains( ColumnStrategy.VIRTUAL ) ) { - return rowType; - } - final AlgDataTypeFactory.Builder builder = AlgDataTypeFactoryImpl.DEFAULT.builder(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { - if ( strategies.get( field.getIndex() ) != ColumnStrategy.VIRTUAL ) { - builder.add( field ); - } - } - return builder.build(); - } - -} - diff --git a/core/src/main/java/org/polypheny/db/prepare/LixToAlgTranslator.java b/core/src/main/java/org/polypheny/db/prepare/LixToAlgTranslator.java index 16e9ee3f84..24ef019848 100644 --- a/core/src/main/java/org/polypheny/db/prepare/LixToAlgTranslator.java +++ b/core/src/main/java/org/polypheny/db/prepare/LixToAlgTranslator.java @@ -49,7 +49,6 @@ import org.polypheny.db.algebra.logical.relational.LogicalProject; import org.polypheny.db.algebra.logical.relational.LogicalRelScan; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexNode; import org.polypheny.db.util.BuiltInMethod; @@ -72,10 +71,6 @@ class LixToAlgTranslator { } - ToAlgContext toAlgContext() { - return () -> cluster; - } - public AlgNode translate( Expression expression ) { diff --git a/core/src/main/java/org/polypheny/db/prepare/Prepare.java b/core/src/main/java/org/polypheny/db/prepare/Prepare.java index 317138541e..a308129905 100644 --- a/core/src/main/java/org/polypheny/db/prepare/Prepare.java +++ b/core/src/main/java/org/polypheny/db/prepare/Prepare.java @@ -63,8 +63,6 @@ import org.polypheny.db.nodes.validate.ValidatorCatalogReader; import org.polypheny.db.nodes.validate.ValidatorTable; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgOptSchema; import org.polypheny.db.plan.AlgOptUtil; @@ -74,7 +72,6 @@ import org.polypheny.db.runtime.Bindable; import org.polypheny.db.runtime.Hook; import org.polypheny.db.runtime.Typed; -import org.polypheny.db.schema.ColumnStrategy; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.tools.Program; import org.polypheny.db.tools.Programs; @@ -154,8 +151,7 @@ protected AlgRoot optimize( AlgRoot root ) { public void visit( AlgNode node, int ordinal, AlgNode parent ) { if ( node instanceof RelScan ) { final AlgOptCluster cluster = node.getCluster(); - final ToAlgContext context = () -> cluster; - final AlgNode r = node.getEntity().unwrap( TranslatableEntity.class ).toAlg( context, node.getTraitSet() ); + final AlgNode r = node.getEntity().unwrap( TranslatableEntity.class ).toAlg( cluster, node.getTraitSet() ); planner.registerClass( r ); } super.visit( node, ordinal, parent ); @@ -259,26 +255,10 @@ public interface CatalogReader extends AlgOptSchema, ValidatorCatalogReader, Ope /** * Definition of a table, for the purposes of the validator and planner. */ - public interface PreparingEntity extends AlgOptEntity, ValidatorTable { + public interface PreparingEntity extends ValidatorTable { } - - /** - * Abstract implementation of {@link PreparingEntity}. - */ - public abstract static class AbstractPreparingEntity implements PreparingEntity { - - - @Override - public List getColumnStrategies() { - return null; - //return AlgOptEntityImpl.columnStrategies( AbstractPreparingEntity.this ); - } - - } - - /** * PreparedExplanation is a PreparedResult for an EXPLAIN PLAN statement. It's always good to have an explanation prepared. */ diff --git a/core/src/main/java/org/polypheny/db/prepare/QueryableAlgBuilder.java b/core/src/main/java/org/polypheny/db/prepare/QueryableAlgBuilder.java index 35aad22d80..21629b6070 100644 --- a/core/src/main/java/org/polypheny/db/prepare/QueryableAlgBuilder.java +++ b/core/src/main/java/org/polypheny/db/prepare/QueryableAlgBuilder.java @@ -107,7 +107,7 @@ AlgNode toAlg( Queryable queryable ) { final QueryableEntity table = tableQueryable.entity.unwrap( QueryableEntity.class ); if ( table instanceof TranslatableEntity ) { - return ((TranslatableEntity) table).toAlg( translator.toAlgContext(), translator.cluster.traitSet() ); + return ((TranslatableEntity) table).toAlg( translator.cluster, translator.cluster.traitSet() ); } else { return LogicalRelScan.create( translator.cluster, null ); } diff --git a/core/src/main/java/org/polypheny/db/schema/ColumnStrategy.java b/core/src/main/java/org/polypheny/db/schema/ColumnStrategy.java index e400aa5f4d..29c4a49da8 100644 --- a/core/src/main/java/org/polypheny/db/schema/ColumnStrategy.java +++ b/core/src/main/java/org/polypheny/db/schema/ColumnStrategy.java @@ -34,7 +34,6 @@ package org.polypheny.db.schema; -import org.polypheny.db.plan.AlgOptEntity; import org.polypheny.db.util.InitializerExpressionFactory; @@ -42,7 +41,6 @@ * Describes how a column gets populated. * * @see InitializerExpressionFactory#generationStrategy - * @see AlgOptEntity#getColumnStrategies() */ public enum ColumnStrategy { diff --git a/core/src/main/java/org/polypheny/db/schema/types/TranslatableEntity.java b/core/src/main/java/org/polypheny/db/schema/types/TranslatableEntity.java index f988fe5973..8bede58afb 100644 --- a/core/src/main/java/org/polypheny/db/schema/types/TranslatableEntity.java +++ b/core/src/main/java/org/polypheny/db/schema/types/TranslatableEntity.java @@ -17,7 +17,7 @@ package org.polypheny.db.schema.types; import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; +import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; public interface TranslatableEntity extends Typed { @@ -25,7 +25,7 @@ public interface TranslatableEntity extends Typed { /** * Converts this entity into a {@link AlgNode}. */ - AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ); + AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ); } diff --git a/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java b/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java index 98846ae181..664c0fe7cb 100644 --- a/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java +++ b/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java @@ -21,7 +21,6 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.nodes.Operator; -import org.polypheny.db.plan.AlgOptEntity; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.ColumnStrategy; @@ -37,7 +36,6 @@ public interface InitializerExpressionFactory { * @param table the table containing the column * @param iColumn the 0-based offset of the column in the table * @return generation strategy, never null - * @see AlgOptEntity#getColumnStrategies() */ ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ); 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 39cdc5c4b0..7eeeb2a7e7 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -547,7 +547,7 @@ private void flattenPlans( List plans ) { AlgStructuredTypeFlattener typeFlattener = new AlgStructuredTypeFlattener( AlgBuilder.create( statement, routedRoot.alg.getCluster() ), routedRoot.alg.getCluster().getRexBuilder(), - routedRoot.alg::getCluster, + routedRoot.alg.getCluster(), true ); plan.proposedRoutingPlan().setRoutedRoot( routedRoot.withAlg( typeFlattener.rewrite( routedRoot.alg ) ) ); } diff --git a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java index 71b1368e72..f8606f119f 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java +++ b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java @@ -117,7 +117,7 @@ public void copyGraphData( AllocationGraph to, LogicalGraph from, Transaction tr AlgStructuredTypeFlattener typeFlattener = new AlgStructuredTypeFlattener( AlgBuilder.create( statement, algRoot.alg.getCluster() ), algRoot.alg.getCluster().getRexBuilder(), - algRoot.alg::getCluster, + algRoot.alg.getCluster(), true ); algRoot = algRoot.withAlg( typeFlattener.rewrite( algRoot.alg ) ); @@ -182,7 +182,7 @@ public void copyDocData( AllocationCollection to, LogicalCollection from, Transa AlgStructuredTypeFlattener typeFlattener = new AlgStructuredTypeFlattener( AlgBuilder.create( statement, algRoot.alg.getCluster() ), algRoot.alg.getCluster().getRexBuilder(), - algRoot.alg::getCluster, + algRoot.alg.getCluster(), true ); algRoot = algRoot.withAlg( typeFlattener.rewrite( algRoot.alg ) ); @@ -518,7 +518,7 @@ private AlgRoot buildUpdateStatement( Statement statement, List asQueryable( DataContext dataContext, Snapshot sna @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - return new CottontailScan( context.getCluster(), this, traitSet, this.cottontailNamespace.getConvention() ); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { + return new CottontailScan( cluster, this, traitSet, this.cottontailNamespace.getConvention() ); } diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTranslatableTable.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTranslatableTable.java index 82b9667233..2c224355c1 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTranslatableTable.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTranslatableTable.java @@ -41,7 +41,7 @@ import org.polypheny.db.adapter.DataContext; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.catalog.entity.physical.PhysicalTable; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; +import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.type.entity.PolyValue; @@ -80,9 +80,9 @@ public Enumerator enumerator() { @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { // Request all fields. - return new CsvScan( context.getCluster(), this, this, fields ); + return new CsvScan( cluster, this, this, fields ); } diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTranslatableTable.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTranslatableTable.java index 9e72b909a7..c87e757f13 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTranslatableTable.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTranslatableTable.java @@ -25,7 +25,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.type.AlgProtoDataType; import org.polypheny.db.catalog.entity.physical.PhysicalTable; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; +import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.type.entity.PolyValue; @@ -69,8 +69,8 @@ public Enumerator enumerator() { @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - return new ExcelTableScan( this, context.getCluster(), this, fields ); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { + return new ExcelTableScan( this, cluster, this, fields ); } } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java index dce1d9b320..18eeb8ac59 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java @@ -30,7 +30,6 @@ import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; import org.polypheny.db.rex.RexNode; @@ -80,9 +79,9 @@ public FileTranslatableEntity( @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - fileSchema.getConvention().register( context.getCluster().getPlanner() ); - return new FileScan( context.getCluster(), physical, this ); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { + fileSchema.getConvention().register( cluster.getPlanner() ); + return new FileScan( cluster, physical, this ); } diff --git a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java index 9ace5494a5..edc7def136 100644 --- a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java +++ b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java @@ -30,7 +30,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgProtoDataType; import org.polypheny.db.catalog.entity.physical.PhysicalTable; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; +import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.type.entity.PolyValue; @@ -104,9 +104,9 @@ public Enumerator enumerator() { @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { // Request all fields. - return new GoogleSheetTableScanProject( context.getCluster(), this, this, fields ); + return new GoogleSheetTableScanProject( cluster, this, this, fields ); } 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 fb9c78a5a9..51e1698821 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 @@ -60,7 +60,6 @@ import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; import org.polypheny.db.rex.RexNode; @@ -176,9 +175,9 @@ public SqlNodeList getNodeList() { @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - jdbcSchema.getConvention().register( context.getCluster().getPlanner() ); - return new JdbcScan( context.getCluster(), this, jdbcSchema.getConvention() ); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { + jdbcSchema.getConvention().register( cluster.getPlanner() ); + return new JdbcScan( cluster, this, jdbcSchema.getConvention() ); } 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 63298df3de..68355b3716 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 @@ -88,7 +88,6 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; import org.polypheny.db.rex.RexNode; @@ -145,8 +144,7 @@ public String toString() { @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - final AlgOptCluster cluster = context.getCluster(); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { return new MongoScan( cluster, traitSet.replace( MongoAlg.CONVENTION ), this ); } 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 ab1aa2afbe..d97bd5c2e6 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 @@ -48,7 +48,6 @@ import org.polypheny.db.catalog.entity.physical.PhysicalGraph; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; import org.polypheny.db.rex.RexNode; @@ -78,8 +77,7 @@ protected NeoEntity( PhysicalEntity physical, List fiel @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - final AlgOptCluster cluster = context.getCluster(); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { return new NeoScan( cluster, traitSet.replace( NeoConvention.INSTANCE ), this ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java index 393e714f74..63cb156641 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java @@ -55,7 +55,6 @@ import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.functions.Functions; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; import org.polypheny.db.rex.RexNode; @@ -148,8 +147,7 @@ public Modify toModificationGraph( @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - final AlgOptCluster cluster = context.getCluster(); + public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { return new NeoLpgScan( cluster, cluster.traitSetOf( NeoConvention.INSTANCE ).replace( ModelTrait.GRAPH ), this ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java index 20b3740a35..b4ef18cbb3 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java @@ -104,7 +104,7 @@ void resolveInNamespace( SqlValidatorNamespace ns, boolean nullable, List>> entries = ((CustomColumnResolvingEntity) t).resolveColumn( rowType, validator.getTypeFactory(), names ); for ( Pair> entry : entries ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java index 4042218f2d..5c6b0c4c33 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java @@ -26,7 +26,6 @@ import org.polypheny.db.algebra.type.AlgDataTypeFactory.Builder; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.entity.LogicalEntity; -import org.polypheny.db.plan.AlgOptEntity; import org.polypheny.db.schema.Entity; import org.polypheny.db.schema.types.ExtensibleEntity; import org.polypheny.db.sql.language.SqlIdentifier; @@ -102,7 +101,7 @@ public EntityNamespace extend( SqlNodeList extendList ) { builder.addAll( SqlValidatorUtil.getExtendedColumns( validator.getTypeFactory(), getTable(), extendList ) ); final List extendedFields = builder.build(); final Entity schemaEntity = table.unwrap( Entity.class ); - if ( schemaEntity != null && table instanceof AlgOptEntity && schemaEntity instanceof ExtensibleEntity ) { + if ( schemaEntity != null && schemaEntity instanceof ExtensibleEntity ) { checkExtendedColumnTypes( extendList ); //final AlgOptEntity algOptEntity = ((AlgOptEntity) table).extend( extendedFields ); //final CatalogEntity validatorTable = algOptEntity.unwrap( ValidatorTable.class ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java index 9b8266a92b..bcaaa92e9c 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java @@ -46,7 +46,6 @@ import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; -import org.polypheny.db.plan.AlgOptEntity; import org.polypheny.db.schema.CustomColumnResolvingEntity; import org.polypheny.db.schema.Entity; import org.polypheny.db.schema.types.ExtensibleEntity; @@ -79,7 +78,7 @@ private SqlValidatorUtil() { /** - * Converts a {@link SqlValidatorScope} into a {@link AlgOptEntity}. This is only possible if the scope represents an identifier, such as "sales.emp". + * Converts a {@link SqlValidatorScope} into a {@link LogicalEntity}. This is only possible if the scope represents an identifier, such as "sales.emp". * Otherwise, returns null. * * @param namespace Namespace 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 a2f53ed677..44bc5d71fb 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 @@ -62,6 +62,7 @@ import java.util.stream.IntStream; import javax.annotation.Nonnull; import kotlin.text.Charsets; +import lombok.Getter; import org.apache.calcite.avatica.util.Spaces; import org.apache.calcite.linq4j.Ord; import org.polypheny.db.algebra.AlgCollation; @@ -145,12 +146,10 @@ import org.polypheny.db.nodes.Operator; import org.polypheny.db.nodes.validate.ValidatorTable; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgOptSamplingParameters; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; -import org.polypheny.db.prepare.AlgOptEntityImpl; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexCall; import org.polypheny.db.rex.RexCallBinding; @@ -259,8 +258,19 @@ public class SqlToAlgConverter implements NodeToAlgConverter { private static final BigDecimal TWO = BigDecimal.valueOf( 2L ); protected final SqlValidator validator; + /** + * -- GETTER -- + * Returns the row-expression builder. + */ + @Getter protected final RexBuilder rexBuilder; protected final Snapshot snapshot; + /** + * -- GETTER -- + * + * @return the RelOptCluster in use. + */ + @Getter protected final AlgOptCluster cluster; private SubQueryConverter subQueryConverter; protected final List leaves = new ArrayList<>(); @@ -308,22 +318,6 @@ public SqlToAlgConverter( SqlValidator validator, Snapshot snapshot, AlgOptClust } - /** - * @return the RelOptCluster in use. - */ - public AlgOptCluster getCluster() { - return cluster; - } - - - /** - * Returns the row-expression builder. - */ - public RexBuilder getRexBuilder() { - return rexBuilder; - } - - /** * Returns the number of dynamic parameters encountered during translation; this must only be called after {@link #convertQuery}. * @@ -446,7 +440,7 @@ public AlgNode flattenTypes( AlgNode rootAlg, boolean restructure ) { new AlgStructuredTypeFlattener( algBuilder, rexBuilder, - createToRelContext(), + cluster, restructure ); return typeFlattener.rewrite( rootAlg ); } @@ -2905,15 +2899,10 @@ private AlgNode createModify( LogicalEntity targetTable, AlgNode source ) { null, false ); } - - - private ToAlgContext createToRelContext() { - return () -> cluster; - } - + public AlgNode toAlg( final LogicalEntity table ) { - final AlgNode scan = table.unwrap( TranslatableEntity.class ).toAlg( createToRelContext(), cluster.traitSet() ); + final AlgNode scan = table.unwrap( TranslatableEntity.class ).toAlg( cluster, cluster.traitSet() ); final InitializerExpressionFactory ief = Util.first( @@ -2936,7 +2925,7 @@ public AlgNode toAlg( final LogicalEntity table ) { ++virtualCount; break; default: - list.add( rexBuilder.makeInputRef( scan, AlgOptEntityImpl.realOrdinal( table, f.getIndex() ) ) ); + list.add( rexBuilder.makeInputRef( scan, f.getIndex() ) ); } } if ( virtualCount > 0 ) { From 25c968235b7cc6c667ac366c33b5672b3d8039f0 Mon Sep 17 00:00:00 2001 From: datomo Date: Wed, 22 Nov 2023 14:48:10 +0100 Subject: [PATCH 03/15] fixed AlgDataTypeKey equals --- .../org/polypheny/db/adapter/Modifiable.java | 8 +-- .../org/polypheny/db/adapter/index/Index.java | 2 +- .../polypheny/db/algebra/AlgDecorrelator.java | 28 ++++---- .../polypheny/db/algebra/AlgFieldTrimmer.java | 4 +- .../algebra/AlgStructuredTypeFlattener.java | 28 ++++---- .../polypheny/db/algebra/core/Aggregate.java | 4 +- .../org/polypheny/db/algebra/core/Join.java | 4 +- .../polypheny/db/algebra/core/Project.java | 2 +- .../polypheny/db/algebra/core/Uncollect.java | 4 +- .../org/polypheny/db/algebra/core/Values.java | 4 +- .../org/polypheny/db/algebra/core/Window.java | 2 +- .../db/algebra/core/common/Transformer.java | 2 +- .../db/algebra/core/lpg/LpgUnwind.java | 6 +- .../db/algebra/core/relational/RelScan.java | 2 +- .../db/algebra/enumerable/EnumUtils.java | 8 +-- .../enumerable/EnumerableAggregate.java | 2 +- .../enumerable/EnumerableMergeJoin.java | 2 +- .../db/algebra/enumerable/EnumerableScan.java | 4 +- .../enumerable/EnumerableStreamer.java | 2 +- .../enumerable/EnumerableTransformer.java | 4 +- .../enumerable/EnumerableUncollect.java | 2 +- .../algebra/enumerable/EnumerableValues.java | 2 +- .../algebra/enumerable/EnumerableWindow.java | 4 +- .../db/algebra/enumerable/JavaRowFormat.java | 4 +- .../db/algebra/enumerable/PhysTypeImpl.java | 12 ++-- .../DocumentAggregateToAggregateRule.java | 2 +- .../db/algebra/externalize/AlgJson.java | 2 +- .../db/algebra/externalize/AlgJsonWriter.java | 4 +- .../db/algebra/externalize/AlgWriterImpl.java | 4 +- .../db/algebra/fun/SplittableAggFunction.java | 8 +-- .../logical/common/LogicalStreamer.java | 10 +-- .../algebra/logical/lpg/LogicalLpgScan.java | 8 +-- .../logical/relational/LogicalProject.java | 2 +- .../logical/relational/LogicalValues.java | 2 +- .../logical/relational/LogicalWindow.java | 4 +- .../algebra/metadata/AlgMdAllPredicates.java | 6 +- .../algebra/metadata/AlgMdColumnOrigins.java | 2 +- .../metadata/AlgMdDistinctRowCount.java | 2 +- .../metadata/AlgMdExpressionLineage.java | 24 +++---- .../db/algebra/metadata/AlgMdPredicates.java | 6 +- .../db/algebra/metadata/AlgMdSelectivity.java | 2 +- .../db/algebra/metadata/AlgMdSize.java | 8 +-- ...AggregateExpandDistinctAggregatesRule.java | 8 +-- .../AggregateProjectPullUpConstantsRule.java | 4 +- .../rules/AggregateReduceFunctionsRule.java | 2 +- .../db/algebra/rules/CalcAlgSplitter.java | 2 +- .../rules/FilterAggregateTransposeRule.java | 4 +- .../rules/FilterSetOpTransposeRule.java | 4 +- .../FilterTableFunctionTransposeRule.java | 4 +- .../db/algebra/rules/JoinCommuteRule.java | 4 +- .../rules/JoinProjectTransposeRule.java | 12 ++-- .../db/algebra/rules/JoinToMultiJoinRule.java | 16 ++--- .../db/algebra/rules/LoptMultiJoin.java | 4 +- .../algebra/rules/LoptOptimizeJoinRule.java | 26 ++++---- .../rules/ProjectJoinTransposeRule.java | 4 +- .../rules/ProjectWindowTransposeRule.java | 6 +- .../db/algebra/rules/PushProjector.java | 16 ++--- .../rules/SemiJoinJoinTransposeRule.java | 10 +-- .../rules/SemiJoinProjectTransposeRule.java | 2 +- .../rules/UnionPullUpConstantsRule.java | 4 +- .../db/algebra/rules/ValuesReduceRule.java | 2 +- .../db/algebra/type/AlgCrossType.java | 4 +- .../db/algebra/type/AlgDataType.java | 4 +- .../db/algebra/type/AlgDataTypeFactory.java | 2 +- .../algebra/type/AlgDataTypeFactoryImpl.java | 18 +++--- .../db/algebra/type/AlgDataTypeImpl.java | 38 +++++------ .../db/algebra/type/AlgRecordType.java | 4 +- .../db/algebra/type/DocumentType.java | 8 +-- .../algebra/type/DynamicRecordTypeImpl.java | 2 +- .../polypheny/db/algebra/type/GraphType.java | 4 +- .../polypheny/db/interpreter/Bindables.java | 2 +- .../polypheny/db/interpreter/Interpreter.java | 2 +- .../polypheny/db/interpreter/ScanNode.java | 2 +- .../org/polypheny/db/plan/AlgOptUtil.java | 64 +++++++++---------- .../db/plan/SubstitutionVisitor.java | 4 +- .../polypheny/db/plan/VisitorDataContext.java | 4 +- .../polypheny/db/prepare/JavaRecordType.java | 4 +- .../db/prepare/JavaTypeFactoryImpl.java | 8 +-- .../db/prepare/PolyphenyDbPrepareImpl.java | 2 +- .../db/processing/QueryProcessorHelpers.java | 6 +- .../java/org/polypheny/db/rex/RexBuilder.java | 8 +-- .../java/org/polypheny/db/rex/RexChecker.java | 4 +- .../org/polypheny/db/rex/RexExecutorImpl.java | 2 +- .../org/polypheny/db/rex/RexFieldAccess.java | 2 +- .../org/polypheny/db/rex/RexIndexRef.java | 2 +- .../db/rex/RexPermuteInputsShuttle.java | 2 +- .../java/org/polypheny/db/rex/RexProgram.java | 12 ++-- .../polypheny/db/rex/RexProgramBuilder.java | 14 ++-- .../org/polypheny/db/rex/RexSubQuery.java | 4 +- .../java/org/polypheny/db/rex/RexUtil.java | 8 +-- .../org/polypheny/db/tools/AlgBuilder.java | 20 +++--- .../java/org/polypheny/db/type/PathType.java | 2 +- .../db/type/PolyTypeFactoryImpl.java | 2 +- .../polypheny/db/type/PolyTypeTransforms.java | 2 +- .../org/polypheny/db/type/PolyTypeUtil.java | 26 ++++---- .../db/type/checker/OperandTypes.java | 12 ++-- .../type/checker/SetopOperandTypeChecker.java | 4 +- .../db/type/inference/InferTypes.java | 2 +- .../db/type/inference/ReturnTypes.java | 4 +- .../TableFunctionReturnTypeInference.java | 6 +- .../NullInitializerExpressionFactory.java | 2 +- .../org/polypheny/db/util/ValidatorUtil.java | 6 +- .../org/polypheny/db/view/ViewManager.java | 2 +- .../catalog/CompoundNameColumnResolver.java | 12 ++-- .../polypheny/db/catalog/CountingFactory.java | 4 +- .../db/catalog/MockCatalogReader.java | 2 +- .../org/polypheny/db/plan/RelOptUtilTest.java | 2 +- .../org/polypheny/db/ddl/DdlManagerImpl.java | 4 +- .../db/processing/AbstractQueryProcessor.java | 6 +- .../db/processing/DataMigratorImpl.java | 10 +-- .../shuttles/QueryParameterizer.java | 6 +- .../db/routing/routers/BaseRouter.java | 4 +- .../db/routing/routers/DmlRouterImpl.java | 6 +- .../org/polypheny/db/misc/AlgBuilderTest.java | 2 +- .../statistics/StatisticsManagerImpl.java | 2 +- .../org/polypheny/db/avatica/DbmsMeta.java | 4 +- .../db/avatica/PolyphenyDbSignature.java | 2 +- .../cottontail/algebra/CottontailFilter.java | 4 +- .../cottontail/algebra/CottontailProject.java | 2 +- .../algebra/CottontailTableModify.java | 2 +- .../CottontailToEnumerableConverter.java | 2 +- .../cottontail/algebra/CottontailValues.java | 4 +- .../CottontailQueryEnumerable.java | 2 +- .../polypheny/db/cql/Cql2RelConverter.java | 2 +- .../polypheny/db/cql/utils/FilterTest.java | 2 +- .../org/polypheny/db/adapter/csv/CsvScan.java | 2 +- .../db/cypher/clause/CypherReturnClause.java | 2 +- .../db/cypher/clause/CypherStarReturn.java | 2 +- .../db/cypher/clause/CypherUnwind.java | 2 +- .../cypher2alg/CypherToAlgConverter.java | 14 ++-- .../db/cypher/expression/CypherVariable.java | 6 +- .../pattern/CypherEveryPathPattern.java | 2 +- .../db/cypher/remove/CypherRemoveLabels.java | 2 +- .../cypher/remove/CypherRemoveProperty.java | 2 +- .../db/cypher/set/CypherSetProperty.java | 2 +- .../db/cypher/set/CypherSetVariable.java | 2 +- .../db/adapter/ethereum/EthereumTable.java | 2 +- .../db/adapter/excel/ExcelTableScan.java | 2 +- .../ExploreQueryProcessor.java | 2 +- .../db/adapter/file/algebra/FileProject.java | 2 +- .../db/adapter/file/algebra/FileValues.java | 2 +- .../adapter/googlesheet/GoogleSheetTable.java | 2 +- .../GoogleSheetTableScanProject.java | 2 +- .../polypheny/db/adapter/jdbc/JdbcRules.java | 2 +- .../polypheny/db/adapter/jdbc/JdbcTable.java | 2 +- .../jdbc/JdbcToEnumerableConverter.java | 4 +- .../jdbc/rel2sql/AlgToSqlConverter.java | 6 +- .../adapter/jdbc/rel2sql/SqlImplementor.java | 2 +- .../db/adapter/mongodb/MongoRowType.java | 2 +- .../mongodb/bson/BsonFunctionHelper.java | 2 +- .../db/adapter/mongodb/rules/MongoFilter.java | 4 +- .../db/adapter/mongodb/rules/MongoRules.java | 2 +- .../db/adapter/mongodb/rules/MongoScan.java | 2 +- .../db/adapter/mongodb/rules/MongoSort.java | 2 +- .../mongodb/rules/MongoTableModify.java | 4 +- .../adapter/mongodb/util/MongoTupleType.java | 2 +- .../languages/mql2alg/MqlToAlgConverter.java | 6 +- .../polypheny/db/adapter/neo4j/NeoEntity.java | 6 +- .../db/adapter/neo4j/NeoGraphImplementor.java | 4 +- .../neo4j/NeoRelationalImplementor.java | 10 +-- .../neo4j/NeoToEnumerableConverter.java | 2 +- .../neo4j/rules/graph/NeoLpgAggregate.java | 2 +- .../adapter/neo4j/rules/graph/NeoLpgScan.java | 4 +- .../neo4j/rules/relational/NeoScan.java | 2 +- .../neo4j/rules/relational/NeoValues.java | 2 +- .../db/adapter/neo4j/util/Translator.java | 4 +- .../java/org/polypheny/db/piglet/Handler.java | 4 +- .../java/org/polypheny/db/restapi/Rest.java | 6 +- .../org/polypheny/db/restapi/RestResult.java | 2 +- .../db/sql/language/SqlUnnestOperator.java | 4 +- .../db/sql/language/fun/SqlInOperator.java | 2 +- .../sql/language/fun/SqlOverlapsOperator.java | 4 +- .../sql/language/validate/AliasNamespace.java | 8 +-- .../language/validate/DelegatingScope.java | 10 +-- .../language/validate/EntityNamespace.java | 4 +- .../validate/IdentifierNamespace.java | 2 +- .../language/validate/SqlValidatorImpl.java | 38 +++++------ .../language/validate/SqlValidatorUtil.java | 4 +- .../language/validate/WithItemNamespace.java | 6 +- .../db/sql/sql2alg/SqlToAlgConverter.java | 30 ++++----- .../sql/sql2alg/StandardConvertletTable.java | 6 +- .../db/sql/language/SqlToAlgTestBase.java | 2 +- .../sql/language/utils/AbstractSqlTester.java | 4 +- .../java/org/polypheny/db/webui/Crud.java | 8 +-- .../polypheny/db/webui/crud/LanguageCrud.java | 6 +- 185 files changed, 536 insertions(+), 536 deletions(-) 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 4b7e0337a6..69134b8b62 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java @@ -78,7 +78,7 @@ static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provi List inputs = new ArrayList<>(); List sequence = new ArrayList<>(); - for ( AlgDataTypeField field : project.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : project.getRowType().getFields() ) { sequence.add( field.getType().getPolyType() ); if ( field.getType().getPolyType() == PolyType.EDGE ) { inputs.addAll( attachPreparedGraphEdgeModifyDelete( modifiable, alg.getCluster(), edgesTable, edgePropertiesTable, builder ) ); @@ -101,7 +101,7 @@ static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provi List inputs = new ArrayList<>(); List sequence = new ArrayList<>(); - for ( AlgDataTypeField field : project.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : project.getRowType().getFields() ) { sequence.add( field.getType().getPolyType() ); if ( field.getType().getPolyType() == PolyType.EDGE ) { inputs.addAll( attachPreparedGraphEdgeModifyDelete( modifiable, alg.getCluster(), edgesTable, edgePropertiesTable, algBuilder ) ); @@ -150,7 +150,7 @@ static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode pro List inputs = new ArrayList<>(); List sequence = new ArrayList<>(); - for ( AlgDataTypeField field : provider.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : provider.getRowType().getFields() ) { sequence.add( field.getType().getPolyType() ); if ( field.getType().getPolyType() == PolyType.EDGE ) { inputs.addAll( attachPreparedGraphEdgeModifyInsert( modifiable, alg.getCluster(), edgesTable, edgePropertiesTable, algBuilder ) ); @@ -363,7 +363,7 @@ static AlgNode getDocModifySubstitute( Modifiable modifiable, long allocId, Docu static Pair, List> replaceUpdates( Pair, List> updates, AlgBuilder builder ) { builder.documentProject( Pair.zip( updates.left, updates.right ).stream().collect( Collectors.toMap( e -> null, e -> e.right ) ), List.of() ); - return Pair.of( updates.left, updates.right.stream().map( u -> new RexDynamicParam( DocumentType.asRelational().getFieldList().get( 1 ).getType(), 1 ) ).collect( Collectors.toList() ) ); + return Pair.of( updates.left, updates.right.stream().map( u -> new RexDynamicParam( DocumentType.asRelational().getFields().get( 1 ).getType(), 1 ) ).collect( Collectors.toList() ) ); } static Pair, List> getRelationalDocumentModify( DocumentModify modify ) { diff --git a/core/src/main/java/org/polypheny/db/adapter/index/Index.java b/core/src/main/java/org/polypheny/db/adapter/index/Index.java index 22a960a0fc..0b1808f864 100644 --- a/core/src/main/java/org/polypheny/db/adapter/index/Index.java +++ b/core/src/main/java/org/polypheny/db/adapter/index/Index.java @@ -261,7 +261,7 @@ protected ImmutableList makeRexRow( final AlgDataType rowType, final assert rowType.getFieldCount() == tuple.size(); List row = new ArrayList<>( tuple.size() ); for ( int i = 0; i < tuple.size(); ++i ) { - final AlgDataType type = rowType.getFieldList().get( i ).getType(); + final AlgDataType type = rowType.getFields().get( i ).getType(); final Pair converted = RexLiteral.convertType( tuple.get( i ), type ); row.add( new RexLiteral( converted.left, type, converted.right ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgDecorrelator.java b/core/src/main/java/org/polypheny/db/algebra/AlgDecorrelator.java index ee4580342b..c0c9556a47 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgDecorrelator.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgDecorrelator.java @@ -456,7 +456,7 @@ public Frame decorrelateAlg( LogicalAggregate alg ) { // Project projects the original expressions, plus any correlated variables the input wants to pass along. final List> projects = new ArrayList<>(); - List newInputOutput = newInput.getRowType().getFieldList(); + List newInputOutput = newInput.getRowType().getFields(); int newPos = 0; @@ -620,7 +620,7 @@ public Frame decorrelateAlg( LogicalProject alg ) { return null; } final List oldProjects = alg.getProjects(); - final List algOutput = alg.getRowType().getFieldList(); + final List algOutput = alg.getRowType().getFields(); // Project projects the original expressions, plus any correlated variables the input wants to pass along. final List> projects = new ArrayList<>(); @@ -645,7 +645,7 @@ public Frame decorrelateAlg( LogicalProject alg ) { // Project any correlated variables the input wants to pass along. final SortedMap corDefOutputs = new TreeMap<>(); for ( Map.Entry entry : frame.corDefOutputs.entrySet() ) { - projects.add( RexIndexRef.of2( entry.getValue(), frame.r.getRowType().getFieldList() ) ); + projects.add( RexIndexRef.of2( entry.getValue(), frame.r.getRowType().getFields() ) ); corDefOutputs.put( entry.getKey(), newPos ); newPos++; } @@ -1013,10 +1013,10 @@ public Frame decorrelateAlg( LogicalCorrelate alg ) { // Join all the correlated variables produced by this correlator alg with the values generated and propagated from the right input final SortedMap corDefOutputs = new TreeMap<>( rightFrame.corDefOutputs ); final List conditions = new ArrayList<>(); - final List newLeftOutput = leftFrame.r.getRowType().getFieldList(); + final List newLeftOutput = leftFrame.r.getRowType().getFields(); int newLeftFieldCount = newLeftOutput.size(); - final List newRightOutput = rightFrame.r.getRowType().getFieldList(); + final List newRightOutput = rightFrame.r.getRowType().getFields(); for ( Map.Entry rightOutput : new ArrayList<>( corDefOutputs.entrySet() ) ) { final CorDef corDef = rightOutput.getKey(); @@ -1166,7 +1166,7 @@ private static RexIndexRef getNewForOldInputRef( AlgNode currentRel, Map> newProjExprs = new ArrayList<>(); // project everything from the LHS and then those from the original projRel - List leftInputFields = left.getRowType().getFieldList(); + List leftInputFields = left.getRowType().getFields(); for ( int i = 0; i < leftInputFields.size(); i++ ) { newProjExprs.add( RexIndexRef.of2( i, leftInputFields ) ); @@ -1236,7 +1236,7 @@ private AlgNode aggregateCorrelatorOutput( Correlate correlate, LogicalProject p final List> newProjects = new ArrayList<>(); // Project everything from the LHS and then those from the original project - final List leftInputFields = left.getRowType().getFieldList(); + final List leftInputFields = left.getRowType().getFields(); for ( int i = 0; i < leftInputFields.size(); i++ ) { newProjects.add( RexIndexRef.of2( i, leftInputFields ) ); @@ -1327,7 +1327,7 @@ private void removeCorVarFromTree( LogicalCorrelate correlate ) { * @return the new Project */ private AlgNode createProjectWithAdditionalExprs( AlgNode input, List> additionalExprs ) { - final List fieldList = input.getRowType().getFieldList(); + final List fieldList = input.getRowType().getFields(); List> projects = new ArrayList<>(); for ( Ord field : Ord.zip( fieldList ) ) { projects.add( @@ -1412,7 +1412,7 @@ public RexNode visitFieldAccess( RexFieldAccess fieldAccess ) { Integer newInputPos = frame.corDefOutputs.get( corRef.def() ); if ( newInputPos != null ) { // This input does produce the corVar referenced. - return new RexIndexRef( newInputPos + newInputOutputOffset, frame.r.getRowType().getFieldList().get( newInputPos ).getType() ); + return new RexIndexRef( newInputPos + newInputOutputOffset, frame.r.getRowType().getFields().get( newInputPos ).getType() ); } } @@ -2078,7 +2078,7 @@ public void onMatch( AlgOptRuleCall call ) { new RexIndexRef( nullIndicatorPos, cluster.getTypeFactory() - .createTypeWithNullability( join.getRowType().getFieldList().get( nullIndicatorPos ).getType(), true ) ); + .createTypeWithNullability( join.getRowType().getFields().get( nullIndicatorPos ).getType(), true ) ); // first project all group-by keys plus the transformed agg input List joinOutputProjects = new ArrayList<>(); @@ -2087,7 +2087,7 @@ public void onMatch( AlgOptRuleCall call ) { for ( int i = 0; i < leftInputFieldCount; i++ ) { joinOutputProjects.add( rexBuilder.makeInputRef( - leftInputFieldType.getFieldList().get( i ).getType(), i ) ); + leftInputFieldType.getFields().get( i ).getType(), i ) ); } for ( RexNode aggInputProjExpr : aggInputProjects ) { @@ -2198,7 +2198,7 @@ public void onMatch( AlgOptRuleCall call ) { // Create identity projection final List> projects = new ArrayList<>(); - final List fields = aggregate.getRowType().getFieldList(); + final List fields = aggregate.getRowType().getFields(); for ( int i = 0; i < fields.size(); i++ ) { projects.add( RexIndexRef.of2( projects.size(), fields ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgFieldTrimmer.java b/core/src/main/java/org/polypheny/db/algebra/AlgFieldTrimmer.java index f0a73f4e2f..5a784b3f9d 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgFieldTrimmer.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgFieldTrimmer.java @@ -218,7 +218,7 @@ protected TrimResult trimChildRestore( AlgNode alg, AlgNode input, ImmutableBitS return trimResult; } final AlgDataType rowType = input.getRowType(); - List fieldList = rowType.getFieldList(); + List fieldList = rowType.getFields(); final List exprList = new ArrayList<>(); final List nameList = rowType.getFieldNames(); RexBuilder rexBuilder = alg.getCluster().getRexBuilder(); @@ -275,7 +275,7 @@ protected RexNode handle( RexFieldAccess fieldAccess ) { final int new_ = mapping.getTarget( old ); final AlgDataTypeFactory.Builder typeBuilder = algBuilder.getTypeFactory().builder(); for ( int target : Util.range( mapping.getTargetCount() ) ) { - typeBuilder.add( v.getType().getFieldList().get( mapping.getSource( target ) ) ); + typeBuilder.add( v.getType().getFields().get( mapping.getSource( target ) ) ); } final RexNode newV = rexBuilder.makeCorrel( typeBuilder.build(), v.id ); if ( old != new_ ) { 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 ff8eb6f759..74b9af4cf3 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgStructuredTypeFlattener.java @@ -237,7 +237,7 @@ public AlgNode rewrite( AlgNode root ) { private List restructureFields( AlgDataType structuredType ) { final List structuringExps = new ArrayList<>(); - for ( AlgDataTypeField field : structuredType.getFieldList() ) { + for ( AlgDataTypeField field : structuredType.getFields() ) { // TODO: row if ( field.getType().getPolyType() == PolyType.STRUCTURED ) { restructured = true; @@ -253,7 +253,7 @@ private List restructureFields( AlgDataType structuredType ) { private RexNode restructure( AlgDataType structuredType ) { // Access null indicator for entire structure. - RexIndexRef nullIndicator = RexIndexRef.of( iRestructureInput++, flattenedRootType.getFieldList() ); + RexIndexRef nullIndicator = RexIndexRef.of( iRestructureInput++, flattenedRootType.getFields() ); // Use NEW to put flattened data back together into a structure. List inputExprs = restructureFields( structuredType ); @@ -332,7 +332,7 @@ protected Ord getNewFieldForOldInput( int oldOrdinal ) { AlgDataType oldInputType = oldInput.getRowType(); final int newOffset = calculateFlattenedOffset( oldInputType, oldOrdinal ); newOrdinal += newOffset; - final AlgDataTypeField field = newInput.getRowType().getFieldList().get( newOffset ); + final AlgDataTypeField field = newInput.getRowType().getFields().get( newOffset ); return Ord.of( newOrdinal, field.getType() ); } @@ -358,7 +358,7 @@ private int calculateFlattenedOffset( AlgDataType rowType, int ordinal ) { // skip null indicator ++offset; } - List oldFields = rowType.getFieldList(); + List oldFields = rowType.getFields(); for ( int i = 0; i < ordinal; ++i ) { AlgDataType oldFieldType = oldFields.get( i ).getType(); if ( oldFieldType.isStruct() ) { @@ -368,7 +368,7 @@ private int calculateFlattenedOffset( AlgDataType rowType, int ordinal ) { rexBuilder.getTypeFactory(), oldFieldType, null ); - final List fields = flattened.getFieldList(); + final List fields = flattened.getFields(); offset += fields.size(); } else { ++offset; @@ -547,7 +547,7 @@ public void rewriteAlg( LogicalRelModify alg ) { @SuppressWarnings("unused") public void rewriteAlg( LogicalAggregate alg ) { AlgDataType inputType = alg.getInput().getRowType(); - for ( AlgDataTypeField field : inputType.getFieldList() ) { + for ( AlgDataTypeField field : inputType.getFields() ) { if ( field.getType().isStruct() ) { // TODO jvs 10-Feb-2005 throw Util.needToImplement( "aggregation on structured types" ); @@ -568,7 +568,7 @@ public void rewriteAlg( Sort alg ) { // validate for ( AlgFieldCollation field : oldCollation.getFieldCollations() ) { int oldInput = field.getFieldIndex(); - AlgDataType sortFieldType = oldChild.getRowType().getFieldList().get( oldInput ).getType(); + AlgDataType sortFieldType = oldChild.getRowType().getFields().get( oldInput ).getType(); if ( sortFieldType.isStruct() ) { // TODO jvs 10-Feb-2005 throw Util.needToImplement( "sorting on structured types" ); @@ -608,7 +608,7 @@ public void rewriteAlg( LogicalJoin alg ) { public void rewriteAlg( LogicalCorrelate alg ) { Builder newPos = ImmutableBitSet.builder(); for ( int pos : alg.getRequiredColumns() ) { - AlgDataType corrFieldType = alg.getLeft().getRowType().getFieldList().get( pos ).getType(); + AlgDataType corrFieldType = alg.getLeft().getRowType().getFields().get( pos ).getType(); if ( corrFieldType.isStruct() ) { throw Util.needToImplement( "correlation on structured type" ); } @@ -792,7 +792,7 @@ private void flattenProjection( RewriteRexShuttle shuttle, RexNode exp, String f // Expand to range AlgDataType flattenedType = PolyTypeUtil.flattenRecordType( rexBuilder.getTypeFactory(), exp.getType(), null ); - List fieldList = flattenedType.getFieldList(); + List fieldList = flattenedType.getFields(); int n = fieldList.size(); for ( int j = 0; j < n; ++j ) { final Ord newField = getNewFieldForOldInput( inputRef.getIndex() ); @@ -831,7 +831,7 @@ private void flattenProjection( RewriteRexShuttle shuttle, RexNode exp, String f ((RexCall) exp).getOperator(), ImmutableList.of( rexBuilder.makeInputRef( newField.e, newField.i ), oldOperands.get( 1 ) ) ); } - for ( AlgDataTypeField field : newExp.getType().getFieldList() ) { + for ( AlgDataTypeField field : newExp.getType().getFields() ) { flattenedExps.add( Pair.of( rexBuilder.makeFieldAccess( newExp, field.getIndex() ), @@ -848,7 +848,7 @@ private void flattenProjection( RewriteRexShuttle shuttle, RexNode exp, String f private void flattenNullLiteral( AlgDataType type, List> flattenedExps ) { AlgDataType flattenedType = PolyTypeUtil.flattenRecordType( rexBuilder.getTypeFactory(), type, null ); - for ( AlgDataTypeField field : flattenedType.getFieldList() ) { + for ( AlgDataTypeField field : flattenedType.getFields() ) { flattenedExps.add( Pair.of( rexBuilder.makeCast( field.getType(), rexBuilder.constantNull() ), @@ -877,7 +877,7 @@ public void rewriteAlg( LogicalRelScan alg ) { if ( !PolyTypeUtil.isFlat( alg.getRowType() ) ) { final List> flattenedExpList = new ArrayList<>(); flattenInputs( - alg.getRowType().getFieldList(), + alg.getRowType().getFields(), rexBuilder.makeRangeReference( newAlg ), flattenedExpList ); newAlg = algBuilder.push( newAlg ) @@ -913,7 +913,7 @@ private void flattenInputs( List fieldList, RexNode prefix, Li for ( AlgDataTypeField field : fieldList ) { final RexNode ref = rexBuilder.makeFieldAccess( prefix, field.getIndex() ); if ( field.getType().isStruct() ) { - flattenInputs( field.getType().getFieldList(), ref, flattenedExpList ); + flattenInputs( field.getType().getFields(), ref, flattenedExpList ); } else { flattenedExpList.add( Pair.of( ref, field.getName() ) ); } @@ -989,7 +989,7 @@ private AlgDataType removeDistinct( AlgDataType type ) { if ( type.getPolyType() != PolyType.DISTINCT ) { return type; } - return type.getFieldList().get( 0 ).getType(); + return type.getFields().get( 0 ).getType(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Aggregate.java b/core/src/main/java/org/polypheny/db/algebra/core/Aggregate.java index f0aae36d58..048e9f36cb 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Aggregate.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Aggregate.java @@ -163,7 +163,7 @@ public static boolean noIndicator( Aggregate aggregate ) { private boolean isPredicate( AlgNode input, int index ) { - final AlgDataType type = input.getRowType().getFieldList().get( index ).getType(); + final AlgDataType type = input.getRowType().getFields().get( index ).getType(); return type.getPolyType() == PolyType.BOOLEAN && !type.isNullable(); } @@ -327,7 +327,7 @@ public static AlgDataType deriveRowType( AlgDataTypeFactory typeFactory, final A final List groupList = groupSet.asList(); assert groupList.size() == groupSet.cardinality(); final AlgDataTypeFactory.Builder builder = typeFactory.builder(); - final List fieldList = inputRowType.getFieldList(); + final List fieldList = inputRowType.getFields(); final Set containedNames = new HashSet<>(); for ( int groupKey : groupList ) { final AlgDataTypeField field = fieldList.get( groupKey ); diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Join.java b/core/src/main/java/org/polypheny/db/algebra/core/Join.java index 4db2fcf274..5c51aff5d9 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Join.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Join.java @@ -141,8 +141,8 @@ public boolean isValid( Litmus litmus, Context context ) { new RexChecker( getCluster().getTypeFactory().builder() .addAll( getSystemFieldList() ) - .addAll( getLeft().getRowType().getFieldList() ) - .addAll( getRight().getRowType().getFieldList() ) + .addAll( getLeft().getRowType().getFields() ) + .addAll( getRight().getRowType().getFields() ) .build(), context, litmus ); condition.accept( checker ); diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Project.java b/core/src/main/java/org/polypheny/db/algebra/core/Project.java index 76995cfe93..5763dd9262 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Project.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Project.java @@ -200,7 +200,7 @@ public AlgWriter explainTerms( AlgWriter pw ) { pw.item( "fields", rowType.getFieldNames() ); pw.item( "exprs", exps ); } else { - for ( Ord field : Ord.zip( rowType.getFieldList() ) ) { + for ( Ord field : Ord.zip( rowType.getFields() ) ) { String fieldName = field.e.getName(); if ( fieldName == null ) { fieldName = "field#" + field.i; diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Uncollect.java b/core/src/main/java/org/polypheny/db/algebra/core/Uncollect.java index b63388d8e4..b79144efab 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Uncollect.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Uncollect.java @@ -137,7 +137,7 @@ protected AlgDataType deriveRowType() { public static AlgDataType deriveUncollectRowType( AlgNode alg, boolean withOrdinality ) { AlgDataType inputType = alg.getRowType(); assert inputType.isStruct() : inputType + " is not a struct"; - final List fields = inputType.getFieldList(); + final List fields = inputType.getFields(); final AlgDataTypeFactory typeFactory = alg.getCluster().getTypeFactory(); final AlgDataTypeFactory.Builder builder = typeFactory.builder(); @@ -157,7 +157,7 @@ public static AlgDataType deriveUncollectRowType( AlgNode alg, boolean withOrdin AlgDataType ret = field.getType().getComponentType(); assert null != ret; if ( ret.isStruct() ) { - builder.addAll( ret.getFieldList() ); + builder.addAll( ret.getFields() ); } else { // Element type is not a record. It may be a scalar type, say "INTEGER". Wrap it in a struct type. builder.add( null, CoreUtil.deriveAliasFromOrdinal( field.getIndex() ), null, ret ); diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Values.java b/core/src/main/java/org/polypheny/db/algebra/core/Values.java index 7f0c27e064..c036ff9a57 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Values.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Values.java @@ -119,7 +119,7 @@ public ImmutableList> getTuples() { private boolean assertRowType() { for ( List tuple : tuples ) { assert tuple.size() == rowType.getFieldCount(); - for ( Pair pair : Pair.zip( tuple, rowType.getFieldList() ) ) { + for ( Pair pair : Pair.zip( tuple, rowType.getFields() ) ) { RexLiteral literal = pair.left; AlgDataType fieldType = pair.right.getType(); @@ -164,7 +164,7 @@ public AlgWriter explainTerms( AlgWriter pw ) { AlgWriter algWriter = super.explainTerms( pw ) // For alg digest, include the row type since a rendered literal may leave the type ambiguous (e.g. "null"). .itemIf( "type", rowType, pw.getDetailLevel() == ExplainLevel.DIGEST_ATTRIBUTES ) - .itemIf( "type", rowType.getFieldList(), pw.nest() ); + .itemIf( "type", rowType.getFields(), pw.nest() ); if ( pw.nest() ) { pw.item( "tuples", tuples ); } else { diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Window.java b/core/src/main/java/org/polypheny/db/algebra/core/Window.java index 2dcfb12589..f915f1076e 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Window.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Window.java @@ -115,7 +115,7 @@ public boolean isValid( Litmus litmus, Context context ) { @Override public AlgDataType get( int index ) { return index < childFieldCount - ? childRowType.getFieldList().get( index ).getType() + ? childRowType.getFields().get( index ).getType() : constants.get( index - childFieldCount ).getType(); } 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 57b3f0ead7..6b37cd3f17 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 @@ -61,7 +61,7 @@ public Transformer( AlgOptCluster cluster, List inputs, @Nullable List< // todo dl: remove after RowType refactor LogicalProject lp = LogicalProject.create( inputs.get( 0 ), - List.of( cluster.getRexBuilder().makeInputRef( inputs.get( 0 ).getRowType().getFieldList().get( 0 ).getType(), 1 ) ), + List.of( cluster.getRexBuilder().makeInputRef( inputs.get( 0 ).getRowType().getFields().get( 0 ).getType(), 1 ) ), List.of( "d" ) ); this.inputs = List.of( lp ); } else { diff --git a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgUnwind.java b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgUnwind.java index cf8b837b08..4e9629c7c1 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgUnwind.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgUnwind.java @@ -60,10 +60,10 @@ protected LpgUnwind( AlgOptCluster cluster, AlgTraitSet traits, AlgNode input, i private static AlgNode adjustInputIfNecessary( AlgNode input, int index ) { - if ( input.getRowType().getFieldList().get( index ).getType().getPolyType() == PolyType.ARRAY ) { + if ( input.getRowType().getFields().get( index ).getType().getPolyType() == PolyType.ARRAY ) { return input; } - AlgDataTypeField field = input.getRowType().getFieldList().get( index ); + AlgDataTypeField field = input.getRowType().getFields().get( index ); RexNode ref = input.getCluster().getRexBuilder().makeInputRef( field.getType(), field.getIndex() ); // we wrap the field in a to-list operation, which wraps single values as list, leaves lists and replaces null with an empty list AlgDataType arrayType = input.getCluster().getTypeFactory().createArrayType( ref.getType(), -1 ); @@ -84,7 +84,7 @@ public String algCompareString() { @Override protected AlgDataType deriveRowType() { List fields = new ArrayList<>(); - fields.add( new AlgDataTypeFieldImpl( -1L, alias, 0, input.getRowType().getFieldList().get( index ).getType().getComponentType() ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, alias, 0, input.getRowType().getFields().get( index ).getType().getComponentType() ) ); return new AlgRecordType( fields ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java index a11cab2439..605928477e 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java @@ -129,7 +129,7 @@ public AlgNode project( ImmutableBitSet fieldsUsed, Set extraF final List exprList = new ArrayList<>(); final List nameList = new ArrayList<>(); final RexBuilder rexBuilder = getCluster().getRexBuilder(); - final List fields = getRowType().getFieldList(); + final List fields = getRowType().getFields(); // Project the subset of fields. for ( int i : fieldsUsed ) { diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java index 73bdccf5b6..b5d69e405c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumUtils.java @@ -99,7 +99,7 @@ static Type javaClass( JavaTypeFactory typeFactory, AlgDataType type ) { public static Class javaRowClass( JavaTypeFactory typeFactory, AlgDataType type ) { if ( type.isStruct() && type.getFieldCount() == 1 && !PolyType.GRAPH_TYPES.contains( type.getPolyType() ) ) { - type = type.getFieldList().get( 0 ).getType(); + type = type.getFields().get( 0 ).getType(); } final Type clazz = typeFactory.getJavaClass( type ); return clazz instanceof Class ? (Class) clazz : PolyValue[].class; @@ -123,7 +123,7 @@ public int size() { static List fieldRowTypes( final AlgDataType inputRowType, final List extraInputs, final List argList ) { - final List inputFields = inputRowType.getFieldList(); + final List inputFields = inputRowType.getFields(); return new AbstractList<>() { @Override public AlgDataType get( int index ) { @@ -438,8 +438,8 @@ static Expression generatePredicate( final ParameterExpression right_ = Expressions.parameter( rightPhysType.getJavaRowType(), "right" ); final RexProgramBuilder program = new RexProgramBuilder( implementor.getTypeFactory().builder() - .addAll( left.getRowType().getFieldList() ) - .addAll( right.getRowType().getFieldList() ) + .addAll( left.getRowType().getFields() ) + .addAll( right.getRowType().getFields() ) .build(), rexBuilder ); program.addCondition( condition ); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableAggregate.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableAggregate.java index 71cb048368..30ebdfbb9a 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableAggregate.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableAggregate.java @@ -241,7 +241,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { new AggAddContextImpl( builder2, accumulator ) { @Override public List rexArguments() { - List inputTypes = inputPhysType.getRowType().getFieldList(); + List inputTypes = inputPhysType.getRowType().getFields(); List args = new ArrayList<>(); for ( int index : agg.call.getArgList() ) { args.add( RexIndexRef.of( index, inputTypes ) ); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableMergeJoin.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableMergeJoin.java index 39d10d653d..797756e471 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableMergeJoin.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableMergeJoin.java @@ -114,7 +114,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { final List leftExpressions = new ArrayList<>(); final List rightExpressions = new ArrayList<>(); for ( Pair pair : Pair.zip( leftKeys, rightKeys ) ) { - final AlgDataType keyType = typeFactory.leastRestrictive( ImmutableList.of( left.getRowType().getFieldList().get( pair.left ).getType(), right.getRowType().getFieldList().get( pair.right ).getType() ) ); + final AlgDataType keyType = typeFactory.leastRestrictive( ImmutableList.of( left.getRowType().getFields().get( pair.left ).getType(), right.getRowType().getFields().get( pair.right ).getType() ) ); final Type keyClass = typeFactory.getJavaClass( keyType ); leftExpressions.add( Types.castIfNecessary( keyClass, leftResult.physType.fieldReference( left_, pair.left ) ) ); rightExpressions.add( Types.castIfNecessary( keyClass, rightResult.physType.fieldReference( right_, pair.right ) ) ); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java index 914ea649e1..a66abebddd 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java @@ -184,7 +184,7 @@ && getRowType().getFieldCount() == 1 private Expression fieldExpression( ParameterExpression row_, int i, PhysType physType, JavaRowFormat format ) { final Expression e = format.field( row_, i, null, physType.getJavaFieldType( i ) ); - final AlgDataType algFieldType = physType.getRowType().getFieldList().get( i ).getType(); + final AlgDataType algFieldType = physType.getRowType().getFields().get( i ).getType(); switch ( algFieldType.getPolyType() ) { case ARRAY: case MULTISET: @@ -223,7 +223,7 @@ private JavaRowFormat format() { private boolean hasCollectionField( AlgDataType rowType ) { - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { switch ( field.getType().getPolyType() ) { case ARRAY: case MULTISET: diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableStreamer.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableStreamer.java index d0076538ad..9c76129eb2 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableStreamer.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableStreamer.java @@ -91,7 +91,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { Expressions.constant( DataContext.ROOT ), builder.append( builder.newName( "query" + System.nanoTime() ), query.block ), exp, - Expressions.constant( getLeft().getRowType().getFieldList().stream().map( f -> f.getType().getPolyType() ).collect( Collectors.toList() ) ) ); + Expressions.constant( getLeft().getRowType().getFields().stream().map( f -> f.getType().getPolyType() ).collect( Collectors.toList() ) ) ); builder.add( Expressions.return_( null, builder.append( "test", transformContext ) ) ); 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 4d772b1eb2..7127b5181f 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 @@ -341,7 +341,7 @@ private Result implementDocumentOnRelational( EnumerableAlgImplementor implement private static void attachDocOnRelational( Result impl, List expressions, ParameterExpression target ) { boolean hasData = false; - for ( AlgDataTypeField field : impl.physType.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : impl.physType.getRowType().getFields() ) { IndexExpression indexField = Expressions.arrayIndex( target, Expressions.constant( field.getIndex() ) ); UnaryExpression element = Expressions.convert_( indexField, PolyBinary.class ); Expression el = Expressions.call( RefactorFunctions.class, "toDocument", element ); @@ -380,7 +380,7 @@ private Result implementRelationalOnDocument( EnumerableAlgImplementor implement ParameterExpression target = Expressions.parameter( Object.class ); - for ( AlgDataTypeField field : getRowType().getFieldList() ) { + for ( AlgDataTypeField field : getRowType().getFields() ) { Expression raw; Expression element = Expressions.convert_( Expressions.arrayIndex( Expressions.convert_( target, new ArrayType( PolyValue.class ) ), Expressions.constant( 0 ) ), PolyDocument.class ); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableUncollect.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableUncollect.java index c8c117ebb4..2a3a457482 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableUncollect.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableUncollect.java @@ -87,7 +87,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { final List fieldCounts = new ArrayList<>(); final List inputTypes = new ArrayList<>(); - for ( AlgDataTypeField field : child.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : child.getRowType().getFields() ) { final AlgDataType type = field.getType(); if ( type instanceof MapPolyType ) { fieldCounts.add( 2 ); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableValues.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableValues.java index b6dc26ac4c..27d5808ba5 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableValues.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableValues.java @@ -95,7 +95,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { final Type rowClass = physType.getJavaRowType(); final List expressions = new ArrayList<>(); - final List fields = rowType.getFieldList(); + final List fields = rowType.getFields(); for ( List tuple : tuples ) { final List literals = new ArrayList<>(); for ( Pair pair : Pair.zip( fields, tuple ) ) { diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableWindow.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableWindow.java index bfd7ad4e4f..1a31eba54f 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableWindow.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableWindow.java @@ -217,7 +217,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { // The output from this stage is the input plus the aggregate functions. final Builder typeBuilder = typeFactory.builder(); - typeBuilder.addAll( inputPhysType.getRowType().getFieldList() ); + typeBuilder.addAll( inputPhysType.getRowType().getFields() ); for ( AggImpState agg : aggs ) { typeBuilder.add( null, agg.call.name, null, agg.call.type ); } @@ -856,7 +856,7 @@ private Expression translateBound( assert fieldCollations.size() == 1 : "When using range window specification, ORDER BY should have exactly one expression. Actual collation is " + group.collation(); // isRange int orderKey = fieldCollations.get( 0 ).getFieldIndex(); - AlgDataType keyType = physType.getRowType().getFieldList().get( orderKey ).getType(); + AlgDataType keyType = physType.getRowType().getFields().get( orderKey ).getType(); Type desiredKeyType = translator.typeFactory.getJavaClass( keyType ); if ( bound.getOffset() == null ) { desiredKeyType = Primitive.box( desiredKeyType ); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/JavaRowFormat.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/JavaRowFormat.java index 7cd2f0171a..e765f57014 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/JavaRowFormat.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/JavaRowFormat.java @@ -48,7 +48,7 @@ Type javaRowClass( JavaTypeFactory typeFactory, AlgDataType type ) { @Override Type javaFieldClass( JavaTypeFactory typeFactory, AlgDataType type, int index ) { - return typeFactory.getJavaClass( type.getFieldList().get( index ).getType() ); + return typeFactory.getJavaClass( type.getFields().get( index ).getType() ); } @@ -81,7 +81,7 @@ public MemberExpression field( Expression expression, int field, Type fromType, @Override Type javaRowClass( JavaTypeFactory typeFactory, AlgDataType type ) { assert type.getFieldCount() == 1; - return typeFactory.getJavaClass( type.getFieldList().get( 0 ).getType() ); + return typeFactory.getJavaClass( type.getFields().get( 0 ).getType() ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/PhysTypeImpl.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/PhysTypeImpl.java index d3f5dc01d3..04b5a89ca5 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/PhysTypeImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/PhysTypeImpl.java @@ -71,7 +71,7 @@ public class PhysTypeImpl implements PhysType { this.rowType = rowType; this.javaRowClass = javaRowClass; this.format = format; - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { fieldClasses.add( EnumUtils.javaRowClass( typeFactory, field.getType() ) ); } } @@ -121,12 +121,12 @@ public PhysType project( List integers, JavaRowFormat format ) { public PhysType project( List integers, boolean indicator, JavaRowFormat format ) { final Builder builder = typeFactory.builder(); for ( int index : integers ) { - builder.add( rowType.getFieldList().get( index ) ); + builder.add( rowType.getFields().get( index ) ); } if ( indicator ) { final AlgDataType booleanType = typeFactory.createTypeWithNullability( typeFactory.createPolyType( PolyType.BOOLEAN ), false ); for ( int index : integers ) { - builder.add( null, "i$" + rowType.getFieldList().get( index ).getName(), null, booleanType ); + builder.add( null, "i$" + rowType.getFields().get( index ).getName(), null, booleanType ); } } AlgDataType projectedRowType = builder.build(); @@ -441,14 +441,14 @@ public Type getJavaFieldType( int index ) { @Override public PhysType component( int fieldOrdinal ) { - final AlgDataTypeField field = rowType.getFieldList().get( fieldOrdinal ); + final AlgDataTypeField field = rowType.getFields().get( fieldOrdinal ); return PhysTypeImpl.of( typeFactory, toStruct( field.getType().getComponentType() ), format, false ); } @Override public PhysType field( int ordinal ) { - final AlgDataTypeField field = rowType.getFieldList().get( ordinal ); + final AlgDataTypeField field = rowType.getFields().get( ordinal ); final AlgDataType type = field.getType(); return PhysTypeImpl.of( typeFactory, toStruct( type ), format, false ); } @@ -494,7 +494,7 @@ public Class fieldClass( int field ) { @Override public boolean fieldNullable( int field ) { - return rowType.getFieldList().get( field ).getType().isNullable(); + return rowType.getFields().get( field ).getType().isNullable(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/document/DocumentAggregateToAggregateRule.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/document/DocumentAggregateToAggregateRule.java index c6725d8ca3..2ba8cfd1be 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/document/DocumentAggregateToAggregateRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/document/DocumentAggregateToAggregateRule.java @@ -116,7 +116,7 @@ public void onMatch( AlgOptRuleCall call ) { AlgNode enumerableAggregate = aggregate.copy( aggregate.getTraitSet().replace( ModelTrait.DOCUMENT ), aggregate.getInputs() ); //RexNode doc = builder.getRexBuilder().makeCall( DocumentType.ofId(), OperatorRegistry.get( QueryLanguage.from( "mongo" ), OperatorName.MQL_MERGE ) ); - Map docs = enumerableAggregate.getRowType().getFieldList().stream().collect( Collectors.toMap( AlgDataTypeField::getName, e -> builder.getRexBuilder().makeInputRef( DocumentType.ofDoc(), e.getIndex() ) ) ); + Map docs = enumerableAggregate.getRowType().getFields().stream().collect( Collectors.toMap( AlgDataTypeField::getName, e -> builder.getRexBuilder().makeInputRef( DocumentType.ofDoc(), e.getIndex() ) ) ); call.transformTo( LogicalDocumentProject.create( enumerableAggregate, docs, List.of() ) ); // call.transformTo( LogicalAggregate.create( alg.getInput(), alg.groupSet, alg.groupSets, alg.aggCalls ) ); diff --git a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java index e2eb1a2693..a5df12a501 100644 --- a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java +++ b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java @@ -293,7 +293,7 @@ Object toJson( Object value ) { private Object toJson( AlgDataType node ) { if ( node.isStruct() ) { final List list = jsonBuilder.list(); - for ( AlgDataTypeField field : node.getFieldList() ) { + for ( AlgDataTypeField field : node.getFields() ) { list.add( toJson( field ) ); } return list; diff --git a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonWriter.java b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonWriter.java index 2aac177611..a1813831df 100644 --- a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonWriter.java +++ b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonWriter.java @@ -115,14 +115,14 @@ private String replaceWithFieldNames( AlgNode alg, Object right ) { if ( str.contains( "$" ) ) { int offset = 0; for ( AlgNode input : alg.getInputs() ) { - for ( AlgDataTypeField field : input.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : input.getRowType().getFields() ) { String searchStr = "$" + (offset + field.getIndex()); int position = str.indexOf( searchStr ); if ( position >= 0 && (str.length() >= position + searchStr.length()) ) { str = str.replace( searchStr, field.getName() ); } } - offset = input.getRowType().getFieldList().size(); + offset = input.getRowType().getFields().size(); } } return str; diff --git a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgWriterImpl.java b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgWriterImpl.java index 4ae3264a10..d26b382bf2 100644 --- a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgWriterImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgWriterImpl.java @@ -144,7 +144,7 @@ private String insertFieldNames( AlgNode alg, Object right ) { if ( str.contains( "$" ) ) { int offset = 0; for ( AlgNode input : alg.getInputs() ) { - for ( AlgDataTypeField field : input.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : input.getRowType().getFields() ) { String searchStr = "$" + (offset + field.getIndex()); int position = str.indexOf( searchStr ); if ( position >= 0 @@ -153,7 +153,7 @@ private String insertFieldNames( AlgNode alg, Object right ) { str = str.replace( searchStr, searchStr + "{" + field.getName() + "}" ); } } - offset = input.getRowType().getFieldList().size(); + offset = input.getRowType().getFields().size(); } } return str; diff --git a/core/src/main/java/org/polypheny/db/algebra/fun/SplittableAggFunction.java b/core/src/main/java/org/polypheny/db/algebra/fun/SplittableAggFunction.java index 09160b9907..2e605b7d94 100644 --- a/core/src/main/java/org/polypheny/db/algebra/fun/SplittableAggFunction.java +++ b/core/src/main/java/org/polypheny/db/algebra/fun/SplittableAggFunction.java @@ -170,7 +170,7 @@ public AggregateCall topSplit( RexBuilder rexBuilder, Registry extra, i public RexNode singleton( RexBuilder rexBuilder, AlgDataType inputRowType, AggregateCall aggregateCall ) { final List predicates = new ArrayList<>(); for ( Integer arg : aggregateCall.getArgList() ) { - final AlgDataType type = inputRowType.getFieldList().get( arg ).getType(); + final AlgDataType type = inputRowType.getFields().get( arg ).getType(); if ( type.isNullable() ) { predicates.add( rexBuilder.makeCall( OperatorRegistry.get( OperatorName.IS_NOT_NULL ), rexBuilder.makeInputRef( type, arg ) ) ); } @@ -203,7 +203,7 @@ class SelfSplitter implements SplittableAggFunction { @Override public RexNode singleton( RexBuilder rexBuilder, AlgDataType inputRowType, AggregateCall aggregateCall ) { final int arg = aggregateCall.getArgList().get( 0 ); - final AlgDataTypeField field = inputRowType.getFieldList().get( arg ); + final AlgDataTypeField field = inputRowType.getFields().get( arg ); return rexBuilder.makeInputRef( field.getType(), arg ); } @@ -239,7 +239,7 @@ abstract class AbstractSumSplitter implements SplittableAggFunction { @Override public RexNode singleton( RexBuilder rexBuilder, AlgDataType inputRowType, AggregateCall aggregateCall ) { final int arg = aggregateCall.getArgList().get( 0 ); - final AlgDataTypeField field = inputRowType.getFieldList().get( arg ); + final AlgDataTypeField field = inputRowType.getFields().get( arg ); return rexBuilder.makeInputRef( field.getType(), arg ); } @@ -267,7 +267,7 @@ public AggregateCall other( AlgDataTypeFactory typeFactory, AggregateCall e ) { @Override public AggregateCall topSplit( RexBuilder rexBuilder, Registry extra, int offset, AlgDataType inputRowType, AggregateCall aggregateCall, int leftSubTotal, int rightSubTotal ) { final List merges = new ArrayList<>(); - final List fieldList = inputRowType.getFieldList(); + final List fieldList = inputRowType.getFields(); if ( leftSubTotal >= 0 ) { final AlgDataType type = fieldList.get( leftSubTotal ).getType(); merges.add( rexBuilder.makeInputRef( type, leftSubTotal ) ); 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 0c38bbd3cf..5e98e5e641 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 @@ -144,7 +144,7 @@ public static LogicalProject getCollector( RexBuilder rexBuilder, AlgNode input return LogicalProject.create( LogicalValues.createOneRow( input.getCluster() ), input.getRowType() - .getFieldList() + .getFields() .stream() .map( f -> rexBuilder.makeDynamicParam( f.getType(), f.getIndex() ) ) .collect( Collectors.toList() ), @@ -156,9 +156,9 @@ private static List createSourceList( RelModify modify, RexBuilder r return modify.getUpdateColumns() .stream() .map( name -> { - int size = modify.getRowType().getFieldList().size(); + int size = modify.getRowType().getFields().size(); int index = modify.getEntity().getRowType().getFieldNames().indexOf( name ); - return rexBuilder.makeDynamicParam( modify.getEntity().getRowType().getFieldList().get( index ).getType(), size + index ); + return rexBuilder.makeDynamicParam( modify.getEntity().getRowType().getFields().get( index ).getType(), size + index ); } ).collect( Collectors.toList() ); } @@ -171,7 +171,7 @@ public static void attachFilter( AlgNode modify, AlgBuilder algBuilder, RexBuild public static void attachFilter( LogicalEntity entity, AlgBuilder algBuilder, RexBuilder rexBuilder, List indexes ) { List fields = new ArrayList<>(); int i = 0; - for ( AlgDataTypeField field : entity.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : entity.getRowType().getFields() ) { if ( !indexes.contains( i ) ) { i++; continue; @@ -209,7 +209,7 @@ public static boolean isModifyApplicable( RelModify modify ) { private static List getOldFieldRefs( AlgDataType rowType ) { - return rowType.getFieldList().stream().map( f -> RexIndexRef.of( f.getIndex(), rowType ) ).collect( Collectors.toList() ); + return rowType.getFields().stream().map( f -> RexIndexRef.of( f.getIndex(), rowType ) ).collect( Collectors.toList() ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java index 1175d805ae..42c066dd9d 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java @@ -60,8 +60,8 @@ public List getRelationalEquivalent( List inputs, List getRelationalEquivalent( List inputs, List - new RexIndexRef( i, input.getRowType().getFieldList().get( i ).getType() ) + new RexIndexRef( i, input.getRowType().getFields().get( i ).getType() ) ) .collect( Collectors.toList() ), input.getRowType() diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalValues.java b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalValues.java index 86ccc2361b..2bf6301d97 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalValues.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalValues.java @@ -114,7 +114,7 @@ public static LogicalValues createOneRow( AlgOptCluster cluster ) { ImmutableList.of( cluster.getRexBuilder().makeExactLiteral( BigDecimal.ZERO, - rowType.getFieldList().get( 0 ).getType() ) ) ); + rowType.getFields().get( 0 ).getType() ) ) ); return create( cluster, rowType, tuples ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalWindow.java b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalWindow.java index 37cee80068..df38c9dde2 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalWindow.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalWindow.java @@ -186,7 +186,7 @@ public RexNode visitLocalRef( RexLocalRef localRef ) { // Figure out the type of the inputs to the output program. // They are: the inputs to this alg, followed by the outputs of each window. final List flattenedAggCallList = new ArrayList<>(); - final List fieldList = new ArrayList<>( child.getRowType().getFieldList() ); + final List fieldList = new ArrayList<>( child.getRowType().getFields() ); final int offset = fieldList.size(); // Use better field names for agg calls that are projected. @@ -236,7 +236,7 @@ public RexNode visitOver( RexOver over ) { "over", over.getType(), "intermed", - intermediateRowType.getFieldList().get( index ).getType(), + intermediateRowType.getFields().get( index ).getType(), Litmus.THROW ); return new RexIndexRef( index, over.getType() ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdAllPredicates.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdAllPredicates.java index b1b8ffeae7..919f08c370 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdAllPredicates.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdAllPredicates.java @@ -150,7 +150,7 @@ public AlgOptPredicateList getAllPredicates( Filter filter, AlgMetadataQuery mq // Infer column origin expressions for given references final Map> mapping = new LinkedHashMap<>(); for ( int idx : inputFieldsUsed ) { - final RexIndexRef ref = RexIndexRef.of( idx, filter.getRowType().getFieldList() ); + final RexIndexRef ref = RexIndexRef.of( idx, filter.getRowType().getFields() ); final Set originalExprs = mq.getExpressionLineage( filter, ref ); if ( originalExprs == null ) { // Bail out @@ -221,13 +221,13 @@ public AlgOptPredicateList getAllPredicates( Join join, AlgMetadataQuery mq ) { // Infer column origin expressions for given references final Map> mapping = new LinkedHashMap<>(); for ( int idx : inputFieldsUsed ) { - final RexIndexRef inputRef = RexIndexRef.of( idx, join.getRowType().getFieldList() ); + final RexIndexRef inputRef = RexIndexRef.of( idx, join.getRowType().getFields() ); final Set originalExprs = mq.getExpressionLineage( join, inputRef ); if ( originalExprs == null ) { // Bail out return null; } - final RexIndexRef ref = RexIndexRef.of( idx, join.getRowType().getFieldList() ); + final RexIndexRef ref = RexIndexRef.of( idx, join.getRowType().getFields() ); mapping.put( ref, originalExprs ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java index 7d9d834c9a..8cd2afb462 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java @@ -102,7 +102,7 @@ public Set getColumnOrigins( Aggregate alg, AlgMetadataQuery mq public Set getColumnOrigins( Join alg, AlgMetadataQuery mq, int iOutputColumn ) { - int nLeftColumns = alg.getLeft().getRowType().getFieldList().size(); + int nLeftColumns = alg.getLeft().getRowType().getFields().size(); Set set; boolean derived = false; if ( iOutputColumn < nLeftColumns ) { diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistinctRowCount.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistinctRowCount.java index 363e38ba5f..bfbb596401 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistinctRowCount.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistinctRowCount.java @@ -107,7 +107,7 @@ public Double getDistinctRowCount( Union alg, AlgMetadataQuery mq, ImmutableBitS new AlgOptUtil.RexInputConverter( rexBuilder, null, - input.getRowType().getFieldList(), + input.getRowType().getFields(), adjustments ) ); } Double partialRowCount = mq.getDistinctRowCount( input, groupKey, modifiedPred ); diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdExpressionLineage.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdExpressionLineage.java index b2056f951d..6eb5bbb8d7 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdExpressionLineage.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdExpressionLineage.java @@ -132,8 +132,8 @@ public Set getExpressionLineage( RelScan alg, AlgMetadataQuery mq, RexN for ( int idx : inputFieldsUsed ) { final RexNode inputRef = RexTableIndexRef.of( AlgTableRef.of( alg.getEntity(), 0 ), - RexIndexRef.of( idx, alg.getRowType().getFieldList() ) ); - final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFieldList() ); + RexIndexRef.of( idx, alg.getRowType().getFields() ) ); + final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFields() ); mapping.put( ref, ImmutableSet.of( inputRef ) ); } @@ -164,13 +164,13 @@ public Set getExpressionLineage( Aggregate alg, AlgMetadataQuery mq, Re // Infer column origin expressions for given references final Map> mapping = new LinkedHashMap<>(); for ( int idx : inputFieldsUsed ) { - final RexIndexRef inputRef = RexIndexRef.of( alg.getGroupSet().nth( idx ), input.getRowType().getFieldList() ); + final RexIndexRef inputRef = RexIndexRef.of( alg.getGroupSet().nth( idx ), input.getRowType().getFields() ); final Set originalExprs = mq.getExpressionLineage( input, inputRef ); if ( originalExprs == null ) { // Bail out return null; } - final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFieldList() ); + final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFields() ); mapping.put( ref, originalExprs ); } @@ -188,7 +188,7 @@ public Set getExpressionLineage( Join alg, AlgMetadataQuery mq, RexNode final RexBuilder rexBuilder = alg.getCluster().getRexBuilder(); final AlgNode leftInput = alg.getLeft(); final AlgNode rightInput = alg.getRight(); - final int nLeftColumns = leftInput.getRowType().getFieldList().size(); + final int nLeftColumns = leftInput.getRowType().getFields().size(); // Extract input fields referenced by expression final ImmutableBitSet inputFieldsUsed = extractInputRefs( outputExpression ); @@ -242,17 +242,17 @@ public Set getExpressionLineage( Join alg, AlgMetadataQuery mq, RexNode final Map> mapping = new LinkedHashMap<>(); for ( int idx : inputFieldsUsed ) { if ( idx < nLeftColumns ) { - final RexIndexRef inputRef = RexIndexRef.of( idx, leftInput.getRowType().getFieldList() ); + final RexIndexRef inputRef = RexIndexRef.of( idx, leftInput.getRowType().getFields() ); final Set originalExprs = mq.getExpressionLineage( leftInput, inputRef ); if ( originalExprs == null ) { // Bail out return null; } // Left input references remain unchanged - mapping.put( RexIndexRef.of( idx, alg.getRowType().getFieldList() ), originalExprs ); + mapping.put( RexIndexRef.of( idx, alg.getRowType().getFields() ), originalExprs ); } else { // Right input. - final RexIndexRef inputRef = RexIndexRef.of( idx - nLeftColumns, rightInput.getRowType().getFieldList() ); + final RexIndexRef inputRef = RexIndexRef.of( idx - nLeftColumns, rightInput.getRowType().getFields() ); final Set originalExprs = mq.getExpressionLineage( rightInput, inputRef ); if ( originalExprs == null ) { // Bail out @@ -260,7 +260,7 @@ public Set getExpressionLineage( Join alg, AlgMetadataQuery mq, RexNode } // Right input references might need to be updated if there are table names clashes with left input final Set updatedExprs = ImmutableSet.copyOf( Iterables.transform( originalExprs, e -> RexUtil.swapTableReferences( rexBuilder, e, currentTablesMapping ) ) ); - mapping.put( RexIndexRef.of( idx, alg.getRowType().getFieldList() ), updatedExprs ); + mapping.put( RexIndexRef.of( idx, alg.getRowType().getFields() ), updatedExprs ); } } @@ -301,14 +301,14 @@ public Set getExpressionLineage( Union alg, AlgMetadataQuery mq, RexNod } // Map references for ( int idx : inputFieldsUsed ) { - final RexIndexRef inputRef = RexIndexRef.of( idx, input.getRowType().getFieldList() ); + final RexIndexRef inputRef = RexIndexRef.of( idx, input.getRowType().getFields() ); final Set originalExprs = mq.getExpressionLineage( input, inputRef ); if ( originalExprs == null ) { // Bail out return null; } // References might need to be updated - final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFieldList() ); + final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFields() ); final Set updatedExprs = originalExprs.stream() .map( e -> RexUtil.swapTableReferences( rexBuilder, e, currentTablesMapping ) ) @@ -350,7 +350,7 @@ public Set getExpressionLineage( Project alg, final AlgMetadataQuery mq // Bail out return null; } - final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFieldList() ); + final RexIndexRef ref = RexIndexRef.of( idx, alg.getRowType().getFields() ); mapping.put( ref, originalExprs ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdPredicates.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdPredicates.java index 3a1fea7dd9..1808d791ae 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdPredicates.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdPredicates.java @@ -246,7 +246,7 @@ private RexNode projectPredicate( final RexBuilder rexBuilder, AlgNode input, Re if ( columnsMapped.intersects( rCols ) ) { final List list = new ArrayList<>(); for ( int c : columnsMapped.intersect( rCols ) ) { - if ( input.getRowType().getFieldList().get( c ).getType().isNullable() && Strong.isNull( r, ImmutableBitSet.of( c ) ) ) { + if ( input.getRowType().getFields().get( c ).getType().isNullable() && Strong.isNull( r, ImmutableBitSet.of( c ) ) ) { list.add( rexBuilder.makeCall( OperatorRegistry.get( OperatorName.IS_NOT_NULL ), rexBuilder.makeInputRef( input, c ) ) ); } } @@ -475,8 +475,8 @@ private JoinConditionBasedPredicateInference( Join joinRel, boolean isSemiJoin, this.joinRel = joinRel; this.isSemiJoin = isSemiJoin; this.simplify = simplify; - nFieldsLeft = joinRel.getLeft().getRowType().getFieldList().size(); - nFieldsRight = joinRel.getRight().getRowType().getFieldList().size(); + nFieldsLeft = joinRel.getLeft().getRowType().getFields().size(); + nFieldsRight = joinRel.getRight().getRowType().getFields().size(); nSysFields = joinRel.getSystemFieldList().size(); leftFieldsBitSet = ImmutableBitSet.range( nSysFields, nSysFields + nFieldsLeft ); rightFieldsBitSet = ImmutableBitSet.range( nSysFields + nFieldsLeft, nSysFields + nFieldsLeft + nFieldsRight ); diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSelectivity.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSelectivity.java index 24685b1dbb..31a19e616c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSelectivity.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSelectivity.java @@ -87,7 +87,7 @@ public Double getSelectivity( Union alg, AlgMetadataQuery mq, RexNode predicate } // convert the predicate to reference the types of the union child - RexNode modifiedPred = predicate.accept( new AlgOptUtil.RexInputConverter( rexBuilder, null, input.getRowType().getFieldList(), adjustments ) ); + RexNode modifiedPred = predicate.accept( new AlgOptUtil.RexInputConverter( rexBuilder, null, input.getRowType().getFields(), adjustments ) ); double sel = mq.getSelectivity( input, modifiedPred ); sumRows += nRows; diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java index 8ccfa66929..c0155329d1 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java @@ -110,7 +110,7 @@ public Double averageRowSize( AlgNode alg, AlgMetadataQuery mq ) { return null; } double d = 0d; - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); for ( Pair p : Pair.zip( averageColumnSizes, fields ) ) { if ( p.left == null ) { d += averageFieldValueSize( p.right ); @@ -158,7 +158,7 @@ public List averageColumnSizes( Project alg, AlgMetadataQuery mq ) { public List averageColumnSizes( Values alg, AlgMetadataQuery mq ) { - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); final ImmutableList.Builder list = ImmutableList.builder(); for ( int i = 0; i < fields.size(); i++ ) { AlgDataTypeField field = fields.get( i ); @@ -179,7 +179,7 @@ public List averageColumnSizes( Values alg, AlgMetadataQuery mq ) { public List averageColumnSizes( RelScan alg, AlgMetadataQuery mq ) { - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); final ImmutableList.Builder list = ImmutableList.builder(); for ( AlgDataTypeField field : fields ) { list.add( averageTypeValueSize( field.getType() ) ); @@ -341,7 +341,7 @@ public Double averageTypeValueSize( AlgDataType type ) { return Math.min( (double) type.getPrecision() * BYTES_PER_CHARACTER, 100d ); case ROW: double average = 0.0; - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { average += averageTypeValueSize( field.getType() ); } return average; diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/AggregateExpandDistinctAggregatesRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/AggregateExpandDistinctAggregatesRule.java index b876a4ea22..2b57433669 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/AggregateExpandDistinctAggregatesRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/AggregateExpandDistinctAggregatesRule.java @@ -169,7 +169,7 @@ public void onMatch( AlgOptRuleCall call ) { } // Create a list of the expressions which will yield the final result. Initially, the expressions point to the input field. - final List aggFields = aggregate.getRowType().getFieldList(); + final List aggFields = aggregate.getRowType().getFields(); final List refs = new ArrayList<>(); final List fieldNames = aggregate.getRowType().getFieldNames(); final ImmutableBitSet groupSet = aggregate.getGroupSet(); @@ -488,7 +488,7 @@ private void doRewrite( AlgBuilder algBuilder, Aggregate aggregate, int n, List< if ( n == 0 ) { leftFields = null; } else { - leftFields = algBuilder.peek().getRowType().getFieldList(); + leftFields = algBuilder.peek().getRowType().getFields(); } // Aggregate( @@ -596,7 +596,7 @@ private void doRewrite( AlgBuilder algBuilder, Aggregate aggregate, int n, List< // Create the join condition. It is of the form // 'left.f0 = right.f0 and left.f1 = right.f1 and ...' // where {f0, f1, ...} are the GROUP BY fields. - final List distinctFields = algBuilder.peek().getRowType().getFieldList(); + final List distinctFields = algBuilder.peek().getRowType().getFields(); final List conditions = new ArrayList<>(); for ( i = 0; i < groupAndIndicatorCount; ++i ) { // null values form its own group use "is not distinct from" so that the join condition allows null values to match. @@ -673,7 +673,7 @@ private static void rewriteAggCalls( List newAggCalls, List argList, int filterArg, Map sourceOf ) { algBuilder.push( aggregate.getInput() ); final List> projects = new ArrayList<>(); - final List childFields = algBuilder.peek().getRowType().getFieldList(); + final List childFields = algBuilder.peek().getRowType().getFields(); for ( int i : aggregate.getGroupSet() ) { sourceOf.put( i, projects.size() ); projects.add( RexIndexRef.of2( i, childFields ) ); diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/AggregateProjectPullUpConstantsRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/AggregateProjectPullUpConstantsRule.java index 823ad47be8..30e8c8efe9 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/AggregateProjectPullUpConstantsRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/AggregateProjectPullUpConstantsRule.java @@ -157,7 +157,7 @@ public void onMatch( AlgOptRuleCall call ) { // Create a projection back again. List> projects = new ArrayList<>(); int source = 0; - for ( AlgDataTypeField field : aggregate.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : aggregate.getRowType().getFields() ) { RexNode expr; final int i = field.getIndex(); if ( i >= groupCount ) { @@ -167,7 +167,7 @@ public void onMatch( AlgOptRuleCall call ) { int pos = aggregate.getGroupSet().nth( i ); if ( map.containsKey( pos ) ) { // Re-generate the constant expression in the project. - AlgDataType originalType = aggregate.getRowType().getFieldList().get( projects.size() ).getType(); + AlgDataType originalType = aggregate.getRowType().getFields().get( projects.size() ).getType(); if ( !originalType.equals( map.get( pos ).getType() ) ) { expr = rexBuilder.makeCast( originalType, map.get( pos ), true ); } else { diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/AggregateReduceFunctionsRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/AggregateReduceFunctionsRule.java index bb37bf8584..0d2451959f 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/AggregateReduceFunctionsRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/AggregateReduceFunctionsRule.java @@ -725,7 +725,7 @@ protected void newCalcAlg( AlgBuilder algBuilder, AlgDataType rowType, List conditions = AlgOptUtil.conjunctions( filterRel.getCondition() ); final RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder(); - final List origFields = aggRel.getRowType().getFieldList(); + final List origFields = aggRel.getRowType().getFields(); final int[] adjustments = new int[origFields.size()]; int j = 0; for ( int i : aggRel.getGroupSet() ) { @@ -106,7 +106,7 @@ public void onMatch( AlgOptRuleCall call ) { if ( canPush( aggRel, rCols ) ) { pushedConditions.add( condition.accept( - new AlgOptUtil.RexInputConverter( rexBuilder, origFields, aggRel.getInput( 0 ).getRowType().getFieldList(), adjustments ) ) ); + new AlgOptUtil.RexInputConverter( rexBuilder, origFields, aggRel.getInput( 0 ).getRowType().getFields(), adjustments ) ) ); } else { remainingConditions.add( condition ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/FilterSetOpTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/FilterSetOpTransposeRule.java index ed9982d5f0..7a44c9920a 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/FilterSetOpTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/FilterSetOpTransposeRule.java @@ -79,11 +79,11 @@ public void onMatch( AlgOptRuleCall call ) { // create filters on top of each setop child, modifying the filter condition to reference each setop child RexBuilder rexBuilder = filterAlg.getCluster().getRexBuilder(); final AlgBuilder algBuilder = call.builder(); - List origFields = setOp.getRowType().getFieldList(); + List origFields = setOp.getRowType().getFields(); int[] adjustments = new int[origFields.size()]; final List newSetOpInputs = new ArrayList<>(); for ( AlgNode input : setOp.getInputs() ) { - RexNode newCondition = condition.accept( new AlgOptUtil.RexInputConverter( rexBuilder, origFields, input.getRowType().getFieldList(), adjustments ) ); + RexNode newCondition = condition.accept( new AlgOptUtil.RexInputConverter( rexBuilder, origFields, input.getRowType().getFields(), adjustments ) ); newSetOpInputs.add( algBuilder.push( input ).filter( newCondition ).build() ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/FilterTableFunctionTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/FilterTableFunctionTransposeRule.java index 813c1c06a2..9c54c21840 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/FilterTableFunctionTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/FilterTableFunctionTransposeRule.java @@ -104,11 +104,11 @@ public void onMatch( AlgOptRuleCall call ) { // create filters on top of each func input, modifying the filter condition to reference the child instead RexBuilder rexBuilder = filter.getCluster().getRexBuilder(); - List origFields = funcRel.getRowType().getFieldList(); + List origFields = funcRel.getRowType().getFields(); // TODO: these need to be non-zero once we support arbitrary mappings int[] adjustments = new int[origFields.size()]; for ( AlgNode funcInput : funcInputs ) { - RexNode newCondition = condition.accept( new RexInputConverter( rexBuilder, origFields, funcInput.getRowType().getFieldList(), adjustments ) ); + RexNode newCondition = condition.accept( new RexInputConverter( rexBuilder, origFields, funcInput.getRowType().getFields(), adjustments ) ); newFuncInputs.add( LogicalFilter.create( funcInput, newCondition ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/JoinCommuteRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/JoinCommuteRule.java index af3e9fa8b0..f83d695f3b 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/JoinCommuteRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/JoinCommuteRule.java @@ -168,8 +168,8 @@ private static class VariableReplacer { VariableReplacer( RexBuilder rexBuilder, AlgDataType leftType, AlgDataType rightType ) { this.rexBuilder = rexBuilder; - this.leftFields = leftType.getFieldList(); - this.rightFields = rightType.getFieldList(); + this.leftFields = leftType.getFields(); + this.rightFields = rightType.getFields(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/JoinProjectTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/JoinProjectTransposeRule.java index 64a8b3c1ae..d04cf91573 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/JoinProjectTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/JoinProjectTransposeRule.java @@ -196,17 +196,17 @@ public void onMatch( AlgOptRuleCall call ) { leftJoinChild, 0, rexBuilder, - joinChildrenRowType.getFieldList(), + joinChildrenRowType.getFields(), projects ); - List leftFields = leftJoinChild.getRowType().getFieldList(); + List leftFields = leftJoinChild.getRowType().getFields(); int nFieldsLeft = leftFields.size(); createProjectExprs( rightProj, rightJoinChild, nFieldsLeft, rexBuilder, - joinChildrenRowType.getFieldList(), + joinChildrenRowType.getFields(), projects ); final List projTypes = new ArrayList<>(); @@ -242,7 +242,7 @@ public void onMatch( AlgOptRuleCall call ) { // Expand out the new projection expressions; if the join is an outer join, modify the expressions to reference the join output final List newProjExprs = new ArrayList<>(); List projList = mergedProgram.getProjectList(); - List newJoinFields = newJoinRel.getRowType().getFieldList(); + List newJoinFields = newJoinRel.getRowType().getFields(); int nJoinFields = newJoinFields.size(); int[] adjustments = new int[nJoinFields]; for ( int i = 0; i < nProjExprs; i++ ) { @@ -252,7 +252,7 @@ public void onMatch( AlgOptRuleCall call ) { newExpr.accept( new AlgOptUtil.RexInputConverter( rexBuilder, - joinChildrenRowType.getFieldList(), + joinChildrenRowType.getFields(), newJoinFields, adjustments ) ); } @@ -324,7 +324,7 @@ protected AlgNode getProjectChild( AlgOptRuleCall call, Project project, boolean * @param projects Projection expressions & names to be created */ protected void createProjectExprs( Project projRel, AlgNode joinChild, int adjustmentAmount, RexBuilder rexBuilder, List joinChildrenFields, List> projects ) { - List childFields = joinChild.getRowType().getFieldList(); + List childFields = joinChild.getRowType().getFields(); if ( projRel != null ) { List> namedProjects = projRel.getNamedProjects(); int nChildFields = childFields.size(); diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/JoinToMultiJoinRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/JoinToMultiJoinRule.java index 1b2ebb88e0..bec88ca2d5 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/JoinToMultiJoinRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/JoinToMultiJoinRule.java @@ -239,8 +239,8 @@ private void combineOuterJoins( Join joinRel, List combinedInputs, AlgN (MultiJoin) right, joinSpecs, left.getRowType().getFieldCount(), - right.getRowType().getFieldList(), - joinRel.getRowType().getFieldList() ); + right.getRowType().getFields(), + joinRel.getRowType().getFields() ); } else { joinSpecs.add( Pair.of( JoinAlgType.INNER, (RexNode) null ) ); } @@ -261,8 +261,8 @@ private void combineOuterJoins( Join joinRel, List combinedInputs, AlgN (MultiJoin) right, joinSpecs, left.getRowType().getFieldCount(), - right.getRowType().getFieldList(), - joinRel.getRowType().getFieldList() ); + right.getRowType().getFields(), + joinRel.getRowType().getFields() ); } else { joinSpecs.add( Pair.of( JoinAlgType.INNER, (RexNode) null ) ); } @@ -366,8 +366,8 @@ private RexNode shiftRightFilter( Join joinRel, AlgNode left, MultiJoin right, R return null; } - int nFieldsOnLeft = left.getRowType().getFieldList().size(); - int nFieldsOnRight = right.getRowType().getFieldList().size(); + int nFieldsOnLeft = left.getRowType().getFields().size(); + int nFieldsOnRight = right.getRowType().getFields().size(); int[] adjustments = new int[nFieldsOnRight]; for ( int i = 0; i < nFieldsOnRight; i++ ) { adjustments[i] = nFieldsOnLeft; @@ -376,8 +376,8 @@ private RexNode shiftRightFilter( Join joinRel, AlgNode left, MultiJoin right, R rightFilter.accept( new AlgOptUtil.RexInputConverter( joinRel.getCluster().getRexBuilder(), - right.getRowType().getFieldList(), - joinRel.getRowType().getFieldList(), + right.getRowType().getFields(), + joinRel.getRowType().getFields(), adjustments ) ); return rightFilter; } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/LoptMultiJoin.java b/core/src/main/java/org/polypheny/db/algebra/rules/LoptMultiJoin.java index add5803a7c..9c9a2a9a50 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/LoptMultiJoin.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/LoptMultiJoin.java @@ -289,7 +289,7 @@ public ImmutableBitSet getFactorsRefByJoinFilter( RexNode joinFilter ) { * Returns array of fields contained within the multi-join */ public List getMultiJoinFields() { - return multiJoin.getRowType().getFieldList(); + return multiJoin.getRowType().getFields(); } @@ -599,7 +599,7 @@ public List getJoinFields( LoptJoinTree left, LoptJoinTree rig factory.createJoinType( left.getJoinTree().getRowType(), right.getJoinTree().getRowType() ); - return rowType.getFieldList(); + return rowType.getFields(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java index c6527ca748..9cc1f77291 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java @@ -352,8 +352,8 @@ private boolean isSelfJoinFilterUnique( AlgMetadataQuery mq, LoptMultiJoin multi new AlgOptUtil.RexInputConverter( rexBuilder, multiJoin.getMultiJoinFields(), - leftRel.getRowType().getFieldList(), - rightRel.getRowType().getFieldList(), + leftRel.getRowType().getFields(), + rightRel.getRowType().getFields(), adjustments ) ); return areSelfJoinKeysUnique( mq, leftRel, rightRel, joinFilters ); @@ -867,7 +867,7 @@ private LoptJoinTree pushDownFactor( AlgMetadataQuery mq, AlgBuilder algBuilder, newCondition, factorToAdd, origJoinOrder, - joinTree.getJoinTree().getRowType().getFieldList() ); + joinTree.getJoinTree().getRowType().getFields() ); // Determine if additional filters apply as a result of adding the new factor, provided this isn't a left or right // outer join; for those cases, the additional filters will be added on top of the join in createJoinSubtree. @@ -1008,8 +1008,8 @@ private RexNode addFilters( LoptMultiJoin multiJoin, LoptJoinTree leftTree, int new AlgOptUtil.RexInputConverter( rexBuilder, multiJoin.getMultiJoinFields(), - leftTree.getJoinTree().getRowType().getFieldList(), - rightTree.getJoinTree().getRowType().getFieldList(), + leftTree.getJoinTree().getRowType().getFields(), + rightTree.getJoinTree().getRowType().getFields(), adjustments ) ); } } @@ -1082,8 +1082,8 @@ private RexNode adjustFilter( LoptMultiJoin multiJoin, LoptJoinTree left, LoptJo new AlgOptUtil.RexInputConverter( rexBuilder, origFields, - left.getJoinTree().getRowType().getFieldList(), - right.getJoinTree().getRowType().getFieldList(), + left.getJoinTree().getRowType().getFields(), + right.getJoinTree().getRowType().getFields(), adjustments ) ); } @@ -1195,7 +1195,7 @@ private LoptJoinTree createReplacementSemiJoin( AlgBuilder algBuilder, LoptMulti } // Map the dimension keys to the corresponding keys from the fact table, based on the fact table's position in the current jointree - List dimFields = multiJoin.getJoinFactor( dimIdx ).getRowType().getFieldList(); + List dimFields = multiJoin.getJoinFactor( dimIdx ).getRowType().getFields(); int nDimFields = dimFields.size(); Integer[] replacementKeys = new Integer[nDimFields]; SemiJoin semiJoin = multiJoin.getJoinRemovalSemiJoin( dimIdx ); @@ -1237,9 +1237,9 @@ private LoptJoinTree createReplacementJoin( AlgBuilder algBuilder, LoptMultiJoin // key from the replacementKeys passed in; for other fields, just create a null expression as a placeholder for the column; this is done so we don't have to adjust the offsets of other // expressions that reference the new factor; the placeholder expression values should never be referenced, so that's why it's ok to create these possibly invalid expressions AlgNode currJoinRel = currJoinTree.getJoinTree(); - List currFields = currJoinRel.getRowType().getFieldList(); + List currFields = currJoinRel.getRowType().getFields(); final int nCurrFields = currFields.size(); - List newFields = multiJoin.getJoinFactor( factorToAdd ).getRowType().getFieldList(); + List newFields = multiJoin.getJoinFactor( factorToAdd ).getRowType().getFields(); final int nNewFields = newFields.size(); List> projects = new ArrayList<>(); RexBuilder rexBuilder = currJoinRel.getCluster().getRexBuilder(); @@ -1329,8 +1329,8 @@ private LoptJoinTree createJoinSubtree( AlgMetadataQuery mq, AlgBuilder algBuild new AlgOptUtil.RexInputConverter( rexBuilder, multiJoin.getMultiJoinFields(), - left.getJoinTree().getRowType().getFieldList(), - right.getJoinTree().getRowType().getFieldList(), + left.getJoinTree().getRowType().getFields(), + right.getJoinTree().getRowType().getFields(), adjustments ) ); } } @@ -1374,7 +1374,7 @@ private void addAdditionalFilters( AlgBuilder algBuilder, LoptMultiJoin multiJoi new AlgOptUtil.RexInputConverter( rexBuilder, multiJoin.getMultiJoinFields(), - algBuilder.peek().getRowType().getFieldList(), + algBuilder.peek().getRowType().getFields(), adjustments ) ); algBuilder.filter( filterCond ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/ProjectJoinTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/ProjectJoinTransposeRule.java index 5a7b77f848..54f5021793 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/ProjectJoinTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/ProjectJoinTransposeRule.java @@ -113,8 +113,8 @@ public void onMatch( AlgOptRuleCall call ) { if ( join.getCondition() != null ) { List projJoinFieldList = new ArrayList<>(); projJoinFieldList.addAll( join.getSystemFieldList() ); - projJoinFieldList.addAll( leftProjAlg.getRowType().getFieldList() ); - projJoinFieldList.addAll( rightProjAlg.getRowType().getFieldList() ); + projJoinFieldList.addAll( leftProjAlg.getRowType().getFields() ); + projJoinFieldList.addAll( rightProjAlg.getRowType().getFields() ); newJoinFilter = pushProject.convertRefsAndExprs( join.getCondition(), projJoinFieldList, adjustments ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/ProjectWindowTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/ProjectWindowTransposeRule.java index ea056591db..67c76d5964 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/ProjectWindowTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/ProjectWindowTransposeRule.java @@ -85,7 +85,7 @@ public void onMatch( AlgOptRuleCall call ) { final LogicalProject project = call.alg( 0 ); final LogicalWindow window = call.alg( 1 ); final AlgOptCluster cluster = window.getCluster(); - final List rowTypeWindowInput = window.getInput().getRowType().getFieldList(); + final List rowTypeWindowInput = window.getInput().getRowType().getFields(); final int windowInputColumn = rowTypeWindowInput.size(); // Record the window input columns which are actually referred either in the LogicalProject above LogicalWindow or LogicalWindow itself @@ -145,7 +145,7 @@ public RexNode visitCall( final RexCall call ) { int aggCallIndex = windowInputColumn; final AlgDataTypeFactory.Builder outputBuilder = cluster.getTypeFactory().builder(); - outputBuilder.addAll( projectBelowWindow.getRowType().getFieldList() ); + outputBuilder.addAll( projectBelowWindow.getRowType().getFields() ); for ( Group group : window.groups ) { final ImmutableBitSet.Builder keys = ImmutableBitSet.builder(); final List orderKeys = new ArrayList<>(); @@ -166,7 +166,7 @@ public RexNode visitCall( final RexCall call ) { for ( RexWinAggCall rexWinAggCall : group.aggCalls ) { aggCalls.add( (RexWinAggCall) rexWinAggCall.accept( indexAdjustment ) ); - final AlgDataTypeField algDataTypeField = window.getRowType().getFieldList().get( aggCallIndex ); + final AlgDataTypeField algDataTypeField = window.getRowType().getFields().get( aggCallIndex ); outputBuilder.add( algDataTypeField ); ++aggCallIndex; } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/PushProjector.java b/core/src/main/java/org/polypheny/db/algebra/rules/PushProjector.java index da8df4a978..92b5d6fa1b 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/PushProjector.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/PushProjector.java @@ -198,14 +198,14 @@ public PushProjector( Project origProj, RexNode origFilter, AlgNode childRel, Ex origProjExprs = origProj.getProjects(); } - childFields = childRel.getRowType().getFieldList(); + childFields = childRel.getRowType().getFields(); nChildFields = childFields.size(); projRefs = new BitSet( nChildFields ); if ( childRel instanceof Join ) { Join joinRel = (Join) childRel; - List leftFields = joinRel.getLeft().getRowType().getFieldList(); - List rightFields = joinRel.getRight().getRowType().getFieldList(); + List leftFields = joinRel.getLeft().getRowType().getFields(); + List rightFields = joinRel.getRight().getRowType().getFields(); nFields = leftFields.size(); nFieldsRight = childRel instanceof SemiJoin ? 0 : rightFields.size(); nSysFields = joinRel.getSystemFieldList().size(); @@ -229,8 +229,8 @@ public PushProjector( Project origProj, RexNode origFilter, AlgNode childRel, Ex } else if ( childRel instanceof Correlate ) { Correlate corrRel = (Correlate) childRel; - List leftFields = corrRel.getLeft().getRowType().getFieldList(); - List rightFields = corrRel.getRight().getRowType().getFieldList(); + List leftFields = corrRel.getLeft().getRowType().getFields(); + List rightFields = corrRel.getRight().getRowType().getFields(); nFields = leftFields.size(); SemiJoinType joinType = corrRel.getJoinType(); switch ( joinType ) { @@ -330,7 +330,7 @@ public AlgNode convertProject( RexNode defaultExpr ) { // If a filter was passed in, convert it to reference the projected columns, placing it on top of the project just created AlgNode projChild; if ( origFilter != null ) { - RexNode newFilter = convertRefsAndExprs( origFilter, newProject.getRowType().getFieldList(), adjustments ); + RexNode newFilter = convertRefsAndExprs( origFilter, newProject.getRowType().getFields(), adjustments ); algBuilder.push( newProject ); algBuilder.filter( newFilter ); projChild = algBuilder.build(); @@ -436,7 +436,7 @@ public Project createProjectRefsAndExprs( AlgNode projChild, boolean adjust, boo } int refIdx = offset - 1; List> newProjects = new ArrayList<>(); - List destFields = projChild.getRowType().getFieldList(); + List destFields = projChild.getRowType().getFields(); // add on the input references for ( int i = 0; i < nInputRefs; i++ ) { @@ -535,7 +535,7 @@ public AlgNode createNewProject( AlgNode projChild, int[] adjustments ) { if ( origProj != null ) { for ( Pair p : origProj.getNamedProjects() ) { - projects.add( Pair.of( convertRefsAndExprs( p.left, projChild.getRowType().getFieldList(), adjustments ), p.right ) ); + projects.add( Pair.of( convertRefsAndExprs( p.left, projChild.getRowType().getFields(), adjustments ), p.right ) ); } } else { for ( Ord field : Ord.zip( childFields ) ) { diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinJoinTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinJoinTransposeRule.java index 32363396c1..a5c21def9b 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinJoinTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinJoinTransposeRule.java @@ -88,18 +88,18 @@ public void onMatch( AlgOptRuleCall call ) { // X is the left child of the join below the semi-join // Y is the right child of the join below the semi-join // Z is the right child of the semi-join - int nFieldsX = join.getLeft().getRowType().getFieldList().size(); - int nFieldsY = join.getRight().getRowType().getFieldList().size(); - int nFieldsZ = semiJoin.getRight().getRowType().getFieldList().size(); + int nFieldsX = join.getLeft().getRowType().getFields().size(); + int nFieldsY = join.getRight().getRowType().getFields().size(); + int nFieldsZ = semiJoin.getRight().getRowType().getFields().size(); int nTotalFields = nFieldsX + nFieldsY + nFieldsZ; List fields = new ArrayList<>(); // create a list of fields for the full join result; note that we can't simply use the fields from the semi-join because the row-type of a semi-join only includes the left hand side fields - List joinFields = semiJoin.getRowType().getFieldList(); + List joinFields = semiJoin.getRowType().getFields(); for ( int i = 0; i < (nFieldsX + nFieldsY); i++ ) { fields.add( joinFields.get( i ) ); } - joinFields = semiJoin.getRight().getRowType().getFieldList(); + joinFields = semiJoin.getRight().getRowType().getFields(); for ( int i = 0; i < nFieldsZ; i++ ) { fields.add( joinFields.get( i ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinProjectTransposeRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinProjectTransposeRule.java index d00ace5f0e..00a247cf18 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinProjectTransposeRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/SemiJoinProjectTransposeRule.java @@ -143,7 +143,7 @@ private RexNode adjustCondition( LogicalProject project, SemiJoin semiJoin ) { bottomProgramBuilder.addProject( pair.left, pair.right ); } int nLeftFields = project.getInput().getRowType().getFieldCount(); - List rightFields = rightChild.getRowType().getFieldList(); + List rightFields = rightChild.getRowType().getFields(); int nRightFields = rightFields.size(); for ( int i = 0; i < nRightFields; i++ ) { final AlgDataTypeField field = rightFields.get( i ); diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/UnionPullUpConstantsRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/UnionPullUpConstantsRule.java index 7df8d91ef9..d50c7a4ed4 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/UnionPullUpConstantsRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/UnionPullUpConstantsRule.java @@ -106,7 +106,7 @@ public void onMatch( AlgOptRuleCall call ) { } // Create expressions for Project operators before and after the Union - List fields = union.getRowType().getFieldList(); + List fields = union.getRowType().getFields(); List topChildExprs = new ArrayList<>(); List topChildExprsFields = new ArrayList<>(); List refs = new ArrayList<>(); @@ -135,7 +135,7 @@ public void onMatch( AlgOptRuleCall call ) { for ( AlgNode input : union.getInputs() ) { List> newChildExprs = new ArrayList<>(); for ( int j : refsIndex ) { - newChildExprs.add( Pair.of( rexBuilder.makeInputRef( input, j ), input.getRowType().getFieldList().get( j ).getName() ) ); + newChildExprs.add( Pair.of( rexBuilder.makeInputRef( input, j ), input.getRowType().getFields().get( j ).getName() ) ); } if ( newChildExprs.isEmpty() ) { // At least a single item in project is required. diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/ValuesReduceRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/ValuesReduceRule.java index 35153dd6ae..4ed5da807c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/ValuesReduceRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/ValuesReduceRule.java @@ -176,7 +176,7 @@ protected void apply( AlgOptRuleCall call, LogicalProject project, LogicalFilter ++k; RexNode e = projectExpr.accept( shuttle ); if ( RexLiteral.isNullLiteral( e ) ) { - e = rexBuilder.makeAbstractCast( project.getRowType().getFieldList().get( k ).getType(), e ); + e = rexBuilder.makeAbstractCast( project.getRowType().getFields().get( k ).getType(), e ); } reducibleExps.add( e ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgCrossType.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgCrossType.java index 71fcb183c6..5f48ddf584 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgCrossType.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgCrossType.java @@ -71,8 +71,8 @@ public boolean isStruct() { @Override - public List getFieldList() { - return fieldList; + public List getFields() { + return fields; } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataType.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataType.java index edf91d4c92..71fa7be2b6 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataType.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataType.java @@ -64,7 +64,7 @@ public interface AlgDataType { * * @return read-only list of fields */ - List getFieldList(); + List getFields(); /** * Returns the names of the fields in a struct type. The field count is equal to the size of the returned list. @@ -79,7 +79,7 @@ public interface AlgDataType { /** * Returns the number of fields in a struct type. * - * This method is equivalent to {@link #getFieldList}.size(). + * This method is equivalent to {@link #getFields}.size(). */ int getFieldCount(); 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 b12fa6466c..6cfd8c074e 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 @@ -568,7 +568,7 @@ public AlgDataType build() { public AlgDataType buildDynamic() { final AlgDataType dynamicType = new DynamicRecordTypeImpl( typeFactory ); final AlgDataType type = build(); - dynamicType.getFieldList().addAll( type.getFieldList() ); + dynamicType.getFields().addAll( type.getFields() ); return dynamicType; } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactoryImpl.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactoryImpl.java index bac62cfa1d..053f351c35 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactoryImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFactoryImpl.java @@ -203,7 +203,7 @@ protected AlgDataType leastRestrictiveStructuredType( final List ty if ( !type.isStruct() ) { return null; } - if ( type.getFieldList().size() != fieldCount ) { + if ( type.getFields().size() != fieldCount ) { return null; } } @@ -214,13 +214,13 @@ protected AlgDataType leastRestrictiveStructuredType( final List ty // REVIEW jvs: Always use the field name from the first type? final int k = j; builder.add( - null, type0.getFieldList().get( j ).getName(), + null, type0.getFields().get( j ).getName(), null, leastRestrictive( new AbstractList<>() { @Override public AlgDataType get( int index ) { - return types.get( index ).getFieldList().get( k ).getType(); + return types.get( index ).getFields().get( k ).getType(); } @@ -262,8 +262,8 @@ private AlgDataType copyRecordType( final AlgRecordType type, final boolean igno return createStructType( type.getStructKind(), - type.getFieldList().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), - type.getFieldList().stream().map( f -> { + type.getFields().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + type.getFields().stream().map( f -> { if ( ignoreNullable ) { return copyType( f.getType() ); } else { @@ -401,7 +401,7 @@ private static void addFields( AlgDataType type, List fieldLis addFields( type1, fieldList ); } } else { - List fields = type.getFieldList(); + List fields = type.getFields(); for ( AlgDataTypeField field : fields ) { if ( field.getIndex() != fieldList.size() ) { field = new AlgDataTypeFieldImpl( field.getId(), field.getName(), fieldList.size(), field.getType() ); @@ -681,12 +681,12 @@ public int hashCode() { @Override public boolean equals( Object obj ) { return obj == this - || obj instanceof Key - && ids == ((Key) obj).ids + || (obj instanceof Key + && ids.equals( ((Key) obj).ids ) && kind == ((Key) obj).kind && names.equals( ((Key) obj).names ) && physicalNames.equals( ((Key) obj).physicalNames ) - && types.equals( ((Key) obj).types ); + && types.equals( ((Key) obj).types )); } } 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 21625651cb..2989ab0bfe 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 @@ -55,7 +55,7 @@ */ public abstract class AlgDataTypeImpl implements AlgDataType, AlgDataTypeFamily { - protected final List fieldList; + protected final List fields; private final List ids; protected String digest; @@ -63,15 +63,15 @@ public abstract class AlgDataTypeImpl implements AlgDataType, AlgDataTypeFamily /** * Creates a AlgDataTypeImpl. * - * @param fieldList List of fields + * @param fields List of fields */ - protected AlgDataTypeImpl( List fieldList ) { - if ( fieldList != null ) { + protected AlgDataTypeImpl( List fields ) { + if ( fields != null ) { // Create a defensive copy of the list. - this.fieldList = ImmutableList.copyOf( fieldList ); - this.ids = fieldList.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ); + this.fields = ImmutableList.copyOf( fields ); + this.ids = fields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ); } else { - this.fieldList = null; + this.fields = null; this.ids = null; } } @@ -90,7 +90,7 @@ protected AlgDataTypeImpl() { @Override public AlgDataTypeField getField( String fieldName, boolean caseSensitive, boolean elideRecord ) { - for ( AlgDataTypeField field : fieldList ) { + for ( AlgDataTypeField field : fields ) { if ( Util.matches( caseSensitive, field.getName(), fieldName ) ) { return field; } @@ -111,15 +111,15 @@ public AlgDataTypeField getField( String fieldName, boolean caseSensitive, boole } } // Extra field - if ( !fieldList.isEmpty() ) { - final AlgDataTypeField lastField = Iterables.getLast( fieldList ); + if ( !fields.isEmpty() ) { + final AlgDataTypeField lastField = Iterables.getLast( fields ); if ( lastField.getName().equals( "_extra" ) ) { return new AlgDataTypeFieldImpl( lastField.getId(), fieldName, -1, lastField.getType() ); } } // a dynamic * field will match any field name. - for ( AlgDataTypeField field : fieldList ) { + for ( AlgDataTypeField field : fields ) { if ( field.isDynamicStar() ) { // the requested field could be in the unresolved star return field; @@ -135,7 +135,7 @@ private static void getFieldRecurse( List slots, AlgDataType type, int dep slots.add( new Slot() ); } final Slot slot = slots.get( depth ); - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { if ( Util.matches( caseSensitive, field.getName(), fieldName ) ) { slot.count++; slot.field = field; @@ -143,7 +143,7 @@ private static void getFieldRecurse( List slots, AlgDataType type, int dep } // No point looking to depth + 1 if there is a hit at depth. if ( slot.count == 0 ) { - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { if ( field.getType().isStruct() ) { getFieldRecurse( slots, field.getType(), depth + 1, fieldName, caseSensitive ); } @@ -153,15 +153,15 @@ private static void getFieldRecurse( List slots, AlgDataType type, int dep @Override - public List getFieldList() { + public List getFields() { assert isStruct(); - return fieldList; + return fields; } @Override public List getFieldNames() { - return fieldList.stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); + return fields.stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); } @@ -174,7 +174,7 @@ public List getFieldIds() { public List getPhysicalFieldNames() { // TODO MV: Is there a more efficient way for doing this? List l = new ArrayList<>(); - fieldList.forEach( f -> l.add( f.getPhysicalName() ) ); + fields.forEach( f -> l.add( f.getPhysicalName() ) ); return l; } @@ -182,7 +182,7 @@ public List getPhysicalFieldNames() { @Override public int getFieldCount() { assert isStruct() : this; - return fieldList.size(); + return fields.size(); } @@ -201,7 +201,7 @@ public AlgDataType getComponentType() { @Override public boolean isStruct() { - return fieldList != null; + return fields != null; } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgRecordType.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgRecordType.java index dc2a31bd73..d5e09dd516 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgRecordType.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgRecordType.java @@ -107,7 +107,7 @@ protected void generateTypeString( StringBuilder sb, boolean withDetail ) { break; } sb.append( "(" ); - for ( Ord ord : Ord.zip( fieldList ) ) { + for ( Ord ord : Ord.zip( fields ) ) { if ( ord.i > 0 ) { sb.append( ", " ); } @@ -131,7 +131,7 @@ protected void generateTypeString( StringBuilder sb, boolean withDetail ) { * method converts it back to a RelRecordType during deserialization. */ private Object writeReplace() { - return new SerializableAlgRecordType( fieldList ); + return new SerializableAlgRecordType( fields ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/DocumentType.java b/core/src/main/java/org/polypheny/db/algebra/type/DocumentType.java index bebc372330..55b7b8fdd6 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/DocumentType.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/DocumentType.java @@ -95,14 +95,14 @@ public boolean isStruct() { @Override - public List getFieldList() { + public List getFields() { return fixedFields; } @Override public List getFieldNames() { - return getFieldList().stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); + return getFields().stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); } @@ -114,7 +114,7 @@ public List getFieldIds() { @Override public int getFieldCount() { - return getFieldList().size(); + return getFields().size(); } @@ -123,7 +123,7 @@ public AlgDataTypeField getField( String fieldName, boolean caseSensitive, boole // everything we ask a document for is there int index = getFieldNames().indexOf( fieldName ); if ( index >= 0 ) { - return getFieldList().get( index ); + return getFields().get( index ); } AlgDataTypeFieldImpl added = new AlgDataTypeFieldImpl( -1L, fieldName, getFieldCount(), new DocumentType() ); fixedFields.add( added ); diff --git a/core/src/main/java/org/polypheny/db/algebra/type/DynamicRecordTypeImpl.java b/core/src/main/java/org/polypheny/db/algebra/type/DynamicRecordTypeImpl.java index 3cfdabc0c0..036054394c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/DynamicRecordTypeImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/DynamicRecordTypeImpl.java @@ -62,7 +62,7 @@ public DynamicRecordTypeImpl( AlgDataTypeFactory typeFactory ) { @Override - public List getFieldList() { + public List getFields() { return holder.getFieldList(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/type/GraphType.java b/core/src/main/java/org/polypheny/db/algebra/type/GraphType.java index 9a308a2a8d..093a7b5ba0 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/GraphType.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/GraphType.java @@ -64,14 +64,14 @@ public boolean isStruct() { @Override - public List getFieldList() { + public List getFields() { return fixedFields; } @Override public List getFieldNames() { - return getFieldList().stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); + return getFields().stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ); } diff --git a/core/src/main/java/org/polypheny/db/interpreter/Bindables.java b/core/src/main/java/org/polypheny/db/interpreter/Bindables.java index 44bb9c1efa..a9d1a547c1 100644 --- a/core/src/main/java/org/polypheny/db/interpreter/Bindables.java +++ b/core/src/main/java/org/polypheny/db/interpreter/Bindables.java @@ -222,7 +222,7 @@ public static BindableScan create( AlgOptCluster cluster, LogicalEntity entity, @Override public AlgDataType deriveRowType() { final AlgDataTypeFactory.Builder builder = getCluster().getTypeFactory().builder(); - final List fieldList = entity.getRowType().getFieldList(); + final List fieldList = entity.getRowType().getFields(); for ( int project : projects ) { builder.add( fieldList.get( project ) ); } diff --git a/core/src/main/java/org/polypheny/db/interpreter/Interpreter.java b/core/src/main/java/org/polypheny/db/interpreter/Interpreter.java index b976c087c2..383fbb9078 100644 --- a/core/src/main/java/org/polypheny/db/interpreter/Interpreter.java +++ b/core/src/main/java/org/polypheny/db/interpreter/Interpreter.java @@ -425,7 +425,7 @@ public Scalar compile( List nodes, AlgDataType inputRowType ) { public AlgDataType combinedRowType( List inputs ) { final Builder builder = interpreter.dataContext.getTypeFactory().builder(); for ( AlgNode input : inputs ) { - builder.addAll( input.getRowType().getFieldList() ); + builder.addAll( input.getRowType().getFields() ); } return builder.build(); } diff --git a/core/src/main/java/org/polypheny/db/interpreter/ScanNode.java b/core/src/main/java/org/polypheny/db/interpreter/ScanNode.java index 7f6fdba27b..7a969efefa 100644 --- a/core/src/main/java/org/polypheny/db/interpreter/ScanNode.java +++ b/core/src/main/java/org/polypheny/db/interpreter/ScanNode.java @@ -230,7 +230,7 @@ private static ScanNode createEnumerable( Compiler compiler, RelScan alg, Enu final Mapping mapping = Mappings.target( acceptedProjects, alg.getEntity().getRowType().getFieldCount() ); filter2 = RexUtil.apply( mapping, filter ); final AlgDataTypeFactory.Builder builder = alg.getCluster().getTypeFactory().builder(); - final List fieldList = alg.getEntity().getRowType().getFieldList(); + final List fieldList = alg.getEntity().getRowType().getFields(); for ( int acceptedProject : acceptedProjects ) { builder.add( fieldList.get( acceptedProject ) ); } diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java index 66a9257a02..655126c9be 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java @@ -286,7 +286,7 @@ public static void go( AlgVisitor visitor, AlgNode p ) { * @see AlgDataType#getFieldNames() */ public static List getFieldTypeList( final AlgDataType type ) { - return Lists.transform( type.getFieldList(), AlgDataTypeField::getType ); + return Lists.transform( type.getFields(), AlgDataTypeField::getType ); } @@ -304,8 +304,8 @@ public static boolean areRowTypesEqual( AlgDataType rowType1, AlgDataType rowTyp if ( rowType2.getFieldCount() != rowType1.getFieldCount() ) { return false; } - final List f1 = rowType1.getFieldList(); - final List f2 = rowType2.getFieldList(); + final List f1 = rowType1.getFields(); + final List f2 = rowType2.getFields(); for ( Pair pair : Pair.zip( f1, f2 ) ) { final AlgDataType type1 = pair.left.getType(); final AlgDataType type2 = pair.right.getType(); @@ -521,10 +521,10 @@ public static Exists createExistsPlan( AlgNode seekRel, SubQueryType subQueryTyp @Deprecated // to be removed before 2.0 public static AlgNode createRenameRel( AlgDataType outputType, AlgNode alg ) { AlgDataType inputType = alg.getRowType(); - List inputFields = inputType.getFieldList(); + List inputFields = inputType.getFields(); int n = inputFields.size(); - List outputFields = outputType.getFieldList(); + List outputFields = outputType.getFields(); assert outputFields.size() == n : "rename: field count mismatch: in=" + inputType + ", out" + outputType; @@ -592,7 +592,7 @@ public static AlgNode createNullFilter( AlgNode alg, Integer[] fieldOrdinals ) { } else { n = rowType.getFieldCount(); } - List fields = rowType.getFieldList(); + List fields = rowType.getFields(); for ( int i = 0; i < n; ++i ) { int iField; if ( fieldOrdinals != null ) { @@ -850,11 +850,11 @@ private static void splitJoinCondition( List sysFieldList, Lis if ( leftKey == null ) { leftKey = op0; leftInput = i; - leftFields = inputs.get( leftInput ).getRowType().getFieldList(); + leftFields = inputs.get( leftInput ).getRowType().getFields(); } else { rightKey = op0; rightInput = i; - rightFields = inputs.get( rightInput ).getRowType().getFieldList(); + rightFields = inputs.get( rightInput ).getRowType().getFields(); reverse = true; foundBothInputs = true; } @@ -863,11 +863,11 @@ private static void splitJoinCondition( List sysFieldList, Lis if ( leftKey == null ) { leftKey = op1; leftInput = i; - leftFields = inputs.get( leftInput ).getRowType().getFieldList(); + leftFields = inputs.get( leftInput ).getRowType().getFields(); } else { rightKey = op1; rightInput = i; - rightFields = inputs.get( rightInput ).getRowType().getFieldList(); + rightFields = inputs.get( rightInput ).getRowType().getFields(); foundBothInputs = true; } } @@ -914,7 +914,7 @@ private static void splitJoinCondition( List sysFieldList, Lis for ( int i = 0; i < inputs.size() && !foundInput; i++ ) { if ( inputsRange[i].contains( projRefs ) ) { leftInput = i; - leftFields = inputs.get( leftInput ).getRowType().getFieldList(); + leftFields = inputs.get( leftInput ).getRowType().getFields(); leftKey = condition.accept( new AlgOptUtil.RexInputConverter( rexBuilder, leftFields, leftFields, adjustments ) ); @@ -1238,7 +1238,7 @@ public static void projectJoinInputs( AlgNode[] inputAlgs, List leftJoi } for ( i = 0; i < origLeftInputSize; i++ ) { - final AlgDataTypeField field = leftRel.getRowType().getFieldList().get( i ); + final AlgDataTypeField field = leftRel.getRowType().getFields().get( i ); newLeftFields.add( rexBuilder.makeInputRef( field.getType(), i ) ); newLeftFieldNames.add( field.getName() ); outputProj.add( systemColCount + i ); @@ -1261,7 +1261,7 @@ public static void projectJoinInputs( AlgNode[] inputAlgs, List leftJoi int leftFieldCount = origLeftInputSize + newLeftKeyCount; for ( i = 0; i < origRightInputSize; i++ ) { - final AlgDataTypeField field = rightRel.getRowType().getFieldList().get( i ); + final AlgDataTypeField field = rightRel.getRowType().getFields().get( i ); newRightFields.add( rexBuilder.makeInputRef( field.getType(), i ) ); newRightFieldNames.add( field.getName() ); outputProj.add( systemColCount + leftFieldCount + i ); @@ -1305,7 +1305,7 @@ public static void projectJoinInputs( AlgNode[] inputAlgs, List leftJoi @Deprecated // to be removed before 2.0 public static AlgNode createProjectJoinRel( List outputProj, AlgNode joinRel ) { int newProjectOutputSize = outputProj.size(); - List joinOutputFields = joinRel.getRowType().getFieldList(); + List joinOutputFields = joinRel.getRowType().getFields(); // If no projection was passed in, or the number of desired projection columns is the same as the number of columns returned from the join, then no need to create a projection if ( (newProjectOutputSize > 0) && (newProjectOutputSize < joinOutputFields.size()) ) { @@ -1506,8 +1506,8 @@ public static RexNode isDistinctFrom( RexBuilder rexBuilder, RexNode x, RexNode RexNode ret = null; if ( x.getType().isStruct() ) { assert y.getType().isStruct(); - List xFields = x.getType().getFieldList(); - List yFields = y.getType().getFieldList(); + List xFields = x.getType().getFields(); + List yFields = y.getType().getFields(); assert xFields.size() == yFields.size(); for ( Pair pair : Pair.zip( xFields, yFields ) ) { AlgDataTypeField xField = pair.left; @@ -1608,7 +1608,7 @@ public static String dumpType( AlgDataType type ) { final PrintWriter pw = new PrintWriter( sw ); final TypeDumper typeDumper = new TypeDumper( pw ); if ( type.isStruct() ) { - typeDumper.acceptFields( type.getFieldList() ); + typeDumper.acceptFields( type.getFields() ); } else { typeDumper.accept( type ); } @@ -1886,12 +1886,12 @@ public static JoinAlgType simplifyJoin( AlgNode joinRel, ImmutableList */ public static boolean classifyFilters( AlgNode joinRel, List filters, JoinAlgType joinType, boolean pushInto, boolean pushLeft, boolean pushRight, List joinFilters, List leftFilters, List rightFilters ) { RexBuilder rexBuilder = joinRel.getCluster().getRexBuilder(); - List joinFields = joinRel.getRowType().getFieldList(); + List joinFields = joinRel.getRowType().getFields(); final int nTotalFields = joinFields.size(); final int nSysFields = 0; // joinRel.getSystemFieldList().size(); - final List leftFields = joinRel.getInputs().get( 0 ).getRowType().getFieldList(); + final List leftFields = joinRel.getInputs().get( 0 ).getRowType().getFields(); final int nFieldsLeft = leftFields.size(); - final List rightFields = joinRel.getInputs().get( 1 ).getRowType().getFieldList(); + final List rightFields = joinRel.getInputs().get( 1 ).getRowType().getFields(); final int nFieldsRight = rightFields.size(); assert nTotalFields == (joinRel instanceof SemiJoin @@ -1985,11 +1985,11 @@ public static void splitFilters( ImmutableBitSet childBitmap, RexNode predicate, public static boolean checkProjAndChildInputs( Project project, boolean checkNames ) { int n = project.getProjects().size(); AlgDataType inputType = project.getInput().getRowType(); - if ( inputType.getFieldList().size() != n ) { + if ( inputType.getFields().size() != n ) { return false; } - List projFields = project.getRowType().getFieldList(); - List inputFields = inputType.getFieldList(); + List projFields = project.getRowType().getFields(); + List inputFields = inputType.getFields(); boolean namesDifferent = false; for ( int i = 0; i < n; ++i ) { RexNode exp = project.getProjects().get( i ); @@ -2024,7 +2024,7 @@ public static boolean checkProjAndChildInputs( Project project, boolean checkNam * @return array of expression representing the swapped join inputs */ public static List createSwappedJoinExprs( AlgNode newJoin, Join origJoin, boolean origOrder ) { - final List newJoinFields = newJoin.getRowType().getFieldList(); + final List newJoinFields = newJoin.getRowType().getFields(); final RexBuilder rexBuilder = newJoin.getCluster().getRexBuilder(); final List exps = new ArrayList<>(); final int nFields = @@ -2261,7 +2261,7 @@ int run( AlgNode node ) { * Permutes a record type according to a mapping. */ public static AlgDataType permute( AlgDataTypeFactory typeFactory, AlgDataType rowType, Mapping mapping ) { - return typeFactory.createStructType( Mappings.apply3( mapping, rowType.getFieldList() ) ); + return typeFactory.createStructType( Mappings.apply3( mapping, rowType.getFields() ) ); } @@ -2299,7 +2299,7 @@ public static AlgNode createProject( final AlgNode child, final List po @Deprecated // to be removed before 2.0 public static AlgNode createRename( AlgNode alg, List fieldNames ) { - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); assert fieldNames.size() == fields.size(); final List refs = new AbstractList() { @@ -2361,7 +2361,7 @@ public static AlgNode permute( AlgNode alg, Permutation permutation, List outputNameList = new ArrayList<>(); final List exprList = new ArrayList<>(); final List projectRefList = new ArrayList<>(); - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); final AlgOptCluster cluster = alg.getCluster(); for ( int i = 0; i < permutation.getTargetCount(); i++ ) { int target = permutation.getTarget( i ); @@ -2443,7 +2443,7 @@ public static AlgNode projectMapping( AlgNode alg, Mapping mapping, List } final List outputNameList = new ArrayList<>(); final List exprList = new ArrayList<>(); - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); final RexBuilder rexBuilder = alg.getCluster().getRexBuilder(); for ( int i = 0; i < mapping.getTargetCount(); i++ ) { final int source = mapping.getSource( i ); @@ -2586,7 +2586,7 @@ public static AlgNode pushDownJoinConditions( Join originalJoin, AlgBuilder algB algBuilder.push( originalJoin.getLeft() ); if ( !extraLeftExprs.isEmpty() ) { - final List fields = algBuilder.peek().getRowType().getFieldList(); + final List fields = algBuilder.peek().getRowType().getFields(); final List> pairs = new AbstractList>() { @Override @@ -2610,7 +2610,7 @@ public Pair get( int index ) { algBuilder.push( originalJoin.getRight() ); if ( !extraRightExprs.isEmpty() ) { - final List fields = algBuilder.peek().getRowType().getFieldList(); + final List fields = algBuilder.peek().getRowType().getFields(); final int newLeftCount = leftCount + extraLeftExprs.size(); final List> pairs = new AbstractList>() { @@ -2755,7 +2755,7 @@ private static boolean containsNullableFields( AlgNode r ) { final AlgDataType rowType = r.getRowType(); final List list = new ArrayList<>(); final AlgMetadataQuery mq = r.getCluster().getMetadataQuery(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { if ( field.getType().isNullable() ) { list.add( rexBuilder.makeCall( OperatorRegistry.get( OperatorName.IS_NOT_NULL ), rexBuilder.makeInputRef( field.getType(), field.getIndex() ) ) ); } @@ -2883,7 +2883,7 @@ public static class TypeDumper { void accept( AlgDataType type ) { if ( type.isStruct() ) { - final List fields = type.getFieldList(); + final List fields = type.getFields(); // RECORD ( // I INTEGER NOT NULL, diff --git a/core/src/main/java/org/polypheny/db/plan/SubstitutionVisitor.java b/core/src/main/java/org/polypheny/db/plan/SubstitutionVisitor.java index 7ec5b96e05..07654bc735 100644 --- a/core/src/main/java/org/polypheny/db/plan/SubstitutionVisitor.java +++ b/core/src/main/java/org/polypheny/db/plan/SubstitutionVisitor.java @@ -1115,7 +1115,7 @@ protected MutableAlg invert( MutableAlg model, MutableAlg input, MutableProject } final List exprList = new ArrayList<>(); final RexBuilder rexBuilder = model.cluster.getRexBuilder(); - for ( AlgDataTypeField field : model.rowType.getFieldList() ) { + for ( AlgDataTypeField field : model.rowType.getFields() ) { exprList.add( rexBuilder.makeZeroLiteral( field.getType() ) ); } for ( Ord expr : Ord.zip( project.projects ) ) { @@ -1655,7 +1655,7 @@ public void onMatch( AlgOptRuleCall call ) { final AlgOptCluster cluster = filter.getCluster(); AlgDataType newRowType = cluster.getTypeFactory().builder() - .addAll( project.getRowType().getFieldList() ) + .addAll( project.getRowType().getFields() ) .add( null, "condition", null, Util.last( newProjects ).getType() ) .build(); final AlgNode newProject = diff --git a/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java b/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java index 7dcdd41503..5997505b88 100644 --- a/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java +++ b/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java @@ -152,7 +152,7 @@ public static DataContext of( AlgNode targetRel, LogicalFilter queryRel ) { public static DataContext of( AlgDataType rowType, RexNode rex ) { - final int size = rowType.getFieldList().size(); + final int size = rowType.getFields().size(); final Object[] values = new Object[size]; final List operands = ((RexCall) rex).getOperands(); final RexNode firstOperand = operands.get( 0 ); @@ -169,7 +169,7 @@ public static DataContext of( AlgDataType rowType, RexNode rex ) { public static DataContext of( AlgDataType rowType, List> usageList ) { - final int size = rowType.getFieldList().size(); + final int size = rowType.getFields().size(); final Object[] values = new Object[size]; for ( Pair elem : usageList ) { Pair value = getValue( elem.getKey(), elem.getValue() ); diff --git a/core/src/main/java/org/polypheny/db/prepare/JavaRecordType.java b/core/src/main/java/org/polypheny/db/prepare/JavaRecordType.java index 7b5be91060..143d2e3181 100644 --- a/core/src/main/java/org/polypheny/db/prepare/JavaRecordType.java +++ b/core/src/main/java/org/polypheny/db/prepare/JavaRecordType.java @@ -43,14 +43,14 @@ public JavaRecordType( List fields, Class clazz ) { public boolean equals( Object obj ) { return this == obj || obj instanceof JavaRecordType - && fieldList.equals( ((JavaRecordType) obj).fieldList ) + && fields.equals( ((JavaRecordType) obj).fields ) && clazz == ((JavaRecordType) obj).clazz; } @Override public int hashCode() { - return Objects.hash( fieldList, clazz ); + return Objects.hash( fields, clazz ); } } diff --git a/core/src/main/java/org/polypheny/db/prepare/JavaTypeFactoryImpl.java b/core/src/main/java/org/polypheny/db/prepare/JavaTypeFactoryImpl.java index 5a49ac6160..55b4710916 100644 --- a/core/src/main/java/org/polypheny/db/prepare/JavaTypeFactoryImpl.java +++ b/core/src/main/java/org/polypheny/db/prepare/JavaTypeFactoryImpl.java @@ -203,7 +203,7 @@ public Type getJavaClass( AlgDataType type ) { return javaType.getJavaClass(); } if ( type.isStruct() && type.getFieldCount() == 1 && type.getPolyType() != PolyType.PATH ) { - return getJavaClass( type.getFieldList().get( 0 ).getType() ); + return getJavaClass( type.getFields().get( 0 ).getType() ); } if ( type instanceof AbstractPolyType || type instanceof DocumentType || type instanceof GraphType ) { switch ( type.getPolyType() ) { @@ -300,8 +300,8 @@ public AlgDataType toSql( AlgDataType type ) { public static AlgDataType toSql( final AlgDataTypeFactory typeFactory, AlgDataType type ) { if ( type instanceof AlgRecordType ) { return typeFactory.createStructType( - type.getFieldList().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), - type.getFieldList().stream().map( field -> toSql( typeFactory, field.getType() ) ).collect( Collectors.toList() ), + type.getFields().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + type.getFields().stream().map( field -> toSql( typeFactory, field.getType() ) ).collect( Collectors.toList() ), type.getFieldNames() ); } if ( type instanceof JavaType ) { @@ -357,7 +357,7 @@ public int size() { private Type createSyntheticType( AlgRecordType type ) { final String name = "Record" + type.getFieldCount() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType( type, name ); - for ( final AlgDataTypeField recordField : type.getFieldList() ) { + for ( final AlgDataTypeField recordField : type.getFields() ) { final Type javaClass = getJavaClass( recordField.getType() ); syntheticType.fields.add( new RecordFieldImpl( syntheticType, recordField.getName(), javaClass, recordField.getType().isNullable() && !Primitive.is( javaClass ), Modifier.PUBLIC ) ); } 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 5a69be964b..24dbae28de 100644 --- a/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java +++ b/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java @@ -405,7 +405,7 @@ private AvaticaType avaticaType( JavaTypeFactory typeFactory, AlgDataType type, switch ( typeOrdinal ) { case Types.STRUCT: final List columns = new ArrayList<>(); - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { columns.add( metaData( typeFactory, field.getIndex(), field.getName(), field.getType(), null, null ) ); } return ColumnMetaData.struct( columns ); diff --git a/core/src/main/java/org/polypheny/db/processing/QueryProcessorHelpers.java b/core/src/main/java/org/polypheny/db/processing/QueryProcessorHelpers.java index 412c5eecde..100e0289f7 100644 --- a/core/src/main/java/org/polypheny/db/processing/QueryProcessorHelpers.java +++ b/core/src/main/java/org/polypheny/db/processing/QueryProcessorHelpers.java @@ -106,10 +106,10 @@ public static LogicalRelModify.Operation mapTableModOp( boolean isDml, Kind sqlK public static List getColumnMetaDataList( JavaTypeFactory typeFactory, AlgDataType x, AlgDataType jdbcType, List> originList ) { final List columns = new ArrayList<>(); - for ( Ord pair : Ord.zip( jdbcType.getFieldList() ) ) { + for ( Ord pair : Ord.zip( jdbcType.getFields() ) ) { final AlgDataTypeField field = pair.e; final AlgDataType type = field.getType(); - final AlgDataType fieldType = x.isStruct() ? x.getFieldList().get( pair.i ).getType() : type; + final AlgDataType fieldType = x.isStruct() ? x.getFields().get( pair.i ).getType() : type; columns.add( QueryProcessorHelpers.metaData( typeFactory, columns.size(), field.getName(), type, fieldType, originList.get( pair.i ) ) ); } return columns; @@ -133,7 +133,7 @@ public static ColumnMetaData.AvaticaType avaticaType( JavaTypeFactory typeFactor switch ( typeOrdinal ) { case Types.STRUCT: final List columns = new ArrayList<>(); - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { columns.add( metaData( typeFactory, field.getIndex(), field.getName(), field.getType(), null, null ) ); } return ColumnMetaData.struct( columns ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexBuilder.java b/core/src/main/java/org/polypheny/db/rex/RexBuilder.java index 771194185e..e2559ea201 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexBuilder.java +++ b/core/src/main/java/org/polypheny/db/rex/RexBuilder.java @@ -162,7 +162,7 @@ public RexBuilder( AlgDataTypeFactory typeFactory ) { * Creates a list of {@link RexIndexRef} expressions, projecting the fields of a given record type. */ public List identityProjects( final AlgDataType rowType ) { - return rowType.getFieldList().stream().map( input -> new RexIndexRef( input.getIndex(), input.getType() ) ).collect( Collectors.toList() ); + return rowType.getFields().stream().map( input -> new RexIndexRef( input.getIndex(), input.getType() ) ).collect( Collectors.toList() ); } @@ -206,7 +206,7 @@ public RexNode makeFieldAccess( RexNode expr, String fieldName, boolean caseSens */ public RexNode makeFieldAccess( RexNode expr, int i ) { final AlgDataType type = expr.getType(); - final List fields = type.getFieldList(); + final List fields = type.getFields(); if ( (i < 0) || (i >= fields.size()) ) { throw new AssertionError( "Field ordinal " + i + " is invalid for type '" + type + "'" ); } @@ -771,7 +771,7 @@ public RexIndexRef makeInputRef( AlgDataType type, int i ) { * @see #identityProjects(AlgDataType) */ public RexIndexRef makeInputRef( AlgNode input, int i ) { - return makeInputRef( input.getRowType().getFieldList().get( i ).getType(), i ); + return makeInputRef( input.getRowType().getFields().get( i ).getType(), i ); } @@ -1365,7 +1365,7 @@ public RexNode makeLiteral( Object value, AlgDataType type, boolean allowCast ) case ROW: operands = new ArrayList<>(); //noinspection unchecked - for ( Pair pair : Pair.zip( type.getFieldList(), (List) value ) ) { + for ( Pair pair : Pair.zip( type.getFields(), (List) value ) ) { final RexNode e = pair.right instanceof RexLiteral ? (RexNode) pair.right diff --git a/core/src/main/java/org/polypheny/db/rex/RexChecker.java b/core/src/main/java/org/polypheny/db/rex/RexChecker.java index 5b80eb51ff..8730473c52 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexChecker.java +++ b/core/src/main/java/org/polypheny/db/rex/RexChecker.java @@ -164,11 +164,11 @@ public Boolean visitFieldAccess( RexFieldAccess fieldAccess ) { assert refType.isStruct(); final AlgDataTypeField field = fieldAccess.getField(); final int index = field.getIndex(); - if ( (index < 0) || (index > refType.getFieldList().size()) ) { + if ( (index < 0) || (index > refType.getFields().size()) ) { ++failCount; return litmus.fail( null ); } - final AlgDataTypeField typeField = refType.getFieldList().get( index ); + final AlgDataTypeField typeField = refType.getFields().get( index ); if ( !AlgOptUtil.eq( "type1", typeField.getType(), "type2", fieldAccess.getType(), litmus ) ) { ++failCount; return litmus.fail( null ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexExecutorImpl.java b/core/src/main/java/org/polypheny/db/rex/RexExecutorImpl.java index 8dd322fbc7..07c0b5e2f9 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexExecutorImpl.java +++ b/core/src/main/java/org/polypheny/db/rex/RexExecutorImpl.java @@ -190,7 +190,7 @@ public Expression field( BlockBuilder list, int index, Type storageType ) { Expression recFromCtxCasted = RexToLixTranslator.convert( recFromCtx, Object[].class ); IndexExpression recordAccess = Expressions.arrayIndex( recFromCtxCasted, Expressions.constant( index ) ); if ( storageType == null ) { - final AlgDataType fieldType = rowType.getFieldList().get( index ).getType(); + final AlgDataType fieldType = rowType.getFields().get( index ).getType(); storageType = ((JavaTypeFactory) typeFactory).getJavaClass( fieldType ); } return RexToLixTranslator.convert( recordAccess, storageType ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexFieldAccess.java b/core/src/main/java/org/polypheny/db/rex/RexFieldAccess.java index 9a40416b8e..25cba0c9a1 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexFieldAccess.java +++ b/core/src/main/java/org/polypheny/db/rex/RexFieldAccess.java @@ -73,7 +73,7 @@ public class RexFieldAccess extends RexNode { this.expr = expr; this.field = field; this.digest = expr + "." + field.getName(); - assert expr.getType().getFieldList().get( field.getIndex() ) == field; + assert expr.getType().getFields().get( field.getIndex() ) == field; } diff --git a/core/src/main/java/org/polypheny/db/rex/RexIndexRef.java b/core/src/main/java/org/polypheny/db/rex/RexIndexRef.java index af3b6ff726..8c1bbb813e 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexIndexRef.java +++ b/core/src/main/java/org/polypheny/db/rex/RexIndexRef.java @@ -100,7 +100,7 @@ public int hashCode() { * Creates a reference to a given field in a row type. */ public static RexIndexRef of( int index, AlgDataType rowType ) { - return of( index, rowType.getFieldList() ); + return of( index, rowType.getFields() ); } diff --git a/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java b/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java index b0816efb12..c0b0538ac8 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java +++ b/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java @@ -84,7 +84,7 @@ public static RexPermuteInputsShuttle of( TargetMapping mapping ) { private static ImmutableList fields( AlgNode[] inputs ) { final ImmutableList.Builder fields = ImmutableList.builder(); for ( AlgNode input : inputs ) { - fields.addAll( input.getRowType().getFieldList() ); + fields.addAll( input.getRowType().getFields() ); } return fields.build(); } 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 558743acd7..a1876389a0 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexProgram.java +++ b/core/src/main/java/org/polypheny/db/rex/RexProgram.java @@ -171,7 +171,7 @@ public int size() { public Pair get( int index ) { return Pair.of( projects.get( index ), - outputRowType.getFieldList().get( index ).getName() ); + outputRowType.getFields().get( index ).getName() ); } }; } @@ -256,8 +256,8 @@ public AlgWriter collectExplainTerms( String prefix, AlgWriter pw ) { * @param pw Plan writer */ public AlgWriter collectExplainTerms( String prefix, AlgWriter pw, ExplainLevel level ) { - final List inFields = inputRowType.getFieldList(); - final List outFields = outputRowType.getFieldList(); + final List inFields = inputRowType.getFields(); + final List outFields = outputRowType.getFields(); assert outFields.size() == projects.size() : "outFields.length=" + outFields.size() + ", projects.length=" + projects.size(); pw.item( prefix + "expr#0" + ((inFields.size() > 1) ? (".." + (inFields.size() - 1)) : ""), "{inputs}" ); for ( int i = inFields.size(); i < exprs.size(); i++ ) { @@ -335,7 +335,7 @@ public static RexProgram createIdentity( AlgDataType rowType, AlgDataType output if ( rowType != outputRowType && !rowType.getFieldNames().equals( outputRowType.getFieldNames() ) ) { throw new IllegalArgumentException( "field type mismatch: " + rowType + " vs. " + outputRowType ); } - final List fields = rowType.getFieldList(); + final List fields = rowType.getFields(); final List projectRefs = new ArrayList<>(); final List refs = new ArrayList<>(); for ( int i = 0; i < fields.size(); i++ ) { @@ -644,7 +644,7 @@ public int getSourceField( int outputOrdinal ) { * Returns whether this program is a permutation of its inputs. */ public boolean isPermutation() { - if ( projects.size() != inputRowType.getFieldList().size() ) { + if ( projects.size() != inputRowType.getFields().size() ) { return false; } for ( int i = 0; i < projects.size(); ++i ) { @@ -661,7 +661,7 @@ public boolean isPermutation() { */ public Permutation getPermutation() { Permutation permutation = new Permutation( projects.size() ); - if ( projects.size() != inputRowType.getFieldList().size() ) { + if ( projects.size() != inputRowType.getFields().size() ) { return null; } for ( int i = 0; i < projects.size(); ++i ) { 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 5d0cb9f659..bd59ee5c6b 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexProgramBuilder.java +++ b/core/src/main/java/org/polypheny/db/rex/RexProgramBuilder.java @@ -87,7 +87,7 @@ private RexProgramBuilder( AlgDataType inputRowType, RexBuilder rexBuilder, RexS // Pre-create an expression for each input field. if ( inputRowType.isStruct() ) { - final List fields = inputRowType.getFieldList(); + final List fields = inputRowType.getFields(); for ( int i = 0; i < fields.size(); i++ ) { registerInternal( RexIndexRef.of( i, fields ), false ); } @@ -123,7 +123,7 @@ private RexProgramBuilder( RexBuilder rexBuilder, final AlgDataType inputRowType final RexShuttle expander = new RexProgram.ExpansionShuttle( exprList ); // Register project expressions and create a named project item. - final List fieldList = outputRowType.getFieldList(); + final List fieldList = outputRowType.getFields(); for ( Pair pair : Pair.zip( projectList, fieldList ) ) { final RexNode project; if ( simplify != null ) { @@ -169,7 +169,7 @@ private void validate( final RexNode expr, final int fieldOrdinal ) { @Override public Void visitIndexRef( RexIndexRef input ) { final int index = input.getIndex(); - final List fields = inputRowType.getFieldList(); + final List fields = inputRowType.getFields(); if ( index < fields.size() ) { final AlgDataTypeField inputField = fields.get( index ); if ( input.getType() != inputField.getType() ) { @@ -560,7 +560,7 @@ public static RexProgramBuilder create( * @param updateRefs Whether to update references that changes as a result of rewrites made by the shuttle */ private void add( List exprList, List projectRefList, RexLocalRef conditionRef, final AlgDataType outputRowType, RexShuttle shuttle, boolean updateRefs ) { - final List outFields = outputRowType.getFieldList(); + final List outFields = outputRowType.getFields(); final RexShuttle registerInputShuttle = new RegisterInputShuttle( false ); // For each common expression, first apply the user's shuttle, then register the result. @@ -754,7 +754,7 @@ public void clearCondition() { */ public void addIdentity() { assert projectRefList.isEmpty(); - for ( AlgDataTypeField field : inputRowType.getFieldList() ) { + for ( AlgDataTypeField field : inputRowType.getFields() ) { addProject( new RexIndexRef( field.getIndex(), field.getType() ), field.getName() ); @@ -769,7 +769,7 @@ public void addIdentity() { * @return Reference to input field */ public RexLocalRef makeInputRef( int index ) { - final List fields = inputRowType.getFieldList(); + final List fields = inputRowType.getFields(); assert index < fields.size(); final AlgDataTypeField field = fields.get( index ); return new RexLocalRef( index, field.getType() ); @@ -867,7 +867,7 @@ public RexNode visitIndexRef( RexIndexRef input ) { "type1", input.getType(), "type2", - inputRowType.getFieldList().get( index ).getType(), + inputRowType.getFields().get( index ).getType(), Litmus.THROW ); } diff --git a/core/src/main/java/org/polypheny/db/rex/RexSubQuery.java b/core/src/main/java/org/polypheny/db/rex/RexSubQuery.java index 902249f718..8c15b57a45 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexSubQuery.java +++ b/core/src/main/java/org/polypheny/db/rex/RexSubQuery.java @@ -96,7 +96,7 @@ static AlgDataType type( AlgNode alg, ImmutableList nodes ) { nullable = true; } } - for ( AlgDataTypeField field : alg.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : alg.getRowType().getFields() ) { if ( field.getType().isNullable() ) { nullable = true; } @@ -119,7 +119,7 @@ public static RexSubQuery exists( AlgNode alg ) { * Creates a scalar sub-query. */ public static RexSubQuery scalar( AlgNode alg ) { - final List fieldList = alg.getRowType().getFieldList(); + final List fieldList = alg.getRowType().getFields(); assert fieldList.size() == 1; final AlgDataTypeFactory typeFactory = alg.getCluster().getTypeFactory(); final AlgDataType type = typeFactory.createTypeWithNullability( fieldList.get( 0 ).getType(), true ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexUtil.java b/core/src/main/java/org/polypheny/db/rex/RexUtil.java index f16314ec2e..0c8f71e4f1 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexUtil.java +++ b/core/src/main/java/org/polypheny/db/rex/RexUtil.java @@ -122,7 +122,7 @@ public static double getSelectivity( RexNode exp ) { * @return cast expressions */ public static List generateCastExpressions( RexBuilder rexBuilder, AlgDataType lhsRowType, AlgDataType rhsRowType ) { - final List fieldList = rhsRowType.getFieldList(); + final List fieldList = rhsRowType.getFields(); int n = fieldList.size(); assert n == lhsRowType.getFieldCount() : "field count: lhs [" + lhsRowType + "] rhs [" + rhsRowType + "]"; List rhsExps = new ArrayList<>(); @@ -142,7 +142,7 @@ public static List generateCastExpressions( RexBuilder rexBuilder, AlgD * @return cast expressions */ public static List generateCastExpressions( RexBuilder rexBuilder, AlgDataType lhsRowType, List rhsExps ) { - List lhsFields = lhsRowType.getFieldList(); + List lhsFields = lhsRowType.getFields(); List castExps = new ArrayList<>(); for ( Pair pair : Pair.zip( lhsFields, rhsExps, true ) ) { AlgDataTypeField lhsField = pair.left; @@ -953,7 +953,7 @@ public static AlgDataType createStructType( AlgDataTypeFactory typeFactory, fina * @see AlgOptUtil#eq(String, AlgDataType, String, AlgDataType, org.polypheny.db.util.Litmus) */ public static boolean compatibleTypes( List exprs, AlgDataType type, Litmus litmus ) { - final List fields = type.getFieldList(); + final List fields = type.getFields(); if ( exprs.size() != fields.size() ) { return litmus.fail( "rowtype mismatches expressions" ); } @@ -981,7 +981,7 @@ public static Pair makeKey( RexNode expr ) { * Returns whether the leading edge of a given array of expressions is wholly {@link RexIndexRef} objects with types corresponding to the underlying datatype. */ public static boolean containIdentity( List exprs, AlgDataType rowType, Litmus litmus ) { - final List fields = rowType.getFieldList(); + final List fields = rowType.getFields(); if ( exprs.size() < fields.size() ) { return litmus.fail( "exprs/rowType length mismatch" ); } 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 1dc132d52a..f2d33fa2ea 100644 --- a/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java +++ b/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java @@ -391,7 +391,7 @@ public void replaceTop( AlgNode node, int amount ) { private static ImmutableList toFields( AlgNode node ) { - return ImmutableList.copyOf( node.getRowType().getFieldList().stream().map( f -> new RelField( ImmutableSet.of(), f ) ).collect( Collectors.toList() ) ); + return ImmutableList.copyOf( node.getRowType().getFields().stream().map( f -> new RelField( ImmutableSet.of(), f ) ).collect( Collectors.toList() ) ); } @@ -580,7 +580,7 @@ private RexNode field( int inputCount, int inputOrdinal, int fieldOrdinal, boole if ( fieldOrdinal < 0 || fieldOrdinal > rowType.getFieldCount() ) { throw new IllegalArgumentException( "field ordinal [" + fieldOrdinal + "] out of range; input fields are: " + rowType.getFieldNames() ); } - final AlgDataTypeField field = rowType.getFieldList().get( fieldOrdinal ); + final AlgDataTypeField field = rowType.getFields().get( fieldOrdinal ); final int offset = inputOffset( inputCount, inputOrdinal ); final RexIndexRef ref = cluster.getRexBuilder().makeInputRef( field.getType(), offset + fieldOrdinal ); if ( frame.alg.getModel() == NamespaceType.DOCUMENT ) { @@ -1459,7 +1459,7 @@ public RexCall lpgNodeMatch( List labels ) { RexBuilder rexBuilder = getRexBuilder(); Operator op = OperatorRegistry.get( QueryLanguage.from( "cypher" ), OperatorName.CYPHER_NODE_MATCH ); AlgDataType nodeType = getTypeFactory().createPolyType( PolyType.NODE ); - return (RexCall) rexBuilder.makeCall( nodeType, op, List.of( rexBuilder.makeInputRef( peek().getRowType().getFieldList().get( 0 ).getType(), 0 ), new RexLiteral( new PolyNode( new PolyDictionary(), PolyList.copyOf( labels ), null ), nodeType, PolyType.NODE ) ) ); + return (RexCall) rexBuilder.makeCall( nodeType, op, List.of( rexBuilder.makeInputRef( peek().getRowType().getFields().get( 0 ).getType(), 0 ), new RexLiteral( new PolyNode( new PolyDictionary(), PolyList.copyOf( labels ), null ), nodeType, PolyType.NODE ) ) ); } @@ -1597,7 +1597,7 @@ public AlgBuilder project( Iterable nodes, Iterable f // Carefully build a list of fields, so that table aliases from the input can be seen for fields that are based on a RexInputRef. final Frame frame1 = stack.pop(); final List relFields = new ArrayList<>(); - for ( AlgDataTypeField f : project.getInput().getRowType().getFieldList() ) { + for ( AlgDataTypeField f : project.getInput().getRowType().getFields() ) { relFields.add( new RelField( ImmutableSet.of(), f ) ); } for ( Pair pair : Pair.zip( project.getProjects(), frame1.structured ) ) { @@ -1766,7 +1766,7 @@ public AlgBuilder rename( List fieldNames ) { // Special treatment for VALUES. Re-build it rather than add a project. final Values v = (Values) build(); final AlgDataTypeFactory.Builder b = getTypeFactory().builder(); - for ( Pair p : Pair.zip( newFieldNames, v.getRowType().getFieldList() ) ) { + for ( Pair p : Pair.zip( newFieldNames, v.getRowType().getFields() ) ) { b.add( null, p.left, null, p.right.getType() ); } return values( v.tuples, b.build() ); @@ -1930,7 +1930,7 @@ public AlgBuilder aggregate( GroupKey groupKey, Iterable aggCalls ) { // build field list final ImmutableList.Builder fields = ImmutableList.builder(); - final List aggregateFields = aggregate.getRowType().getFieldList(); + final List aggregateFields = aggregate.getRowType().getFields(); int i = 0; // first, group fields for ( Integer groupField : groupSet.asList() ) { @@ -2555,8 +2555,8 @@ protected AlgNode buildSubstitutionJoin( AlgNode nodesScan, AlgNode propertiesSc RexNode nodeCondition = builder.makeCall( OperatorRegistry.get( OperatorName.EQUALS ), - builder.makeInputRef( nodesScan.getRowType().getFieldList().get( 0 ).getType(), 0 ), - builder.makeInputRef( propertiesScan.getRowType().getFieldList().get( 0 ).getType(), nodesScan.getRowType().getFieldList().size() ) ); + builder.makeInputRef( nodesScan.getRowType().getFields().get( 0 ).getType(), 0 ), + builder.makeInputRef( propertiesScan.getRowType().getFields().get( 0 ).getType(), nodesScan.getRowType().getFields().size() ) ); return new LogicalJoin( nodesScan.getCluster(), out, nodesScan, propertiesScan, nodeCondition, Set.of(), JoinAlgType.LEFT, false, ImmutableList.of() ); } @@ -2628,7 +2628,7 @@ public AlgBuilder match( } final AlgDataType inputRowType = peek().getRowType(); - for ( AlgDataTypeField fs : inputRowType.getFieldList() ) { + for ( AlgDataTypeField fs : inputRowType.getFields() ) { if ( !typeBuilder.nameExists( fs.getName() ) ) { typeBuilder.add( fs ); } @@ -3017,7 +3017,7 @@ private Frame( AlgNode alg ) { return; } ImmutableList.Builder builder = ImmutableList.builder(); - for ( AlgDataTypeField field : alg.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : alg.getRowType().getFields() ) { builder.add( new RelField( aliases, field ) ); } this.alg = alg; diff --git a/core/src/main/java/org/polypheny/db/type/PathType.java b/core/src/main/java/org/polypheny/db/type/PathType.java index b6599c36b2..7e0f5cf8e0 100644 --- a/core/src/main/java/org/polypheny/db/type/PathType.java +++ b/core/src/main/java/org/polypheny/db/type/PathType.java @@ -37,7 +37,7 @@ protected PathType( boolean isNullable, List fields ) { protected void generateTypeString( StringBuilder sb, boolean withDetail ) { int i = 0; sb.append( " Path(" ); - for ( AlgDataTypeField field : fieldList ) { + for ( AlgDataTypeField field : fields ) { if ( i != 0 ) { sb.append( ", " ); } diff --git a/core/src/main/java/org/polypheny/db/type/PolyTypeFactoryImpl.java b/core/src/main/java/org/polypheny/db/type/PolyTypeFactoryImpl.java index 39192419b1..4cbf6213af 100644 --- a/core/src/main/java/org/polypheny/db/type/PolyTypeFactoryImpl.java +++ b/core/src/main/java/org/polypheny/db/type/PolyTypeFactoryImpl.java @@ -494,7 +494,7 @@ private AlgDataType copyObjectType( AlgDataType type, boolean nullable ) { return new ObjectPolyType( type.getPolyType(), nullable, - type.getFieldList(), + type.getFields(), type.getComparability() ); } diff --git a/core/src/main/java/org/polypheny/db/type/PolyTypeTransforms.java b/core/src/main/java/org/polypheny/db/type/PolyTypeTransforms.java index 2cee9b0c3c..8cb7aedfe0 100644 --- a/core/src/main/java/org/polypheny/db/type/PolyTypeTransforms.java +++ b/core/src/main/java/org/polypheny/db/type/PolyTypeTransforms.java @@ -168,7 +168,7 @@ private PolyType toVar( AlgDataType type ) { */ public static final PolyTypeTransform ONLY_COLUMN = ( opBinding, typeToTransform ) -> { - final List fields = typeToTransform.getFieldList(); + final List fields = typeToTransform.getFields(); assert fields.size() == 1; return fields.get( 0 ).getType(); }; diff --git a/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java b/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java index 2e0b835124..ece6a4ea59 100644 --- a/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java +++ b/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java @@ -248,7 +248,7 @@ public static boolean containsNullable( AlgDataType type ) { if ( !type.isStruct() ) { return false; } - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { if ( containsNullable( field.getType() ) ) { return true; } @@ -511,8 +511,8 @@ public static boolean sameNamedType( AlgDataType t1, AlgDataType t2 ) { if ( t1.getFieldCount() != t2.getFieldCount() ) { return false; } - List fields1 = t1.getFieldList(); - List fields2 = t2.getFieldList(); + List fields1 = t1.getFields(); + List fields2 = t2.getFields(); for ( int i = 0; i < fields1.size(); ++i ) { if ( !sameNamedType( fields1.get( i ).getType(), fields2.get( i ).getType() ) ) { return false; @@ -722,9 +722,9 @@ public static boolean canCastFrom( AlgDataType toType, AlgDataType fromType, boo // can't cast between different distinct types return false; } - return canCastFrom( toType.getFieldList().get( 0 ).getType(), fromType, coerce ); + return canCastFrom( toType.getFields().get( 0 ).getType(), fromType, coerce ); } else if ( fromTypeName == PolyType.DISTINCT ) { - return canCastFrom( toType, fromType.getFieldList().get( 0 ).getType(), coerce ); + return canCastFrom( toType, fromType.getFields().get( 0 ).getType(), coerce ); } else if ( toTypeName == PolyType.ROW ) { if ( fromTypeName != PolyType.ROW ) { return false; @@ -734,8 +734,8 @@ public static boolean canCastFrom( AlgDataType toType, AlgDataType fromType, boo return false; } for ( int i = 0; i < n; ++i ) { - AlgDataTypeField toField = toType.getFieldList().get( i ); - AlgDataTypeField fromField = fromType.getFieldList().get( i ); + AlgDataTypeField toField = toType.getFields().get( i ); + AlgDataTypeField fromField = fromType.getFields().get( i ); if ( !canCastFrom( toField.getType(), fromField.getType(), coerce ) ) { return false; } @@ -833,7 +833,7 @@ private static boolean flattenFields( AlgDataTypeFactory typeFactory, AlgDataTyp list.add( nullIndicatorField ); nested = true; } - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { if ( flatteningMap != null ) { flatteningMap[field.getIndex()] = list.size(); } @@ -940,7 +940,7 @@ public static boolean equalSansNullability( AlgDataTypeFactory factory, AlgDataT * @return Ordinal of field */ public static int findField( AlgDataType type, String fieldName ) { - List fields = type.getFieldList(); + List fields = type.getFields(); for ( int i = 0; i < fields.size(); i++ ) { AlgDataTypeField field = fields.get( i ); if ( field.getName().equals( fieldName ) ) { @@ -961,7 +961,7 @@ public static int findField( AlgDataType type, String fieldName ) { * @return list of data types that are requested by requiredFields */ public static List projectTypes( final AlgDataType rowType, final List requiredFields ) { - final List fields = rowType.getFieldList(); + final List fields = rowType.getFields(); return new AbstractList<>() { @Override @@ -995,7 +995,7 @@ public static AlgDataType createEmptyStructType( AlgDataTypeFactory typeFactory */ public static boolean isFlat( AlgDataType type ) { if ( type.isStruct() ) { - for ( AlgDataTypeField field : type.getFieldList() ) { + for ( AlgDataTypeField field : type.getFields() ) { if ( field.getType().isStruct() ) { return false; } @@ -1023,7 +1023,7 @@ public static boolean isComparable( AlgDataType type1, AlgDataType type2 ) { if ( n != type2.getFieldCount() ) { return false; } - for ( Pair pair : Pair.zip( type1.getFieldList(), type2.getFieldList() ) ) { + for ( Pair pair : Pair.zip( type1.getFields(), type2.getFields() ) ) { if ( !isComparable( pair.left.getType(), pair.right.getType() ) ) { return false; } @@ -1151,7 +1151,7 @@ private static boolean isSameFamily( AlgDataType type1, AlgDataType type2 ) { if ( n != type2.getFieldCount() ) { return false; } - for ( Pair pair : Pair.zip( type1.getFieldList(), type2.getFieldList() ) ) { + for ( Pair pair : Pair.zip( type1.getFields(), type2.getFields() ) ) { if ( !isSameFamily( pair.left.getType(), pair.right.getType() ) ) { return false; } diff --git a/core/src/main/java/org/polypheny/db/type/checker/OperandTypes.java b/core/src/main/java/org/polypheny/db/type/checker/OperandTypes.java index 68b7159035..bd4918a404 100644 --- a/core/src/main/java/org/polypheny/db/type/checker/OperandTypes.java +++ b/core/src/main/java/org/polypheny/db/type/checker/OperandTypes.java @@ -445,10 +445,10 @@ public boolean checkSingleOperandType( CallBinding callBinding, Node node, int i boolean validationError = false; if ( !type.isStruct() ) { validationError = true; - } else if ( type.getFieldList().size() != 1 ) { + } else if ( type.getFields().size() != 1 ) { validationError = true; } else { - PolyType typeName = type.getFieldList().get( 0 ).getType().getPolyType(); + PolyType typeName = type.getFields().get( 0 ).getType().getPolyType(); if ( typeName != PolyType.MULTISET && typeName != PolyType.ARRAY ) { validationError = true; } @@ -518,7 +518,7 @@ public boolean checkSingleOperandType( CallBinding callBinding, Node node, int i boolean validationError = false; if ( !type.isStruct() ) { validationError = true; - } else if ( type.getFieldList().size() != 1 ) { + } else if ( type.getFields().size() != 1 ) { validationError = true; } @@ -578,9 +578,9 @@ public boolean checkSingleOperandType( CallBinding callBinding, Node node, int i assert 0 == iFormalOperand; AlgDataType type = callBinding.getValidator().deriveType( callBinding.getScope(), node ); boolean valid = false; - if ( type.isStruct() && type.getFieldList().size() == 2 ) { - final AlgDataType t0 = type.getFieldList().get( 0 ).getType(); - final AlgDataType t1 = type.getFieldList().get( 1 ).getType(); + if ( type.isStruct() && type.getFields().size() == 2 ) { + final AlgDataType t0 = type.getFields().get( 0 ).getType(); + final AlgDataType t1 = type.getFields().get( 1 ).getType(); if ( PolyTypeUtil.isDatetime( t0 ) ) { if ( PolyTypeUtil.isDatetime( t1 ) ) { // t0 must be comparable with t1; (DATE, TIMESTAMP) is not valid diff --git a/core/src/main/java/org/polypheny/db/type/checker/SetopOperandTypeChecker.java b/core/src/main/java/org/polypheny/db/type/checker/SetopOperandTypeChecker.java index 98d7530411..e3f0561816 100644 --- a/core/src/main/java/org/polypheny/db/type/checker/SetopOperandTypeChecker.java +++ b/core/src/main/java/org/polypheny/db/type/checker/SetopOperandTypeChecker.java @@ -63,7 +63,7 @@ public boolean checkOperandTypes( CallBinding callBinding, boolean throwOnFailur } // Each operand must have the same number of columns. - final List fields = argType.getFieldList(); + final List fields = argType.getFields(); if ( i == 0 ) { colCount = fields.size(); continue; @@ -90,7 +90,7 @@ public boolean checkOperandTypes( CallBinding callBinding, boolean throwOnFailur new AbstractList() { @Override public AlgDataType get( int index ) { - return argTypes[index].getFieldList().get( i2 ).getType(); + return argTypes[index].getFields().get( i2 ).getType(); } diff --git a/core/src/main/java/org/polypheny/db/type/inference/InferTypes.java b/core/src/main/java/org/polypheny/db/type/inference/InferTypes.java index dcf02058f2..9e724e55dc 100644 --- a/core/src/main/java/org/polypheny/db/type/inference/InferTypes.java +++ b/core/src/main/java/org/polypheny/db/type/inference/InferTypes.java @@ -68,7 +68,7 @@ private InferTypes() { for ( int i = 0; i < operandTypes.length; ++i ) { operandTypes[i] = returnType.isStruct() - ? returnType.getFieldList().get( i ).getType() + ? returnType.getFields().get( i ).getType() : returnType; } }; diff --git a/core/src/main/java/org/polypheny/db/type/inference/ReturnTypes.java b/core/src/main/java/org/polypheny/db/type/inference/ReturnTypes.java index 3e74bf3f14..fe89f48f56 100644 --- a/core/src/main/java/org/polypheny/db/type/inference/ReturnTypes.java +++ b/core/src/main/java/org/polypheny/db/type/inference/ReturnTypes.java @@ -541,7 +541,7 @@ public int size() { final AlgDataType recordMultisetType = opBinding.getOperandType( 0 ); AlgDataType multisetType = recordMultisetType.getComponentType(); assert multisetType != null : "expected a multiset type: " + recordMultisetType; - final List fields = multisetType.getFieldList(); + final List fields = multisetType.getFields(); assert fields.size() > 0; final AlgDataType firstColType = fields.get( 0 ).getType(); return opBinding.getTypeFactory().createMultisetType( firstColType, -1 ); @@ -573,7 +573,7 @@ public int size() { assert isStruct && (fieldCount == 1); - AlgDataTypeField fieldType = recordType.getFieldList().get( 0 ); + AlgDataTypeField fieldType = recordType.getFields().get( 0 ); assert fieldType != null : "expected a record type with one field: " + recordType; final AlgDataType firstColType = fieldType.getType(); return opBinding.getTypeFactory().createTypeWithNullability( firstColType, true ); diff --git a/core/src/main/java/org/polypheny/db/type/inference/TableFunctionReturnTypeInference.java b/core/src/main/java/org/polypheny/db/type/inference/TableFunctionReturnTypeInference.java index 8f8acac38c..0ee2a6ac34 100644 --- a/core/src/main/java/org/polypheny/db/type/inference/TableFunctionReturnTypeInference.java +++ b/core/src/main/java/org/polypheny/db/type/inference/TableFunctionReturnTypeInference.java @@ -62,7 +62,7 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { AlgDataType unexpandedOutputType = protoType.apply( opBinding.getTypeFactory() ); List expandedOutputTypes = new ArrayList<>(); List expandedFieldNames = new ArrayList<>(); - for ( AlgDataTypeField field : unexpandedOutputType.getFieldList() ) { + for ( AlgDataTypeField field : unexpandedOutputType.getFields() ) { AlgDataType fieldType = field.getType(); String fieldName = field.getName(); if ( fieldType.getPolyType() != PolyType.CURSOR ) { @@ -117,7 +117,7 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { for ( String columnName : columnNames ) { iInputColumn = -1; AlgDataTypeField cursorField = null; - for ( AlgDataTypeField cField : cursorType.getFieldList() ) { + for ( AlgDataTypeField cField : cursorType.getFields() ) { ++iInputColumn; if ( cField.getName().equals( columnName ) ) { cursorField = cField; @@ -128,7 +128,7 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { } } else { iInputColumn = -1; - for ( AlgDataTypeField cursorField : cursorType.getFieldList() ) { + for ( AlgDataTypeField cursorField : cursorType.getFields() ) { ++iInputColumn; addOutputColumn( expandedFieldNames, expandedOutputTypes, iInputColumn, iCursor, opBinding, cursorField ); } diff --git a/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java b/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java index 2d8b0fe3c0..c200c913db 100644 --- a/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java +++ b/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java @@ -39,7 +39,7 @@ public NullInitializerExpressionFactory() { @Override public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { - return table.getRowType().getFieldList().get( iColumn ).getType().isNullable() + return table.getRowType().getFields().get( iColumn ).getType().isNullable() ? ColumnStrategy.NULLABLE : ColumnStrategy.NOT_NULLABLE; } diff --git a/core/src/main/java/org/polypheny/db/util/ValidatorUtil.java b/core/src/main/java/org/polypheny/db/util/ValidatorUtil.java index f9ffe9b5fb..4db0df3780 100644 --- a/core/src/main/java/org/polypheny/db/util/ValidatorUtil.java +++ b/core/src/main/java/org/polypheny/db/util/ValidatorUtil.java @@ -104,9 +104,9 @@ public static AlgDataType createJoinType( AlgDataTypeFactory typeFactory, AlgDat ? new HashSet<>() : new TreeSet<>( String.CASE_INSENSITIVE_ORDER ); addFields( systemFieldList, typeList, nameList, ids, uniqueNameList ); - addFields( leftType.getFieldList(), typeList, nameList, ids, uniqueNameList ); + addFields( leftType.getFields(), typeList, nameList, ids, uniqueNameList ); if ( rightType != null ) { - addFields( rightType.getFieldList(), typeList, nameList, ids, uniqueNameList ); + addFields( rightType.getFields(), typeList, nameList, ids, uniqueNameList ); } if ( fieldNameList != null ) { assert fieldNameList.size() == nameList.size(); @@ -275,7 +275,7 @@ public static AlgDataType createTypeFromProjection( AlgDataType type, List fields = new ArrayList<>( columnNameList.size() ); for ( String name : columnNameList ) { AlgDataTypeField field = type.getField( name, caseSensitive, false ); - fields.add( type.getFieldList().get( field.getIndex() ) ); + fields.add( type.getFields().get( field.getIndex() ) ); } return typeFactory.createStructType( fields ); } diff --git a/core/src/main/java/org/polypheny/db/view/ViewManager.java b/core/src/main/java/org/polypheny/db/view/ViewManager.java index e8145aa86f..46f5fc75a6 100644 --- a/core/src/main/java/org/polypheny/db/view/ViewManager.java +++ b/core/src/main/java/org/polypheny/db/view/ViewManager.java @@ -56,7 +56,7 @@ public class ViewManager { public static LogicalSort orderMaterialized( AlgNode other ) { - int positionPrimary = other.getRowType().getFieldList().size() - 1; + int positionPrimary = other.getRowType().getFields().size() - 1; AlgFieldCollation algFieldCollation = new AlgFieldCollation( positionPrimary, Direction.ASCENDING ); AlgCollations.of( algFieldCollation ); diff --git a/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java b/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java index b77f6a8cf3..74036bb788 100644 --- a/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java +++ b/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java @@ -61,7 +61,7 @@ public List>> resolveColumn( AlgDataType row if ( subMap != null ) { Integer index = subMap.get( names.get( 1 ) ); if ( index != null ) { - ret.add( new Pair<>( rowType.getFieldList().get( index ), names.subList( 2, names.size() ) ) ); + ret.add( new Pair<>( rowType.getFields().get( index ), names.subList( 2, names.size() ) ) ); } } } @@ -70,7 +70,7 @@ public List>> resolveColumn( AlgDataType row final List remainder = names.subList( 1, names.size() ); Integer index = nameMap.get( columnName ); if ( index != null ) { - ret.add( new Pair<>( rowType.getFieldList().get( index ), remainder ) ); + ret.add( new Pair<>( rowType.getFields().get( index ), remainder ) ); return ret; } @@ -80,7 +80,7 @@ public List>> resolveColumn( AlgDataType row if ( subMap != null ) { index = subMap.get( columnName ); if ( index != null ) { - ret.add( new Pair<>( rowType.getFieldList().get( index ), remainder ) ); + ret.add( new Pair<>( rowType.getFields().get( index ), remainder ) ); return ret; } } @@ -91,7 +91,7 @@ public List>> resolveColumn( AlgDataType row } index = entry.getValue().get( columnName ); if ( index != null ) { - ret.add( new Pair<>( rowType.getFieldList().get( index ), remainder ) ); + ret.add( new Pair<>( rowType.getFields().get( index ), remainder ) ); } } @@ -111,8 +111,8 @@ public List>> resolveColumn( AlgDataType row private static AlgDataType createStructType( final AlgDataType rowType, AlgDataTypeFactory typeFactory, final List> entries ) { return typeFactory.createStructType( StructKind.PEEK_FIELDS, - rowType.getFieldList().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), - entries.stream().map( e -> rowType.getFieldList().get( e.getValue() ).getType() ).collect( Collectors.toList() ), + rowType.getFields().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + entries.stream().map( e -> rowType.getFields().get( e.getValue() ).getType() ).collect( Collectors.toList() ), entries.stream().map( Entry::getKey ).collect( Collectors.toList() ) ); } diff --git a/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java b/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java index a44204ad6f..bf991241b4 100644 --- a/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java +++ b/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java @@ -52,7 +52,7 @@ public class CountingFactory extends NullInitializerExpressionFactory { @Override public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { - final AlgDataTypeField field = table.getRowType().getFieldList().get( iColumn ); + final AlgDataTypeField field = table.getRowType().getFields().get( iColumn ); if ( defaultColumns.contains( field.getName() ) ) { return ColumnStrategy.DEFAULT; } @@ -63,7 +63,7 @@ public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { @Override public RexNode newColumnDefaultValue( LogicalEntity table, int iColumn, InitializerContext context ) { THREAD_CALL_COUNT.get().incrementAndGet(); - final AlgDataTypeField field = table.getRowType().getFieldList().get( iColumn ); + final AlgDataTypeField field = table.getRowType().getFields().get( iColumn ); if ( defaultColumns.contains( field.getName() ) ) { final RexBuilder rexBuilder = context.getRexBuilder(); return rexBuilder.makeExactLiteral( BigDecimal.ONE ); diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java index d63578337a..941283a3d8 100644 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java +++ b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java @@ -188,7 +188,7 @@ private static List deduceMonotonicity( LogicalEntity table ) { // Deduce which fields the table is sorted on. int i = -1; - for ( AlgDataTypeField field : table.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : table.getRowType().getFields() ) { ++i; final Monotonicity monotonicity = Util.getMonotonicity( table, field.getName() ); if ( monotonicity != Monotonicity.NOT_MONOTONIC ) { diff --git a/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java b/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java index ad770046f5..636d45114f 100644 --- a/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java +++ b/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java @@ -88,7 +88,7 @@ public JavaTypeFactory getTypeFactory() { private static final AlgDataType EMP_ROW = EMP_SCAN.getRowType(); private static final AlgDataType DEPT_ROW = DEPT_SCAN.getRowType(); - private static final List EMP_DEPT_JOIN_REL_FIELDS = Lists.newArrayList( Iterables.concat( EMP_ROW.getFieldList(), DEPT_ROW.getFieldList() ) ); + private static final List EMP_DEPT_JOIN_REL_FIELDS = Lists.newArrayList( Iterables.concat( EMP_ROW.getFields(), DEPT_ROW.getFields() ) ); public RelOptUtilTest() { 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 c2d5bb9bbf..5aa8ccec2d 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -1802,7 +1802,7 @@ private List getColumnInformation( List projectedColum List columns = new ArrayList<>(); int position = 1; - for ( AlgDataTypeField alg : fieldList.getFieldList() ) { + for ( AlgDataTypeField alg : fieldList.getFields() ) { AlgDataType type = alg.getType(); if ( alg.getType().getPolyType() == PolyType.ARRAY ) { type = alg.getType().getComponentType(); @@ -1874,7 +1874,7 @@ private List getUnderlyingColumns( AlgNode algNode, AlgDataType fieldList List logicalColumnNames = columns.stream().map( c -> c.name ).collect( Collectors.toList() ); List underlyingColumns = new ArrayList<>(); for ( int i = 0; i < columns.size(); i++ ) { - for ( AlgDataTypeField algDataTypeField : fieldList.getFieldList() ) { + for ( AlgDataTypeField algDataTypeField : fieldList.getFields() ) { String name = logicalColumnNames.get( i ); if ( algDataTypeField.getName().equals( name ) ) { underlyingColumns.add( columns.get( i ).id ); 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 7eeeb2a7e7..4427dd4e81 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -718,7 +718,7 @@ public AlgNode visit( AlgNode node ) { for ( final List row : rows ) { final List record = new ArrayList<>(); for ( int i = 0; i < row.size(); ++i ) { - AlgDataType fieldType = originalProject.getRowType().getFieldList().get( i ).getType(); + AlgDataType fieldType = originalProject.getRowType().getFields().get( i ).getType(); Pair converted = RexLiteral.convertType( row.get( i ), fieldType ); record.add( new RexLiteral( converted.left, @@ -875,7 +875,7 @@ public AlgNode visit( LogicalProject project ) { return super.visit( project ); } final RexIndexRef rir = (RexIndexRef) expr; - final AlgDataTypeField field = scan.getRowType().getFieldList().get( rir.getIndex() ); + final AlgDataTypeField field = scan.getRowType().getFields().get( rir.getIndex() ); final String column = field.getName(); columns.add( column ); ctypes.add( field.getType() ); @@ -1045,7 +1045,7 @@ private List routeCached( AlgRoot logicalRoot, List parameterize( AlgRoot routedRoot, AlgDataType parameterRowType ) { AlgNode routed = routedRoot.alg; List parameterRowTypeList = new ArrayList<>(); - parameterRowType.getFieldList().forEach( algDataTypeField -> parameterRowTypeList.add( algDataTypeField.getType() ) ); + parameterRowType.getFields().forEach( algDataTypeField -> parameterRowTypeList.add( algDataTypeField.getType() ) ); // Parameterize QueryParameterizer queryParameterizer = new QueryParameterizer( parameterRowType.getFieldCount(), parameterRowTypeList, routed.getTraitSet().contains( ModelTrait.GRAPH ) ); diff --git a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java index f8606f119f..c5f3563c61 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java +++ b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java @@ -344,7 +344,7 @@ public void executeQuery( List selectedColumns, AlgRoot source Map resultColMapping = new HashMap<>(); for ( AllocationColumn column : selectedColumns ) { int i = 0; - for ( AlgDataTypeField metaData : implementation.getRowType().getFieldList() ) { + for ( AlgDataTypeField metaData : implementation.getRowType().getFields() ) { if ( metaData.getName().equalsIgnoreCase( column.getLogicalColumnName() ) ) { resultColMapping.put( column.getColumnId(), i ); } @@ -390,9 +390,9 @@ public void executeQuery( List selectedColumns, AlgRoot source } List fields; if ( isMaterializedView ) { - fields = targetAlg.alg.getEntity().getRowType().getFieldList(); + fields = targetAlg.alg.getEntity().getRowType().getFields(); } else { - fields = sourceAlg.validatedRowType.getFieldList(); + fields = sourceAlg.validatedRowType.getFields(); } for ( Map.Entry> v : values.entrySet() ) { @@ -642,7 +642,7 @@ public void copySelectiveData( Transaction transaction, LogicalAdapter store, Lo Map resultColMapping = new HashMap<>(); for ( LogicalColumn logicalColumn : selectColumnList ) { int i = 0; - for ( AlgDataTypeField metaData : result.getRowType().getFieldList() ) { + for ( AlgDataTypeField metaData : result.getRowType().getFields() ) { if ( metaData.getName().equalsIgnoreCase( logicalColumn.name ) ) { resultColMapping.put( logicalColumn.id, i ); } @@ -968,7 +968,7 @@ public void copyPartitionDataOld( Transaction transaction, LogicalAdapter store, Map resultColMapping = new HashMap<>(); for ( LogicalColumn logicalColumn : selectColumnList ) { int i = 0; - for ( AlgDataTypeField metaData : result.getRowType().getFieldList() ) { + for ( AlgDataTypeField metaData : result.getRowType().getFields() ) { if ( metaData.getName().equalsIgnoreCase( logicalColumn.name ) ) { resultColMapping.put( logicalColumn.id, i ); } 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 f3f771baf6..127fc82326 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 @@ -274,7 +274,7 @@ public AlgNode visit( LogicalRelModify initial ) { } else { idx = idxMapping.get( i ); } - AlgDataType type = input.getRowType().getFieldList().get( i ).getType(); + AlgDataType type = input.getRowType().getFields().get( i ).getType(); if ( firstRow ) { projects.add( new RexDynamicParam( type, idx ) ); } @@ -338,7 +338,7 @@ public AlgNode visitAsymmetricModify( LogicalRelModify initial ) { } else { idx = idxMapping.get( i ); } - AlgDataType type = input.getRowType().getFieldList().get( i ).getType(); + AlgDataType type = input.getRowType().getFields().get( i ).getType(); if ( firstRow ) { projects.add( new RexDynamicParam( type, idx ) ); } @@ -402,7 +402,7 @@ public AlgNode visit( LogicalDocumentModify initial ) { idx = idxMapping.get( i ); } - AlgDataType type = input.getRowType().getFieldList().get( i ).getType(); + AlgDataType type = input.getRowType().getFields().get( i ).getType(); if ( firstRow ) { projects.put( null, new RexDynamicParam( type, idx ) ); } diff --git a/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java b/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java index 9457221237..0cdd58198b 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java +++ b/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java @@ -246,8 +246,8 @@ public RoutedAlgBuilder handleRelScan( if ( table.getRowType().getFieldCount() == builder.peek().getRowType().getFieldCount() && !table.getRowType().equals( builder.peek().getRowType() ) ) { // we adjust the - Map namesIndexMapping = table.getRowType().getFieldList().stream().collect( Collectors.toMap( AlgDataTypeField::getName, AlgDataTypeField::getIndex ) ); - List target = builder.peek().getRowType().getFieldList().stream().map( f -> namesIndexMapping.get( f.getName() ) ).collect( Collectors.toList() ); + Map namesIndexMapping = table.getRowType().getFields().stream().collect( Collectors.toMap( AlgDataTypeField::getName, AlgDataTypeField::getIndex ) ); + List target = builder.peek().getRowType().getFields().stream().map( f -> namesIndexMapping.get( f.getName() ) ).collect( Collectors.toList() ); builder.permute( Mappings.bijection( target ) ); } 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 ffe4b482e9..559080b6eb 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 @@ -344,8 +344,8 @@ private Triple handleDmlInsert( List updateColumn if ( modify.getInput() instanceof LogicalValues ) { // Get fieldList and map columns to index since they could be in arbitrary order int partitionColumnIndex = -1; - for ( int j = 0; j < (modify.getInput()).getRowType().getFieldList().size(); j++ ) { - String columnFieldName = (modify.getInput()).getRowType().getFieldList().get( j ).getName(); + for ( int j = 0; j < (modify.getInput()).getRowType().getFields().size(); j++ ) { + String columnFieldName = (modify.getInput()).getRowType().getFields().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 ); @@ -925,7 +925,7 @@ private AlgBuilder handleSelectFromOtherTable( RoutedAlgBuilder builder, Logical private void dmlConditionCheck( LogicalFilter node, LogicalTable catalogTable, List placements, RexNode operand ) { if ( operand instanceof RexIndexRef ) { int index = ((RexIndexRef) operand).getIndex(); - AlgDataTypeField field = node.getInput().getRowType().getFieldList().get( index ); + AlgDataTypeField field = node.getInput().getRowType().getFields().get( index ); LogicalColumn column; String columnName; String[] columnNames = field.getName().split( "\\." ); diff --git a/dbms/src/test/java/org/polypheny/db/misc/AlgBuilderTest.java b/dbms/src/test/java/org/polypheny/db/misc/AlgBuilderTest.java index 82d866b242..21e7eea9a3 100644 --- a/dbms/src/test/java/org/polypheny/db/misc/AlgBuilderTest.java +++ b/dbms/src/test/java/org/polypheny/db/misc/AlgBuilderTest.java @@ -1528,7 +1528,7 @@ public void testAlias() { + " LogicalScan(model=[RELATIONAL], table=[[public, employee]])\n" + " LogicalScan(model=[RELATIONAL], table=[[public, department]])\n"; assertThat( root, Matchers.hasTree( expected ) ); - final AlgDataTypeField field = root.getRowType().getFieldList().get( 1 ); + final AlgDataTypeField field = root.getRowType().getFields().get( 1 ); assertThat( field.getName(), is( "name" ) ); assertThat( field.getType().isNullable(), is( true ) ); } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java index e035093ffd..4162b71ead 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java @@ -503,7 +503,7 @@ private AlgNode getAggregateColumn( QueryResult queryResult, NodeType nodeType, throw new GenericRuntimeException( "Unknown aggregate is used in Statistic Manager." ); } - AlgDataType relDataType = logicalProject.getRowType().getFieldList().get( 0 ).getType(); + AlgDataType relDataType = logicalProject.getRowType().getFields().get( 0 ).getType(); AlgDataType dataType; if ( relDataType.getPolyType() == PolyType.DECIMAL ) { dataType = cluster.getTypeFactory().createTypeWithNullability( diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index e620914680..ab546ffd7a 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -1382,7 +1382,7 @@ private Enumerable externalize( Enumerable enumerable, AlgD @Override public Enumerator enumerator() { List> transform = new ArrayList<>(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { transform.add( PolyValue.wrapNullableIfNecessary( PolyValue.getPolyToJava( field.getType(), true ), field.getType().isNullable() ) ); } boolean isSingle = rowType.getFieldCount() == 1; @@ -1745,7 +1745,7 @@ private RuntimeException propagate( Throwable e ) { public List deriveAvaticaParameters( AlgDataType parameterRowType ) { final List parameters = new ArrayList<>(); - for ( AlgDataTypeField field : parameterRowType.getFieldList() ) { + for ( AlgDataTypeField field : parameterRowType.getFields() ) { AlgDataType type = field.getType(); parameters.add( new AvaticaParameter( diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java index 0fe0be3a17..8d43adb9c3 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java @@ -90,7 +90,7 @@ public PolyphenyDbSignature( public static PolyphenyDbSignature from( PolyImplementation prepareQuery ) { final List parameters = new ArrayList<>(); if ( prepareQuery.rowType != null ) { - for ( AlgDataTypeField field : prepareQuery.rowType.getFieldList() ) { + for ( AlgDataTypeField field : prepareQuery.rowType.getFields() ) { AlgDataType type = field.getType(); parameters.add( new AvaticaParameter( diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailFilter.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailFilter.java index 6481f1462b..6fdb012008 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailFilter.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailFilter.java @@ -120,10 +120,10 @@ public static class Translator { public Translator( CottontailImplementContext context, AlgDataType rowType ) { this.rowType = rowType; - this.fieldNames = rowType.getFieldList().stream() + this.fieldNames = rowType.getFields().stream() .map( AlgDataTypeField::getPhysicalName ) .collect( Collectors.toList() ); - this.columnTypes = rowType.getFieldList().stream() + this.columnTypes = rowType.getFields().stream() .map( AlgDataTypeField::getType ) .map( AlgDataType::getPolyType ) .collect( Collectors.toList() ); diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java index c02d518a92..352e4ef71f 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java @@ -90,7 +90,7 @@ public void implement( CottontailImplementContext context ) { context.visitChild( 0, getInput() ); } - final List fieldList = context.cottontailTable.getRowType().getFieldList(); + final List fieldList = context.cottontailTable.getRowType().getFields(); final List physicalColumnNames = new ArrayList<>( fieldList.size() ); final List columnTypes = new ArrayList<>( fieldList.size() ); 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 746c10a30c..6724001ce3 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 @@ -147,7 +147,7 @@ private Expression buildUpdateTupleBuilder( CottontailImplementContext context ) final List physicalColumnNames = new ArrayList<>(); final List logicalColumnNames = new ArrayList<>(); final List columnTypes = new ArrayList<>(); - for ( AlgDataTypeField field : context.cottontailTable.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : context.cottontailTable.getRowType().getFields() ) { physicalColumnNames.add( context.cottontailTable.getPhysicalColumnName( field.getName() ) ); logicalColumnNames.add( field.getName() ); columnTypes.add( field.getType().getPolyType() ); diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java index 9d1b5d5d52..b26940fc9d 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java @@ -216,7 +216,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { * Generates accessor methods used to access data contained in {@link Tuple}s returned by Cottontail DB. */ private void generateGet( AlgDataType rowType, BlockBuilder blockBuilder, ParameterExpression result_, int i, Expression target ) { - final AlgDataType fieldType = rowType.getFieldList().get( i ).getType(); + final AlgDataType fieldType = rowType.getFields().get( i ).getType(); // Fetch Data from DataMap // This should generate: `result_.get()` diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java index 745417cdc8..b744d69b66 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java @@ -57,7 +57,7 @@ public void implement( CottontailImplementContext context ) { final List> physicalColumnNames = new ArrayList<>(); List tupleIndexes = new ArrayList<>(); int i = 0; - for ( AlgDataTypeField field : this.rowType.getFieldList() ) { + for ( AlgDataTypeField field : this.rowType.getFields() ) { try { physicalColumnNames.add( new Pair<>( context.cottontailTable.getPhysicalColumnName( field.getName() ), field.getType().getPolyType() ) ); tupleIndexes.add( i ); @@ -74,7 +74,7 @@ public void implement( CottontailImplementContext context ) { builder.add( Expressions.declare( Modifier.FINAL, valuesMap_, valuesMapCreator ) ); List values; - if ( this.rowType.getFieldList().size() > physicalColumnNames.size() ) { + if ( this.rowType.getFields().size() > physicalColumnNames.size() ) { values = new ArrayList<>(); for ( int idx : tupleIndexes ) { values.add( tuple.get( idx ) ); diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java index 44968b561b..2cec4d0ba5 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java @@ -129,7 +129,7 @@ public RowTypeParser( AlgDataType rowType, List physicalColumnNames ) { @Override public PolyValue[] apply( Tuple a0 ) { final PolyValue[] returnValue = new PolyValue[this.physicalColumnNames.size()]; - final List fieldList = this.rowType.getFieldList(); + final List fieldList = this.rowType.getFields(); for ( int i = 0; i < fieldList.size(); i++ ) { final AlgDataType type = fieldList.get( i ).getType(); returnValue[i] = this.parseSingleField( a0.get( i ), type ); 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 97e2570b2b..d76630a917 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 @@ -235,7 +235,7 @@ private AlgBuilder generateFilters( AlgBuilder algBuilder, RexBuilder rexBuilder AtomicReference secondToLastRexNode = new AtomicReference<>(); AlgDataType filtersRowType = baseNode.getRowType(); - List filtersRows = filtersRowType.getFieldList(); + List filtersRows = filtersRowType.getFields(); Map filterMap = new HashMap<>(); filtersRows.forEach( ( r ) -> filterMap.put( r.getName(), r ) ); diff --git a/plugins/cql-language/src/test/java/org/polypheny/db/cql/utils/FilterTest.java b/plugins/cql-language/src/test/java/org/polypheny/db/cql/utils/FilterTest.java index 6f3c16f0b0..3c5333d4ef 100644 --- a/plugins/cql-language/src/test/java/org/polypheny/db/cql/utils/FilterTest.java +++ b/plugins/cql-language/src/test/java/org/polypheny/db/cql/utils/FilterTest.java @@ -45,7 +45,7 @@ public FilterTest() throws UnknownIndexException { super( AlgBuildLevel.INITIAL_PROJECTION ); baseNode = algBuilder.peek(); AlgDataType filtersRowType = baseNode.getRowType(); - List filtersRows = filtersRowType.getFieldList(); + List filtersRows = filtersRowType.getFields(); filtersRows.forEach( ( r ) -> filterMap.put( r.getKey(), r ) ); } diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvScan.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvScan.java index 767f0fbcfc..a8169d6745 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvScan.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvScan.java @@ -90,7 +90,7 @@ public AlgWriter explainTerms( AlgWriter pw ) { @Override public AlgDataType deriveRowType() { - final List fieldList = entity.getRowType().getFieldList(); + final List fieldList = entity.getRowType().getFields(); final AlgDataTypeFactory.Builder builder = getCluster().getTypeFactory().builder(); for ( int field : fields ) { builder.add( fieldList.get( field ) ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherReturnClause.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherReturnClause.java index 8c75ede863..79a176f813 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherReturnClause.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherReturnClause.java @@ -121,7 +121,7 @@ private LogicalLpgAggregate getAggregate( CypherContext context, AlgNode node ) List groupIndexes = node .getRowType() - .getFieldList() + .getFields() .stream() .filter( f -> !aggNames.contains( f.getName() ) ) .map( AlgDataTypeField::getIndex ) diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherStarReturn.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherStarReturn.java index 26ef14c066..1f8e945451 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherStarReturn.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherStarReturn.java @@ -45,7 +45,7 @@ public boolean isStar() { public Pair getRex( CypherContext context, RexType type ) { AlgNode node = context.peek(); - for ( AlgDataTypeField field : node.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : node.getRowType().getFields() ) { context.add( Pair.of( PolyString.of( field.getName() ), context.rexBuilder.makeInputRef( field.getType(), field.getIndex() ) ) ); } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUnwind.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUnwind.java index 6c65e03aa8..2ea5f17402 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUnwind.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUnwind.java @@ -85,7 +85,7 @@ public void getUnwind( CypherContext context ) { AlgNode node = context.peek(); - if ( node.getRowType().getFieldList().size() != 1 ) { + if ( node.getRowType().getFields().size() != 1 ) { if ( !node.getRowType().getFieldNames().contains( namedNode.left ) ) { throw new UnsupportedOperationException(); } 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 fd120fcd54..5e7a723256 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 @@ -273,7 +273,7 @@ private void convertReturn( CypherReturnClause clause, CypherContext context ) { private AlgNode removeHiddenRows( CypherContext context, AlgNode node, List missingNames ) { List nodes = new ArrayList<>(); List names = new ArrayList<>(); - node.getRowType().getFieldList().forEach( f -> { + node.getRowType().getFields().forEach( f -> { if ( !missingNames.contains( f.getName() ) ) { nodes.add( context.rexBuilder.makeInputRef( f.getType(), f.getIndex() ) ); names.add( PolyString.of( f.getName() ) ); @@ -293,7 +293,7 @@ private AlgNode addHiddenRows( CypherContext context, AlgNode node, List } List> additional = new ArrayList<>(); - for ( AlgDataTypeField field : input.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : input.getRowType().getFields() ) { for ( String name : missingNames ) { String[] split = name.split( "\\." ); if ( split.length > 1 && split[0].equals( field.getName() ) ) { @@ -323,7 +323,7 @@ private AlgNode addHiddenRows( CypherContext context, AlgNode node, List nodes = new ArrayList<>(); names = new ArrayList<>(); - node.getRowType().getFieldList().forEach( f -> { + node.getRowType().getFields().forEach( f -> { nodes.add( context.rexBuilder.makeInputRef( f.getType(), f.getIndex() ) ); names.add( PolyString.of( f.getName() ) ); } ); @@ -511,8 +511,8 @@ public void combineFilter() { private void addProjectIfNecessary() { if ( stack.size() >= 1 && rexQueue.size() > 0 ) { AlgNode node = stack.peek(); - if ( node.getRowType().getFieldList().size() == 1 - && node.getRowType().getFieldList().get( 0 ).getType().getPolyType() == PolyType.GRAPH ) { + if ( node.getRowType().getFields().size() == 1 + && node.getRowType().getFields().get( 0 ).getType().getPolyType() == PolyType.GRAPH ) { node = stack.pop(); List> rex = new ArrayList<>(); @@ -723,7 +723,7 @@ public void combineValues() { AlgNode node = stack.peek(); List names = node.getRowType().getFieldNames(); - List fields = node.getRowType().getFieldList(); + List fields = node.getRowType().getFields(); // nodes can be added as literals for ( Pair namedNode : nodes ) { @@ -826,7 +826,7 @@ public RexNode getLabelUpdate( List labels, String variable, boolean rep if ( index < 0 ) { throw new GenericRuntimeException( String.format( "Unknown variable with name %s", variable ) ); } - AlgDataTypeField field = node.getRowType().getFieldList().get( index ); + AlgDataTypeField field = node.getRowType().getFields().get( index ); if ( field.getType().getPolyType() == PolyType.EDGE && labels.size() != 1 ) { throw new GenericRuntimeException( "Edges require exactly one label" ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java index 31c873eef4..96960ebec5 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherVariable.java @@ -61,12 +61,12 @@ public Pair getRex( CypherContext context, RexType type ) { // search r -> RowType(r:Edge) return Pair.of( PolyString.of( name ), - context.rexBuilder.makeInputRef( node.getRowType().getFieldList().get( index ).getType(), index ) ); + context.rexBuilder.makeInputRef( node.getRowType().getFields().get( index ).getType(), index ) ); } - for ( AlgDataTypeField field : node.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : node.getRowType().getFields() ) { if ( field.getType() instanceof PathType ) { - for ( AlgDataTypeField pathField : field.getType().getFieldList() ) { + for ( AlgDataTypeField pathField : field.getType().getFields() ) { if ( pathField.getName().equals( name ) ) { // search r -> RowType(Path(r:Edge, n:Node)) RexIndexRef pathRef = context.rexBuilder.makeInputRef( field.getType(), field.getIndex() ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/pattern/CypherEveryPathPattern.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/pattern/CypherEveryPathPattern.java index 72994000ac..cd6570f951 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/pattern/CypherEveryPathPattern.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/pattern/CypherEveryPathPattern.java @@ -130,7 +130,7 @@ public Pair getPatternMatch( CypherContext context ) { } RexNode path = getPathFilter( context ); - String name = path.getType().getFieldList().stream().map( AlgDataTypeField::getName ).collect( Collectors.joining( "-", "$", "$" ) ); + String name = path.getType().getFields().stream().map( AlgDataTypeField::getName ).collect( Collectors.joining( "-", "$", "$" ) ); return Pair.of( PolyString.of( name ), path ); } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveLabels.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveLabels.java index e4be4463fe..33c5726db0 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveLabels.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveLabels.java @@ -53,7 +53,7 @@ public void removeItem( CypherContext context ) { if ( index < 0 ) { throw new GenericRuntimeException( String.format( "Unknown variable with name %s", variable ) ); } - AlgDataTypeField field = node.getRowType().getFieldList().get( index ); + AlgDataTypeField field = node.getRowType().getFields().get( index ); if ( field.getType().getPolyType() == PolyType.EDGE && labels.size() != 1 ) { throw new GenericRuntimeException( "Edges require exactly one label" ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveProperty.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveProperty.java index 61dcb1f3ea..f2d8c6b882 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveProperty.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/remove/CypherRemoveProperty.java @@ -50,7 +50,7 @@ public void removeItem( CypherContext context ) { if ( index < 0 ) { throw new GenericRuntimeException( String.format( "Unknown variable with name %s", nodeName ) ); } - AlgDataTypeField field = node.getRowType().getFieldList().get( index ); + AlgDataTypeField field = node.getRowType().getFields().get( index ); RexNode ref = context.getRexNode( nodeName ); if ( ref == null ) { diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetProperty.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetProperty.java index 5d5b2a75c4..5f192f4c95 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetProperty.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetProperty.java @@ -53,7 +53,7 @@ public void convertItem( CypherContext context ) { if ( index < 0 ) { throw new GenericRuntimeException( String.format( "Unknown variable with name %s", nodeName ) ); } - AlgDataTypeField field = node.getRowType().getFieldList().get( index ); + AlgDataTypeField field = node.getRowType().getFields().get( index ); RexNode ref = context.getRexNode( nodeName ); if ( ref == null ) { diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetVariable.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetVariable.java index 2b51c81aaa..c00739279d 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetVariable.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/set/CypherSetVariable.java @@ -66,7 +66,7 @@ public void convertItem( CypherContext context ) { if ( index < 0 ) { throw new GenericRuntimeException( String.format( "Unknown variable with name %s", nodeName ) ); } - AlgDataTypeField field = node.getRowType().getFieldList().get( index ); + AlgDataTypeField field = node.getRowType().getFields().get( index ); RexNode ref = context.getRexNode( nodeName ); if ( ref == null ) { diff --git a/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumTable.java b/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumTable.java index f16e48c24b..17dd5b0da7 100644 --- a/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumTable.java +++ b/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumTable.java @@ -70,7 +70,7 @@ public EthereumTable( @Override public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - return typeFactory.createStructType( this.protoRowType.apply( typeFactory ).getFieldList() ); + return typeFactory.createStructType( this.protoRowType.apply( typeFactory ).getFields() ); } diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTableScan.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTableScan.java index c1f9fe4418..da464559ea 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTableScan.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTableScan.java @@ -67,7 +67,7 @@ public AlgWriter explainTerms( AlgWriter pw ) { @Override public AlgDataType deriveRowType() { - final List fieldList = entity.getRowType().getFieldList(); + final List fieldList = entity.getRowType().getFields(); final AlgDataTypeFactory.Builder builder = getCluster().getTypeFactory().builder(); for ( int field : fields ) { builder.add( fieldList.get( field ) ); diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java index e552b9b8fa..dce1db6407 100644 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java +++ b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java @@ -118,7 +118,7 @@ private ExploreQueryResult executeSqlSelect( final Statement statement, final St List typeInfo = new ArrayList<>(); List name = new ArrayList<>(); - for ( AlgDataTypeField metaData : result.getRowType().getFieldList() ) { + for ( AlgDataTypeField metaData : result.getRowType().getFields() ) { typeInfo.add( metaData.getType().getFullTypeString() ); name.add( metaData.getName() ); } 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 748ec038fe..9752e19950 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 @@ -120,7 +120,7 @@ public void implement( FileImplementor implementor ) { if ( inputRefsOnly ) { implementor.project( null, mapping ); } else { - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { if ( field.getName().startsWith( "EXPR$" ) ) { //don't set EXPR-columns in FileImplementor return; 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 b622b7bd72..4218a3dad7 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 @@ -55,7 +55,7 @@ public void implement( final FileImplementor implementor ) { return; } List columns = new ArrayList<>(); - for ( AlgDataTypeField type : recordType.getFieldList() ) { + for ( AlgDataTypeField type : recordType.getFields() ) { columns.add( type.getName() ); } implementor.setColumnNames( columns ); diff --git a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java index edc7def136..6569ccc7c1 100644 --- a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java +++ b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTable.java @@ -84,7 +84,7 @@ public String toString() { @Override public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - return typeFactory.createStructType( this.protoRowType.apply( typeFactory ).getFieldList() ); + return typeFactory.createStructType( this.protoRowType.apply( typeFactory ).getFields() ); } diff --git a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTableScanProject.java b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTableScanProject.java index ac6f691b7f..41b7eb59a2 100644 --- a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTableScanProject.java +++ b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetTableScanProject.java @@ -73,7 +73,7 @@ public AlgWriter explainTerms( AlgWriter pw ) { @Override public AlgDataType deriveRowType() { - final List fieldList = entity.getRowType().getFieldList(); + final List fieldList = entity.getRowType().getFields(); final AlgDataTypeFactory.Builder builder = getCluster().getTypeFactory().builder(); for ( int field : fields ) { builder.add( fieldList.get( field ) ); 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 69c750047f..5b4127fc84 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 @@ -603,7 +603,7 @@ private static boolean itemOperatorInFilter( Filter filter ) { private static boolean isStringComparableArrayType( Filter filter ) { - for ( AlgDataTypeField dataTypeField : filter.getRowType().getFieldList() ) { + for ( AlgDataTypeField dataTypeField : filter.getRowType().getFields() ) { if ( dataTypeField.getType().getPolyType() == PolyType.ARRAY ) { switch ( dataTypeField.getType().getComponentType().getPolyType() ) { case BOOLEAN: 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 51e1698821..e0aac5b7f4 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 @@ -121,7 +121,7 @@ public String toString() { private List> fieldClasses( final JavaTypeFactory typeFactory ) { final AlgDataType rowType = getRowType(); - return rowType.getFieldList().stream().map( f -> { + return rowType.getFields().stream().map( f -> { final AlgDataType type = f.getType(); final Class clazz = (Class) typeFactory.getJavaClass( type ); final Rep rep = Util.first( Rep.of( clazz ), Rep.OBJECT ); diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcToEnumerableConverter.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcToEnumerableConverter.java index a7b1059a88..16af97300a 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcToEnumerableConverter.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcToEnumerableConverter.java @@ -290,8 +290,8 @@ private void generateGet( Expression calendar_, CalendarPolicy calendarPolicy, SqlDialect dialect ) { - final Primitive primitive = Primitive.ofBoxOr( PolyValue.ofPrimitive( physType.fieldClass( i ), rowType.getFieldList().get( i ).getType().getPolyType() ) ); - final AlgDataType fieldType = physType.getRowType().getFieldList().get( i ).getType(); + final Primitive primitive = Primitive.ofBoxOr( PolyValue.ofPrimitive( physType.fieldClass( i ), rowType.getFields().get( i ).getType().getPolyType() ) ); + final AlgDataType fieldType = physType.getRowType().getFields().get( i ).getType(); final List dateTimeArgs = new ArrayList<>(); dateTimeArgs.add( Expressions.constant( i + 1 ) ); PolyType polyType = fieldType.getPolyType(); 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 3255d24922..857e8da9e1 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 @@ -418,7 +418,7 @@ public Result visit( Sort e ) { if ( stack.size() != 1 && builder.select.getSqlSelectList() == null ) { // Generates explicit column names instead of start(*) for non-root ORDER BY to avoid ambiguity. final List selectList = Expressions.list(); - for ( AlgDataTypeField field : e.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : e.getRowType().getFields() ) { addSelect( selectList, builder.context.field( field.getIndex() ), e.getRowType() ); } builder.select.setSelectList( new SqlNodeList( selectList, POS ) ); @@ -635,9 +635,9 @@ private SqlCall as( SqlNode e, String alias ) { @Override public void addSelect( List selectList, SqlNode node, AlgDataType rowType ) { //String name = rowType.getFieldNames().get( selectList.size() ); - String name = rowType.getFieldList().get( selectList.size() ).getPhysicalName(); + String name = rowType.getFields().get( selectList.size() ).getPhysicalName(); if ( name == null ) { - name = rowType.getFieldList().get( selectList.size() ).getName(); + name = rowType.getFields().get( selectList.size() ).getName(); } String alias = SqlValidatorUtil.getAlias( node, -1 ); final String lowerName = name.toLowerCase( Locale.ROOT ); diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java index b4908369a6..48b9ebf812 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/SqlImplementor.java @@ -1035,7 +1035,7 @@ protected AliasContext( SqlDialect dialect, Map aliases, bo @Override public SqlNode field( int ordinal ) { for ( Map.Entry alias : aliases.entrySet() ) { - final List fields = alias.getValue().getFieldList(); + final List fields = alias.getValue().getFields(); if ( ordinal < fields.size() ) { AlgDataTypeField field = fields.get( ordinal ); final SqlNode mappedSqlNode = ordinalMap.get( field.getName().toLowerCase( Locale.ROOT ) ); diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java index d1cf6764a1..0dec512d2d 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java @@ -63,7 +63,7 @@ public String getName( Long id ) { public static AlgRecordType fromRecordType( AlgRecordType rowType, MongoEntity mongoEntity ) { - return new MongoRowType( rowType.getStructKind(), rowType.getFieldList(), mongoEntity ); + return new MongoRowType( rowType.getStructKind(), rowType.getFields(), mongoEntity ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java index ff384423d8..d9472a518f 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java @@ -141,7 +141,7 @@ private static BsonArray getArgsArray( ImmutableList operands, AlgDataT private static BsonValue getVal( RexNode rexNode, AlgDataType rowType, Implementor implementor ) { if ( rexNode.isA( Kind.INPUT_REF ) ) { RexIndexRef rex = (RexIndexRef) rexNode; - return new BsonString( "$" + rowType.getFieldList().get( rex.getIndex() ).getPhysicalName() ); + return new BsonString( "$" + rowType.getFields().get( rex.getIndex() ).getPhysicalName() ); } else if ( rexNode.isA( Kind.ARRAY_VALUE_CONSTRUCTOR ) ) { RexCall rex = (RexCall) rexNode; return BsonUtil.getBsonArray( rex, implementor.getBucket() ); diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java index 5c611624a0..7814b72d56 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java @@ -1217,8 +1217,8 @@ private String getPhysicalName( RexIndexRef input ) { // DML (and also DDL) have to use the physical name, as they do not allow // to use projections beforehand if ( implementor.isDML() ) { - if ( rowType != null && rowType.getFieldList().get( input.getIndex() ) != null ) { - name = rowType.getFieldList().get( input.getIndex() ).getPhysicalName(); + if ( rowType != null && rowType.getFields().get( input.getIndex() ) != null ) { + name = rowType.getFields().get( input.getIndex() ).getPhysicalName(); } return name; } 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 364c9c9da8..feaddc00dd 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 @@ -146,7 +146,7 @@ static List mongoFieldNames( final AlgDataType rowType ) { new AbstractList<>() { @Override public String get( int index ) { - final String name = MongoRules.maybeFix( rowType.getFieldList().get( index ).getName() ); + final String name = MongoRules.maybeFix( rowType.getFields().get( index ).getName() ); return name.startsWith( "$" ) ? "_" + name.substring( 2 ) : name; } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java index fc0088fe05..0bc9601723 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java @@ -99,7 +99,7 @@ public void implement( Implementor implementor ) { implementor.setStaticRowType( (AlgRecordType) rowType ); return; } - implementor.list.add( Pair.of( null, new BsonDocument( "$project", new BsonDocument( rowType.getFieldList().stream().map( p -> new BsonElement( p.getName(), new BsonString( "$" + p.getPhysicalName() ) ) ).collect( Collectors.toList() ) ) ).toJson() ) ); + implementor.list.add( Pair.of( null, new BsonDocument( "$project", new BsonDocument( rowType.getFields().stream().map( p -> new BsonElement( p.getName(), new BsonString( "$" + p.getPhysicalName() ) ) ).collect( Collectors.toList() ) ) ).toJson() ) ); } } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java index 01baa761cf..a7110a3af8 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java @@ -66,7 +66,7 @@ public void implement( Implementor implementor ) { implementor.visitChild( 0, getInput() ); if ( !collation.getFieldCollations().isEmpty() ) { final List keys = new ArrayList<>(); - final List fields = getRowType().getFieldList(); + final List fields = getRowType().getFields(); for ( AlgFieldCollation fieldCollation : collation.getFieldCollations() ) { // we can only sort by field not by db.collection.field String name = 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 6b4a08631a..e57510f612 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 @@ -384,7 +384,7 @@ private BsonValue visitCall( Implementor implementor, RexCall call, Kind op, Pol private void handlePreparedInsert( Implementor implementor, MongoProject input ) { - if ( !(input.getInput() instanceof MongoValues || input.getInput() instanceof MongoDocuments) && input.getInput().getRowType().getFieldList().size() == 1 ) { + if ( !(input.getInput() instanceof MongoValues || input.getInput() instanceof MongoDocuments) && input.getInput().getRowType().getFields().size() == 1 ) { return; } @@ -414,7 +414,7 @@ private void handlePreparedInsert( Implementor implementor, MongoProject input ) } else if ( rexNode instanceof RexCall ) { PolyType type = this.entity .getRowType( getCluster().getTypeFactory() ) - .getFieldList() + .getFields() .get( pos ) .getType() .getComponentType() diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/util/MongoTupleType.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/util/MongoTupleType.java index e15e554f86..ea8afe5aba 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/util/MongoTupleType.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/util/MongoTupleType.java @@ -59,7 +59,7 @@ public static MongoTupleType from( AlgDataType type ) { List types = new ArrayList<>(); switch ( type.getPolyType() ) { case ROW: - type.getFieldList().forEach( field -> types.add( from( field ) ) ); + type.getFields().forEach( field -> types.add( from( field ) ) ); } return new MongoTupleType( null, type.getPolyType(), types, type.isNullable() ); } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java index 56fd795c6f..c44b4cb102 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java @@ -1085,7 +1085,7 @@ private AlgNode combineGroup( BsonValue value, AlgNode node, AlgDataType rowType if ( entry.getKey().equals( "_id" ) ) { if ( entry.getValue().isNull() ) { names.addAll( 0, rowType.getFieldNames() ); - nodes.addAll( 0, rowType.getFieldList().stream().map( f -> RexIndexRef.of( f.getIndex(), rowType ) ).collect( Collectors.toList() ) ); + nodes.addAll( 0, rowType.getFields().stream().map( f -> RexIndexRef.of( f.getIndex(), rowType ) ).collect( Collectors.toList() ) ); } else if ( entry.getValue().isString() ) { names.add( entry.getValue().asString().getValue().substring( 1 ) ); @@ -2207,7 +2207,7 @@ private AlgNode combineProjection( BsonValue projectionValue, AlgNode node, AlgD List values = new ArrayList<>(); List names = new ArrayList<>(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { if ( !excludes.contains( field.getName() ) ) { names.add( field.getName() ); values.add( RexIndexRef.of( field.getIndex(), rowType ) ); @@ -2227,7 +2227,7 @@ private AlgNode combineProjection( BsonValue projectionValue, AlgNode node, AlgD for ( Entry entry : includes.entrySet() ) { List values = new ArrayList<>(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { // we attach the new values to the input bson values.add( new RexCall( 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 d97bd5c2e6..04bf52e96e 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 @@ -166,7 +166,7 @@ public Enumerator enumerator() { private List getComponentType() { - return rowType.getFieldList().stream().map( t -> { + return rowType.getFields().stream().map( t -> { if ( t.getType().getComponentType() != null ) { return t.getType().getComponentType().getPolyType(); } @@ -176,12 +176,12 @@ private List getComponentType() { private List getTypes() { - return rowType.getFieldList().stream().map( t -> t.getType().getPolyType() ).collect( Collectors.toList() ); + return rowType.getFields().stream().map( t -> t.getType().getPolyType() ).collect( Collectors.toList() ); } private String buildAllQuery() { - return rowType.getFieldList().stream().map( f -> "n." + f.getPhysicalName() ).collect( Collectors.joining( ", " ) ); + return rowType.getFields().stream().map( f -> "n." + f.getPhysicalName() ).collect( Collectors.joining( ", " ) ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraphImplementor.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraphImplementor.java index cfd11d8949..f4f5120d59 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraphImplementor.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraphImplementor.java @@ -154,7 +154,7 @@ public void addReturnIfNecessary() { */ private List getFields( AlgDataType rowType ) { List statements = new ArrayList<>(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { statements.add( getField( field ) ); } @@ -177,7 +177,7 @@ private NeoStatement getField( AlgDataTypeField field ) { case PATH: PathType type = (PathType) field.getType(); List path = new ArrayList<>(); - for ( AlgDataTypeField pathPart : type.getFieldList() ) { + for ( AlgDataTypeField pathPart : type.getFields() ) { path.add( (ElementStatement) getField( pathPart ) ); } return path_( path ); diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoRelationalImplementor.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoRelationalImplementor.java index 41f950037f..b5b3c1023a 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoRelationalImplementor.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoRelationalImplementor.java @@ -186,7 +186,7 @@ public static Pair createCreate( Immut if ( pos >= rowType.getFieldCount() ) { continue; } - props.add( property_( rowType.getFieldList().get( pos ).getPhysicalName(), literal_( NeoUtil.rexAsString( value, null, false ) ) ) ); + props.add( property_( rowType.getFields().get( pos ).getPhysicalName(), literal_( NeoUtil.rexAsString( value, null, false ) ) ) ); pos++; } String name = entity.name; @@ -200,7 +200,7 @@ public static Pair createCreate( Immut public static NeoStatements.OperatorStatement create( Function1, OperatorStatement> transformer, NeoProject neoProject, AlgNode last, NeoRelationalImplementor implementor ) { - List fields = neoProject.getRowType().getFieldList(); + List fields = neoProject.getRowType().getFields(); List nodes = new ArrayList<>(); int i = 0; @@ -219,7 +219,7 @@ public static NeoStatements.OperatorStatement create( Function1 public static OperatorStatement createProjectValues( NeoProject last, NeoEntity entity, NeoRelationalImplementor implementor ) { List properties = new ArrayList<>(); - List fields = entity.getRowType().getFieldList(); + List fields = entity.getRowType().getFields(); int i = 0; for ( RexNode project : last.getProjects() ) { @@ -279,13 +279,13 @@ public void addFilter( NeoFilter filter ) { private Map getToPhysicalMapping( @Nullable AlgNode node ) { Map mapping = new HashMap<>(); - for ( AlgDataTypeField field : entity.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : entity.getRowType().getFields() ) { mapping.put( field.getName(), entity.name + "." + field.getPhysicalName() ); } if ( node instanceof NeoProject ) { NeoProject project = (NeoProject) node; - for ( AlgDataTypeField field : project.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : project.getRowType().getFields() ) { if ( !mapping.containsKey( field.getName() ) ) { Translator translator = new Translator( project.getRowType(), project.getRowType(), new HashMap<>(), this, null, true ); mapping.put( field.getName(), project.getProjects().get( field.getIndex() ).accept( translator ) ); diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoToEnumerableConverter.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoToEnumerableConverter.java index 932418203f..de69b5713e 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoToEnumerableConverter.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoToEnumerableConverter.java @@ -228,7 +228,7 @@ public Expression getFields( BlockBuilder builder, AlgDataType rowType, Function return builder.append( builder.newName( "fields" ), EnumUtils.constantArrayList( rowType - .getFieldList() + .getFields() .stream() .map( f -> typeGetter.apply( f.getType() ) ) .collect( Collectors.toList() ), PolyType.class ) ); diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgAggregate.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgAggregate.java index 7ee0d56aaf..bd96f5ae88 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgAggregate.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgAggregate.java @@ -72,7 +72,7 @@ public void implement( NeoGraphImplementor implementor ) { if ( implementor.getLast() instanceof LpgProject ) { OperatorStatement last = implementor.removeLast(); List finalRow = new ArrayList<>(); - for ( AlgDataTypeField ignored : getRowType().getFieldList() ) { + for ( AlgDataTypeField ignored : getRowType().getFields() ) { finalRow.add( null ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgScan.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgScan.java index c043972ce3..0b03052c35 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgScan.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/graph/NeoLpgScan.java @@ -44,8 +44,8 @@ public NeoLpgScan( AlgOptCluster cluster, AlgTraitSet traitSet, NeoGraph graph ) public void implement( NeoGraphImplementor implementor ) { implementor.setGraph( entity ); - if ( rowType.getFieldList().size() == 1 ) { - AlgDataTypeField field = rowType.getFieldList().get( 0 ); + if ( rowType.getFields().size() == 1 ) { + AlgDataTypeField field = rowType.getFields().get( 0 ); if ( field.getType().getPolyType() == PolyType.GRAPH ) { implementor.setAll( true ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoScan.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoScan.java index 5173814082..2d503d4b74 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoScan.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoScan.java @@ -59,7 +59,7 @@ public void implement( NeoRelationalImplementor implementor ) { if ( !implementor.isDml() ) { List mapping = entity .getRowType() - .getFieldList() + .getFields() .stream().map( f -> as_( literal_( entity.name + "." + f.getPhysicalName() ), literal_( f.getName() ) ) ) .collect( Collectors.toList() ); diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoValues.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoValues.java index 1545ce881d..4aa745feb9 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoValues.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/rules/relational/NeoValues.java @@ -36,7 +36,7 @@ public NeoValues( AlgOptCluster cluster, AlgDataType rowType, ImmutableList> tuples( Ast.ValuesStmt valuesSt private ImmutableList tuple( List pigNodeList, AlgDataType rowType ) { final ImmutableList.Builder listBuilder = ImmutableList.builder(); - for ( Pair pair : Pair.zip( pigNodeList, rowType.getFieldList() ) ) { + for ( Pair pair : Pair.zip( pigNodeList, rowType.getFields() ) ) { final PigNode pigNode = pair.left; final AlgDataType type = pair.right.getType(); listBuilder.add( item( pigNode, type ) ); 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 6a59798b61..c1d300afc0 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 @@ -174,7 +174,7 @@ String processPatchResource( final ResourcePatchRequest resourcePatchRequest, fi // Values AlgDataType tableRowType = table.getRowType(); - List tableRows = tableRowType.getFieldList(); + List tableRows = tableRowType.getFields(); List valueColumnNames = this.valuesColumnNames( resourcePatchRequest.values ); List rexValues = this.valuesNode( statement, algBuilder, rexBuilder, resourcePatchRequest, tableRows, inputStreams ).get( 0 ); @@ -271,7 +271,7 @@ String processPostResource( final ResourcePostRequest insertValueRequest, final // Values AlgDataType tableRowType = table.getRowType(); - List tableRows = tableRowType.getFieldList(); + List tableRows = tableRowType.getFields(); AlgOptPlanner planner = statement.getQueryProcessor().getPlanner(); AlgOptCluster cluster = AlgOptCluster.create( planner, rexBuilder, null, Catalog.getInstance().getSnapshot() ); @@ -334,7 +334,7 @@ List filters( Statement statement, AlgBuilder algBuilder, RexBuilder re List filterNodes = new ArrayList<>(); AlgNode baseNodeForFilters = algBuilder.peek(); AlgDataType filtersRowType = baseNodeForFilters.getRowType(); - List filtersRows = filtersRowType.getFieldList(); + List filtersRows = filtersRowType.getFields(); Map filterMap = new HashMap<>(); filtersRows.forEach( ( r ) -> filterMap.put( r.getName(), r ) ); int index = 0; diff --git a/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/RestResult.java b/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/RestResult.java index 826698aba9..2ea76dbc07 100644 --- a/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/RestResult.java +++ b/plugins/rest-interface/src/main/java/org/polypheny/db/restapi/RestResult.java @@ -124,7 +124,7 @@ private void transformNonDML() { HashMap temp = new HashMap<>(); int i = 0; - for ( AlgDataTypeField type : dataType.getFieldList() ) { + for ( AlgDataTypeField type : dataType.getFields() ) { PolyValue o = row[i]; String columnName = columns.get( i ).columnName; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUnnestOperator.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUnnestOperator.java index 5d98d05551..a8311cfd49 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUnnestOperator.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUnnestOperator.java @@ -75,7 +75,7 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { } if ( type.isStruct() ) { - type = type.getFieldList().get( 0 ).getType(); + type = type.getFields().get( 0 ).getType(); } assert type instanceof ArrayType || type instanceof MultisetPolyType || type instanceof MapPolyType; @@ -84,7 +84,7 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { builder.add( null, UnnestOperator.MAP_VALUE_COLUMN_NAME, null, type.unwrap( MapPolyType.class ).getValueType() ); } else { if ( type.getComponentType().isStruct() ) { - builder.addAll( type.getComponentType().getFieldList() ); + builder.addAll( type.getComponentType().getFields() ); } else { builder.add( null, CoreUtil.deriveAliasFromOrdinal( operand ), null, type.getComponentType() ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlInOperator.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlInOperator.java index 6a92cf5b13..c4c06ca843 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlInOperator.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlInOperator.java @@ -132,7 +132,7 @@ public AlgDataType deriveType( Validator validator, ValidatorScope scope, Call c // Result is a boolean, nullable if there are any nullable types on either side. return typeFactory.createTypeWithNullability( typeFactory.createPolyType( PolyType.BOOLEAN ), - anyNullable( leftRowType.getFieldList() ) || anyNullable( rightRowType.getFieldList() ) ); + anyNullable( leftRowType.getFields() ) || anyNullable( rightRowType.getFields() ) ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlOverlapsOperator.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlOverlapsOperator.java index c3f3a003ad..15e373d85e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlOverlapsOperator.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlOverlapsOperator.java @@ -130,8 +130,8 @@ public boolean checkOperandTypes( SqlCallBinding callBinding, boolean throwOnFai final AlgDataType t0 = callBinding.getOperandType( 0 ); final AlgDataType t1 = callBinding.getOperandType( 1 ); if ( !PolyTypeUtil.isDatetime( t1 ) ) { - final AlgDataType t00 = t0.getFieldList().get( 0 ).getType(); - final AlgDataType t10 = t1.getFieldList().get( 0 ).getType(); + final AlgDataType t00 = t0.getFields().get( 0 ).getType(); + final AlgDataType t10 = t1.getFields().get( 0 ).getType(); if ( !PolyTypeUtil.sameNamedType( t00, t10 ) ) { if ( throwOnFailure ) { throw callBinding.newValidationSignatureError(); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AliasNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AliasNamespace.java index a0dca69806..077a5197e9 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AliasNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AliasNamespace.java @@ -79,7 +79,7 @@ protected AlgDataType validateImpl( AlgDataType targetRowType ) { throw validator.newValidationError( node, RESOURCE.aliasListDegree( rowType.getFieldCount(), getString( rowType ), nameList.size() ) ); } final List typeList = new ArrayList<>(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { typeList.add( field.getType() ); } return validator.getTypeFactory().createStructType( null, typeList, nameList ); @@ -89,7 +89,7 @@ protected AlgDataType validateImpl( AlgDataType targetRowType ) { private String getString( AlgDataType rowType ) { StringBuilder buf = new StringBuilder(); buf.append( "(" ); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { if ( field.getIndex() > 0 ) { buf.append( ", " ); } @@ -112,9 +112,9 @@ public SqlNode getNode() { public String translate( String name ) { final AlgDataType underlyingRowType = validator.getValidatedNodeType( call.operand( 0 ) ); int i = 0; - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { if ( field.getName().equals( name ) ) { - return underlyingRowType.getFieldList().get( i ).getName(); + return underlyingRowType.getFields().get( i ).getName(); } ++i; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java index b4ef18cbb3..e9796145ac 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java @@ -125,7 +125,7 @@ void resolveInNamespace( SqlValidatorNamespace ns, boolean nullable, List colNames return; } - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { colNames.add( new MonikerImpl( field.getName(), MonikerType.COLUMN ) ); } } @@ -374,7 +374,7 @@ public SqlQualified fullyQualify( SqlIdentifier identifier ) { if ( fromPath.stepCount() > 1 ) { assert fromRowType != null; for ( Step p : fromPath.steps() ) { - fromRowType = fromRowType.getFieldList().get( p.i ).getType(); + fromRowType = fromRowType.getFields().get( p.i ).getType(); } ++i; } @@ -450,7 +450,7 @@ private int worstKind( Path path ) { if ( step.i < 0 ) { throw validator.newValidationError( identifier, Static.RESOURCE.columnNotFound( name ) ); } - final AlgDataTypeField field0 = step.rowType.getFieldList().get( step.i ); + final AlgDataTypeField field0 = step.rowType.getFields().get( step.i ); final String fieldName = field0.getName(); switch ( step.kind ) { case PEEK_FIELDS: @@ -521,7 +521,7 @@ public SqlNodeList getOrderList() { private boolean hasAmbiguousUnresolvedStar( AlgDataType rowType, AlgDataTypeField field, String columnName ) { if ( field.isDynamicStar() && !DynamicRecordType.isDynamicStarColName( columnName ) ) { int count = 0; - for ( AlgDataTypeField possibleStar : rowType.getFieldList() ) { + for ( AlgDataTypeField possibleStar : rowType.getFields() ) { if ( possibleStar.isDynamicStar() ) { if ( ++count > 1 ) { return true; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java index 5c6b0c4c33..845096bed9 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java @@ -67,7 +67,7 @@ protected AlgDataType validateImpl( AlgDataType targetRowType ) { return table.getRowType(); } final Builder builder = validator.getTypeFactory().builder(); - builder.addAll( table.getRowType().getFieldList() ); + builder.addAll( table.getRowType().getFields() ); builder.addAll( extendedFields ); return builder.build(); } @@ -125,7 +125,7 @@ private AlgDataType getBaseRowType() { */ private void checkExtendedColumnTypes( SqlNodeList extendList ) { final List extendedFields = SqlValidatorUtil.getExtendedColumns( validator.getTypeFactory(), table, extendList ); - final List baseFields = getBaseRowType().getFieldList(); + final List baseFields = getBaseRowType().getFields(); final Map nameToIndex = ValidatorUtil.mapNameToIndex( baseFields ); for ( final AlgDataTypeField extendedField : extendedFields ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java index 9d0a86b4e2..aa414296df 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java @@ -220,7 +220,7 @@ public AlgDataType validateImpl( AlgDataType targetRowType ) { // Build a list of monotonic expressions. final ImmutableList.Builder> builder = ImmutableList.builder(); - List fields = rowType.getFieldList(); + List fields = rowType.getFields(); for ( AlgDataTypeField field : fields ) { final String fieldName = field.getName(); final Monotonicity monotonicity = resolvedNamespace.getMonotonicity( fieldName ); 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 9af717f67f..cb2e396792 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 @@ -505,7 +505,7 @@ private boolean expandStar( List selectItems, Set aliases, List final SqlValidatorNamespace fromNs = getNamespace( from, scope ); assert fromNs != null; final AlgDataType rowType = fromNs.getRowType(); - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { String columnName = field.getName(); // TODO: do real implicit collation here @@ -562,7 +562,7 @@ private boolean expandStar( List selectItems, Set aliases, List scope, includeSystemVars ); } else if ( rowType.isStruct() ) { - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { String columnName = field.getName(); // TODO: do real implicit collation here @@ -789,7 +789,7 @@ public final void lookupNameCompletionHints( SqlValidatorScope scope, List= i - ? targetRowType.getFieldList().get( i ).getType() + ? targetRowType.getFields().get( i ).getType() : unknownType, expandedSelectItems, aliases, @@ -3992,7 +3992,7 @@ private void handleScalarSubQuery( SqlSelect parentSelect, SqlSelect selectItem, assert type instanceof AlgRecordType; AlgRecordType rec = (AlgRecordType) type; - AlgDataType nodeType = rec.getFieldList().get( 0 ).getType(); + AlgDataType nodeType = rec.getFields().get( 0 ).getType(); nodeType = typeFactory.createTypeWithNullability( nodeType, true ); fieldList.add( new AlgDataTypeFieldImpl( 1L, alias, 0, nodeType ) ); } @@ -4016,7 +4016,7 @@ protected AlgDataType createTargetRowType( LogicalEntity table, SqlNodeList targ if ( targetColumnList == null ) { return baseRowType; } - List targetFields = baseRowType.getFieldList(); + List targetFields = baseRowType.getFields(); final List fields = new ArrayList<>(); if ( append ) { for ( AlgDataTypeField targetField : targetFields ) { @@ -4122,7 +4122,7 @@ public RexNode convertExpression( Node e ) { } }; final List strategies = table.unwrap( LogicalTable.class ).getColumnStrategies(); - for ( final AlgDataTypeField field : table.getRowType().getFieldList() ) { + for ( final AlgDataTypeField field : table.getRowType().getFields() ) { final AlgDataTypeField targetField = logicalTargetRowType.getField( field.getName(), true, false ); switch ( strategies.get( field.getIndex() ) ) { case NOT_NULLABLE: @@ -4177,7 +4177,7 @@ protected AlgDataType getLogicalTargetRowType( AlgDataType targetRowType, SqlIns final SqlNode source = insert.getSource(); final AlgDataType sourceRowType = getSqlNamespace( source ).getRowType(); final AlgDataType logicalSourceRowType = getLogicalSourceRowType( sourceRowType, insert ); - final AlgDataType implicitTargetRowType = typeFactory.createStructType( targetRowType.getFieldList().subList( 0, logicalSourceRowType.getFieldCount() ) ); + final AlgDataType implicitTargetRowType = typeFactory.createStructType( targetRowType.getFields().subList( 0, logicalSourceRowType.getFieldCount() ) ); final SqlValidatorNamespace targetNamespace = getSqlNamespace( insert ); validateNamespace( targetNamespace, implicitTargetRowType ); return implicitTargetRowType; @@ -4195,8 +4195,8 @@ protected AlgDataType getLogicalSourceRowType( AlgDataType sourceRowType, SqlIns protected void checkTypeAssignment( AlgDataType sourceRowType, AlgDataType targetRowType, final SqlNode query ) { // NOTE jvs 23-Feb-2006: subclasses may allow for extra targets representing system-maintained columns, so stop after all sources matched - List sourceFields = sourceRowType.getFieldList(); - List targetFields = targetRowType.getFieldList(); + List sourceFields = sourceRowType.getFields(); + List targetFields = targetRowType.getFields(); final int sourceCount = sourceFields.size(); for ( int i = 0; i < sourceCount; ++i ) { AlgDataType sourceType = sourceFields.get( i ).getType(); @@ -4431,7 +4431,7 @@ protected void validateValues( SqlCall node, AlgDataType targetRowType, final Sq SqlCall rowConstructor = (SqlCall) operand; if ( conformance.isInsertSubsetColumnsAllowed() && targetRowType.isStruct() && rowConstructor.operandCount() < targetRowType.getFieldCount() ) { - targetRowType = typeFactory.createStructType( targetRowType.getFieldList().subList( 0, rowConstructor.operandCount() ) ); + targetRowType = typeFactory.createStructType( targetRowType.getFields().subList( 0, rowConstructor.operandCount() ) ); } else if ( targetRowType.isStruct() && rowConstructor.operandCount() != targetRowType.getFieldCount() ) { return; } @@ -4439,7 +4439,7 @@ protected void validateValues( SqlCall node, AlgDataType targetRowType, final Sq inferUnknownTypes( targetRowType, scope, rowConstructor ); if ( targetRowType.isStruct() ) { - for ( Pair pair : Pair.zip( rowConstructor.getOperandList(), targetRowType.getFieldList() ) ) { + for ( Pair pair : Pair.zip( rowConstructor.getOperandList(), targetRowType.getFields() ) ) { if ( !pair.right.getType().isNullable() && CoreUtil.isNullLiteral( pair.left, false ) ) { throw newValidationError( node, RESOURCE.columnNotNullable( pair.right.getName() ) ); } @@ -4702,7 +4702,7 @@ public void validateMatchRecognize( SqlCall call ) { if ( allRows ) { final SqlValidatorNamespace sqlNs = getSqlNamespace( matchRecognize.getTableRef() ); final AlgDataType inputDataType = sqlNs.getRowType(); - for ( AlgDataTypeField fs : inputDataType.getFieldList() ) { + for ( AlgDataTypeField fs : inputDataType.getFields() ) { if ( !typeBuilder.nameExists( fs.getName() ) ) { typeBuilder.add( fs ); } @@ -6065,7 +6065,7 @@ private class Permute { case JOIN: final SqlJoin join = (SqlJoin) from; final Permute left = new Permute( join.getLeft(), offset ); - final int fieldCount = getValidatedNodeType( join.getLeft() ).getFieldList().size(); + final int fieldCount = getValidatedNodeType( join.getLeft() ).getFields().size(); final Permute right = new Permute( join.getRight(), offset + fieldCount ); final List names = usingNames( join ); final List> sources = new ArrayList<>(); @@ -6088,14 +6088,14 @@ private class Permute { b.add( f ).nullable( nullable ); } } - for ( AlgDataTypeField f : left.rowType.getFieldList() ) { + for ( AlgDataTypeField f : left.rowType.getFields() ) { final ImmutableList source = left.sources.get( f.getIndex() ); if ( sourceSet.add( source ) ) { sources.add( source ); b.add( f ); } } - for ( AlgDataTypeField f : right.rowType.getFieldList() ) { + for ( AlgDataTypeField f : right.rowType.getFields() ) { final ImmutableList source = right.sources.get( f.getIndex() ); if ( sourceSet.add( source ) ) { sources.add( source ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java index bcaaa92e9c..d31a562678 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java @@ -179,7 +179,7 @@ public static ImmutableMap getIndexToFieldMap( List indexToField = getIndexToFieldMap( sourceRowType.getFieldList(), targetRowType ); + Map indexToField = getIndexToFieldMap( sourceRowType.getFields(), targetRowType ); return getOrdinalBitSet( sourceRowType, indexToField ); } @@ -191,7 +191,7 @@ public static ImmutableBitSet getOrdinalBitSet( AlgDataType sourceRowType, AlgDa * @param indexToField The map of ordinals to target fields. */ public static ImmutableBitSet getOrdinalBitSet( AlgDataType sourceRowType, Map indexToField ) { - ImmutableBitSet source = ImmutableBitSet.of( Lists.transform( sourceRowType.getFieldList(), AlgDataTypeField::getIndex ) ); + ImmutableBitSet source = ImmutableBitSet.of( Lists.transform( sourceRowType.getFields(), AlgDataTypeField::getIndex ) ); ImmutableBitSet target = ImmutableBitSet.of( indexToField.keySet() ); return source.intersect( target ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithItemNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithItemNamespace.java index e4c0356871..5ccde58270 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithItemNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithItemNamespace.java @@ -48,7 +48,7 @@ protected AlgDataType validateImpl( AlgDataType targetRowType ) { return rowType; } final Builder builder = validator.getTypeFactory().builder(); - for ( Pair pair : Pair.zip( withItem.columnList.getSqlList(), rowType.getFieldList() ) ) { + for ( Pair pair : Pair.zip( withItem.columnList.getSqlList(), rowType.getFields() ) ) { builder.add( null, ((SqlIdentifier) pair.left).getSimple(), null, pair.right.getType() ); } return builder.build(); @@ -68,9 +68,9 @@ public String translate( String name ) { } final AlgDataType underlyingRowType = validator.getValidatedNodeType( withItem.query ); int i = 0; - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { if ( field.getName().equals( name ) ) { - return underlyingRowType.getFieldList().get( i ).getName(); + return underlyingRowType.getFields().get( i ).getName(); } ++i; } 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 44bc5d71fb..c058b73472 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 @@ -405,7 +405,7 @@ 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 read final + List validatedFields = validator.getValidatedNodeType( query ).getFields(); // TODO DL read final final AlgDataType validatedRowType = validator.getTypeFactory().createStructType( validatedFields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), @@ -418,7 +418,7 @@ private void checkConvertedType( Node query, AlgNode result ) { } }*/ - final List convertedFields = result.getRowType().getFieldList().subList( 0, validatedFields.size() ); + final List convertedFields = result.getRowType().getFields().subList( 0, validatedFields.size() ); final AlgDataType convertedRowType = validator.getTypeFactory().createStructType( convertedFields ); if ( !AlgOptUtil.equal( "validated row type", validatedRowType, "converted row type", convertedRowType, Litmus.IGNORE ) ) { @@ -675,7 +675,7 @@ private void distinctify( Blackboard bb, boolean checkForDupExprs ) { } final Map squished = new HashMap<>(); - final List fields = alg.getRowType().getFieldList(); + final List fields = alg.getRowType().getFields(); final List> newProjects = new ArrayList<>(); for ( int i = 0; i < fields.size(); i++ ) { if ( origins.get( i ) == i ) { @@ -1512,7 +1512,7 @@ private RexLiteral convertLiteralInValuesList( SqlNode sqlNode, Blackboard bb, A if ( !(sqlNode instanceof SqlLiteral) ) { return null; } - AlgDataTypeField field = rowType.getFieldList().get( iField ); + AlgDataTypeField field = rowType.getFields().get( iField ); AlgDataType type = field.getType(); if ( type.isStruct() ) { // null literals for weird stuff like UDT's need special handling during type flattening, so don't use LogicalValues for those @@ -2293,7 +2293,7 @@ private CorrelationUse getCorrelationUse( Blackboard bb, final AlgNode r0 ) { while ( topLevelFieldAccess.getReferenceExpr() instanceof RexFieldAccess ) { topLevelFieldAccess = (RexFieldAccess) topLevelFieldAccess.getReferenceExpr(); } - final AlgDataTypeField field = rowType.getFieldList().get( topLevelFieldAccess.getField().getIndex() - namespaceOffset ); + final AlgDataTypeField field = rowType.getFields().get( topLevelFieldAccess.getField().getIndex() - namespaceOffset ); int pos = namespaceOffset + field.getIndex(); assert field.getType() == topLevelFieldAccess.getField().getType(); @@ -2424,7 +2424,7 @@ RexNode convertUsing( SqlValidatorNamespace leftNamespace, SqlValidatorNamespace final AlgDataType rowType = n.getRowType(); final AlgDataTypeField field = nameMatcher.field( rowType, name ); operands.add( rexBuilder.makeInputRef( field.getType(), offset + field.getIndex() ) ); - offset += rowType.getFieldList().size(); + offset += rowType.getFields().size(); } list.add( rexBuilder.makeCall( OperatorRegistry.get( OperatorName.EQUALS ), operands ) ); } @@ -2917,7 +2917,7 @@ public AlgNode toAlg( final LogicalEntity table ) { int virtualCount = 0; final List list = new ArrayList<>(); - for ( AlgDataTypeField f : table.getRowType().getFieldList() ) { + for ( AlgDataTypeField f : table.getRowType().getFields() ) { final ColumnStrategy strategy = ief.generationStrategy( table, f.getIndex() ); switch ( strategy ) { case VIRTUAL: @@ -2970,7 +2970,7 @@ protected AlgNode convertColumnList( final SqlInsert call, AlgNode source ) { final LogicalEntity targetTable = getTargetTable( call ); final AlgDataType targetRowType = targetTable.getRowType();//AlgOptEntityImpl.realRowType( targetTable ); - final List targetFields = targetRowType.getFieldList(); + final List targetFields = targetRowType.getFields(); boolean isDocument = call.getSchemaType() == NamespaceType.DOCUMENT; List sourceExps = new ArrayList<>( Collections.nCopies( targetFields.size(), null ) ); @@ -3085,7 +3085,7 @@ protected void collectInsertTargets( SqlInsert call, final RexNode sourceRef, fi if ( validator.getConformance().isInsertSubsetColumnsAllowed() ) { final AlgDataType targetRowType = typeFactory.createStructType( - tableRowType.getFieldList() + tableRowType.getFields() .subList( 0, sourceRef.getType().getFieldCount() ) ); targetColumnNames.addAll( targetRowType.getFieldNames() ); } else { @@ -3777,7 +3777,7 @@ public RexNode register( AlgNode alg, JoinAlgType joinType, List leftKe @Override public AlgDataTypeField get( int index ) { return join.getRowType() - .getFieldList() + .getFields() .get( origLeftInputCount + index ); } @@ -3870,7 +3870,7 @@ Pair> lookupExp( SqlQualified qualified ) { return null; } else { final Map fieldOffsets = new HashMap<>(); - for ( AlgDataTypeField f : resolve.rowType().getFieldList() ) { + for ( AlgDataTypeField f : resolve.rowType().getFields() ) { if ( !fieldOffsets.containsKey( f.getName() ) ) { fieldOffsets.put( f.getName(), f.getIndex() ); } @@ -3894,9 +3894,9 @@ Pair> lookupExp( SqlQualified qualified ) { int i = 0; int offset = 0; for ( SqlValidatorNamespace c : ancestorScope1.getChildren() ) { - builder.addAll( c.getRowType().getFieldList() ); + builder.addAll( c.getRowType().getFields() ); if ( i == resolve.path.steps().get( 0 ).i ) { - for ( AlgDataTypeField field : c.getRowType().getFieldList() ) { + for ( AlgDataTypeField field : c.getRowType().getFields() ) { fields.put( field.getName(), field.getIndex() + offset ); } } @@ -3934,7 +3934,7 @@ AlgDataTypeField getRootField( RexIndexRef inputRef ) { return null; } if ( fieldOffset < rowType.getFieldCount() ) { - return rowType.getFieldList().get( fieldOffset ); + return rowType.getFields().get( fieldOffset ); } fieldOffset -= rowType.getFieldCount(); } @@ -4490,7 +4490,7 @@ void addAuxiliaryGroupExpr( SqlNode node, int index, AuxiliaryConverter converte private void addExpr( RexNode expr, String name ) { if ( (name == null) && (expr instanceof RexIndexRef) ) { final int i = ((RexIndexRef) expr).getIndex(); - name = bb.root.getRowType().getFieldList().get( i ).getName(); + name = bb.root.getRowType().getFields().get( i ).getName(); } if ( Pair.right( convertedInputExprs ).contains( name ) ) { // In case like 'SELECT ... GROUP BY x, y, x', don't add name 'x' twice. diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/StandardConvertletTable.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/StandardConvertletTable.java index 21cc9991db..48e80383bb 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/StandardConvertletTable.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/StandardConvertletTable.java @@ -384,7 +384,7 @@ public RexNode convertMultiset( SqlRexContext cx, SqlMultisetValueConstructor op final AlgDataType originalType = cx.getValidator().getValidatedNodeType( call ); RexRangeRef rr = cx.getSubQueryExpr( call ); assert rr != null; - AlgDataType msType = rr.getType().getFieldList().get( 0 ).getType(); + AlgDataType msType = rr.getType().getFields().get( 0 ).getType(); RexNode expr = cx.getRexBuilder().makeInputRef( msType, rr.getOffset() ); assert msType.getComponentType().isStruct(); if ( !originalType.getComponentType().isStruct() ) { @@ -411,7 +411,7 @@ public RexNode convertMultisetQuery( SqlRexContext cx, SqlMultisetQueryConstruct final AlgDataType originalType = cx.getValidator().getValidatedNodeType( call ); RexRangeRef rr = cx.getSubQueryExpr( call ); assert rr != null; - AlgDataType msType = rr.getType().getFieldList().get( 0 ).getType(); + AlgDataType msType = rr.getType().getFields().get( 0 ).getType(); RexNode expr = cx.getRexBuilder().makeInputRef( msType, rr.getOffset() ); assert msType.getComponentType().isStruct(); if ( !originalType.getComponentType().isStruct() ) { @@ -474,7 +474,7 @@ protected RexNode convertCast( SqlRexContext cx, final SqlCall call ) { if ( argComponentType.isStruct() && !componentType.isStruct() ) { AlgDataType tt = typeFactory.builder() - .add( null, argComponentType.getFieldList().get( 0 ).getName(), null, componentType ) + .add( null, argComponentType.getFields().get( 0 ).getName(), null, componentType ) .build(); tt = typeFactory.createTypeWithNullability( tt, componentType.isNullable() ); boolean isn = type.isNullable(); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java index e399605854..3529a28693 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java @@ -299,7 +299,7 @@ private List deduceMonotonicity( LogicalTable table ) { // Deduce which fields the table is sorted on. int i = -1; - for ( AlgDataTypeField field : rowType.getFieldList() ) { + for ( AlgDataTypeField field : rowType.getFields() ) { ++i; final Monotonicity monotonicity = ValidatorTable.getMonotonicity( table, field.getName() ); if ( monotonicity != Monotonicity.NOT_MONOTONIC ) { diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java index 7e5a64a496..c3888c14b9 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java @@ -161,7 +161,7 @@ protected void checkParseEx( Throwable e, String expectedMsgPattern, String sql @Override public AlgDataType getColumnType( String sql ) { AlgDataType rowType = getResultType( sql ); - final List fields = rowType.getFieldList(); + final List fields = rowType.getFields(); assertEquals( "expected query to return 1 field", 1, fields.size() ); return fields.get( 0 ).getType(); } @@ -496,7 +496,7 @@ public void checkMonotonic( String query, Monotonicity expectedMonotonicity ) { SqlNode n = parseAndValidate( validator, query ); final AlgDataType rowType = validator.getValidatedNodeType( n ); final SqlValidatorNamespace selectNamespace = validator.getSqlNamespace( n ); - final String field0 = rowType.getFieldList().get( 0 ).getName(); + final String field0 = rowType.getFields().get( 0 ).getName(); final Monotonicity monotonicity = selectNamespace.getMonotonicity( field0 ); assertThat( monotonicity, equalTo( expectedMonotonicity ) ); } diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index 63034b7325..f8946ff374 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -2588,7 +2588,7 @@ RelationalResult executeAlg( final AlgRequest request, Session session ) { PlacementType placementType = store == null ? PlacementType.AUTOMATIC : PlacementType.MANUAL; List columns = new ArrayList<>(); - root.alg.getRowType().getFieldList().forEach( f -> columns.add( f.getName() ) ); + root.alg.getRowType().getFields().forEach( f -> columns.add( f.getName() ) ); // Default Namespace long namespaceId = transaction.getDefaultNamespace().id; @@ -2630,7 +2630,7 @@ RelationalResult executeAlg( final AlgRequest request, Session session ) { PlacementType placementType = PlacementType.AUTOMATIC; List columns = new ArrayList<>(); - root.alg.getRowType().getFieldList().forEach( f -> columns.add( f.getName() ) ); + root.alg.getRowType().getFields().forEach( f -> columns.add( f.getName() ) ); // Default Namespace long namespaceId = transaction.getDefaultNamespace().id; @@ -2679,7 +2679,7 @@ RelationalResult executeAlg( final AlgRequest request, Session session ) { UiColumnDefinition[] header = new UiColumnDefinition[polyImplementation.getRowType().getFieldCount()]; int counter = 0; - for ( AlgDataTypeField col : polyImplementation.getRowType().getFieldList() ) { + for ( AlgDataTypeField col : polyImplementation.getRowType().getFields() ) { header[counter++] = UiColumnDefinition.builder() .name( col.getName() ) .dataType( col.getType() @@ -3038,7 +3038,7 @@ void getDirectory( File dir, Context ctx ) { } List header = new ArrayList<>(); - for ( AlgDataTypeField metaData : implementation.getRowType().getFieldList() ) { + for ( AlgDataTypeField metaData : implementation.getRowType().getFields() ) { String columnName = metaData.getName(); String filter = ""; 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 c5b7a6c6d8..b1ed3cdfc0 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 @@ -231,7 +231,7 @@ public static void attachError( Transaction transaction, List> resu } List header = new ArrayList<>(); - for ( AlgDataTypeField field : implementation.rowType.getFieldList() ) { + for ( AlgDataTypeField field : implementation.rowType.getFields() ) { String columnName = field.getName(); String filter = getFilter( field, request.filter ); @@ -287,7 +287,7 @@ private static GraphResult getGraphResult( Statement statement, QueryLanguage la return GraphResult.builder() .data( data.stream().map( r -> Arrays.stream( r ).map( LanguageCrud::toJson ).toArray( String[]::new ) ).toArray( String[][]::new ) ) - .header( implementation.rowType.getFieldList().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) + .header( implementation.rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) .query( query ) .language( language ) .namespaceType( implementation.getNamespaceType() ) @@ -308,7 +308,7 @@ private static DocResult getDocResult( Statement statement, QueryLanguage langua } return DocResult.builder() - .header( implementation.rowType.getFieldList().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) + .header( implementation.rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) .data( data.stream().map( d -> d.get( 0 ).toJson() ).toArray( String[]::new ) ) .query( query ) .language( language ) From abe266f879f63557bb91d44cc5eb45f9509ff2c2 Mon Sep 17 00:00:00 2001 From: datomo Date: Thu, 23 Nov 2023 14:18:29 +0100 Subject: [PATCH 04/15] adjustment for anyQuery methods - broken don't merge --- .../org/polypheny/db/PolyImplementation.java | 124 -------- .../java/org/polypheny/db/ResultIterator.java | 192 +++++++++++++ .../org/polypheny/db/adapter/index/Index.java | 2 +- .../db/processing/LanguageContext.java | 32 +++ .../polypheny/db/processing/QueryContext.java | 59 ++++ .../db/processing/ResultContext.java | 39 +++ dbms/build.gradle | 4 - .../db/processing/AbstractQueryProcessor.java | 2 +- .../db/processing/DataMigratorImpl.java | 2 +- .../polypheny/db/sql/clause/SelectTest.java | 2 +- .../statistics/StatisticQueryProcessor.java | 2 +- plugins/sql-language/build.gradle | 3 + .../polypheny/db/sql/SqlLanguagePlugin.java | 264 +++++++++++++++++- .../java/org/polypheny/db/webui/Crud.java | 22 +- .../polypheny/db/webui/crud/LanguageCrud.java | 52 +--- 15 files changed, 605 insertions(+), 196 deletions(-) create mode 100644 core/src/main/java/org/polypheny/db/ResultIterator.java create mode 100644 core/src/main/java/org/polypheny/db/processing/LanguageContext.java create mode 100644 core/src/main/java/org/polypheny/db/processing/QueryContext.java create mode 100644 core/src/main/java/org/polypheny/db/processing/ResultContext.java diff --git a/core/src/main/java/org/polypheny/db/PolyImplementation.java b/core/src/main/java/org/polypheny/db/PolyImplementation.java index ff966cf0db..d9b3b20ef6 100644 --- a/core/src/main/java/org/polypheny/db/PolyImplementation.java +++ b/core/src/main/java/org/polypheny/db/PolyImplementation.java @@ -16,18 +16,12 @@ package org.polypheny.db; -import static org.reflections.Reflections.log; - import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import javax.annotation.Nullable; import lombok.Getter; import lombok.experimental.Accessors; @@ -40,8 +34,6 @@ import org.apache.calcite.linq4j.Enumerator; import org.apache.calcite.linq4j.Linq4j; import org.apache.calcite.linq4j.function.Function1; -import org.apache.commons.lang3.time.StopWatch; -import org.jetbrains.annotations.NotNull; import org.polypheny.db.adapter.DataContext; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.type.AlgDataType; @@ -362,120 +354,4 @@ public static void addMonitoringInformation( Statement statement, MonitoringType } - public static class ResultIterator implements AutoCloseable { - - - private final Iterator iterator; - private final int batch; - private final ExecutionTimeMonitor executionTimeMonitor; - private final boolean isIndex; - private final boolean isTimed; - private final AlgDataType rowType; - - private final StatementEvent statementEvent; - - - private ResultIterator( Iterator iterator, Statement statement, int batch, boolean isTimed, boolean isIndex, boolean isAnalyzed, AlgDataType rowType, ExecutionTimeMonitor executionTimeMonitor ) { - this.iterator = iterator; - this.batch = batch; - this.isIndex = isIndex; - this.isTimed = isTimed; - this.statementEvent = isAnalyzed ? statement.getMonitoringEvent() : null; - this.executionTimeMonitor = executionTimeMonitor; - this.rowType = rowType; - } - - - public List> getNextBatch() { - - StopWatch stopWatch = null; - try { - if ( isTimed ) { - stopWatch = new StopWatch(); - stopWatch.start(); - } - List> res = new ArrayList<>(); - int i = 0; - while ( (batch < 0 || i++ < batch) && iterator.hasNext() ) { - res.add( Lists.newArrayList( iterator.next() ) ); - } - - //List> res = MetaImpl.collect( cursorFactory, (Iterator) iterator., new ArrayList<>() ).stream().map( e -> (List) e ).collect( Collectors.toList() ); - - if ( isTimed ) { - stopWatch.stop(); - executionTimeMonitor.setExecutionTime( stopWatch.getNanoTime() ); - } - - // Only if it is an index - if ( statementEvent != null && isIndex ) { - statementEvent.setIndexSize( res.size() ); - } - - return res; - } catch ( Throwable t ) { - try { - close(); - throw new GenericRuntimeException( t ); - } catch ( Exception e ) { - throw new GenericRuntimeException( t ); - } - - } - } - - - public List> getAllRowsAndClose() { - List> result = getNextBatch(); - try { - close(); - } catch ( Exception e ) { - throw new GenericRuntimeException( e ); - } - return result; - } - - - public List getSingleRows() { - return getNextBatch( null ); - } - - - @NotNull - private List getNextBatch( @Nullable Function transformer ) { - final Iterable iterable = () -> iterator; - - if ( transformer == null ) { - return (List) StreamSupport - .stream( iterable.spliterator(), false ) - .collect( Collectors.toList() ); - } - return StreamSupport - .stream( iterable.spliterator(), false ) - .map( transformer ) - .collect( Collectors.toList() ); - } - - - public List getArrayRows() { - - return getNextBatch( rowType.getFieldCount() == 1 ? e -> (PolyValue[]) e : null ); - - } - - - @Override - public void close() throws Exception { - try { - if ( iterator instanceof AutoCloseable ) { - ((AutoCloseable) iterator).close(); - } - } catch ( Exception e ) { - log.error( "Exception while closing result iterator", e ); - } - } - - } - - } diff --git a/core/src/main/java/org/polypheny/db/ResultIterator.java b/core/src/main/java/org/polypheny/db/ResultIterator.java new file mode 100644 index 0000000000..1cfb50fd00 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/ResultIterator.java @@ -0,0 +1,192 @@ +/* + * 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; + +import static org.reflections.Reflections.log; + +import com.google.common.collect.Lists; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; +import javax.annotation.Nullable; +import org.apache.commons.lang3.time.StopWatch; +import org.jetbrains.annotations.NotNull; +import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.monitoring.events.StatementEvent; +import org.polypheny.db.processing.LanguageContext; +import org.polypheny.db.processing.QueryContext; +import org.polypheny.db.processing.ResultContext; +import org.polypheny.db.routing.ExecutionTimeMonitor; +import org.polypheny.db.transaction.Statement; +import org.polypheny.db.type.entity.PolyValue; +import org.polypheny.db.util.Pair; + +public class ResultIterator implements AutoCloseable { + + public final static Map REGISTER = new HashMap<>(); + + + private final Iterator iterator; + private final int batch; + private final ExecutionTimeMonitor executionTimeMonitor; + private final boolean isIndex; + private final boolean isTimed; + private final AlgDataType rowType; + + private final StatementEvent statementEvent; + + + public ResultIterator( Iterator iterator, Statement statement, int batch, boolean isTimed, boolean isIndex, boolean isAnalyzed, AlgDataType rowType, ExecutionTimeMonitor executionTimeMonitor ) { + this.iterator = iterator; + this.batch = batch; + this.isIndex = isIndex; + this.isTimed = isTimed; + this.statementEvent = isAnalyzed ? statement.getMonitoringEvent() : null; + this.executionTimeMonitor = executionTimeMonitor; + this.rowType = rowType; + } + + + public List> getNextBatch() { + + StopWatch stopWatch = null; + try { + if ( isTimed ) { + stopWatch = new StopWatch(); + stopWatch.start(); + } + List> res = new ArrayList<>(); + int i = 0; + while ( (batch < 0 || i++ < batch) && iterator.hasNext() ) { + res.add( Lists.newArrayList( iterator.next() ) ); + } + + //List> res = MetaImpl.collect( cursorFactory, (Iterator) iterator., new ArrayList<>() ).stream().map( e -> (List) e ).collect( Collectors.toList() ); + + if ( isTimed ) { + stopWatch.stop(); + executionTimeMonitor.setExecutionTime( stopWatch.getNanoTime() ); + } + + // Only if it is an index + if ( statementEvent != null && isIndex ) { + statementEvent.setIndexSize( res.size() ); + } + + return res; + } catch ( Throwable t ) { + try { + close(); + throw new GenericRuntimeException( t ); + } catch ( Exception e ) { + throw new GenericRuntimeException( t ); + } + + } + } + + + public List> getAllRowsAndClose() { + List> result = getNextBatch(); + try { + close(); + } catch ( Exception e ) { + throw new GenericRuntimeException( e ); + } + return result; + } + + + public List getSingleRows() { + return getNextBatch( null ); + } + + + @NotNull + private List getNextBatch( @Nullable Function transformer ) { + final Iterable iterable = () -> iterator; + + if ( transformer == null ) { + return (List) StreamSupport + .stream( iterable.spliterator(), false ) + .collect( Collectors.toList() ); + } + return StreamSupport + .stream( iterable.spliterator(), false ) + .map( transformer ) + .collect( Collectors.toList() ); + } + + + public List getArrayRows() { + + return getNextBatch( rowType.getFieldCount() == 1 ? e -> (PolyValue[]) e : null ); + + } + + + @Override + public void close() throws Exception { + try { + if ( iterator instanceof AutoCloseable ) { + ((AutoCloseable) iterator).close(); + } + } catch ( Exception e ) { + log.error( "Exception while closing result iterator", e ); + } + } + + + public static List> anyQuery( QueryContext queries ) { + LanguageContext operators = REGISTER.get( queries.getLanguage().getSerializedName() ); + List> iterators = new ArrayList<>(); + for ( QueryContext query : operators.getSplitter().apply( queries ) ) { + iterators.add( Pair.of( query, operators.getToIterator().apply( query ) ) ); + } + return iterators; + } + + + public static List>> anyQueryAsValues( QueryContext queries ) { + LanguageContext operators = REGISTER.get( queries.getLanguage().getSerializedName() ); + List> iters = anyQuery( queries ); + BiFunction>> operator = operators.getToPolyValue(); + return iters.stream().map( p -> operator.apply( p.left, p.right ) ).collect( Collectors.toList() ); + + } + + + public static void addLanguage( + String language, + LanguageContext function ) { + REGISTER.put( language, function ); + } + + + public static void removeLanguage( String name ) { + REGISTER.remove( name ); + } + + +} diff --git a/core/src/main/java/org/polypheny/db/adapter/index/Index.java b/core/src/main/java/org/polypheny/db/adapter/index/Index.java index 0b1808f864..573f3b8dcc 100644 --- a/core/src/main/java/org/polypheny/db/adapter/index/Index.java +++ b/core/src/main/java/org/polypheny/db/adapter/index/Index.java @@ -24,7 +24,7 @@ import java.util.stream.Collectors; import lombok.Getter; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.Kind; diff --git a/core/src/main/java/org/polypheny/db/processing/LanguageContext.java b/core/src/main/java/org/polypheny/db/processing/LanguageContext.java new file mode 100644 index 0000000000..2f106de8e5 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/processing/LanguageContext.java @@ -0,0 +1,32 @@ +/* + * 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.processing; + +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Function; +import lombok.Value; +import org.polypheny.db.type.entity.PolyValue; + +@Value +public class LanguageContext { + + Function> splitter; + Function toIterator; + BiFunction>> toPolyValue; + +} diff --git a/core/src/main/java/org/polypheny/db/processing/QueryContext.java b/core/src/main/java/org/polypheny/db/processing/QueryContext.java new file mode 100644 index 0000000000..2493ce0cb9 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/processing/QueryContext.java @@ -0,0 +1,59 @@ +/* + * 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.processing; + +import lombok.Value; +import lombok.experimental.NonFinal; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.languages.QueryLanguage; +import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.transaction.TransactionManager; + +@Value +public class QueryContext { + + String query; + + QueryLanguage language; + + boolean isAnalysed; + + boolean usesCache; + + long userId; + + String origin; + + int batch; // -1 for all + + TransactionManager manager; + + @NonFinal + Transaction transaction; + + + public Transaction openTransaction() { + return manager.startTransaction( userId, Catalog.defaultNamespaceId, isAnalysed, origin ); + } + + + public Transaction openTransaction( long namespaceId ) { + return manager.startTransaction( userId, namespaceId, isAnalysed, origin ); + } + + +} diff --git a/core/src/main/java/org/polypheny/db/processing/ResultContext.java b/core/src/main/java/org/polypheny/db/processing/ResultContext.java new file mode 100644 index 0000000000..b02deff147 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/processing/ResultContext.java @@ -0,0 +1,39 @@ +/* + * 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.processing; + + +import lombok.Value; +import org.polypheny.db.ResultIterator; + +@Value +public class ResultContext { + + ResultIterator iterator; + + String error; + + QueryContext query; + + double executionTime; + + + public static ResultContext ofError( String error, QueryContext context, double executionTime ) { + return new ResultContext( null, error, context, executionTime ); + } + +} diff --git a/dbms/build.gradle b/dbms/build.gradle index d2c29e588b..34e7197b72 100644 --- a/dbms/build.gradle +++ b/dbms/build.gradle @@ -74,10 +74,6 @@ dependencies { testImplementation group: "com.konghq", name: "unirest-java", version: unirest_version // MIT - // TODO MV: Remove these dependencies and reactivate the corresponding tests using docker deployed data stores - testImplementation group: "com.wix", name: "wix-embedded-mysql", version: embedded_mysql_version - testImplementation group: "io.zonky.test", name: "embedded-postgres", version: embedded_postgres_version - testImplementation group: "monetdb", name: "monetdb-java-lite", version: embedded_monetdb_version implementation group: "org.mongodb", name: "mongodb-driver-sync", version: mongodb_driver_sync_version // Apache 2.0 } 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 4427dd4e81..5aaa610af3 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -40,7 +40,7 @@ import org.apache.commons.lang3.time.StopWatch; import org.jetbrains.annotations.NotNull; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.DataContext.ParameterValue; import org.polypheny.db.adapter.index.Index; diff --git a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java index c5f3563c61..abe0a35a92 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java +++ b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java @@ -36,7 +36,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.AlgStructuredTypeFlattener; diff --git a/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java b/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java index c05d32490f..ae2f7f27ed 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java @@ -30,7 +30,7 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; import org.polypheny.db.algebra.AlgNode; diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java index 57b6a24894..14f15d35d2 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java @@ -23,7 +23,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.Kind; diff --git a/plugins/sql-language/build.gradle b/plugins/sql-language/build.gradle index 5c609d0fa7..8266981248 100644 --- a/plugins/sql-language/build.gradle +++ b/plugins/sql-language/build.gradle @@ -38,6 +38,9 @@ dependencies { implementation group: "net.sf.opencsv", name: "opencsv", version: opencsv_version // Apache 2.0 + implementation group: "com.j256.simplemagic", name: "simplemagic", version: simplemagic_version // ISC + + // --- Test Compile --- testImplementation project(path: ":dbms", configuration: "test") testImplementation project(path: ":dbms") diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java index 2223d1b3fc..3da539c36b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java @@ -19,14 +19,23 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; +import java.sql.ResultSetMetaData; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; +import java.util.Optional; import java.util.Properties; +import java.util.regex.Pattern; import java.util.stream.Collectors; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import org.apache.calcite.avatica.util.TimeUnit; +import org.jetbrains.annotations.Nullable; +import org.polypheny.db.PolyImplementation; +import org.polypheny.db.ResultIterator; import org.polypheny.db.adapter.java.JavaTypeFactory; +import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.FunctionCategory; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.constant.Modality; @@ -34,18 +43,35 @@ import org.polypheny.db.algebra.operators.ChainedOperatorTable; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.operators.OperatorTable; +import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.algebra.type.AlgDataTypeField; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalColumn; +import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.PolyphenyDbConnectionProperty; +import org.polypheny.db.config.RuntimeConfig; +import org.polypheny.db.information.InformationGroup; +import org.polypheny.db.information.InformationManager; +import org.polypheny.db.information.InformationPage; +import org.polypheny.db.information.InformationStacktrace; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.OperatorRegistry; +import org.polypheny.db.languages.QueryLanguage; +import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.sql.parser.impl.SqlParserImpl; import org.polypheny.db.nodes.LangFunctionOperator; +import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; +import org.polypheny.db.processing.LanguageContext; +import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext; +import org.polypheny.db.processing.ResultContext; import org.polypheny.db.sql.language.SqlAggFunction; import org.polypheny.db.sql.language.SqlAsOperator; import org.polypheny.db.sql.language.SqlBinaryOperator; @@ -155,19 +181,27 @@ import org.polypheny.db.sql.language.fun.SqlTranslate3Function; import org.polypheny.db.sql.language.fun.SqlTrimFunction; import org.polypheny.db.sql.language.validate.PolyphenyDbSqlValidator; +import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.type.OperandCountRange; import org.polypheny.db.type.PolyOperandCountRanges; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.checker.OperandTypes; +import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.inference.InferTypes; import org.polypheny.db.type.inference.ReturnTypes; import org.polypheny.db.util.Conformance; import org.polypheny.db.util.Litmus; import org.polypheny.db.util.Optionality; -import org.polypheny.db.webui.Crud; -import org.polypheny.db.webui.crud.LanguageCrud; -import org.polypheny.db.webui.models.results.Result; - +import org.polypheny.db.util.Pair; +import org.polypheny.db.webui.Crud.QueryExecutionException; +import org.polypheny.db.webui.models.SortState; +import org.polypheny.db.webui.models.catalog.UiColumnDefinition; +import org.polypheny.db.webui.models.catalog.UiColumnDefinition.UiColumnDefinitionBuilder; +import org.polypheny.db.webui.models.results.RelationalResult; + +@Slf4j public class SqlLanguagePlugin extends PolyPlugin { @Getter @@ -197,13 +231,12 @@ public void stop() { public static void startup() { - PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.crud.languageCrud.addLanguage( "sql", ( - session, - request, - transactionManager, - userId, - databaseId, - c ) -> Crud.anySqlQuery( request, session, c ).stream().map( r -> (Result) r ).collect( Collectors.toList() ) ) ); + PolyPluginManager.AFTER_INIT.add( () -> { + ResultIterator.addLanguage( "sql", new LanguageContext( + queries -> split( queries ), + query -> anySqlQuery( query ), + ( query, iter ) -> computeValues( query, iter ) ) ); + } ); LanguageManager.getINSTANCE().addQueryLanguage( NamespaceType.RELATIONAL, "sql", List.of( "sql" ), SqlParserImpl.FACTORY, SqlProcessor::new, SqlLanguagePlugin::getSqlValidator ); if ( !isInit() ) { @@ -212,6 +245,215 @@ public static void startup() { } + private static List> computeValues( QueryContext query, ResultContext context ) { + LogicalTable table = null; + if ( request.entityId != null ) { + table = Catalog.snapshot().rel().getTable( request.entityId ).orElseThrow(); + } + + List header = new ArrayList<>(); + for ( AlgDataTypeField metaData : implementation.getRowType().getFields() ) { + String columnName = metaData.getName(); + + String filter = ""; + if ( request.filter != null && request.filter.containsKey( columnName ) ) { + filter = request.filter.get( columnName ); + } + + SortState sort; + if ( request.sortState != null && request.sortState.containsKey( columnName ) ) { + sort = request.sortState.get( columnName ); + } else { + sort = new SortState(); + } + + UiColumnDefinitionBuilder dbCol = UiColumnDefinition.builder() + .name( metaData.getName() ) + .dataType( metaData.getType().getPolyType().getTypeName() ) + .nullable( metaData.getType().isNullable() == (ResultSetMetaData.columnNullable == 1) ) + .precision( metaData.getType().getPrecision() ) + .sort( sort ) + .filter( filter ); + + // Get column default values + if ( table != null ) { + Optional logicalColumn = Catalog.snapshot().rel().getColumn( table.id, columnName ); + if ( logicalColumn.isPresent() ) { + if ( logicalColumn.get().defaultValue != null ) { + dbCol.defaultValue( logicalColumn.get().defaultValue.value.toJson() ); + } + } + } + header.add( dbCol.build() ); + } + + List data = computeResultData( rows, header, statement.getTransaction() ); + + return RelationalResult.builder() + .header( header.toArray( new UiColumnDefinition[0] ) ) + .data( data.toArray( new String[0][] ) ) + .namespaceType( implementation.getNamespaceType() ) + .language( QueryLanguage.from( "sql" ) ) + .affectedTuples( data.size() ) + .hasMore( hasMoreRows ); + } + + + private static @Nullable List split( QueryContext queries ) { + try { + return queries.openTransaction().getProcessor( QueryLanguage.from( "sql" ) ).splitStatements( queries.getQuery() ).stream().map( q -> new QueryContext( + q, + queries.getLanguage(), + queries.isAnalysed(), + queries.isUsesCache(), + queries.getUserId(), + queries.getOrigin(), + queries.getBatch(), + queries.getManager(), + queries.getTransaction() ) ).collect( Collectors.toList() ); + } catch ( RuntimeException e ) { + return null; + } + } + + + /** + * Run any query coming from the SQL console + */ + public static ResultContext anySqlQuery( final QueryContext context ) { + Transaction transaction = context.getTransaction(); + long executionTime = 0; + long temp = 0; + boolean noLimit; + String query = context.getQuery(); + Pattern p = Pattern.compile( ".*(COMMIT|ROLLBACK).*", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.DOTALL ); + if ( p.matcher( context.getQuery() ).matches() ) { + temp = System.nanoTime(); + boolean isCommit = Pattern.matches( "(?si:[\\s]*COMMIT.*)", query ); + try { + if ( Pattern.matches( "(?si:[\\s]*COMMIT.*)", query ) ) { + transaction.commit(); + } else { + transaction.rollback(); + } + + executionTime += System.nanoTime() - temp; + return new ResultContext( null, null, context.getQuery(), context.getLanguage(), transaction, executionTime ); + } catch ( TransactionException e ) { + log.error( String.format( "Caught exception while %s a query from the console", isCommit ? "committing" : "rolling back" ), e ); + executionTime += System.nanoTime() - temp; + log.error( e.toString() ); + } + } else if ( Pattern.matches( "(?si:^[\\s]*[/(\\s]*SELECT.*)", query ) ) { + try { + temp = System.nanoTime(); + ResultIterator iter = SqlLanguagePlugin.executeSqlSelect( transaction.createStatement(), context ); + executionTime += System.nanoTime() - temp; + return new ResultContext( iter, null, context.getQuery(), context.getLanguage(), transaction, executionTime ); + } catch ( QueryExecutionException | RuntimeException e ) { + log.error( "Caught exception while executing a query from the console", e ); + executionTime += System.nanoTime() - temp; + return new ResultContext( null, e.getCause().getMessage(), context.getQuery(), context.getLanguage(), transaction, executionTime ); + } + } + try { + temp = System.nanoTime(); + ResultIterator iterator = SqlLanguagePlugin.executeSqlUpdate( transaction.createStatement(), transaction, context ); + executionTime += System.nanoTime() - temp; + + return new ResultContext( iterator, null, context.getQuery(), context.getLanguage(), transaction, executionTime ); + } catch ( QueryExecutionException | RuntimeException e ) { + log.error( "Caught exception while executing a query from the console", e ); + executionTime += System.nanoTime() - temp; + return new ResultContext( null, e.getMessage(), context.getQuery(), context.getLanguage(), transaction, executionTime ); + } + + } + + + public static ResultIterator executeSqlSelect( final Statement statement, final QueryContext context ) throws QueryExecutionException { + PolyImplementation implementation; + boolean isAnalyze = statement.getTransaction().isAnalyze(); + + try { + implementation = processQuery( statement, context.getQuery(), isAnalyze ); + return implementation.execute( statement, context.getBatch(), isAnalyze, true, false ); + + } catch ( Throwable t ) { + if ( statement.getTransaction().isAnalyze() ) { + InformationManager analyzer = statement.getTransaction().getQueryAnalyzer(); + InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); + InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); + InformationStacktrace exceptionElement = new InformationStacktrace( t, exceptionGroup ); + analyzer.addPage( exceptionPage ); + analyzer.addGroup( exceptionGroup ); + analyzer.registerInformation( exceptionElement ); + } + throw new GenericRuntimeException( t ); + } + } + + + private static PolyImplementation processQuery( Statement statement, String sql, boolean isAnalyze ) { + PolyImplementation implementation; + if ( isAnalyze ) { + statement.getOverviewDuration().start( "Parsing" ); + } + Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); + Node parsed = sqlProcessor.parse( sql ).get( 0 ); + if ( isAnalyze ) { + statement.getOverviewDuration().stop( "Parsing" ); + } + AlgRoot logicalRoot; + QueryParameters parameters = new QueryParameters( sql, NamespaceType.RELATIONAL ); + if ( parsed.isA( Kind.DDL ) ) { + implementation = sqlProcessor.prepareDdl( statement, parsed, parameters ); + } else { + if ( isAnalyze ) { + statement.getOverviewDuration().start( "Validation" ); + } + Pair validated = sqlProcessor.validate( statement.getTransaction(), parsed, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ); + if ( isAnalyze ) { + statement.getOverviewDuration().stop( "Validation" ); + statement.getOverviewDuration().start( "Translation" ); + } + logicalRoot = sqlProcessor.translate( statement, validated.left, parameters ); + if ( isAnalyze ) { + statement.getOverviewDuration().stop( "Translation" ); + } + implementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); + } + return implementation; + } + + + private static ResultIterator executeSqlUpdate( final Statement statement, final Transaction transaction, final QueryContext context ) throws QueryExecutionException { + PolyImplementation implementation; + + try { + implementation = processQuery( statement, context.getQuery(), transaction.isAnalyze() ); + } catch ( Throwable t ) { + if ( transaction.isAnalyze() ) { + InformationManager analyzer = transaction.getQueryAnalyzer(); + InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); + InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); + InformationStacktrace exceptionElement = new InformationStacktrace( t, exceptionGroup ); + analyzer.addPage( exceptionPage ); + analyzer.addGroup( exceptionGroup ); + analyzer.registerInformation( exceptionElement ); + } + throw new GenericRuntimeException( t.getMessage(), t ); + + + } + try { + return implementation.execute( statement ); + } catch ( Exception e ) { + throw new GenericRuntimeException( e ); + } + } + + public static PolyphenyDbSqlValidator getSqlValidator( org.polypheny.db.prepare.Context context, Snapshot snapshot ) { final OperatorTable opTab0 = fun( OperatorTable.class, SqlStdOperatorTable.instance() ); diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index f8946ff374..f0bab50527 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -76,7 +76,7 @@ import org.apache.commons.io.IOUtils; import org.eclipse.jetty.websocket.api.Session; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.adapter.AbstractAdapterSetting; import org.polypheny.db.adapter.AbstractAdapterSettingDirectory; import org.polypheny.db.adapter.Adapter; @@ -157,6 +157,7 @@ import org.polypheny.db.plugins.PolyPluginManager; import org.polypheny.db.plugins.PolyPluginManager.PluginStatus; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext; import org.polypheny.db.security.SecurityManager; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; @@ -2807,16 +2808,15 @@ else if ( !namespace.isCreate() && namespace.isDrop() ) { private void createGraph( Namespace namespace, Context ctx ) { QueryLanguage cypher = QueryLanguage.from( "cypher" ); - ctx.json( - LanguageCrud.anyQuery( cypher, null, - new QueryRequest( - "CREATE DATABASE " + namespace.getName() + " ON STORE " + namespace.getStore(), - false, - true, "cypher", - namespace.getName() ), - transactionManager, - Catalog.defaultUserId, - Catalog.defaultNamespaceId ).get( 0 ) ); + QueryContext context = new QueryContext( "CREATE DATABASE " + namespace.getName() + " ON STORE " + namespace.getStore(), + cypher, + false, + true, + Catalog.defaultUserId, + "Polypheny-UI", + -1, + transactionManager ); + ctx.json( LanguageCrud.anyQueryResult( context ).get( 0 ) ); } 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 b1ed3cdfc0..722396dc21 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 @@ -24,14 +24,14 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.BiFunction; import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.websocket.api.Session; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.polypheny.db.PolyImplementation; -import org.polypheny.db.PolyImplementation.ResultIterator; +import org.polypheny.db.ResultIterator; import org.polypheny.db.adapter.Adapter; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.algebra.AlgRoot; @@ -53,12 +53,14 @@ import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.processing.ExtendedQueryParameters; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.graph.PolyGraph; +import org.polypheny.db.util.Pair; import org.polypheny.db.util.PolyphenyMode; import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.models.IndexModel; @@ -82,7 +84,7 @@ public class LanguageCrud { public static Crud crud; - public final static Map>>> REGISTER = new HashMap<>(); + public final static Map>> REGISTER = new HashMap<>(); public LanguageCrud( Crud crud ) { @@ -93,20 +95,15 @@ public LanguageCrud( Crud crud ) { public static void anyQuery( Context ctx ) { QueryRequest request = ctx.bodyAsClass( QueryRequest.class ); QueryLanguage language = QueryLanguage.from( request.language ); - Result result = anyQuery( language, null, request, crud.getTransactionManager(), Catalog.defaultUserId, Catalog.defaultNamespaceId ).get( 0 ); - ctx.json( result ); + QueryContext context = new QueryContext( request.query, language, request.analyze, request.cache, Catalog.defaultUserId, "Polypheny UI", request.noLimit ? -1 : crud.getPageSize(), crud.getTransactionManager() ); + ctx.json( anyQueryResult( context ) ); } - public static List> anyQuery( - QueryLanguage language, - Session session, - QueryRequest request, - TransactionManager transactionManager, - long userId, - long namespaceId ) { - - return REGISTER.get( language.getSerializedName() ).apply( session, request, transactionManager, userId, namespaceId, crud ); + public static List> anyQueryResult( QueryContext context ) { + List> iterators = ResultIterator.anyQuery( context ); + BiFunction> resultProducer = REGISTER.get( context.getLanguage() ); + return iterators.stream().map( p -> resultProducer.apply( p.left, p.right ) ).collect( Collectors.toList() ); } @@ -192,7 +189,6 @@ public static void attachError( Transaction transaction, List> resu throw new GenericRuntimeException( "Unknown data model." ); } - if ( transaction.isActive() ) { try { transaction.rollback(); @@ -425,31 +421,5 @@ public void getCollectionPlacements( Context context ) { } - public void addLanguage( - String language, - Consumer7>> function ) { - REGISTER.put( language, function ); - } - - - public void removeLanguage( String name ) { - REGISTER.remove( name ); - } - - - @FunctionalInterface - public interface Consumer7 { - - Seven apply( One one, Two two, Three three, Four four, Five five, Six six ); - - } - - } From 39947b1cedf449ff6a6046d7064225d4a7fc9ef2 Mon Sep 17 00:00:00 2001 From: datomo Date: Sun, 26 Nov 2023 01:15:55 +0100 Subject: [PATCH 05/15] streamlining query execution --- .../org/polypheny/db/PolyImplementation.java | 24 +- .../java/org/polypheny/db/ResultIterator.java | 68 +- .../org/polypheny/db/StatisticsManager.java | 6 +- .../db/adapter/AbstractAdapterSetting.java | 2 +- .../polypheny/db/algebra/constant/Kind.java | 3 - .../db/catalog/entity/LogicalEntity.java | 2 +- .../db/languages/LanguageManager.java | 141 ++- .../polypheny/db/languages/QueryLanguage.java | 39 +- .../db/monitoring/events/StatementEvent.java | 2 +- .../db/nodes/ExecutableStatement.java | 4 +- .../java/org/polypheny/db/nodes/Node.java | 12 + .../nodes/UnsupportedExecutableStatement.java | 4 +- .../db/plugins/PolyPluginManager.java | 26 +- .../db/processing/AutomaticDdlProcessor.java | 3 +- .../db/processing/ImplementationContext.java | 82 ++ .../db/processing/LanguageContext.java | 5 +- .../polypheny/db/processing/Processor.java | 47 +- .../polypheny/db/processing/QueryContext.java | 67 +- .../db/processing/ResultContext.java | 39 - .../db/schema/impl/AbstractEntity.java | 2 +- .../polypheny/db/catalog/MockIdentifier.java | 7 + ...elOptUtilTest.java => AlgOptUtilTest.java} | 4 +- .../java/org/polypheny/db/PolyphenyDb.java | 7 +- .../polypheny/db/processing/AlgProcessor.java | 7 +- .../{FileAdapterTest.java => FileTest.java} | 12 +- .../db/adapter/GoogleSheetSourceTest.java | 129 --- .../db/adapter/MonetdbSourceTest.java | 82 -- .../polypheny/db/adapter/MysqlSourceTest.java | 83 -- .../db/adapter/PostgresSourceTest.java | 84 -- .../db/statistics/StatisticsTest.java | 6 +- gradle.properties | 2 +- .../events/metrics/DmlDataPoint.java | 2 +- .../events/metrics/QueryDataPointImpl.java | 2 +- .../statistics/StatisticRepository.java | 6 +- .../monitoring/statistics/StatisticTable.java | 4 +- .../statistics/StatisticsManagerImpl.java | 10 +- .../org/polypheny/db/avatica/DbmsMeta.java | 35 +- ...elConverter.java => Cql2AlgConverter.java} | 6 +- .../polypheny/db/cql/CqlLanguagePlugin.java | 119 +- .../org/polypheny/db/cql/CqlProcessor.java | 95 ++ .../java/org/polypheny/db/cql/CqlQuery.java | 58 +- .../org/polypheny/db/cql/CqlQueryBuilder.java | 14 +- .../db/cypher/CypherLanguagePlugin.java | 117 +- .../org/polypheny/db/cypher/CypherNode.java | 36 +- .../polypheny/db/cypher/CypherProcessor.java | 6 +- .../admin/CypherAlterDatabaseAlias.java | 4 +- .../db/cypher/admin/CypherCreateDatabase.java | 11 +- .../admin/CypherCreateDatabaseAlias.java | 11 +- .../db/cypher/admin/CypherDropAlias.java | 4 +- .../db/cypher/admin/CypherDropDatabase.java | 11 +- .../cypher/clause/CypherCreateConstraint.java | 4 +- .../db/cypher/clause/CypherUseClause.java | 4 +- .../cypher2alg/CypherToAlgConverter.java | 16 +- .../db/cypher/ddl/CypherAddPlacement.java | 4 +- .../db/cypher/ddl/CypherDropPlacement.java | 4 +- .../db/cypher/expression/CypherUseGraph.java | 6 +- .../db/cypher/query/CypherSingleQuery.java | 6 +- plugins/explore-by-example/build.gradle | 80 -- plugins/explore-by-example/gradle.properties | 27 - .../db/exploreByExample/Explore.java | 527 --------- .../ExploreByExamplePlugin.java | 82 -- .../db/exploreByExample/ExploreManager.java | 357 ------ .../ExploreQueryProcessor.java | 195 ---- .../exploreByExample/ExploreQueryResult.java | 54 - .../db/exploreByExample/WekaToSql.java | 133 --- .../models/RelationalExploreResult.java | 74 -- .../db/exploreByExample/ExploreTest.java | 50 - .../db/exploreByExample/MockProcessor.java | 45 - .../db/http/HttpInterfacePlugin.java | 25 +- .../AlgToSqlConverterTest.java | 20 +- .../{rel2sql => alg2sql}/PlannerTest.java | 2 +- .../plan/AlgOptPlanReaderTest.java | 29 +- .../rel2sql/RelToSqlConverterStructsTest.java | 264 ----- .../db/languages/MongoLanguagePlugin.java | 123 +- .../polypheny/db/languages/MqlProcessor.java | 16 +- .../db/languages/mql/MqlAddPlacement.java | 13 +- .../db/languages/mql/MqlAggregate.java | 7 + .../polypheny/db/languages/mql/MqlCount.java | 7 + .../db/languages/mql/MqlCreateCollection.java | 13 +- .../db/languages/mql/MqlCreateView.java | 21 +- .../polypheny/db/languages/mql/MqlDelete.java | 7 + .../db/languages/mql/MqlDeletePlacement.java | 13 +- .../polypheny/db/languages/mql/MqlDrop.java | 13 +- .../db/languages/mql/MqlDropDatabase.java | 7 +- .../polypheny/db/languages/mql/MqlFind.java | 7 + .../db/languages/mql/MqlFindAndModify.java | 7 + .../languages/mql/MqlFindOneAndReplace.java | 7 + .../db/languages/mql/MqlFindOneAndUpdate.java | 7 + .../polypheny/db/languages/mql/MqlInsert.java | 7 + .../polypheny/db/languages/mql/MqlNode.java | 21 +- .../polypheny/db/languages/mql/MqlRemove.java | 7 + .../db/languages/mql/MqlRenameCollection.java | 13 +- .../db/languages/mql/MqlReplace.java | 7 + .../polypheny/db/languages/mql/MqlSave.java | 7 + .../polypheny/db/languages/mql/MqlUpdate.java | 7 + .../db/languages/mql/MqlUseDatabase.java | 4 +- .../languages/mql2alg/MqlToAlgConverter.java | 12 +- .../polypheny/db/mql/mql2alg/Mql2AlgTest.java | 11 +- .../db/notebooks/model/JupyterKernel.java | 16 +- .../org/polypheny/db/PigLanguagePlugin.java | 106 +- .../java/org/polypheny/db/piglet/Ast.java | 22 +- .../org/polypheny/db/piglet/PigProcessor.java | 5 +- .../polypheny/db/sql/SqlLanguagePlugin.java | 264 +---- .../org/polypheny/db/sql/SqlProcessor.java | 5 +- .../polypheny/db/sql/language/SqlDelete.java | 7 + .../db/sql/language/SqlIdentifier.java | 8 + .../polypheny/db/sql/language/SqlInsert.java | 7 + .../polypheny/db/sql/language/SqlMerge.java | 7 + .../polypheny/db/sql/language/SqlNode.java | 7 + .../polypheny/db/sql/language/SqlSelect.java | 7 + .../db/sql/language/SqlSetOption.java | 4 +- .../polypheny/db/sql/language/SqlUpdate.java | 7 + .../sql/language/ddl/SqlAlterAdaptersAdd.java | 4 +- .../language/ddl/SqlAlterAdaptersDrop.java | 4 +- .../db/sql/language/ddl/SqlAlterConfig.java | 4 +- .../language/ddl/SqlAlterInterfacesAdd.java | 4 +- .../language/ddl/SqlAlterInterfacesDrop.java | 4 +- .../ddl/SqlCreateMaterializedView.java | 29 +- .../sql/language/ddl/SqlCreateNamespace.java | 4 +- .../db/sql/language/ddl/SqlCreateTable.java | 4 +- .../db/sql/language/ddl/SqlCreateType.java | 4 +- .../db/sql/language/ddl/SqlCreateView.java | 19 +- .../db/sql/language/ddl/SqlDropFunction.java | 4 +- .../language/ddl/SqlDropMaterializedView.java | 4 +- .../db/sql/language/ddl/SqlDropNamespace.java | 4 +- .../db/sql/language/ddl/SqlDropTable.java | 4 +- .../db/sql/language/ddl/SqlDropType.java | 4 +- .../db/sql/language/ddl/SqlDropView.java | 4 +- .../db/sql/language/ddl/SqlTruncate.java | 4 +- .../SqlAlterMaterializedViewAddIndex.java | 4 +- .../SqlAlterMaterializedViewDropIndex.java | 4 +- ...lAlterMaterializedViewFreshnessManual.java | 4 +- .../SqlAlterMaterializedViewRename.java | 4 +- .../SqlAlterMaterializedViewRenameColumn.java | 4 +- .../SqlAlterNamespaceOwner.java | 4 +- .../SqlAlterNamespaceRename.java | 4 +- .../SqlAlterSourceTableAddColumn.java | 4 +- .../altertable/SqlAlterTableAddColumn.java | 4 +- .../SqlAlterTableAddForeignKey.java | 4 +- .../ddl/altertable/SqlAlterTableAddIndex.java | 4 +- .../SqlAlterTableAddPartitions.java | 4 +- .../altertable/SqlAlterTableAddPlacement.java | 4 +- .../SqlAlterTableAddPrimaryKey.java | 4 +- .../SqlAlterTableAddUniqueConstraint.java | 4 +- .../altertable/SqlAlterTableDropColumn.java | 4 +- .../SqlAlterTableDropConstraint.java | 4 +- .../SqlAlterTableDropForeignKey.java | 4 +- .../altertable/SqlAlterTableDropIndex.java | 4 +- .../SqlAlterTableDropPlacement.java | 4 +- .../SqlAlterTableDropPrimaryKey.java | 4 +- .../SqlAlterTableMergePartitions.java | 4 +- .../altertable/SqlAlterTableModifyColumn.java | 4 +- .../SqlAlterTableModifyPartitions.java | 4 +- .../SqlAlterTableModifyPlacement.java | 4 +- ...SqlAlterTableModifyPlacementAddColumn.java | 4 +- ...qlAlterTableModifyPlacementDropColumn.java | 4 +- .../ddl/altertable/SqlAlterTableOwner.java | 4 +- .../ddl/altertable/SqlAlterTableRename.java | 4 +- .../altertable/SqlAlterTableRenameColumn.java | 4 +- .../ddl/alterview/SqlAlterViewRename.java | 4 +- .../alterview/SqlAlterViewRenameColumn.java | 4 +- settings.gradle | 1 - .../java/org/polypheny/db/webui/Crud.java | 1002 +++++------------ .../org/polypheny/db/webui/WebSocket.java | 58 +- .../polypheny/db/webui/crud/LanguageCrud.java | 219 ++-- .../db/webui/crud/ResultBuilderContext.java | 21 +- .../db/webui/models/results/Result.java | 2 +- 167 files changed, 1654 insertions(+), 4281 deletions(-) create mode 100644 core/src/main/java/org/polypheny/db/processing/ImplementationContext.java delete mode 100644 core/src/main/java/org/polypheny/db/processing/ResultContext.java rename core/src/test/java/org/polypheny/db/plan/{RelOptUtilTest.java => AlgOptUtilTest.java} (99%) rename dbms/src/test/java/org/polypheny/db/adapter/{FileAdapterTest.java => FileTest.java} (97%) delete mode 100644 dbms/src/test/java/org/polypheny/db/adapter/GoogleSheetSourceTest.java delete mode 100644 dbms/src/test/java/org/polypheny/db/adapter/MonetdbSourceTest.java delete mode 100644 dbms/src/test/java/org/polypheny/db/adapter/MysqlSourceTest.java delete mode 100644 dbms/src/test/java/org/polypheny/db/adapter/PostgresSourceTest.java rename plugins/cql-language/src/main/java/org/polypheny/db/cql/{Cql2RelConverter.java => Cql2AlgConverter.java} (98%) create mode 100644 plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlProcessor.java delete mode 100644 plugins/explore-by-example/build.gradle delete mode 100644 plugins/explore-by-example/gradle.properties delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/Explore.java delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreByExamplePlugin.java delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreManager.java delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryResult.java delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/WekaToSql.java delete mode 100644 plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/models/RelationalExploreResult.java delete mode 100644 plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/ExploreTest.java delete mode 100644 plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/MockProcessor.java rename plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/{rel2sql => alg2sql}/AlgToSqlConverterTest.java (99%) rename plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/{rel2sql => alg2sql}/PlannerTest.java (99%) rename plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/{rel2sql => alg2sql}/plan/AlgOptPlanReaderTest.java (78%) delete mode 100644 plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/RelToSqlConverterStructsTest.java rename plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/requests/ClassifyAllData.java => webui/src/main/java/org/polypheny/db/webui/crud/ResultBuilderContext.java (58%) diff --git a/core/src/main/java/org/polypheny/db/PolyImplementation.java b/core/src/main/java/org/polypheny/db/PolyImplementation.java index d9b3b20ef6..f3ed0e0e96 100644 --- a/core/src/main/java/org/polypheny/db/PolyImplementation.java +++ b/core/src/main/java/org/polypheny/db/PolyImplementation.java @@ -37,6 +37,7 @@ import org.polypheny.db.adapter.DataContext; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.algebra.type.AlgDataTypeFactory.Builder; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.interpreter.BindableConvention; @@ -50,6 +51,8 @@ import org.polypheny.db.runtime.Bindable; import org.polypheny.db.runtime.Typed; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.type.PolyType; +import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.category.PolyNumber; @@ -72,9 +75,6 @@ public class PolyImplementation { @Accessors(fluent = true) private final boolean isDDL; private Iterator iterator; - private boolean isOpen; - private StatementEvent statementEvent; - private int batch; /** @@ -98,7 +98,7 @@ public PolyImplementation( Kind kind, Statement statement, @Nullable Convention resultConvention ) { - this.rowType = rowType; + this.namespaceType = namespaceType; this.executionTimeMonitor = executionTimeMonitor; this.preparedResult = preparedResult; @@ -106,8 +106,14 @@ public PolyImplementation( this.statement = statement; this.resultConvention = resultConvention; this.isDDL = Kind.DDL.contains( kind ); + if ( this.isDDL ) { this.columns = ImmutableList.of(); + Builder builder = statement.getTransaction().getTypeFactory().builder(); + builder.add( "ROWTYPE", null, PolyType.BIGINT ); + this.rowType = builder.build(); + } else { + this.rowType = rowType; } } @@ -159,7 +165,7 @@ public CursorFactory getCursorFactory() { public Bindable getBindable() { if ( Kind.DDL.contains( kind ) ) { - return null; + return dataContext -> Linq4j.singletonEnumerable( new PolyInteger[]{ PolyInteger.of( 1 ) } ); } if ( bindable != null ) { @@ -207,11 +213,6 @@ public List getColumns() { } - public ResultIterator execute( Statement statement ) { - return execute( statement, -1, false, false, false ); - } - - public ResultIterator execute( Statement statement, int batch ) { return execute( statement, batch, false, false, false ); } @@ -226,7 +227,8 @@ public ResultIterator execute( Statement statement, int batch, boolean isAnalyze isIndex, isAnalyzed, rowType, - executionTimeMonitor ); + executionTimeMonitor, + this ); } diff --git a/core/src/main/java/org/polypheny/db/ResultIterator.java b/core/src/main/java/org/polypheny/db/ResultIterator.java index 1cfb50fd00..5f5224c848 100644 --- a/core/src/main/java/org/polypheny/db/ResultIterator.java +++ b/core/src/main/java/org/polypheny/db/ResultIterator.java @@ -20,50 +20,43 @@ import com.google.common.collect.Lists; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import javax.annotation.Nullable; +import lombok.Value; import org.apache.commons.lang3.time.StopWatch; import org.jetbrains.annotations.NotNull; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.monitoring.events.StatementEvent; -import org.polypheny.db.processing.LanguageContext; -import org.polypheny.db.processing.QueryContext; -import org.polypheny.db.processing.ResultContext; import org.polypheny.db.routing.ExecutionTimeMonitor; import org.polypheny.db.transaction.Statement; import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.util.Pair; +@Value public class ResultIterator implements AutoCloseable { - public final static Map REGISTER = new HashMap<>(); + Iterator iterator; + int batch; + ExecutionTimeMonitor executionTimeMonitor; + boolean isIndex; + boolean isTimed; + AlgDataType rowType; + StatementEvent statementEvent; + PolyImplementation implementation; - private final Iterator iterator; - private final int batch; - private final ExecutionTimeMonitor executionTimeMonitor; - private final boolean isIndex; - private final boolean isTimed; - private final AlgDataType rowType; - - private final StatementEvent statementEvent; - - - public ResultIterator( Iterator iterator, Statement statement, int batch, boolean isTimed, boolean isIndex, boolean isAnalyzed, AlgDataType rowType, ExecutionTimeMonitor executionTimeMonitor ) { + public ResultIterator( Iterator iterator, Statement statement, int batch, boolean isTimed, boolean isIndex, boolean isAnalyzed, AlgDataType rowType, ExecutionTimeMonitor executionTimeMonitor, PolyImplementation implementation ) { this.iterator = iterator; this.batch = batch; this.isIndex = isIndex; this.isTimed = isTimed; this.statementEvent = isAnalyzed ? statement.getMonitoringEvent() : null; this.executionTimeMonitor = executionTimeMonitor; + this.implementation = implementation; this.rowType = rowType; } @@ -107,6 +100,11 @@ public List> getNextBatch() { } + public boolean hasMoreRows() { + return implementation.hasMoreRows(); + } + + public List> getAllRowsAndClose() { List> result = getNextBatch(); try { @@ -157,36 +155,4 @@ public void close() throws Exception { } } - - public static List> anyQuery( QueryContext queries ) { - LanguageContext operators = REGISTER.get( queries.getLanguage().getSerializedName() ); - List> iterators = new ArrayList<>(); - for ( QueryContext query : operators.getSplitter().apply( queries ) ) { - iterators.add( Pair.of( query, operators.getToIterator().apply( query ) ) ); - } - return iterators; - } - - - public static List>> anyQueryAsValues( QueryContext queries ) { - LanguageContext operators = REGISTER.get( queries.getLanguage().getSerializedName() ); - List> iters = anyQuery( queries ); - BiFunction>> operator = operators.getToPolyValue(); - return iters.stream().map( p -> operator.apply( p.left, p.right ) ).collect( Collectors.toList() ); - - } - - - public static void addLanguage( - String language, - LanguageContext function ) { - REGISTER.put( language, function ); - } - - - public static void removeLanguage( String name ) { - REGISTER.remove( name ); - } - - } diff --git a/core/src/main/java/org/polypheny/db/StatisticsManager.java b/core/src/main/java/org/polypheny/db/StatisticsManager.java index 17ce8d1109..daf3d82977 100644 --- a/core/src/main/java/org/polypheny/db/StatisticsManager.java +++ b/core/src/main/java/org/polypheny/db/StatisticsManager.java @@ -59,7 +59,7 @@ public static StatisticsManager getInstance() { public abstract void deleteTableToUpdate( long tableId ); - public abstract void updateRowCountPerTable( long tableId, int number, MonitoringType type ); + public abstract void updateRowCountPerTable( long tableId, long number, MonitoringType type ); public abstract void setIndexSize( long tableId, int indexSize ); @@ -73,9 +73,9 @@ public static StatisticsManager getInstance() { public abstract Map getQualifiedStatisticMap(); - public abstract > Object getTableStatistic( long schemaId, long tableId ); + public abstract Object getTableStatistic( long schemaId, long tableId ); - public abstract Integer rowCountPerTable( long tableId ); + public abstract Long rowCountPerTable( long tableId ); public abstract void updateCommitRollback( boolean committed ); diff --git a/core/src/main/java/org/polypheny/db/adapter/AbstractAdapterSetting.java b/core/src/main/java/org/polypheny/db/adapter/AbstractAdapterSetting.java index 91ed1b4564..a74d490e51 100644 --- a/core/src/main/java/org/polypheny/db/adapter/AbstractAdapterSetting.java +++ b/core/src/main/java/org/polypheny/db/adapter/AbstractAdapterSetting.java @@ -116,7 +116,7 @@ public static List fromAnnotations( Annotation[] annotat false, Arrays.stream( properties.usedModes() ).map( DeployMode::getName ).collect( Collectors.toList() ), List.of( DeploySetting.ALL ), - properties.usedModes()[0].getName(), + properties.defaultMode().getName(), 0 ) ); return settings; diff --git a/core/src/main/java/org/polypheny/db/algebra/constant/Kind.java b/core/src/main/java/org/polypheny/db/algebra/constant/Kind.java index 5295f8fb39..da6ca6fc82 100644 --- a/core/src/main/java/org/polypheny/db/algebra/constant/Kind.java +++ b/core/src/main/java/org/polypheny/db/algebra/constant/Kind.java @@ -1228,9 +1228,6 @@ public enum Kind { /** * DDL statement not handled above. * - * Note to other projects: If you are extending Polypheny-DB's SQL parser and have your own object types you no - * doubt want to define CREATE and DROP commands for them. Use OTHER_DDL in the short term, but we are happy to add new - * enum values for your object types. Just ask! */ OTHER_DDL, diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java index 428c9e32a1..8c408c4c2a 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java @@ -116,7 +116,7 @@ public boolean isRolledUp( String fieldName ) { public double getRowCount() { - Integer count = StatisticsManager.getInstance().rowCountPerTable( id ); + Long count = StatisticsManager.getInstance().rowCountPerTable( id ); if ( count == null ) { return 0; } diff --git a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java index bb5daf3af0..fe41e8a3d8 100644 --- a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java +++ b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java @@ -20,14 +20,25 @@ import java.beans.PropertyChangeSupport; import java.util.ArrayList; import java.util.List; -import java.util.function.BiFunction; -import java.util.function.Supplier; +import java.util.stream.Collectors; import lombok.Getter; -import org.polypheny.db.catalog.logistic.NamespaceType; -import org.polypheny.db.catalog.snapshot.Snapshot; -import org.polypheny.db.nodes.validate.Validator; -import org.polypheny.db.prepare.Context; +import org.polypheny.db.PolyImplementation; +import org.polypheny.db.algebra.AlgRoot; +import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.config.RuntimeConfig; +import org.polypheny.db.information.InformationGroup; +import org.polypheny.db.information.InformationManager; +import org.polypheny.db.information.InformationPage; +import org.polypheny.db.information.InformationStacktrace; +import org.polypheny.db.nodes.Node; +import org.polypheny.db.processing.ImplementationContext; +import org.polypheny.db.processing.ImplementationContext.ExecutedContext; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; +import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.util.Pair; public class LanguageManager { @@ -59,8 +70,7 @@ public void removeObserver( PropertyChangeListener listener ) { } - public void addQueryLanguage( NamespaceType namespaceType, String serializedName, List otherNames, ParserFactory factory, Supplier processorSupplier, BiFunction validatorSupplier ) { - QueryLanguage language = new QueryLanguage( namespaceType, serializedName, otherNames, factory, processorSupplier, validatorSupplier ); + public void addQueryLanguage( QueryLanguage language ) { REGISTER.add( language ); listeners.firePropertyChange( "language", null, language ); } @@ -70,4 +80,119 @@ public static void removeQueryLanguage( String name ) { REGISTER.remove( QueryLanguage.from( name ) ); } + + public List anyPrepareQuery( QueryContext context, Statement statement ) { + //Statement statement = transaction.createStatement(); + Transaction transaction = statement.getTransaction(); + + if ( transaction.isAnalyze() ) { + context.getInformationTarget().accept( transaction.getQueryAnalyzer() ); + } + + if ( transaction.isAnalyze() ) { + statement.getOverviewDuration().start( "Parsing" ); + } + List parsedQueries = context.getLanguage().getSplitter().apply( context ); + if ( transaction.isAnalyze() ) { + statement.getOverviewDuration().stop( "Parsing" ); + } + + Processor processor = context.getLanguage().getProcessorSupplier().get(); + List implementationContexts = new ArrayList<>(); + for ( ParsedQueryContext parsed : parsedQueries ) { + try { + + PolyImplementation implementation; + if ( parsed.getQueryNode().isDdl() ) { + implementation = processor.prepareDdl( statement, parsed ); + } else { + + if ( context.getLanguage().getValidatorSupplier() != null ) { + if ( transaction.isAnalyze() ) { + statement.getOverviewDuration().start( "Validation" ); + } + Pair validated = processor.validate( + transaction, + parsed.getQueryNode(), + RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ); + parsed = ParsedQueryContext.fromQuery( parsed.getQuery(), validated.left, context ); + if ( transaction.isAnalyze() ) { + statement.getOverviewDuration().stop( "Validation" ); + } + } + + if ( transaction.isAnalyze() ) { + statement.getOverviewDuration().start( "Translation" ); + } + + AlgRoot root = processor.translate( statement, parsed ); + + if ( transaction.isAnalyze() ) { + statement.getOverviewDuration().stop( "Translation" ); + } + implementation = statement.getQueryProcessor().prepareQuery( root, true ); + } + implementationContexts.add( new ImplementationContext( implementation, parsed, statement ) ); + + } catch ( Exception e ) { + if ( transaction.isAnalyze() ) { + InformationManager analyzer = transaction.getQueryAnalyzer(); + InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); + InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); + InformationStacktrace exceptionElement = new InformationStacktrace( e, exceptionGroup ); + analyzer.addPage( exceptionPage ); + analyzer.addGroup( exceptionGroup ); + analyzer.registerInformation( exceptionElement ); + } + } + } + return implementationContexts; + } + + + public List anyQuery( QueryContext context, Statement statement ) { + + List prepared = anyPrepareQuery( context, statement ); + Transaction transaction = statement.getTransaction(); + + List executedContexts = new ArrayList<>(); + + for ( ImplementationContext implementation : prepared ) { + try { + if ( context.isAnalysed() ) { + implementation.getStatement().getOverviewDuration().start( "Execution" ); + } + executedContexts.add( implementation.execute( implementation.getStatement() ) ); + if ( context.isAnalysed() ) { + implementation.getStatement().getOverviewDuration().stop( "Execution" ); + } + } catch ( Exception e ) { + if ( transaction.isAnalyze() ) { + InformationManager analyzer = transaction.getQueryAnalyzer(); + InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); + InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); + InformationStacktrace exceptionElement = new InformationStacktrace( e, exceptionGroup ); + analyzer.addPage( exceptionPage ); + analyzer.addGroup( exceptionGroup ); + analyzer.registerInformation( exceptionElement ); + } + executedContexts.add( ExecutedContext.ofError( e ) ); + return executedContexts; + } + } + + return executedContexts; + } + + + public static List toQueryNodes( QueryContext queries ) { + Processor cypherProcessor = queries.getLanguage().getProcessorSupplier().get(); + List statements = cypherProcessor.parse( queries.getQuery() ); + + return Pair.zip( statements, List.of( queries.getQuery().split( ";" ) ) ) + .stream() + .map( p -> ParsedQueryContext.fromQuery( p.right, p.left, queries ) ) + .collect( Collectors.toList() ); + } + } diff --git a/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java b/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java index 2d61278dc6..fbb69de62c 100644 --- a/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java +++ b/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java @@ -20,32 +20,53 @@ import java.util.Locale; import java.util.Objects; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.Supplier; -import lombok.Getter; +import javax.annotation.Nullable; +import lombok.Value; +import org.jetbrains.annotations.NotNull; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.nodes.validate.Validator; import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; -@Getter +@Value public class QueryLanguage { - private final NamespaceType namespaceType; - private final String serializedName; - private final ParserFactory factory; - private final Supplier processorSupplier; - private final BiFunction validatorSupplier; - private final List otherNames; + @NotNull + NamespaceType namespaceType; + @NotNull + String serializedName; + @NotNull + List otherNames; + @Nullable + ParserFactory factory; + @NotNull + Supplier processorSupplier; + @Nullable + BiFunction validatorSupplier; + @NotNull + Function> splitter; - public QueryLanguage( NamespaceType namespaceType, String serializedName, List otherNames, ParserFactory factory, Supplier processorSupplier, BiFunction validatorSupplier ) { + public QueryLanguage( + @NotNull NamespaceType namespaceType, + @NotNull String serializedName, + @NotNull List otherNames, + @Nullable ParserFactory factory, + @NotNull Supplier processorSupplier, + @Nullable BiFunction validatorSupplier, + @NotNull Function> splitter ) { this.namespaceType = namespaceType; this.serializedName = serializedName; this.factory = factory; this.processorSupplier = processorSupplier; this.validatorSupplier = validatorSupplier; this.otherNames = otherNames; + this.splitter = splitter; } diff --git a/core/src/main/java/org/polypheny/db/monitoring/events/StatementEvent.java b/core/src/main/java/org/polypheny/db/monitoring/events/StatementEvent.java index d450bc02c9..bad35533c8 100644 --- a/core/src/main/java/org/polypheny/db/monitoring/events/StatementEvent.java +++ b/core/src/main/java/org/polypheny/db/monitoring/events/StatementEvent.java @@ -49,7 +49,7 @@ public abstract class StatementEvent extends BaseEvent { protected String description; protected List fieldNames; protected long executionTime; - protected int rowCount; + protected long rowCount; protected boolean isAnalyze; protected boolean isSubQuery; protected boolean isCommitted; diff --git a/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java b/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java index 64384a894b..e43a111bd3 100644 --- a/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java +++ b/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java @@ -17,8 +17,8 @@ package org.polypheny.db.nodes; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -27,7 +27,7 @@ */ public interface ExecutableStatement { - void execute( Context context, Statement statement, QueryParameters parameters ); + void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ); } diff --git a/core/src/main/java/org/polypheny/db/nodes/Node.java b/core/src/main/java/org/polypheny/db/nodes/Node.java index b479485b2b..0de48d273c 100644 --- a/core/src/main/java/org/polypheny/db/nodes/Node.java +++ b/core/src/main/java/org/polypheny/db/nodes/Node.java @@ -18,7 +18,9 @@ import java.util.List; import java.util.Set; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; +import org.polypheny.db.catalog.Catalog; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.util.Litmus; @@ -81,6 +83,14 @@ static E clone( E e ) { ParserPos getPos(); + default boolean isDdl() { + return Kind.DDL.contains( getKind() ); + } + + default long getNamespaceId() { + return Catalog.defaultNamespaceId; + } + /** * Returns whether this node is structurally equivalent to another node. * Some examples: @@ -92,4 +102,6 @@ static E clone( E e ) { */ boolean equalsDeep( Node node, Litmus litmus ); + @Nullable String getEntity(); + } diff --git a/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java b/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java index 6a0b4a805e..b75f15138c 100644 --- a/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java +++ b/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java @@ -16,8 +16,8 @@ package org.polypheny.db.nodes; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -27,7 +27,7 @@ public interface UnsupportedExecutableStatement extends ExecutableStatement { @Override - default void execute( Context context, Statement statement, QueryParameters parameters ) { + default void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { throw new UnsupportedOperationException( "The operation is not supported by the used language." ); } diff --git a/core/src/main/java/org/polypheny/db/plugins/PolyPluginManager.java b/core/src/main/java/org/polypheny/db/plugins/PolyPluginManager.java index 39635e6e7d..0b5f89c4a7 100644 --- a/core/src/main/java/org/polypheny/db/plugins/PolyPluginManager.java +++ b/core/src/main/java/org/polypheny/db/plugins/PolyPluginManager.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.List; -import java.util.function.Supplier; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -57,7 +56,6 @@ import org.pf4j.PluginLoader; import org.pf4j.PluginState; import org.pf4j.PluginWrapper; -import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.config.Config; import org.polypheny.db.config.Config.ConfigListener; @@ -79,9 +77,6 @@ public class PolyPluginManager extends DefaultPluginManager { @Getter private static PersistentMonitoringRepository PERSISTENT_MONITORING; - @Getter - private static Supplier CATALOG_SUPPLIER; - @Getter public static ObservableMap PLUGINS = new ObservableMap<>(); @@ -312,7 +307,7 @@ private static boolean isCompatible( VersionDependency versionDependencies ) { return true; } - throw new RuntimeException( "Polypheny dependencies for plugins are not yet supported." ); + throw new GenericRuntimeException( "Polypheny dependencies for plugins are not yet supported." ); } @@ -333,7 +328,7 @@ private static org.pf4j.PluginState toState( org.polypheny.db.config.PluginStatu case ACTIVE: return org.pf4j.PluginState.STARTED; default: - throw new RuntimeException( "Could not find the corresponding plugin state." ); + throw new GenericRuntimeException( "Could not find the corresponding plugin state." ); } } @@ -403,19 +398,6 @@ public static void startUp( TransactionManager transactionManager, Authenticator } - /** - * Sets a catalog supplier, which allows to load a {@link Catalog} on runtime. - * - * @param catalogSupplier the supplier, which returns a {@link Catalog} implementation - */ - public static void setCatalogsSupplier( Supplier catalogSupplier ) { - if ( CATALOG_SUPPLIER != null ) { - throw new RuntimeException( "There is already a catalog supplier set." ); - } - CATALOG_SUPPLIER = catalogSupplier; - } - - /** * Allows to set a {@link PersistentMonitoringRepository } used to store monitoring events during runtime. * @@ -530,7 +512,7 @@ private T getManifestValue( Function1 transformer, Manifest manif private VersionDependency getVersionDependencies( Manifest manifest ) { String dep = manifest.getMainAttributes().getValue( PLUGIN_POLYPHENY_DEPENDENCIES ); - if ( dep == null || dep.trim().equals( "" ) ) { + if ( dep == null || dep.trim().isEmpty() ) { return new VersionDependency( DependencyType.NONE, null ); } @@ -553,7 +535,7 @@ private VersionDependency getVersionDependencies( Manifest manifest ) { private List getCategories( Manifest manifest ) { String categories = manifest.getMainAttributes().getValue( PLUGIN_CATEGORIES ); - if ( categories == null || categories.trim().equals( "" ) ) { + if ( categories == null || categories.trim().isEmpty() ) { return List.of(); } diff --git a/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java b/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java index 7d91d83f2a..122f2f1422 100644 --- a/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java +++ b/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java @@ -18,12 +18,13 @@ import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; public abstract class AutomaticDdlProcessor extends Processor { - public abstract void autoGenerateDDL( Statement statement, Node query, QueryParameters parameters ); + public abstract void autoGenerateDDL( Statement statement, ParsedQueryContext context ); public abstract boolean needsDdlGeneration( Node query, QueryParameters parameters ); diff --git a/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java b/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java new file mode 100644 index 0000000000..4a2cd0ccf2 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java @@ -0,0 +1,82 @@ +/* + * 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.processing; + + +import lombok.EqualsAndHashCode; +import lombok.Value; +import lombok.experimental.NonFinal; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.polypheny.db.PolyImplementation; +import org.polypheny.db.ResultIterator; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; +import org.polypheny.db.transaction.Statement; + +@Value +@NonFinal +public class ImplementationContext { + + PolyImplementation implementation; + + ParsedQueryContext query; + + Statement statement; + + + public ExecutedContext execute( Statement statement ) { + long time = System.nanoTime(); + try { + ResultIterator result = implementation.execute( statement, query.getBatch(), query.isAnalysed(), query.isAnalysed(), false ); + time = System.nanoTime() - time; + return new ExecutedContext( implementation, null, query, time, result, statement ); + } catch ( Exception e ) { + time = System.nanoTime() - time; + return new ExecutedContext( implementation, e.getMessage(), query, time, null, statement ); + } + + } + + + @EqualsAndHashCode(callSuper = true) + @Value + public static class ExecutedContext extends ImplementationContext { + + @Nullable + String error; + + long executionTime; + + @NotNull + ResultIterator iterator; + + + private ExecutedContext( PolyImplementation implementation, String error, ParsedQueryContext query, long executionTime, ResultIterator iterator, Statement statement ) { + super( implementation, query, statement ); + this.executionTime = executionTime; + this.iterator = iterator; + this.error = error; + } + + + public static ExecutedContext ofError( Exception e ) { + return new ExecutedContext( null, e.getMessage(), null, 0l, null, null ); + } + + } + +} diff --git a/core/src/main/java/org/polypheny/db/processing/LanguageContext.java b/core/src/main/java/org/polypheny/db/processing/LanguageContext.java index 2f106de8e5..6384f01b7e 100644 --- a/core/src/main/java/org/polypheny/db/processing/LanguageContext.java +++ b/core/src/main/java/org/polypheny/db/processing/LanguageContext.java @@ -17,7 +17,6 @@ package org.polypheny.db.processing; import java.util.List; -import java.util.function.BiFunction; import java.util.function.Function; import lombok.Value; import org.polypheny.db.type.entity.PolyValue; @@ -26,7 +25,7 @@ public class LanguageContext { Function> splitter; - Function toIterator; - BiFunction>> toPolyValue; + Function toIterator; + Function>> toPolyValue; } diff --git a/core/src/main/java/org/polypheny/db/processing/Processor.java b/core/src/main/java/org/polypheny/db/processing/Processor.java index 19e6a6bcbf..b5e1807a40 100644 --- a/core/src/main/java/org/polypheny/db/processing/Processor.java +++ b/core/src/main/java/org/polypheny/db/processing/Processor.java @@ -27,6 +27,7 @@ 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.routing.ExecutionTimeMonitor; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; @@ -41,37 +42,37 @@ public abstract class Processor { public abstract Pair validate( Transaction transaction, Node parsed, boolean addDefaultValues ); - public abstract AlgRoot translate( Statement statement, Node query, QueryParameters parameters ); - - - public PolyImplementation prepareDdl( Statement statement, Node parsed, QueryParameters parameters ) { - if ( parsed instanceof ExecutableStatement ) { - try { - // Acquire global schema lock - lock( statement ); - // Execute statement - return getImplementation( statement, (ExecutableStatement) parsed, parameters ); - } catch ( DeadlockException e ) { - throw new GenericRuntimeException( "Exception while acquiring global schema lock", e ); - } catch ( TransactionException e ) { - throw new GenericRuntimeException( e ); - } finally { - // Release lock - unlock( statement ); - } - } else { - throw new GenericRuntimeException( "All DDL queries should be of a type that inherits ExecutableStatement. But this one is of type " + parsed.getClass() ); + public abstract AlgRoot translate( Statement statement, ParsedQueryContext context ); + + + public PolyImplementation prepareDdl( Statement statement, ParsedQueryContext context ) { + if ( !(context.getQueryNode() instanceof ExecutableStatement) ) { + throw new GenericRuntimeException( "All DDL queries should be of a type that inherits ExecutableStatement. But this one is of type " + context.getQueryNode().getClass() ); } + try { + // Acquire global schema lock + lock( statement ); + // Execute statement + return getImplementation( statement, context ); + } catch ( DeadlockException e ) { + throw new GenericRuntimeException( "Exception while acquiring global schema lock", e ); + } catch ( TransactionException e ) { + throw new GenericRuntimeException( e ); + } finally { + // Release lock + unlock( statement ); + } + } - PolyImplementation getImplementation( Statement statement, ExecutableStatement parsed, QueryParameters parameters ) throws TransactionException { - parsed.execute( statement.getPrepareContext(), statement, parameters ); + PolyImplementation getImplementation( Statement statement, ParsedQueryContext context ) throws TransactionException { + ((ExecutableStatement) context.getQueryNode()).execute( statement.getPrepareContext(), statement, context ); statement.getTransaction().commit(); Catalog.getInstance().commit(); return new PolyImplementation( null, - parameters.getNamespaceType(), + context.getLanguage().getNamespaceType(), new ExecutionTimeMonitor(), null, Kind.CREATE_NAMESPACE, // technically correct, maybe change diff --git a/core/src/main/java/org/polypheny/db/processing/QueryContext.java b/core/src/main/java/org/polypheny/db/processing/QueryContext.java index 2493ce0cb9..7bc5641645 100644 --- a/core/src/main/java/org/polypheny/db/processing/QueryContext.java +++ b/core/src/main/java/org/polypheny/db/processing/QueryContext.java @@ -16,44 +16,83 @@ package org.polypheny.db.processing; +import java.util.function.Consumer; +import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.NonFinal; +import lombok.experimental.SuperBuilder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.information.InformationManager; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.nodes.Node; import org.polypheny.db.transaction.TransactionManager; @Value +@NonFinal +@SuperBuilder(toBuilder = true) public class QueryContext { + + @NotNull String query; + @NotNull QueryLanguage language; - boolean isAnalysed; + @Builder.Default + boolean isAnalysed = false; - boolean usesCache; + @Builder.Default + boolean usesCache = true; - long userId; + @Builder.Default + long userId = Catalog.defaultUserId; + @NotNull String origin; - int batch; // -1 for all + @Builder.Default + int batch = -1; // -1 for all - TransactionManager manager; + @NotNull + TransactionManager transactionManager; - @NonFinal - Transaction transaction; + @Builder.Default + @Nullable + Consumer informationTarget = i -> { + }; + @Builder.Default + long namespaceId = Catalog.defaultNamespaceId; - public Transaction openTransaction() { - return manager.startTransaction( userId, Catalog.defaultNamespaceId, isAnalysed, origin ); - } + @EqualsAndHashCode(callSuper = true) + @Value - public Transaction openTransaction( long namespaceId ) { - return manager.startTransaction( userId, namespaceId, isAnalysed, origin ); - } + @SuperBuilder(toBuilder = true) + public static class ParsedQueryContext extends QueryContext { + + @NotNull Node queryNode; + public static ParsedQueryContext fromQuery( String query, Node queryNode, QueryContext context ) { + return ParsedQueryContext.builder() + .query( query ) + .queryNode( queryNode ) + .language( context.language ) + .isAnalysed( context.isAnalysed ) + .usesCache( context.usesCache ) + .userId( context.userId ) + .origin( context.getOrigin() ) + .batch( context.batch ) + .namespaceId( context.namespaceId ) + .transactionManager( context.transactionManager ) + .informationTarget( context.informationTarget ).build(); + } + + } + } diff --git a/core/src/main/java/org/polypheny/db/processing/ResultContext.java b/core/src/main/java/org/polypheny/db/processing/ResultContext.java deleted file mode 100644 index b02deff147..0000000000 --- a/core/src/main/java/org/polypheny/db/processing/ResultContext.java +++ /dev/null @@ -1,39 +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.processing; - - -import lombok.Value; -import org.polypheny.db.ResultIterator; - -@Value -public class ResultContext { - - ResultIterator iterator; - - String error; - - QueryContext query; - - double executionTime; - - - public static ResultContext ofError( String error, QueryContext context, double executionTime ) { - return new ResultContext( null, error, context, executionTime ); - } - -} diff --git a/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java b/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java index 4d4f431a3f..cf7fc9cc6d 100644 --- a/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java +++ b/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java @@ -106,7 +106,7 @@ public Statistic getStatistic() { if ( id == null ) { return Statistics.UNKNOWN; } - Integer rowCount = StatisticsManager.getInstance().rowCountPerTable( id ); + Long rowCount = StatisticsManager.getInstance().rowCountPerTable( id ); if ( rowCount == null ) { return Statistics.UNKNOWN; diff --git a/core/src/test/java/org/polypheny/db/catalog/MockIdentifier.java b/core/src/test/java/org/polypheny/db/catalog/MockIdentifier.java index afcf7b4018..1cec7f484b 100644 --- a/core/src/test/java/org/polypheny/db/catalog/MockIdentifier.java +++ b/core/src/test/java/org/polypheny/db/catalog/MockIdentifier.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Set; import lombok.Getter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; @@ -95,6 +96,12 @@ public boolean equalsDeep( Node node, Litmus litmus ) { } + @Override + public @Nullable String getEntity() { + return null; + } + + @Override public R accept( NodeVisitor visitor ) { return null; diff --git a/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java b/core/src/test/java/org/polypheny/db/plan/AlgOptUtilTest.java similarity index 99% rename from core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java rename to core/src/test/java/org/polypheny/db/plan/AlgOptUtilTest.java index 636d45114f..6e1cc1deee 100644 --- a/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java +++ b/core/src/test/java/org/polypheny/db/plan/AlgOptUtilTest.java @@ -54,7 +54,7 @@ * Unit test for {@link AlgOptUtil} and other classes in this package. */ @Ignore -public class RelOptUtilTest { +public class AlgOptUtilTest { /** * Creates a config based on the "scott" schema. @@ -91,7 +91,7 @@ public JavaTypeFactory getTypeFactory() { private static final List EMP_DEPT_JOIN_REL_FIELDS = Lists.newArrayList( Iterables.concat( EMP_ROW.getFields(), DEPT_ROW.getFields() ) ); - public RelOptUtilTest() { + public AlgOptUtilTest() { } diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index d6f7a3b1c7..044956285e 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -62,6 +62,7 @@ import org.polypheny.db.information.HostInformation; import org.polypheny.db.information.JavaInformation; import org.polypheny.db.languages.LanguageManager; +import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.monitoring.core.MonitoringServiceProvider; import org.polypheny.db.monitoring.statistics.StatisticQueryProcessor; import org.polypheny.db.monitoring.statistics.StatisticsManagerImpl; @@ -123,7 +124,7 @@ public class PolyphenyDb { public boolean daemonMode = false; @Option(name = { "-defaultStore" }, description = "Type of default storeId") - public String defaultStoreName = "hsqldb"; + public String defaultStoreName = "postgresql"; @Option(name = { "-defaultSource" }, description = "Type of default source") public String defaultSourceName = "csv"; @@ -385,13 +386,15 @@ public void join( final long millis ) throws InterruptedException { FrequencyMap.setAndGetInstance( new FrequencyMapImpl( catalog ) ); // temporary add sql and rel here - LanguageManager.getINSTANCE().addQueryLanguage( + QueryLanguage language = new QueryLanguage( NamespaceType.RELATIONAL, "alg", List.of( "alg", "algebra" ), null, AlgProcessor::new, + null, null ); + 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 index 21f3d065e8..eb874f25d4 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AlgProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AlgProcessor.java @@ -25,6 +25,7 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.QueryParameters; 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; @@ -47,9 +48,9 @@ public Pair validate( Transaction transaction, Node parsed, b @Override - public AlgRoot translate( Statement statement, Node query, QueryParameters parameters ) { + public AlgRoot translate( Statement statement, ParsedQueryContext context ) { try { - return AlgRoot.of( QueryPlanBuilder.buildFromJsonAlg( statement, parameters.getQuery() ), Kind.SELECT ); + return AlgRoot.of( QueryPlanBuilder.buildFromJsonAlg( statement, context.getQuery() ), Kind.SELECT ); } catch ( JsonProcessingException e ) { throw new GenericRuntimeException( e ); } @@ -57,7 +58,7 @@ public AlgRoot translate( Statement statement, Node query, QueryParameters param @Override - public PolyImplementation prepareDdl( Statement statement, Node parsed, QueryParameters parameters ) { + public PolyImplementation prepareDdl( Statement statement, ParsedQueryContext context ) { throw new GenericRuntimeException( AlgProcessor.class.getSimpleName() + " AlgProcessor does not support DDLs!" ); } diff --git a/dbms/src/test/java/org/polypheny/db/adapter/FileAdapterTest.java b/dbms/src/test/java/org/polypheny/db/adapter/FileTest.java similarity index 97% rename from dbms/src/test/java/org/polypheny/db/adapter/FileAdapterTest.java rename to dbms/src/test/java/org/polypheny/db/adapter/FileTest.java index 49e90eecd8..22a425d72f 100644 --- a/dbms/src/test/java/org/polypheny/db/adapter/FileAdapterTest.java +++ b/dbms/src/test/java/org/polypheny/db/adapter/FileTest.java @@ -33,25 +33,21 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) -public class FileAdapterTest { +@Category(AdapterTestSuite.class) +public class FileTest { @BeforeClass public static void start() throws SQLException { // Ensures that Polypheny-DB is running // noinspection ResultOfMethodCallIgnored TestHelper.getInstance(); - - try ( JdbcConnection jdbcConnection = new JdbcConnection( false ) ) { - Connection connection = jdbcConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - statement.executeUpdate( "ALTER ADAPTERS ADD \"mm\" USING 'File' AS 'Store' WITH '{mode:embedded}'" ); - } - } } diff --git a/dbms/src/test/java/org/polypheny/db/adapter/GoogleSheetSourceTest.java b/dbms/src/test/java/org/polypheny/db/adapter/GoogleSheetSourceTest.java deleted file mode 100644 index 2ece83abd4..0000000000 --- a/dbms/src/test/java/org/polypheny/db/adapter/GoogleSheetSourceTest.java +++ /dev/null @@ -1,129 +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.adapter; - -import com.google.common.collect.ImmutableList; -import com.google.gson.Gson; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.polypheny.db.TestHelper; -import org.polypheny.db.TestHelper.JdbcConnection; - - -@Ignore // for debug purpose -public class GoogleSheetSourceTest { - - @BeforeClass - public static void start() throws SQLException { - TestHelper.getInstance(); - - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - Map settings = new HashMap<>(); - settings.put( "maxStringLength", "255" ); - settings.put( "querySize", "1000" ); - settings.put( "sheetsURL", "-----ADD-----" ); - settings.put( "mode", "remote" ); - settings.put( "resetRefreshToken", "No" ); - Gson gson = new Gson(); - statement.executeUpdate( "ALTER ADAPTERS ADD \"googlesheetunit\" USING 'GoogleSheets' AS SOURCE WITH '" + gson.toJson( settings ) + "'" ); - } - } - } - - - @AfterClass - public static void end() throws SQLException { - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - statement.executeUpdate( "ALTER ADAPTERS DROP googlesheetunit" ); - } - } - - } - - - @Test - public void existsSelect() throws SQLException { - try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - List expectedResult = ImmutableList.of( - new Object[]{ "Oracle", "Product Manager", 127000 }, - new Object[]{ "eBay", "Software Engineer", 100000 }, - new Object[]{ "Amazon", "Product Manager", 310000 }, - new Object[]{ "Apple", "Software Engineering Manager", 372000 }, - new Object[]{ "Microsoft", "Software Engineer", 157000 } - - ); - TestHelper.checkResultSet( - statement.executeQuery( "SELECT \"Company\", \"Title\", \"Yearly Compensation\" from salaries LIMIT 5" ), - expectedResult - ); - } - } - } - - - @Test - public void existsSecondSelect() throws SQLException { - try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - List expectedResult = ImmutableList.of( - new Object[]{ "GP", "F", 18, "U", "GT3", "A", 4, 4, "at_home", "teacher", "course", "mother", 2, 2, 0, "yes", "no", "no", "no", "yes", "yes", "no", "no", 4, 3, 4, 3, 6, 5, 6, 6 }, - new Object[]{ "GP", "F", 17, "U", "GT3", "T", 1, 1, "at_home", "other", "course", "father", 1, 2, 0, "no", "yes", "no", "no", "no", "yes", "yes", "no", 5, 3, 3, 3, 4, 5, 5, 6 }, - new Object[]{ "GP", "F", 15, "U", "LE3", "T", 1, 1, "at_home", "other", "other", "mother", 1, 2, 3, "yes", "no", "yes", "no", "yes", "yes", "yes", "no", 4, 3, 2, 3, 10, 7, 8, 10 } - ); - TestHelper.checkResultSet( - statement.executeQuery( "SELECT * from student_data LIMIT 3" ), - expectedResult - ); - } - } - } - - - @Test - public void existsThirdSelect() throws SQLException { - try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - List expectedResult = ImmutableList.of( - new Object[]{ "Alexandra", "Female" }, - new Object[]{ "Andrew", "Male" }, - new Object[]{ "Anna", "Female" } - ); - TestHelper.checkResultSet( - statement.executeQuery( "SELECT \"Student Name\", \"Gender\" from student_formatting" ), - expectedResult - ); - } - } - } - -} diff --git a/dbms/src/test/java/org/polypheny/db/adapter/MonetdbSourceTest.java b/dbms/src/test/java/org/polypheny/db/adapter/MonetdbSourceTest.java deleted file mode 100644 index 263523f4a5..0000000000 --- a/dbms/src/test/java/org/polypheny/db/adapter/MonetdbSourceTest.java +++ /dev/null @@ -1,82 +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.adapter; - -import com.google.gson.Gson; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; -import nl.cwi.monetdb.embedded.env.MonetDBEmbeddedDatabase; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.polypheny.db.TestHelper; -import org.polypheny.db.TestHelper.JdbcConnection; - - -@SuppressWarnings("SqlDialectInspection") -@Ignore -public class MonetdbSourceTest extends AbstractSourceTest { - - @BeforeClass - public static void start() throws SQLException { - // Ensures that Polypheny-DB is running - //noinspection ResultOfMethodCallIgnored - TestHelper.getInstance(); - - // Start embedded Monetdb and add default schema and data - MonetDBEmbeddedDatabase.startDatabase( null ); //in-memory mode - MonetDBEmbeddedDatabase.createConnection(); - try ( Connection conn = DriverManager.getConnection( "jdbc:monetdb:embedded::memory:" ) ) { - executeScript( conn, "org/polypheny/db/adapter/monetdb-schema.sql" ); - } - - // Add adapter to Polypheny-DB - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - Map settings = new HashMap<>(); - settings.put( "database", "" ); - settings.put( "mode", "remote" ); - settings.put( "host", "running-embedded" ); - settings.put( "maxConnections", "25" ); - settings.put( "password", "" ); - settings.put( "username", "" ); - settings.put( "port", "" ); - settings.put( "tables", "public.auction,public.bid,public.category,public.picture,public.user" ); - Gson gson = new Gson(); - statement.executeUpdate( "ALTER ADAPTERS ADD monetdbunit USING 'Monetdb' AS 'Source' WITH '" + gson.toJson( settings ) + "'" ); - } - } - } - - - @AfterClass - public static void end() throws SQLException { - MonetDBEmbeddedDatabase.stopDatabase(); - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - statement.executeUpdate( "ALTER ADAPTERS DROP monetdbunit" ); - } - } - } - -} diff --git a/dbms/src/test/java/org/polypheny/db/adapter/MysqlSourceTest.java b/dbms/src/test/java/org/polypheny/db/adapter/MysqlSourceTest.java deleted file mode 100644 index b348501ba5..0000000000 --- a/dbms/src/test/java/org/polypheny/db/adapter/MysqlSourceTest.java +++ /dev/null @@ -1,83 +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.adapter; - -import com.google.gson.Gson; -import com.wix.mysql.EmbeddedMysql; -import com.wix.mysql.ScriptResolver; -import com.wix.mysql.distribution.Version; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.polypheny.db.TestHelper; -import org.polypheny.db.TestHelper.JdbcConnection; - -@SuppressWarnings("SqlDialectInspection") -@Ignore -public class MysqlSourceTest extends AbstractSourceTest { - - private static EmbeddedMysql server; - - - @BeforeClass - public static void start() throws SQLException { - // Ensures that Polypheny-DB is running - //noinspection ResultOfMethodCallIgnored - TestHelper.getInstance(); - - // Start MariaDB and add default schema and data - server = EmbeddedMysql.anEmbeddedMysql( Version.v5_7_latest ) - .addSchema( "test", ScriptResolver.classPathScript( "org/polypheny/db/adapter/mariadb-schema.sql" ) ) - .start(); - - // Add adapter - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - Map settings = new HashMap<>(); - settings.put( "database", "test" ); - settings.put( "host", "localhost" ); - settings.put( "maxConnections", "25" ); - settings.put( "password", "" ); - settings.put( "username", "root" ); - settings.put( "port", "" + server.getConfig().getPort() ); - settings.put( "transactionIsolation", "SERIALIZABLE" ); - settings.put( "tables", "auction,bid,category,picture,user" ); - Gson gson = new Gson(); - statement.executeUpdate( "ALTER ADAPTERS ADD mariadbunit USING 'Mysql' AS 'Source' WITH '" + gson.toJson( settings ) + "'" ); - } - } - } - - - @AfterClass - public static void end() throws SQLException { - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - statement.executeUpdate( "ALTER ADAPTERS DROP mariadbunit" ); - } - } - server.stop(); - } - -} diff --git a/dbms/src/test/java/org/polypheny/db/adapter/PostgresSourceTest.java b/dbms/src/test/java/org/polypheny/db/adapter/PostgresSourceTest.java deleted file mode 100644 index ddb0d64672..0000000000 --- a/dbms/src/test/java/org/polypheny/db/adapter/PostgresSourceTest.java +++ /dev/null @@ -1,84 +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.adapter; - -import com.google.gson.Gson; -import io.zonky.test.db.postgres.junit.EmbeddedPostgresRules; -import io.zonky.test.db.postgres.junit.SingleInstancePostgresRule; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.polypheny.db.TestHelper; -import org.polypheny.db.TestHelper.JdbcConnection; - -@SuppressWarnings("SqlDialectInspection") -@Ignore -public class PostgresSourceTest extends AbstractSourceTest { - - @ClassRule - public static SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance(); - - - @BeforeClass - public static void start() throws SQLException { - // Ensures that Polypheny-DB is running - //noinspection ResultOfMethodCallIgnored - TestHelper.getInstance(); - - // Add default schema and data to postgres database - try ( Connection conn = pg.getEmbeddedPostgres().getPostgresDatabase().getConnection() ) { - executeScript( conn, "org/polypheny/db/adapter/postgres-schema.sql" ); - } - - // Add adapter to Polypheny-DB - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - Map settings = new HashMap<>(); - settings.put( "database", "postgres" ); - settings.put( "mode", "remote" ); - settings.put( "host", "localhost" ); - settings.put( "maxConnections", "25" ); - settings.put( "password", "" ); - settings.put( "username", "postgres" ); - settings.put( "port", "" + pg.getEmbeddedPostgres().getPort() ); - settings.put( "transactionIsolation", "SERIALIZABLE" ); - settings.put( "tables", "public.auction,public.bid,public.category,public.picture,public.user" ); - Gson gson = new Gson(); - statement.executeUpdate( "ALTER ADAPTERS ADD postgresunit USING 'Postgresql' AS 'Source' WITH '" + gson.toJson( settings ) + "'" ); - } - } - } - - - @AfterClass - public static void end() throws SQLException { - try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { - Connection connection = polyphenyDbConnection.getConnection(); - try ( Statement statement = connection.createStatement() ) { - statement.executeUpdate( "ALTER ADAPTERS DROP postgresunit" ); - } - } - } - -} diff --git a/dbms/src/test/java/org/polypheny/db/statistics/StatisticsTest.java b/dbms/src/test/java/org/polypheny/db/statistics/StatisticsTest.java index 5982ff7a63..9263f71921 100644 --- a/dbms/src/test/java/org/polypheny/db/statistics/StatisticsTest.java +++ b/dbms/src/test/java/org/polypheny/db/statistics/StatisticsTest.java @@ -253,8 +253,8 @@ public void testSimpleRowCount() throws SQLException { LogicalTable catalogTableNation = snapshot.rel().getTable( "statisticschema", "nation" ).orElseThrow(); LogicalTable catalogTableRegion = snapshot.rel().getTable( "statisticschema", "region" ).orElseThrow(); - Integer rowCountNation = StatisticsManager.getInstance().rowCountPerTable( catalogTableNation.id ); - Integer rowCountRegion = StatisticsManager.getInstance().rowCountPerTable( catalogTableRegion.id ); + Long rowCountNation = StatisticsManager.getInstance().rowCountPerTable( catalogTableNation.id ); + Long rowCountRegion = StatisticsManager.getInstance().rowCountPerTable( catalogTableRegion.id ); Assert.assertEquals( Integer.valueOf( 3 ), rowCountNation ); Assert.assertEquals( Integer.valueOf( 2 ), rowCountRegion ); @@ -306,7 +306,7 @@ private void assertStatisticsConvertTo( int maxSeconds, int target ) { continue; } LogicalTable catalogTableNation = Catalog.snapshot().rel().getTable( "statisticschema", "nationdelete" ).orElseThrow(); - Integer rowCount = StatisticsManager.getInstance().rowCountPerTable( catalogTableNation.id ); + Long rowCount = StatisticsManager.getInstance().rowCountPerTable( catalogTableNation.id ); // potentially table exists not yet in statistics but in catalog if ( rowCount != null && rowCount == target ) { successfull = true; diff --git a/gradle.properties b/gradle.properties index a3afe3baa9..e71361882f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -109,7 +109,7 @@ poi_ooxml_version = 5.2.3 polypheny_jdbc_driver_version = 1.5.3 polypheny_ui_version = 1.0-SNAPSHOT postgresql_version = 42.2.19 -pf4j_version = 3.9.0 +pf4j_version = 3.10.0 quidem_version = 0.9 protobuf_version = 3.23.4 protobuf_plugin_version = 0.9.4 diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/DmlDataPoint.java b/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/DmlDataPoint.java index a70a45dc96..162de8bd64 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/DmlDataPoint.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/DmlDataPoint.java @@ -54,7 +54,7 @@ public class DmlDataPoint implements MonitoringDataPoint, Serializable { private long executionTime; private boolean isSubQuery; protected boolean isCommitted; - private int rowCount; + private long rowCount; private List fieldNames; private List accessedPartitions; private String queryClass; diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/QueryDataPointImpl.java b/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/QueryDataPointImpl.java index 94c4cce7ee..5a90813182 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/QueryDataPointImpl.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/events/metrics/QueryDataPointImpl.java @@ -47,7 +47,7 @@ public class QueryDataPointImpl implements QueryDataPoint, Serializable { long executionTime; boolean isSubQuery; boolean isCommitted; - int rowCount; + long rowCount; List fieldNames; List accessedPartitions; String algCompareString; diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticRepository.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticRepository.java index e42b0ce24b..dfdcc9ecbf 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticRepository.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticRepository.java @@ -101,7 +101,7 @@ private void updateQueryStatistics( QueryDataPointImpl dataPoint, StatisticsMana } } else { for ( long id : values ) { - if ( catalog.getSnapshot().getLogicalEntity( id ) != null ) { + if ( catalog.getSnapshot().getLogicalEntity( id ).isPresent() ) { statisticsManager.setTableCalls( id, dataPoint.getMonitoringType() ); } } @@ -127,7 +127,7 @@ private void updateDmlStatistics( DmlDataPoint dataPoint, StatisticsManager stat return; } if ( dataPoint.getMonitoringType() == MonitoringType.INSERT ) { - int added = dataPoint.getRowCount(); + long added = dataPoint.getRowCount(); statisticsManager.tablesToUpdate( tableId, dataPoint.getChangedValues(), @@ -135,7 +135,7 @@ private void updateDmlStatistics( DmlDataPoint dataPoint, StatisticsManager stat catalog.getSnapshot().getLogicalEntity( tableId ).orElseThrow().namespaceId ); statisticsManager.updateRowCountPerTable( tableId, added, dataPoint.getMonitoringType() ); } else if ( dataPoint.getMonitoringType() == MonitoringType.DELETE ) { - int deleted = dataPoint.getRowCount(); + long deleted = dataPoint.getRowCount(); statisticsManager.updateRowCountPerTable( tableId, deleted, dataPoint.getMonitoringType() ); // After a delete, it is not clear what exactly was deleted, so the statistics of the table are updated statisticsManager.tablesToUpdate( tableId ); diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java index c1ea48c155..65039f6129 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java @@ -52,7 +52,7 @@ public class StatisticTable { private EntityType entityType; @Getter - private int numberOfRows; + private long numberOfRows; @Getter @Setter @@ -87,7 +87,7 @@ public StatisticTable( Long tableId ) { } - public void setNumberOfRows( int rows ) { + public void setNumberOfRows( long rows ) { this.numberOfRows = Math.max( rows, 0 ); } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java index 4162b71ead..9cba794966 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java @@ -932,13 +932,13 @@ public void deleteTableToUpdate( long tableId ) { * @param type of the rowCount information */ @Override - public void updateRowCountPerTable( long tableId, int number, MonitoringType type ) { + public void updateRowCountPerTable( long tableId, long number, MonitoringType type ) { StatisticTable table; switch ( type ) { case INSERT: if ( tableStatistic.containsKey( tableId ) ) { table = tableStatistic.get( tableId ); - int totalRows = table.getNumberOfRows() + number; + long totalRows = table.getNumberOfRows() + number; table.setNumberOfRows( totalRows ); } else { @@ -949,7 +949,7 @@ public void updateRowCountPerTable( long tableId, int number, MonitoringType typ case DELETE: if ( tableStatistic.containsKey( tableId ) ) { table = tableStatistic.get( tableId ); - int totalRows = table.getNumberOfRows() - number; + long totalRows = table.getNumberOfRows() - number; table.setNumberOfRows( totalRows ); } else { @@ -982,7 +982,7 @@ public void updateRowCountPerTable( long tableId, int number, MonitoringType typ @Override public void setIndexSize( long tableId, int indexSize ) { if ( tableStatistic.containsKey( tableId ) ) { - int numberOfRows = tableStatistic.remove( tableId ).getNumberOfRows(); + long numberOfRows = tableStatistic.remove( tableId ).getNumberOfRows(); if ( numberOfRows != indexSize ) { // Use indexSize because it should be correct StatisticTable statisticTable = tableStatistic.get( tableId ); @@ -1139,7 +1139,7 @@ public Object getTableStatistic( long schemaId, long tableId ) { * @return the number of rows of a given table */ @Override - public synchronized Integer rowCountPerTable( long tableId ) { + public synchronized Long rowCountPerTable( long tableId ) { if ( tableStatistic.containsKey( tableId ) ) { return tableStatistic.get( tableId ).getNumberOfRows(); } else { diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index ab546ffd7a..4a0e48d255 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -73,8 +73,6 @@ import org.polypheny.db.PolyImplementation; import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.java.JavaTypeFactory; -import org.polypheny.db.algebra.AlgRoot; -import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.AlgDataTypeSystem; @@ -102,17 +100,17 @@ import org.polypheny.db.catalog.logistic.EntityType.PrimitiveTableType; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.Pattern; -import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.iface.AuthenticationException; import org.polypheny.db.iface.Authenticator; import org.polypheny.db.information.InformationGroup; import org.polypheny.db.information.InformationManager; import org.polypheny.db.information.InformationPage; import org.polypheny.db.information.InformationTable; +import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext; import org.polypheny.db.routing.ExecutionTimeMonitor; import org.polypheny.db.transaction.Transaction; import org.polypheny.db.transaction.TransactionException; @@ -1072,7 +1070,7 @@ public ExecuteResult prepareAndExecute( final StatementHandle h, final String sq PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); statementHandle.setPreparedQuery( sql ); statementHandle.setStatement( connection.getCurrentOrCreateNewTransaction().createStatement() ); - return execute( h, new LinkedList<>(), maxRowsInFirstFrame, connection ); + return execute( h, new ArrayList<>(), maxRowsInFirstFrame, connection ); } } @@ -1353,24 +1351,15 @@ private PolyValue toPolyValue( TypedValue value ) { private void prepare( StatementHandle h, String sql ) throws NoSuchStatementException { PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); - Processor sqlProcessor = statementHandle.getStatement().getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); - - Node parsed = sqlProcessor.parse( sql ).get( 0 ); - - PolyphenyDbSignature signature; - if ( parsed.isA( Kind.DDL ) ) { - signature = PolyphenyDbSignature.from( sqlProcessor.prepareDdl( statementHandle.getStatement(), parsed, new QueryParameters( sql, NamespaceType.RELATIONAL ) ) ); - } else { - Pair validated = sqlProcessor.validate( - statementHandle.getStatement().getTransaction(), - parsed, - RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ); - AlgRoot logicalRoot = sqlProcessor.translate( statementHandle.getStatement(), validated.left, null ); - AlgDataType parameterRowType = sqlProcessor.getParameterRowType( validated.left ); - - // Prepare - signature = PolyphenyDbSignature.from( statementHandle.getStatement().getQueryProcessor().prepareQuery( logicalRoot, parameterRowType, true ) ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + QueryContext context = QueryContext.builder() + .query( sql ) + .language( language ) + .origin( "DBMS Meta" ) + .transactionManager( transactionManager ) + .build(); + + PolyphenyDbSignature signature = PolyphenyDbSignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement() ).get( 0 ).getImplementation() ); h.signature = signature; statementHandle.setSignature( signature ); 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/Cql2AlgConverter.java similarity index 98% rename from plugins/cql-language/src/main/java/org/polypheny/db/cql/Cql2RelConverter.java rename to plugins/cql-language/src/main/java/org/polypheny/db/cql/Cql2AlgConverter.java index d76630a917..67b9b1fa36 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/Cql2AlgConverter.java @@ -53,14 +53,14 @@ * to relational algebra ({@link AlgNode}, {@link AlgRoot}, {@link RexNode}) */ @Slf4j -public class Cql2RelConverter { +public class Cql2AlgConverter { private final CqlQuery cqlQuery; private final Map tableScanColumnOrdinalities; private final Map projectionColumnOrdinalities; - public Cql2RelConverter( final CqlQuery cqlQuery ) { + public Cql2AlgConverter( final CqlQuery cqlQuery ) { this.cqlQuery = cqlQuery; this.tableScanColumnOrdinalities = new HashMap<>(); this.projectionColumnOrdinalities = new HashMap<>(); @@ -75,7 +75,7 @@ public Cql2RelConverter( final CqlQuery cqlQuery ) { * @param rexBuilder {@link RexBuilder}. * @return {@link AlgRoot}. */ - public AlgRoot convert2Rel( AlgBuilder algBuilder, RexBuilder rexBuilder ) { + public AlgRoot convert2Alg( AlgBuilder algBuilder, RexBuilder rexBuilder ) { algBuilder = generateScan( algBuilder, rexBuilder ); if ( cqlQuery.filters != null ) { algBuilder = generateProjections( algBuilder, rexBuilder ); diff --git a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java index 79e6bfd996..a2c341cec5 100644 --- a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java +++ b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java @@ -16,35 +16,15 @@ package org.polypheny.db.cql; -import java.util.Collections; import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.websocket.api.Session; -import org.polypheny.db.PolyImplementation; -import org.polypheny.db.adapter.java.JavaTypeFactory; -import org.polypheny.db.algebra.AlgRoot; -import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; -import org.polypheny.db.cql.parser.CqlParser; -import org.polypheny.db.information.InformationManager; -import org.polypheny.db.information.InformationObserver; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; -import org.polypheny.db.rex.RexBuilder; -import org.polypheny.db.tools.AlgBuilder; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionException; -import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.crud.LanguageCrud; -import org.polypheny.db.webui.models.requests.QueryRequest; -import org.polypheny.db.webui.models.results.RelationalResult; -import org.polypheny.db.webui.models.results.Result; @Slf4j public class CqlLanguagePlugin extends PolyPlugin { @@ -64,106 +44,17 @@ public CqlLanguagePlugin( PluginContext context ) { @Override public void start() { - PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.crud.languageCrud.addLanguage( NAME, CqlLanguagePlugin::processCqlRequest ) ); - LanguageManager.getINSTANCE().addQueryLanguage( NamespaceType.RELATIONAL, NAME, List.of( NAME ), null, null, null ); + QueryLanguage language = new QueryLanguage( NamespaceType.RELATIONAL, NAME, List.of( NAME ), null, CqlProcessor::new, null, CqlQueryBuilder::splitter ); + LanguageManager.getINSTANCE().addQueryLanguage( language ); + PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getRelResult ) ); } @Override public void stop() { - LanguageCrud.crud.languageCrud.removeLanguage( NAME ); + QueryLanguage language = QueryLanguage.from( NAME ); + LanguageCrud.deleteToResult( language ); LanguageManager.removeQueryLanguage( NAME ); } - - public static List> processCqlRequest( - Session session, - QueryRequest request, - TransactionManager transactionManager, - long userId, - long databaseId, - InformationObserver observer ) { - String query = request.query; - Transaction transaction = Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, databaseId, "HTTP Interface CQL" ); - try { - if ( query.trim().isEmpty() ) { - throw new GenericRuntimeException( "CQL query is an empty string!" ); - } - - if ( log.isDebugEnabled() ) { - log.debug( "Starting to process CQL resource request. Session ID: {}.", session ); - } - - if ( request.analyze ) { - transaction.getQueryAnalyzer().setSession( session ); - } - - // This is not a nice solution. In case of a sql script with auto commit only the first statement is analyzed - // and in case of auto commit of, the information is overwritten - InformationManager queryAnalyzer = null; - if ( request.analyze ) { - queryAnalyzer = transaction.getQueryAnalyzer().observe( observer ); - } - - Statement statement = transaction.createStatement(); - AlgBuilder algBuilder = AlgBuilder.create( statement ); - JavaTypeFactory typeFactory = transaction.getTypeFactory(); - RexBuilder rexBuilder = new RexBuilder( typeFactory ); - - long executionTime = System.nanoTime(); - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Parsing" ); - } - CqlParser cqlParser = new CqlParser( query, Catalog.DATABASE_NAME ); - CqlQuery cqlQuery = cqlParser.parse(); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Parsing" ); - } - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Translation" ); - } - Cql2RelConverter cql2AlgConverter = new Cql2RelConverter( cqlQuery ); - AlgRoot algRoot = cql2AlgConverter.convert2Rel( algBuilder, rexBuilder ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Translation" ); - } - - PolyImplementation polyImplementation = statement.getQueryProcessor().prepareQuery( algRoot, true ); - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Execution" ); - } - Result result = LanguageCrud.getResult( QueryLanguage.from( NAME ), statement, request, query, polyImplementation, transaction, request.noLimit ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Execution" ); - } - - String commitStatus; - try { - transaction.commit(); - commitStatus = "Committed"; - } catch ( TransactionException e ) { - log.error( "Error while committing", e ); - try { - transaction.rollback(); - commitStatus = "Rolled back"; - } catch ( TransactionException ex ) { - log.error( "Caught exception while rollback", e ); - commitStatus = "Error while rolling back"; - } - } - - executionTime = System.nanoTime() - executionTime; - if ( queryAnalyzer != null ) { - Crud.attachQueryAnalyzer( queryAnalyzer, executionTime, commitStatus, 1 ); - } - - return Collections.singletonList( result ); - } catch ( Throwable t ) { - return Collections.singletonList( RelationalResult.builder().error( t.getMessage() ).query( query ).xid( transaction.getXid().toString() ).build() ); - } - } - } diff --git a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlProcessor.java b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlProcessor.java new file mode 100644 index 0000000000..9650f77437 --- /dev/null +++ b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlProcessor.java @@ -0,0 +1,95 @@ +/* + * 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.cql; + +import java.util.Collections; +import java.util.List; +import org.polypheny.db.adapter.java.JavaTypeFactory; +import org.polypheny.db.algebra.AlgRoot; +import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.cql.parser.CqlParser; +import org.polypheny.db.cql.parser.ParseException; +import org.polypheny.db.languages.QueryParameters; +import org.polypheny.db.nodes.Node; +import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; +import org.polypheny.db.rex.RexBuilder; +import org.polypheny.db.tools.AlgBuilder; +import org.polypheny.db.transaction.Lock.LockMode; +import org.polypheny.db.transaction.LockManager; +import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.transaction.TransactionImpl; +import org.polypheny.db.util.DeadlockException; +import org.polypheny.db.util.Pair; + +public class CqlProcessor extends Processor { + + @Override + public List parse( String query ) { + CqlParser cqlParser = new CqlParser( query, Catalog.DATABASE_NAME ); + try { + return List.of( cqlParser.parse() ); + } catch ( ParseException e ) { + throw new GenericRuntimeException( e ); + } + } + + + @Override + public Pair validate( Transaction transaction, Node parsed, boolean addDefaultValues ) { + return null; + } + + + @Override + public AlgRoot translate( Statement statement, ParsedQueryContext context ) { + AlgBuilder algBuilder = AlgBuilder.create( statement ); + JavaTypeFactory typeFactory = statement.getTransaction().getTypeFactory(); + RexBuilder rexBuilder = new RexBuilder( typeFactory ); + + Cql2AlgConverter cql2AlgConverter = new Cql2AlgConverter( (CqlQuery) context.getQueryNode() ); + return cql2AlgConverter.convert2Alg( algBuilder, rexBuilder ); + } + + + @Override + public void unlock( Statement statement ) { + LockManager.INSTANCE.unlock( Collections.singletonList( LockManager.GLOBAL_LOCK ), (TransactionImpl) statement.getTransaction() ); + } + + + @Override + protected void lock( Statement statement ) throws DeadlockException { + LockManager.INSTANCE.lock( Collections.singletonList( Pair.of( LockManager.GLOBAL_LOCK, LockMode.EXCLUSIVE ) ), (TransactionImpl) statement.getTransaction() ); + } + + + @Override + public String getQuery( Node parsed, QueryParameters parameters ) { + return parsed.toString(); + } + + + @Override + public AlgDataType getParameterRowType( Node left ) { + return null; + } + +} diff --git a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQuery.java b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQuery.java index d8edd05028..f03a972d16 100644 --- a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQuery.java +++ b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQuery.java @@ -18,15 +18,23 @@ import java.util.List; import java.util.Map; +import java.util.Set; +import org.jetbrains.annotations.Nullable; +import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.cql.BooleanGroup.ColumnOpsBooleanOperator; import org.polypheny.db.cql.utils.Tree; +import org.polypheny.db.languages.ParserPos; +import org.polypheny.db.languages.QueryLanguage; +import org.polypheny.db.nodes.Node; +import org.polypheny.db.nodes.NodeVisitor; +import org.polypheny.db.util.Litmus; import org.polypheny.db.util.Pair; /** * Packaging all the information in a CQL query together. */ -public class CqlQuery { +public class CqlQuery implements Node { public final Tree queryRelation; public final Tree, Filter> filters; @@ -52,6 +60,30 @@ public CqlQuery( } + @Override + public Node clone( ParserPos pos ) { + return null; + } + + + @Override + public Kind getKind() { + return Kind.SELECT; + } + + + @Override + public QueryLanguage getLanguage() { + return QueryLanguage.from( "pig" ); + } + + + @Override + public boolean isA( Set category ) { + return false; + } + + @Override public String toString() { StringBuilder stringBuilder = new StringBuilder(); @@ -71,4 +103,28 @@ public String toString() { return stringBuilder.toString(); } + + @Override + public ParserPos getPos() { + return null; + } + + + @Override + public boolean equalsDeep( Node node, Litmus litmus ) { + return false; + } + + + @Override + public @Nullable String getEntity() { + return null; + } + + + @Override + public R accept( NodeVisitor visitor ) { + return null; + } + } diff --git a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQueryBuilder.java b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQueryBuilder.java index 491259b569..b3ace54616 100644 --- a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQueryBuilder.java +++ b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlQueryBuilder.java @@ -29,6 +29,8 @@ import org.polypheny.db.cql.exception.InvalidModifierException; import org.polypheny.db.cql.exception.UnknownIndexException; import org.polypheny.db.cql.utils.Tree; +import org.polypheny.db.processing.QueryContext; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.util.Pair; @@ -39,10 +41,8 @@ @Slf4j public class CqlQueryBuilder { - private final String databaseName; private final Stack, Filter>> filters; private final Map tableIndexMapping; - private final Map tableAliases; private final Map columnIndexMapping; private final List>> sortSpecifications; private final Projections projections; @@ -51,10 +51,9 @@ public class CqlQueryBuilder { public CqlQueryBuilder( String databaseName ) { - this.databaseName = databaseName; this.filters = new Stack<>(); this.tableIndexMapping = new TreeMap<>( String.CASE_INSENSITIVE_ORDER ); - this.tableAliases = new TreeMap<>( String.CASE_INSENSITIVE_ORDER ); + Map tableAliases = new TreeMap<>( String.CASE_INSENSITIVE_ORDER ); this.columnIndexMapping = new TreeMap<>( String.CASE_INSENSITIVE_ORDER ); this.sortSpecifications = new ArrayList<>(); this.projections = new Projections(); @@ -72,7 +71,7 @@ public CqlQueryBuilder( String databaseName ) { */ public CqlQuery build() throws Exception { log.debug( "Building CqlQuery." ); - if ( queryRelation == null && filters.size() == 0 ) { + if ( queryRelation == null && filters.isEmpty() ) { log.error( "Query relations and filters cannot both be empty." ); throw new Exception( "Query relations and filters cannot both be empty." ); } @@ -297,4 +296,9 @@ public void addProjection( ColumnIndex columnIndex, Map modifi projections.add( columnIndex, modifiers ); } + + public static List splitter( QueryContext queryContext ) { + return null; + } + } 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 f0e0bb5f6e..9caa977e22 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 @@ -16,30 +16,15 @@ package org.polypheny.db.cypher; -import java.util.ArrayList; import java.util.List; -import org.eclipse.jetty.websocket.api.Session; -import org.polypheny.db.PolyImplementation; -import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.cypher.parser.CypherParserImpl; -import org.polypheny.db.information.InformationManager; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.nodes.Node; import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; -import org.polypheny.db.processing.ExtendedQueryParameters; -import org.polypheny.db.processing.Processor; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.crud.LanguageCrud; -import org.polypheny.db.webui.models.requests.QueryRequest; -import org.polypheny.db.webui.models.results.GraphResult; -import org.polypheny.db.webui.models.results.Result; public class CypherLanguagePlugin extends PolyPlugin { @@ -58,8 +43,16 @@ public CypherLanguagePlugin( PluginContext context ) { @Override public void start() { - PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.crud.languageCrud.addLanguage( NAME, CypherLanguagePlugin::anyCypherQuery ) ); - LanguageManager.getINSTANCE().addQueryLanguage( NamespaceType.GRAPH, NAME, List.of( NAME, "opencypher" ), CypherParserImpl.FACTORY, CypherProcessor::new, null ); + QueryLanguage language = new QueryLanguage( + NamespaceType.GRAPH, + NAME, + List.of( NAME, "opencypher" ), + CypherParserImpl.FACTORY, + CypherProcessor::new, + null, + LanguageManager::toQueryNodes ); + LanguageManager.getINSTANCE().addQueryLanguage( language ); + PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getGraphResult ) ); if ( !CypherRegisterer.isInit() ) { CypherRegisterer.registerOperators(); @@ -69,7 +62,8 @@ public void start() { @Override public void stop() { - LanguageCrud.crud.languageCrud.removeLanguage( NAME ); + QueryLanguage language = QueryLanguage.from( NAME ); + LanguageCrud.deleteToResult( language ); LanguageManager.removeQueryLanguage( NAME ); if ( CypherRegisterer.isInit() ) { @@ -78,91 +72,4 @@ public void stop() { } - public static List> anyCypherQuery( - Session session, - QueryRequest request, - TransactionManager transactionManager, - long userId, - long namespaceId, - Crud crud ) { - - String query = request.query; - - Transaction transaction = Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, namespaceId, "HTTP Interface Cypher" ); - Processor cypherProcessor = transaction.getProcessor( QueryLanguage.from( NAME ) ); - - List> results = new ArrayList<>(); - - InformationManager queryAnalyzer = null; - long executionTime = 0; - try { - if ( request.analyze ) { - transaction.getQueryAnalyzer().setSession( session ); - } - - queryAnalyzer = LanguageCrud.attachAnalyzerIfSpecified( request, crud, transaction ); - - executionTime = System.nanoTime(); - - Statement statement = transaction.createStatement(); - ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, request.namespace ); - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Parsing" ); - } - List statements = cypherProcessor.parse( query ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Parsing" ); - } - - int i = 0; - List splits = List.of( query.split( ";" ) ); - assert statements.size() <= splits.size(); - for ( Node node : statements ) { - CypherStatement stmt = (CypherStatement) node; - - if ( stmt.isDDL() ) { - cypherProcessor.prepareDdl( statement, node, parameters ); - GraphResult result = GraphResult - .builder() - .affectedTuples( 1 ) - .query( splits.get( i ) ) - .namespace( request.namespace ) - .xid( transaction.getXid().toString() ) - .build(); - results.add( result ); - } else { - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Translation" ); - } - AlgRoot logicalRoot = cypherProcessor.translate( statement, stmt, parameters ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Translation" ); - } - - // Prepare - PolyImplementation polyImplementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Execution" ); - } - results.add( LanguageCrud.getResult( QueryLanguage.from( NAME ), statement, request, query, polyImplementation, transaction, query.toLowerCase().contains( " limit " ) ) ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Execution" ); - } - } - i++; - } - - - } catch ( Throwable t ) { - LanguageCrud.printLog( t, request ); - LanguageCrud.attachError( transaction, results, query, NamespaceType.DOCUMENT, t ); - } - - LanguageCrud.commitAndFinish( transaction, queryAnalyzer, results, executionTime ); - - return results; - } - } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java index 58c7f0b6aa..e492541da8 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java @@ -32,9 +32,9 @@ import org.polypheny.db.nodes.NodeVisitor; import org.polypheny.db.util.Litmus; +@Getter public abstract class CypherNode implements Node { - @Getter public final ParserPos pos; public static final List DDL = ImmutableList.of( CypherKind.CREATE_DATABASE, CypherKind.DROP, CypherKind.ADMIN_COMMAND ); @@ -107,6 +107,12 @@ public static String getNameOrNull( CypherSimpleEither } + @Override + public @Nullable String getEntity() { + return null; + } + + public enum CypherKind { SCOPE, REMOVE, @@ -128,7 +134,33 @@ public enum CypherKind { MATCH, MERGE, ORDER_ITEM, - RETURN, SET, SHOW, TRANSACTION, UNWIND, USE, WAIT, WHERE, WITH, MAP_PROJECTION, YIELD, EITHER, RESOURCE, PRIVILEGE, PATH_LENGTH, CALL_RESULT, HINT, PATH, PERIODIC_COMMIT, UNION, SINGLE, NAMED_PATTERN, NODE_PATTERN, REL_PATTERN, SHORTEST_PATTERN, LITERAL, SET_ITEM + RETURN, + SET, + SHOW, + TRANSACTION, + UNWIND, + USE, + WAIT, + WHERE, + WITH, + MAP_PROJECTION, + YIELD, + EITHER, + RESOURCE, + PRIVILEGE, + PATH_LENGTH, + CALL_RESULT, + HINT, + PATH, + PERIODIC_COMMIT, + UNION, + SINGLE, + NAMED_PATTERN, + NODE_PATTERN, + REL_PATTERN, + SHORTEST_PATTERN, + LITERAL, + SET_ITEM } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherProcessor.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherProcessor.java index 9d77b226b0..f611a5db1a 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherProcessor.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherProcessor.java @@ -33,8 +33,8 @@ import org.polypheny.db.nodes.Node; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptUtil; -import org.polypheny.db.processing.ExtendedQueryParameters; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.tools.AlgBuilder; import org.polypheny.db.transaction.Lock.LockMode; @@ -94,7 +94,7 @@ public Pair validate( Transaction transaction, Node parsed, b @Override - public AlgRoot translate( Statement statement, Node query, QueryParameters parameters ) { + public AlgRoot translate( Statement statement, ParsedQueryContext context ) { final StopWatch stopWatch = new StopWatch(); if ( log.isDebugEnabled() ) { @@ -108,7 +108,7 @@ public AlgRoot translate( Statement statement, Node query, QueryParameters param final CypherToAlgConverter cypherToAlgConverter = new CypherToAlgConverter( statement, builder, rexBuilder, cluster ); - AlgRoot logicalRoot = cypherToAlgConverter.convert( (CypherNode) query, (ExtendedQueryParameters) parameters, cluster ); + AlgRoot logicalRoot = cypherToAlgConverter.convert( (CypherNode) context.getQueryNode(), context, cluster ); // Decorrelate final AlgBuilder algBuilder = AlgBuilder.create( statement ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabaseAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabaseAlias.java index c5ffba9fb3..71fa2922e5 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabaseAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabaseAlias.java @@ -25,9 +25,9 @@ import org.polypheny.db.cypher.CypherSimpleEither; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -52,7 +52,7 @@ public CypherAlterDatabaseAlias( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { List graphs = statement.getTransaction().getSnapshot().getNamespaces( new Pattern( targetName ) ); if ( graphs.size() != 1 ) { diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java index 4c5a4aae16..d69763e724 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import lombok.Getter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.Catalog; @@ -28,9 +29,9 @@ import org.polypheny.db.cypher.clause.CypherWaitClause; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -64,7 +65,7 @@ public CypherCreateDatabase( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { AdapterManager manager = AdapterManager.getInstance(); if ( wait != null && wait.isWait() ) { try { @@ -108,4 +109,10 @@ public CypherKind getCypherKind() { return CypherKind.CREATE_DATABASE; } + + @Override + public @Nullable String getEntity() { + return databaseName; + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java index d0a6a3c920..63441636f5 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java @@ -18,6 +18,7 @@ import java.util.List; import lombok.Getter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Pattern; @@ -25,9 +26,9 @@ import org.polypheny.db.cypher.CypherSimpleEither; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -55,7 +56,7 @@ public CypherCreateDatabaseAlias( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { List graphs = statement.getTransaction().getSnapshot().getNamespaces( new Pattern( targetName ) ); if ( graphs.size() != 1 ) { throw new GenericRuntimeException( "Error while creating a new graph database alias." ); @@ -69,4 +70,10 @@ public boolean isDDL() { return true; } + + @Override + public @Nullable String getEntity() { + return targetName; + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java index 8e4925848b..049723acdb 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java @@ -25,9 +25,9 @@ import org.polypheny.db.cypher.CypherSimpleEither; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -46,7 +46,7 @@ public CypherDropAlias( ParserPos pos, CypherSimpleEither graphs = statement.getTransaction().getSnapshot().getNamespaces( new Pattern( aliasName ) ); if ( graphs.size() != 1 ) { throw new GenericRuntimeException( "Error while dropping a graph database alias." ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java index e3a4a9acd7..7e4a87b5a0 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Pattern; @@ -26,9 +27,9 @@ import org.polypheny.db.cypher.clause.CypherWaitClause; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -55,7 +56,7 @@ public CypherDropDatabase( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { if ( wait != null && wait.isWait() ) { try { Thread.sleep( TimeUnit.MILLISECONDS.convert( wait.getNanos(), TimeUnit.NANOSECONDS ) ); @@ -82,4 +83,10 @@ public boolean isDDL() { return true; } + + @Override + public @Nullable String getEntity() { + return databaseName; + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java index 2b89e57a4e..6c492df4c0 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java @@ -26,9 +26,9 @@ import org.polypheny.db.cypher.expression.CypherVariable; import org.polypheny.db.cypher.parser.StringPos; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -74,7 +74,7 @@ public CypherCreateConstraint( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { if ( constraintType != ConstraintType.UNIQUE ) { throw new UnsupportedOperationException( "Only unique constraints are supported at the moment." ); } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java index 2a4382d007..fdc55dab00 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java @@ -19,9 +19,9 @@ import lombok.Getter; import org.polypheny.db.cypher.expression.CypherExpression; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -50,7 +50,7 @@ public boolean isDDL() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { } 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 5e7a723256..e9042318ab 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 @@ -73,7 +73,7 @@ import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.processing.ExtendedQueryParameters; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexCall; import org.polypheny.db.rex.RexLiteral; @@ -107,12 +107,12 @@ public CypherToAlgConverter( Statement statement, AlgBuilder builder, RexBuilder } - public AlgRoot convert( CypherNode query, ExtendedQueryParameters parameters, AlgOptCluster cluster ) { - long namespaceId = getNamespaceId( parameters ); + public AlgRoot convert( CypherNode query, ParsedQueryContext parsedContext, AlgOptCluster cluster ) { + long namespaceId = getNamespaceId( parsedContext ); - LogicalEntity entity = getEntity( namespaceId, parameters ); + LogicalEntity entity = getEntity( namespaceId ); - if ( parameters.isFullGraph() ) { + if ( parsedContext.getQuery().trim().equals( "*" ) ) { // simple full graph scan return AlgRoot.of( buildFullScan( (LogicalGraph) entity ), Kind.SELECT ); } @@ -130,7 +130,7 @@ public AlgRoot convert( CypherNode query, ExtendedQueryParameters parameters, Al @NotNull - private LogicalEntity getEntity( long namespaceId, ExtendedQueryParameters parameters ) { + private LogicalEntity getEntity( long namespaceId ) { Optional optionalGraph = this.snapshot.graph().getGraph( namespaceId ); if ( optionalGraph.isPresent() ) { return optionalGraph.get(); @@ -154,8 +154,8 @@ private AlgNode buildFullScan( LogicalGraph graph ) { } - private long getNamespaceId( ExtendedQueryParameters parameters ) { - return snapshot.getNamespace( parameters.namespace ).orElseThrow().id; + private long getNamespaceId( ParsedQueryContext context ) { + return snapshot.getNamespace( context.getQueryNode().getNamespaceId() ).orElseThrow().id; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java index fb01622f30..36e2b531e4 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java @@ -31,9 +31,9 @@ import org.polypheny.db.cypher.admin.CypherAdminCommand; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -61,7 +61,7 @@ public CypherAddPlacement( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { AdapterManager adapterManager = AdapterManager.getInstance(); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java index c1964eea7e..5f7bd04f41 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java @@ -29,9 +29,9 @@ import org.polypheny.db.cypher.admin.CypherAdminCommand; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; public class CypherDropPlacement extends CypherAdminCommand implements ExecutableStatement { @@ -51,7 +51,7 @@ public CypherDropPlacement( @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { AdapterManager adapterManager = AdapterManager.getInstance(); List graphs = statement.getTransaction().getSnapshot().getNamespaces( new Pattern( this.databaseName ) ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java index 1a0040e675..59a6d87e0c 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java @@ -21,9 +21,9 @@ import org.polypheny.db.cypher.admin.CypherWithGraph; import org.polypheny.db.cypher.clause.CypherUseClause; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @Getter @@ -42,9 +42,9 @@ public CypherUseGraph( CypherWithGraph statement, CypherUseClause useClause ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { if ( this.statement != null && this.statement.isDDL() ) { - ((ExecutableStatement) this.statement).execute( context, statement, parameters ); + ((ExecutableStatement) this.statement).execute( context, statement, parsedQueryContext ); } if ( useClause != null ) { log.warn( useClause.toString() ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java index 602bc08781..96fb91c38d 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java @@ -23,9 +23,9 @@ import org.polypheny.db.cypher.clause.CypherClause; import org.polypheny.db.cypher.clause.CypherQuery; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @Getter @@ -70,10 +70,10 @@ public boolean isDDL() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { for ( CypherClause clause : clauses ) { if ( clause.isDDL() ) { - ((ExecutableStatement) clause).execute( context, statement, parameters ); + ((ExecutableStatement) clause).execute( context, statement, parsedQueryContext ); } } } diff --git a/plugins/explore-by-example/build.gradle b/plugins/explore-by-example/build.gradle deleted file mode 100644 index 1412f9e74d..0000000000 --- a/plugins/explore-by-example/build.gradle +++ /dev/null @@ -1,80 +0,0 @@ -group "org.polypheny" - - -dependencies { - compileOnly project(":core") - compileOnly project(":webui") - - implementation group: "nz.ac.waikato.cms.weka", name: "weka-stable", version: weka_version // GPL 3.0 - compileOnly(group: "io.javalin", name: "javalin", version: javalin_version) { // Apache 2.0 - exclude(group: "org.slf4j") - } - - - // --- Test Compile --- - testImplementation project(path: ":core", configuration: "tests") - testImplementation project(path: ":core") - testImplementation project(path: ":webui") - - testImplementation group: "junit", name: "junit", version: junit_version -} - -compileJava { - dependsOn(":config:processResources") - dependsOn(":core:processResources") - dependsOn(":information:processResources") - dependsOn(":webui:processResources") -} - -delombok { - dependsOn(":core:processResources") - dependsOn(":webui:processResources") -} - - -sourceSets { - main { - java { - srcDirs = ["src/main/java"] - outputDir = file(project.buildDir.absolutePath + "/classes") - } - resources { - srcDirs = ["src/main/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/classes") - } - test { - java { - srcDirs = ["src/test/java"] - outputDir = file(project.buildDir.absolutePath + "/test-classes") - } - resources { - srcDirs = ["src/test/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/test-classes") - } -} - - -/** - * JARs - */ -jar { - manifest { - attributes "Manifest-Version": "1.0" - attributes "Copyright": "The Polypheny Project (polypheny.org)" - attributes "Version": "$project.version" - } -} -java { - withJavadocJar() - withSourcesJar() -} - -licensee { - ignoreDependencies('nz.ac.waikato.cms.weka') { - transitive = true - because "removed on release branches" - } - -} diff --git a/plugins/explore-by-example/gradle.properties b/plugins/explore-by-example/gradle.properties deleted file mode 100644 index ec15d201d7..0000000000 --- a/plugins/explore-by-example/gradle.properties +++ /dev/null @@ -1,27 +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. -# - -pluginVersion = 0.0.1 - -pluginId = explore-by-example -pluginClass = org.polypheny.db.exploreByExample.ExploreByExamplePlugin -pluginProvider = The Polypheny Project -pluginDependencies = -pluginUrlPath = -pluginCategories = -pluginPolyDependencies = -pluginIsSystemComponent = false -pluginIsUiVisible = true \ No newline at end of file diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/Explore.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/Explore.java deleted file mode 100644 index 594922a3e7..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/Explore.java +++ /dev/null @@ -1,527 +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.exploreByExample; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import weka.classifiers.trees.J48; -import weka.core.Attribute; -import weka.core.DenseInstance; -import weka.core.FastVector; -import weka.core.Instances; -import weka.core.Utils; - - -@Slf4j -public class Explore { - - @Getter - private int id; - @Setter - List> uniqueValues; - @Getter - @Setter - private List labeled; - @Getter - @Setter - private String[] dataType; - @Setter - @Getter - private String[] labels; - private Instances unlabeledData; - @Getter - private String buildGraph; - @Getter - private String[][] data; - @Getter - private String query; - @Getter - private String sqlStatement; - @Getter - private boolean classificationPossible = true; - private final ExploreQueryProcessor exploreQueryProcessor; - @Getter - private List dataAfterClassification; - @Getter - private int tableSize; - private final List qualifiedNames = new ArrayList<>(); - @Getter - private String classifiedSqlStatement; - private final Map nameAndType = new HashMap<>(); - @Getter - private boolean isConvertedToSql; - @Getter - private boolean includesJoin; - public boolean isDataAfterClassification; - - public String entityName; - public long entityId; - - - public Explore( int identifier, String query, ExploreQueryProcessor exploreQueryProcessor ) { - this.id = identifier; - this.query = query; - this.sqlStatement = query; - this.exploreQueryProcessor = exploreQueryProcessor; - this.dataType = getTypeInfo( query ); - } - - - /** - * First exploration/classification with the labeled entries from the user - */ - public void exploreUserInput() { - isDataAfterClassification = true; - List initialDataClassification = getAllData( sqlStatement ); - unlabeledData = createInstance( initialDataClassification, rotate2dArray( initialDataClassification ), dataType, uniqueValues ); - dataAfterClassification = classifyUnlabeledData( trainData( createInstance( rotate2dArray( labeled ), labeled, dataType, uniqueValues ) ), unlabeledData ); - } - - - /** - * For each additional exploration - * - * @param labeled data from user - */ - public void updateExploration( List labeled ) { - dataAfterClassification = classifyUnlabeledData( trainData( createInstance( rotate2dArray( labeled ), labeled, dataType, uniqueValues ) ), unlabeledData ); - } - - - /** - * Final classification of all data according to isConvertedToSql with Weka or by creating a sql query - * - * @param labeled data from user - * @param isConvertedToSql boolean if it should be converted to SQL or not - */ - public void classifyAllData( List labeled, boolean isConvertedToSql ) { - List allData = getAllData( this.query ); - isDataAfterClassification = false; - classificationPossible = false; - this.isConvertedToSql = isConvertedToSql; - if ( isConvertedToSql ) { - classifiedSqlStatement = sqlClassifiedData( trainData( createInstance( rotate2dArray( labeled ), labeled, dataType, uniqueValues ) ), nameAndType ); - tableSize = getSQLCount( classifiedSqlStatement ); - } else { - unlabeledData = createInstance( allData, rotate2dArray( allData ), dataType, uniqueValues ); - data = classifyData( trainData( createInstance( rotate2dArray( labeled ), labeled, dataType, uniqueValues ) ), unlabeledData ); - } - } - - - /** - * Executes query to get the type information about all the queries - * - * @param query from user interface - * @return different data types of a query - */ - - public String[] getTypeInfo( String query ) { - ExploreQueryResult exploreQueryResult = this.exploreQueryProcessor.executeSQL( query ); - - String[] fullNames = query.split( "SELECT " )[1].split( "\nFROM" )[0].replace( " ", "" ).toLowerCase().split( "," ); - String[] dataType = new String[fullNames.length]; - - for ( int i = 0; i < exploreQueryResult.typeInfo.size(); i++ ) { - String name = fullNames[i].substring( fullNames[i].lastIndexOf( "." ) + 1 ); - name = name.replace( "\"", "" ); // remove quotes - if ( exploreQueryResult.name.get( i ).startsWith( name ) ) { - String type = exploreQueryResult.typeInfo.get( i ); - if ( Stream.of( "VARCHAR", "INTEGER", "BIGINT", "SMALLINT", "TINYINT", "DECIMAL", "JSON" ).anyMatch( type::contains ) || type.contains( "VARCHAR" ) ) { - dataType[i] = exploreQueryResult.typeInfo.get( i ); - nameAndType.put( fullNames[i], dataType[i] ); - } else { - dataType = null; - return null; - } - } - } - - Collections.addAll( qualifiedNames, fullNames ); - qualifiedNames.add( "classifications" ); - - return dataType; - } - - - /** - * Creates the SQL query for the initial table - */ - public void createSQLStatement() { - - List selectedCols = new ArrayList<>(); - List whereClause = new ArrayList<>(); - List allCols = new ArrayList<>(); - List groupByList = new ArrayList<>(); - List intCols = new ArrayList<>(); - List unionList = new ArrayList<>(); - List allBlankCols = new ArrayList<>(); - includesJoin = false; - int rowCount = getSQLCount( sqlStatement + "\nLIMIT 60" ); - - if ( rowCount < 10 ) { - classificationPossible = false; - tableSize = rowCount; - } else if ( rowCount > 10 && rowCount < 40 ) { - tableSize = rowCount; - } else if ( rowCount > 40 ) { - String selectDistinct = sqlStatement.replace( "SELECT", "SELECT DISTINCT" ) + "\nLIMIT 60"; - if ( sqlStatement.contains( "WHERE" ) ) { - includesJoin = true; - sqlStatement = selectDistinct; - tableSize = getSQLCount( sqlStatement.replace( "\nLIMIT 60", "\nLIMIT 200" ) ); - return; - } - if ( sqlStatement.split( "\nFROM" )[1].split( "," ).length > 1 ) { - sqlStatement = selectDistinct; - tableSize = getSQLCount( sqlStatement ); - return; - } - rowCount = getSQLCount( selectDistinct ); - if ( rowCount < 10 ) { - tableSize = rowCount; - classificationPossible = false; - } else if ( rowCount > 10 && rowCount < 40 ) { - tableSize = rowCount; - sqlStatement = selectDistinct; - } else if ( rowCount > 40 ) { - - selectedCols = Arrays.asList( sqlStatement.replace( "SELECT", "" ).split( "\nFROM" )[0].split( "," ) ); - - boolean includesInteger = false; - boolean includesVarchar = false; - for ( int i = 0; i < selectedCols.size(); i++ ) { - if ( dataType[i].equals( "VARCHAR" ) ) { - includesVarchar = true; - allCols.add( selectedCols.get( i ) ); - groupByList.add( selectedCols.get( i ) ); - allBlankCols.add( selectedCols.get( i ) ); - } - if ( dataType[i].equals( "INTEGER" ) || dataType[i].equals( "BIGINT" ) || dataType[i].equals( "SMALLINT" ) || dataType[i].equals( "TINYINT" ) || dataType[i].equals( "DECIMAL" ) ) { - includesInteger = true; - allCols.add( "AVG(" + selectedCols.get( i ) + ") AS " + selectedCols.get( i ).substring( selectedCols.get( i ).lastIndexOf( '.' ) + 1 ) ); - intCols.add( selectedCols.get( i ) ); - allBlankCols.add( selectedCols.get( i ) ); - } - } - - if ( includesInteger ) { - getMins( intCols ).forEach( ( s, min ) -> unionList.add( "\nUNION \n(SELECT " + String.join( ",", allBlankCols ) + "\nFROM" + sqlStatement.split( "\nFROM" )[1] + "\nWHERE " + s + "=" + min + "\nLIMIT 1)" ) ); - getMaxs( intCols ).forEach( ( s, max ) -> unionList.add( "\nUNION \n(SELECT " + String.join( ",", allBlankCols ) + "\nFROM" + sqlStatement.split( "\nFROM" )[1] + "\nWHERE " + s + "=" + max + "\nLIMIT 1)" ) ); - } - - if ( includesVarchar ) { - sqlStatement = "(SELECT " + String.join( ",", allCols ) + "\nFROM" + sqlStatement.split( "\nFROM" )[1] + "\nGROUP BY " + String.join( ",", groupByList ) + "\nLIMIT 200)" + String.join( "", unionList ); - } else { - sqlStatement = "SELECT " + String.join( ",", allCols ) + "\nFROM" + sqlStatement.split( "\nFROM" )[1] + String.join( "", unionList ); - } - - tableSize = getSQLCount( sqlStatement + "\nLIMIT 200" ); - } - } - } - - - /** - * Gets all unique Values for a given query and adds true and false for Weka Instances - */ - public List> getStatistics( String query ) { - - List> uniqueValues = new ArrayList<>(); - List values = this.exploreQueryProcessor.getAllUniqueValues( prepareColInfo( query ), query ); - - for ( ExploreQueryResult uniqueValue : values ) { - List data = new ArrayList<>(); - for ( int i = 0; i < uniqueValue.data.length; i++ ) { - List cols = new ArrayList<>(); - for ( int j = 0; j < uniqueValue.data[i].length; j++ ) { - cols.add( uniqueValue.data[i][j] ); - } - data.add( String.join( ",", cols ) ); - } - uniqueValues.add( data ); - } - - List trueFalse = new ArrayList<>(); - trueFalse.add( "true" ); - trueFalse.add( "false" ); - uniqueValues.add( trueFalse ); - - return uniqueValues; - } - - - /** - * Gets all data with a query and adds "?" for classification - * - * @return List of all Data - */ - private List getAllData( String query ) { - ExploreQueryResult exploreQueryResult = this.exploreQueryProcessor.executeSQL( query ); - List allDataTable = new ArrayList<>( Arrays.asList( exploreQueryResult.data ) ); - allDataTable = rotate2dArray( allDataTable ); - - String[] questionMark = new String[exploreQueryResult.count]; - for ( int j = 0; j < exploreQueryResult.count; j++ ) { - questionMark[j] = "?"; - } - allDataTable.add( questionMark ); - - return allDataTable; - } - - - /** - * Given a query it returns a list of all qualified column names - * - * @return list of all columns - */ - private List prepareColInfo( String query ) { - return Arrays.asList( query.replace( "SELECT", "" ).split( "\nFROM" )[0].split( "," ) ); - } - - - /** - * @return the amount of entries of a given sql query - */ - private int getSQLCount( String sql ) { - ExploreQueryResult exploreQueryResult = this.exploreQueryProcessor.executeSQL( sql ); - return (exploreQueryResult.count); - } - - - private Map getUniqueValuesCount( List cols ) { - Map counts = new HashMap<>(); - cols.forEach( s -> counts.put( s, getUniqueValueCount( "SELECT DISTINCT" + s + "\nFROM " + s.replaceAll( "\\.[^.]*$", "" ) + "\nLIMIT 200" ) ) ); - return counts; - } - - - private Map getMins( List cols ) { - Map mins = new HashMap<>(); - cols.forEach( s -> mins.put( s, Integer.parseInt( getMin( "SELECT MIN(" + s + ") \nFROM " + s.replaceAll( "\\.[^.]*$", "" ) + "\nLIMIT 200 " ) ) ) ); - return mins; - } - - - private Map getMaxs( List cols ) { - Map maxs = new HashMap<>(); - cols.forEach( s -> maxs.put( s, Integer.parseInt( getMin( "SELECT MAX(" + s + ") \nFROM " + s.replaceAll( "\\.[^.]*$", "" ) + "\nLIMIT 200 " ) ) ) ); - return maxs; - } - - - private String getMin( String sql ) { - ExploreQueryResult exploreQueryResult = this.exploreQueryProcessor.executeSQL( sql ); - return (exploreQueryResult.col); - } - - - private int getUniqueValueCount( String sql ) { - ExploreQueryResult exploreQueryResult = this.exploreQueryProcessor.executeSQL( sql ); - return (exploreQueryResult.count); - } - - - /** - * Rotates a {@code List} to switch between rows and columns - * - * @param table of rows or columns - * @return rotated table - */ - private List rotate2dArray( List table ) { - int width = table.get( 0 ).length; - int height = table.size(); - - String[][] rotatedTable = new String[width][height]; - - for ( int x = 0; x < width; x++ ) { - for ( int y = 0; y < height; y++ ) { - rotatedTable[x][y] = table.get( y )[x]; - } - } - List tab = new ArrayList<>(); - Collections.addAll( tab, rotatedTable ); - return tab; - } - - - /** - * Creates a Weka instance for a given data table - */ - public Instances createInstance( List rotatedTable, List table, String[] dataType, List> uniqueValues ) { - - int numInstances = rotatedTable.get( 0 ).length; - int dimLength = table.get( 0 ).length; - FastVector atts = new FastVector(); - FastVector attVals; - FastVector[] attValsEl = new FastVector[dimLength]; - Instances classifiedData; - double[] vals; - //fullNames.add("classification"); - - // attributes - for ( int dim = 0; dim < dimLength; dim++ ) { - attVals = new FastVector(); - - if ( Arrays.asList( "VARCHAR", "JSON" ).contains( dataType[dim] ) ) { - for ( int i = 0; i < uniqueValues.get( dim ).size(); i++ ) { - attVals.addElement( uniqueValues.get( dim ).get( i ) ); - } - atts.addElement( new Attribute( qualifiedNames.get( dim ), attVals ) ); - attValsEl[dim] = attVals; - } else if ( Arrays.asList( "INTEGER", "BIGINT", "SMALLINT", "TINYINT", "DECIMAL" ).contains( dataType[dim] ) ) { - atts.addElement( new Attribute( qualifiedNames.get( dim ) ) ); - } - } - // instances object - classifiedData = new Instances( "ClassifiedData", atts, 0 ); - - // fill data classified - for ( int obj = 0; obj < numInstances; obj++ ) { - vals = new double[classifiedData.numAttributes()]; - - for ( int dim = 0; dim < dimLength; dim++ ) { - if ( dataType[dim].equals( "VARCHAR" ) ) { - if ( attValsEl[dim].contains( table.get( obj )[dim] ) ) { - vals[dim] = attValsEl[dim].indexOf( table.get( obj )[dim] ); - } else { - vals[dim] = Utils.missingValue(); - } - } else if ( dataType[dim].equals( "INTEGER" ) || dataType[dim].equals( "BIGINT" ) || dataType[dim].equals( "SMALLINT" ) || dataType[dim].equals( "TINYINT" ) || dataType[dim].equals( "DECIMAL" ) ) { - vals[dim] = Double.parseDouble( table.get( obj )[dim] ); - } - } - classifiedData.add( new DenseInstance( 1.0, vals ) ); - } - return classifiedData; - } - - - /** - * Trains a J48 Tree with the entry selection from the user - * - * @param classifiedData weka Instances - * @return J48 tree - */ - public J48 trainData( Instances classifiedData ) { - classifiedData.setClassIndex( classifiedData.numAttributes() - 1 ); - J48 tree = new J48(); - - String[] options = { "-U" }; - try { - tree.setOptions( options ); - } catch ( Exception e ) { - log.error( "Caught exception while setting options for Classification", e ); - } - - try { - tree.buildClassifier( classifiedData ); - this.buildGraph = tree.graph(); - } catch ( Exception e ) { - log.error( "Caught exception while building Classifier and tree graph", e ); - } - - return tree; - } - - - /** - * Translates a Weka J48 Tree to a SQL query - * - * @param tree J48 tree - * @param nameAndType of all the columns - * @return sql query - */ - public String sqlClassifiedData( J48 tree, Map nameAndType ) { - String classifiedSqlStatement = query.split( "\nLIMIT" )[0] + WekaToSql.translate( tree.toString(), nameAndType, includesJoin ); - sqlStatement = classifiedSqlStatement; - return classifiedSqlStatement; - } - - - /** - * Classifies unlabeled data with the before created tree - * - * @param tree J48 tree - * @param unlabeled Weka Instances - * @return labeled data - */ - public List classifyUnlabeledData( J48 tree, Instances unlabeled ) { - unlabeled.setClassIndex( unlabeled.numAttributes() - 1 ); - Instances labeled = new Instances( unlabeled ); - String[] label = new String[unlabeled.numInstances()]; - List labeledData = new ArrayList<>(); - - for ( int i = 0; i < unlabeled.numInstances(); i++ ) { - double clsLabel = 0; - - try { - clsLabel = tree.classifyInstance( unlabeled.instance( i ) ); - } catch ( Exception e ) { - log.error( "Caught exception while classifying unlabeled data", e ); - } - - labeled.instance( i ).setClassValue( clsLabel ); - label[i] = unlabeled.classAttribute().value( (int) clsLabel ); - labeledData.add( labeled.instance( i ).toString().split( "," ) ); - } - - return labeledData; - } - - - /** - * Classify all Data with tree built before - * - * @param tree J48 Weka Tree - * @param unlabeled all selected unlabeled Data - * @return only the data labeled as true - */ - public String[][] classifyData( J48 tree, Instances unlabeled ) { - List labeledData = new ArrayList<>(); - unlabeled.setClassIndex( unlabeled.numAttributes() - 1 ); - Instances labeled = new Instances( unlabeled ); - - for ( int i = 0; i < unlabeled.numInstances(); i++ ) { - double clsLabel = 0; - - try { - clsLabel = tree.classifyInstance( unlabeled.instance( i ) ); - } catch ( Exception e ) { - log.error( "Caught exception while classifying all unlabeled data", e ); - } - - labeled.instance( i ).setClassValue( clsLabel ); - - if ( "true".equals( unlabeled.classAttribute().value( (int) clsLabel ) ) ) { - labeledData.add( Arrays.copyOf( labeled.instance( i ).toString().split( "," ), labeled.instance( i ).toString().split( "," ).length - 1 ) ); - } - } - return labeledData.toArray( new String[0][] ); - } - -} diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreByExamplePlugin.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreByExamplePlugin.java deleted file mode 100644 index d4041ca670..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreByExamplePlugin.java +++ /dev/null @@ -1,82 +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.exploreByExample; - -import lombok.extern.slf4j.Slf4j; -import org.pf4j.Extension; -import org.polypheny.db.iface.Authenticator; -import org.polypheny.db.plugins.PluginContext; -import org.polypheny.db.plugins.PolyPlugin; -import org.polypheny.db.processing.TransactionExtension; -import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.webui.ConfigService.HandlerType; -import org.polypheny.db.webui.HttpServer; - -public class ExploreByExamplePlugin extends PolyPlugin { - - /** - * Constructor to be used by plugin manager for plugin instantiation. - * Your plugins have to provide constructor with this exact signature to be successfully loaded by manager. - */ - public ExploreByExamplePlugin( PluginContext context ) { - super( context ); - } - - - @Override - public void start() { - TransactionExtension.REGISTER.add( new ExploreStarter() ); - } - - - @Override - public void stop() { - HttpServer server = HttpServer.getInstance(); - server.removeRoute( "/classifyData", HandlerType.POST ); - server.removeRoute( "/getExploreTables", HandlerType.POST ); - server.removeRoute( "/createInitialExploreQuery", HandlerType.POST ); - server.removeRoute( "/exploration", HandlerType.POST ); - } - - - @Slf4j - @Extension - public static class ExploreStarter implements TransactionExtension { - - public ExploreStarter() { - // empty on purpose - log.debug( "ExploreStarter started" ); - } - - - @Override - public void initExtension( TransactionManager manager, Authenticator authenticator ) { - final ExploreQueryProcessor exploreQueryProcessor = new ExploreQueryProcessor( manager, authenticator ); // Explore-by-Example - ExploreManager explore = ExploreManager.getInstance(); - explore.setExploreQueryProcessor( exploreQueryProcessor ); - - HttpServer server = HttpServer.getInstance(); - server.addSerializedRoute( "/classifyData", explore::classifyData, HandlerType.POST ); - server.addSerializedRoute( "/getExploreTables", explore::getExploreTables, HandlerType.POST ); - server.addSerializedRoute( "/createInitialExploreQuery", explore::createInitialExploreQuery, HandlerType.POST ); - server.addSerializedRoute( "/exploration", explore::exploration, HandlerType.POST ); - } - - } - - -} diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreManager.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreManager.java deleted file mode 100644 index df20d37305..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreManager.java +++ /dev/null @@ -1,357 +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.exploreByExample; - - -import io.javalin.http.Context; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.exploreByExample.models.RelationalExploreResult; -import org.polypheny.db.exploreByExample.models.RelationalExploreResult.RelationalExploreResultBuilder; -import org.polypheny.db.exploreByExample.requests.ClassifyAllData; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionException; -import org.polypheny.db.webui.Crud; -import org.polypheny.db.webui.Crud.QueryExecutionException; -import org.polypheny.db.webui.models.requests.ExploreData; -import org.polypheny.db.webui.models.requests.ExploreTables; -import org.polypheny.db.webui.models.requests.QueryExplorationRequest; -import org.polypheny.db.webui.models.results.ExploreResult; -import org.polypheny.db.webui.models.results.RelationalResult; -import org.polypheny.db.webui.models.results.RelationalResult.RelationalResultBuilder; - -@Slf4j -public class ExploreManager { - - private static ExploreManager INSTANCE = null; - private final Map explore = new HashMap<>(); - private final AtomicInteger atomicId = new AtomicInteger(); - private ExploreQueryProcessor exploreQueryProcessor; - - - public synchronized static ExploreManager getInstance() { - if ( INSTANCE == null ) { - INSTANCE = new ExploreManager(); - } - return INSTANCE; - } - - - public void setExploreQueryProcessor( ExploreQueryProcessor exploreQueryProcessor ) { - this.exploreQueryProcessor = exploreQueryProcessor; - } - - - public Explore getExploreInformation( Integer id ) { - return explore.get( id ); - } - - - /** - * Creates the initial sql statement for initial query. - * - * @param id ExploreID to identify the explore object at this point always null - * @param query Initial sql query form user interface - * @return Explore object - */ - public Explore createSqlQuery( Integer id, String query ) { - if ( id == null ) { - int identifier = atomicId.getAndIncrement(); - explore.put( identifier, new Explore( identifier, query, this.exploreQueryProcessor ) ); - - if ( explore.get( identifier ).getDataType() == null ) { - return explore.get( identifier ); - } - - explore.get( identifier ).createSQLStatement(); - return explore.get( identifier ); - } - return null; - } - - - /** - * Starts the exploration process or continuous the process, depending on the explore id. - * - * @param id Explore ID to identify the explore object - * @param classified data form user - * @param dataType for all columns - * @return Explore Object - */ - public Explore exploreData( Integer id, String[][] classified, String[] dataType ) { - List labeled = new ArrayList<>(); - - for ( String[] data : classified ) { - if ( !(data[data.length - 1].equals( "?" )) ) { - labeled.add( data ); - } - } - - if ( id != null && explore.containsKey( id ) && explore.get( id ).getLabeled() != null ) { - explore.get( id ).updateExploration( labeled ); - } else { - explore.get( id ).setLabeled( labeled ); - explore.get( id ).setUniqueValues( explore.get( id ).getStatistics( explore.get( id ).getQuery() ) ); - explore.get( id ).setDataType( dataType ); - explore.get( id ).exploreUserInput(); - } - return explore.get( id ); - } - - - /** - * Classify all data for final result - * - * @param id Explore ID to identify the explore object - * @param classified data form user - * @param returnsSql to check if WekaToSQL is active or not - * @return Explore object - */ - public Explore classifyData( Integer id, String[][] classified, boolean returnsSql ) { - List labeled = new ArrayList<>(); - for ( String[] data : classified ) { - if ( !(data[data.length - 1].equals( "?" )) ) { - labeled.add( data ); - } - } - explore.get( id ).classifyAllData( labeled, returnsSql ); - return explore.get( id ); - } - - - /** - * Gets the classified Data from User - * return possibly interesting Data to User - */ - public void classifyData( final Context ctx, Crud crud ) { - ClassifyAllData classifyAllData = ctx.bodyAsClass( ClassifyAllData.class ); - - boolean isConvertedToSql = isClassificationToSql(); - - Explore explore = classifyData( classifyAllData.id, classifyAllData.classified, isConvertedToSql ); - - if ( isConvertedToSql ) { - Transaction transaction = crud.getTransaction(); - Statement statement = transaction.createStatement(); - RelationalExploreResultBuilder result; - - try { - result = RelationalExploreResult.from( Crud - .executeSqlSelect( statement, classifyAllData, explore.getClassifiedSqlStatement(), false, crud ).build() ) - .query( explore.getClassifiedSqlStatement() ); - transaction.commit(); - } catch ( QueryExecutionException | TransactionException | RuntimeException e ) { - log.error( "Caught exception while executing a query from the console", e ); - result = RelationalExploreResult.builder() - .error( e.getMessage() ) - .query( explore.getClassifiedSqlStatement() ); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Caught exception while rollback", ex ); - } - } - - result.explorerId( explore.getId() ) - .currentPage( classifyAllData.cPage ) - .table( explore.entityName ) - .highestPage( (int) Math.ceil( (double) explore.getTableSize() / crud.getPageSize() ) ) - .classificationInfo( "NoClassificationPossible" ) - .isConvertedToSql( isConvertedToSql ); - - ctx.json( result ); - } else { - RelationalResultBuilder result = RelationalExploreResult.builder() - .header( classifyAllData.header ) - .data( Arrays.copyOfRange( explore.getData(), 0, 10 ) ) - .classificationInfo( "NoClassificationPossible" ) - .explorerId( explore.getId() ) - .currentPage( classifyAllData.cPage ) - .table( explore.entityName ) - .highestPage( (int) Math.ceil( (double) explore.getData().length / crud.getPageSize() ) ) - .isConvertedToSql( isConvertedToSql ); - ctx.json( result ); - } - - } - - - public boolean isClassificationToSql() { - return RuntimeConfig.EXPLORE_BY_EXAMPLE_TO_SQL.getBoolean(); - } - - - /** - * For pagination within the Explore-by-Example table - */ - public void getExploreTables( final Context ctx, Crud crud ) { - ExploreTables exploreTables = ctx.bodyAsClass( ExploreTables.class ); - Transaction transaction = crud.getTransaction(); - Statement statement = transaction.createStatement(); - - RelationalExploreResultBuilder result; - Explore explore = getExploreInformation( exploreTables.id ); - String[][] paginationData; - - String query = explore.getSqlStatement() + " OFFSET " + ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()); - - if ( !explore.isConvertedToSql() && !explore.isClassificationPossible() ) { - int tablesize = explore.getData().length; - - if ( tablesize >= ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()) && tablesize < ((Math.max( 0, exploreTables.cPage )) * crud.getPageSize()) ) { - paginationData = Arrays.copyOfRange( explore.getData(), ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()), tablesize ); - } else { - paginationData = Arrays.copyOfRange( explore.getData(), ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()), ((Math.max( 0, exploreTables.cPage )) * crud.getPageSize()) ); - } - result = RelationalExploreResult.builder() - .header( exploreTables.columns ) - .classifiedData( paginationData ) - .classificationInfo( "NoClassificationPossible" ) - .explorerId( explore.getId() ) - .currentPage( exploreTables.cPage ) - .table( explore.entityName ) - .highestPage( (int) Math.ceil( (double) tablesize / crud.getPageSize() ) ); - - ctx.json( result ); - } - - try { - result = RelationalExploreResult.from( crud.executeSqlSelect( statement, exploreTables, query ).build() ); - } catch ( QueryExecutionException e ) { - log.error( "Caught exception while fetching a table", e ); - result = RelationalExploreResult.builder().error( "Could not fetch table " + exploreTables.entityId ); - try { - transaction.rollback(); - ctx.status( 500 ).json( result ); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - - try { - transaction.commit(); - } catch ( TransactionException e ) { - log.error( "Caught exception while committing transaction", e ); - } - result.explorerId( explore.getId() ) - .currentPage( exploreTables.cPage ) - .table( explore.entityName ); - int tableSize = explore.getTableSize(); - - result.highestPage( (int) Math.ceil( (double) tableSize / crud.getPageSize() ) ); - - if ( !explore.isClassificationPossible() ) { - result.classificationInfo( "NoClassificationPossible" ); - } else { - result.classificationInfo( "ClassificationPossible" ); - } - result.includesClassificationInfo( explore.isDataAfterClassification ); - - if ( explore.isDataAfterClassification ) { - int tablesize = explore.getDataAfterClassification().size(); - List paginationDataList; - if ( tablesize >= ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()) && tablesize < ((Math.max( 0, exploreTables.cPage )) * crud.getPageSize()) ) { - paginationDataList = explore.getDataAfterClassification().subList( ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()), tablesize ); - } else { - paginationDataList = explore.getDataAfterClassification().subList( ((Math.max( 0, exploreTables.cPage - 1 )) * crud.getPageSize()), ((Math.max( 0, exploreTables.cPage )) * crud.getPageSize()) ); - } - - paginationData = new String[paginationDataList.size()][]; - for ( int i = 0; i < paginationDataList.size(); i++ ) { - paginationData[i] = paginationDataList.get( i ); - } - - result.classifiedData( paginationData ); - } - ctx.json( result ); - - } - - - /** - * Creates the initial query for the Explore-by-Example process - */ - public void createInitialExploreQuery( final Context ctx, final Crud crud ) { - QueryExplorationRequest queryExplorationRequest = ctx.bodyAsClass( QueryExplorationRequest.class ); - - RelationalExploreResultBuilder result = RelationalExploreResult.builder(); - - Explore explore = createSqlQuery( null, queryExplorationRequest.query ); - if ( explore.getDataType() == null ) { - ctx.status( 400 ).json( RelationalExploreResult.builder().error( "Explore by Example is only available for tables with the following datatypes: VARCHAR, INTEGER, SMALLINT, TINYINT, BIGINT, DECIMAL" ) ); - return; - } - - Transaction transaction = Crud.getTransaction( queryExplorationRequest.analyze, true, crud.getTransactionManager(), Catalog.defaultUserId, Catalog.defaultNamespaceId, "Explore-by-Example" ); - Statement statement = transaction.createStatement(); - try { - String query = explore.getSqlStatement(); - RelationalResult rel = Crud.executeSqlSelect( statement, queryExplorationRequest, query, false, crud ).query( query ).build(); - result = RelationalExploreResult.from( rel ); - transaction.commit(); - } catch ( QueryExecutionException | TransactionException | RuntimeException e ) { - log.error( "Caught exception while executing a query from the console", e ); - result = RelationalExploreResult.builder().error( e.getMessage() ); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Caught exception while rollback", ex ); - } - } - - result.explorerId( explore.getId() ); - if ( !explore.isClassificationPossible() ) { - result.classificationInfo( "NoClassificationPossible" ); - - } else { - result.classificationInfo( "ClassificationPossible" ); - } - result - .currentPage( queryExplorationRequest.cPage ) - .table( explore.entityName ) - .highestPage( (int) Math.ceil( (double) explore.getTableSize() / crud.getPageSize() ) ); - - ctx.json( result ); - } - - - /** - * Start Classification, classifies the initial dataset, to show what would be within the final result set - */ - public void exploration( final Context ctx, final Crud crud ) { - ExploreData exploreData = ctx.bodyAsClass( ExploreData.class ); - - String[] dataType = new String[exploreData.header.length + 1]; - for ( int i = 0; i < exploreData.header.length; i++ ) { - dataType[i] = exploreData.header[i].dataType; - } - dataType[exploreData.header.length] = "VARCHAR"; - - Explore explore = exploreData( exploreData.id, exploreData.classified, dataType ); - - ctx.json( new ExploreResult( exploreData.header, explore.getDataAfterClassification(), explore.getId(), explore.getBuildGraph() ) ); - } - -} diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java deleted file mode 100644 index dce1db6407..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryProcessor.java +++ /dev/null @@ -1,195 +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.exploreByExample; - - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import lombok.extern.slf4j.Slf4j; -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.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.iface.Authenticator; -import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.nodes.Node; -import org.polypheny.db.processing.Processor; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionException; -import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.util.Pair; - - -@Slf4j -public class ExploreQueryProcessor { - - private final TransactionManager transactionManager; - private final long databaseId; - private final long userId; - private final static int DEFAULT_SIZE = 200; - - - public ExploreQueryProcessor( final TransactionManager transactionManager, long userId, long databaseId ) { - this.transactionManager = transactionManager; - this.userId = userId; - this.databaseId = databaseId; - } - - - public ExploreQueryProcessor( final TransactionManager transactionManager, Authenticator authenticator ) { - this( transactionManager, Catalog.defaultUserId, Catalog.defaultNamespaceId ); - } - - - private Transaction getTransaction() { - return transactionManager.startTransaction( userId, false, "Explore-by-Example" ); - } - - - public List getAllUniqueValues( List qualifiedColumnNames, String qualifiedTableName ) { - String tables = qualifiedTableName.split( "\nFROM " )[1].split( " LIMIT" )[0]; - return qualifiedColumnNames.stream().map( c -> getAllUniqueValuesMethod( c, tables ) ).collect( Collectors.toList() ); - } - - - private ExploreQueryResult getAllUniqueValuesMethod( String qualifiedColumn, String qualifiedTableName ) { - String query = "SELECT " + qualifiedColumn + " FROM " + qualifiedTableName + " GROUP BY " + qualifiedColumn + " LIMIT 200"; - return this.executeSQL( query ); - } - - - public ExploreQueryResult executeSQL( String query ) { - return executeSQL( query, getPageSize() ); - } - - - public ExploreQueryResult executeSQL( String query, int pagination ) { - ExploreQueryResult result = new ExploreQueryResult(); - Transaction transaction = getTransaction(); - Statement statement = transaction.createStatement(); - try { - result = executeSqlSelect( statement, query, pagination ); - transaction.commit(); - } catch ( ExploreQueryProcessor.QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while executing a query from the console", e ); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Caught exception while rollback", e ); - } - } - return result; - } - - // ----------------------------------------------------------------------- - // Helper - // ----------------------------------------------------------------------- - - - private ExploreQueryResult executeSqlSelect( final Statement statement, final String sqlSelect, final int pagination ) throws ExploreQueryProcessor.QueryExecutionException { - PolyImplementation result; - try { - result = processQuery( statement, sqlSelect ); - } catch ( Throwable t ) { - throw new ExploreQueryProcessor.QueryExecutionException( t ); - } - List> rows = result.execute( statement, DEFAULT_SIZE ).getAllRowsAndClose(); - - List typeInfo = new ArrayList<>(); - List name = new ArrayList<>(); - for ( AlgDataTypeField metaData : result.getRowType().getFields() ) { - typeInfo.add( metaData.getType().getFullTypeString() ); - name.add( metaData.getName() ); - } - - if ( rows.size() == 1 ) { - for ( List row : rows ) { - if ( row.size() == 1 ) { - for ( Object o : row ) { - return new ExploreQueryResult( o.toString(), rows.size(), typeInfo, name ); - } - } - } - } - - List data = new ArrayList<>(); - for ( List row : rows ) { - String[] temp = new String[row.size()]; - int counter = 0; - for ( Object o : row ) { - if ( o == null ) { - temp[counter] = null; - } else { - temp[counter] = o.toString(); - } - counter++; - } - data.add( temp ); - } - - String[][] d = data.toArray( new String[0][] ); - - return new ExploreQueryResult( d, rows.size(), typeInfo, name ); - - } - - - private PolyImplementation processQuery( Statement statement, String sql ) { - PolyImplementation result; - Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); - - Node parsed = sqlProcessor.parse( sql ).get( 0 ); - - if ( parsed.isA( Kind.DDL ) ) { - // explore by example should not execute any ddls - throw new GenericRuntimeException( "No DDL expected here" ); - } else { - Pair validated = sqlProcessor.validate( statement.getTransaction(), parsed, false ); - AlgRoot logicalRoot = sqlProcessor.translate( statement, validated.left, null ); - - // Prepare - result = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); - } - return result; - } - - - /** - * Get the page - */ - private int getPageSize() { - return RuntimeConfig.UI_PAGE_SIZE.getInteger(); - } - - - static class QueryExecutionException extends Exception { - - QueryExecutionException( Throwable t ) { - super( t ); - } - - } - - -} diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryResult.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryResult.java deleted file mode 100644 index 8f5ae7eec9..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/ExploreQueryResult.java +++ /dev/null @@ -1,54 +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.exploreByExample; - - -import java.util.List; -import lombok.Getter; - - -public class ExploreQueryResult { - - @Getter - public String[][] data; - public String col; - public int count; - List typeInfo; - List name; - - - public ExploreQueryResult() { - - } - - - public ExploreQueryResult( String[][] data, int count, List colInfo, List name ) { - this.data = data; - this.count = count; - this.typeInfo = colInfo; - this.name = name; - } - - - public ExploreQueryResult( String col, int count, List colInfo, List name ) { - this.col = col; - this.count = count; - this.typeInfo = colInfo; - this.name = name; - } - -} diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/WekaToSql.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/WekaToSql.java deleted file mode 100644 index 4baf465aad..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/WekaToSql.java +++ /dev/null @@ -1,133 +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.exploreByExample; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - - -public class WekaToSql { - - - public static String translate( String tree, Map nameAndType, boolean includesJoin ) { - List splitTree = new ArrayList<>( Arrays.asList( tree.replace( " ", " " ).replace( " ", " " ).split( "Number of Leaves" )[0].split( "\\n" ) ) ); - splitTree.remove( 0 ); - splitTree.remove( 0 ); - splitTree.remove( 0 ); - - List selectedElements = new ArrayList<>(); - - for ( String element : splitTree ) { - if ( !element.contains( "false" ) ) { - if ( element.contains( ":" ) ) { - selectedElements.add( element.split( ":" )[0] ); - } else { - selectedElements.add( element ); - } - } - } - - splitTree.clear(); - for ( String element : selectedElements ) { - List elements = new ArrayList<>(); - List temp = new ArrayList<>(); - if ( element.contains( "<=" ) || element.contains( ">" ) ) { - splitTree.add( element ); - } else if ( element.contains( "=" ) ) { - elements = Arrays.asList( element.split( "=" ) ); - - if ( nameAndType.get( elements.get( 0 ).replaceAll( " ", "" ).replaceAll( "\\|", "" ) ).equals( "VARCHAR" ) ) { - temp.add( elements.get( 0 ).replaceAll( " ", "" ) ); - temp.add( "'" + elements.get( 1 ).substring( 1 ) + "'" ); - splitTree.add( String.join( " = ", temp ) ); - } else { - splitTree.add( element ); - } - } - } - if ( includesJoin ) { - return "\nAND " + WekaToSql.iterateTee( splitTree ); - } else { - return "\nWHERE " + WekaToSql.iterateTee( splitTree ); - } - } - - - private static String iterateTee( List splitTree ) { - List res = new ArrayList<>(); - boolean flag = false; - List sequence = new ArrayList<>(); - String element; - - for ( String node : splitTree ) { - if ( node.contains( "|" ) ) { - sequence.add( node ); - flag = true; - } else { - if ( !flag ) { - sequence.add( node ); - flag = true; - } else { - if ( sequence.size() > 0 ) { - element = sequence.get( 0 ); - sequence.remove( 0 ); - List temp = new ArrayList<>(); - for ( String el : sequence ) { - if ( el.contains( "|" ) ) { - temp.add( el.replaceFirst( "\\|", "" ) ); - } else { - temp.add( el ); - } - } - - if ( temp.size() > 0 ) { - res.add( element + "\nAND " + iterateTee( temp ) ); - } else { - res.add( element ); - } - sequence = new ArrayList<>(); - sequence.add( node ); - } - } - - } - } - if ( sequence.size() > 0 ) { - element = sequence.get( 0 ); - sequence.remove( 0 ); - List temp = new ArrayList<>(); - for ( String el : sequence ) { - if ( el.contains( "|" ) ) { - temp.add( el.replace( "|", "" ) ); - } else { - temp.add( el ); - } - } - - if ( temp.size() > 0 ) { - res.add( element + "\nAND " + iterateTee( temp ) ); - } else { - res.add( element ); - } - } - return "((" + String.join( ") OR (", res ) + "))"; - } - -} diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/models/RelationalExploreResult.java b/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/models/RelationalExploreResult.java deleted file mode 100644 index 0c542c85e1..0000000000 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/models/RelationalExploreResult.java +++ /dev/null @@ -1,74 +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.exploreByExample.models; - -import lombok.EqualsAndHashCode; -import lombok.Value; -import lombok.experimental.SuperBuilder; -import org.polypheny.db.webui.models.results.RelationalResult; - - -@EqualsAndHashCode(callSuper = true) -@SuperBuilder(toBuilder = true) -@Value -public class RelationalExploreResult extends RelationalResult { - - /** - * Explore-by-Example, information about classification, because classification is only possible if a table holds at least 10 entries - */ - public String classificationInfo; - - /** - * Explore-by-Example Explorer Id for - */ - public int explorerId; - - /** - * Pagination for Explore-by-Example, Information if it includes classified data - */ - public boolean includesClassificationInfo; - - /** - * Pagination for Explore-by-Example, to display the classified Data with the addition of true/false - */ - public String[][] classifiedData; - - /** - * Explore-by-Example, Information if the weka classifier is translated to sql or not - */ - public boolean isConvertedToSql; - - - public static RelationalExploreResultBuilder from( RelationalResult rel ) { - RelationalExploreResultBuilder builder = builder(); - builder.header( rel.header ); - builder.currentPage( rel.currentPage ); - builder.highestPage( rel.highestPage ); - builder.hasMore( rel.hasMore ); - builder.table( rel.table ); - builder.tables( rel.tables ); - builder.request( rel.request ); - builder.affectedTuples( rel.affectedTuples ); - builder.exception( rel.exception ); - builder.query( rel.query ); - builder.language( rel.language ); - builder.type( rel.type ); - - return builder; - } - -} diff --git a/plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/ExploreTest.java b/plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/ExploreTest.java deleted file mode 100644 index d0eff0b890..0000000000 --- a/plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/ExploreTest.java +++ /dev/null @@ -1,50 +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.exploreByExample; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - - -public class ExploreTest { - - - @Test - public void parallelExploreTest() { - String query = "SELECT public.depts.deptno\nFROM public.depts"; - ExploreManager manager = ExploreManager.getInstance(); - manager.setExploreQueryProcessor( new MockProcessor() ); - Explore explore = manager.createSqlQuery( null, query ); - assertNotNull( explore ); - - assertEquals( manager.getExploreInformation( explore.getId() ), explore ); - - Explore explore2 = manager.createSqlQuery( null, query ); - assertNotNull( explore2 ); - - assertNotEquals( explore2, explore ); - - assertEquals( manager.getExploreInformation( explore.getId() ), explore ); - assertEquals( manager.getExploreInformation( explore2.getId() ), explore2 ); - } - -} - diff --git a/plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/MockProcessor.java b/plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/MockProcessor.java deleted file mode 100644 index 94460fa319..0000000000 --- a/plugins/explore-by-example/src/test/java/org/polypheny/db/exploreByExample/MockProcessor.java +++ /dev/null @@ -1,45 +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.exploreByExample; - - -import java.util.Collections; - - -/** - * This is a simple mock sql processor, which enables limited testing for the Explore-by-Example functionality - */ -public class MockProcessor extends ExploreQueryProcessor { - - public MockProcessor() { - super( null, null ); - - } - - - @Override - public ExploreQueryResult executeSQL( String query ) { - ExploreQueryResult res = new ExploreQueryResult(); - if ( query.endsWith( "LIMIT 60" ) ) { - res.count = 30; - return res; - } - res = new ExploreQueryResult( new String[][]{}, 0, Collections.singletonList( "INTEGER" ), Collections.singletonList( "public.depts.deptno" ) ); - return res; - } - -} diff --git a/plugins/http-interface/src/main/java/org/polypheny/db/http/HttpInterfacePlugin.java b/plugins/http-interface/src/main/java/org/polypheny/db/http/HttpInterfacePlugin.java index 1f819390a6..651d49d4bb 100644 --- a/plugins/http-interface/src/main/java/org/polypheny/db/http/HttpInterfacePlugin.java +++ b/plugins/http-interface/src/main/java/org/polypheny/db/http/HttpInterfacePlugin.java @@ -41,6 +41,7 @@ import org.pf4j.Extension; import org.polypheny.db.StatusService; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.iface.Authenticator; import org.polypheny.db.iface.QueryInterface; @@ -53,6 +54,7 @@ import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; +import org.polypheny.db.processing.QueryContext; import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.util.Util; import org.polypheny.db.webui.Crud; @@ -71,7 +73,6 @@ public HttpInterfacePlugin( PluginContext context ) { } - @Override public void afterCatalogInit() { // Add HTTP interface @@ -163,7 +164,7 @@ public void run() { StatusService.printInfo( String.format( "%s started and is listening on port %d.", INTERFACE_NAME, port ) ); } ); - LanguageCrud.REGISTER.forEach( ( key, value ) -> addRoute( QueryLanguage.from( key ) ) ); + LanguageManager.getLanguages().forEach( this::addRoute ); } @@ -179,15 +180,17 @@ public void anyQuery( QueryLanguage language, final Context ctx ) { QueryRequest query = ctx.bodyAsClass( QueryRequest.class ); String sessionId = ctx.req.getSession().getId(); Crud.cleanupOldSession( sessionXids, sessionId ); - - List> results = LanguageCrud.anyQuery( - language, - null, - query, - transactionManager, - Catalog.defaultUserId, - Catalog.defaultNamespaceId - ); + LogicalNamespace namespace = Catalog.snapshot().getNamespace( query.namespace ).orElse( null ); + + List> results = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query.query ) + .language( language ) + .userId( Catalog.defaultUserId ) + .origin( "Http Interface" ) + .transactionManager( transactionManager ) + .namespaceId( namespace == null ? Catalog.defaultNamespaceId : namespace.id ) + .build(), query ); ctx.json( results.toArray( new Result[0] ) ); if ( !statementCounters.containsKey( language ) ) { diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverterTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java similarity index 99% rename from plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverterTest.java rename to plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java index 9977960d86..3c271bdbac 100644 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverterTest.java +++ b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java @@ -12,26 +12,9 @@ * 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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.jdbc.rel2sql; +package org.polypheny.db.adapter.jdbc.alg2sql; import static org.hamcrest.CoreMatchers.is; @@ -45,6 +28,7 @@ import org.polypheny.db.adapter.DataContext.SlimDataContext; import org.polypheny.db.adapter.java.JavaTypeFactory; import org.polypheny.db.adapter.java.ReflectiveSchema; +import org.polypheny.db.adapter.jdbc.rel2sql.AlgToSqlConverter; import org.polypheny.db.adapter.jdbc.rel2sql.AlgToSqlConverter.PlainAlgToSqlConverter; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.constant.NullCollation; diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/PlannerTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java similarity index 99% rename from plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/PlannerTest.java rename to plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java index 4afa448569..1a7917c06c 100644 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/PlannerTest.java +++ b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.polypheny.db.adapter.jdbc.rel2sql; +package org.polypheny.db.adapter.jdbc.alg2sql; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/plan/AlgOptPlanReaderTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/plan/AlgOptPlanReaderTest.java similarity index 78% rename from plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/plan/AlgOptPlanReaderTest.java rename to plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/plan/AlgOptPlanReaderTest.java index 5c20ff2ed6..890760d593 100644 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/plan/AlgOptPlanReaderTest.java +++ b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/plan/AlgOptPlanReaderTest.java @@ -12,28 +12,17 @@ * 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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.jdbc.rel2sql.plan; +package org.polypheny.db.adapter.jdbc.alg2sql.plan; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + import org.junit.Test; import org.polypheny.db.adapter.jdbc.JdbcRules; import org.polypheny.db.algebra.AbstractAlgNode; @@ -42,10 +31,6 @@ import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - /** * Unit test for {@link AlgJson}. diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/RelToSqlConverterStructsTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/RelToSqlConverterStructsTest.java deleted file mode 100644 index 9da2302311..0000000000 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/rel2sql/RelToSqlConverterStructsTest.java +++ /dev/null @@ -1,264 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.jdbc.rel2sql; - - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import org.apache.calcite.linq4j.tree.Expression; -import org.junit.Test; -import org.polypheny.db.algebra.AlgCollation; -import org.polypheny.db.algebra.AlgDistribution; -import org.polypheny.db.algebra.AlgReferentialConstraint; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.logistic.NamespaceType; -import org.polypheny.db.catalog.snapshot.Snapshot; -import org.polypheny.db.nodes.Call; -import org.polypheny.db.nodes.Node; -import org.polypheny.db.schema.Entity; -import org.polypheny.db.schema.Function; -import org.polypheny.db.schema.Namespace; -import org.polypheny.db.schema.SchemaPlus; -import org.polypheny.db.schema.SchemaVersion; -import org.polypheny.db.schema.Statistic; -import org.polypheny.db.schema.TableType; -import org.polypheny.db.sql.language.dialect.PolyphenyDbSqlDialect; -import org.polypheny.db.type.PolyType; -import org.polypheny.db.util.ImmutableBitSet; - - -/** - * Tests for {@link AlgToSqlConverter} on a schema that has nested structures of multiple levels. - */ -public class RelToSqlConverterStructsTest { - - private static final Namespace NAMESPACE = new Namespace() { - @Override - public Entity getEntity( String name ) { - return ENTITY; - } - - - @Override - public Set getEntityNames() { - return ImmutableSet.of( "myTable" ); - } - - - @Override - public AlgProtoDataType getType( String name ) { - return null; - } - - - @Override - public Set getTypeNames() { - return ImmutableSet.of(); - } - - - @Override - public Collection getFunctions( String name ) { - return null; - } - - - @Override - public Set getFunctionNames() { - return ImmutableSet.of(); - } - - - @Override - public Namespace getSubNamespace( String name ) { - return null; - } - - - @Override - public Set getSubNamespaceNames() { - return ImmutableSet.of(); - } - - - @Override - public Expression getExpression( Snapshot snapshot, String name ) { - return null; - } - - - @Override - public boolean isMutable() { - return false; - } - - - @Override - public Namespace snapshot( SchemaVersion version ) { - return null; - } - }; - - // Table schema is as following: - // { a: INT, n1: { n11: { b INT }, n12: {c: Int } }, n2: { d: Int }, e: Int } - private static final Entity ENTITY = new Entity() { - @Override - public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - final AlgDataType aType = typeFactory.createPolyType( PolyType.BIGINT ); - final AlgDataType bType = typeFactory.createPolyType( PolyType.BIGINT ); - final AlgDataType cType = typeFactory.createPolyType( PolyType.BIGINT ); - final AlgDataType dType = typeFactory.createPolyType( PolyType.BIGINT ); - final AlgDataType eType = typeFactory.createPolyType( PolyType.BIGINT ); - final AlgDataType n11Type = typeFactory.createStructType( , ImmutableList.of( bType ), ImmutableList.of( "b" ) ); - final AlgDataType n12Type = typeFactory.createStructType( , ImmutableList.of( cType ), ImmutableList.of( "c" ) ); - final AlgDataType n1Type = typeFactory.createStructType( , ImmutableList.of( n11Type, n12Type ), ImmutableList.of( "n11", "n12" ) ); - final AlgDataType n2Type = typeFactory.createStructType( , ImmutableList.of( dType ), ImmutableList.of( "d" ) ); - return typeFactory.createStructType( , - ImmutableList.of( aType, n1Type, n2Type, eType ), ImmutableList.of( "a", "n1", "n2", "e" ) ); - } - - - @Override - public Statistic getStatistic() { - return STATS; - } - - - @Override - public Long getId() { - return null; - } - - - @Override - public TableType getJdbcTableType() { - return null; - } - - - @Override - public boolean isRolledUp( String column ) { - return false; - } - - - @Override - public boolean rolledUpColumnValidInsideAgg( String column, Call call, Node parent ) { - return false; - } - }; - - private static final Statistic STATS = new Statistic() { - @Override - public Double getRowCount() { - return 0D; - } - - - @Override - public boolean isKey( ImmutableBitSet columns ) { - return false; - } - - - @Override - public List getReferentialConstraints() { - return ImmutableList.of(); - } - - - @Override - public List getCollations() { - return ImmutableList.of(); - } - - - @Override - public AlgDistribution getDistribution() { - return null; - } - }; - - private static final SchemaPlus ROOT_SCHEMA = AbstractPolyphenyDbSchema.createSnapshot( "" ).add( "myDb", NAMESPACE, NamespaceType.RELATIONAL ).plus(); - - - private AlgToSqlConverterTest.Sql sql( String sql ) { - return new AlgToSqlConverterTest.Sql( - ROOT_SCHEMA, - sql, - PolyphenyDbSqlDialect.DEFAULT, - AlgToSqlConverterTest.DEFAULT_REL_CONFIG, - ImmutableList.of() ); - } - - - @Test - public void testNestedSchemaSelectStar() { - String query = "SELECT * FROM \"myTable\""; - String expected = "SELECT \"a\", \"n1\".\"n11\".\"b\" AS \"n1\", \"n1\".\"n12\".\"c\" AS \"n12\", \"n2\".\"d\" AS \"n2\", \"e\"\n" - + "FROM \"myDb\".\"myTable\""; - sql( query ).ok( expected ); - } - - - @Test - public void testNestedSchemaRootColumns() { - String query = "SELECT \"a\", \"e\" FROM \"myTable\""; - String expected = "SELECT \"a\", \"e\"\n" - + "FROM \"myDb\".\"myTable\""; - sql( query ).ok( expected ); - } - - - @Test - public void testNestedSchemaNestedColumns() { - String query = "SELECT \"a\", \"e\", " - + "\"myTable\".\"n1\".\"n11\".\"b\", " - + "\"myTable\".\"n2\".\"d\" " - + "FROM \"myTable\""; - String expected = "SELECT \"a\", " - + "\"e\", " - + "\"n1\".\"n11\".\"b\", " - + "\"n2\".\"d\"\n" - + "FROM \"myDb\".\"myTable\""; - sql( query ).ok( expected ); - } - -} - 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 805da10895..be6df0f659 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 @@ -17,26 +17,13 @@ package org.polypheny.db.languages; 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; -import org.polypheny.db.PolyImplementation; -import org.polypheny.db.algebra.AlgRoot; 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.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; -import org.polypheny.db.information.InformationManager; -import org.polypheny.db.languages.mql.Mql.Family; -import org.polypheny.db.languages.mql.MqlCollectionStatement; -import org.polypheny.db.languages.mql.MqlNode; -import org.polypheny.db.languages.mql.MqlQueryParameters; -import org.polypheny.db.languages.mql.MqlUseDatabase; import org.polypheny.db.mql.parser.MqlParserImpl; import org.polypheny.db.nodes.DeserializeFunctionOperator; import org.polypheny.db.nodes.LangFunctionOperator; @@ -44,15 +31,7 @@ import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; -import org.polypheny.db.processing.AutomaticDdlProcessor; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.crud.LanguageCrud; -import org.polypheny.db.webui.models.requests.QueryRequest; -import org.polypheny.db.webui.models.results.RelationalResult; -import org.polypheny.db.webui.models.results.Result; @Slf4j public class MongoLanguagePlugin extends PolyPlugin { @@ -86,103 +65,23 @@ public void stop() { public static void startup() { - PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.crud.languageCrud.addLanguage( "mongo", MongoLanguagePlugin::anyMongoQuery ) ); - LanguageManager.getINSTANCE().addQueryLanguage( NamespaceType.DOCUMENT, "mongo", List.of( "mongo", "mql" ), MqlParserImpl.FACTORY, MqlProcessor::new, null ); - + QueryLanguage language = new QueryLanguage( + NamespaceType.DOCUMENT, + "mongo", + List.of( "mongo", "mql" ), + MqlParserImpl.FACTORY, + MqlProcessor::new, + null, + LanguageManager::toQueryNodes ); + LanguageManager.getINSTANCE().addQueryLanguage( language ); + + PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getDocResult ) ); if ( !isInit() ) { registerOperators(); } } - public static List> anyMongoQuery( - Session session, - QueryRequest request, - TransactionManager transactionManager, - long userId, - long defaultNamespace, - Crud crud ) { - QueryLanguage language = QueryLanguage.from( "mongo" ); - - Transaction transaction = Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, defaultNamespace, "HTTP Interface MQL" ); - AutomaticDdlProcessor mqlProcessor = (AutomaticDdlProcessor) transaction.getProcessor( language ); - - if ( request.analyze ) { - transaction.getQueryAnalyzer().setSession( session ); - } - - InformationManager queryAnalyzer = LanguageCrud.attachAnalyzerIfSpecified( request, crud, transaction ); - - List> results = new ArrayList<>(); - - String[] mqls = request.query.trim().split( "\\n(?=(use|db.|show))" ); - - Long namespaceId = request.namespace == null ? null : Catalog.snapshot().getNamespace( request.namespace ).map( n -> n.id ).orElse( null ); - long executionTime = System.nanoTime(); - boolean noLimit = false; - - for ( String query : mqls ) { - try { - Statement statement = transaction.createStatement(); - QueryParameters parameters = new MqlQueryParameters( query, namespaceId, NamespaceType.DOCUMENT ); - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Parsing" ); - } - MqlNode parsed = (MqlNode) mqlProcessor.parse( query ).get( 0 ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Parsing" ); - } - - if ( parsed instanceof MqlUseDatabase ) { - Optional optionalNamespace = Catalog.snapshot().getNamespace( ((MqlUseDatabase) parsed).getDatabase() ); - namespaceId = optionalNamespace.map( logicalNamespace -> logicalNamespace.id ).orElseGet( () -> Catalog.getInstance().createNamespace( ((MqlUseDatabase) parsed).getDatabase(), NamespaceType.DOCUMENT, false ) ); - continue; - } - - if ( parsed instanceof MqlCollectionStatement && ((MqlCollectionStatement) parsed).getLimit() != null ) { - noLimit = true; - } - - if ( parsed.getFamily() == Family.DML && mqlProcessor.needsDdlGeneration( 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 ) { - mqlProcessor.prepareDdl( statement, parsed, parameters ); - RelationalResult result = RelationalResult.builder().affectedTuples( 1 ).query( query ).xid( transaction.getXid().toString() ).namespaceType( NamespaceType.DOCUMENT ).build(); - results.add( result ); - } else { - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Translation" ); - } - AlgRoot logicalRoot = mqlProcessor.translate( statement, parsed, parameters ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Translation" ); - } - - // Prepare - PolyImplementation polyImplementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Execution" ); - } - results.add( LanguageCrud.getResult( language, statement, request, query, polyImplementation, transaction, noLimit ) ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Execution" ); - } - } - } catch ( Throwable t ) { - LanguageCrud.attachError( transaction, results, query, NamespaceType.DOCUMENT, t ); - log.warn( "Error on mql query: " + t.getMessage() ); - } - } - - LanguageCrud.commitAndFinish( transaction, queryAnalyzer, results, executionTime ); - - return results; - } - public static void registerOperators() { if ( isInit ) { diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java index 1fc93b7f9b..92b8627fac 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java @@ -39,6 +39,7 @@ import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.processing.AutomaticDdlProcessor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.tools.AlgBuilder; import org.polypheny.db.transaction.Lock.LockMode; @@ -112,8 +113,9 @@ public boolean needsDdlGeneration( Node query, QueryParameters parameters ) { } - public void autoGenerateDDL( Statement statement, Node query, QueryParameters parameters ) { - if ( ((MqlCollectionStatement) query).getCollection() == null ) { + @Override + public void autoGenerateDDL( Statement statement, ParsedQueryContext context ) { + if ( context.getQueryNode().getEntity() == null ) { try { statement.getTransaction().commit(); } catch ( TransactionException e ) { @@ -123,9 +125,9 @@ public void autoGenerateDDL( Statement statement, Node query, QueryParameters pa throw new GenericRuntimeException( "No collections is used." ); } new MqlCreateCollection( - ParserPos.sum( Collections.singletonList( query ) ), - ((MqlCollectionStatement) query).getCollection(), - null ).execute( statement.getPrepareContext(), statement, parameters ); + ParserPos.sum( Collections.singletonList( context.getQueryNode() ) ), + context.getQueryNode().getEntity(), + null ).execute( statement.getPrepareContext(), statement, context ); try { statement.getTransaction().commit(); Catalog.getInstance().commit(); @@ -136,7 +138,7 @@ public void autoGenerateDDL( Statement statement, Node query, QueryParameters pa @Override - public AlgRoot translate( Statement statement, Node mql, QueryParameters parameters ) { + public AlgRoot translate( Statement statement, ParsedQueryContext context ) { final StopWatch stopWatch = new StopWatch(); if ( log.isDebugEnabled() ) { log.debug( "Planning Statement ..." ); @@ -147,7 +149,7 @@ public AlgRoot translate( Statement statement, Node mql, QueryParameters paramet final AlgOptCluster cluster = AlgOptCluster.createDocument( statement.getQueryProcessor().getPlanner(), rexBuilder, statement.getTransaction().getSnapshot() ); final MqlToAlgConverter mqlToAlgConverter = new MqlToAlgConverter( statement.getTransaction().getSnapshot(), cluster ); - AlgRoot logicalRoot = mqlToAlgConverter.convert( mql, parameters ); + AlgRoot logicalRoot = mqlToAlgConverter.convert( context ); // Decorrelate final AlgBuilder algBuilder = AlgBuilder.create( statement ); diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java index 4eb55766b6..39433cc50f 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.Adapter; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; @@ -26,10 +27,10 @@ import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; public class MqlAddPlacement extends MqlCollectionStatement implements ExecutableStatement { @@ -41,10 +42,10 @@ public MqlAddPlacement( ParserPos pos, String collection, List stores ) @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { AdapterManager adapterManager = AdapterManager.getInstance(); - long namespaceId = context.getSnapshot().getNamespace( ((MqlQueryParameters) parameters).getNamespaceId() ).orElseThrow().id; + long namespaceId = context.getSnapshot().getNamespace( parsedQueryContext.getQueryNode().getNamespaceId() ).orElseThrow().id; List collections = context.getSnapshot().doc().getCollections( namespaceId, new Pattern( getCollection() ) ); @@ -70,4 +71,10 @@ public Type getMqlKind() { return Type.ADD_PLACEMENT; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAggregate.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAggregate.java index cf6d78311d..0ea675092e 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAggregate.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAggregate.java @@ -19,6 +19,7 @@ import lombok.Getter; import org.bson.BsonArray; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -49,4 +50,10 @@ public Type getMqlKind() { return Type.AGGREGATE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCount.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCount.java index e8f5549702..9c3e9d7e06 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCount.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCount.java @@ -18,6 +18,7 @@ import lombok.Getter; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -50,4 +51,10 @@ public Type getMqlKind() { return Type.COUNT; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java index 4398c12ea7..1adb1fe86c 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java @@ -19,15 +19,16 @@ import java.util.List; import java.util.stream.Collectors; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.logistic.PlacementType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -59,10 +60,16 @@ public String toString() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public @Nullable String getEntity() { + return name; + } + + + @Override + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { AdapterManager adapterManager = AdapterManager.getInstance(); - long namespaceId = context.getSnapshot().getNamespace( ((MqlQueryParameters) parameters).getNamespaceId() ).orElseThrow().id; + long namespaceId = context.getSnapshot().getNamespace( parsedQueryContext.getNamespaceId() ).orElseThrow().id; PlacementType placementType = PlacementType.AUTOMATIC; diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java index 6e448018e5..7016af4dd0 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java @@ -18,6 +18,7 @@ import org.bson.BsonArray; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.AlgCollation; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; @@ -25,11 +26,10 @@ import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; -import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -49,19 +49,14 @@ public MqlCreateView( ParserPos pos, String name, String source, BsonArray pipel @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { - Long database = ((MqlQueryParameters) parameters).getNamespaceId(); + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { + Long database = parsedQueryContext.getQueryNode().getNamespaceId(); long schemaId = context.getSnapshot().getNamespace( database ).orElseThrow().id; - Node mqlNode = statement.getTransaction() - .getProcessor( QueryLanguage.from( "mongo" ) ) - .parse( buildQuery() ) - .get( 0 ); - AlgRoot algRoot = statement.getTransaction() .getProcessor( QueryLanguage.from( "mongo" ) ) - .translate( statement, mqlNode, parameters ); + .translate( statement, parsedQueryContext ); PlacementType placementType = PlacementType.AUTOMATIC; AlgNode algNode = algRoot.alg; @@ -98,4 +93,10 @@ public Type getMqlKind() { return Type.CREATE_VIEW; } + + @Override + public @Nullable String getEntity() { + return name; + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDelete.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDelete.java index 8ec5e6888a..29d84ce7b0 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDelete.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDelete.java @@ -18,6 +18,7 @@ import lombok.Getter; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -45,4 +46,10 @@ public Type getMqlKind() { return Type.DELETE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java index 30e8771668..89cdff1c94 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.Adapter; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; @@ -25,10 +26,10 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; public class MqlDeletePlacement extends MqlCollectionStatement implements ExecutableStatement { @@ -40,10 +41,10 @@ public MqlDeletePlacement( ParserPos pos, String collection, List stores @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { AdapterManager adapterManager = AdapterManager.getInstance(); - long namespaceId = context.getSnapshot().getNamespace( ((MqlQueryParameters) parameters).getNamespaceId() ).orElseThrow().id; + long namespaceId = context.getSnapshot().getNamespace( parsedQueryContext.getQueryNode().getNamespaceId() ).orElseThrow().id; LogicalCollection collection = context.getSnapshot().doc().getCollection( namespaceId, getCollection() ).orElseThrow(); @@ -65,4 +66,10 @@ public Type getMqlKind() { return Type.DELETE_PLACEMENT; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java index ab5f5efcd2..cf2add316c 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java @@ -18,15 +18,16 @@ import java.util.List; import java.util.Optional; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -44,9 +45,9 @@ public Type getMqlKind() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager ddlManager = DdlManager.getInstance(); - Long namespaceId = ((MqlQueryParameters) parameters).getNamespaceId(); + Long namespaceId = parsedQueryContext.getQueryNode().getNamespaceId(); Optional optionalNamespace = context.getSnapshot().getNamespace( namespaceId ); if ( optionalNamespace.isEmpty() ) { @@ -63,4 +64,10 @@ public void execute( Context context, Statement statement, QueryParameters param ddlManager.dropCollection( collections.get( 0 ), statement ); } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java index 83d6699437..75cfa04665 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java @@ -19,10 +19,10 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -34,8 +34,8 @@ public MqlDropDatabase( ParserPos pos ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { - Long namespaceId = ((MqlQueryParameters) parameters).getNamespaceId(); + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { + Long namespaceId = parsedQueryContext.getQueryNode().getNamespaceId(); DdlManager.getInstance().dropNamespace( Catalog.snapshot().getNamespace( namespaceId ).orElseThrow().name, true, statement ); } @@ -46,4 +46,5 @@ public Type getMqlKind() { return Type.DROP_DATABASE; } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFind.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFind.java index dfecdea433..8ceba02be5 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFind.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFind.java @@ -18,6 +18,7 @@ import lombok.Getter; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -45,4 +46,10 @@ public Type getMqlKind() { return Type.FIND; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindAndModify.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindAndModify.java index c743e07e18..2e21ece60b 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindAndModify.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindAndModify.java @@ -19,6 +19,7 @@ import lombok.Getter; import org.bson.BsonArray; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -72,4 +73,10 @@ public Type getMqlKind() { return Type.FIND_MODIFY; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndReplace.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndReplace.java index 9e192c1758..37da8144b6 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndReplace.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndReplace.java @@ -18,6 +18,7 @@ import lombok.Getter; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -51,4 +52,10 @@ public Type getMqlKind() { return Type.FIND_REPLACE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndUpdate.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndUpdate.java index b9b1452937..fbf6706d74 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndUpdate.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlFindOneAndUpdate.java @@ -20,6 +20,7 @@ import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.BsonValue; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -68,4 +69,10 @@ public Type getMqlKind() { return Type.FIND_UPDATE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlInsert.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlInsert.java index ff5de486e9..477a10fbf6 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlInsert.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlInsert.java @@ -21,6 +21,7 @@ import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.BsonValue; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -52,4 +53,10 @@ public Type getMqlKind() { return Type.INSERT; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlNode.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlNode.java index 5936f5a349..45d0e36b38 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlNode.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlNode.java @@ -23,6 +23,7 @@ import lombok.Setter; import org.bson.BsonArray; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; @@ -31,17 +32,15 @@ import org.polypheny.db.util.Litmus; +@Getter public abstract class MqlNode implements Node { - @Getter protected final ParserPos pos; - @Getter @Setter List stores = new ArrayList<>(); @Setter - @Getter List primary = new ArrayList<>(); @@ -83,6 +82,12 @@ protected boolean getBoolean( BsonDocument document, String name ) { } + @Override + public @Nullable String getEntity() { + return null; + } + + @Override public Object clone() { return null; @@ -123,6 +128,16 @@ public boolean equalsDeep( Node node, Litmus litmus ) { @Override public Kind getKind() { + switch ( getFamily() ) { + case DCL: + return Kind.OTHER; + case DDL: + return Kind.OTHER_DDL; + case DML: + return Kind.INSERT; + case DQL: + return Kind.SELECT; + } return Kind.OTHER; } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRemove.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRemove.java index 6104955c15..92a34f1d86 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRemove.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRemove.java @@ -17,6 +17,7 @@ package org.polypheny.db.languages.mql; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -37,4 +38,10 @@ public Type getMqlKind() { return Type.REMOVE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java index ccbd54f2ac..b715c31d8c 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java @@ -16,13 +16,14 @@ package org.polypheny.db.languages.mql; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -46,8 +47,8 @@ public Type getMqlKind() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { - Long namespaceId = ((MqlQueryParameters) parameters).getNamespaceId(); + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { + Long namespaceId = parsedQueryContext.getQueryNode().getNamespaceId(); LogicalCollection collection = context.getSnapshot().doc().getCollection( namespaceId, getCollection() ).orElseThrow(); @@ -59,4 +60,10 @@ public void execute( Context context, Statement statement, QueryParameters param } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlReplace.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlReplace.java index 711f02da36..ca194b995a 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlReplace.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlReplace.java @@ -17,6 +17,7 @@ package org.polypheny.db.languages.mql; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -37,4 +38,10 @@ public Type getMqlKind() { return Type.REPLACE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlSave.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlSave.java index 57fb4f1ae8..24e2d50ab6 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlSave.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlSave.java @@ -17,6 +17,7 @@ package org.polypheny.db.languages.mql; import org.bson.BsonDocument; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -37,4 +38,10 @@ public Type getMqlKind() { return Type.SAVE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUpdate.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUpdate.java index a8a8688bf2..aa2b3883c4 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUpdate.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUpdate.java @@ -20,6 +20,7 @@ import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.BsonValue; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -68,4 +69,10 @@ public Type getMqlKind() { return Type.UPDATE; } + + @Override + public @Nullable String getEntity() { + return getCollection(); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java index a22dcd3ceb..3cdd550ae2 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java @@ -20,10 +20,10 @@ import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; @@ -40,7 +40,7 @@ public MqlUseDatabase( ParserPos pos, String database ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().createNamespace( this.database, NamespaceType.DOCUMENT, true, false ); } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java index c44b4cb102..d44928e6f7 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java @@ -73,7 +73,6 @@ import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.mql.Mql.Type; import org.polypheny.db.languages.mql.MqlAggregate; import org.polypheny.db.languages.mql.MqlCollectionStatement; @@ -81,12 +80,11 @@ import org.polypheny.db.languages.mql.MqlDelete; import org.polypheny.db.languages.mql.MqlFind; import org.polypheny.db.languages.mql.MqlInsert; -import org.polypheny.db.languages.mql.MqlQueryParameters; import org.polypheny.db.languages.mql.MqlQueryStatement; import org.polypheny.db.languages.mql.MqlUpdate; -import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; import org.polypheny.db.plan.AlgOptCluster; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexCall; import org.polypheny.db.rex.RexIndexRef; @@ -237,11 +235,11 @@ private void resetDefaults() { } - public AlgRoot convert( Node query, QueryParameters parameters ) { + public AlgRoot convert( ParsedQueryContext context ) { resetDefaults(); - this.namespaceId = ((MqlQueryParameters) parameters).getNamespaceId(); - if ( query instanceof MqlCollectionStatement ) { - return convert( (MqlCollectionStatement) query ); + this.namespaceId = context.getNamespaceId(); + if ( context.getQueryNode() instanceof MqlCollectionStatement ) { + return convert( (MqlCollectionStatement) context.getQueryNode() ); } throw new GenericRuntimeException( "DML or DQL need a collection" ); } diff --git a/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java b/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java index d7f7d987a8..e02f43c08d 100644 --- a/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java +++ b/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java @@ -19,13 +19,13 @@ import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.catalog.MockCatalogReaderDocument; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.Snapshot; -import org.polypheny.db.languages.mql.MqlQueryParameters; +import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.languages.mql2alg.MqlToAlgConverter; import org.polypheny.db.mql.mql.MqlTest; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.Contexts; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.test.MockRelOptPlanner; @@ -48,7 +48,12 @@ public abstract class Mql2AlgTest extends MqlTest { public AlgRoot translate( String mql ) { - return MQL_TO_ALG_CONVERTER.convert( parse( mql ), new MqlQueryParameters( mql, "private", NamespaceType.DOCUMENT ) ); + return MQL_TO_ALG_CONVERTER.convert( + ParsedQueryContext.builder() + .query( mql ) + .queryNode( parse( mql ) ) + .language( QueryLanguage.from( "mql" ) ) + .origin( "Mql Test" ).build() ); } } 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 9e7004dd9f..c5e3f5196f 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 @@ -43,6 +43,7 @@ import org.polypheny.db.notebooks.model.language.JupyterKernelLanguage; import org.polypheny.db.notebooks.model.language.JupyterKernelLanguage.JupyterQueryPart; import org.polypheny.db.notebooks.model.language.JupyterLanguageFactory; +import org.polypheny.db.processing.QueryContext; import org.polypheny.db.webui.crud.LanguageCrud; import org.polypheny.db.webui.models.requests.QueryRequest; import org.polypheny.db.webui.models.results.Result; @@ -249,14 +250,13 @@ public void executePolyCell( */ 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, - queryRequest, - jsm.getTransactionManager(), - Catalog.defaultUserId, - Catalog.defaultNamespaceId - ); + List> results = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( QueryLanguage.from( language ) ) + .origin( "Notebooks" ) + .transactionManager( jsm.getTransactionManager() ) + .build(), queryRequest ); return resultSetGson.toJson( results ); } diff --git a/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java b/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java index f0b224e515..453dc31861 100644 --- a/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java +++ b/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java @@ -16,32 +16,16 @@ package org.polypheny.db; -import java.util.Collections; import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.websocket.api.Session; -import org.polypheny.db.algebra.AlgRoot; -import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; -import org.polypheny.db.information.InformationManager; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; -import org.polypheny.db.nodes.Node; import org.polypheny.db.piglet.PigProcessor; import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; -import org.polypheny.db.processing.Processor; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionException; -import org.polypheny.db.transaction.TransactionManager; -import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.crud.LanguageCrud; -import org.polypheny.db.webui.models.requests.QueryRequest; -import org.polypheny.db.webui.models.results.RelationalResult; -import org.polypheny.db.webui.models.results.Result; @Slf4j public class PigLanguagePlugin extends PolyPlugin { @@ -61,97 +45,19 @@ public PigLanguagePlugin( PluginContext context ) { @Override public void start() { - PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.crud.languageCrud.addLanguage( NAME, PigLanguagePlugin::anyPigQuery ) ); - LanguageManager.getINSTANCE().addQueryLanguage( NamespaceType.RELATIONAL, NAME, List.of( NAME, "piglet" ), null, PigProcessor::new, null ); + QueryLanguage language = new QueryLanguage( NamespaceType.RELATIONAL, NAME, List.of( NAME, "piglet" ), null, PigProcessor::new, null, LanguageManager::toQueryNodes ); + LanguageManager.getINSTANCE().addQueryLanguage( language ); + PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getRelResult ) ); + } @Override public void stop() { - LanguageCrud.crud.languageCrud.removeLanguage( NAME ); + QueryLanguage language = QueryLanguage.from( NAME ); + LanguageCrud.deleteToResult( language ); LanguageManager.removeQueryLanguage( NAME ); } - public static List> anyPigQuery( - Session session, - QueryRequest request, - TransactionManager transactionManager, - long userId, - long databaseId, - Crud crud ) { - String query = request.query; - Transaction transaction = Crud.getTransaction( request.analyze, request.cache, transactionManager, userId, databaseId, "HTTP Interface Pig" ); - QueryLanguage language = QueryLanguage.from( NAME ); - - try { - if ( query.trim().isEmpty() ) { - throw new GenericRuntimeException( "PIG query is an empty string!" ); - } - - if ( log.isDebugEnabled() ) { - log.debug( "Starting to process PIG resource request. Session ID: {}.", session ); - } - - if ( request.analyze ) { - transaction.getQueryAnalyzer().setSession( session ); - } - - // This is not a nice solution. In case of a sql script with auto commit only the first statement is analyzed - // and in case of auto commit of, the information is overwritten - InformationManager queryAnalyzer = null; - if ( request.analyze ) { - queryAnalyzer = transaction.getQueryAnalyzer().observe( crud ); - } - - Statement statement = transaction.createStatement(); - - long executionTime = System.nanoTime(); - Processor processor = transaction.getProcessor( language ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Parsing" ); - } - Node parsed = processor.parse( query ).get( 0 ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Parsing" ); - } - - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().start( "Translation" ); - } - AlgRoot algRoot = processor.translate( statement, parsed, new QueryParameters( query, NamespaceType.RELATIONAL ) ); - if ( transaction.isAnalyze() ) { - statement.getOverviewDuration().stop( "Translation" ); - } - - PolyImplementation polyImplementation = statement.getQueryProcessor().prepareQuery( algRoot, true ); - - Result result = LanguageCrud.getResult( language, statement, request, query, polyImplementation, transaction, request.noLimit ); - - String commitStatus; - try { - transaction.commit(); - commitStatus = "Committed"; - } catch ( TransactionException e ) { - log.error( "Error while committing", e ); - try { - transaction.rollback(); - commitStatus = "Rolled back"; - } catch ( TransactionException ex ) { - log.error( "Caught exception while rollback", e ); - commitStatus = "Error while rolling back"; - } - } - - executionTime = System.nanoTime() - executionTime; - if ( queryAnalyzer != null ) { - Crud.attachQueryAnalyzer( queryAnalyzer, executionTime, commitStatus, 1 ); - } - - return Collections.singletonList( result ); - } catch ( Throwable t ) { - return Collections.singletonList( RelationalResult.builder().error( t.getMessage() ).query( query ).xid( transaction.getXid().toString() ).build() ); - } - } - } diff --git a/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Ast.java b/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Ast.java index f344f16a98..040b3c4d27 100644 --- a/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Ast.java +++ b/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Ast.java @@ -35,9 +35,14 @@ import com.google.common.collect.ImmutableList; +import java.math.BigDecimal; +import java.util.List; +import java.util.Objects; +import java.util.Set; import lombok.Getter; import org.apache.calcite.avatica.util.Spacer; import org.apache.calcite.linq4j.Ord; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; @@ -48,11 +53,6 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; -import java.math.BigDecimal; -import java.util.List; -import java.util.Objects; -import java.util.Set; - /** * Abstract syntax tree. @@ -172,6 +172,12 @@ protected PigNode( ParserPos pos, Op op ) { } + @Override + public @Nullable String getEntity() { + return null; + } + + @Override public Node clone( ParserPos pos ) { throw new UnsupportedOperationException( "Pig nodes cannot be cloned." ); @@ -251,6 +257,12 @@ public LoadStmt( ParserPos pos, Identifier target, Literal name ) { this.name = Objects.requireNonNull( name ); } + + @Override + public @Nullable String getEntity() { + return name.value.toString(); + } + } diff --git a/plugins/pig-language/src/main/java/org/polypheny/db/piglet/PigProcessor.java b/plugins/pig-language/src/main/java/org/polypheny/db/piglet/PigProcessor.java index fc7182d3ee..a852bed64e 100644 --- a/plugins/pig-language/src/main/java/org/polypheny/db/piglet/PigProcessor.java +++ b/plugins/pig-language/src/main/java/org/polypheny/db/piglet/PigProcessor.java @@ -32,6 +32,7 @@ import org.polypheny.db.piglet.parser.ParseException; import org.polypheny.db.piglet.parser.PigletParser; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.tools.PigAlgBuilder; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; @@ -81,9 +82,9 @@ public Pair validate( Transaction transaction, Node parsed, b @Override - public AlgRoot translate( Statement statement, Node query, QueryParameters parameters ) { + public AlgRoot translate( Statement statement, ParsedQueryContext context ) { final PigAlgBuilder builder = PigAlgBuilder.create( statement ); - new Handler( builder ).handle( (PigNode) query ); + new Handler( builder ).handle( (PigNode) context.getQueryNode() ); return AlgRoot.of( builder.build(), Kind.SELECT ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java index 3da539c36b..55e1031511 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java @@ -19,23 +19,14 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; -import java.sql.ResultSetMetaData; -import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; -import java.util.Optional; import java.util.Properties; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.calcite.avatica.util.TimeUnit; -import org.jetbrains.annotations.Nullable; -import org.polypheny.db.PolyImplementation; -import org.polypheny.db.ResultIterator; import org.polypheny.db.adapter.java.JavaTypeFactory; -import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.FunctionCategory; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.constant.Modality; @@ -43,35 +34,19 @@ import org.polypheny.db.algebra.operators.ChainedOperatorTable; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.operators.OperatorTable; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.logical.LogicalColumn; -import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.PolyphenyDbConnectionProperty; -import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.information.InformationGroup; -import org.polypheny.db.information.InformationManager; -import org.polypheny.db.information.InformationPage; -import org.polypheny.db.information.InformationStacktrace; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.languages.sql.parser.impl.SqlParserImpl; import org.polypheny.db.nodes.LangFunctionOperator; -import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; -import org.polypheny.db.processing.LanguageContext; -import org.polypheny.db.processing.Processor; -import org.polypheny.db.processing.QueryContext; -import org.polypheny.db.processing.ResultContext; import org.polypheny.db.sql.language.SqlAggFunction; import org.polypheny.db.sql.language.SqlAsOperator; import org.polypheny.db.sql.language.SqlBinaryOperator; @@ -181,25 +156,16 @@ import org.polypheny.db.sql.language.fun.SqlTranslate3Function; import org.polypheny.db.sql.language.fun.SqlTrimFunction; import org.polypheny.db.sql.language.validate.PolyphenyDbSqlValidator; -import org.polypheny.db.transaction.Statement; -import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.type.OperandCountRange; import org.polypheny.db.type.PolyOperandCountRanges; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.checker.OperandTypes; -import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.inference.InferTypes; import org.polypheny.db.type.inference.ReturnTypes; import org.polypheny.db.util.Conformance; import org.polypheny.db.util.Litmus; import org.polypheny.db.util.Optionality; -import org.polypheny.db.util.Pair; -import org.polypheny.db.webui.Crud.QueryExecutionException; -import org.polypheny.db.webui.models.SortState; -import org.polypheny.db.webui.models.catalog.UiColumnDefinition; -import org.polypheny.db.webui.models.catalog.UiColumnDefinition.UiColumnDefinitionBuilder; -import org.polypheny.db.webui.models.results.RelationalResult; +import org.polypheny.db.webui.crud.LanguageCrud; @Slf4j public class SqlLanguagePlugin extends PolyPlugin { @@ -231,13 +197,20 @@ public void stop() { public static void startup() { + // add language to general processing + QueryLanguage language = new QueryLanguage( + NamespaceType.RELATIONAL, + "sql", + List.of( "sql" ), + SqlParserImpl.FACTORY, + SqlProcessor::new, + SqlLanguagePlugin::getValidator, + LanguageManager::toQueryNodes ); + LanguageManager.getINSTANCE().addQueryLanguage( language ); PolyPluginManager.AFTER_INIT.add( () -> { - ResultIterator.addLanguage( "sql", new LanguageContext( - queries -> split( queries ), - query -> anySqlQuery( query ), - ( query, iter ) -> computeValues( query, iter ) ) ); + // add language to webui + LanguageCrud.addToResult( language, LanguageCrud::getRelResult ); } ); - LanguageManager.getINSTANCE().addQueryLanguage( NamespaceType.RELATIONAL, "sql", List.of( "sql" ), SqlParserImpl.FACTORY, SqlProcessor::new, SqlLanguagePlugin::getSqlValidator ); if ( !isInit() ) { registerOperators(); @@ -245,216 +218,7 @@ public static void startup() { } - private static List> computeValues( QueryContext query, ResultContext context ) { - LogicalTable table = null; - if ( request.entityId != null ) { - table = Catalog.snapshot().rel().getTable( request.entityId ).orElseThrow(); - } - - List header = new ArrayList<>(); - for ( AlgDataTypeField metaData : implementation.getRowType().getFields() ) { - String columnName = metaData.getName(); - - String filter = ""; - if ( request.filter != null && request.filter.containsKey( columnName ) ) { - filter = request.filter.get( columnName ); - } - - SortState sort; - if ( request.sortState != null && request.sortState.containsKey( columnName ) ) { - sort = request.sortState.get( columnName ); - } else { - sort = new SortState(); - } - - UiColumnDefinitionBuilder dbCol = UiColumnDefinition.builder() - .name( metaData.getName() ) - .dataType( metaData.getType().getPolyType().getTypeName() ) - .nullable( metaData.getType().isNullable() == (ResultSetMetaData.columnNullable == 1) ) - .precision( metaData.getType().getPrecision() ) - .sort( sort ) - .filter( filter ); - - // Get column default values - if ( table != null ) { - Optional logicalColumn = Catalog.snapshot().rel().getColumn( table.id, columnName ); - if ( logicalColumn.isPresent() ) { - if ( logicalColumn.get().defaultValue != null ) { - dbCol.defaultValue( logicalColumn.get().defaultValue.value.toJson() ); - } - } - } - header.add( dbCol.build() ); - } - - List data = computeResultData( rows, header, statement.getTransaction() ); - - return RelationalResult.builder() - .header( header.toArray( new UiColumnDefinition[0] ) ) - .data( data.toArray( new String[0][] ) ) - .namespaceType( implementation.getNamespaceType() ) - .language( QueryLanguage.from( "sql" ) ) - .affectedTuples( data.size() ) - .hasMore( hasMoreRows ); - } - - - private static @Nullable List split( QueryContext queries ) { - try { - return queries.openTransaction().getProcessor( QueryLanguage.from( "sql" ) ).splitStatements( queries.getQuery() ).stream().map( q -> new QueryContext( - q, - queries.getLanguage(), - queries.isAnalysed(), - queries.isUsesCache(), - queries.getUserId(), - queries.getOrigin(), - queries.getBatch(), - queries.getManager(), - queries.getTransaction() ) ).collect( Collectors.toList() ); - } catch ( RuntimeException e ) { - return null; - } - } - - - /** - * Run any query coming from the SQL console - */ - public static ResultContext anySqlQuery( final QueryContext context ) { - Transaction transaction = context.getTransaction(); - long executionTime = 0; - long temp = 0; - boolean noLimit; - String query = context.getQuery(); - Pattern p = Pattern.compile( ".*(COMMIT|ROLLBACK).*", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.DOTALL ); - if ( p.matcher( context.getQuery() ).matches() ) { - temp = System.nanoTime(); - boolean isCommit = Pattern.matches( "(?si:[\\s]*COMMIT.*)", query ); - try { - if ( Pattern.matches( "(?si:[\\s]*COMMIT.*)", query ) ) { - transaction.commit(); - } else { - transaction.rollback(); - } - - executionTime += System.nanoTime() - temp; - return new ResultContext( null, null, context.getQuery(), context.getLanguage(), transaction, executionTime ); - } catch ( TransactionException e ) { - log.error( String.format( "Caught exception while %s a query from the console", isCommit ? "committing" : "rolling back" ), e ); - executionTime += System.nanoTime() - temp; - log.error( e.toString() ); - } - } else if ( Pattern.matches( "(?si:^[\\s]*[/(\\s]*SELECT.*)", query ) ) { - try { - temp = System.nanoTime(); - ResultIterator iter = SqlLanguagePlugin.executeSqlSelect( transaction.createStatement(), context ); - executionTime += System.nanoTime() - temp; - return new ResultContext( iter, null, context.getQuery(), context.getLanguage(), transaction, executionTime ); - } catch ( QueryExecutionException | RuntimeException e ) { - log.error( "Caught exception while executing a query from the console", e ); - executionTime += System.nanoTime() - temp; - return new ResultContext( null, e.getCause().getMessage(), context.getQuery(), context.getLanguage(), transaction, executionTime ); - } - } - try { - temp = System.nanoTime(); - ResultIterator iterator = SqlLanguagePlugin.executeSqlUpdate( transaction.createStatement(), transaction, context ); - executionTime += System.nanoTime() - temp; - - return new ResultContext( iterator, null, context.getQuery(), context.getLanguage(), transaction, executionTime ); - } catch ( QueryExecutionException | RuntimeException e ) { - log.error( "Caught exception while executing a query from the console", e ); - executionTime += System.nanoTime() - temp; - return new ResultContext( null, e.getMessage(), context.getQuery(), context.getLanguage(), transaction, executionTime ); - } - - } - - - public static ResultIterator executeSqlSelect( final Statement statement, final QueryContext context ) throws QueryExecutionException { - PolyImplementation implementation; - boolean isAnalyze = statement.getTransaction().isAnalyze(); - - try { - implementation = processQuery( statement, context.getQuery(), isAnalyze ); - return implementation.execute( statement, context.getBatch(), isAnalyze, true, false ); - - } catch ( Throwable t ) { - if ( statement.getTransaction().isAnalyze() ) { - InformationManager analyzer = statement.getTransaction().getQueryAnalyzer(); - InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); - InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); - InformationStacktrace exceptionElement = new InformationStacktrace( t, exceptionGroup ); - analyzer.addPage( exceptionPage ); - analyzer.addGroup( exceptionGroup ); - analyzer.registerInformation( exceptionElement ); - } - throw new GenericRuntimeException( t ); - } - } - - - private static PolyImplementation processQuery( Statement statement, String sql, boolean isAnalyze ) { - PolyImplementation implementation; - if ( isAnalyze ) { - statement.getOverviewDuration().start( "Parsing" ); - } - Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); - Node parsed = sqlProcessor.parse( sql ).get( 0 ); - if ( isAnalyze ) { - statement.getOverviewDuration().stop( "Parsing" ); - } - AlgRoot logicalRoot; - QueryParameters parameters = new QueryParameters( sql, NamespaceType.RELATIONAL ); - if ( parsed.isA( Kind.DDL ) ) { - implementation = sqlProcessor.prepareDdl( statement, parsed, parameters ); - } else { - if ( isAnalyze ) { - statement.getOverviewDuration().start( "Validation" ); - } - Pair validated = sqlProcessor.validate( statement.getTransaction(), parsed, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ); - if ( isAnalyze ) { - statement.getOverviewDuration().stop( "Validation" ); - statement.getOverviewDuration().start( "Translation" ); - } - logicalRoot = sqlProcessor.translate( statement, validated.left, parameters ); - if ( isAnalyze ) { - statement.getOverviewDuration().stop( "Translation" ); - } - implementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); - } - return implementation; - } - - - private static ResultIterator executeSqlUpdate( final Statement statement, final Transaction transaction, final QueryContext context ) throws QueryExecutionException { - PolyImplementation implementation; - - try { - implementation = processQuery( statement, context.getQuery(), transaction.isAnalyze() ); - } catch ( Throwable t ) { - if ( transaction.isAnalyze() ) { - InformationManager analyzer = transaction.getQueryAnalyzer(); - InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); - InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); - InformationStacktrace exceptionElement = new InformationStacktrace( t, exceptionGroup ); - analyzer.addPage( exceptionPage ); - analyzer.addGroup( exceptionGroup ); - analyzer.registerInformation( exceptionElement ); - } - throw new GenericRuntimeException( t.getMessage(), t ); - - - } - try { - return implementation.execute( statement ); - } catch ( Exception e ) { - throw new GenericRuntimeException( e ); - } - } - - - public static PolyphenyDbSqlValidator getSqlValidator( org.polypheny.db.prepare.Context context, Snapshot snapshot ) { + public static PolyphenyDbSqlValidator getValidator( org.polypheny.db.prepare.Context context, Snapshot snapshot ) { final OperatorTable opTab0 = fun( OperatorTable.class, SqlStdOperatorTable.instance() ); final OperatorTable opTab = ChainedOperatorTable.of( opTab0, snapshot ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java index 830242baa4..47fc023cdc 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java @@ -52,6 +52,7 @@ import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.runtime.PolyphenyDbException; import org.polypheny.db.sql.language.SqlBasicCall; @@ -179,7 +180,7 @@ public Pair validate( Transaction transaction, Node parsed, b @Override - public AlgRoot translate( Statement statement, Node query, QueryParameters parameters ) { + public AlgRoot translate( Statement statement, ParsedQueryContext context ) { final StopWatch stopWatch = new StopWatch(); if ( log.isDebugEnabled() ) { log.debug( "Planning Statement ..." ); @@ -197,7 +198,7 @@ public AlgRoot translate( Statement statement, Node query, QueryParameters param .convertTableAccess( false ) .build(); final SqlToAlgConverter sqlToAlgConverter = new SqlToAlgConverter( validator, statement.getTransaction().getSnapshot(), cluster, StandardConvertletTable.INSTANCE, config ); - AlgRoot logicalRoot = sqlToAlgConverter.convertQuery( query, false, true ); + AlgRoot logicalRoot = sqlToAlgConverter.convertQuery( context.getQueryNode(), false, true ); // Decorrelate final AlgBuilder algBuilder = config.getAlgBuilderFactory().create( cluster, null ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDelete.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDelete.java index 72b3a9ec0b..bea4f44ad1 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDelete.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDelete.java @@ -18,6 +18,7 @@ import java.util.List; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -55,6 +56,12 @@ public Kind getKind() { } + @Override + public @Nullable String getEntity() { + return targetTable.getEntity(); + } + + @Override public Operator getOperator() { return OPERATOR; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlIdentifier.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlIdentifier.java index a4943b83f9..136c2b5947 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlIdentifier.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlIdentifier.java @@ -21,7 +21,9 @@ import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import lombok.Getter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.DynamicRecordType; @@ -359,6 +361,12 @@ public boolean equalsDeep( Node node, Litmus litmus ) { } + @Override + public @Nullable String getEntity() { + return names.stream().collect( Collectors.joining( "." ) ); + } + + @Override public R accept( NodeVisitor visitor ) { return visitor.visit( this ); 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 a4cf8616f0..2fb7ca7342 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 @@ -19,6 +19,7 @@ import java.util.List; import lombok.Getter; import lombok.Setter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.languages.ParserPos; @@ -61,6 +62,12 @@ public Kind getKind() { } + @Override + public @Nullable String getEntity() { + return targetTable.getEntity(); + } + + @Override public Operator getOperator() { return OPERATOR; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlMerge.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlMerge.java index 3a4241a30d..3784f7ef3a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlMerge.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlMerge.java @@ -18,6 +18,7 @@ import java.util.List; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -68,6 +69,12 @@ public Kind getKind() { } + @Override + public @Nullable String getEntity() { + return targetTable.getEntity(); + } + + @Override public List getOperandList() { return ImmutableNullableList.of( targetTable, condition, source, updateCall, insertCall, sourceSelect, alias ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlNode.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlNode.java index e90270128b..56c0cecb79 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlNode.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlNode.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Objects; import java.util.Set; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.languages.ParserPos; @@ -68,6 +69,12 @@ public Object clone() { } + @Override + public @Nullable String getEntity() { + return null; + } + + @Override public QueryLanguage getLanguage() { return QueryLanguage.from( "sql" ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSelect.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSelect.java index 892f8573fe..6b6d84f7eb 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSelect.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSelect.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -97,6 +98,12 @@ public Kind getKind() { } + @Override + public @Nullable String getEntity() { + return from.getEntity(); + } + + @Override public List getOperandList() { return ImmutableNullableList.of( keywordList, selectList, from, where, groupBy, having, windowDecls, orderBy, offset, fetch ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java index e280bbacda..7f8a02778d 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java @@ -24,12 +24,12 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Call; import org.polypheny.db.nodes.Literal; import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.validate.SqlValidator; import org.polypheny.db.sql.language.validate.SqlValidatorScope; import org.polypheny.db.transaction.Statement; @@ -213,7 +213,7 @@ public void setValue( SqlNode value ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().setOption(); } 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 911abfbb1a..8b2841d774 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 @@ -19,6 +19,7 @@ import java.util.List; import lombok.Getter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -63,6 +64,12 @@ public Kind getKind() { } + @Override + public @Nullable String getEntity() { + return targetTable.getEntity(); + } + + @Override public Operator getOperator() { return OPERATOR; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java index c61b5726b1..9bbd061f02 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java @@ -28,9 +28,9 @@ import org.polypheny.db.catalog.entity.LogicalAdapter.AdapterType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlAlter; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlOperator; @@ -91,7 +91,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { @SuppressWarnings("unchecked") Map configMap = new Gson().fromJson( removeQuotationMarks( config.toString() ), Map.class ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java index 6299983e73..3ef44336de 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlAlter; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlOperator; @@ -75,7 +75,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { try { DdlManager.getInstance().dropAdapter( uniqueName.toString(), statement ); } catch ( Exception e ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java index f5720013ac..141f56aeb3 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java @@ -25,9 +25,9 @@ import org.polypheny.db.config.Config; import org.polypheny.db.config.ConfigManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlAlter; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlOperator; @@ -81,7 +81,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { String keyStr = key.toString(); String valueStr = value.toString(); if ( keyStr.startsWith( "'" ) ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java index f480994a66..2ea99e68b3 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java @@ -28,9 +28,9 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.iface.QueryInterfaceManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlAlter; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlOperator; @@ -87,7 +87,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { String uniqueNameStr = removeQuotationMarks( uniqueName.toString() ); String clazzNameStr = removeQuotationMarks( clazzName.toString() ); Map configMap = new Gson().fromJson( removeQuotationMarks( config.toString() ), Map.class ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java index dfe9ca27b1..93260dbf50 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java @@ -26,9 +26,9 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.iface.QueryInterfaceManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlAlter; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlOperator; @@ -77,7 +77,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { String uniqueNameStr = uniqueName.toString(); if ( uniqueNameStr.startsWith( "'" ) ) { uniqueNameStr = uniqueNameStr.substring( 1 ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java index f20b3d396d..a1c1af6128 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java @@ -36,11 +36,11 @@ import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlCreate; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -107,7 +107,7 @@ public List getSqlOperandList() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { long namespaceId; String viewName; @@ -134,11 +134,17 @@ public void execute( Context context, Statement statement, QueryParameters param PlacementType placementType = !store.isEmpty() ? PlacementType.AUTOMATIC : PlacementType.MANUAL; - Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); - AlgRoot algRoot = sqlProcessor.translate( - statement, - sqlProcessor.validate( - statement.getTransaction(), this.query, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ).left, null ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Processor sqlProcessor = statement.getTransaction().getProcessor( language ); + AlgRoot algRoot = sqlProcessor.translate( statement, + ParsedQueryContext.builder() + .query( query.toString() ) + .language( language ) + .queryNode( + sqlProcessor.validate( + statement.getTransaction(), this.query, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ).left ) + .origin( statement.getTransaction().getOrigin() ) + .build() ); List columns = null; @@ -146,9 +152,9 @@ public void execute( Context context, Statement statement, QueryParameters param columns = getColumnInfo(); } - MaterializedCriteria materializedCriteria; - // Depending on the freshness type different information is needed + MaterializedCriteria materializedCriteria = new MaterializedCriteria(); + if ( freshnessType != null ) { switch ( freshnessType ) { case "UPDATE": @@ -160,12 +166,7 @@ public void execute( Context context, Statement statement, QueryParameters param case "MANUAL": materializedCriteria = new MaterializedCriteria( CriteriaType.MANUAL ); break; - default: - materializedCriteria = new MaterializedCriteria(); - break; } - } else { - materializedCriteria = new MaterializedCriteria(); } boolean ordered = query.getKind().belongsTo( Kind.ORDER ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java index da75bbad7e..468057d845 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java @@ -23,10 +23,10 @@ import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlCreate; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -86,7 +86,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().createNamespace( name.getSimple(), type, ifNotExists, replace ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java index 56075651de..1255181a8e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java @@ -36,12 +36,12 @@ import org.polypheny.db.ddl.DdlManager.FieldInformation; import org.polypheny.db.ddl.DdlManager.PartitionInformation; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Identifier; import org.polypheny.db.nodes.Node; import org.polypheny.db.partition.raw.RawPartitionInformation; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlCreate; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlLiteral; @@ -191,7 +191,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { if ( query != null ) { throw new GenericRuntimeException( "Not yet supported" ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java index e3fca87398..a1d9f9c890 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java @@ -22,10 +22,10 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlCreate; import org.polypheny.db.sql.language.SqlDataTypeSpec; import org.polypheny.db.sql.language.SqlIdentifier; @@ -62,7 +62,7 @@ public class SqlCreateType extends SqlCreate implements ExecutableStatement { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().createType(); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java index 38974d8127..7bb2f1dd1f 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java @@ -34,11 +34,11 @@ import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlCreate; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -96,7 +96,7 @@ public List getSqlOperandList() { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { String viewName; long namespaceId; @@ -112,10 +112,17 @@ public void execute( Context context, Statement statement, QueryParameters param PlacementType placementType = PlacementType.AUTOMATIC; - Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); - AlgRoot algRoot = sqlProcessor.translate( - statement, - sqlProcessor.validate( statement.getTransaction(), this.query, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ).left, null ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Processor sqlProcessor = statement.getTransaction().getProcessor( language ); + AlgRoot algRoot = sqlProcessor.translate( statement, + ParsedQueryContext.builder() + .query( query.toString() ) + .language( language ) + .queryNode( + sqlProcessor.validate( + statement.getTransaction(), this.query, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ).left ) + .origin( statement.getTransaction().getOrigin() ) + .build() ); AlgNode algNode = algRoot.alg; AlgCollation algCollation = algRoot.collation; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java index 160de7d62a..982a78c0ce 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java @@ -20,8 +20,8 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; @@ -45,7 +45,7 @@ public SqlDropFunction( ParserPos pos, boolean ifExists, SqlIdentifier name ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().dropFunction(); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java index d480a123c7..523ee5d960 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java @@ -23,8 +23,8 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; @@ -45,7 +45,7 @@ public class SqlDropMaterializedView extends SqlDropObject { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { final Optional table = searchEntity( context, name ); if ( table.isEmpty() ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java index 9d01c75b2e..30f4750541 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java @@ -22,10 +22,10 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlDrop; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -77,7 +77,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().dropNamespace( name.getSimple(), ifExists, statement ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java index 2971b0ee36..7fafca89ff 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java @@ -23,8 +23,8 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; @@ -48,7 +48,7 @@ public class SqlDropTable extends SqlDropObject { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { final Optional table = searchEntity( context, name ); if ( table.isEmpty() ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java index 4023a5034f..ec703343c3 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java @@ -20,8 +20,8 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; @@ -42,7 +42,7 @@ public class SqlDropType extends SqlDropObject { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().dropType(); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java index 11db418ce6..9bf43c8b4c 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java @@ -24,8 +24,8 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; @@ -49,7 +49,7 @@ public class SqlDropView extends SqlDropObject { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { final Optional table = searchEntity( context, name ); if ( table.isEmpty() ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java index c3f8b11632..46df63d76e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java @@ -23,10 +23,10 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlDdl; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -76,7 +76,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, name ); DdlManager.getInstance().truncate( table, statement ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java index b1568ff972..8f989354a0 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java @@ -29,9 +29,9 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -111,7 +111,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable catalogTable = getTableFailOnEmpty( context, table ); String indexMethodName = indexMethod != null ? indexMethod.getSimple() : null; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java index 4ac0f312e8..86109f4d9a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java @@ -23,9 +23,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -71,7 +71,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); if ( table.entityType != EntityType.MATERIALIZED_VIEW ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java index 08780a2a3e..3298cf803a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java @@ -22,9 +22,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -66,7 +66,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, name ); if ( table.entityType != EntityType.MATERIALIZED_VIEW ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java index b4d9ba5141..20d56d64d2 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java @@ -23,9 +23,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -74,7 +74,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable catalogTable = getTableFailOnEmpty( context, oldName ); if ( catalogTable.entityType != EntityType.MATERIALIZED_VIEW ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java index d3879acd78..5e8e752e83 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java @@ -23,9 +23,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -75,7 +75,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, materializedView ); if ( table.entityType != EntityType.MATERIALIZED_VIEW ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java index a2aa3f177e..4bc50ce732 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java @@ -20,9 +20,9 @@ import java.util.List; import java.util.Objects; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -74,7 +74,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { throw new UnsupportedOperationException( "This functionality is not yet supported." ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java index 1e3acbef14..d598c86e13 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java @@ -21,9 +21,9 @@ import java.util.Objects; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -72,7 +72,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { DdlManager.getInstance().renameNamespace( newName.getSimple(), currentName.getSimple() ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java index 84da248d82..500c660f34 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java @@ -25,9 +25,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlLiteral; import org.polypheny.db.sql.language.SqlNode; @@ -106,7 +106,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.SOURCE ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java index 7ca68a718b..5d11fb0de7 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java @@ -27,9 +27,9 @@ import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.ddl.DdlManager.ColumnTypeInformation; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlDataTypeSpec; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlLiteral; @@ -116,7 +116,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java index 9ed1b9769f..861e51de8d 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.logistic.ForeignKeyOption; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -98,7 +98,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); LogicalTable refTable = getTableFailOnEmpty( context, referencesTable ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java index 58661a6e31..ee36d8d4eb 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java @@ -29,9 +29,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -112,7 +112,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY && logicalTable.entityType != EntityType.MATERIALIZED_VIEW ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java index bf44c14c9a..76ecb7c52d 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java @@ -29,11 +29,11 @@ import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.ddl.DdlManager.PartitionInformation; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Identifier; import org.polypheny.db.nodes.Node; import org.polypheny.db.partition.raw.RawPartitionInformation; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -135,7 +135,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); if ( table.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java index 74ba6e5137..e8ba8d357a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java @@ -29,9 +29,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -113,7 +113,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); DataStore storeInstance = getDataStoreInstance( storeName ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java index 2c200b99ab..57125f3c02 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java @@ -25,9 +25,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -78,7 +78,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java index 4e6e06aaa6..403c68eed6 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java @@ -25,9 +25,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -85,7 +85,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java index 29cfd32acc..79160bd059 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -75,7 +75,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY && logicalTable.entityType != EntityType.SOURCE ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java index 199a223cc5..5a9ee34ca6 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -75,7 +75,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java index 1ed8538486..76e2b85081 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java @@ -22,9 +22,9 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -74,7 +74,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); DdlManager.getInstance().dropForeignKey( logicalTable, foreignKeyName.getSimple() ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java index 578ba56e37..047bd48dcc 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -75,7 +75,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY && logicalTable.entityType != EntityType.MATERIALIZED_VIEW ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java index 106645c85b..50edc7d9d9 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java @@ -25,9 +25,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -78,7 +78,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); DataStore store = getDataStoreInstance( storeName ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java index 763a7057c2..0f0e491127 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -73,7 +73,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java index fc20c16ceb..ee36d9cefb 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java @@ -26,9 +26,9 @@ import org.polypheny.db.catalog.logistic.PartitionType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -76,7 +76,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); if ( table.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java index 93d9fc0a9a..c3fed9b39e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java @@ -26,9 +26,9 @@ import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.ddl.DdlManager.ColumnTypeInformation; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlDataTypeSpec; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlLiteral; @@ -139,7 +139,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, tableName ); if ( table.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java index 26530ebc68..0065fb13ba 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java @@ -35,9 +35,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -99,7 +99,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { Catalog catalog = Catalog.getInstance(); LogicalTable table = getTableFailOnEmpty( context, this.table ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java index bbc304eea5..9293dd2e84 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java @@ -31,9 +31,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlNodeList; @@ -116,7 +116,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); if ( table.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java index 3c34b9689f..5535760dcf 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java @@ -26,9 +26,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -88,7 +88,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); DataStore store = getDataStoreInstance( storeName ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java index db72088620..b2d4012210 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java @@ -26,9 +26,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -84,7 +84,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, this.table ); DataStore store = getDataStoreInstance( storeName ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java index 83e0f17172..36a30ed60e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java @@ -24,9 +24,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -75,7 +75,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); if ( logicalTable.entityType != EntityType.ENTITY ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java index ac8834e653..ba9e514082 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java @@ -23,9 +23,9 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -74,7 +74,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, oldName ); if ( newName.names.size() != 1 ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java index cecccc0824..ef4d301b49 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java @@ -22,9 +22,9 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -77,7 +77,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable logicalTable = getTableFailOnEmpty( context, table ); DdlManager.getInstance().renameColumn( logicalTable, columnOldName.getSimple(), columnNewName.getSimple(), statement ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java index 2118ee0226..fdced02adb 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java @@ -23,9 +23,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -76,7 +76,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, oldName ); if ( table.entityType != EntityType.VIEW ) { 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 dbd5b23730..bfb3f6a634 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 @@ -23,9 +23,9 @@ import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWriter; @@ -74,7 +74,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override - public void execute( Context context, Statement statement, QueryParameters parameters ) { + public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { LogicalTable table = getTableFailOnEmpty( context, view ); if ( table.entityType != EntityType.VIEW ) { diff --git a/settings.gradle b/settings.gradle index 3375fb99a7..8ceb2ed496 100644 --- a/settings.gradle +++ b/settings.gradle @@ -47,7 +47,6 @@ include 'plugins:google-sheet-adapter' include 'plugins:excel-adapter' // other plugins -include 'plugins:explore-by-example' include 'plugins:notebooks' // disabled adapter plugins diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index f0bab50527..4526ecdcc7 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -32,7 +32,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -42,7 +41,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.sql.ResultSetMetaData; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -71,7 +69,6 @@ import javax.servlet.http.Part; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.apache.calcite.avatica.remote.AvaticaRuntimeException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.eclipse.jetty.websocket.api.Session; @@ -143,12 +140,10 @@ import org.polypheny.db.information.InformationManager; import org.polypheny.db.information.InformationObserver; import org.polypheny.db.information.InformationPage; -import org.polypheny.db.information.InformationStacktrace; import org.polypheny.db.information.InformationText; +import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.QueryParameters; import org.polypheny.db.monitoring.events.StatementEvent; -import org.polypheny.db.nodes.Node; import org.polypheny.db.partition.PartitionFunctionInfo; import org.polypheny.db.partition.PartitionFunctionInfo.PartitionFunctionInfoColumn; import org.polypheny.db.partition.PartitionManager; @@ -156,7 +151,8 @@ import org.polypheny.db.partition.properties.PartitionProperty; import org.polypheny.db.plugins.PolyPluginManager; import org.polypheny.db.plugins.PolyPluginManager.PluginStatus; -import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.ImplementationContext; +import org.polypheny.db.processing.ImplementationContext.ExecutedContext; import org.polypheny.db.processing.QueryContext; import org.polypheny.db.security.SecurityManager; import org.polypheny.db.transaction.Statement; @@ -168,6 +164,7 @@ import org.polypheny.db.type.PolyTypeFamily; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.category.PolyBlob; +import org.polypheny.db.type.entity.category.PolyNumber; import org.polypheny.db.util.BsonUtil; import org.polypheny.db.util.FileInputHandle; import org.polypheny.db.util.Pair; @@ -175,6 +172,7 @@ import org.polypheny.db.webui.auth.AuthCrud; import org.polypheny.db.webui.crud.CatalogCrud; import org.polypheny.db.webui.crud.LanguageCrud; +import org.polypheny.db.webui.crud.LanguageCrud.TriFunction; import org.polypheny.db.webui.crud.StatisticCrud; import org.polypheny.db.webui.models.DbTable; import org.polypheny.db.webui.models.ForeignKey; @@ -200,7 +198,6 @@ import org.polypheny.db.webui.models.catalog.PolyTypeModel; import org.polypheny.db.webui.models.catalog.SnapshotModel; import org.polypheny.db.webui.models.catalog.UiColumnDefinition; -import org.polypheny.db.webui.models.catalog.UiColumnDefinition.UiColumnDefinitionBuilder; import org.polypheny.db.webui.models.requests.AlgRequest; import org.polypheny.db.webui.models.requests.BatchUpdateRequest; import org.polypheny.db.webui.models.requests.BatchUpdateRequest.Update; @@ -209,10 +206,11 @@ import org.polypheny.db.webui.models.requests.EditTableRequest; import org.polypheny.db.webui.models.requests.PartitioningRequest; import org.polypheny.db.webui.models.requests.PartitioningRequest.ModifyPartitionRequest; -import org.polypheny.db.webui.models.requests.QueryRequest; import org.polypheny.db.webui.models.requests.UIRequest; import org.polypheny.db.webui.models.results.RelationalResult; import org.polypheny.db.webui.models.results.RelationalResult.RelationalResultBuilder; +import org.polypheny.db.webui.models.results.Result; +import org.polypheny.db.webui.models.results.Result.ResultBuilder; import org.polypheny.db.webui.models.results.ResultType; @@ -221,6 +219,7 @@ public class Crud implements InformationObserver, PropertyChangeListener { private static final Gson gson = new Gson(); + public static final String ORIGIN = "Polypheny-UI"; private final TransactionManager transactionManager; public final LanguageCrud languageCrud; @@ -268,6 +267,7 @@ public static void cleanupOldSession( ConcurrentHashMap> ses RelationalResult getTable( final UIRequest request ) { Transaction transaction = getTransaction(); RelationalResultBuilder resultBuilder; + QueryLanguage language = QueryLanguage.from( "sql" ); StringBuilder query = new StringBuilder(); String where = ""; @@ -284,30 +284,19 @@ RelationalResult getTable( final UIRequest request ) { .append( fullTableName ) .append( where ) .append( orderBy ); - if ( false && !request.noLimit ) { - query.append( " LIMIT " ) - .append( getPageSize() ) - .append( " OFFSET " ) - .append( (Math.max( 0, request.currentPage - 1 )) * getPageSize() ); - } - try { - resultBuilder = executeSqlSelect( transaction.createStatement(), request, query.toString(), request.noLimit, this ); - resultBuilder.xid( transaction.getXid().toString() ); - } catch ( Exception e ) { - if ( request.filter != null ) { - resultBuilder = RelationalResult.builder().error( "Error while filtering table " + request.entityId ); - } else { - resultBuilder = RelationalResult.builder().error( "Could not fetch table " + request.entityId ); - log.error( "Caught exception while fetching a table", e ); - } - try { - transaction.rollback(); - return resultBuilder.build(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } + TriFunction> builder = LanguageCrud.getToResult( language ); + + Statement statement = transaction.createStatement(); + ImplementationContext implementationContext = LanguageManager.getINSTANCE().anyPrepareQuery( + QueryContext.builder() + .query( query.toString() ) + .language( language ) + .origin( transaction.getOrigin() ) + .batch( request.noLimit ? -1 : getPageSize() ) + .transactionManager( transactionManager ) + .build(), statement ).get( 0 ); + resultBuilder = (RelationalResultBuilder) builder.apply( implementationContext.execute( statement ), request, statement );//.executeSqlSelect( transaction.createStatement(), request, query.toString(), request.noLimit, this ); // determine if it is a view or a table LogicalTable table = Catalog.snapshot().rel().getTable( request.entityId ).orElseThrow(); @@ -348,7 +337,7 @@ RelationalResult getTable( final UIRequest request ) { resultBuilder.header( cols.toArray( new UiColumnDefinition[0] ) ); resultBuilder.currentPage( request.currentPage ).table( table.name ); - int tableSize = 0; + long tableSize = 0; try { tableSize = getTableSize( transaction, request ); } catch ( Exception e ) { @@ -401,20 +390,15 @@ void getEntities( final Context ctx ) { void renameTable( final Context ctx ) { IndexModel table = ctx.bodyAsClass( IndexModel.class ); String query = String.format( "ALTER TABLE \"%s\".\"%s\" RENAME TO \"%s\"", table.getNamespaceId(), table.getEntityId(), table.getName() ); - Transaction transaction = getTransaction(); - RelationalResult result; - try { - int rows = executeSqlUpdate( transaction, query ); - result = RelationalResult.builder().affectedTuples( rows ).query( query ).build(); - transaction.commit(); - } catch ( QueryExecutionException | TransactionException e ) { - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( result ); } @@ -424,8 +408,7 @@ void renameTable( final Context ctx ) { */ void dropTruncateTable( final Context ctx ) { EditTableRequest request = ctx.bodyAsClass( EditTableRequest.class ); - Transaction transaction = getTransaction(); - RelationalResult result; + StringBuilder query = new StringBuilder(); if ( request.tableType != null && request.action.equalsIgnoreCase( "drop" ) && request.tableType == EntityType.VIEW ) { query.append( "DROP VIEW " ); @@ -439,23 +422,15 @@ void dropTruncateTable( final Context ctx ) { String fullTableName = String.format( "\"%s\".\"%s\"", namespaceTable.left.name, namespaceTable.right.name ); query.append( fullTableName ); - try { - int updates = executeSqlUpdate( transaction, query.toString() ); - result = RelationalResult.builder() - .affectedTuples( updates ) - .query( query.toString() ) - .table( fullTableName ) - .build(); - transaction.commit(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while dropping or truncating a table", e ); - result = RelationalResult.builder().error( e.getMessage() ).query( query.toString() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query.toString() ) + .language( language ) + .userId( Catalog.defaultUserId ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); ctx.json( result ); } @@ -489,7 +464,7 @@ private String getFullEntityName( long entityId ) { */ void createTable( final Context ctx ) { EditTableRequest request = ctx.bodyAsClass( EditTableRequest.class ); - Transaction transaction = getTransaction(); + StringBuilder query = new StringBuilder(); StringJoiner colJoiner = new StringJoiner( "," ); LogicalNamespace namespace = getNamespace( request ); @@ -497,7 +472,7 @@ void createTable( final Context ctx ) { String fullTableName = String.format( "\"%s\".\"%s\"", namespace.name, request.entityName ); query.append( "CREATE TABLE " ).append( fullTableName ).append( "(" ); StringBuilder colBuilder; - RelationalResult result; + StringJoiner primaryKeys = new StringJoiner( ",", "PRIMARY KEY (", ")" ); int primaryCounter = 0; for ( UiColumnDefinition col : request.columns ) { @@ -554,20 +529,14 @@ void createTable( final Context ctx ) { LogicalAdapter adapter = Catalog.snapshot().getAdapter( request.storeId ).orElseThrow(); query.append( String.format( " ON STORE \"%s\"", adapter.uniqueName ) ); } - - try { - int a = executeSqlUpdate( transaction, query.toString() ); - result = RelationalResult.builder().affectedTuples( a ).query( query.toString() ).build(); - transaction.commit(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while creating a table", e ); - result = RelationalResult.builder().error( e.getMessage() ).query( query.toString() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback CREATE TABLE statement: {}", ex.getMessage(), ex ); - } - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query.toString() ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); ctx.json( result ); } @@ -645,27 +614,24 @@ void insertTuple( final Context ctx ) throws IOException { } String query = String.format( "INSERT INTO %s %s VALUES %s", entityName, columns, values ); - try { - int numRows = executeSqlUpdate( statement, transaction, query ); - transaction.commit(); - ctx.json( RelationalResult.builder().affectedTuples( numRows ).query( query ).build() ); - } catch ( Exception | TransactionException e ) { - log.info( "Generated query: {}", query ); - log.error( "Could not insert row", e ); - try { - transaction.rollback(); - } catch ( TransactionException e2 ) { - log.error( "Caught error while rolling back transaction", e2 ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).query( query ).build() ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + QueryContext context = QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(); + + Result result = LanguageCrud.anyQueryResult( context, new UIRequest() ).get( 0 );//executeSqlUpdate( statement, transaction, query ); + ctx.json( result ); + } /** * Run any query coming from the SQL console */ - public static List anySqlQuery( final QueryRequest request, final Session session, Crud crud ) { + /*public static List anySqlQuery( final QueryRequest request, final Session session, Crud crud ) { Transaction transaction = getTransaction( request.analyze, request.cache, crud ); if ( request.analyze ) { @@ -807,9 +773,7 @@ public static List anySqlQuery( final QueryRequest request, fi } return results; - } - - + }*/ public static void attachQueryAnalyzer( InformationManager queryAnalyzer, long executionTime, String commitStatus, int numberOfQueries ) { InformationPage p1 = new InformationPage( "Transaction", "Analysis of the transaction." ); queryAnalyzer.addPage( p1 ); @@ -821,7 +785,6 @@ public static void attachQueryAnalyzer( InformationManager queryAnalyzer, long e } else { long millis = TimeUnit.MILLISECONDS.convert( executionTime, TimeUnit.NANOSECONDS ); // format time: see: https://stackoverflow.com/questions/625433/how-to-convert-milliseconds-to-x-mins-x-seconds-in-java#answer-625444 - //noinspection SuspiciousDateFormat DateFormat df = new SimpleDateFormat( "m 'min' s 'sec' S 'ms'" ); String durationText = df.format( new Date( millis ) ); text1 = new InformationText( g1, String.format( "Execution time: %s", durationText ) ); @@ -902,29 +865,24 @@ private String computeWherePK( final LogicalTable table, final Map result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query.toString() ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( numOfRows ).build(); - } catch ( TransactionException | Exception e ) { - log.error( "Caught exception while deleting a row", e ); - result = RelationalResult.builder().error( e.getMessage() ).query( builder.toString() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } + if ( result.error == null && statisticCrud.isActiveTracking() ) { + transaction.addChangedTable( tableId ); } ctx.json( result ); } @@ -973,36 +931,23 @@ void updateTuple( final Context ctx ) throws ServletException, IOException { } } - StringBuilder builder = new StringBuilder(); - builder - .append( "UPDATE " ) - .append( fullName ) - .append( " SET " ) - .append( setStatements ) - .append( computeWherePK( Catalog.snapshot().rel().getTable( logicalColumns.get( 0 ).tableId ).orElseThrow(), oldValues ) ); + String query = "UPDATE " + + fullName + + " SET " + + setStatements + + computeWherePK( Catalog.snapshot().rel().getTable( logicalColumns.get( 0 ).tableId ).orElseThrow(), oldValues ); - RelationalResult result; - try { - int numOfTuples = executeSqlUpdate( statement, transaction, builder.toString() ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); - if ( numOfTuples == 1 ) { - if ( statisticCrud.isActiveTracking() ) { - transaction.addChangedTable( fullName ); - } - transaction.commit(); - result = RelationalResult.builder().affectedTuples( numOfTuples ).build(); - } else { - transaction.rollback(); - result = RelationalResult.builder().error( "Attempt to update " + numOfTuples + " tuples was blocked." ).query( builder.toString() ).build(); - } - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while updating a row", e ); - result = RelationalResult.builder().error( e.getMessage() ).query( builder.toString() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } + if ( result.error == null && result.data.length == 1 && statisticCrud.isActiveTracking() ) { + transaction.addChangedTable( fullName ); } ctx.json( result ); } @@ -1018,25 +963,21 @@ void batchUpdate( final Context ctx ) throws ServletException, IOException { Transaction transaction = getTransaction(); Statement statement; - int totalRows = 0; - try { - for ( Update update : request.updates ) { - statement = transaction.createStatement(); - String query = update.getQuery( request.tableId, statement, ctx.req ); - totalRows += executeSqlUpdate( statement, transaction, query ); - } - transaction.commit(); - ctx.json( RelationalResult.builder().affectedTuples( totalRows ).build() ); - } catch ( IOException | QueryExecutionException | TransactionException e ) { - try { - transaction.rollback(); - } catch ( TransactionException transactionException ) { - log.error( "Could not rollback", e ); - ctx.status( 500 ).json( RelationalResult.builder().error( e.getMessage() ).build() ); - } - log.error( "The batch update failed", e ); - ctx.status( 500 ).json( RelationalResult.builder().error( e.getMessage() ).build() ); + QueryLanguage language = QueryLanguage.from( "sql" ); + List> results = new ArrayList<>(); + for ( Update update : request.updates ) { + statement = transaction.createStatement(); + String query = update.getQuery( request.tableId, statement, ctx.req ); + + results.add( LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ) ); } + ctx.json( results ); } @@ -1224,8 +1165,7 @@ private LogicalTable getLogicalTable( String namespace, String table ) { void updateMaterialized( final Context ctx ) { UIRequest request = ctx.bodyAsClass( UIRequest.class ); - Transaction transaction = getTransaction(); - RelationalResult result; + List queries = new ArrayList<>(); StringBuilder sBuilder = new StringBuilder(); @@ -1234,35 +1174,28 @@ void updateMaterialized( final Context ctx ) { String query = String.format( "ALTER MATERIALIZED VIEW %s FRESHNESS MANUAL", tableId ); queries.add( query ); - result = RelationalResult.builder().affectedTuples( 1 ).query( queries.toString() ).build(); - try { - for ( String q : queries ) { - sBuilder.append( q ); - executeSqlUpdate( transaction, q ); - } - transaction.commit(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while updating a column", e ); - result = RelationalResult.builder().error( e.getMessage() ).affectedTuples( 0 ).query( sBuilder.toString() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException e2 ) { - log.error( "Caught exception during rollback", e2 ); - result = RelationalResult.builder().error( e2.getMessage() ).affectedTuples( 0 ).query( sBuilder.toString() ).build(); - } - } + for ( String q : queries ) { + sBuilder.append( q ); - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( result ); + + } } void updateColumn( final Context ctx ) { ColumnRequest request = ctx.bodyAsClass( ColumnRequest.class ); - Transaction transaction = getTransaction(); UiColumnDefinition oldColumn = request.oldColumn; UiColumnDefinition newColumn = request.newColumn; - RelationalResult result; List queries = new ArrayList<>(); StringBuilder sBuilder = new StringBuilder(); @@ -1343,7 +1276,7 @@ void updateColumn( final Context ctx ) { case "TINYINT": String defaultValue = request.newColumn.defaultValue.replace( ",", "." ); BigDecimal b = new BigDecimal( defaultValue ); - query = query + b.toString(); + query = query + b; break; case "VARCHAR": query = query + String.format( "'%s'", request.newColumn.defaultValue ); @@ -1357,25 +1290,20 @@ void updateColumn( final Context ctx ) { } } - result = RelationalResult.builder().affectedTuples( 1 ).query( queries.toString() ).build(); - try { - for ( String query : queries ) { - sBuilder.append( query ); - executeSqlUpdate( transaction, query ); - } - transaction.commit(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while updating a column", e ); - result = RelationalResult.builder().error( e.getMessage() ).affectedTuples( 0 ).query( sBuilder.toString() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException e2 ) { - log.error( "Caught exception during rollback", e2 ); - result = RelationalResult.builder().error( e2.getMessage() ).affectedTuples( 0 ).query( sBuilder.toString() ).build(); - } + for ( String query : queries ) { + sBuilder.append( query ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( result ); } - ctx.json( result ); + } @@ -1384,7 +1312,6 @@ void updateColumn( final Context ctx ) { */ void addColumn( final Context ctx ) { ColumnRequest request = ctx.bodyAsClass( ColumnRequest.class ); - Transaction transaction = getTransaction(); String tableId = getFullEntityName( request.entityId ); @@ -1405,7 +1332,7 @@ void addColumn( final Context ctx ) { } query = query + ")"; } - if ( !request.newColumn.collectionsType.isEmpty() ) { + if ( request.newColumn.collectionsType != null && !request.newColumn.collectionsType.isEmpty() ) { query = query + " " + request.newColumn.collectionsType; int dimension = request.newColumn.dimension == null ? -1 : request.newColumn.dimension; int cardinality = request.newColumn.cardinality == null ? -1 : request.newColumn.cardinality; @@ -1444,21 +1371,15 @@ void addColumn( final Context ctx ) { } } } - RelationalResult result; - try { - int affectedTuples = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( affectedTuples ).query( query ).build(); - } catch ( TransactionException | QueryExecutionException e ) { - log.error( "Caught exception while adding a column", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -1467,26 +1388,18 @@ void addColumn( final Context ctx ) { */ void dropColumn( final Context ctx ) { ColumnRequest request = ctx.bodyAsClass( ColumnRequest.class ); - Transaction transaction = getTransaction(); String tableId = getFullEntityName( request.entityId ); - - RelationalResult result; String query = String.format( "ALTER TABLE %s DROP COLUMN \"%s\"", tableId, request.oldColumn.name ); - try { - int affectedTuples = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( affectedTuples ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while dropping a column", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -1554,7 +1467,6 @@ void getConstraints( final Context ctx ) { void dropConstraint( final Context ctx ) { ConstraintRequest request = ctx.bodyAsClass( ConstraintRequest.class ); - Transaction transaction = getTransaction(); String[] t = request.table.split( "\\." ); String tableId = String.format( "\"%s\".\"%s\"", t[0], t[1] ); @@ -1567,21 +1479,15 @@ void dropConstraint( final Context ctx ) { } else { query = String.format( "ALTER TABLE %s DROP CONSTRAINT \"%s\"", tableId, request.constraint.name ); } - RelationalResult result; - try { - int rows = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( rows ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while dropping a constraint", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -1590,7 +1496,6 @@ void dropConstraint( final Context ctx ) { */ void addPrimaryKey( final Context ctx ) { ConstraintRequest request = ctx.bodyAsClass( ConstraintRequest.class ); - Transaction transaction = getTransaction(); String[] t = request.table.split( "\\." ); String tableId = String.format( "\"%s\".\"%s\"", t[0], t[1] ); @@ -1606,21 +1511,16 @@ void addPrimaryKey( final Context ctx ) { joiner.add( "\"" + s + "\"" ); } String query = "ALTER TABLE " + tableId + " ADD PRIMARY KEY " + joiner; - try { - int rows = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( rows ).query( query ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while adding a primary key", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); - ctx.json( result ); + ctx.json( res ); } @@ -1629,31 +1529,25 @@ void addPrimaryKey( final Context ctx ) { */ void addUniqueConstraint( final Context ctx ) { ConstraintRequest request = ctx.bodyAsClass( ConstraintRequest.class ); - Transaction transaction = getTransaction(); String[] t = request.table.split( "\\." ); String tableId = String.format( "\"%s\".\"%s\"", t[0], t[1] ); - RelationalResult result; + Result result; if ( request.constraint.columns.length > 0 ) { StringJoiner joiner = new StringJoiner( ",", "(", ")" ); for ( String s : request.constraint.columns ) { joiner.add( "\"" + s + "\"" ); } - String query = "ALTER TABLE " + tableId + " ADD CONSTRAINT \"" + request.constraint.name + "\" UNIQUE " + joiner.toString(); - try { - int rows = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( rows ).query( query ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while adding a unique constraint", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } + String query = "ALTER TABLE " + tableId + " ADD CONSTRAINT \"" + request.constraint.name + "\" UNIQUE " + joiner; + QueryLanguage language = QueryLanguage.from( "sql" ); + result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); } else { result = RelationalResult.builder().error( "Cannot add unique constraint if no columns are provided." ).build(); } @@ -1725,30 +1619,21 @@ void getIndexes( final Context ctx ) { /** * Drop an index of a table - * - * @param ctx */ void dropIndex( final Context ctx ) { IndexModel index = ctx.bodyAsClass( IndexModel.class ); - Transaction transaction = getTransaction(); String tableName = getFullEntityName( index.entityId ); String query = String.format( "ALTER TABLE %s DROP INDEX \"%s\"", tableName, index.getName() ); - RelationalResult result; - try { - int a = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( a ).query( query ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while dropping an index", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -1757,13 +1642,11 @@ void dropIndex( final Context ctx ) { */ void createIndex( final Context ctx ) { IndexModel index = ctx.bodyAsClass( IndexModel.class ); - Transaction transaction = getTransaction(); LogicalNamespace namespace = Catalog.snapshot().getNamespace( index.namespaceId ).orElseThrow(); LogicalTable table = Catalog.snapshot().rel().getTable( index.entityId ).orElseThrow(); String tableId = String.format( "\"%s\".\"%s\"", namespace.name, table.name ); - RelationalResult result; StringJoiner colJoiner = new StringJoiner( ",", "(", ")" ); for ( long col : index.columnIds ) { colJoiner.add( "\"" + Catalog.snapshot().rel().getColumn( col ).orElseThrow().name + "\"" ); @@ -1775,20 +1658,15 @@ void createIndex( final Context ctx ) { String onStore = String.format( "ON STORE \"%s\"", store ); String query = String.format( "ALTER TABLE %s ADD INDEX \"%s\" ON %s USING \"%s\" %s", tableId, index.getName(), colJoiner, index.getMethod(), onStore ); - try { - int a = executeSqlUpdate( transaction, query ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( a ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while creating an index", e ); - result = RelationalResult.builder().error( e.getMessage() ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -1876,20 +1754,15 @@ void addDropPlacement( final Context ctx ) { index.getMethod().toUpperCase(), columnListStr, index.getStoreUniqueName() ); - Transaction transaction = getTransaction(); - int affectedTuples = 0; - try { - affectedTuples = executeSqlUpdate( transaction, query ); - transaction.commit(); - } catch ( QueryExecutionException | TransactionException e ) { - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).build() ); - } - ctx.json( RelationalResult.builder().affectedTuples( affectedTuples ).query( query ).build() ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -2043,42 +1916,32 @@ void partitionTable( final Context ctx ) { //Changes to extensions to this model now have to be made on two parts String query = String.format( "ALTER TABLE \"%s\".\"%s\" PARTITION BY %s (\"%s\") %s ", - request.schemaName, request.tableName, request.functionName, request.partitionColumnName, content.toString() ); - - Transaction trx = getTransaction(); - try { - int i = executeSqlUpdate( trx, query ); - trx.commit(); - ctx.json( RelationalResult.builder().affectedTuples( i ).query( query ).build() ); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Could not partition table", e ); - try { - trx.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).query( query ).build() ); - } + request.schemaName, request.tableName, request.functionName, request.partitionColumnName, content ); + + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } void mergePartitions( final Context ctx ) { PartitioningRequest request = ctx.bodyAsClass( PartitioningRequest.class ); String query = String.format( "ALTER TABLE \"%s\".\"%s\" MERGE PARTITIONS", request.schemaName, request.tableName ); - Transaction trx = getTransaction(); - try { - int i = executeSqlUpdate( trx, query ); - trx.commit(); - ctx.json( RelationalResult.builder().affectedTuples( i ).query( query ).build() ); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Could not merge partitions", e ); - try { - trx.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).query( query ).build() ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -2088,21 +1951,16 @@ void modifyPartitions( final Context ctx ) { for ( String partition : request.partitions ) { partitions.add( "\"" + partition + "\"" ); } - String query = String.format( "ALTER TABLE \"%s\".\"%s\" MODIFY PARTITIONS(%s) ON STORE %s", request.schemaName, request.tableName, partitions.toString(), request.storeUniqueName ); - Transaction trx = getTransaction(); - try { - int i = executeSqlUpdate( trx, query ); - trx.commit(); - ctx.json( RelationalResult.builder().affectedTuples( i ).query( query ).build() ); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Could not modify partitions", e ); - try { - trx.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).query( query ).build() ); - } + String query = String.format( "ALTER TABLE \"%s\".\"%s\" MODIFY PARTITIONS(%s) ON STORE %s", request.schemaName, request.tableName, partitions, request.storeUniqueName ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -2256,20 +2114,15 @@ void addAdapter( final Context ctx ) { } String query = String.format( "ALTER ADAPTERS ADD \"%s\" USING '%s' AS '%s' WITH '%s'", a.name, a.adapterName, a.type, Crud.gson.toJson( settings ) ); - Transaction transaction = getTransaction(); - try { - int numRows = executeSqlUpdate( transaction, query ); - transaction.commit(); - ctx.json( RelationalResult.builder().affectedTuples( numRows ).query( query ).build() ); - } catch ( Throwable e ) { - log.error( "Could not deploy data storeId", e ); - try { - transaction.rollback(); - } catch ( TransactionException transactionException ) { - log.error( "Exception while rollback", transactionException ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).query( query ).build() ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -2320,20 +2173,15 @@ private static void handleUploadFiles( Map inputStreams, Ad void removeAdapter( final Context ctx ) { String uniqueName = ctx.body(); String query = String.format( "ALTER ADAPTERS DROP \"%s\"", uniqueName ); - Transaction transaction = getTransaction(); - try { - int a = executeSqlUpdate( transaction, query ); - transaction.commit(); - ctx.json( RelationalResult.builder().affectedTuples( a ).query( query ).build() ); - } catch ( TransactionException | QueryExecutionException e ) { - log.error( "Could not remove storeId {}", ctx.body(), e ); - try { - transaction.rollback(); - } catch ( TransactionException transactionException ) { - log.error( "Exception while rollback", transactionException ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).query( query ).build() ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -2482,30 +2330,23 @@ void getUml( final Context ctx ) { */ void addForeignKey( final Context ctx ) { ForeignKey fk = ctx.bodyAsClass( ForeignKey.class ); - Transaction transaction = getTransaction(); String[] t = fk.getSourceTable().split( "\\." ); String fkTable = String.format( "\"%s\".\"%s\"", t[0], t[1] ); t = fk.getTargetTable().split( "\\." ); String pkTable = String.format( "\"%s\".\"%s\"", t[0], t[1] ); - RelationalResult result; String sql = String.format( "ALTER TABLE %s ADD CONSTRAINT \"%s\" FOREIGN KEY (\"%s\") REFERENCES %s(\"%s\") ON UPDATE %s ON DELETE %s", fkTable, fk.getFkName(), fk.getSourceColumn(), pkTable, fk.getTargetColumn(), fk.getOnUpdate(), fk.getOnDelete() ); - try { - executeSqlUpdate( transaction, sql ); - transaction.commit(); - result = RelationalResult.builder().affectedTuples( 1 ).query( sql ).build(); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while adding a foreign key", e ); - result = RelationalResult.builder().error( e.getMessage() ).query( sql ).build(); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - } - ctx.json( result ); + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( sql ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } @@ -2683,13 +2524,12 @@ RelationalResult executeAlg( final AlgRequest request, Session session ) { for ( AlgDataTypeField col : polyImplementation.getRowType().getFields() ) { header[counter++] = UiColumnDefinition.builder() .name( col.getName() ) - .dataType( col.getType() - .getFullTypeString() ).nullable( col.getType() - .isNullable() == (ResultSetMetaData.columnNullable == 1) ).precision( col.getType() - .getPrecision() ).build(); + .dataType( col.getType().getFullTypeString() ) + .nullable( col.getType().isNullable() ) + .precision( col.getType().getPrecision() ).build(); } - List data = computeResultData( rows, Arrays.asList( header ), statement.getTransaction() ); + List data = LanguageCrud.computeResultData( rows, List.of( header ), statement.getTransaction() ); try { executionTime += System.nanoTime() - temp; @@ -2743,8 +2583,6 @@ void namespaceRequest( final Context ctx ) { return; } - Transaction transaction = getTransaction(); - NamespaceType type = namespace.getType(); // create namespace @@ -2761,19 +2599,15 @@ void namespaceRequest( final Context ctx ) { if ( namespace.getAuthorization() != null && !namespace.getAuthorization().isEmpty() ) { query.append( " AUTHORIZATION " ).append( namespace.getAuthorization() ); } - try { - int rows = executeSqlUpdate( transaction, query.toString() ); - transaction.commit(); - ctx.json( RelationalResult.builder().affectedTuples( rows ).build() ); - } catch ( QueryExecutionException | TransactionException e ) { - log.error( "Caught exception while creating a namespace", e ); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).build() ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query.toString() ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } // drop namespace else if ( !namespace.isCreate() && namespace.isDrop() ) { @@ -2787,19 +2621,15 @@ else if ( !namespace.isCreate() && namespace.isDrop() ) { if ( namespace.isCascade() ) { query.append( " CASCADE" ); } - try { - int rows = executeSqlUpdate( transaction, query.toString() ); - transaction.commit(); - ctx.json( RelationalResult.builder().affectedTuples( rows ).build() ); - } catch ( TransactionException | QueryExecutionException e ) { - log.error( "Caught exception while dropping a namespace", e ); - try { - transaction.rollback(); - } catch ( TransactionException ex ) { - log.error( "Could not rollback", ex ); - } - ctx.json( RelationalResult.builder().error( e.getMessage() ).build() ); - } + QueryLanguage language = QueryLanguage.from( "sql" ); + Result res = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( query.toString() ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(), new UIRequest() ).get( 0 ); + ctx.json( res ); } else { ctx.json( RelationalResult.builder().error( "Neither the field 'create' nor the field 'drop' was set." ).build() ); } @@ -2808,15 +2638,13 @@ else if ( !namespace.isCreate() && namespace.isDrop() ) { private void createGraph( Namespace namespace, Context ctx ) { QueryLanguage cypher = QueryLanguage.from( "cypher" ); - QueryContext context = new QueryContext( "CREATE DATABASE " + namespace.getName() + " ON STORE " + namespace.getStore(), - cypher, - false, - true, - Catalog.defaultUserId, - "Polypheny-UI", - -1, - transactionManager ); - ctx.json( LanguageCrud.anyQueryResult( context ).get( 0 ) ); + QueryContext context = QueryContext.builder() + .query( "CREATE DATABASE " + namespace.getName() + " ON STORE " + namespace.getStore() ) + .language( cypher ) + .origin( ORIGIN ) + .transactionManager( transactionManager ) + .build(); + ctx.json( LanguageCrud.anyQueryResult( context, new UIRequest() ).get( 0 ) ); } @@ -2972,7 +2800,7 @@ private File getFile( Context ctx, String location, boolean sendBack ) { void getDirectory( File dir, Context ctx ) { ctx.header( "Content-ExpressionType", "application/zip" ); ctx.header( "Content-Disposition", "attachment; filename=" + dir.getName() + ".zip" ); - String zipFileName = UUID.randomUUID().toString() + ".zip"; + String zipFileName = UUID.randomUUID() + ".zip"; File zipFile = new File( System.getProperty( "user.home" ), ".polypheny/tmp/" + zipFileName ); try ( ZipOutputStream zipOut = new ZipOutputStream( Files.newOutputStream( zipFile.toPath() ) ) ) { zipDirectory( "", dir, zipOut ); @@ -2996,228 +2824,34 @@ void getDirectory( File dir, Context ctx ) { // ----------------------------------------------------------------------- - /** - * Execute a select statement with default limit - */ - public RelationalResultBuilder executeSqlSelect( final Statement statement, final UIRequest request, final String sqlSelect ) throws QueryExecutionException { - return executeSqlSelect( statement, request, sqlSelect, false, this ); - } - - - public static RelationalResultBuilder executeSqlSelect( final Statement statement, final UIRequest request, final String sqlSelect, final boolean noLimit, Crud crud ) throws QueryExecutionException { - PolyImplementation implementation; - List> rows = List.of(); - boolean hasMoreRows; - boolean isAnalyze = statement.getTransaction().isAnalyze(); - - try { - implementation = crud.processQuery( statement, sqlSelect, isAnalyze ); - ResultIterator iterator = implementation.execute( statement, noLimit ? -1 : crud.getPageSize(), isAnalyze, true, false ); - for ( int i = 0; i < request.currentPage; i++ ) { - rows = iterator.getNextBatch(); - } - iterator.close(); - hasMoreRows = implementation.hasMoreRows(); - - } catch ( Throwable t ) { - if ( statement.getTransaction().isAnalyze() ) { - InformationManager analyzer = statement.getTransaction().getQueryAnalyzer(); - InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); - InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); - InformationStacktrace exceptionElement = new InformationStacktrace( t, exceptionGroup ); - analyzer.addPage( exceptionPage ); - analyzer.addGroup( exceptionGroup ); - analyzer.registerInformation( exceptionElement ); - } - throw new QueryExecutionException( t ); - } - - LogicalTable table = null; - if ( request.entityId != null ) { - table = Catalog.snapshot().rel().getTable( request.entityId ).orElseThrow(); - } - - List header = new ArrayList<>(); - for ( AlgDataTypeField metaData : implementation.getRowType().getFields() ) { - String columnName = metaData.getName(); - - String filter = ""; - if ( request.filter != null && request.filter.containsKey( columnName ) ) { - filter = request.filter.get( columnName ); - } - - SortState sort; - if ( request.sortState != null && request.sortState.containsKey( columnName ) ) { - sort = request.sortState.get( columnName ); - } else { - sort = new SortState(); - } - - UiColumnDefinitionBuilder dbCol = UiColumnDefinition.builder() - .name( metaData.getName() ) - .dataType( metaData.getType().getPolyType().getTypeName() ) - .nullable( metaData.getType().isNullable() == (ResultSetMetaData.columnNullable == 1) ) - .precision( metaData.getType().getPrecision() ) - .sort( sort ) - .filter( filter ); - - // Get column default values - if ( table != null ) { - Optional logicalColumn = Catalog.snapshot().rel().getColumn( table.id, columnName ); - if ( logicalColumn.isPresent() ) { - if ( logicalColumn.get().defaultValue != null ) { - dbCol.defaultValue( logicalColumn.get().defaultValue.value.toJson() ); - } - } - } - header.add( dbCol.build() ); - } - - List data = computeResultData( rows, header, statement.getTransaction() ); - - return RelationalResult.builder() - .header( header.toArray( new UiColumnDefinition[0] ) ) - .data( data.toArray( new String[0][] ) ) - .namespaceType( implementation.getNamespaceType() ) - .language( QueryLanguage.from( "sql" ) ) - .affectedTuples( data.size() ) - .hasMore( hasMoreRows ); - } - - - /** - * Convert data from a query result to Strings readable in the UI - * - * @param rows Rows from the enumerable iterator - * @param header Header from the UI-ResultSet - */ - public static List computeResultData( final List> rows, final List header, final Transaction transaction ) { - List data = new ArrayList<>(); - for ( List row : rows ) { - String[] temp = new String[row.size()]; - int counter = 0; - for ( PolyValue o : row ) { - if ( o == null || o.isNull() ) { - temp[counter] = null; - } else { - String columnName = String.valueOf( header.get( counter ).name.hashCode() ); - File mmFolder = new File( System.getProperty( "user.home" ), ".polypheny/tmp" ); - mmFolder.mkdirs(); - ContentInfoUtil util = new ContentInfoUtil(); - if ( List.of( PolyType.FILE.getName(), PolyType.VIDEO.getName(), PolyType.AUDIO.getName(), PolyType.IMAGE.getName() ).contains( header.get( counter ).dataType ) ) { - ContentInfo info = util.findMatch( o.asBlob().value ); - String extension = ""; - if ( info != null && info.getFileExtensions() != null && info.getFileExtensions().length > 0 ) { - extension = "." + info.getFileExtensions()[0]; - } - File f = new File( mmFolder, columnName + "_" + UUID.randomUUID() + extension ); - try ( FileOutputStream fos = new FileOutputStream( f ) ) { - fos.write( o.asBlob().value ); - } catch ( IOException e ) { - throw new GenericRuntimeException( "Could not place file in mm folder", e ); - } - temp[counter] = f.getName(); - TemporalFileManager.addFile( transaction.getXid().toString(), f ); - } else { - temp[counter] = o.toJson(); - } - } - counter++; - } - data.add( temp ); - } - return data; - } - - - private PolyImplementation processQuery( Statement statement, String sql, boolean isAnalyze ) { - PolyImplementation implementation; - if ( isAnalyze ) { - statement.getOverviewDuration().start( "Parsing" ); - } - Processor sqlProcessor = statement.getTransaction().getProcessor( QueryLanguage.from( "sql" ) ); - Node parsed = sqlProcessor.parse( sql ).get( 0 ); - if ( isAnalyze ) { - statement.getOverviewDuration().stop( "Parsing" ); - } - AlgRoot logicalRoot; - QueryParameters parameters = new QueryParameters( sql, NamespaceType.RELATIONAL ); - if ( parsed.isA( Kind.DDL ) ) { - implementation = sqlProcessor.prepareDdl( statement, parsed, parameters ); - } else { - if ( isAnalyze ) { - statement.getOverviewDuration().start( "Validation" ); - } - Pair validated = sqlProcessor.validate( statement.getTransaction(), parsed, RuntimeConfig.ADD_DEFAULT_VALUES_IN_INSERTS.getBoolean() ); - if ( isAnalyze ) { - statement.getOverviewDuration().stop( "Validation" ); - statement.getOverviewDuration().start( "Translation" ); - } - logicalRoot = sqlProcessor.translate( statement, validated.left, parameters ); - if ( isAnalyze ) { - statement.getOverviewDuration().stop( "Translation" ); - } - implementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); - } - return implementation; - } - - - public int executeSqlUpdate( final Transaction transaction, final String sqlUpdate ) throws QueryExecutionException { - return executeSqlUpdate( transaction.createStatement(), transaction, sqlUpdate ); - } - - - private int executeSqlUpdate( final Statement statement, final Transaction transaction, final String sqlUpdate ) throws QueryExecutionException { - PolyImplementation implementation; - - try { - implementation = processQuery( statement, sqlUpdate, transaction.isAnalyze() ); - } catch ( Throwable t ) { - if ( transaction.isAnalyze() ) { - InformationManager analyzer = transaction.getQueryAnalyzer(); - InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); - InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); - InformationStacktrace exceptionElement = new InformationStacktrace( t, exceptionGroup ); - analyzer.addPage( exceptionPage ); - analyzer.addGroup( exceptionGroup ); - analyzer.registerInformation( exceptionElement ); - } - if ( t instanceof AvaticaRuntimeException ) { - throw new QueryExecutionException( ((AvaticaRuntimeException) t).getErrorMessage(), t ); - } else { - throw new QueryExecutionException( t.getMessage(), t ); - } - - } - try { - return implementation.getRowsChanged( statement ); - } catch ( Exception e ) { - throw new QueryExecutionException( e ); - } - } - - /** * Get the Number of rows in a table */ - private int getTableSize( Transaction transaction, final UIRequest request ) throws QueryExecutionException { + private long getTableSize( Transaction transaction, final UIRequest request ) { String tableId = getFullEntityName( request.entityId ); String query = "SELECT count(*) FROM " + tableId; if ( request.filter != null ) { query += " " + filterTable( request.filter ); } Statement statement = transaction.createStatement(); - RelationalResult result = executeSqlSelect( statement, request.toBuilder().currentPage( 1 ).build(), query ).build(); + QueryLanguage language = QueryLanguage.from( "sql" ); + ImplementationContext context = LanguageManager.getINSTANCE().anyPrepareQuery( + QueryContext.builder() + .query( query ) + .language( language ) + .origin( ORIGIN ) + .transactionManager( transactionManager ).build(), statement ).get( 0 ); + List> values = context.execute( statement ).getIterator().getNextBatch(); // We expect the result to be in the first column of the first row - if ( result.data.length == 0 ) { + if ( values.isEmpty() || values.get( 0 ).isEmpty() ) { return 0; } else { + PolyNumber number = values.get( 0 ).get( 0 ).asNumber(); if ( statement.getMonitoringEvent() != null ) { StatementEvent eventData = statement.getMonitoringEvent(); - eventData.setRowCount( Integer.parseInt( result.data[0][0] ) ); + eventData.setRowCount( number.longValue() ); } - return Integer.parseInt( result.getData()[0][0] ); + return number.longValue(); } } @@ -3279,7 +2913,7 @@ public Transaction getTransaction() { public static Transaction getTransaction( boolean analyze, boolean useCache, TransactionManager transactionManager, long userId, long databaseId ) { - return getTransaction( analyze, useCache, transactionManager, userId, databaseId, "Polypheny-UI" ); + return getTransaction( analyze, useCache, transactionManager, userId, databaseId, ORIGIN ); } @@ -3300,26 +2934,6 @@ public static Transaction getTransaction( boolean analyze, boolean useCache, Cru } - /** - * Get the data types of each column of a table - * - * @param namespaceName name of the namespace - * @param tableName name of the table - * @return HashMap containing the type of each column. The key is the name of the column and the value is the Sql ExpressionType (java.sql.Types). - */ - private Map getColumns( String namespaceName, String tableName ) { - Map dataTypes = new HashMap<>(); - - LogicalTable table = getLogicalTable( namespaceName, tableName ); - List logicalColumns = Catalog.snapshot().rel().getColumns( table.id ); - for ( LogicalColumn logicalColumn : logicalColumns ) { - dataTypes.put( logicalColumn.name, logicalColumn ); - } - - return dataTypes; - } - - void addDockerInstance( final Context ctx ) { Map config = gson.fromJson( ctx.body(), Map.class ); DockerSetupResult res = DockerSetupHelper.newDockerInstance( 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 8c2b713bf2..f9140b4fa6 100644 --- a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java +++ b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java @@ -33,10 +33,10 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.QueryLanguage; +import org.polypheny.db.processing.QueryContext; import org.polypheny.db.type.entity.graph.PolyGraph; import org.polypheny.db.webui.crud.LanguageCrud; import org.polypheny.db.webui.models.requests.AlgRequest; @@ -54,6 +54,7 @@ public class WebSocket implements Consumer { private static final Queue sessions = new ConcurrentLinkedQueue<>(); + public static final String POLYPHENY_UI = "Polypheny-UI"; private final Crud crud; private final ConcurrentHashMap> queryAnalyzers = new ConcurrentHashMap<>(); @@ -108,7 +109,7 @@ public void onMessage( final WsMessageContext ctx ) { switch ( request.type ) { case "GraphRequest": GraphRequest graphRequest = ctx.messageAsClass( GraphRequest.class ); - PolyGraph graph = LanguageCrud.getGraph( Catalog.snapshot().getNamespace( graphRequest.namespace ).orElseThrow().name, crud.getTransactionManager() ); + PolyGraph graph = LanguageCrud.getGraph( Catalog.snapshot().getNamespace( graphRequest.namespace ).orElseThrow().name, crud.getTransactionManager(), ctx.session ); ctx.send( graph.toJson() ); @@ -117,13 +118,15 @@ public void onMessage( final WsMessageContext ctx ) { QueryRequest queryRequest = ctx.messageAsClass( QueryRequest.class ); QueryLanguage language = QueryLanguage.from( queryRequest.language ); - List> results = LanguageCrud.anyQuery( - language, - ctx.session, - queryRequest, - crud.getTransactionManager(), - Catalog.defaultUserId, - Catalog.defaultNamespaceId ); + List> results = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( queryRequest.query ) + .language( language ) + .isAnalysed( queryRequest.analyze ) + .usesCache( queryRequest.cache ) + .origin( POLYPHENY_UI ).batch( queryRequest.noLimit ? -1 : crud.getPageSize() ) + .transactionManager( crud.getTransactionManager() ) + .informationTarget( i -> i.setSession( ctx.session ) ).build(), queryRequest ); for ( Result result : results ) { if ( !(result instanceof RelationalResult) ) { @@ -153,31 +156,32 @@ 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.namespace ).orElseThrow(); + LogicalNamespace namespace = Catalog.getInstance().getSnapshot().getNamespace( uiRequest.namespace ).orElse( null ); switch ( namespace.namespaceType ) { case RELATIONAL: result = crud.getTable( uiRequest ); break; case DOCUMENT: - LogicalCollection collection = Catalog.snapshot().doc().getCollection( uiRequest.entityId ).orElseThrow(); - result = LanguageCrud.anyQuery( - QueryLanguage.from( "mongo" ), - ctx.session, - new QueryRequest( String.format( "db.%s.find({})", collection.name ), false, false, "mql", namespace.name ), - crud.getTransactionManager(), - Catalog.defaultUserId, - Catalog.defaultNamespaceId - ).get( 0 ); + result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( "db.%s.find({})" ) + .language( QueryLanguage.from( "mongo" ) ) + .origin( POLYPHENY_UI ) + .transactionManager( crud.getTransactionManager() ) + .informationTarget( i -> i.setSession( ctx.session ) ) + .namespaceId( namespace == null ? Catalog.defaultNamespaceId : namespace.id ) + .build(), uiRequest ).get( 0 ); break; case GRAPH: - result = LanguageCrud.anyQuery( - QueryLanguage.from( "cypher" ), - ctx.session, - new QueryRequest( "MATCH (n) RETURN n", false, false, "mql", namespace.name ), - crud.getTransactionManager(), - Catalog.defaultUserId, - Catalog.defaultNamespaceId - ).get( 0 ); + result = LanguageCrud.anyQueryResult( + QueryContext.builder() + .query( "MATCH (n) RETURN n" ) + .language( QueryLanguage.from( "cypher" ) ) + .origin( POLYPHENY_UI ) + .namespaceId( namespace == null ? Catalog.defaultNamespaceId : namespace.id ) + .transactionManager( crud.getTransactionManager() ) + .informationTarget( i -> i.setSession( ctx.session ) ) + .build(), uiRequest ).get( 0 ); break; } if ( result == null ) { 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 722396dc21..37c29826f7 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 @@ -16,7 +16,12 @@ package org.polypheny.db.webui.crud; +import com.j256.simplemagic.ContentInfo; +import com.j256.simplemagic.ContentInfoUtil; import io.javalin.http.Context; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.sql.ResultSetMetaData; import java.util.ArrayList; import java.util.Arrays; @@ -24,17 +29,17 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.function.BiFunction; +import java.util.UUID; import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.eclipse.jetty.websocket.api.Session; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.polypheny.db.PolyImplementation; import org.polypheny.db.ResultIterator; import org.polypheny.db.adapter.Adapter; import org.polypheny.db.adapter.AdapterManager; -import org.polypheny.db.algebra.AlgRoot; +import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.allocation.AllocationEntity; @@ -47,22 +52,23 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.catalog.logistic.NamespaceType; -import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.information.InformationManager; import org.polypheny.db.information.InformationObserver; +import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.processing.ExtendedQueryParameters; -import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.ImplementationContext; +import org.polypheny.db.processing.ImplementationContext.ExecutedContext; import org.polypheny.db.processing.QueryContext; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.TransactionManager; +import org.polypheny.db.type.PolyType; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.graph.PolyGraph; -import org.polypheny.db.util.Pair; import org.polypheny.db.util.PolyphenyMode; import org.polypheny.db.webui.Crud; +import org.polypheny.db.webui.TemporalFileManager; import org.polypheny.db.webui.models.IndexModel; import org.polypheny.db.webui.models.PlacementModel; import org.polypheny.db.webui.models.PlacementModel.DocumentStore; @@ -74,8 +80,10 @@ import org.polypheny.db.webui.models.requests.UIRequest; import org.polypheny.db.webui.models.results.DocResult; import org.polypheny.db.webui.models.results.GraphResult; +import org.polypheny.db.webui.models.results.GraphResult.GraphResultBuilder; import org.polypheny.db.webui.models.results.RelationalResult; import org.polypheny.db.webui.models.results.Result; +import org.polypheny.db.webui.models.results.Result.ResultBuilder; @Getter @Slf4j @@ -84,7 +92,7 @@ public class LanguageCrud { public static Crud crud; - public final static Map>> REGISTER = new HashMap<>(); + protected final static Map>> REGISTER = new HashMap<>(); public LanguageCrud( Crud crud ) { @@ -92,18 +100,52 @@ public LanguageCrud( Crud crud ) { } + public static void addToResult( QueryLanguage queryLanguage, TriFunction> toResult ) { + REGISTER.put( queryLanguage, toResult ); + } + + + public static TriFunction> getToResult( QueryLanguage queryLanguage ) { + return REGISTER.get( queryLanguage ); + } + + + public static void deleteToResult( QueryLanguage language ) { + REGISTER.remove( language ); + } + + public static void anyQuery( Context ctx ) { QueryRequest request = ctx.bodyAsClass( QueryRequest.class ); QueryLanguage language = QueryLanguage.from( request.language ); - QueryContext context = new QueryContext( request.query, language, request.analyze, request.cache, Catalog.defaultUserId, "Polypheny UI", request.noLimit ? -1 : crud.getPageSize(), crud.getTransactionManager() ); - ctx.json( anyQueryResult( context ) ); + QueryContext context = QueryContext.builder() + .query( request.query ) + .language( language ) + .isAnalysed( request.analyze ) + .usesCache( request.cache ) + .origin( "Polypheny-UI" ) + .batch( request.noLimit ? -1 : crud.getPageSize() ) + .transactionManager( crud.getTransactionManager() ).build(); + ctx.json( anyQueryResult( context, request ) ); } - public static List> anyQueryResult( QueryContext context ) { - List> iterators = ResultIterator.anyQuery( context ); - BiFunction> resultProducer = REGISTER.get( context.getLanguage() ); - return iterators.stream().map( p -> resultProducer.apply( p.left, p.right ) ).collect( Collectors.toList() ); + public static List> anyQueryResult( QueryContext context, UIRequest request ) { + Transaction transaction = context.getTransactionManager().startTransaction( context.getUserId(), Catalog.defaultNamespaceId, context.isAnalysed(), context.getOrigin() ); + attachAnalyzerIfSpecified( context, crud, transaction ); + + List executedContexts = LanguageManager.getINSTANCE().anyQuery( context, transaction.createStatement() ); + + List> results = new ArrayList<>(); + TriFunction> builder = REGISTER.get( context.getLanguage() ); + + for ( ExecutedContext executedContext : executedContexts ) { + results.add( builder.apply( executedContext, request, executedContext.getStatement() ).build() ); + } + + commitAndFinish( transaction, transaction.getQueryAnalyzer(), results, executedContexts.stream().map( ExecutedContext::getExecutionTime ).reduce( Long::sum ).orElseThrow() ); + + return results; } @@ -132,33 +174,35 @@ public static void commitAndFinish( Transaction transaction, InformationManager @Nullable - public static InformationManager attachAnalyzerIfSpecified( QueryRequest request, InformationObserver observer, Transaction transaction ) { + public static InformationManager attachAnalyzerIfSpecified( QueryContext context, InformationObserver observer, Transaction transaction ) { // This is not a nice solution. In case of a sql script with auto commit only the first statement is analyzed // and in case of auto commit of, the information is overwritten InformationManager queryAnalyzer = null; - if ( request.analyze ) { + if ( context.isAnalysed() ) { queryAnalyzer = transaction.getQueryAnalyzer().observe( observer ); } return queryAnalyzer; } - public static PolyGraph getGraph( String namespace, TransactionManager manager ) { - + public static PolyGraph getGraph( String namespace, TransactionManager manager, Session session ) { + QueryLanguage language = QueryLanguage.from( "cypher" ); 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( namespace ); - AlgRoot logicalRoot = processor.translate( statement, null, parameters ); - PolyImplementation polyImplementation = statement.getQueryProcessor().prepareQuery( logicalRoot, true ); - - ResultIterator iterator = polyImplementation.execute( statement, 1 ); + ImplementationContext context = LanguageManager.getINSTANCE().anyPrepareQuery( + QueryContext.builder() + .query( "MATCH (*) RETURN n" ) + .language( language ) + .origin( transaction.getOrigin() ) + .transactionManager( manager ) + .informationTarget( i -> i.setSession( session ) ) + .build(), transaction.createStatement() ).get( 0 ); + + ResultIterator iterator = context.execute( transaction.createStatement() ).getIterator(); List> res = iterator.getNextBatch(); try { iterator.close(); - statement.getTransaction().commit(); + transaction.commit(); } catch ( Exception | TransactionException e ) { throw new GenericRuntimeException( "Error while committing graph retrieval query." ); } @@ -167,11 +211,6 @@ public static PolyGraph getGraph( String namespace, TransactionManager manager ) } - public static void printLog( Throwable t, QueryRequest request ) { - log.warn( "Failed during execution\nquery:" + request.query + "\nMsg:" + t.getMessage() ); - } - - public static void attachError( Transaction transaction, List> results, String query, NamespaceType model, Throwable t ) { //String msg = t.getMessage() == null ? "" : t.getMessage(); Result result; @@ -202,24 +241,21 @@ public static void attachError( Transaction transaction, List> resu @NotNull - public static Result getResult( QueryLanguage language, Statement statement, QueryRequest request, String query, PolyImplementation implementation, Transaction transaction, final boolean noLimit ) { + public static ResultBuilder getRelResult( ExecutedContext context, UIRequest request, Statement statement ) { Catalog catalog = Catalog.getInstance(); - - if ( language == QueryLanguage.from( "mongo" ) ) { - return getDocResult( statement, language, request, query, implementation, transaction, noLimit ); - } else if ( language == QueryLanguage.from( "cypher" ) ) { - return getGraphResult( statement, language, request, query, implementation, transaction, noLimit ); + ResultIterator iterator = context.getIterator(); + List> rows = new ArrayList<>(); + for ( int i = 0; i < request.currentPage; i++ ) { + rows = iterator.getNextBatch(); } - ResultIterator iterator = implementation.execute( statement, noLimit ? -1 : language == QueryLanguage.from( "cypher" ) ? RuntimeConfig.UI_NODE_AMOUNT.getInteger() : RuntimeConfig.UI_PAGE_SIZE.getInteger() ); - List> rows = iterator.getNextBatch(); try { iterator.close(); } catch ( Exception e ) { throw new GenericRuntimeException( e ); } - boolean hasMoreRows = implementation.hasMoreRows(); + boolean hasMoreRows = context.getIterator().hasMoreRows(); LogicalTable table = null; if ( request.entityId != null ) { @@ -227,7 +263,7 @@ public static void attachError( Transaction transaction, List> resu } List header = new ArrayList<>(); - for ( AlgDataTypeField field : implementation.rowType.getFields() ) { + for ( AlgDataTypeField field : context.getIterator().getImplementation().rowType.getFields() ) { String columnName = field.getName(); String filter = getFilter( field, request.filter ); @@ -254,26 +290,63 @@ public static void attachError( Transaction transaction, List> resu header.add( dbCol.build() ); } - List data = Crud.computeResultData( rows, header, statement.getTransaction() ); + List data = computeResultData( rows, header, statement.getTransaction() ); return RelationalResult .builder() .header( header.toArray( new UiColumnDefinition[0] ) ) .data( data.toArray( new String[0][] ) ) - .namespaceType( implementation.getNamespaceType() ) + .namespaceType( context.getIterator().getImplementation().getNamespaceType() ) .namespace( request.namespace ) - .language( language ) + .language( context.getQuery().getLanguage() ) .affectedTuples( data.size() ) .hasMore( hasMoreRows ) - .xid( transaction.getXid().toString() ) - .query( query ) - .build(); + .xid( statement.getTransaction().getXid().toString() ) + .query( context.getQuery().getQuery() ); } - private static GraphResult getGraphResult( Statement statement, QueryLanguage language, QueryRequest request, String query, PolyImplementation implementation, Transaction transaction, boolean noLimit ) { + public static List computeResultData( final List> rows, final List header, final Transaction transaction ) { + List data = new ArrayList<>(); + for ( List row : rows ) { + String[] temp = new String[row.size()]; + int counter = 0; + for ( PolyValue o : row ) { + if ( o == null || o.isNull() ) { + temp[counter] = null; + } else { + String columnName = String.valueOf( header.get( counter ).name.hashCode() ); + File mmFolder = new File( System.getProperty( "user.home" ), ".polypheny/tmp" ); + mmFolder.mkdirs(); + ContentInfoUtil util = new ContentInfoUtil(); + if ( List.of( PolyType.FILE.getName(), PolyType.VIDEO.getName(), PolyType.AUDIO.getName(), PolyType.IMAGE.getName() ).contains( header.get( counter ).dataType ) ) { + ContentInfo info = util.findMatch( o.asBlob().value ); + String extension = ""; + if ( info != null && info.getFileExtensions() != null && info.getFileExtensions().length > 0 ) { + extension = "." + info.getFileExtensions()[0]; + } + File f = new File( mmFolder, columnName + "_" + UUID.randomUUID() + extension ); + try ( FileOutputStream fos = new FileOutputStream( f ) ) { + fos.write( o.asBlob().value ); + } catch ( IOException e ) { + throw new GenericRuntimeException( "Could not place file in mm folder", e ); + } + temp[counter] = f.getName(); + TemporalFileManager.addFile( transaction.getXid().toString(), f ); + } else { + temp[counter] = o.toJson(); + } + } + counter++; + } + data.add( temp ); + } + return data; + } - ResultIterator iterator = implementation.execute( statement, noLimit ? -1 : RuntimeConfig.UI_PAGE_SIZE.getInteger() ); + + public static ResultBuilder getGraphResult( ExecutedContext context, UIRequest request, Statement statement ) { + ResultIterator iterator = context.getIterator(); List data = iterator.getArrayRows(); try { iterator.close(); @@ -281,21 +354,25 @@ private static GraphResult getGraphResult( Statement statement, QueryLanguage la throw new GenericRuntimeException( e ); } - return GraphResult.builder() + GraphResultBuilder builder = GraphResult.builder() .data( data.stream().map( r -> Arrays.stream( r ).map( LanguageCrud::toJson ).toArray( String[]::new ) ).toArray( String[][]::new ) ) - .header( implementation.rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) - .query( query ) - .language( language ) - .namespaceType( implementation.getNamespaceType() ) - .xid( transaction.getXid().toString() ) - .namespace( request.namespace ) - .build(); - } + .header( context.getIterator().getImplementation().rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) + .query( context.getQuery().getQuery() ) + .language( context.getQuery().getLanguage() ) + .namespaceType( context.getIterator().getImplementation().getNamespaceType() ) + .xid( statement.getTransaction().getXid().toString() ) + .namespace( request.namespace ); + + if ( Kind.DML.contains( context.getIterator().getImplementation().getKind() ) ) { + builder.affectedTuples( data.get( 0 )[0].asNumber().longValue() ); + } + return builder; + } - 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() ); + public static ResultBuilder getDocResult( ExecutedContext context, UIRequest request, Statement statement ) { + ResultIterator iterator = context.getIterator(); List> data = iterator.getNextBatch(); try { iterator.close(); @@ -304,14 +381,13 @@ private static DocResult getDocResult( Statement statement, QueryLanguage langua } return DocResult.builder() - .header( implementation.rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) + .header( context.getIterator().getImplementation().rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) .data( data.stream().map( d -> d.get( 0 ).toJson() ).toArray( String[]::new ) ) - .query( query ) - .language( language ) - .xid( transaction.getXid().toString() ) - .namespaceType( implementation.getNamespaceType() ) - .namespace( request.namespace ) - .build(); + .query( context.getQuery().getQuery() ) + .language( context.getQuery().getLanguage() ) + .xid( statement.getTransaction().getXid().toString() ) + .namespaceType( context.getIterator().getImplementation().getNamespaceType() ) + .namespace( request.namespace ); } @@ -421,5 +497,12 @@ public void getCollectionPlacements( Context context ) { } + @FunctionalInterface + public interface TriFunction { + + Result apply( First first, Second second, Third third ); + + } + } diff --git a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/requests/ClassifyAllData.java b/webui/src/main/java/org/polypheny/db/webui/crud/ResultBuilderContext.java similarity index 58% rename from plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/requests/ClassifyAllData.java rename to webui/src/main/java/org/polypheny/db/webui/crud/ResultBuilderContext.java index 20bc213196..824cee0c82 100644 --- a/plugins/explore-by-example/src/main/java/org/polypheny/db/exploreByExample/requests/ClassifyAllData.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/ResultBuilderContext.java @@ -14,22 +14,17 @@ * limitations under the License. */ -package org.polypheny.db.exploreByExample.requests; +package org.polypheny.db.webui.crud; - -import org.polypheny.db.webui.models.catalog.UiColumnDefinition; +import java.util.function.BiFunction; +import org.polypheny.db.processing.ImplementationContext; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.webui.models.requests.UIRequest; +import org.polypheny.db.webui.models.results.Result.ResultBuilder; +public class ResultBuilderContext { -public class ClassifyAllData extends UIRequest { - - public Integer id; - public UiColumnDefinition[] header; - public String[][] classified; - /** - * TRUE if information about the query execution should be added to the Query Analyzer (InformationManager) - */ - public boolean analyze; - public int cPage; + BiFunction> ddlBuilder; + BiFunction> builder; } 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 babb652bc8..540f164808 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 @@ -90,7 +90,7 @@ public abstract class Result { /** * Number of affected rows */ - public int affectedTuples; + public long affectedTuples; /** From 5f7cfa823af601dd26656ce9e98e0d6a33a34e79 Mon Sep 17 00:00:00 2001 From: datomo Date: Sun, 26 Nov 2023 18:53:36 +0100 Subject: [PATCH 06/15] fixes for new anyQuery logic --- .../algebra/logical/lpg/LogicalLpgValues.java | 39 ++++++++------ .../db/catalog/impl/PolyCatalog.java | 2 +- .../polypheny/db/processing/QueryContext.java | 4 +- .../org/polypheny/db/type/BasicPolyType.java | 2 +- .../java/org/polypheny/db/PolyphenyDb.java | 2 +- .../db/processing/AbstractQueryProcessor.java | 21 +++++--- .../org/polypheny/db/mql/MqlTestTemplate.java | 23 ++++++++ .../org/polypheny/db/cypher/CypherNode.java | 5 +- .../db/cypher/admin/CypherAlterDatabase.java | 2 +- .../db/cypher/admin/CypherCreateDatabase.java | 2 +- .../admin/CypherCreateDatabaseAlias.java | 2 +- .../db/cypher/admin/CypherDropAlias.java | 2 +- .../db/cypher/admin/CypherDropDatabase.java | 2 +- .../db/cypher/clause/CypherUseClause.java | 2 +- .../cypher2alg/CypherToAlgConverter.java | 5 +- .../db/cypher/expression/CypherUseGraph.java | 4 +- .../db/cypher/query/CypherSingleQuery.java | 8 +-- .../db/languages/MongoLanguagePlugin.java | 53 ++++++++++++++++++- .../db/languages/mql/MqlDropDatabase.java | 2 +- 19 files changed, 131 insertions(+), 51 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java index ff66eadec0..dfa3e2c8f5 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java @@ -16,6 +16,7 @@ package org.polypheny.db.algebra.logical.lpg; +import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; @@ -48,15 +49,19 @@ import org.polypheny.db.type.entity.graph.PolyEdge; import org.polypheny.db.type.entity.graph.PolyEdge.EdgeDirection; import org.polypheny.db.type.entity.graph.PolyNode; +import org.polypheny.db.util.Collation; import org.polypheny.db.util.Pair; @Getter public class LogicalLpgValues extends LpgValues implements RelationalTransformable { - public static final BasicPolyType ID_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.VARCHAR, 36 ); - public static final BasicPolyType LABEL_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.VARCHAR, 255 ); - public static final BasicPolyType VALUE_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.VARCHAR, 255 ); + public static final BasicPolyType ID_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.VARCHAR, 36 ) + .createWithCharsetAndCollation( Charsets.UTF_16, Collation.IMPLICIT ); + public static final BasicPolyType LABEL_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.VARCHAR, 255 ) + .createWithCharsetAndCollation( Charsets.UTF_16, Collation.IMPLICIT ); + public static final BasicPolyType VALUE_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.VARCHAR, 255 ) + .createWithCharsetAndCollation( Charsets.UTF_16, Collation.IMPLICIT ); public static final BasicPolyType NODE_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.NODE ); public static final BasicPolyType EDGE_TYPE = new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.EDGE ); private final ImmutableList> values; @@ -140,7 +145,7 @@ public List getRelationalEquivalent( List values, List> getNodeValues( ImmutableList nodes ) { ImmutableList.Builder> rows = ImmutableList.builder(); for ( PolyNode node : nodes ) { - RexLiteral id = getNls( node.id.value, ID_TYPE ); + RexLiteral id = getStringLiteral( node.id.value, ID_TYPE ); // empty node without label, as non label nodes are permitted (use $, as null is not possible for pk) ImmutableList.Builder idRow = ImmutableList.builder(); idRow.add( id ); @@ -150,7 +155,7 @@ private ImmutableList> getNodeValues( ImmutableList row = ImmutableList.builder(); row.add( id ); - row.add( getNls( label.value, LABEL_TYPE ) ); + row.add( getStringLiteral( label.value, LABEL_TYPE ) ); rows.add( row.build() ); } } @@ -161,13 +166,13 @@ private ImmutableList> getNodeValues( ImmutableList> getNodePropertyValues( ImmutableList nodes ) { ImmutableList.Builder> rows = ImmutableList.builder(); for ( PolyNode node : nodes ) { - RexLiteral id = getNls( node.id.value, ID_TYPE ); + RexLiteral id = getStringLiteral( node.id.value, ID_TYPE ); for ( Entry entry : node.properties.entrySet() ) { ImmutableList.Builder row = ImmutableList.builder(); row.add( id ); - row.add( getNls( entry.getKey().value, LABEL_TYPE ) ); - row.add( getNls( entry.getValue().toString(), VALUE_TYPE ) ); + row.add( getStringLiteral( entry.getKey().value, LABEL_TYPE ) ); + row.add( getStringLiteral( entry.getValue().toString(), VALUE_TYPE ) ); rows.add( row.build() ); } } @@ -175,8 +180,8 @@ private ImmutableList> getNodePropertyValues( Immutabl } - private static RexLiteral getNls( String value, BasicPolyType type ) { - return new RexLiteral( PolyString.of( value ), type, PolyType.CHAR ); + private static RexLiteral getStringLiteral( String value, BasicPolyType type ) { + return new RexLiteral( PolyString.of( value ), type, PolyType.VARCHAR ); } @@ -184,11 +189,11 @@ private ImmutableList> getEdgeValues( ImmutableList> rows = ImmutableList.builder(); for ( PolyEdge edge : edges ) { ImmutableList.Builder row = ImmutableList.builder(); - row.add( getNls( edge.id.value, ID_TYPE ) ); - row.add( getNls( edge.labels.get( 0 ).value, LABEL_TYPE ) ); + row.add( getStringLiteral( edge.id.value, ID_TYPE ) ); + row.add( getStringLiteral( edge.labels.get( 0 ).value, LABEL_TYPE ) ); - row.add( getNls( edge.source.value, ID_TYPE ) ); - row.add( getNls( edge.target.value, ID_TYPE ) ); + row.add( getStringLiteral( edge.source.value, ID_TYPE ) ); + row.add( getStringLiteral( edge.target.value, ID_TYPE ) ); rows.add( row.build() ); } @@ -199,13 +204,13 @@ private ImmutableList> getEdgeValues( ImmutableList> getEdgePropertyValues( ImmutableList edges ) { ImmutableList.Builder> rows = ImmutableList.builder(); for ( PolyEdge edge : edges ) { - RexLiteral id = getNls( edge.id.value, ID_TYPE ); + RexLiteral id = getStringLiteral( edge.id.value, ID_TYPE ); for ( Entry entry : edge.properties.entrySet() ) { ImmutableList.Builder row = ImmutableList.builder(); row.add( id ); - row.add( getNls( entry.getKey().value, LABEL_TYPE ) ); - row.add( getNls( entry.getValue().toString(), VALUE_TYPE ) ); + row.add( getStringLiteral( entry.getKey().value, LABEL_TYPE ) ); + row.add( getStringLiteral( entry.getValue().toString(), VALUE_TYPE ) ); rows.add( row.build() ); } } diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java b/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java index 918bc93b98..cf87ff3a80 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java @@ -242,7 +242,7 @@ private void restoreLastState() { private void validateNamespaceType( long id, NamespaceType type ) { if ( logicalCatalogs.get( id ).getLogicalNamespace().namespaceType != type ) { - throw new GenericRuntimeException( "error while retrieving catalog" ); + throw new GenericRuntimeException( "Error while retrieving namespace type" ); } } diff --git a/core/src/main/java/org/polypheny/db/processing/QueryContext.java b/core/src/main/java/org/polypheny/db/processing/QueryContext.java index 7bc5641645..f55cbf8083 100644 --- a/core/src/main/java/org/polypheny/db/processing/QueryContext.java +++ b/core/src/main/java/org/polypheny/db/processing/QueryContext.java @@ -23,7 +23,6 @@ import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.information.InformationManager; import org.polypheny.db.languages.QueryLanguage; @@ -57,11 +56,10 @@ public class QueryContext { @Builder.Default int batch = -1; // -1 for all - @NotNull TransactionManager transactionManager; @Builder.Default - @Nullable + @NotNull Consumer informationTarget = i -> { }; diff --git a/core/src/main/java/org/polypheny/db/type/BasicPolyType.java b/core/src/main/java/org/polypheny/db/type/BasicPolyType.java index 43a2d8a815..cc6ff1ebbb 100644 --- a/core/src/main/java/org/polypheny/db/type/BasicPolyType.java +++ b/core/src/main/java/org/polypheny/db/type/BasicPolyType.java @@ -159,7 +159,7 @@ public BasicPolyType createWithNullability( boolean nullable ) { *

* This must be a character type. */ - BasicPolyType createWithCharsetAndCollation( Charset charset, Collation collation ) { + public BasicPolyType createWithCharsetAndCollation( Charset charset, Collation collation ) { Preconditions.checkArgument( PolyTypeUtil.inCharFamily( this ) ); return new BasicPolyType( this.typeSystem, diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index 044956285e..b5ba4502df 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -124,7 +124,7 @@ public class PolyphenyDb { public boolean daemonMode = false; @Option(name = { "-defaultStore" }, description = "Type of default storeId") - public String defaultStoreName = "postgresql"; + public String defaultStoreName = "hsqldb"; @Option(name = { "-defaultSource" }, description = "Type of default source") public String defaultSourceName = "csv"; 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 5aaa610af3..26d50db28d 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -1289,7 +1289,7 @@ private Map> getAccessedPartitionsPerScan( AlgNode alg, Map> getAccessedPartitionsPerScan( AlgNode alg, Map partitionValues = new ArrayList<>( aggregatedPartitionValues.get( scanId ) ); @@ -1312,7 +1317,7 @@ private Map> getAccessedPartitionsPerScan( AlgNode alg, Map> getAccessedPartitionsPerScan( AlgNode alg, Map> getAccessedPartitionsPerScan( AlgNode alg, Map Stream.concat( l1.stream(), l2.stream() ).collect( Collectors.toList() ) ); - scanPerTable.putIfAbsent( scanId, catalogTable.id ); + scanPerTable.putIfAbsent( scanId, table.id ); // Fallback all partitionIds are needed } @@ -1345,7 +1350,7 @@ private Map> getAccessedPartitionsPerScan( AlgNode alg, Map Stream.concat( l1.stream(), l2.stream() ).collect( Collectors.toList() ) ); - scanPerTable.putIfAbsent( scanId, catalogTable.id ); + scanPerTable.putIfAbsent( scanId, table.id ); } } diff --git a/dbms/src/test/java/org/polypheny/db/mql/MqlTestTemplate.java b/dbms/src/test/java/org/polypheny/db/mql/MqlTestTemplate.java index b02e2fc6e8..f5fffef615 100644 --- a/dbms/src/test/java/org/polypheny/db/mql/MqlTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/mql/MqlTestTemplate.java @@ -20,6 +20,7 @@ import java.util.List; import org.junit.After; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.MongoConnection; @@ -42,6 +43,28 @@ public static void start() { } + @Before + public void initCollection() { + initCollection( database ); + } + + + @After + public void dropCollection() { + dropCollection( database ); + } + + + public static void dropCollection( String collection ) { + MongoConnection.executeGetResponse( "db." + collection + ".drop()" ); + } + + + public static void initCollection( String collection ) { + MongoConnection.executeGetResponse( "db.createCollection(" + collection + ")" ); + } + + @AfterClass public static void tearDown() { dropDatabase(); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java index e492541da8..696ebd32a5 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/CypherNode.java @@ -47,7 +47,7 @@ protected CypherNode( ParserPos pos ) { @Override public Kind getKind() { - return Kind.OTHER; + return isDdl() ? Kind.OTHER_DDL : Kind.OTHER; } @@ -89,7 +89,8 @@ public void accept( CypherVisitor visitor ) { } - public boolean isDDL() { + @Override + public boolean isDdl() { return DDL.contains( getCypherKind() ); } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabase.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabase.java index 2083d3d068..b9481ec2c0 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabase.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterDatabase.java @@ -44,7 +44,7 @@ public CypherAlterDatabase( @Override - public boolean isDDL() { + public boolean isDdl() { return true; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java index d69763e724..cb59064919 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabase.java @@ -99,7 +99,7 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa @Override - public boolean isDDL() { + public boolean isDdl() { return true; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java index 63441636f5..280131ddce 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateDatabaseAlias.java @@ -66,7 +66,7 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa @Override - public boolean isDDL() { + public boolean isDdl() { return true; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java index 049723acdb..21e18dd344 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java @@ -56,7 +56,7 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa @Override - public boolean isDDL() { + public boolean isDdl() { return true; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java index 7e4a87b5a0..5613254e02 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropDatabase.java @@ -79,7 +79,7 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa @Override - public boolean isDDL() { + public boolean isDdl() { return true; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java index fdc55dab00..0db6584a41 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java @@ -44,7 +44,7 @@ public CypherKind getCypherKind() { @Override - public boolean isDDL() { + public boolean isDdl() { return true; } 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 e9042318ab..673ff432ab 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 @@ -108,7 +108,7 @@ public CypherToAlgConverter( Statement statement, AlgBuilder builder, RexBuilder public AlgRoot convert( CypherNode query, ParsedQueryContext parsedContext, AlgOptCluster cluster ) { - long namespaceId = getNamespaceId( parsedContext ); + long namespaceId = parsedContext.getNamespaceId(); LogicalEntity entity = getEntity( namespaceId ); @@ -154,9 +154,6 @@ private AlgNode buildFullScan( LogicalGraph graph ) { } - private long getNamespaceId( ParsedQueryContext context ) { - return snapshot.getNamespace( context.getQueryNode().getNamespaceId() ).orElseThrow().id; - } private void convertQuery( CypherNode node, CypherContext context ) { diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java index 59a6d87e0c..ac4bce323c 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java @@ -43,7 +43,7 @@ public CypherUseGraph( CypherWithGraph statement, CypherUseClause useClause ) { @Override public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { - if ( this.statement != null && this.statement.isDDL() ) { + if ( this.statement != null && this.statement.isDdl() ) { ((ExecutableStatement) this.statement).execute( context, statement, parsedQueryContext ); } if ( useClause != null ) { @@ -53,7 +53,7 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa @Override - public boolean isDDL() { + public boolean isDdl() { return true; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java index 96fb91c38d..bb47ed0b5f 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java @@ -58,11 +58,11 @@ public CypherKind getCypherKind() { @Override - public boolean isDDL() { - if ( clauses.stream().allMatch( CypherNode::isDDL ) ) { + public boolean isDdl() { + if ( clauses.stream().allMatch( CypherNode::isDdl ) ) { return true; } - if ( clauses.stream().noneMatch( CypherNode::isDDL ) ) { + if ( clauses.stream().noneMatch( CypherNode::isDdl ) ) { return false; } throw new GenericRuntimeException( "The mixed query is not supported" ); @@ -72,7 +72,7 @@ public boolean isDDL() { @Override public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { for ( CypherClause clause : clauses ) { - if ( clause.isDDL() ) { + if ( clause.isDdl() ) { ((ExecutableStatement) clause).execute( context, statement, parsedQueryContext ); } } 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 be6df0f659..b850bd73e5 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 @@ -17,13 +17,21 @@ package org.polypheny.db.languages; import com.google.common.annotations.VisibleForTesting; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; 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.LogicalCollection; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.snapshot.Snapshot; +import org.polypheny.db.languages.mql.MqlCreateCollection; +import org.polypheny.db.languages.mql.MqlCreateView; import org.polypheny.db.mql.parser.MqlParserImpl; import org.polypheny.db.nodes.DeserializeFunctionOperator; import org.polypheny.db.nodes.LangFunctionOperator; @@ -31,6 +39,9 @@ import org.polypheny.db.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.plugins.PolyPluginManager; +import org.polypheny.db.processing.QueryContext; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; +import org.polypheny.db.util.Pair; import org.polypheny.db.webui.crud.LanguageCrud; @Slf4j @@ -72,7 +83,7 @@ public static void startup() { MqlParserImpl.FACTORY, MqlProcessor::new, null, - LanguageManager::toQueryNodes ); + MongoLanguagePlugin::anyQuerySplitter ); LanguageManager.getINSTANCE().addQueryLanguage( language ); PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getDocResult ) ); @@ -82,6 +93,46 @@ public static void startup() { } + private static List anyQuerySplitter( QueryContext context ) { + List queries = new ArrayList<>( LanguageManager.toQueryNodes( context ) ); + Snapshot snapshot = Catalog.snapshot(); + List> toCreate = new ArrayList<>(); + List> created = new ArrayList<>(); + for ( ParsedQueryContext query : queries ) { + if ( query.getQueryNode().getEntity() == null ) { + continue; + } + Optional collection = snapshot.doc().getCollection( query.getNamespaceId(), query.getQueryNode().getEntity() ); + if ( collection.isEmpty() && !created.contains( Pair.of( context.getNamespaceId(), query.getQueryNode().getEntity() ) ) ) { + if ( query.getQueryNode() instanceof MqlCreateCollection || query.getQueryNode() instanceof MqlCreateView ) { + // entity was created during this query + created.add( Pair.of( context.getNamespaceId(), query.getQueryNode().getEntity() ) ); + } else { + // we have to create this query manually + toCreate.add( 0, Pair.of( query.getNamespaceId(), query.getQueryNode().getEntity() ) ); + } + } + } + + List> toCreateQueries = toCreate.stream().map( p -> + QueryContext.builder() + .query( "db.createCollection(" + p.right + ")" ) + .namespaceId( p.left ) + .language( context.getLanguage() ) + .transactionManager( context.getTransactionManager() ) + .origin( context.getOrigin() ) + .informationTarget( context.getInformationTarget() ) + .build() ).map( LanguageManager::toQueryNodes ).collect( Collectors.toList() ); + + for ( List toCreateQuery : toCreateQueries ) { + for ( int i = toCreateQueries.size() - 1; i >= 0; i-- ) { + queries.add( 0, toCreateQuery.get( i ) ); + } + } + + return queries; + } + public static void registerOperators() { if ( isInit ) { diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java index 75cfa04665..3a808b44cb 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropDatabase.java @@ -35,7 +35,7 @@ public MqlDropDatabase( ParserPos pos ) { @Override public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { - Long namespaceId = parsedQueryContext.getQueryNode().getNamespaceId(); + Long namespaceId = parsedQueryContext.getNamespaceId(); DdlManager.getInstance().dropNamespace( Catalog.snapshot().getNamespace( namespaceId ).orElseThrow().name, true, statement ); } From b57570bee76315ead00a17a33a60c97060bf732f Mon Sep 17 00:00:00 2001 From: datomo Date: Sun, 26 Nov 2023 21:46:46 +0100 Subject: [PATCH 07/15] removing old catalogReader inheritant classes and old tests --- .../relational/RelationalTransformable.java | 5 - .../polypheny/db/algebra/fun/AggFunction.java | 2 +- .../catalog/catalogs/AllocationCatalog.java | 2 +- .../db/catalog/entity/LogicalEntity.java | 2 +- .../db/languages/NodeToAlgConverter.java | 2 - .../validate/ValidatorCatalogReader.java | 2 +- .../db/nodes/validate/ValidatorTable.java | 2 +- ...lanner.java => AbstractAlgOptPlanner.java} | 4 +- .../org/polypheny/db/plan/AlgOptEntity.java | 111 ---- .../org/polypheny/db/plan/AlgOptQuery.java | 29 +- .../org/polypheny/db/plan/AlgOptSchema.java | 17 +- .../java/org/polypheny/db/plan/Context.java | 2 +- .../org/polypheny/db/plan/hep/HepPlanner.java | 12 +- .../db/plan/volcano/VolcanoPlanner.java | 4 +- .../db/prepare/PolyphenyDbCatalogReader.java | 150 ----- .../db/prepare/PolyphenyDbPrepareImpl.java | 207 ------ .../org/polypheny/db/prepare/Prepare.java | 71 -- .../java/org/polypheny/db/schema/Entity.java | 1 + .../org/polypheny/db/schema/Namespace.java | 1 + .../java/org/polypheny/db/schema/Wrapper.java | 56 -- .../org/polypheny/db/schema/graph/Graph.java | 2 +- .../db/schema/graph/ModifiableGraph.java | 45 -- .../db/schema/impl/AbstractEntity.java | 2 +- .../java/org/polypheny/db/util/Wrapper.java | 35 + .../catalog/CompoundNameColumnResolver.java | 120 ---- .../db/catalog/MockCatalogReader.java | 629 ------------------ .../db/catalog/MockCatalogReaderDocument.java | 56 -- .../db/catalog/MockCatalogReaderDynamic.java | 71 -- .../db/catalog/MockCatalogReaderExtended.java | 75 --- .../db/catalog/MockCatalogReaderSimple.java | 288 -------- ...OptPlanner.java => MockAlgOptPlanner.java} | 6 +- .../db/processing/AbstractQueryProcessor.java | 32 +- .../db/processing/HepQueryProcessor.java | 51 -- .../db/adapter/jdbc/alg2sql/PlannerTest.java | 32 +- .../polypheny/db/mql/mql2alg/Mql2AlgTest.java | 5 +- .../language/validate/SqlValidatorScope.java | 3 +- .../db/sql/sql2alg/SqlToAlgConverter.java | 14 +- .../org/polypheny/db/sql/HepPlannerTest.java | 10 +- .../org/polypheny/db/sql/MutableRelTest.java | 2 +- .../org/polypheny/db/sql/PlannerTest.java | 3 +- .../org/polypheny/db/sql/RelOptTestBase.java | 17 +- .../polypheny/db/sql/RexTransformerTest.java | 2 +- .../db/sql/SqlLanguageDependent.java | 6 +- .../db/sql/language/SqlTestFactory.java | 33 +- .../sql/language/SqlToAlgConverterTest.java | 56 +- .../db/sql/language/SqlToAlgTestBase.java | 553 ++------------- .../sql/language/utils/AbstractSqlTester.java | 108 --- .../language/utils/SqlValidatorTestCase.java | 204 ------ .../db/sql/util/PlannerImplMock.java | 17 +- .../db/sql/volcano/TraitPropagationTest.java | 73 +- 50 files changed, 189 insertions(+), 3043 deletions(-) rename core/src/main/java/org/polypheny/db/plan/{AbstractRelOptPlanner.java => AbstractAlgOptPlanner.java} (98%) delete mode 100644 core/src/main/java/org/polypheny/db/plan/AlgOptEntity.java delete mode 100644 core/src/main/java/org/polypheny/db/prepare/PolyphenyDbCatalogReader.java delete mode 100644 core/src/main/java/org/polypheny/db/schema/Wrapper.java delete mode 100644 core/src/main/java/org/polypheny/db/schema/graph/ModifiableGraph.java create mode 100644 core/src/main/java/org/polypheny/db/util/Wrapper.java delete mode 100644 core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java delete mode 100644 core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java delete mode 100644 core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDocument.java delete mode 100644 core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDynamic.java delete mode 100644 core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderExtended.java delete mode 100644 core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderSimple.java rename core/src/test/java/org/polypheny/db/test/{MockRelOptPlanner.java => MockAlgOptPlanner.java} (97%) delete mode 100644 dbms/src/main/java/org/polypheny/db/processing/HepQueryProcessor.java diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java index 198a8214ed..85346c358d 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java @@ -22,7 +22,6 @@ import org.polypheny.db.algebra.core.common.Modify.Operation; import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.snapshot.Snapshot; -import org.polypheny.db.prepare.Prepare.CatalogReader; import org.polypheny.db.schema.types.ModifiableTable; @@ -31,10 +30,6 @@ */ public interface RelationalTransformable { - default CatalogReader getCatalogReader() { - throw new UnsupportedOperationException(); - } - List getRelationalEquivalent( List values, List entities, Snapshot snapshot ); diff --git a/core/src/main/java/org/polypheny/db/algebra/fun/AggFunction.java b/core/src/main/java/org/polypheny/db/algebra/fun/AggFunction.java index 54a9a9542c..7d01bd2d89 100644 --- a/core/src/main/java/org/polypheny/db/algebra/fun/AggFunction.java +++ b/core/src/main/java/org/polypheny/db/algebra/fun/AggFunction.java @@ -18,7 +18,7 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.nodes.Function; -import org.polypheny.db.schema.Wrapper; +import org.polypheny.db.util.Wrapper; public interface AggFunction extends Function, Wrapper { diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/AllocationCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/AllocationCatalog.java index 70124bb2c4..e41eca8123 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/AllocationCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/AllocationCatalog.java @@ -24,7 +24,7 @@ import org.polypheny.db.catalog.impl.allocation.PolyAllocDocCatalog; import org.polypheny.db.catalog.impl.allocation.PolyAllocGraphCatalog; import org.polypheny.db.catalog.impl.allocation.PolyAllocRelCatalog; -import org.polypheny.db.schema.Wrapper; +import org.polypheny.db.util.Wrapper; @SerializeClass(subclasses = { PolyAllocDocCatalog.class, PolyAllocGraphCatalog.class, PolyAllocRelCatalog.class }) public interface AllocationCatalog extends Wrapper { diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java index 8c408c4c2a..7f4edf94be 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java @@ -37,10 +37,10 @@ import org.polypheny.db.catalog.refactor.CatalogType; import org.polypheny.db.schema.Statistic; import org.polypheny.db.schema.Statistics; -import org.polypheny.db.schema.Wrapper; import org.polypheny.db.schema.types.Expressible; import org.polypheny.db.schema.types.Typed; import org.polypheny.db.util.ImmutableBitSet; +import org.polypheny.db.util.Wrapper; @Getter @SuperBuilder(toBuilder = true) diff --git a/core/src/main/java/org/polypheny/db/languages/NodeToAlgConverter.java b/core/src/main/java/org/polypheny/db/languages/NodeToAlgConverter.java index 849eba0a8b..07b89fd88c 100644 --- a/core/src/main/java/org/polypheny/db/languages/NodeToAlgConverter.java +++ b/core/src/main/java/org/polypheny/db/languages/NodeToAlgConverter.java @@ -47,8 +47,6 @@ static ConfigBuilder configBuilder() { return new ConfigBuilder(); } - void setDynamicParamCountInExplain( int explainParamCount ); - AlgNode flattenTypes( AlgNode rootAlg, boolean restructure ); AlgNode decorrelate( Node query, AlgNode rootAlg ); diff --git a/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorCatalogReader.java b/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorCatalogReader.java index 082b498a3e..58c6f2e1c3 100644 --- a/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorCatalogReader.java +++ b/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorCatalogReader.java @@ -22,8 +22,8 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.nodes.Identifier; -import org.polypheny.db.schema.Wrapper; import org.polypheny.db.util.Moniker; +import org.polypheny.db.util.Wrapper; /** diff --git a/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorTable.java b/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorTable.java index f7f5dfbb83..29d51993a8 100644 --- a/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorTable.java +++ b/core/src/main/java/org/polypheny/db/nodes/validate/ValidatorTable.java @@ -23,7 +23,7 @@ import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.schema.Wrapper; +import org.polypheny.db.util.Wrapper; /** diff --git a/core/src/main/java/org/polypheny/db/plan/AbstractRelOptPlanner.java b/core/src/main/java/org/polypheny/db/plan/AbstractAlgOptPlanner.java similarity index 98% rename from core/src/main/java/org/polypheny/db/plan/AbstractRelOptPlanner.java rename to core/src/main/java/org/polypheny/db/plan/AbstractAlgOptPlanner.java index 52c31e1059..76c6ac144d 100644 --- a/core/src/main/java/org/polypheny/db/plan/AbstractRelOptPlanner.java +++ b/core/src/main/java/org/polypheny/db/plan/AbstractAlgOptPlanner.java @@ -59,7 +59,7 @@ /** * Abstract base for implementations of the {@link AlgOptPlanner} interface. */ -public abstract class AbstractRelOptPlanner implements AlgOptPlanner { +public abstract class AbstractAlgOptPlanner implements AlgOptPlanner { /** * Regular expression for integer. @@ -95,7 +95,7 @@ public abstract class AbstractRelOptPlanner implements AlgOptPlanner { /** * Creates an AbstractRelOptPlanner. */ - protected AbstractRelOptPlanner( AlgOptCostFactory costFactory, Context context ) { + protected AbstractAlgOptPlanner( AlgOptCostFactory costFactory, Context context ) { assert costFactory != null; this.costFactory = costFactory; if ( context == null ) { diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptEntity.java b/core/src/main/java/org/polypheny/db/plan/AlgOptEntity.java deleted file mode 100644 index 07d473cea5..0000000000 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptEntity.java +++ /dev/null @@ -1,111 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.plan; - - -import java.util.List; -import org.apache.calcite.linq4j.tree.Expression; -import org.polypheny.db.algebra.AlgDistribution; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.logical.relational.LogicalRelScan; -import org.polypheny.db.algebra.metadata.AlgMetadataQuery; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.schema.ColumnStrategy; -import org.polypheny.db.schema.Entity; -import org.polypheny.db.schema.Wrapper; - - -/** - * Represents a relational dataset in a {@link AlgOptSchema}. It has methods to describe and implement itself. - */ -public interface AlgOptEntity extends Wrapper { - - /** - * Returns an estimate of the number of rows in the table. - */ - double getRowCount(); - - /** - * Describes the type of rows returned by this table. - */ - AlgDataType getRowType(); - - - /** - * Converts this table into a {@link AlgNode relational expression}. - * - * The {@link AlgOptPlanner planner} calls this method to convert a table into an initial - * relational expression, generally something abstract, such as a {@link LogicalRelScan}, then optimizes this - * expression by applying {@link AlgOptRule rules} to transform it into more efficient access methods for this table. - */ - AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ); - - /** - * Returns a description of the physical distribution of the rows in this table. - * - * @see AlgMetadataQuery#distribution(AlgNode) - */ - AlgDistribution getDistribution(); - - - /** - * Generates code for this table. - * - * @param clazz The desired collection class; for example {@code Queryable}. - */ - Expression getExpression( Class clazz ); - - /** - * Returns a list describing how each column is populated. The list has the same number of entries as there are fields, - * and is immutable. - */ - List getColumnStrategies(); - - @Deprecated - default Entity getEntity() { - return null; - } - - - /** - * Contains the context needed to convert a table into a relational expression. - */ - interface ToAlgContext { - - AlgOptCluster getCluster(); - - } - -} - diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptQuery.java b/core/src/main/java/org/polypheny/db/plan/AlgOptQuery.java index 13eac238a3..31bb390614 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptQuery.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptQuery.java @@ -37,7 +37,6 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.core.CorrelationId; /** @@ -45,45 +44,23 @@ */ public class AlgOptQuery { - /** - * Prefix to the name of correlating variables. - */ - public static final String CORREL_PREFIX = CorrelationId.CORREL_PREFIX; - /** * Maps name of correlating variable (e.g. "$cor3") to the {@link AlgNode} which implements it. */ - final Map mapCorrelToRel; + final Map mapCorrelToAlg; - private final AlgOptPlanner planner; final AtomicInteger nextCorrel; /** * For use by RelOptCluster only. */ - AlgOptQuery( AlgOptPlanner planner, AtomicInteger nextCorrel, Map mapCorrelToRel ) { - this.planner = planner; + AlgOptQuery( AtomicInteger nextCorrel, Map mapCorrelToAlg ) { this.nextCorrel = nextCorrel; - this.mapCorrelToRel = mapCorrelToRel; - } - - - /** - * Returns the relational expression which populates a correlating variable. - */ - public AlgNode lookupCorrel( String name ) { - return mapCorrelToRel.get( name ); + this.mapCorrelToAlg = mapCorrelToAlg; } - /** - * Maps a correlating variable to a {@link AlgNode}. - */ - public void mapCorrel( String name, AlgNode alg ) { - mapCorrelToRel.put( name, alg ); - } - } diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptSchema.java b/core/src/main/java/org/polypheny/db/plan/AlgOptSchema.java index 31ced7dbd2..56da14f4ed 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptSchema.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptSchema.java @@ -34,24 +34,9 @@ package org.polypheny.db.plan; -import java.util.List; -import org.polypheny.db.catalog.entity.logical.LogicalTable; - - /** - * A RelOptSchema is a set of {@link AlgOptEntity} objects. + * A RelOptSchema is a set of objects. */ public interface AlgOptSchema { - /** - * Retrieves a {@link AlgOptEntity} based upon a member access. - * - * For example, the Saffron expression salesSchema.emps would be resolved using a call to salesSchema.getTableForMember(new String[]{"emps" }). - * - * Note that name.length is only greater than 1 for queries originating from JDBC. - * - * @param names Qualified name - */ - LogicalTable getTableForMember( List names ); - } diff --git a/core/src/main/java/org/polypheny/db/plan/Context.java b/core/src/main/java/org/polypheny/db/plan/Context.java index 810804d84e..437eb438fb 100644 --- a/core/src/main/java/org/polypheny/db/plan/Context.java +++ b/core/src/main/java/org/polypheny/db/plan/Context.java @@ -34,7 +34,7 @@ package org.polypheny.db.plan; -import org.polypheny.db.schema.Wrapper; +import org.polypheny.db.util.Wrapper; /** diff --git a/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java b/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java index 8d5f65dd7c..ec1e8cb99a 100644 --- a/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java +++ b/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java @@ -54,7 +54,7 @@ import org.polypheny.db.algebra.core.AlgFactories; import org.polypheny.db.algebra.metadata.AlgMetadataProvider; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; -import org.polypheny.db.plan.AbstractRelOptPlanner; +import org.polypheny.db.plan.AbstractAlgOptPlanner; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptCostFactory; import org.polypheny.db.plan.AlgOptCostImpl; @@ -81,7 +81,7 @@ /** * HepPlanner is a heuristic implementation of the {@link AlgOptPlanner} interface. */ -public class HepPlanner extends AbstractRelOptPlanner { +public class HepPlanner extends AbstractAlgOptPlanner { private final HepProgram mainProgram; @@ -151,7 +151,7 @@ public HepPlanner( HepProgram program, Context context, boolean noDag, Function2 // implement RelOptPlanner @Override public void setRoot( AlgNode alg ) { - root = addRelToGraph( alg ); + root = addAlgToGraph( alg ); dumpGraph(); } @@ -686,7 +686,7 @@ private HepAlgVertex applyTransformationResults( HepAlgVertex vertex, HepRuleCal parents.add( parent ); } - HepAlgVertex newVertex = addRelToGraph( bestRel ); + HepAlgVertex newVertex = addAlgToGraph( bestRel ); // There's a chance that newVertex is the same as one of the parents due to common subexpression recognition (e.g. the LogicalProject added by JoinCommuteRule). In that // case, treat the transformation as a nop to avoid creating a loop. @@ -734,7 +734,7 @@ public boolean isRegistered( AlgNode alg ) { } - private HepAlgVertex addRelToGraph( AlgNode alg ) { + private HepAlgVertex addAlgToGraph( AlgNode alg ) { // Check if a transformation already produced a reference to an existing vertex. if ( graph.vertexSet().contains( alg ) ) { return (HepAlgVertex) alg; @@ -744,7 +744,7 @@ private HepAlgVertex addRelToGraph( AlgNode alg ) { final List inputs = alg.getInputs(); final List newInputs = new ArrayList<>(); for ( AlgNode input1 : inputs ) { - HepAlgVertex childVertex = addRelToGraph( input1 ); + HepAlgVertex childVertex = addAlgToGraph( input1 ); newInputs.add( childVertex ); } diff --git a/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java index 67f7888376..cceddcd16a 100644 --- a/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java +++ b/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java @@ -82,7 +82,7 @@ import org.polypheny.db.algebra.rules.UnionToDistinctRule; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.plan.AbstractRelOptPlanner; +import org.polypheny.db.plan.AbstractAlgOptPlanner; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptCostFactory; import org.polypheny.db.plan.AlgOptListener; @@ -108,7 +108,7 @@ * VolcanoPlanner optimizes queries by transforming expressions selectively according to a dynamic programming algorithm. */ @Slf4j -public class VolcanoPlanner extends AbstractRelOptPlanner { +public class VolcanoPlanner extends AbstractAlgOptPlanner { protected static final double COST_IMPROVEMENT = .5; diff --git a/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbCatalogReader.java b/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbCatalogReader.java deleted file mode 100644 index 91f059b293..0000000000 --- a/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbCatalogReader.java +++ /dev/null @@ -1,150 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.prepare; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import lombok.NonNull; -import org.apache.commons.lang3.NotImplementedException; -import org.polypheny.db.algebra.constant.FunctionCategory; -import org.polypheny.db.algebra.constant.MonikerType; -import org.polypheny.db.algebra.constant.Syntax; -import org.polypheny.db.algebra.operators.OperatorTable; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.logical.LogicalCollection; -import org.polypheny.db.catalog.entity.logical.LogicalGraph; -import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.catalog.snapshot.Snapshot; -import org.polypheny.db.nodes.Identifier; -import org.polypheny.db.nodes.Operator; -import org.polypheny.db.schema.Wrapper; -import org.polypheny.db.util.Moniker; -import org.polypheny.db.util.MonikerImpl; -import org.polypheny.db.util.ValidatorUtil; - - -/** - * Implementation of {@link Prepare.CatalogReader} and also {@link OperatorTable} based on - * tables and functions defined schemas. - */ -public class PolyphenyDbCatalogReader implements Prepare.CatalogReader { - - protected final Snapshot snapshot; - protected final AlgDataTypeFactory typeFactory; - - - public PolyphenyDbCatalogReader( @NonNull Snapshot snapshot, AlgDataTypeFactory typeFactory ) { - this.snapshot = snapshot; - this.typeFactory = typeFactory; - } - - - @Override - public LogicalTable getTable( final List names ) { - throw new NotImplementedException(); - } - - - @Override - public LogicalCollection getCollection( final List names ) { - throw new NotImplementedException(); - } - - - @Override - public LogicalGraph getGraph( final String name ) { - throw new NotImplementedException(); - } - - - @Override - public AlgDataType getNamedType( Identifier typeName ) { - throw new NotImplementedException(); - } - - - @Override - public List getAllSchemaObjectNames( List names ) { - final List result = new ArrayList<>(); - for ( String subSchema : snapshot.getNamespaces( null ).stream().map( n -> n.name ).collect( Collectors.toList() ) ) { - result.add( moniker( subSchema, MonikerType.SCHEMA ) ); - } - - return result; - } - - - private Moniker moniker( String name, MonikerType type ) { - /*final List path = schema.path( name ); - if ( path.size() == 1 && !schema.root().getName().equals( "" ) && type == MonikerType.SCHEMA ) { - type = MonikerType.CATALOG; - }*/ - return new MonikerImpl( name, type ); - } - - - @Override - public LogicalTable getTableForMember( List names ) { - return getTable( names ); - } - - - @Override - public AlgDataType createTypeFromProjection( final AlgDataType type, final List columnNameList ) { - return ValidatorUtil.createTypeFromProjection( type, columnNameList, typeFactory, Wrapper.nameMatcher.isCaseSensitive() ); - } - - - @Override - public void lookupOperatorOverloads( Identifier opName, FunctionCategory category, Syntax syntax, List operatorList ) { - throw new UnsupportedOperationException( "This operation is not longer supported" ); - } - - - @Override - public List getOperatorList() { - return null; - } - - - @Override - public Snapshot getSnapshot() { - return snapshot; - } - - -} - 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 24dbae28de..1d8496494f 100644 --- a/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java +++ b/core/src/main/java/org/polypheny/db/prepare/PolyphenyDbPrepareImpl.java @@ -41,14 +41,10 @@ import java.sql.Types; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import org.apache.calcite.avatica.ColumnMetaData; import org.apache.calcite.avatica.ColumnMetaData.AvaticaType; import org.apache.calcite.avatica.ColumnMetaData.Rep; -import org.apache.calcite.avatica.Meta.CursorFactory; -import org.apache.calcite.linq4j.Linq4j; import org.apache.calcite.linq4j.tree.BinaryExpression; import org.apache.calcite.linq4j.tree.BlockStatement; import org.apache.calcite.linq4j.tree.Blocks; @@ -61,15 +57,6 @@ import org.apache.calcite.linq4j.tree.ParameterExpression; import org.polypheny.db.adapter.java.JavaTypeFactory; import org.polypheny.db.algebra.AlgCollationTraitDef; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.AlgRoot; -import org.polypheny.db.algebra.constant.ExplainFormat; -import org.polypheny.db.algebra.constant.ExplainLevel; -import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.algebra.enumerable.EnumerableAlg; -import org.polypheny.db.algebra.enumerable.EnumerableAlg.Prefer; -import org.polypheny.db.algebra.enumerable.EnumerableCalc; -import org.polypheny.db.algebra.enumerable.EnumerableInterpretable; import org.polypheny.db.algebra.enumerable.EnumerableInterpreterRule; import org.polypheny.db.algebra.enumerable.EnumerableRules; import org.polypheny.db.algebra.enumerable.RexToLixTranslator; @@ -106,22 +93,15 @@ import org.polypheny.db.algebra.rules.ValuesReduceRule; import org.polypheny.db.algebra.stream.StreamRules; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.interpreter.BindableConvention; import org.polypheny.db.interpreter.Bindables; -import org.polypheny.db.interpreter.Interpreters; -import org.polypheny.db.languages.NodeToAlgConverter; import org.polypheny.db.languages.OperatorRegistry; -import org.polypheny.db.languages.QueryLanguage; -import org.polypheny.db.languages.RexConvertletTable; import org.polypheny.db.nodes.BinaryOperator; import org.polypheny.db.nodes.ExecutableStatement; import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; -import org.polypheny.db.nodes.validate.Validator; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCostFactory; import org.polypheny.db.plan.AlgOptPlanner; @@ -129,26 +109,16 @@ import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Contexts; -import org.polypheny.db.plan.Convention; import org.polypheny.db.plan.ConventionTraitDef; import org.polypheny.db.plan.volcano.VolcanoPlanner; import org.polypheny.db.plan.volcano.VolcanoPlannerPhase; -import org.polypheny.db.prepare.Prepare.PreparedExplain; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexNode; -import org.polypheny.db.rex.RexProgram; -import org.polypheny.db.runtime.Bindable; import org.polypheny.db.runtime.Hook; -import org.polypheny.db.runtime.Typed; -import org.polypheny.db.schema.PolyphenyDbSchema; import org.polypheny.db.schema.trait.ModelTraitDef; import org.polypheny.db.tools.Frameworks.PrepareAction; import org.polypheny.db.type.ExtraPolyTypes; import org.polypheny.db.type.PolyType; -import org.polypheny.db.type.entity.PolyString; -import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.util.Conformance; -import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; @@ -321,7 +291,6 @@ protected AlgOptPlanner createPlanner( final Context prepareContext, org.polyphe planner.addRule( preProcessRule, VolcanoPlannerPhase.PRE_PROCESS ); } - for ( AlgOptRule rule : DEFAULT_RULES ) { planner.addRule( rule ); } @@ -495,182 +464,6 @@ public R perform( PrepareAction action ) { } - /** - * Holds state for the process of preparing a SQL statement. - */ - public static class PolyphenyDbPreparingStmt extends Prepare { - - protected final AlgOptPlanner planner; - protected final RexBuilder rexBuilder; - protected final PolyphenyDbPrepareImpl prepare; - protected final PolyphenyDbSchema schema; - protected final AlgDataTypeFactory typeFactory; - protected final RexConvertletTable convertletTable; - private final Prefer prefer; - private final Map internalParameters = new LinkedHashMap<>(); - private int expansionDepth; - private Validator sqlValidator; - - - PolyphenyDbPreparingStmt( - PolyphenyDbPrepareImpl prepare, - Context context, - Snapshot snapshot, - AlgDataTypeFactory typeFactory, - PolyphenyDbSchema schema, - Prefer prefer, - AlgOptPlanner planner, - Convention resultConvention, - RexConvertletTable convertletTable ) { - super( context, snapshot, resultConvention ); - this.prepare = prepare; - this.schema = schema; - this.prefer = prefer; - this.planner = planner; - this.typeFactory = typeFactory; - this.convertletTable = convertletTable; - this.rexBuilder = new RexBuilder( typeFactory ); - } - - - @Override - protected void init( Class runtimeContextClass ) { - } - - - @Override - public AlgNode flattenTypes( AlgNode rootRel, boolean restructure ) { - return rootRel; - } - - - @Override - protected AlgNode decorrelate( NodeToAlgConverter sqlToRelConverter, Node query, AlgNode rootRel ) { - return sqlToRelConverter.decorrelate( query, rootRel ); - } - - - protected Validator createSqlValidator( Snapshot snapshot ) { - return QueryLanguage.from( "sql" ).getValidatorSupplier().apply( context, snapshot ); - } - - - @Override - protected Validator getSqlValidator() { - if ( sqlValidator == null ) { - sqlValidator = createSqlValidator( snapshot ); - } - return sqlValidator; - } - - - @Override - protected PreparedResult createPreparedExplanation( AlgDataType resultType, AlgDataType parameterRowType, AlgRoot root, ExplainFormat format, ExplainLevel detailLevel ) { - return new PolyphenyDbPreparedExplain( resultType, parameterRowType, root, format, detailLevel ); - } - - - @Override - protected PreparedResult implement( AlgRoot root ) { - AlgDataType resultType = root.alg.getRowType(); - boolean isDml = root.kind.belongsTo( Kind.DML ); - final Bindable bindable; - final String generatedCode; - if ( resultConvention == BindableConvention.INSTANCE ) { - bindable = Interpreters.bindable( root.alg ); - generatedCode = null; - } else { - EnumerableAlg enumerable = (EnumerableAlg) root.alg; - if ( !root.isRefTrivial() ) { - final List projects = new ArrayList<>(); - final RexBuilder rexBuilder = enumerable.getCluster().getRexBuilder(); - for ( int field : Pair.left( root.fields ) ) { - projects.add( rexBuilder.makeInputRef( enumerable, field ) ); - } - RexProgram program = RexProgram.create( - enumerable.getRowType(), - projects, - null, - root.validatedRowType, - rexBuilder ); - enumerable = EnumerableCalc.create( enumerable, program ); - } - - try { - CatalogReader.THREAD_LOCAL.set( snapshot ); - final Conformance conformance = context.config().conformance(); - internalParameters.put( "_conformance", PolyString.of( conformance.toString() ) ); - Pair, String> implementationPair = EnumerableInterpretable.toBindable( - internalParameters, - enumerable, - prefer, - null ); - bindable = implementationPair.left; - generatedCode = implementationPair.right; - } finally { - CatalogReader.THREAD_LOCAL.remove(); - } - } - - if ( timingTracer != null ) { - timingTracer.traceTime( "end codegen" ); - } - - if ( timingTracer != null ) { - timingTracer.traceTime( "end compilation" ); - } - - return new PreparedResultImpl<>( - resultType, - parameterRowType, - fieldOrigins, - root.collation.getFieldCollations().isEmpty() - ? ImmutableList.of() - : ImmutableList.of( root.collation ), - root.alg, - mapTableModOp( isDml, root.kind ), - isDml ) { - @Override - public String getCode() { - return generatedCode; - } - - - @Override - public Bindable getBindable( CursorFactory cursorFactory ) { - return bindable; - } - - - @Override - public Type getElementType() { - return ((Typed) bindable).getElementType(); - } - }; - } - - } - - - /** - * An {@code EXPLAIN} statement, prepared and ready to execute. - */ - private static class PolyphenyDbPreparedExplain extends PreparedExplain { - - PolyphenyDbPreparedExplain( AlgDataType resultType, AlgDataType parameterRowType, AlgRoot root, ExplainFormat format, ExplainLevel detailLevel ) { - super( resultType, parameterRowType, root, format, detailLevel ); - } - - - @Override - public Bindable getBindable( final CursorFactory cursorFactory ) { - final String explanation = getCode(); - return dataContext -> Linq4j.singletonEnumerable( new PolyValue[]{ PolyString.of( explanation ) } ); - } - - } - - /** * Translator from Java AST to {@link RexNode}. */ diff --git a/core/src/main/java/org/polypheny/db/prepare/Prepare.java b/core/src/main/java/org/polypheny/db/prepare/Prepare.java index a308129905..5db1ab4d77 100644 --- a/core/src/main/java/org/polypheny/db/prepare/Prepare.java +++ b/core/src/main/java/org/polypheny/db/prepare/Prepare.java @@ -47,24 +47,15 @@ import org.polypheny.db.algebra.AlgVisitor; import org.polypheny.db.algebra.constant.ExplainFormat; import org.polypheny.db.algebra.constant.ExplainLevel; -import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; -import org.polypheny.db.algebra.operators.OperatorTable; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.logical.LogicalCollection; -import org.polypheny.db.catalog.entity.logical.LogicalGraph; -import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.NodeToAlgConverter; import org.polypheny.db.nodes.Node; -import org.polypheny.db.nodes.validate.Validator; -import org.polypheny.db.nodes.validate.ValidatorCatalogReader; import org.polypheny.db.nodes.validate.ValidatorTable; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptPlanner; -import org.polypheny.db.plan.AlgOptSchema; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; @@ -78,7 +69,6 @@ import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Holder; import org.polypheny.db.util.TryThreadLocal; -import org.polypheny.db.util.trace.PolyphenyDbTimingTracer; import org.polypheny.db.util.trace.PolyphenyDbTrace; import org.slf4j.Logger; @@ -96,12 +86,6 @@ public abstract class Prepare { * Convention via which results should be returned by execution. */ protected final Convention resultConvention; - protected PolyphenyDbTimingTracer timingTracer; - protected List> fieldOrigins; - protected AlgDataType parameterRowType; - - // temporary. for testing. - public static final TryThreadLocal THREAD_TRIM = TryThreadLocal.of( false ); /** * Temporary, until "Decorrelate sub-queries in Project and Join" is fixed. @@ -120,14 +104,6 @@ public Prepare( Context context, Snapshot snapshot, Convention resultConvention } - protected abstract PreparedResult createPreparedExplanation( - AlgDataType resultType, - AlgDataType parameterRowType, - AlgRoot root, - ExplainFormat format, - ExplainLevel detailLevel ); - - /** * Optimizes a query plan. * @@ -199,58 +175,11 @@ protected AlgTraitSet getDesiredRootTraitSet( AlgRoot root ) { protected abstract PreparedResult implement( AlgRoot root ); - protected LogicalRelModify.Operation mapTableModOp( boolean isDml, Kind Kind ) { - if ( !isDml ) { - return null; - } - switch ( Kind ) { - case INSERT: - return Modify.Operation.INSERT; - case DELETE: - return Modify.Operation.DELETE; - case MERGE: - return Modify.Operation.MERGE; - case UPDATE: - return Modify.Operation.UPDATE; - default: - return null; - } - } - - - /** - * Protected method to allow subclasses to override construction of SqlToRelConverter. - */ - //protected abstract NodeToAlgConverter getSqlToRelConverter( Validator validator, CatalogReader catalogReader, NodeToAlgConverter.Config config ); - public abstract AlgNode flattenTypes( AlgNode rootRel, boolean restructure ); - protected abstract AlgNode decorrelate( NodeToAlgConverter sqlToRelConverter, Node query, AlgNode rootRel ); protected abstract void init( Class runtimeContextClass ); - protected abstract Validator getSqlValidator(); - - - /** - * Interface by which validator and planner can read table metadata. - */ - public interface CatalogReader extends AlgOptSchema, ValidatorCatalogReader, OperatorTable { - - @Override - LogicalTable getTableForMember( List names ); - - @Override - LogicalTable getTable( List names ); - - LogicalCollection getCollection( List names ); - - LogicalGraph getGraph( String name ); - - ThreadLocal THREAD_LOCAL = new ThreadLocal<>(); - - } - /** * Definition of a table, for the purposes of the validator and planner. diff --git a/core/src/main/java/org/polypheny/db/schema/Entity.java b/core/src/main/java/org/polypheny/db/schema/Entity.java index d7207455fb..325daeb007 100644 --- a/core/src/main/java/org/polypheny/db/schema/Entity.java +++ b/core/src/main/java/org/polypheny/db/schema/Entity.java @@ -39,6 +39,7 @@ import org.polypheny.db.nodes.Call; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.JavaTypeFactoryImpl; +import org.polypheny.db.util.Wrapper; /** diff --git a/core/src/main/java/org/polypheny/db/schema/Namespace.java b/core/src/main/java/org/polypheny/db/schema/Namespace.java index bd2194a48e..5c965f3fb4 100644 --- a/core/src/main/java/org/polypheny/db/schema/Namespace.java +++ b/core/src/main/java/org/polypheny/db/schema/Namespace.java @@ -41,6 +41,7 @@ import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.Convention; +import org.polypheny.db.util.Wrapper; /** diff --git a/core/src/main/java/org/polypheny/db/schema/Wrapper.java b/core/src/main/java/org/polypheny/db/schema/Wrapper.java deleted file mode 100644 index c2e6df31ff..0000000000 --- a/core/src/main/java/org/polypheny/db/schema/Wrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019-2020 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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.schema; - - -import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.util.NameMatcher; -import org.polypheny.db.util.NameMatchers; - -/** - * Mix-in interface that allows you to find sub-objects. - */ -public interface Wrapper { - - NameMatcher nameMatcher = NameMatchers.withCaseSensitive( RuntimeConfig.RELATIONAL_CASE_SENSITIVE.getBoolean() ); - - default C unwrap( Class aClass ) { - if ( aClass.isInstance( this ) ) { - return aClass.cast( this ); - } - return null; - } - -} - diff --git a/core/src/main/java/org/polypheny/db/schema/graph/Graph.java b/core/src/main/java/org/polypheny/db/schema/graph/Graph.java index ecee967ee3..e8cd700ee0 100644 --- a/core/src/main/java/org/polypheny/db/schema/graph/Graph.java +++ b/core/src/main/java/org/polypheny/db/schema/graph/Graph.java @@ -18,7 +18,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.GraphType; -import org.polypheny.db.schema.Wrapper; +import org.polypheny.db.util.Wrapper; public interface Graph extends Wrapper { diff --git a/core/src/main/java/org/polypheny/db/schema/graph/ModifiableGraph.java b/core/src/main/java/org/polypheny/db/schema/graph/ModifiableGraph.java deleted file mode 100644 index 51477d0262..0000000000 --- a/core/src/main/java/org/polypheny/db/schema/graph/ModifiableGraph.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019-2022 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.schema.graph; - -import java.util.List; -import org.apache.calcite.linq4j.tree.Expression; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.core.common.Modify.Operation; -import org.polypheny.db.algebra.core.lpg.LpgModify; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.logical.LogicalGraph; -import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.prepare.PolyphenyDbCatalogReader; -import org.polypheny.db.rex.RexNode; -import org.polypheny.db.schema.SchemaPlus; -import org.polypheny.db.schema.Statistic; - - -public interface ModifiableGraph { - - LpgModify toModificationAlg( AlgOptCluster cluster, AlgTraitSet traits, LogicalGraph graph, PolyphenyDbCatalogReader catalogReader, AlgNode input, Operation operation, List ids, List operations ); - - Expression getExpression( SchemaPlus schema, String tableName, Class clazz ); - - AlgDataType getRowType( AlgDataTypeFactory typeFactory ); - - Statistic getStatistic(); - -} diff --git a/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java b/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java index cf7fc9cc6d..605fbcba73 100644 --- a/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java +++ b/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntity.java @@ -43,7 +43,7 @@ import org.polypheny.db.schema.Statistic; import org.polypheny.db.schema.Statistics; import org.polypheny.db.schema.TableType; -import org.polypheny.db.schema.Wrapper; +import org.polypheny.db.util.Wrapper; /** diff --git a/core/src/main/java/org/polypheny/db/util/Wrapper.java b/core/src/main/java/org/polypheny/db/util/Wrapper.java new file mode 100644 index 0000000000..d3bf87119e --- /dev/null +++ b/core/src/main/java/org/polypheny/db/util/Wrapper.java @@ -0,0 +1,35 @@ +/* + * 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.util; + + +import org.jetbrains.annotations.Nullable; + +/** + * Mix-in interface that allows you to find sub-objects. + */ +public interface Wrapper { + + default @Nullable C unwrap( Class aClass ) { + if ( aClass.isInstance( this ) ) { + return aClass.cast( this ); + } + return null; + } + +} + diff --git a/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java b/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java deleted file mode 100644 index 74036bb788..0000000000 --- a/core/src/test/java/org/polypheny/db/catalog/CompoundNameColumnResolver.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2019-2021 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.catalog; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import org.apache.calcite.linq4j.Ord; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; -import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.util.Pair; - - -/** - * ColumnResolver implementation that resolves CompoundNameColumn by simulating Phoenix behaviors. - */ -final class CompoundNameColumnResolver implements MockCatalogReader.ColumnResolver { - - private final Map nameMap = new HashMap<>(); - private final Map> groupMap = new HashMap<>(); - private final String defaultColumnGroup; - - - CompoundNameColumnResolver( List columns, String defaultColumnGroup ) { - this.defaultColumnGroup = defaultColumnGroup; - for ( Ord column : Ord.zip( columns ) ) { - nameMap.put( column.e.getName(), column.i ); - Map subMap = groupMap.computeIfAbsent( column.e.first, k -> new HashMap<>() ); - subMap.put( column.e.second, column.i ); - } - } - - - @Override - public List>> resolveColumn( AlgDataType rowType, AlgDataTypeFactory typeFactory, List names ) { - List>> ret = new ArrayList<>(); - if ( names.size() >= 2 ) { - Map subMap = groupMap.get( names.get( 0 ) ); - if ( subMap != null ) { - Integer index = subMap.get( names.get( 1 ) ); - if ( index != null ) { - ret.add( new Pair<>( rowType.getFields().get( index ), names.subList( 2, names.size() ) ) ); - } - } - } - - final String columnName = names.get( 0 ); - final List remainder = names.subList( 1, names.size() ); - Integer index = nameMap.get( columnName ); - if ( index != null ) { - ret.add( new Pair<>( rowType.getFields().get( index ), remainder ) ); - return ret; - } - - final List priorityGroups = Arrays.asList( "", defaultColumnGroup ); - for ( String group : priorityGroups ) { - Map subMap = groupMap.get( group ); - if ( subMap != null ) { - index = subMap.get( columnName ); - if ( index != null ) { - ret.add( new Pair<>( rowType.getFields().get( index ), remainder ) ); - return ret; - } - } - } - for ( Map.Entry> entry : groupMap.entrySet() ) { - if ( priorityGroups.contains( entry.getKey() ) ) { - continue; - } - index = entry.getValue().get( columnName ); - if ( index != null ) { - ret.add( new Pair<>( rowType.getFields().get( index ), remainder ) ); - } - } - - if ( ret.isEmpty() && names.size() == 1 ) { - Map subMap = groupMap.get( columnName ); - if ( subMap != null ) { - List> entries = new ArrayList<>( subMap.entrySet() ); - entries.sort( ( o1, o2 ) -> o1.getValue() - o2.getValue() ); - ret.add( new Pair<>( new AlgDataTypeFieldImpl( -1L, columnName, -1, createStructType( rowType, typeFactory, entries ) ), remainder ) ); - } - } - - return ret; - } - - - private static AlgDataType createStructType( final AlgDataType rowType, AlgDataTypeFactory typeFactory, final List> entries ) { - return typeFactory.createStructType( - StructKind.PEEK_FIELDS, - rowType.getFields().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), - entries.stream().map( e -> rowType.getFields().get( e.getValue() ).getType() ).collect( Collectors.toList() ), - entries.stream().map( Entry::getKey ).collect( Collectors.toList() ) ); - } - -} - diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java deleted file mode 100644 index 941283a3d8..0000000000 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java +++ /dev/null @@ -1,629 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.catalog; - - -import com.google.common.collect.ImmutableList; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.polypheny.db.algebra.AlgCollation; -import org.polypheny.db.algebra.AlgCollations; -import org.polypheny.db.algebra.AlgDistribution; -import org.polypheny.db.algebra.AlgDistributions; -import org.polypheny.db.algebra.AlgFieldCollation; -import org.polypheny.db.algebra.AlgReferentialConstraint; -import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.algebra.constant.Monotonicity; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.algebra.type.DynamicRecordTypeImpl; -import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.catalog.entity.LogicalEntity; -import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.nodes.Call; -import org.polypheny.db.nodes.Node; -import org.polypheny.db.prepare.PolyphenyDbCatalogReader; -import org.polypheny.db.prepare.Prepare.PreparingEntity; -import org.polypheny.db.schema.CustomColumnResolvingEntity; -import org.polypheny.db.schema.Entity; -import org.polypheny.db.schema.Statistic; -import org.polypheny.db.schema.TableType; -import org.polypheny.db.schema.Wrapper; -import org.polypheny.db.schema.types.StreamableEntity; -import org.polypheny.db.util.ImmutableBitSet; -import org.polypheny.db.util.InitializerExpressionFactory; -import org.polypheny.db.util.NullInitializerExpressionFactory; -import org.polypheny.db.util.Pair; -import org.polypheny.db.util.Util; - - -/** - * Mock implementation of {#@link SqlValidatorCatalogReader} which returns tables "EMP", "DEPT", "BONUS", "SALGRADE" (same as Oracle's SCOTT schema). - * Also two streams "ORDERS", "SHIPMENTS"; and a view "EMP_20". - */ -public abstract class MockCatalogReader extends PolyphenyDbCatalogReader { - - static final String DEFAULT_CATALOG = "CATALOG"; - static final String DEFAULT_SCHEMA = "SALES"; - static final List PREFIX = ImmutableList.of( DEFAULT_SCHEMA ); - - - /** - * Creates a MockCatalogReader. - * - * Caller must then call {@link #init} to populate with data. - * - * @param typeFactory Type factory - */ - public MockCatalogReader( AlgDataTypeFactory typeFactory, boolean caseSensitive ) { - super( - Catalog.snapshot(), - typeFactory ); - } - - - /** - * Initializes this catalog reader. - */ - public abstract MockCatalogReader init(); - - - protected void registerTablesWithRollUp( MockSchema schema, Fixture f ) { - // Register "EMP_R" table. Contains a rolled up column. - final MockEntity empRolledTable = MockEntity.create( this, schema, "EMP_R", false, 14 ); - empRolledTable.addColumn( "EMPNO", f.intType, true ); - empRolledTable.addColumn( "DEPTNO", f.intType ); - empRolledTable.addColumn( "SLACKER", f.booleanType ); - empRolledTable.addColumn( "SLACKINGMIN", f.intType ); - empRolledTable.registerRolledUpColumn( "SLACKINGMIN" ); - registerTable( empRolledTable ); - - // Register the "DEPT_R" table. Doesn't contain a rolled up column, - // but is useful for testing join - MockEntity deptSlackingTable = MockEntity.create( this, schema, "DEPT_R", false, 4 ); - deptSlackingTable.addColumn( "DEPTNO", f.intType, true ); - deptSlackingTable.addColumn( "SLACKINGMIN", f.intType ); - registerTable( deptSlackingTable ); - - // Register nested schema NEST that contains table with a rolled up column. - MockSchema nestedSchema = new MockSchema( "NEST" ); - registerNestedSchema( schema, nestedSchema, -1 ); - - // Register "EMP_R" table which contains a rolled up column in NEST schema. - ImmutableList tablePath = ImmutableList.of( schema.getCatalogName(), schema.name, nestedSchema.name, "EMP_R" ); - final MockEntity nestedEmpRolledTable = MockEntity.create( this, tablePath, false, 14 ); - nestedEmpRolledTable.addColumn( "EMPNO", f.intType, true ); - nestedEmpRolledTable.addColumn( "DEPTNO", f.intType ); - nestedEmpRolledTable.addColumn( "SLACKER", f.booleanType ); - nestedEmpRolledTable.addColumn( "SLACKINGMIN", f.intType ); - nestedEmpRolledTable.registerRolledUpColumn( "SLACKINGMIN" ); - registerTable( nestedEmpRolledTable ); - } - - - protected void registerType( final List names, final AlgProtoDataType algProtoDataType ) { - assert names.get( 0 ).equals( DEFAULT_CATALOG ); - final List schemaPath = Util.skipLast( names ); - //final PolyphenyDbSchema schema = ValidatorUtil.getNamespace( snapshot, schemaPath, NameMatchers.withCaseSensitive( true ) ); - //schema.add( Util.last( names ), algProtoDataType ); - } - - - protected void registerTable( final MockEntity table ) { - table.onRegister( typeFactory ); - final WrapperEntity wrapperTable = new WrapperEntity( table ); - if ( table.stream ) { - registerTable( - table.names, - new StreamableWrapperEntity( table ) { - @Override - public Entity stream() { - return wrapperTable; - } - } ); - } else { - registerTable( table.names, wrapperTable ); - } - } - - - private void registerTable( final List names, final Entity entity ) { - assert names.get( 0 ).equals( DEFAULT_CATALOG ); - final List schemaPath = Util.skipLast( names ); - final String tableName = Util.last( names ); - //final PolyphenyDbSchema schema = ValidatorUtil.getNamespace( snapshot, schemaPath, NameMatchers.withCaseSensitive( true ) ); - //schema.add( tableName, entity ); - } - - - protected void registerSchema( MockSchema schema, long id ) { - //rootSchema.add( schema.name, new AbstractNamespace( id ), NamespaceType.RELATIONAL ); - } - - - private void registerNestedSchema( MockSchema parentSchema, MockSchema schema, long id ) { - //rootSchema.getSubNamespace( parentSchema.getName(), true ).add( schema.name, new AbstractNamespace( id ), NamespaceType.RELATIONAL ); - } - - - private static List deduceMonotonicity( LogicalEntity table ) { - final List collationList = new ArrayList<>(); - - // Deduce which fields the table is sorted on. - int i = -1; - for ( AlgDataTypeField field : table.getRowType().getFields() ) { - ++i; - final Monotonicity monotonicity = Util.getMonotonicity( table, field.getName() ); - if ( monotonicity != Monotonicity.NOT_MONOTONIC ) { - final AlgFieldCollation.Direction direction = - monotonicity.isDecreasing() - ? AlgFieldCollation.Direction.DESCENDING - : AlgFieldCollation.Direction.ASCENDING; - collationList.add( AlgCollations.of( new AlgFieldCollation( i, direction ) ) ); - } - } - return collationList; - } - - - /** - * Column resolver - */ - public interface ColumnResolver { - - List>> resolveColumn( AlgDataType rowType, AlgDataTypeFactory typeFactory, List names ); - - } - - - /** - * Mock schema. - */ - public static class MockSchema { - - private final List tableNames = new ArrayList<>(); - private String name; - - - public MockSchema( String name ) { - this.name = name; - } - - - public void addTable( String name ) { - tableNames.add( name ); - } - - - public String getCatalogName() { - return DEFAULT_CATALOG; - } - - - public String getName() { - return name; - } - - } - - - /** - * Mock implementation of - * {@link PreparingEntity}. - */ - public static class MockEntity extends LogicalTable { - - protected final MockCatalogReader catalogReader; - protected final boolean stream; - protected final double rowCount; - protected final List> columnList = new ArrayList<>(); - protected final List keyList = new ArrayList<>(); - protected final List referentialConstraints = new ArrayList<>(); - protected AlgDataType rowType; - protected List collationList; - protected final List names; - protected final Set monotonicColumnSet = new HashSet<>(); - protected StructKind kind = StructKind.FULLY_QUALIFIED; - protected final ColumnResolver resolver; - protected final InitializerExpressionFactory initializerFactory; - protected final Set rolledUpColumns = new HashSet<>(); - - - public MockEntity( - MockCatalogReader catalogReader, String catalogName, String schemaName, String name, boolean stream, double rowCount, - ColumnResolver resolver, InitializerExpressionFactory initializerFactory ) { - this( catalogReader, ImmutableList.of( catalogName, schemaName, name ), stream, rowCount, resolver, initializerFactory ); - } - - - public void registerRolledUpColumn( String columnName ) { - rolledUpColumns.add( columnName ); - } - - - private MockEntity( MockCatalogReader catalogReader, List names, boolean stream, double rowCount, ColumnResolver resolver, InitializerExpressionFactory initializerFactory ) { - super( -1, Util.last( names ), -1, EntityType.ENTITY, null, true ); - this.catalogReader = catalogReader; - this.stream = stream; - this.rowCount = rowCount; - this.names = names; - this.resolver = resolver; - this.initializerFactory = initializerFactory; - } - - - /** - * Copy constructor. - */ - protected MockEntity( - MockCatalogReader catalogReader, boolean stream, double rowCount, List> columnList, List keyList, AlgDataType rowType, List collationList, - List names, Set monotonicColumnSet, StructKind kind, ColumnResolver resolver, InitializerExpressionFactory initializerFactory ) { - super( -1, Util.last( names ), -1, EntityType.ENTITY, null, true ); - this.catalogReader = catalogReader; - this.stream = stream; - this.rowCount = rowCount; - this.rowType = rowType; - this.collationList = collationList; - this.names = names; - this.kind = kind; - this.resolver = resolver; - this.initializerFactory = initializerFactory; - for ( String name : monotonicColumnSet ) { - addMonotonic( name ); - } - } - - - /** - * Implementation of AbstractModifiableTable. - */ - private class ModifiableEntity extends LogicalTable implements Wrapper { - - protected ModifiableEntity( String tableName ) { - super( -1, Util.last( names ), -1, EntityType.ENTITY, null, true ); - - } - - - @Override - public C unwrap( Class aClass ) { - if ( aClass.isInstance( initializerFactory ) ) { - return aClass.cast( initializerFactory ); - } else if ( aClass.isInstance( MockEntity.this ) ) { - return aClass.cast( MockEntity.this ); - } - return super.unwrap( aClass ); - } - - - /*@Override - public Entity extend( final List fields ) { - return new ModifiableEntity( Util.last( names ) ) { - @Override - public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - ImmutableList allFields = ImmutableList.copyOf( Iterables.concat( ModifiableEntity.this.getRowType( typeFactory ).getFieldList(), fields ) ); - return typeFactory.createStructType( allFields ); - } - }; - }*/ - - - } - - - /*@Override - protected AlgOptEntity extend( final Entity extendedEntity ) { - return new MockEntity( catalogReader, names, stream, rowCount, resolver, initializerFactory ) { - @Override - public AlgDataType getRowType() { - return extendedEntity.getRowType( catalogReader.typeFactory ); - } - }; - }*/ - - - public static MockEntity create( MockCatalogReader catalogReader, MockSchema schema, String name, boolean stream, double rowCount ) { - return create( catalogReader, schema, name, stream, rowCount, null ); - } - - - public static MockEntity create( MockCatalogReader catalogReader, List names, boolean stream, double rowCount ) { - return new MockEntity( catalogReader, names, stream, rowCount, null, NullInitializerExpressionFactory.INSTANCE ); - } - - - public static MockEntity create( - MockCatalogReader catalogReader, - MockSchema schema, String name, boolean stream, double rowCount, - ColumnResolver resolver ) { - return create( catalogReader, schema, name, stream, rowCount, resolver, - NullInitializerExpressionFactory.INSTANCE ); - } - - - public static MockEntity create( MockCatalogReader catalogReader, MockSchema schema, String name, boolean stream, double rowCount, ColumnResolver resolver, InitializerExpressionFactory initializerExpressionFactory ) { - MockEntity table = new MockEntity( catalogReader, schema.getCatalogName(), schema.name, name, stream, rowCount, resolver, initializerExpressionFactory ); - schema.addTable( name ); - return table; - } - - - @Override - public T unwrap( Class clazz ) { - if ( clazz.isInstance( this ) ) { - return clazz.cast( this ); - } - if ( clazz.isInstance( initializerFactory ) ) { - return clazz.cast( initializerFactory ); - } - if ( clazz.isAssignableFrom( Entity.class ) ) { - final LogicalEntity entity = resolver == null - ? new ModifiableEntity( Util.last( names ) ) - : new ModifiableEntityWithCustomColumnResolving( Util.last( names ) ); - return clazz.cast( entity ); - } - return null; - } - - - @Override - public double getRowCount() { - return rowCount; - } - - - @Override - public AlgDistribution getDistribution() { - return AlgDistributions.BROADCAST_DISTRIBUTED; - } - - - @Override - public AlgDataType getRowType() { - return rowType; - } - - - public void onRegister( AlgDataTypeFactory typeFactory ) { - rowType = typeFactory.createStructType( kind, null, Pair.right( columnList ), Pair.left( columnList ) ); - collationList = deduceMonotonicity( this ); - } - - - public void addColumn( String name, AlgDataType type ) { - addColumn( name, type, false ); - } - - - public void addColumn( String name, AlgDataType type, boolean isKey ) { - if ( isKey ) { - keyList.add( columnList.size() ); - } - columnList.add( Pair.of( name, type ) ); - } - - - public void addMonotonic( String name ) { - monotonicColumnSet.add( name ); - assert Pair.left( columnList ).contains( name ); - } - - - public void setKind( StructKind kind ) { - this.kind = kind; - } - - - public StructKind getKind() { - return kind; - } - - - /** - * Subclass of {@link ModifiableEntity} that also implements {@link CustomColumnResolvingEntity}. - */ - private class ModifiableEntityWithCustomColumnResolving extends ModifiableEntity implements Wrapper { - - ModifiableEntityWithCustomColumnResolving( String tableName ) { - super( tableName ); - } - - - /*@Override - public List>> resolveColumn( AlgDataType rowType, AlgDataTypeFactory typeFactory, List names ) { - return resolver.resolveColumn( rowType, typeFactory, names ); - }*/ - - } - - } - - - /** - * Mock implementation of {@link PreparingEntity} with dynamic record type. - */ - public static class MockDynamicEntity extends MockEntity { - - public MockDynamicEntity( MockCatalogReader catalogReader, String catalogName, String schemaName, String name, boolean stream, double rowCount ) { - super( catalogReader, catalogName, schemaName, name, stream, rowCount, null, NullInitializerExpressionFactory.INSTANCE ); - } - - - @Override - public void onRegister( AlgDataTypeFactory typeFactory ) { - rowType = new DynamicRecordTypeImpl( typeFactory ); - } - - /** - * Recreates an immutable rowType, if the table has Dynamic Record Type, when converts table to Rel. - */ - /*@Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - if ( rowType.isDynamicStruct() ) { - rowType = new AlgRecordType( rowType.getFieldList() ); - } - return super.toAlg( context, traitSet ); - }*/ - - } - - - /** - * Wrapper around a {@link MockEntity}, giving it a {@link Entity} interface. You can get the {@code MockTable} by calling {@link #unwrap(Class)}. - */ - private static class WrapperEntity implements Entity, Wrapper { - - private final MockEntity table; - - - WrapperEntity( MockEntity table ) { - this.table = table; - } - - - @Override - public C unwrap( Class aClass ) { - return aClass.isInstance( this ) - ? aClass.cast( this ) - : aClass.isInstance( table ) - ? aClass.cast( table ) - : null; - } - - - @Override - public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - return table.getRowType(); - } - - - @Override - public Statistic getStatistic() { - return new Statistic() { - @Override - public Double getRowCount() { - return table.rowCount; - } - - - @Override - public boolean isKey( ImmutableBitSet columns ) { - return table.isKey( columns ); - } - - - @Override - public List getReferentialConstraints() { - return List.of(); - //return table.getReferentialConstraints(); - } - - - @Override - public List getCollations() { - return table.collationList; - } - - - @Override - public AlgDistribution getDistribution() { - return table.getDistribution(); - } - }; - } - - - @Override - public Long getId() { - throw new RuntimeException( "Method getTableId is not implemented." ); - } - - - @Override - public Long getPartitionId() { - throw new RuntimeException( "Method getTableId is not implemented." ); - } - - - @Override - public Long getAdapterId() { - return null; - } - - - @Override - public boolean isRolledUp( String column ) { - return table.rolledUpColumns.contains( column ); - } - - - @Override - public boolean rolledUpColumnValidInsideAgg( String column, Call call, Node parent ) { - // For testing - return call.getKind() != Kind.MAX && (parent.getKind() == Kind.SELECT || parent.getKind() == Kind.FILTER); - } - - - @Override - public TableType getJdbcTableType() { - return table.stream ? TableType.STREAM : TableType.TABLE; - } - - } - - - /** - * Wrapper around a {@link MockEntity}, giving it a {@link StreamableEntity} interface. - */ - private static class StreamableWrapperEntity extends WrapperEntity implements StreamableEntity { - - StreamableWrapperEntity( MockEntity table ) { - super( table ); - } - - - @Override - public Entity stream() { - return this; - } - - } - -} diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDocument.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDocument.java deleted file mode 100644 index 869d1dfc53..0000000000 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDocument.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019-2022 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.catalog; - -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.type.PolyType; - - -public class MockCatalogReaderDocument extends MockCatalogReaderSimple { - - /** - * Creates a MockCatalogReader. - * - * Caller must then call {@link #init} to populate with data. - * - * @param typeFactory Type factory - * @param caseSensitive case sensitivity - */ - public MockCatalogReaderDocument( AlgDataTypeFactory typeFactory, boolean caseSensitive ) { - super( typeFactory, caseSensitive ); - } - - - @Override - public MockCatalogReader init() { - Fixture fixture = getFixture(); - - // Register "SALES" schema. - MockSchema salesSchema = new MockSchema( "private" ); - registerSchema( salesSchema, -1 ); - - // Register "EMP" table. - final MockEntity empTable = MockEntity.create( this, salesSchema, "secrets", false, 14, null ); - - empTable.addColumn( "d", typeFactory.createPolyType( PolyType.DOCUMENT ) ); - registerTable( empTable ); - - registerTablesWithRollUp( salesSchema, fixture ); - return this; - } - -} diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDynamic.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDynamic.java deleted file mode 100644 index c76c753e0d..0000000000 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderDynamic.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2019-2021 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.catalog; - - -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.type.PolyType; - - -/** - * Registers dynamic tables. - * - * Not thread-safe. - */ -public class MockCatalogReaderDynamic extends MockCatalogReader { - - /** - * Creates a MockCatalogReader. - * - * Caller must then call {@link #init} to populate with data. - * - * @param typeFactory Type factory - * @param caseSensitive case sensitivity - */ - public MockCatalogReaderDynamic( AlgDataTypeFactory typeFactory, boolean caseSensitive ) { - super( typeFactory, caseSensitive ); - } - - - @Override - public MockCatalogReader init() { - // Register "DYNAMIC" schema. - MockSchema schema = new MockSchema( "SALES" ); - registerSchema( schema, -1 ); - - MockEntity nationTable = new MockDynamicEntity( this, schema.getCatalogName(), schema.getName(), "NATION", false, 100 ); - registerTable( nationTable ); - - MockEntity customerTable = new MockDynamicEntity( this, schema.getCatalogName(), schema.getName(), "CUSTOMER", false, 100 ); - registerTable( customerTable ); - - // CREATE TABLE "REGION" - static table with known schema. - final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); - final AlgDataType varcharType = typeFactory.createPolyType( PolyType.VARCHAR ); - - MockEntity regionTable = MockEntity.create( this, schema, "REGION", false, 100 ); - regionTable.addColumn( "R_REGIONKEY", intType ); - regionTable.addColumn( "R_NAME", varcharType ); - regionTable.addColumn( "R_COMMENT", varcharType ); - registerTable( regionTable ); - - return this; - } - -} - diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderExtended.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderExtended.java deleted file mode 100644 index eb1ce7b14e..0000000000 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderExtended.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2019-2021 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.catalog; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; - - -/** - * Adds some extra tables to the mock catalog. These increase the time and complexity of initializing the catalog and - * are not used for all tests. - */ -public class MockCatalogReaderExtended extends MockCatalogReaderSimple { - - /** - * Creates a MockCatalogReader. - * - * Caller must then call {@link #init} to populate with data. - * - * @param typeFactory Type factory - * @param caseSensitive case sensitivity - */ - public MockCatalogReaderExtended( AlgDataTypeFactory typeFactory, boolean caseSensitive ) { - super( typeFactory, caseSensitive ); - } - - - @Override - public MockCatalogReader init() { - super.init(); - - MockSchema structTypeSchema = new MockSchema( "STRUCT" ); - registerSchema( structTypeSchema, -1 ); - final Fixture f = new Fixture( typeFactory ); - final List columnsExtended = Arrays.asList( - new CompoundNameColumn( "", "K0", f.varchar20TypeNull ), - new CompoundNameColumn( "", "C1", f.varchar20TypeNull ), - new CompoundNameColumn( "F0", "C0", f.intType ), - new CompoundNameColumn( "F1", "C1", f.intTypeNull ) ); - final List extendedColumns = new ArrayList<>( columnsExtended ); - extendedColumns.add( new CompoundNameColumn( "F2", "C2", f.varchar20Type ) ); - final CompoundNameColumnResolver structExtendedTableResolver = new CompoundNameColumnResolver( extendedColumns, "F0" ); - final MockEntity structExtendedTypeTable = MockEntity.create( - this, - structTypeSchema, - "T_EXTEND", - false, - 100, - structExtendedTableResolver ); - for ( CompoundNameColumn column : columnsExtended ) { - structExtendedTypeTable.addColumn( column.getName(), column.type ); - } - registerTable( structExtendedTypeTable ); - - return this; - } - -} diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderSimple.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderSimple.java deleted file mode 100644 index 95ced9ec42..0000000000 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReaderSimple.java +++ /dev/null @@ -1,288 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.catalog; - - -import com.google.common.collect.ImmutableList; -import java.util.Arrays; -import java.util.List; -import lombok.Getter; -import org.polypheny.db.algebra.constant.FunctionCategory; -import org.polypheny.db.algebra.constant.Syntax; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.nodes.Identifier; -import org.polypheny.db.nodes.Operator; -import org.polypheny.db.type.ObjectPolyType; -import org.polypheny.db.type.PolyType; -import org.polypheny.db.util.InitializerExpressionFactory; - - -/** - * Simple catalog reader for testing. - */ -public class MockCatalogReaderSimple extends MockCatalogReader { - - @Getter - private final Fixture fixture; - - - /** - * Creates a MockCatalogReader. - * - * Caller must then call {@link #init} to populate with data. - * - * @param typeFactory Type factory - * @param caseSensitive case sensitivity - */ - public MockCatalogReaderSimple( AlgDataTypeFactory typeFactory, boolean caseSensitive ) { - super( typeFactory, caseSensitive ); - fixture = new Fixture( typeFactory ); - } - - - @Override - public AlgDataType getNamedType( Identifier typeName ) { - return super.getNamedType( typeName ); - } - - - @Override - public MockCatalogReader init() { - ObjectPolyType addressType = fixture.addressType; - - // Register "SALES" schema. - MockSchema salesSchema = new MockSchema( "SALES" ); - registerSchema( salesSchema, -1 ); - - // Register "EMP" table with customer InitializerExpressionFactory to check whether newDefaultValue method called or not. - final InitializerExpressionFactory countingInitializerExpressionFactory = new CountingFactory( ImmutableList.of( "DEPTNO" ) ); - - registerType( ImmutableList.of( salesSchema.getCatalogName(), salesSchema.getName(), "customBigInt" ), typeFactory -> typeFactory.createPolyType( PolyType.BIGINT ) ); - - // Register "EMP" table. - final MockEntity empTable = MockEntity.create( this, salesSchema, "EMP", false, 14, null, countingInitializerExpressionFactory ); - empTable.addColumn( "EMPNO", fixture.intType, true ); - empTable.addColumn( "ENAME", fixture.varchar20Type ); - empTable.addColumn( "JOB", fixture.varchar10Type ); - empTable.addColumn( "MGR", fixture.intTypeNull ); - empTable.addColumn( "HIREDATE", fixture.timestampType ); - empTable.addColumn( "SAL", fixture.intType ); - empTable.addColumn( "COMM", fixture.intType ); - empTable.addColumn( "DEPTNO", fixture.intType ); - empTable.addColumn( "SLACKER", fixture.booleanType ); - registerTable( empTable ); - - // Register "EMPNULLABLES" table with nullable columns. - final MockEntity empNullablesTable = MockEntity.create( this, salesSchema, "EMPNULLABLES", false, 14 ); - empNullablesTable.addColumn( "EMPNO", fixture.intType, true ); - empNullablesTable.addColumn( "ENAME", fixture.varchar20Type ); - empNullablesTable.addColumn( "JOB", fixture.varchar10TypeNull ); - empNullablesTable.addColumn( "MGR", fixture.intTypeNull ); - empNullablesTable.addColumn( "HIREDATE", fixture.timestampTypeNull ); - empNullablesTable.addColumn( "SAL", fixture.intTypeNull ); - empNullablesTable.addColumn( "COMM", fixture.intTypeNull ); - empNullablesTable.addColumn( "DEPTNO", fixture.intTypeNull ); - empNullablesTable.addColumn( "SLACKER", fixture.booleanTypeNull ); - registerTable( empNullablesTable ); - - // Register "EMPDEFAULTS" table with default values for some columns. - final MockEntity empDefaultsTable = MockEntity.create( this, salesSchema, "EMPDEFAULTS", false, 14, null, new EmpInitializerExpressionFactory() ); - empDefaultsTable.addColumn( "EMPNO", fixture.intType, true ); - empDefaultsTable.addColumn( "ENAME", fixture.varchar20Type ); - empDefaultsTable.addColumn( "JOB", fixture.varchar10TypeNull ); - empDefaultsTable.addColumn( "MGR", fixture.intTypeNull ); - empDefaultsTable.addColumn( "HIREDATE", fixture.timestampTypeNull ); - empDefaultsTable.addColumn( "SAL", fixture.intTypeNull ); - empDefaultsTable.addColumn( "COMM", fixture.intTypeNull ); - empDefaultsTable.addColumn( "DEPTNO", fixture.intTypeNull ); - empDefaultsTable.addColumn( "SLACKER", fixture.booleanTypeNull ); - registerTable( empDefaultsTable ); - - // Register "EMP_B" table. As "EMP", birth with a "BIRTHDATE" column. - final MockEntity empBTable = MockEntity.create( this, salesSchema, "EMP_B", false, 14 ); - empBTable.addColumn( "EMPNO", fixture.intType, true ); - empBTable.addColumn( "ENAME", fixture.varchar20Type ); - empBTable.addColumn( "JOB", fixture.varchar10Type ); - empBTable.addColumn( "MGR", fixture.intTypeNull ); - empBTable.addColumn( "HIREDATE", fixture.timestampType ); - empBTable.addColumn( "SAL", fixture.intType ); - empBTable.addColumn( "COMM", fixture.intType ); - empBTable.addColumn( "DEPTNO", fixture.intType ); - empBTable.addColumn( "SLACKER", fixture.booleanType ); - empBTable.addColumn( "BIRTHDATE", fixture.dateType ); - registerTable( empBTable ); - - // Register "DEPT" table. - MockEntity deptTable = MockEntity.create( this, salesSchema, "DEPT", false, 4 ); - deptTable.addColumn( "DEPTNO", fixture.intType, true ); - deptTable.addColumn( "NAME", fixture.varchar10Type ); - registerTable( deptTable ); - - // Register "DEPT_NESTED" table. - MockEntity deptNestedTable = MockEntity.create( this, salesSchema, "DEPT_NESTED", false, 4 ); - deptNestedTable.addColumn( "DEPTNO", fixture.intType, true ); - deptNestedTable.addColumn( "NAME", fixture.varchar10Type ); - deptNestedTable.addColumn( "SKILL", fixture.skillRecordType ); - deptNestedTable.addColumn( "EMPLOYEES", fixture.empListType ); - registerTable( deptNestedTable ); - - // Register "BONUS" table. - MockEntity bonusTable = MockEntity.create( this, salesSchema, "BONUS", false, 0 ); - bonusTable.addColumn( "ENAME", fixture.varchar20Type ); - bonusTable.addColumn( "JOB", fixture.varchar10Type ); - bonusTable.addColumn( "SAL", fixture.intType ); - bonusTable.addColumn( "COMM", fixture.intType ); - registerTable( bonusTable ); - - // Register "SALGRADE" table. - MockEntity salgradeTable = MockEntity.create( this, salesSchema, "SALGRADE", false, 5 ); - salgradeTable.addColumn( "GRADE", fixture.intType, true ); - salgradeTable.addColumn( "LOSAL", fixture.intType ); - salgradeTable.addColumn( "HISAL", fixture.intType ); - registerTable( salgradeTable ); - - // Register "EMP_ADDRESS" table - MockEntity contactAddressTable = MockEntity.create( this, salesSchema, "EMP_ADDRESS", false, 26 ); - contactAddressTable.addColumn( "EMPNO", fixture.intType, true ); - contactAddressTable.addColumn( "HOME_ADDRESS", addressType ); - contactAddressTable.addColumn( "MAILING_ADDRESS", addressType ); - registerTable( contactAddressTable ); - - // Register "CUSTOMER" schema. - MockSchema customerSchema = new MockSchema( "CUSTOMER" ); - registerSchema( customerSchema, -1 ); - - // Register "CONTACT" table. - MockEntity contactTable = MockEntity.create( this, customerSchema, "CONTACT", false, 1000 ); - contactTable.addColumn( "CONTACTNO", fixture.intType ); - contactTable.addColumn( "FNAME", fixture.varchar10Type ); - contactTable.addColumn( "LNAME", fixture.varchar10Type ); - contactTable.addColumn( "EMAIL", fixture.varchar20Type ); - contactTable.addColumn( "COORD", fixture.rectilinearCoordType ); - registerTable( contactTable ); - - // Register "CONTACT_PEEK" table. The - MockEntity contactPeekTable = MockEntity.create( this, customerSchema, "CONTACT_PEEK", false, 1000 ); - contactPeekTable.addColumn( "CONTACTNO", fixture.intType ); - contactPeekTable.addColumn( "FNAME", fixture.varchar10Type ); - contactPeekTable.addColumn( "LNAME", fixture.varchar10Type ); - contactPeekTable.addColumn( "EMAIL", fixture.varchar20Type ); - contactPeekTable.addColumn( "COORD", fixture.rectilinearPeekCoordType ); - contactPeekTable.addColumn( "COORD_NE", fixture.rectilinearPeekNoExpandCoordType ); - registerTable( contactPeekTable ); - - // Register "ACCOUNT" table. - MockEntity accountTable = MockEntity.create( this, customerSchema, "ACCOUNT", false, 457 ); - accountTable.addColumn( "ACCTNO", fixture.intType ); - accountTable.addColumn( "TYPE", fixture.varchar20Type ); - accountTable.addColumn( "BALANCE", fixture.intType ); - registerTable( accountTable ); - - // Register "ORDERS" stream. - MockEntity ordersStream = MockEntity.create( this, salesSchema, "ORDERS", true, Double.POSITIVE_INFINITY ); - ordersStream.addColumn( "ROWTIME", fixture.timestampType ); - ordersStream.addMonotonic( "ROWTIME" ); - ordersStream.addColumn( "PRODUCTID", fixture.intType ); - ordersStream.addColumn( "ORDERID", fixture.intType ); - registerTable( ordersStream ); - - // Register "SHIPMENTS" stream. "ROWTIME" is not column 0, just to mix things up. - MockEntity shipmentsStream = MockEntity.create( this, salesSchema, "SHIPMENTS", true, Double.POSITIVE_INFINITY ); - shipmentsStream.addColumn( "ORDERID", fixture.intType ); - shipmentsStream.addColumn( "ROWTIME", fixture.timestampType ); - shipmentsStream.addMonotonic( "ROWTIME" ); - registerTable( shipmentsStream ); - - // Register "PRODUCTS" table. - MockEntity productsTable = MockEntity.create( this, salesSchema, "PRODUCTS", false, 200D ); - productsTable.addColumn( "PRODUCTID", fixture.intType ); - productsTable.addColumn( "NAME", fixture.varchar20Type ); - productsTable.addColumn( "SUPPLIERID", fixture.intType ); - registerTable( productsTable ); - - // Register "SUPPLIERS" table. - MockEntity suppliersTable = MockEntity.create( this, salesSchema, "SUPPLIERS", false, 10D ); - suppliersTable.addColumn( "SUPPLIERID", fixture.intType ); - suppliersTable.addColumn( "NAME", fixture.varchar20Type ); - suppliersTable.addColumn( "CITY", fixture.intType ); - registerTable( suppliersTable ); - - MockSchema structTypeSchema = new MockSchema( "STRUCT" ); - registerSchema( structTypeSchema, -1 ); - final List columns = Arrays.asList( - new CompoundNameColumn( "", "K0", fixture.varchar20Type ), - new CompoundNameColumn( "", "C1", fixture.varchar20Type ), - new CompoundNameColumn( "F1", "A0", fixture.intType ), - new CompoundNameColumn( "F2", "A0", fixture.booleanType ), - new CompoundNameColumn( "F0", "C0", fixture.intType ), - new CompoundNameColumn( "F1", "C0", fixture.intTypeNull ), - new CompoundNameColumn( "F0", "C1", fixture.intType ), - new CompoundNameColumn( "F1", "C2", fixture.intType ), - new CompoundNameColumn( "F2", "C3", fixture.intType ) ); - final CompoundNameColumnResolver structTypeTableResolver = new CompoundNameColumnResolver( columns, "F0" ); - final MockEntity structTypeTable = MockEntity.create( this, structTypeSchema, "T", false, 100, structTypeTableResolver ); - for ( CompoundNameColumn column : columns ) { - structTypeTable.addColumn( column.getName(), column.type ); - } - registerTable( structTypeTable ); - - final List columnsNullable = Arrays.asList( - new CompoundNameColumn( "", "K0", fixture.varchar20TypeNull ), - new CompoundNameColumn( "", "C1", fixture.varchar20TypeNull ), - new CompoundNameColumn( "F1", "A0", fixture.intTypeNull ), - new CompoundNameColumn( "F2", "A0", fixture.booleanTypeNull ), - new CompoundNameColumn( "F0", "C0", fixture.intTypeNull ), - new CompoundNameColumn( "F1", "C0", fixture.intTypeNull ), - new CompoundNameColumn( "F0", "C1", fixture.intTypeNull ), - new CompoundNameColumn( "F1", "C2", fixture.intType ), - new CompoundNameColumn( "F2", "C3", fixture.intTypeNull ) ); - final MockEntity structNullableTypeTable = MockEntity.create( this, structTypeSchema, "T_NULLABLES", false, 100, structTypeTableResolver ); - for ( CompoundNameColumn column : columnsNullable ) { - structNullableTypeTable.addColumn( column.getName(), column.type ); - } - registerTable( structNullableTypeTable ); - - registerTablesWithRollUp( salesSchema, fixture ); - return this; - - } - - - @Override - public void lookupOperatorOverloads( Identifier opName, FunctionCategory category, Syntax syntax, List operatorList ) { - throw new UnsupportedOperationException( "This operation is not longer supported" ); - } - -} diff --git a/core/src/test/java/org/polypheny/db/test/MockRelOptPlanner.java b/core/src/test/java/org/polypheny/db/test/MockAlgOptPlanner.java similarity index 97% rename from core/src/test/java/org/polypheny/db/test/MockRelOptPlanner.java rename to core/src/test/java/org/polypheny/db/test/MockAlgOptPlanner.java index 6dd8c706dd..89bc4afcac 100644 --- a/core/src/test/java/org/polypheny/db/test/MockRelOptPlanner.java +++ b/core/src/test/java/org/polypheny/db/test/MockAlgOptPlanner.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.Map; import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.plan.AbstractRelOptPlanner; +import org.polypheny.db.plan.AbstractAlgOptPlanner; import org.polypheny.db.plan.AlgOptCostImpl; import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgOptRule; @@ -40,7 +40,7 @@ /** * MockRelOptPlanner is a mock implementation of the {@link AlgOptPlanner} interface. */ -public class MockRelOptPlanner extends AbstractRelOptPlanner { +public class MockAlgOptPlanner extends AbstractAlgOptPlanner { private AlgNode root; @@ -54,7 +54,7 @@ public class MockRelOptPlanner extends AbstractRelOptPlanner { /** * Creates MockRelOptPlanner. */ - public MockRelOptPlanner( Context context ) { + public MockAlgOptPlanner( Context context ) { super( AlgOptCostImpl.FACTORY, context ); setExecutor( new RexExecutorImpl( Schemas.createDataContext( null ) ) ); } 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 26d50db28d..fc99609bb4 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -101,7 +101,6 @@ import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; -import org.polypheny.db.prepare.Prepare.CatalogReader; import org.polypheny.db.prepare.Prepare.PreparedResult; import org.polypheny.db.prepare.Prepare.PreparedResultImpl; import org.polypheny.db.processing.caching.ImplementationCache; @@ -1148,24 +1147,19 @@ private PreparedResult implement( AlgRoot root, AlgDataType parameter enumerable = EnumerableCalc.create( enumerable, program ); } - try { - CatalogReader.THREAD_LOCAL.set( statement.getTransaction().getSnapshot() ); - final Conformance conformance = statement.getPrepareContext().config().conformance(); - - final Map internalParameters = new LinkedHashMap<>(); - internalParameters.put( "_conformance", conformance ); - - Pair, String> implementationPair = EnumerableInterpretable.toBindable( - internalParameters, - enumerable, - prefer, - statement ); - bindable = implementationPair.left; - generatedCode = implementationPair.right; - statement.getDataContext().addAll( internalParameters ); - } finally { - CatalogReader.THREAD_LOCAL.remove(); - } + final Conformance conformance = statement.getPrepareContext().config().conformance(); + + final Map internalParameters = new LinkedHashMap<>(); + internalParameters.put( "_conformance", conformance ); + + Pair, String> implementationPair = EnumerableInterpretable.toBindable( + internalParameters, + enumerable, + prefer, + statement ); + bindable = implementationPair.left; + generatedCode = implementationPair.right; + statement.getDataContext().addAll( internalParameters ); } AlgDataType resultType = root.alg.getRowType(); diff --git a/dbms/src/main/java/org/polypheny/db/processing/HepQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/HepQueryProcessor.java deleted file mode 100644 index 1a5c4cb423..0000000000 --- a/dbms/src/main/java/org/polypheny/db/processing/HepQueryProcessor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2019-2022 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 lombok.Getter; -import org.polypheny.db.algebra.rules.AggregateReduceFunctionsRule; -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.plan.hep.HepPlanner; -import org.polypheny.db.plan.hep.HepProgramBuilder; -import org.polypheny.db.transaction.Statement; - - -@Getter -public class HepQueryProcessor extends AbstractQueryProcessor { - - private final HepPlanner planner; - - - protected HepQueryProcessor( Statement statement ) { - super( statement ); - HepProgramBuilder hepProgramBuilder = - new HepProgramBuilder() - .addRuleInstance( CalcSplitRule.INSTANCE ) - .addRuleInstance( AggregateReduceFunctionsRule.INSTANCE ) - .addRuleInstance( FilterScanRule.INSTANCE ) - .addRuleInstance( FilterScanRule.INTERPRETER ) - .addRuleInstance( ProjectScanRule.INSTANCE ) - .addRuleInstance( ProjectScanRule.INTERPRETER ); - - planner = new HepPlanner( hepProgramBuilder.build() ); - } - - -} diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java index 1a7917c06c..46f3c6c21c 100644 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java +++ b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java @@ -21,9 +21,6 @@ import java.util.List; import org.junit.Test; -import org.polypheny.db.adapter.DataContext.SlimDataContext; -import org.polypheny.db.adapter.java.JavaTypeFactory; -import org.polypheny.db.adapter.java.ReflectiveSchema; import org.polypheny.db.adapter.jdbc.JdbcAlg; import org.polypheny.db.adapter.jdbc.JdbcConvention; import org.polypheny.db.adapter.jdbc.JdbcImplementor; @@ -38,22 +35,16 @@ import org.polypheny.db.algebra.enumerable.EnumerableRules; import org.polypheny.db.algebra.enumerable.EnumerableScan; import org.polypheny.db.algebra.rules.FilterMergeRule; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.languages.Parser; import org.polypheny.db.languages.Parser.ParserConfig; import org.polypheny.db.nodes.Node; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptEntity; import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgOptRule; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitDef; import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.prepare.ContextImpl; -import org.polypheny.db.prepare.JavaTypeFactoryImpl; -import org.polypheny.db.schema.HrSchema; -import org.polypheny.db.schema.PolyphenyDbSchema; -import org.polypheny.db.schema.SchemaPlus; import org.polypheny.db.sql.SqlLanguageDependent; import org.polypheny.db.sql.util.PlannerImplMock; import org.polypheny.db.tools.FrameworkConfig; @@ -107,27 +98,10 @@ private Planner getPlanner( List traitDefs, Program... programs ) { private Planner getPlanner( List traitDefs, ParserConfig parserConfig, Program... programs ) { - final SchemaPlus schema = Frameworks - .createSnapshot( true ) - .add( "hr", new ReflectiveSchema( new HrSchema(), -1 ), NamespaceType.RELATIONAL ); final FrameworkConfig config = Frameworks.newConfigBuilder() .parserConfig( parserConfig ) - .defaultSnapshot( schema ) - .traitDefs( traitDefs ) .programs( programs ) - .prepareContext( new ContextImpl( - PolyphenyDbSchema.from( schema ), - new SlimDataContext() { - @Override - public JavaTypeFactory getTypeFactory() { - return new JavaTypeFactoryImpl(); - } - }, - "", - 0, - 0, - null ) ) .build(); return new PlannerImplMock( config ); } @@ -181,14 +155,14 @@ public AlgNode convert( AlgNode alg ) { */ private static class MockJdbcScan extends RelScan implements JdbcAlg { - MockJdbcScan( AlgOptCluster cluster, AlgOptEntity table, JdbcConvention jdbcConvention ) { + MockJdbcScan( AlgOptCluster cluster, LogicalEntity table, JdbcConvention jdbcConvention ) { super( cluster, cluster.traitSetOf( jdbcConvention ), table ); } @Override public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new MockJdbcScan( getCluster(), table, (JdbcConvention) getConvention() ); + return new MockJdbcScan( getCluster(), entity, (JdbcConvention) getConvention() ); } diff --git a/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java b/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java index e02f43c08d..c2e04e4494 100644 --- a/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java +++ b/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/Mql2AlgTest.java @@ -18,7 +18,6 @@ import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.MockCatalogReaderDocument; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.languages.mql2alg.MqlToAlgConverter; @@ -27,7 +26,7 @@ import org.polypheny.db.plan.Contexts; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; -import org.polypheny.db.test.MockRelOptPlanner; +import org.polypheny.db.test.MockAlgOptPlanner; public abstract class Mql2AlgTest extends MqlTest { @@ -41,7 +40,7 @@ public abstract class Mql2AlgTest extends MqlTest { static { factory = AlgDataTypeFactory.DEFAULT; - cluster = AlgOptCluster.create( new MockRelOptPlanner( Contexts.empty() ), new RexBuilder( factory ), null, null ); + cluster = AlgOptCluster.create( new MockAlgOptPlanner( Contexts.empty() ), new RexBuilder( factory ), null, null ); snapshot = new MockCatalogReaderDocument( factory, false ).getSnapshot(); MQL_TO_ALG_CONVERTER = new MqlToAlgConverter( snapshot, cluster ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorScope.java index f4356c3ff0..06f698e6c0 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorScope.java @@ -28,7 +28,6 @@ import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.nodes.validate.ValidatorCatalogReader; import org.polypheny.db.nodes.validate.ValidatorScope; import org.polypheny.db.sql.language.SqlCall; import org.polypheny.db.sql.language.SqlIdentifier; @@ -167,7 +166,7 @@ public interface SqlValidatorScope extends ValidatorScope { /** * Looks up a table in this scope from its name. If found, calls {@link Resolved#resolve(List, NameMatcher, boolean, Resolved)}. {@link EntityNamespace} that wraps it. If the "table" is defined in a {@code WITH} clause it may be a query, not a table after all. * - * The name matcher is not null, and one typically uses {@link ValidatorCatalogReader#nameMatcher}. + * The name matcher is not null, and one typically uses {@link org.polypheny.db.catalog.snapshot.Snapshot#nameMatcher}. * * @param names Name of table, may be qualified or fully-qualified * @param nameMatcher Name matcher 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 c058b73472..831d6f5b92 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 @@ -168,7 +168,6 @@ import org.polypheny.db.rex.RexWindowBound; import org.polypheny.db.schema.ColumnStrategy; import org.polypheny.db.schema.Entity; -import org.polypheny.db.schema.Wrapper; import org.polypheny.db.schema.types.ModifiableTable; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.sql.language.SqlAggFunction; @@ -242,6 +241,7 @@ import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; import org.polypheny.db.util.ValidatorUtil; +import org.polypheny.db.util.Wrapper; import org.polypheny.db.util.trace.PolyphenyDbTrace; import org.slf4j.Logger; @@ -386,18 +386,6 @@ public void setSubQueryConverter( SubQueryConverter converter ) { } - /** - * Sets the number of dynamic parameters in the current EXPLAIN PLAN statement. - * - * @param explainParamCount number of dynamic parameters in the statement - */ - @Override - public void setDynamicParamCountInExplain( int explainParamCount ) { - assert config.isExplain(); - this.explainParamCount = explainParamCount; - } - - private void checkConvertedType( Node query, AlgNode result ) { if ( query.isA( Kind.DML ) ) { return; diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/HepPlannerTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/HepPlannerTest.java index a587cd13c4..59d6f40655 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/HepPlannerTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/HepPlannerTest.java @@ -128,7 +128,7 @@ public void algDigestLength() { sb.append( " union all select name from sales.dept" ); } sb.append( ")" ); - AlgRoot root = tester.convertSqlToRel( sb.toString() ); + AlgRoot root = tester.convertSqlToAlg( sb.toString() ); planner.setRoot( root.alg ); AlgNode best = planner.findBestExp(); @@ -218,7 +218,7 @@ public void testCommonSubExpression() { planner.addListener( listener ); final String sql = "(select 1 from dept where abs(-1)=20)\n" + "union all\n" + "(select 1 from dept where abs(-1)=20)"; - planner.setRoot( tester.convertSqlToRel( sql ).alg ); + planner.setRoot( tester.convertSqlToAlg( sql ).alg ); AlgNode bestRel = planner.findBestExp(); assertThat( bestRel.getInput( 0 ).equals( bestRel.getInput( 1 ) ), is( true ) ); @@ -266,10 +266,10 @@ public void testGC() throws Exception { programBuilder.addRuleInstance( FilterToCalcRule.INSTANCE ); HepPlanner planner = new HepPlanner( programBuilder.build() ); - planner.setRoot( tester.convertSqlToRel( "select upper(name) from dept where deptno=20" ).alg ); + planner.setRoot( tester.convertSqlToAlg( "select upper(name) from dept where deptno=20" ).alg ); planner.findBestExp(); // Reuse of HepPlanner (should trigger GC). - planner.setRoot( tester.convertSqlToRel( "select upper(name) from dept where deptno=20" ).alg ); + planner.setRoot( tester.convertSqlToAlg( "select upper(name) from dept where deptno=20" ).alg ); planner.findBestExp(); } @@ -293,7 +293,7 @@ private long checkRuleApplyCount( HepMatchOrder matchOrder ) { final HepTestListener listener = new HepTestListener( 0 ); HepPlanner planner = new HepPlanner( programBuilder.build() ); planner.addListener( listener ); - planner.setRoot( tester.convertSqlToRel( COMPLEX_UNION_TREE ).alg ); + planner.setRoot( tester.convertSqlToAlg( COMPLEX_UNION_TREE ).alg ); planner.findBestExp(); return listener.getApplyTimes(); } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/MutableRelTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/MutableRelTest.java index 0ef79075be..7c1caf17c9 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/MutableRelTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/MutableRelTest.java @@ -218,7 +218,7 @@ private static void checkConvertMutableAlg( String alg, String sql ) { private static void checkConvertMutableAlg( String alg, String sql, boolean decorrelate, List rules ) { final SqlToAlgTestBase test = new SqlToAlgTestBase() { }; - AlgNode origRel = test.createTester().convertSqlToRel( sql ).alg; + AlgNode origRel = test.createTester().convertSqlToAlg( sql ).alg; if ( decorrelate ) { final AlgBuilder algBuilder = AlgFactories.LOGICAL_BUILDER.create( origRel.getCluster(), null ); origRel = AlgDecorrelator.decorrelateQuery( origRel, algBuilder ); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java index 58bedc2e9c..3b11372f2b 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java @@ -115,6 +115,7 @@ import org.polypheny.db.type.checker.OperandTypes; import org.polypheny.db.type.inference.ReturnTypes; import org.polypheny.db.util.Optionality; +import org.polypheny.db.util.PolyphenyMode; import org.polypheny.db.util.Util; @@ -124,7 +125,7 @@ public class PlannerTest extends SqlLanguageDependent { static { - Catalog.mode = true; + Catalog.mode = PolyphenyMode.TEST; } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RelOptTestBase.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RelOptTestBase.java index 317fb3fa6a..bae3b052c6 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RelOptTestBase.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RelOptTestBase.java @@ -34,6 +34,13 @@ package org.polypheny.db.sql; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; import org.polypheny.db.algebra.AlgDecorrelator; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; @@ -51,14 +58,6 @@ import org.polypheny.db.sql.language.SqlToAlgTestBase; import org.polypheny.db.tools.AlgBuilder; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - /** * RelOptTestBase is an abstract base for tests which exercise a planner and/or rules via {@link DiffRepository}. @@ -132,7 +131,7 @@ protected void checkPlanning( Tester tester, HepProgram preProgram, AlgOptPlanne protected void checkPlanning( Tester tester, HepProgram preProgram, AlgOptPlanner planner, String sql, boolean unchanged ) { final DiffRepository diffRepos = getDiffRepos(); String sql2 = diffRepos.expand( "sql", sql ); - final AlgRoot root = tester.convertSqlToRel( sql2 ); + final AlgRoot root = tester.convertSqlToAlg( sql2 ); final AlgNode algInitial = root.alg; assertNotNull( algInitial ); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexTransformerTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexTransformerTest.java index b424113536..7bc9d95092 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexTransformerTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexTransformerTest.java @@ -72,7 +72,7 @@ public class RexTransformerTest { private static AlgNode toAlg( String sql ) { final SqlToAlgTestBase test = new SqlToAlgTestBase() { }; - return test.createTester().convertSqlToRel( sql ).alg; + return test.createTester().convertSqlToAlg( sql ).alg; } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/SqlLanguageDependent.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/SqlLanguageDependent.java index b29876296b..49f9abe7aa 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/SqlLanguageDependent.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/SqlLanguageDependent.java @@ -16,10 +16,14 @@ package org.polypheny.db.sql; +import org.polypheny.db.TestHelper; + public class SqlLanguageDependent { + static { - SqlLanguagePlugin.startup(); + TestHelper.getInstance(); + //SqlLanguagePlugin.startup(); } } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlTestFactory.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlTestFactory.java index 1f72c8c5c2..d6dfc748d3 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlTestFactory.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlTestFactory.java @@ -30,11 +30,8 @@ import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.algebra.type.DelegatingTypeSystem; -import org.polypheny.db.catalog.MockCatalogReader; -import org.polypheny.db.catalog.MockCatalogReaderSimple; import org.polypheny.db.languages.Parser; import org.polypheny.db.languages.Parser.ParserConfig; -import org.polypheny.db.nodes.validate.ValidatorCatalogReader; import org.polypheny.db.prepare.JavaTypeFactoryImpl; import org.polypheny.db.sql.MockSqlOperatorTable; import org.polypheny.db.sql.language.advise.SqlAdvisor; @@ -67,28 +64,24 @@ public class SqlTestFactory { public static final SqlTestFactory INSTANCE = new SqlTestFactory(); private final ImmutableMap options; - private final MockCatalogReaderFactory catalogReaderFactory; private final ValidatorFactory validatorFactory; private final Supplier typeFactory; private final Supplier operatorTable; - private final Supplier catalogReader; private final Supplier parserConfig; protected SqlTestFactory() { - this( DEFAULT_OPTIONS, MockCatalogReaderSimple::new, null );//SqlValidatorUtil::newValidator ); + this( DEFAULT_OPTIONS, null );//SqlValidatorUtil::newValidator ); } - protected SqlTestFactory( ImmutableMap options, MockCatalogReaderFactory catalogReaderFactory, ValidatorFactory validatorFactory ) { + protected SqlTestFactory( ImmutableMap options, ValidatorFactory validatorFactory ) { this.options = options; - this.catalogReaderFactory = catalogReaderFactory; this.validatorFactory = validatorFactory; this.operatorTable = Suppliers.memoize( () -> createOperatorTable( (OperatorTable) options.get( "operatorTable" ) ) ); this.typeFactory = Suppliers.memoize( () -> createTypeFactory( (Conformance) options.get( "conformance" ) ) ); Boolean caseSensitive = (Boolean) options.get( "caseSensitive" ); - this.catalogReader = Suppliers.memoize( () -> catalogReaderFactory.create( typeFactory.get(), caseSensitive ).init() ); this.parserConfig = Suppliers.memoize( () -> createParserConfig( options ) ); } @@ -125,7 +118,7 @@ public static ParserConfig createParserConfig( ImmutableMap opti public SqlValidator getValidator() { final Conformance conformance = (Conformance) options.get( "conformance" ); - return validatorFactory.create( operatorTable.get(), catalogReader.get(), typeFactory.get(), conformance ); + return validatorFactory.create( operatorTable.get(), typeFactory.get(), conformance ); } @@ -151,17 +144,13 @@ public SqlTestFactory with( String name, Object value ) { builder.put( entry ); } builder.put( name, value ); - return new SqlTestFactory( builder.build(), catalogReaderFactory, validatorFactory ); + return new SqlTestFactory( builder.build(), validatorFactory ); } - public SqlTestFactory withCatalogReader( MockCatalogReaderFactory newCatalogReaderFactory ) { - return new SqlTestFactory( options, newCatalogReaderFactory, validatorFactory ); - } - public SqlTestFactory withValidator( ValidatorFactory newValidatorFactory ) { - return new SqlTestFactory( options, catalogReaderFactory, newValidatorFactory ); + return new SqlTestFactory( options, newValidatorFactory ); } @@ -196,20 +185,10 @@ public boolean allowExtendedTrim() { */ public interface ValidatorFactory { - SqlValidator create( OperatorTable opTab, ValidatorCatalogReader catalogReader, AlgDataTypeFactory typeFactory, Conformance conformance ); + SqlValidator create( OperatorTable opTab, AlgDataTypeFactory typeFactory, Conformance conformance ); } - /** - * Creates {@link MockCatalogReader} for tests. - * Note: {@link MockCatalogReader#init()} is to be invoked later, so a typical implementation should be via constructor reference like {@code MockCatalogReaderSimple::new}. - */ - public interface MockCatalogReaderFactory { - - MockCatalogReader create( AlgDataTypeFactory typeFactory, boolean caseSensitive ); - - } - } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgConverterTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgConverterTest.java index 37a406713b..b8685963de 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgConverterTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgConverterTest.java @@ -33,10 +33,10 @@ import org.polypheny.db.algebra.constant.NullCollation; import org.polypheny.db.algebra.core.CorrelationId; import org.polypheny.db.algebra.externalize.AlgXmlWriter; -import org.polypheny.db.catalog.MockCatalogReaderExtended; import org.polypheny.db.config.PolyphenyDbConnectionConfigImpl; import org.polypheny.db.config.PolyphenyDbConnectionProperty; import org.polypheny.db.languages.NodeToAlgConverter; +import org.polypheny.db.languages.NodeToAlgConverter.Config; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.plan.Contexts; import org.polypheny.db.sql.DiffRepository; @@ -71,7 +71,7 @@ protected DiffRepository getDiffRepos() { * Sets the SQL statement for a test. */ public final Sql sql( String sql ) { - return new Sql( sql, true, true, tester, false, SqlToAlgConverter.Config.DEFAULT, tester.getConformance() ); + return new Sql( sql, true, true, tester, false, Config.DEFAULT, tester.getConformance() ); } @@ -155,7 +155,7 @@ public void testJoinUsingDynamicTable() { final String sql = "select * from SALES.NATION t1\n" + "join SALES.NATION t2\n" + "using (n_nationkey)"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -1261,7 +1261,7 @@ public void testUnnestArrayPlan() { final String sql = "select d.deptno, e2.empno\n" + "from dept_nested as d,\n" + " UNNEST(d.employees) e2"; - sql( sql ).with( getExtendedTester() ).ok(); + sql( sql ).ok(); } @@ -1271,7 +1271,7 @@ public void testUnnestArrayPlanAs() { final String sql = "select d.deptno, e2.empno\n" + "from dept_nested as d,\n" + " UNNEST(d.employees) as e2(empno, y, z)"; - sql( sql ).with( getExtendedTester() ).ok(); + sql( sql ).ok(); } @@ -2070,7 +2070,7 @@ public void testStreamWindowedAggregation() { @Test public void testExplainAsXml() { String sql = "select 1 + 2, 3 from (values (true))"; - final AlgNode alg = tester.convertSqlToRel( sql ).alg; + final AlgNode alg = tester.convertSqlToAlg( sql ).alg; StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); AlgXmlWriter planWriter = new AlgXmlWriter( pw, ExplainLevel.EXPPLAN_ATTRIBUTES ); @@ -2720,7 +2720,7 @@ public void testCustomColumnResolvingWithSelectFieldNameDotStar() { @Test public void testSelectFromDynamicTable() throws Exception { final String sql = "select n_nationkey, n_name from SALES.NATION"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2730,7 +2730,7 @@ public void testSelectFromDynamicTable() throws Exception { @Test public void testSelectStarFromDynamicTable() throws Exception { final String sql = "select * from SALES.NATION"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2744,7 +2744,7 @@ public void testNotInWithLiteral() { + "WHERE n_name NOT IN\n" + " (SELECT ''\n" + " FROM SALES.NATION)"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2756,7 +2756,7 @@ public void testReferDynamicStarInSelectOB() throws Exception { final String sql = "select n_nationkey, n_name\n" + "from (select * from SALES.NATION)\n" + "order by n_regionkey"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2769,7 +2769,7 @@ public void testDynamicStarInTableJoin() throws Exception { + " (select * from SALES.NATION) T1, " + " (SELECT * from SALES.CUSTOMER) T2 " + " where T1.n_nationkey = T2.c_nationkey"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2779,7 +2779,7 @@ public void testDynamicNestedColumn() { + "from (\n" + " select t2.fake_col as fake_q1\n" + " from SALES.CUSTOMER as t2) as t3"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2789,7 +2789,7 @@ public void testDynamicSchemaUnnest() { + "from SALES.CUSTOMER as t1,\n" + "lateral (select t2.\"$unnest\" as fake_col3\n" + " from unnest(t1.fake_col) as t2) as t3"; - sql( sql3 ).with( getTesterWithDynamicTable() ).ok(); + sql( sql3 ).ok(); } @@ -2799,7 +2799,7 @@ public void testStarDynamicSchemaUnnest() { + "from SALES.CUSTOMER as t1,\n" + "lateral (select t2.\"$unnest\" as fake_col3\n" + " from unnest(t1.fake_col) as t2) as t3"; - sql( sql3 ).with( getTesterWithDynamicTable() ).ok(); + sql( sql3 ).ok(); } @@ -2808,7 +2808,7 @@ public void testStarDynamicSchemaUnnest2() { final String sql3 = "select *\n" + "from SALES.CUSTOMER as t1,\n" + "unnest(t1.fake_col) as t2"; - sql( sql3 ).with( getTesterWithDynamicTable() ).ok(); + sql( sql3 ).ok(); } @@ -2817,7 +2817,7 @@ public void testStarDynamicSchemaUnnestNestedSubQuery() { String sql3 = "select t2.c1\n" + "from (select * from SALES.CUSTOMER) as t1,\n" + "unnest(t1.fake_col) as t2(c1)"; - sql( sql3 ).with( getTesterWithDynamicTable() ).ok(); + sql( sql3 ).ok(); } @@ -2827,7 +2827,7 @@ public void testStarDynamicSchemaUnnestNestedSubQuery() { @Test public void testReferDynamicStarInSelectWhereGB() throws Exception { final String sql = "select n_regionkey, count(*) as cnt from (select * from SALES.NATION) where n_nationkey > 5 group by n_regionkey"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2837,7 +2837,7 @@ public void testReferDynamicStarInSelectWhereGB() throws Exception { @Test public void testDynamicStarInJoinAndSubQ() throws Exception { final String sql = "select * from (select * from SALES.NATION T1, SALES.CUSTOMER T2 where T1.n_nationkey = T2.c_nationkey)"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2847,7 +2847,7 @@ public void testDynamicStarInJoinAndSubQ() throws Exception { @Test public void testStarJoinStaticDynTable() throws Exception { final String sql = "select * from SALES.NATION N, SALES.REGION as R where N.n_regionkey = R.r_regionkey"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2857,7 +2857,7 @@ public void testStarJoinStaticDynTable() throws Exception { @Test public void testGrpByColFromStarInSubQuery() throws Exception { final String sql = "SELECT n.n_nationkey AS col from (SELECT * FROM SALES.NATION) as n group by n.n_nationkey"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2868,7 +2868,7 @@ public void testGrpByColFromStarInSubQuery() throws Exception { public void testDynStarInExistSubQ() throws Exception { final String sql = "select *\n" + "from SALES.REGION where exists (select * from SALES.NATION)"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2878,7 +2878,7 @@ public void testDynStarInExistSubQ() throws Exception { @Test public void testSelectDynamicStarOrderBy() throws Exception { final String sql = "SELECT * from SALES.NATION order by n_nationkey"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2907,7 +2907,7 @@ public void testWindowOnDynamicStar() throws Exception { final String sql = "SELECT SUM(n_nationkey) OVER w\n" + "FROM (SELECT * FROM SALES.NATION) subQry\n" + "WINDOW w AS (PARTITION BY REGION ORDER BY n_nationkey)"; - sql( sql ).with( getTesterWithDynamicTable() ).ok(); + sql( sql ).ok(); } @@ -2924,7 +2924,7 @@ public void testWindowAndGroupByWithDynamicStar() { public boolean isGroupByAlias() { return true; } - } ).with( getTesterWithDynamicTable() ).ok(); + } ).ok(); } @@ -2945,10 +2945,6 @@ public void testAnyValueAggregateFunctionGroupBy() throws Exception { } - private Tester getExtendedTester() { - return tester.withCatalogReaderFactory( MockCatalogReaderExtended::new ); - } - /* // TODO MV: FIX @Test @@ -3153,7 +3149,7 @@ public void testUserDefinedOrderByOver() { Properties properties = new Properties(); properties.setProperty( PolyphenyDbConnectionProperty.DEFAULT_NULL_COLLATION.camelName(), NullCollation.LOW.name() ); PolyphenyDbConnectionConfigImpl connectionConfig = new PolyphenyDbConnectionConfigImpl( properties ); - TesterImpl tester = new TesterImpl( getDiffRepos(), false, false, true, false, null, null, SqlToAlgConverter.Config.DEFAULT, ConformanceEnum.DEFAULT, Contexts.of( connectionConfig ) ); + TesterImpl tester = new TesterImpl( getDiffRepos(), false, false, true, false, null, SqlToAlgConverter.Config.DEFAULT, ConformanceEnum.DEFAULT, Contexts.of( connectionConfig ) ); sql( sql ).with( tester ).ok(); } @@ -3326,7 +3322,7 @@ public void visit( AlgNode node, int ordinal, AlgNode parent ) { /** * Allows fluent testing. */ - public class Sql { + public static class Sql { private final String sql; private final boolean expand; diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java index 3529a28693..c410e0627a 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToAlgTestBase.java @@ -20,74 +20,65 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.function.Function; -import org.polypheny.db.algebra.AlgCollation; -import org.polypheny.db.algebra.AlgCollations; -import org.polypheny.db.algebra.AlgDistribution; -import org.polypheny.db.algebra.AlgDistributions; -import org.polypheny.db.algebra.AlgFieldCollation; +import org.junit.BeforeClass; +import org.polypheny.db.TestHelper; import org.polypheny.db.algebra.AlgFieldTrimmer; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.ConformanceEnum; -import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.core.AlgFactories; import org.polypheny.db.algebra.operators.OperatorTable; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.MockCatalogReader; -import org.polypheny.db.catalog.MockCatalogReaderDynamic; -import org.polypheny.db.catalog.MockCatalogReaderSimple; -import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.config.PolyphenyDbConnectionConfig; -import org.polypheny.db.languages.NodeToAlgConverter; import org.polypheny.db.languages.NodeToAlgConverter.Config; -import org.polypheny.db.languages.Parser; -import org.polypheny.db.languages.Parser.ParserConfig; +import org.polypheny.db.languages.QueryLanguage; +import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.validate.ValidatorCatalogReader; -import org.polypheny.db.nodes.validate.ValidatorTable; import org.polypheny.db.plan.AlgOptCluster; -import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgOptSchema; import org.polypheny.db.plan.AlgOptSchemaWithSampling; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.Context; import org.polypheny.db.plan.Contexts; import org.polypheny.db.prepare.Prepare; -import org.polypheny.db.rex.RexBuilder; -import org.polypheny.db.schema.ColumnStrategy; +import org.polypheny.db.processing.Processor; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.DiffRepository; import org.polypheny.db.sql.MockSqlOperatorTable; +import org.polypheny.db.sql.SqlLanguageDependent; import org.polypheny.db.sql.language.fun.SqlStdOperatorTable; -import org.polypheny.db.sql.language.parser.SqlAbstractParserImpl; -import org.polypheny.db.sql.language.parser.SqlParser; import org.polypheny.db.sql.language.validate.SqlValidator; import org.polypheny.db.sql.language.validate.SqlValidatorImpl; -import org.polypheny.db.sql.sql2alg.SqlToAlgConverter; -import org.polypheny.db.sql.sql2alg.StandardConvertletTable; -import org.polypheny.db.test.MockRelOptPlanner; +import org.polypheny.db.test.MockAlgOptPlanner; import org.polypheny.db.tools.AlgBuilder; +import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.type.PolyTypeFactoryImpl; import org.polypheny.db.util.Conformance; -import org.polypheny.db.util.ImmutableBitSet; -import org.polypheny.db.util.SourceStringReader; +import org.polypheny.db.util.Pair; /** * SqlToAlgTestBase is an abstract base for tests which involve conversion from SQL to relational algebra. * - * SQL statements to be translated can use the schema defined in {@link MockCatalogReader}; note that this is slightly different from Farrago's SALES schema. If you get a parser or validator + * SQL statements to be translated can use the schema defined in note that this is slightly different from Farrago's SALES schema. If you get a parser or validator * error from your test SQL, look down in the stack until you see "Caused by", which will usually tell you the real error. */ -public abstract class SqlToAlgTestBase { +public abstract class SqlToAlgTestBase extends SqlLanguageDependent { + + private static TestHelper testHelper; + + + @BeforeClass + public static void start() { + testHelper = TestHelper.getInstance(); + } + protected static final String NL = System.getProperty( "line.separator" ); @@ -100,17 +91,7 @@ public SqlToAlgTestBase() { public Tester createTester() { - return new TesterImpl( getDiffRepos(), false, false, true, false, null, null, Config.DEFAULT, ConformanceEnum.DEFAULT, Contexts.empty() ); - } - - - protected Tester createTester( Conformance conformance ) { - return new TesterImpl( getDiffRepos(), false, false, true, false, null, null, Config.DEFAULT, conformance, Contexts.empty() ); - } - - - protected Tester getTesterWithDynamicTable() { - return tester.withCatalogReaderFactory( MockCatalogReaderDynamic::new ); + return new TesterImpl( getDiffRepos(), false, false, true, false, null, Config.DEFAULT, ConformanceEnum.DEFAULT, Contexts.empty() ); } @@ -155,41 +136,13 @@ public interface Tester { * @param sql SQL statement * @return Relational expression, never null */ - AlgRoot convertSqlToRel( String sql ); - - SqlNode parseQuery( String sql ) throws Exception; - - /** - * Factory method to create a {@link SqlValidator}. - */ - SqlValidator createValidator( ValidatorCatalogReader catalogReader, AlgDataTypeFactory typeFactory ); - - /** - * Factory method for a - * {@link Prepare.CatalogReader}. - */ - Prepare.CatalogReader createCatalogReader( AlgDataTypeFactory typeFactory ); - - AlgOptPlanner createPlanner(); - - /** - * Returns the {@link OperatorTable} to use. - */ - OperatorTable getOperatorTable(); + AlgRoot convertSqlToAlg( String sql ); /** * Returns the SQL dialect to test. */ Conformance getConformance(); - /** - * Checks that a SQL statement converts to a given plan. - * - * @param sql SQL query - * @param plan Expected plan - */ - void assertConvertsTo( String sql, String plan ); - /** * Checks that a SQL statement converts to a given plan, optionally trimming columns that are not needed. * @@ -199,13 +152,6 @@ public interface Tester { */ void assertConvertsTo( String sql, String plan, boolean trim ); - /** - * Returns the diff repository. - * - * @return Diff repository - */ - DiffRepository getDiffRepos(); - /** * Returns the validator. * @@ -218,11 +164,6 @@ public interface Tester { */ Tester withDecorrelation( boolean enable ); - /** - * Returns a tester that optionally decorrelates queries after planner rules have fired. - */ - Tester withLateDecorrelation( boolean enable ); - /** * Returns a tester that optionally expands sub-queries. If {@code expand} is false, the plan contains a {@link org.polypheny.db.rex.RexSubQuery} for each sub-query. * @@ -240,22 +181,8 @@ public interface Tester { */ Tester withConformance( Conformance conformance ); - Tester withCatalogReaderFactory( SqlTestFactory.MockCatalogReaderFactory factory ); - - /** - * Returns a tester that optionally trims unused fields. - */ - Tester withTrim( boolean enable ); - - Tester withClusterFactory( Function function ); - boolean isLateDecorrelate(); - /** - * Returns a tester that uses a given context. - */ - Tester withContext( Context context ); - } @@ -264,280 +191,19 @@ public interface Tester { */ protected static class MockRelOptSchema implements AlgOptSchemaWithSampling { - private final ValidatorCatalogReader catalogReader; - private final AlgDataTypeFactory typeFactory; - public MockRelOptSchema( ValidatorCatalogReader catalogReader, AlgDataTypeFactory typeFactory ) { - this.catalogReader = catalogReader; - this.typeFactory = typeFactory; - } - - - @Override - public LogicalTable getTableForMember( List names ) { - final LogicalTable table = catalogReader.getTable( names ); - final AlgDataType rowType = table.getRowType(); - final List collationList = deduceMonotonicity( table ); - if ( names.size() < 3 ) { - String[] newNames2 = { "CATALOG", "SALES", "" }; - List newNames = new ArrayList<>(); - int i = 0; - while ( newNames.size() < newNames2.length ) { - newNames.add( i, newNames2[i] ); - ++i; - } - names = newNames; - } - return createColumnSet( table, names, rowType, collationList ); - } - - - private List deduceMonotonicity( LogicalTable table ) { - final AlgDataType rowType = table.getRowType(); - final List collationList = new ArrayList<>(); - - // Deduce which fields the table is sorted on. - int i = -1; - for ( AlgDataTypeField field : rowType.getFields() ) { - ++i; - final Monotonicity monotonicity = ValidatorTable.getMonotonicity( table, field.getName() ); - if ( monotonicity != Monotonicity.NOT_MONOTONIC ) { - final AlgFieldCollation.Direction direction = - monotonicity.isDecreasing() - ? AlgFieldCollation.Direction.DESCENDING - : AlgFieldCollation.Direction.ASCENDING; - collationList.add( AlgCollations.of( new AlgFieldCollation( i, direction ) ) ); - } - } - return collationList; } - protected MockColumnSet createColumnSet( LogicalTable table, List names, final AlgDataType rowType, final List collationList ) { - return new MockColumnSet( names, rowType, collationList ); - } - - - /** - * Mock column set. - */ - protected class MockColumnSet extends LogicalTable { - - private final List names; - private final AlgDataType rowType; - private final List collationList; - - - protected MockColumnSet( List names, AlgDataType rowType, final List collationList ) { - super( null ); - this.names = ImmutableList.copyOf( names ); - this.rowType = rowType; - this.collationList = collationList; - } - - - @Override - public T unwrap( Class clazz ) { - if ( clazz.isInstance( this ) ) { - return clazz.cast( this ); - } - return null; - } - - - @Override - public double getRowCount() { - // use something other than 0 to give costing tests some room, and make emps bigger than depts for join asymmetry - if ( Iterables.getLast( names ).equals( "EMP" ) ) { - return 1000; - } else { - return 100; - } - } - - - @Override - public AlgDataType getRowType() { - return rowType; - } - - - /*@Override - public AlgOptSchema getRelOptSchema() { - return MockRelOptSchema.this; - } - - - @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - return LogicalRelScan.create( context.getCluster(), this ); - } - - - @Override - public List getCollationList() { - return collationList; - }*/ - - - @Override - public AlgDistribution getDistribution() { - return AlgDistributions.BROADCAST_DISTRIBUTED; - } - - - @Override - public Boolean isKey( ImmutableBitSet columns ) { - return false; - } - - - /*@Override - public List getReferentialConstraints() { - return ImmutableList.of(); - }*/ - - - @Override - public List getColumnStrategies() { - throw new UnsupportedOperationException(); - } - - - /*@Override - public CatalogEntity getCatalogEntity() { - return null; - } - - - @Override - public CatalogEntityPlacement getPartitionPlacement() { - return null; - } - - - @Override - public Expression getExpression( Class clazz ) { - return null; - } - - - @Override - public AlgOptEntity extend( List extendedFields ) { - final AlgDataType extendedRowType = AlgDataTypeFactory.DEFAULT.builder() - .addAll( rowType.getFieldList() ) - .addAll( extendedFields ) - .build(); - return new MockColumnSet( names, extendedRowType, collationList ); - }*/ - - } - } - /** - * Table that delegates to a given table. - */ - /*private static class DelegatingRelOptEntity implements AlgOptEntity { - - private final AlgOptEntity parent; - - - DelegatingRelOptEntity( AlgOptEntity parent ) { - this.parent = parent; - } - - - @Override - public T unwrap( Class clazz ) { - if ( clazz.isInstance( this ) ) { - return clazz.cast( this ); - } - return parent.unwrap( clazz ); - } - - - @Override - public Expression getExpression( Class clazz ) { - return parent.getExpression( clazz ); - } - - - @Override - public AlgOptEntity extend( List extendedFields ) { - return parent.extend( extendedFields ); - } - - - @Override - public double getRowCount() { - return parent.getRowCount(); - } - - - @Override - public AlgDataType getRowType() { - return parent.getRowType(); - } - - - @Override - public AlgOptSchema getRelOptSchema() { - return parent.getRelOptSchema(); - } - - - @Override - public AlgNode toAlg( ToAlgContext context, AlgTraitSet traitSet ) { - return LogicalRelScan.create( context.getCluster(), this ); - } - - - @Override - public List getCollationList() { - return parent.getCollationList(); - } - - - @Override - public AlgDistribution getDistribution() { - return parent.getDistribution(); - } - - - @Override - public boolean isKey( ImmutableBitSet columns ) { - return parent.isKey( columns ); - } - - - @Override - public List getReferentialConstraints() { - return parent.getReferentialConstraints(); - } - - - @Override - public List getColumnStrategies() { - return parent.getColumnStrategies(); - } - - - @Override - public CatalogEntity getCatalogEntity() { - return null; - } - - }*/ - /** - * Default implementation of {@link Tester}, using mock classes {@link MockRelOptSchema} and {@link MockRelOptPlanner}. + * Default implementation of {@link Tester}, using mock classes and {@link MockAlgOptPlanner}. */ public static class TesterImpl implements Tester { - private AlgOptPlanner planner; private OperatorTable opTab; private final DiffRepository diffRepos; private final boolean enableDecorrelate; @@ -545,7 +211,6 @@ public static class TesterImpl implements Tester { private final boolean enableTrim; private final boolean enableExpand; private final Conformance conformance; - private final SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory; private final Function clusterFactory; private AlgDataTypeFactory typeFactory; public final Config config; @@ -559,7 +224,6 @@ public static class TesterImpl implements Tester { * @param enableDecorrelate Whether to decorrelate * @param enableTrim Whether to trim unused fields * @param enableExpand Whether to expand sub-queries - * @param catalogReaderFactory Function to create catalog reader, or null * @param clusterFactory Called after a cluster has been created */ protected TesterImpl( @@ -568,7 +232,6 @@ protected TesterImpl( boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, - SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, Function clusterFactory ) { this( @@ -577,7 +240,6 @@ protected TesterImpl( enableTrim, enableExpand, enableLateDecorrelate, - catalogReaderFactory, clusterFactory, Config.DEFAULT, ConformanceEnum.DEFAULT, @@ -591,7 +253,6 @@ protected TesterImpl( boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, - SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, Function clusterFactory, Config config, Conformance conformance, @@ -601,7 +262,6 @@ protected TesterImpl( this.enableTrim = enableTrim; this.enableExpand = enableExpand; this.enableLateDecorrelate = enableLateDecorrelate; - this.catalogReaderFactory = catalogReaderFactory; this.clusterFactory = clusterFactory; this.config = config; this.conformance = conformance; @@ -610,55 +270,25 @@ protected TesterImpl( @Override - public AlgRoot convertSqlToRel( String sql ) { - Objects.requireNonNull( sql ); - final SqlNode sqlQuery; - final Config localConfig; - try { - sqlQuery = parseQuery( sql ); - } catch ( RuntimeException | Error e ) { - throw e; - } catch ( Exception e ) { - throw new RuntimeException( e ); - } - final AlgDataTypeFactory typeFactory = getTypeFactory(); - final Prepare.CatalogReader catalogReader = createCatalogReader( typeFactory ); - final SqlValidator validator = createValidator( catalogReader, typeFactory ); - final PolyphenyDbConnectionConfig polyphenyDbConfig = context.unwrap( PolyphenyDbConnectionConfig.class ); - if ( polyphenyDbConfig != null ) { - validator.setDefaultNullCollation( polyphenyDbConfig.defaultNullCollation() ); - } - if ( config == Config.DEFAULT ) { - localConfig = NodeToAlgConverter.configBuilder().trimUnusedFields( true ).expand( enableExpand ).build(); - } else { - localConfig = config; - } + public AlgRoot convertSqlToAlg( String sql ) { + QueryLanguage language = QueryLanguage.from( "sql" ); - final SqlToAlgConverter converter = createSqlToRelConverter( validator, catalogReader, typeFactory, localConfig ); + Processor processor = language.getProcessorSupplier().get(); - final SqlNode validatedQuery = validator.validateSql( sqlQuery ); - AlgRoot root = converter.convertQuery( validatedQuery, false, true ); - assert root != null; - if ( enableDecorrelate || enableTrim ) { - root = root.withAlg( converter.flattenTypes( root.alg, true ) ); - } - if ( enableDecorrelate ) { - root = root.withAlg( converter.decorrelate( sqlQuery, root.alg ) ); - } - if ( enableTrim ) { - root = root.withAlg( converter.trimUnusedFields( true, root.alg ) ); - } - return root; - } + List nodes = processor.parse( sql ); + + TransactionManager transactionManager = testHelper.getTransactionManager(); + + Transaction transaction = transactionManager.startTransaction( Catalog.defaultUserId, false, "Sql Test" ); + AlgRoot root = null; + for ( Node node : nodes ) { + Pair validated = processor.validate( transaction, node, true ); - protected SqlToAlgConverter createSqlToRelConverter( final SqlValidator validator, final Prepare.CatalogReader catalogReader, final AlgDataTypeFactory typeFactory, final Config config ) { - final RexBuilder rexBuilder = new RexBuilder( typeFactory ); - AlgOptCluster cluster = AlgOptCluster.create( getPlanner(), rexBuilder, getPlanner().emptyTraitSet(), Catalog.snapshot() ); - if ( clusterFactory != null ) { - cluster = clusterFactory.apply( cluster ); + Statement statement = transaction.createStatement(); + root = processor.translate( statement, ParsedQueryContext.builder().origin( "Sql Test" ).query( sql ).queryNode( validated.left ).build() ); } - return new SqlToAlgConverter( validator, Catalog.snapshot(), cluster, StandardConvertletTable.INSTANCE, config ); + return root; } @@ -675,39 +305,18 @@ protected AlgDataTypeFactory createTypeFactory() { } - protected final AlgOptPlanner getPlanner() { - if ( planner == null ) { - planner = createPlanner(); - } - return planner; - } - - - @Override - public SqlNode parseQuery( String sql ) throws Exception { - final ParserConfig sqlParserConfig = Parser.configBuilder().setConformance( getConformance() ).build(); - - SqlAbstractParserImpl parserImpl = (SqlAbstractParserImpl) sqlParserConfig.parserFactory().getParser( new SourceStringReader( sql ) ); - - Parser parser = new SqlParser( parserImpl, sqlParserConfig ); - return (SqlNode) parser.parseQuery(); - } - - @Override public Conformance getConformance() { return conformance; } - @Override - public SqlValidator createValidator( ValidatorCatalogReader catalogReader, AlgDataTypeFactory typeFactory ) { - return new FarragoTestValidator( getOperatorTable(), catalogReader, typeFactory, getConformance() ); + private SqlValidator createValidator( AlgDataTypeFactory typeFactory ) { + return new FarragoTestValidator( getOperatorTable(), typeFactory, getConformance() ); } - @Override - public final OperatorTable getOperatorTable() { + private OperatorTable getOperatorTable() { if ( opTab == null ) { opTab = createOperatorTable(); } @@ -727,34 +336,10 @@ protected OperatorTable createOperatorTable() { } - @Override - public Prepare.CatalogReader createCatalogReader( AlgDataTypeFactory typeFactory ) { - MockCatalogReader catalogReader; - if ( this.catalogReaderFactory != null ) { - catalogReader = catalogReaderFactory.create( typeFactory, true ); - } else { - catalogReader = new MockCatalogReaderSimple( typeFactory, true ); - } - return catalogReader.init(); - } - - - @Override - public AlgOptPlanner createPlanner() { - return new MockRelOptPlanner( context ); - } - - - @Override - public void assertConvertsTo( String sql, String plan ) { - assertConvertsTo( sql, plan, false ); - } - - @Override public void assertConvertsTo( String sql, String plan, boolean trim ) { String sql2 = getDiffRepos().expand( "sql", sql ); - AlgNode alg = convertSqlToRel( sql2 ).project(); + AlgNode alg = convertSqlToAlg( sql2 ).project(); assertNotNull( alg ); assertValid( alg ); @@ -784,8 +369,7 @@ public AlgFieldTrimmer createFieldTrimmer( AlgBuilder algBuilder ) { } - @Override - public DiffRepository getDiffRepos() { + private DiffRepository getDiffRepos() { return diffRepos; } @@ -793,8 +377,7 @@ public DiffRepository getDiffRepos() { @Override public SqlValidator getValidator() { final AlgDataTypeFactory typeFactory = getTypeFactory(); - final ValidatorCatalogReader catalogReader = createCatalogReader( typeFactory ); - return createValidator( catalogReader, typeFactory ); + return createValidator( typeFactory ); } @@ -802,15 +385,7 @@ public SqlValidator getValidator() { public TesterImpl withDecorrelation( boolean enableDecorrelate ) { return this.enableDecorrelate == enableDecorrelate ? this - : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); - } - - - @Override - public Tester withLateDecorrelation( boolean enableLateDecorrelate ) { - return this.enableLateDecorrelate == enableLateDecorrelate - ? this - : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); + : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, clusterFactory, config, conformance, context ); } @@ -818,15 +393,7 @@ public Tester withLateDecorrelation( boolean enableLateDecorrelate ) { public TesterImpl withConfig( Config config ) { return this.config == config ? this - : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); - } - - - @Override - public Tester withTrim( boolean enableTrim ) { - return this.enableTrim == enableTrim - ? this - : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); + : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, clusterFactory, config, conformance, context ); } @@ -834,31 +401,13 @@ public Tester withTrim( boolean enableTrim ) { public Tester withExpand( boolean enableExpand ) { return this.enableExpand == enableExpand ? this - : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); + : new TesterImpl( diffRepos, enableDecorrelate, enableTrim, enableExpand, enableLateDecorrelate, clusterFactory, config, conformance, context ); } @Override public Tester withConformance( Conformance conformance ) { - return new TesterImpl( diffRepos, enableDecorrelate, false, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); - } - - - @Override - public Tester withCatalogReaderFactory( SqlTestFactory.MockCatalogReaderFactory factory ) { - return new TesterImpl( diffRepos, enableDecorrelate, false, enableExpand, enableLateDecorrelate, factory, clusterFactory, config, conformance, context ); - } - - - @Override - public Tester withClusterFactory( Function clusterFactory ) { - return new TesterImpl( diffRepos, enableDecorrelate, false, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); - } - - - @Override - public Tester withContext( Context context ) { - return new TesterImpl( diffRepos, enableDecorrelate, false, enableExpand, enableLateDecorrelate, catalogReaderFactory, clusterFactory, config, conformance, context ); + return new TesterImpl( diffRepos, enableDecorrelate, false, enableExpand, enableLateDecorrelate, clusterFactory, config, conformance, context ); } @@ -875,7 +424,7 @@ public boolean isLateDecorrelate() { */ private static class FarragoTestValidator extends SqlValidatorImpl { - FarragoTestValidator( OperatorTable opTab, ValidatorCatalogReader catalogReader, AlgDataTypeFactory typeFactory, Conformance conformance ) { + FarragoTestValidator( OperatorTable opTab, AlgDataTypeFactory typeFactory, Conformance conformance ) { super( opTab, Catalog.snapshot(), typeFactory, conformance ); } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java index c3888c14b9..b4006fc39b 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/AbstractSqlTester.java @@ -21,10 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -49,28 +47,19 @@ import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; import org.polypheny.db.runtime.Utilities; -import org.polypheny.db.sql.language.SqlCall; -import org.polypheny.db.sql.language.SqlIntervalLiteral; import org.polypheny.db.sql.language.SqlLiteral; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlOperator; -import org.polypheny.db.sql.language.SqlSelect; import org.polypheny.db.sql.language.SqlTestFactory; -import org.polypheny.db.sql.language.SqlUtil; -import org.polypheny.db.sql.language.dialect.AnsiSqlDialect; import org.polypheny.db.sql.language.parser.SqlParserUtil; import org.polypheny.db.sql.language.parser.SqlParserUtil.StringAndPos; import org.polypheny.db.sql.language.util.SqlShuttle; import org.polypheny.db.sql.language.utils.SqlValidatorTestCase.Tester; import org.polypheny.db.sql.language.validate.SqlValidator; import org.polypheny.db.sql.language.validate.SqlValidatorNamespace; -import org.polypheny.db.sql.language.validate.SqlValidatorScope; import org.polypheny.db.type.PolyType; -import org.polypheny.db.util.Collation; -import org.polypheny.db.util.Collation.Coercibility; import org.polypheny.db.util.Conformance; import org.polypheny.db.util.Pair; -import org.polypheny.db.util.TestUtil; import org.polypheny.db.util.Util; @@ -206,34 +195,6 @@ public void checkColumnType( String sql, String expected ) { } - @Override - public void checkFieldOrigin( String sql, String fieldOriginList ) { - SqlValidator validator = getValidator(); - SqlNode n = parseAndValidate( validator, sql ); - final List> list = validator.getFieldOrigins( n ); - final StringBuilder buf = new StringBuilder( "{" ); - int i = 0; - for ( List strings : list ) { - if ( i++ > 0 ) { - buf.append( ", " ); - } - if ( strings == null ) { - buf.append( "null" ); - } else { - int j = 0; - for ( String s : strings ) { - if ( j++ > 0 ) { - buf.append( '.' ); - } - buf.append( s ); - } - } - } - buf.append( "}" ); - assertEquals( fieldOriginList, buf.toString() ); - } - - @Override public void checkResultType( String sql, String expected ) { AlgDataType actualType = getResultType( sql ); @@ -242,31 +203,6 @@ public void checkResultType( String sql, String expected ) { } - @Override - public void checkIntervalConv( String sql, String expected ) { - SqlValidator validator = getValidator(); - final SqlCall n = (SqlCall) parseAndValidate( validator, sql ); - - SqlNode node = null; - for ( int i = 0; i < n.operandCount(); i++ ) { - node = SqlUtil.stripAs( n.operand( i ) ); - if ( node instanceof SqlCall ) { - node = ((SqlCall) node).operand( 0 ); - break; - } - } - - assertNotNull( node ); - SqlIntervalLiteral intervalLiteral = (SqlIntervalLiteral) node; - SqlIntervalLiteral.IntervalValue interval = (SqlIntervalLiteral.IntervalValue) intervalLiteral.getValue(); - long l = interval.getIntervalQualifier().isYearMonth() - ? SqlParserUtil.intervalToMonths( interval ) - : SqlParserUtil.intervalToMillis( interval ); - String actual = l + ""; - assertEquals( expected, actual ); - } - - @Override public void checkType( String expression, String type ) { for ( String sql : buildQueries( expression ) ) { @@ -275,31 +211,6 @@ public void checkType( String expression, String type ) { } - @Override - public void checkCollation( String expression, String expectedCollationName, Coercibility expectedCoercibility ) { - for ( String sql : buildQueries( expression ) ) { - AlgDataType actualType = getColumnType( sql ); - Collation collation = actualType.getCollation(); - - assertEquals( expectedCollationName, collation.getCollationName() ); - assertEquals( expectedCoercibility, collation.getCoercibility() ); - } - } - - - @Override - public void checkCharset( String expression, Charset expectedCharset ) { - for ( String sql : buildQueries( expression ) ) { - AlgDataType actualType = getColumnType( sql ); - Charset actualCharset = actualType.getCharset(); - - if ( !expectedCharset.equals( actualCharset ) ) { - fail( "\n" + "Expected=" + expectedCharset.name() + "\n" + " actual=" + actualCharset.name() ); - } - } - } - - @Override public SqlTester withQuoting( Quoting quoting ) { return with( "quoting", quoting ); @@ -502,14 +413,6 @@ public void checkMonotonic( String query, Monotonicity expectedMonotonicity ) { } - @Override - public void checkRewrite( SqlValidator validator, String query, String expectedRewrite ) { - SqlNode rewrittenNode = parseAndValidate( validator, query ); - String actualRewrite = rewrittenNode.toSqlString( AnsiSqlDialect.DEFAULT, false ).getSql(); - TestUtil.assertEqualsVerbose( expectedRewrite, Util.toLinux( actualRewrite ) ); - } - - @Override public void checkFails( String expression, String expectedError, boolean runtime ) { if ( runtime ) { @@ -536,17 +439,6 @@ public void checkQuery( String sql ) { } - @Override - public Monotonicity getMonotonicity( String sql ) { - final SqlValidator validator = getValidator(); - final SqlNode node = parseAndValidate( validator, sql ); - final SqlSelect select = (SqlSelect) node; - final SqlNode selectItem0 = select.getSqlSelectList().getSqlList().get( 0 ); - final SqlValidatorScope scope = validator.getSelectScope( select ); - return selectItem0.getMonotonicity( scope ); - } - - public static String buildQuery( String expression ) { return "values (" + expression + ")"; } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/SqlValidatorTestCase.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/SqlValidatorTestCase.java index cac6cd116b..e6b89fb919 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/SqlValidatorTestCase.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/utils/SqlValidatorTestCase.java @@ -17,23 +17,15 @@ package org.polypheny.db.sql.language.utils; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.nio.charset.Charset; import org.junit.rules.MethodRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; -import org.polypheny.db.algebra.constant.ConformanceEnum; -import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.MockCatalogReaderExtended; import org.polypheny.db.languages.NodeParseException; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlTestFactory; import org.polypheny.db.sql.language.parser.SqlParserUtil; import org.polypheny.db.sql.language.validate.SqlValidator; -import org.polypheny.db.util.Collation.Coercibility; import org.polypheny.db.util.Conformance; @@ -46,10 +38,6 @@ */ public class SqlValidatorTestCase { - private static final SqlTestFactory EXTENDED_TEST_FACTORY = SqlTestFactory.INSTANCE.withCatalogReader( MockCatalogReaderExtended::new ); - static final SqlTester EXTENDED_CATALOG_TESTER = new SqlValidatorTester( EXTENDED_TEST_FACTORY ); - static final SqlTester EXTENDED_CATALOG_TESTER_2003 = new SqlValidatorTester( EXTENDED_TEST_FACTORY ).withConformance( ConformanceEnum.PRAGMATIC_2003 ); - static final SqlTester EXTENDED_CATALOG_TESTER_LENIENT = new SqlValidatorTester( EXTENDED_TEST_FACTORY ).withConformance( ConformanceEnum.LENIENT ); public static final MethodRule TESTER_CONFIGURATION_RULE = new TesterConfigurationRule(); protected SqlTester tester; @@ -81,36 +69,11 @@ public final Sql expr( String sql ) { } - public final Sql winSql( String sql ) { - return sql( sql ); - } - - - public final Sql win( String sql ) { - return sql( "select * from emp " + sql ); - } - - - public Sql winExp( String sql ) { - return winSql( "select " + sql + " from emp window w as (order by deptno)" ); - } - - - public Sql winExp2( String sql ) { - return winSql( "select " + sql + " from emp" ); - } - - public void check( String sql ) { sql( sql ).ok(); } - public void checkExp( String sql ) { - tester.assertExceptionIsThrown( AbstractSqlTester.buildQuery( sql ), null ); - } - - /** * Checks that a SQL query gives a particular error, or succeeds if {@code expected} is null. */ @@ -119,83 +82,6 @@ public final void checkFails( String sql, String expected ) { } - /** - * Checks that a SQL expression gives a particular error. - */ - public final void checkExpFails( String sql, String expected ) { - tester.assertExceptionIsThrown( AbstractSqlTester.buildQuery( sql ), expected ); - } - - - /** - * Checks that a SQL expression gives a particular error, and that the location of the error is the whole expression. - */ - public final void checkWholeExpFails( String sql, String expected ) { - assert sql.indexOf( '^' ) < 0; - checkExpFails( "^" + sql + "^", expected ); - } - - - public final void checkExpType( String sql, String expected ) { - checkColumnType( AbstractSqlTester.buildQuery( sql ), expected ); - } - - - /** - * Checks that a query returns a single column, and that the column has the expected type. For example, - * - * checkColumnType("SELECT empno FROM Emp", "INTEGER NOT NULL"); - * - * @param sql Query - * @param expected Expected type, including nullability - */ - public final void checkColumnType( String sql, String expected ) { - tester.checkColumnType( sql, expected ); - } - - - /** - * Checks that a query returns a row of the expected type. For example, - * - * checkResultType("select empno, name from emp","{EMPNO INTEGER NOT NULL, NAME VARCHAR(10) NOT NULL}"); - * - * @param sql Query - * @param expected Expected row type - */ - public final void checkResultType( String sql, String expected ) { - tester.checkResultType( sql, expected ); - } - - - /** - * Checks that the first column returned by a query has the expected type. For example, - * - * checkQueryType("SELECT empno FROM Emp", "INTEGER NOT NULL"); - * - * @param sql Query - * @param expected Expected type, including nullability - */ - public final void checkIntervalConv( String sql, String expected ) { - tester.checkIntervalConv( AbstractSqlTester.buildQuery( sql ), expected ); - } - - - protected final void assertExceptionIsThrown( String sql, String expectedMsgPattern ) { - assert expectedMsgPattern != null; - tester.assertExceptionIsThrown( sql, expectedMsgPattern ); - } - - - public void checkCharset( String sql, Charset expectedCharset ) { - tester.checkCharset( sql, expectedCharset ); - } - - - public void checkCollation( String sql, String expectedCollationName, Coercibility expectedCoercibility ) { - tester.checkCollation( sql, expectedCollationName, expectedCoercibility ); - } - - /** * Checks whether an exception matches the expected pattern. If sap contains an error location, checks this too. * @@ -251,50 +137,16 @@ public interface Tester { */ AlgDataType getResultType( String sql ); - void checkCollation( String sql, String expectedCollationName, Coercibility expectedCoercibility ); - - void checkCharset( String sql, Charset expectedCharset ); - /** * Checks that a query returns one column of an expected type. For example, checkType("VALUES (1 + 2)", "INTEGER NOT NULL"). */ void checkColumnType( String sql, String expected ); - /** - * Given a SQL query, returns a list of the origins of each result field. - * - * @param sql SQL query - * @param fieldOriginList Field origin list, e.g. "{(CATALOG.SALES.EMP.EMPNO, null)}" - */ - void checkFieldOrigin( String sql, String fieldOriginList ); - - /** - * Checks that a query gets rewritten to an expected form. - * - * @param validator validator to use; null for default - * @param query query to test - * @param expectedRewrite expected SQL text after rewrite and unparse - */ - void checkRewrite( SqlValidator validator, String query, String expectedRewrite ); - /** * Checks that a query returns one column of an expected type. For example, checkType("select empno, name from emp""{EMPNO INTEGER NOT NULL, NAME VARCHAR(10) NOT NULL}"). */ void checkResultType( String sql, String expected ); - /** - * Checks if the interval value conversion to milliseconds is valid. For example, checkIntervalConv(VALUES (INTERVAL '1' Minute), "60000"). - */ - void checkIntervalConv( String sql, String expected ); - - /** - * Given a SQL query, returns the monotonicity of the first item in the SELECT clause. - * - * @param sql SQL query - * @return Monotonicity - */ - Monotonicity getMonotonicity( String sql ); - Conformance getConformance(); } @@ -322,31 +174,11 @@ static class Sql { } - Sql tester( SqlTester tester ) { - return new Sql( tester, sql, true ); - } - - public Sql sql( String sql ) { return new Sql( tester, sql, true ); } - Sql withExtendedCatalog() { - return tester( EXTENDED_CATALOG_TESTER ); - } - - - Sql withExtendedCatalog2003() { - return tester( EXTENDED_CATALOG_TESTER_2003 ); - } - - - Sql withExtendedCatalogLenient() { - return tester( EXTENDED_CATALOG_TESTER_LENIENT ); - } - - Sql ok() { tester.assertExceptionIsThrown( sql, null ); return this; @@ -359,48 +191,12 @@ Sql fails( String expected ) { } - Sql failsIf( boolean b, String expected ) { - if ( b ) { - fails( expected ); - } else { - ok(); - } - return this; - } - - public Sql type( String expectedType ) { tester.checkResultType( sql, expectedType ); return this; } - public Sql columnType( String expectedType ) { - tester.checkColumnType( sql, expectedType ); - return this; - } - - - public Sql monotonic( Monotonicity expectedMonotonicity ) { - tester.checkMonotonic( sql, expectedMonotonicity ); - return this; - } - - - public Sql bindType( final String bindType ) { - tester.check( sql, null, parameterRowType -> assertThat( parameterRowType.toString(), is( bindType ) ), result -> { - } ); - return this; - } - - - /** - * Removes the carets from the SQL string. Useful if you want to run a test once at a conformance level where it fails, then run it again at a conformance level where it succeeds. - */ - public Sql sansCarets() { - return new Sql( tester, sql.replace( "^", "" ), true ); - } - } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java index 23f15c036b..d886e2cbd7 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java @@ -40,8 +40,6 @@ import org.polypheny.db.plan.AlgTraitDef; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Context; -import org.polypheny.db.prepare.PolyphenyDbCatalogReader; -import org.polypheny.db.prepare.Prepare.CatalogReader; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexExecutor; import org.polypheny.db.schema.SchemaPlus; @@ -225,7 +223,6 @@ public Node parse( final Reader reader ) throws NodeParseException { public Node validate( Node sqlNode ) throws ValidationException { ensure( State.STATE_3_PARSED ); final Conformance conformance = conformance(); - final PolyphenyDbCatalogReader catalogReader = createCatalogReader(); this.validator = new PolyphenyDbSqlValidator( operatorTable != null ? operatorTable : SqlStdOperatorTable.instance(), Catalog.snapshot(), typeFactory, conformance ); this.validator.setIdentifierExpansion( true ); try { @@ -262,7 +259,7 @@ public AlgRoot alg( Node sql ) throws AlgConversionException { .trimUnusedFields( false ) .convertTableAccess( false ) .build(); - final NodeToAlgConverter sqlToRelConverter = getSqlToRelConverter( (SqlValidator) validator, createCatalogReader(), cluster, StandardConvertletTable.INSTANCE, config ); + final NodeToAlgConverter sqlToRelConverter = getSqlToRelConverter( (SqlValidator) validator, cluster, StandardConvertletTable.INSTANCE, config ); root = sqlToRelConverter.convertQuery( validatedSqlNode, false, true ); root = root.withAlg( sqlToRelConverter.flattenTypes( root.alg, true ) ); final AlgBuilder algBuilder = config.getAlgBuilderFactory().create( cluster, null ); @@ -274,7 +271,6 @@ public AlgRoot alg( Node sql ) throws AlgConversionException { private SqlToAlgConverter getSqlToRelConverter( SqlValidator validator, - CatalogReader catalogReader, AlgOptCluster cluster, SqlRexConvertletTable convertletTable, Config config ) { @@ -282,17 +278,6 @@ private SqlToAlgConverter getSqlToRelConverter( } - // PolyphenyDbCatalogReader is stateless; no need to storeId one - private PolyphenyDbCatalogReader createCatalogReader() { - /*final SchemaPlus rootSchema = rootSchema( Catalog.snapshot() ); - return new PolyphenyDbCatalogReader( - PolyphenyDbSchema.from( rootSchema ), - PolyphenyDbSchema.from( defaultSnapshot ).path( null ), - typeFactory );*/ - return null; - } - - private static SchemaPlus rootSchema( SchemaPlus schema ) { for ( ; ; ) { if ( schema.getParentSchema() == null ) { diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/TraitPropagationTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/TraitPropagationTest.java index 89a95f21e1..03b8167ef7 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/TraitPropagationTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/TraitPropagationTest.java @@ -66,7 +66,6 @@ import org.polypheny.db.algebra.rules.SortRemoveRule; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.Catalog; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.languages.PolyphenyDbServerStatement; import org.polypheny.db.plan.AlgOptCluster; @@ -75,7 +74,6 @@ import org.polypheny.db.plan.AlgOptRule; import org.polypheny.db.plan.AlgOptRuleCall; import org.polypheny.db.plan.AlgOptRuleOperand; -import org.polypheny.db.plan.AlgOptSchema; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTrait; import org.polypheny.db.plan.AlgTraitSet; @@ -85,10 +83,8 @@ import org.polypheny.db.plan.volcano.AlgSubset; import org.polypheny.db.plan.volcano.VolcanoPlanner; import org.polypheny.db.prepare.Context; -import org.polypheny.db.prepare.PolyphenyDbCatalogReader; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexNode; -import org.polypheny.db.schema.SchemaPlus; import org.polypheny.db.sql.volcano.TraitPropagationTest.PropAction.Phys; import org.polypheny.db.sql.volcano.TraitPropagationTest.PropAction.PhysAggRule; import org.polypheny.db.sql.volcano.TraitPropagationTest.PropAction.PhysProjRule; @@ -98,7 +94,6 @@ import org.polypheny.db.tools.Frameworks; import org.polypheny.db.tools.RuleSet; import org.polypheny.db.tools.RuleSets; -import org.polypheny.db.type.PolyType; import org.polypheny.db.util.ImmutableBitSet; @@ -130,70 +125,6 @@ public void testOne() throws Exception { */ static class PropAction { - public AlgNode apply( AlgOptCluster cluster, AlgOptSchema algOptSchema, SchemaPlus rootSchema ) { - final AlgDataTypeFactory typeFactory = cluster.getTypeFactory(); - final RexBuilder rexBuilder = cluster.getRexBuilder(); - final AlgOptPlanner planner = cluster.getPlanner(); - - final AlgDataType stringType = typeFactory.createJavaType( String.class ); - final AlgDataType integerType = typeFactory.createJavaType( Integer.class ); - final AlgDataType sqlBigInt = typeFactory.createPolyType( PolyType.BIGINT ); - - // SELECT * from T; - /*final Entity entity = new AbstractEntity() { - @Override - public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - return typeFactory.builder() - .add( "s", null, stringType ) - .add( "i", null, integerType ).build(); - } - - - @Override - public Statistic getStatistic() { - return Statistics.of( 100d, ImmutableList.of(), ImmutableList.of( COLLATION ) ); - } - }; - - final AlgOptAbstractEntity t1 = new AlgOptAbstractEntity( algOptSchema, "t1", entity.getRowType( typeFactory ) ) { - @Override - public LogicalTable getCatalogTable() { - return null; - } - - - @Override - public T unwrap( Class clazz ) { - return clazz.isInstance( entity ) - ? clazz.cast( entity ) - : super.unwrap( clazz ); - } - }; - - final AlgNode rt1 = EnumerableScan.create( cluster, t1 ); - - // project s column - AlgNode project = LogicalProject.create( - rt1, - ImmutableList.of( (RexNode) rexBuilder.makeInputRef( stringType, 0 ), rexBuilder.makeInputRef( integerType, 1 ) ), - typeFactory.builder().add( "s", null, stringType ).add( "i", null, integerType ).build() ); - - // aggregate on s, count - AggregateCall aggCall = AggregateCall.create( OperatorRegistry.getAgg( OperatorName.COUNT ), false, false, Collections.singletonList( 1 ), -1, AlgCollations.EMPTY, sqlBigInt, "cnt" ); - AlgNode agg = new LogicalAggregate( cluster, cluster.traitSetOf( Convention.NONE ), project, false, ImmutableBitSet.of( 0 ), null, Collections.singletonList( aggCall ) ); - - final AlgNode rootRel = agg; - - AlgOptUtil.dumpPlan( "LOGICAL PLAN", rootRel, ExplainFormat.TEXT, ExplainLevel.DIGEST_ATTRIBUTES ); - - AlgTraitSet desiredTraits = rootRel.getTraitSet().replace( PHYSICAL ); - final AlgNode rootRel2 = planner.changeTraits( rootRel, desiredTraits ); - planner.setRoot( rootRel2 ); - return planner.findBestExp(); - }*/ - return null; - } - // RULES @@ -449,7 +380,6 @@ static AlgNode run( PropAction action, RuleSet rules ) throws Exception { final PolyphenyDbServerStatement statement = connection.createStatement().unwrap( PolyphenyDbServerStatement.class ); final Context prepareContext = statement.createPrepareContext(); final JavaTypeFactory typeFactory = prepareContext.getTypeFactory(); - PolyphenyDbCatalogReader catalogReader = new PolyphenyDbCatalogReader( prepareContext.getSnapshot(), typeFactory ); final RexBuilder rexBuilder = new RexBuilder( typeFactory ); final AlgOptPlanner planner = new VolcanoPlanner( config.getCostFactory(), config.getContext() ); @@ -463,8 +393,7 @@ static AlgNode run( PropAction action, RuleSet rules ) throws Exception { planner.addRule( r ); } - final AlgOptCluster cluster = AlgOptCluster.create( planner, rexBuilder, planner.emptyTraitSet(), Catalog.snapshot() ); - return action.apply( cluster, catalogReader, null ); + return null; } } From 0bb567ee7788cc24d9419a4204b5ce0b8e04222e Mon Sep 17 00:00:00 2001 From: datomo Date: Sun, 26 Nov 2023 23:09:59 +0100 Subject: [PATCH 08/15] reformatting and mongo adjustment --- .github/workflows/integration.yml | 2 +- .../java/org/polypheny/db/ResultIterator.java | 7 --- .../db/catalog/snapshot/Snapshot.java | 7 --- .../db/processing/AutomaticDdlProcessor.java | 31 ------------- gradle.properties | 6 +-- .../db/adapter/mongodb/MongoEntity.java | 29 +++++++++++- .../mongodb/rules/MongoTableModify.java | 2 +- .../polypheny/db/languages/MqlProcessor.java | 45 +------------------ 8 files changed, 33 insertions(+), 96 deletions(-) delete mode 100644 core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 70172bc236..022e633a1d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - adapter: [ mongodb, hsqldb, monetdb, postgresql, file, cottontail, cassandra, neo4j ] + adapter: [ mongodb, hsqldb, monetdb, postgresql, file, cottontail, neo4j ] name: Integration Tests (Java 11) steps: - name: Checkout diff --git a/core/src/main/java/org/polypheny/db/ResultIterator.java b/core/src/main/java/org/polypheny/db/ResultIterator.java index 5f5224c848..61b2c2d19f 100644 --- a/core/src/main/java/org/polypheny/db/ResultIterator.java +++ b/core/src/main/java/org/polypheny/db/ResultIterator.java @@ -75,8 +75,6 @@ public List> getNextBatch() { res.add( Lists.newArrayList( iterator.next() ) ); } - //List> res = MetaImpl.collect( cursorFactory, (Iterator) iterator., new ArrayList<>() ).stream().map( e -> (List) e ).collect( Collectors.toList() ); - if ( isTimed ) { stopWatch.stop(); executionTimeMonitor.setExecutionTime( stopWatch.getNanoTime() ); @@ -116,11 +114,6 @@ public List> getAllRowsAndClose() { } - public List getSingleRows() { - return getNextBatch( null ); - } - - @NotNull private List getNextBatch( @Nullable Function transformer ) { final Iterable iterable = () -> iterator; diff --git a/core/src/main/java/org/polypheny/db/catalog/snapshot/Snapshot.java b/core/src/main/java/org/polypheny/db/catalog/snapshot/Snapshot.java index bbec7badc4..7fb8ed07f2 100644 --- a/core/src/main/java/org/polypheny/db/catalog/snapshot/Snapshot.java +++ b/core/src/main/java/org/polypheny/db/catalog/snapshot/Snapshot.java @@ -19,14 +19,11 @@ import java.util.List; import java.util.Optional; import javax.annotation.Nullable; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; import org.jetbrains.annotations.NotNull; import org.polypheny.db.adapter.java.AdapterTemplate; import org.polypheny.db.algebra.constant.FunctionCategory; import org.polypheny.db.algebra.constant.Syntax; import org.polypheny.db.algebra.operators.OperatorTable; -import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalAdapter; import org.polypheny.db.catalog.entity.LogicalAdapter.AdapterType; import org.polypheny.db.catalog.entity.LogicalQueryInterface; @@ -48,10 +45,6 @@ public interface Snapshot extends OperatorTable { long id(); - default Expression getSnapshotExpression( long id ) { - return Expressions.call( Catalog.CATALOG_EXPRESSION, "getSnapshot", Expressions.constant( id ) ); - } - /** * Get all schemas which fit to the specified filter pattern. diff --git a/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java b/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java deleted file mode 100644 index 122f2f1422..0000000000 --- a/core/src/main/java/org/polypheny/db/processing/AutomaticDdlProcessor.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2019-2022 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 org.polypheny.db.languages.QueryParameters; -import org.polypheny.db.nodes.Node; -import org.polypheny.db.processing.QueryContext.ParsedQueryContext; -import org.polypheny.db.transaction.Statement; - - -public abstract class AutomaticDdlProcessor extends Processor { - - public abstract void autoGenerateDDL( Statement statement, ParsedQueryContext context ); - - public abstract boolean needsDdlGeneration( Node query, QueryParameters parameters ); - -} diff --git a/gradle.properties b/gradle.properties index e71361882f..b1d69367f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,9 +48,6 @@ cottontaildb_driver_version = 0.13.0 cottontaildb_grpc_version = 1.36.0 elasticsearch_rest_client_version = 6.2.4 elasticsearch_version = 6.2.4 -embedded_monetdb_version = 2.39 -embedded_mysql_version = 4.6.1 -embedded_postgres_version = 1.3.1 esri_geometry_api_version = 2.2.0 fmpp_plugin_version = 0.9.16 geode_core_version = 1.6.0 @@ -116,9 +113,8 @@ protobuf_plugin_version = 0.9.4 reflections_version = 0.10.2 shadow_plugin_version = 7.1.1 simplemagic_version = 1.16 -slf4j_api_version = 2.0.3 +slf4j_api_version = 2.0.9 transport_netty4_client_version = 6.2.4 typesafe_config_version = 1.2.1 unirest_version = 3.11.10 web3j_version = 5.0.0 -weka_version = 3.8.0 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 68355b3716..62b70c55fb 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 @@ -46,6 +46,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -80,12 +81,18 @@ 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.algebra.type.AlgDataTypeFactory; +import org.polypheny.db.algebra.type.AlgDataTypeImpl; +import org.polypheny.db.algebra.type.AlgProtoDataType; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalCollection; +import org.polypheny.db.catalog.entity.physical.PhysicalColumn; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -138,6 +145,27 @@ public class MongoEntity extends PhysicalEntity implements TranslatableEntity, M } + @Override + public AlgDataType getRowType() { + if ( namespaceType == NamespaceType.RELATIONAL ) { + return buildProto().apply( AlgDataTypeFactory.DEFAULT ); + } + return super.getRowType(); + } + + + public AlgProtoDataType buildProto() { + final AlgDataTypeFactory.Builder fieldInfo = AlgDataTypeFactory.DEFAULT.builder(); + + for ( PhysicalColumn column : fields.stream().map( f -> f.unwrap( PhysicalColumn.class ) ).sorted( Comparator.comparingInt( a -> a.position ) ).collect( Collectors.toList() ) ) { + AlgDataType sqlType = column.getAlgDataType( AlgDataTypeFactory.DEFAULT ); + fieldInfo.add( column.id, column.logicalName, column.name, sqlType ).nullable( column.nullable ); + } + + return AlgDataTypeImpl.proto( fieldInfo.build() ); + } + + public String toString() { return "MongoTable {" + physical.name + "}"; } @@ -325,7 +353,6 @@ public Modify toModificationCollection( } - @Override public Serializable[] getParameterArray() { return new Serializable[0]; 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 e57510f612..683bfac69d 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 @@ -150,7 +150,7 @@ private void handleUpdate( Implementor implementor ) { condImplementor.setStaticRowType( implementor.getStaticRowType() ); ((MongoAlg) input).implement( condImplementor ); implementor.filter = condImplementor.filter; - assert condImplementor.getStaticRowType() instanceof MongoRowType; + //assert condImplementor.getStaticRowType() instanceof MongoRowType; MongoRowType rowType = (MongoRowType) condImplementor.getStaticRowType(); int pos = 0; BsonDocument doc = new BsonDocument(); diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java index 92b8627fac..fb06f136f3 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MqlProcessor.java @@ -26,19 +26,15 @@ import org.polypheny.db.algebra.constant.ExplainFormat; 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; -import org.polypheny.db.languages.mql.MqlQueryParameters; import org.polypheny.db.languages.mql.parser.MqlParser; import org.polypheny.db.languages.mql.parser.MqlParser.MqlParserConfig; import org.polypheny.db.languages.mql2alg.MqlToAlgConverter; import org.polypheny.db.nodes.Node; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptUtil; -import org.polypheny.db.processing.AutomaticDdlProcessor; +import org.polypheny.db.processing.Processor; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.tools.AlgBuilder; @@ -46,7 +42,6 @@ import org.polypheny.db.transaction.LockManager; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; -import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.TransactionImpl; import org.polypheny.db.util.DeadlockException; import org.polypheny.db.util.Pair; @@ -54,7 +49,7 @@ @Slf4j -public class MqlProcessor extends AutomaticDdlProcessor { +public class MqlProcessor extends Processor { private static final MqlParserConfig parserConfig; @@ -101,42 +96,6 @@ public Pair validate( Transaction transaction, Node parsed, b } - @Override - public boolean needsDdlGeneration( Node query, QueryParameters parameters ) { - if ( query instanceof MqlCollectionStatement ) { - return Catalog.snapshot() - .getNamespace( ((MqlQueryParameters) parameters).getNamespaceId() ) - .stream().flatMap( n -> Catalog.getInstance().getSnapshot().doc().getCollections( n.id, null ).stream() ) - .noneMatch( t -> t.name.equals( ((MqlCollectionStatement) query).getCollection() ) ); - } - return false; - } - - - @Override - public void autoGenerateDDL( Statement statement, ParsedQueryContext context ) { - if ( context.getQueryNode().getEntity() == null ) { - try { - statement.getTransaction().commit(); - } catch ( TransactionException e ) { - throw new GenericRuntimeException( "There was a problem auto-generating the needed collection." ); - } - - throw new GenericRuntimeException( "No collections is used." ); - } - new MqlCreateCollection( - ParserPos.sum( Collections.singletonList( context.getQueryNode() ) ), - context.getQueryNode().getEntity(), - null ).execute( statement.getPrepareContext(), statement, context ); - try { - statement.getTransaction().commit(); - Catalog.getInstance().commit(); - } catch ( TransactionException e ) { - throw new GenericRuntimeException( "There was a problem auto-generating the needed collection." ); - } - } - - @Override public AlgRoot translate( Statement statement, ParsedQueryContext context ) { final StopWatch stopWatch = new StopWatch(); From ef69fdee4342bd04c650c1fc0e4fa8847c6cee66 Mon Sep 17 00:00:00 2001 From: datomo Date: Mon, 27 Nov 2023 10:46:17 +0100 Subject: [PATCH 09/15] renamed namespaceType to DataModel --- .../org/polypheny/db/PolyImplementation.java | 10 ++-- .../org/polypheny/db/adapter/Adapter.java | 4 +- .../org/polypheny/db/algebra/AlgNode.java | 4 +- .../document/LogicalDocumentValues.java | 6 +-- .../rules/AllocationToPhysicalScanRule.java | 10 ++-- .../algebra/rules/LoptSemiJoinOptimizer.java | 4 +- .../org/polypheny/db/catalog/Catalog.java | 6 +-- .../db/catalog/entity/LogicalEntity.java | 10 ++-- .../allocation/AllocationCollection.java | 4 +- .../entity/allocation/AllocationEntity.java | 4 +- .../entity/allocation/AllocationGraph.java | 4 +- .../entity/allocation/AllocationTable.java | 4 +- .../entity/logical/LogicalCollection.java | 4 +- .../catalog/entity/logical/LogicalColumn.java | 4 +- .../catalog/entity/logical/LogicalEntity.java | 6 +-- .../catalog/entity/logical/LogicalGraph.java | 4 +- .../entity/logical/LogicalNamespace.java | 10 ++-- .../catalog/entity/logical/LogicalTable.java | 6 +-- .../entity/physical/PhysicalCollection.java | 4 +- .../entity/physical/PhysicalColumn.java | 4 +- .../entity/physical/PhysicalEntity.java | 6 +-- .../entity/physical/PhysicalField.java | 6 +-- .../entity/physical/PhysicalGraph.java | 4 +- .../entity/physical/PhysicalTable.java | 4 +- .../db/catalog/impl/AdapterRestore.java | 2 +- .../polypheny/db/catalog/impl/NCatalog.java | 4 +- .../db/catalog/impl/PolyCatalog.java | 24 ++++----- .../{NamespaceType.java => DataModel.java} | 22 ++++---- .../snapshot/impl/AllocSnapshotImpl.java | 14 +++--- .../snapshot/impl/SnapshotBuilder.java | 8 +-- .../java/org/polypheny/db/ddl/DdlManager.java | 4 +- .../polypheny/db/interpreter/Bindables.java | 2 +- .../db/languages/LanguageManager.java | 29 ++++------- .../polypheny/db/languages/QueryLanguage.java | 8 +-- .../db/languages/QueryParameters.java | 8 +-- .../processing/ExtendedQueryParameters.java | 8 +-- .../db/processing/ImplementationContext.java | 37 ++++++++++---- .../processing/LogicalAlgAnalyzeShuttle.java | 22 ++++---- .../polypheny/db/processing/Processor.java | 2 +- .../db/routing/LogicalQueryInformation.java | 6 +-- .../java/org/polypheny/db/schema/Entity.java | 6 +-- .../org/polypheny/db/schema/SchemaPlus.java | 4 +- .../polypheny/db/schema/trait/ModelTrait.java | 12 ++--- .../org/polypheny/db/tools/AlgBuilder.java | 4 +- .../main/java/org/polypheny/db/util/Util.java | 4 +- .../org/polypheny/db/catalog/MockCatalog.java | 4 +- .../java/org/polypheny/db/PolyphenyDb.java | 10 ++-- .../org/polypheny/db/ddl/DdlManagerImpl.java | 20 ++++---- .../org/polypheny/db/ddl/DefaultInserter.java | 4 +- .../db/processing/AbstractQueryProcessor.java | 6 +-- .../processing/ConstraintEnforceAttacher.java | 4 +- .../shuttles/LogicalQueryInformationImpl.java | 10 ++-- .../db/routing/routers/AbstractDqlRouter.java | 4 +- .../db/routing/routers/BaseRouter.java | 4 +- .../db/transaction/EntityAccessMap.java | 4 +- .../db/catalog/CatalogTransactionTest.java | 6 +-- .../db/information/InformationManager.java | 10 ++++ .../statistics/DashboardInformation.java | 6 +-- .../statistics/StatisticQueryProcessor.java | 6 +-- .../monitoring/statistics/StatisticTable.java | 6 +-- .../statistics/StatisticsManagerImpl.java | 2 +- .../org/polypheny/db/avatica/DbmsMeta.java | 50 +++++++++---------- ...enyDbSignature.java => PolySignature.java} | 18 +++---- ...ntHandle.java => PolyStatementHandle.java} | 8 +-- .../db/avatica/PolyphenyDbResultSet.java | 16 +++--- .../polypheny/db/cql/CqlLanguagePlugin.java | 4 +- .../db/cypher/CypherLanguagePlugin.java | 4 +- .../jdbc/alg2sql/AlgToSqlConverterTest.java | 6 +-- .../db/adapter/mongodb/MongoEntity.java | 6 +-- .../db/languages/MongoLanguagePlugin.java | 4 +- .../db/languages/mql/MqlQueryParameters.java | 6 +-- .../db/languages/mql/MqlUseDatabase.java | 4 +- .../languages/mql2alg/MqlToAlgConverter.java | 4 +- .../polypheny/db/adapter/neo4j/NeoEntity.java | 2 +- .../org/polypheny/db/PigLanguagePlugin.java | 4 +- .../sql-language/src/main/codegen/Parser.jj | 14 +++--- .../src/main/codegen/includes/ddlParser.ftl | 8 +-- .../polypheny/db/sql/SqlLanguagePlugin.java | 4 +- .../org/polypheny/db/sql/SqlProcessor.java | 8 +-- .../polypheny/db/sql/language/SqlInsert.java | 6 +-- .../sql/language/ddl/SqlCreateNamespace.java | 8 +-- .../db/sql/language/ddl/SqlDdlNodes.java | 6 +-- .../validate/IdentifierNamespace.java | 8 +-- .../language/validate/SqlValidatorImpl.java | 4 +- .../language/validate/SqlValidatorUtil.java | 4 +- .../db/sql/sql2alg/SqlToAlgConverter.java | 6 +-- .../java/org/polypheny/db/webui/Crud.java | 14 +++--- .../org/polypheny/db/webui/WebSocket.java | 2 +- .../polypheny/db/webui/crud/CatalogCrud.java | 26 +++++----- .../polypheny/db/webui/crud/LanguageCrud.java | 17 ++++--- .../polypheny/db/webui/models/Namespace.java | 8 +-- .../db/webui/models/SidebarElement.java | 10 ++-- .../catalog/requests/NamespaceRequest.java | 4 +- .../catalog/schema/CollectionModel.java | 8 +-- .../models/catalog/schema/EntityModel.java | 10 ++-- .../models/catalog/schema/GraphModel.java | 8 +-- .../models/catalog/schema/NamespaceModel.java | 10 ++-- .../models/catalog/schema/TableModel.java | 8 +-- .../models/requests/SchemaTreeRequest.java | 4 +- .../db/webui/models/results/DocResult.java | 6 +-- .../db/webui/models/results/GraphResult.java | 6 +-- .../models/results/RelationalResult.java | 6 +-- .../db/webui/models/results/Result.java | 6 +-- 103 files changed, 428 insertions(+), 405 deletions(-) rename core/src/main/java/org/polypheny/db/catalog/logistic/{NamespaceType.java => DataModel.java} (75%) rename plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/{PolyphenyDbSignature.java => PolySignature.java} (90%) rename plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/{PolyphenyDbStatementHandle.java => PolyStatementHandle.java} (85%) diff --git a/core/src/main/java/org/polypheny/db/PolyImplementation.java b/core/src/main/java/org/polypheny/db/PolyImplementation.java index f3ed0e0e96..eff55e46fd 100644 --- a/core/src/main/java/org/polypheny/db/PolyImplementation.java +++ b/core/src/main/java/org/polypheny/db/PolyImplementation.java @@ -39,7 +39,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory.Builder; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.interpreter.BindableConvention; import org.polypheny.db.monitoring.events.MonitoringType; import org.polypheny.db.monitoring.events.StatementEvent; @@ -64,7 +64,7 @@ public class PolyImplementation { private final long maxRowCount = -1; private final Kind kind; private Bindable bindable; - private final NamespaceType namespaceType; + private final DataModel dataModel; private final ExecutionTimeMonitor executionTimeMonitor; private CursorFactory cursorFactory; private final Convention resultConvention; @@ -83,7 +83,7 @@ public class PolyImplementation { * on access e.g. {@link #getColumns()} * * @param rowType defines the types of the result - * @param namespaceType type of the + * @param dataModel type of the * @param executionTimeMonitor to keep track of different execution times * @param preparedResult nullable result, which holds all info from the execution * @param kind of initial query, which is used to get type of result e.g. DDL, DQL,... @@ -92,14 +92,14 @@ public class PolyImplementation { */ public PolyImplementation( @Nullable AlgDataType rowType, - NamespaceType namespaceType, + DataModel dataModel, ExecutionTimeMonitor executionTimeMonitor, @Nullable PreparedResult preparedResult, Kind kind, Statement statement, @Nullable Convention resultConvention ) { - this.namespaceType = namespaceType; + this.dataModel = dataModel; this.executionTimeMonitor = executionTimeMonitor; this.preparedResult = preparedResult; this.kind = kind; diff --git a/core/src/main/java/org/polypheny/db/adapter/Adapter.java b/core/src/main/java/org/polypheny/db/adapter/Adapter.java index acda9edfaa..31eaff2201 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Adapter.java +++ b/core/src/main/java/org/polypheny/db/adapter/Adapter.java @@ -37,7 +37,7 @@ import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.Config; import org.polypheny.db.config.Config.ConfigListener; @@ -271,7 +271,7 @@ public void addInformationPhysicalNames() { List physicalsOnAdapter = new ArrayList<>();//snapshot.physical().getPhysicalsOnAdapter( adapterId ); for ( PhysicalEntity entity : physicalsOnAdapter ) { - if ( entity.namespaceType != NamespaceType.RELATIONAL ) { + if ( entity.dataModel != DataModel.RELATIONAL ) { continue; } PhysicalTable physicalTable = (PhysicalTable) entity; diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgNode.java b/core/src/main/java/org/polypheny/db/algebra/AlgNode.java index ea80a1709d..dbe08bf153 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgNode.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgNode.java @@ -45,7 +45,7 @@ import org.polypheny.db.algebra.metadata.Metadata; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.entity.LogicalEntity; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.plan.AlgImplementor; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; @@ -359,7 +359,7 @@ default AlgNode unfoldView( @Nullable AlgNode parent, int index, AlgOptCluster c return this; } - default NamespaceType getModel() { + default DataModel getModel() { return Objects.requireNonNull( getTraitSet().getTrait( ModelTraitDef.INSTANCE ) ).getDataModel(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentValues.java b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentValues.java index a970957763..ce04b86bec 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentValues.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentValues.java @@ -22,7 +22,7 @@ import org.polypheny.db.algebra.core.document.DocumentValues; import org.polypheny.db.algebra.core.relational.RelationalTransformable; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; @@ -83,8 +83,8 @@ public static LogicalDocumentValues createOneTuple( AlgOptCluster cluster ) { @Override - public NamespaceType getModel() { - return NamespaceType.DOCUMENT; + public DataModel getModel() { + return DataModel.DOCUMENT; } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java index 4c2a2d7c95..a6b2c4c264 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalScanRule.java @@ -53,7 +53,7 @@ public void onMatch( AlgOptRuleCall call ) { AlgNode newAlg; - switch ( scan.entity.namespaceType ) { + switch ( scan.entity.dataModel ) { case RELATIONAL: newAlg = handleRelationalEntity( call, scan, alloc ); break; @@ -73,7 +73,7 @@ public void onMatch( AlgOptRuleCall call ) { private static AlgNode handleGraphEntity( AlgOptRuleCall call, Scan scan, AllocationEntity alloc ) { AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).getGraphScan( alloc.id, call.builder() ); - if ( scan.getModel() != scan.entity.namespaceType ) { + if ( scan.getModel() != scan.entity.dataModel ) { // cross-model queries need a transformer first, we let another rule handle that alg = call.builder().push( alg ).transform( scan.getTraitSet().getTrait( ModelTraitDef.INSTANCE ), scan.getRowType(), true ).build(); } @@ -84,7 +84,7 @@ private static AlgNode handleGraphEntity( AlgOptRuleCall call, Scan scan, All private static AlgNode handleDocumentEntity( AlgOptRuleCall call, Scan scan, AllocationEntity alloc ) { AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).getDocumentScan( alloc.id, call.builder() ); - if ( scan.getModel() != scan.entity.namespaceType ) { + if ( scan.getModel() != scan.entity.dataModel ) { // cross-model queries need a transformer first, we let another rule handle that alg = call.builder().push( alg ).transform( scan.getTraitSet().getTrait( ModelTraitDef.INSTANCE ), scan.getRowType(), true ).build(); } @@ -94,11 +94,11 @@ private static AlgNode handleDocumentEntity( AlgOptRuleCall call, Scan scan, private AlgNode handleRelationalEntity( AlgOptRuleCall call, Scan scan, AllocationEntity alloc ) { AlgNode alg = AdapterManager.getInstance().getAdapter( alloc.adapterId ).getRelScan( alloc.id, call.builder() ); - if ( scan.getModel() == scan.entity.namespaceType ) { + if ( scan.getModel() == scan.entity.dataModel ) { alg = attachReorder( alg, scan, call.builder() ); } - if ( scan.getModel() != scan.entity.namespaceType ) { + if ( scan.getModel() != scan.entity.dataModel ) { // cross-model queries need a transformer first, we let another rule handle that alg = call.builder().push( alg ).transform( scan.getTraitSet().getTrait( ModelTraitDef.INSTANCE ), scan.getRowType(), true ).build(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java b/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java index 37e5508872..e07eec7b82 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java @@ -53,8 +53,8 @@ import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptUtil; @@ -669,7 +669,7 @@ public int compare( Integer alg1Idx, Integer alg2Idx ) { private abstract static class LcsEntity extends LogicalEntity { protected LcsEntity() { - super( -1, "lcs", -1, EntityType.ENTITY, NamespaceType.RELATIONAL, false ); + super( -1, "lcs", -1, EntityType.ENTITY, DataModel.RELATIONAL, false ); } } diff --git a/core/src/main/java/org/polypheny/db/catalog/Catalog.java b/core/src/main/java/org/polypheny/db/catalog/Catalog.java index 640b682d06..639a40cb48 100644 --- a/core/src/main/java/org/polypheny/db/catalog/Catalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/Catalog.java @@ -45,7 +45,7 @@ import org.polypheny.db.catalog.entity.LogicalQueryInterface; import org.polypheny.db.catalog.entity.LogicalUser; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.iface.QueryInterfaceManager.QueryInterfaceTemplate; import org.polypheny.db.util.PolyphenyMode; @@ -178,11 +178,11 @@ public void removeObserver( PropertyChangeListener listener ) { * Adds a schema in a specified database * * @param name The name of the schema - * @param namespaceType The type of this schema + * @param dataModel The type of this schema * @param caseSensitive * @return The id of the inserted schema */ - public abstract long createNamespace( String name, NamespaceType namespaceType, boolean caseSensitive ); + public abstract long createNamespace( String name, DataModel dataModel, boolean caseSensitive ); /** * Add an adapter diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java index 7f4edf94be..9b3e1c9195 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalEntity.java @@ -32,8 +32,8 @@ 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.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.refactor.CatalogType; import org.polypheny.db.schema.Statistic; import org.polypheny.db.schema.Statistics; @@ -55,7 +55,7 @@ public abstract class LogicalEntity implements LogicalObject, Wrapper, Serializa public EntityType entityType; @Serialize - public NamespaceType namespaceType; + public DataModel dataModel; @Serialize @SerializeNullable @@ -73,19 +73,19 @@ public LogicalEntity( String name, long namespaceId, EntityType type, - NamespaceType namespaceType, + DataModel dataModel, boolean modifiable ) { this.id = id; this.namespaceId = namespaceId; this.name = name; this.entityType = type; - this.namespaceType = namespaceType; + this.dataModel = dataModel; this.modifiable = modifiable; } public AlgDataType getRowType() { - switch ( namespaceType ) { + switch ( dataModel ) { case RELATIONAL: throw new UnsupportedOperationException( "Should be overwritten by child" ); case DOCUMENT: diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationCollection.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationCollection.java index 0368c92f16..31b207c0bc 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationCollection.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationCollection.java @@ -24,7 +24,7 @@ import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; @EqualsAndHashCode(callSuper = true) @Value @@ -38,7 +38,7 @@ public AllocationCollection( @Deserialize("logicalId") long logicalId, @Deserialize("namespaceId") long namespaceId, @Deserialize("adapterId") long adapterId ) { - super( id, placementId, partitionId, logicalId, namespaceId, adapterId, NamespaceType.DOCUMENT ); + super( id, placementId, partitionId, logicalId, namespaceId, adapterId, DataModel.DOCUMENT ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java index 8e7f98f937..fac6d95b99 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java @@ -25,8 +25,8 @@ import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.PartitionType; @EqualsAndHashCode(callSuper = true) @@ -59,7 +59,7 @@ protected AllocationEntity( long logicalId, long namespaceId, long adapterId, - NamespaceType type ) { + DataModel type ) { super( id, null, namespaceId, EntityType.ENTITY, type, true ); this.adapterId = adapterId; this.logicalId = logicalId; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationGraph.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationGraph.java index 9cbda2db31..0c0f89e8d0 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationGraph.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationGraph.java @@ -24,7 +24,7 @@ import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; @EqualsAndHashCode(callSuper = true) @Value @@ -39,7 +39,7 @@ public AllocationGraph( @Deserialize("logicalId") long logicalId, @Deserialize("namespaceId") long namespaceId, @Deserialize("adapterId") long adapterId ) { - super( id, placementId, partitionId, logicalId, namespaceId, adapterId, NamespaceType.GRAPH ); + super( id, placementId, partitionId, logicalId, namespaceId, adapterId, DataModel.GRAPH ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationTable.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationTable.java index 34e32a4078..dfe05cc57d 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationTable.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationTable.java @@ -32,7 +32,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeImpl; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalColumn; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; @EqualsAndHashCode(callSuper = true) @Value @@ -47,7 +47,7 @@ public AllocationTable( @Deserialize("logicalId") long logicalId, @Deserialize("namespaceId") long namespaceId, @Deserialize("adapterId") long adapterId ) { - super( id, placementId, partitionId, logicalId, namespaceId, adapterId, NamespaceType.RELATIONAL ); + super( id, placementId, partitionId, logicalId, namespaceId, adapterId, DataModel.RELATIONAL ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java index 9e95e5c0ec..8780447c2e 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java @@ -25,8 +25,8 @@ import org.apache.calcite.linq4j.tree.Expressions; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; @EqualsAndHashCode(callSuper = true) @Value @@ -42,7 +42,7 @@ public LogicalCollection( @Deserialize("namespaceId") long namespaceId, @Deserialize("entityType") EntityType entityType, @Deserialize("modifiable") boolean modifiable ) { - super( id, name, namespaceId, entityType, NamespaceType.DOCUMENT, modifiable ); + super( id, name, namespaceId, entityType, DataModel.DOCUMENT, modifiable ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java index da176cd4d5..437367a6cc 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java @@ -32,7 +32,7 @@ import org.polypheny.db.catalog.entity.LogicalDefaultValue; import org.polypheny.db.catalog.entity.LogicalObject; import org.polypheny.db.catalog.logistic.Collation; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.type.PolyType; @@ -88,7 +88,7 @@ public class LogicalColumn implements LogicalObject, Comparable { @SerializeNullable public LogicalDefaultValue defaultValue; - public NamespaceType namespaceType = NamespaceType.RELATIONAL; + public DataModel dataModel = DataModel.RELATIONAL; public LogicalColumn( diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java index 607300befb..c165d48b6d 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java @@ -20,8 +20,8 @@ import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; @EqualsAndHashCode(callSuper = true) @SuperBuilder(toBuilder = true) @@ -35,9 +35,9 @@ public LogicalEntity( String name, long namespaceId, EntityType type, - NamespaceType namespaceType, + DataModel dataModel, boolean modifiable ) { - super( id, name, namespaceId, type, namespaceType, modifiable ); + super( id, name, namespaceId, type, dataModel, modifiable ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java index 57544242db..6f9227a8f5 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java @@ -24,8 +24,8 @@ import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; @EqualsAndHashCode(callSuper = true) @Value @@ -42,7 +42,7 @@ public LogicalGraph( @Deserialize("name") String name, @Deserialize("modifiable") boolean modifiable, @Deserialize("caseSensitive") boolean caseSensitive ) { - super( id, name, id, EntityType.ENTITY, NamespaceType.GRAPH, modifiable ); + super( id, name, id, EntityType.ENTITY, DataModel.GRAPH, modifiable ); this.caseSensitive = caseSensitive; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java index cfb91bb5a7..f9b99f60e8 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java @@ -28,7 +28,7 @@ import lombok.With; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalObject; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; @EqualsAndHashCode(callSuper = false) @@ -46,7 +46,7 @@ public class LogicalNamespace implements LogicalObject, Comparable a.position ) ).collect( Collectors.toList() ) ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/AdapterRestore.java b/core/src/main/java/org/polypheny/db/catalog/impl/AdapterRestore.java index a955299185..1a2954b826 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/AdapterRestore.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/AdapterRestore.java @@ -70,7 +70,7 @@ public void addPhysicals( AllocationEntity allocation, List phys public void activate( Adapter adapter ) { physicals.forEach( ( allocId, physicals ) -> { AllocationEntity entity = allocations.get( allocId ); - switch ( entity.namespaceType ) { + switch ( entity.dataModel ) { case RELATIONAL: adapter.restoreTable( entity.unwrap( AllocationTable.class ), physicals ); diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/NCatalog.java b/core/src/main/java/org/polypheny/db/catalog/impl/NCatalog.java index f458d993aa..2cfedd7df9 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/NCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/NCatalog.java @@ -20,7 +20,7 @@ import org.polypheny.db.catalog.impl.logical.DocumentCatalog; import org.polypheny.db.catalog.impl.logical.GraphCatalog; import org.polypheny.db.catalog.impl.logical.RelationalCatalog; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; @SerializeClass(subclasses = { GraphCatalog.class, RelationalCatalog.class, DocumentCatalog.class }) // required for deserialization public interface NCatalog { @@ -31,7 +31,7 @@ public interface NCatalog { boolean hasUncommittedChanges(); - NamespaceType getType(); + DataModel getType(); default T unwrap( Class clazz ) { if ( !this.getClass().isAssignableFrom( clazz ) ) { diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java b/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java index cf87ff3a80..351ab83d00 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/PolyCatalog.java @@ -58,7 +58,7 @@ import org.polypheny.db.catalog.impl.logical.DocumentCatalog; import org.polypheny.db.catalog.impl.logical.GraphCatalog; import org.polypheny.db.catalog.impl.logical.RelationalCatalog; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.catalog.snapshot.impl.SnapshotBuilder; import org.polypheny.db.iface.QueryInterfaceManager.QueryInterfaceTemplate; @@ -240,8 +240,8 @@ private void restoreLastState() { } - private void validateNamespaceType( long id, NamespaceType type ) { - if ( logicalCatalogs.get( id ).getLogicalNamespace().namespaceType != type ) { + private void validateNamespaceType( long id, DataModel type ) { + if ( logicalCatalogs.get( id ).getLogicalNamespace().dataModel != type ) { throw new GenericRuntimeException( "Error while retrieving namespace type" ); } } @@ -249,42 +249,42 @@ private void validateNamespaceType( long id, NamespaceType type ) { @Override public LogicalRelationalCatalog getLogicalRel( long namespaceId ) { - validateNamespaceType( namespaceId, NamespaceType.RELATIONAL ); + validateNamespaceType( namespaceId, DataModel.RELATIONAL ); return (LogicalRelationalCatalog) logicalCatalogs.get( namespaceId ); } @Override public LogicalDocumentCatalog getLogicalDoc( long namespaceId ) { - validateNamespaceType( namespaceId, NamespaceType.DOCUMENT ); + validateNamespaceType( namespaceId, DataModel.DOCUMENT ); return (LogicalDocumentCatalog) logicalCatalogs.get( namespaceId ); } @Override public LogicalGraphCatalog getLogicalGraph( long namespaceId ) { - validateNamespaceType( namespaceId, NamespaceType.GRAPH ); + validateNamespaceType( namespaceId, DataModel.GRAPH ); return (LogicalGraphCatalog) logicalCatalogs.get( namespaceId ); } @Override public AllocationRelationalCatalog getAllocRel( long namespaceId ) { - validateNamespaceType( namespaceId, NamespaceType.RELATIONAL ); + validateNamespaceType( namespaceId, DataModel.RELATIONAL ); return (AllocationRelationalCatalog) allocationCatalogs.get( namespaceId ); } @Override public AllocationDocumentCatalog getAllocDoc( long namespaceId ) { - validateNamespaceType( namespaceId, NamespaceType.DOCUMENT ); + validateNamespaceType( namespaceId, DataModel.DOCUMENT ); return (AllocationDocumentCatalog) allocationCatalogs.get( namespaceId ); } @Override public AllocationGraphCatalog getAllocGraph( long namespaceId ) { - validateNamespaceType( namespaceId, NamespaceType.GRAPH ); + validateNamespaceType( namespaceId, DataModel.GRAPH ); return (AllocationGraphCatalog) allocationCatalogs.get( namespaceId ); } @@ -309,12 +309,12 @@ public long createUser( String name, String password ) { } - public long createNamespace( String name, NamespaceType namespaceType, boolean caseSensitive ) { + public long createNamespace( String name, DataModel dataModel, boolean caseSensitive ) { // cannot separate namespace and entity ids, as there are models which have their entity on the namespace level long id = idBuilder.getNewLogicalId(); - LogicalNamespace namespace = new LogicalNamespace( id, name, namespaceType, caseSensitive ); + LogicalNamespace namespace = new LogicalNamespace( id, name, dataModel, caseSensitive ); - switch ( namespaceType ) { + switch ( dataModel ) { case RELATIONAL: logicalCatalogs.put( id, new RelationalCatalog( namespace ) ); allocationCatalogs.put( id, new PolyAllocRelCatalog( namespace ) ); diff --git a/core/src/main/java/org/polypheny/db/catalog/logistic/NamespaceType.java b/core/src/main/java/org/polypheny/db/catalog/logistic/DataModel.java similarity index 75% rename from core/src/main/java/org/polypheny/db/catalog/logistic/NamespaceType.java rename to core/src/main/java/org/polypheny/db/catalog/logistic/DataModel.java index d527e3907e..444ac939c1 100644 --- a/core/src/main/java/org/polypheny/db/catalog/logistic/NamespaceType.java +++ b/core/src/main/java/org/polypheny/db/catalog/logistic/DataModel.java @@ -20,7 +20,7 @@ import org.polypheny.db.schema.trait.ModelTrait; @Getter -public enum NamespaceType { +public enum DataModel { RELATIONAL( 1 ), DOCUMENT( 2 ), GRAPH( 3 ); @@ -29,19 +29,19 @@ public enum NamespaceType { public final int id; - NamespaceType( int id ) { + DataModel( int id ) { this.id = id; } - public static NamespaceType getDefault() { + public static DataModel getDefault() { //return (NamespaceType) ConfigManager.getInstance().getConfig( "runtime/defaultSchemaModel" ).getEnum(); - return NamespaceType.RELATIONAL; + return DataModel.RELATIONAL; } - public static NamespaceType getById( final int id ) { - for ( NamespaceType t : values() ) { + public static DataModel getById( final int id ) { + for ( DataModel t : values() ) { if ( t.id == id ) { return t; } @@ -50,8 +50,8 @@ public static NamespaceType getById( final int id ) { } - public static NamespaceType getByName( final String name ) { - for ( NamespaceType t : values() ) { + public static DataModel getByName( final String name ) { + for ( DataModel t : values() ) { if ( t.name().equalsIgnoreCase( name ) ) { return t; } @@ -61,11 +61,11 @@ public static NamespaceType getByName( final String name ) { public ModelTrait getModelTrait() { - if ( this == NamespaceType.RELATIONAL ) { + if ( this == DataModel.RELATIONAL ) { return ModelTrait.RELATIONAL; - } else if ( this == NamespaceType.DOCUMENT ) { + } else if ( this == DataModel.DOCUMENT ) { return ModelTrait.DOCUMENT; - } else if ( this == NamespaceType.GRAPH ) { + } else if ( this == DataModel.GRAPH ) { return ModelTrait.GRAPH; } throw new RuntimeException( "Not found a suitable NamespaceType." ); 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 651124a40c..5041da089d 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 @@ -43,7 +43,7 @@ import org.polypheny.db.catalog.entity.allocation.AllocationPartitionGroup; import org.polypheny.db.catalog.entity.allocation.AllocationPlacement; import org.polypheny.db.catalog.entity.allocation.AllocationTable; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.AllocSnapshot; import org.polypheny.db.partition.properties.PartitionProperty; import org.polypheny.db.util.Pair; @@ -87,27 +87,27 @@ public AllocSnapshotImpl( Map allocationCatalogs, Map a.getNamespace().namespaceType == NamespaceType.RELATIONAL ) + .filter( a -> a.getNamespace().dataModel == DataModel.RELATIONAL ) .map( c -> (AllocationRelationalCatalog) c ) .collect( Collectors.toList() ) ); this.collections = buildCollections( allocationCatalogs .values() .stream() - .filter( a -> a.getNamespace().namespaceType == NamespaceType.DOCUMENT ) + .filter( a -> a.getNamespace().dataModel == DataModel.DOCUMENT ) .map( c -> (AllocationDocumentCatalog) c ) .collect( Collectors.toList() ) ); this.graphs = buildGraphs( allocationCatalogs .values() .stream() - .filter( a -> a.getNamespace().namespaceType == NamespaceType.GRAPH ) + .filter( a -> a.getNamespace().dataModel == DataModel.GRAPH ) .map( c -> (AllocationGraphCatalog) c ) .collect( Collectors.toList() ) ); this.columns = buildPlacementColumns( allocationCatalogs.values() .stream() - .filter( a -> a.getNamespace().namespaceType == NamespaceType.RELATIONAL ) + .filter( a -> a.getNamespace().dataModel == DataModel.RELATIONAL ) .map( c -> (AllocationRelationalCatalog) c ) .map( AllocationRelationalCatalog::getColumns ) .flatMap( c -> c.values().stream() ) @@ -129,7 +129,7 @@ public AllocSnapshotImpl( Map allocationCatalogs, Map a.getNamespace().namespaceType == NamespaceType.RELATIONAL ) + .filter( a -> a.getNamespace().dataModel == DataModel.RELATIONAL ) .map( c -> (AllocationRelationalCatalog) c ) .map( AllocationRelationalCatalog::getProperties ) .flatMap( c -> c.values().stream() ) @@ -251,7 +251,7 @@ private ImmutableMap buildPartitions( Map buildPartitionGroups( Map allocationCatalogs ) { return ImmutableMap.copyOf( allocationCatalogs.values() .stream() - .filter( a -> a.getNamespace().namespaceType == NamespaceType.RELATIONAL ) + .filter( a -> a.getNamespace().dataModel == DataModel.RELATIONAL ) .map( c -> (AllocationRelationalCatalog) c ) .map( AllocationRelationalCatalog::getPartitionGroups ) .flatMap( c -> c.values().stream() ) diff --git a/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/SnapshotBuilder.java b/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/SnapshotBuilder.java index 5d1c5f6ff0..ca380b9a34 100644 --- a/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/SnapshotBuilder.java +++ b/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/SnapshotBuilder.java @@ -27,7 +27,7 @@ import org.polypheny.db.catalog.catalogs.LogicalRelationalCatalog; import org.polypheny.db.catalog.entity.LogicalAdapter; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.AllocSnapshot; import org.polypheny.db.catalog.snapshot.LogicalDocSnapshot; import org.polypheny.db.catalog.snapshot.LogicalGraphSnapshot; @@ -57,7 +57,7 @@ private static LogicalGraphSnapshot buildGraphSnapshots( Map e.getValue().getLogicalNamespace().namespaceType == NamespaceType.GRAPH ) + .filter( e -> e.getValue().getLogicalNamespace().dataModel == DataModel.GRAPH ) .collect( Collectors.toMap( Entry::getKey, e -> (LogicalGraphCatalog) e.getValue() ) ) ); } @@ -66,7 +66,7 @@ private static LogicalDocSnapshot buildDocSnapshots( Map l return new LogicalDocSnapshotImpl( logicalCatalogs .entrySet() .stream() - .filter( e -> e.getValue().getLogicalNamespace().namespaceType == NamespaceType.DOCUMENT ) + .filter( e -> e.getValue().getLogicalNamespace().dataModel == DataModel.DOCUMENT ) .collect( Collectors.toMap( Entry::getKey, e -> (LogicalDocumentCatalog) e.getValue() ) ) ); } @@ -75,7 +75,7 @@ private static LogicalRelSnapshot buildRelSnapshots( Map l return new LogicalRelSnapshotImpl( logicalCatalogs .entrySet() .stream() - .filter( e -> e.getValue().getLogicalNamespace().namespaceType == NamespaceType.RELATIONAL ) + .filter( e -> e.getValue().getLogicalNamespace().dataModel == DataModel.RELATIONAL ) .collect( Collectors.toMap( Entry::getKey, e -> (LogicalRelationalCatalog) e.getValue() ) ) ); } diff --git a/core/src/main/java/org/polypheny/db/ddl/DdlManager.java b/core/src/main/java/org/polypheny/db/ddl/DdlManager.java index 5a63f06cdf..2ab00591b2 100644 --- a/core/src/main/java/org/polypheny/db/ddl/DdlManager.java +++ b/core/src/main/java/org/polypheny/db/ddl/DdlManager.java @@ -34,8 +34,8 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Collation; import org.polypheny.db.catalog.logistic.ConstraintType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.ForeignKeyOption; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.PlacementType; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.nodes.DataTypeSpec; @@ -94,7 +94,7 @@ public static DdlManager getInstance() { * @param ifNotExists whether to silently ignore if a namespace with this name does already exist * @param replace whether to replace an existing namespace with this name */ - public abstract long createNamespace( String name, NamespaceType type, boolean ifNotExists, boolean replace ); + public abstract long createNamespace( String name, DataModel type, boolean ifNotExists, boolean replace ); /** * Adds a new adapter (data store or data source) diff --git a/core/src/main/java/org/polypheny/db/interpreter/Bindables.java b/core/src/main/java/org/polypheny/db/interpreter/Bindables.java index a9d1a547c1..f352cce4d9 100644 --- a/core/src/main/java/org/polypheny/db/interpreter/Bindables.java +++ b/core/src/main/java/org/polypheny/db/interpreter/Bindables.java @@ -213,7 +213,7 @@ public static BindableScan create( AlgOptCluster cluster, LogicalEntity entity ) public static BindableScan create( AlgOptCluster cluster, LogicalEntity entity, List filters, List projects ) { final AlgTraitSet traitSet = cluster.traitSetOf( BindableConvention.INSTANCE ) - .replace( entity.namespaceType.getModelTrait() ) + .replace( entity.dataModel.getModelTrait() ) .replaceIfs( AlgCollationTraitDef.INSTANCE, entity::getCollations ); return new BindableScan( cluster, traitSet, entity, ImmutableList.copyOf( filters ), ImmutableList.copyOf( projects ) ); } diff --git a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java index fe41e8a3d8..216e82a95f 100644 --- a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java +++ b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java @@ -26,10 +26,6 @@ import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.information.InformationGroup; -import org.polypheny.db.information.InformationManager; -import org.polypheny.db.information.InformationPage; -import org.polypheny.db.information.InformationStacktrace; import org.polypheny.db.nodes.Node; import org.polypheny.db.processing.ImplementationContext; import org.polypheny.db.processing.ImplementationContext.ExecutedContext; @@ -132,18 +128,14 @@ public List anyPrepareQuery( QueryContext context, Statem } implementation = statement.getQueryProcessor().prepareQuery( root, true ); } - implementationContexts.add( new ImplementationContext( implementation, parsed, statement ) ); + implementationContexts.add( new ImplementationContext( implementation, parsed, statement, null ) ); } catch ( Exception e ) { if ( transaction.isAnalyze() ) { - InformationManager analyzer = transaction.getQueryAnalyzer(); - InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); - InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); - InformationStacktrace exceptionElement = new InformationStacktrace( e, exceptionGroup ); - analyzer.addPage( exceptionPage ); - analyzer.addGroup( exceptionGroup ); - analyzer.registerInformation( exceptionElement ); + transaction.getQueryAnalyzer().attachStacktrace( e ); } + implementationContexts.add( ImplementationContext.ofError( e, parsed, statement ) ); + return implementationContexts; } } return implementationContexts; @@ -159,6 +151,9 @@ public List anyQuery( QueryContext context, Statement statement for ( ImplementationContext implementation : prepared ) { try { + if ( implementation.getException().isPresent() ) { + throw implementation.getException().get(); + } if ( context.isAnalysed() ) { implementation.getStatement().getOverviewDuration().start( "Execution" ); } @@ -168,15 +163,9 @@ public List anyQuery( QueryContext context, Statement statement } } catch ( Exception e ) { if ( transaction.isAnalyze() ) { - InformationManager analyzer = transaction.getQueryAnalyzer(); - InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); - InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); - InformationStacktrace exceptionElement = new InformationStacktrace( e, exceptionGroup ); - analyzer.addPage( exceptionPage ); - analyzer.addGroup( exceptionGroup ); - analyzer.registerInformation( exceptionElement ); + transaction.getQueryAnalyzer().attachStacktrace( e ); } - executedContexts.add( ExecutedContext.ofError( e ) ); + executedContexts.add( ExecutedContext.ofError( e, implementation ) ); return executedContexts; } } diff --git a/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java b/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java index fbb69de62c..61fdabcb92 100644 --- a/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java +++ b/core/src/main/java/org/polypheny/db/languages/QueryLanguage.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; import lombok.Value; import org.jetbrains.annotations.NotNull; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.nodes.validate.Validator; import org.polypheny.db.prepare.Context; @@ -37,7 +37,7 @@ public class QueryLanguage { @NotNull - NamespaceType namespaceType; + DataModel dataModel; @NotNull String serializedName; @NotNull @@ -53,14 +53,14 @@ public class QueryLanguage { public QueryLanguage( - @NotNull NamespaceType namespaceType, + @NotNull DataModel dataModel, @NotNull String serializedName, @NotNull List otherNames, @Nullable ParserFactory factory, @NotNull Supplier processorSupplier, @Nullable BiFunction validatorSupplier, @NotNull Function> splitter ) { - this.namespaceType = namespaceType; + this.dataModel = dataModel; this.serializedName = serializedName; this.factory = factory; this.processorSupplier = processorSupplier; diff --git a/core/src/main/java/org/polypheny/db/languages/QueryParameters.java b/core/src/main/java/org/polypheny/db/languages/QueryParameters.java index 5ea2e05611..b12413887e 100644 --- a/core/src/main/java/org/polypheny/db/languages/QueryParameters.java +++ b/core/src/main/java/org/polypheny/db/languages/QueryParameters.java @@ -17,7 +17,7 @@ package org.polypheny.db.languages; import lombok.Getter; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.interpreter.Node; /** @@ -27,12 +27,12 @@ @Getter public class QueryParameters { - private final NamespaceType namespaceType; + private final DataModel dataModel; private final String query; - public QueryParameters( String query, NamespaceType namespaceType ) { - this.namespaceType = namespaceType; + public QueryParameters( String query, DataModel dataModel ) { + this.dataModel = dataModel; this.query = query; } 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 5677c7e047..2f98e6c6ff 100644 --- a/core/src/main/java/org/polypheny/db/processing/ExtendedQueryParameters.java +++ b/core/src/main/java/org/polypheny/db/processing/ExtendedQueryParameters.java @@ -21,7 +21,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.NonFinal; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.QueryParameters; @@ -36,15 +36,15 @@ public class ExtendedQueryParameters extends QueryParameters { public boolean fullGraph; - public ExtendedQueryParameters( String query, NamespaceType namespaceType, String namespace ) { - super( query, namespaceType ); + public ExtendedQueryParameters( String query, DataModel dataModel, String namespace ) { + super( query, dataModel ); this.namespace = namespace; this.fullGraph = false; } public ExtendedQueryParameters( String namespace ) { - super( "*", NamespaceType.GRAPH ); + super( "*", DataModel.GRAPH ); this.namespace = namespace; this.fullGraph = true; } diff --git a/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java b/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java index 4a2cd0ccf2..4d8e06ae28 100644 --- a/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java +++ b/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java @@ -17,6 +17,7 @@ package org.polypheny.db.processing; +import java.util.Optional; import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.NonFinal; @@ -37,6 +38,14 @@ public class ImplementationContext { Statement statement; + @Nullable + Exception exception; + + + public static ImplementationContext ofError( Exception e, ParsedQueryContext parsed, Statement statement ) { + return new ImplementationContext( null, parsed, statement, e ); + } + public ExecutedContext execute( Statement statement ) { long time = System.nanoTime(); @@ -46,35 +55,45 @@ public ExecutedContext execute( Statement statement ) { return new ExecutedContext( implementation, null, query, time, result, statement ); } catch ( Exception e ) { time = System.nanoTime() - time; - return new ExecutedContext( implementation, e.getMessage(), query, time, null, statement ); + return new ExecutedContext( implementation, e, query, time, null, statement ); } } + public Optional getException() { + return Optional.of( exception ); + } + + @EqualsAndHashCode(callSuper = true) @Value public static class ExecutedContext extends ImplementationContext { - @Nullable - String error; + @NotNull + ResultIterator iterator; long executionTime; - @NotNull - ResultIterator iterator; + @Nullable + Exception error; - private ExecutedContext( PolyImplementation implementation, String error, ParsedQueryContext query, long executionTime, ResultIterator iterator, Statement statement ) { - super( implementation, query, statement ); + private ExecutedContext( PolyImplementation implementation, @Nullable Exception error, ParsedQueryContext query, long executionTime, ResultIterator iterator, Statement statement ) { + super( implementation, query, statement, error ); this.executionTime = executionTime; this.iterator = iterator; this.error = error; } - public static ExecutedContext ofError( Exception e ) { - return new ExecutedContext( null, e.getMessage(), null, 0l, null, null ); + public static ExecutedContext ofError( Exception e, ImplementationContext implementation ) { + return new ExecutedContext( implementation.implementation, e, implementation.query, 0l, null, implementation.statement ); + } + + + public Optional getError() { + return Optional.of( error ); } } diff --git a/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java b/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java index 590ef8a97c..7a90a7aaf0 100644 --- a/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java +++ b/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java @@ -68,7 +68,7 @@ import org.polypheny.db.catalog.entity.allocation.AllocationEntity; import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.transaction.Statement; @@ -90,9 +90,9 @@ public class LogicalAlgAnalyzeShuttle extends AlgShuttleImpl { public Map availableColumnsWithTable = new HashMap<>(); // columnId -> tableId - public Map> modifiedEntities = new HashMap<>(); + public Map> modifiedEntities = new HashMap<>(); - public Map> scannedEntities = new HashMap<>(); + public Map> scannedEntities = new HashMap<>(); public List entityIds = new ArrayList<>(); @@ -143,7 +143,7 @@ public String getQueryName() { } - private void addScannedEntity( NamespaceType type, long entityId ) { + private void addScannedEntity( DataModel type, long entityId ) { if ( !scannedEntities.containsKey( type ) ) { scannedEntities.put( type, new HashSet<>() ); } @@ -151,7 +151,7 @@ private void addScannedEntity( NamespaceType type, long entityId ) { } - private void addModifiedEntity( NamespaceType type, long entityId ) { + private void addModifiedEntity( DataModel type, long entityId ) { if ( !modifiedEntities.containsKey( type ) ) { modifiedEntities.put( type, new HashSet<>() ); } @@ -170,7 +170,7 @@ public AlgNode visit( LogicalAggregate aggregate ) { public AlgNode visit( LogicalLpgModify modify ) { hashBasis.add( modify.getClass().getSimpleName() ); - addModifiedEntity( modify.getEntity().namespaceType, getLogicalId( modify ) ); + addModifiedEntity( modify.getEntity().dataModel, getLogicalId( modify ) ); return super.visit( modify ); } @@ -180,7 +180,7 @@ public AlgNode visit( LogicalLpgModify modify ) { public AlgNode visit( LogicalLpgScan scan ) { hashBasis.add( scan.getClass().getSimpleName() + "#" + scan.entity.id ); - addScannedEntity( scan.getEntity().namespaceType, scan.entity.id ); + addScannedEntity( scan.getEntity().dataModel, scan.entity.id ); return super.visit( scan ); } @@ -247,7 +247,7 @@ public AlgNode visit( LogicalLpgTransformer transformer ) { public AlgNode visit( LogicalDocumentModify modify ) { hashBasis.add( "LogicalDocumentModify" ); - addModifiedEntity( modify.getEntity().namespaceType, getLogicalId( modify ) ); + addModifiedEntity( modify.getEntity().dataModel, getLogicalId( modify ) ); return super.visit( modify ); } @@ -285,7 +285,7 @@ public AlgNode visit( LogicalDocumentProject project ) { public AlgNode visit( LogicalDocumentScan scan ) { hashBasis.add( "LogicalDocumentScan#" + scan.entity.id ); - addScannedEntity( scan.entity.namespaceType, getLogicalId( scan ) ); + addScannedEntity( scan.entity.dataModel, getLogicalId( scan ) ); return super.visit( scan ); } @@ -326,7 +326,7 @@ public AlgNode visit( RelScan scan ) { } hashBasis.add( "Scan#" + scan.getEntity().id ); - addScannedEntity( scan.getEntity().namespaceType, getLogicalId( scan ) ); + addScannedEntity( scan.getEntity().dataModel, getLogicalId( scan ) ); // get available columns for every table scan this.getAvailableColumns( scan ); @@ -428,7 +428,7 @@ public AlgNode visit( LogicalExchange exchange ) { public AlgNode visit( LogicalRelModify modify ) { hashBasis.add( "LogicalModify" ); - addModifiedEntity( modify.getEntity().namespaceType, getLogicalId( modify ) ); + addModifiedEntity( modify.getEntity().dataModel, getLogicalId( modify ) ); // e.g. inserts only have underlying values and need to attach the table correctly this.getAvailableColumns( modify ); diff --git a/core/src/main/java/org/polypheny/db/processing/Processor.java b/core/src/main/java/org/polypheny/db/processing/Processor.java index b5e1807a40..86a8ca45e6 100644 --- a/core/src/main/java/org/polypheny/db/processing/Processor.java +++ b/core/src/main/java/org/polypheny/db/processing/Processor.java @@ -72,7 +72,7 @@ PolyImplementation getImplementation( Statement statement, ParsedQueryContext co Catalog.getInstance().commit(); return new PolyImplementation( null, - context.getLanguage().getNamespaceType(), + context.getLanguage().getDataModel(), new ExecutionTimeMonitor(), null, Kind.CREATE_NAMESPACE, // technically correct, maybe change diff --git a/core/src/main/java/org/polypheny/db/routing/LogicalQueryInformation.java b/core/src/main/java/org/polypheny/db/routing/LogicalQueryInformation.java index 9be19b0949..8a4d8fd211 100644 --- a/core/src/main/java/org/polypheny/db/routing/LogicalQueryInformation.java +++ b/core/src/main/java/org/polypheny/db/routing/LogicalQueryInformation.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; /** @@ -63,9 +63,9 @@ public interface LogicalQueryInformation { */ String getQueryHash(); - ImmutableMap> getScannedEntities(); + ImmutableMap> getScannedEntities(); - ImmutableMap> getModifiedEntities(); + ImmutableMap> getModifiedEntities(); ImmutableSet getAllModifiedEntities(); diff --git a/core/src/main/java/org/polypheny/db/schema/Entity.java b/core/src/main/java/org/polypheny/db/schema/Entity.java index 325daeb007..2487554bfd 100644 --- a/core/src/main/java/org/polypheny/db/schema/Entity.java +++ b/core/src/main/java/org/polypheny/db/schema/Entity.java @@ -35,7 +35,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.nodes.Call; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.JavaTypeFactoryImpl; @@ -112,8 +112,8 @@ default AlgDataTypeFactory getTypeFactory() { boolean rolledUpColumnValidInsideAgg( String column, Call call, Node parent ); - default NamespaceType getNamespaceType() { - return NamespaceType.RELATIONAL; + default DataModel getNamespaceType() { + return DataModel.RELATIONAL; } interface Table { diff --git a/core/src/main/java/org/polypheny/db/schema/SchemaPlus.java b/core/src/main/java/org/polypheny/db/schema/SchemaPlus.java index 37ac21b55b..0e5ef6807d 100644 --- a/core/src/main/java/org/polypheny/db/schema/SchemaPlus.java +++ b/core/src/main/java/org/polypheny/db/schema/SchemaPlus.java @@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableList; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.schema.Namespace.Schema; @@ -77,7 +77,7 @@ public interface SchemaPlus extends Namespace, Schema { /** * Adds a schema as a sub-schema of this schema, and returns the wrapped object. */ - SchemaPlus add( String name, Namespace namespace, NamespaceType namespaceType ); + SchemaPlus add( String name, Namespace namespace, DataModel dataModel ); /** * Adds a table to this schema. diff --git a/core/src/main/java/org/polypheny/db/schema/trait/ModelTrait.java b/core/src/main/java/org/polypheny/db/schema/trait/ModelTrait.java index 16f1bbd932..aca1f11497 100644 --- a/core/src/main/java/org/polypheny/db/schema/trait/ModelTrait.java +++ b/core/src/main/java/org/polypheny/db/schema/trait/ModelTrait.java @@ -18,7 +18,7 @@ import lombok.Getter; import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgTrait; import org.polypheny.db.plan.Convention; @@ -31,16 +31,16 @@ @Getter public class ModelTrait implements AlgTrait { - public static final ModelTrait RELATIONAL = new ModelTrait( NamespaceType.RELATIONAL ); + public static final ModelTrait RELATIONAL = new ModelTrait( DataModel.RELATIONAL ); - public static final ModelTrait DOCUMENT = new ModelTrait( NamespaceType.DOCUMENT ); + public static final ModelTrait DOCUMENT = new ModelTrait( DataModel.DOCUMENT ); - public static final ModelTrait GRAPH = new ModelTrait( NamespaceType.GRAPH ); + public static final ModelTrait GRAPH = new ModelTrait( DataModel.GRAPH ); - private final NamespaceType dataModel; + private final DataModel dataModel; - public ModelTrait( NamespaceType dataModel ) { + public ModelTrait( DataModel dataModel ) { this.dataModel = dataModel; } 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 f2d33fa2ea..c0f22784fc 100644 --- a/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java +++ b/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java @@ -110,7 +110,7 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.QueryLanguage; @@ -583,7 +583,7 @@ private RexNode field( int inputCount, int inputOrdinal, int fieldOrdinal, boole final AlgDataTypeField field = rowType.getFields().get( fieldOrdinal ); final int offset = inputOffset( inputCount, inputOrdinal ); final RexIndexRef ref = cluster.getRexBuilder().makeInputRef( field.getType(), offset + fieldOrdinal ); - if ( frame.alg.getModel() == NamespaceType.DOCUMENT ) { + if ( frame.alg.getModel() == DataModel.DOCUMENT ) { return ref; } final AlgDataTypeField aliasField = frame.relFields().get( fieldOrdinal ); diff --git a/core/src/main/java/org/polypheny/db/util/Util.java b/core/src/main/java/org/polypheny/db/util/Util.java index eb6e454616..ff3ef193b2 100644 --- a/core/src/main/java/org/polypheny/db/util/Util.java +++ b/core/src/main/java/org/polypheny/db/util/Util.java @@ -104,7 +104,7 @@ import org.polypheny.db.algebra.fun.AggFunction; import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.nodes.BasicNodeVisitor; import org.polypheny.db.nodes.Call; import org.polypheny.db.nodes.Literal; @@ -2023,7 +2023,7 @@ public static Iterator filter( Iterator iterator, Predicate predica public static Monotonicity getMonotonicity( LogicalEntity entity, String columnName ) { - if ( entity.namespaceType != NamespaceType.RELATIONAL ) { + if ( entity.dataModel != DataModel.RELATIONAL ) { return Monotonicity.NOT_MONOTONIC; } diff --git a/core/src/test/java/org/polypheny/db/catalog/MockCatalog.java b/core/src/test/java/org/polypheny/db/catalog/MockCatalog.java index 39c84355c9..bd0cf354d7 100644 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalog.java +++ b/core/src/test/java/org/polypheny/db/catalog/MockCatalog.java @@ -30,7 +30,7 @@ import org.polypheny.db.catalog.entity.LogicalAdapter.AdapterType; import org.polypheny.db.catalog.entity.LogicalQueryInterface; import org.polypheny.db.catalog.entity.LogicalUser; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -145,7 +145,7 @@ public void rollback() { } @Override - public long createNamespace( String name, NamespaceType namespaceType, boolean caseSensitive ) { + public long createNamespace( String name, DataModel dataModel, boolean caseSensitive ) { throw new NotImplementedException(); } diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index b5ba4502df..8c078772c7 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -45,8 +45,8 @@ 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.NamespaceType; -import org.polypheny.db.cli.PolyphenyModesConverter; +import org.polypheny.db.catalog.logistic.DataModel; +import org.polypheny.db.cli.PolyModesConverter; import org.polypheny.db.config.ConfigManager; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.ddl.DdlManager; @@ -114,7 +114,7 @@ public class PolyphenyDb { @Option(name = { "-memoryCatalog" }, description = "Store catalog only in-memory") public boolean memoryCatalog = false; - @Option(name = { "-mode" }, description = "Special system configuration for running tests", typeConverterProvider = PolyphenyModesConverter.class) + @Option(name = { "-mode" }, description = "Special system configuration for running tests", typeConverterProvider = PolyModesConverter.class) public PolyphenyMode mode = PolyphenyMode.PRODUCTION; @Option(name = { "-gui" }, description = "Show splash screen on startup and add taskbar gui") @@ -124,7 +124,7 @@ public class PolyphenyDb { public boolean daemonMode = false; @Option(name = { "-defaultStore" }, description = "Type of default storeId") - public String defaultStoreName = "hsqldb"; + public String defaultStoreName = "monetdb"; @Option(name = { "-defaultSource" }, description = "Type of default source") public String defaultSourceName = "csv"; @@ -387,7 +387,7 @@ public void join( final long millis ) throws InterruptedException { // temporary add sql and rel here QueryLanguage language = new QueryLanguage( - NamespaceType.RELATIONAL, + DataModel.RELATIONAL, "alg", List.of( "alg", "algebra" ), null, 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 5aa8ccec2d..73371deef3 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -80,12 +80,12 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Collation; import org.polypheny.db.catalog.logistic.ConstraintType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.DataPlacementRole; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.catalog.logistic.ForeignKeyOption; import org.polypheny.db.catalog.logistic.IndexType; import org.polypheny.db.catalog.logistic.NameGenerator; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.PartitionType; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.catalog.logistic.PlacementType; @@ -172,7 +172,7 @@ protected DataStore getDataStoreInstance( long storeId ) { @Override - public long createNamespace( String name, NamespaceType type, boolean ifNotExists, boolean replace ) { + public long createNamespace( String name, DataModel type, boolean ifNotExists, boolean replace ) { name = name.toLowerCase(); // Check if there is already a namespace with this name Optional optionalNamespace = catalog.getSnapshot().getNamespace( name ); @@ -869,14 +869,14 @@ private void deleteAllocationColumn( LogicalTable table, Statement statement, Al private void checkModelLogic( LogicalTable catalogTable ) { - if ( catalogTable.namespaceType == NamespaceType.DOCUMENT ) { + if ( catalogTable.dataModel == DataModel.DOCUMENT ) { throw new GenericRuntimeException( "Modification operation is not allowed by schema type DOCUMENT" ); } } private void checkModelLogic( LogicalTable catalogTable, String columnName ) { - if ( catalogTable.namespaceType == NamespaceType.DOCUMENT + if ( catalogTable.dataModel == DataModel.DOCUMENT && (columnName.equals( "_data" ) || columnName.equals( "_id" )) ) { throw new GenericRuntimeException( "Modification operation is not allowed by schema type DOCUMENT" ); } @@ -1648,10 +1648,10 @@ public void createMaterializedView( String viewName, long namespaceId, AlgRoot a private void checkModelLangCompatibility( QueryLanguage language, long namespaceId ) { LogicalNamespace namespace = catalog.getSnapshot().getNamespace( namespaceId ).orElseThrow(); - if ( namespace.namespaceType != language.getNamespaceType() ) { + if ( namespace.dataModel != language.getDataModel() ) { throw new GenericRuntimeException( "The used language cannot execute schema changing queries on this entity with the data model %s.", - namespace.getNamespaceType() ); + namespace.getDataModel() ); } } @@ -1675,7 +1675,7 @@ public long createGraph( String name, boolean modifiable, @Nullable List PolyImplementation createPolyImplementation( PreparedResult preparedResult, Kind kind, AlgNode optimalNode, AlgDataType validatedRowType, Convention resultConvention, ExecutionTimeMonitor executionTimeMonitor, NamespaceType namespaceType ) { + private PolyImplementation createPolyImplementation( PreparedResult preparedResult, Kind kind, AlgNode optimalNode, AlgDataType validatedRowType, Convention resultConvention, ExecutionTimeMonitor executionTimeMonitor, DataModel dataModel ) { final AlgDataType jdbcType = QueryProcessorHelpers.makeStruct( optimalNode.getCluster().getTypeFactory(), validatedRowType ); return new PolyImplementation( jdbcType, - namespaceType, + dataModel, executionTimeMonitor, preparedResult, kind, 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 97e4521066..56056eaab6 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/ConstraintEnforceAttacher.java +++ b/dbms/src/main/java/org/polypheny/db/processing/ConstraintEnforceAttacher.java @@ -59,8 +59,8 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.ConstraintType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.LogicalRelSnapshot; import org.polypheny.db.config.Config; import org.polypheny.db.config.Config.ConfigListener; @@ -642,7 +642,7 @@ private boolean testConstraintsValid() { .getNamespaces( null ) .stream() .flatMap( n -> Catalog.getInstance().getSnapshot().rel().getTables( n.id, null ).stream() ) - .filter( t -> t.entityType == EntityType.ENTITY && t.getNamespaceType() == NamespaceType.RELATIONAL ) + .filter( t -> t.entityType == EntityType.ENTITY && t.getDataModel() == DataModel.RELATIONAL ) .collect( Collectors.toList() ); Transaction transaction = this.manager.startTransaction( Catalog.defaultUserId, false, "ConstraintEnforcement" ); Statement statement = transaction.createStatement(); diff --git a/dbms/src/main/java/org/polypheny/db/processing/shuttles/LogicalQueryInformationImpl.java b/dbms/src/main/java/org/polypheny/db/processing/shuttles/LogicalQueryInformationImpl.java index cf29e9409e..3c680ffea3 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/shuttles/LogicalQueryInformationImpl.java +++ b/dbms/src/main/java/org/polypheny/db/processing/shuttles/LogicalQueryInformationImpl.java @@ -26,7 +26,7 @@ import java.util.Set; import java.util.stream.Collectors; import lombok.Value; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.routing.LogicalQueryInformation; @Value @@ -37,8 +37,8 @@ public class LogicalQueryInformationImpl implements LogicalQueryInformation { public ImmutableMap availableColumns; // column id -> schemaName.tableName.ColumnName public ImmutableMap availableColumnsWithTable; // columnId -> tableId public ImmutableMap usedColumns; - public ImmutableMap> scannedEntities; - public ImmutableMap> modifiedEntities; + public ImmutableMap> scannedEntities; + public ImmutableMap> modifiedEntities; public ImmutableSet allModifiedEntities; public ImmutableSet allScannedEntities; public ImmutableSet allEntities; @@ -50,8 +50,8 @@ public LogicalQueryInformationImpl( Map availableColumns, Map availableColumnsWithTable, Map usedColumns, - Map> scannedEntities, - Map> modifiedEntities ) { + Map> scannedEntities, + Map> modifiedEntities ) { this.queryHash = queryHash; this.accessedPartitions = ImmutableMap.copyOf( accessedPartitions ); this.availableColumns = ImmutableMap.copyOf( availableColumns ); diff --git a/dbms/src/main/java/org/polypheny/db/routing/routers/AbstractDqlRouter.java b/dbms/src/main/java/org/polypheny/db/routing/routers/AbstractDqlRouter.java index 6f1e1112df..7c344ea178 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/routers/AbstractDqlRouter.java +++ b/dbms/src/main/java/org/polypheny/db/routing/routers/AbstractDqlRouter.java @@ -42,7 +42,7 @@ import org.polypheny.db.catalog.entity.logical.LogicalEntity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.routing.LogicalQueryInformation; @@ -195,7 +195,7 @@ protected List buildSelect( AlgNode node, List( partitionsColumnsPlacements.values() ).get( 0 ).get( 0 ); // todo dl: remove after RowType refactor - if ( catalog.getSnapshot().getNamespace( placement.namespaceId ).orElseThrow().namespaceType == NamespaceType.DOCUMENT ) { + if ( catalog.getSnapshot().getNamespace( placement.namespaceId ).orElseThrow().dataModel == DataModel.DOCUMENT ) { AlgDataType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( 1L, "d", 0, cluster.getTypeFactory().createPolyType( PolyType.DOCUMENT ) ) ) ); builder.push( new LogicalTransformer( node.getCluster(), diff --git a/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java b/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java index 31400c287a..43e402bc13 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java @@ -46,7 +46,7 @@ import org.polypheny.db.catalog.entity.allocation.AllocationEntity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.partition.properties.PartitionProperty; import org.polypheny.db.plan.AlgOptUtil; @@ -277,7 +277,7 @@ public void visit( AlgNode p, int ordinal, AlgNode parent ) { if ( accessedPartitions.containsKey( p.getId() ) ) { relevantPartitions = accessedPartitions.get( p.getId() ); } else { - if ( table.namespaceType == NamespaceType.RELATIONAL ) { + if ( table.dataModel == DataModel.RELATIONAL ) { List allocations = Catalog.getInstance().getSnapshot().alloc().getFromLogical( table.id ); relevantPartitions = allocations.stream().map( a -> a.id ).collect( Collectors.toList() ); } else { diff --git a/dbms/src/test/java/org/polypheny/db/catalog/CatalogTransactionTest.java b/dbms/src/test/java/org/polypheny/db/catalog/CatalogTransactionTest.java index af9a2f650b..0242386f28 100644 --- a/dbms/src/test/java/org/polypheny/db/catalog/CatalogTransactionTest.java +++ b/dbms/src/test/java/org/polypheny/db/catalog/CatalogTransactionTest.java @@ -23,8 +23,8 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.impl.PolyCatalog; import org.polypheny.db.catalog.logistic.Collation; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.type.PolyType; public class CatalogTransactionTest { @@ -40,7 +40,7 @@ public static void initClass() { public void simpleRollbackTest() { PolyCatalog catalog = new PolyCatalog(); - long namespaceId = catalog.createNamespace( "test", NamespaceType.RELATIONAL, false ); + long namespaceId = catalog.createNamespace( "test", DataModel.RELATIONAL, false ); catalog.commit(); @@ -61,7 +61,7 @@ public void simpleRollbackTest() { public void rollbackTest() { PolyCatalog catalog = new PolyCatalog(); - long namespaceId = catalog.createNamespace( "test", NamespaceType.RELATIONAL, false ); + long namespaceId = catalog.createNamespace( "test", DataModel.RELATIONAL, false ); catalog.commit(); diff --git a/information/src/main/java/org/polypheny/db/information/InformationManager.java b/information/src/main/java/org/polypheny/db/information/InformationManager.java index 7b4fdceb41..f04a66e5c9 100644 --- a/information/src/main/java/org/polypheny/db/information/InformationManager.java +++ b/information/src/main/java/org/polypheny/db/information/InformationManager.java @@ -320,4 +320,14 @@ private void notifyPageList() { } } + + public void attachStacktrace( Exception e ) { + InformationPage exceptionPage = new InformationPage( "Stacktrace" ).fullWidth(); + InformationGroup exceptionGroup = new InformationGroup( exceptionPage.getId(), "Stacktrace" ); + InformationStacktrace exceptionElement = new InformationStacktrace( e, exceptionGroup ); + this.addPage( exceptionPage ); + this.addGroup( exceptionGroup ); + this.registerInformation( exceptionElement ); + } + } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/DashboardInformation.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/DashboardInformation.java index 0f755ad4f4..5cabca9618 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/DashboardInformation.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/DashboardInformation.java @@ -22,7 +22,7 @@ import lombok.Setter; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalAdapter.AdapterType; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.monitoring.core.MonitoringServiceProvider; import org.polypheny.db.monitoring.events.metrics.DmlDataPoint; @@ -50,7 +50,7 @@ public class DashboardInformation { private final Map> availableAdapter = new HashMap<>(); - private final Map> availableSchemas = new HashMap<>(); + private final Map> availableSchemas = new HashMap<>(); private boolean catalogPersistent; @@ -78,7 +78,7 @@ public void updatePolyphenyStatistic() { this.availableAdapter.put( v.uniqueName, Pair.of( v.adapterTypeName, v.type ) ); } ); snapshot.getNamespaces( null ).forEach( v -> { - availableSchemas.put( v.id, Pair.of( v.name, v.namespaceType ) ); + availableSchemas.put( v.id, Pair.of( v.name, v.dataModel ) ); } ); } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java index 14f15d35d2..7efc5071bd 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticQueryProcessor.java @@ -30,7 +30,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.RuntimeConfig; @@ -86,7 +86,7 @@ public List getAllColumns() { Snapshot snapshot = Catalog.getInstance().getSnapshot(); return snapshot.getNamespaces( null ) .stream() - .filter( n -> n.namespaceType == NamespaceType.RELATIONAL ) + .filter( n -> n.dataModel == DataModel.RELATIONAL ) .flatMap( n -> snapshot.rel().getTables( Pattern.of( n.name ), null ).stream().filter( t -> t.entityType != EntityType.VIEW ).flatMap( t -> snapshot.rel().getColumns( t.id ).stream() ) ) .map( QueryResult::fromCatalogColumn ) .collect( Collectors.toList() ); @@ -100,7 +100,7 @@ public List getAllColumns() { */ public List getAllTable() { Snapshot snapshot = Catalog.getInstance().getSnapshot(); - return snapshot.getNamespaces( null ).stream().filter( n -> n.namespaceType == NamespaceType.RELATIONAL ) + return snapshot.getNamespaces( null ).stream().filter( n -> n.dataModel == DataModel.RELATIONAL ) .flatMap( n -> snapshot.rel().getTables( Pattern.of( n.name ), null ).stream().filter( t -> t.entityType != EntityType.VIEW ) ).collect( Collectors.toList() ); } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java index 65039f6129..9b28f83fed 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticTable.java @@ -24,7 +24,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; /** @@ -43,7 +43,7 @@ public class StatisticTable { private TableCalls calls; @Getter - private NamespaceType namespaceType; + private DataModel dataModel; @Getter private final List availableAdapters = new ArrayList<>(); @@ -74,7 +74,7 @@ public StatisticTable( Long tableId ) { if ( catalog.getSnapshot().getLogicalEntity( tableId ).isPresent() ) { LogicalTable catalogTable = catalog.getSnapshot().getLogicalEntity( tableId ).map( e -> e.unwrap( LogicalTable.class ) ).orElseThrow(); this.table = catalogTable.name; - this.namespaceType = catalogTable.namespaceType; + this.dataModel = catalogTable.dataModel; //this.dataPlacements = ImmutableList.copyOf( catalog.getSnapshot().alloc().getDataPlacements( catalogTable.id ).stream().map( c -> c.adapterId ).collect( Collectors.toList() ) ); this.entityType = catalogTable.entityType; } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java index 9cba794966..763dfeeff4 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/StatisticsManagerImpl.java @@ -721,7 +721,7 @@ public void displayInformation() { } ); tableStatistic.forEach( ( k, v ) -> { - tableInformation.addRow( v.getTable(), v.getNamespaceType(), v.getNumberOfRows() ); + tableInformation.addRow( v.getTable(), v.getDataModel(), v.getNumberOfRows() ); if ( RuntimeConfig.ACTIVE_TRACKING.getBoolean() && v.getEntityType() != EntityType.MATERIALIZED_VIEW ) { tableSelectInformation.addRow( diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index 4a0e48d255..7e8f48a2ca 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -96,9 +96,9 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.entity.logical.LogicalTable.PrimitiveCatalogTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.catalog.logistic.EntityType.PrimitiveTableType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.iface.AuthenticationException; import org.polypheny.db.iface.Authenticator; @@ -147,7 +147,7 @@ public class DbmsMeta implements ProtobufMeta { public static final boolean SEND_FIRST_FRAME_WITH_RESPONSE = false; private final ConcurrentMap openConnections = new ConcurrentHashMap<>(); - private final ConcurrentMap openStatements = new ConcurrentHashMap<>(); + private final ConcurrentMap openStatements = new ConcurrentHashMap<>(); final Calendar calendar = Unsafe.localCalendar(); private final Catalog catalog = Catalog.getInstance(); @@ -203,8 +203,8 @@ private MetaResultSet createMetaResultSet( List columns, CursorFactory cursorFactory, final Iterable firstFrame ) { - final PolyphenyDbSignature signature = - new PolyphenyDbSignature( + final PolySignature signature = + new PolySignature( "", ImmutableList.of(), internalParameters, @@ -217,7 +217,7 @@ private MetaResultSet createMetaResultSet( null, StatementType.SELECT, new ExecutionTimeMonitor(), - NamespaceType.RELATIONAL ) { + DataModel.RELATIONAL ) { @Override public Enumerable enumerable( DataContext dataContext ) { return Linq4j.asEnumerable( firstFrame ); @@ -906,7 +906,7 @@ public ExecuteBatchResult executeBatchProtobuf( final StatementHandle h, final L log.trace( "executeBatchProtobuf( StatementHandle {}, List {} )", h, parameterValues ); } - final PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + final PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); long[] updateCounts = new long[parameterValues.size()]; Map> values = new HashMap<>(); @@ -988,7 +988,7 @@ public StatementHandle prepare( final ConnectionHandle ch, final String sql, fin } StatementHandle h = createStatement( ch ); - PolyphenyDbStatementHandle polyphenyDbStatement; + PolyStatementHandle polyphenyDbStatement; try { polyphenyDbStatement = getPolyphenyDbStatementHandle( h ); } catch ( NoSuchStatementException e ) { @@ -1007,7 +1007,7 @@ public StatementHandle prepare( final ConnectionHandle ch, final String sql, fin List avaticaParameters = deriveAvaticaParameters( parameterRowType ); - PolyphenyDbSignature signature = new PolyphenyDbSignature( + PolySignature signature = new PolySignature( sql, avaticaParameters, ImmutableMap.of(), @@ -1020,7 +1020,7 @@ public StatementHandle prepare( final ConnectionHandle ch, final String sql, fin null, StatementType.SELECT, null, - NamespaceType.RELATIONAL ); + DataModel.RELATIONAL ); h.signature = signature; polyphenyDbStatement.setSignature( signature ); @@ -1067,7 +1067,7 @@ public ExecuteResult prepareAndExecute( final StatementHandle h, final String sq log.trace( "prepareAndExecute( StatementHandle {}, String {}, long {}, int {}, PrepareCallback {} )", h, sql, maxRowCount, maxRowsInFirstFrame, callback ); } - PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); statementHandle.setPreparedQuery( sql ); statementHandle.setStatement( connection.getCurrentOrCreateNewTransaction().createStatement() ); return execute( h, new ArrayList<>(), maxRowsInFirstFrame, connection ); @@ -1135,9 +1135,9 @@ public Frame fetch( final StatementHandle h, final long offset, final int fetchM log.trace( "fetch( StatementHandle {}, long {}, int {} )", h, offset, fetchMaxRowCount ); } - final PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + final PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); - final PolyphenyDbSignature signature = statementHandle.getSignature(); + final PolySignature signature = statementHandle.getSignature(); final Iterator iterator; if ( statementHandle.getOpenResultSet() == null ) { final Iterable iterable = createExternalIterable( statementHandle.getStatement().getDataContext(), signature ); @@ -1169,7 +1169,7 @@ public Frame fetch( final StatementHandle h, final long offset, final int fetchM } - private Iterable createExternalIterable( DataContext dataContext, PolyphenyDbSignature signature ) { + private Iterable createExternalIterable( DataContext dataContext, PolySignature signature ) { return externalize( signature.enumerable( dataContext ), signature.rowType ); } @@ -1209,7 +1209,7 @@ public ExecuteResult execute( final StatementHandle h, final List pa if ( log.isTraceEnabled() ) { log.trace( "execute( StatementHandle {}, List {}, int {} )", h, parameterValues, maxRowsInFirstFrame ); } - final PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + final PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); statementHandle.setStatement( connection.getCurrentOrCreateNewTransaction().createStatement() ); return execute( h, parameterValues, maxRowsInFirstFrame, connection ); } @@ -1217,7 +1217,7 @@ public ExecuteResult execute( final StatementHandle h, final List pa private ExecuteResult execute( StatementHandle h, List parameterValues, int maxRowsInFirstFrame, PolyphenyDbConnectionHandle connection ) throws NoSuchStatementException { - final PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + final PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); long index = 0; for ( TypedValue v : parameterValues ) { @@ -1300,7 +1300,7 @@ private PolyType toPolyType( Rep type ) { private PolyList convertList( List list ) { - List newList = new LinkedList<>(); + List newList = new ArrayList<>(); for ( TypedValue o : list ) { newList.add( toPolyValue( o ) ); } @@ -1350,7 +1350,7 @@ private PolyValue toPolyValue( TypedValue value ) { private void prepare( StatementHandle h, String sql ) throws NoSuchStatementException { - PolyphenyDbStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); + PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); QueryLanguage language = QueryLanguage.from( "sql" ); QueryContext context = QueryContext.builder() .query( sql ) @@ -1359,7 +1359,7 @@ private void prepare( StatementHandle h, String sql ) throws NoSuchStatementExce .transactionManager( transactionManager ) .build(); - PolyphenyDbSignature signature = PolyphenyDbSignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement() ).get( 0 ).getImplementation() ); + PolySignature signature = PolySignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement() ).get( 0 ).getImplementation() ); h.signature = signature; statementHandle.setSignature( signature ); @@ -1394,7 +1394,7 @@ public Enumerator enumerator() { } - private List execute( StatementHandle h, PolyphenyDbConnectionHandle connection, PolyphenyDbStatementHandle statementHandle, int maxRowsInFirstFrame ) { + private List execute( StatementHandle h, PolyphenyDbConnectionHandle connection, PolyStatementHandle statementHandle, int maxRowsInFirstFrame ) { List resultSets; if ( statementHandle.getSignature().statementType == StatementType.OTHER_DDL ) { MetaResultSet resultSet = MetaResultSet.count( statementHandle.getConnection().getConnectionId().toString(), h.id, 1 ); @@ -1447,10 +1447,10 @@ public StatementHandle createStatement( ConnectionHandle ch ) { log.trace( "createStatement( ConnectionHandle {} )", ch ); } - final PolyphenyDbStatementHandle statement; + final PolyStatementHandle statement; final int id = statementIdGenerator.getAndIncrement(); - statement = new PolyphenyDbStatementHandle<>( connection, id ); + statement = new PolyStatementHandle<>( connection, id ); openStatements.put( ch.id + "::" + id, statement ); StatementHandle h = new StatementHandle( ch.id, statement.getStatementId(), null ); @@ -1475,7 +1475,7 @@ public void closeStatement( final StatementHandle statementHandle ) { log.trace( "closeStatement( StatementHandle {} )", statementHandle ); } - final PolyphenyDbStatementHandle toClose = openStatements.remove( statementHandle.connectionId + "::" + statementHandle.id ); + final PolyStatementHandle toClose = openStatements.remove( statementHandle.connectionId + "::" + statementHandle.id ); if ( toClose != null ) { if ( toClose.getOpenResultSet() != null && toClose.getOpenResultSet() instanceof AutoCloseable ) { try { @@ -1588,7 +1588,7 @@ public void closeConnection( ConnectionHandle ch ) { for ( final String key : openStatements.keySet() ) { if ( key.startsWith( ch.id ) ) { - PolyphenyDbStatementHandle statementHandle = openStatements.remove( key ); + PolyStatementHandle statementHandle = openStatements.remove( key ); statementHandle.unset(); } } @@ -1607,8 +1607,8 @@ private PolyphenyDbConnectionHandle getPolyphenyDbConnectionHandle( String conne } - private PolyphenyDbStatementHandle getPolyphenyDbStatementHandle( StatementHandle h ) throws NoSuchStatementException { - final PolyphenyDbStatementHandle statement; + private PolyStatementHandle getPolyphenyDbStatementHandle( StatementHandle h ) throws NoSuchStatementException { + final PolyStatementHandle statement; if ( openStatements.containsKey( h.connectionId + "::" + h.id ) ) { statement = openStatements.get( h.connectionId + "::" + h.id ); } else { diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java similarity index 90% rename from plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java rename to plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java index 8d43adb9c3..a8f47081c4 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbSignature.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java @@ -35,7 +35,7 @@ import org.polypheny.db.algebra.AlgCollation; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.routing.ExecutionTimeMonitor; import org.polypheny.db.runtime.Bindable; import org.polypheny.db.schema.PolyphenyDbSchema; @@ -48,7 +48,7 @@ * */ @Getter -public class PolyphenyDbSignature extends Meta.Signature { +public class PolySignature extends Meta.Signature { @JsonIgnore public final AlgDataType rowType; @@ -58,11 +58,11 @@ public class PolyphenyDbSignature extends Meta.Signature { private final List collationList; private final long maxRowCount; private final Bindable bindable; - private final NamespaceType namespaceType; + private final DataModel dataModel; private final ExecutionTimeMonitor executionTimeMonitor; - public PolyphenyDbSignature( + public PolySignature( String sql, List parameterList, Map internalParameters, @@ -75,7 +75,7 @@ public PolyphenyDbSignature( Bindable bindable, StatementType statementType, ExecutionTimeMonitor executionTimeMonitor, - NamespaceType namespaceType ) { + DataModel dataModel ) { super( columns, sql, parameterList, internalParameters, cursorFactory, statementType ); this.rowType = rowType; this.rootSchema = rootSchema; @@ -83,11 +83,11 @@ public PolyphenyDbSignature( this.maxRowCount = maxRowCount; this.bindable = bindable; this.executionTimeMonitor = executionTimeMonitor; - this.namespaceType = namespaceType; + this.dataModel = dataModel; } - public static PolyphenyDbSignature from( PolyImplementation prepareQuery ) { + public static PolySignature from( PolyImplementation prepareQuery ) { final List parameters = new ArrayList<>(); if ( prepareQuery.rowType != null ) { for ( AlgDataTypeField field : prepareQuery.rowType.getFields() ) { @@ -103,7 +103,7 @@ public static PolyphenyDbSignature from( PolyImplementation prepareQuery ) { field.getName() ) ); } } - return new PolyphenyDbSignature( + return new PolySignature( "", parameters, new HashMap<>(), @@ -116,7 +116,7 @@ public static PolyphenyDbSignature from( PolyImplementation prepareQuery ) { prepareQuery.getBindable(), prepareQuery.getStatementType(), prepareQuery.getExecutionTimeMonitor(), - prepareQuery.getNamespaceType() + prepareQuery.getDataModel() ); } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyStatementHandle.java similarity index 85% rename from plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java rename to plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyStatementHandle.java index 33a986d5d9..312a7aa8b9 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbStatementHandle.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyStatementHandle.java @@ -27,12 +27,12 @@ * */ @Getter -public class PolyphenyDbStatementHandle { +public class PolyStatementHandle { private final PolyphenyDbConnectionHandle connection; private final int statementId; private volatile transient Iterator openResultSet; - private volatile transient PolyphenyDbSignature signature; + private volatile transient PolySignature signature; @Setter private volatile transient String preparedQuery; @Setter @@ -45,7 +45,7 @@ public class PolyphenyDbStatementHandle { private final StopWatch executionStopWatch = new StopWatch(); - public PolyphenyDbStatementHandle( final PolyphenyDbConnectionHandle connection, final int statementId ) { + public PolyStatementHandle( final PolyphenyDbConnectionHandle connection, final int statementId ) { this.connection = connection; this.statementId = statementId; } @@ -59,7 +59,7 @@ public synchronized void setOpenResultSet( Iterator result ) { } - public synchronized void setSignature( PolyphenyDbSignature signature ) { + public synchronized void setSignature( PolySignature signature ) { this.signature = signature; this.openResultSet = null; executionStopWatch.reset(); diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java index a4f2e2fffd..5e50660315 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java @@ -62,8 +62,8 @@ public class PolyphenyDbResultSet extends AvaticaResultSet { /** * Creates a PolyphenyDbResultSet. */ - public PolyphenyDbResultSet( AvaticaStatement statement, PolyphenyDbSignature polyphenyDbSignature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame ) throws SQLException { - super( statement, null, polyphenyDbSignature, resultSetMetaData, timeZone, firstFrame ); + public PolyphenyDbResultSet( AvaticaStatement statement, PolySignature polySignature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame ) throws SQLException { + super( statement, null, polySignature, resultSetMetaData, timeZone, firstFrame ); } @@ -75,9 +75,9 @@ public ResultSet create( ColumnMetaData.AvaticaType elementType, Iterable // Do not make public - PolyphenyDbSignature getSignature() { - return (PolyphenyDbSignature) signature; + PolySignature getSignature() { + return (PolySignature) signature; } } diff --git a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java index a2c341cec5..9556c3c200 100644 --- a/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java +++ b/plugins/cql-language/src/main/java/org/polypheny/db/cql/CqlLanguagePlugin.java @@ -18,7 +18,7 @@ import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.plugins.PluginContext; @@ -44,7 +44,7 @@ public CqlLanguagePlugin( PluginContext context ) { @Override public void start() { - QueryLanguage language = new QueryLanguage( NamespaceType.RELATIONAL, NAME, List.of( NAME ), null, CqlProcessor::new, null, CqlQueryBuilder::splitter ); + QueryLanguage language = new QueryLanguage( DataModel.RELATIONAL, NAME, List.of( NAME ), null, CqlProcessor::new, null, CqlQueryBuilder::splitter ); LanguageManager.getINSTANCE().addQueryLanguage( language ); PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getRelResult ) ); } 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 9caa977e22..649557b1f8 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 @@ -17,7 +17,7 @@ package org.polypheny.db.cypher; import java.util.List; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.cypher.parser.CypherParserImpl; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; @@ -44,7 +44,7 @@ public CypherLanguagePlugin( PluginContext context ) { @Override public void start() { QueryLanguage language = new QueryLanguage( - NamespaceType.GRAPH, + DataModel.GRAPH, NAME, List.of( NAME, "opencypher" ), CypherParserImpl.FACTORY, diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java index 3c271bdbac..dccb84190e 100644 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java +++ b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/AlgToSqlConverterTest.java @@ -36,7 +36,7 @@ import org.polypheny.db.algebra.rules.UnionMergeRule; import org.polypheny.db.algebra.type.AlgDataTypeSystemImpl; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.NodeToAlgConverter; import org.polypheny.db.languages.NodeToAlgConverter.Config; import org.polypheny.db.languages.OperatorRegistry; @@ -108,7 +108,7 @@ public class AlgToSqlConverterTest extends SqlLanguageDependent { private Sql sql( String sql ) { final SchemaPlus schema = Frameworks .createSnapshot( true ) - .add( "foodmart", new ReflectiveSchema( new FoodmartSchema(), -1 ), NamespaceType.RELATIONAL ); + .add( "foodmart", new ReflectiveSchema( new FoodmartSchema(), -1 ), DataModel.RELATIONAL ); return new Sql( schema, sql, PolyphenyDbSqlDialect.DEFAULT, DEFAULT_REL_CONFIG, ImmutableList.of() ); } @@ -164,7 +164,7 @@ private static MysqlSqlDialect mySqlDialect( NullCollation nullCollation ) { */ private static AlgBuilder algBuilder() { // Creates a config based on the "scott" schema. - final SchemaPlus schema = Frameworks.createSnapshot( true ).add( "scott", new ReflectiveSchema( new ScottSchema(), -1 ), NamespaceType.RELATIONAL ); + final SchemaPlus schema = Frameworks.createSnapshot( true ).add( "scott", new ReflectiveSchema( new ScottSchema(), -1 ), DataModel.RELATIONAL ); Frameworks.ConfigBuilder configBuilder = Frameworks.newConfigBuilder() .parserConfig( Parser.ParserConfig.DEFAULT ) .defaultSnapshot( schema ) 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 62b70c55fb..426ec29375 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 @@ -92,7 +92,7 @@ import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -135,7 +135,7 @@ public class MongoEntity extends PhysicalEntity implements TranslatableEntity, M * Creates a MongoTable. */ MongoEntity( PhysicalEntity physical, List fields, MongoNamespace namespace, TransactionProvider transactionProvider ) { - super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.namespaceId, physical.namespaceName, physical.namespaceType, physical.adapterId ); + super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.namespaceId, physical.namespaceName, physical.dataModel, physical.adapterId ); this.physical = physical; this.mongoNamespace = namespace; this.transactionProvider = transactionProvider; @@ -147,7 +147,7 @@ public class MongoEntity extends PhysicalEntity implements TranslatableEntity, M @Override public AlgDataType getRowType() { - if ( namespaceType == NamespaceType.RELATIONAL ) { + if ( dataModel == DataModel.RELATIONAL ) { return buildProto().apply( AlgDataTypeFactory.DEFAULT ); } return super.getRowType(); 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 b850bd73e5..96ad196f2b 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 @@ -28,7 +28,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.mql.MqlCreateCollection; import org.polypheny.db.languages.mql.MqlCreateView; @@ -77,7 +77,7 @@ public void stop() { public static void startup() { QueryLanguage language = new QueryLanguage( - NamespaceType.DOCUMENT, + DataModel.DOCUMENT, "mongo", List.of( "mongo", "mql" ), MqlParserImpl.FACTORY, diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlQueryParameters.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlQueryParameters.java index 05d5255032..73cfc92966 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlQueryParameters.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlQueryParameters.java @@ -17,7 +17,7 @@ package org.polypheny.db.languages.mql; import lombok.Getter; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.QueryParameters; @Getter @@ -26,8 +26,8 @@ public class MqlQueryParameters extends QueryParameters { final Long namespaceId; - public MqlQueryParameters( String query, Long namespaceId, NamespaceType namespaceType ) { - super( query, namespaceType ); + public MqlQueryParameters( String query, Long namespaceId, DataModel dataModel ) { + super( query, dataModel ); this.namespaceId = namespaceId; } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java index 3cdd550ae2..77ca5a4793 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseDatabase.java @@ -17,7 +17,7 @@ package org.polypheny.db.languages.mql; import lombok.Getter; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -41,7 +41,7 @@ public MqlUseDatabase( ParserPos pos, String database ) { @Override public void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ) { - DdlManager.getInstance().createNamespace( this.database, NamespaceType.DOCUMENT, true, false ); + DdlManager.getInstance().createNamespace( this.database, DataModel.DOCUMENT, true, false ); } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java index d44928e6f7..ccb35381fe 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java @@ -69,7 +69,7 @@ import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.QueryLanguage; @@ -260,7 +260,7 @@ public AlgRoot convert( MqlCollectionStatement query ) { AlgNode node; - if ( entity.namespaceType == NamespaceType.RELATIONAL ) { + if ( entity.dataModel == DataModel.RELATIONAL ) { _dataExists = false; } 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 04bf52e96e..c867d7e2c5 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 @@ -70,7 +70,7 @@ 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 ); + super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.namespaceId, physical.namespaceName, physical.dataModel, physical.adapterId ); this.fields = fields; this.namespace = namespace; } diff --git a/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java b/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java index 453dc31861..bb88231b3b 100644 --- a/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java +++ b/plugins/pig-language/src/main/java/org/polypheny/db/PigLanguagePlugin.java @@ -18,7 +18,7 @@ import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.LanguageManager; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.piglet.PigProcessor; @@ -45,7 +45,7 @@ public PigLanguagePlugin( PluginContext context ) { @Override public void start() { - QueryLanguage language = new QueryLanguage( NamespaceType.RELATIONAL, NAME, List.of( NAME, "piglet" ), null, PigProcessor::new, null, LanguageManager::toQueryNodes ); + QueryLanguage language = new QueryLanguage( DataModel.RELATIONAL, NAME, List.of( NAME, "piglet" ), null, PigProcessor::new, null, LanguageManager::toQueryNodes ); LanguageManager.getINSTANCE().addQueryLanguage( language ); PolyPluginManager.AFTER_INIT.add( () -> LanguageCrud.addToResult( language, LanguageCrud::getRelResult ) ); diff --git a/plugins/sql-language/src/main/codegen/Parser.jj b/plugins/sql-language/src/main/codegen/Parser.jj index 017d666cb9..653d4e1cb2 100644 --- a/plugins/sql-language/src/main/codegen/Parser.jj +++ b/plugins/sql-language/src/main/codegen/Parser.jj @@ -145,7 +145,7 @@ import java.util.HashMap; import org.polypheny.db.util.CoreUtil; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.ParserFactory; import org.polypheny.db.util.Conformance; import org.polypheny.db.languages.NodeParseException; @@ -1850,21 +1850,21 @@ SqlCreate SqlCreateNamespace(Span s, boolean replace) : { final boolean ifNotExists; final SqlIdentifier id; - final NamespaceType namespaceType; + final DataModel dataModel; } { ( - { namespaceType = NamespaceType.RELATIONAL; } + { dataModel = DataModel.RELATIONAL; } | - { namespaceType = NamespaceType.DOCUMENT; } + { dataModel = DataModel.DOCUMENT; } | - { namespaceType = NamespaceType.GRAPH; } + { dataModel = DataModel.GRAPH; } | - { namespaceType = NamespaceType.RELATIONAL; } + { dataModel = DataModel.RELATIONAL; } ) ( | ) ifNotExists = IfNotExistsOpt() id = CompoundIdentifier() { - return SqlDdlNodes.createNamespace(s.end(this), replace, ifNotExists, id, namespaceType); + return SqlDdlNodes.createNamespace(s.end(this), replace, ifNotExists, id, dataModel); } } diff --git a/plugins/sql-language/src/main/codegen/includes/ddlParser.ftl b/plugins/sql-language/src/main/codegen/includes/ddlParser.ftl index 3c99d8c850..cd1a4d4896 100644 --- a/plugins/sql-language/src/main/codegen/includes/ddlParser.ftl +++ b/plugins/sql-language/src/main/codegen/includes/ddlParser.ftl @@ -39,17 +39,17 @@ SqlCreate SqlCreateSchema(Span s, boolean replace) : { final boolean ifNotExists; final SqlIdentifier id; - final NamespaceType namespaceType; + final DataModel dataModel; } { ( - { namespaceType = NamespaceType.DOCUMENT; } + { dataModel = DataModel.DOCUMENT; } | - { namespaceType = NamespaceType.RELATIONAL; } + { dataModel = DataModel.RELATIONAL; } ) ifNotExists = IfNotExistsOpt() id = CompoundIdentifier() { - return SqlDdlNodes.createSchema(s.end(this), replace, ifNotExists, id, namespaceType); + return SqlDdlNodes.createSchema(s.end(this), replace, ifNotExists, id, dataModel); } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java index 55e1031511..c1ec4de4cb 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java @@ -35,7 +35,7 @@ import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.operators.OperatorTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.PolyphenyDbConnectionProperty; import org.polypheny.db.languages.LanguageManager; @@ -199,7 +199,7 @@ public void stop() { public static void startup() { // add language to general processing QueryLanguage language = new QueryLanguage( - NamespaceType.RELATIONAL, + DataModel.RELATIONAL, "sql", List.of( "sql" ), SqlParserImpl.FACTORY, diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java index 47fc023cdc..2df8ff07a2 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java @@ -38,7 +38,7 @@ import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.languages.NodeParseException; @@ -256,13 +256,13 @@ private void addDefaultValues( Transaction transaction, SqlInsert insert ) { if ( oldColumnList != null ) { LogicalTable catalogTable = getTable( transaction, (SqlIdentifier) insert.getTargetTable() ); - NamespaceType namespaceType = Catalog.getInstance().getSnapshot().getNamespace( catalogTable.namespaceId ).orElseThrow().namespaceType; + DataModel dataModel = Catalog.getInstance().getSnapshot().getNamespace( catalogTable.namespaceId ).orElseThrow().dataModel; catalogTable = getTable( transaction, (SqlIdentifier) insert.getTargetTable() ); SqlNodeList newColumnList = new SqlNodeList( ParserPos.ZERO ); int size = catalogTable.getColumns().size(); - if ( namespaceType == NamespaceType.DOCUMENT ) { + if ( dataModel == DataModel.DOCUMENT ) { List columnNames = catalogTable.getColumnNames(); size += (int) oldColumnList.getSqlList().stream().filter( column -> !columnNames.contains( ((SqlIdentifier) column).names.get( 0 ) ) ).count(); } @@ -325,7 +325,7 @@ private void addDefaultValues( Transaction transaction, SqlInsert insert ) { } // add doc values back TODO DL: change - if ( namespaceType == NamespaceType.DOCUMENT ) { + if ( dataModel == DataModel.DOCUMENT ) { List documentColumns = new ArrayList<>(); for ( Node column : oldColumnList.getSqlList() ) { if ( newColumnList.getSqlList() 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 2fb7ca7342..7b9ebf4997 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 @@ -21,7 +21,7 @@ import lombok.Setter; import org.jetbrains.annotations.Nullable; import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; import org.polypheny.db.nodes.Operator; @@ -166,8 +166,8 @@ public void validate( SqlValidator validator, SqlValidatorScope scope ) { } - public NamespaceType getSchemaType() { - return NamespaceType.RELATIONAL; + public DataModel getSchemaType() { + return DataModel.RELATIONAL; } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java index 468057d845..87eff9fca8 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Objects; import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.ExecutableStatement; @@ -44,7 +44,7 @@ public class SqlCreateNamespace extends SqlCreate implements ExecutableStatement private final SqlIdentifier name; - private final NamespaceType type; + private final DataModel type; private static final SqlOperator OPERATOR = new SqlSpecialOperator( "CREATE NAMESPACE", Kind.CREATE_NAMESPACE ); @@ -52,10 +52,10 @@ public class SqlCreateNamespace extends SqlCreate implements ExecutableStatement /** * Creates a SqlCreateNamespace. */ - SqlCreateNamespace( ParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier name, NamespaceType namespaceType ) { + SqlCreateNamespace( ParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier name, DataModel dataModel ) { super( OPERATOR, pos, replace, ifNotExists ); this.name = Objects.requireNonNull( name ); - this.type = namespaceType; + this.type = dataModel; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDdlNodes.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDdlNodes.java index 5bd6ff73f8..cfe4ba5952 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDdlNodes.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDdlNodes.java @@ -18,7 +18,7 @@ import java.util.List; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Operator; import org.polypheny.db.partition.raw.RawPartitionInformation; @@ -43,8 +43,8 @@ private SqlDdlNodes() { /** * Creates a CREATE NAMESPACE. */ - public static SqlCreateNamespace createNamespace( ParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier name, NamespaceType namespaceType ) { - return new SqlCreateNamespace( pos, replace, ifNotExists, name, namespaceType ); + public static SqlCreateNamespace createNamespace( ParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier name, DataModel dataModel ) { + return new SqlCreateNamespace( pos, replace, ifNotExists, name, dataModel ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java index aa414296df..b94c957cdf 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java @@ -33,7 +33,7 @@ import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.sql.language.SqlCall; @@ -170,11 +170,11 @@ private SqlValidatorNamespace resolveImpl( SqlIdentifier id ) { } else if ( ns.size() == 2 ) { LogicalNamespace namespace = validator.snapshot.getNamespace( ns.get( 0 ) ).orElseThrow(); LogicalEntity entity = null; - if ( namespace.namespaceType == NamespaceType.RELATIONAL ) { + if ( namespace.dataModel == DataModel.RELATIONAL ) { entity = validator.snapshot.rel().getTable( namespace.id, ns.get( 1 ) ).orElse( null ); - } else if ( namespace.namespaceType == NamespaceType.DOCUMENT ) { + } else if ( namespace.dataModel == DataModel.DOCUMENT ) { entity = validator.snapshot.doc().getCollection( namespace.id, ns.get( 1 ) ).orElse( null ); - } else if ( namespace.namespaceType == NamespaceType.GRAPH ) { + } else if ( namespace.dataModel == DataModel.GRAPH ) { throw new NotImplementedException(); } 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 cb2e396792..6b2d19d11a 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 @@ -75,7 +75,7 @@ import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.languages.OperatorRegistry; @@ -4061,7 +4061,7 @@ public void validateInsert( SqlInsert insert ) { null, null ); - boolean allowDynamic = insert.getSchemaType() == NamespaceType.DOCUMENT; + boolean allowDynamic = insert.getSchemaType() == DataModel.DOCUMENT; // INSERT has an optional column name list. If present then reduce the rowtype to the columns specified. If not present then the entire target rowtype is used. final AlgDataType targetRowType = createTargetRowType( table, insert.getTargetColumnList(), false, allowDynamic ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java index d31a562678..b36e7e32b2 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java @@ -41,7 +41,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.languages.ParserPos; @@ -623,7 +623,7 @@ public static boolean isNotRelational( SqlValidatorImpl validator ) { namespace = Catalog.defaultNamespaceName; } - return validator.snapshot.getNamespace( namespace ).orElseThrow().namespaceType != NamespaceType.RELATIONAL; + return validator.snapshot.getNamespace( namespace ).orElseThrow().dataModel != DataModel.RELATIONAL; } 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 831d6f5b92..c172f1fcb0 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 @@ -127,8 +127,8 @@ import org.polypheny.db.catalog.entity.LogicalEntity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.NodeToAlgConverter; import org.polypheny.db.languages.OperatorRegistry; @@ -2959,7 +2959,7 @@ protected AlgNode convertColumnList( final SqlInsert call, AlgNode source ) { final LogicalEntity targetTable = getTargetTable( call ); final AlgDataType targetRowType = targetTable.getRowType();//AlgOptEntityImpl.realRowType( targetTable ); final List targetFields = targetRowType.getFields(); - boolean isDocument = call.getSchemaType() == NamespaceType.DOCUMENT; + boolean isDocument = call.getSchemaType() == DataModel.DOCUMENT; List sourceExps = new ArrayList<>( Collections.nCopies( targetFields.size(), null ) ); List fieldNames = new ArrayList<>( Collections.nCopies( targetFields.size(), null ) ); // TODO DL: reevaluate and make final again? @@ -3082,7 +3082,7 @@ protected void collectInsertTargets( SqlInsert call, final RexNode sourceRef, fi } else { boolean allowDynamic = false; - if ( call.getSchemaType() == NamespaceType.DOCUMENT ) { + if ( call.getSchemaType() == DataModel.DOCUMENT ) { allowDynamic = true; } diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index 4526ecdcc7..de55ab6fcb 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -113,10 +113,10 @@ import org.polypheny.db.catalog.entity.logical.LogicalView; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.ConstraintType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.catalog.logistic.ForeignKeyOption; import org.polypheny.db.catalog.logistic.NameGenerator; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.PartitionType; import org.polypheny.db.catalog.logistic.PlacementType; import org.polypheny.db.catalog.snapshot.LogicalRelSnapshot; @@ -300,7 +300,7 @@ RelationalResult getTable( final UIRequest request ) { // determine if it is a view or a table LogicalTable table = Catalog.snapshot().rel().getTable( request.entityId ).orElseThrow(); - resultBuilder.namespaceType( table.namespaceType ); + resultBuilder.dataModel( table.dataModel ); if ( table.modifiable ) { resultBuilder.type( ResultType.TABLE ); } else { @@ -367,7 +367,7 @@ void getEntities( final Context ctx ) { LogicalNamespace namespace = Catalog.snapshot().getNamespace( namespaceId ).orElseThrow(); List entities = List.of(); - switch ( namespace.namespaceType ) { + switch ( namespace.dataModel ) { case RELATIONAL: entities = Catalog.snapshot().rel().getTables( namespace.id, null ); break; @@ -2578,18 +2578,18 @@ RelationalResult executeAlg( final AlgRequest request, Session session ) { void namespaceRequest( final Context ctx ) { Namespace namespace = ctx.bodyAsClass( Namespace.class ); - if ( namespace.getType() == NamespaceType.GRAPH ) { + if ( namespace.getType() == DataModel.GRAPH ) { createGraph( namespace, ctx ); return; } - NamespaceType type = namespace.getType(); + DataModel type = namespace.getType(); // create namespace if ( namespace.isCreate() && !namespace.isDrop() ) { StringBuilder query = new StringBuilder( "CREATE " ); - if ( Objects.requireNonNull( namespace.getType() ) == NamespaceType.DOCUMENT ) { + if ( Objects.requireNonNull( namespace.getType() ) == DataModel.DOCUMENT ) { query.append( "DOCUMENT " ); } @@ -2685,7 +2685,7 @@ public void observeInfos( final String infoAsJson, final String analyzerId, fina public void observePageList( final InformationPage[] pages, final String analyzerId, final Session session ) { List nodes = new ArrayList<>(); for ( InformationPage page : pages ) { - nodes.add( new SidebarElement( page.getId(), page.getName(), NamespaceType.RELATIONAL, analyzerId + "/", page.getIcon() ).setLabel( page.getLabel() ) ); + nodes.add( new SidebarElement( page.getId(), page.getName(), DataModel.RELATIONAL, analyzerId + "/", page.getIcon() ).setLabel( page.getLabel() ) ); } WebSocket.sendMessage( session, gson.toJson( nodes.toArray( new SidebarElement[0] ) ) ); } 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 f9140b4fa6..13bc95641b 100644 --- a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java +++ b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java @@ -157,7 +157,7 @@ public void onMessage( final WsMessageContext ctx ) { UIRequest uiRequest = ctx.messageAsClass( UIRequest.class ); try { LogicalNamespace namespace = Catalog.getInstance().getSnapshot().getNamespace( uiRequest.namespace ).orElse( null ); - switch ( namespace.namespaceType ) { + switch ( namespace.dataModel ) { case RELATIONAL: result = crud.getTable( uiRequest ); break; diff --git a/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java b/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java index 624ec63eb5..737cdd9e5e 100644 --- a/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/CatalogCrud.java @@ -29,8 +29,8 @@ import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.models.AlgNodeModel; @@ -67,7 +67,7 @@ public void getTypeNamespaces( final Context ctx ) { ctx.json( Catalog.snapshot() .getNamespaces( null ) .stream() - .collect( Collectors.toMap( LogicalNamespace::getName, LogicalNamespace::getNamespaceType ) ) ); + .collect( Collectors.toMap( LogicalNamespace::getName, LogicalNamespace::getDataModel ) ) ); } @@ -82,12 +82,12 @@ public void getSchemaTree( final Context ctx ) { List namespaces = Catalog.snapshot().getNamespaces( null ); // remove unwanted namespaces - namespaces = namespaces.stream().filter( s -> request.dataModels.contains( s.namespaceType ) ).collect( Collectors.toList() ); + namespaces = namespaces.stream().filter( s -> request.dataModels.contains( s.dataModel ) ).collect( Collectors.toList() ); for ( LogicalNamespace namespace : namespaces ) { - SidebarElement schemaTree = new SidebarElement( namespace.name, namespace.name, namespace.namespaceType, "", getIconName( namespace.namespaceType ) ); + SidebarElement schemaTree = new SidebarElement( namespace.name, namespace.name, namespace.dataModel, "", getIconName( namespace.dataModel ) ); if ( request.depth > 1 ) { - switch ( namespace.namespaceType ) { + switch ( namespace.dataModel ) { case RELATIONAL: attachTreeElements( namespace, request, schemaTree ); break; @@ -117,7 +117,7 @@ private void attachDocumentTreeElements( LogicalNamespace namespace, SchemaTreeR } if ( request.showTable ) { - schemaTree.addChild( new SidebarElement( namespace.name + ".tables", "tables", namespace.namespaceType, request.routerLinkRoot, "fa fa-table" ).addChildren( collectionTree ).setRouterLink( "" ) ); + schemaTree.addChild( new SidebarElement( namespace.name + ".tables", "tables", namespace.dataModel, request.routerLinkRoot, "fa fa-table" ).addChildren( collectionTree ).setRouterLink( "" ) ); } else { schemaTree.addChildren( collectionTree ).setRouterLink( "" ); } @@ -133,7 +133,7 @@ private static SidebarElement attachCollectionElement( LogicalNamespace namespac icon = "icon-eye"; } - SidebarElement tableElement = new SidebarElement( namespace.name + "." + collection.name, collection.name, namespace.namespaceType, request.routerLinkRoot, icon ); + SidebarElement tableElement = new SidebarElement( namespace.name + "." + collection.name, collection.name, namespace.dataModel, request.routerLinkRoot, icon ); if ( request.views ) { if ( collection.entityType == EntityType.ENTITY || collection.entityType == EntityType.SOURCE ) { @@ -158,15 +158,15 @@ private void attachTreeElements( LogicalNamespace namespace, SchemaTreeRequest r } else if ( table.entityType == EntityType.VIEW ) { icon = "icon-eye"; } - if ( table.entityType != EntityType.VIEW && namespace.namespaceType == NamespaceType.DOCUMENT ) { + if ( table.entityType != EntityType.VIEW && namespace.dataModel == DataModel.DOCUMENT ) { icon = "cui-description"; } - SidebarElement tableElement = new SidebarElement( namespace.name + "." + table.name, table.name, namespace.namespaceType, request.routerLinkRoot, icon ); + SidebarElement tableElement = new SidebarElement( namespace.name + "." + table.name, table.name, namespace.dataModel, request.routerLinkRoot, icon ); if ( request.depth > 2 ) { List columns = Catalog.snapshot().rel().getColumns( table.id ); for ( LogicalColumn column : columns ) { - tableElement.addChild( new SidebarElement( namespace.name + "." + table.name + "." + column.name, column.name, namespace.namespaceType, request.routerLinkRoot, icon ).setCssClass( "sidebarColumn" ) ); + tableElement.addChild( new SidebarElement( namespace.name + "." + table.name + "." + column.name, column.name, namespace.dataModel, request.routerLinkRoot, icon ).setCssClass( "sidebarColumn" ) ); } } @@ -184,15 +184,15 @@ private void attachTreeElements( LogicalNamespace namespace, SchemaTreeRequest r } if ( request.showTable ) { - schemaTree.addChild( new SidebarElement( namespace.name + ".tables", "tables", namespace.namespaceType, request.routerLinkRoot, "fa fa-table" ).addChildren( collectionTree ).setRouterLink( "" ) ); + schemaTree.addChild( new SidebarElement( namespace.name + ".tables", "tables", namespace.dataModel, request.routerLinkRoot, "fa fa-table" ).addChildren( collectionTree ).setRouterLink( "" ) ); } else { schemaTree.addChildren( collectionTree ).setRouterLink( "" ); } } - private String getIconName( NamespaceType namespaceType ) { - switch ( namespaceType ) { + private String getIconName( DataModel dataModel ) { + switch ( dataModel ) { case RELATIONAL: return "cui-layers"; case DOCUMENT: 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 37c29826f7..6d17fa23b9 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 @@ -50,8 +50,8 @@ import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.information.InformationManager; import org.polypheny.db.information.InformationObserver; import org.polypheny.db.languages.LanguageManager; @@ -140,6 +140,11 @@ public static void anyQuery( Context ctx ) { TriFunction> builder = REGISTER.get( context.getLanguage() ); for ( ExecutedContext executedContext : executedContexts ) { + if ( executedContext.getError().isPresent() ) { + attachError( transaction, results, executedContext.getQuery().getQuery(), executedContext.getQuery().getLanguage().getDataModel(), executedContext.getError().get() ); + continue; + } + results.add( builder.apply( executedContext, request, executedContext.getStatement() ).build() ); } @@ -211,7 +216,7 @@ public static PolyGraph getGraph( String namespace, TransactionManager manager, } - public static void attachError( Transaction transaction, List> results, String query, NamespaceType model, Throwable t ) { + public static void attachError( Transaction transaction, List> results, String query, DataModel model, Throwable t ) { //String msg = t.getMessage() == null ? "" : t.getMessage(); Result result; switch ( model ) { @@ -296,7 +301,7 @@ public static void attachError( Transaction transaction, List> resu .builder() .header( header.toArray( new UiColumnDefinition[0] ) ) .data( data.toArray( new String[0][] ) ) - .namespaceType( context.getIterator().getImplementation().getNamespaceType() ) + .dataModel( context.getIterator().getImplementation().getDataModel() ) .namespace( request.namespace ) .language( context.getQuery().getLanguage() ) .affectedTuples( data.size() ) @@ -359,7 +364,7 @@ public static List computeResultData( final List> rows .header( context.getIterator().getImplementation().rowType.getFields().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) ) .query( context.getQuery().getQuery() ) .language( context.getQuery().getLanguage() ) - .namespaceType( context.getIterator().getImplementation().getNamespaceType() ) + .dataModel( context.getIterator().getImplementation().getDataModel() ) .xid( statement.getTransaction().getXid().toString() ) .namespace( request.namespace ); @@ -386,7 +391,7 @@ public static List computeResultData( final List> rows .query( context.getQuery().getQuery() ) .language( context.getQuery().getLanguage() ) .xid( statement.getTransaction().getXid().toString() ) - .namespaceType( context.getIterator().getImplementation().getNamespaceType() ) + .dataModel( context.getIterator().getImplementation().getDataModel() ) .namespace( request.namespace ); } @@ -422,7 +427,7 @@ public void getDocumentDatabases( final Context ctx ) { Map names = Catalog.getInstance().getSnapshot() .getNamespaces( null ) .stream() - .collect( Collectors.toMap( LogicalNamespace::getName, s -> s.namespaceType.name() ) ); + .collect( Collectors.toMap( LogicalNamespace::getName, s -> s.dataModel.name() ) ); String[][] data = names.entrySet().stream().map( n -> new String[]{ n.getKey(), n.getValue() } ).toArray( String[][]::new ); ctx.json( RelationalResult diff --git a/webui/src/main/java/org/polypheny/db/webui/models/Namespace.java b/webui/src/main/java/org/polypheny/db/webui/models/Namespace.java index e1c13c13d6..2162094c4d 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/Namespace.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/Namespace.java @@ -22,7 +22,7 @@ import lombok.Getter; import lombok.Value; import lombok.experimental.NonFinal; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; /** @@ -35,7 +35,7 @@ public class Namespace { @JsonProperty String name; @JsonProperty - NamespaceType type; + DataModel type; @JsonProperty String store; @@ -64,12 +64,12 @@ public class Namespace { */ public Namespace( @JsonProperty("name") String name, - @JsonProperty("type") final NamespaceType type, + @JsonProperty("type") final DataModel type, @JsonProperty("store") @Nullable final String store ) { this.name = name; this.type = type; - if ( type == NamespaceType.GRAPH ) { + if ( type == DataModel.GRAPH ) { assert store != null; this.store = store; } else { diff --git a/webui/src/main/java/org/polypheny/db/webui/models/SidebarElement.java b/webui/src/main/java/org/polypheny/db/webui/models/SidebarElement.java index 97c141a44e..b9bd2e6529 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/SidebarElement.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/SidebarElement.java @@ -21,7 +21,7 @@ import java.util.List; import lombok.Setter; import lombok.experimental.Accessors; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; /** @@ -31,7 +31,7 @@ @Accessors(chain = true) public class SidebarElement { - private final NamespaceType namespaceType; + private final DataModel dataModel; private String id; private String name; @Setter @@ -49,14 +49,14 @@ public class SidebarElement { * * @param id unique id for the SidebarElement, e.g. of the form "schemaName.tableName.columnName" * @param name the name of the SidebarElement that will be displayed in the UI - * @param namespaceType the schema type of the sidebar element, this is nullable for non-database elements + * @param dataModel the schema type of the sidebar element, this is nullable for non-database elements * @param routerLinkRoot routerLink to the view where the Sidebar is displayed. When clicking on a SidebarElement, the user will be directed to the page "routerLinkRoot/id" (id of the SidebarElement) * @param icon class name of the icon that will be displayed left of the id, e.g. "fa fa-table" */ - public SidebarElement( final String id, final String name, NamespaceType namespaceType, final String routerLinkRoot, String icon ) { + public SidebarElement( final String id, final String name, DataModel dataModel, final String routerLinkRoot, String icon ) { this.id = id; this.name = name; - this.namespaceType = namespaceType; + this.dataModel = dataModel; if ( !routerLinkRoot.isEmpty() ) { this.routerLink = routerLinkRoot + id; } else { diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/requests/NamespaceRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/requests/NamespaceRequest.java index 049468e058..1d3a467a6f 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/catalog/requests/NamespaceRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/requests/NamespaceRequest.java @@ -18,12 +18,12 @@ import java.util.List; import lombok.AllArgsConstructor; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; @AllArgsConstructor public class NamespaceRequest { - public List namespaceTypes; + public List dataModels; public String pattern; diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/CollectionModel.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/CollectionModel.java index 7efde351cb..117dc80a68 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/CollectionModel.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/CollectionModel.java @@ -18,19 +18,19 @@ import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalCollection; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; public class CollectionModel extends EntityModel { - public CollectionModel( @Nullable Long id, @Nullable String name, Long namespaceId, boolean modifiable, NamespaceType namespaceType, EntityType entityType ) { - super( id, name, namespaceId, modifiable, namespaceType, entityType ); + public CollectionModel( @Nullable Long id, @Nullable String name, Long namespaceId, boolean modifiable, DataModel dataModel, EntityType entityType ) { + super( id, name, namespaceId, modifiable, dataModel, entityType ); } public static CollectionModel from( LogicalCollection collection ) { - return new CollectionModel( collection.id, collection.name, collection.namespaceId, collection.modifiable, collection.namespaceType, collection.entityType ); + return new CollectionModel( collection.id, collection.name, collection.namespaceId, collection.modifiable, collection.dataModel, collection.entityType ); } } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/EntityModel.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/EntityModel.java index 7c8f9ac615..6c3e4c1531 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/EntityModel.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/EntityModel.java @@ -18,14 +18,14 @@ import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalEntity; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; import org.polypheny.db.webui.models.catalog.IdEntity; public class EntityModel extends IdEntity { - public final NamespaceType namespaceType; + public final DataModel dataModel; public final EntityType entityType; @@ -34,17 +34,17 @@ public class EntityModel extends IdEntity { public final boolean modifiable; - public EntityModel( @Nullable Long id, @Nullable String name, @Nullable Long namespaceId, boolean modifiable, NamespaceType namespaceType, EntityType entityType ) { + public EntityModel( @Nullable Long id, @Nullable String name, @Nullable Long namespaceId, boolean modifiable, DataModel dataModel, EntityType entityType ) { super( id, name ); this.namespaceId = namespaceId; - this.namespaceType = namespaceType; + this.dataModel = dataModel; this.entityType = entityType; this.modifiable = modifiable; } public static EntityModel from( LogicalEntity entity ) { - return new EntityModel( entity.id, entity.name, entity.namespaceId, entity.modifiable, entity.namespaceType, entity.entityType ); + return new EntityModel( entity.id, entity.name, entity.namespaceId, entity.modifiable, entity.dataModel, entity.entityType ); } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/GraphModel.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/GraphModel.java index 85d82ffe2e..09685ffe94 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/GraphModel.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/GraphModel.java @@ -18,18 +18,18 @@ import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalGraph; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; public class GraphModel extends EntityModel { - public GraphModel( @Nullable Long id, @Nullable String name, Long namespaceId, boolean modifiable, NamespaceType namespaceType, EntityType entityType ) { - super( id, name, namespaceId, modifiable, namespaceType, entityType ); + public GraphModel( @Nullable Long id, @Nullable String name, Long namespaceId, boolean modifiable, DataModel dataModel, EntityType entityType ) { + super( id, name, namespaceId, modifiable, dataModel, entityType ); } public static GraphModel from( LogicalGraph graph ) { - return new GraphModel( graph.id, graph.name, graph.namespaceId, graph.modifiable, graph.namespaceType, graph.entityType ); + return new GraphModel( graph.id, graph.name, graph.namespaceId, graph.modifiable, graph.dataModel, graph.entityType ); } } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/NamespaceModel.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/NamespaceModel.java index 8bddcbaa75..fdb4cf804c 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/NamespaceModel.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/NamespaceModel.java @@ -17,25 +17,25 @@ package org.polypheny.db.webui.models.catalog.schema; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.webui.models.catalog.IdEntity; public class NamespaceModel extends IdEntity { public final boolean caseSensitive; - public final NamespaceType namespaceType; + public final DataModel dataModel; - public NamespaceModel( long id, String name, NamespaceType type, boolean caseSensitive ) { + public NamespaceModel( long id, String name, DataModel type, boolean caseSensitive ) { super( id, name ); - this.namespaceType = type; + this.dataModel = type; this.caseSensitive = caseSensitive; } public static NamespaceModel from( LogicalNamespace namespace ) { - return new NamespaceModel( namespace.id, namespace.name, namespace.namespaceType, namespace.caseSensitive ); + return new NamespaceModel( namespace.id, namespace.name, namespace.dataModel, namespace.caseSensitive ); } } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/TableModel.java b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/TableModel.java index 50014b7070..d6190f9462 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/TableModel.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/catalog/schema/TableModel.java @@ -18,19 +18,19 @@ import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalTable; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.NamespaceType; public class TableModel extends EntityModel { - public TableModel( @Nullable Long id, @Nullable String name, Long namespaceId, boolean modifiable, NamespaceType namespaceType, EntityType entityType ) { - super( id, name, namespaceId, modifiable, namespaceType, entityType ); + public TableModel( @Nullable Long id, @Nullable String name, Long namespaceId, boolean modifiable, DataModel dataModel, EntityType entityType ) { + super( id, name, namespaceId, modifiable, dataModel, entityType ); } public static TableModel from( LogicalTable table ) { - return new TableModel( table.id, table.name, table.namespaceId, table.modifiable, table.namespaceType, table.entityType ); + return new TableModel( table.id, table.name, table.namespaceId, table.modifiable, table.dataModel, table.entityType ); } } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/requests/SchemaTreeRequest.java b/webui/src/main/java/org/polypheny/db/webui/models/requests/SchemaTreeRequest.java index 3a6cd6f020..a179388c49 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/requests/SchemaTreeRequest.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/requests/SchemaTreeRequest.java @@ -18,7 +18,7 @@ import java.util.List; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; public class SchemaTreeRequest extends UIRequest { @@ -27,7 +27,7 @@ public class SchemaTreeRequest extends UIRequest { public int depth; public boolean showTable; - public List dataModels; + public List dataModels; } 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 b37d11f881..8c2570a531 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 @@ -20,7 +20,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.SuperBuilder; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.webui.models.catalog.FieldDefinition; @@ -30,7 +30,7 @@ public class DocResult extends Result { public DocResult( - @JsonProperty("namespaceType") NamespaceType namespaceType, + @JsonProperty("dataModel") DataModel dataModel, @JsonProperty("namespace") String namespace, @JsonProperty("data") String[] data, @JsonProperty("header") FieldDefinition[] header, @@ -44,7 +44,7 @@ public DocResult( @JsonProperty("language") QueryLanguage language, @JsonProperty("affectedTuples") int affectedTuples ) { super( - namespaceType, + dataModel, namespace, data, header, diff --git a/webui/src/main/java/org/polypheny/db/webui/models/results/GraphResult.java b/webui/src/main/java/org/polypheny/db/webui/models/results/GraphResult.java index 2a81a5c983..3ea3fb7ab0 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/results/GraphResult.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/results/GraphResult.java @@ -20,7 +20,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.SuperBuilder; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.webui.models.catalog.FieldDefinition; @@ -30,7 +30,7 @@ public class GraphResult extends Result { public GraphResult( - @JsonProperty("namespaceType") NamespaceType namespaceType, + @JsonProperty("dataModel") DataModel dataModel, @JsonProperty("namespace") String namespace, @JsonProperty("data") String[][] data, @JsonProperty("header") FieldDefinition[] header, @@ -43,7 +43,7 @@ public GraphResult( @JsonProperty("hasMore") boolean hasMore, @JsonProperty("language") QueryLanguage language, @JsonProperty("affectedTuples") int affectedTuples ) { - super( namespaceType, namespace, data, header, exception, query, xid, error, currentPage, highestPage, hasMore, language, affectedTuples ); + super( dataModel, namespace, data, header, exception, query, xid, error, currentPage, highestPage, hasMore, language, affectedTuples ); } public static abstract class GraphResultBuilder> extends ResultBuilder { 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 34358767e6..ee8b3a2a24 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 @@ -24,7 +24,7 @@ import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.QueryLanguage; import org.polypheny.db.webui.HttpServer; import org.polypheny.db.webui.models.catalog.UiColumnDefinition; @@ -61,7 +61,7 @@ public class RelationalResult extends Result { @JsonCreator public RelationalResult( - @JsonProperty("namespaceType") NamespaceType namespaceType, + @JsonProperty("dataModel") DataModel dataModel, @JsonProperty("namespace") String namespace, @JsonProperty("data") String[][] data, @JsonProperty("UiColumnDefinition") UiColumnDefinition[] header, @@ -78,7 +78,7 @@ public RelationalResult( @JsonProperty("ResultType") ResultType type, @JsonProperty("hasMoreRows") boolean hasMore, @JsonProperty("language") QueryLanguage language ) { - super( namespaceType, namespace, data, header, exception, query, xid, error, currentPage, highestPage, hasMore, language, affectedTuples ); + super( dataModel, 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 540f164808..5ca6c097f8 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 @@ -31,7 +31,7 @@ import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; -import org.polypheny.db.catalog.logistic.NamespaceType; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.languages.QueryLanguage; @@ -44,7 +44,7 @@ public abstract class Result { /** * namespace type of result DOCUMENT/RELATIONAL */ - public NamespaceType namespaceType; + public DataModel dataModel; public String namespace; @@ -103,7 +103,7 @@ public static abstract class ResultBuilder, B exten */ protected B $fillValuesFrom( C instance ) { this.data = instance.data; - this.namespaceType = instance.namespaceType; + this.dataModel = instance.dataModel; this.xid = instance.xid; this.error = instance.error; this.namespace = instance.namespace; From b5c21ccb2f46092e8aa86f30a09366bb590b48ae Mon Sep 17 00:00:00 2001 From: datomo Date: Mon, 27 Nov 2023 11:03:59 +0100 Subject: [PATCH 10/15] fix for MonetdbStore --- .../util/{PolyphenyMode.java => PolyMode.java} | 2 +- .../db/util/PolyphenyHomeDirManager.java | 4 ++-- .../db/algebra/enumerable/EnumerableScan.java | 4 ++-- .../java/org/polypheny/db/catalog/Catalog.java | 4 ++-- .../polypheny/db/docker/DockerContainer.java | 4 ++-- .../org/polypheny/db/docker/DockerManager.java | 4 ++-- .../db/adapter/index/CowHashIndexTest.java | 4 ++-- .../org/polypheny/db/rex/RexBuilderTest.java | 4 ++-- .../java/org/polypheny/db/PolyphenyDb.java | 18 +++++++++--------- ...sConverter.java => PolyModesConverter.java} | 16 ++++++++-------- .../test/java/org/polypheny/db/TestHelper.java | 4 ++-- .../adapter/monetdb/stores/MonetdbStore.java | 2 +- .../java/org/polypheny/db/sql/PlannerTest.java | 4 ++-- .../polypheny/db/sql/util/PlannerImplMock.java | 4 ++-- .../polypheny/db/webui/crud/LanguageCrud.java | 4 ++-- 15 files changed, 41 insertions(+), 41 deletions(-) rename config/src/main/java/org/polypheny/db/util/{PolyphenyMode.java => PolyMode.java} (96%) rename dbms/src/main/java/org/polypheny/db/cli/{PolyphenyModesConverter.java => PolyModesConverter.java} (77%) diff --git a/config/src/main/java/org/polypheny/db/util/PolyphenyMode.java b/config/src/main/java/org/polypheny/db/util/PolyMode.java similarity index 96% rename from config/src/main/java/org/polypheny/db/util/PolyphenyMode.java rename to config/src/main/java/org/polypheny/db/util/PolyMode.java index 8c79512f80..3f01c0583a 100644 --- a/config/src/main/java/org/polypheny/db/util/PolyphenyMode.java +++ b/config/src/main/java/org/polypheny/db/util/PolyMode.java @@ -16,7 +16,7 @@ package org.polypheny.db.util; -public enum PolyphenyMode { +public enum PolyMode { PRODUCTION, DEVELOPMENT, TEST, diff --git a/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java b/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java index 27b77e12e7..6b03ebf649 100644 --- a/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java +++ b/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java @@ -39,7 +39,7 @@ public class PolyphenyHomeDirManager { private File root; private final List dirs = new ArrayList<>(); private final List deleteOnExit = new ArrayList<>(); - private static PolyphenyMode mode; + private static PolyMode mode; public static PolyphenyHomeDirManager getInstance() { @@ -77,7 +77,7 @@ private PolyphenyHomeDirManager() { } - public static PolyphenyHomeDirManager setModeAndGetInstance( PolyphenyMode mode ) { + public static PolyphenyHomeDirManager setModeAndGetInstance( PolyMode mode ) { if ( PolyphenyHomeDirManager.mode != null ) { throw new RuntimeException( "Could not set the mode." ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java index a66abebddd..7e9a0f8043 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java @@ -52,7 +52,7 @@ import org.polypheny.db.schema.types.ScannableEntity; import org.polypheny.db.schema.types.StreamableEntity; import org.polypheny.db.util.BuiltInMethod; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; /** @@ -256,7 +256,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { @Override public AlgOptCost computeSelfCost( AlgOptPlanner planner, AlgMetadataQuery mq ) { - if ( Catalog.mode == PolyphenyMode.TEST ) { + if ( Catalog.mode == PolyMode.TEST ) { // normally this enumerable is not used by Polypheny and is therefore "removed" by an infinite cost, // but theoretically it is able to handle scans on the application layer // this is tested by different instances and should then lead to a finite selfCost diff --git a/core/src/main/java/org/polypheny/db/catalog/Catalog.java b/core/src/main/java/org/polypheny/db/catalog/Catalog.java index 639a40cb48..bf35749b58 100644 --- a/core/src/main/java/org/polypheny/db/catalog/Catalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/Catalog.java @@ -48,7 +48,7 @@ import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.iface.QueryInterfaceManager.QueryInterfaceTemplate; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; public abstract class Catalog implements ExtensionPoint { @@ -69,7 +69,7 @@ public abstract class Catalog implements ExtensionPoint { private static Catalog INSTANCE = null; public static boolean resetCatalog; public static boolean memoryCatalog; - public static PolyphenyMode mode; + public static PolyMode mode; public static final Expression CATALOG_EXPRESSION = Expressions.call( Catalog.class, "getInstance" ); diff --git a/core/src/main/java/org/polypheny/db/docker/DockerContainer.java b/core/src/main/java/org/polypheny/db/docker/DockerContainer.java index 5146869c84..d3c6cb31fe 100644 --- a/core/src/main/java/org/polypheny/db/docker/DockerContainer.java +++ b/core/src/main/java/org/polypheny/db/docker/DockerContainer.java @@ -41,7 +41,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; /** * The container is the main interaction instance for calling classes when interacting with Docker. @@ -127,7 +127,7 @@ public int execute( List cmd ) throws IOException { public static String getPhysicalUniqueName( String uniqueName ) { // while not all Docker containers belong to an adapter we annotate it anyway String name = "polypheny_" + RuntimeConfig.INSTANCE_UUID.getString() + "_" + uniqueName; - if ( Catalog.mode != PolyphenyMode.TEST ) { + if ( Catalog.mode != PolyMode.TEST ) { return name; } return name + "_test"; diff --git a/core/src/main/java/org/polypheny/db/docker/DockerManager.java b/core/src/main/java/org/polypheny/db/docker/DockerManager.java index 44a6e6cbd7..29b1ef183d 100644 --- a/core/src/main/java/org/polypheny/db/docker/DockerManager.java +++ b/core/src/main/java/org/polypheny/db/docker/DockerManager.java @@ -32,7 +32,7 @@ import org.polypheny.db.config.ConfigDocker; import org.polypheny.db.config.ConfigManager; import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; public final class DockerManager { @@ -53,7 +53,7 @@ public static DockerManager getInstance() { public Optional getInstanceById( int instanceId ) { // Tests expect a localhost docker instance with id 0 - if ( Catalog.mode == PolyphenyMode.TEST && instanceId == 0 ) { + if ( Catalog.mode == PolyMode.TEST && instanceId == 0 ) { return dockerInstances.values().stream().filter( d -> d.getHost().equals( "localhost" ) ).findFirst(); } return Optional.ofNullable( dockerInstances.get( instanceId ) ); diff --git a/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java b/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java index 92c5efe631..3f1037a010 100644 --- a/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java +++ b/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java @@ -31,15 +31,15 @@ import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Pair; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.util.PolyphenyHomeDirManager; -import org.polypheny.db.util.PolyphenyMode; public class CowHashIndexTest { @BeforeClass public static void init() { - PolyphenyHomeDirManager.setModeAndGetInstance( PolyphenyMode.TEST ); + PolyphenyHomeDirManager.setModeAndGetInstance( PolyMode.TEST ); } @Test diff --git a/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java b/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java index 2a81f8e004..db16823316 100644 --- a/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java +++ b/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java @@ -56,8 +56,8 @@ import org.polypheny.db.util.Collation; import org.polypheny.db.util.DateString; import org.polypheny.db.util.NlsString; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.util.PolyphenyHomeDirManager; -import org.polypheny.db.util.PolyphenyMode; import org.polypheny.db.util.TimeString; import org.polypheny.db.util.TimestampString; import org.polypheny.db.util.TimestampWithTimeZoneString; @@ -72,7 +72,7 @@ public class RexBuilderTest { @BeforeClass public static void init() { try { - PolyphenyHomeDirManager.setModeAndGetInstance( PolyphenyMode.TEST ); + PolyphenyHomeDirManager.setModeAndGetInstance( PolyMode.TEST ); } catch ( Exception e ) { // can fail } diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index 8c078772c7..f820cb2d53 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -80,8 +80,8 @@ import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.transaction.TransactionManagerImpl; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.util.PolyphenyHomeDirManager; -import org.polypheny.db.util.PolyphenyMode; import org.polypheny.db.view.MaterializedViewManager; import org.polypheny.db.view.MaterializedViewManagerImpl; import org.polypheny.db.webui.ConfigService; @@ -115,7 +115,7 @@ public class PolyphenyDb { public boolean memoryCatalog = false; @Option(name = { "-mode" }, description = "Special system configuration for running tests", typeConverterProvider = PolyModesConverter.class) - public PolyphenyMode mode = PolyphenyMode.PRODUCTION; + public PolyMode mode = PolyMode.PRODUCTION; @Option(name = { "-gui" }, description = "Show splash screen on startup and add taskbar gui") public boolean desktopMode = false; @@ -184,7 +184,7 @@ public void runPolyphenyDb() { } // Configuration shall not be persisted - ConfigManager.memoryMode = (mode == PolyphenyMode.TEST || memoryCatalog); + ConfigManager.memoryMode = (mode == PolyMode.TEST || memoryCatalog); ConfigManager.resetCatalogOnStartup = resetCatalog; // Select behavior depending on arguments @@ -241,7 +241,7 @@ public void runPolyphenyDb() { } // Backup content of Polypheny folder - if ( mode == PolyphenyMode.TEST || memoryCatalog ) { + if ( mode == PolyMode.TEST || memoryCatalog ) { if ( dirManager.checkIfExists( "_test_backup" ) ) { throw new GenericRuntimeException( "Unable to backup the Polypheny folder since there is already a backup folder." ); } @@ -287,7 +287,7 @@ public void runPolyphenyDb() { } } - if ( mode == PolyphenyMode.TEST ) { + if ( mode == PolyMode.TEST ) { uuid = "polypheny-test"; } @@ -410,7 +410,7 @@ public void join( final long millis ) throws InterruptedException { DdlManager.setAndGetInstance( new DdlManagerImpl( catalog ) ); // Add config and monitoring test page for UI testing - if ( mode == PolyphenyMode.TEST ) { + if ( mode == PolyMode.TEST ) { new UiTestingConfigPage(); new UiTestingMonitoringPage(); } @@ -473,12 +473,12 @@ public void join( final long millis ) throws InterruptedException { private boolean initializeDockerManager() { if ( AutoDocker.getInstance().isAvailable() ) { - if ( mode == PolyphenyMode.TEST ) { + if ( mode == PolyMode.TEST ) { resetDocker = true; Catalog.resetDocker = true; } boolean success = AutoDocker.getInstance().doAutoConnect(); - if ( mode == PolyphenyMode.TEST && !success ) { + if ( mode == PolyMode.TEST && !success ) { // AutoDocker does not work in Windows containers if ( !System.getenv( "RUNNER_OS" ).equals( "Windows" ) ) { log.error( "Failed to connect to docker instance" ); @@ -559,7 +559,7 @@ private Catalog startCatalog() { private void restore( Authenticator authenticator, Catalog catalog ) { PolyPluginManager.startUp( transactionManager, authenticator ); - if ( !resetCatalog && mode != PolyphenyMode.TEST ) { + if ( !resetCatalog && mode != PolyMode.TEST ) { Catalog.getInstance().restore(); } Catalog.getInstance().updateSnapshot(); diff --git a/dbms/src/main/java/org/polypheny/db/cli/PolyphenyModesConverter.java b/dbms/src/main/java/org/polypheny/db/cli/PolyModesConverter.java similarity index 77% rename from dbms/src/main/java/org/polypheny/db/cli/PolyphenyModesConverter.java rename to dbms/src/main/java/org/polypheny/db/cli/PolyModesConverter.java index 7572f9750a..8f1e6671fa 100644 --- a/dbms/src/main/java/org/polypheny/db/cli/PolyphenyModesConverter.java +++ b/dbms/src/main/java/org/polypheny/db/cli/PolyModesConverter.java @@ -23,10 +23,10 @@ import com.github.rvesse.airline.types.TypeConverter; import java.util.Arrays; import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; @Slf4j -public class PolyphenyModesConverter extends DefaultTypeConverter { +public class PolyModesConverter extends DefaultTypeConverter { @Override public TypeConverter getTypeConverter( OptionMetadata option, ParseState state ) { @@ -44,22 +44,22 @@ public TypeConverter getTypeConverter( ArgumentsMetadata arguments, ParseSta public Object convert( String name, Class type, String value ) { String adjustedName = value.toUpperCase(); - if ( Arrays.stream( PolyphenyMode.values() ).anyMatch( v -> v.name().equals( adjustedName ) ) ) { - return PolyphenyMode.valueOf( adjustedName.toUpperCase() ); + if ( Arrays.stream( PolyMode.values() ).anyMatch( v -> v.name().equals( adjustedName ) ) ) { + return PolyMode.valueOf( adjustedName.toUpperCase() ); } switch ( adjustedName.toLowerCase() ) { case "t": - return PolyphenyMode.TEST; + return PolyMode.TEST; case "b": case "bench": - return PolyphenyMode.BENCHMARK; + return PolyMode.BENCHMARK; case "d": case "dev": - return PolyphenyMode.DEVELOPMENT; + return PolyMode.DEVELOPMENT; } log.warn( "Could not find the mode: " + adjustedName ); - return PolyphenyMode.PRODUCTION; + return PolyMode.PRODUCTION; } } diff --git a/dbms/src/test/java/org/polypheny/db/TestHelper.java b/dbms/src/test/java/org/polypheny/db/TestHelper.java index f1c02eabaf..0b56964a37 100644 --- a/dbms/src/test/java/org/polypheny/db/TestHelper.java +++ b/dbms/src/test/java/org/polypheny/db/TestHelper.java @@ -67,7 +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.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.webui.HttpServer; import org.polypheny.db.webui.models.results.DocResult; import org.polypheny.db.webui.models.results.GraphResult; @@ -95,7 +95,7 @@ private TestHelper() { log.info( "Starting Polypheny-DB..." ); Runnable runnable = () -> { - polyphenyDb.mode = PolyphenyMode.TEST; + polyphenyDb.mode = PolyMode.TEST; String defaultStoreName = System.getProperty( "storeId.default" ); if ( defaultStoreName != null ) { polyphenyDb.defaultStoreName = defaultStoreName; diff --git a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java index da9d23287d..1a9fb5ad1c 100644 --- a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java +++ b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/stores/MonetdbStore.java @@ -341,7 +341,7 @@ protected String getTypeString( PolyType type ) { @Override public String getDefaultPhysicalNamespaceName() { - return "public" + getAdapterId(); + return "public"; } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java index 3b11372f2b..606282fc63 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/PlannerTest.java @@ -115,7 +115,7 @@ import org.polypheny.db.type.checker.OperandTypes; import org.polypheny.db.type.inference.ReturnTypes; import org.polypheny.db.util.Optionality; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.util.Util; @@ -125,7 +125,7 @@ public class PlannerTest extends SqlLanguageDependent { static { - Catalog.mode = PolyphenyMode.TEST; + Catalog.mode = PolyMode.TEST; } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java index d886e2cbd7..34e2318660 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/util/PlannerImplMock.java @@ -59,7 +59,7 @@ import org.polypheny.db.tools.Program; import org.polypheny.db.tools.ValidationException; import org.polypheny.db.util.Conformance; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.util.SourceStringReader; @@ -69,7 +69,7 @@ public class PlannerImplMock implements Planner { static { - Catalog.mode = PolyphenyMode.TEST; + Catalog.mode = PolyMode.TEST; } 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 6d17fa23b9..efe8c4ab47 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 @@ -66,7 +66,7 @@ import org.polypheny.db.type.PolyType; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.type.entity.graph.PolyGraph; -import org.polypheny.db.util.PolyphenyMode; +import org.polypheny.db.util.PolyMode; import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.TemporalFileManager; import org.polypheny.db.webui.models.IndexModel; @@ -399,7 +399,7 @@ public static List computeResultData( final List> rows private static String toJson( @Nullable PolyValue src ) { return src == null ? null - : Catalog.mode == PolyphenyMode.TEST ? src.toTypedJson() : src.toJson(); + : Catalog.mode == PolyMode.TEST ? src.toTypedJson() : src.toJson(); } From 6bc401aada3cd4e6117ebffb61be4d4ecdf98ada Mon Sep 17 00:00:00 2001 From: datomo Date: Mon, 27 Nov 2023 14:03:22 +0100 Subject: [PATCH 11/15] multiple renamings, adjustment to mongodb store --- .../org/polypheny/db/adapter/Modifiable.java | 18 +-- .../db/adapter/java/ReflectiveSchema.java | 151 +----------------- .../polypheny/db/algebra/AbstractAlgNode.java | 4 +- .../org/polypheny/db/algebra/AlgInput.java | 4 +- .../org/polypheny/db/algebra/AlgNode.java | 4 +- .../db/algebra/core/AlgFactories.java | 6 +- .../db/algebra/core/common/Modify.java | 4 +- .../db/algebra/core/common/Scan.java | 4 +- .../algebra/core/document/DocumentModify.java | 4 +- .../algebra/core/document/DocumentScan.java | 4 +- .../algebra/core/document/DocumentValues.java | 4 +- .../db/algebra/core/lpg/LpgModify.java | 4 +- .../db/algebra/core/lpg/LpgScan.java | 4 +- .../db/algebra/core/relational/RelModify.java | 4 +- .../db/algebra/core/relational/RelScan.java | 6 +- .../relational/RelationalTransformable.java | 6 +- .../db/algebra/enumerable/EnumerableScan.java | 6 +- .../db/algebra/externalize/AlgJsonReader.java | 4 +- .../logical/common/LogicalStreamer.java | 4 +- .../document/LogicalDocumentModify.java | 10 +- .../logical/document/LogicalDocumentScan.java | 10 +- .../algebra/logical/lpg/LogicalLpgModify.java | 8 +- .../algebra/logical/lpg/LogicalLpgScan.java | 8 +- .../algebra/logical/lpg/LogicalLpgValues.java | 4 +- .../logical/relational/LogicalRelModify.java | 10 +- .../logical/relational/LogicalRelScan.java | 8 +- .../relational/LogicalRelViewScan.java | 8 +- .../db/algebra/metadata/AlgColumnOrigin.java | 8 +- .../db/algebra/metadata/AlgMdCollation.java | 4 +- .../algebra/metadata/AlgMdColumnOrigins.java | 4 +- .../metadata/AlgMdColumnUniqueness.java | 7 +- .../algebra/metadata/AlgMdDistribution.java | 4 +- .../db/algebra/metadata/AlgMetadataQuery.java | 4 +- .../algebra/mutable/MutableTableModify.java | 8 +- .../algebra/rules/LoptOptimizeJoinRule.java | 16 +- .../algebra/rules/LoptSemiJoinOptimizer.java | 8 +- .../{LogicalEntity.java => Entity.java} | 10 +- .../db/catalog/entity/LogicalAdapter.java | 2 +- .../db/catalog/entity/LogicalDatabase.java | 79 --------- .../catalog/entity/LogicalQueryInterface.java | 2 +- .../db/catalog/entity/LogicalUser.java | 2 +- .../{LogicalObject.java => PolyObject.java} | 2 +- .../entity/allocation/AllocationColumn.java | 4 +- .../entity/allocation/AllocationEntity.java | 4 +- .../allocation/AllocationPartition.java | 4 +- .../allocation/AllocationPartitionGroup.java | 4 +- .../allocation/AllocationPlacement.java | 4 +- .../entity/logical/LogicalCollection.java | 4 +- .../catalog/entity/logical/LogicalColumn.java | 6 +- .../catalog/entity/logical/LogicalEntity.java | 3 +- .../entity/logical/LogicalForeignKey.java | 4 +- .../catalog/entity/logical/LogicalIndex.java | 4 +- .../db/catalog/entity/logical/LogicalKey.java | 4 +- .../entity/logical/LogicalNamespace.java | 6 +- .../entity/logical/LogicalPrimaryKey.java | 4 +- .../entity/physical/PhysicalEntity.java | 4 +- .../entity/physical/PhysicalField.java | 4 +- .../snapshot/impl/LogicalRelSnapshotImpl.java | 8 + .../polypheny/db/interpreter/Bindables.java | 14 +- .../org/polypheny/db/plan/AlgOptUtil.java | 8 +- .../polypheny/db/plan/hep/HepAlgVertex.java | 2 +- .../org/polypheny/db/plan/hep/HepPlanner.java | 64 ++++---- .../processing/LogicalAlgAnalyzeShuttle.java | 14 +- .../polypheny/db/rex/RexTableIndexRef.java | 8 +- .../org/polypheny/db/schema/Namespace.java | 4 +- .../schema/impl/AbstractEntityQueryable.java | 4 +- .../db/schema/impl/AbstractNamespace.java | 6 +- .../db/schema/impl/DelegatingNamespace.java | 4 +- .../db/schema/types/ModifiableCollection.java | 4 +- .../db/schema/types/ModifiableGraph.java | 4 +- .../db/schema/types/ModifiableTable.java | 4 +- .../org/polypheny/db/tools/AlgBuilder.java | 8 +- .../db/util/InitializerExpressionFactory.java | 6 +- .../NullInitializerExpressionFactory.java | 6 +- .../main/java/org/polypheny/db/util/Util.java | 4 +- .../polypheny/db/catalog/CountingFactory.java | 6 +- .../EmpInitializerExpressionFactory.java | 6 +- .../db/schemas/HrClusteredSchema.java | 6 +- .../java/org/polypheny/db/test/JdbcTest.java | 4 +- .../java/org/polypheny/db/PolyphenyDb.java | 2 +- .../db/processing/AbstractQueryProcessor.java | 4 +- .../db/routing/routers/BaseRouter.java | 6 +- .../db/transaction/EntityAccessMap.java | 6 +- .../db/monitoring/statistics/QueryResult.java | 6 +- .../org/polypheny/db/avatica/DbmsMeta.java | 107 ++++++------- ...nHandle.java => PolyConnectionHandle.java} | 27 +--- ...enyDbResultSet.java => PolyResultSet.java} | 6 +- .../db/avatica/PolyStatementHandle.java | 4 +- .../db/avatica/PrimitiveDatabase.java | 28 ++++ .../adapter/cottontail/CottontailEntity.java | 4 +- .../cottontail/CottontailNamespace.java | 4 +- .../db/adapter/file/FileStoreSchema.java | 4 +- .../adapter/file/FileTranslatableEntity.java | 4 +- .../db/adapter/file/algebra/FileScan.java | 4 +- .../polypheny/db/adapter/jdbc/JdbcSchema.java | 4 +- .../polypheny/db/adapter/jdbc/JdbcTable.java | 4 +- .../db/adapter/jdbc/alg2sql/PlannerTest.java | 4 +- .../db/adapter/mongodb/MongoAlg.java | 35 ++-- .../db/adapter/mongodb/MongoEntity.java | 6 +- .../db/adapter/mongodb/MongoNamespace.java | 9 +- .../mongodb/rules/MongoDocumentModify.java | 3 +- .../adapter/mongodb/rules/MongoProject.java | 7 +- .../db/adapter/mongodb/rules/MongoRules.java | 4 +- .../db/adapter/mongodb/rules/MongoScan.java | 4 +- .../mongodb/rules/MongoTableModify.java | 43 +++-- .../rules/MongoToEnumerableConverter.java | 4 +- .../languages/mql2alg/MqlToAlgConverter.java | 16 +- .../polypheny/db/adapter/neo4j/NeoEntity.java | 6 +- .../polypheny/db/adapter/neo4j/NeoGraph.java | 6 +- .../db/adapter/neo4j/NeoNamespace.java | 4 +- .../polypheny/db/sql/language/SqlUtil.java | 4 +- .../language/validate/AbstractNamespace.java | 4 +- .../validate/DelegatingNamespace.java | 4 +- .../language/validate/DelegatingScope.java | 7 +- .../db/sql/language/validate/EmptyScope.java | 4 +- .../language/validate/EntityNamespace.java | 15 +- .../validate/IdentifierNamespace.java | 12 +- .../db/sql/language/validate/ListScope.java | 4 +- .../language/validate/SqlValidatorImpl.java | 33 ++-- .../validate/SqlValidatorNamespace.java | 4 +- .../language/validate/SqlValidatorUtil.java | 15 +- .../language/validate/UnnestNamespace.java | 4 +- .../db/sql/language/validate/WithScope.java | 6 +- .../db/sql/sql2alg/SqlToAlgConverter.java | 33 ++-- .../SqlToRelConverterExtendedTest.java | 4 +- 125 files changed, 524 insertions(+), 732 deletions(-) rename core/src/main/java/org/polypheny/db/catalog/entity/{LogicalEntity.java => Entity.java} (93%) delete mode 100644 core/src/main/java/org/polypheny/db/catalog/entity/LogicalDatabase.java rename core/src/main/java/org/polypheny/db/catalog/entity/{LogicalObject.java => PolyObject.java} (95%) rename plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/{PolyphenyDbConnectionHandle.java => PolyConnectionHandle.java} (73%) rename plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/{PolyphenyDbResultSet.java => PolyResultSet.java} (91%) create mode 100644 plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PrimitiveDatabase.java 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 69134b8b62..90d5ffc526 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java @@ -46,7 +46,7 @@ import org.polypheny.db.algebra.type.DocumentType; import org.polypheny.db.algebra.type.GraphType; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.allocation.AllocationCollection; import org.polypheny.db.catalog.entity.allocation.AllocationGraph; import org.polypheny.db.catalog.entity.allocation.AllocationTable; @@ -73,7 +73,7 @@ public interface Modifiable extends Scannable { - static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder builder, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable ) { + static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder builder, Entity nodesTable, Entity nodePropertiesTable, Entity edgesTable, Entity edgePropertiesTable ) { AlgNode project = new LogicalLpgProject( alg.getCluster(), alg.getTraitSet(), alg.getInput(), alg.operations, alg.ids ); List inputs = new ArrayList<>(); @@ -96,7 +96,7 @@ static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provi } - static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable ) { + static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, Entity nodesTable, Entity nodePropertiesTable, Entity edgesTable, Entity edgePropertiesTable ) { AlgNode project = new LogicalLpgProject( alg.getCluster(), alg.getTraitSet(), alg.getInput(), alg.operations, alg.ids ); List inputs = new ArrayList<>(); @@ -117,7 +117,7 @@ static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provi } - static List attachPreparedGraphNodeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, AlgBuilder algBuilder ) { + static List attachPreparedGraphNodeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, Entity nodesTable, Entity nodePropertiesTable, AlgBuilder algBuilder ) { RexBuilder rexBuilder = algBuilder.getRexBuilder(); AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); @@ -146,7 +146,7 @@ static List attachPreparedGraphNodeModifyDelete( Modifiable modifiable, return inputs; } - static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable ) { + static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, Entity nodesTable, Entity nodePropertiesTable, Entity edgesTable, Entity edgePropertiesTable ) { List inputs = new ArrayList<>(); List sequence = new ArrayList<>(); @@ -165,7 +165,7 @@ static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode pro return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), provider, transformer ); } - static List attachPreparedGraphNodeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, AlgBuilder algBuilder ) { + static List attachPreparedGraphNodeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, Entity nodesTable, Entity nodePropertiesTable, AlgBuilder algBuilder ) { RexBuilder rexBuilder = algBuilder.getRexBuilder(); AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); @@ -192,7 +192,7 @@ static List attachPreparedGraphNodeModifyInsert( Modifiable modifiable, return inputs; } - static List attachPreparedGraphEdgeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable, AlgBuilder algBuilder ) { + static List attachPreparedGraphEdgeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, Entity edgesTable, Entity edgePropertiesTable, AlgBuilder algBuilder ) { RexBuilder rexBuilder = algBuilder.getRexBuilder(); AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); @@ -218,7 +218,7 @@ static List attachPreparedGraphEdgeModifyDelete( Modifiable modifiable, return inputs; } - static List attachPreparedGraphEdgeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable, AlgBuilder algBuilder ) { + static List attachPreparedGraphEdgeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, Entity edgesTable, Entity edgePropertiesTable, AlgBuilder algBuilder ) { RexBuilder rexBuilder = algBuilder.getRexBuilder(); AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); @@ -248,7 +248,7 @@ static List attachPreparedGraphEdgeModifyInsert( Modifiable modifiable, } - static Modify getModify( LogicalEntity table, AlgNode input, Operation operation, List updateList, List sourceList ) { + static Modify getModify( Entity table, AlgNode input, Operation operation, List updateList, List sourceList ) { return table.unwrap( ModifiableTable.class ).toModificationTable( input.getCluster(), input.getTraitSet(), table, input, operation, updateList, sourceList ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/java/ReflectiveSchema.java b/core/src/main/java/org/polypheny/db/adapter/java/ReflectiveSchema.java index 8f07b79c29..52533b4a1f 100644 --- a/core/src/main/java/org/polypheny/db/adapter/java/ReflectiveSchema.java +++ b/core/src/main/java/org/polypheny/db/adapter/java/ReflectiveSchema.java @@ -43,31 +43,19 @@ import java.lang.reflect.Type; import java.util.List; import java.util.Map; -import lombok.extern.slf4j.Slf4j; import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.linq4j.Linq4j; -import org.apache.calcite.linq4j.function.Function1; import org.apache.calcite.linq4j.tree.Primitive; -import org.apache.commons.lang3.NotImplementedException; -import org.polypheny.db.adapter.DataContext; import org.polypheny.db.algebra.AlgReferentialConstraint; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.LogicalEntity; -import org.polypheny.db.catalog.entity.logical.LogicalTable; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; -import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.schema.Function; import org.polypheny.db.schema.Namespace; import org.polypheny.db.schema.Namespace.Schema; -import org.polypheny.db.schema.Statistic; -import org.polypheny.db.schema.Statistics; import org.polypheny.db.schema.TableMacro; import org.polypheny.db.schema.impl.AbstractNamespace; import org.polypheny.db.schema.impl.ReflectiveFunctionBase; -import org.polypheny.db.schema.types.ScannableEntity; import org.polypheny.db.schema.types.TranslatableEntity; -import org.polypheny.db.type.entity.PolyValue; /** @@ -77,7 +65,7 @@ public class ReflectiveSchema extends AbstractNamespace implements Schema { private final Class clazz; private Object target; - private Map tableMap; + private Map tableMap; private Multimap functionMap; @@ -111,7 +99,7 @@ public Object getTarget() { @Override - public Map getTables() { + public Map getTables() { if ( tableMap == null ) { tableMap = createTableMap(); } @@ -119,17 +107,17 @@ public Map getTables() { } - private Map createTableMap() { - final ImmutableMap.Builder builder = ImmutableMap.builder(); + private Map createTableMap() { + final ImmutableMap.Builder builder = ImmutableMap.builder(); for ( Field field : clazz.getFields() ) { final String fieldName = field.getName(); - final LogicalEntity entity = fieldRelation( field ); + final Entity entity = fieldRelation( field ); if ( entity == null ) { continue; } builder.put( fieldName, entity ); } - Map tableMap = builder.build(); + Map tableMap = builder.build(); // Unique-Key - Foreign-Key for ( Field field : clazz.getFields() ) { if ( AlgReferentialConstraint.class.isAssignableFrom( field.getType() ) ) { @@ -177,7 +165,7 @@ private Multimap createFunctionMap() { /** * Returns a table based on a particular field of this schema. If the field is not of the right type to be a relation, returns null. */ - private LogicalEntity fieldRelation( final Field field ) { + private Entity fieldRelation( final Field field ) { final Type elementType = getElementType( field.getType() ); if ( elementType == null ) { return null; @@ -223,64 +211,6 @@ private static Enumerable toEnumerable( final Object o ) { } - /** - * Table that is implemented by reading from a Java object. - */ - @Slf4j - private static class ReflectiveEntity extends LogicalTable implements ScannableEntity { - - private final Type elementType; - private final Enumerable enumerable; - - - ReflectiveEntity( Type elementType, Enumerable enumerable, Long id, Long partitionId, Long adapterId ) { - super( id, "test", -1, EntityType.ENTITY, null, false ); - this.elementType = elementType; - this.enumerable = enumerable; - throw new NotImplementedException(); - } - - - @Override - public Statistic getStatistic() { - return Statistics.UNKNOWN; - } - - - @Override - public Enumerable scan( DataContext root ) { - if ( elementType == PolyValue[].class ) { - return enumerable; - } else { - //noinspection unchecked - //return enumerable.select( new FieldSelector( (Class) elementType ) ); - - log.warn( "todo 23f23" ); - return null; - } - } - - - @Override - public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - return getRowType(); - } - - - /*@Override - public Queryable asQueryable( DataContext dataContext, Snapshot snapshot, String tableName ) { - return new AbstractTableQueryable( dataContext, snapshot, this, tableName ) { - @Override - @SuppressWarnings("unchecked") - public Enumerator enumerator() { - return (Enumerator) enumerable.enumerator(); - } - }; - }*/ - - } - - /** * Table macro based on a Java method. */ @@ -314,70 +244,5 @@ public TranslatableEntity apply( final List arguments ) { } - /** - * Table based on a Java field. - * - * @param element type - */ - private static class FieldEntity extends ReflectiveEntity { - - private final Field field; - private Statistic statistic; - - - FieldEntity( Field field, Type elementType, Enumerable enumerable, Long id, Long partitionId, Long adapterId ) { - this( field, elementType, enumerable, Statistics.UNKNOWN, id, partitionId, adapterId ); - } - - - FieldEntity( Field field, Type elementType, Enumerable enumerable, Statistic statistic, Long id, Long partitionId, Long adapterId ) { - super( elementType, enumerable, id, partitionId, adapterId ); - this.field = field; - this.statistic = statistic; - } - - - public String toString() { - return "Relation {field=" + field.getName() + "}"; - } - - - @Override - public Statistic getStatistic() { - return statistic; - } - - - } - - - /** - * Function that returns an array of a given object's field values. - */ - private static class FieldSelector implements Function1 { - - private final Field[] fields; - - - FieldSelector( Class elementType ) { - this.fields = elementType.getFields(); - } - - - @Override - public Object[] apply( Object o ) { - try { - final Object[] objects = new Object[fields.length]; - for ( int i = 0; i < fields.length; i++ ) { - objects[i] = fields[i].get( o ); - } - return objects; - } catch ( IllegalAccessException e ) { - throw new RuntimeException( e ); - } - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java b/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java index a6c50aa594..46d7c52d06 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java +++ b/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java @@ -53,7 +53,7 @@ import org.polypheny.db.algebra.metadata.Metadata; import org.polypheny.db.algebra.metadata.MetadataFactory; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; @@ -389,7 +389,7 @@ public final String getDescription() { @Override - public LogicalEntity getEntity() { + public Entity getEntity() { return null; } diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgInput.java b/core/src/main/java/org/polypheny/db/algebra/AlgInput.java index 48477b907f..6a9a0134fc 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgInput.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgInput.java @@ -36,7 +36,7 @@ import java.util.List; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.util.ImmutableBitSet; @@ -51,7 +51,7 @@ public interface AlgInput { AlgTraitSet getTraitSet(); - LogicalEntity getEntity( String entity ); + Entity getEntity( String entity ); /** * Returns the input relational expression. Throws if there is not precisely one input. diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgNode.java b/core/src/main/java/org/polypheny/db/algebra/AlgNode.java index dbe08bf153..73fd0cd63a 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgNode.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgNode.java @@ -44,7 +44,7 @@ import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.metadata.Metadata; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.plan.AlgImplementor; import org.polypheny.db.plan.AlgOptCluster; @@ -262,7 +262,7 @@ public interface AlgNode extends AlgOptNode, Cloneable { * * @return If this relational expression represents an access to a table, returns that table, otherwise returns null */ - LogicalEntity getEntity(); + Entity getEntity(); /** * Returns the name of this relational expression's class, sans package name, for use in explain. For example, for a diff --git a/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java b/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java index d02d2db39a..9858a34a4c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/AlgFactories.java @@ -66,7 +66,7 @@ import org.polypheny.db.algebra.logical.relational.LogicalUnion; import org.polypheny.db.algebra.logical.relational.LogicalValues; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.Contexts; @@ -537,7 +537,7 @@ public interface ScanFactory { /** * Creates a {@link RelScan}. */ - AlgNode createScan( AlgOptCluster cluster, LogicalEntity entity ); + AlgNode createScan( AlgOptCluster cluster, Entity entity ); } @@ -548,7 +548,7 @@ public interface ScanFactory { private static class ScanFactoryImpl implements ScanFactory { @Override - public AlgNode createScan( AlgOptCluster cluster, LogicalEntity entity ) { + public AlgNode createScan( AlgOptCluster cluster, Entity entity ) { // Check if RelOptTable contains a View, in this case a LogicalViewScan needs to be created if ( entity.entityType == EntityType.VIEW ) { return LogicalRelViewScan.create( cluster, entity ); diff --git a/core/src/main/java/org/polypheny/db/algebra/core/common/Modify.java b/core/src/main/java/org/polypheny/db/algebra/core/common/Modify.java index 96aae50e34..8abcf77a1f 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/common/Modify.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/common/Modify.java @@ -22,12 +22,12 @@ import lombok.experimental.SuperBuilder; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.SingleAlg; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @SuperBuilder(toBuilder = true) -public abstract class Modify extends SingleAlg { +public abstract class Modify extends SingleAlg { @Getter public final E entity; diff --git a/core/src/main/java/org/polypheny/db/algebra/core/common/Scan.java b/core/src/main/java/org/polypheny/db/algebra/core/common/Scan.java index 457d77d05a..54eae3b536 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/common/Scan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/common/Scan.java @@ -18,12 +18,12 @@ import lombok.Getter; import org.polypheny.db.algebra.AbstractAlgNode; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @Getter -public abstract class Scan extends AbstractAlgNode { +public abstract class Scan extends AbstractAlgNode { public final E entity; diff --git a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java index ef7a4635c2..ee4023c7cc 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java @@ -30,7 +30,7 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexNode; @@ -40,7 +40,7 @@ @SuperBuilder(toBuilder = true) @Value @NonFinal -public abstract class DocumentModify extends Modify implements DocumentAlg { +public abstract class DocumentModify extends Modify implements DocumentAlg { @NonNull public ImmutableMap updates; diff --git a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java index 2b6579c5dd..eed155f42c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java @@ -18,13 +18,13 @@ import org.polypheny.db.algebra.core.common.Scan; import org.polypheny.db.algebra.type.DocumentType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.schema.trait.ModelTrait; -public abstract class DocumentScan extends Scan implements DocumentAlg { +public abstract class DocumentScan extends Scan implements DocumentAlg { /** diff --git a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentValues.java b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentValues.java index 123aaa98b7..108467f6b0 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentValues.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentValues.java @@ -26,7 +26,7 @@ import org.polypheny.db.algebra.logical.relational.LogicalValues; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.DocumentType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; @@ -125,7 +125,7 @@ public LogicalValues getRelationalEquivalent() { } - public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { + public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { return List.of( getRelationalEquivalent() ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgModify.java b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgModify.java index 29b8678553..1e0a6aa101 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgModify.java @@ -21,7 +21,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexNode; @@ -29,7 +29,7 @@ import org.polypheny.db.type.entity.PolyString; -public abstract class LpgModify extends Modify implements LpgAlg { +public abstract class LpgModify extends Modify implements LpgAlg { @Getter public final Operation operation; diff --git a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgScan.java b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgScan.java index 7fa9858f9c..6ec585fe26 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgScan.java @@ -18,13 +18,13 @@ import org.polypheny.db.algebra.core.common.Scan; import org.polypheny.db.algebra.type.GraphType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.schema.trait.ModelTrait; -public abstract class LpgScan extends Scan implements LpgAlg { +public abstract class LpgScan extends Scan implements LpgAlg { /** 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 4bfa329c86..c5b7728c56 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 @@ -29,7 +29,7 @@ import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; @@ -52,7 +52,7 @@ *
  • for {@code UPDATE}, all old values plus updated new values. * */ -public abstract class RelModify extends Modify implements RelAlg { +public abstract class RelModify extends Modify implements RelAlg { /** diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java index 605928477e..0ba768adc6 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java @@ -33,7 +33,7 @@ import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; @@ -48,7 +48,7 @@ /** * Relational operator that returns the contents of a table. */ -public abstract class RelScan extends Scan implements RelAlg { +public abstract class RelScan extends Scan implements RelAlg { protected RelScan( AlgOptCluster cluster, AlgTraitSet traitSet, @NonNull E entity ) { super( cluster, traitSet.replace( ModelTrait.RELATIONAL ), entity ); @@ -87,7 +87,7 @@ public AlgDataType deriveRowType() { /** * Returns an identity projection for the given table. */ - public static ImmutableList identity( LogicalEntity entity ) { + public static ImmutableList identity( Entity entity ) { return ImmutableList.copyOf( IntStream.range( 0, entity.getRowType().getFieldCount() ).boxed().collect( Collectors.toList() ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java index 85346c358d..9ff33fb901 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelationalTransformable.java @@ -20,7 +20,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.common.Modify.Operation; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.schema.types.ModifiableTable; @@ -31,10 +31,10 @@ public interface RelationalTransformable { - List getRelationalEquivalent( List values, List entities, Snapshot snapshot ); + List getRelationalEquivalent( List values, List entities, Snapshot snapshot ); - static Modify getModify( LogicalEntity entity, AlgNode alg, Operation operation ) { + static Modify getModify( Entity entity, AlgNode alg, Operation operation ) { return entity.unwrap( ModifiableTable.class ).toModificationTable( alg.getCluster(), alg.getTraitSet(), entity, alg, operation, null, null ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java index 7e9a0f8043..806e9e5da2 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableScan.java @@ -38,7 +38,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.interpreter.Row; import org.polypheny.db.plan.AlgOptCluster; @@ -78,7 +78,7 @@ public EnumerableScan( AlgOptCluster cluster, AlgTraitSet traitSet, PhysicalTabl /** * Creates an EnumerableScan. */ - public static EnumerableScan create( AlgOptCluster cluster, LogicalEntity entity ) { + public static EnumerableScan create( AlgOptCluster cluster, Entity entity ) { PhysicalTable physicalTable = entity.unwrap( PhysicalTable.class ); Class elementType = EnumerableScan.deduceElementType( physicalTable ); final AlgTraitSet traitSet = @@ -105,7 +105,7 @@ public int hashCode() { /** * Returns whether EnumerableScan can generate code to handle a particular variant of the Table SPI. */ - public static boolean canHandle( LogicalEntity entity ) { + public static boolean canHandle( Entity entity ) { // FilterableTable and ProjectableFilterableTable cannot be handled in/ enumerable convention because they might reject filters and those filters would need to be handled dynamically. return entity instanceof QueryableEntity || entity instanceof ScannableEntity; } diff --git a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonReader.java b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonReader.java index aee8aa1264..1f8c3e3eb7 100644 --- a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonReader.java +++ b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJsonReader.java @@ -53,7 +53,7 @@ import org.polypheny.db.algebra.AlgInput; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptSchema; import org.polypheny.db.plan.AlgTraitSet; @@ -127,7 +127,7 @@ public AlgTraitSet getTraitSet() { @Override - public LogicalEntity getEntity( String entity ) { + public Entity getEntity( String entity ) { final List list; if ( jsonAlg.get( entity ) instanceof String ) { String str = (String) jsonAlg.get( entity ); 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 5e98e5e641..bbe14c2d6f 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 @@ -36,7 +36,7 @@ import org.polypheny.db.algebra.logical.relational.LogicalValues; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -168,7 +168,7 @@ public static void attachFilter( AlgNode modify, AlgBuilder algBuilder, RexBuild } - public static void attachFilter( LogicalEntity entity, AlgBuilder algBuilder, RexBuilder rexBuilder, List indexes ) { + public static void attachFilter( Entity entity, AlgBuilder algBuilder, RexBuilder rexBuilder, List indexes ) { List fields = new ArrayList<>(); int i = 0; for ( AlgDataTypeField field : entity.getRowType().getFields() ) { diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java index 1f38c9e785..56833bdbea 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java @@ -25,7 +25,7 @@ import org.polypheny.db.algebra.AlgShuttle; import org.polypheny.db.algebra.core.document.DocumentModify; import org.polypheny.db.algebra.core.relational.RelationalTransformable; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexNode; @@ -33,17 +33,17 @@ @SuperBuilder(toBuilder = true) @EqualsAndHashCode(callSuper = true) @Value -public class LogicalDocumentModify extends DocumentModify implements RelationalTransformable { +public class LogicalDocumentModify extends DocumentModify implements RelationalTransformable { /** * Subclass of {@link DocumentModify} not targeted at any particular engine or calling convention. */ - public LogicalDocumentModify( AlgTraitSet traits, LogicalEntity entity, AlgNode input, Operation operation, Map updates, List removes, Map renames ) { + public LogicalDocumentModify( AlgTraitSet traits, Entity entity, AlgNode input, Operation operation, Map updates, List removes, Map renames ) { super( traits, entity, input, operation, updates, removes, renames ); } - public static LogicalDocumentModify create( LogicalEntity entity, AlgNode input, Operation operation, Map updates, List removes, Map renames ) { + public static LogicalDocumentModify create( Entity entity, AlgNode input, Operation operation, Map updates, List removes, Map renames ) { return new LogicalDocumentModify( input.getTraitSet(), entity, input, operation, updates, removes, renames ); } @@ -55,7 +55,7 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { @Override - public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { + public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { return List.of( RelationalTransformable.getModify( entities.get( 0 ), values.get( 0 ), operation ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentScan.java b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentScan.java index e0937fea86..a5e297fd6b 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentScan.java @@ -22,7 +22,7 @@ import org.polypheny.db.algebra.core.document.DocumentScan; import org.polypheny.db.algebra.core.relational.RelationalTransformable; import org.polypheny.db.algebra.logical.relational.LogicalRelScan; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptRule; @@ -30,23 +30,23 @@ import org.polypheny.db.schema.trait.ModelTrait; -public class LogicalDocumentScan extends DocumentScan implements RelationalTransformable { +public class LogicalDocumentScan extends DocumentScan implements RelationalTransformable { /** * Subclass of {@link DocumentScan} not targeted at any particular engine or calling convention. */ - public LogicalDocumentScan( AlgOptCluster cluster, AlgTraitSet traitSet, LogicalEntity document ) { + public LogicalDocumentScan( AlgOptCluster cluster, AlgTraitSet traitSet, Entity document ) { super( cluster, traitSet.replace( ModelTrait.DOCUMENT ), document ); } - public static AlgNode create( AlgOptCluster cluster, LogicalEntity collection ) { + public static AlgNode create( AlgOptCluster cluster, Entity collection ) { return new LogicalDocumentScan( cluster, cluster.traitSet(), collection ); } @Override - public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { + public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { return List.of( AlgOptRule.convert( LogicalRelScan.create( getCluster(), entities.get( 0 ) ), ModelTrait.RELATIONAL ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgModify.java b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgModify.java index ea0611931d..9d658dc0a1 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgModify.java @@ -24,7 +24,7 @@ import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.lpg.LpgModify; import org.polypheny.db.algebra.core.relational.RelationalTransformable; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptUtil; @@ -33,13 +33,13 @@ import org.polypheny.db.type.entity.PolyString; -public class LogicalLpgModify extends LpgModify implements RelationalTransformable { +public class LogicalLpgModify extends LpgModify implements RelationalTransformable { /** * Subclass of {@link LpgModify} not targeted at any particular engine or calling convention. */ - public LogicalLpgModify( AlgOptCluster cluster, AlgTraitSet traits, LogicalEntity entity, AlgNode input, Operation operation, List ids, List operations ) { + public LogicalLpgModify( AlgOptCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input, Operation operation, List ids, List operations ) { super( cluster, traits, entity, input, operation, ids, operations, AlgOptUtil.createDmlRowType( Kind.INSERT, cluster.getTypeFactory() ) ); } @@ -51,7 +51,7 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { @Override - public List getRelationalEquivalent( List inputs, List entities, Snapshot snapshot ) { + public List getRelationalEquivalent( List inputs, List entities, Snapshot snapshot ) { List modifies = new ArrayList<>(); // modify of nodes diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java index 42c066dd9d..e6943091a6 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgScan.java @@ -28,7 +28,7 @@ import org.polypheny.db.algebra.logical.relational.LogicalRelScan; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.plan.AlgOptCluster; @@ -38,19 +38,19 @@ import org.polypheny.db.schema.trait.ModelTrait; -public class LogicalLpgScan extends LpgScan implements RelationalTransformable { +public class LogicalLpgScan extends LpgScan implements RelationalTransformable { /** * Subclass of {@link LpgScan} not targeted at any particular engine or calling convention. */ - public LogicalLpgScan( AlgOptCluster cluster, AlgTraitSet traitSet, LogicalEntity graph, AlgDataType rowType ) { + public LogicalLpgScan( AlgOptCluster cluster, AlgTraitSet traitSet, Entity graph, AlgDataType rowType ) { super( cluster, traitSet.replace( ModelTrait.GRAPH ), graph ); this.rowType = rowType; } @Override - public List getRelationalEquivalent( List inputs, List entities, Snapshot snapshot ) { + public List getRelationalEquivalent( List inputs, List entities, Snapshot snapshot ) { assert !entities.isEmpty(); AlgTraitSet out = getTraitSet().replace( ModelTrait.RELATIONAL ); LogicalRelScan nodes = new LogicalRelScan( getCluster(), out, entities.get( 0 ) ); diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java index dfa3e2c8f5..0a6c4e2b02 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgValues.java @@ -36,7 +36,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.algebra.type.AlgRecordType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -118,7 +118,7 @@ public static LogicalLpgValues create( @Override - public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { + public List getRelationalEquivalent( List values, List entities, Snapshot snapshot ) { AlgTraitSet out = traitSet.replace( ModelTrait.RELATIONAL ); AlgOptCluster cluster = AlgOptCluster.create( getCluster().getPlanner(), getCluster().getRexBuilder(), out, snapshot ); 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 0a34f34164..39a361e789 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 @@ -20,7 +20,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgShuttle; import org.polypheny.db.algebra.core.relational.RelModify; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; @@ -31,7 +31,7 @@ /** * Sub-class of {@link RelModify} not targeted at any particular engine or calling convention. */ -public final class LogicalRelModify extends RelModify { +public final class LogicalRelModify extends RelModify { /** @@ -42,7 +42,7 @@ public final class LogicalRelModify extends RelModify { public LogicalRelModify( AlgOptCluster cluster, AlgTraitSet traitSet, - LogicalEntity table, + Entity table, AlgNode input, Operation operation, List updateColumns, @@ -54,7 +54,7 @@ public LogicalRelModify( public LogicalRelModify( AlgTraitSet traits, - LogicalEntity table, + Entity table, AlgNode child, Operation operation, List targets, @@ -67,7 +67,7 @@ public LogicalRelModify( * Creates a LogicalModify. */ public static LogicalRelModify create( - LogicalEntity table, + Entity table, AlgNode input, Operation operation, List updateColumns, diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelScan.java b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelScan.java index 889bef4fe0..cd34a7ffcf 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelScan.java @@ -41,7 +41,7 @@ import org.polypheny.db.algebra.AlgInput; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.relational.RelScan; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalMaterializedView; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.logistic.EntityType; @@ -73,7 +73,7 @@ * * can. It is the optimizer's responsibility to find these ways, by applying transformation rules. */ -public final class LogicalRelScan extends RelScan { +public final class LogicalRelScan extends RelScan { /** @@ -81,7 +81,7 @@ public final class LogicalRelScan extends RelScan { * * Use {@link #create} unless you know what you're doing. */ - public LogicalRelScan( AlgOptCluster cluster, AlgTraitSet traitSet, LogicalEntity table ) { + public LogicalRelScan( AlgOptCluster cluster, AlgTraitSet traitSet, Entity table ) { super( cluster, traitSet, table ); } @@ -107,7 +107,7 @@ public AlgNode copy( AlgTraitSet traitSet, List inputs ) { * * @param cluster Cluster */ - public static LogicalRelScan create( AlgOptCluster cluster, final LogicalEntity entity ) { + public static LogicalRelScan create( AlgOptCluster cluster, final Entity entity ) { final AlgTraitSet traitSet = cluster.traitSetOf( Convention.NONE ) diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelViewScan.java b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelViewScan.java index fe04c49f3e..1bc8c4b362 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelViewScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelViewScan.java @@ -26,7 +26,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalView; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -36,20 +36,20 @@ @Getter -public class LogicalRelViewScan extends RelScan { +public class LogicalRelViewScan extends RelScan { private final AlgNode algNode; private final AlgCollation algCollation; - public LogicalRelViewScan( AlgOptCluster cluster, AlgTraitSet traitSet, LogicalEntity table, AlgNode algNode, AlgCollation algCollation ) { + public LogicalRelViewScan( AlgOptCluster cluster, AlgTraitSet traitSet, Entity table, AlgNode algNode, AlgCollation algCollation ) { super( cluster, traitSet, table ); this.algNode = algNode; this.algCollation = algCollation; } - public static AlgNode create( AlgOptCluster cluster, final LogicalEntity entity ) { + public static AlgNode create( AlgOptCluster cluster, final Entity entity ) { final AlgTraitSet traitSet = cluster.traitSetOf( Convention.NONE ) diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgColumnOrigin.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgColumnOrigin.java index dcfb5ed227..bb77ad9abc 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgColumnOrigin.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgColumnOrigin.java @@ -34,7 +34,7 @@ package org.polypheny.db.algebra.metadata; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; /** @@ -42,14 +42,14 @@ */ public class AlgColumnOrigin { - private final LogicalEntity originTable; + private final Entity originTable; private final int iOriginColumn; private final boolean isDerived; - public AlgColumnOrigin( LogicalEntity origin, int iOriginColumn, boolean isDerived ) { + public AlgColumnOrigin( Entity origin, int iOriginColumn, boolean isDerived ) { this.originTable = origin; this.iOriginColumn = iOriginColumn; this.isDerived = isDerived; @@ -59,7 +59,7 @@ public AlgColumnOrigin( LogicalEntity origin, int iOriginColumn, boolean isDeriv /** * @return table of origin */ - public LogicalEntity getOriginTable() { + public Entity getOriginTable() { return originTable; } diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java index 6c01384242..9f98966b63 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java @@ -73,7 +73,7 @@ import org.polypheny.db.algebra.enumerable.EnumerableSemiJoin; import org.polypheny.db.algebra.enumerable.EnumerableThetaJoin; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.hep.HepAlgVertex; import org.polypheny.db.plan.volcano.AlgSubset; import org.polypheny.db.rex.RexCall; @@ -203,7 +203,7 @@ public ImmutableList collations( AlgSubset alg, AlgMetadataQuery m /** * Helper method to determine a {@link RelScan}'s collation. */ - public static List table( LogicalEntity table ) { + public static List table( Entity table ) { return table.getCollations(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java index 8cd2afb462..49670d88a3 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnOrigins.java @@ -47,7 +47,7 @@ import org.polypheny.db.algebra.core.SetOp; import org.polypheny.db.algebra.core.Sort; import org.polypheny.db.algebra.core.TableFunctionScan; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.rex.RexIndexRef; import org.polypheny.db.rex.RexNode; import org.polypheny.db.rex.RexVisitor; @@ -222,7 +222,7 @@ public Set getColumnOrigins( AlgNode alg, AlgMetadataQuery mq, final Set set = new HashSet<>(); - LogicalEntity entity = alg.getEntity(); + Entity entity = alg.getEntity(); if ( entity == null ) { // Somebody is making column values up out of thin air, like a VALUES clause, so we return an empty set. return set; diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java index c43605bc03..37b533b60e 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java @@ -71,7 +71,7 @@ /** - * RelMdColumnUniqueness supplies a default implementation of {@link AlgMetadataQuery#areColumnsUnique} for the standard logical algebra. + * {@link AlgMdColumnUniqueness} supplies a default implementation of {@link AlgMetadataQuery#areColumnsUnique} for the standard logical algebra. */ public class AlgMdColumnUniqueness implements MetadataHandler { @@ -212,10 +212,9 @@ public Boolean areColumnsUnique( Project alg, AlgMetadataQuery mq, ImmutableBitS if ( castType.equals( origType ) ) { childColumns.set( ((RexIndexRef) castOperand).getIndex() ); } - } else { - // If the expression will not influence uniqueness of the projection, then skip it. - continue; } + // If the expression does not influence uniqueness of the projection, then skip it. + continue; } // If no columns can affect uniqueness, then return unknown diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistribution.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistribution.java index 0bffb59b7f..df1f16b9cd 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistribution.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdDistribution.java @@ -49,7 +49,7 @@ import org.polypheny.db.algebra.core.Values; import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.hep.HepAlgVertex; import org.polypheny.db.rex.RexLiteral; import org.polypheny.db.rex.RexNode; @@ -130,7 +130,7 @@ public AlgDistribution distribution( HepAlgVertex alg, AlgMetadataQuery mq ) { /** * Helper method to determine a {@link RelScan}'s distribution. */ - public static AlgDistribution table( LogicalEntity table ) { + public static AlgDistribution table( Entity table ) { return table.getDistribution(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMetadataQuery.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMetadataQuery.java index 7cb4bc21f5..ceb01897e5 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMetadataQuery.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMetadataQuery.java @@ -48,7 +48,7 @@ import org.polypheny.db.algebra.AlgDistribution; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.constant.ExplainLevel; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPredicateList; import org.polypheny.db.rex.RexNode; @@ -392,7 +392,7 @@ public Set getTableReferences( AlgNode alg ) { * @param alg the AlgNode * @return the table, if the {@link AlgNode} is a simple table; otherwise null */ - public LogicalEntity getTableOrigin( AlgNode alg ) { + public Entity getTableOrigin( AlgNode alg ) { // Determine the simple origin of the first column in the/ AlgNode. If it's simple, then that means that the underlying table is also simple, even if the column itself is derived. if ( alg.getRowType().getFieldCount() == 0 ) { return null; 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 3da0233032..73e1a3b68a 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 @@ -39,7 +39,7 @@ 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.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.rex.RexNode; @@ -48,14 +48,14 @@ */ public class MutableTableModify extends MutableSingleAlg { - public final LogicalEntity table; + public final Entity table; public final Operation operation; public final List updateColumnList; public final List sourceExpressionList; public final boolean flattened; - private MutableTableModify( AlgDataType rowType, MutableAlg input, LogicalEntity table, Operation operation, List updateColumnList, List sourceExpressionList, boolean flattened ) { + private MutableTableModify( AlgDataType rowType, MutableAlg input, Entity table, Operation operation, List updateColumnList, List sourceExpressionList, boolean flattened ) { super( MutableAlgType.TABLE_MODIFY, rowType, input ); this.table = table; this.operation = operation; @@ -76,7 +76,7 @@ private MutableTableModify( AlgDataType rowType, MutableAlg input, LogicalEntity * @param sourceExpressionList List of value expressions to be set (e.g. exp1, exp2); null if not UPDATE * @param flattened Whether set flattens the input row type */ - public static MutableTableModify of( AlgDataType rowType, MutableAlg input, LogicalEntity table, Operation operation, List updateColumnList, List sourceExpressionList, boolean flattened ) { + public static MutableTableModify of( AlgDataType rowType, MutableAlg input, Entity table, Operation operation, List updateColumnList, List sourceExpressionList, boolean flattened ) { return new MutableTableModify( rowType, input, table, operation, updateColumnList, sourceExpressionList, flattened ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java index 9cc1f77291..3e78cdfb25 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/LoptOptimizeJoinRule.java @@ -58,7 +58,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptRule; @@ -252,10 +252,10 @@ private void setJoinKey( ImmutableBitSet.Builder joinKeys, ImmutableBitSet.Build */ private void findRemovableSelfJoins( AlgMetadataQuery mq, LoptMultiJoin multiJoin ) { // Candidates for self-joins must be simple factors - Map simpleFactors = getSimpleFactors( mq, multiJoin ); + Map simpleFactors = getSimpleFactors( mq, multiJoin ); // See if a simple factor is repeated and therefore potentially is part of a self-join. Restrict each factor to at most one self-join. - final List repeatedTables = new ArrayList<>(); + final List repeatedTables = new ArrayList<>(); final TreeSet sortedFactors = new TreeSet<>(); sortedFactors.addAll( simpleFactors.keySet() ); final Map selfJoinPairs = new HashMap<>(); @@ -298,8 +298,8 @@ private void findRemovableSelfJoins( AlgMetadataQuery mq, LoptMultiJoin multiJoi * @param multiJoin join factors being optimized * @return map consisting of the simple factors and the tables they correspond */ - private Map getSimpleFactors( AlgMetadataQuery mq, LoptMultiJoin multiJoin ) { - final Map returnList = new HashMap<>(); + private Map getSimpleFactors( AlgMetadataQuery mq, LoptMultiJoin multiJoin ) { + final Map returnList = new HashMap<>(); // Loop through all join factors and locate the ones where each column referenced from the factor is not derived and originates from the same underlying table. Also, discard factors that // are null-generating or will be removed because of semijoins. @@ -311,7 +311,7 @@ private Map getSimpleFactors( AlgMetadataQuery mq, LoptM continue; } final AlgNode alg = multiJoin.getJoinFactor( factIdx ); - final LogicalEntity table = mq.getTableOrigin( alg ); + final Entity table = mq.getTableOrigin( alg ); if ( table != null ) { returnList.put( factIdx, table ); } @@ -1509,11 +1509,11 @@ public static boolean isRemovableSelfJoin( Join joinRel ) { // Make sure the join is between the same simple factor final AlgMetadataQuery mq = joinRel.getCluster().getMetadataQuery(); - final LogicalEntity leftTable = mq.getTableOrigin( left ); + final Entity leftTable = mq.getTableOrigin( left ); if ( leftTable == null ) { return false; } - final LogicalEntity rightTable = mq.getTableOrigin( right ); + final Entity rightTable = mq.getTableOrigin( right ); if ( rightTable == null ) { return false; } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java b/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java index e07eec7b82..cd5f358526 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/LoptSemiJoinOptimizer.java @@ -52,7 +52,7 @@ import org.polypheny.db.algebra.metadata.AlgMdUtil; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.operators.OperatorName; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.languages.OperatorRegistry; @@ -342,7 +342,7 @@ private RexNode adjustSemiJoinCondition( LoptMultiJoin multiJoin, int leftAdjust */ private LcsEntity validateKeys( AlgNode factRel, List leftKeys, List rightKeys, List actualLeftKeys ) { int keyIdx = 0; - LogicalEntity theTable = null; + Entity theTable = null; ListIterator keyIter = leftKeys.listIterator(); while ( keyIter.hasNext() ) { boolean removeKey = false; @@ -352,7 +352,7 @@ private LcsEntity validateKeys( AlgNode factRel, List leftKeys, List { +public abstract class Entity implements PolyObject, Wrapper, Serializable, CatalogType, Expressible, Typed, Comparable { @Serialize public long id; @@ -59,6 +60,7 @@ public abstract class LogicalEntity implements LogicalObject, Wrapper, Serializa @Serialize @SerializeNullable + @Nullable public String name; @Serialize @@ -68,9 +70,9 @@ public abstract class LogicalEntity implements LogicalObject, Wrapper, Serializa public boolean modifiable; - public LogicalEntity( + public Entity( long id, - String name, + @Nullable String name, long namespaceId, EntityType type, DataModel dataModel, @@ -150,7 +152,7 @@ public String getNamespaceName() { @Override - public int compareTo( @NotNull LogicalEntity o ) { + public int compareTo( @NotNull Entity o ) { if ( !this.getClass().getSimpleName().equals( o.getClass().getSimpleName() ) ) { return -1; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalAdapter.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalAdapter.java index 1805d5b299..3a0ff404a8 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalAdapter.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalAdapter.java @@ -32,7 +32,7 @@ @EqualsAndHashCode @Value @SuperBuilder(toBuilder = true) -public class LogicalAdapter implements LogicalObject { +public class LogicalAdapter implements PolyObject { private static final long serialVersionUID = -6140489767408917639L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalDatabase.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalDatabase.java deleted file mode 100644 index 94b575cd4c..0000000000 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalDatabase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2019-2022 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.catalog.entity; - -import java.io.Serializable; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - - -@EqualsAndHashCode -public final class LogicalDatabase implements LogicalObject, Comparable { - - private static final long serialVersionUID = -4529369849606480011L; - - public final long id; - public final String name; - public final int ownerId; - public final String ownerName; - public final Long defaultNamespaceId; // can be null - public final String defaultNamespaceName; // can be null - - - public LogicalDatabase( - final long id, - @NonNull final String name, - final int ownerId, - @NonNull final String ownerName, - final Long defaultNamespaceId, - final String defaultNamespaceName ) { - this.id = id; - this.name = name; - this.ownerId = ownerId; - this.ownerName = ownerName; - this.defaultNamespaceId = defaultNamespaceId; - this.defaultNamespaceName = defaultNamespaceName; - } - - - // Used for creating ResultSets - @Override - public Serializable[] getParameterArray() { - return new Serializable[]{ name, ownerName, defaultNamespaceName }; - } - - - @Override - public int compareTo( LogicalDatabase o ) { - if ( o != null ) { - return (int) (this.id - o.id); - } - return -1; - } - - - @RequiredArgsConstructor - public static class PrimitiveCatalogDatabase { - - public final String tableCat; - public final String owner; - public final String defaultSchema; - - } - -} diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalQueryInterface.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalQueryInterface.java index 16b9f6ee8b..3f63b1e0fa 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalQueryInterface.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalQueryInterface.java @@ -31,7 +31,7 @@ @EqualsAndHashCode @Value @SuperBuilder(toBuilder = true) -public class LogicalQueryInterface implements LogicalObject { +public class LogicalQueryInterface implements PolyObject { private static final long serialVersionUID = 7212289724539530050L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalUser.java b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalUser.java index 9d81be4009..3defae3b69 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalUser.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/LogicalUser.java @@ -26,7 +26,7 @@ @EqualsAndHashCode @Value -public class LogicalUser implements LogicalObject, Comparable { +public class LogicalUser implements PolyObject, Comparable { private static final long serialVersionUID = 5022567585804699491L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalObject.java b/core/src/main/java/org/polypheny/db/catalog/entity/PolyObject.java similarity index 95% rename from core/src/main/java/org/polypheny/db/catalog/entity/LogicalObject.java rename to core/src/main/java/org/polypheny/db/catalog/entity/PolyObject.java index 4fb78adb4e..a7e251c2f0 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/LogicalObject.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/PolyObject.java @@ -23,7 +23,7 @@ /** * */ -public interface LogicalObject extends Serializable { +public interface PolyObject extends Serializable { Serializable[] getParameterArray(); diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationColumn.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationColumn.java index f950c010c8..488c7beb60 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationColumn.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationColumn.java @@ -26,14 +26,14 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.PlacementType; @EqualsAndHashCode @Value @SuperBuilder(toBuilder = true) -public class AllocationColumn implements LogicalObject { +public class AllocationColumn implements PolyObject { private static final long serialVersionUID = -1909757888176291095L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java index fac6d95b99..20d65bc09e 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java @@ -24,7 +24,7 @@ import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.catalog.logistic.PartitionType; @@ -35,7 +35,7 @@ @Slf4j @SuperBuilder @SerializeClass(subclasses = { AllocationTable.class, AllocationGraph.class, AllocationCollection.class }) -public abstract class AllocationEntity extends LogicalEntity { +public abstract class AllocationEntity extends Entity { @Serialize public long adapterId; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartition.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartition.java index ecf181935c..b491e1d2c4 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartition.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartition.java @@ -27,7 +27,7 @@ import lombok.Getter; import lombok.Value; import org.jetbrains.annotations.NotNull; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.DataPlacementRole; import org.polypheny.db.catalog.logistic.PartitionType; import org.polypheny.db.catalog.logistic.PlacementType; @@ -37,7 +37,7 @@ * This class is considered the logical representation of a physical table on a specific store. */ @Value -public class AllocationPartition implements LogicalObject { +public class AllocationPartition implements PolyObject { private static final long serialVersionUID = 8835793248417591036L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartitionGroup.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartitionGroup.java index aaf7988bc5..6b170e0acc 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartitionGroup.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPartitionGroup.java @@ -23,12 +23,12 @@ import lombok.EqualsAndHashCode; import lombok.Value; import org.jetbrains.annotations.Nullable; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; @EqualsAndHashCode @Value -public class AllocationPartitionGroup implements LogicalObject { +public class AllocationPartitionGroup implements PolyObject { private static final long serialVersionUID = 6229244317971622972L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPlacement.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPlacement.java index c82e74ee0b..8eab351537 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPlacement.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationPlacement.java @@ -20,10 +20,10 @@ import io.activej.serializer.annotations.Serialize; import java.io.Serializable; import lombok.Value; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; @Value -public class AllocationPlacement implements LogicalObject { +public class AllocationPlacement implements PolyObject { @Serialize public long id; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java index 8780447c2e..893ffe552b 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java @@ -24,14 +24,14 @@ import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; @EqualsAndHashCode(callSuper = true) @Value @SuperBuilder(toBuilder = true) -public class LogicalCollection extends LogicalEntity implements LogicalObject { +public class LogicalCollection extends LogicalEntity implements PolyObject { private static final long serialVersionUID = -6490762948368178584L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java index 437367a6cc..d2edfcaecc 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalColumn.java @@ -30,7 +30,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.LogicalDefaultValue; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.Collation; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.type.PolyType; @@ -40,7 +40,7 @@ @Value @SuperBuilder(toBuilder = true) @NonFinal -public class LogicalColumn implements LogicalObject, Comparable { +public class LogicalColumn implements PolyObject, Comparable { private static final long serialVersionUID = -4792846455300897399L; @@ -175,7 +175,7 @@ public Serializable[] getParameterArray() { null, position, nullable ? "YES" : "NO", - LogicalObject.getEnumNameOrNull( collation ) }; + PolyObject.getEnumNameOrNull( collation ) }; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java index c165d48b6d..aa3672ecc0 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java @@ -20,6 +20,7 @@ import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; @@ -27,7 +28,7 @@ @SuperBuilder(toBuilder = true) @Value @NonFinal -public abstract class LogicalEntity extends org.polypheny.db.catalog.entity.LogicalEntity { +public abstract class LogicalEntity extends Entity { public LogicalEntity( diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalForeignKey.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalForeignKey.java index 4455a48323..73ca9d9c7a 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalForeignKey.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalForeignKey.java @@ -29,7 +29,7 @@ import lombok.SneakyThrows; import lombok.Value; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.ForeignKeyOption; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -136,7 +136,7 @@ public Serializable[] getParameterArray( String referencedKeyColumnName, String // Used for creating ResultSets @RequiredArgsConstructor - public static class LogicalForeignKeyColumn implements LogicalObject { + public static class LogicalForeignKeyColumn implements PolyObject { private static final long serialVersionUID = 3287177728197412000L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalIndex.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalIndex.java index 078ee67b8e..83e481063b 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalIndex.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalIndex.java @@ -29,7 +29,7 @@ import lombok.Value; import lombok.experimental.SuperBuilder; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.IndexType; @@ -121,7 +121,7 @@ public Serializable[] getParameterArray( int ordinalPosition, String columnName // Used for creating ResultSets @RequiredArgsConstructor @Value - public static class LogicalIndexColumn implements LogicalObject { + public static class LogicalIndexColumn implements PolyObject { private static final long serialVersionUID = -5596459769680478780L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalKey.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalKey.java index da1e825128..2e42afb9b6 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalKey.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalKey.java @@ -27,7 +27,7 @@ import lombok.experimental.NonFinal; import org.jetbrains.annotations.NotNull; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -35,7 +35,7 @@ @Value @NonFinal @SerializeClass(subclasses = { LogicalGenericKey.class, LogicalPrimaryKey.class, LogicalForeignKey.class }) -public abstract class LogicalKey implements LogicalObject, Comparable { +public abstract class LogicalKey implements PolyObject, Comparable { private static final long serialVersionUID = -5803762884192662540L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java index f9b99f60e8..644f2b9d87 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java @@ -27,14 +27,14 @@ import lombok.Value; import lombok.With; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.logistic.DataModel; @EqualsAndHashCode(callSuper = false) @With @Value -public class LogicalNamespace implements LogicalObject, Comparable { +public class LogicalNamespace implements PolyObject, Comparable { private static final long serialVersionUID = 3090632164988970558L; @@ -66,7 +66,7 @@ public LogicalNamespace( // Used for creating ResultSets @Override public Serializable[] getParameterArray() { - return new Serializable[]{ name, Catalog.DATABASE_NAME, Catalog.USER_NAME, LogicalObject.getEnumNameOrNull( dataModel ) }; + return new Serializable[]{ name, Catalog.DATABASE_NAME, Catalog.USER_NAME, PolyObject.getEnumNameOrNull( dataModel ) }; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalPrimaryKey.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalPrimaryKey.java index 5d8462aaed..5be3518e48 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalPrimaryKey.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalPrimaryKey.java @@ -27,7 +27,7 @@ import lombok.RequiredArgsConstructor; import lombok.Value; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalObject; +import org.polypheny.db.catalog.entity.PolyObject; @Value @@ -68,7 +68,7 @@ public Serializable[] getParameterArray( String columnName, int keySeq ) { // Used for creating ResultSets @RequiredArgsConstructor - public static class LogicalPrimaryKeyColumn implements LogicalObject { + public static class LogicalPrimaryKeyColumn implements PolyObject { private static final long serialVersionUID = -2669773639977732201L; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java index 3a023a2238..f2e4bf57c9 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java @@ -22,7 +22,7 @@ import lombok.Value; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; @@ -31,7 +31,7 @@ @NonFinal @SuperBuilder(toBuilder = true) @SerializeClass(subclasses = { PhysicalTable.class, PhysicalGraph.class, PhysicalCollection.class }) -public abstract class PhysicalEntity extends LogicalEntity { +public abstract class PhysicalEntity extends Entity { @Serialize public String namespaceName; 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 ea7afc1a59..3d27bed400 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 @@ -24,7 +24,7 @@ import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; import org.apache.calcite.linq4j.tree.Expression; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.logistic.EntityType; @@ -33,7 +33,7 @@ @SuperBuilder(toBuilder = true) @NonFinal @SerializeClass(subclasses = PhysicalColumn.class) -public abstract class PhysicalField extends LogicalEntity { +public abstract class PhysicalField extends Entity { @Serialize public long adapterId; diff --git a/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/LogicalRelSnapshotImpl.java b/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/LogicalRelSnapshotImpl.java index 3485d5d738..24f811bd4c 100644 --- a/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/LogicalRelSnapshotImpl.java +++ b/core/src/main/java/org/polypheny/db/catalog/snapshot/impl/LogicalRelSnapshotImpl.java @@ -53,6 +53,7 @@ public class LogicalRelSnapshotImpl implements LogicalRelSnapshot { ImmutableMap namespaces; ImmutableMap namespaceNames; + ImmutableMap namespaceCaseSensitive; ImmutableMap tables; @@ -64,6 +65,7 @@ public class LogicalRelSnapshotImpl implements LogicalRelSnapshot { ImmutableMap> tablesNamespace; ImmutableMap> tableColumns; + ImmutableMap columns; ImmutableMap, LogicalColumn> columnNames; @@ -71,6 +73,7 @@ public class LogicalRelSnapshotImpl implements LogicalRelSnapshot { ImmutableMap keys; ImmutableMap> tableKeys; + ImmutableMap columnsKey; ImmutableMap index; @@ -78,6 +81,7 @@ public class LogicalRelSnapshotImpl implements LogicalRelSnapshot { ImmutableMap constraints; ImmutableMap foreignKeys; + ImmutableMap primaryKeys; ImmutableMap> keyToIndexes; @@ -87,9 +91,13 @@ public class LogicalRelSnapshotImpl implements LogicalRelSnapshot { ImmutableMap>, LogicalColumn> tableColumnNameColumn; ImmutableMap, LogicalColumn> tableIdColumnNameColumn; + ImmutableMap> tableConstraints; + ImmutableMap> tableForeignKeys; + ImmutableMap nodes; + ImmutableMap> connectedViews; diff --git a/core/src/main/java/org/polypheny/db/interpreter/Bindables.java b/core/src/main/java/org/polypheny/db/interpreter/Bindables.java index f352cce4d9..03cc698e5e 100644 --- a/core/src/main/java/org/polypheny/db/interpreter/Bindables.java +++ b/core/src/main/java/org/polypheny/db/interpreter/Bindables.java @@ -77,7 +77,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; @@ -168,7 +168,7 @@ public BindableScanRule( AlgBuilderFactory algBuilderFactory ) { @Override public void onMatch( AlgOptRuleCall call ) { final LogicalRelScan scan = call.alg( 0 ); - final LogicalEntity table = scan.entity; + final Entity table = scan.entity; if ( BindableScan.canHandle( table ) ) { call.transformTo( BindableScan.create( scan.getCluster(), scan.entity ) ); } @@ -180,7 +180,7 @@ public void onMatch( AlgOptRuleCall call ) { /** * Scan of a table that implements {@link ScannableEntity} and therefore can be converted into an {@link Enumerable}. */ - public static class BindableScan extends RelScan implements BindableAlg { + public static class BindableScan extends RelScan implements BindableAlg { public final ImmutableList filters; public final ImmutableList projects; @@ -191,7 +191,7 @@ public static class BindableScan extends RelScan implements Binda * * Use {@link #create} unless you know what you are doing. */ - BindableScan( AlgOptCluster cluster, AlgTraitSet traitSet, LogicalEntity entity, ImmutableList filters, ImmutableList projects ) { + BindableScan( AlgOptCluster cluster, AlgTraitSet traitSet, Entity entity, ImmutableList filters, ImmutableList projects ) { super( cluster, traitSet, entity ); this.filters = Objects.requireNonNull( filters ); this.projects = Objects.requireNonNull( projects ); @@ -202,7 +202,7 @@ public static class BindableScan extends RelScan implements Binda /** * Creates a BindableScan. */ - public static BindableScan create( AlgOptCluster cluster, LogicalEntity entity ) { + public static BindableScan create( AlgOptCluster cluster, Entity entity ) { return create( cluster, entity, ImmutableList.of(), identity( entity ) ); } @@ -210,7 +210,7 @@ public static BindableScan create( AlgOptCluster cluster, LogicalEntity entity ) /** * Creates a BindableScan. */ - public static BindableScan create( AlgOptCluster cluster, LogicalEntity entity, List filters, List projects ) { + public static BindableScan create( AlgOptCluster cluster, Entity entity, List filters, List projects ) { final AlgTraitSet traitSet = cluster.traitSetOf( BindableConvention.INSTANCE ) .replace( entity.dataModel.getModelTrait() ) @@ -267,7 +267,7 @@ public String algCompareString() { } - public static boolean canHandle( LogicalEntity entity ) { + public static boolean canHandle( Entity entity ) { return entity.unwrap( ScannableEntity.class ) != null || entity.unwrap( FilterableEntity.class ) != null || entity.unwrap( ProjectableFilterableEntity.class ) != null; diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java index 655126c9be..df4517739d 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java @@ -102,7 +102,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.algebra.type.DocumentType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.OperatorRegistry; import org.polypheny.db.nodes.Operator; @@ -191,7 +191,7 @@ public static boolean isOrder( AlgNode alg ) { /** * Returns a set of tables used by this expression or its children */ - public static Set findTables( AlgNode alg ) { + public static Set findTables( AlgNode alg ) { return new LinkedHashSet<>( findAllTables( alg ) ); } @@ -199,9 +199,9 @@ public static Set findTables( AlgNode alg ) { /** * Returns a list of all tables used by this expression or its children */ - public static List findAllTables( AlgNode alg ) { + public static List findAllTables( AlgNode alg ) { final Multimap, AlgNode> nodes = AlgMetadataQuery.instance().getNodeTypes( alg ); - final List usedTables = new ArrayList<>(); + final List usedTables = new ArrayList<>(); for ( Entry, Collection> e : nodes.asMap().entrySet() ) { if ( RelScan.class.isAssignableFrom( e.getKey() ) ) { for ( AlgNode node : e.getValue() ) { diff --git a/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java b/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java index 807ea8cd75..2ea75915a6 100644 --- a/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java +++ b/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java @@ -113,7 +113,7 @@ protected String computeDigest() { * * @param newRel new expression */ - void replaceRel( AlgNode newRel ) { + void replaceAlg( AlgNode newRel ) { currentAlg = newRel; } diff --git a/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java b/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java index ec1e8cb99a..53ebce7670 100644 --- a/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java +++ b/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java @@ -597,7 +597,7 @@ private boolean matchOperands( AlgOptRuleOperand operand, AlgNode alg, List childRels = (List) alg.getInputs(); + List childAlgs = (List) alg.getInputs(); switch ( operand.childPolicy ) { case ANY: return true; @@ -605,8 +605,8 @@ private boolean matchOperands( AlgOptRuleOperand operand, AlgNode alg, List children = new ArrayList<>( childRels.size() ); - for ( HepAlgVertex childRel : childRels ) { - children.add( childRel.getCurrentAlg() ); + final List children = new ArrayList<>( childAlgs.size() ); + for ( HepAlgVertex childAlg : childAlgs ) { + children.add( childAlg.getCurrentAlg() ); } nodeChildren.put( alg, children ); return true; default: int n = operand.getChildOperands().size(); - if ( childRels.size() < n ) { + if ( childAlgs.size() < n ) { return false; } - for ( Pair pair : Pair.zip( childRels, operand.getChildOperands() ) ) { + for ( Pair pair : Pair.zip( childAlgs, operand.getChildOperands() ) ) { boolean match = matchOperands( pair.right, pair.left.getCurrentAlg(), bindings, nodeChildren ); if ( !match ) { return false; @@ -637,16 +637,16 @@ private boolean matchOperands( AlgOptRuleOperand operand, AlgNode alg, List parentTrait ) { // TODO jvs 5-Apr-2006: Take the one that gives the best global cost rather than the best local cost. That requires "tentative" graph edits. assert !call.getResults().isEmpty(); - AlgNode bestRel = null; + AlgNode bestAlg = null; if ( call.getResults().size() == 1 ) { // No costing required; skip it to minimize the chance of hitting rels without cost information. - bestRel = call.getResults().get( 0 ); + bestAlg = call.getResults().get( 0 ); } else { AlgOptCost bestCost = null; final AlgMetadataQuery mq = call.getMetadataQuery(); @@ -656,15 +656,15 @@ private HepAlgVertex applyTransformationResults( HepAlgVertex vertex, HepRuleCal // Keep in the isTraceEnabled for the getRowCount method call LOGGER.trace( "considering {} with cumulative cost={} and rowcount={}", alg, thisCost, mq.getRowCount( alg ) ); } - if ( (bestRel == null) || thisCost.isLt( bestCost ) ) { - bestRel = alg; + if ( (bestAlg == null) || thisCost.isLt( bestCost ) ) { + bestAlg = alg; bestCost = thisCost; } } } ++nTransformations; - notifyTransformation( call, bestRel, true ); + notifyTransformation( call, bestAlg, true ); // Before we add the result, make a copy of the list of vertex's parents. We'll need this later during contraction so that we only update the existing parents, not the new parents (otherwise loops can result). // Also take care of filtering out parents by traits in case we're dealing with a converter rule. @@ -672,13 +672,13 @@ private HepAlgVertex applyTransformationResults( HepAlgVertex vertex, HepRuleCal final List parents = new ArrayList<>(); for ( HepAlgVertex parent : allParents ) { if ( parentTrait != null ) { - AlgNode parentRel = parent.getCurrentAlg(); - if ( parentRel instanceof Converter ) { + AlgNode parentAlg = parent.getCurrentAlg(); + if ( parentAlg instanceof Converter ) { // We don't support automatically chaining conversions. Treating a converter as a candidate parent here can cause the "iParentMatch" check below to // throw away a new converter needed in the multi-parent DAG case. continue; } - if ( !parentRel.getTraitSet().contains( parentTrait ) ) { + if ( !parentAlg.getTraitSet().contains( parentTrait ) ) { // This parent does not want the converted result. continue; } @@ -686,7 +686,7 @@ private HepAlgVertex applyTransformationResults( HepAlgVertex vertex, HepRuleCal parents.add( parent ); } - HepAlgVertex newVertex = addAlgToGraph( bestRel ); + HepAlgVertex newVertex = addAlgToGraph( bestAlg ); // There's a chance that newVertex is the same as one of the parents due to common subexpression recognition (e.g. the LogicalProject added by JoinCommuteRule). In that // case, treat the transformation as a nop to avoid creating a loop. @@ -700,13 +700,13 @@ private HepAlgVertex applyTransformationResults( HepAlgVertex vertex, HepRuleCal // Assume listener doesn't want to see garbage. collectGarbage(); } - notifyTransformation( call, bestRel, false ); + notifyTransformation( call, bestAlg, false ); dumpGraph(); return newVertex; } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public AlgNode register( AlgNode alg, AlgNode equivAlg ) { // Ignore; this call is mostly to tell Volcano how to avoid infinite loops. @@ -720,14 +720,14 @@ public void onCopy( AlgNode alg, AlgNode newAlg ) { } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public AlgNode ensureRegistered( AlgNode alg, AlgNode equivAlg ) { return alg; } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public boolean isRegistered( AlgNode alg ) { return true; @@ -740,7 +740,7 @@ private HepAlgVertex addAlgToGraph( AlgNode alg ) { return (HepAlgVertex) alg; } - // Recursively add children, replacing this rel's inputs with corresponding child vertices. + // Recursively add children, replacing this algs inputs with corresponding child vertices. final List inputs = alg.getInputs(); final List newInputs = new ArrayList<>(); for ( AlgNode input1 : inputs ) { @@ -749,9 +749,9 @@ private HepAlgVertex addAlgToGraph( AlgNode alg ) { } if ( !Util.equalShallow( inputs, newInputs ) ) { - AlgNode oldRel = alg; + AlgNode oldAlg = alg; alg = alg.copy( alg.getTraitSet(), newInputs ); - onCopy( oldRel, alg ); + onCopy( oldAlg, alg ); } // Compute digest first time we add to DAG, otherwise can't get equivVertex for common sub-expression alg.recomputeDigest(); @@ -792,18 +792,18 @@ private void contractVertices( HepAlgVertex preservedVertex, HepAlgVertex discar // Update specified parents of discardedVertex. for ( HepAlgVertex parent : parents ) { - AlgNode parentRel = parent.getCurrentAlg(); - List inputs = parentRel.getInputs(); + AlgNode parentAlg = parent.getCurrentAlg(); + List inputs = parentAlg.getInputs(); for ( int i = 0; i < inputs.size(); ++i ) { AlgNode child = inputs.get( i ); if ( child != discardedVertex ) { continue; } - parentRel.replaceInput( i, preservedVertex ); + parentAlg.replaceInput( i, preservedVertex ); } graph.removeEdge( parent, discardedVertex ); graph.addEdge( parent, preservedVertex ); - updateVertex( parent, parentRel ); + updateVertex( parent, parentAlg ); } // NOTE: we don't actually do graph.removeVertex(discardedVertex), because it might still be reachable from preservedVertex. Leave that job for garbage collection. @@ -828,7 +828,7 @@ private void updateVertex( HepAlgVertex vertex, AlgNode alg ) { // otherwise the digest will be removed wrongly in the mapDigestToVertex when collectGC so it must update the digest that map to vertex mapDigestToVertex.put( newDigest, vertex ); if ( alg != vertex.getCurrentAlg() ) { - vertex.replaceRel( alg ); + vertex.replaceAlg( alg ); } notifyEquivalence( alg, vertex, false ); } @@ -936,14 +936,14 @@ private void dumpGraph() { } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public void registerMetadataProviders( List list ) { list.add( 0, new HepAlgMetadataProvider() ); } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public long getAlgMetadataTimestamp( AlgNode alg ) { // TODO jvs 20-Apr-2006: This is overly conservative. Better would be to keep a timestamp per HepAlgVertex, and update only affected vertices and all ancestors on each transformation. diff --git a/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java b/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java index 7a90a7aaf0..3711ea191e 100644 --- a/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java +++ b/core/src/main/java/org/polypheny/db/processing/LogicalAlgAnalyzeShuttle.java @@ -64,7 +64,7 @@ import org.polypheny.db.algebra.logical.relational.LogicalSort; import org.polypheny.db.algebra.logical.relational.LogicalUnion; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.allocation.AllocationEntity; import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalTable; @@ -459,7 +459,7 @@ private void getAvailableColumns( AlgNode scan ) { private void getPartitioningInfo( LogicalFilter filter ) { - LogicalEntity table = filter.getInput().getEntity(); + Entity table = filter.getInput().getEntity(); if ( table == null ) { return; } @@ -468,7 +468,7 @@ private void getPartitioningInfo( LogicalFilter filter ) { } - private void handleIfPartitioned( AlgNode node, LogicalEntity logicalEntity ) { + private void handleIfPartitioned( AlgNode node, Entity logicalEntity ) { // Only if table is partitioned if ( Catalog.snapshot().alloc().getPlacementsFromLogical( logicalEntity.id ).size() > 1 || Catalog.snapshot().alloc().getPartitionsFromLogical( logicalEntity.id ).size() > 1 ) { @@ -495,22 +495,22 @@ private void handleIfPartitioned( AlgNode node, LogicalEntity logicalEntity ) { private void getPartitioningInfo( LogicalDocumentFilter filter ) { - LogicalEntity entity = filter.getInput().getEntity(); + Entity entity = filter.getInput().getEntity(); if ( entity == null ) { return; } - handleIfPartitioned( filter, entity.unwrap( LogicalEntity.class ) ); + handleIfPartitioned( filter, entity.unwrap( Entity.class ) ); } private void getPartitioningInfo( LogicalLpgFilter filter ) { - LogicalEntity entity = filter.getInput().getEntity(); + Entity entity = filter.getInput().getEntity(); if ( entity == null ) { return; } - handleIfPartitioned( filter, entity.unwrap( LogicalEntity.class ) ); + handleIfPartitioned( filter, entity.unwrap( Entity.class ) ); } diff --git a/core/src/main/java/org/polypheny/db/rex/RexTableIndexRef.java b/core/src/main/java/org/polypheny/db/rex/RexTableIndexRef.java index aa941a1395..def6b1c3af 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexTableIndexRef.java +++ b/core/src/main/java/org/polypheny/db/rex/RexTableIndexRef.java @@ -41,7 +41,7 @@ import org.polypheny.db.algebra.metadata.BuiltInMetadata.ExpressionLineage; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; /** @@ -132,12 +132,12 @@ public Kind getKind() { @Getter public static class AlgTableRef implements Comparable { - private final LogicalEntity table; + private final Entity table; private final int entityNumber; private final String digest; - private AlgTableRef( LogicalEntity table, int entityNumber ) { + private AlgTableRef( Entity table, int entityNumber ) { this.table = table; this.entityNumber = entityNumber; this.digest = table.id + ".#" + entityNumber; @@ -170,7 +170,7 @@ public String toString() { } - public static AlgTableRef of( LogicalEntity table, int entityNumber ) { + public static AlgTableRef of( Entity table, int entityNumber ) { return new AlgTableRef( table, entityNumber ); } diff --git a/core/src/main/java/org/polypheny/db/schema/Namespace.java b/core/src/main/java/org/polypheny/db/schema/Namespace.java index 5c965f3fb4..9dff48645b 100644 --- a/core/src/main/java/org/polypheny/db/schema/Namespace.java +++ b/core/src/main/java/org/polypheny/db/schema/Namespace.java @@ -38,7 +38,7 @@ import java.util.Set; import org.apache.calcite.linq4j.tree.Expression; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.Convention; import org.polypheny.db.util.Wrapper; @@ -95,7 +95,7 @@ default Long getAdapterId() { * @param name Table name * @return Table, or null */ - LogicalEntity getEntity( String name ); + Entity getEntity( String name ); /** * Returns the names of the tables in this schema. diff --git a/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntityQueryable.java b/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntityQueryable.java index 2d8cc9986f..d0c02e1efc 100644 --- a/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntityQueryable.java +++ b/core/src/main/java/org/polypheny/db/schema/impl/AbstractEntityQueryable.java @@ -43,7 +43,7 @@ import org.jetbrains.annotations.NotNull; import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.java.AbstractQueryableEntity; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.schema.types.QueryableEntity; @@ -55,7 +55,7 @@ * * @param element type */ -public abstract class AbstractEntityQueryable extends AbstractQueryable { +public abstract class AbstractEntityQueryable extends AbstractQueryable { public final DataContext dataContext; public final Snapshot snapshot; diff --git a/core/src/main/java/org/polypheny/db/schema/impl/AbstractNamespace.java b/core/src/main/java/org/polypheny/db/schema/impl/AbstractNamespace.java index 96219bcf11..4ce2f667a9 100644 --- a/core/src/main/java/org/polypheny/db/schema/impl/AbstractNamespace.java +++ b/core/src/main/java/org/polypheny/db/schema/impl/AbstractNamespace.java @@ -43,7 +43,7 @@ import lombok.Getter; import org.apache.calcite.linq4j.tree.Expression; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.Convention; import org.polypheny.db.schema.Function; @@ -108,7 +108,7 @@ public Expression getExpression( Snapshot snapshot, long id ) { * * @return Map of tables in this schema by name */ - protected Map getTables() { + protected Map getTables() { return ImmutableMap.of(); } @@ -120,7 +120,7 @@ public final Set getEntityNames() { @Override - public final LogicalEntity getEntity( String name ) { + public final Entity getEntity( String name ) { return getTables().get( name ); } diff --git a/core/src/main/java/org/polypheny/db/schema/impl/DelegatingNamespace.java b/core/src/main/java/org/polypheny/db/schema/impl/DelegatingNamespace.java index ee88a94cb3..fb0bdd928f 100644 --- a/core/src/main/java/org/polypheny/db/schema/impl/DelegatingNamespace.java +++ b/core/src/main/java/org/polypheny/db/schema/impl/DelegatingNamespace.java @@ -38,7 +38,7 @@ import java.util.Set; import org.apache.calcite.linq4j.tree.Expression; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.Convention; import org.polypheny.db.schema.Function; @@ -95,7 +95,7 @@ public Expression getExpression( Snapshot snapshot, long id ) { @Override - public LogicalEntity getEntity( String name ) { + public Entity getEntity( String name ) { return namespace.getEntity( name ); } diff --git a/core/src/main/java/org/polypheny/db/schema/types/ModifiableCollection.java b/core/src/main/java/org/polypheny/db/schema/types/ModifiableCollection.java index 41b03a5528..16f6d1926d 100644 --- a/core/src/main/java/org/polypheny/db/schema/types/ModifiableCollection.java +++ b/core/src/main/java/org/polypheny/db/schema/types/ModifiableCollection.java @@ -21,7 +21,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.common.Modify.Operation; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexNode; @@ -31,7 +31,7 @@ public interface ModifiableCollection extends Typed { Modify toModificationCollection( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity collection, + Entity collection, AlgNode child, Operation operation, Map updates, diff --git a/core/src/main/java/org/polypheny/db/schema/types/ModifiableGraph.java b/core/src/main/java/org/polypheny/db/schema/types/ModifiableGraph.java index fc8cc1626b..2a317fd94e 100644 --- a/core/src/main/java/org/polypheny/db/schema/types/ModifiableGraph.java +++ b/core/src/main/java/org/polypheny/db/schema/types/ModifiableGraph.java @@ -20,7 +20,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.common.Modify.Operation; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexNode; @@ -31,7 +31,7 @@ public interface ModifiableGraph extends Typed { Modify toModificationGraph( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity entity, + Entity entity, AlgNode child, Operation operation, List targets, diff --git a/core/src/main/java/org/polypheny/db/schema/types/ModifiableTable.java b/core/src/main/java/org/polypheny/db/schema/types/ModifiableTable.java index 9874b0de57..e35ec313c8 100644 --- a/core/src/main/java/org/polypheny/db/schema/types/ModifiableTable.java +++ b/core/src/main/java/org/polypheny/db/schema/types/ModifiableTable.java @@ -20,7 +20,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.common.Modify.Operation; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexNode; @@ -30,7 +30,7 @@ public interface ModifiableTable extends Typed { Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity physicalEntity, + Entity physicalEntity, AlgNode child, Operation operation, List targets, 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 c0f22784fc..da74890328 100644 --- a/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java +++ b/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java @@ -105,7 +105,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalGraph; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; @@ -1371,7 +1371,7 @@ public AlgBuilder scan( List tableNames ) { } - public AlgBuilder scan( @Nonnull LogicalEntity entity ) { + public AlgBuilder scan( @Nonnull Entity entity ) { final AlgNode scan = scanFactory.createScan( cluster, entity ); push( scan ); rename( entity.getRowType().getFieldNames() ); @@ -1412,7 +1412,7 @@ public AlgBuilder scan( String... tableNames ) { } - public AlgBuilder documentScan( LogicalEntity collection ) { + public AlgBuilder documentScan( Entity collection ) { stack.add( new Frame( new LogicalDocumentScan( cluster, cluster.traitSet().replace( ModelTrait.DOCUMENT ), collection ) ) ); return this; } @@ -1437,7 +1437,7 @@ public AlgBuilder lpgScan( long logicalId ) { } - public AlgBuilder lpgScan( LogicalEntity entity ) { + public AlgBuilder lpgScan( Entity entity ) { stack.add( new Frame( new LogicalLpgScan( cluster, cluster.traitSet().replace( ModelTrait.GRAPH ), entity, entity.getRowType() ) ) ); return this; } diff --git a/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java b/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java index 664c0fe7cb..91b0ea96fb 100644 --- a/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java +++ b/core/src/main/java/org/polypheny/db/util/InitializerExpressionFactory.java @@ -19,7 +19,7 @@ import java.util.List; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.nodes.Operator; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.ColumnStrategy; @@ -37,7 +37,7 @@ public interface InitializerExpressionFactory { * @param iColumn the 0-based offset of the column in the table * @return generation strategy, never null */ - ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ); + ColumnStrategy generationStrategy( Entity table, int iColumn ); /** * Creates an expression which evaluates to the default value for a particular column. @@ -47,7 +47,7 @@ public interface InitializerExpressionFactory { * @param context Context for creating the expression * @return default value expression */ - RexNode newColumnDefaultValue( LogicalEntity table, int iColumn, InitializerContext context ); + RexNode newColumnDefaultValue( Entity table, int iColumn, InitializerContext context ); /** * Creates an expression which evaluates to the initializer expression for a particular attribute of a structured type. diff --git a/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java b/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java index c200c913db..06bc097496 100644 --- a/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java +++ b/core/src/main/java/org/polypheny/db/util/NullInitializerExpressionFactory.java @@ -19,7 +19,7 @@ import java.util.List; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.nodes.Operator; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.ColumnStrategy; @@ -38,7 +38,7 @@ public NullInitializerExpressionFactory() { @Override - public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { + public ColumnStrategy generationStrategy( Entity table, int iColumn ) { return table.getRowType().getFields().get( iColumn ).getType().isNullable() ? ColumnStrategy.NULLABLE : ColumnStrategy.NOT_NULLABLE; @@ -46,7 +46,7 @@ public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { @Override - public RexNode newColumnDefaultValue( LogicalEntity table, int iColumn, InitializerContext context ) { + public RexNode newColumnDefaultValue( Entity table, int iColumn, InitializerContext context ) { return context.getRexBuilder().constantNull(); } diff --git a/core/src/main/java/org/polypheny/db/util/Util.java b/core/src/main/java/org/polypheny/db/util/Util.java index ff3ef193b2..9063a0e2c9 100644 --- a/core/src/main/java/org/polypheny/db/util/Util.java +++ b/core/src/main/java/org/polypheny/db/util/Util.java @@ -102,7 +102,7 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.fun.AggFunction; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.nodes.BasicNodeVisitor; @@ -2022,7 +2022,7 @@ public static Iterator filter( Iterator iterator, Predicate predica } - public static Monotonicity getMonotonicity( LogicalEntity entity, String columnName ) { + public static Monotonicity getMonotonicity( Entity entity, String columnName ) { if ( entity.dataModel != DataModel.RELATIONAL ) { return Monotonicity.NOT_MONOTONIC; } diff --git a/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java b/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java index bf991241b4..3bb804a4c8 100644 --- a/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java +++ b/core/src/test/java/org/polypheny/db/catalog/CountingFactory.java @@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.nodes.Operator; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexNode; @@ -51,7 +51,7 @@ public class CountingFactory extends NullInitializerExpressionFactory { @Override - public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { + public ColumnStrategy generationStrategy( Entity table, int iColumn ) { final AlgDataTypeField field = table.getRowType().getFields().get( iColumn ); if ( defaultColumns.contains( field.getName() ) ) { return ColumnStrategy.DEFAULT; @@ -61,7 +61,7 @@ public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { @Override - public RexNode newColumnDefaultValue( LogicalEntity table, int iColumn, InitializerContext context ) { + public RexNode newColumnDefaultValue( Entity table, int iColumn, InitializerContext context ) { THREAD_CALL_COUNT.get().incrementAndGet(); final AlgDataTypeField field = table.getRowType().getFields().get( iColumn ); if ( defaultColumns.contains( field.getName() ) ) { diff --git a/core/src/test/java/org/polypheny/db/catalog/EmpInitializerExpressionFactory.java b/core/src/test/java/org/polypheny/db/catalog/EmpInitializerExpressionFactory.java index e8e8ee679a..d19b6931a8 100644 --- a/core/src/test/java/org/polypheny/db/catalog/EmpInitializerExpressionFactory.java +++ b/core/src/test/java/org/polypheny/db/catalog/EmpInitializerExpressionFactory.java @@ -19,7 +19,7 @@ import java.math.BigDecimal; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.rex.RexBuilder; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.ColumnStrategy; @@ -34,7 +34,7 @@ class EmpInitializerExpressionFactory extends NullInitializerExpressionFactory { @Override - public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { + public ColumnStrategy generationStrategy( Entity table, int iColumn ) { switch ( iColumn ) { case 0: case 1: @@ -47,7 +47,7 @@ public ColumnStrategy generationStrategy( LogicalEntity table, int iColumn ) { @Override - public RexNode newColumnDefaultValue( LogicalEntity table, int iColumn, InitializerContext context ) { + public RexNode newColumnDefaultValue( Entity table, int iColumn, InitializerContext context ) { final RexBuilder rexBuilder = context.getRexBuilder(); final AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); switch ( iColumn ) { diff --git a/core/src/test/java/org/polypheny/db/schemas/HrClusteredSchema.java b/core/src/test/java/org/polypheny/db/schemas/HrClusteredSchema.java index d4c79945bf..f084b590f4 100644 --- a/core/src/test/java/org/polypheny/db/schemas/HrClusteredSchema.java +++ b/core/src/test/java/org/polypheny/db/schemas/HrClusteredSchema.java @@ -47,7 +47,7 @@ import org.polypheny.db.algebra.AlgFieldCollation; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.schema.Namespace.Schema; @@ -64,7 +64,7 @@ */ public final class HrClusteredSchema extends AbstractNamespace implements Schema { - private final ImmutableMap tables; + private final ImmutableMap tables; public HrClusteredSchema( long id ) { @@ -106,7 +106,7 @@ public HrClusteredSchema( long id ) { @Override - protected Map getTables() { + protected Map getTables() { return tables; } 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 1290e6e031..cb50718b84 100644 --- a/core/src/test/java/org/polypheny/db/test/JdbcTest.java +++ b/core/src/test/java/org/polypheny/db/test/JdbcTest.java @@ -21,7 +21,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.impl.AbstractEntity; @@ -46,7 +46,7 @@ protected AbstractModifiableTable( String tableName ) { //@Override public RelModify toModificationAlg( AlgOptCluster cluster, - LogicalEntity entity, + Entity entity, AlgNode child, RelModify.Operation operation, List updateColumnList, diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index f820cb2d53..af42d9d428 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -124,7 +124,7 @@ public class PolyphenyDb { public boolean daemonMode = false; @Option(name = { "-defaultStore" }, description = "Type of default storeId") - public String defaultStoreName = "monetdb"; + public String defaultStoreName = "mongodb"; @Option(name = { "-defaultSource" }, description = "Type of default source") public String defaultSourceName = "csv"; 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 ea2bc5b02f..a9ac3b2c98 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -77,7 +77,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -1285,7 +1285,7 @@ private Map> getAccessedPartitionsPerScan( AlgNode alg, Map handleDocScan( + public DocumentScan handleDocScan( DocumentScan scan, Statement statement, @Nullable List excludedPlacements ) { diff --git a/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java b/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java index 43e402bc13..37776eea57 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/EntityAccessMap.java @@ -42,7 +42,7 @@ import org.polypheny.db.algebra.core.lpg.LpgScan; import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.allocation.AllocationEntity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -228,7 +228,7 @@ public Mode getEntityAccessMode( @NonNull EntityAccessMap.EntityIdentifier entit * @param table table of interest * @return qualified name */ - public EntityIdentifier getQualifiedName( LogicalEntity table, long partitionId ) { + public EntityIdentifier getQualifiedName( Entity table, long partitionId ) { return new EntityIdentifier( table.id, partitionId, NamespaceLevel.ENTITY_LEVEL ); } @@ -242,7 +242,7 @@ private class TableRelVisitor extends AlgVisitor { @Override public void visit( AlgNode p, int ordinal, AlgNode parent ) { super.visit( p, ordinal, parent ); - LogicalEntity table = p.getEntity(); + Entity table = p.getEntity(); if ( table == null ) { return; } diff --git a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/QueryResult.java b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/QueryResult.java index 5349fa78be..7fe5dcd5c8 100644 --- a/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/QueryResult.java +++ b/monitoring/src/main/java/org/polypheny/db/monitoring/statistics/QueryResult.java @@ -19,7 +19,7 @@ import lombok.Data; import lombok.Getter; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalColumn; @@ -30,11 +30,11 @@ @Data class QueryResult { - private final LogicalEntity entity; + private final Entity entity; private final LogicalColumn column; - QueryResult( LogicalEntity entity, LogicalColumn column ) { + QueryResult( Entity entity, LogicalColumn column ) { this.entity = entity; this.column = column; } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index 7e8f48a2ca..259c686766 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -77,9 +77,8 @@ import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalDatabase.PrimitiveCatalogDatabase; -import org.polypheny.db.catalog.entity.LogicalObject; import org.polypheny.db.catalog.entity.LogicalUser; +import org.polypheny.db.catalog.entity.PolyObject; import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalColumn.PrimitiveCatalogColumn; import org.polypheny.db.catalog.entity.logical.LogicalForeignKey; @@ -146,7 +145,7 @@ public class DbmsMeta implements ProtobufMeta { public static final boolean SEND_FIRST_FRAME_WITH_RESPONSE = false; - private final ConcurrentMap openConnections = new ConcurrentHashMap<>(); + private final ConcurrentMap openConnections = new ConcurrentHashMap<>(); private final ConcurrentMap openStatements = new ConcurrentHashMap<>(); final Calendar calendar = Unsafe.localCalendar(); @@ -252,9 +251,9 @@ private MetaResultSet createMetaResultSet( final ConnectionHandle ch, final } - private Enumerable toEnumerable( final List entities ) { + private Enumerable toEnumerable( final List entities ) { final List objects = new LinkedList<>(); - for ( LogicalObject entity : entities ) { + for ( PolyObject entity : entities ) { objects.add( entity.getParameterArray() ); } return Linq4j.asEnumerable( objects ); @@ -268,7 +267,7 @@ private Enumerable toEnumerable( final List ent */ @Override public Map getDatabaseProperties( ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getDatabaseProperties( ConnectionHandle {} )", ch ); @@ -286,7 +285,7 @@ public Map getDatabaseProperties( ConnectionHandle ch // TODO: typeList is ignored @Override public MetaResultSet getTables( final ConnectionHandle ch, final String database, final Pat schemaPattern, final Pat tablePattern, final List typeList ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getTables( ConnectionHandle {}, String {}, Pat {}, Pat {}, List {} )", ch, database, schemaPattern, tablePattern, typeList ); @@ -334,7 +333,7 @@ private List getLogicalTables( Pattern schemaPattern, Pattern tabl @Override public MetaResultSet getColumns( final ConnectionHandle ch, final String database, final Pat schemaPattern, final Pat tablePattern, final Pat columnPattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getAllocColumns( ConnectionHandle {}, String {}, Pat {}, Pat {}, Pat {} )", ch, database, schemaPattern, tablePattern, columnPattern ); @@ -377,7 +376,7 @@ public MetaResultSet getColumns( final ConnectionHandle ch, final String databas @Override public MetaResultSet getSchemas( final ConnectionHandle ch, final String database, final Pat schemaPattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getNamespaces( ConnectionHandle {}, String {}, Pat {} )", ch, database, schemaPattern ); @@ -404,7 +403,7 @@ public MetaResultSet getSchemas( final ConnectionHandle ch, final String databas @Override public MetaResultSet getCatalogs( final ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getCatalogs( ConnectionHandle {} )", ch ); @@ -416,7 +415,7 @@ public MetaResultSet getCatalogs( final ConnectionHandle ch ) { ch, statementHandle, Linq4j.asEnumerable( databases ), - PrimitiveCatalogDatabase.class, + PrimitiveDatabase.class, // According to JDBC standard: "TABLE_CAT", // Polypheny-DB specific extensions: @@ -429,7 +428,7 @@ public MetaResultSet getCatalogs( final ConnectionHandle ch ) { @Override public MetaResultSet getTableTypes( final ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getTableTypes( ConnectionHandle {} )", ch ); @@ -453,7 +452,7 @@ public MetaResultSet getTableTypes( final ConnectionHandle ch ) { @Override public MetaResultSet getProcedures( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat procedureNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getProcedures( ConnectionHandle {}, String {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, procedureNamePattern ); @@ -467,7 +466,7 @@ public MetaResultSet getProcedures( final ConnectionHandle ch, final String cata @Override public MetaResultSet getProcedureColumns( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat procedureNamePattern, final Pat columnNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getProcedureColumns( ConnectionHandle {}, String {}, Pat {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, procedureNamePattern, columnNamePattern ); @@ -481,7 +480,7 @@ public MetaResultSet getProcedureColumns( final ConnectionHandle ch, final Strin @Override public MetaResultSet getColumnPrivileges( final ConnectionHandle ch, final String catalog, final String schema, final String table, final Pat columnNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getColumnPrivileges( ConnectionHandle {}, String {}, String {}, String {}, Pat {} )", ch, catalog, schema, table, columnNamePattern ); @@ -497,7 +496,7 @@ public MetaResultSet getColumnPrivileges( final ConnectionHandle ch, final Strin @Override public MetaResultSet getTablePrivileges( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat tableNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getTablePrivileges( ConnectionHandle {}, String {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, tableNamePattern ); @@ -513,7 +512,7 @@ public MetaResultSet getTablePrivileges( final ConnectionHandle ch, final String @Override public MetaResultSet getBestRowIdentifier( final ConnectionHandle ch, final String catalog, final String schema, final String table, final int scope, final boolean nullable ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getBestRowIdentifier( ConnectionHandle {}, String {}, String {}, String {}, int {}, boolean {} )", ch, catalog, schema, table, scope, nullable ); @@ -527,7 +526,7 @@ public MetaResultSet getBestRowIdentifier( final ConnectionHandle ch, final Stri @Override public MetaResultSet getVersionColumns( final ConnectionHandle ch, final String catalog, final String schema, final String table ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getVersionColumns( ConnectionHandle {}, String {}, String {}, String {} )", ch, catalog, schema, table ); @@ -541,7 +540,7 @@ public MetaResultSet getVersionColumns( final ConnectionHandle ch, final String @Override public MetaResultSet getPrimaryKeys( final ConnectionHandle ch, final String database, final String schema, final String table ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getPrimaryKeys( ConnectionHandle {}, String {}, String {}, String {} )", ch, database, schema, table ); @@ -578,7 +577,7 @@ public MetaResultSet getPrimaryKeys( final ConnectionHandle ch, final String dat @SuppressWarnings("Duplicates") @Override public MetaResultSet getImportedKeys( final ConnectionHandle ch, final String database, final String schema, final String table ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getImportedKeys( ConnectionHandle {}, String {}, String {}, String {} )", ch, database, schema, table ); @@ -621,7 +620,7 @@ public MetaResultSet getImportedKeys( final ConnectionHandle ch, final String da @SuppressWarnings("Duplicates") @Override public MetaResultSet getExportedKeys( final ConnectionHandle ch, final String database, final String schema, final String table ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getExportedKeys( ConnectionHandle {}, String {}, String {}, String {} )", ch, database, schema, table ); @@ -663,7 +662,7 @@ public MetaResultSet getExportedKeys( final ConnectionHandle ch, final String da @Override public MetaResultSet getCrossReference( final ConnectionHandle ch, final String parentCatalog, final String parentSchema, final String parentTable, final String foreignCatalog, final String foreignSchema, final String foreignTable ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getCrossReference( ConnectionHandle {}, String {}, String {}, String {}, String {}, String {}, String {} )", ch, parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable ); @@ -679,7 +678,7 @@ public MetaResultSet getCrossReference( final ConnectionHandle ch, final String @Override public MetaResultSet getTypeInfo( final ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getTypeInfo( ConnectionHandle {} )", ch ); @@ -738,7 +737,7 @@ public MetaResultSet getTypeInfo( final ConnectionHandle ch ) { @Override public MetaResultSet getIndexInfo( final ConnectionHandle ch, final String database, final String schema, final String table, final boolean unique, final boolean approximate ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getIndexInfo( ConnectionHandle {}, String {}, String {}, String {}, boolean {}, boolean {} )", ch, database, schema, table, unique, approximate ); @@ -781,7 +780,7 @@ public MetaResultSet getIndexInfo( final ConnectionHandle ch, final String datab @Override public MetaResultSet getUDTs( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat typeNamePattern, final int[] types ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getUDTs( ConnectionHandle {}, String {}, Pat {}, Pat {}, int[] {} )", ch, catalog, schemaPattern, typeNamePattern, types ); @@ -795,7 +794,7 @@ public MetaResultSet getUDTs( final ConnectionHandle ch, final String catalog, f @Override public MetaResultSet getSuperTypes( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat typeNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getSuperTypes( ConnectionHandle {}, String {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, typeNamePattern ); @@ -809,7 +808,7 @@ public MetaResultSet getSuperTypes( final ConnectionHandle ch, final String cata @Override public MetaResultSet getSuperTables( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat tableNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getSuperTables( ConnectionHandle {}, String {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, tableNamePattern ); @@ -823,7 +822,7 @@ public MetaResultSet getSuperTables( final ConnectionHandle ch, final String cat @Override public MetaResultSet getAttributes( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat typeNamePattern, final Pat attributeNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getAttributes( ConnectionHandle {}, String {}, Pat {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, typeNamePattern, attributeNamePattern ); @@ -837,7 +836,7 @@ public MetaResultSet getAttributes( final ConnectionHandle ch, final String cata @Override public MetaResultSet getClientInfoProperties( final ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getClientInfoProperties( ConnectionHandle {} )", ch ); @@ -851,7 +850,7 @@ public MetaResultSet getClientInfoProperties( final ConnectionHandle ch ) { @Override public MetaResultSet getFunctions( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat functionNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getFunctions( ConnectionHandle {}, String {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, functionNamePattern ); @@ -865,7 +864,7 @@ public MetaResultSet getFunctions( final ConnectionHandle ch, final String catal @Override public MetaResultSet getFunctionColumns( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat functionNamePattern, final Pat columnNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getFunctionColumns( ConnectionHandle {}, String {}, Pat {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, functionNamePattern, columnNamePattern ); @@ -879,7 +878,7 @@ public MetaResultSet getFunctionColumns( final ConnectionHandle ch, final String @Override public MetaResultSet getPseudoColumns( final ConnectionHandle ch, final String catalog, final Pat schemaPattern, final Pat tableNamePattern, final Pat columnNamePattern ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "getPseudoColumns( ConnectionHandle {}, String {}, Pat {}, Pat {}, Pat {} )", ch, catalog, schemaPattern, tableNamePattern, columnNamePattern ); @@ -900,7 +899,7 @@ public MetaResultSet getPseudoColumns( final ConnectionHandle ch, final String c */ @Override public ExecuteBatchResult executeBatchProtobuf( final StatementHandle h, final List parameterValues ) throws NoSuchStatementException { - final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); + final PolyConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "executeBatchProtobuf( StatementHandle {}, List {} )", h, parameterValues ); @@ -959,7 +958,7 @@ public ExecuteBatchResult executeBatchProtobuf( final StatementHandle h, final L */ @Override public Iterable createIterable( final StatementHandle h, final QueryState state, final Signature signature, final List parameters, final Frame firstFrame ) { - final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); + final PolyConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "createExternalIterable( StatementHandle {}, QueryState {}, Signature {}, List {}, Frame {} )", h, state, signature, parameters, firstFrame ); @@ -981,7 +980,7 @@ public Iterable createIterable( final StatementHandle h, final QueryStat */ @Override public StatementHandle prepare( final ConnectionHandle ch, final String sql, final long maxRowCount ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "prepare( ConnectionHandle {}, String {}, long {} )", ch, sql, maxRowCount ); @@ -1061,7 +1060,7 @@ public ExecuteResult prepareAndExecute( final StatementHandle h, final String sq */ @Override public ExecuteResult prepareAndExecute( final StatementHandle h, final String sql, final long maxRowCount, final int maxRowsInFirstFrame, final PrepareCallback callback ) throws NoSuchStatementException { - final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); + final PolyConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "prepareAndExecute( StatementHandle {}, String {}, long {}, int {}, PrepareCallback {} )", h, sql, maxRowCount, maxRowsInFirstFrame, callback ); @@ -1084,7 +1083,7 @@ public ExecuteResult prepareAndExecute( final StatementHandle h, final String sq */ @Override public ExecuteBatchResult prepareAndExecuteBatch( final StatementHandle h, final List sqlCommands ) throws NoSuchStatementException { - final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); + final PolyConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "prepareAndExecuteBatch( StatementHandle {}, List {} )", h, sqlCommands ); @@ -1105,7 +1104,7 @@ public ExecuteBatchResult prepareAndExecuteBatch( final StatementHandle h, final */ @Override public ExecuteBatchResult executeBatch( final StatementHandle h, final List> parameterValues ) throws NoSuchStatementException { - final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); + final PolyConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "executeBatch( StatementHandle {}, List> {} )", h, parameterValues ); @@ -1129,7 +1128,7 @@ public ExecuteBatchResult executeBatch( final StatementHandle h, final List pa */ @Override public ExecuteResult execute( final StatementHandle h, final List parameterValues, final int maxRowsInFirstFrame ) throws NoSuchStatementException { - final PolyphenyDbConnectionHandle connection = openConnections.get( h.connectionId ); + final PolyConnectionHandle connection = openConnections.get( h.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "execute( StatementHandle {}, List {}, int {} )", h, parameterValues, maxRowsInFirstFrame ); @@ -1216,7 +1215,7 @@ public ExecuteResult execute( final StatementHandle h, final List pa } - private ExecuteResult execute( StatementHandle h, List parameterValues, int maxRowsInFirstFrame, PolyphenyDbConnectionHandle connection ) throws NoSuchStatementException { + private ExecuteResult execute( StatementHandle h, List parameterValues, int maxRowsInFirstFrame, PolyConnectionHandle connection ) throws NoSuchStatementException { final PolyStatementHandle statementHandle = getPolyphenyDbStatementHandle( h ); long index = 0; @@ -1394,7 +1393,7 @@ public Enumerator enumerator() { } - private List execute( StatementHandle h, PolyphenyDbConnectionHandle connection, PolyStatementHandle statementHandle, int maxRowsInFirstFrame ) { + private List execute( StatementHandle h, PolyConnectionHandle connection, PolyStatementHandle statementHandle, int maxRowsInFirstFrame ) { List resultSets; if ( statementHandle.getSignature().statementType == StatementType.OTHER_DDL ) { MetaResultSet resultSet = MetaResultSet.count( statementHandle.getConnection().getConnectionId().toString(), h.id, 1 ); @@ -1441,7 +1440,7 @@ private List execute( StatementHandle h, PolyphenyDbConnectionHan */ @Override public StatementHandle createStatement( ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "createStatement( ConnectionHandle {} )", ch ); @@ -1469,7 +1468,7 @@ public StatementHandle createStatement( ConnectionHandle ch ) { */ @Override public void closeStatement( final StatementHandle statementHandle ) { - final PolyphenyDbConnectionHandle connection = openConnections.get( statementHandle.connectionId ); + final PolyConnectionHandle connection = openConnections.get( statementHandle.connectionId ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "closeStatement( StatementHandle {} )", statementHandle ); @@ -1551,7 +1550,7 @@ public void openConnection( final ConnectionHandle ch, final Map throw new GenericRuntimeException( e.getLocalizedMessage(), -1, "", AvaticaSeverity.ERROR ); } - openConnections.put( ch.id, new PolyphenyDbConnectionHandle( ch, user, ch.id, null, namespace, transactionManager ) ); + openConnections.put( ch.id, new PolyConnectionHandle( ch, user, ch.id, namespace, transactionManager ) ); } @@ -1560,13 +1559,13 @@ public void openConnection( final ConnectionHandle ch, final Map */ @Override public void closeConnection( ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "closeConnection( ConnectionHandle {} )", ch ); } - final PolyphenyDbConnectionHandle connectionToClose = openConnections.remove( ch.id ); + final PolyConnectionHandle connectionToClose = openConnections.remove( ch.id ); if ( connectionToClose == null ) { if ( log.isDebugEnabled() ) { log.debug( "Connection {} already closed.", ch.id ); @@ -1598,7 +1597,7 @@ public void closeConnection( ConnectionHandle ch ) { } - private PolyphenyDbConnectionHandle getPolyphenyDbConnectionHandle( String connectionId ) { + private PolyConnectionHandle getPolyphenyDbConnectionHandle( String connectionId ) { if ( openConnections.containsKey( connectionId ) ) { return openConnections.get( connectionId ); } else { @@ -1639,7 +1638,7 @@ public boolean syncResults( final StatementHandle sh, final QueryState state, fi */ @Override public void commit( final ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "commit( ConnectionHandle {} )", ch ); @@ -1669,7 +1668,7 @@ public void commit( final ConnectionHandle ch ) { */ @Override public void rollback( final ConnectionHandle ch ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "rollback( ConnectionHandle {} )", ch ); @@ -1702,13 +1701,13 @@ public void rollback( final ConnectionHandle ch ) { */ @Override public ConnectionProperties connectionSync( ConnectionHandle ch, ConnectionProperties connProps ) { - final PolyphenyDbConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); + final PolyConnectionHandle connection = getPolyphenyDbConnectionHandle( ch.id ); synchronized ( connection ) { if ( log.isTraceEnabled() ) { log.trace( "connectionSync( ConnectionHandle {}, ConnectionProperties {} )", ch, connProps ); } - final PolyphenyDbConnectionHandle connectionToSync = openConnections.get( ch.id ); + final PolyConnectionHandle connectionToSync = openConnections.get( ch.id ); if ( connectionToSync == null ) { if ( log.isDebugEnabled() ) { log.debug( "Connection {} is not execute.", ch.id ); @@ -1801,9 +1800,9 @@ public void updateConnectionNumberTable() { public void updateConnectionListTable() { connectionListTable.reset(); - for ( Entry entry : openConnections.entrySet() ) { + for ( Entry entry : openConnections.entrySet() ) { String connectionId = entry.getKey(); - PolyphenyDbConnectionHandle connectionHandle = entry.getValue(); + PolyConnectionHandle connectionHandle = entry.getValue(); Transaction currentTx = connectionHandle.getCurrentTransaction(); String txId = "-"; if ( currentTx != null ) { diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbConnectionHandle.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyConnectionHandle.java similarity index 73% rename from plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbConnectionHandle.java rename to plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyConnectionHandle.java index cffaaa75ee..c3102fee5c 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbConnectionHandle.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyConnectionHandle.java @@ -24,7 +24,6 @@ import org.apache.calcite.avatica.Meta.ConnectionHandle; import org.apache.calcite.avatica.Meta.ConnectionProperties; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalDatabase; import org.polypheny.db.catalog.entity.LogicalUser; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.transaction.PUID.ConnectionId; @@ -36,7 +35,7 @@ /** * */ -public class PolyphenyDbConnectionHandle { +public class PolyConnectionHandle { private final Meta.ConnectionHandle handle; @@ -44,38 +43,24 @@ public class PolyphenyDbConnectionHandle { @Getter private final LogicalUser user; - private final LogicalDatabase database; private final LogicalNamespace namespace; @Getter private final ConnectionId connectionId; private Transaction currentTransaction; - private PolyphenyDbResultSet currentOpenResultSet; + private PolyResultSet currentOpenResultSet; private final TransactionManager transactionManager; private final ConnectionProperties connectionProperties = new ConnectionPropertiesImpl( true, false, java.sql.Connection.TRANSACTION_SERIALIZABLE, Catalog.DATABASE_NAME, Catalog.defaultNamespaceName ); - public PolyphenyDbConnectionHandle( final Meta.ConnectionHandle handle, final LogicalUser logicalUser, final ConnectionId connectionId, final LogicalDatabase database, final LogicalNamespace namespace, final TransactionManager transactionManager ) { + public PolyConnectionHandle( final ConnectionHandle handle, final LogicalUser logicalUser, final String connectionId, final LogicalNamespace namespace, final TransactionManager transactionManager ) { this.handle = handle; - this.userId = UserId.fromString( logicalUser.name ); // TODO: refactor CatalogUser - this.user = logicalUser; - this.connectionId = connectionId; - this.database = database; - this.namespace = namespace; - this.transactionManager = transactionManager; - } - - - public PolyphenyDbConnectionHandle( final ConnectionHandle handle, final LogicalUser logicalUser, final String connectionId, final LogicalDatabase database, final LogicalNamespace namespace, final TransactionManager transactionManager ) { - this.handle = handle; - - this.userId = UserId.fromString( logicalUser.name ); // TODO: refactor CatalogUser + this.userId = UserId.fromString( logicalUser.name ); this.user = logicalUser; this.connectionId = ConnectionId.fromString( connectionId ); - this.database = database; this.namespace = namespace; this.transactionManager = transactionManager; } @@ -107,7 +92,7 @@ public Transaction getCurrentOrCreateNewTransaction() { } - public void setCurrentOpenResultSet( PolyphenyDbResultSet resultSet ) { + public void setCurrentOpenResultSet( PolyResultSet resultSet ) { this.currentOpenResultSet = resultSet; } @@ -135,7 +120,7 @@ public boolean equals( Object o ) { if ( o == null || getClass() != o.getClass() ) { return false; } - PolyphenyDbConnectionHandle that = (PolyphenyDbConnectionHandle) o; + PolyConnectionHandle that = (PolyConnectionHandle) o; return Objects.equals( connectionId, that.connectionId ); } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyResultSet.java similarity index 91% rename from plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java rename to plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyResultSet.java index 5e50660315..30ea8374e7 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyphenyDbResultSet.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolyResultSet.java @@ -57,12 +57,12 @@ /** * Implementation of {@link ResultSet} for the Polypheny-DB engine. */ -public class PolyphenyDbResultSet extends AvaticaResultSet { +public class PolyResultSet extends AvaticaResultSet { /** * Creates a PolyphenyDbResultSet. */ - public PolyphenyDbResultSet( AvaticaStatement statement, PolySignature polySignature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame ) throws SQLException { + public PolyResultSet( AvaticaStatement statement, PolySignature polySignature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame ) throws SQLException { super( statement, null, polySignature, resultSetMetaData, timeZone, firstFrame ); } @@ -92,7 +92,7 @@ public ResultSet create( ColumnMetaData.AvaticaType elementType, Iterable { - private final PolyphenyDbConnectionHandle connection; + private final PolyConnectionHandle connection; private final int statementId; private volatile transient Iterator openResultSet; private volatile transient PolySignature signature; @@ -45,7 +45,7 @@ public class PolyStatementHandle { private final StopWatch executionStopWatch = new StopWatch(); - public PolyStatementHandle( final PolyphenyDbConnectionHandle connection, final int statementId ) { + public PolyStatementHandle( final PolyConnectionHandle connection, final int statementId ) { this.connection = connection; this.statementId = statementId; } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PrimitiveDatabase.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PrimitiveDatabase.java new file mode 100644 index 0000000000..a32c135c6a --- /dev/null +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PrimitiveDatabase.java @@ -0,0 +1,28 @@ +/* + * 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.avatica; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class PrimitiveDatabase { + + public final String tableCat; + public final String owner; + public final String defaultSchema; + +} diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java index 4e889e22b9..10ef784e69 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java @@ -30,7 +30,7 @@ import org.polypheny.db.algebra.core.common.Modify.Operation; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; @@ -109,7 +109,7 @@ public String toString() { public Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet algTraits, - LogicalEntity table, + Entity table, AlgNode input, Operation operation, List updateColumnList, diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java index 842a4be0b4..e1c0fc4d97 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java @@ -25,7 +25,7 @@ import org.apache.calcite.linq4j.tree.Expression; import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.cottontail.CottontailPlugin.CottontailStore; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.schema.Namespace; import org.polypheny.db.schema.Namespace.Schema; @@ -131,7 +131,7 @@ public Expression getExpression( Snapshot snapshot, long id ) { @Override - protected Map getTables() { + protected Map getTables() { return ImmutableMap.copyOf( this.tableMap ); } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java index c3a0690c8b..f98d09c51c 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java @@ -32,7 +32,7 @@ import org.polypheny.db.adapter.file.FileAlg.FileImplementor.Operation; import org.polypheny.db.adapter.file.FilePlugin.FileStore; import org.polypheny.db.adapter.file.util.FileUtil; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.schema.Namespace.Schema; import org.polypheny.db.schema.impl.AbstractNamespace; @@ -44,7 +44,7 @@ public class FileStoreSchema extends AbstractNamespace implements FileSchema, Schema { private final String schemaName; - private final Map tables = new HashMap<>(); + private final Map tables = new HashMap<>(); private final FileStore store; private final FileConvention convention; diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java index 18eeb8ac59..2d98405ddf 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileTranslatableEntity.java @@ -27,7 +27,7 @@ import org.polypheny.db.algebra.core.common.Modify; import org.polypheny.db.algebra.core.common.Modify.Operation; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -89,7 +89,7 @@ public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { public Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet algTraits, - LogicalEntity table, + Entity table, AlgNode input, Operation operation, List updateColumnList, diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileScan.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileScan.java index 5bd3f2c5bf..6a0860ef97 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileScan.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileScan.java @@ -25,7 +25,7 @@ import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; @@ -38,7 +38,7 @@ public class FileScan extends RelScan implements FileAlg private final FileTranslatableEntity fileTable; - public FileScan( AlgOptCluster cluster, LogicalEntity table, FileTranslatableEntity fileTable ) { + public FileScan( AlgOptCluster cluster, Entity table, FileTranslatableEntity fileTable ) { //convention was: EnumerableConvention.INSTANCE super( cluster, cluster.traitSetOf( fileTable.getFileSchema().getConvention() ).replace( ModelTrait.RELATIONAL ), fileTable ); this.fileTable = fileTable; diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcSchema.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcSchema.java index e6e374ffef..2c893c355f 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcSchema.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/JdbcSchema.java @@ -56,7 +56,7 @@ import org.polypheny.db.algebra.type.AlgProtoDataType; import org.polypheny.db.catalog.catalogs.RelStoreCatalog; import org.polypheny.db.catalog.catalogs.StoreCatalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -224,7 +224,7 @@ public final Set getFunctionNames() { @Override - public LogicalEntity getEntity( String name ) { + public Entity getEntity( String name ) { return getTableMap().get( name ); } 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 e0aac5b7f4..c7508169aa 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 @@ -53,7 +53,7 @@ import org.polypheny.db.algebra.logical.relational.LogicalRelModify; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalColumn; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -202,7 +202,7 @@ public Enumerable scan( DataContext root ) { public Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet algTraits, - LogicalEntity table, + Entity table, AlgNode input, Operation operation, List updateColumnList, diff --git a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java index 46f3c6c21c..d47a078435 100644 --- a/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java +++ b/plugins/jdbc-adapter-framework/src/test/java/org/polypheny/db/adapter/jdbc/alg2sql/PlannerTest.java @@ -35,7 +35,7 @@ import org.polypheny.db.algebra.enumerable.EnumerableRules; import org.polypheny.db.algebra.enumerable.EnumerableScan; import org.polypheny.db.algebra.rules.FilterMergeRule; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.languages.Parser; import org.polypheny.db.languages.Parser.ParserConfig; import org.polypheny.db.nodes.Node; @@ -155,7 +155,7 @@ public AlgNode convert( AlgNode alg ) { */ private static class MockJdbcScan extends RelScan implements JdbcAlg { - MockJdbcScan( AlgOptCluster cluster, LogicalEntity table, JdbcConvention jdbcConvention ) { + MockJdbcScan( AlgOptCluster cluster, Entity table, JdbcConvention jdbcConvention ) { super( cluster, cluster.traitSetOf( jdbcConvention ), table ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java index a42401cf5c..f67d545148 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java @@ -53,8 +53,7 @@ import org.polypheny.db.algebra.core.common.Modify.Operation; import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.logical.relational.LogicalProject; -import org.polypheny.db.algebra.type.AlgRecordType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.plan.Convention; @@ -71,7 +70,7 @@ public interface MongoAlg extends AlgNode { /** * Calling convention for relational operations that occur in MongoDB. */ - Convention CONVENTION = MongoConvention.INSTANCE;//new Convention.Impl( "MONGO", MongoRel.class ); + Convention CONVENTION = MongoConvention.INSTANCE;//new Convention.Impl( "MONGO", MongoAlg.class ); /** @@ -81,6 +80,7 @@ class Implementor extends AlgShuttleImpl implements Serializable { public final List> list = new ArrayList<>(); public List operations = new ArrayList<>(); + public BsonArray filter = new BsonArray(); @Getter @Setter @@ -93,7 +93,13 @@ class Implementor extends AlgShuttleImpl implements Serializable { public boolean onlyOne = false; public boolean isDocumentUpdate = false; - public LogicalEntity entity; + @Getter + private MongoEntity entity; + + @Getter + @Setter + private AlgDataType rowType; + @Setter @Getter public boolean hasProject = false; @@ -107,9 +113,6 @@ class Implementor extends AlgShuttleImpl implements Serializable { @Setter private Operation operation; - @Getter - private AlgRecordType staticRowType; - public Implementor() { isDML = false; @@ -132,18 +135,6 @@ public void visitChild( int ordinal, AlgNode input ) { } - public void setStaticRowType( AlgRecordType staticRowType ) { - if ( this.staticRowType != null ) { - return; - } - if ( mongoEntity != null ) { - this.staticRowType = MongoRowType.fromRecordType( staticRowType, mongoEntity ); - } else { - this.staticRowType = staticRowType; - } - } - - public String getPhysicalName( String name ) { int index = mongoEntity.physical.unwrap( PhysicalTable.class ).columns.stream().map( c -> c.name ).collect( Collectors.toList() ).indexOf( name ); if ( index != -1 ) { @@ -153,6 +144,12 @@ public String getPhysicalName( String name ) { } + public void setEntity( MongoEntity entity ) { + this.entity = entity; + this.rowType = entity.getRowType(); + } + + public BsonDocument getFilter() { BsonDocument filter; if ( this.filter.size() == 1 ) { 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 426ec29375..3e31ce0c0a 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 @@ -86,7 +86,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeImpl; import org.polypheny.db.algebra.type.AlgProtoDataType; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalCollection; import org.polypheny.db.catalog.entity.physical.PhysicalColumn; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; @@ -315,7 +315,7 @@ private static Integer parseIntString( String valueString ) { public Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet traitSet, - LogicalEntity table, + Entity table, AlgNode child, Operation operation, List updateColumnList, @@ -335,7 +335,7 @@ public Modify toModificationTable( public Modify toModificationCollection( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity collection, + Entity collection, AlgNode child, Operation operation, Map updates, diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoNamespace.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoNamespace.java index 99586040d7..7357c825c3 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoNamespace.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoNamespace.java @@ -48,13 +48,12 @@ import org.apache.calcite.linq4j.tree.Expression; import org.polypheny.db.adapter.mongodb.MongoPlugin.MongoStore; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; import org.polypheny.db.catalog.impl.Expressible; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.Convention; -import org.polypheny.db.schema.Entity; import org.polypheny.db.schema.Function; import org.polypheny.db.schema.Namespace; import org.polypheny.db.schema.Namespace.Schema; @@ -73,10 +72,10 @@ public class MongoNamespace implements Namespace, Schema, Expressible { private final Convention convention = MongoAlg.CONVENTION; @Getter - private final Map tableMap = new HashMap<>(); + private final Map tableMap = new HashMap<>(); @Getter - private final Map collectionMap = new HashMap<>(); + private final Map collectionMap = new HashMap<>(); private final MongoClient connection; private final TransactionProvider transactionProvider; @Getter @@ -122,7 +121,7 @@ public Set getSubNamespaceNames() { @Override - public LogicalEntity getEntity( String name ) { + public Entity getEntity( String name ) { return null; } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java index fa9f3195e3..b4a0b7b550 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java @@ -37,6 +37,7 @@ public class MongoDocumentModify extends DocumentModify implements private final GridFSBucket bucket; private Implementor implementor; + protected MongoDocumentModify( AlgTraitSet traits, MongoEntity collection, @@ -55,7 +56,7 @@ public void implement( Implementor implementor ) { implementor.setDML( true ); this.implementor = implementor; - implementor.entity = entity; + implementor.setEntity( entity ); implementor.setOperation( this.getOperation() ); switch ( this.getOperation() ) { diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java index 40dada2f19..8f15108be6 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java @@ -27,7 +27,6 @@ import org.bson.json.JsonMode; import org.bson.json.JsonWriterSettings; import org.polypheny.db.adapter.mongodb.MongoAlg; -import org.polypheny.db.adapter.mongodb.MongoRowType; import org.polypheny.db.adapter.mongodb.bson.BsonFunctionHelper; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.constant.Kind; @@ -78,10 +77,10 @@ public void implement( Implementor implementor ) { final List excludes = new ArrayList<>(); final List unwinds = new ArrayList<>(); // We use our specialized rowType to derive the mapped underlying column identifiers - MongoRowType mongoRowType = null; - if ( implementor.getStaticRowType() instanceof MongoRowType ) { + AlgDataType mongoRowType = implementor.getRowType(); + /*if ( implementor.getStaticRowType() instanceof MongoRowType ) { mongoRowType = ((MongoRowType) implementor.getStaticRowType()); - } + }*/ BsonDocument documents = new BsonDocument(); 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 feaddc00dd..98bd411b30 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 @@ -443,7 +443,7 @@ public String handleSpecialCases( RexCall call ) { array.addAll( translateList( call.operands ).stream().map( BsonString::new ).collect( Collectors.toList() ) ); return array.toString(); } else if ( call.isA( Kind.MQL_QUERY_VALUE ) ) { - return translateDocValueAsKey( implementor.getStaticRowType(), call, "$" ); + return translateDocValueAsKey( implementor.getRowType(), call, "$" ); } else if ( call.isA( Kind.MQL_ITEM ) ) { RexNode leftPre = call.operands.get( 0 ); String left = leftPre.accept( this ); @@ -459,7 +459,7 @@ public String handleSpecialCases( RexCall call ) { return "{\"$slice\":[ " + left + "," + skip + "," + return_ + "]}"; } else if ( call.isA( Kind.MQL_EXCLUDE ) ) { String parent = implementor - .getStaticRowType() + .getRowType() .getFieldNames() .get( ((RexIndexRef) call.operands.get( 0 )).getIndex() ); diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java index 0bc9601723..bf131f7219 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoScan.java @@ -28,7 +28,6 @@ import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.algebra.type.AlgRecordType; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; @@ -91,12 +90,11 @@ public void register( AlgOptPlanner planner ) { @Override public void implement( Implementor implementor ) { - implementor.entity = entity; + implementor.setEntity( entity ); //implementor.setStaticRowType( (AlgRecordType) rowType ); //implementor.physicalMapper.addAll( rowType.getFieldNames() ); if ( implementor.isDML() ) { - implementor.setStaticRowType( (AlgRecordType) rowType ); return; } implementor.list.add( Pair.of( null, new BsonDocument( "$project", new BsonDocument( rowType.getFields().stream().map( p -> new BsonElement( p.getName(), new BsonString( "$" + p.getPhysicalName() ) ) ).collect( Collectors.toList() ) ) ).toJson() ) ); 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 683bfac69d..0adcff4bf4 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 @@ -32,7 +32,6 @@ import org.polypheny.db.adapter.mongodb.MongoAlg; import org.polypheny.db.adapter.mongodb.MongoEntity; import org.polypheny.db.adapter.mongodb.MongoPlugin.MongoStore; -import org.polypheny.db.adapter.mongodb.MongoRowType; import org.polypheny.db.adapter.mongodb.bson.BsonDynamic; import org.polypheny.db.adapter.mongodb.rules.MongoRules.MongoDocuments; import org.polypheny.db.algebra.AbstractAlgNode; @@ -42,8 +41,6 @@ import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.algebra.type.AlgRecordType; -import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.entity.physical.PhysicalCollection; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.plan.AlgOptCluster; @@ -107,7 +104,7 @@ public void implement( Implementor implementor ) { implementor.setDML( true ); this.implementor = implementor; - implementor.entity = entity; + implementor.setEntity( entity ); implementor.setOperation( this.getOperation() ); switch ( this.getOperation() ) { @@ -136,7 +133,7 @@ public void implement( Implementor implementor ) { private void handleDelete( Implementor implementor ) { Implementor filterCollector = new Implementor( true ); - filterCollector.setStaticRowType( implementor.getStaticRowType() ); + filterCollector.setEntity( entity ); ((MongoAlg) input).implement( filterCollector ); implementor.filter = filterCollector.filter; if ( Pair.right( filterCollector.list ).contains( "{$limit: 1}" ) ) { @@ -147,11 +144,11 @@ private void handleDelete( Implementor implementor ) { private void handleUpdate( Implementor implementor ) { Implementor condImplementor = new Implementor( true ); - condImplementor.setStaticRowType( implementor.getStaticRowType() ); + condImplementor.setEntity( entity ); ((MongoAlg) input).implement( condImplementor ); implementor.filter = condImplementor.filter; //assert condImplementor.getStaticRowType() instanceof MongoRowType; - MongoRowType rowType = (MongoRowType) condImplementor.getStaticRowType(); + AlgDataType rowType = condImplementor.getRowType(); int pos = 0; BsonDocument doc = new BsonDocument(); List docDocs = new ArrayList<>(); @@ -159,31 +156,30 @@ private void handleUpdate( Implementor implementor ) { for ( RexNode el : getSourceExpressions() ) { if ( el.isA( Kind.LITERAL ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + rowType.getFields().get( pos ).getPhysicalName(),//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( getUpdateColumns().get( pos ), implementor ), + rowType.getFields().get( pos ).getPhysicalName(),//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( getUpdateColumns().get( pos ), implementor ), + rowType.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), BsonUtil.getBsonArray( call, bucket ) ); } } else if ( el.isA( Kind.DYNAMIC_PARAM ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + rowType.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), new BsonDynamic( (RexDynamicParam) el ) ); } else if ( el.isA( Kind.FIELD_ACCESS ) ) { doc.append( - rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + rowType.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), new BsonString( - "$" + rowType.getPhysicalName( - ((RexFieldAccess) el).getField().getName(), implementor ) ) ); + "$" + rowType.getFields().get( pos ).getPhysicalName() ) );//rowType.getPhysicalName( ((RexFieldAccess) el).getField().getName(), implementor ) ) ); } pos++; } @@ -201,7 +197,7 @@ private void handleUpdate( Implementor implementor ) { } - private BsonDocument handleDocumentUpdate( RexCall el, GridFSBucket bucket, MongoRowType rowType ) { + private BsonDocument handleDocumentUpdate( RexCall el, GridFSBucket bucket, AlgDataType rowType ) { if ( el.op.getKind() == Kind.MQL_JSONIFY ) { assert el.getOperands().size() == 1; return handleDocumentUpdate( (RexCall) el.getOperands().get( 0 ), bucket, rowType ); @@ -218,7 +214,7 @@ private BsonDocument handleDocumentUpdate( RexCall el, GridFSBucket bucket, Mong } - private void attachUpdateStep( BsonDocument doc, RexCall el, MongoRowType rowType, String key ) { + private void attachUpdateStep( BsonDocument doc, RexCall el, AlgDataType rowType, String key ) { List keys = getDocUpdateKey( (RexIndexRef) el.operands.get( 0 ), (RexCall) el.operands.get( 1 ), rowType ); switch ( el.op.getKind() ) { case MQL_UPDATE_REPLACE: @@ -250,7 +246,7 @@ private void attachUpdateStep( BsonDocument doc, RexCall el, MongoRowType rowTyp } - private String getDocParentKey( RexIndexRef rexInputRef, MongoRowType rowType ) { + private String getDocParentKey( RexIndexRef rexInputRef, AlgDataType rowType ) { return rowType.getFieldNames().get( rexInputRef.getIndex() ); } @@ -324,7 +320,7 @@ public static BsonDocument getReplaceUpdate( List keys, RexCall call, Im } - private List getDocUpdateKey( RexIndexRef row, RexCall subfield, MongoRowType rowType ) { + private List getDocUpdateKey( RexIndexRef row, RexCall subfield, AlgDataType rowType ) { String name = rowType.getFieldNames().get( row.getIndex() ); return subfield .operands @@ -389,7 +385,7 @@ private void handlePreparedInsert( Implementor implementor, MongoProject input ) } BsonDocument doc = new BsonDocument(); - MongoEntity entity = implementor.entity.unwrap( MongoEntity.class ); + MongoEntity entity = implementor.getEntity().unwrap( MongoEntity.class ); GridFSBucket bucket = implementor.getBucket(); //noinspection AssertWithSideEffects assert input.getRowType().getFieldCount() == this.getEntity().getRowType().getFieldCount(); @@ -401,8 +397,7 @@ private void handlePreparedInsert( Implementor implementor, MongoProject input ) } else { throw new GenericRuntimeException( "Mapping for physical mongo fields not found" ); }*/ - - implementor.setStaticRowType( (AlgRecordType) input.getRowType() ); + implementor.setEntity( entity ); int pos = 0; for ( RexNode rexNode : input.getChildExps() ) { @@ -461,7 +456,7 @@ private BsonValue getBsonArray( RexCall el, PolyType type, GridFSBucket bucket ) private void handleDirectInsert( Implementor implementor, MongoValues values ) { List docs = new ArrayList<>(); - LogicalTable catalogTable = implementor.entity.unwrap( LogicalTable.class ); + MongoEntity entity = implementor.getEntity(); GridFSBucket bucket = implementor.bucket; AlgDataType valRowType = rowType; @@ -470,8 +465,8 @@ private void handleDirectInsert( Implementor implementor, MongoValues values ) { valRowType = values.getRowType(); } - List columnNames = catalogTable.getColumnNames(); - List columnIds = catalogTable.getColumnIds(); + List columnNames = entity.getRowType().getFieldNames(); + List columnIds = entity.getRowType().getFieldIds(); for ( ImmutableList literals : values.tuples ) { BsonDocument doc = new BsonDocument(); int pos = 0; diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoToEnumerableConverter.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoToEnumerableConverter.java index cbde383df0..376acdf9fc 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoToEnumerableConverter.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoToEnumerableConverter.java @@ -81,13 +81,13 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { final AlgDataType rowType = getRowType(); final PhysType physType = PhysTypeImpl.of( implementor.getTypeFactory(), rowType, pref.prefer( JavaRowFormat.ARRAY ) ); - if ( mongoImplementor.entity == null ) { + if ( mongoImplementor.getEntity() == null ) { return implementor.result( physType, new BlockBuilder().toBlock() ); } final Expression tupleTypes = MongoTupleType.from( rowType ).asExpression(); - final Expression table = list.append( "table", mongoImplementor.entity.asExpression()/*.getExpression( MongoEntity.MongoQueryable.class )*/ ); + final Expression table = list.append( "table", mongoImplementor.getEntity().asExpression()/*.getExpression( MongoEntity.MongoQueryable.class )*/ ); List opList = Pair.right( mongoImplementor.list ); diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java index ccb35381fe..9cdd345706 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql2alg/MqlToAlgConverter.java @@ -63,7 +63,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.DocumentType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalGraph; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; @@ -209,7 +209,7 @@ public class MqlToAlgConverter { private long namespaceId; private boolean notActive = false; private boolean usesDocumentModel; - private LogicalEntity entity; + private Entity entity; public MqlToAlgConverter( Snapshot snapshot, AlgOptCluster cluster ) { @@ -307,7 +307,7 @@ public AlgRoot convert( MqlCollectionStatement query ) { } - private LogicalEntity getEntity( MqlCollectionStatement query, long namespaceId ) { + private Entity getEntity( MqlCollectionStatement query, long namespaceId ) { LogicalNamespace namespace = snapshot.getNamespace( namespaceId ).orElseThrow(); Optional optionalDoc = snapshot.doc().getCollection( namespace.id, query.getCollection() ); @@ -329,7 +329,7 @@ private LogicalEntity getEntity( MqlCollectionStatement query, long namespaceId /** * Starts converting a db.collection.update(); */ - private AlgNode convertUpdate( MqlUpdate query, LogicalEntity entity, AlgNode node ) { + private AlgNode convertUpdate( MqlUpdate query, Entity entity, AlgNode node ) { if ( !query.getQuery().isEmpty() ) { node = convertQuery( query, entity.getRowType(), node ); if ( query.isOnlyOne() ) { @@ -352,7 +352,7 @@ private AlgNode convertUpdate( MqlUpdate query, LogicalEntity entity, AlgNode no * this method is implemented like the reduced update pipeline, * but in fact could be combined and therefore optimized a lot more */ - private AlgNode translateUpdate( MqlUpdate query, AlgDataType rowType, AlgNode node, LogicalEntity entity ) { + private AlgNode translateUpdate( MqlUpdate query, AlgDataType rowType, AlgNode node, Entity entity ) { Map> updates = new HashMap<>(); Map removes = new HashMap<>(); Map renames = new HashMap<>(); @@ -637,7 +637,7 @@ private Map translateCurrentDate( BsonDocument value, AlgDataTy /** * Starts translating an update pipeline */ - private AlgNode convertReducedPipeline( MqlUpdate query, AlgDataType rowType, AlgNode node, LogicalEntity entity ) { + private AlgNode convertReducedPipeline( MqlUpdate query, AlgDataType rowType, AlgNode node, Entity entity ) { Map updates = new HashMap<>(); Map>> mergedUpdates = new HashMap<>(); mergedUpdates.put( UpdateOperation.REMOVE, new ArrayList<>() ); @@ -688,7 +688,7 @@ private AlgNode convertReducedPipeline( MqlUpdate query, AlgDataType rowType, Al /** * Translates a delete operation from its MqlNode format to the {@link AlgNode} form */ - private AlgNode convertDelete( MqlDelete query, LogicalEntity table, AlgNode node ) { + private AlgNode convertDelete( MqlDelete query, Entity table, AlgNode node ) { if ( !query.getQuery().isEmpty() ) { node = convertQuery( query, table.getRowType(), node ); } @@ -713,7 +713,7 @@ private AlgNode convertDelete( MqlDelete query, LogicalEntity table, AlgNode nod * @param entity the table/collection into which the values are inserted * @return the modified AlgNode */ - private AlgNode convertInsert( MqlInsert query, LogicalEntity entity ) { + private AlgNode convertInsert( MqlInsert query, Entity entity ) { return LogicalDocumentModify.create( entity, convertMultipleValues( query.getValues(), entity.getRowType() ), 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 c867d7e2c5..6e1f4cd442 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 @@ -42,7 +42,7 @@ 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.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; import org.polypheny.db.catalog.entity.physical.PhysicalGraph; @@ -89,10 +89,10 @@ public AlgNode toAlg( AlgOptCluster cluster, AlgTraitSet traitSet ) { * @param operation the operation type */ @Override - public Modify toModificationTable( + public Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity physical, + Entity physical, AlgNode child, Operation operation, List targets, diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java index 63cb156641..86f76f7ba2 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoGraph.java @@ -48,7 +48,7 @@ import org.polypheny.db.algebra.logical.lpg.LogicalLpgModify; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; import org.polypheny.db.catalog.entity.physical.PhysicalGraph; @@ -107,7 +107,7 @@ public NeoGraph( PhysicalEntity physical, List fields, public Modify toModificationTable( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity table, + Entity table, AlgNode child, Operation operation, List targets, @@ -129,7 +129,7 @@ public Modify toModificationTable( public Modify toModificationGraph( AlgOptCluster cluster, AlgTraitSet traits, - LogicalEntity graph, + Entity graph, AlgNode child, Operation operation, List targets, diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoNamespace.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoNamespace.java index 9ef6a318b7..e36d884b35 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoNamespace.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/NeoNamespace.java @@ -25,7 +25,7 @@ import org.neo4j.driver.Session; import org.polypheny.db.adapter.neo4j.Neo4jPlugin.Neo4jStore; import org.polypheny.db.algebra.type.AlgProtoDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; @@ -96,7 +96,7 @@ public Set getSubNamespaceNames() { @Override - public LogicalEntity getEntity( String name ) { + public Entity getEntity( String name ) { return null; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUtil.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUtil.java index bbe0575e79..10ad926714 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUtil.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlUtil.java @@ -42,7 +42,7 @@ import org.polypheny.db.algebra.operators.OperatorTable; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypePrecedenceList; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -617,7 +617,7 @@ public static AlgDataType getNamedType( Identifier node, Snapshot snapshot ) { } - public static boolean supportsModality( Modality modality, LogicalEntity entity ) { + public static boolean supportsModality( Modality modality, Entity entity ) { if ( Objects.requireNonNull( modality ) == Modality.STREAM ) { return entity instanceof StreamableEntity; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AbstractNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AbstractNamespace.java index e99d00d259..4f3d34fe8e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AbstractNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/AbstractNamespace.java @@ -24,7 +24,7 @@ import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; @@ -147,7 +147,7 @@ public SqlNode getEnclosingNode() { @Override - public LogicalEntity getTable() { + public Entity getTable() { return null; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingNamespace.java index 327b6ec6d9..cbe71391b2 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingNamespace.java @@ -20,7 +20,7 @@ import java.util.List; import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.util.Pair; @@ -50,7 +50,7 @@ public SqlValidator getValidator() { @Override - public LogicalEntity getTable() { + public Entity getTable() { return namespace.getTable(); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java index e9796145ac..3091d06d89 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/DelegatingScope.java @@ -31,12 +31,11 @@ import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.DynamicRecordType; import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.prepare.Prepare.PreparingEntity; import org.polypheny.db.schema.CustomColumnResolvingEntity; -import org.polypheny.db.schema.Entity; import org.polypheny.db.sql.language.SqlCall; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -102,9 +101,9 @@ void resolveInNamespace( SqlValidatorNamespace ns, boolean nullable, List>> entries = ((CustomColumnResolvingEntity) t).resolveColumn( rowType, validator.getTypeFactory(), names ); for ( Pair> entry : entries ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EmptyScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EmptyScope.java index b3aa3cbd88..16262119f1 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EmptyScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EmptyScope.java @@ -26,7 +26,7 @@ import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.schema.PolyphenyDbSchema; @@ -84,7 +84,7 @@ public void resolve( List names, NameMatcher nameMatcher, boolean deep, @Override public SqlValidatorNamespace getTableNamespace( List names ) { - LogicalEntity table = validator.snapshot.rel().getTable( names.get( 0 ), names.get( 1 ) ).orElse( null ); + Entity table = validator.snapshot.rel().getTable( names.get( 0 ), names.get( 1 ) ).orElse( null ); return table != null ? new EntityNamespace( validator, table ) : null; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java index 845096bed9..7977eaf6ba 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/EntityNamespace.java @@ -25,8 +25,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory.Builder; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; -import org.polypheny.db.schema.Entity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.schema.types.ExtensibleEntity; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -42,21 +41,21 @@ class EntityNamespace extends AbstractNamespace { @Getter - private final LogicalEntity table; + private final Entity table; public final ImmutableList extendedFields; /** * Creates a TableNamespace. */ - private EntityNamespace( SqlValidatorImpl validator, LogicalEntity entity, List fields ) { + private EntityNamespace( SqlValidatorImpl validator, Entity entity, List fields ) { super( validator, null ); this.table = entity; this.extendedFields = ImmutableList.copyOf( fields ); } - EntityNamespace( SqlValidatorImpl validator, LogicalEntity table ) { + EntityNamespace( SqlValidatorImpl validator, Entity table ) { this( validator, table, ImmutableList.of() ); } @@ -83,7 +82,7 @@ public SqlNode getNode() { @Override public Monotonicity getMonotonicity( String columnName ) { - final LogicalEntity table = getTable(); + final Entity table = getTable(); return Util.getMonotonicity( table, columnName ); } @@ -100,7 +99,7 @@ public EntityNamespace extend( SqlNodeList extendList ) { builder.addAll( this.extendedFields ); builder.addAll( SqlValidatorUtil.getExtendedColumns( validator.getTypeFactory(), getTable(), extendList ) ); final List extendedFields = builder.build(); - final Entity schemaEntity = table.unwrap( Entity.class ); + final org.polypheny.db.schema.Entity schemaEntity = table.unwrap( org.polypheny.db.schema.Entity.class ); if ( schemaEntity != null && schemaEntity instanceof ExtensibleEntity ) { checkExtendedColumnTypes( extendList ); //final AlgOptEntity algOptEntity = ((AlgOptEntity) table).extend( extendedFields ); @@ -115,7 +114,7 @@ public EntityNamespace extend( SqlNodeList extendList ) { * Gets the data-type of all columns in a table (for a view table: including columns of the underlying table) */ private AlgDataType getBaseRowType() { - final Entity schemaEntity = table.unwrap( Entity.class ); + final org.polypheny.db.schema.Entity schemaEntity = table.unwrap( org.polypheny.db.schema.Entity.class ); return schemaEntity.getRowType( validator.typeFactory ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java index b94c957cdf..d212b4e3e5 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/IdentifierNamespace.java @@ -29,7 +29,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -169,7 +169,7 @@ private SqlValidatorNamespace resolveImpl( SqlIdentifier id ) { } } else if ( ns.size() == 2 ) { LogicalNamespace namespace = validator.snapshot.getNamespace( ns.get( 0 ) ).orElseThrow(); - LogicalEntity entity = null; + Entity entity = null; if ( namespace.dataModel == DataModel.RELATIONAL ) { entity = validator.snapshot.rel().getTable( namespace.id, ns.get( 1 ) ).orElse( null ); } else if ( namespace.dataModel == DataModel.DOCUMENT ) { @@ -188,7 +188,7 @@ private SqlValidatorNamespace resolveImpl( SqlIdentifier id ) { public AlgDataType validateImpl( AlgDataType targetRowType ) { resolvedNamespace = Objects.requireNonNull( resolveImpl( id ) ); if ( resolvedNamespace instanceof EntityNamespace ) { - LogicalEntity table = resolvedNamespace.getTable(); + Entity table = resolvedNamespace.getTable(); if ( validator.shouldExpandIdentifiers() ) { // TODO: expand qualifiers for column references also List qualifiedNames = List.of( table.name ); @@ -254,7 +254,7 @@ public SqlValidatorNamespace resolve() { @Override - public LogicalEntity getTable() { + public Entity getTable() { return resolvedNamespace == null ? null : resolve().getTable(); } @@ -267,14 +267,14 @@ public List> getMonotonicExprs() { @Override public Monotonicity getMonotonicity( String columnName ) { - final LogicalEntity table = getTable(); + final Entity table = getTable(); return Util.getMonotonicity( table, columnName ); } @Override public boolean supportsModality( Modality modality ) { - final LogicalEntity table = getTable(); + final Entity table = getTable(); if ( table == null ) { return modality == Modality.RELATION; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/ListScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/ListScope.java index c95f43481a..1b30ac2500 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/ListScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/ListScope.java @@ -31,7 +31,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.algebra.type.StructKind; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.util.Moniker; @@ -100,7 +100,7 @@ private ScopeChild findChild( List names, NameMatcher nameMatcher ) { } // Look up the 2 tables independently, in case one is qualified with catalog & schema and the other is not. - final LogicalEntity table = child.namespace.getTable(); + final Entity table = child.namespace.getTable(); if ( table != null ) { Optional optionalEntity = getEntity( names ); if ( optionalEntity.isPresent() 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 6b2d19d11a..0b15cdf22f 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 @@ -72,7 +72,7 @@ import org.polypheny.db.algebra.type.AlgRecordType; import org.polypheny.db.algebra.type.DynamicRecordType; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.DataModel; @@ -105,7 +105,6 @@ import org.polypheny.db.runtime.Resources; import org.polypheny.db.runtime.Resources.ExInst; import org.polypheny.db.schema.ColumnStrategy; -import org.polypheny.db.schema.Entity; import org.polypheny.db.schema.document.DocumentUtil; import org.polypheny.db.sql.language.SqlAggFunction; import org.polypheny.db.sql.language.SqlBasicCall; @@ -2999,7 +2998,7 @@ private void checkRollUpInUsing( SqlIdentifier identifier, SqlNode leftOrRight ) // if it's not a SqlIdentifier then that's fine, it'll be validated somewhere else. if ( leftOrRight instanceof SqlIdentifier ) { SqlIdentifier from = (SqlIdentifier) leftOrRight; - LogicalEntity entity = findTable( + Entity entity = findTable( Util.last( from.names ), snapshot.nameMatcher.isCaseSensitive() ); String name = Util.last( identifier.names ); @@ -3365,7 +3364,7 @@ private boolean isRolledUpColumnAllowedInAgg( SqlIdentifier identifier, SqlValid String tableAlias = pair.left; - LogicalEntity entity = findTable( tableAlias ); + Entity entity = findTable( tableAlias ); if ( entity != null ) { return entity.rolledUpColumnValidInsideAgg(); } @@ -3384,7 +3383,7 @@ private boolean isRolledUpColumn( SqlIdentifier identifier, SqlValidatorScope sc String tableAlias = pair.left; String columnName = pair.right; - LogicalEntity entity = findTable( tableAlias ); + Entity entity = findTable( tableAlias ); if ( entity != null ) { return entity.isRolledUp( columnName ); } @@ -3393,15 +3392,15 @@ private boolean isRolledUpColumn( SqlIdentifier identifier, SqlValidatorScope sc @Nullable - private LogicalEntity findTable( String tableName, boolean caseSensitive ) { + private Entity findTable( String tableName, boolean caseSensitive ) { return snapshot.rel().getTable( Catalog.defaultNamespaceId, tableName ).orElse( null ); } /** - * Given a table alias, find the corresponding {@link Entity} associated with it + * Given a table alias, find the corresponding {@link org.polypheny.db.schema.Entity} associated with it */ - private LogicalEntity findTable( String alias ) { + private Entity findTable( String alias ) { return findTable( alias, snapshot.nameMatcher.isCaseSensitive() ); } @@ -3998,7 +3997,7 @@ private void handleScalarSubQuery( SqlSelect parentSelect, SqlSelect selectItem, } - protected AlgDataType createTargetRowType( LogicalEntity table, SqlNodeList targetColumnList, boolean append ) { + protected AlgDataType createTargetRowType( Entity table, SqlNodeList targetColumnList, boolean append ) { return createTargetRowType( table, targetColumnList, append, false ); } @@ -4011,7 +4010,7 @@ protected AlgDataType createTargetRowType( LogicalEntity table, SqlNodeList targ * @param append Whether to append fields to those in baseRowType * @return Rowtype */ - protected AlgDataType createTargetRowType( LogicalEntity table, SqlNodeList targetColumnList, boolean append, boolean allowDynamic ) { + protected AlgDataType createTargetRowType( Entity table, SqlNodeList targetColumnList, boolean append, boolean allowDynamic ) { AlgDataType baseRowType = table.getRowType(); if ( targetColumnList == null ) { return baseRowType; @@ -4054,7 +4053,7 @@ protected AlgDataType createTargetRowType( LogicalEntity table, SqlNodeList targ public void validateInsert( SqlInsert insert ) { final SqlValidatorNamespace targetNamespace = getSqlNamespace( insert ); validateNamespace( targetNamespace, unknownType ); - final LogicalEntity table = + final Entity table = SqlValidatorUtil.getLogicalEntity( targetNamespace, snapshot, @@ -4101,7 +4100,7 @@ public void validateInsert( SqlInsert insert ) { } - private void checkFieldCount( SqlNode node, LogicalEntity table, SqlNode source, AlgDataType logicalSourceRowType, AlgDataType logicalTargetRowType ) { + private void checkFieldCount( SqlNode node, Entity table, SqlNode source, AlgDataType logicalSourceRowType, AlgDataType logicalTargetRowType ) { final int sourceFieldCount = logicalSourceRowType.getFieldCount(); final int targetFieldCount = logicalTargetRowType.getFieldCount(); if ( sourceFieldCount != targetFieldCount ) { @@ -4321,7 +4320,7 @@ public void validateDelete( SqlDelete call ) { final SqlValidatorNamespace targetNamespace = getSqlNamespace( call ); validateNamespace( targetNamespace, unknownType ); - final LogicalEntity table = targetNamespace.getTable(); + final Entity table = targetNamespace.getTable(); validateAccess( call.getTargetTable(), table, AccessEnum.DELETE ); } @@ -4331,7 +4330,7 @@ public void validateDelete( SqlDelete call ) { public void validateUpdate( SqlUpdate call ) { final SqlValidatorNamespace targetNamespace = getSqlNamespace( call ); validateNamespace( targetNamespace, unknownType ); - final LogicalEntity table = + final Entity table = SqlValidatorUtil.getLogicalEntity( targetNamespace, snapshot, @@ -4366,7 +4365,7 @@ public void validateMerge( SqlMerge call ) { IdentifierNamespace targetNamespace = (IdentifierNamespace) getSqlNamespace( call.getTargetTable() ); validateNamespace( targetNamespace, unknownType ); - LogicalEntity table = targetNamespace.getTable(); + Entity table = targetNamespace.getTable(); validateAccess( call.getTargetTable(), table, AccessEnum.UPDATE ); AlgDataType targetRowType = unknownType; @@ -4403,7 +4402,7 @@ public void validateMerge( SqlMerge call ) { * @param table Table * @param requiredAccess Access requested on table */ - private void validateAccess( SqlNode node, LogicalEntity table, AccessEnum requiredAccess ) { + private void validateAccess( SqlNode node, Entity table, AccessEnum requiredAccess ) { if ( table != null ) { AccessType access = AccessType.ALL; if ( !access.allowsAccess( requiredAccess ) ) { @@ -5064,7 +5063,7 @@ private List getFieldOrigin( SqlNode sqlQuery, int i ) { if ( selectItem instanceof SqlIdentifier ) { final SqlQualified qualified = scope.fullyQualify( (SqlIdentifier) selectItem ); SqlValidatorNamespace namespace = qualified.namespace; - final LogicalEntity table = namespace.getTable(); + final Entity table = namespace.getTable(); if ( table == null ) { return null; } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorNamespace.java index acbd89ebb7..d2de5bfa2d 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorNamespace.java @@ -21,7 +21,7 @@ import org.polypheny.db.algebra.constant.Modality; import org.polypheny.db.algebra.constant.Monotonicity; import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.nodes.validate.ValidatorNamespace; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -54,7 +54,7 @@ public interface SqlValidatorNamespace extends ValidatorNamespace { /** * Returns the underlying table, or null if there is none. */ - LogicalEntity getTable(); + Entity getTable(); /** * Returns the type of this namespace. diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java index b36e7e32b2..2f2aaf4e9b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/SqlValidatorUtil.java @@ -39,7 +39,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -47,7 +47,6 @@ import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; import org.polypheny.db.schema.CustomColumnResolvingEntity; -import org.polypheny.db.schema.Entity; import org.polypheny.db.schema.types.ExtensibleEntity; import org.polypheny.db.sql.language.SqlCall; import org.polypheny.db.sql.language.SqlDataTypeSpec; @@ -78,14 +77,14 @@ private SqlValidatorUtil() { /** - * Converts a {@link SqlValidatorScope} into a {@link LogicalEntity}. This is only possible if the scope represents an identifier, such as "sales.emp". + * Converts a {@link SqlValidatorScope} into a {@link Entity}. This is only possible if the scope represents an identifier, such as "sales.emp". * Otherwise, returns null. * * @param namespace Namespace * @param datasetName Name of sample dataset to substitute, or null to use the regular table * @param usedDataset Output parameter which is set to true if a sample dataset is found; may be null */ - public static LogicalEntity getLogicalEntity( SqlValidatorNamespace namespace, Snapshot snapshot, String datasetName, boolean[] usedDataset ) { + public static Entity getLogicalEntity( SqlValidatorNamespace namespace, Snapshot snapshot, String datasetName, boolean[] usedDataset ) { if ( namespace.isWrapperFor( SqlValidatorImpl.DmlNamespace.class ) ) { final SqlValidatorImpl.DmlNamespace dmlNamespace = namespace.unwrap( SqlValidatorImpl.DmlNamespace.class ); @@ -128,7 +127,7 @@ private static LogicalTable getLogicalEntity( EntityNamespace entityNamespace, S /** * Gets a list of extended columns with field indices to the underlying table. */ - public static List getExtendedColumns( AlgDataTypeFactory typeFactory, LogicalEntity table, SqlNodeList extendedColumns ) { + public static List getExtendedColumns( AlgDataTypeFactory typeFactory, Entity table, SqlNodeList extendedColumns ) { final ImmutableList.Builder extendedFields = ImmutableList.builder(); final ExtensibleEntity extTable = table.unwrap( ExtensibleEntity.class ); int extendedFieldOffset = @@ -264,7 +263,7 @@ public static SqlValidatorWithHints newValidator( OperatorTable opTab, Snapshot } - public static AlgDataTypeField getTargetField( AlgDataType rowType, AlgDataTypeFactory typeFactory, SqlIdentifier id, Snapshot snapshot, LogicalEntity table ) { + public static AlgDataTypeField getTargetField( AlgDataType rowType, AlgDataTypeFactory typeFactory, SqlIdentifier id, Snapshot snapshot, Entity table ) { return getTargetField( rowType, typeFactory, id, snapshot, table, false ); } @@ -277,8 +276,8 @@ public static AlgDataTypeField getTargetField( AlgDataType rowType, AlgDataTypeF * @param table the target table or null if it is not a RelOptTable instance * @return the target field or null if the name cannot be resolved */ - public static AlgDataTypeField getTargetField( AlgDataType rowType, AlgDataTypeFactory typeFactory, SqlIdentifier id, Snapshot snapshot, LogicalEntity table, boolean isDocument ) { - final Entity t = table == null ? null : table.unwrap( Entity.class ); + public static AlgDataTypeField getTargetField( AlgDataType rowType, AlgDataTypeFactory typeFactory, SqlIdentifier id, Snapshot snapshot, Entity table, boolean isDocument ) { + final org.polypheny.db.schema.Entity t = table == null ? null : table.unwrap( org.polypheny.db.schema.Entity.class ); if ( !(t instanceof CustomColumnResolvingEntity) ) { final NameMatcher nameMatcher = snapshot.nameMatcher; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/UnnestNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/UnnestNamespace.java index be5084aa5d..c872ddfe0f 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/UnnestNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/UnnestNamespace.java @@ -18,7 +18,7 @@ import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.sql.language.SqlCall; import org.polypheny.db.sql.language.SqlIdentifier; import org.polypheny.db.sql.language.SqlNode; @@ -45,7 +45,7 @@ class UnnestNamespace extends AbstractNamespace { @Override - public LogicalEntity getTable() { + public Entity getTable() { final SqlNode toUnnest = unnest.operand( 0 ); if ( toUnnest instanceof SqlIdentifier ) { // When operand of SqlIdentifier type does not have struct, fake a table for UnnestNamespace diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithScope.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithScope.java index 23647a30aa..3f19c89270 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithScope.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/validate/WithScope.java @@ -19,7 +19,7 @@ import java.util.List; import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.sql.language.SqlNode; import org.polypheny.db.sql.language.SqlWithItem; @@ -71,7 +71,7 @@ public void resolveTable( List names, NameMatcher nameMatcher, Path path final SqlValidatorNamespace ns = validator.getSqlNamespace( withItem ); final Step path2 = path.plus( ns.getRowType(), 0, names.get( 0 ), StructKind.FULLY_QUALIFIED ); LogicalNamespace namespace = validator.snapshot.getNamespace( names.get( 0 ) ).orElseThrow(); - LogicalEntity entity = validator.snapshot.rel().getTable( names.get( 0 ), names.get( 1 ) ).orElseThrow(); + Entity entity = validator.snapshot.rel().getTable( names.get( 0 ), names.get( 1 ) ).orElseThrow(); resolved.found( ns, false, null, path2, null ); return; } @@ -84,7 +84,7 @@ public void resolve( List names, NameMatcher nameMatcher, boolean deep, if ( names.size() == 1 && names.equals( withItem.name.names ) ) { final SqlValidatorNamespace ns = validator.getSqlNamespace( withItem ); final Step path = Path.EMPTY.plus( ns.getRowType(), 0, names.get( 0 ), StructKind.FULLY_QUALIFIED ); - LogicalEntity entity = validator.snapshot.rel().getTable( names.get( 0 ), names.get( 1 ) ).orElseThrow(); + Entity entity = validator.snapshot.rel().getTable( names.get( 0 ), names.get( 1 ) ).orElseThrow(); resolved.found( ns, false, null, path, null ); return; } 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 c172f1fcb0..55b173800c 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 @@ -124,7 +124,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.DataModel; @@ -167,7 +167,6 @@ import org.polypheny.db.rex.RexUtil; import org.polypheny.db.rex.RexWindowBound; import org.polypheny.db.schema.ColumnStrategy; -import org.polypheny.db.schema.Entity; import org.polypheny.db.schema.types.ModifiableTable; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.sql.language.SqlAggFunction; @@ -2109,7 +2108,7 @@ private void convertIdentifier( Blackboard bb, SqlIdentifier id, SqlNodeList ext } final String datasetName = datasetStack.isEmpty() ? null : datasetStack.peek(); final boolean[] usedDataset = { false }; - LogicalEntity table = SqlValidatorUtil.getLogicalEntity( fromNamespace, snapshot, datasetName, usedDataset ); + Entity table = SqlValidatorUtil.getLogicalEntity( fromNamespace, snapshot, datasetName, usedDataset ); if ( extendedColumns != null && extendedColumns.size() > 0 ) { assert table != null; final ValidatorTable validatorTable = table.unwrap( ValidatorTable.class ); @@ -2853,7 +2852,7 @@ private boolean all( SqlCall call ) { protected AlgNode convertInsert( SqlInsert call ) { - LogicalEntity targetTable = getTargetTable( call ); + Entity targetTable = getTargetTable( call ); final AlgDataType targetRowType = validator.getValidatedNodeType( call ); assert targetRowType != null; @@ -2867,9 +2866,9 @@ protected AlgNode convertInsert( SqlInsert call ) { /** * Creates a relational expression to modify a table or modifiable view. */ - private AlgNode createModify( LogicalEntity targetTable, AlgNode source ) { + private AlgNode createModify( Entity targetTable, AlgNode source ) { final ModifiableTable modifiableTable = targetTable.unwrap( ModifiableTable.class ); - if ( modifiableTable != null && modifiableTable == targetTable.unwrap( Entity.class ) ) { + if ( modifiableTable != null && modifiableTable == targetTable.unwrap( org.polypheny.db.schema.Entity.class ) ) { return modifiableTable.toModificationTable( cluster, source.getTraitSet(), @@ -2887,9 +2886,9 @@ private AlgNode createModify( LogicalEntity targetTable, AlgNode source ) { null, false ); } - - public AlgNode toAlg( final LogicalEntity table ) { + + public AlgNode toAlg( final Entity table ) { final AlgNode scan = table.unwrap( TranslatableEntity.class ).toAlg( cluster, cluster.traitSet() ); final InitializerExpressionFactory ief = @@ -2925,7 +2924,7 @@ public AlgNode toAlg( final LogicalEntity table ) { } - protected LogicalEntity getTargetTable( SqlNode call ) { + protected Entity getTargetTable( SqlNode call ) { final SqlValidatorNamespace targetNs = validator.getSqlNamespace( call ); if ( targetNs.isWrapperFor( SqlValidatorImpl.DmlNamespace.class ) ) { final SqlValidatorImpl.DmlNamespace dmlNamespace = targetNs.unwrap( SqlValidatorImpl.DmlNamespace.class ); @@ -2956,7 +2955,7 @@ protected AlgNode convertColumnList( final SqlInsert call, AlgNode source ) { final List columnExprs = new ArrayList<>(); collectInsertTargets( call, sourceRef, targetColumnNames, columnExprs ); - final LogicalEntity targetTable = getTargetTable( call ); + final Entity targetTable = getTargetTable( call ); final AlgDataType targetRowType = targetTable.getRowType();//AlgOptEntityImpl.realRowType( targetTable ); final List targetFields = targetRowType.getFields(); boolean isDocument = call.getSchemaType() == DataModel.DOCUMENT; @@ -3007,7 +3006,7 @@ protected AlgNode convertColumnList( final SqlInsert call, AlgNode source ) { /** * Creates a blackboard for translating the expressions of generated columns in an INSERT statement. */ - private Blackboard createInsertBlackboard( LogicalEntity targetTable, RexNode sourceRef, List targetColumnNames ) { + private Blackboard createInsertBlackboard( Entity targetTable, RexNode sourceRef, List targetColumnNames ) { final Map nameToNodeMap = new HashMap<>(); int j = 0; @@ -3028,9 +3027,9 @@ private Blackboard createInsertBlackboard( LogicalEntity targetTable, RexNode so } - private InitializerExpressionFactory getInitializerFactory( LogicalEntity validatorTable ) { + private InitializerExpressionFactory getInitializerFactory( Entity validatorTable ) { // We might unwrap a null instead of a InitializerExpressionFactory. - final Entity entity = unwrap( validatorTable, Entity.class ); + final org.polypheny.db.schema.Entity entity = unwrap( validatorTable, org.polypheny.db.schema.Entity.class ); if ( entity != null ) { InitializerExpressionFactory f = unwrap( entity, InitializerExpressionFactory.class ); if ( f != null ) { @@ -3066,7 +3065,7 @@ private RexNode castNullLiteralIfNeeded( RexNode node, AlgDataType type ) { * @param columnExprs List of expressions, to be populated */ protected void collectInsertTargets( SqlInsert call, final RexNode sourceRef, final List targetColumnNames, List columnExprs ) { - final LogicalEntity targetTable = getTargetTable( call ); + final Entity targetTable = getTargetTable( call ); final AlgDataType tableRowType = targetTable.getRowType(); SqlNodeList targetColumnList = call.getTargetColumnList(); if ( targetColumnList == null ) { @@ -3139,7 +3138,7 @@ protected void collectInsertTargets( SqlInsert call, final RexNode sourceRef, fi private AlgNode convertDelete( SqlDelete call ) { - LogicalEntity targetTable = getTargetTable( call ); + Entity targetTable = getTargetTable( call ); AlgNode sourceRel = convertSelect( call.getSourceSelect(), false ); return LogicalRelModify.create( targetTable, @@ -3161,7 +3160,7 @@ private AlgNode convertUpdate( SqlUpdate call ) { rexNodeSourceExpressionListBuilder.add( rn ); } - LogicalEntity targetTable = getTargetTable( call ); + Entity targetTable = getTargetTable( call ); // convert update column list from SqlIdentifier to String final List targetColumnNameList = new ArrayList<>(); @@ -3186,7 +3185,7 @@ private AlgNode convertUpdate( SqlUpdate call ) { private AlgNode convertMerge( SqlMerge call ) { - LogicalEntity targetTable = getTargetTable( call ); + Entity targetTable = getTargetTable( call ); // convert update column list from SqlIdentifier to String final List targetColumnNameList = new ArrayList<>(); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToRelConverterExtendedTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToRelConverterExtendedTest.java index cd27b90a48..6011e556d3 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToRelConverterExtendedTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/language/SqlToRelConverterExtendedTest.java @@ -23,7 +23,7 @@ import org.polypheny.db.algebra.AlgShuttleImpl; import org.polypheny.db.algebra.core.relational.RelScan; import org.polypheny.db.algebra.externalize.AlgJsonWriter; -import org.polypheny.db.catalog.entity.LogicalEntity; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.runtime.Hook; import org.polypheny.db.runtime.Hook.Closeable; @@ -58,7 +58,7 @@ public static void foo( AlgNode alg ) { final String json = writer.asString(); // Find the schema. If there are no tables in the plan, we won't need one. - final LogicalEntity[] entities = { null }; + final Entity[] entities = { null }; alg.accept( new AlgShuttleImpl() { @Override public AlgNode visit( RelScan scan ) { From 63cef21f18f4f6d92a124ccc359c1b8c084b4370 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 28 Nov 2023 00:10:59 +0100 Subject: [PATCH 12/15] fixes for mongo updates and additional fixes --- .../db/algebra/type/AlgDataTypeFactory.java | 6 ++ .../db/languages/LanguageManager.java | 15 ++-- .../polypheny/db/plan/hep/HepAlgVertex.java | 12 +-- .../org/polypheny/db/plan/hep/HepPlanner.java | 22 +++--- .../db/processing/ImplementationContext.java | 4 +- .../db/type/entity/PolyBigDecimal.java | 2 +- .../java/org/polypheny/db/PolyphenyDb.java | 2 +- .../db/processing/AbstractQueryProcessor.java | 4 +- .../db/avatica/AvaticaInterfacePlugin.java | 4 +- .../db/adapter/mongodb/MongoAlg.java | 8 +- .../db/adapter/mongodb/MongoEntity.java | 40 +++++----- .../db/adapter/mongodb/MongoEnumerator.java | 11 +++ .../db/adapter/mongodb/MongoPlugin.java | 10 +-- .../db/adapter/mongodb/MongoRowType.java | 74 ------------------- .../adapter/mongodb/rules/MongoAggregate.java | 19 +---- .../adapter/mongodb/rules/MongoProject.java | 20 ++++- .../db/adapter/mongodb/rules/MongoRules.java | 2 +- .../db/adapter/mongodb/rules/MongoSort.java | 6 +- .../mongodb/rules/MongoTableModify.java | 26 ++++--- .../org/polypheny/db/sql/SqlProcessor.java | 15 +++- .../polypheny/db/webui/crud/LanguageCrud.java | 1 + 21 files changed, 126 insertions(+), 177 deletions(-) delete mode 100644 plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java 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 6cfd8c074e..ffd04b2dcc 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 @@ -499,6 +499,12 @@ public Builder add( String name, String physicalName, PolyType typeName, int pre } + public Builder add( String name, String physicalName, AlgDataType type ) { + add( null, name, physicalName, type ); + return this; + } + + /** * Changes the nullability of the last field added. * diff --git a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java index 216e82a95f..6e22d83559 100644 --- a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java +++ b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java @@ -19,6 +19,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import lombok.Getter; @@ -154,15 +155,9 @@ public List anyQuery( QueryContext context, Statement statement if ( implementation.getException().isPresent() ) { throw implementation.getException().get(); } - if ( context.isAnalysed() ) { - implementation.getStatement().getOverviewDuration().start( "Execution" ); - } executedContexts.add( implementation.execute( implementation.getStatement() ) ); - if ( context.isAnalysed() ) { - implementation.getStatement().getOverviewDuration().stop( "Execution" ); - } } catch ( Exception e ) { - if ( transaction.isAnalyze() ) { + if ( transaction.isAnalyze() && implementation.getException().isEmpty() ) { transaction.getQueryAnalyzer().attachStacktrace( e ); } executedContexts.add( ExecutedContext.ofError( e, implementation ) ); @@ -175,10 +170,10 @@ public List anyQuery( QueryContext context, Statement statement public static List toQueryNodes( QueryContext queries ) { - Processor cypherProcessor = queries.getLanguage().getProcessorSupplier().get(); - List statements = cypherProcessor.parse( queries.getQuery() ); + Processor processor = queries.getLanguage().getProcessorSupplier().get(); + List statements = processor.parse( queries.getQuery() ); - return Pair.zip( statements, List.of( queries.getQuery().split( ";" ) ) ) + return Pair.zip( statements, Arrays.stream( queries.getQuery().split( ";" ) ).filter( q -> !q.trim().isEmpty() ).collect( Collectors.toList() ) ) .stream() .map( p -> ParsedQueryContext.fromQuery( p.right, p.left, queries ) ) .collect( Collectors.toList() ); diff --git a/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java b/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java index 2ea75915a6..f04815864f 100644 --- a/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java +++ b/core/src/main/java/org/polypheny/db/plan/hep/HepAlgVertex.java @@ -35,6 +35,7 @@ import java.util.List; +import lombok.Getter; import org.polypheny.db.algebra.AbstractAlgNode; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgWriter; @@ -48,11 +49,9 @@ /** * HepAlgVertex wraps a real {@link AlgNode} as a vertex in a DAG representing the entire query expression. */ +@Getter public class HepAlgVertex extends AbstractAlgNode { - /** - * Wrapped alg currently chosen for implementation of expression. - */ private AlgNode currentAlg; @@ -118,12 +117,5 @@ void replaceAlg( AlgNode newRel ) { } - /** - * @return current implementation chosen for this vertex - */ - public AlgNode getCurrentAlg() { - return currentAlg; - } - } diff --git a/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java b/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java index 53ebce7670..e895585f0a 100644 --- a/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java +++ b/core/src/main/java/org/polypheny/db/plan/hep/HepPlanner.java @@ -148,7 +148,7 @@ public HepPlanner( HepProgram program, Context context, boolean noDag, Function2 } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public void setRoot( AlgNode alg ) { root = addAlgToGraph( alg ); @@ -156,7 +156,7 @@ public void setRoot( AlgNode alg ) { } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public AlgNode getRoot() { return root; @@ -169,7 +169,7 @@ public List getRules() { } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public boolean addRule( AlgOptRule rule ) { boolean added = allRules.add( rule ); @@ -202,7 +202,7 @@ public boolean removeRule( AlgOptRule rule ) { } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public AlgNode changeTraits( AlgNode alg, AlgTraitSet toTraits ) { // Ignore traits, except for the root, where we remember what the final conversion should be. @@ -213,7 +213,7 @@ public AlgNode changeTraits( AlgNode alg, AlgTraitSet toTraits ) { } - // implement RelOptPlanner + // implement AlgOptPlanner @Override public AlgNode findBestExp() { assert root != null; @@ -552,12 +552,12 @@ private boolean doesConverterApply( ConverterRule converterRule, HepAlgVertex ve AlgTrait outTrait = converterRule.getOutTrait(); List parents = Graphs.predecessorListOf( graph, vertex ); for ( HepAlgVertex parent : parents ) { - AlgNode parentRel = parent.getCurrentAlg(); - if ( parentRel instanceof Converter ) { + AlgNode parentAlg = parent.getCurrentAlg(); + if ( parentAlg instanceof Converter ) { // We don't support converter chains. continue; } - if ( parentRel.getTraitSet().contains( outTrait ) ) { + if ( parentAlg.getTraitSet().contains( outTrait ) ) { // This parent wants the traits produced by the converter. return true; } @@ -645,7 +645,7 @@ private HepAlgVertex applyTransformationResults( HepAlgVertex vertex, HepRuleCal AlgNode bestAlg = null; if ( call.getResults().size() == 1 ) { - // No costing required; skip it to minimize the chance of hitting rels without cost information. + // No costing required; skip it to minimize the chance of hitting Algs without cost information. bestAlg = call.getResults().get( 0 ); } else { AlgOptCost bestCost = null; @@ -816,7 +816,7 @@ private void contractVertices( HepAlgVertex preservedVertex, HepAlgVertex discar private void updateVertex( HepAlgVertex vertex, AlgNode alg ) { if ( alg != vertex.getCurrentAlg() ) { // REVIEW jvs: We'll do this again later during garbage collection. Or we could get rid of mark/sweep garbage collection and do it precisely - // at this point by walking down to all rels which are only reachable from here. + // at this point by walking down to all Algs which are only reachable from here. notifyDiscard( vertex.getCurrentAlg() ); } String oldDigest = vertex.getCurrentAlg().toString(); @@ -839,7 +839,7 @@ private AlgNode buildFinalPlan( HepAlgVertex vertex ) { notifyChosen( alg ); - // Recursively process children, replacing this rel's inputs with corresponding child rels. + // Recursively process children, replacing this Alg's inputs with corresponding child Algs. List inputs = alg.getInputs(); for ( int i = 0; i < inputs.size(); ++i ) { AlgNode child = inputs.get( i ); diff --git a/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java b/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java index 4d8e06ae28..18367320c2 100644 --- a/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java +++ b/core/src/main/java/org/polypheny/db/processing/ImplementationContext.java @@ -62,7 +62,7 @@ public ExecutedContext execute( Statement statement ) { public Optional getException() { - return Optional.of( exception ); + return Optional.ofNullable( exception ); } @@ -93,7 +93,7 @@ public static ExecutedContext ofError( Exception e, ImplementationContext implem public Optional getError() { - return Optional.of( error ); + return Optional.ofNullable( error ); } } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java b/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java index fcf6ea0d20..4f4ad9d4f4 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyBigDecimal.java @@ -96,7 +96,7 @@ public static PolyBigDecimal ofNullable( BigDecimal value ) { @Override public @Nullable String toJson() { - return value == null ? JsonToken.VALUE_NULL.asString() : value.toString(); + return value == null ? JsonToken.VALUE_NULL.asString() : value.toPlainString(); } diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index af42d9d428..1d4cc135b9 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -124,7 +124,7 @@ public class PolyphenyDb { public boolean daemonMode = false; @Option(name = { "-defaultStore" }, description = "Type of default storeId") - public String defaultStoreName = "mongodb"; + public String defaultStoreName = "hsqldb"; @Option(name = { "-defaultSource" }, description = "Type of default source") public String defaultSourceName = "csv"; 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 a9ac3b2c98..3910f20e13 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -211,7 +211,7 @@ public PolyImplementation prepareQuery( AlgRoot logicalRoot, AlgDataType paramet if ( statement.getTransaction().isAnalyze() ) { statement.getOverviewDuration().start( "Processing" ); } - final ProposedImplementations proposedImplementations = prepareQueryList( logicalRoot, parameterRowType, isRouted, isSubquery ); + final ProposedImplementations proposedImplementations = prepareQueries( logicalRoot, parameterRowType, isRouted, isSubquery ); if ( statement.getTransaction().isAnalyze() ) { statement.getOverviewDuration().stop( "Processing" ); @@ -246,7 +246,7 @@ private void attachQueryPlans( AlgRoot logicalRoot ) { } - private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataType parameterRowType, boolean isRouted, boolean isSubQuery ) { + private ProposedImplementations prepareQueries( AlgRoot logicalRoot, AlgDataType parameterRowType, boolean isRouted, boolean isSubQuery ) { boolean isAnalyze = statement.getTransaction().isAnalyze() && !isSubQuery; boolean lock = !isSubQuery; diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/AvaticaInterfacePlugin.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/AvaticaInterfacePlugin.java index 60536993f9..bd9b3fa06c 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/AvaticaInterfacePlugin.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/AvaticaInterfacePlugin.java @@ -76,8 +76,8 @@ public static class AvaticaInterface extends QueryInterface implements PropertyC @SuppressWarnings("WeakerAccess") public static final String INTERFACE_NAME = "AVATICA Interface"; - @SuppressWarnings("WeakerAccess") - public static final String INTERFACE_DESCRIPTION = "AVATICA-SQL query interface supporting the PolySQL dialect."; + @SuppressWarnings({ "WeakerAccess", "unused" }) + public static final String INTERFACE_DESCRIPTION = "AVATICA-SQL query interface supporting the Polypheny SQL dialect."; @SuppressWarnings("WeakerAccess") public static final List AVAILABLE_SETTINGS = ImmutableList.of( new QueryInterfaceSettingInteger( "port", false, true, false, 20591 ), diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java index f67d545148..22a899e625 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoAlg.java @@ -104,7 +104,6 @@ class Implementor extends AlgShuttleImpl implements Serializable { @Getter public boolean hasProject = false; - MongoEntity mongoEntity; @Setter @Getter private boolean isDML; @@ -136,9 +135,9 @@ public void visitChild( int ordinal, AlgNode input ) { public String getPhysicalName( String name ) { - int index = mongoEntity.physical.unwrap( PhysicalTable.class ).columns.stream().map( c -> c.name ).collect( Collectors.toList() ).indexOf( name ); + int index = entity.physical.unwrap( PhysicalTable.class ).columns.stream().map( c -> c.name ).collect( Collectors.toList() ).indexOf( name ); if ( index != -1 ) { - return MongoStore.getPhysicalColumnName( mongoEntity.physical.unwrap( PhysicalTable.class ).columns.stream().map( c -> c.id ).collect( Collectors.toList() ).get( index ) ); + return MongoStore.getPhysicalColumnName( entity.physical.unwrap( PhysicalTable.class ).columns.stream().map( c -> c.id ).collect( Collectors.toList() ).get( index ) ); } throw new GenericRuntimeException( "This column is not part of the table." ); } @@ -201,14 +200,13 @@ public AlgNode visit( RelScan scan ) { public List getNecessaryPhysicalFields() { - return new ArrayList<>( physicalMapper ); + return new ArrayList<>( entity.getRowType().getFieldNames() ); } public List reorderPhysical() { // this is only needed if there is a basic scan without project or group, // where we cannot be sure if the fields are all ordered as intended - assert entity.getRowType().getFieldCount() == physicalMapper.size(); return entity.getRowType().getFieldNames(); } 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 3e31ce0c0a..80f87aa1f2 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 @@ -387,6 +387,11 @@ public PhysicalEntity normalize() { } + public String getPhysicalName( String logicalName ) { + return fields.stream().filter( f -> f.logicalName.equals( logicalName ) ).map( f -> f.name ).findFirst().orElse( null ); + } + + /*@Override @@ -485,17 +490,16 @@ public Enumerable find( String filterJson, String projectJson, Mong */ @SuppressWarnings("UnusedDeclaration") public Enumerable handleDirectDML( Operation operation, String filter, List operations, boolean onlyOne, boolean needsDocument ) { - MongoEntity mongoEntity = getEntity(); PolyXid xid = dataContext.getStatement().getTransaction().getXid(); - dataContext.getStatement().getTransaction().registerInvolvedAdapter( AdapterManager.getInstance().getStore( (int) mongoEntity.getStoreId() ) ); - GridFSBucket bucket = mongoEntity.getMongoNamespace().getBucket(); + dataContext.getStatement().getTransaction().registerInvolvedAdapter( AdapterManager.getInstance().getStore( entity.getAdapterId() ) ); + GridFSBucket bucket = entity.getMongoNamespace().getBucket(); try { - final long changes = doDML( operation, filter, operations, onlyOne, needsDocument, mongoEntity, xid, bucket ); + final long changes = doDML( operation, filter, operations, onlyOne, needsDocument, xid, bucket ); return Linq4j.asEnumerable( Collections.singletonList( PolyLong.of( changes ) ) ); } catch ( MongoException e ) { - mongoEntity.getTransactionProvider().rollback( xid ); + entity.getTransactionProvider().rollback( xid ); log.warn( "Failed" ); log.warn( String.format( "op: %s\nfilter: %s\nops: [%s]", operation.name(), filter, String.join( ";", operations ) ) ); log.warn( e.getMessage() ); @@ -504,8 +508,8 @@ public Enumerable handleDirectDML( Operation operation, String filter, L } - private long doDML( Operation operation, String filter, List operations, boolean onlyOne, boolean needsDocument, MongoEntity mongoEntity, PolyXid xid, GridFSBucket bucket ) { - ClientSession session = mongoEntity.getTransactionProvider().startTransaction( xid, true ); + private long doDML( Operation operation, String filter, List operations, boolean onlyOne, boolean needsDocument, PolyXid xid, GridFSBucket bucket ) { + ClientSession session = entity.getTransactionProvider().startTransaction( xid, true ); long changes = 0; switch ( operation ) { @@ -515,12 +519,12 @@ private long doDML( Operation operation, String filter, List operations, // prepared MongoDynamic util = new MongoDynamic( BsonDocument.parse( operations.get( 0 ) ), bucket, dataContext ); List inserts = util.getAll( dataContext.getParameterValues() ); - mongoEntity.getCollection().insertMany( session, inserts ); + entity.getCollection().insertMany( session, inserts ); return inserts.size(); } else { // direct List docs = operations.stream().map( BsonDocument::parse ).map( BsonUtil::asDocument ).collect( Collectors.toList() ); - mongoEntity.getCollection().insertMany( session, docs ); + entity.getCollection().insertMany( session, docs ); return docs.size(); } @@ -534,24 +538,24 @@ private long doDML( Operation operation, String filter, List operations, for ( Map parameterValue : dataContext.getParameterValues() ) { if ( onlyOne ) { if ( needsDocument ) { - changes += mongoEntity + changes += entity .getCollection() .updateOne( session, filterUtil.insert( parameterValue ), docUtil.insert( parameterValue ) ) .getModifiedCount(); } else { - changes += mongoEntity + changes += entity .getCollection() .updateOne( session, filterUtil.insert( parameterValue ), Collections.singletonList( docUtil.insert( parameterValue ) ) ) .getModifiedCount(); } } else { if ( needsDocument ) { - changes += mongoEntity + changes += entity .getCollection() .updateMany( session, filterUtil.insert( parameterValue ), docUtil.insert( parameterValue ) ) .getModifiedCount(); } else { - changes += mongoEntity + changes += entity .getCollection() .updateMany( session, filterUtil.insert( parameterValue ), Collections.singletonList( docUtil.insert( parameterValue ) ) ) .getModifiedCount(); @@ -561,12 +565,12 @@ private long doDML( Operation operation, String filter, List operations, } else { // direct if ( onlyOne ) { - changes = mongoEntity + changes = entity .getCollection() .updateOne( session, BsonDocument.parse( filter ), BsonDocument.parse( operations.get( 0 ) ) ) .getModifiedCount(); } else { - changes = mongoEntity + changes = entity .getCollection() .updateMany( session, BsonDocument.parse( filter ), BsonDocument.parse( operations.get( 0 ) ) ) .getModifiedCount(); @@ -586,16 +590,16 @@ private long doDML( Operation operation, String filter, List operations, filters = filterUtil.getAll( dataContext.getParameterValues(), DeleteManyModel::new ); } - changes = mongoEntity.getCollection().bulkWrite( session, filters ).getDeletedCount(); + changes = entity.getCollection().bulkWrite( session, filters ).getDeletedCount(); } else { // direct if ( onlyOne ) { - changes = mongoEntity + changes = entity .getCollection() .deleteOne( session, BsonDocument.parse( filter ) ) .getDeletedCount(); } else { - changes = mongoEntity + changes = entity .getCollection() .deleteMany( session, BsonDocument.parse( filter ) ) .getDeletedCount(); diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEnumerator.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEnumerator.java index 15d8fb53b5..cc4fa09679 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEnumerator.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEnumerator.java @@ -49,10 +49,13 @@ import org.polypheny.db.adapter.mongodb.util.MongoTupleType; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.type.entity.PolyBigDecimal; +import org.polypheny.db.type.entity.PolyDate; import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyLong; import org.polypheny.db.type.entity.PolyNull; import org.polypheny.db.type.entity.PolyString; +import org.polypheny.db.type.entity.PolyTime; +import org.polypheny.db.type.entity.PolyTimeStamp; import org.polypheny.db.type.entity.PolyValue; @@ -252,11 +255,19 @@ private static PolyValue convert( BsonValue o, MongoTupleType type ) { case BIGINT: return PolyLong.of( o.asNumber().longValue() ); case INTEGER: + case SMALLINT: + case TINYINT: return PolyInteger.of( o.asNumber().longValue() ); case VARCHAR: return PolyString.of( o.asString().getValue() ); case DECIMAL: return PolyBigDecimal.of( o.asNumber().decimal128Value().bigDecimalValue() ); + case TIMESTAMP: + return PolyTimeStamp.of( o.asNumber().longValue() ); + case TIME: + return PolyTime.of( o.asNumber().longValue() ); + case DATE: + return PolyDate.of( o.asNumber().longValue() ); } throw new NotImplementedException(); diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoPlugin.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoPlugin.java index 341849699d..34590d7799 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoPlugin.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoPlugin.java @@ -339,7 +339,7 @@ public void dropCollection( Context context, AllocationCollection allocation ) { public void dropTable( Context context, long allocId ) { commitAll(); context.getStatement().getTransaction().registerInvolvedAdapter( this ); - PhysicalTable physical = storeCatalog.fromAllocation( allocId, PhysicalTable.class ); + PhysicalEntity physical = storeCatalog.fromAllocation( allocId, PhysicalEntity.class ); this.currentNamespace.database.getCollection( physical.name ).drop(); storeCatalog.removeAllocAndPhysical( allocId ); @@ -599,10 +599,10 @@ private enum IndexTypes { DEFAULT, COMPOUND, SINGLE; - /*MULTIKEY, - GEOSPATIAL, - TEXT, - HASHED;*/ + /*MULTIKEY, + GEOSPATIAL, + TEXT, + HASHED;*/ public IndexMethodModel asMethod() { diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java deleted file mode 100644 index 0dec512d2d..0000000000 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoRowType.java +++ /dev/null @@ -1,74 +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.adapter.mongodb; - -import java.util.HashMap; -import java.util.List; -import org.polypheny.db.adapter.mongodb.MongoAlg.Implementor; -import org.polypheny.db.adapter.mongodb.MongoPlugin.MongoStore; -import org.polypheny.db.algebra.type.AlgDataTypeField; -import org.polypheny.db.algebra.type.AlgRecordType; -import org.polypheny.db.algebra.type.StructKind; -import org.polypheny.db.catalog.entity.physical.PhysicalTable; - -public class MongoRowType extends AlgRecordType { - - private final HashMap idToName = new HashMap<>(); - private final HashMap nameToId = new HashMap<>(); - - - public MongoRowType( StructKind kind, List fields, MongoEntity mongoEntity ) { - super( kind, fields ); - mongoEntity.physical.unwrap( PhysicalTable.class ).columns.forEach( column -> { - idToName.put( column.id, column.name ); - nameToId.put( column.name, column.id ); - } ); - } - - - public Long getId( String name ) { - if ( name.contains( "." ) ) { - String[] splits = name.split( "\\." ); - return nameToId.get( splits[splits.length - 1] ); - } - - return nameToId.get( name ); - } - - - public String getPhysicalName( String name, Implementor implementor ) { - String id = MongoStore.getPhysicalColumnName( getId( name ) ); - implementor.physicalMapper.add( id ); - return id; - } - - - public String getName( Long id ) { - return idToName.get( id ); - } - - - public static AlgRecordType fromRecordType( AlgRecordType rowType, MongoEntity mongoEntity ) { - return new MongoRowType( rowType.getStructKind(), rowType.getFields(), mongoEntity ); - } - - - public boolean containsPhysicalName( String name ) { - return nameToId.containsKey( name ); - } - -} diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoAggregate.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoAggregate.java index a8c719dc51..3d7d24d4ab 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoAggregate.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoAggregate.java @@ -17,9 +17,10 @@ package org.polypheny.db.adapter.mongodb.rules; -import java.util.AbstractList; +import com.google.common.collect.Streams; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.polypheny.db.adapter.mongodb.MongoAlg; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.InvalidAlgException; @@ -100,19 +101,7 @@ public void implement( Implementor implementor ) { implementor.add( null, "{$group: " + Util.toString( list, "{", ", ", "}" ) + "}" ); final List fixups; if ( groupSet.cardinality() == 1 ) { - fixups = new AbstractList<>() { - @Override - public String get( int index ) { - final String outName = outNames.get( index ); - return MongoRules.maybeQuote( outName ) + ": " + MongoRules.maybeQuote( "$" + (index == 0 ? "_id" : outName) ); - } - - - @Override - public int size() { - return outNames.size(); - } - }; + fixups = Streams.mapWithIndex( outNames.stream(), ( n, j ) -> MongoRules.maybeQuote( n ) + ": " + MongoRules.maybeQuote( "$" + (j == 0 ? "_id" : n) ) ).collect( Collectors.toList() ); } else { fixups = new ArrayList<>(); fixups.add( "_id: 0" ); @@ -134,7 +123,7 @@ public int size() { private String toMongo( AggFunction aggregation, List inNames, List args, Implementor implementor ) { if ( aggregation.getOperatorName() == OperatorName.COUNT ) { - if ( args.size() == 0 ) { + if ( args.isEmpty() ) { return "{$sum: 1}"; } else { assert args.size() == 1; diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java index 8f15108be6..3f975836cb 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoProject.java @@ -33,11 +33,14 @@ import org.polypheny.db.algebra.core.Project; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.algebra.type.AlgDataTypeFactory; +import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.rex.RexCall; +import org.polypheny.db.rex.RexIndexRef; import org.polypheny.db.rex.RexNode; import org.polypheny.db.rex.RexVisitorImpl; import org.polypheny.db.util.Pair; @@ -50,12 +53,27 @@ public class MongoProject extends Project implements MongoAlg { public MongoProject( AlgOptCluster cluster, AlgTraitSet traitSet, AlgNode input, List projects, AlgDataType rowType ) { - super( cluster, traitSet, input, projects, rowType ); + super( cluster, traitSet, input, projects, adjustRowType( rowType, projects, input ) ); assert getConvention() == CONVENTION; //assert getConvention() == input.getConvention(); // TODO DL fix logicalFilter bug } + private static AlgDataType adjustRowType( AlgDataType rowType, List projects, AlgNode input ) { + final AlgDataTypeFactory.Builder fieldInfo = AlgDataTypeFactory.DEFAULT.builder(); + + for ( Pair pair : Pair.zip( rowType.getFields(), projects ) ) { + fieldInfo.add( + pair.left.getName(), + pair.right instanceof RexIndexRef + ? input.getRowType().getFields().get( ((RexIndexRef) pair.right).getIndex() ).getPhysicalName() + : pair.left.getPhysicalName(), + pair.right.getType() ); + } + return fieldInfo.build(); + } + + @Override public Project copy( AlgTraitSet traitSet, AlgNode input, List projects, AlgDataType rowType ) { return new MongoProject( getCluster(), traitSet, input, projects, rowType ); 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 98bd411b30..7cc15fcdf7 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 @@ -655,7 +655,7 @@ private MongoProjectRule() { && !containsIncompatible( project ) && !UnsupportedRexCallVisitor.containsModelItem( project.getProjects() ), Convention.NONE, MongoAlg.CONVENTION, - "MongoProjectRule" ); + MongoProjectRule.class.getSimpleName() ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java index a7110a3af8..1b9304c38d 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoSort.java @@ -51,7 +51,7 @@ public MongoSort( AlgOptCluster cluster, AlgTraitSet traitSet, AlgNode child, Al @Override public Sort copy( AlgTraitSet traitSet, AlgNode newInput, AlgCollation newCollation, ImmutableList fieldExps, RexNode offset, RexNode fetch ) { - return new MongoSort( getCluster(), traitSet, input, collation, fieldExps, offset, fetch ); + return new MongoSort( getCluster(), traitSet, newInput, collation, fieldExps, offset, fetch ); } @@ -88,10 +88,10 @@ public void implement( Implementor implementor ) { implementor.add( null, "{$sort: " + Util.toString( keys, "{", ", ", "}" ) + "}" ); } if ( offset != null ) { - implementor.add( null, "{$skip: " + ((RexLiteral) offset).getValue() + "}" ); + implementor.add( null, "{$skip: " + ((RexLiteral) offset).getValue().toJson() + "}" ); } if ( fetch != null ) { - implementor.add( null, "{$limit: " + ((RexLiteral) fetch).getValue() + "}" ); + implementor.add( null, "{$limit: " + ((RexLiteral) fetch).getValue().toJson() + "}" ); } } 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 0adcff4bf4..dcf1d3d2d1 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 @@ -71,10 +71,10 @@ protected MongoTableModify( MongoEntity entity, AlgNode input, Operation operation, - List updateColumnList, - List sourceExpressionList, + List updateColumns, + List sourceExpressions, boolean flattened ) { - super( cluster, traitSet, entity, input, operation, updateColumnList, sourceExpressionList, flattened ); + super( cluster, traitSet, entity, input, operation, updateColumns, sourceExpressions, flattened ); this.bucket = entity.unwrap( MongoEntity.class ).getMongoNamespace().getBucket(); } @@ -154,32 +154,33 @@ private void handleUpdate( Implementor implementor ) { List docDocs = new ArrayList<>(); GridFSBucket bucket = implementor.getBucket(); for ( RexNode el : getSourceExpressions() ) { + String physicalName = entity.getPhysicalName( getUpdateColumns().get( pos ) ); if ( el.isA( Kind.LITERAL ) ) { doc.append( - rowType.getFields().get( pos ).getPhysicalName(),//getPhysicalName( getUpdateColumns().get( pos ), implementor ), + physicalName,//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.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + physicalName,//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.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + physicalName,//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), BsonUtil.getBsonArray( call, bucket ) ); } } else if ( el.isA( Kind.DYNAMIC_PARAM ) ) { doc.append( - rowType.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + physicalName,//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), new BsonDynamic( (RexDynamicParam) el ) ); } else if ( el.isA( Kind.FIELD_ACCESS ) ) { doc.append( - rowType.getFields().get( pos ).getPhysicalName(),//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), + physicalName,//rowType.getPhysicalName( getUpdateColumns().get( pos ), implementor ), new BsonString( - "$" + rowType.getFields().get( pos ).getPhysicalName() ) );//rowType.getPhysicalName( ((RexFieldAccess) el).getField().getName(), implementor ) ) ); + "$" + physicalName ) );//rowType.getPhysicalName( ((RexFieldAccess) el).getField().getName(), implementor ) ) ); } pos++; } @@ -401,11 +402,12 @@ private void handlePreparedInsert( Implementor implementor, MongoProject input ) int pos = 0; for ( RexNode rexNode : input.getChildExps() ) { + String physicalName = entity.getPhysicalName( input.getRowType().getFields().get( pos ).getName() ); if ( rexNode instanceof RexDynamicParam ) { // preparedInsert - doc.append( entity.fields.get( pos ).name, new BsonDynamic( (RexDynamicParam) rexNode ) ); + doc.append( physicalName, new BsonDynamic( (RexDynamicParam) rexNode ) ); } else if ( rexNode instanceof RexLiteral ) { - doc.append( entity.fields.get( pos ).name, BsonUtil.getAsBson( (RexLiteral) rexNode, bucket ) ); + doc.append( physicalName, BsonUtil.getAsBson( (RexLiteral) rexNode, bucket ) ); } else if ( rexNode instanceof RexCall ) { PolyType type = this.entity .getRowType( getCluster().getTypeFactory() ) @@ -415,7 +417,7 @@ private void handlePreparedInsert( Implementor implementor, MongoProject input ) .getComponentType() .getPolyType(); - doc.append( entity.fields.get( pos ).name, getBsonArray( (RexCall) rexNode, type, bucket ) ); + doc.append( physicalName, getBsonArray( (RexCall) rexNode, type, bucket ) ); } else if ( rexNode.getKind() == Kind.INPUT_REF && input.getInput() instanceof MongoValues ) { handleDirectInsert( implementor, (MongoValues) input.getInput() ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java index 2df8ff07a2..d824449597 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlProcessor.java @@ -17,10 +17,11 @@ package org.polypheny.db.sql; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.calcite.avatica.AvaticaSeverity; @@ -108,9 +109,15 @@ public SqlProcessor() { @Override public List parse( String query ) { + // todo we should not split the query here, but rather in the parser + return Arrays.stream( query.split( ";" ) ).filter( s -> !s.trim().isEmpty() ).map( this::parseSingle ).collect( Collectors.toList() ); + } + + + public Node parseSingle( String query ) { final StopWatch stopWatch = new StopWatch(); if ( log.isDebugEnabled() ) { - log.debug( "Parsing PolySQL statement ..." ); + log.debug( "Parsing SQL statement ..." ); } stopWatch.start(); Node parsed; @@ -131,9 +138,9 @@ public List parse( String query ) { log.trace( "Parsed query: [{}]", parsed ); } if ( log.isDebugEnabled() ) { - log.debug( "Parsing PolySQL statement ... done. [{}]", stopWatch ); + log.debug( "Parsing SQL statement ... done. [{}]", stopWatch ); } - return ImmutableList.of( parsed ); + return parsed; } 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 efe8c4ab47..5a75398256 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 @@ -132,6 +132,7 @@ public static void anyQuery( Context ctx ) { public static List> anyQueryResult( QueryContext context, UIRequest request ) { Transaction transaction = context.getTransactionManager().startTransaction( context.getUserId(), Catalog.defaultNamespaceId, context.isAnalysed(), context.getOrigin() ); + transaction.setUseCache( context.isUsesCache() ); attachAnalyzerIfSpecified( context, crud, transaction ); List executedContexts = LanguageManager.getINSTANCE().anyQuery( context, transaction.createStatement() ); From e1d3da3835598359b656df6eb639921634ae7235 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 28 Nov 2023 11:17:51 +0100 Subject: [PATCH 13/15] fix for insert from other entity --- .../db/routing/routers/BaseRouter.java | 6 +-- .../db/routing/routers/DmlRouterImpl.java | 11 ++++- .../org/polypheny/db/avatica/DbmsMeta.java | 2 +- .../polypheny/db/avatica/PolySignature.java | 46 ++++++++++++++----- .../polypheny/db/adapter/neo4j/NeoEntity.java | 25 ++++++++++ 5 files changed, 74 insertions(+), 16 deletions(-) diff --git a/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java b/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java index 51323a464f..7ef3a3754f 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java +++ b/dbms/src/main/java/org/polypheny/db/routing/routers/BaseRouter.java @@ -61,6 +61,7 @@ import org.polypheny.db.catalog.entity.allocation.AllocationTable; import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalColumn; +import org.polypheny.db.catalog.entity.logical.LogicalEntity; import org.polypheny.db.catalog.entity.logical.LogicalGraph; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; @@ -230,12 +231,11 @@ public RoutedAlgBuilder handleRelScan( Statement statement, Entity entity ) { - org.polypheny.db.catalog.entity.logical.LogicalEntity table; + LogicalEntity table; if ( entity.unwrap( LogicalTable.class ) != null ) { List allocations = statement.getTransaction().getSnapshot().alloc().getFromLogical( entity.id ); - - table = entity.unwrap( org.polypheny.db.catalog.entity.logical.LogicalEntity.class ); + table = entity.unwrap( LogicalEntity.class ); builder.scan( allocations.get( 0 ) ); } else if ( entity.unwrap( AllocationTable.class ) != null ) { builder.scan( entity.unwrap( AllocationTable.class ) ); 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 559080b6eb..a4381f87d7 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 @@ -61,6 +61,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.allocation.AllocationColumn; import org.polypheny.db.catalog.entity.allocation.AllocationEntity; import org.polypheny.db.catalog.entity.allocation.AllocationPartition; @@ -794,7 +795,7 @@ private AlgBuilder buildDml( if ( node instanceof LogicalDocumentScan ) { return handleLogicalDocumentScan( builder, statement ); } else if ( node instanceof LogicalRelScan && node.getEntity() != null ) { - return handleRelScan( builder, statement, allocEntity != null ? allocEntity : ((LogicalRelScan) node).entity ); + return handleRelScan( builder, statement, getParentOrCurrent( allocEntity, ((LogicalRelScan) node).entity ) ); } else if ( node instanceof LogicalDocumentValues ) { return handleDocuments( (LogicalDocumentValues) node, builder ); } else if ( node instanceof Values ) { @@ -809,6 +810,14 @@ private AlgBuilder buildDml( } + private Entity getParentOrCurrent( AllocationEntity allocEntity, Entity entity ) { + if ( allocEntity == null || allocEntity.logicalId != entity.id ) { + return entity; + } + return allocEntity; + } + + private RoutedAlgBuilder handleLogicalFilter( AlgNode node, RoutedAlgBuilder builder, LogicalTable table, List placements, Statement statement ) { List columns = statement.getTransaction().getSnapshot().rel().getColumns( table.id ); if ( columns.size() != placements.size() ) { // partitioned, check if there is a illegal condition diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index 259c686766..7bd5c08e7b 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -1358,7 +1358,7 @@ private void prepare( StatementHandle h, String sql ) throws NoSuchStatementExce .transactionManager( transactionManager ) .build(); - PolySignature signature = PolySignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement() ).get( 0 ).getImplementation() ); + PolySignature signature = PolySignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement() ).get( 0 ) ); h.signature = signature; statementHandle.setSignature( signature ); diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java index a8f47081c4..9d242f7a22 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/PolySignature.java @@ -36,6 +36,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.logistic.DataModel; +import org.polypheny.db.processing.ImplementationContext; import org.polypheny.db.routing.ExecutionTimeMonitor; import org.polypheny.db.runtime.Bindable; import org.polypheny.db.schema.PolyphenyDbSchema; @@ -87,10 +88,14 @@ public PolySignature( } - public static PolySignature from( PolyImplementation prepareQuery ) { + public static PolySignature from( ImplementationContext prepareQuery ) { final List parameters = new ArrayList<>(); - if ( prepareQuery.rowType != null ) { - for ( AlgDataTypeField field : prepareQuery.rowType.getFields() ) { + if ( prepareQuery.getImplementation() == null ) { + return fromError( prepareQuery ); + } + PolyImplementation implementation = prepareQuery.getImplementation(); + if ( implementation.rowType != null ) { + for ( AlgDataTypeField field : prepareQuery.getImplementation().rowType.getFields() ) { AlgDataType type = field.getType(); parameters.add( new AvaticaParameter( @@ -107,16 +112,35 @@ public static PolySignature from( PolyImplementation prepareQuery ) { "", parameters, new HashMap<>(), - prepareQuery.getRowType(), - prepareQuery.getColumns(), - prepareQuery.getCursorFactory(), + implementation.getRowType(), + implementation.getColumns(), + implementation.getCursorFactory(), + null, + ImmutableList.of(), + implementation.getMaxRowCount(), + implementation.getBindable(), + implementation.getStatementType(), + implementation.getExecutionTimeMonitor(), + implementation.getDataModel() + ); + } + + + private static PolySignature fromError( ImplementationContext prepareQuery ) { + return new PolySignature( + "", + new ArrayList<>(), + new HashMap<>(), + null, + new ArrayList<>(), + null, null, ImmutableList.of(), - prepareQuery.getMaxRowCount(), - prepareQuery.getBindable(), - prepareQuery.getStatementType(), - prepareQuery.getExecutionTimeMonitor(), - prepareQuery.getDataModel() + -1, + null, + PolyImplementation.toStatementType( prepareQuery.getQuery().getQueryNode().getKind() ), + null, + prepareQuery.getQuery().getLanguage().getDataModel() ); } 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 6e1f4cd442..67ec0da1a2 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 @@ -18,6 +18,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,11 +42,16 @@ import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.algebra.logical.relational.LogicalRelModify; import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.algebra.type.AlgDataTypeFactory; +import org.polypheny.db.algebra.type.AlgDataTypeImpl; +import org.polypheny.db.algebra.type.AlgProtoDataType; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.Entity; +import org.polypheny.db.catalog.entity.physical.PhysicalColumn; import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalField; import org.polypheny.db.catalog.entity.physical.PhysicalGraph; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; @@ -144,6 +150,25 @@ public PhysicalEntity normalize() { } + public AlgDataType getRowType() { + if ( dataModel == DataModel.RELATIONAL ) { + return buildProto().apply( AlgDataTypeFactory.DEFAULT ); + } + return super.getRowType(); + } + + + public AlgProtoDataType buildProto() { + final AlgDataTypeFactory.Builder fieldInfo = AlgDataTypeFactory.DEFAULT.builder(); + + for ( PhysicalColumn column : fields.stream().map( f -> f.unwrap( PhysicalColumn.class ) ).sorted( Comparator.comparingInt( a -> a.position ) ).collect( Collectors.toList() ) ) { + AlgDataType sqlType = column.getAlgDataType( AlgDataTypeFactory.DEFAULT ); + fieldInfo.add( column.id, column.logicalName, column.name, sqlType ).nullable( column.nullable ); + } + + return AlgDataTypeImpl.proto( fieldInfo.build() ); + } + public static class NeoQueryable extends AbstractEntityQueryable { private final AlgDataType rowType; From 1eb7d3ed2dee42ccd06431b54772475283e9a190 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 28 Nov 2023 21:53:38 +0100 Subject: [PATCH 14/15] removing legacy code, fixes, for neo4j, file and cottontail adapters --- .../db/languages/LanguageManager.java | 18 +- .../org/polypheny/db/type/PolyTypeUtil.java | 3 + .../db/excluded/CassandraExcluded.java | 21 - .../constraints/ForeignKeyConstraintTest.java | 3 +- .../db/constraints/UniqueConstraintTest.java | 3 +- .../db/crossmodel/CrossModelTestTemplate.java | 3 +- .../java/org/polypheny/db/cypher/DdlTest.java | 3 - .../org/polypheny/db/jdbc/JdbcArrayTest.java | 14 +- .../org/polypheny/db/jdbc/JdbcDdlTest.java | 3 +- .../org/polypheny/db/jdbc/JdbcDmlTest.java | 3 +- .../db/jdbc/JdbcPreparedStatementsTest.java | 3 +- .../polypheny/db/misc/DataMigratorTest.java | 3 +- .../db/misc/HorizontalPartitioningTest.java | 4 +- .../polypheny/db/misc/UnsupportedDmlTest.java | 3 +- .../db/misc/VerticalPartitioningTest.java | 3 +- .../org/polypheny/db/mql/AggregateTest.java | 3 +- .../java/org/polypheny/db/mql/DdlTest.java | 3 +- .../java/org/polypheny/db/mql/DmlTest.java | 3 +- .../java/org/polypheny/db/mql/FindTest.java | 3 +- .../org/polypheny/db/restapi/RestTest.java | 2 - .../db/sql/SqlInsertSelectFromTest.java | 3 +- .../db/sql/SqlLimitOffsetFetchTest.java | 3 +- .../polypheny/db/sql/SqlSortExcludeTest.java | 3 +- .../polypheny/db/sql/clause/GroupByTest.java | 3 +- .../org/polypheny/db/sql/clause/JoinTest.java | 3 +- .../polypheny/db/sql/clause/SelectTest.java | 3 +- .../org/polypheny/db/sql/fun/CaseTest.java | 3 +- .../sql/fun/CeilFloorSignFunctionsTest.java | 3 +- .../db/sql/fun/DayTimeFunctionsTest.java | 3 +- .../sql/fun/LogExponentialFunctionsTest.java | 3 +- .../polypheny/db/sql/fun/OperatorsTest.java | 3 +- .../db/sql/fun/PowerAbsModFunctionTest.java | 3 +- .../db/sql/fun/SqlDistanceFunctionTest.java | 3 +- .../db/sql/fun/StringFunctionsTest.java | 3 +- .../sql/fun/TrigonometricFunctionsTest.java | 3 +- .../db/sql/fun/TypeConversionTest.java | 3 +- .../db/sql/view/ComplexViewTest.java | 3 +- .../org/polypheny/db/sql/view/ViewTest.java | 3 +- plugins/cassandra-adapter/build.gradle | 80 - plugins/cassandra-adapter/gradle.properties | 27 - .../adapter/jdbc/CassandraSourcePlugin.java | 149 - .../adapter/cottontail/CottontailEntity.java | 13 +- .../cottontail/CottontailNamespace.java | 1 + .../adapter/cottontail/CottontailPlugin.java | 3 + .../cottontail/algebra/CottontailAlg.java | 1 - .../cottontail/algebra/CottontailProject.java | 4 +- .../cottontail/algebra/CottontailScan.java | 2 +- .../cottontail/algebra/CottontailSort.java | 2 +- .../algebra/CottontailTableModify.java | 6 +- .../CottontailToEnumerableConverter.java | 39 +- .../cottontail/algebra/CottontailValues.java | 2 +- .../CottontailBatchInsertEnumerable.java | 22 +- .../CottontailDeleteEnumerable.java | 24 +- .../CottontailEnumerableFactory.java | 27 +- .../CottontailInsertEnumerable.java | 22 +- .../CottontailQueryEnumerable.java | 22 +- .../CottontailUpdateEnumerable.java | 16 +- .../CottontailTableModificationRule.java | 2 +- .../cottontail/util/CottontailTypeUtil.java | 6 +- .../adapter/cottontail/util/Linq4JFixer.java | 85 +- plugins/druid-adapter/build.gradle | 79 - plugins/druid-adapter/gradle.properties | 27 - .../druid/BinaryOperatorConversion.java | 81 - .../adapter/druid/CeilOperatorConversion.java | 99 - .../db/adapter/druid/ComplexMetric.java | 107 - .../adapter/druid/DefaultDimensionSpec.java | 101 - .../db/adapter/druid/DimensionSpec.java | 57 - .../druid/DirectOperatorConversion.java | 76 - .../db/adapter/druid/DruidConnection.java | 43 - .../db/adapter/druid/DruidConnectionImpl.java | 762 --- .../db/adapter/druid/DruidDateTimeUtils.java | 400 -- .../db/adapter/druid/DruidEntity.java | 297 - .../db/adapter/druid/DruidExpressions.java | 283 - .../polypheny/db/adapter/druid/DruidJson.java | 50 - .../db/adapter/druid/DruidJsonFilter.java | 658 -- .../db/adapter/druid/DruidPlugin.java | 32 - .../db/adapter/druid/DruidQuery.java | 1795 ------ .../db/adapter/druid/DruidRules.java | 836 --- .../db/adapter/druid/DruidSchema.java | 110 - .../adapter/druid/DruidSqlCastConverter.java | 159 - .../druid/DruidSqlOperatorConverter.java | 68 - .../db/adapter/druid/DruidTableFactory.java | 184 - .../polypheny/db/adapter/druid/DruidType.java | 111 - .../druid/ExtractOperatorConversion.java | 103 - .../druid/ExtractionDimensionSpec.java | 134 - .../db/adapter/druid/ExtractionFunction.java | 45 - .../druid/FloorOperatorConversion.java | 93 - .../db/adapter/druid/Granularities.java | 149 - .../db/adapter/druid/Granularity.java | 75 - .../adapter/druid/NaryOperatorConverter.java | 79 - .../polypheny/db/adapter/druid/QueryType.java | 59 - .../druid/SubstringOperatorConversion.java | 103 - .../adapter/druid/TimeExtractionFunction.java | 254 - .../druid/UnaryPrefixOperatorConversion.java | 81 - .../druid/UnarySuffixOperatorConversion.java | 80 - .../db/adapter/druid/VirtualColumn.java | 130 - .../db/adapter/druid/package-info.java | 7 - .../adapter/druid/DruidQueryFilterTest.java | 131 - .../org/polypheny/db/test/DruidAdapterIT.java | 4437 ------------- .../polypheny/db/test/DruidAdapterIT2.java | 3810 ------------ .../db/test/DruidDateRangeRulesTest.java | 226 - .../druid-foodmart-model-timestamp.json | 137 - .../test/resources/druid-foodmart-model.json | 137 - .../src/test/resources/druid-wiki-model.json | 72 - .../druid-wiki-no-columns-model.json | 26 - .../resources/druid-wiki-no-tables-model.json | 15 - .../src/test/resources/foodmart-schema.spec | 73 - .../src/test/resources/log4j.properties | 10 - plugins/elasticsearch-adapter/build.gradle | 100 - .../elasticsearch-adapter/gradle.properties | 27 - .../elasticsearch/ElasticsearchAggregate.java | 187 - .../elasticsearch/ElasticsearchConstants.java | 63 - .../elasticsearch/ElasticsearchEntity.java | 429 -- .../ElasticsearchEnumerators.java | 157 - .../elasticsearch/ElasticsearchFilter.java | 116 - .../elasticsearch/ElasticsearchJson.java | 769 --- .../elasticsearch/ElasticsearchMapping.java | 200 - .../elasticsearch/ElasticsearchMethod.java | 78 - .../elasticsearch/ElasticsearchPlugin.java | 32 - .../elasticsearch/ElasticsearchProject.java | 126 - .../elasticsearch/ElasticsearchRel.java | 163 - .../elasticsearch/ElasticsearchRules.java | 326 - .../elasticsearch/ElasticsearchScan.java | 122 - .../elasticsearch/ElasticsearchSchema.java | 169 - .../ElasticsearchSearchResult.java | 200 - .../elasticsearch/ElasticsearchSort.java | 96 - .../ElasticsearchToEnumerableConverter.java | 152 - ...lasticsearchToEnumerableConverterRule.java | 70 - .../elasticsearch/ElasticsearchTransport.java | 323 - .../elasticsearch/ElasticsearchVersion.java | 75 - .../MapProjectionFieldVisitor.java | 64 - .../elasticsearch/PredicateAnalyzer.java | 1102 ---- .../adapter/elasticsearch/QueryBuilders.java | 575 -- .../db/adapter/elasticsearch/Scrolling.java | 193 - .../adapter/elasticsearch/package-info.java | 7 - .../elasticsearch/AggregationTest.java | 297 - .../elasticsearch/BooleanLogicTest.java | 188 - .../db/adapter/elasticsearch/Closer.java | 57 - .../ElasticSearchAdapterTest.java | 612 -- .../elasticsearch/ElasticsearchJsonTest.java | 199 - .../ElasticsearchVersionTest.java | 85 - .../EmbeddedElasticsearchNode.java | 183 - .../EmbeddedElasticsearchPolicy.java | 244 - .../elasticsearch/Projection2Test.java | 238 - .../adapter/elasticsearch/ProjectionTest.java | 125 - .../elasticsearch/QueryBuildersTest.java | 165 - .../adapter/elasticsearch/ScrollingTest.java | 119 - .../db/test/ElasticsearchChecker.java | 144 - .../src/test/resources/log4j2.xml | 17 - .../src/test/resources/zips-mini.json | 149 - plugins/geode-adapter/build.gradle | 94 - plugins/geode-adapter/gradle.properties | 27 - .../db/adapter/geode/GeodePlugin.java | 32 - .../adapter/geode/algebra/GeodeAggregate.java | 138 - .../db/adapter/geode/algebra/GeodeAlg.java | 147 - .../db/adapter/geode/algebra/GeodeEntity.java | 279 - .../geode/algebra/GeodeEnumerator.java | 116 - .../db/adapter/geode/algebra/GeodeFilter.java | 407 -- .../adapter/geode/algebra/GeodeProject.java | 91 - .../db/adapter/geode/algebra/GeodeRules.java | 398 -- .../db/adapter/geode/algebra/GeodeScan.java | 107 - .../db/adapter/geode/algebra/GeodeSchema.java | 88 - .../db/adapter/geode/algebra/GeodeSort.java | 121 - .../algebra/GeodeToEnumerableConverter.java | 171 - .../GeodeToEnumerableConverterRule.java | 64 - .../adapter/geode/algebra/package-info.java | 6 - .../geode/simple/GeodeSimpleEnumerator.java | 104 - .../simple/GeodeSimpleScannableEntity.java | 96 - .../geode/simple/GeodeSimpleSchema.java | 86 - .../db/adapter/geode/simple/package-info.java | 6 - .../db/adapter/geode/util/GeodeUtils.java | 326 - .../geode/util/JavaTypeFactoryExtImpl.java | 120 - .../db/adapter/geode/util/package-info.java | 6 - .../geode/algebra/AbstractGeodeTest.java | 51 - .../geode/algebra/GeodeAllDataTypesTest.java | 269 - .../geode/algebra/GeodeAssertions.java | 64 - .../geode/algebra/GeodeBookstoreTest.java | 525 -- .../geode/algebra/GeodeEmbeddedPolicy.java | 180 - .../adapter/geode/algebra/GeodeZipsTest.java | 272 - .../db/adapter/geode/algebra/JsonLoader.java | 123 - .../geode/algebra/RelationalJdbcExample.java | 116 - .../geode/simple/BookMasterRegionTest.java | 77 - .../geode/simple/SimpleJdbcExample.java | 102 - .../src/test/resources/book_customer.json | 3 - .../src/test/resources/book_master.json | 3 - .../src/test/resources/log4j.properties | 11 - .../src/test/resources/zips-mini.json | 149 - plugins/html-adapter/build.gradle | 95 - plugins/html-adapter/gradle.properties | 27 - .../polypheny/db/adapter/html/HtmlEntity.java | 156 - .../db/adapter/html/HtmlEnumerator.java | 120 - .../db/adapter/html/HtmlFieldType.java | 104 - .../polypheny/db/adapter/html/HtmlPlugin.java | 32 - .../polypheny/db/adapter/html/HtmlReader.java | 257 - .../db/adapter/html/HtmlReaderException.java | 52 - .../db/adapter/html/HtmlRowConverter.java | 435 -- .../polypheny/db/adapter/html/HtmlScan.java | 110 - .../polypheny/db/adapter/html/HtmlSchema.java | 183 - .../polypheny/db/adapter/html/JsonEntity.java | 76 - .../db/adapter/html/JsonEnumerator.java | 103 - .../db/adapter/html/package-info.java | 41 - .../db/adapter/html/HtmlReaderTest.java | 302 - .../polypheny/db/adapter/html/HtmlSuite.java | 78 - .../polypheny/db/adapter/html/SqlTest.java | 409 -- .../db/adapter/html/package-info.java | 8 - .../src/test/resources/geo/countries.csv | 246 - .../src/test/resources/sales-csv.json | 14 - .../src/test/resources/sales-csv/DEPTS.csv | 4 - .../src/test/resources/sales-csv/EMPS.csv.gz | Bin 262 -> 0 bytes .../src/test/resources/sales-csv/EMPTY.csv | 0 .../test/resources/sales-csv/HEADER_ONLY.csv | 1 - .../src/test/resources/sales-csv/SDEPTS.csv | 7 - .../src/test/resources/sales.json | 23 - .../src/test/resources/sales/DEPTS.html | 26 - .../src/test/resources/sales/EMPS.html | 40 - .../src/test/resources/tableNoTH.html | 23 - .../src/test/resources/tableNoTheadTbody.html | 26 - .../src/test/resources/tableOK.html | 30 - .../src/test/resources/tableX2.html | 51 - .../src/test/resources/testModel.json | 27 - .../src/test/resources/webjoin.sql | 10 - .../html-adapter/src/test/resources/wiki.json | 214 - plugins/mapdb-catalog/build.gradle | 78 - plugins/mapdb-catalog/gradle.properties | 27 - .../org/polypheny/db/catalog/CatalogImpl.java | 5530 ----------------- .../polypheny/db/catalog/CatalogInfoPage.java | 189 - .../db/catalog/GenericSerializer.java | 85 - .../db/catalog/MapDBCatalogPlugin.java | 42 - .../org/polypheny/db/test/CatalogTest.java | 455 -- .../db/adapter/neo4j/util/NeoUtil.java | 3 +- plugins/pig-adapter/build.gradle | 97 - plugins/pig-adapter/gradle.properties | 27 - .../db/adapter/pig/PigAggFunction.java | 71 - .../db/adapter/pig/PigAggregate.java | 223 - .../org/polypheny/db/adapter/pig/PigAlg.java | 114 - .../db/adapter/pig/PigAlgFactories.java | 131 - .../polypheny/db/adapter/pig/PigDataType.java | 89 - .../polypheny/db/adapter/pig/PigEntity.java | 98 - .../polypheny/db/adapter/pig/PigFilter.java | 166 - .../org/polypheny/db/adapter/pig/PigJoin.java | 132 - .../polypheny/db/adapter/pig/PigPlugin.java | 33 - .../polypheny/db/adapter/pig/PigProject.java | 82 - .../polypheny/db/adapter/pig/PigRules.java | 183 - .../org/polypheny/db/adapter/pig/PigScan.java | 110 - .../polypheny/db/adapter/pig/PigSchema.java | 68 - .../adapter/pig/PigToEnumerableConverter.java | 93 - .../pig/PigToEnumerableConverterRule.java | 63 - .../db/adapter/pig/package-info.java | 40 - .../polypheny/db/test/AbstractPigTest.java | 50 - .../org/polypheny/db/test/PigAdapterTest.java | 205 - .../db/test/PigAlgBuilderStyleTest.java | 307 - .../pig-adapter/src/test/resources/data.txt | 3 - .../pig-adapter/src/test/resources/data2.txt | 2 - .../src/test/resources/log4j.properties | 14 - .../pig-adapter/src/test/resources/model.json | 31 - 255 files changed, 252 insertions(+), 43231 deletions(-) delete mode 100644 core/src/test/java/org/polypheny/db/excluded/CassandraExcluded.java delete mode 100644 plugins/cassandra-adapter/build.gradle delete mode 100644 plugins/cassandra-adapter/gradle.properties delete mode 100644 plugins/cassandra-adapter/src/main/java/org/polypheny/db/adapter/jdbc/CassandraSourcePlugin.java delete mode 100644 plugins/druid-adapter/build.gradle delete mode 100644 plugins/druid-adapter/gradle.properties delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/BinaryOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/CeilOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ComplexMetric.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DefaultDimensionSpec.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DimensionSpec.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DirectOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnection.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnectionImpl.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidDateTimeUtils.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidEntity.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidExpressions.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidJson.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidJsonFilter.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidPlugin.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidQuery.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidRules.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidSchema.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidSqlCastConverter.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidSqlOperatorConverter.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidTableFactory.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidType.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ExtractOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ExtractionDimensionSpec.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ExtractionFunction.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/FloorOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/Granularities.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/Granularity.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/NaryOperatorConverter.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/QueryType.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/SubstringOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/TimeExtractionFunction.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/UnaryPrefixOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/UnarySuffixOperatorConversion.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/VirtualColumn.java delete mode 100644 plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/package-info.java delete mode 100644 plugins/druid-adapter/src/test/java/org/polypheny/db/adapter/druid/DruidQueryFilterTest.java delete mode 100644 plugins/druid-adapter/src/test/java/org/polypheny/db/test/DruidAdapterIT.java delete mode 100644 plugins/druid-adapter/src/test/java/org/polypheny/db/test/DruidAdapterIT2.java delete mode 100644 plugins/druid-adapter/src/test/java/org/polypheny/db/test/DruidDateRangeRulesTest.java delete mode 100644 plugins/druid-adapter/src/test/resources/druid-foodmart-model-timestamp.json delete mode 100644 plugins/druid-adapter/src/test/resources/druid-foodmart-model.json delete mode 100644 plugins/druid-adapter/src/test/resources/druid-wiki-model.json delete mode 100644 plugins/druid-adapter/src/test/resources/druid-wiki-no-columns-model.json delete mode 100644 plugins/druid-adapter/src/test/resources/druid-wiki-no-tables-model.json delete mode 100644 plugins/druid-adapter/src/test/resources/foodmart-schema.spec delete mode 100644 plugins/druid-adapter/src/test/resources/log4j.properties delete mode 100644 plugins/elasticsearch-adapter/build.gradle delete mode 100644 plugins/elasticsearch-adapter/gradle.properties delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchAggregate.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchConstants.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchEntity.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchEnumerators.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchFilter.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchJson.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchMapping.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchMethod.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchPlugin.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchProject.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchRel.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchRules.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchScan.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchSchema.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchSearchResult.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchSort.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchToEnumerableConverter.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchToEnumerableConverterRule.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchTransport.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchVersion.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/MapProjectionFieldVisitor.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/PredicateAnalyzer.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/QueryBuilders.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/Scrolling.java delete mode 100644 plugins/elasticsearch-adapter/src/main/java/org/polypheny/db/adapter/elasticsearch/package-info.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/AggregationTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/BooleanLogicTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/Closer.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/ElasticSearchAdapterTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchJsonTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/ElasticsearchVersionTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/EmbeddedElasticsearchNode.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/EmbeddedElasticsearchPolicy.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/Projection2Test.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/ProjectionTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/QueryBuildersTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/adapter/elasticsearch/ScrollingTest.java delete mode 100644 plugins/elasticsearch-adapter/src/test/java/org/polypheny/db/test/ElasticsearchChecker.java delete mode 100644 plugins/elasticsearch-adapter/src/test/resources/log4j2.xml delete mode 100644 plugins/elasticsearch-adapter/src/test/resources/zips-mini.json delete mode 100644 plugins/geode-adapter/build.gradle delete mode 100644 plugins/geode-adapter/gradle.properties delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/GeodePlugin.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeAggregate.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeAlg.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeEntity.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeEnumerator.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeFilter.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeProject.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeRules.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeScan.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeSchema.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeSort.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeToEnumerableConverter.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/GeodeToEnumerableConverterRule.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/algebra/package-info.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/simple/GeodeSimpleEnumerator.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/simple/GeodeSimpleScannableEntity.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/simple/GeodeSimpleSchema.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/simple/package-info.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/util/GeodeUtils.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/util/JavaTypeFactoryExtImpl.java delete mode 100644 plugins/geode-adapter/src/main/java/org/polypheny/db/adapter/geode/util/package-info.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/AbstractGeodeTest.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/GeodeAllDataTypesTest.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/GeodeAssertions.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/GeodeBookstoreTest.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/GeodeEmbeddedPolicy.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/GeodeZipsTest.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/JsonLoader.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/algebra/RelationalJdbcExample.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/simple/BookMasterRegionTest.java delete mode 100644 plugins/geode-adapter/src/test/java/org/polypheny/db/adapter/geode/simple/SimpleJdbcExample.java delete mode 100644 plugins/geode-adapter/src/test/resources/book_customer.json delete mode 100644 plugins/geode-adapter/src/test/resources/book_master.json delete mode 100644 plugins/geode-adapter/src/test/resources/log4j.properties delete mode 100644 plugins/geode-adapter/src/test/resources/zips-mini.json delete mode 100644 plugins/html-adapter/build.gradle delete mode 100644 plugins/html-adapter/gradle.properties delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlEntity.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlEnumerator.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlFieldType.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlPlugin.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlReader.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlReaderException.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlRowConverter.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlScan.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/HtmlSchema.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/JsonEntity.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/JsonEnumerator.java delete mode 100644 plugins/html-adapter/src/main/java/org/polypheny/db/adapter/html/package-info.java delete mode 100644 plugins/html-adapter/src/test/java/org/polypheny/db/adapter/html/HtmlReaderTest.java delete mode 100644 plugins/html-adapter/src/test/java/org/polypheny/db/adapter/html/HtmlSuite.java delete mode 100644 plugins/html-adapter/src/test/java/org/polypheny/db/adapter/html/SqlTest.java delete mode 100644 plugins/html-adapter/src/test/java/org/polypheny/db/adapter/html/package-info.java delete mode 100644 plugins/html-adapter/src/test/resources/geo/countries.csv delete mode 100644 plugins/html-adapter/src/test/resources/sales-csv.json delete mode 100644 plugins/html-adapter/src/test/resources/sales-csv/DEPTS.csv delete mode 100644 plugins/html-adapter/src/test/resources/sales-csv/EMPS.csv.gz delete mode 100644 plugins/html-adapter/src/test/resources/sales-csv/EMPTY.csv delete mode 100644 plugins/html-adapter/src/test/resources/sales-csv/HEADER_ONLY.csv delete mode 100644 plugins/html-adapter/src/test/resources/sales-csv/SDEPTS.csv delete mode 100644 plugins/html-adapter/src/test/resources/sales.json delete mode 100644 plugins/html-adapter/src/test/resources/sales/DEPTS.html delete mode 100644 plugins/html-adapter/src/test/resources/sales/EMPS.html delete mode 100644 plugins/html-adapter/src/test/resources/tableNoTH.html delete mode 100644 plugins/html-adapter/src/test/resources/tableNoTheadTbody.html delete mode 100644 plugins/html-adapter/src/test/resources/tableOK.html delete mode 100644 plugins/html-adapter/src/test/resources/tableX2.html delete mode 100644 plugins/html-adapter/src/test/resources/testModel.json delete mode 100644 plugins/html-adapter/src/test/resources/webjoin.sql delete mode 100644 plugins/html-adapter/src/test/resources/wiki.json delete mode 100644 plugins/mapdb-catalog/build.gradle delete mode 100644 plugins/mapdb-catalog/gradle.properties delete mode 100644 plugins/mapdb-catalog/src/main/java/org/polypheny/db/catalog/CatalogImpl.java delete mode 100644 plugins/mapdb-catalog/src/main/java/org/polypheny/db/catalog/CatalogInfoPage.java delete mode 100644 plugins/mapdb-catalog/src/main/java/org/polypheny/db/catalog/GenericSerializer.java delete mode 100644 plugins/mapdb-catalog/src/main/java/org/polypheny/db/catalog/MapDBCatalogPlugin.java delete mode 100644 plugins/mapdb-catalog/src/test/java/org/polypheny/db/test/CatalogTest.java delete mode 100644 plugins/pig-adapter/build.gradle delete mode 100644 plugins/pig-adapter/gradle.properties delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigAggFunction.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigAggregate.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigAlg.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigAlgFactories.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigDataType.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigEntity.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigFilter.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigJoin.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigPlugin.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigProject.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigRules.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigScan.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigSchema.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigToEnumerableConverter.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/PigToEnumerableConverterRule.java delete mode 100644 plugins/pig-adapter/src/main/java/org/polypheny/db/adapter/pig/package-info.java delete mode 100644 plugins/pig-adapter/src/test/java/org/polypheny/db/test/AbstractPigTest.java delete mode 100644 plugins/pig-adapter/src/test/java/org/polypheny/db/test/PigAdapterTest.java delete mode 100644 plugins/pig-adapter/src/test/java/org/polypheny/db/test/PigAlgBuilderStyleTest.java delete mode 100644 plugins/pig-adapter/src/test/resources/data.txt delete mode 100644 plugins/pig-adapter/src/test/resources/data2.txt delete mode 100644 plugins/pig-adapter/src/test/resources/log4j.properties delete mode 100644 plugins/pig-adapter/src/test/resources/model.json diff --git a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java index 6e22d83559..449c4d8b04 100644 --- a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java +++ b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.stream.Collectors; import lombok.Getter; +import org.jetbrains.annotations.Nullable; import org.polypheny.db.PolyImplementation; import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.type.AlgDataType; @@ -35,6 +36,7 @@ import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; +import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.util.Pair; public class LanguageManager { @@ -132,9 +134,10 @@ public List anyPrepareQuery( QueryContext context, Statem implementationContexts.add( new ImplementationContext( implementation, parsed, statement, null ) ); } catch ( Exception e ) { - if ( transaction.isAnalyze() ) { + if ( transaction != null && transaction.isAnalyze() ) { transaction.getQueryAnalyzer().attachStacktrace( e ); } + cancelTransaction( transaction ); implementationContexts.add( ImplementationContext.ofError( e, parsed, statement ) ); return implementationContexts; } @@ -143,6 +146,17 @@ public List anyPrepareQuery( QueryContext context, Statem } + private static void cancelTransaction( @Nullable Transaction transaction ) { + if ( transaction != null && transaction.isActive() ) { + try { + transaction.rollback(); + } catch ( TransactionException ex ) { + // Ignore + } + } + } + + public List anyQuery( QueryContext context, Statement statement ) { List prepared = anyPrepareQuery( context, statement ); @@ -160,6 +174,8 @@ public List anyQuery( QueryContext context, Statement statement if ( transaction.isAnalyze() && implementation.getException().isEmpty() ) { transaction.getQueryAnalyzer().attachStacktrace( e ); } + cancelTransaction( transaction ); + executedContexts.add( ExecutedContext.ofError( e, implementation ) ); return executedContexts; } diff --git a/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java b/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java index ece6a4ea59..fdf019c33d 100644 --- a/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java +++ b/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java @@ -70,6 +70,7 @@ import org.polypheny.db.type.entity.PolyFloat; import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyLong; +import org.polypheny.db.type.entity.PolyString; import org.polypheny.db.type.entity.PolyTime; import org.polypheny.db.type.entity.PolyTimeStamp; import org.polypheny.db.type.entity.PolyValue; @@ -1354,6 +1355,8 @@ public static PolyValue stringToObject( final String s, final PolyType polyType return PolyFloat.of( Float.parseFloat( s ) ); case DECIMAL: return PolyBigDecimal.of( new BigDecimal( s ) ); + case VARCHAR: + return PolyString.of( s ); //case ARRAY: default: throw new NotImplementedException(); diff --git a/core/src/test/java/org/polypheny/db/excluded/CassandraExcluded.java b/core/src/test/java/org/polypheny/db/excluded/CassandraExcluded.java deleted file mode 100644 index 19d83272fd..0000000000 --- a/core/src/test/java/org/polypheny/db/excluded/CassandraExcluded.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2019-2021 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.excluded; - -public interface CassandraExcluded { - -} diff --git a/dbms/src/test/java/org/polypheny/db/constraints/ForeignKeyConstraintTest.java b/dbms/src/test/java/org/polypheny/db/constraints/ForeignKeyConstraintTest.java index 49cdf0f0d8..e0f69236a6 100644 --- a/dbms/src/test/java/org/polypheny/db/constraints/ForeignKeyConstraintTest.java +++ b/dbms/src/test/java/org/polypheny/db/constraints/ForeignKeyConstraintTest.java @@ -35,7 +35,6 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.CottontailExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @@ -46,7 +45,7 @@ @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j @RunWith(Parameterized.class) -@Category({ AdapterTestSuite.class, CottontailExcluded.class, FileExcluded.class, CassandraExcluded.class, Neo4jExcluded.class, MonetdbExcluded.class }) +@Category({ AdapterTestSuite.class, CottontailExcluded.class, FileExcluded.class, Neo4jExcluded.class, MonetdbExcluded.class }) public class ForeignKeyConstraintTest { @Parameters(name = "Create Indexes: {0}") diff --git a/dbms/src/test/java/org/polypheny/db/constraints/UniqueConstraintTest.java b/dbms/src/test/java/org/polypheny/db/constraints/UniqueConstraintTest.java index ebdd3cbfbd..1994e41449 100644 --- a/dbms/src/test/java/org/polypheny/db/constraints/UniqueConstraintTest.java +++ b/dbms/src/test/java/org/polypheny/db/constraints/UniqueConstraintTest.java @@ -35,7 +35,6 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.CottontailExcluded; import org.polypheny.db.excluded.FileExcluded; @@ -43,7 +42,7 @@ @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j @RunWith(Parameterized.class) -@Category({ AdapterTestSuite.class, CottontailExcluded.class, FileExcluded.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class, CottontailExcluded.class, FileExcluded.class }) public class UniqueConstraintTest { @Parameters(name = "Create Indexes: {0}") diff --git a/dbms/src/test/java/org/polypheny/db/crossmodel/CrossModelTestTemplate.java b/dbms/src/test/java/org/polypheny/db/crossmodel/CrossModelTestTemplate.java index fff47f8814..c8e43f50ae 100644 --- a/dbms/src/test/java/org/polypheny/db/crossmodel/CrossModelTestTemplate.java +++ b/dbms/src/test/java/org/polypheny/db/crossmodel/CrossModelTestTemplate.java @@ -24,9 +24,8 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class CrossModelTestTemplate { public static void executeStatements( SqlConsumer... statementConsumers ) { diff --git a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java index fbc97ad1da..f977f75e9e 100644 --- a/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java +++ b/dbms/src/test/java/org/polypheny/db/cypher/DdlTest.java @@ -29,7 +29,6 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalGraph; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.webui.models.results.GraphResult; @Category({ AdapterTestSuite.class }) @@ -116,7 +115,6 @@ public void initialPlacementTest() throws SQLException { @Test - @Category(CassandraExcluded.class) public void deletePlacementTest() throws SQLException { try { Catalog catalog = Catalog.getInstance(); @@ -149,7 +147,6 @@ public void deletePlacementTest() throws SQLException { @Test - @Category(CassandraExcluded.class) public void deletePlacementDataTest() throws SQLException { execute( "CREATE DATABASE " + graphName + " IF NOT EXISTS" ); diff --git a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcArrayTest.java b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcArrayTest.java index 81399f18cf..f19ca28b57 100644 --- a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcArrayTest.java +++ b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcArrayTest.java @@ -29,7 +29,6 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.HsqldbExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @@ -122,7 +121,6 @@ public void basicViewTest() throws SQLException { @Test - @Category({ FileExcluded.class, CassandraExcluded.class }) public void arrayTypesTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); @@ -183,7 +181,7 @@ public void arrayTypesTest() throws SQLException { @Test - @Category({ FileExcluded.class, CassandraExcluded.class }) + @Category({ FileExcluded.class }) public void arrayTypesViewTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); @@ -245,7 +243,7 @@ public void arrayTypesViewTest() throws SQLException { @Test - @Category({ FileExcluded.class, CassandraExcluded.class }) + @Category({ FileExcluded.class }) public void arrayTypesMaterializedTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); @@ -307,7 +305,7 @@ public void arrayTypesMaterializedTest() throws SQLException { @Test - @Category({ FileExcluded.class, CassandraExcluded.class }) + @Category({ FileExcluded.class }) public void itemOperatorTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); @@ -342,7 +340,7 @@ public void itemOperatorTest() throws SQLException { @Test //@Ignore - @Category({ FileExcluded.class, HsqldbExcluded.class, MonetdbExcluded.class, CassandraExcluded.class }) + @Category({ FileExcluded.class, HsqldbExcluded.class, MonetdbExcluded.class }) public void itemOperatorTest2() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); @@ -372,7 +370,7 @@ public void itemOperatorTest2() throws SQLException { @Test - @Category({ FileExcluded.class, CassandraExcluded.class }) + @Category({ FileExcluded.class }) public void nullTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); @@ -396,7 +394,7 @@ public void nullTest() throws SQLException { @Test - @Category({ FileExcluded.class, CassandraExcluded.class }) + @Category({ FileExcluded.class }) public void arrayFilterTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); diff --git a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDdlTest.java b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDdlTest.java index 486b706560..ae01e347a8 100644 --- a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDdlTest.java +++ b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDdlTest.java @@ -34,14 +34,13 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.type.PolyType; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class JdbcDdlTest { diff --git a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDmlTest.java b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDmlTest.java index d2d0e557c6..8a6b6ff679 100644 --- a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDmlTest.java +++ b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcDmlTest.java @@ -28,12 +28,11 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class JdbcDmlTest { diff --git a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcPreparedStatementsTest.java b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcPreparedStatementsTest.java index feaf41be1e..d5556bab8f 100644 --- a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcPreparedStatementsTest.java +++ b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcPreparedStatementsTest.java @@ -38,12 +38,11 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.CottontailExcluded; import org.polypheny.db.excluded.FileExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class JdbcPreparedStatementsTest { diff --git a/dbms/src/test/java/org/polypheny/db/misc/DataMigratorTest.java b/dbms/src/test/java/org/polypheny/db/misc/DataMigratorTest.java index 4818d5f786..40c095e428 100644 --- a/dbms/src/test/java/org/polypheny/db/misc/DataMigratorTest.java +++ b/dbms/src/test/java/org/polypheny/db/misc/DataMigratorTest.java @@ -29,10 +29,9 @@ import org.polypheny.db.TestHelper.JdbcConnection; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalTable; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class DataMigratorTest { diff --git a/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java b/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java index a04655eec7..8cfbe89122 100644 --- a/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java +++ b/dbms/src/test/java/org/polypheny/db/misc/HorizontalPartitioningTest.java @@ -41,7 +41,6 @@ import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.config.Config; import org.polypheny.db.config.ConfigManager; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.monitoring.core.MonitoringServiceProvider; import org.polypheny.db.partition.PartitionManager; @@ -52,7 +51,7 @@ @SuppressWarnings({ "SqlNoDataSourceInspection", "SqlDialectInspection" }) -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class HorizontalPartitioningTest { @BeforeClass @@ -498,7 +497,6 @@ public void listPartitioningTest() throws SQLException { @Test - @Category(CassandraExcluded.class) public void rangePartitioningTest() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); diff --git a/dbms/src/test/java/org/polypheny/db/misc/UnsupportedDmlTest.java b/dbms/src/test/java/org/polypheny/db/misc/UnsupportedDmlTest.java index 5b662a5b46..dcc8d41153 100644 --- a/dbms/src/test/java/org/polypheny/db/misc/UnsupportedDmlTest.java +++ b/dbms/src/test/java/org/polypheny/db/misc/UnsupportedDmlTest.java @@ -25,12 +25,11 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper.MongoConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.mql.MqlTestTemplate; import org.polypheny.db.webui.models.results.DocResult; -@Category({ AdapterTestSuite.class, CassandraExcluded.class, FileExcluded.class }) // todo fix error with filter in file +@Category({ AdapterTestSuite.class, FileExcluded.class }) // todo fix error with filter in file public class UnsupportedDmlTest extends MqlTestTemplate { @Test diff --git a/dbms/src/test/java/org/polypheny/db/misc/VerticalPartitioningTest.java b/dbms/src/test/java/org/polypheny/db/misc/VerticalPartitioningTest.java index 6615443984..ba5e4b554f 100644 --- a/dbms/src/test/java/org/polypheny/db/misc/VerticalPartitioningTest.java +++ b/dbms/src/test/java/org/polypheny/db/misc/VerticalPartitioningTest.java @@ -34,11 +34,10 @@ import org.polypheny.db.catalog.entity.allocation.AllocationPlacement; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.logistic.Pattern; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class VerticalPartitioningTest { diff --git a/dbms/src/test/java/org/polypheny/db/mql/AggregateTest.java b/dbms/src/test/java/org/polypheny/db/mql/AggregateTest.java index 9b6c249413..6676b38047 100644 --- a/dbms/src/test/java/org/polypheny/db/mql/AggregateTest.java +++ b/dbms/src/test/java/org/polypheny/db/mql/AggregateTest.java @@ -26,14 +26,13 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper.MongoConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.CottontailExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.MonetdbExcluded; import org.polypheny.db.webui.models.results.DocResult; -@Category({ AdapterTestSuite.class, FileExcluded.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class, FileExcluded.class }) public class AggregateTest extends MqlTestTemplate { diff --git a/dbms/src/test/java/org/polypheny/db/mql/DdlTest.java b/dbms/src/test/java/org/polypheny/db/mql/DdlTest.java index 8305813766..3a4248f009 100644 --- a/dbms/src/test/java/org/polypheny/db/mql/DdlTest.java +++ b/dbms/src/test/java/org/polypheny/db/mql/DdlTest.java @@ -35,11 +35,10 @@ import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.logistic.Pattern; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.webui.models.results.DocResult; @SuppressWarnings("SqlNoDataSourceInspection") -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) // cassandra can only compare primary key equality, but for streamer each key has to be compared +@Category({ AdapterTestSuite.class }) public class DdlTest extends MqlTestTemplate { final static String collectionName = "doc"; diff --git a/dbms/src/test/java/org/polypheny/db/mql/DmlTest.java b/dbms/src/test/java/org/polypheny/db/mql/DmlTest.java index d475b09c77..d0ccfd6506 100644 --- a/dbms/src/test/java/org/polypheny/db/mql/DmlTest.java +++ b/dbms/src/test/java/org/polypheny/db/mql/DmlTest.java @@ -30,7 +30,6 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper.MongoConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.webui.models.results.DocResult; @@ -39,7 +38,7 @@ * Integration tests, which use the MongoQL-interface to observe * correctness of the MongoQL language and the document model */ -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class DmlTest extends MqlTestTemplate { @After diff --git a/dbms/src/test/java/org/polypheny/db/mql/FindTest.java b/dbms/src/test/java/org/polypheny/db/mql/FindTest.java index fb2aa7db48..f3e9bb3617 100644 --- a/dbms/src/test/java/org/polypheny/db/mql/FindTest.java +++ b/dbms/src/test/java/org/polypheny/db/mql/FindTest.java @@ -25,12 +25,11 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper.MongoConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.webui.models.results.DocResult; -@Category({ AdapterTestSuite.class, FileExcluded.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class, FileExcluded.class }) public class FindTest extends MqlTestTemplate { private final List DATA_0 = Arrays.asList( diff --git a/dbms/src/test/java/org/polypheny/db/restapi/RestTest.java b/dbms/src/test/java/org/polypheny/db/restapi/RestTest.java index ccd781b8e5..2a9f50468f 100644 --- a/dbms/src/test/java/org/polypheny/db/restapi/RestTest.java +++ b/dbms/src/test/java/org/polypheny/db/restapi/RestTest.java @@ -47,7 +47,6 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings("SqlDialectInspection") @Slf4j @@ -182,7 +181,6 @@ private static HttpRequest buildRestDelete( String table, Map @Test // this needs to be rewritten - @Category({ CassandraExcluded.class }) public void testOperations() { // Insert HttpRequest request = buildRestInsert( "restschema.resttest", ImmutableList.of( getTestRow() ) ); diff --git a/dbms/src/test/java/org/polypheny/db/sql/SqlInsertSelectFromTest.java b/dbms/src/test/java/org/polypheny/db/sql/SqlInsertSelectFromTest.java index 7f0a0e0d77..6b5951c434 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/SqlInsertSelectFromTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/SqlInsertSelectFromTest.java @@ -26,10 +26,9 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class SqlInsertSelectFromTest { private static final String CREATE_TABLE_TEST_1 = diff --git a/dbms/src/test/java/org/polypheny/db/sql/SqlLimitOffsetFetchTest.java b/dbms/src/test/java/org/polypheny/db/sql/SqlLimitOffsetFetchTest.java index 331093f906..6f1e7bc6f6 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/SqlLimitOffsetFetchTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/SqlLimitOffsetFetchTest.java @@ -28,10 +28,9 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class SqlLimitOffsetFetchTest { @BeforeClass diff --git a/dbms/src/test/java/org/polypheny/db/sql/SqlSortExcludeTest.java b/dbms/src/test/java/org/polypheny/db/sql/SqlSortExcludeTest.java index a3f43be2d7..c2e5076311 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/SqlSortExcludeTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/SqlSortExcludeTest.java @@ -28,14 +28,13 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; /** * SELECT col1, col2 FROM table ORDER BY col3 * results in SELECT col1, col2, col3 FROM table ORDER BY col3 * which is often not desired */ -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class SqlSortExcludeTest { @BeforeClass diff --git a/dbms/src/test/java/org/polypheny/db/sql/clause/GroupByTest.java b/dbms/src/test/java/org/polypheny/db/sql/clause/GroupByTest.java index 7b6fa2aecf..2a59e7750c 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/clause/GroupByTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/clause/GroupByTest.java @@ -29,13 +29,12 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class GroupByTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/clause/JoinTest.java b/dbms/src/test/java/org/polypheny/db/sql/clause/JoinTest.java index b2ca05b4b5..ef9ee652a0 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/clause/JoinTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/clause/JoinTest.java @@ -30,12 +30,11 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class JoinTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java b/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java index ae2f7f27ed..28e0af180e 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/clause/SelectTest.java @@ -36,7 +36,6 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.CottontailExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.tools.AlgBuilder; @@ -47,7 +46,7 @@ @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class SelectTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/CaseTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/CaseTest.java index d3eaedf8e7..fc9f623d59 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/CaseTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/CaseTest.java @@ -28,14 +28,13 @@ import org.junit.experimental.categories.Category; import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.CottontailExcluded; import org.polypheny.db.excluded.FileExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class CaseTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/CeilFloorSignFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/CeilFloorSignFunctionsTest.java index 2809fbb603..7a539ab196 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/CeilFloorSignFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/CeilFloorSignFunctionsTest.java @@ -31,12 +31,11 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class CeilFloorSignFunctionsTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/DayTimeFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/DayTimeFunctionsTest.java index ef70a18bae..7f97fcb108 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/DayTimeFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/DayTimeFunctionsTest.java @@ -34,14 +34,13 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class DayTimeFunctionsTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/LogExponentialFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/LogExponentialFunctionsTest.java index 45911457bc..463a3d53c7 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/LogExponentialFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/LogExponentialFunctionsTest.java @@ -30,13 +30,12 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class, MonetdbExcluded.class }) +@Category({ AdapterTestSuite.class, MonetdbExcluded.class }) public class LogExponentialFunctionsTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/OperatorsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/OperatorsTest.java index 15a678639d..6b85d97c5c 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/OperatorsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/OperatorsTest.java @@ -29,14 +29,13 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class OperatorsTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/PowerAbsModFunctionTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/PowerAbsModFunctionTest.java index df85a7d2e0..1e4870b4d2 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/PowerAbsModFunctionTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/PowerAbsModFunctionTest.java @@ -31,12 +31,11 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class PowerAbsModFunctionTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/SqlDistanceFunctionTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/SqlDistanceFunctionTest.java index c4e0747e65..889144bb39 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/SqlDistanceFunctionTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/SqlDistanceFunctionTest.java @@ -36,13 +36,12 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, FileExcluded.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class, FileExcluded.class }) public class SqlDistanceFunctionTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java index ce676f64d3..ee6d7f1bf9 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java @@ -31,13 +31,12 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class StringFunctionsTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/TrigonometricFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/TrigonometricFunctionsTest.java index fa576e3313..cfc83b97f0 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/TrigonometricFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/TrigonometricFunctionsTest.java @@ -30,13 +30,12 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class TrigonometricFunctionsTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/TypeConversionTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/TypeConversionTest.java index bc3774b2b8..e68349a503 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/TypeConversionTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/TypeConversionTest.java @@ -33,12 +33,11 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class TypeConversionTest { diff --git a/dbms/src/test/java/org/polypheny/db/sql/view/ComplexViewTest.java b/dbms/src/test/java/org/polypheny/db/sql/view/ComplexViewTest.java index 8a043c2d19..dce090c9a3 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/view/ComplexViewTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/view/ComplexViewTest.java @@ -31,7 +31,6 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; import org.polypheny.db.excluded.FileExcluded; import org.polypheny.db.excluded.MonetdbExcluded; @@ -40,7 +39,7 @@ */ @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class ComplexViewTest { private final static String DROP_TABLES_NATION = "DROP TABLE IF EXISTS nation"; diff --git a/dbms/src/test/java/org/polypheny/db/sql/view/ViewTest.java b/dbms/src/test/java/org/polypheny/db/sql/view/ViewTest.java index 0157f64c1b..71c395b779 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/view/ViewTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/view/ViewTest.java @@ -28,11 +28,10 @@ import org.polypheny.db.AdapterTestSuite; import org.polypheny.db.TestHelper; import org.polypheny.db.TestHelper.JdbcConnection; -import org.polypheny.db.excluded.CassandraExcluded; @SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" }) @Slf4j -@Category({ AdapterTestSuite.class, CassandraExcluded.class }) +@Category({ AdapterTestSuite.class }) public class ViewTest { private final static String VIEW_TEST_EMP_TABLE_SQL = "CREATE TABLE viewTestEmpTable (" diff --git a/plugins/cassandra-adapter/build.gradle b/plugins/cassandra-adapter/build.gradle deleted file mode 100644 index 8f120f8d3a..0000000000 --- a/plugins/cassandra-adapter/build.gradle +++ /dev/null @@ -1,80 +0,0 @@ -group "org.polypheny" - - -dependencies { - compileOnly project(":core") - compileOnly project(":plugins:sql-language") - compileOnly project(":plugins:jdbc-adapter-framework") - - // JDBC Driver - implementation group: "org.mariadb.jdbc", name: "mariadb-java-client", version: mariadb_version // LGPL 2.1 - - - // --- Test Compile --- - testImplementation project(path: ":core", configuration: "tests") - testImplementation project(path: ":plugins:sql-language", configuration: "tests") - -} - - -sourceSets { - main { - java { - srcDirs = ["src/main/java"] - outputDir = file(project.buildDir.absolutePath + "/classes") - } - resources { - srcDirs = ["src/main/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/classes") - } - test { - java { - srcDirs = ["src/test/java"] - outputDir = file(project.buildDir.absolutePath + "/test-classes") - } - resources { - srcDirs = ["src/test/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/test-classes") - } -} - -compileJava { - dependsOn(":core:processResources") - dependsOn(":plugins:sql-language:processResources") - dependsOn(":plugins:jdbc-adapter-framework:processResources") -} - -compileTestJava { - dependsOn(":plugins:jdbc-adapter-framework:processResources") -} - -delombok { - dependsOn(":plugins:sql-language:processResources") - dependsOn(":plugins:jdbc-adapter-framework:processResources") -} - -/** - * JARs - */ -jar { - manifest { - attributes "Manifest-Version": "1.0" - attributes "Copyright": "The Polypheny Project (polypheny.org)" - attributes "Version": "$project.version" - } -} -java { - withJavadocJar() - withSourcesJar() -} - -javadoc { - dependsOn(":plugins:jdbc-adapter-framework:processResources") -} - -licensee { - allowDependency('org.mariadb.jdbc', 'mariadb-java-client', '2.7.2') { because 'removed on release branches' } -} - diff --git a/plugins/cassandra-adapter/gradle.properties b/plugins/cassandra-adapter/gradle.properties deleted file mode 100644 index 1b60d8a7d7..0000000000 --- a/plugins/cassandra-adapter/gradle.properties +++ /dev/null @@ -1,27 +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. -# - -pluginVersion = 0.0.1 - -pluginId = cassandra-adapter -pluginClass = org.polypheny.db.adapter.jdbc.CassandraSourcePlugin -pluginProvider = The Polypheny Project -pluginDependencies = jdbc-adapter-framework, sql-language -pluginUrlPath = -pluginCategories = source -pluginPolyDependencies = -pluginIsSystemComponent = false -pluginIsUiVisible = true \ No newline at end of file diff --git a/plugins/cassandra-adapter/src/main/java/org/polypheny/db/adapter/jdbc/CassandraSourcePlugin.java b/plugins/cassandra-adapter/src/main/java/org/polypheny/db/adapter/jdbc/CassandraSourcePlugin.java deleted file mode 100644 index 921cf7080c..0000000000 --- a/plugins/cassandra-adapter/src/main/java/org/polypheny/db/adapter/jdbc/CassandraSourcePlugin.java +++ /dev/null @@ -1,149 +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.adapter.jdbc; - - -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import lombok.extern.slf4j.Slf4j; -import org.polypheny.db.adapter.AdapterManager; -import org.polypheny.db.adapter.DeployMode; -import org.polypheny.db.adapter.annotations.AdapterProperties; -import org.polypheny.db.adapter.annotations.AdapterSettingInteger; -import org.polypheny.db.adapter.annotations.AdapterSettingList; -import org.polypheny.db.adapter.annotations.AdapterSettingString; -import org.polypheny.db.adapter.jdbc.sources.AbstractJdbcSource; -import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper; -import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper; -import org.polypheny.db.catalog.entity.physical.PhysicalTable; -import org.polypheny.db.plugins.PluginContext; -import org.polypheny.db.plugins.PolyPlugin; -import org.polypheny.db.prepare.Context; -import org.polypheny.db.sql.language.dialect.MysqlSqlDialect; - -public class CassandraSourcePlugin extends PolyPlugin { - - - public static final String ADAPTER_NAME = "Cassandra"; - private long id; - - - /** - * Constructor to be used by plugin manager for plugin instantiation. - * Your plugins have to provide constructor with this exact signature to be successfully loaded by manager. - */ - public CassandraSourcePlugin( PluginContext context ) { - super( context ); - } - - - @Override - public void afterCatalogInit() { - this.id = AdapterManager.addAdapterTemplate( CassandraSource.class, ADAPTER_NAME, CassandraSource::new ); - } - - - @Override - public void stop() { - AdapterManager.removeAdapterTemplate( this.id ); - } - - - @Slf4j - @AdapterProperties( - name = "Cassandra", - description = "Data source adapter for the database system cassandra.", - usedModes = DeployMode.REMOTE, - defaultMode = DeployMode.REMOTE) - @AdapterSettingString(name = "host", defaultValue = "localhost", position = 1, - description = "Hostname or IP address of the remote Cassandra instance.") - @AdapterSettingInteger(name = "port", defaultValue = 3306, position = 2, - description = "JDBC port number on the remote Cassandra instance.") - @AdapterSettingString(name = "database", defaultValue = "polypheny", position = 3, - description = "Name of the database to connect to.") - @AdapterSettingString(name = "username", defaultValue = "polypheny", position = 4, - description = "Username to be used for authenticating at the remote instance.") - @AdapterSettingString(name = "password", defaultValue = "polypheny", position = 5, - description = "Password to be used for authenticating at the remote instance.") - @AdapterSettingInteger(name = "maxConnections", defaultValue = 25, - description = "Maximum number of concurrent JDBC connections.") - @AdapterSettingList(name = "transactionIsolation", options = { "SERIALIZABLE", "READ_UNCOMMITTED", "READ_COMMITTED", "REPEATABLE_READ" }, defaultValue = "SERIALIZABLE", - description = "Which level of transaction isolation should be used.") - @AdapterSettingString(name = "tables", defaultValue = "foo,bar", - description = "List of tables which should be imported. The names must to be separated by a comma.") - public static class CassandraSource extends AbstractJdbcSource { - - public CassandraSource( long storeId, String uniqueName, final Map settings ) { - super( storeId, uniqueName, settings, "org.mariadb.jdbc.Driver", MysqlSqlDialect.DEFAULT, false ); - } - - - @Override - public void refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - return; - } - storeCatalog.replacePhysical( currentJdbcSchema.createJdbcTable( storeCatalog, table ) ); - } - - @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( - logical.table.getNamespaceName(), - logical.table.name, - logical.columns.stream().collect( Collectors.toMap( c -> c.id, c -> c.name ) ), - logical.table, - logical.columns.stream().collect( Collectors.toMap( t -> t.id, t -> t ) ), - allocation ); - } - - - @Override - public void shutdown() { - try { - removeInformationPage(); - connectionFactory.close(); - } catch ( SQLException e ) { - log.warn( "Exception while shutting down {}", getUniqueName(), e ); - } - } - - - @Override - protected void reloadSettings( List updatedSettings ) { - // TODO: Implement disconnect and reconnect to PostgreSQL instance. - } - - - @Override - protected String getConnectionUrl( final String dbHostname, final int dbPort, final String dbName ) { - return String.format( "jdbc:cassandra://%s:%d/%s", dbHostname, dbPort, dbName ); - } - - - @Override - protected boolean requiresSchema() { - return false; - } - - } - -} \ No newline at end of file diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java index 10ef784e69..799ff1d2e5 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailEntity.java @@ -22,6 +22,7 @@ import org.apache.calcite.linq4j.Enumerator; import org.apache.calcite.linq4j.Queryable; import org.polypheny.db.adapter.DataContext; +import org.polypheny.db.adapter.cottontail.CottontailPlugin.CottontailStore; import org.polypheny.db.adapter.cottontail.algebra.CottontailScan; import org.polypheny.db.adapter.cottontail.enumberable.CottontailQueryEnumerable; import org.polypheny.db.adapter.java.JavaTypeFactory; @@ -54,7 +55,9 @@ public class CottontailEntity extends PhysicalTable implements TranslatableEntity, ModifiableTable, QueryableEntity { private final PhysicalTable table; + private final CottontailStore store; private AlgProtoDataType protoRowType; + @Getter private CottontailNamespace cottontailNamespace; @Getter @@ -70,7 +73,8 @@ public class CottontailEntity extends PhysicalTable implements TranslatableEntit protected CottontailEntity( CottontailNamespace cottontailNamespace, String physicalSchemaName, - PhysicalTable physical ) { + PhysicalTable physical, + CottontailStore cottontailStore ) { super( physical.id, physical.allocationId, physical.logicalId, @@ -80,6 +84,7 @@ protected CottontailEntity( physical.namespaceName, physical.adapterId ); + this.store = cottontailStore; this.cottontailNamespace = cottontailNamespace; this.table = physical; @@ -142,6 +147,12 @@ public CottontailConvention getUnderlyingConvention() { } + @SuppressWarnings("unused") + public void registerStore( DataContext dataContext ) { + dataContext.getStatement().getTransaction().registerInvolvedAdapter( this.store ); + } + + @Override public Type getElementType() { return Object[].class; diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java index e1c0fc4d97..7a8b65925b 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailNamespace.java @@ -101,6 +101,7 @@ public static CottontailNamespace create( } + @SuppressWarnings("unused") public void registerStore( DataContext dataContext ) { dataContext.getStatement().getTransaction().registerInvolvedAdapter( this.cottontailStore ); } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailPlugin.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailPlugin.java index c7cd5f1721..7481017343 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailPlugin.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/CottontailPlugin.java @@ -243,6 +243,9 @@ public List createTable( Context context, LogicalTableWrapper lo if ( !success ) { throw new GenericRuntimeException( "Unable to create table." ); } + + storeCatalog.replacePhysical( new CottontailEntity( currentNamespace, this.currentNamespace.getCottontailSchema().getName(), table, this ) ); + return List.of( table ); } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailAlg.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailAlg.java index b17b7bd867..77f619724d 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailAlg.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailAlg.java @@ -49,7 +49,6 @@ class CottontailImplementContext { public String tableName; public CottontailEntity table; - public CottontailEntity cottontailTable; public Expression filterBuilder; diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java index 352e4ef71f..2ddc5c7d2c 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailProject.java @@ -90,12 +90,12 @@ public void implement( CottontailImplementContext context ) { context.visitChild( 0, getInput() ); } - final List fieldList = context.cottontailTable.getRowType().getFields(); + final List fieldList = context.table.getRowType().getFields(); final List physicalColumnNames = new ArrayList<>( fieldList.size() ); final List columnTypes = new ArrayList<>( fieldList.size() ); for ( AlgDataTypeField field : fieldList ) { - physicalColumnNames.add( context.cottontailTable.getPhysicalColumnName( field.getName() ) ); + physicalColumnNames.add( field.getPhysicalName() ); if ( field.getType().getComponentType() != null ) { columnTypes.add( field.getType().getComponentType().getPolyType() ); } else { diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailScan.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailScan.java index 26a27ae59f..caf6ef1edf 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailScan.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailScan.java @@ -58,7 +58,7 @@ public AlgOptCost computeSelfCost( AlgOptPlanner planner, AlgMetadataQuery mq ) public void implement( CottontailImplementContext context ) { // context.from = From.newBuilder().setEntity( this.cottontailTable.getLogicalTable() ).build(); if ( context.queryType == null ) { - context.cottontailTable = this.cottontailTable; + context.table = this.cottontailTable; context.schemaName = this.cottontailTable.getPhysicalSchemaName(); context.tableName = this.cottontailTable.getPhysicalTableName(); context.queryType = QueryType.SELECT; diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java index 5dcd991978..4048367b07 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java @@ -98,7 +98,7 @@ private static ParameterExpression sortMapBuilder( AlgCollation node, Cottontail final String logicalName = columnNames.get( c.getFieldIndex() ); String physicalName; try { - physicalName = context.cottontailTable.getPhysicalColumnName( logicalName ); + physicalName = context.table.getPhysicalColumnName( logicalName ); } catch ( IndexOutOfBoundsException e ) { physicalName = logicalName; /* Case of column being calculated and there being no physical column. */ } 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 6724001ce3..7ec75c95f1 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 @@ -109,7 +109,7 @@ public AlgOptCost computeSelfCost( AlgOptPlanner planner, AlgMetadataQuery mq ) @Override public void implement( CottontailImplementContext context ) { - context.cottontailTable = this.cottontailTable; + context.table = this.cottontailTable; context.table = this.entity; context.schemaName = this.cottontailTable.getPhysicalSchemaName(); context.tableName = this.cottontailTable.getPhysicalTableName(); @@ -147,8 +147,8 @@ private Expression buildUpdateTupleBuilder( CottontailImplementContext context ) final List physicalColumnNames = new ArrayList<>(); final List logicalColumnNames = new ArrayList<>(); final List columnTypes = new ArrayList<>(); - for ( AlgDataTypeField field : context.cottontailTable.getRowType().getFields() ) { - physicalColumnNames.add( context.cottontailTable.getPhysicalColumnName( field.getName() ) ); + for ( AlgDataTypeField field : context.table.getRowType().getFields() ) { + physicalColumnNames.add( field.getPhysicalName() ); logicalColumnNames.add( field.getName() ); columnTypes.add( field.getType().getPolyType() ); } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java index b26940fc9d..080220a494 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailToEnumerableConverter.java @@ -26,7 +26,7 @@ import org.apache.calcite.linq4j.tree.Types; import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.cottontail.CottontailConvention; -import org.polypheny.db.adapter.cottontail.CottontailNamespace; +import org.polypheny.db.adapter.cottontail.CottontailEntity; import org.polypheny.db.adapter.cottontail.algebra.CottontailAlg.CottontailImplementContext; import org.polypheny.db.adapter.cottontail.enumberable.CottontailDeleteEnumerable; import org.polypheny.db.adapter.cottontail.enumberable.CottontailEnumerableFactory; @@ -47,9 +47,9 @@ import org.polypheny.db.plan.AlgOptPlanner; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.ConventionTraitDef; -import org.polypheny.db.schema.Schemas; import org.polypheny.db.type.ArrayType; import org.polypheny.db.type.PolyType; +import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.BuiltInMethod; import org.vitrivr.cottontail.client.iterators.Tuple; @@ -114,7 +114,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { final Expression values_ = builder.append( "values", - Expressions.newArrayBounds( Object.class, 1, Expressions.constant( fieldCount ) ) ); + Expressions.newArrayBounds( PolyValue.class, 1, Expressions.constant( fieldCount ) ) ); for ( int i = 0; i < fieldCount; i++ ) { this.generateGet( rowType, builder, resultMap_, i, Expressions.arrayIndex( values_, Expressions.constant( i ) ) ); } @@ -136,7 +136,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { expressionOrNullExpression( cottontailContext.filterBuilder ), // WHERE DataContext.ROOT, rowBuilder_, - Expressions.call( Schemas.unwrap( convention.expression, CottontailNamespace.class ), "getWrapper" ) + cottontailContext.table.asExpression( CottontailEntity.class ) ) ); break; @@ -150,7 +150,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { Expressions.constant( cottontailContext.schemaName ), cottontailContext.valuesHashMapList, DataContext.ROOT, - Expressions.call( Schemas.unwrap( convention.expression, CottontailNamespace.class ), "getWrapper" ) + cottontailContext.table.asExpression( CottontailEntity.class ) ) ); } else { @@ -162,7 +162,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { Expressions.constant( cottontailContext.schemaName ), cottontailContext.preparedValuesMapBuilder, DataContext.ROOT, - Expressions.call( Schemas.unwrap( convention.expression, CottontailNamespace.class ), "getWrapper" ) + cottontailContext.table.asExpression( CottontailEntity.class ) ) ); } @@ -178,7 +178,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { expressionOrNullExpression( cottontailContext.filterBuilder ), cottontailContext.preparedValuesMapBuilder, DataContext.ROOT, - Expressions.call( Schemas.unwrap( convention.expression, CottontailNamespace.class ), "getWrapper" ) + cottontailContext.table.asExpression( CottontailEntity.class ) ) ); break; @@ -192,7 +192,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { Expressions.constant( cottontailContext.schemaName ), expressionOrNullExpression( cottontailContext.filterBuilder ), DataContext.ROOT, - Expressions.call( Schemas.unwrap( convention.expression, CottontailNamespace.class ), "getWrapper" ) + cottontailContext.table.asExpression( CottontailEntity.class ) ) ); break; @@ -201,10 +201,11 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { enumerable = null; } - list.add( Expressions.statement( Expressions.call( - Schemas.unwrap( convention.expression, CottontailNamespace.class ), - "registerStore", - DataContext.ROOT ) ) ); + list.add( Expressions.statement( + Expressions.call( + cottontailContext.table.asExpression( CottontailEntity.class ), + "registerStore", + DataContext.ROOT ) ) ); list.add( Expressions.return_( null, enumerable ) ); @@ -231,13 +232,27 @@ private void generateGet( AlgDataType rowType, BlockBuilder blockBuilder, Parame final Expression source; switch ( fieldType.getPolyType() ) { case BOOLEAN: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getBoolData", Object.class ), getDataFromMap_ ); + break; case INTEGER: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getIntData", Object.class ), getDataFromMap_ ); + break; case BIGINT: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getBigIntData", Object.class ), getDataFromMap_ ); + break; case FLOAT: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getFloatData", Object.class ), getDataFromMap_ ); + break; case REAL: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getRealData", Object.class ), getDataFromMap_ ); + break; case DOUBLE: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getDoubleData", Object.class ), getDataFromMap_ ); + break; case CHAR: case VARCHAR: + source = Expressions.call( Types.lookupMethod( Linq4JFixer.class, "getStringData", Object.class ), getDataFromMap_ ); + break; case NULL: source = getDataFromMap_; break; diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java index b744d69b66..9fca9b09fc 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailValues.java @@ -59,7 +59,7 @@ public void implement( CottontailImplementContext context ) { int i = 0; for ( AlgDataTypeField field : this.rowType.getFields() ) { try { - physicalColumnNames.add( new Pair<>( context.cottontailTable.getPhysicalColumnName( field.getName() ), field.getType().getPolyType() ) ); + physicalColumnNames.add( new Pair<>( context.table.getPhysicalColumnName( field.getName() ), field.getType().getPolyType() ) ); tupleIndexes.add( i ); } catch ( IndexOutOfBoundsException e ) { // ignore; this table seems to be vertically partitioned and this store does not have all columns diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailBatchInsertEnumerable.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailBatchInsertEnumerable.java index 17f6a50e5b..5927385980 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailBatchInsertEnumerable.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailBatchInsertEnumerable.java @@ -20,10 +20,12 @@ import org.apache.calcite.linq4j.AbstractEnumerable; import org.apache.calcite.linq4j.Enumerator; import org.polypheny.db.adapter.cottontail.CottontailWrapper; +import org.polypheny.db.type.entity.PolyLong; +import org.polypheny.db.type.entity.PolyValue; import org.vitrivr.cottontail.grpc.CottontailGrpc.BatchInsertMessage; -public class CottontailBatchInsertEnumerable extends AbstractEnumerable { +public class CottontailBatchInsertEnumerable extends AbstractEnumerable { private final List inserts; private final CottontailWrapper wrapper; @@ -36,17 +38,17 @@ public CottontailBatchInsertEnumerable( List inserts, Cotton @Override - public Enumerator enumerator() { + public Enumerator enumerator() { return new CottontailInsertResultEnumerator(); } - private class CottontailInsertResultEnumerator implements Enumerator { + private class CottontailInsertResultEnumerator implements Enumerator { /** * Result of the last BATCH INSERT that was performed. */ - private long currentResult; + private PolyValue[] currentResult; /** * The pointer to the last {@link BatchInsertMessage} that was executed. @@ -55,7 +57,7 @@ private class CottontailInsertResultEnumerator implements Enumerator { @Override - public Long current() { + public PolyValue[] current() { return this.currentResult; } @@ -65,14 +67,12 @@ public boolean moveNext() { if ( this.pointer < CottontailBatchInsertEnumerable.this.inserts.size() ) { final BatchInsertMessage insertMessage = CottontailBatchInsertEnumerable.this.inserts.get( this.pointer++ ); if ( CottontailBatchInsertEnumerable.this.wrapper.insert( insertMessage ) ) { - this.currentResult = insertMessage.getInsertsCount(); - } else { - this.currentResult = -1; + this.currentResult = new PolyValue[]{ PolyLong.of( insertMessage.getInsertsCount() ) }; + return true; } - return !(this.currentResult == -1L); - } else { - return false; + this.currentResult = new PolyValue[]{ PolyLong.of( -1 ) }; } + return false; } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailDeleteEnumerable.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailDeleteEnumerable.java index df07617648..ed0dab814a 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailDeleteEnumerable.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailDeleteEnumerable.java @@ -29,13 +29,14 @@ import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.cottontail.CottontailWrapper; import org.polypheny.db.adapter.cottontail.util.CottontailTypeUtil; +import org.polypheny.db.type.entity.PolyLong; import org.polypheny.db.type.entity.PolyValue; import org.vitrivr.cottontail.grpc.CottontailGrpc.DeleteMessage; import org.vitrivr.cottontail.grpc.CottontailGrpc.Metadata; import org.vitrivr.cottontail.grpc.CottontailGrpc.Where; -public class CottontailDeleteEnumerable extends AbstractEnumerable { +public class CottontailDeleteEnumerable extends AbstractEnumerable { public static final Method CREATE_DELETE_METHOD = Types.lookupMethod( CottontailDeleteEnumerable.class, @@ -53,12 +54,13 @@ public CottontailDeleteEnumerable( List deletes, DataContext data @Override - public Enumerator enumerator() { - return new CottontailDeleteEnumerator<>( deletes, wrapper ); + public Enumerator enumerator() { + return new CottontailDeleteEnumerator( deletes, wrapper ); } - public static CottontailDeleteEnumerable delete( + @SuppressWarnings("unused") + public static CottontailDeleteEnumerable delete( String entity, String schema, Function1, Where> whereBuilder, @@ -86,7 +88,7 @@ public static CottontailDeleteEnumerable delete( } } - return new CottontailDeleteEnumerable<>( deleteMessages, dataContext, wrapper ); + return new CottontailDeleteEnumerable( deleteMessages, dataContext, wrapper ); } @@ -107,10 +109,10 @@ private static DeleteMessage buildSingleDelete( } - private static class CottontailDeleteEnumerator implements Enumerator { + private static class CottontailDeleteEnumerator implements Enumerator { Iterator deleteMessageIterator; - Long currentResult; + PolyValue[] currentResult; CottontailWrapper wrapper; @@ -121,8 +123,8 @@ public CottontailDeleteEnumerator( List deleteMessages, Cottontai @Override - public T current() { - return (T) currentResult; + public PolyValue[] current() { + return currentResult; } @@ -131,9 +133,9 @@ public boolean moveNext() { if ( deleteMessageIterator.hasNext() ) { DeleteMessage deleteMessage = deleteMessageIterator.next(); - this.currentResult = wrapper.delete( deleteMessage ); + this.currentResult = new PolyValue[]{ PolyLong.of( wrapper.delete( deleteMessage ) ) }; - return !this.currentResult.equals( -1L ); + return !this.currentResult.equals( PolyLong.of( -1L ) ); } return false; } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailEnumerableFactory.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailEnumerableFactory.java index 106e7d2022..be5f12f904 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailEnumerableFactory.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailEnumerableFactory.java @@ -27,6 +27,7 @@ import org.apache.calcite.linq4j.function.Function1; import org.apache.calcite.linq4j.tree.Types; import org.polypheny.db.adapter.DataContext; +import org.polypheny.db.adapter.cottontail.CottontailEntity; import org.polypheny.db.adapter.cottontail.CottontailWrapper; import org.polypheny.db.adapter.cottontail.util.CottontailTypeUtil; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -62,7 +63,7 @@ public class CottontailEnumerableFactory { public static final Method CREATE_QUERY_METHOD = Types.lookupMethod( CottontailEnumerableFactory.class, "query", - String.class, String.class, Map.class, Map.class, Function1.class, Function1.class, Function1.class, DataContext.class, Function1.class, CottontailWrapper.class ); + String.class, String.class, Map.class, Map.class, Function1.class, Function1.class, Function1.class, DataContext.class, Function1.class, CottontailEntity.class ); /** * Method signature for building INSERT of values. @@ -70,7 +71,7 @@ public class CottontailEnumerableFactory { public static final Method CREATE_INSERT_VALUES = Types.lookupMethod( CottontailEnumerableFactory.class, "insertFromValues", - String.class, String.class, List.class, DataContext.class, CottontailWrapper.class ); + String.class, String.class, List.class, DataContext.class, CottontailEntity.class ); /** * Method signature for building INSERT for prepared statements. @@ -78,7 +79,7 @@ public class CottontailEnumerableFactory { public static final Method CREATE_INSERT_PREPARED = Types.lookupMethod( CottontailEnumerableFactory.class, "insertFromPreparedStatements", - String.class, String.class, Function1.class, DataContext.class, CottontailWrapper.class ); + String.class, String.class, Function1.class, DataContext.class, CottontailEntity.class ); /** * Method signature for building UPDATE with values. @@ -86,9 +87,10 @@ public class CottontailEnumerableFactory { public static final Method CREATE_UPDATE_METHOD = Types.lookupMethod( CottontailEnumerableFactory.class, "updateFromValues", - String.class, String.class, Function1.class, Function1.class, DataContext.class, CottontailWrapper.class ); + String.class, String.class, Function1.class, Function1.class, DataContext.class, CottontailEntity.class ); + @SuppressWarnings("unused") public static CottontailQueryEnumerable query( String from, String schema, @@ -99,9 +101,9 @@ public static CottontailQueryEnumerable query( Function1, Where> whereBuilder, DataContext dataContext, Function1 rowParser, - CottontailWrapper wrapper + CottontailEntity entity ) { - + CottontailWrapper wrapper = entity.getCottontailNamespace().getWrapper(); /* Begin or continue Cottontail DB transaction. */ final long txId = wrapper.beginOrContinue( dataContext.getStatement().getTransaction() ); @@ -211,13 +213,14 @@ private static Query buildSingleQuery( @SuppressWarnings("unused") // Used via reflection - public static AbstractEnumerable insertFromValues( + public static AbstractEnumerable insertFromValues( String from, String schema, List> values, DataContext dataContext, - CottontailWrapper wrapper + CottontailEntity entity ) { + CottontailWrapper wrapper = entity.getCottontailNamespace().getWrapper(); /* Begin or continue Cottontail DB transaction. */ final long txId = wrapper.beginOrContinue( dataContext.getStatement().getTransaction() ); @@ -237,13 +240,14 @@ public static AbstractEnumerable insertFromValues( @SuppressWarnings("unused") // Used via reflection - public static AbstractEnumerable insertFromPreparedStatements( + public static AbstractEnumerable insertFromPreparedStatements( String from, String schema, Function1, Map> tupleBuilder, DataContext dataContext, - CottontailWrapper wrapper + CottontailEntity entity ) { + CottontailWrapper wrapper = entity.getCottontailNamespace().getWrapper(); /* Begin or continue Cottontail DB transaction. */ final long txId = wrapper.beginOrContinue( dataContext.getStatement().getTransaction() ); @@ -311,8 +315,9 @@ public static CottontailUpdateEnumerable updateFromValues( Function1, Where> whereBuilder, Function1, Map> tupleBuilder, DataContext dataContext, - CottontailWrapper wrapper + CottontailEntity cottontail ) { + CottontailWrapper wrapper = cottontail.getCottontailNamespace().getWrapper(); /* Begin or continue Cottontail DB transaction. */ final long txId = wrapper.beginOrContinue( dataContext.getStatement().getTransaction() ); diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailInsertEnumerable.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailInsertEnumerable.java index 32a02736eb..5e1f7b7c18 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailInsertEnumerable.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailInsertEnumerable.java @@ -19,10 +19,12 @@ import org.apache.calcite.linq4j.AbstractEnumerable; import org.apache.calcite.linq4j.Enumerator; import org.polypheny.db.adapter.cottontail.CottontailWrapper; +import org.polypheny.db.type.entity.PolyLong; +import org.polypheny.db.type.entity.PolyValue; import org.vitrivr.cottontail.grpc.CottontailGrpc.InsertMessage; -public class CottontailInsertEnumerable extends AbstractEnumerable { +public class CottontailInsertEnumerable extends AbstractEnumerable { private final List inserts; private final CottontailWrapper wrapper; @@ -35,17 +37,17 @@ public CottontailInsertEnumerable( List inserts, CottontailWrappe @Override - public Enumerator enumerator() { + public Enumerator enumerator() { return new CottontailInsertResultEnumerator(); } - private class CottontailInsertResultEnumerator implements Enumerator { + private class CottontailInsertResultEnumerator implements Enumerator { /** * Result of the last INSERT that was performed. */ - private long currentResult; + private PolyValue[] currentResult; /** * The pointer to the last {@link InsertMessage} that was executed. @@ -54,7 +56,7 @@ private class CottontailInsertResultEnumerator implements Enumerator { @Override - public Long current() { + public PolyValue[] current() { return this.currentResult; } @@ -64,14 +66,12 @@ public boolean moveNext() { if ( this.pointer < CottontailInsertEnumerable.this.inserts.size() ) { final InsertMessage insertMessage = CottontailInsertEnumerable.this.inserts.get( this.pointer++ ); if ( CottontailInsertEnumerable.this.wrapper.insert( insertMessage ) ) { - this.currentResult = 1; - } else { - this.currentResult = -1; + this.currentResult = new PolyValue[]{ PolyLong.of( 1 ) }; + return true; } - return !(this.currentResult == -1L); - } else { - return false; + this.currentResult = new PolyValue[]{ PolyLong.of( -1 ) }; } + return false; } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java index 2cec4d0ba5..e5ff95a8d1 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailQueryEnumerable.java @@ -28,20 +28,14 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.sql.language.fun.SqlArrayValueConstructor; import org.polypheny.db.type.ArrayType; -import org.polypheny.db.type.entity.PolyBigDecimal; -import org.polypheny.db.type.entity.PolyBinary; import org.polypheny.db.type.entity.PolyBoolean; -import org.polypheny.db.type.entity.PolyDate; import org.polypheny.db.type.entity.PolyDouble; import org.polypheny.db.type.entity.PolyFloat; import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyLong; import org.polypheny.db.type.entity.PolyNull; import org.polypheny.db.type.entity.PolyString; -import org.polypheny.db.type.entity.PolyTime; -import org.polypheny.db.type.entity.PolyTimeStamp; import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.type.entity.document.PolyDocument; import org.vitrivr.cottontail.client.iterators.Tuple; import org.vitrivr.cottontail.client.iterators.TupleIterator; @@ -165,22 +159,22 @@ private PolyValue parseSingleField( Object data, AlgDataType type ) { case NULL: return PolyNull.NULL; /* Pass through, no conversion needed. */ case TINYINT: - return PolyInteger.of( Linq4JFixer.getTinyIntData( data ) ); + return Linq4JFixer.getTinyIntData( data ); case SMALLINT: - return PolyInteger.of( Linq4JFixer.getSmallIntData( data ) ); + return Linq4JFixer.getSmallIntData( data ); case JSON: - return PolyDocument.parse( Linq4JFixer.getStringData( data ) ); + return Linq4JFixer.getStringData( data ); case DECIMAL: - return PolyBigDecimal.of( Linq4JFixer.getDecimalData( data ) ); + return Linq4JFixer.getDecimalData( data ); case DATE: - return PolyDate.of( Linq4JFixer.getDateData( data ) ); + return Linq4JFixer.getDateData( data ); case TIME: - return PolyTime.of( Linq4JFixer.getTimeData( data ) ); + return Linq4JFixer.getTimeData( data ); case TIMESTAMP: - return PolyTimeStamp.of( Linq4JFixer.getTimestampData( data ) ); + return Linq4JFixer.getTimestampData( data ); case BINARY: case VARBINARY: - return PolyBinary.of( Linq4JFixer.getBinaryData( data ) ); + return Linq4JFixer.getBinaryData( data ); case ARRAY: ArrayType arrayType = (ArrayType) type; if ( arrayType.getDimension() == 1 && CottontailToEnumerableConverter.SUPPORTED_ARRAY_COMPONENT_TYPES.contains( arrayType.getComponentType().getPolyType() ) ) { diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailUpdateEnumerable.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailUpdateEnumerable.java index 61fa15cd14..c44a5c7f9e 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailUpdateEnumerable.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/enumberable/CottontailUpdateEnumerable.java @@ -21,11 +21,13 @@ import org.apache.calcite.linq4j.AbstractEnumerable; import org.apache.calcite.linq4j.Enumerator; import org.polypheny.db.adapter.cottontail.CottontailWrapper; +import org.polypheny.db.type.entity.PolyLong; +import org.polypheny.db.type.entity.PolyValue; import org.vitrivr.cottontail.grpc.CottontailGrpc.UpdateMessage; @Slf4j -public class CottontailUpdateEnumerable extends AbstractEnumerable { +public class CottontailUpdateEnumerable extends AbstractEnumerable { private final List updates; private final CottontailWrapper wrapper; @@ -38,17 +40,17 @@ public CottontailUpdateEnumerable( List updates, CottontailWrappe @Override - public Enumerator enumerator() { + public Enumerator enumerator() { return new CottontailUpdateEnumerator(); } - private class CottontailUpdateEnumerator implements Enumerator { + private class CottontailUpdateEnumerator implements Enumerator { /** * Result of the last UPDATE that was performed. */ - private long currentResult; + private PolyValue[] currentResult; /** * The pointer to the last {@link UpdateMessage} that was executed. @@ -57,7 +59,7 @@ private class CottontailUpdateEnumerator implements Enumerator { @Override - public Long current() { + public PolyValue[] current() { return this.currentResult; } @@ -66,8 +68,8 @@ public Long current() { public boolean moveNext() { if ( this.pointer < CottontailUpdateEnumerable.this.updates.size() ) { final UpdateMessage updateMessage = CottontailUpdateEnumerable.this.updates.get( this.pointer++ ); - this.currentResult = CottontailUpdateEnumerable.this.wrapper.update( updateMessage ); - return !(this.currentResult == -1L); + this.currentResult = new PolyValue[]{ PolyLong.of( CottontailUpdateEnumerable.this.wrapper.update( updateMessage ) ) }; + return !currentResult[0].equals( PolyLong.of( -1 ) ); } return false; } 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 46a702b627..c78f027125 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 @@ -46,7 +46,7 @@ private static boolean supports( RelModify modify ) { @Override public boolean matches( AlgOptRuleCall call ) { - final RelModify modify = call.alg( 0 ); + final RelModify modify = call.alg( 0 ); if ( modify.getEntity().unwrap( CottontailEntity.class ) == null ) { return false; } diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java index 13b657b58b..f08de343e9 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java @@ -70,7 +70,7 @@ public class CottontailTypeUtil { public static final Method COTTONTAIL_SIMPLE_CONSTANT_TO_DATA_METHOD = Types.lookupMethod( CottontailTypeUtil.class, "toData", - Object.class, PolyType.class, PolyType.class ); + PolyValue.class, PolyType.class, PolyType.class ); public static final Method COTTONTAIL_KNN_BUILDER_METHOD = Types.lookupMethod( Linq4JFixer.class, @@ -179,10 +179,10 @@ public static CottontailGrpc.Type getPhysicalTypeRepresentation( PolyType logica public static Expression rexDynamicParamToDataExpression( RexDynamicParam dynamicParam, ParameterExpression dynamicParameterMap_, PolyType actualType ) { return Expressions.call( COTTONTAIL_SIMPLE_CONSTANT_TO_DATA_METHOD, - Expressions.call( + Expressions.convert_( Expressions.call( dynamicParameterMap_, BuiltInMethod.MAP_GET.method, - Expressions.constant( dynamicParam.getIndex() ) ), + Expressions.constant( dynamicParam.getIndex() ) ), PolyValue.class ), Expressions.constant( actualType ), Expressions.constant( dynamicParam.getType() != null ? dynamicParam.getType().getComponentType() != null ? diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/Linq4JFixer.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/Linq4JFixer.java index 84e248a8bd..239b34546f 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/Linq4JFixer.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/Linq4JFixer.java @@ -21,12 +21,19 @@ import java.util.List; import org.apache.calcite.avatica.util.ByteString; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.type.entity.PolyBigDecimal; +import org.polypheny.db.type.entity.PolyBinary; import org.polypheny.db.type.entity.PolyBoolean; +import org.polypheny.db.type.entity.PolyDate; import org.polypheny.db.type.entity.PolyDouble; import org.polypheny.db.type.entity.PolyFloat; import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyList; import org.polypheny.db.type.entity.PolyLong; +import org.polypheny.db.type.entity.PolyString; +import org.polypheny.db.type.entity.PolyTime; +import org.polypheny.db.type.entity.PolyTimeStamp; +import org.polypheny.db.type.entity.PolyValue; import org.vitrivr.cottontail.client.language.basics.Distances; import org.vitrivr.cottontail.grpc.CottontailGrpc.AtomicBooleanOperand; import org.vitrivr.cottontail.grpc.CottontailGrpc.AtomicBooleanPredicate; @@ -55,11 +62,11 @@ public class Linq4JFixer { * @param data The data, expected to be {@link Byte}. * @return {@link Byte} */ - public static Byte getTinyIntData( Object data ) { + public static PolyValue getTinyIntData( Object data ) { if ( data == null ) { return null; } - return ((Integer) data).byteValue(); + return PolyInteger.of( ((Integer) data) ); } @@ -69,11 +76,11 @@ public static Byte getTinyIntData( Object data ) { * @param data The data, expected to be {@link Short}. * @return {@link Short} */ - public static Short getSmallIntData( Object data ) { + public static PolyInteger getSmallIntData( Object data ) { if ( data == null ) { return null; } - return ((Integer) data).shortValue(); + return PolyInteger.of( (Integer) data ); } @@ -83,11 +90,11 @@ public static Short getSmallIntData( Object data ) { * @param data The data, expected to be {@link String}. * @return {@link String} */ - public static String getStringData( Object data ) { + public static PolyString getStringData( Object data ) { if ( data == null ) { return null; } - return (String) data; + return PolyString.of( (String) data ); } @@ -97,11 +104,11 @@ public static String getStringData( Object data ) { * @param data The data, expected to be {@link String}. * @return {@link BigDecimal} */ - public static BigDecimal getDecimalData( Object data ) { + public static PolyBigDecimal getDecimalData( Object data ) { if ( data == null ) { return null; } - return new BigDecimal( (String) data ); + return PolyBigDecimal.of( (String) data ); } @@ -111,11 +118,11 @@ public static BigDecimal getDecimalData( Object data ) { * @param data The data, expected to be {@link String}. * @return {@link ByteString} */ - public static byte[] getBinaryData( Object data ) { + public static PolyBinary getBinaryData( Object data ) { if ( data == null ) { return null; } - return ByteString.parseBase64( (String) data ); + return PolyBinary.of( ByteString.parseBase64( (String) data ) ); } @@ -125,25 +132,38 @@ public static byte[] getBinaryData( Object data ) { * @param data The data, expected to be {@link Integer}. * @return {@link Integer} */ - public static Integer getTimeData( Object data ) { + public static PolyTime getTimeData( Object data ) { if ( !(data instanceof Integer) ) { return null; } - return (Integer) data; + return PolyTime.of( (Integer) data ); } + /** + * Converts the given object and returns it as {@link Double} object. + * + * @param data The data, expected to be {@link Double}. + * @return {@link PolyDouble} + */ + public static PolyDouble getDoubleData( Object data ) { + if ( !(data instanceof Double) ) { + return null; + } + return PolyDouble.of( (Double) data ); + } + /** * Converts the given object and returns it as {@link Integer} object. * * @param data The data, expected to be {@link Integer}. * @return {@link Integer} */ - public static Integer getDateData( Object data ) { + public static PolyDate getDateData( Object data ) { if ( !(data instanceof Integer) ) { return null; } - return (Integer) data; + return PolyDate.of( (Integer) data ); } @@ -153,14 +173,47 @@ public static Integer getDateData( Object data ) { * @param data The data, expected to be {@link java.util.Date}. * @return {@link Integer} */ - public static Long getTimestampData( Object data ) { + public static PolyTimeStamp getTimestampData( Object data ) { + if ( data == null ) { + return null; + } + return PolyTimeStamp.of( (java.util.Date) data ); + } + + + public static PolyFloat getRealData( Object data ) { + if ( data == null ) { + return null; + } + return PolyFloat.of( (Number) data ); + } + + + public static PolyLong getBigIntData( Object data ) { + if ( data == null ) { + return null; + } + return PolyLong.of( (Number) data ); + } + + + public static PolyInteger getIntData( Object data ) { + if ( data == null ) { + return null; + } + return PolyInteger.of( (Integer) data ); + } + + + public static PolyBoolean getBoolData( Object data ) { if ( data == null ) { return null; } - return ((java.util.Date) data).getTime(); + return PolyBoolean.of( (Boolean) data ); } + public static PolyList getBoolVector( Object data ) { if ( data == null ) { return null; diff --git a/plugins/druid-adapter/build.gradle b/plugins/druid-adapter/build.gradle deleted file mode 100644 index 4e18e9a1e6..0000000000 --- a/plugins/druid-adapter/build.gradle +++ /dev/null @@ -1,79 +0,0 @@ -group "org.polypheny" - - -dependencies { - compileOnly project(":core") - compileOnly project(":plugins:sql-language") - - implementation group: "joda-time", name: "joda-time", version: joda_time_version // Apache 2.0 - - - // --- Test Compile --- - testImplementation project(path: ":core", configuration: "tests") - testImplementation project(path: ":core") - testImplementation project(path: ":plugins:sql-language", configuration: "tests") - - testImplementation group: "junit", name: "junit", version: junit_version - testImplementation group: "org.hamcrest", name: "hamcrest-core", version: hamcrest_core_version // BSD 3-clause - - testImplementation group: "org.mockito", name: "mockito-core", version: mockito_core_version // MIT -} - - -sourceSets { - main { - java { - srcDirs = ["src/main/java"] - outputDir = file(project.buildDir.absolutePath + "/classes") - } - resources { - srcDirs = ["src/main/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/classes") - } - test { - java { - srcDirs = ["src/test/java"] - outputDir = file(project.buildDir.absolutePath + "/test-classes") - } - resources { - srcDirs = ["src/test/resources"] - } - output.resourcesDir = file(project.buildDir.absolutePath + "/test-classes") - } -} - -compileJava { - dependsOn(":plugins:sql-language:processResources") -} - -delombok { - dependsOn(":plugins:sql-language:processResources") -} - -/** - * Tests - */ -test { - include "**/DruidDateRangeRulesTest.class" -} - - -/** - * JARs - */ -jar { - manifest { - attributes "Manifest-Version": "1.0" - attributes "Copyright": "The Polypheny Project (polypheny.org)" - attributes "Version": "$project.version" - } -} -java { - withJavadocJar() - withSourcesJar() -} - -licensee { - allow('Apache-2.0') -} diff --git a/plugins/druid-adapter/gradle.properties b/plugins/druid-adapter/gradle.properties deleted file mode 100644 index e647dd697f..0000000000 --- a/plugins/druid-adapter/gradle.properties +++ /dev/null @@ -1,27 +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. -# - -pluginVersion = 0.0.1 - -pluginId = druid-adapter -pluginClass = org.polypheny.db.adapter.druid.DruidPlugin -pluginProvider = The Polypheny Project -pluginDependencies = -pluginUrlPath = -pluginCategories = source -pluginPolyDependencies = -pluginIsSystemComponent = false -pluginIsUiVisible = false \ No newline at end of file diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/BinaryOperatorConversion.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/BinaryOperatorConversion.java deleted file mode 100644 index e8fac31d91..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/BinaryOperatorConversion.java +++ /dev/null @@ -1,81 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import java.util.List; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.nodes.Operator; -import org.polypheny.db.rex.RexCall; -import org.polypheny.db.rex.RexNode; - - -/** - * Binary operator conversion utility class used to convert expression like exp1 Operator exp2 - */ -public class BinaryOperatorConversion implements DruidSqlOperatorConverter { - - private final Operator operator; - private final String druidOperator; - - - public BinaryOperatorConversion( final Operator operator, final String druidOperator ) { - this.operator = operator; - this.druidOperator = druidOperator; - } - - - @Override - public Operator polyphenyDbOperator() { - return operator; - } - - - @Override - public String toDruidExpression( RexNode rexNode, AlgDataType rowType, DruidQuery druidQuery ) { - - final RexCall call = (RexCall) rexNode; - - final List druidExpressions = DruidExpressions.toDruidExpressions( druidQuery, rowType, call.getOperands() ); - if ( druidExpressions == null ) { - return null; - } - if ( druidExpressions.size() != 2 ) { - throw new IllegalStateException( DruidQuery.format( "Got binary operator[%s] with %s args?", operator.getName(), druidExpressions.size() ) ); - } - - return DruidQuery.format( "(%s %s %s)", druidExpressions.get( 0 ), druidOperator, druidExpressions.get( 1 ) ); - } - -} diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/CeilOperatorConversion.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/CeilOperatorConversion.java deleted file mode 100644 index 023fe257fb..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/CeilOperatorConversion.java +++ /dev/null @@ -1,99 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import java.util.TimeZone; -import javax.annotation.Nullable; -import org.apache.calcite.avatica.util.DateTimeUtils; -import org.apache.calcite.avatica.util.TimeUnitRange; -import org.polypheny.db.algebra.operators.OperatorName; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.languages.OperatorRegistry; -import org.polypheny.db.nodes.Operator; -import org.polypheny.db.rex.RexCall; -import org.polypheny.db.rex.RexLiteral; -import org.polypheny.db.rex.RexNode; -import org.polypheny.db.type.PolyType; - - -/** - * DruidSqlOperatorConverter implementation that handles Ceil operations conversions - */ -public class CeilOperatorConversion implements DruidSqlOperatorConverter { - - @Override - public Operator polyphenyDbOperator() { - return OperatorRegistry.get( OperatorName.CEIL ); - } - - - @Nullable - @Override - public String toDruidExpression( RexNode rexNode, AlgDataType rowType, DruidQuery query ) { - final RexCall call = (RexCall) rexNode; - final RexNode arg = call.getOperands().get( 0 ); - final String druidExpression = DruidExpressions.toDruidExpression( arg, rowType, query ); - if ( druidExpression == null ) { - return null; - } else if ( call.getOperands().size() == 1 ) { - // case CEIL(expr) - return DruidQuery.format( "ceil(%s)", druidExpression ); - } else if ( call.getOperands().size() == 2 ) { - // CEIL(expr TO timeUnit) - final RexLiteral flag = (RexLiteral) call.getOperands().get( 1 ); - final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue(); - final Granularity.Type type = DruidDateTimeUtils.toDruidGranularity( timeUnit ); - if ( type == null ) { - // Unknown Granularity bail out - return null; - } - String isoPeriodFormat = DruidDateTimeUtils.toISOPeriodFormat( type ); - if ( isoPeriodFormat == null ) { - return null; - } - final TimeZone tz; - if ( arg.getType().getPolyType() == PolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE ) { - tz = TimeZone.getTimeZone( query.getConnectionConfig().timeZone() ); - } else { - tz = DateTimeUtils.UTC_ZONE; - } - return DruidExpressions.applyTimestampCeil( druidExpression, isoPeriodFormat, "", tz ); - } else { - return null; - } - } - -} - diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ComplexMetric.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ComplexMetric.java deleted file mode 100644 index 5164127bbc..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/ComplexMetric.java +++ /dev/null @@ -1,107 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.algebra.core.AggregateCall; - - -/** - * Used to store information about available complex metrics in the Druid Adapter - */ -public class ComplexMetric { - - /** - * The underlying metric column this complex metric represents - */ - private final String metricName; - - /** - * The type of this metric - */ - private final DruidType type; - - - public ComplexMetric( String metricName, DruidType type ) { - validate( type ); - this.metricName = metricName; - this.type = type; - } - - - private void validate( DruidType type ) { - if ( !type.isComplex() ) { - throw new IllegalArgumentException( "Druid type: " + type + " is not complex" ); - } - } - - - public String getMetricName() { - return metricName; - } - - - public DruidType getDruidType() { - return type; - } - - - public String getMetricType() { - switch ( type ) { - case HYPER_UNIQUE: - return "hyperUnique"; - case THETA_SKETCH: - return "thetaSketch"; - default: - throw new AssertionError( "Type: " + type + " does not have an associated metric type" ); - } - } - - - /** - * Returns true if and only if this ComplexMetric can be used in the given {@link AggregateCall}. - */ - public boolean canBeUsed( AggregateCall call ) { - switch ( type ) { - case HYPER_UNIQUE: - case THETA_SKETCH: - return call != null && call.getAggregation().getKind() == Kind.COUNT && call.isDistinct(); - default: - return false; - } - } - -} - diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DefaultDimensionSpec.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DefaultDimensionSpec.java deleted file mode 100644 index 214b204e8b..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DefaultDimensionSpec.java +++ /dev/null @@ -1,101 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import com.fasterxml.jackson.core.JsonGenerator; -import java.io.IOException; -import java.util.Objects; - - -/** - * Default implementation of DimensionSpec. - * - * The default implementation returns dimension values as is and optionally renames the dimension. - */ -public class DefaultDimensionSpec implements DimensionSpec { - - private final String dimension; - private final String outputName; - private final DruidType outputType; - - - public DefaultDimensionSpec( String dimension, String outputName, DruidType outputType ) { - this.dimension = Objects.requireNonNull( dimension ); - this.outputName = Objects.requireNonNull( outputName ); - this.outputType = outputType == null ? DruidType.STRING : outputType; - } - - - public DefaultDimensionSpec( String dimension ) { - this( dimension, dimension, null ); - } - - - @Override - public void write( JsonGenerator generator ) throws IOException { - generator.writeStartObject(); - generator.writeStringField( "type", "default" ); - generator.writeStringField( "dimension", dimension ); - generator.writeStringField( "outputName", outputName ); - generator.writeStringField( "outputType", outputType.name() ); - generator.writeEndObject(); - } - - - @Override - public String getOutputName() { - return outputName; - } - - - @Override - public DruidType getOutputType() { - return outputType; - } - - - @Override - public ExtractionFunction getExtractionFn() { - return null; - } - - - @Override - public String getDimension() { - return dimension; - } - -} - diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DimensionSpec.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DimensionSpec.java deleted file mode 100644 index 000d0b7c10..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DimensionSpec.java +++ /dev/null @@ -1,57 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import javax.annotation.Nullable; - - -/** - * Interface for Druid DimensionSpec. - * - * DimensionSpecs define how dimension values get transformed prior to aggregation. - */ -public interface DimensionSpec extends DruidJson { - - String getOutputName(); - - DruidType getOutputType(); - - @Nullable - ExtractionFunction getExtractionFn(); - - String getDimension(); - -} - diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DirectOperatorConversion.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DirectOperatorConversion.java deleted file mode 100644 index 4d4ed135d1..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DirectOperatorConversion.java +++ /dev/null @@ -1,76 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import java.util.List; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.nodes.Operator; -import org.polypheny.db.rex.RexCall; -import org.polypheny.db.rex.RexNode; - - -/** - * Direct operator conversion for expression like Function(exp_1,...exp_n) - */ -public class DirectOperatorConversion implements DruidSqlOperatorConverter { - - private final Operator operator; - private final String druidFunctionName; - - - public DirectOperatorConversion( final Operator operator, final String druidFunctionName ) { - this.operator = operator; - this.druidFunctionName = druidFunctionName; - } - - - @Override - public Operator polyphenyDbOperator() { - return operator; - } - - - @Override - public String toDruidExpression( RexNode rexNode, AlgDataType rowType, DruidQuery druidQuery ) { - final RexCall call = (RexCall) rexNode; - final List druidExpressions = DruidExpressions.toDruidExpressions( druidQuery, rowType, call.getOperands() ); - if ( druidExpressions == null ) { - return null; - } - return DruidExpressions.functionCall( druidFunctionName, druidExpressions ); - } - -} - diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnection.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnection.java deleted file mode 100644 index 9506407459..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnection.java +++ /dev/null @@ -1,43 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -/** - * Connection to Druid. - */ -public interface DruidConnection { - -} - diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnectionImpl.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnectionImpl.java deleted file mode 100644 index 9dc992ca13..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidConnectionImpl.java +++ /dev/null @@ -1,762 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import static org.polypheny.db.runtime.HttpUtils.post; - -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.CollectionType; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Set; -import java.util.TimeZone; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.calcite.avatica.AvaticaUtils; -import org.apache.calcite.avatica.ColumnMetaData; -import org.apache.calcite.avatica.util.DateTimeUtils; -import org.apache.calcite.linq4j.AbstractEnumerable; -import org.apache.calcite.linq4j.Enumerable; -import org.apache.calcite.linq4j.Enumerator; -import org.joda.time.Interval; -import org.polypheny.db.config.RuntimeConfig; -import org.polypheny.db.interpreter.Row; -import org.polypheny.db.interpreter.Row.RowBuilder; -import org.polypheny.db.interpreter.Sink; -import org.polypheny.db.type.PolyType; -import org.polypheny.db.util.Holder; -import org.polypheny.db.util.Util; - - -/** - * Implementation of {@link DruidConnection}. - */ -class DruidConnectionImpl implements DruidConnection { - - private final String url; - private final String coordinatorUrl; - - public static final String DEFAULT_RESPONSE_TIMESTAMP_COLUMN = "timestamp"; - private static final SimpleDateFormat UTC_TIMESTAMP_FORMAT; - private static final SimpleDateFormat TIMESTAMP_FORMAT; - - - static { - final TimeZone utc = DateTimeUtils.UTC_ZONE; - UTC_TIMESTAMP_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT ); - UTC_TIMESTAMP_FORMAT.setTimeZone( utc ); - TIMESTAMP_FORMAT = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.ROOT ); - TIMESTAMP_FORMAT.setTimeZone( utc ); - } - - - DruidConnectionImpl( String url, String coordinatorUrl ) { - this.url = Objects.requireNonNull( url ); - this.coordinatorUrl = Objects.requireNonNull( coordinatorUrl ); - } - - - /** - * Executes a query request. - * - * @param queryType Query type - * @param data Data to post - * @param sink Sink to which to send the parsed rows - * @param fieldNames Names of fields - * @param fieldTypes Types of fields (never null, but elements may be null) - * @param page Page definition (in/out) - */ - public void request( QueryType queryType, String data, Sink sink, List fieldNames, List fieldTypes, Page page ) { - final String url = this.url + "/druid/v2/?pretty"; - final Map requestHeaders = ImmutableMap.of( "Content-Type", "application/json" ); - if ( RuntimeConfig.DEBUG.getBoolean() ) { - System.out.println( data ); - } - try ( InputStream in0 = post( url, data, requestHeaders, 10000, 1800000 ); InputStream in = traceResponse( in0 ) ) { - parse( queryType, in, sink, fieldNames, fieldTypes, page ); - } catch ( IOException e ) { - throw new RuntimeException( "Error while processing druid request [" + data + "]", e ); - } - } - - - /** - * Parses the output of a query, sending the results to a {@link Sink}. - */ - private void parse( QueryType queryType, InputStream in, Sink sink, List fieldNames, List fieldTypes, Page page ) { - final JsonFactory factory = new JsonFactory(); - final RowBuilder rowBuilder = Row.newBuilder( fieldNames.size() ); - - if ( RuntimeConfig.DEBUG.getBoolean() ) { - try { - final byte[] bytes = AvaticaUtils.readFullyToBytes( in ); - System.out.println( "Response: " + new String( bytes, StandardCharsets.UTF_8 ) ); - in = new ByteArrayInputStream( bytes ); - } catch ( IOException e ) { - throw new RuntimeException( e ); - } - } - - int posTimestampField = -1; - for ( int i = 0; i < fieldTypes.size(); i++ ) { - // TODO: This need to be revisited. The logic seems implying that only one column of type timestamp is present, this is not necessarily true - if ( fieldTypes.get( i ) == ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP ) { - posTimestampField = i; - break; - } - } - - try ( JsonParser parser = factory.createParser( in ) ) { - switch ( queryType ) { - case TIMESERIES: - if ( parser.nextToken() == JsonToken.START_ARRAY ) { - while ( parser.nextToken() == JsonToken.START_OBJECT ) { - // loop until token equal to "}" - final Long timeValue = extractTimestampField( parser ); - if ( parser.nextToken() == JsonToken.FIELD_NAME && parser.getCurrentName().equals( "result" ) && parser.nextToken() == JsonToken.START_OBJECT ) { - if ( posTimestampField != -1 ) { - rowBuilder.set( posTimestampField, timeValue ); - } - parseFields( fieldNames, fieldTypes, rowBuilder, parser ); - sink.send( rowBuilder.build() ); - rowBuilder.reset(); - } - expect( parser, JsonToken.END_OBJECT ); - } - } - break; - - case TOP_N: - if ( parser.nextToken() == JsonToken.START_ARRAY && parser.nextToken() == JsonToken.START_OBJECT ) { - final Long timeValue = extractTimestampField( parser ); - if ( parser.nextToken() == JsonToken.FIELD_NAME && parser.getCurrentName().equals( "result" ) && parser.nextToken() == JsonToken.START_ARRAY ) { - while ( parser.nextToken() == JsonToken.START_OBJECT ) { - // loop until token equal to "}" - if ( posTimestampField != -1 ) { - rowBuilder.set( posTimestampField, timeValue ); - } - parseFields( fieldNames, fieldTypes, rowBuilder, parser ); - sink.send( rowBuilder.build() ); - rowBuilder.reset(); - } - } - } - break; - - case SELECT: - if ( parser.nextToken() == JsonToken.START_ARRAY && parser.nextToken() == JsonToken.START_OBJECT ) { - page.pagingIdentifier = null; - page.offset = -1; - page.totalRowCount = 0; - expectScalarField( parser, DEFAULT_RESPONSE_TIMESTAMP_COLUMN ); - if ( parser.nextToken() == JsonToken.FIELD_NAME && parser.getCurrentName().equals( "result" ) && parser.nextToken() == JsonToken.START_OBJECT ) { - while ( parser.nextToken() == JsonToken.FIELD_NAME ) { - if ( parser.getCurrentName().equals( "pagingIdentifiers" ) && parser.nextToken() == JsonToken.START_OBJECT ) { - JsonToken token = parser.nextToken(); - while ( parser.getCurrentToken() == JsonToken.FIELD_NAME ) { - page.pagingIdentifier = parser.getCurrentName(); - if ( parser.nextToken() == JsonToken.VALUE_NUMBER_INT ) { - page.offset = parser.getIntValue(); - } - token = parser.nextToken(); - } - expect( token, JsonToken.END_OBJECT ); - } else if ( parser.getCurrentName().equals( "events" ) && parser.nextToken() == JsonToken.START_ARRAY ) { - while ( parser.nextToken() == JsonToken.START_OBJECT ) { - expectScalarField( parser, "segmentId" ); - expectScalarField( parser, "offset" ); - if ( parser.nextToken() == JsonToken.FIELD_NAME && parser.getCurrentName().equals( "event" ) && parser.nextToken() == JsonToken.START_OBJECT ) { - parseFields( fieldNames, fieldTypes, posTimestampField, rowBuilder, parser ); - sink.send( rowBuilder.build() ); - rowBuilder.reset(); - page.totalRowCount += 1; - } - expect( parser, JsonToken.END_OBJECT ); - } - parser.nextToken(); - } else if ( parser.getCurrentName().equals( "dimensions" ) || parser.getCurrentName().equals( "metrics" ) ) { - expect( parser, JsonToken.START_ARRAY ); - while ( parser.nextToken() != JsonToken.END_ARRAY ) { - // empty - } - } - } - } - } - break; - - case GROUP_BY: - if ( parser.nextToken() == JsonToken.START_ARRAY ) { - while ( parser.nextToken() == JsonToken.START_OBJECT ) { - expectScalarField( parser, "version" ); - final Long timeValue = extractTimestampField( parser ); - if ( parser.nextToken() == JsonToken.FIELD_NAME && parser.getCurrentName().equals( "event" ) && parser.nextToken() == JsonToken.START_OBJECT ) { - if ( posTimestampField != -1 ) { - rowBuilder.set( posTimestampField, timeValue ); - } - parseFields( fieldNames, fieldTypes, posTimestampField, rowBuilder, parser ); - sink.send( rowBuilder.build() ); - rowBuilder.reset(); - } - expect( parser, JsonToken.END_OBJECT ); - } - } - break; - - case SCAN: - if ( parser.nextToken() == JsonToken.START_ARRAY ) { - while ( parser.nextToken() == JsonToken.START_OBJECT ) { - expectScalarField( parser, "segmentId" ); - - expect( parser, JsonToken.FIELD_NAME ); - if ( parser.getCurrentName().equals( "columns" ) ) { - expect( parser, JsonToken.START_ARRAY ); - while ( parser.nextToken() != JsonToken.END_ARRAY ) { - // Skip the columns list - } - } - if ( parser.nextToken() == JsonToken.FIELD_NAME && parser.getCurrentName().equals( "events" ) && parser.nextToken() == JsonToken.START_ARRAY ) { - // Events is Array of Arrays where each array is a row - while ( parser.nextToken() == JsonToken.START_ARRAY ) { - for ( String field : fieldNames ) { - parseFieldForName( fieldNames, fieldTypes, posTimestampField, rowBuilder, parser, field ); - } - expect( parser, JsonToken.END_ARRAY ); - Row row = rowBuilder.build(); - sink.send( row ); - rowBuilder.reset(); - page.totalRowCount += 1; - } - } - expect( parser, JsonToken.END_OBJECT ); - } - } - } - } catch ( IOException | InterruptedException e ) { - throw new RuntimeException( e ); - } - } - - - private void parseFields( List fieldNames, List fieldTypes, Row.RowBuilder rowBuilder, JsonParser parser ) throws IOException { - parseFields( fieldNames, fieldTypes, -1, rowBuilder, parser ); - } - - - private void parseFields( List fieldNames, List fieldTypes, int posTimestampField, Row.RowBuilder rowBuilder, JsonParser parser ) throws IOException { - while ( parser.nextToken() == JsonToken.FIELD_NAME ) { - parseField( fieldNames, fieldTypes, posTimestampField, rowBuilder, parser ); - } - } - - - private void parseField( List fieldNames, List fieldTypes, int posTimestampField, Row.RowBuilder rowBuilder, JsonParser parser ) throws IOException { - final String fieldName = parser.getCurrentName(); - parseFieldForName( fieldNames, fieldTypes, posTimestampField, rowBuilder, parser, fieldName ); - } - - - private void parseFieldForName( List fieldNames, List fieldTypes, int posTimestampField, Row.RowBuilder rowBuilder, JsonParser parser, String fieldName ) throws IOException { - // Move to next token, which is name's value - JsonToken token = parser.nextToken(); - - boolean isTimestampColumn = fieldName.equals( DEFAULT_RESPONSE_TIMESTAMP_COLUMN ); - int i = fieldNames.indexOf( fieldName ); - ColumnMetaData.Rep type = null; - if ( i < 0 ) { - if ( !isTimestampColumn ) { - // Field not present - return; - } - } else { - type = fieldTypes.get( i ); - } - - if ( isTimestampColumn || ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP == type ) { - final int fieldPos = posTimestampField != -1 ? posTimestampField : i; - if ( token == JsonToken.VALUE_NUMBER_INT ) { - rowBuilder.set( posTimestampField, parser.getLongValue() ); - return; - } else { - // We don't have any way to figure out the format of time upfront since we only have org.apache.calcite.avatica.ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP as type to represent - // both timestamp and timestamp with local timezone. Logic where type is inferred can be found at DruidQuery.DruidQueryNode.getPrimitive(). Thus need to guess via try and catch - synchronized ( UTC_TIMESTAMP_FORMAT ) { - // synchronized block to avoid race condition - try { - // First try to parse as Timestamp with timezone. - rowBuilder.set( fieldPos, UTC_TIMESTAMP_FORMAT.parse( parser.getText() ).getTime() ); - } catch ( ParseException e ) { - // swallow the exception and try timestamp format - try { - rowBuilder.set( fieldPos, TIMESTAMP_FORMAT.parse( parser.getText() ).getTime() ); - } catch ( ParseException e2 ) { - // unknown format should not happen - throw new RuntimeException( e2 ); - } - } - } - return; - } - } - - switch ( token ) { - case VALUE_NUMBER_INT: - if ( type == null ) { - type = ColumnMetaData.Rep.LONG; - } - // fall through - case VALUE_NUMBER_FLOAT: - if ( type == null ) { - // JSON's "float" is 64-bit floating point - type = ColumnMetaData.Rep.DOUBLE; - } - switch ( type ) { - case BYTE: - rowBuilder.set( i, parser.getByteValue() ); - break; - case SHORT: - rowBuilder.set( i, parser.getShortValue() ); - break; - case INTEGER: - rowBuilder.set( i, parser.getIntValue() ); - break; - case LONG: - rowBuilder.set( i, parser.getLongValue() ); - break; - case DOUBLE: - rowBuilder.set( i, parser.getDoubleValue() ); - break; - } - break; - case VALUE_TRUE: - rowBuilder.set( i, true ); - break; - case VALUE_FALSE: - rowBuilder.set( i, false ); - break; - case VALUE_NULL: - break; - case VALUE_STRING: - default: - final String s = parser.getText(); - if ( type != null ) { - switch ( type ) { - case LONG: - case PRIMITIVE_LONG: - case SHORT: - case PRIMITIVE_SHORT: - case INTEGER: - case PRIMITIVE_INT: - switch ( s ) { - case "Infinity": - case "-Infinity": - case "NaN": - throw new RuntimeException( "/ by zero" ); - } - rowBuilder.set( i, Long.valueOf( s ) ); - break; - case FLOAT: - case PRIMITIVE_FLOAT: - case PRIMITIVE_DOUBLE: - case NUMBER: - case DOUBLE: - switch ( s ) { - case "Infinity": - rowBuilder.set( i, Double.POSITIVE_INFINITY ); - return; - case "-Infinity": - rowBuilder.set( i, Double.NEGATIVE_INFINITY ); - return; - case "NaN": - rowBuilder.set( i, Double.NaN ); - return; - } - rowBuilder.set( i, Double.valueOf( s ) ); - break; - } - } else { - rowBuilder.set( i, s ); - } - } - } - - - private void expect( JsonParser parser, JsonToken token ) throws IOException { - expect( parser.nextToken(), token ); - } - - - private void expect( JsonToken token, JsonToken expected ) throws IOException { - if ( token != expected ) { - throw new RuntimeException( "expected " + expected + ", got " + token ); - } - } - - - private void expectScalarField( JsonParser parser, String name ) throws IOException { - expect( parser, JsonToken.FIELD_NAME ); - if ( !parser.getCurrentName().equals( name ) ) { - throw new RuntimeException( "expected field " + name + ", got " + parser.getCurrentName() ); - } - final JsonToken t = parser.nextToken(); - switch ( t ) { - case VALUE_NULL: - case VALUE_FALSE: - case VALUE_TRUE: - case VALUE_NUMBER_INT: - case VALUE_NUMBER_FLOAT: - case VALUE_STRING: - break; - default: - throw new RuntimeException( "expected scalar field, got " + t ); - } - } - - - private void expectObjectField( JsonParser parser, String name ) throws IOException { - expect( parser, JsonToken.FIELD_NAME ); - if ( !parser.getCurrentName().equals( name ) ) { - throw new RuntimeException( "expected field " + name + ", got " + parser.getCurrentName() ); - } - expect( parser, JsonToken.START_OBJECT ); - while ( parser.nextToken() != JsonToken.END_OBJECT ) { - // empty - } - } - - - private Long extractTimestampField( JsonParser parser ) throws IOException { - expect( parser, JsonToken.FIELD_NAME ); - if ( !parser.getCurrentName().equals( DEFAULT_RESPONSE_TIMESTAMP_COLUMN ) ) { - throw new RuntimeException( "expected field " + DEFAULT_RESPONSE_TIMESTAMP_COLUMN + ", got " + parser.getCurrentName() ); - } - parser.nextToken(); - try { - final Date parse; - // synchronized block to avoid race condition - synchronized ( UTC_TIMESTAMP_FORMAT ) { - parse = UTC_TIMESTAMP_FORMAT.parse( parser.getText() ); - } - return parse.getTime(); - } catch ( ParseException e ) { - // ignore bad value - } - return null; - } - - - /** - * Executes a request and returns the resulting rows as an {@link Enumerable}, running the parser in a thread provided by {@code service}. - */ - public Enumerable enumerable( final QueryType queryType, final String request, final List fieldNames, final ExecutorService service ) throws IOException { - return new AbstractEnumerable() { - @Override - public Enumerator enumerator() { - final BlockingQueueEnumerator enumerator = new BlockingQueueEnumerator<>(); - final RunnableQueueSink sink = new RunnableQueueSink() { - @Override - public void send( Row row ) throws InterruptedException { - enumerator.queue.put( row ); - } - - - @Override - public void end() { - enumerator.done.set( true ); - } - - - @Override - public void run() { - try { - final Page page = new Page(); - final List fieldTypes = Collections.nCopies( fieldNames.size(), null ); - request( queryType, request, this, fieldNames, fieldTypes, page ); - enumerator.done.set( true ); - } catch ( Throwable e ) { - enumerator.throwableHolder.set( e ); - enumerator.done.set( true ); - } - } - }; - service.execute( sink ); - return enumerator; - } - }; - } - - - /** - * Reads segment metadata, and populates a list of columns and metrics. - */ - void metadata( String dataSourceName, String timestampColumnName, List intervals, Map fieldBuilder, Set metricNameBuilder, Map> complexMetrics ) { - final String url = this.url + "/druid/v2/?pretty"; - final Map requestHeaders = ImmutableMap.of( "Content-Type", "application/json" ); - final String data = DruidQuery.metadataQuery( dataSourceName, intervals ); - if ( RuntimeConfig.DEBUG.getBoolean() ) { - System.out.println( "Druid: " + data ); - } - try ( InputStream in0 = post( url, data, requestHeaders, 10000, 1800000 ); InputStream in = traceResponse( in0 ) ) { - final ObjectMapper mapper = new ObjectMapper().configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); - final CollectionType listType = mapper.getTypeFactory().constructCollectionType( List.class, JsonSegmentMetadata.class ); - final List list = mapper.readValue( in, listType ); - in.close(); - fieldBuilder.put( timestampColumnName, PolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE ); - for ( JsonSegmentMetadata o : list ) { - for ( Map.Entry entry : o.columns.entrySet() ) { - if ( entry.getKey().equals( DruidEntity.DEFAULT_TIMESTAMP_COLUMN ) ) { - // timestamp column - continue; - } - final DruidType druidType; - try { - druidType = DruidType.getTypeFromMetaData( entry.getValue().type ); - } catch ( AssertionError e ) { - // ignore exception; not a supported type - continue; - } - fieldBuilder.put( entry.getKey(), druidType.sqlType ); - } - if ( o.aggregators != null ) { - for ( Map.Entry entry : o.aggregators.entrySet() ) { - if ( !fieldBuilder.containsKey( entry.getKey() ) ) { - continue; - } - DruidType type = DruidType.getTypeFromMetaData( entry.getValue().type ); - if ( type.isComplex() ) { - // Each complex type will get their own alias, equal to their actual name. Maybe we should have some smart string replacement strategies to make the column names more natural. - List metricList = new ArrayList<>(); - metricList.add( new ComplexMetric( entry.getKey(), type ) ); - complexMetrics.put( entry.getKey(), metricList ); - } else { - metricNameBuilder.add( entry.getKey() ); - } - } - } - } - } catch ( IOException e ) { - throw new RuntimeException( e ); - } - } - - - /** - * Reads data source names from Druid. - */ - Set tableNames() { - final Map requestHeaders = ImmutableMap.of( "Content-Type", "application/json" ); - final String data = null; - final String url = coordinatorUrl + "/druid/coordinator/v1/metadata/datasources"; - if ( RuntimeConfig.DEBUG.getBoolean() ) { - System.out.println( "Druid: table names" + data + "; " + url ); - } - try ( InputStream in0 = post( url, data, requestHeaders, 10000, 1800000 ); - InputStream in = traceResponse( in0 ) ) { - final ObjectMapper mapper = new ObjectMapper(); - final CollectionType listType = mapper.getTypeFactory().constructCollectionType( List.class, String.class ); - final List list = mapper.readValue( in, listType ); - return ImmutableSet.copyOf( list ); - } catch ( IOException e ) { - throw new RuntimeException( e ); - } - } - - - private InputStream traceResponse( InputStream in ) { - if ( RuntimeConfig.DEBUG.getBoolean() ) { - try { - final byte[] bytes = AvaticaUtils.readFullyToBytes( in ); - in.close(); - System.out.println( "Response: " + new String( bytes, StandardCharsets.UTF_8 ) ); // CHECKSTYLE: IGNORE 0 - in = new ByteArrayInputStream( bytes ); - } catch ( IOException e ) { - throw new RuntimeException( e ); - } - } - return in; - } - - - /** - * A {@link Sink} that is also {@link Runnable}. - */ - private interface RunnableQueueSink extends Sink, Runnable { - - } - - - /** - * An {@link Enumerator} that gets its rows from a {@link BlockingQueue}. There are other fields to signal errors and end-of-data. - * - * @param element type - */ - private static class BlockingQueueEnumerator implements Enumerator { - - final BlockingQueue queue = new ArrayBlockingQueue<>( 1000 ); - final AtomicBoolean done = new AtomicBoolean( false ); - final Holder throwableHolder = Holder.of( null ); - - E next; - - - @Override - public E current() { - if ( next == null ) { - throw new NoSuchElementException(); - } - return next; - } - - - @Override - public boolean moveNext() { - for ( ; ; ) { - next = queue.poll(); - if ( next != null ) { - return true; - } - if ( done.get() ) { - close(); - return false; - } - } - } - - - @Override - public void reset() { - } - - - @Override - public void close() { - final Throwable e = throwableHolder.get(); - if ( e != null ) { - throwableHolder.set( null ); - Util.throwIfUnchecked( e ); - throw new RuntimeException( e ); - } - } - - } - - - /** - * Progress through a large fetch. - */ - static class Page { - - String pagingIdentifier = null; - int offset = -1; - int totalRowCount = 0; - - - @Override - public String toString() { - return "{" + pagingIdentifier + ": " + offset + "}"; - } - - } - - - /** - * Result of a "segmentMetadata" call, populated by Jackson. - */ - @SuppressWarnings({ "WeakerAccess", "unused" }) - private static class JsonSegmentMetadata { - - public String id; - public List intervals; - public Map columns; - public long size; - public long numRows; - public Map aggregators; - - } - - - /** - * Element of the "columns" collection in the result of a "segmentMetadata" call, populated by Jackson. - */ - @SuppressWarnings({ "WeakerAccess", "unused" }) - private static class JsonColumn { - - public String type; - public boolean hasMultipleValues; - public int size; - public Integer cardinality; - public String errorMessage; - - } - - - /** - * Element of the "aggregators" collection in the result of a "segmentMetadata" call, populated by Jackson. - */ - @SuppressWarnings({ "WeakerAccess", "unused" }) - private static class JsonAggregator { - - public String type; - public String name; - public String fieldName; - - - DruidType druidType() { - return DruidType.getTypeFromMetric( type ); - } - - } - -} diff --git a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidDateTimeUtils.java b/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidDateTimeUtils.java deleted file mode 100644 index 5f8f552b95..0000000000 --- a/plugins/druid-adapter/src/main/java/org/polypheny/db/adapter/druid/DruidDateTimeUtils.java +++ /dev/null @@ -1,400 +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. - * - * This file incorporates code covered by the following terms: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you 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.adapter.druid; - - -import com.google.common.collect.BoundType; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.collect.Range; -import com.google.common.collect.TreeRangeSet; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nullable; -import org.apache.calcite.avatica.util.TimeUnitRange; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.joda.time.chrono.ISOChronology; -import org.polypheny.db.algebra.constant.Kind; -import org.polypheny.db.algebra.type.AlgDataType; -import org.polypheny.db.rex.RexCall; -import org.polypheny.db.rex.RexInputRef; -import org.polypheny.db.rex.RexLiteral; -import org.polypheny.db.rex.RexNode; -import org.polypheny.db.type.PolyType; -import org.polypheny.db.util.DateString; -import org.polypheny.db.util.TimestampString; -import org.polypheny.db.util.Util; -import org.polypheny.db.util.trace.PolyphenyDbTrace; -import org.slf4j.Logger; - - -/** - * Utilities for generating intervals from RexNode. - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class DruidDateTimeUtils { - - protected static final Logger LOGGER = PolyphenyDbTrace.getPlannerTracer(); - - - private DruidDateTimeUtils() { - } - - - /** - * Generates a list of {@link Interval}s equivalent to a given expression. Assumes that all the predicates in the input reference a single column: the timestamp column. - */ - @Nullable - public static List createInterval( RexNode e ) { - final List> ranges = extractRanges( e, false ); - if ( ranges == null ) { - // We did not succeed, bail out - return null; - } - final TreeRangeSet condensedRanges = TreeRangeSet.create(); - for ( Range r : ranges ) { - condensedRanges.add( r ); - } - LOGGER.debug( "Inferred ranges on interval : {}", condensedRanges ); - return toInterval( ImmutableList.>copyOf( condensedRanges.asRanges() ) ); - } - - - protected static List toInterval( List> ranges ) { - List intervals = Lists.transform( ranges, range -> { - if ( !range.hasLowerBound() && !range.hasUpperBound() ) { - return DruidEntity.DEFAULT_INTERVAL; - } - long start = range.hasLowerBound() - ? range.lowerEndpoint().longValue() - : DruidEntity.DEFAULT_INTERVAL.getStartMillis(); - long end = range.hasUpperBound() - ? range.upperEndpoint().longValue() - : DruidEntity.DEFAULT_INTERVAL.getEndMillis(); - if ( range.hasLowerBound() && range.lowerBoundType() == BoundType.OPEN ) { - start++; - } - if ( range.hasUpperBound() && range.upperBoundType() == BoundType.CLOSED ) { - end++; - } - return new Interval( start, end, ISOChronology.getInstanceUTC() ); - } ); - if ( LOGGER.isDebugEnabled() ) { - LOGGER.debug( "Converted time ranges {} to interval {}", ranges, intervals ); - } - return intervals; - } - - - @Nullable - protected static List> extractRanges( RexNode node, boolean withNot ) { - switch ( node.getKind() ) { - case EQUALS: - case LESS_THAN: - case LESS_THAN_OR_EQUAL: - case GREATER_THAN: - case GREATER_THAN_OR_EQUAL: - case BETWEEN: - case IN: - return leafToRanges( (RexCall) node, withNot ); - - case NOT: - return extractRanges( ((RexCall) node).getOperands().get( 0 ), !withNot ); - - case OR: { - RexCall call = (RexCall) node; - List> intervals = new ArrayList<>(); - for ( RexNode child : call.getOperands() ) { - List> extracted = - extractRanges( child, withNot ); - if ( extracted != null ) { - intervals.addAll( extracted ); - } - } - return intervals; - } - - case AND: { - RexCall call = (RexCall) node; - List> ranges = new ArrayList<>(); - for ( RexNode child : call.getOperands() ) { - List> extractedRanges = extractRanges( child, false ); - if ( extractedRanges == null || extractedRanges.isEmpty() ) { - // We could not extract, we bail out - return null; - } - if ( ranges.isEmpty() ) { - ranges.addAll( extractedRanges ); - continue; - } - List> overlapped = new ArrayList<>(); - for ( Range current : ranges ) { - for ( Range interval : extractedRanges ) { - if ( current.isConnected( interval ) ) { - overlapped.add( current.intersection( interval ) ); - } - } - } - ranges = overlapped; - } - return ranges; - } - - default: - return null; - } - } - - - @Nullable - protected static List> leafToRanges( RexCall call, boolean withNot ) { - switch ( call.getKind() ) { - case EQUALS: - case LESS_THAN: - case LESS_THAN_OR_EQUAL: - case GREATER_THAN: - case GREATER_THAN_OR_EQUAL: { - final Long value; - Kind kind = call.getKind(); - if ( call.getOperands().get( 0 ) instanceof RexInputRef && literalValue( call.getOperands().get( 1 ) ) != null ) { - value = literalValue( call.getOperands().get( 1 ) ); - } else if ( call.getOperands().get( 1 ) instanceof RexInputRef && literalValue( call.getOperands().get( 0 ) ) != null ) { - value = literalValue( call.getOperands().get( 0 ) ); - kind = kind.reverse(); - } else { - return null; - } - switch ( kind ) { - case LESS_THAN: - return ImmutableList.of( withNot ? Range.atLeast( value ) : Range.lessThan( value ) ); - case LESS_THAN_OR_EQUAL: - return ImmutableList.of( withNot ? Range.greaterThan( value ) : Range.atMost( value ) ); - case GREATER_THAN: - return ImmutableList.of( withNot ? Range.atMost( value ) : Range.greaterThan( value ) ); - case GREATER_THAN_OR_EQUAL: - return ImmutableList.of( withNot ? Range.lessThan( value ) : Range.atLeast( value ) ); - default: - if ( !withNot ) { - return ImmutableList.of( Range.closed( value, value ) ); - } - return ImmutableList.of( Range.lessThan( value ), Range.greaterThan( value ) ); - } - } - case BETWEEN: { - final Long value1; - final Long value2; - if ( literalValue( call.getOperands().get( 2 ) ) != null && literalValue( call.getOperands().get( 3 ) ) != null ) { - value1 = literalValue( call.getOperands().get( 2 ) ); - value2 = literalValue( call.getOperands().get( 3 ) ); - } else { - return null; - } - - boolean inverted = value1.compareTo( value2 ) > 0; - if ( !withNot ) { - return ImmutableList.of( inverted ? Range.closed( value2, value1 ) : Range.closed( value1, value2 ) ); - } - return ImmutableList.of( Range.lessThan( inverted ? value2 : value1 ), Range.greaterThan( inverted ? value1 : value2 ) ); - } - case IN: { - ImmutableList.Builder> ranges = - ImmutableList.builder(); - for ( RexNode operand : Util.skip( call.operands ) ) { - final Long element = literalValue( operand ); - if ( element == null ) { - return null; - } - if ( withNot ) { - ranges.add( Range.lessThan( element ) ); - ranges.add( Range.greaterThan( element ) ); - } else { - ranges.add( Range.closed( element, element ) ); - } - } - return ranges.build(); - } - default: - return null; - } - } - - - /** - * Returns the literal value for the given node, assuming it is a literal with datetime type, or a cast that only alters nullability on top of a literal with datetime type. - */ - @Nullable - protected static Long literalValue( RexNode node ) { - switch ( node.getKind() ) { - case LITERAL: - switch ( ((RexLiteral) node).getTypeName() ) { - case TIMESTAMP: - case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - TimestampString tsVal = ((RexLiteral) node).getValueAs( TimestampString.class ); - if ( tsVal == null ) { - return null; - } - return tsVal.getMillisSinceEpoch(); - case DATE: - DateString dateVal = ((RexLiteral) node).getValueAs( DateString.class ); - if ( dateVal == null ) { - return null; - } - return dateVal.getMillisSinceEpoch(); - } - break; - case CAST: - // Normally all CASTs are eliminated by now by constant reduction. But when HiveExecutor is used there may be a cast that changes only nullability, from TIMESTAMP NOT NULL literal to TIMESTAMP literal. - // We can handle that case by traversing the dummy CAST. - assert node instanceof RexCall; - final RexCall call = (RexCall) node; - final RexNode operand = call.getOperands().get( 0 ); - final AlgDataType callType = call.getType(); - final AlgDataType operandType = operand.getType(); - if ( operand.getKind() == Kind.LITERAL - && callType.getPolyType() == operandType.getPolyType() - && (callType.getPolyType() == PolyType.DATE - || callType.getPolyType() == PolyType.TIMESTAMP - || callType.getPolyType() == PolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE) - && callType.isNullable() - && !operandType.isNullable() ) { - return literalValue( operand ); - } - } - return null; - } - - - /** - * Infers granularity from a time unit. It supports {@code FLOOR(