diff --git a/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java b/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java index 13c2940f4f..a365e47770 100644 --- a/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/DocumentScanDelegate.java @@ -44,14 +44,8 @@ public DocumentScanDelegate( Scannable scannable, DocStoreCatalog catalog ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - scannable.createTable( context, logical, allocation ); - } - - - @Override - public List refreshTable( long allocId ) { - return scannable.refreshTable( allocId ); + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + return scannable.createTable( context, logical, allocation ); } @@ -61,23 +55,12 @@ public void restoreTable( AllocationTable alloc, List entities ) } - @Override - public List refreshGraph( long allocId ) { - return Scannable.refreshGraphSubstitute( scannable, allocId ); - } - - @Override public void restoreGraph( AllocationGraph alloc, List entities ) { Scannable.restoreGraphSubstitute( scannable, alloc, entities ); } - @Override - public List refreshCollection( long allocId ) { - return scannable.refreshCollection( allocId ); - } - @Override public void restoreCollection( AllocationCollection alloc, List entities ) { @@ -92,8 +75,8 @@ public void dropTable( Context context, long allocId ) { @Override - public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { - Scannable.createGraphSubstitute( scannable, context, logical, allocation ); + public List createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { + return Scannable.createGraphSubstitute( scannable, context, logical, allocation ); } @@ -104,8 +87,8 @@ public void dropGraph( Context context, AllocationGraph allocation ) { @Override - public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { - scannable.createCollection( context, logical, allocation ); + public List createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { + return scannable.createCollection( context, logical, allocation ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java b/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java index 272026a4da..7fd4a5eb76 100644 --- a/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java @@ -43,41 +43,22 @@ public GraphScanDelegate( Scannable scannable, GraphStoreCatalog catalog ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - scannable.createTable( context, logical, allocation ); + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + return scannable.createTable( context, logical, allocation ); } - - @Override - public List refreshTable( long allocId ) { - return scannable.refreshTable( allocId ); - } - - @Override public void restoreTable( AllocationTable alloc, List entities ) { scannable.restoreTable( alloc, entities ); } - @Override - public List refreshGraph( long allocId ) { - return scannable.refreshGraph( allocId ); - } - - @Override public void restoreGraph( AllocationGraph alloc, List entities ) { scannable.restoreGraph( alloc, entities ); } - @Override - public List refreshCollection( long allocId ) { - return Scannable.refreshCollectionSubstitution( scannable, allocId ); - } - - @Override public void restoreCollection( AllocationCollection alloc, List entities ) { Scannable.restoreCollectionSubstitute( scannable, alloc, entities ); @@ -91,8 +72,8 @@ public void dropTable( Context context, long allocId ) { @Override - public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { - scannable.createGraph( context, logical, allocation ); + public List createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { + return scannable.createGraph( context, logical, allocation ); } @@ -103,8 +84,8 @@ public void dropGraph( Context context, AllocationGraph allocation ) { @Override - public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { - Scannable.createCollectionSubstitute( scannable, context, logical, allocation ); + public List createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { + return Scannable.createCollectionSubstitute( scannable, context, logical, allocation ); } 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 aa2671633a..fb4ac5e5e0 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java @@ -90,7 +90,7 @@ static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provi throw new GenericRuntimeException( "Graph insert of non-graph elements is not possible." ); } } - AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) ); + AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) ); LogicalLpgTransformer transformer = new LogicalLpgTransformer( alg.getCluster(), alg.getTraitSet(), inputs, updateRowType, sequence, Modify.Operation.UPDATE ); return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), project, transformer ); @@ -111,7 +111,7 @@ static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provi throw new GenericRuntimeException( "Graph delete of non-graph elements is not possible." ); } } - AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) ); + AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) ); LogicalLpgTransformer transformer = new LogicalLpgTransformer( alg.getCluster(), alg.getTraitSet(), inputs, updateRowType, sequence, Modify.Operation.DELETE ); return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), project, transformer ); @@ -160,7 +160,7 @@ static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode pro throw new RuntimeException( "Graph insert of non-graph elements is not possible." ); } } - AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) ); + AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) ); LogicalLpgTransformer transformer = new LogicalLpgTransformer( alg.getCluster(), alg.getTraitSet(), inputs, updateRowType, sequence, Modify.Operation.INSERT ); return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), provider, transformer ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/RelationalModifyDelegate.java b/core/src/main/java/org/polypheny/db/adapter/RelationalModifyDelegate.java index 24afcc7022..7f4c5aaf71 100644 --- a/core/src/main/java/org/polypheny/db/adapter/RelationalModifyDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/RelationalModifyDelegate.java @@ -31,6 +31,7 @@ import org.polypheny.db.catalog.entity.logical.LogicalGraph; import org.polypheny.db.catalog.entity.logical.LogicalIndex; import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper; +import org.polypheny.db.catalog.entity.physical.PhysicalEntity; import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.prepare.Context; import org.polypheny.db.tools.AlgBuilder; @@ -92,14 +93,14 @@ public void updateColumnType( Context context, long allocId, LogicalColumn colum @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - modifiable.createTable( context, logical, allocation ); + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + return modifiable.createTable( context, logical, allocation ); } @Override - public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { - Scannable.createGraphSubstitute( modifiable, context, logical, allocation ); + public List createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { + return Scannable.createGraphSubstitute( modifiable, context, logical, allocation ); } @@ -110,9 +111,11 @@ public void dropGraph( Context context, AllocationGraph allocation ) { @Override - public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { + public List createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { PhysicalTable physical = Scannable.createSubstitutionTable( modifiable, context, logical, allocation, "_doc_", List.of( Triple.of( DocumentType.DOCUMENT_ID, DocumentType.ID_SIZE, PolyType.VARBINARY ), Triple.of( DocumentType.DOCUMENT_DATA, DocumentType.DATA_SIZE, PolyType.VARBINARY ) ) ); catalog.addPhysical( allocation, physical ); + + return List.of( physical ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java b/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java index c44000d54a..d8996bf4db 100644 --- a/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java +++ b/core/src/main/java/org/polypheny/db/adapter/RelationalScanDelegate.java @@ -54,16 +54,11 @@ public AlgNode getDocumentScan( long allocId, AlgBuilder builder ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - scannable.createTable( context, logical, allocation ); + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + return scannable.createTable( context, logical, allocation ); } - @Override - public List refreshTable( long allocId ) { - return scannable.refreshTable( allocId ); - } - @Override public void restoreTable( AllocationTable alloc, List entities ) { @@ -71,24 +66,12 @@ public void restoreTable( AllocationTable alloc, List entities ) } - @Override - public List refreshGraph( long allocId ) { - return Scannable.refreshGraphSubstitute( scannable, allocId ); - } - - @Override public void restoreGraph( AllocationGraph alloc, List entities ) { Scannable.restoreGraphSubstitute( scannable, alloc, entities ); } - @Override - public List refreshCollection( long allocId ) { - return Scannable.refreshCollectionSubstitution( scannable, allocId ); - } - - @Override public void restoreCollection( AllocationCollection alloc, List entities ) { Scannable.restoreCollectionSubstitute( scannable, alloc, entities ); @@ -102,8 +85,8 @@ public void dropTable( Context context, long allocId ) { @Override - public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { - Scannable.createGraphSubstitute( scannable, context, logical, allocation ); + public List createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { + return Scannable.createGraphSubstitute( scannable, context, logical, allocation ); } @@ -114,8 +97,8 @@ public void dropGraph( Context context, AllocationGraph allocation ) { @Override - public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { - Scannable.createCollectionSubstitute( scannable, context, logical, allocation ); + public List createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { + return Scannable.createCollectionSubstitute( scannable, context, logical, allocation ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/Scannable.java b/core/src/main/java/org/polypheny/db/adapter/Scannable.java index 19a7cf445c..e0c219c01b 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Scannable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Scannable.java @@ -112,10 +112,12 @@ default AlgNode getDocumentScan( long allocId, AlgBuilder builder ) { return builder.documentScan( entity ).build(); } - default void createTable( Context context, LogicalTableWrapper logical, List allocations ) { + default List> createTable( Context context, LogicalTableWrapper logical, List allocations ) { + List> entities = new ArrayList<>(); for ( AllocationTableWrapper allocation : allocations ) { - createTable( context, logical, allocation ); + entities.add( createTable( context, logical, allocation ) ); } + return entities; } static AlgNode getDocumentScanSubstitute( Scannable scannable, long allocId, AlgBuilder builder ) { @@ -127,31 +129,12 @@ static AlgNode getDocumentScanSubstitute( Scannable scannable, long allocId, Alg return builder.build(); } - void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ); - - List refreshTable( long allocId ); + List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ); void restoreTable( AllocationTable alloc, List entities ); - List refreshGraph( long allocId ); - - static List refreshGraphSubstitute( Scannable scannable, long allocId ) { - List physicals = scannable.getCatalog().getPhysicalsFromAllocs( allocId ); - scannable.refreshTable( physicals.get( 0 ).allocationId ); - scannable.refreshTable( physicals.get( 1 ).allocationId ); - scannable.refreshTable( physicals.get( 2 ).allocationId ); - scannable.refreshTable( physicals.get( 3 ).allocationId ); - return physicals; - } - void restoreGraph( AllocationGraph alloc, List entities ); - List refreshCollection( long allocId ); - - static List refreshCollectionSubstitution( Scannable scannable, long allocId ) { - return scannable.refreshTable( scannable.getCatalog().getPhysicalsFromAllocs( allocId ).get( 0 ).allocationId ); - } - void restoreCollection( AllocationCollection alloc, List entities ); @@ -163,9 +146,9 @@ static List refreshCollectionSubstitution( Scannable scannable, * It comes with a substitution methods called by default and should be overwritten if the inheriting {@link DataStore} * support the LPG data model. */ - void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ); + List createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ); - static void createGraphSubstitute( Scannable scannable, Context context, LogicalGraph logical, AllocationGraph allocation ) { + static List createGraphSubstitute( Scannable scannable, Context context, LogicalGraph logical, AllocationGraph allocation ) { PhysicalTable node = createSubstitutionTable( scannable, context, logical, allocation, "_node_", List.of( Triple.of( "id", GraphType.ID_SIZE, PolyType.VARCHAR ), Triple.of( "label", GraphType.LABEL_SIZE, PolyType.VARCHAR ) ) ); @@ -187,6 +170,7 @@ static void createGraphSubstitute( Scannable scannable, Context context, Logical Triple.of( "value", GraphType.VALUE_SIZE, PolyType.VARCHAR ) ) ); scannable.getCatalog().addPhysical( allocation, node, nProperties, edge, eProperties ); + return List.of( node, nProperties, edge, eProperties ); } /** @@ -210,14 +194,15 @@ static void dropGraphSubstitute( Scannable scannable, Context context, Allocatio * It comes with a substitution methods called by default and should be overwritten if the inheriting {@link DataStore} * support the document data model natively. */ - void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ); + List createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ); - static void createCollectionSubstitute( Scannable scannable, Context context, LogicalCollection logical, AllocationCollection allocation ) { + static List createCollectionSubstitute( Scannable scannable, Context context, LogicalCollection logical, AllocationCollection allocation ) { PhysicalTable doc = createSubstitutionTable( scannable, context, logical, allocation, "_doc_", List.of( Triple.of( DocumentType.DOCUMENT_ID, DocumentType.DATA_SIZE, PolyType.VARCHAR ), Triple.of( DocumentType.DOCUMENT_DATA, DocumentType.DATA_SIZE, PolyType.VARCHAR ) ) ); scannable.getCatalog().addPhysical( allocation, doc ); + return List.of( doc ); } /** 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 75636b0682..f0aae36d58 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 @@ -347,7 +347,7 @@ public static AlgDataType deriveRowType( AlgDataTypeFactory typeFactory, final A name = base + "_" + i++; } containedNames.add( name ); - builder.add( name, null, booleanType ); + builder.add( null, name, null, booleanType ); } } for ( Ord aggCall : Ord.zip( aggCalls ) ) { @@ -363,7 +363,7 @@ public static AlgDataType deriveRowType( AlgDataTypeFactory typeFactory, final A name = base + "_" + i++; } containedNames.add( name ); - builder.add( name, null, aggCall.e.type ); + builder.add( null, name, null, aggCall.e.type ); } return builder.build(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/Collect.java b/core/src/main/java/org/polypheny/db/algebra/core/Collect.java index 1f996f360b..900dbb2562 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/Collect.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/Collect.java @@ -127,7 +127,7 @@ public static AlgDataType deriveCollectRowType( SingleAlg alg, String fieldName assert childType.isStruct(); final AlgDataTypeFactory typeFactory = alg.getCluster().getTypeFactory(); AlgDataType ret = PolyTypeUtil.createMultisetType( typeFactory, childType, false ); - ret = typeFactory.builder().add( fieldName, null, ret ).build(); + ret = typeFactory.builder().add( null, fieldName, null, ret ).build(); return typeFactory.createTypeWithNullability( ret, false ); } 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 4e9c8d5661..b63388d8e4 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 @@ -151,8 +151,8 @@ public static AlgDataType deriveUncollectRowType( AlgNode alg, boolean withOrdin for ( AlgDataTypeField field : fields ) { if ( field.getType() instanceof MapPolyType ) { - builder.add( UnnestOperator.MAP_KEY_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getKeyType() ); - builder.add( UnnestOperator.MAP_VALUE_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getValueType() ); + builder.add( null, UnnestOperator.MAP_KEY_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getKeyType() ); + builder.add( null, UnnestOperator.MAP_VALUE_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getValueType() ); } else { AlgDataType ret = field.getType().getComponentType(); assert null != ret; @@ -160,7 +160,7 @@ public static AlgDataType deriveUncollectRowType( AlgNode alg, boolean withOrdin builder.addAll( ret.getFieldList() ); } else { // Element type is not a record. It may be a scalar type, say "INTEGER". Wrap it in a struct type. - builder.add( CoreUtil.deriveAliasFromOrdinal( field.getIndex() ), null, ret ); + builder.add( null, CoreUtil.deriveAliasFromOrdinal( field.getIndex() ), null, ret ); } } } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgMatch.java b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgMatch.java index 875ba7a39c..03381c5c70 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgMatch.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgMatch.java @@ -61,7 +61,7 @@ protected AlgDataType deriveRowType() { int i = 0; for ( RexNode match : matches ) { - fields.add( new AlgDataTypeFieldImpl( names.get( i ).value, i, match.getType() ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, names.get( i ).value, i, match.getType() ) ); i++; } return new AlgRecordType( fields ); diff --git a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgProject.java b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgProject.java index 3457e7ca5e..0c135dd283 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgProject.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgProject.java @@ -74,7 +74,7 @@ protected AlgDataType deriveRowType() { int index = 0; for ( PolyString name : names ) { if ( name != null ) { - fields.add( new AlgDataTypeFieldImpl( name.value, index, projects.get( i ).getType() ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, name.value, index, projects.get( i ).getType() ) ); index++; } i++; 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 9593b30f4a..cf8b837b08 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 @@ -84,7 +84,7 @@ public String algCompareString() { @Override protected AlgDataType deriveRowType() { List fields = new ArrayList<>(); - fields.add( new AlgDataTypeFieldImpl( alias, 0, input.getRowType().getFieldList().get( index ).getType().getComponentType() ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, alias, 0, input.getRowType().getFieldList().get( index ).getType().getComponentType() ) ); return new AlgRecordType( fields ); } 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 bfe76e949e..03f23a817e 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 @@ -205,7 +205,7 @@ public String algCompareString() { "." + entity.id + "$" + (getInputs() != null ? getInputs().stream().map( AlgNode::algCompareString ).collect( Collectors.joining( "$" ) ) + "$" : "") + getOperation().name() + "$" + - (getUpdateColumnList() != null ? String.join( "$", getUpdateColumnList() ) + "$" : "") + + (getUpdateColumnList() != null ? getUpdateColumnList().stream().map( c -> "c" ).collect( Collectors.joining( "$" ) ) + "$" : "") + (getSourceExpressionList() != null ? getSourceExpressionList().stream().map( RexNode::hashCode ).map( Objects::toString ).collect( Collectors.joining( "$" ) ) : "") + "$" + isFlattened() + "&"; } 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 8cc63fc4ae..b6dc26ac4c 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 @@ -113,7 +113,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { null, Expressions.call( BuiltInMethod.AS_ENUMERABLE.method, - Expressions.newArrayInit( Primitive.box( rowClass ), expressions ) ) ) ); + Expressions.newArrayInit( Primitive.box( rowClass ), 2, expressions ) ) ) ); return implementor.result( physType, builder.toBlock() ); } 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 ef8b5ddd15..bfd7ad4e4f 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 @@ -219,7 +219,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { final Builder typeBuilder = typeFactory.builder(); typeBuilder.addAll( inputPhysType.getRowType().getFieldList() ); for ( AggImpState agg : aggs ) { - typeBuilder.add( agg.call.name, null, agg.call.type ); + typeBuilder.add( null, agg.call.name, null, agg.call.type ); } AlgDataType outputRowType = typeBuilder.build(); final PhysType outputPhysType = PhysTypeImpl.of( typeFactory, outputRowType, pref.prefer( result.format ) ); 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 8d1c2560e5..4329ac0876 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 @@ -83,7 +83,7 @@ public static PhysType of( JavaTypeFactory typeFactory, AlgDataType rowType, Jav if ( false && optimize ) { // we always want arrays format = format.optimize( rowType ); } - final Type javaRowClass = JavaRowFormat.ARRAY.javaRowClass( typeFactory, rowType );//format.javaRowClass( typeFactory, rowType ); + final Type javaRowClass = format.javaRowClass( typeFactory, rowType ); return new PhysTypeImpl( typeFactory, rowType, javaRowClass, format ); } @@ -93,7 +93,7 @@ static PhysType of( final JavaTypeFactory typeFactory, Type javaRowClass ) { if ( javaRowClass instanceof Types.RecordType ) { final Types.RecordType recordType = (Types.RecordType) javaRowClass; for ( Types.RecordField field : recordType.getRecordFields() ) { - builder.add( field.getName(), null, typeFactory.createType( field.getType() ) ); + builder.add( null, field.getName(), null, typeFactory.createType( field.getType() ) ); } } AlgDataType rowType = builder.build(); @@ -123,7 +123,7 @@ public PhysType project( List integers, boolean indicator, JavaRowForma if ( indicator ) { final AlgDataType booleanType = typeFactory.createTypeWithNullability( typeFactory.createPolyType( PolyType.BOOLEAN ), false ); for ( int index : integers ) { - builder.add( "i$" + rowType.getFieldList().get( index ).getName(), null, booleanType ); + builder.add( null, "i$" + rowType.getFieldList().get( index ).getName(), null, booleanType ); } } AlgDataType projectedRowType = builder.build(); @@ -456,7 +456,7 @@ private AlgDataType toStruct( AlgDataType type ) { return type; } return typeFactory.builder() - .add( CoreUtil.deriveAliasFromOrdinal( 0 ), null, type ) + .add( null, CoreUtil.deriveAliasFromOrdinal( 0 ), null, type ) .build(); } 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 0cdafd24c4..b6b821430f 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 @@ -221,7 +221,7 @@ public AlgDataType toType( AlgDataTypeFactory typeFactory, Object o ) { @SuppressWarnings("unchecked") final List> jsonList = (List>) o; final AlgDataTypeFactory.Builder builder = typeFactory.builder(); for ( Map jsonMap : jsonList ) { - builder.add( (String) jsonMap.get( "name" ), null, toType( typeFactory, jsonMap ) ); + builder.add( null, (String) jsonMap.get( "name" ), null, toType( typeFactory, jsonMap ) ); } return builder.build(); } else { 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 ab136ba2cb..ba48d707e5 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 @@ -37,6 +37,7 @@ import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.entity.CatalogEntity; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.volcano.AlgSubset; @@ -95,7 +96,7 @@ public static LogicalStreamer create( Modify allModify, AlgBuilder algBuilder private static LogicalStreamer getLogicalStreamer( RelModify modify, AlgBuilder algBuilder, RexBuilder rexBuilder, AlgNode input ) { if ( input == null ) { - throw new RuntimeException( "Error while creating Streamer." ); + throw new GenericRuntimeException( "Error while creating Streamer." ); } // add all previous variables e.g. _id, _data(previous), _data(updated) @@ -157,8 +158,7 @@ private static List createSourceList( RelModify modify, RexBuilder r .map( name -> { int size = modify.getRowType().getFieldList().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().getFieldList().get( index ).getType(), size + index ); } ).collect( Collectors.toList() ); } 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 320b53804a..ee3ec25a4d 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 @@ -96,12 +96,12 @@ public static LogicalLpgValues create( int i = 0; for ( PolyString name : Pair.left( nodes ).stream().filter( Objects::nonNull ).collect( Collectors.toList() ) ) { - fields.add( new AlgDataTypeFieldImpl( name.value, i, nodeType ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, name.value, i, nodeType ) ); i++; } for ( PolyString name : Pair.left( edges ).stream().filter( s -> s.value != null ).collect( Collectors.toList() ) ) { - fields.add( new AlgDataTypeFieldImpl( name.value, i, edgeType ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, name.value, i, edgeType ) ); i++; } 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 98bd1c9137..6ca2392344 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 @@ -50,6 +50,8 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.Window; import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.algebra.type.AlgDataTypeField; +import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptUtil; import org.polypheny.db.plan.AlgTraitSet; @@ -65,7 +67,6 @@ import org.polypheny.db.tools.AlgBuilder; import org.polypheny.db.util.ImmutableBitSet; import org.polypheny.db.util.Litmus; -import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; @@ -184,7 +185,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().getFieldList() ); final int offset = fieldList.size(); // Use better field names for agg calls that are projected. @@ -195,7 +196,7 @@ public RexNode visitLocalRef( RexLocalRef localRef ) { fieldNames.put( index - offset, outRowType.getFieldNames().get( ref.i ) ); } } - + int j = 0; for ( Ord window : Ord.zip( groups ) ) { for ( Ord over : Ord.zip( window.e.aggCalls ) ) { // Add the k-th over expression of the i-th window to the output of the program. @@ -203,7 +204,7 @@ public RexNode visitLocalRef( RexLocalRef localRef ) { if ( name == null || name.startsWith( "$" ) ) { name = "w" + window.i + "$o" + over.i; } - fieldList.add( Pair.of( name, over.e.getType() ) ); + fieldList.add( new AlgDataTypeFieldImpl( -1L, name, j++, over.e.getType() ) ); flattenedAggCallList.add( over.e ); } } 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 55539582c8..64a8b3c1ae 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 @@ -213,7 +213,7 @@ public void onMatch( AlgOptRuleCall call ) { for ( int i = 0; i < nProjExprs; i++ ) { projTypes.add( projects.get( i ).left.getType() ); } - AlgDataType projRowType = rexBuilder.getTypeFactory().createStructType( projTypes, Pair.right( projects ) ); + AlgDataType projRowType = rexBuilder.getTypeFactory().createStructType( null, projTypes, Pair.right( projects ) ); // create the RexPrograms and merge them RexProgram bottomProgram = 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 7a586f33bd..edf91d4c92 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 @@ -73,6 +73,8 @@ public interface AlgDataType { */ List getFieldNames(); + List getFieldIds(); + /** * Returns the number of fields in a struct type. 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 7021ee70ab..ae320fc088 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 @@ -87,35 +87,35 @@ public interface AlgDataTypeFactory { * Creates a type that represents a structured collection of fields, given lists of the names and types of the fields. * * @param kind Name resolution policy - * @param typeList types of the fields - * @param fieldNameList names of the fields + * @param types types of the fields + * @param fieldNames names of the fields * @return canonical struct type descriptor */ - AlgDataType createStructType( StructKind kind, List typeList, List fieldNameList ); + AlgDataType createStructType( StructKind kind, final List ids, List types, List fieldNames ); /** * Creates a type that represents a structured collection of fields, given lists of the names and types of the fields. * * @param kind Name resolution policy - * @param typeList types of the fields - * @param fieldNameList names of the fields - * @param physicalFieldNameList physical names of the fields + * @param types types of the fields + * @param fieldNames names of the fields + * @param physicalFieldNames physical names of the fields * @return canonical struct type descriptor */ - AlgDataType createStructType( StructKind kind, final List typeList, final List fieldNameList, final List physicalFieldNameList ); + AlgDataType createStructType( StructKind kind, final List ids, final List types, final List fieldNames, final List physicalFieldNames ); /** * Creates a type that represents a structured collection of fields. Shorthand for createStructType(StructKind.FULLY_QUALIFIED, typeList, fieldNameList). */ - AlgDataType createStructType( List typeList, List fieldNameList ); + AlgDataType createStructType( List ids, List types, List fieldNames ); /** * Creates a type that represents a structured collection of fieldList, obtaining the field information from a list of (name, type) pairs. * - * @param fieldList List of (name, type) pairs + * @param fields List of (name, type) pairs * @return canonical struct type descriptor */ - AlgDataType createStructType( List> fieldList ); + AlgDataType createStructType( List fields ); /** * Creates an array type. Arrays are ordered collections of elements. @@ -336,8 +336,8 @@ public FieldInfoBuilder( AlgDataTypeFactory typeFactory ) { @Override - public FieldInfoBuilder add( String name, String physicalName, AlgDataType type ) { - return (FieldInfoBuilder) super.add( name, physicalName, type ); + public FieldInfoBuilder add( Long id, String name, String physicalName, AlgDataType type ) { + return (FieldInfoBuilder) super.add( id, name, physicalName, type ); } @@ -405,6 +405,7 @@ class Builder { private final List names = new ArrayList<>(); private final List physicalNames = new ArrayList<>(); private final List types = new ArrayList<>(); + private final List ids = new ArrayList<>(); private StructKind kind = StructKind.FULLY_QUALIFIED; private final AlgDataTypeFactory typeFactory; @@ -463,7 +464,8 @@ public AlgDataType getFieldType( int index ) { /** * Adds a field with given name and type. */ - public Builder add( String name, String physicalName, AlgDataType type ) { + public Builder add( Long id, String name, String physicalName, AlgDataType type ) { + ids.add( id ); names.add( name ); physicalNames.add( physicalName ); types.add( type ); @@ -475,7 +477,7 @@ public Builder add( String name, String physicalName, AlgDataType type ) { * Adds a field with a type created using {@link AlgDataTypeFactory#createPolyType(PolyType)}. */ public Builder add( String name, String physicalName, PolyType typeName ) { - add( name, physicalName, typeFactory.createPolyType( typeName ) ); + add( null, name, physicalName, typeFactory.createPolyType( typeName ) ); return this; } @@ -484,7 +486,7 @@ public Builder add( String name, String physicalName, PolyType typeName ) { * Adds a field with a type created using {@link AlgDataTypeFactory#createPolyType(PolyType, int)}. */ public Builder add( String name, String physicalName, PolyType typeName, int precision ) { - add( name, physicalName, typeFactory.createPolyType( typeName, precision ) ); + add( null, name, physicalName, typeFactory.createPolyType( typeName, precision ) ); return this; } @@ -493,7 +495,7 @@ public Builder add( String name, String physicalName, PolyType typeName, int pre * Adds a field with a type created using {@link AlgDataTypeFactory#createPolyType(PolyType, int, int)}. */ public Builder add( String name, String physicalName, PolyType typeName, int precision, int scale ) { - add( name, physicalName, typeFactory.createPolyType( typeName, precision, scale ) ); + add( null, name, physicalName, typeFactory.createPolyType( typeName, precision, scale ) ); return this; } @@ -517,7 +519,7 @@ public Builder nullable( boolean nullable ) { * Adds a field. Field's ordinal is ignored. */ public Builder add( AlgDataTypeField field ) { - add( field.getName(), field.getPhysicalName(), field.getType() ); + add( null, field.getName(), field.getPhysicalName(), field.getType() ); return this; } @@ -528,7 +530,7 @@ public Builder add( AlgDataTypeField field ) { public Builder addAll( Iterable> fields ) { for ( Map.Entry field : fields ) { // TODO MV: Adding null for physical name - add( field.getKey(), null, field.getValue() ); + add( null, field.getKey(), null, field.getValue() ); } return this; } @@ -557,7 +559,7 @@ public Builder uniquify() { * Creates a struct type with the current contents of this builder. */ public AlgDataType build() { - return typeFactory.createStructType( kind, types, names, physicalNames ); + return typeFactory.createStructType( kind, ids, types, names, physicalNames ); } 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 da1fe1c876..bac62cfa1d 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 @@ -49,6 +49,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.apache.calcite.linq4j.tree.Primitive; import org.polypheny.db.type.ArrayType; @@ -82,7 +83,7 @@ private static AlgDataType keyToType( @Nonnull Object k ) { final Key key = (Key) k; final ImmutableList.Builder list = ImmutableList.builder(); for ( int i = 0; i < key.names.size(); i++ ) { - list.add( new AlgDataTypeFieldImpl( key.names.get( i ), key.physicalNames.get( i ), i, key.types.get( i ) ) ); + list.add( new AlgDataTypeFieldImpl( key.ids.get( i ), key.names.get( i ), key.physicalNames.get( i ), i, key.types.get( i ) ) ); } return new AlgRecordType( key.kind, list.build() ); } @@ -151,66 +152,33 @@ public AlgDataType createJoinType( AlgDataType... types ) { @Override - public AlgDataType createStructType( final List typeList, final List fieldNameList ) { - return createStructType( StructKind.FULLY_QUALIFIED, typeList, fieldNameList ); + public AlgDataType createStructType( List ids, final List types, final List fieldNames ) { + return createStructType( StructKind.FULLY_QUALIFIED, ids, types, fieldNames ); } @Override - public AlgDataType createStructType( StructKind kind, final List typeList, final List fieldNameList ) { - return createStructType( kind, typeList, fieldNameList, ImmutableList.copyOf( fieldNameList ) ); + public AlgDataType createStructType( StructKind kind, final List ids, final List types, final List fieldNames ) { + return createStructType( kind, ids, types, fieldNames, ImmutableList.copyOf( fieldNames ) ); } @Override - public AlgDataType createStructType( StructKind kind, final List typeList, final List fieldNameList, final List physicalFieldNameList ) { - assert typeList.size() == fieldNameList.size(); - assert typeList.size() == physicalFieldNameList.size(); - return canonize( kind, fieldNameList, physicalFieldNameList, typeList ); + public AlgDataType createStructType( StructKind kind, final List ids, final List types, final List fieldNames, final List physicalFieldNames ) { + assert types.size() == fieldNames.size(); + assert types.size() == physicalFieldNames.size(); + return canonize( kind, ids, fieldNames, physicalFieldNames, types ); } @Override - public final AlgDataType createStructType( final List> fieldList ) { + public final AlgDataType createStructType( final List fields ) { return canonize( StructKind.FULLY_QUALIFIED, - new AbstractList<>() { - @Override - public String get( int index ) { - return fieldList.get( index ).getKey(); - } - - - @Override - public int size() { - return fieldList.size(); - } - }, - // TODO MV: Using the logical names here might be wrong - new AbstractList<>() { - @Override - public String get( int index ) { - return fieldList.get( index ).getKey(); - } - - - @Override - public int size() { - return fieldList.size(); - } - }, - new AbstractList<>() { - @Override - public AlgDataType get( int index ) { - return fieldList.get( index ).getValue(); - } - - - @Override - public int size() { - return fieldList.size(); - } - } ); + fields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + fields.stream().map( AlgDataTypeField::getName ).collect( Collectors.toList() ), + fields.stream().map( AlgDataTypeField::getPhysicalName ).collect( Collectors.toList() ), + fields.stream().map( AlgDataTypeField::getType ).collect( Collectors.toList() ) ); } @@ -246,7 +214,7 @@ protected AlgDataType leastRestrictiveStructuredType( final List ty // REVIEW jvs: Always use the field name from the first type? final int k = j; builder.add( - type0.getFieldList().get( j ).getName(), + null, type0.getFieldList().get( j ).getName(), null, leastRestrictive( new AbstractList<>() { @@ -294,23 +262,14 @@ private AlgDataType copyRecordType( final AlgRecordType type, final boolean igno return createStructType( type.getStructKind(), - new AbstractList<>() { - @Override - public AlgDataType get( int index ) { - AlgDataType fieldType = type.getFieldList().get( index ).getType(); - if ( ignoreNullable ) { - return copyType( fieldType ); - } else { - return createTypeWithNullability( fieldType, nullable ); - } - } - - - @Override - public int size() { - return type.getFieldCount(); + type.getFieldList().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + type.getFieldList().stream().map( f -> { + if ( ignoreNullable ) { + return copyType( f.getType() ); + } else { + return createTypeWithNullability( f.getType(), nullable ); } - }, + } ).collect( Collectors.toList() ), type.getFieldNames(), type.getPhysicalFieldNames() ); } @@ -374,7 +333,7 @@ protected AlgDataType canonize( final AlgDataType type ) { *

* This approach allows us to use a cheap temporary key. A permanent key is more expensive, because it must be immutable and not hold references into other data structures. */ - protected AlgDataType canonize( final StructKind kind, final List names, final List physicalNames, final List types ) { + protected AlgDataType canonize( final StructKind kind, final List ids, final List names, final List physicalNames, final List types ) { // skip canonize step for ArrayTypes, to not cache cardinality or dimension boolean skipCache = false; for ( AlgDataType t : types ) { @@ -389,19 +348,19 @@ protected AlgDataType canonize( final StructKind kind, final List names, } if ( !skipCache ) { - final AlgDataType type = CACHE.getIfPresent( new Key( kind, names, physicalNames, types ) ); + final AlgDataType type = CACHE.getIfPresent( new Key( kind, ids, names, physicalNames, types ) ); if ( type != null ) { return type; } } final ImmutableList names2 = ImmutableList.copyOf( names ); - final List physicalNames2 = physicalNames; final ImmutableList types2 = ImmutableList.copyOf( types ); + final List ids2 = new ArrayList<>( ids ); if ( skipCache ) { - return keyToType( new Key( kind, names2, physicalNames2, types2 ) ); + return keyToType( new Key( kind, ids2, names2, physicalNames, types2 ) ); } else { - return CACHE.getUnchecked( new Key( kind, names2, physicalNames2, types2 ) ); + return CACHE.getUnchecked( new Key( kind, ids2, names2, physicalNames, types2 ) ); } } @@ -445,7 +404,7 @@ private static void addFields( AlgDataType type, List fieldLis List fields = type.getFieldList(); for ( AlgDataTypeField field : fields ) { if ( field.getIndex() != fieldList.size() ) { - field = new AlgDataTypeFieldImpl( field.getName(), fieldList.size(), field.getType() ); + field = new AlgDataTypeFieldImpl( field.getId(), field.getName(), fieldList.size(), field.getType() ); } fieldList.add( field ); } @@ -464,7 +423,7 @@ private List fieldsOf( Class clazz ) { if ( Modifier.isStatic( field.getModifiers() ) ) { continue; } - list.add( new AlgDataTypeFieldImpl( field.getName(), list.size(), createJavaType( field.getType() ) ) ); + list.add( new AlgDataTypeFieldImpl( null, field.getName(), list.size(), createJavaType( field.getType() ) ) ); } if ( list.isEmpty() ) { @@ -701,10 +660,12 @@ private static class Key { private final List names; private final List physicalNames; private final List types; + private final List ids; - Key( StructKind kind, List names, List physicalNames, List types ) { + Key( StructKind kind, List ids, List names, List physicalNames, List types ) { this.kind = kind; + this.ids = ids; this.names = names; this.physicalNames = physicalNames; this.types = types; @@ -721,6 +682,7 @@ public int hashCode() { public boolean equals( Object obj ) { return obj == this || obj instanceof Key + && ids == ((Key) obj).ids && kind == ((Key) obj).kind && names.equals( ((Key) obj).names ) && physicalNames.equals( ((Key) obj).physicalNames ) diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java index fa9d071fb5..614ba66704 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeField.java @@ -67,6 +67,8 @@ public interface AlgDataTypeField extends Map.Entry { */ int getIndex(); + Long getId(); + /** * Gets the type of this field. * diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java index abf3654bb3..9f5583ab19 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeFieldImpl.java @@ -35,31 +35,35 @@ import java.io.Serializable; +import lombok.Value; import org.polypheny.db.type.PolyType; /** * Default implementation of {@link AlgDataTypeField}. */ +@Value public class AlgDataTypeFieldImpl implements AlgDataTypeField, Serializable { - private final AlgDataType type; - private final String name; - private final String physicalName; - private final int index; + AlgDataType type; + String name; + String physicalName; + int index; + Long id; /** * Creates a RelDataTypeFieldImpl. */ - public AlgDataTypeFieldImpl( String name, int index, AlgDataType type ) { - this( name, null, index, type ); + public AlgDataTypeFieldImpl( Long id, String name, int index, AlgDataType type ) { + this( id, name, null, index, type ); } - public AlgDataTypeFieldImpl( String name, String physicalName, int index, AlgDataType type ) { + public AlgDataTypeFieldImpl( Long id, String name, String physicalName, int index, AlgDataType type ) { assert name != null; assert type != null; + this.id = id; this.name = name; this.index = index; this.type = type; diff --git a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java index 538294de7a..8f59746412 100644 --- a/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java +++ b/core/src/main/java/org/polypheny/db/algebra/type/AlgDataTypeHolder.java @@ -91,6 +91,7 @@ Pair getFieldOrInsert( String fieldName, boolean case // This field does not exist in our field list; add it AlgDataTypeField newField = new AlgDataTypeFieldImpl( + -1L, fieldName, fields.size(), typeFactory.createTypeWithNullability( typeFactory.createPolyType( typeName ), true ) ); 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 6593a9bc04..d873fb0bc3 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 @@ -40,6 +40,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.polypheny.db.nodes.IntervalQualifier; import org.polypheny.db.type.BasicPolyType; import org.polypheny.db.type.PolyType; @@ -56,6 +57,7 @@ public abstract class AlgDataTypeImpl implements AlgDataType, AlgDataTypeFamily { protected final List fieldList; + private final List ids; protected String digest; @@ -68,8 +70,10 @@ protected AlgDataTypeImpl( List fieldList ) { if ( fieldList != null ) { // Create a defensive copy of the list. this.fieldList = ImmutableList.copyOf( fieldList ); + this.ids = fieldList.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ); } else { this.fieldList = null; + this.ids = null; } } @@ -108,10 +112,10 @@ public AlgDataTypeField getField( String fieldName, boolean caseSensitive, boole } } // Extra field - if ( fieldList.size() > 0 ) { + if ( !fieldList.isEmpty() ) { final AlgDataTypeField lastField = Iterables.getLast( fieldList ); if ( lastField.getName().equals( "_extra" ) ) { - return new AlgDataTypeFieldImpl( fieldName, -1, lastField.getType() ); + return new AlgDataTypeFieldImpl( lastField.getId(), fieldName, -1, lastField.getType() ); } } @@ -162,6 +166,12 @@ public List getFieldNames() { } + @Override + public List getFieldIds() { + return ids; + } + + public List getPhysicalFieldNames() { // TODO MV: Is there a more efficient way for doing this? List l = new ArrayList<>(); 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 1474b170f6..65c330b902 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 @@ -59,25 +59,25 @@ public DocumentType() { public DocumentType( List ids, List names ) { - this( Streams.mapWithIndex( Pair.zip( ids, names ).stream(), ( p, i ) -> new AlgDataTypeFieldImpl( p.getRight(), (int) i, p.getLeft().getType() ) ).collect( Collectors.toList() ) ); + this( Streams.mapWithIndex( Pair.zip( ids, names ).stream(), ( p, i ) -> new AlgDataTypeFieldImpl( -1L, p.getRight(), (int) i, p.getLeft().getType() ) ).collect( Collectors.toList() ) ); } public static DocumentType ofId() { - return new DocumentType( List.of( new AlgDataTypeFieldImpl( DOCUMENT_ID, 0, new DocumentType( List.of() ) ) ) ); + return new DocumentType( List.of( new AlgDataTypeFieldImpl( -1L, DOCUMENT_ID, 0, new DocumentType( List.of() ) ) ) ); } public static AlgDataType asRelational() { return new AlgRecordType( List.of( - new AlgDataTypeFieldImpl( DOCUMENT_ID, 0, AlgDataTypeFactory.DEFAULT.createPolyType( PolyType.VARBINARY, 2024 ) ), - new AlgDataTypeFieldImpl( DOCUMENT_DATA, 1, AlgDataTypeFactory.DEFAULT.createPolyType( PolyType.VARBINARY, 2024 ) ) + new AlgDataTypeFieldImpl( -1L, DOCUMENT_ID, 0, AlgDataTypeFactory.DEFAULT.createPolyType( PolyType.VARBINARY, 2024 ) ), + new AlgDataTypeFieldImpl( -1L, DOCUMENT_DATA, 1, AlgDataTypeFactory.DEFAULT.createPolyType( PolyType.VARBINARY, 2024 ) ) ) ); } public static AlgDataType ofDoc() { - return new DocumentType( List.of( new AlgDataTypeFieldImpl( "d", 0, DocumentType.ofId() ) ) ); + return new DocumentType( List.of( new AlgDataTypeFieldImpl( -1L, "d", 0, DocumentType.ofId() ) ) ); } @@ -106,6 +106,12 @@ public List getFieldNames() { } + @Override + public List getFieldIds() { + return fixedFields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ); + } + + @Override public int getFieldCount() { return getFieldList().size(); @@ -119,7 +125,7 @@ public AlgDataTypeField getField( String fieldName, boolean caseSensitive, boole if ( index >= 0 ) { return getFieldList().get( index ); } - AlgDataTypeFieldImpl added = new AlgDataTypeFieldImpl( fieldName, getFieldCount(), new DocumentType() ); + AlgDataTypeFieldImpl added = new AlgDataTypeFieldImpl( -1L, fieldName, getFieldCount(), new DocumentType() ); fixedFields.add( added ); computeDigest(); 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 a00547439b..9a308a2a8d 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 @@ -46,7 +46,7 @@ public GraphType( List fixedFields ) { public static GraphType of() { - return new GraphType( List.of( new AlgDataTypeFieldImpl( GRAPH_ID, 0, AlgDataTypeFactory.DEFAULT.createPolyType( PolyType.CHAR, 255 ) ) ) ); + return new GraphType( List.of( new AlgDataTypeFieldImpl( -1L, GRAPH_ID, 0, AlgDataTypeFactory.DEFAULT.createPolyType( PolyType.CHAR, 255 ) ) ) ); } @@ -75,6 +75,12 @@ public List getFieldNames() { } + @Override + public List getFieldIds() { + return fixedFields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ); + } + + @Override public int getFieldCount() { return fixedFields.size(); diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java index 7e151e2d62..a2baa7a83a 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/DocStoreCatalog.java @@ -143,7 +143,7 @@ public PhysicalTable createTable( List columns = wrapper.columns; List pColumns = columns.stream().map( c -> new PhysicalColumn( columnNames.get( c.columnId ), logical.id, allocation.id, allocation.adapterId, c.position, logicalColumns.get( c.columnId ) ) ).collect( Collectors.toList() ); long physicalId = IdBuilder.getInstance().getNewPhysicalId(); - PhysicalTable table = new PhysicalTable( physicalId, allocation.id, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId ); + PhysicalTable table = new PhysicalTable( physicalId, allocation.id, allocation.logicalId, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId ); pColumns.forEach( this::addColumn ); addPhysical( allocation, table ); return table; @@ -152,7 +152,7 @@ public PhysicalTable createTable( public PhysicalCollection createCollection( String namespaceName, String name, LogicalCollection logical, AllocationCollection allocation ) { long physicalId = IdBuilder.getInstance().getNewPhysicalId(); - PhysicalCollection collection = new PhysicalCollection( physicalId, allocation.id, logical.namespaceId, name, namespaceName, adapterId ); + PhysicalCollection collection = new PhysicalCollection( physicalId, allocation.id, logical.id, logical.namespaceId, name, namespaceName, adapterId ); addPhysical( allocation, collection ); return collection; } diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java index 977c6854a1..8599756c4d 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/GraphStoreCatalog.java @@ -85,7 +85,7 @@ public PhysicalTable createTable( List columns = wrapper.columns; List pColumns = columns.stream().map( c -> new PhysicalColumn( columnNames.get( c.columnId ), logical.id, allocation.id, allocation.adapterId, c.position, logicalColumns.get( c.columnId ) ) ).collect( Collectors.toList() ); long physicalId = IdBuilder.getInstance().getNewPhysicalId(); - PhysicalTable table = new PhysicalTable( physicalId, allocation.id, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId ); + PhysicalTable table = new PhysicalTable( physicalId, allocation.id, logical.id, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId ); pColumns.forEach( this::addColumn ); addPhysical( allocation, table ); return table; @@ -102,7 +102,7 @@ public PhysicalGraph createGraph( LogicalGraph logical, AllocationGraph allocation ) { long physicalId = IdBuilder.getInstance().getNewPhysicalId(); - PhysicalGraph physical = new PhysicalGraph( physicalId, allocation.id, name, adapterId ); + PhysicalGraph physical = new PhysicalGraph( physicalId, allocation.id, logical.id, name, adapterId ); addPhysical( allocation, physical ); return physical; } diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java index 9de6b7c37e..6a83cd4ff2 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/RelStoreCatalog.java @@ -93,7 +93,7 @@ public PhysicalTable createTable( String namespaceName, String tableName, Map columns = wrapper.columns; List pColumns = columns.stream().map( c -> new PhysicalColumn( columnNames.get( c.columnId ), logical.id, allocation.id, allocation.adapterId, c.position, lColumns.get( c.columnId ) ) ).collect( Collectors.toList() ); - PhysicalTable table = new PhysicalTable( IdBuilder.getInstance().getNewPhysicalId(), allocation.id, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId ); + PhysicalTable table = new PhysicalTable( IdBuilder.getInstance().getNewPhysicalId(), allocation.id, allocation.logicalId, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId ); pColumns.forEach( this::addColumn ); addPhysical( allocation, table ); return table; 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 c8c1e7a1e9..34e32a4078 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 @@ -58,7 +58,7 @@ public AlgDataType getRowType() { for ( AllocationColumn column : getColumns().stream().sorted( Comparator.comparingInt( a -> a.position ) ).collect( Collectors.toList() ) ) { LogicalColumn lColumn = Catalog.snapshot().rel().getColumn( column.columnId ).orElseThrow(); AlgDataType sqlType = column.getAlgDataType(); - fieldInfo.add( lColumn.name, null, sqlType ).nullable( lColumn.nullable ); + fieldInfo.add( column.columnId, lColumn.name, lColumn.name, sqlType ).nullable( lColumn.nullable ); } return AlgDataTypeImpl.proto( fieldInfo.build() ).apply( AlgDataTypeFactory.DEFAULT ); diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java index 0f1bf3684e..8ef222c6a5 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java @@ -36,6 +36,7 @@ import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.algebra.type.AlgDataTypeImpl; import org.polypheny.db.catalog.Catalog; +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.schema.ColumnStrategy; @@ -48,7 +49,6 @@ public class LogicalTable extends LogicalEntity { private static final long serialVersionUID = 4653390333258552102L; - @Serialize @SerializeNullable public Long primaryKey; @@ -64,7 +64,7 @@ public LogicalTable( this.primaryKey = primaryKey; if ( type == EntityType.ENTITY && !modifiable ) { - throw new RuntimeException( "Tables of table type TABLE must be modifiable!" ); + throw new GenericRuntimeException( "Tables of table type TABLE must be modifiable!" ); } } @@ -96,7 +96,7 @@ public AlgDataType getRowType() { for ( LogicalColumn column : Catalog.getInstance().getSnapshot().rel().getColumns( id ).stream().sorted( Comparator.comparingInt( a -> a.position ) ).collect( Collectors.toList() ) ) { AlgDataType sqlType = column.getAlgDataType( AlgDataTypeFactory.DEFAULT ); - fieldInfo.add( column.name, null, sqlType ).nullable( column.nullable ); + fieldInfo.add( column.id, column.name, null, sqlType ).nullable( column.nullable ); } return AlgDataTypeImpl.proto( fieldInfo.build() ).apply( AlgDataTypeFactory.DEFAULT ); diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalCollection.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalCollection.java index cf685ffba0..7c22994732 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalCollection.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalCollection.java @@ -34,11 +34,12 @@ public class PhysicalCollection extends PhysicalEntity { public PhysicalCollection( @Deserialize("id") long id, @Deserialize("allocationId") long allocationId, + @Deserialize("logicalId") long logicalId, @Deserialize("namespaceId") long namespaceId, @Deserialize("name") String name, @Deserialize("namespaceName") String namespaceName, @Deserialize("adapterId") long adapterId ) { - super( id, allocationId, name, namespaceId, namespaceName, NamespaceType.DOCUMENT, adapterId ); + super( id, allocationId, logicalId, name, namespaceId, namespaceName, NamespaceType.DOCUMENT, adapterId ); } @@ -56,7 +57,7 @@ public Expression asExpression() { @Override public PhysicalEntity normalize() { - return new PhysicalCollection( id, allocationId, namespaceId, name, namespaceName, adapterId ); + return new PhysicalCollection( id, allocationId, logicalId, namespaceId, name, namespaceName, adapterId ); } } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java index 628bf04d1c..0f902ad486 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java @@ -87,7 +87,6 @@ public class PhysicalColumn extends PhysicalField { public PhysicalColumn( @Deserialize("id") final long id, @Deserialize("name") final String name, - @Deserialize("logicalName") final String logicalName, @Deserialize("allocId") final long allocId, @Deserialize("entityId") final long tableId, @Deserialize("adapterId") final long adapterId, @@ -101,7 +100,7 @@ public PhysicalColumn( @Deserialize("nullable") final boolean nullable, @Deserialize("collation") final Collation collation, @Deserialize("defaultValue") CatalogDefaultValue defaultValue ) { - super( id, name, logicalName, allocId, tableId, adapterId, NamespaceType.RELATIONAL, true ); + super( id, name, allocId, tableId, adapterId, NamespaceType.RELATIONAL, true ); this.position = position; this.type = type; this.collectionsType = collectionsType; @@ -125,7 +124,6 @@ public PhysicalColumn( this( column.id, name, - column.name, allocTableId, tableId, adapterId, 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 574249a967..a7dee70257 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 @@ -42,12 +42,16 @@ public abstract class PhysicalEntity extends CatalogEntity { @Serialize public long allocationId; + @Serialize + public long logicalId; + - protected PhysicalEntity( long id, long allocationId, String name, long namespaceId, String namespaceName, NamespaceType namespaceType, long adapterId ) { + protected PhysicalEntity( long id, long allocationId, long logicalId, String name, long namespaceId, String namespaceName, NamespaceType namespaceType, long adapterId ) { super( id, name, namespaceId, EntityType.ENTITY, namespaceType, true ); this.allocationId = allocationId; this.namespaceName = namespaceName; this.adapterId = adapterId; + this.logicalId = logicalId; } 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 6d648b0f5b..ad540a2c24 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 @@ -41,8 +41,6 @@ public abstract class PhysicalField extends CatalogEntity { @Serialize public long entityId; - @Serialize - public String logicalName; @Serialize public long allocId; @@ -51,14 +49,12 @@ public abstract class PhysicalField extends CatalogEntity { public PhysicalField( final long id, final String name, - final String logicalName, final long allocId, final long entityId, final long adapterId, final NamespaceType namespaceType, final boolean modifiable ) { super( id, name, allocId, EntityType.ENTITY, namespaceType, modifiable ); - this.logicalName = logicalName; this.entityId = entityId; this.allocId = allocId; this.adapterId = adapterId; diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalGraph.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalGraph.java index 1d381476de..fb1e6957b0 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalGraph.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalGraph.java @@ -34,9 +34,10 @@ public class PhysicalGraph extends PhysicalEntity { public PhysicalGraph( @Deserialize("id") long id, @Deserialize("allocationId") long allocationId, + @Deserialize("logicalId") long logicalId, @Deserialize("name") String name, @Deserialize("adapterId") long adapterId ) { - super( id, allocationId, name, id, name, NamespaceType.GRAPH, adapterId ); // for graph both name and namespaceName are the same + super( id, allocationId, logicalId, name, id, name, NamespaceType.GRAPH, adapterId ); // for graph both name and namespaceName are the same } @@ -54,7 +55,7 @@ public Expression asExpression() { @Override public PhysicalEntity normalize() { - return new PhysicalGraph( id, allocationId, name, adapterId ); + return new PhysicalGraph( id, allocationId, logicalId, name, adapterId ); } } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java index 44b993f11f..9f763a2bca 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalTable.java @@ -51,12 +51,13 @@ public class PhysicalTable extends PhysicalEntity { public PhysicalTable( @Deserialize("id") long id, @Deserialize("allocationId") long allocationId, + @Deserialize("logicalId") long logicalId, @Deserialize("name") String name, @Deserialize("columns") List columns, @Deserialize("namespaceId") long namespaceId, @Deserialize("namespaceName") String namespaceName, @Deserialize("adapterId") long adapterId ) { - super( id, allocationId, name, namespaceId, namespaceName, NamespaceType.RELATIONAL, adapterId ); + super( id, allocationId, logicalId, name, namespaceId, namespaceName, NamespaceType.RELATIONAL, adapterId ); this.columns = ImmutableList.copyOf( columns ); } @@ -72,7 +73,7 @@ public AlgProtoDataType buildProto() { for ( PhysicalColumn column : columns.stream().sorted( Comparator.comparingInt( a -> a.position ) ).collect( Collectors.toList() ) ) { AlgDataType sqlType = column.getAlgDataType( AlgDataTypeFactory.DEFAULT ); - fieldInfo.add( column.logicalName, column.name, sqlType ).nullable( column.nullable ); + fieldInfo.add( column.id, column.name, column.name, sqlType ).nullable( column.nullable ); } return AlgDataTypeImpl.proto( fieldInfo.build() ); @@ -87,7 +88,6 @@ public Serializable[] getParameterArray() { @Override public Expression asExpression() { - //return Expressions.call( Catalog.PHYSICAL_EXPRESSION, "getPhysicalTable", Expressions.constant( id ) ); return Expressions.call( Expressions.convert_( Expressions.call( Catalog.PHYSICAL_EXPRESSION.apply( adapterId ), "get" ), StoreCatalog.class ), "getPhysical", Expressions.constant( id ) ); } @@ -97,10 +97,6 @@ public List getColumnNames() { } - public List getLogicalNames() { - return columns.stream().map( c -> c.logicalName ).collect( Collectors.toList() ); - } - public List getColumnIds() { return columns.stream().map( c -> c.id ).collect( Collectors.toList() ); @@ -109,7 +105,7 @@ public List getColumnIds() { @Override public PhysicalEntity normalize() { - return new PhysicalTable( id, allocationId, name, columns, namespaceId, namespaceName, adapterId ); + return new PhysicalTable( id, allocationId, logicalId, name, columns, namespaceId, namespaceName, adapterId ); } } diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/Persister.java b/core/src/main/java/org/polypheny/db/catalog/impl/Persister.java index ffd30f6106..f04712d575 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/Persister.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/Persister.java @@ -67,11 +67,9 @@ public synchronized void write( String data ) { public synchronized String read() { - //String data; StringBuilder data = new StringBuilder(); try { BufferedReader reader = new BufferedReader( new FileReader( backup, Charsets.ISO_8859_1 ) ); - int c; while ( ((c = reader.read()) != -1) ) { data.append( (char) c ); 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 6ce3aae104..901a2a686e 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 @@ -26,7 +26,6 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.adapter.AbstractAdapterSetting; @@ -171,38 +170,8 @@ public void init() { @Override public void updateSnapshot() { - // reset physical catalogs - - // update all except physicals, so information can be accessed this.snapshot = SnapshotBuilder.createSnapshot( idBuilder.getNewSnapshotId(), this, logicalCatalogs, allocationCatalogs ); - Map adapterRestore = adapters.values().stream().collect( Collectors.toMap( a -> a.id, a -> new AdapterRestore( a.id ) ) ); - // generate new physical entities, atm only relational - for ( AllocationCatalog catalog : this.allocationCatalogs.values() ) { - if ( catalog.getNamespace().namespaceType == NamespaceType.RELATIONAL ) { - catalog.unwrap( AllocationRelationalCatalog.class ).getTables().forEach( ( id, table ) -> { - addNamespaceIfNecessary( table ); - adapterRestore.get( table.adapterId ).addPhysicals( table, AdapterManager.getInstance().getAdapter( table.adapterId ).refreshTable( table.id ) ); - } ); - } else if ( catalog.getNamespace().namespaceType == NamespaceType.DOCUMENT ) { - catalog.unwrap( AllocationDocumentCatalog.class ).getCollections().forEach( ( id, collection ) -> { - addNamespaceIfNecessary( collection ); - adapterRestore.get( collection.adapterId ).addPhysicals( collection, AdapterManager.getInstance().getAdapter( collection.adapterId ).refreshCollection( collection.id ) ); - } ); - } else if ( catalog.getNamespace().namespaceType == NamespaceType.GRAPH ) { - catalog.unwrap( AllocationGraphCatalog.class ).getGraphs().forEach( ( id, graph ) -> { - addNamespaceIfNecessary( graph ); - adapterRestore.get( graph.adapterId ).addPhysicals( graph, AdapterManager.getInstance().getAdapter( graph.adapterId ).refreshGraph( graph.id ) ); - } ); - } - } - - synchronized ( this ) { - this.adapterRestore.clear(); - this.adapterRestore.putAll( adapterRestore ); - // update with newly generated physical entities - this.snapshot = SnapshotBuilder.createSnapshot( idBuilder.getNewSnapshotId(), this, logicalCatalogs, allocationCatalogs ); - } this.listeners.firePropertyChange( "snapshot", null, this.snapshot ); } diff --git a/core/src/main/java/org/polypheny/db/interpreter/AggregateNode.java b/core/src/main/java/org/polypheny/db/interpreter/AggregateNode.java index 3ccc782ab7..0a2946a2dc 100644 --- a/core/src/main/java/org/polypheny/db/interpreter/AggregateNode.java +++ b/core/src/main/java/org/polypheny/db/interpreter/AggregateNode.java @@ -202,7 +202,7 @@ private AccumulatorFactory getAccumulator( final AggregateCall call, boolean ign final PhysType inputPhysType = PhysTypeImpl.of( typeFactory, alg.getInput().getRowType(), JavaRowFormat.ARRAY ); final Builder builder = typeFactory.builder(); for ( Expression expression : agg.state ) { - builder.add( "a", null, typeFactory.createJavaType( (Class) expression.getType() ) ); + builder.add( null, "a", null, typeFactory.createJavaType( (Class) expression.getType() ) ); } final PhysType accPhysType = PhysTypeImpl.of( typeFactory, builder.build(), JavaRowFormat.ARRAY ); final ParameterExpression inParameter = Expressions.parameter( inputPhysType.getJavaRowType(), "in" ); 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 bf985e1df2..9269c77fc9 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java @@ -212,7 +212,6 @@ public static List findAllTables( AlgNode alg ) { } - /** * Returns a list of variables set by a relational expression or its descendants. */ @@ -1407,14 +1406,12 @@ public static AlgDataType createDmlRowType( Kind kind, AlgDataTypeFactory typeFa case UPDATE: return typeFactory.createStructType( ImmutableList.of( - Pair.of( - AvaticaConnection.ROWCOUNT_COLUMN_NAME, + new AlgDataTypeFieldImpl( -1L, AvaticaConnection.ROWCOUNT_COLUMN_NAME, 0, typeFactory.createPolyType( PolyType.BIGINT ) ) ) ); case EXPLAIN: return typeFactory.createStructType( ImmutableList.of( - Pair.of( - AvaticaConnection.PLAN_COLUMN_NAME, + new AlgDataTypeFieldImpl( -1L, AvaticaConnection.PLAN_COLUMN_NAME, 0, typeFactory.createPolyType( PolyType.VARCHAR, AlgDataType.PRECISION_NOT_SPECIFIED ) ) ) ); default: throw Util.unexpected( kind ); @@ -2384,7 +2381,7 @@ public static AlgNode permute( AlgNode alg, Permutation permutation, List type ) { if ( !Modifier.isStatic( field.getModifiers() ) ) { // FIXME: watch out for recursion final Type fieldType = fieldType( field ); - list.add( new AlgDataTypeFieldImpl( field.getName(), list.size(), createType( fieldType ) ) ); + list.add( new AlgDataTypeFieldImpl( -1L, field.getName(), list.size(), createType( fieldType ) ) ); } } return canonize( new JavaRecordType( list, type ) ); @@ -394,6 +394,7 @@ 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.getFieldNames() ); } 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 7514ccd571..412c5eecde 100644 --- a/core/src/main/java/org/polypheny/db/processing/QueryProcessorHelpers.java +++ b/core/src/main/java/org/polypheny/db/processing/QueryProcessorHelpers.java @@ -53,7 +53,7 @@ public static AlgDataType makeStruct( AlgDataTypeFactory typeFactory, AlgDataTyp return type; } // TODO MV: This "null" might be wrong - return typeFactory.builder().add( "$0", null, type ).build(); + return typeFactory.builder().add( null, "$0", null, type ).build(); } 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 c3ec19f2d2..abc82aab34 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexUtil.java +++ b/core/src/main/java/org/polypheny/db/rex/RexUtil.java @@ -937,7 +937,7 @@ public static AlgDataType createStructType( AlgDataTypeFactory typeFactory, fina if ( names == null || (name = names.get( i )) == null ) { name = "$f" + i; } - builder.add( name, null, exprs.get( i ).getType() ); + builder.add( null, name, null, exprs.get( i ).getType() ); } return builder.build(); } 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 876f2a8bbb..7419cb3854 100644 --- a/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java +++ b/core/src/main/java/org/polypheny/db/tools/AlgBuilder.java @@ -54,7 +54,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.Set; import java.util.SortedSet; @@ -1381,11 +1380,11 @@ public AlgBuilder scan( @Nonnull CatalogEntity entity ) { public AlgBuilder reorder( AlgDataType target ) { - List names = peek().getRowType().getFieldNames(); - List targetNames = target.getFieldNames(); + List ids = peek().getRowType().getFieldIds(); + List targetIds = target.getFieldIds(); List mapping = new ArrayList<>(); - for ( String name : names ) { - mapping.add( targetNames.indexOf( name ) ); + for ( Long id : ids ) { + mapping.add( targetIds.indexOf( id ) ); } permute( new Permutation( mapping ) ); @@ -1399,12 +1398,6 @@ public AlgBuilder scan( @Nonnull PhysicalEntity entity ) { return this; } - - private Map flip( Map map ) { - return map.entrySet().stream().collect( Collectors.toMap( Entry::getValue, Entry::getKey ) ); - } - - /** * Creates a {@link RelScan} of the table with a given name. * @@ -1653,7 +1646,7 @@ public AlgBuilder project( Iterable nodes, Iterable f } while ( uniqueNameList.contains( name ) ); fieldNameList.set( i, name ); } - AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( name, i, node.getType() ); + AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( -1L, name, i, node.getType() ); switch ( node.getKind() ) { case INPUT_REF: // preserve alg aliases for INPUT_REF fields @@ -1774,7 +1767,7 @@ public AlgBuilder rename( List fieldNames ) { final Values v = (Values) build(); final AlgDataTypeFactory.Builder b = getTypeFactory().builder(); for ( Pair p : Pair.zip( newFieldNames, v.getRowType().getFieldList() ) ) { - b.add( p.left, null, p.right.getType() ); + b.add( null, p.left, null, p.right.getType() ); } return values( v.tuples, b.build() ); } @@ -1952,7 +1945,7 @@ public AlgBuilder aggregate( GroupKey groupKey, Iterable aggCalls ) { } else { String name = aggregateFields.get( i ).getName(); - AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( name, i, node.getType() ); + AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( -1L, name, i, node.getType() ); fields.add( new RelField( ImmutableSet.of(), fieldType ) ); } i++; @@ -1961,7 +1954,7 @@ public AlgBuilder aggregate( GroupKey groupKey, Iterable aggCalls ) { if ( groupKey_.indicator ) { for ( int j = 0; j < groupSet.cardinality(); ++j ) { final AlgDataTypeField field = aggregateFields.get( i ); - final AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( field.getName(), i, field.getType() ); + final AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( -1L, field.getName(), i, field.getType() ); fields.add( new RelField( ImmutableSet.of(), fieldType ) ); i++; } @@ -1969,7 +1962,7 @@ public AlgBuilder aggregate( GroupKey groupKey, Iterable aggCalls ) { // third, aggregate fields. retain `i' as field index for ( int j = 0; j < aggregateCalls.size(); ++j ) { final AggregateCall call = aggregateCalls.get( j ); - final AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( aggregateFields.get( i + j ).getName(), i + j, call.getType() ); + final AlgDataTypeField fieldType = new AlgDataTypeFieldImpl( -1L, aggregateFields.get( i + j ).getName(), i + j, call.getType() ); fields.add( new RelField( ImmutableSet.of(), fieldType ) ); } stack.push( new Frame( aggregate, fields.build() ) ); @@ -2223,7 +2216,7 @@ public int size() { return rowCount; } } ); - builder.add( name, null, type ); + builder.add( null, name, null, type ); } final AlgDataType rowType = builder.build(); return values( tupleList, rowType ); @@ -2625,12 +2618,12 @@ public AlgBuilder match( final AlgDataTypeFactory.Builder typeBuilder = cluster.getTypeFactory().builder(); for ( RexNode partitionKey : partitionKeys ) { - typeBuilder.add( partitionKey.toString(), null, partitionKey.getType() ); + typeBuilder.add( null, partitionKey.toString(), null, partitionKey.getType() ); } if ( allRows ) { for ( RexNode orderKey : orderKeys ) { if ( !typeBuilder.nameExists( orderKey.toString() ) ) { - typeBuilder.add( orderKey.toString(), null, orderKey.getType() ); + typeBuilder.add( null, orderKey.toString(), null, orderKey.getType() ); } } @@ -2646,7 +2639,7 @@ public AlgBuilder match( for ( RexNode measure : measureList ) { List operands = ((RexCall) measure).getOperands(); String alias = operands.get( 1 ).toString(); - typeBuilder.add( alias, null, operands.get( 0 ).getType() ); + typeBuilder.add( null, alias, null, operands.get( 0 ).getType() ); measures.put( alias, operands.get( 0 ) ); } 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 cb803e4c96..2e0b835124 100644 --- a/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java +++ b/core/src/main/java/org/polypheny/db/type/PolyTypeUtil.java @@ -194,7 +194,7 @@ public static AlgDataType promoteToRowType( AlgDataTypeFactory typeFactory, AlgD if ( fieldName == null ) { fieldName = "ROW_VALUE"; } - type = typeFactory.builder().add( fieldName, null, type ).build(); + type = typeFactory.builder().add( null, fieldName, null, type ).build(); } return type; } @@ -810,7 +810,7 @@ public static AlgDataType flattenRecordType( AlgDataTypeFactory typeFactory, Alg types.add( field.getType() ); fieldNames.add( field.getName() + "_" + i ); } - return typeFactory.createStructType( types, fieldNames ); + return typeFactory.createStructType( null, types, fieldNames ); } @@ -829,7 +829,7 @@ private static boolean flattenFields( AlgDataTypeFactory typeFactory, AlgDataTyp if ( type.isNullable() ) { indicatorType = typeFactory.createTypeWithNullability( indicatorType, true ); } - AlgDataTypeField nullIndicatorField = new AlgDataTypeFieldImpl( "NULL_VALUE", 0, indicatorType ); + AlgDataTypeField nullIndicatorField = new AlgDataTypeFieldImpl( -1L, "NULL_VALUE", 0, indicatorType ); list.add( nullIndicatorField ); nested = true; } @@ -854,7 +854,7 @@ private static boolean flattenFields( AlgDataTypeFactory typeFactory, AlgDataTyp flattenRecordType( typeFactory, field.getType().getComponentType(), null ), -1 ); } - field = new AlgDataTypeFieldImpl( field.getName(), field.getIndex(), flattenedCollectionType ); + field = new AlgDataTypeFieldImpl( field.getId(), field.getName(), field.getIndex(), flattenedCollectionType ); list.add( field ); } else { list.add( field ); @@ -985,7 +985,7 @@ public int size() { * @return Struct type with no fields */ public static AlgDataType createEmptyStructType( AlgDataTypeFactory typeFactory ) { - return typeFactory.createStructType( ImmutableList.of(), ImmutableList.of() ); + return typeFactory.createStructType( null, ImmutableList.of(), ImmutableList.of() ); } 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 e7ed2c116b..e0e64363f2 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 @@ -16,6 +16,7 @@ package org.polypheny.db.type.entity; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonToken; import io.activej.serializer.BinaryInput; @@ -51,7 +52,8 @@ public class PolyBigDecimal extends PolyNumber { public BigDecimal value; - public PolyBigDecimal( @JsonProperty @Deserialize("value") BigDecimal value ) { + @JsonCreator + public PolyBigDecimal( @JsonProperty("value") @Deserialize("value") BigDecimal value ) { super( PolyType.DECIMAL ); this.value = value; } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java b/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java index 4efd93019b..03f2ed61f9 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java @@ -51,7 +51,7 @@ public class PolyBoolean extends PolyValue { public Boolean value; - public PolyBoolean( @JsonProperty @Deserialize("value") Boolean value ) { + public PolyBoolean( @JsonProperty("value") @Deserialize("value") Boolean value ) { super( PolyType.BOOLEAN ); this.value = value; } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java b/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java index 9c8d47b17f..eb814f4bd2 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyInteger.java @@ -48,7 +48,7 @@ public class PolyInteger extends PolyNumber { public Integer value; - public PolyInteger( @JsonProperty @Deserialize("value") Integer value ) { + public PolyInteger( @JsonProperty("value") @Deserialize("value") Integer value ) { super( PolyType.INTEGER ); this.value = value; } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyList.java b/core/src/main/java/org/polypheny/db/type/entity/PolyList.java index ad09462817..ac5cdd8379 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyList.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyList.java @@ -16,9 +16,11 @@ package org.polypheny.db.type.entity; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.core.type.TypeReference; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -34,6 +36,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.Delegate; +import lombok.extern.slf4j.Slf4j; import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.jetbrains.annotations.NotNull; @@ -42,6 +45,7 @@ import org.polypheny.db.type.PolyType; import org.polypheny.db.util.Pair; +@Slf4j @EqualsAndHashCode(callSuper = true) @Value(staticConstructor = "copyOf") public class PolyList extends PolyValue implements List { @@ -49,10 +53,10 @@ public class PolyList extends PolyValue implements List @Delegate @JsonProperty - @JsonSerialize public List value; + @JsonCreator public PolyList( @JsonProperty @Deserialize("value") List value ) { super( PolyType.ARRAY ); this.value = new ArrayList<>( value ); @@ -65,6 +69,18 @@ public PolyList( E... value ) { } + @Override + public @Nullable String toTypedJson() { + try { + return JSON_WRAPPER.writerFor( new TypeReference() { + } ).writeValueAsString( this ); + } catch ( JsonProcessingException e ) { + log.warn( "Error on serializing typed JSON." ); + return null; + } + } + + public static PolyList of( Collection value ) { return new PolyList<>( new ArrayList<>( value ) ); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java b/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java index 7984bca952..1b227e609f 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyNull.java @@ -106,7 +106,6 @@ public boolean isDocument() { return PolyDocument.ofDocument( null ); } - @Override public boolean isList() { return true; diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyString.java b/core/src/main/java/org/polypheny/db/type/entity/PolyString.java index 2d6729e911..5a1ad4fb0d 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyString.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyString.java @@ -51,7 +51,7 @@ public class PolyString extends PolyValue { public Charset charset; - public PolyString( @JsonProperty @Deserialize("value") String value ) { + public PolyString( @JsonProperty("value") @Deserialize("value") String value ) { this( value, Charsets.UTF_16 ); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java index 6ead5a0bff..7bd1dfa594 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java @@ -16,21 +16,17 @@ package org.polypheny.db.type.entity; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; import io.activej.serializer.BinaryInput; import io.activej.serializer.BinaryOutput; import io.activej.serializer.BinarySerializer; @@ -40,7 +36,6 @@ import io.activej.serializer.SimpleSerializerDef; import io.activej.serializer.annotations.Serialize; import io.activej.serializer.annotations.SerializeClass; -import java.io.IOException; import java.lang.reflect.Type; import java.util.Optional; import java.util.stream.Collectors; @@ -110,6 +105,30 @@ PolyNode.class, PolyEdge.class, PolyPath.class }) // add on Constructor already exists exception +@JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT, property = "clazz", visible = true) // to allow typed json serialization +@JsonSubTypes({ + @JsonSubTypes.Type(value = PolyList.class, name = "LIST"), + @JsonSubTypes.Type(value = PolyBigDecimal.class, name = "DECIMAL"), + @JsonSubTypes.Type(value = PolyNull.class, name = "NULL"), + @JsonSubTypes.Type(value = PolyString.class, name = "STRING"), + @JsonSubTypes.Type(value = PolyDate.class, name = "DATE"), + @JsonSubTypes.Type(value = PolyTime.class, name = "TIME"), + @JsonSubTypes.Type(value = PolyDouble.class, name = "DOUBLE"), + @JsonSubTypes.Type(value = PolyFloat.class, name = "FLOAT"), + @JsonSubTypes.Type(value = PolyLong.class, name = "LONG"), + @JsonSubTypes.Type(value = PolyInteger.class, name = "INTEGER"), + @JsonSubTypes.Type(value = PolyBoolean.class, name = "BOOLEAN"), + @JsonSubTypes.Type(value = PolyTimeStamp.class, name = "TIMESTAMP"), + @JsonSubTypes.Type(value = PolyBinary.class, name = "BINARY"), + @JsonSubTypes.Type(value = PolyDocument.class, name = "DOCUMENT"), + @JsonSubTypes.Type(value = PolySymbol.class, name = "SYMBOL"), + @JsonSubTypes.Type(value = PolyMap.class, name = "MAP"), + @JsonSubTypes.Type(value = PolyNode.class, name = "NODE"), + @JsonSubTypes.Type(value = PolyEdge.class, name = "EDGE"), + @JsonSubTypes.Type(value = PolyPath.class, name = "PATH"), + @JsonSubTypes.Type(value = PolyDictionary.class, name = "DICTIONARY"), + @JsonSubTypes.Type(value = PolyUserDefinedValue.class, name = "UDV") +}) public abstract class PolyValue implements Expressible, Comparable, PolySerializable { @JsonIgnore @@ -138,18 +157,16 @@ public abstract class PolyValue implements Expressible, Comparable, P setSerializationInclusion( JsonInclude.Include.NON_NULL ); configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false ); + setVisibility( getSerializationConfig().getDefaultVisibilityChecker() + .withIsGetterVisibility( Visibility.NONE ) + .withGetterVisibility( Visibility.NONE ) + .withSetterVisibility( Visibility.NONE ) ); writerWithDefaultPrettyPrinter(); - registerModule( new SimpleModule() - .addDeserializer( PolyValue.class, new PolyDeserializer( PolyValue.class ) ) - .addSerializer( PolyValue.class, new PolySerializer( PolyValue.class ) ) ); } }; - - public static final ObjectMapper JSON_RAW = new ObjectMapper(); - - @Serialize + @JsonIgnore public PolyType type; @@ -197,13 +214,10 @@ public static Function1 getPolyToJava( AlgDataType type, bool ? (o.asList().stream().map( elTrans::apply ).collect( Collectors.toList() )) : o.asList().stream().map( elTrans::apply ).collect( Collectors.toList() ).toArray(); case FILE: - return o -> o; case IMAGE: - return o -> o; case AUDIO: - return o -> o; case VIDEO: - return o -> o; + return o -> o.asBlob().asByteArray(); default: throw new org.apache.commons.lang3.NotImplementedException( "meta" ); } @@ -253,8 +267,9 @@ public static E fromTypedJson( String value, Class claz public String toJson() { + // fallback serializer try { - return JSON_RAW.writeValueAsString( this ); + return JSON_WRAPPER.writeValueAsString( this ); } catch ( JsonProcessingException e ) { log.warn( "Error on deserialize JSON." ); return null; @@ -432,7 +447,6 @@ public String serialize() { @Override - @JsonIgnore public BinarySerializer getSerializer() { return (BinarySerializer) serializer; } @@ -841,80 +855,4 @@ public PolyValue decode( BinaryInput in ) throws CorruptedDataException { } - - public static class PolySerializer extends StdSerializer { - - private static final String CLASSNAME = "className"; - private static final String INSTANCE = "instance"; - - - protected PolySerializer( Class t ) { - super( t ); - } - - - @Override - public void serialize( PolyValue value, JsonGenerator gen, SerializerProvider serializers ) throws IOException { - if ( value == null ) { - gen.writeNull(); - return; - } - - gen.writeStartObject(); - gen.writeFieldName( CLASSNAME ); - gen.writeString( value.getClass().getName() ); - gen.writeFieldName( INSTANCE ); - gen.writeRawValue( JSON_RAW.writeValueAsString( value ) ); - gen.writeEndObject(); - } - - } - - - public static class PolyDeserializer extends StdDeserializer { - - private static final String CLASSNAME = "className"; - private static final String INSTANCE = "instance"; - - - protected PolyDeserializer( Class vc ) { - super( vc ); - } - - - @Override - public PolyValue deserialize( JsonParser p, DeserializationContext ctxt ) throws IOException, JsonProcessingException { - JsonToken token = p.currentToken(); - if ( token == JsonToken.VALUE_NULL ) { - p.nextValue(); - return null; - } - - String className = null; - PolyValue instance = null; - String name = p.nextFieldName(); - - while ( name != null ) { - if ( name.equals( CLASSNAME ) ) { - className = p.nextTextValue(); - } else if ( name.equals( INSTANCE ) ) { - Class type; - try { - type = (Class) Class.forName( className ); - } catch ( ClassNotFoundException e ) { - throw new JsonParseException( p, "Invalid class name: " + className, e ); - } - instance = JSON_WRAPPER.readValue( p, type ); - } else { - p.skipChildren(); - } - name = p.nextFieldName(); - } - - return instance; - - } - - } - } diff --git a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java index 2be7c5f219..4dabf9150b 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java +++ b/core/src/main/java/org/polypheny/db/type/entity/graph/PolyPath.java @@ -140,7 +140,7 @@ public List getPathType( AlgDataType nodeType, AlgDataType edg } if ( name != null && name.value != null ) { - pathType.add( new AlgDataTypeFieldImpl( name.value, i, type ) ); + pathType.add( new AlgDataTypeFieldImpl( -1L, name.value, i, type ) ); } i++; 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 d5c8c192f1..3e74bf3f14 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 @@ -556,7 +556,7 @@ public int size() { AlgDataType componentType = multisetType.getComponentType(); assert componentType != null : "expected a multiset type: " + multisetType; final AlgDataTypeFactory typeFactory = opBinding.getTypeFactory(); - final AlgDataType type = typeFactory.builder().add( CoreUtil.deriveAliasFromOrdinal( 0 ), null, componentType ).build(); + final AlgDataType type = typeFactory.builder().add( null, CoreUtil.deriveAliasFromOrdinal( 0 ), null, componentType ).build(); return typeFactory.createMultisetType( type, -1 ); }; /** 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 8c2b8b2dc2..8f8acac38c 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 @@ -134,7 +134,7 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { } } } - return opBinding.getTypeFactory().createStructType( expandedOutputTypes, expandedFieldNames ); + return opBinding.getTypeFactory().createStructType( null, expandedOutputTypes, expandedFieldNames ); } 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 c57d0b9892..f9ffe9b5fb 100644 --- a/core/src/main/java/org/polypheny/db/util/ValidatorUtil.java +++ b/core/src/main/java/org/polypheny/db/util/ValidatorUtil.java @@ -96,26 +96,27 @@ public static AlgDataType createJoinType( AlgDataTypeFactory typeFactory, AlgDat + rightType.getFieldCount())); List nameList = new ArrayList<>(); final List typeList = new ArrayList<>(); + final List ids = new ArrayList<>(); // Use a set to keep track of the field names; this is needed to ensure that the contains() call to check for name uniqueness runs in constant time; otherwise, if the number of fields is large, doing a contains() on a list can be expensive. final Set uniqueNameList = typeFactory.getTypeSystem().isSchemaCaseSensitive() ? new HashSet<>() : new TreeSet<>( String.CASE_INSENSITIVE_ORDER ); - addFields( systemFieldList, typeList, nameList, uniqueNameList ); - addFields( leftType.getFieldList(), typeList, nameList, uniqueNameList ); + addFields( systemFieldList, typeList, nameList, ids, uniqueNameList ); + addFields( leftType.getFieldList(), typeList, nameList, ids, uniqueNameList ); if ( rightType != null ) { - addFields( rightType.getFieldList(), typeList, nameList, uniqueNameList ); + addFields( rightType.getFieldList(), typeList, nameList, ids, uniqueNameList ); } if ( fieldNameList != null ) { assert fieldNameList.size() == nameList.size(); nameList = fieldNameList; } - return typeFactory.createStructType( typeList, nameList ); + return typeFactory.createStructType( ids, typeList, nameList ); } - private static void addFields( List fieldList, List typeList, List nameList, Set uniqueNames ) { + private static void addFields( List fieldList, List typeList, List nameList, List ids, Set uniqueNames ) { for ( AlgDataTypeField field : fieldList ) { String name = field.getName(); @@ -132,6 +133,7 @@ private static void addFields( List fieldList, List>> resolveColumn( AlgDataType row if ( subMap != null ) { List> entries = new ArrayList<>( subMap.entrySet() ); entries.sort( ( o1, o2 ) -> o1.getValue() - o2.getValue() ); - ret.add( new Pair<>( new AlgDataTypeFieldImpl( columnName, -1, createStructType( rowType, typeFactory, entries ) ), remainder ) ); + ret.add( new Pair<>( new AlgDataTypeFieldImpl( -1L, columnName, -1, createStructType( rowType, typeFactory, entries ) ), remainder ) ); } } @@ -110,31 +111,9 @@ public List>> resolveColumn( AlgDataType row private static AlgDataType createStructType( final AlgDataType rowType, AlgDataTypeFactory typeFactory, final List> entries ) { return typeFactory.createStructType( StructKind.PEEK_FIELDS, - new AbstractList() { - @Override - public AlgDataType get( int index ) { - final int i = entries.get( index ).getValue(); - return rowType.getFieldList().get( i ).getType(); - } - - - @Override - public int size() { - return entries.size(); - } - }, - new AbstractList() { - @Override - public String get( int index ) { - return entries.get( index ).getKey(); - } - - - @Override - public int size() { - return entries.size(); - } - } ); + rowType.getFieldList().stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + entries.stream().map( e -> rowType.getFieldList().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/Fixture.java b/core/src/test/java/org/polypheny/db/catalog/Fixture.java index bdd86e12d5..2bf0f914d6 100644 --- a/core/src/test/java/org/polypheny/db/catalog/Fixture.java +++ b/core/src/test/java/org/polypheny/db/catalog/Fixture.java @@ -67,48 +67,48 @@ final class Fixture { booleanTypeNull = typeFactory.createTypeWithNullability( booleanType, true ); rectilinearCoordType = typeFactory.builder() - .add( "X", null, intType ) - .add( "Y", null, intType ) + .add( null, "X", null, intType ) + .add( null, "Y", null, intType ) .build(); rectilinearPeekCoordType = typeFactory.builder() - .add( "X", null, intType ) - .add( "Y", null, intType ) + .add( null, "X", null, intType ) + .add( null, "Y", null, intType ) .kind( StructKind.PEEK_FIELDS ) .build(); rectilinearPeekNoExpandCoordType = typeFactory.builder() - .add( "M", null, intType ) + .add( null, "M", null, intType ) .add( - "SUB", + null, "SUB", null, typeFactory.builder() - .add( "A", null, intType ) - .add( "B", null, intType ) + .add( null, "A", null, intType ) + .add( null, "B", null, intType ) .kind( StructKind.PEEK_FIELDS_NO_EXPAND ) .build() ) .kind( StructKind.PEEK_FIELDS_NO_EXPAND ) .build(); abRecordType = typeFactory.builder() - .add( "A", null, varchar10Type ) - .add( "B", null, varchar10Type ) + .add( null, "A", null, varchar10Type ) + .add( null, "B", null, varchar10Type ) .build(); skillRecordType = typeFactory.builder() - .add( "TYPE", null, varchar10Type ) - .add( "DESC", null, varchar20Type ) - .add( "OTHERS", null, abRecordType ) + .add( null, "TYPE", null, varchar10Type ) + .add( null, "DESC", null, varchar20Type ) + .add( null, "OTHERS", null, abRecordType ) .build(); empRecordType = typeFactory.builder() - .add( "EMPNO", null, intType ) - .add( "ENAME", null, varchar10Type ) + .add( null, "EMPNO", null, intType ) + .add( null, "ENAME", null, varchar10Type ) .add( - "DETAIL", + null, "DETAIL", null, typeFactory.builder() - .add( "SKILLS", null, typeFactory.createArrayType( skillRecordType, -1 ) ) + .add( null, "SKILLS", null, typeFactory.createArrayType( skillRecordType, -1 ) ) .build() ) .build(); empListType = typeFactory.createArrayType( empRecordType, -1 ); @@ -118,10 +118,10 @@ final class Fixture { //new MockIdentifier( "ADDRESS", ParserPos.ZERO ), false, Arrays.asList( - new AlgDataTypeFieldImpl( "STREET", 0, varchar20Type ), - new AlgDataTypeFieldImpl( "CITY", 1, varchar20Type ), - new AlgDataTypeFieldImpl( "ZIP", 2, intType ), - new AlgDataTypeFieldImpl( "STATE", 3, varchar20Type ) ), + new AlgDataTypeFieldImpl( 1L, "STREET", 0, varchar20Type ), + new AlgDataTypeFieldImpl( 2L, "CITY", 1, varchar20Type ), + new AlgDataTypeFieldImpl( 3L, "ZIP", 2, intType ), + new AlgDataTypeFieldImpl( 4L, "STATE", 3, varchar20Type ) ), AlgDataTypeComparability.NONE ); } 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 1e780588f1..34e367f4e7 100644 --- a/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java +++ b/core/src/test/java/org/polypheny/db/catalog/MockCatalogReader.java @@ -422,12 +422,11 @@ public AlgDataType getRowType() { public void onRegister( AlgDataTypeFactory typeFactory ) { - rowType = typeFactory.createStructType( kind, Pair.right( columnList ), Pair.left( columnList ) ); + 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 ); } @@ -492,7 +491,6 @@ 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. */ 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 1831333c7a..ad770046f5 100644 --- a/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java +++ b/core/src/test/java/org/polypheny/db/plan/RelOptUtilTest.java @@ -107,8 +107,8 @@ public void testTypeDump() { Util.toLinux( AlgOptUtil.dumpType( t1 ) + "\n" ) ); AlgDataType t2 = typeFactory.builder() - .add( "f0", null, t1 ) - .add( "f1", null, typeFactory.createMultisetType( t1, -1 ) ) + .add( null, "f0", null, t1 ) + .add( null, "f1", null, typeFactory.createMultisetType( t1, -1 ) ) .build(); TestUtil.assertEqualsVerbose( TestUtil.fold( diff --git a/core/src/test/java/org/polypheny/db/test/RexProgramBuilderBase.java b/core/src/test/java/org/polypheny/db/test/RexProgramBuilderBase.java index c3f892ea32..f529d819bf 100644 --- a/core/src/test/java/org/polypheny/db/test/RexProgramBuilderBase.java +++ b/core/src/test/java/org/polypheny/db/test/RexProgramBuilderBase.java @@ -221,12 +221,12 @@ private RexDynamicParam getDynamicParam( AlgDataType type, String fieldNamePrefi AlgDataType nullableType = typeFactory.createTypeWithNullability( k, true ); Builder builder = typeFactory.builder(); for ( int i = 0; i < MAX_FIELDS; i++ ) { - builder.add( fieldNamePrefix + i, null, nullableType ); + builder.add( null, fieldNamePrefix + i, null, nullableType ); } String notNullPrefix = "notNull" + Character.toUpperCase( fieldNamePrefix.charAt( 0 ) ) + fieldNamePrefix.substring( 1 ); for ( int i = 0; i < MAX_FIELDS; i++ ) { - builder.add( notNullPrefix + i, null, k ); + builder.add( null, notNullPrefix + i, null, k ); } return rexBuilder.makeDynamicParam( builder.build(), 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 f937c58670..08e97cc5ce 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -403,7 +403,7 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy for ( ProposedRoutingPlan routingPlan : proposedRoutingPlans ) { AlgRoot routedRoot = routingPlan.getRoutedRoot(); AlgRoot parameterizedRoot; - if ( statement.getDataContext().getParameterValues().size() == 0 + if ( statement.getDataContext().getParameterValues().isEmpty() && (RuntimeConfig.PARAMETERIZE_DML.getBoolean() || !routedRoot.kind.belongsTo( Kind.DML )) ) { Pair parameterized = parameterize( routedRoot, parameterRowType ); parameterizedRoot = parameterized.left; @@ -919,7 +919,7 @@ public AlgNode visit( LogicalProject project ) { return super.visit( project ); } // TODO: Avoid copying stuff around - final AlgDataType compositeType = builder.getTypeFactory().createStructType( ctypes, columns ); + final AlgDataType compositeType = builder.getTypeFactory().createStructType( null, ctypes, columns ); final Values replacement = idx.getAsValues( statement.getTransaction().getXid(), builder, compositeType ); final LogicalProject rProject = new LogicalProject( replacement.getCluster(), @@ -976,19 +976,19 @@ private List route( AlgRoot logicalRoot, Statement statemen } for ( Router router : RoutingManager.getInstance().getRouters() ) { - try{ + try { List builders = router.route( logicalRoot, statement, queryInformation ); List plans = builders.stream() .map( builder -> new ProposedRoutingPlanImpl( builder, logicalRoot, queryInformation.getQueryHash(), router.getClass() ) ) .collect( Collectors.toList() ); proposedPlans.addAll( plans ); - } catch ( Throwable e ){ + } catch ( Throwable e ) { log.warn( String.format( "Router: %s was not able to route the query.", router.getClass().getSimpleName() ) ); // this should not be necessary but some of the routers fail loudly, which makes this necessary todo dl } - + } - - if ( proposedPlans.isEmpty() ){ + + if ( proposedPlans.isEmpty() ) { throw new GenericRuntimeException( "No router was able to route the query successfully." ); } @@ -1110,6 +1110,7 @@ private Pair parameterize( AlgRoot routedRoot, AlgDataType // parameterRowType AlgDataType newParameterRowType = statement.getTransaction().getTypeFactory().createStructType( + types.stream().map( t -> 1L ).collect( Collectors.toList() ), types, new AbstractList<>() { @Override 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 fddbc52633..996c86924c 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java +++ b/dbms/src/main/java/org/polypheny/db/processing/DataMigratorImpl.java @@ -238,11 +238,11 @@ private static LogicalLpgValues getLogicalLpgValues( AlgBuilder builder, PolyGra List fields = new ArrayList<>(); int index = 0; if ( !graph.getNodes().isEmpty() ) { - fields.add( new AlgDataTypeFieldImpl( "n", index, builder.getTypeFactory().createPolyType( PolyType.NODE ) ) ); + fields.add( new AlgDataTypeFieldImpl( 1L, "n", index, builder.getTypeFactory().createPolyType( PolyType.NODE ) ) ); index++; } if ( !graph.getEdges().isEmpty() ) { - fields.add( new AlgDataTypeFieldImpl( "e", index, builder.getTypeFactory().createPolyType( PolyType.EDGE ) ) ); + fields.add( new AlgDataTypeFieldImpl( 1L, "e", index, builder.getTypeFactory().createPolyType( PolyType.EDGE ) ) ); } return new LogicalLpgValues( builder.getCluster(), builder.getCluster().traitSetOf( ModelTrait.GRAPH ), graph.getNodes().values(), graph.getEdges().values(), ImmutableList.of(), new AlgRecordType( fields ) ); 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 200e5259c2..6007075a07 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 @@ -437,7 +437,7 @@ public AlgNode buildJoinedScan( Statement statement, AlgOptCluster cluster, Logi AllocationColumn placement = new ArrayList<>( partitionsColumnsPlacements.values() ).get( 0 ).get( 0 ); // todo dl: remove after RowType refactor if ( catalog.getSnapshot().getNamespace( placement.namespaceId ).orElseThrow().namespaceType == NamespaceType.DOCUMENT ) { - AlgDataType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "d", 0, cluster.getTypeFactory().createPolyType( PolyType.DOCUMENT ) ) ) ); + AlgDataType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( 1L, "d", 0, cluster.getTypeFactory().createPolyType( PolyType.DOCUMENT ) ) ) ); builder.push( new LogicalTransformer( node.getCluster(), List.of( node ), diff --git a/dbms/src/test/java/org/polypheny/db/type/PolyTypeUtilTest.java b/dbms/src/test/java/org/polypheny/db/type/PolyTypeUtilTest.java index 5040332281..572dba1b21 100644 --- a/dbms/src/test/java/org/polypheny/db/type/PolyTypeUtilTest.java +++ b/dbms/src/test/java/org/polypheny/db/type/PolyTypeUtilTest.java @@ -119,7 +119,7 @@ public void testTypesIsSameFamilyWithInconvertibleStructTypes() { private AlgDataType struct( AlgDataType... algDataTypes ) { final Builder builder = f.typeFactory.builder(); for ( int i = 0; i < algDataTypes.length; i++ ) { - builder.add( "field" + i, null, algDataTypes[i] ); + builder.add( null, "field" + i, null, algDataTypes[i] ); } return builder.build(); } 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 2e9c0bc374..4e6154fbdc 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 @@ -67,8 +67,6 @@ public class CottontailEntity extends PhysicalTable implements TranslatableEntit private final String physicalTableName; private final List physicalColumnNames; - private final List logicalColumnNames; - protected CottontailEntity( CottontailNamespace cottontailNamespace, @@ -76,6 +74,7 @@ protected CottontailEntity( PhysicalTable physical ) { super( physical.id, physical.allocationId, + physical.logicalId, physical.name, physical.columns, physical.namespaceId, @@ -85,7 +84,6 @@ protected CottontailEntity( this.cottontailNamespace = cottontailNamespace; this.table = physical; - this.logicalColumnNames = physical.getLogicalNames(); this.physicalSchemaName = physicalSchemaName; this.physicalTableName = physical.name; this.physicalColumnNames = physical.getColumnNames(); @@ -98,7 +96,7 @@ protected CottontailEntity( public String getPhysicalColumnName( String logicalColumnName ) { - return this.physicalColumnNames.get( this.logicalColumnNames.indexOf( logicalColumnName ) ); + return this.physicalColumnNames.get( this.table.columns.indexOf( logicalColumnName ) ); } 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 b1ad34613f..af0500f390 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 @@ -208,18 +208,7 @@ public void updateNamespace( String name, long id ) { @Override - public List refreshTable( long allocId ) { - PhysicalTable physical = storeCatalog.fromAllocation( allocId ); - storeCatalog.replacePhysical( new CottontailEntity( - this.currentNamespace, - this.dbName, - physical ) ); - return List.of( physical ); - } - - - @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocationWrapper ) { + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocationWrapper ) { context.getStatement().getTransaction().registerInvolvedAdapter( this ); /* Begin or continue Cottontail DB transaction. */ final long txId = this.wrapper.beginOrContinue( context.getStatement().getTransaction() ); @@ -253,8 +242,7 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio if ( !success ) { throw new GenericRuntimeException( "Unable to create table." ); } - refreshTable( allocationWrapper.table.id ); - + return List.of( table ); } @@ -376,7 +364,7 @@ public void addColumn( Context context, long allocId, LogicalColumn logicalColum this.wrapper.dropEntityBlocking( DropEntityMessage.newBuilder().setMetadata( Metadata.newBuilder().setTransactionId( txId ) ).setEntity( tableEntity ).build() ); // Update column placement physical table names - storeCatalog.replacePhysical( new PhysicalTable( table.id, table.allocationId, newPhysicalTableName, pColumns, table.namespaceId, table.namespaceName, table.adapterId ) ); + storeCatalog.replacePhysical( new PhysicalTable( table.id, table.allocationId, table.logicalId, newPhysicalTableName, pColumns, table.namespaceId, table.namespaceName, table.adapterId ) ); } @@ -438,7 +426,7 @@ public void dropColumn( Context context, long allocId, long columnId ) { } } ); - storeCatalog.replacePhysical( new PhysicalTable( table.id, table.allocationId, newPhysicalTableName, pColumns, table.namespaceId, table.namespaceName, table.adapterId ) ); + storeCatalog.replacePhysical( new PhysicalTable( table.id, table.allocationId, table.logicalId, newPhysicalTableName, pColumns, table.namespaceId, table.namespaceName, table.adapterId ) ); // Delete old table this.wrapper.dropEntityBlocking( DropEntityMessage.newBuilder().setMetadata( Metadata.newBuilder().setTransactionId( txId ) ).setEntity( tableEntity ).build() ); @@ -593,7 +581,7 @@ public void updateColumnType( Context context, long allocId, LogicalColumn newCo .setMetadata( Metadata.newBuilder().setTransactionId( txId ).build() ) .setEntity( tableEntity ).build() ); - storeCatalog.replacePhysical( new PhysicalTable( physicalTable.id, physicalTable.allocationId, newPhysicalTableName, pColumns, physicalTable.namespaceId, physicalTable.namespaceName, physicalTable.adapterId ) ); + storeCatalog.replacePhysical( new PhysicalTable( physicalTable.id, physicalTable.allocationId, physicalTable.logicalId, newPhysicalTableName, pColumns, physicalTable.namespaceId, physicalTable.namespaceName, physicalTable.adapterId ) ); } 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 cf725707cc..d6e2a8c642 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,7 +120,7 @@ public static class Translator { public Translator( CottontailImplementContext context, AlgDataType rowType ) { this.rowType = rowType; this.fieldNames = rowType.getFieldList().stream() - .map( it -> context.cottontailTable.getPhysicalColumnName( it.getName() ) ) + .map( AlgDataTypeField::getPhysicalName ) .collect( Collectors.toList() ); this.columnTypes = rowType.getFieldList().stream() .map( AlgDataTypeField::getType ) diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvEnumerator.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvEnumerator.java index 9f2e0867f4..922a0e6328 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvEnumerator.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvEnumerator.java @@ -60,7 +60,6 @@ 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.util.Pair; import org.polypheny.db.util.Source; @@ -145,6 +144,7 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, Li static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, List fieldTypes, Boolean stream ) { final List types = new ArrayList<>(); final List names = new ArrayList<>(); + final List ids = new ArrayList<>(); if ( stream ) { names.add( ROWTIME_COLUMN_NAME ); types.add( typeFactory.createPolyType( PolyType.TIMESTAMP ) ); @@ -177,6 +177,7 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, Li } names.add( name ); types.add( type ); + ids.add( null ); if ( fieldTypes != null ) { fieldTypes.add( fieldType ); } @@ -188,7 +189,7 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, Li names.add( "line" ); types.add( typeFactory.createPolyType( PolyType.VARCHAR ) ); } - return typeFactory.createStructType( Pair.zip( names, types ) ); + return typeFactory.createStructType( ids, types, names ); } diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSchema.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSchema.java index dce45b2017..24d8ac95f9 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSchema.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSchema.java @@ -82,7 +82,7 @@ public CsvSchema( long id, URL directoryUrl, CsvTable.Flavor flavor ) { } - public PhysicalTable createCsvTable( long id, PhysicalTable table, CsvSource csvSource ) { + public CsvTable createCsvTable( long id, PhysicalTable table, CsvSource csvSource ) { final AlgDataTypeFactory typeFactory = new PolyTypeFactoryImpl( AlgDataTypeSystem.DEFAULT ); final AlgDataTypeFactory.Builder fieldInfo = typeFactory.builder(); List fieldTypes = new LinkedList<>(); @@ -92,7 +92,7 @@ public PhysicalTable createCsvTable( long id, PhysicalTable table, CsvSource csv for ( PhysicalColumn column : table.getColumns() ) { AlgDataType sqlType = sqlType( typeFactory, column.type, column.length, column.scale, null ); - fieldInfo.add( column.name, columns.get( column.position - 1 ).physicalColumnName, sqlType ).nullable( column.nullable ); + fieldInfo.add( column.id, column.name, columns.get( column.position - 1 ).physicalColumnName, sqlType ).nullable( column.nullable ); fieldTypes.add( CsvFieldType.getCsvFieldType( column.type ) ); fieldIds.add( column.position ); } diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java index 213190524b..83812ad096 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java @@ -115,26 +115,20 @@ public void updateNamespace( String name, long id ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 ); - } + CsvTable physical = currentNamespace.createCsvTable( table.id, table, this ); - @Override - public List refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - throw new GenericRuntimeException( "physical not found" ); - } - storeCatalog.replacePhysical( currentNamespace.createCsvTable( table.id, table, this ) ); - return List.of( table ); + storeCatalog.replacePhysical( physical ); + + return List.of( physical ); } diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTable.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTable.java index c7cf88e440..dc3508edd5 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTable.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvTable.java @@ -56,6 +56,7 @@ public abstract class CsvTable extends PhysicalTable { super( id, table.allocationId, + table.logicalId, table.name, table.columns, table.namespaceId, 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 4f27f2d84c..6c65e03aa8 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 @@ -67,7 +67,7 @@ public void getUnwind( CypherContext context ) { if ( expression.getType() == ExpressionType.LITERAL && ((CypherLiteral) expression).getLiteralType() == Literal.NULL ) { // special case, this is equal to empty list AlgDataType type = context.typeFactory.createArrayType( context.typeFactory.createPolyType( PolyType.ANY ), -1 ); - AlgDataType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( variable.getName(), 0, type ) ) ); + AlgDataType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, variable.getName(), 0, type ) ) ); RexLiteral emptyList = (RexLiteral) context.rexBuilder.makeLiteral( ComparableList.of(), type, false ); 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 c401eb0968..08fa9b46da 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 @@ -657,7 +657,7 @@ public AlgNode asValues( List> nameAndValues ) { List fields = new ArrayList<>(); int i = 0; for ( Pair nameAndValue : nameAndValues ) { - fields.add( new AlgDataTypeFieldImpl( nameAndValue.left.value, i, nameAndValue.right.getType() ) ); + fields.add( new AlgDataTypeFieldImpl( -1L, nameAndValue.left.value, i, nameAndValue.right.getType() ) ); i++; } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java index 8dc3eef60f..111ae33e13 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherExpression.java @@ -124,7 +124,7 @@ public Pair getValues( CypherContext context, String name ) if ( namedNode.right.isA( Kind.LITERAL ) ) { ImmutableList> values = ImmutableList.of( ImmutableList.of( (RexLiteral) namedNode.right ) ); - AlgRecordType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( name, 0, namedNode.right.getType() ) ) ); + AlgRecordType rowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, name, 0, namedNode.right.getType() ) ) ); LogicalLpgValues node = LogicalLpgValues.create( context.cluster, context.cluster.traitSet(), rowType, values ); context.add( node ); diff --git a/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumNamespace.java b/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumNamespace.java index 05b1e40087..d3d52fe630 100644 --- a/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumNamespace.java +++ b/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumNamespace.java @@ -53,7 +53,7 @@ public EthereumTable createBlockchainTable( PhysicalTable table, EthereumDataSou List fieldIds = new ArrayList<>( table.columns.size() ); for ( PhysicalColumn column : table.columns ) { AlgDataType sqlType = sqlType( typeFactory, column.type, column.length, column.scale, null ); - fieldInfo.add( column.logicalName, column.name, sqlType ).nullable( column.nullable ); + fieldInfo.add( column.id, column.name, column.name, sqlType ).nullable( column.nullable ); fieldTypes.add( EthereumFieldType.getBlockchainFieldType( column.type ) ); fieldIds.add( column.position ); } diff --git a/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumPlugin.java b/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumPlugin.java index 8b80159a0f..c1142f532c 100644 --- a/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumPlugin.java +++ b/plugins/ethereum-adapter/src/main/java/org/polypheny/db/adapter/ethereum/EthereumPlugin.java @@ -135,26 +135,20 @@ public void updateNamespace( String name, long id ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 ); - } + EthereumTable physical = currentNamespace.createBlockchainTable( table, this ); - @Override - public List refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - throw new GenericRuntimeException( "Could not find physical" ); - } - storeCatalog.replacePhysical( currentNamespace.createBlockchainTable( table, this ) ); - return List.of( table ); + storeCatalog.replacePhysical( physical ); + + return List.of( physical ); } 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 5e3382c608..f16e48c24b 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 @@ -17,7 +17,6 @@ package org.polypheny.db.adapter.ethereum; import java.math.BigInteger; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; @@ -28,13 +27,11 @@ import org.polypheny.db.adapter.ethereum.EthereumPlugin.EthereumDataSource; 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.catalog.entity.physical.PhysicalTable; import org.polypheny.db.rex.RexNode; import org.polypheny.db.schema.types.FilterableEntity; import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.util.Pair; public class EthereumTable extends PhysicalTable implements FilterableEntity { @@ -56,6 +53,7 @@ public EthereumTable( EthereumDataSource ethereumDataSource ) { super( table.id, table.allocationId, + table.logicalId, table.name, table.columns, table.namespaceId, @@ -72,13 +70,7 @@ public EthereumTable( @Override public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - final List types = new ArrayList<>(); - final List names = new ArrayList<>(); - for ( AlgDataTypeField field : this.protoRowType.apply( typeFactory ).getFieldList() ) { - types.add( field.getType() ); - names.add( field.getName() ); - } - return typeFactory.createStructType( Pair.zip( names, types ) ); + return typeFactory.createStructType( this.protoRowType.apply( typeFactory ).getFieldList() ); } diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelEnumerator.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelEnumerator.java index 35e0b28cbb..0e1fa940cc 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelEnumerator.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelEnumerator.java @@ -53,7 +53,6 @@ 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.util.Pair; import org.polypheny.db.util.Source; class ExcelEnumerator implements Enumerator { @@ -135,10 +134,12 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, St static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, List fieldTypes, Boolean stream ) { final List types = new ArrayList<>(); final List names = new ArrayList<>(); + final List ids = new ArrayList<>(); if ( stream ) { names.add( ROWTIME_COLUMN_NAME ); types.add( typeFactory.createPolyType( PolyType.TIMESTAMP ) ); + ids.add( null ); } try { Iterator rows = openExcel( source, "" ); @@ -148,6 +149,7 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, Li while ( cellIterator.hasNext() ) { Cell cell = cellIterator.next(); names.add( cell.getStringCellValue() ); + ids.add( null ); } break; } @@ -177,8 +179,9 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, Li if ( names.isEmpty() ) { names.add( "line" ); types.add( typeFactory.createPolyType( PolyType.VARCHAR ) ); + ids.add( null ); } - return typeFactory.createStructType( Pair.zip( names, types ) ); + return typeFactory.createStructType( ids, types, names ); } @@ -188,10 +191,12 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, Li static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, String sheetname, List fieldTypes, Boolean stream ) { final List types = new ArrayList<>(); final List names = new ArrayList<>(); + final List ids = new ArrayList<>(); if ( stream ) { names.add( ROWTIME_COLUMN_NAME ); types.add( typeFactory.createPolyType( PolyType.TIMESTAMP ) ); + ids.add( null ); } try { Iterator rows = openExcel( source, sheetname ); @@ -201,6 +206,7 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, St while ( cellIterator.hasNext() ) { Cell cell = cellIterator.next(); names.add( cell.getStringCellValue() ); + ids.add( null ); } break; } @@ -231,7 +237,7 @@ static AlgDataType deduceRowType( JavaTypeFactory typeFactory, Source source, St names.add( "line" ); types.add( typeFactory.createPolyType( PolyType.VARCHAR ) ); } - return typeFactory.createStructType( Pair.zip( names, types ) ); + return typeFactory.createStructType( ids, types, names ); } diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelNamespace.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelNamespace.java index 1d76bb11ec..abb523de91 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelNamespace.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelNamespace.java @@ -70,11 +70,11 @@ public ExcelTable createExcelTable( PhysicalTable table, ExcelSource excelSource final AlgDataTypeFactory.Builder fieldInfo = typeFactory.builder(); List fieldTypes = new LinkedList<>(); List fieldIds = new ArrayList<>( table.columns.size() ); - for ( PhysicalColumn catalogColumn : table.columns ) { - AlgDataType sqlType = sqlType( typeFactory, catalogColumn.type, catalogColumn.length, catalogColumn.scale, null ); - fieldInfo.add( catalogColumn.logicalName, catalogColumn.name, sqlType ).nullable( catalogColumn.nullable ); - fieldTypes.add( ExcelFieldType.getExcelFieldType( catalogColumn.type ) ); - fieldIds.add( catalogColumn.position ); + for ( PhysicalColumn column : table.columns ) { + AlgDataType sqlType = sqlType( typeFactory, column.type, column.length, column.scale, null ); + fieldInfo.add( column.id, column.name, column.name, sqlType ).nullable( column.nullable ); + fieldTypes.add( ExcelFieldType.getExcelFieldType( column.type ) ); + fieldIds.add( column.position ); } String excelFileName = excelSource.sheetName; diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java index 04bfbb26fe..254595a341 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java @@ -134,26 +134,20 @@ public void updateNamespace( String name, long id ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 ); - } + ExcelTable physical = currentNamespace.createExcelTable( table, this ); - @Override - public List refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - throw new GenericRuntimeException( "Could not find physicals" ); - } - storeCatalog.replacePhysical( currentNamespace.createExcelTable( table, this ) ); - return List.of( table ); + storeCatalog.replacePhysical( physical ); + + return List.of( physical ); } diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTable.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTable.java index bcf0c0f702..22fec7cb4c 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTable.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelTable.java @@ -41,6 +41,7 @@ public class ExcelTable extends PhysicalTable { ExcelTable( PhysicalTable table, Source source, AlgProtoDataType protoRowType, List fieldTypes, int[] fields, ExcelSource excelSource, String sheet ) { super( table.id, table.allocationId, + table.logicalId, table.name, table.columns, table.namespaceId, diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java index c410f4684d..38f0f0af49 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java @@ -190,15 +190,7 @@ public void updateNamespace( String name, long id ) { @Override - public List refreshTable( long allocId ) { - PhysicalTable physical = storeCatalog.fromAllocation( allocId ); - storeCatalog.replacePhysical( currentNamespace.createFileTable( physical ) ); - return List.of( physical ); - } - - - @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocationWrapper ) { + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocationWrapper ) { context.getStatement().getTransaction().registerInvolvedAdapter( this ); String physicalTableName = getPhysicalTableName( allocationWrapper.table.id ); @@ -217,7 +209,10 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio } } - refreshTable( allocationWrapper.table.id ); + FileTranslatableEntity physical = currentNamespace.createFileTable( table ); + + storeCatalog.replacePhysical( physical ); + return List.of( physical ); } 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 e526e623d0..2c424c519b 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 @@ -62,6 +62,7 @@ public FileTranslatableEntity( final List pkIds ) { super( physical.id, physical.allocationId, + physical.logicalId, physical.name, physical.columns, physical.namespaceId, diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java index 4cdeaeed29..07e877764b 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.StringJoiner; +import java.util.stream.Collectors; import lombok.Getter; import lombok.experimental.Delegate; import lombok.extern.slf4j.Slf4j; @@ -41,6 +42,7 @@ import org.polypheny.db.adapter.RelationalScanDelegate; import org.polypheny.db.adapter.annotations.AdapterProperties; import org.polypheny.db.adapter.annotations.AdapterSettingString; +import org.polypheny.db.adapter.file.FileTranslatableEntity; import org.polypheny.db.catalog.catalogs.RelStoreCatalog; import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper; import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper; @@ -69,7 +71,7 @@ public class Qfs extends DataSource { @Delegate(excludes = Exclude.class) - private RelationalScanDelegate delegate; + private final RelationalScanDelegate delegate; @Getter private File rootDir; @@ -101,20 +103,21 @@ public void updateNamespace( String name, long id ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { //Todo - } - - - @Override - public List refreshTable( long allocId ) { - PhysicalTable physical = storeCatalog.fromAllocation( allocId ); - storeCatalog.replacePhysical( currentNamespace.createFileTable( physical ) ); + PhysicalTable table = storeCatalog.createTable( + logical.table.getNamespaceName(), + logical.getTable().name, + logical.columns.stream().collect( Collectors.toMap( c -> c.id, c -> c.name ) ), + logical.table, + logical.columns.stream().collect( Collectors.toMap( c -> c.id, c -> c ) ), + allocation ); + FileTranslatableEntity physical = currentNamespace.createFileTable( table ); + storeCatalog.replacePhysical( physical ); return List.of( physical ); } - @Override public void dropTable( Context context, long allocId ) { throw new NotImplementedException();//Todo diff --git a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetNamespace.java b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetNamespace.java index 49f879d476..12da4828ed 100644 --- a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetNamespace.java +++ b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetNamespace.java @@ -70,7 +70,7 @@ public PhysicalTable createGoogleSheetTable( PhysicalTable table, GoogleSheetSou for ( PhysicalColumn column : table.columns ) { AlgDataType sqlType = sqlType( typeFactory, column.type, column.length, column.scale, null ); - fieldInfo.add( column.logicalName, column.name, sqlType ).nullable( column.nullable ); + fieldInfo.add( column.id, column.name, column.name, sqlType ).nullable( column.nullable ); fieldTypes.add( GoogleSheetFieldType.getGoogleSheetFieldType( column.type ) ); fieldIds.add( column.position ); } diff --git a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetSource.java b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetSource.java index 9501bba637..f8a9319ec6 100644 --- a/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetSource.java +++ b/plugins/google-sheet-adapter/src/main/java/org/polypheny/db/adapter/googlesheet/GoogleSheetSource.java @@ -336,24 +336,14 @@ public void truncate( Context context, long allocId ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 List refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - throw new GenericRuntimeException( "Could no find physical" ); - } storeCatalog.replacePhysical( currentNamespace.createGoogleSheetTable( table, this ) ); return List.of( table ); } 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 6ff5c1d99d..9ace5494a5 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 @@ -17,7 +17,6 @@ package org.polypheny.db.adapter.googlesheet; import java.net.URL; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.calcite.linq4j.AbstractEnumerable; @@ -29,14 +28,12 @@ import org.polypheny.db.algebra.AlgNode; 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.catalog.entity.physical.PhysicalTable; import org.polypheny.db.plan.AlgOptEntity.ToAlgContext; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.schema.types.TranslatableEntity; import org.polypheny.db.type.entity.PolyValue; -import org.polypheny.db.util.Pair; /** @@ -64,6 +61,7 @@ public GoogleSheetTable( List fieldTypes ) { super( table.id, table.allocationId, + table.logicalId, table.name, table.columns, table.namespaceId, @@ -86,13 +84,7 @@ public String toString() { @Override public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { - final List types = new ArrayList<>(); - final List names = new ArrayList<>(); - for ( AlgDataTypeField field : this.protoRowType.apply( typeFactory ).getFieldList() ) { - types.add( field.getType() ); - names.add( field.getName() ); - } - return typeFactory.createStructType( Pair.zip( names, types ) ); + return typeFactory.createStructType( this.protoRowType.apply( typeFactory ).getFieldList() ); } 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 8e3cab0528..938be3667c 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 @@ -105,6 +105,7 @@ public JdbcTable( super( physical.id, physical.allocationId, + physical.logicalId, physical.name, physical.columns, physical.namespaceId, @@ -165,11 +166,10 @@ public SqlIdentifier physicalTableName() { public SqlNodeList getNodeList() { List pcnl = Expressions.list(); - int i = 0; for ( PhysicalColumn column : columns ) { SqlNode[] operands = new SqlNode[]{ new SqlIdentifier( Arrays.asList( namespaceName, name, column.name ), ParserPos.ZERO ), - new SqlIdentifier( Collections.singletonList( column.logicalName ), ParserPos.ZERO ) + new SqlIdentifier( Collections.singletonList( column.name ), ParserPos.ZERO ) }; pcnl.add( new SqlBasicCall( (SqlOperator) OperatorRegistry.get( OperatorName.AS ), operands, ParserPos.ZERO ) ); } 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 ae5b592fd2..d61189bd61 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 @@ -519,7 +519,7 @@ private SqlNodeList identifierList( List names ) { * Converts a list of names expressions to a list of single-part {@link SqlIdentifier}s. */ private SqlNodeList physicalIdentifierList( JdbcTable entity, List columnNames ) { - return new SqlNodeList( entity.columns.stream().filter( c -> columnNames.contains( c.logicalName ) ).map( c -> new SqlIdentifier( c.name, ParserPos.ZERO ) ).collect( Collectors.toList() ), POS ); + return new SqlNodeList( entity.columns.stream().map( c -> new SqlIdentifier( c.name, ParserPos.ZERO ) ).collect( Collectors.toList() ), POS ); } diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java index 9c1f76cc6d..55f8221e72 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/stores/AbstractJdbcStore.java @@ -29,6 +29,7 @@ import org.polypheny.db.adapter.DeployMode; import org.polypheny.db.adapter.RelationalModifyDelegate; import org.polypheny.db.adapter.jdbc.JdbcSchema; +import org.polypheny.db.adapter.jdbc.JdbcTable; import org.polypheny.db.adapter.jdbc.JdbcUtils; import org.polypheny.db.adapter.jdbc.connection.ConnectionFactory; import org.polypheny.db.adapter.jdbc.connection.ConnectionHandlerException; @@ -141,7 +142,7 @@ public Namespace getCurrentNamespace() { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocationWrapper ) { + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocationWrapper ) { AllocationTable allocation = allocationWrapper.table; String namespaceName = getDefaultPhysicalSchemaName(); String tableName = getPhysicalTableName( allocation.id, 0 ); @@ -160,6 +161,10 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio allocationWrapper ); executeCreateTable( context, table ); + + JdbcTable physical = this.currentJdbcSchema.createJdbcTable( storeCatalog, table ); + storeCatalog.replacePhysical( physical ); + return List.of( physical ); } @@ -175,14 +180,6 @@ private void executeCreateTable( Context context, PhysicalTable table ) { } - @Override - public List refreshTable( long allocId ) { - PhysicalTable physical = storeCatalog.fromAllocation( allocId ); - storeCatalog.addPhysical( storeCatalog.getAlloc( allocId ), this.currentJdbcSchema.createJdbcTable( storeCatalog, physical ) ); - return List.of( physical ); - } - - protected StringBuilder buildCreateTableQuery( PhysicalTable table ) { StringBuilder builder = new StringBuilder(); builder.append( "CREATE TABLE " ) 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 index 0de33b1ac5..9da2302311 100644 --- 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 @@ -145,13 +145,12 @@ public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) { 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" ) ); + 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" ) ); } diff --git a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java index c5606f224b..ee4e3d4bb2 100644 --- a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java +++ b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java @@ -27,11 +27,14 @@ import org.polypheny.db.adapter.annotations.AdapterProperties; import org.polypheny.db.adapter.annotations.AdapterSettingInteger; import org.polypheny.db.adapter.annotations.AdapterSettingString; +import org.polypheny.db.adapter.jdbc.JdbcTable; import org.polypheny.db.adapter.jdbc.connection.ConnectionFactory; import org.polypheny.db.adapter.jdbc.connection.TransactionalConnectionFactory; 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.PhysicalEntity; +import org.polypheny.db.catalog.entity.physical.PhysicalTable; import org.polypheny.db.prepare.Context; import org.polypheny.db.sql.language.SqlDialect; import org.polypheny.db.sql.language.dialect.MonetdbSqlDialect; @@ -108,14 +111,20 @@ protected boolean requiresSchema() { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 ); + + JdbcTable physical = currentJdbcSchema.createJdbcTable( storeCatalog, table ); + + storeCatalog.replacePhysical( physical ); + + return List.of( physical ); } } 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 cc1983541f..102f87d256 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 @@ -131,7 +131,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.name, physical.namespaceId, physical.namespaceName, physical.namespaceType, physical.adapterId ); + super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.namespaceId, physical.namespaceName, physical.namespaceType, physical.adapterId ); this.physical = physical; this.mongoNamespace = namespace; this.transactionProvider = transactionProvider; @@ -366,7 +366,7 @@ public MongoQueryable asQueryable( DataContext dataContext, Snapsho @Override public PhysicalEntity normalize() { - return new PhysicalCollection( id, allocationId, namespaceId, name, namespaceName, adapterId ); + return new PhysicalCollection( id, allocationId, logicalId, namespaceId, name, namespaceName, adapterId ); } 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 d3d402007b..0d762f0c03 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 @@ -309,7 +309,7 @@ protected void reloadSettings( List updatedSettings ) { @Override - public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { + public List createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) { commitAll(); String name = getPhysicalTableName( allocation.id, adapterId ); @@ -318,7 +318,7 @@ public void createCollection( Context context, LogicalCollection logical, Alloca storeCatalog.addNamespace( allocation.namespaceId, currentNamespace ); } - PhysicalCollection physical = storeCatalog.createCollection( + PhysicalCollection table = storeCatalog.createCollection( logical.getNamespaceName(), name, logical, @@ -326,16 +326,10 @@ public void createCollection( Context context, LogicalCollection logical, Alloca this.currentNamespace.database.createCollection( name ); - this.storeCatalog.addPhysical( allocation, this.currentNamespace.createEntity( physical, List.of() ) ); - - } + MongoEntity physical = this.currentNamespace.createEntity( table, List.of() ); + this.storeCatalog.addPhysical( allocation, physical ); - @Override - public List refreshCollection( long allocId ) { - PhysicalEntity physical = storeCatalog.fromAllocation( allocId, PhysicalEntity.class ); - List fields = storeCatalog.getFields( allocId ); - storeCatalog.replacePhysical( this.currentNamespace.createEntity( physical, fields ) ); return List.of( physical ); } @@ -606,7 +600,7 @@ public AlgNode getDocModify( long allocId, DocumentModify modify, AlgBuilder @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { commitAll(); if ( this.currentNamespace == null ) { @@ -624,10 +618,10 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio allocation ); this.storeCatalog.addPhysical( allocation.table, this.currentNamespace.createEntity( physical, physical.columns ) ); + return refreshTable( allocation.table.id ); } - @Override public List refreshTable( long allocId ) { PhysicalEntity physical = storeCatalog.fromAllocation( allocId, PhysicalEntity.class ); List fields = storeCatalog.getFields( allocId ); diff --git a/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java b/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java index 0d7ae466a5..ae853d7161 100644 --- a/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java +++ b/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java @@ -33,7 +33,6 @@ import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper; 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.plugins.PluginContext; import org.polypheny.db.plugins.PolyPlugin; import org.polypheny.db.prepare.Context; @@ -97,26 +96,20 @@ public MysqlSource( long storeId, String uniqueName, final Map s @Override - public List refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - throw new GenericRuntimeException( "Could not find physical" ); - } - storeCatalog.replacePhysical( currentJdbcSchema.createJdbcTable( storeCatalog, table ) ); - return List.of( table ); - } - - - @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 ); + + JdbcTable physical = currentJdbcSchema.createJdbcTable( storeCatalog, table ); + + storeCatalog.replacePhysical( physical ); + + return List.of( physical ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java index 78d32cd46e..345486d706 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java @@ -283,7 +283,7 @@ public void executeDdlTrx( PolyXid session, String query ) { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { if ( this.currentNamespace == null ) { updateNamespace( DEFAULT_DATABASE, allocation.table.id ); storeCatalog.addNamespace( allocation.table.namespaceId, currentNamespace ); @@ -300,11 +300,10 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio allocation ); this.storeCatalog.addPhysical( allocation.table, this.currentNamespace.createEntity( physical, physical.columns, currentNamespace ) ); - + return refreshTable( allocation.table.id ); } - @Override public List refreshTable( long allocId ) { PhysicalEntity physical = storeCatalog.fromAllocation( allocId, PhysicalEntity.class ); List fields = storeCatalog.getFields( allocId ); @@ -486,7 +485,7 @@ public void truncate( Context context, long allocId ) { @Override - public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { + public List createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) { String mappingLabel = getMappingLabel( allocation.id ); PhysicalGraph physical = storeCatalog.createGraph( getPhysicalGraphName( allocation.id ), @@ -494,10 +493,10 @@ public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ); this.storeCatalog.addPhysical( allocation, new NeoGraph( physical, List.of(), this.transactionProvider, this.db, getMappingLabel( physical.id ), this ) ); + return refreshGraph( allocation.id ); } - @Override public List refreshGraph( long allocId ) { PhysicalGraph physical = storeCatalog.fromAllocation( allocId, PhysicalGraph.class ); storeCatalog.replacePhysical( new NeoGraph( physical, List.of(), this.transactionProvider, this.db, getMappingLabel( physical.id ), 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 1f829a5548..56f21deccf 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 @@ -73,7 +73,7 @@ public class NeoEntity extends PhysicalEntity implements TranslatableEntity, Mod protected NeoEntity( PhysicalEntity physical, List fields, NeoNamespace namespace ) { - super( physical.id, physical.allocationId, physical.name, physical.namespaceId, physical.namespaceName, physical.namespaceType, physical.adapterId ); + super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.namespaceId, physical.namespaceName, physical.namespaceType, physical.adapterId ); this.rowType = physical.getRowType(); this.fields = fields; this.namespace = namespace; @@ -150,7 +150,7 @@ public NeoQueryable asQueryable( DataContext dataContext, Snapshot snapshot ) { @Override public PhysicalEntity normalize() { - return new PhysicalGraph( id, allocationId, name, adapterId ); + return new PhysicalGraph( id, allocationId, logicalId, name, adapterId ); } 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 02d287733b..ae009036dc 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 @@ -88,7 +88,7 @@ public class NeoGraph extends PhysicalGraph implements TranslatableEntity, Modif public NeoGraph( PhysicalEntity physical, List fields, TransactionProvider transactionProvider, Driver db, String mappingLabel, Neo4jStore store ) { - super( physical.id, physical.allocationId, physical.name, physical.adapterId ); + super( physical.id, physical.allocationId, physical.logicalId, physical.name, physical.adapterId ); this.transactionProvider = transactionProvider; this.db = db; this.mappingLabel = mappingLabel; diff --git a/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Handler.java b/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Handler.java index 0b2ce839ac..42f8ab268f 100644 --- a/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Handler.java +++ b/plugins/pig-language/src/main/java/org/polypheny/db/piglet/Handler.java @@ -35,6 +35,10 @@ import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.type.AlgDataType; @@ -51,11 +55,6 @@ import org.polypheny.db.type.PolyType; import org.polypheny.db.util.Pair; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * Walks over a Pig AST and calls the corresponding methods in a {@link PigAlgBuilder}. @@ -271,7 +270,7 @@ private RexLiteral item( PigNode pigNode, AlgDataType type ) { private AlgDataType toType( Ast.Schema schema ) { final AlgDataTypeFactory.Builder typeBuilder = builder.getTypeFactory().builder(); for ( Ast.FieldSchema fieldSchema : schema.fieldSchemaList ) { - typeBuilder.add( fieldSchema.id.value, null, toType( fieldSchema.type ) ); + typeBuilder.add( null, fieldSchema.id.value, null, toType( fieldSchema.type ) ); } return typeBuilder.build(); } @@ -327,7 +326,7 @@ private AlgDataType toType( Ast.TupleType type ) { final AlgDataTypeFactory typeFactory = builder.getTypeFactory(); final AlgDataTypeFactory.Builder builder = typeFactory.builder(); for ( Ast.FieldSchema fieldSchema : type.fieldSchemaList ) { - builder.add( fieldSchema.id.value, null, toType( fieldSchema.type ) ); + builder.add( null, fieldSchema.id.value, null, toType( fieldSchema.type ) ); } return builder.build(); } diff --git a/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java b/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java index 304dc96a3e..d3fc2d6ffe 100644 --- a/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java +++ b/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java @@ -32,7 +32,6 @@ import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper; 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.prepare.Context; import org.polypheny.db.sql.language.dialect.PostgresqlSqlDialect; @@ -102,24 +101,15 @@ protected boolean requiresSchema() { @Override - public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { - storeCatalog.createTable( + public List createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) { + PhysicalTable table = 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 List refreshTable( long allocId ) { - PhysicalTable table = storeCatalog.getTable( allocId ); - if ( table == null ) { - log.warn( "todo" ); - throw new GenericRuntimeException( "Could not find physical" ); - } storeCatalog.replacePhysical( currentJdbcSchema.createJdbcTable( storeCatalog, table ) ); return List.of( table ); } 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 22acc461f3..5d98d05551 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 @@ -80,13 +80,13 @@ public AlgDataType inferReturnType( OperatorBinding opBinding ) { assert type instanceof ArrayType || type instanceof MultisetPolyType || type instanceof MapPolyType; if ( type instanceof MapPolyType ) { - builder.add( UnnestOperator.MAP_KEY_COLUMN_NAME, null, type.unwrap( MapPolyType.class ).getKeyType() ); - builder.add( UnnestOperator.MAP_VALUE_COLUMN_NAME, null, type.unwrap( MapPolyType.class ).getValueType() ); + builder.add( null, UnnestOperator.MAP_KEY_COLUMN_NAME, null, type.unwrap( MapPolyType.class ).getKeyType() ); + builder.add( null, UnnestOperator.MAP_VALUE_COLUMN_NAME, null, type.unwrap( MapPolyType.class ).getValueType() ); } else { if ( type.getComponentType().isStruct() ) { builder.addAll( type.getComponentType().getFieldList() ); } else { - builder.add( CoreUtil.deriveAliasFromOrdinal( operand ), null, type.getComponentType() ); + builder.add( null, CoreUtil.deriveAliasFromOrdinal( operand ), null, type.getComponentType() ); } } } 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 b9bb6dd574..4e06adc32c 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 @@ -191,7 +191,7 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { @Override public void execute( Context context, Statement statement, QueryParameters parameters ) { if ( query != null ) { - throw new RuntimeException( "Not yet supported" ); + throw new GenericRuntimeException( "Not yet supported" ); } String tableName; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlRowOperator.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlRowOperator.java index 40907e1810..570b699aee 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlRowOperator.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/fun/SqlRowOperator.java @@ -18,9 +18,10 @@ import java.util.AbstractList; -import java.util.Map; 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.AlgDataTypeFieldImpl; import org.polypheny.db.nodes.OperatorBinding; import org.polypheny.db.nodes.RowOperator; import org.polypheny.db.sql.language.SqlCall; @@ -31,7 +32,6 @@ import org.polypheny.db.type.checker.OperandTypes; import org.polypheny.db.type.inference.InferTypes; import org.polypheny.db.util.CoreUtil; -import org.polypheny.db.util.Pair; /** @@ -66,11 +66,12 @@ public SqlSyntax getSqlSyntax() { public AlgDataType inferReturnType( final OperatorBinding opBinding ) { // The type of a ROW(e1,e2) expression is a record with the types {e1type,e2type}. According to the standard, field names are implementation-defined. return opBinding.getTypeFactory().createStructType( - new AbstractList>() { + new AbstractList<>() { @Override - public Map.Entry get( int index ) { - return Pair.of( + public AlgDataTypeField get( int index ) { + return new AlgDataTypeFieldImpl( -1L, CoreUtil.deriveAliasFromOrdinal( index ), + index, opBinding.getOperandType( index ) ); } 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 f5ffe05189..bf8fa5f6fd 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 @@ -238,7 +238,7 @@ protected AlgDataType toStruct( AlgDataType type, SqlNode unnest ) { return type; } return validator.getTypeFactory().builder() - .add( validator.deriveAlias( unnest, 0 ), null, type ) + .add( null, validator.deriveAlias( unnest, 0 ), null, type ) .build(); } 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 7b53c3898c..a0dca69806 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 @@ -82,7 +82,7 @@ protected AlgDataType validateImpl( AlgDataType targetRowType ) { for ( AlgDataTypeField field : rowType.getFieldList() ) { typeList.add( field.getType() ); } - return validator.getTypeFactory().createStructType( typeList, nameList ); + return validator.getTypeFactory().createStructType( null, typeList, nameList ); } 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 6d6b829425..9f9c9ec187 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 @@ -67,6 +67,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.algebra.type.AlgDataTypeFieldImpl; import org.polypheny.db.algebra.type.AlgDataTypeSystem; import org.polypheny.db.algebra.type.AlgRecordType; import org.polypheny.db.algebra.type.DynamicRecordType; @@ -358,7 +359,7 @@ public AlgDataType getUnknownType() { @Override public SqlNodeList expandStar( SqlNodeList selectList, SqlSelect select, boolean includeSystemVars ) { final List list = new ArrayList<>(); - final List> types = new ArrayList<>(); + final List types = new ArrayList<>(); for ( int i = 0; i < selectList.size(); i++ ) { final SqlNode selectItem = (SqlNode) selectList.get( i ); final AlgDataType originalType = getValidatedNodeTypeIfKnown( selectItem ); @@ -431,7 +432,7 @@ public String getParentCursor( String columnListParamName ) { * @param includeSystemVars If true include system vars in lists * @return Whether the node was expanded */ - private boolean expandSelectItem( final SqlNode selectItem, SqlSelect select, AlgDataType targetType, List selectItems, Set aliases, List> fields, final boolean includeSystemVars ) { + private boolean expandSelectItem( final SqlNode selectItem, SqlSelect select, AlgDataType targetType, List selectItems, Set aliases, List fields, final boolean includeSystemVars ) { final SelectScope scope = (SelectScope) getWhereScope( select ); if ( expandStar( selectItems, aliases, fields, includeSystemVars, scope, selectItem ) ) { return true; @@ -463,12 +464,12 @@ private boolean expandSelectItem( final SqlNode selectItem, SqlSelect select, Al } final AlgDataType type = deriveType( selectScope, expanded ); setValidatedNodeType( expanded, type ); - fields.add( Pair.of( alias, type ) ); + fields.add( new AlgDataTypeFieldImpl( 1L, alias, 0, type ) ); return false; } - private boolean expandStar( List selectItems, Set aliases, List> fields, boolean includeSystemVars, SelectScope scope, SqlNode node ) { + private boolean expandStar( List selectItems, Set aliases, List fields, boolean includeSystemVars, SelectScope scope, SqlNode node ) { if ( !(node instanceof SqlIdentifier) ) { return false; } @@ -529,7 +530,7 @@ private boolean expandStar( List selectItems, Set aliases, List final Entry entry = fields.get( i ); final AlgDataType type = entry.getValue(); if ( !type.isNullable() ) { - fields.set( i, Pair.of( entry.getKey(), typeFactory.createTypeWithNullability( type, true ) ) ); + fields.set( i, new AlgDataTypeFieldImpl( 1L, entry.getKey(), i, typeFactory.createTypeWithNullability( type, true ) ) ); } } } @@ -588,7 +589,7 @@ private SqlNode maybeCast( SqlNode node, AlgDataType currentType, AlgDataType de } - private boolean addOrExpandField( List selectItems, Set aliases, List> fields, boolean includeSystemVars, SelectScope scope, SqlIdentifier id, AlgDataTypeField field ) { + private boolean addOrExpandField( List selectItems, Set aliases, List fields, boolean includeSystemVars, SelectScope scope, SqlIdentifier id, AlgDataTypeField field ) { switch ( field.getType().getStructKind() ) { case PEEK_FIELDS: case PEEK_FIELDS_DEFAULT: @@ -1513,7 +1514,7 @@ protected SqlSelect createSourceSelectForDelete( SqlDelete call ) { */ AlgDataType getTableConstructorRowType( SqlCall values, SqlValidatorScope scope ) { final List rows = values.getOperandList(); - assert rows.size() >= 1; + assert !rows.isEmpty(); final List rowTypes = new ArrayList<>(); for ( final Node row : rows ) { assert row.getKind() == Kind.ROW; @@ -1521,14 +1522,16 @@ AlgDataType getTableConstructorRowType( SqlCall values, SqlValidatorScope scope // REVIEW jvs: Once we support single-row queries as rows, need to infer aliases from there. final List aliasList = new ArrayList<>(); - final List typeList = new ArrayList<>(); + final List types = new ArrayList<>(); + final List ids = new ArrayList<>(); for ( Ord column : Ord.zip( rowConstructor.getOperandList() ) ) { final String alias = deriveAlias( (SqlNode) column.e, column.i ); aliasList.add( alias ); final AlgDataType type = deriveType( scope, column.e ); - typeList.add( type ); + types.add( type ); + ids.add( null ); } - rowTypes.add( typeFactory.createStructType( typeList, aliasList ) ); + rowTypes.add( typeFactory.createStructType( ids, types, aliasList ) ); } if ( rows.size() == 1 ) { // TODO jvs: Get rid of this workaround once leastRestrictive can handle all cases @@ -1772,13 +1775,13 @@ protected void inferUnknownTypes( @Nonnull AlgDataType inferredType, @Nonnull Sq /** * Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list. */ - protected void addToSelectList( List list, Set aliases, List> fieldList, SqlNode exp, SqlValidatorScope scope, final boolean includeSystemVars ) { + protected void addToSelectList( List list, Set aliases, List fieldList, SqlNode exp, SqlValidatorScope scope, final boolean includeSystemVars ) { String alias = SqlValidatorUtil.getAlias( exp, -1 ); String uniqueAlias = ValidatorUtil.uniquify( alias, aliases, ValidatorUtil.EXPR_SUGGESTER ); if ( !alias.equals( uniqueAlias ) ) { exp = (SqlNode) SqlValidatorUtil.addAlias( exp, uniqueAlias ); } - fieldList.add( Pair.of( uniqueAlias, deriveType( scope, exp ) ) ); + fieldList.add( new AlgDataTypeFieldImpl( 1L, uniqueAlias, fieldList.size(), deriveType( scope, exp ) ) ); list.add( exp ); } @@ -3891,7 +3894,7 @@ protected AlgDataType validateSelectList( final SqlNodeList selectItems, SqlSele final SqlValidatorScope selectScope = getSelectScope( select ); final List expandedSelectItems = new ArrayList<>(); final Set aliases = new HashSet<>(); - final List> fieldList = new ArrayList<>(); + final List fieldList = new ArrayList<>(); for ( int i = 0; i < selectItems.size(); i++ ) { Node selectItem = selectItems.get( i ); @@ -3966,7 +3969,7 @@ private void validateExpr( SqlNode expr, SqlValidatorScope scope ) { * @param aliasList built from user or system values * @param fieldList Built up entries for each select list entry */ - private void handleScalarSubQuery( SqlSelect parentSelect, SqlSelect selectItem, List expandedSelectItems, Set aliasList, List> fieldList ) { + private void handleScalarSubQuery( SqlSelect parentSelect, SqlSelect selectItem, List expandedSelectItems, Set aliasList, List fieldList ) { // A scalar sub-query only has one output column. if ( 1 != selectItem.getSqlSelectList().size() ) { throw newValidationError( selectItem, RESOURCE.onlyScalarSubQueryAllowed() ); @@ -3990,7 +3993,7 @@ private void handleScalarSubQuery( SqlSelect parentSelect, SqlSelect selectItem, AlgDataType nodeType = rec.getFieldList().get( 0 ).getType(); nodeType = typeFactory.createTypeWithNullability( nodeType, true ); - fieldList.add( Pair.of( alias, nodeType ) ); + fieldList.add( new AlgDataTypeFieldImpl( 1L, alias, 0, nodeType ) ); } @@ -4013,10 +4016,10 @@ protected AlgDataType createTargetRowType( CatalogEntity table, SqlNodeList targ return baseRowType; } List targetFields = baseRowType.getFieldList(); - final List> fields = new ArrayList<>(); + final List fields = new ArrayList<>(); if ( append ) { for ( AlgDataTypeField targetField : targetFields ) { - fields.add( Pair.of( CoreUtil.deriveAliasFromOrdinal( fields.size() ), targetField.getType() ) ); + fields.add( new AlgDataTypeFieldImpl( 1L, CoreUtil.deriveAliasFromOrdinal( fields.size() ), fields.size(), targetField.getType() ) ); } } final Set assignedFields = new HashSet<>(); @@ -4674,7 +4677,7 @@ public void validateMatchRecognize( SqlCall call ) { identifier.validate( this, scope ); AlgDataType type = deriveType( scope, identifier ); String name = identifier.names.get( 1 ); - typeBuilder.add( name, null, type ); + typeBuilder.add( null, name, null, type ); } } @@ -4694,7 +4697,7 @@ public void validateMatchRecognize( SqlCall call ) { AlgDataType type = deriveType( scope, identifier ); String name = identifier.names.get( 1 ); if ( !typeBuilder.nameExists( name ) ) { - typeBuilder.add( name, null, type ); + typeBuilder.add( null, name, null, type ); } } } @@ -4776,7 +4779,7 @@ public void validateMatchRecognize( SqlCall call ) { List> measureColumns = validateMeasure( matchRecognize, scope, allRows ); for ( Map.Entry c : measureColumns ) { if ( !typeBuilder.nameExists( c.getKey() ) ) { - typeBuilder.add( c.getKey(), null, c.getValue() ); + typeBuilder.add( null, c.getKey(), null, c.getValue() ); } } @@ -5107,8 +5110,8 @@ public SqlNode visit( DynamicParam param ) { } } ); return typeFactory.createStructType( - types, - new AbstractList() { + List.of(), + types, new AbstractList<>() { @Override public String get( int index ) { return "?" + index; @@ -6160,7 +6163,7 @@ private List usingNames( SqlJoin join ) { /** * Moves fields according to the permutation. */ - public void permute( List selectItems, List> fields ) { + public void permute( List selectItems, List fields ) { if ( trivial ) { return; } @@ -6192,7 +6195,7 @@ public void permute( List selectItems, List getExtendedColumns( AlgDataTypeFactory type for ( final Pair pair : pairs( extendedColumns ) ) { final SqlIdentifier identifier = pair.left; final SqlDataTypeSpec type = pair.right; - extendedFields.add( new AlgDataTypeFieldImpl( identifier.toString(), extendedFieldOffset++, type.deriveType( typeFactory ) ) ); + extendedFields.add( new AlgDataTypeFieldImpl( -1L, identifier.toString(), extendedFieldOffset++, type.deriveType( typeFactory ) ) ); } return extendedFields.build(); } @@ -286,7 +286,7 @@ public static AlgDataTypeField getTargetField( AlgDataType rowType, AlgDataTypeF AlgDataTypeField typeField = nameMatcher.field( rowType, id.getSimple() ); if ( typeField == null && isDocument ) { - return new AlgDataTypeFieldImpl( id.getSimple(), -1, new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.JSON, 300 ) ); + return new AlgDataTypeFieldImpl( -1L, id.getSimple(), -1, new BasicPolyType( AlgDataTypeSystem.DEFAULT, PolyType.JSON, 300 ) ); } return typeField; 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 f041103d43..e4c0356871 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 @@ -49,7 +49,7 @@ protected AlgDataType validateImpl( AlgDataType targetRowType ) { } final Builder builder = validator.getTypeFactory().builder(); for ( Pair pair : Pair.zip( withItem.columnList.getSqlList(), rowType.getFieldList() ) ) { - builder.add( ((SqlIdentifier) pair.left).getSimple(), null, pair.right.getType() ); + builder.add( null, ((SqlIdentifier) pair.left).getSimple(), null, pair.right.getType() ); } return builder.build(); } 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 b7ede83cc5..467afa056d 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 @@ -413,8 +413,8 @@ private void checkConvertedType( Node query, AlgNode result ) { List validatedFields = validator.getValidatedNodeType( query ).getFieldList(); // TODO DL readd final final AlgDataType validatedRowType = validator.getTypeFactory().createStructType( - Pair.right( validatedFields ), - ValidatorUtil.uniquify( + validatedFields.stream().map( AlgDataTypeField::getId ).collect( Collectors.toList() ), + Pair.right( validatedFields ), ValidatorUtil.uniquify( Pair.left( validatedFields ), false ) ); /*int diff = validatedFields.size() - result.getRowType().getFieldList().size(); @@ -3784,9 +3784,9 @@ public RexNode register( AlgNode alg, JoinAlgType joinType, List leftKe final int rexRangeRefLength = leftKeyCount + rightFieldLength; AlgDataType returnType = typeFactory.createStructType( - new AbstractList>() { + new AbstractList<>() { @Override - public Map.Entry get( int index ) { + public AlgDataTypeField get( int index ) { return join.getRowType() .getFieldList() .get( origLeftInputCount + index ); 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 00152d47f3..21cc9991db 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 @@ -474,7 +474,7 @@ protected RexNode convertCast( SqlRexContext cx, final SqlCall call ) { if ( argComponentType.isStruct() && !componentType.isStruct() ) { AlgDataType tt = typeFactory.builder() - .add( argComponentType.getFieldList().get( 0 ).getName(), null, componentType ) + .add( null, argComponentType.getFieldList().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/RexExecutorTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java index 2a58f34745..754cde2492 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java @@ -129,7 +129,7 @@ public void testVariableExecution() throws Exception { ImmutableList constExps = ImmutableList.of( substr ); final AlgDataType rowType = typeFactory.builder() - .add( "someStr", null, varchar ) + .add( null, "someStr", null, varchar ) .build(); final RexExecutable exec = executor.getExecutable( rexBuilder, constExps, rowType ); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexProgramTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexProgramTest.java index 9dac88ddc8..8488f019a1 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexProgramTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexProgramTest.java @@ -332,7 +332,7 @@ private RexProgramBuilder createProg( int variant ) { typeFactory.createPolyType( PolyType.INTEGER ), typeFactory.createPolyType( PolyType.INTEGER ) ); List names = Arrays.asList( "x", "y" ); - AlgDataType inputRowType = typeFactory.createStructType( types, names ); + AlgDataType inputRowType = typeFactory.createStructType( , types, names ); final RexProgramBuilder builder = new RexProgramBuilder( inputRowType, rexBuilder ); // $t0 = x // $t1 = y @@ -668,14 +668,14 @@ public void testCnf() { final AlgDataType booleanType = typeFactory.createPolyType( PolyType.BOOLEAN ); final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, booleanType ) - .add( "b", null, booleanType ) - .add( "c", null, booleanType ) - .add( "d", null, booleanType ) - .add( "e", null, booleanType ) - .add( "f", null, booleanType ) - .add( "g", null, booleanType ) - .add( "h", null, intType ) + .add( null, "a", null, booleanType ) + .add( null, "b", null, booleanType ) + .add( null, "c", null, booleanType ) + .add( null, "d", null, booleanType ) + .add( null, "e", null, booleanType ) + .add( null, "f", null, booleanType ) + .add( null, "g", null, booleanType ) + .add( null, "h", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -731,11 +731,11 @@ public void testCnf() { public void testCnf2() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "x", null, intType ) - .add( "y", null, intType ) - .add( "z", null, intType ) - .add( "a", null, intType ) - .add( "b", null, intType ) + .add( null, "x", null, intType ) + .add( null, "y", null, intType ) + .add( null, "z", null, intType ) + .add( null, "a", null, intType ) + .add( null, "b", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -801,8 +801,8 @@ public void testCnf2() { public void testThresholdCnf() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "x", null, intType ) - .add( "y", null, intType ) + .add( null, "x", null, intType ) + .add( null, "y", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -852,8 +852,8 @@ private void checkExponentialCnf( int n ) { final AlgDataType booleanType = typeFactory.createPolyType( PolyType.BOOLEAN ); final AlgDataTypeFactory.Builder builder = typeFactory.builder(); for ( int i = 0; i < n; i++ ) { - builder.add( "x" + i, null, booleanType ) - .add( "y" + i, null, booleanType ); + builder.add( null, "x" + i, null, booleanType ) + .add( null, "y" + i, null, booleanType ); } final AlgDataType rowType3 = builder.build(); final RexDynamicParam range3 = rexBuilder.makeDynamicParam( rowType3, 0 ); @@ -880,14 +880,14 @@ public void testPullFactors() { final AlgDataType booleanType = typeFactory.createPolyType( PolyType.BOOLEAN ); final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, booleanType ) - .add( "b", null, booleanType ) - .add( "c", null, booleanType ) - .add( "d", null, booleanType ) - .add( "e", null, booleanType ) - .add( "f", null, booleanType ) - .add( "g", null, booleanType ) - .add( "h", null, intType ) + .add( null, "a", null, booleanType ) + .add( null, "b", null, booleanType ) + .add( null, "c", null, booleanType ) + .add( null, "d", null, booleanType ) + .add( null, "e", null, booleanType ) + .add( null, "f", null, booleanType ) + .add( null, "g", null, booleanType ) + .add( null, "h", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -937,17 +937,17 @@ public void testSimplify() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType intNullableType = typeFactory.createTypeWithNullability( intType, true ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, booleanType ) - .add( "b", null, booleanType ) - .add( "c", null, booleanType ) - .add( "d", null, booleanType ) - .add( "e", null, booleanType ) - .add( "f", null, booleanType ) - .add( "g", null, booleanType ) - .add( "h", null, intType ) - .add( "i", null, intNullableType ) - .add( "j", null, intType ) - .add( "k", null, intType ) + .add( null, "a", null, booleanType ) + .add( null, "b", null, booleanType ) + .add( null, "c", null, booleanType ) + .add( null, "d", null, booleanType ) + .add( null, "e", null, booleanType ) + .add( null, "f", null, booleanType ) + .add( null, "g", null, booleanType ) + .add( null, "h", null, intType ) + .add( null, "i", null, intNullableType ) + .add( null, "j", null, intType ) + .add( null, "k", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -1170,14 +1170,14 @@ public void testSimplifyFilter() { final AlgDataType booleanType = typeFactory.createPolyType( PolyType.BOOLEAN ); final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, intType ) - .add( "b", null, intType ) - .add( "c", null, booleanType ) - .add( "d", null, booleanType ) - .add( "e", null, booleanType ) - .add( "f", null, booleanType ) - .add( "g", null, booleanType ) - .add( "h", null, intType ) + .add( null, "a", null, intType ) + .add( null, "b", null, intType ) + .add( null, "c", null, booleanType ) + .add( null, "d", null, booleanType ) + .add( null, "e", null, booleanType ) + .add( null, "f", null, booleanType ) + .add( null, "g", null, booleanType ) + .add( null, "h", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -1345,8 +1345,8 @@ public void testSimplifyFilter() { public void testSimplifyAndPush() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, intType ) - .add( "b", null, intType ) + .add( null, "a", null, intType ) + .add( null, "b", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -1406,9 +1406,9 @@ public void testSimplifyAndPush() { public void testSimplifyOrTerms() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, intType ).nullable( false ) - .add( "b", null, intType ).nullable( true ) - .add( "c", null, intType ).nullable( true ) + .add( null, "a", null, intType ).nullable( false ) + .add( null, "b", null, intType ).nullable( true ) + .add( null, "c", null, intType ).nullable( true ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -1499,7 +1499,7 @@ public void testSimplifyNotAnd() { public void testSimplifyUnknown() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, intType ).nullable( true ) + .add( null, "a", null, intType ).nullable( true ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -1543,7 +1543,7 @@ public void testSimplifyUnknown() { public void testSimplifyAnd3() { final AlgDataType boolType = typeFactory.createPolyType( PolyType.BOOLEAN ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, boolType ).nullable( true ) + .add( null, "a", null, boolType ).nullable( true ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); @@ -2058,11 +2058,11 @@ public boolean isDeterministic() { public void testConstantMap() { final AlgDataType intType = typeFactory.createPolyType( PolyType.INTEGER ); final AlgDataType rowType = typeFactory.builder() - .add( "a", null, intType ) - .add( "b", null, intType ) - .add( "c", null, intType ) - .add( "d", null, intType ) - .add( "e", null, intType ) + .add( null, "a", null, intType ) + .add( null, "b", null, intType ) + .add( null, "c", null, intType ) + .add( null, "d", null, intType ) + .add( null, "e", null, intType ) .build(); final RexDynamicParam range = rexBuilder.makeDynamicParam( rowType, 0 ); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/TestFixture.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/TestFixture.java index 12670caeaf..1776eb85bd 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/TestFixture.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/TestFixture.java @@ -126,18 +126,18 @@ public TestFixture() { str = ref( 11, stringDataType ); rowType = typeFactory.builder() - .add( "bool", null, this.boolRelDataType ) - .add( "int", null, intAlgDataType ) - .add( "dec", null, decRelDataType ) - .add( "long", null, longRelDataType ) - .add( "short", null, shortDataType ) - .add( "byte", null, byteDataType ) - .add( "float", null, floatDataType ) - .add( "char", null, charDataType ) - .add( "date", null, dateDataType ) - .add( "timestamp", null, timestampDataType ) - .add( "time", null, timeDataType ) - .add( "string", null, stringDataType ) + .add( null, "bool", null, this.boolRelDataType ) + .add( null, "int", null, intAlgDataType ) + .add( null, "dec", null, decRelDataType ) + .add( null, "long", null, longRelDataType ) + .add( null, "short", null, shortDataType ) + .add( null, "byte", null, byteDataType ) + .add( null, "float", null, floatDataType ) + .add( null, "char", null, charDataType ) + .add( null, "date", null, dateDataType ) + .add( null, "timestamp", null, timestampDataType ) + .add( null, "time", null, timeDataType ) + .add( null, "string", null, stringDataType ) .build(); final Holder holder = Holder.of( null ); diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/PlannerTests.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/PlannerTests.java index 14e609ca2d..9968b88f5a 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/PlannerTests.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/PlannerTests.java @@ -90,7 +90,7 @@ public AlgOptCost computeSelfCost( AlgOptPlanner planner, AlgMetadataQuery mq ) protected AlgDataType deriveRowType() { final AlgDataTypeFactory typeFactory = getCluster().getTypeFactory(); return typeFactory.builder() - .add( "this", null, typeFactory.createJavaType( Void.TYPE ) ) + .add( null, "this", null, typeFactory.createJavaType( Void.TYPE ) ) .build(); } 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 0d66179b50..f3bdf862dc 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 @@ -413,7 +413,7 @@ private static class PhysTable extends AbstractAlgNode implements Phys { AlgDataTypeFactory typeFactory = cluster.getTypeFactory(); final AlgDataType stringType = typeFactory.createJavaType( String.class ); final AlgDataType integerType = typeFactory.createJavaType( Integer.class ); - this.rowType = typeFactory.builder().add( "s", null, stringType ).add( "i", null, integerType ).build(); + this.rowType = typeFactory.builder().add( null, "s", null, stringType ).add( null, "i", null, integerType ).build(); } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/VolcanoPlannerTraitTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/VolcanoPlannerTraitTest.java index 63124b14e3..2a2dedd470 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/VolcanoPlannerTraitTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/volcano/VolcanoPlannerTraitTest.java @@ -387,7 +387,7 @@ public AlgOptCost computeSelfCost( AlgOptPlanner planner, AlgMetadataQuery mq ) protected AlgDataType deriveRowType() { final AlgDataTypeFactory typeFactory = getCluster().getTypeFactory(); return typeFactory.builder() - .add( "this", null, typeFactory.createJavaType( Void.TYPE ) ) + .add( null, "this", null, typeFactory.createJavaType( Void.TYPE ) ) .build(); } diff --git a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java index 62884440c4..a98b38ae5d 100644 --- a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java +++ b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java @@ -17,6 +17,7 @@ package org.polypheny.db.webui; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -90,6 +91,10 @@ public void run() { { setSerializationInclusion( JsonInclude.Include.NON_NULL ); configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); + setVisibility( getSerializationConfig().getDefaultVisibilityChecker() + .withIsGetterVisibility( Visibility.NONE ) + .withGetterVisibility( Visibility.NONE ) + .withSetterVisibility( Visibility.NONE ) ); configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false ); writerWithDefaultPrettyPrinter(); }