Skip to content

Commit

Permalink
fix(RDF): Output not always as expected when using table inheritance (#…
Browse files Browse the repository at this point in the history
…4417)

* Fixed test succeeding due to re-use of RDFHandler

* Split buggy test into 2 separate tests

* fixed the test: describeTable() only used if 'rowId == null' so predicate not available as subject

* reduced duplicate code

* removed unneeded import

* Added multiple tests to validate behavior

* Added second child table to ensure correct functioning

* enhanced tests to validate table inheritance from different schema

* test fixes

* if RDF API uses table filter, ensures all child tables from same scheme are included as well

* Added additional tests to validate cross-schema behavior

* Improved tests to include multi-layer external schema & reduced testing code duplicity

* updated test to ensure a grandchild uses all inherited columns and validate on this

* minor fix

* Added test when using non-existing table

* fixed some tests

* RDFSchema filtering on table now works with a filter defining multiple schemas

* removed unneeded code

* minor fixes / comment adjustments
  • Loading branch information
svandenhoek authored Nov 18, 2024
1 parent c612410 commit 869d8a5
Show file tree
Hide file tree
Showing 2 changed files with 532 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,31 @@ public void describeAsRDF(
describeRoot(builder);
}

// Collect all tables present in selected schemas.
Set<Table> allTables = new HashSet<>();

for (final Schema schema : schemas) {
if (table == null) {
describeSchema(builder, schema);
}
final List<Table> tables = table != null ? Arrays.asList(table) : schema.getTablesSorted();
for (final Table tableToDescribe : tables) {
// for full-schema retrieval, don't print the (huge and mostly unused) ontologies
// of course references to ontologies are still included and are fully retrievable
if (table == null
&& tableToDescribe.getMetadata().getTableType().equals(TableType.ONTOLOGIES)) {
continue;
}
if (rowId == null) {
describeTable(builder, tableToDescribe);
describeColumns(builder, tableToDescribe, columnName);
}
// if a column name is provided then only provide column metadata, no row values
if (columnName == null) {
rowsToRdf(builder, tableToDescribe, rowId);
}
allTables.addAll(schema.getTablesSorted());
}

final Set<Table> tables = table != null ? tablesToDescribe(allTables, table) : allTables;
for (final Table tableToDescribe : tables) {
// for full-schema retrieval, don't print the (huge and mostly unused) ontologies
// of course references to ontologies are still included and are fully retrievable
if (table == null
&& tableToDescribe.getMetadata().getTableType().equals(TableType.ONTOLOGIES)) {
continue;
}
if (rowId == null) {
describeTable(builder, tableToDescribe);
describeColumns(builder, tableToDescribe, columnName);
}
// if a column name is provided then only provide column metadata, no row values
if (columnName == null) {
rowsToRdf(builder, tableToDescribe, rowId);
}
}
Rio.write(builder.build(), outputStream, rdfFormat, config);
Expand All @@ -215,6 +220,31 @@ public void describeAsRDF(
}
}

private Set<Table> tablesToDescribe(Set<Table> allTables, Table tableFilter) {
Set<Table> tablesToDescribe = new HashSet<>();
for (Table currentTable : allTables) {
processInheritedTable(tableFilter, tablesToDescribe, currentTable);
}
return tablesToDescribe;
}

private boolean processInheritedTable(
Table tableFilter, Set<Table> tablesToDescribe, Table currentTable) {
if (currentTable == null) {
return false;
}
if (currentTable.getSchema().getName().equals(tableFilter.getSchema().getName())
&& currentTable.getName().equals(tableFilter.getName())) {
tablesToDescribe.add(currentTable);
return true;
}
if (processInheritedTable(tableFilter, tablesToDescribe, currentTable.getInheritedTable())) {
tablesToDescribe.add(currentTable);
return true;
}
return false;
}

private void addModelToBuilder(ModelBuilder builder, Model model) {
model.getNamespaces().forEach(builder::setNamespace);
model.forEach(e -> builder.add(e.getSubject(), e.getPredicate(), e.getObject()));
Expand Down
Loading

0 comments on commit 869d8a5

Please sign in to comment.