Skip to content

Commit

Permalink
added constraint validity test on create
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Apr 8, 2024
1 parent e1c4e18 commit ecb3b39
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/ddl/DdlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> columnNames, List<String> refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete );
public abstract void createForeignKey( LogicalTable table, LogicalTable refTable, List<String> columnNames, List<String> refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete, Statement statement );

/**
* Adds an index to a table
Expand Down Expand Up @@ -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<String> columnNames, String constraintName );
public abstract void createUniqueConstraint( LogicalTable table, List<String> columnNames, String constraintName, Statement statement );

/**
* Drop a specific column in a table
Expand Down
8 changes: 6 additions & 2 deletions dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void createColumn( String columnName, LogicalTable table, String beforeCo


@Override
public void createForeignKey( LogicalTable table, LogicalTable refTable, List<String> columnNames, List<String> refColumnNames, String constraintName, ForeignKeyOption onUpdate, ForeignKeyOption onDelete ) {
public void createForeignKey( LogicalTable table, LogicalTable refTable, List<String> columnNames, List<String> 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 );
Expand All @@ -539,6 +539,8 @@ public void createForeignKey( LogicalTable table, LogicalTable refTable, List<St
}
catalog.getLogicalRel( table.namespaceId ).addForeignKey( table.id, columnIds, refTable.id, referencesIds, constraintName, onUpdate, onDelete );
catalog.getLogicalRel( table.namespaceId ).addConstraint( table.id, ConstraintType.FOREIGN.name(), columnIds, ConstraintType.FOREIGN );

statement.getTransaction().getLogicalTables().add( table );
}


Expand Down Expand Up @@ -816,12 +818,13 @@ public void createPrimaryKey( LogicalTable table, List<String> columnNames, Stat
}
}
}
statement.getTransaction().getLogicalTables().add( table );

}


@Override
public void createUniqueConstraint( LogicalTable table, List<String> columnNames, String constraintName ) {
public void createUniqueConstraint( LogicalTable table, List<String> columnNames, String constraintName, Statement statement ) {
// Make sure that this is a table of type TABLE (and not SOURCE)
checkIfDdlPossible( table.entityType );

Expand All @@ -833,6 +836,7 @@ public void createUniqueConstraint( LogicalTable table, List<String> columnNames
columnIds.add( logicalColumn.id );
}
catalog.getLogicalRel( table.namespaceId ).addUniqueConstraint( table.id, constraintName, columnIds );
statement.getTransaction().getLogicalTables().add( table );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}

}
Expand Down
2 changes: 1 addition & 1 deletion webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<Integer, String>> fields = Pair.zip( IntStream.range( 0, rowType.getFieldCount() ).boxed().toList(), rowType.getFieldNames() );
final AlgCollation collation =
Expand Down

0 comments on commit ecb3b39

Please sign in to comment.