From ecb3b39aecbc2e621a9870c57d2128630f7a9679 Mon Sep 17 00:00:00 2001 From: datomo Date: Mon, 8 Apr 2024 14:55:44 +0200 Subject: [PATCH] added constraint validity test on create --- core/src/main/java/org/polypheny/db/ddl/DdlManager.java | 4 ++-- .../main/java/org/polypheny/db/ddl/DdlManagerImpl.java | 8 ++++++-- .../ddl/altertable/SqlAlterTableAddForeignKey.java | 3 ++- .../ddl/altertable/SqlAlterTableAddUniqueConstraint.java | 6 +++--- webui/src/main/java/org/polypheny/db/webui/Crud.java | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/ddl/DdlManager.java b/core/src/main/java/org/polypheny/db/ddl/DdlManager.java index bb7638e0da..68fca87dd6 100644 --- a/core/src/main/java/org/polypheny/db/ddl/DdlManager.java +++ b/core/src/main/java/org/polypheny/db/ddl/DdlManager.java @@ -179,7 +179,7 @@ public static DdlManager getInstance() { * @param onUpdate how to enforce the constraint on updated * @param onDelete how to enforce the constraint on delete */ - public abstract void createForeignKey( LogicalTable table, LogicalTable refTable, List columnNames, List refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete ); + public abstract void createForeignKey( LogicalTable table, LogicalTable refTable, List columnNames, List refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete, Statement statement ); /** * Adds an index to a table @@ -234,7 +234,7 @@ public static DdlManager getInstance() { * @param columnNames the names of the columns which are part of the constraint * @param constraintName the name of the unique constraint */ - public abstract void createUniqueConstraint( LogicalTable table, List columnNames, String constraintName ); + public abstract void createUniqueConstraint( LogicalTable table, List columnNames, String constraintName, Statement statement ); /** * Drop a specific column in a table diff --git a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java index 73af33d006..2dfbacbf67 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -522,7 +522,7 @@ public void createColumn( String columnName, LogicalTable table, String beforeCo @Override - public void createForeignKey( LogicalTable table, LogicalTable refTable, List columnNames, List refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete ) { + public void createForeignKey( LogicalTable table, LogicalTable refTable, List columnNames, List refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete, Statement statement ) { // Make sure that this is a table of type TABLE (and not SOURCE) checkIfDdlPossible( table.entityType ); checkIfDdlPossible( refTable.entityType ); @@ -539,6 +539,8 @@ public void createForeignKey( LogicalTable table, LogicalTable refTable, List columnNames, Stat } } } + statement.getTransaction().getLogicalTables().add( table ); } @Override - public void createUniqueConstraint( LogicalTable table, List columnNames, String constraintName ) { + public void createUniqueConstraint( LogicalTable table, List columnNames, String constraintName, Statement statement ) { // Make sure that this is a table of type TABLE (and not SOURCE) checkIfDdlPossible( table.entityType ); @@ -833,6 +836,7 @@ public void createUniqueConstraint( LogicalTable table, List columnNames columnIds.add( logicalColumn.id ); } catalog.getLogicalRel( table.namespaceId ).addUniqueConstraint( table.id, constraintName, columnIds ); + statement.getTransaction().getLogicalTables().add( table ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java index 30bbd952f3..d7cbd9851b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java @@ -118,7 +118,8 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa referencesList.getList().stream().map( Node::toString ).toList(), constraintName.getSimple(), onUpdate, - onDelete ); + onDelete, + statement ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java index decaf4d75f..fda9e89325 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.EntityType; @@ -94,8 +93,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().createUniqueConstraint( logicalTable, - columnList.getList().stream().map( Node::toString ).collect( Collectors.toList() ), - constraintName.getSimple() ); + columnList.getList().stream().map( Node::toString ).toList(), + constraintName.getSimple(), + statement ); } } diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index 33c259f44c..9a53d7a8ef 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -2419,7 +2419,7 @@ RelationalResult executeAlg( final AlgRequest request, Session session ) { return RelationalResult.builder().error( e.getMessage() ).build(); } - // Wrap {@link AlgNode} into a RelRoot + // Wrap {@link AlgNode} into a AlgRoot final AlgDataType rowType = result.getTupleType(); final List> fields = Pair.zip( IntStream.range( 0, rowType.getFieldCount() ).boxed().toList(), rowType.getFieldNames() ); final AlgCollation collation =