Skip to content

Commit

Permalink
fix(rdf): non-required refLink caused RDF API to fail (#4688)
Browse files Browse the repository at this point in the history
* fixed refLink being processed when actually null

* minor fix to test code

* minor test change
  • Loading branch information
svandenhoek authored Feb 11, 2025
1 parent f09c1ff commit 0fb3ef1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@ Set<Value> retrieveValues(String baseURL, Row row, Column column) {

@Override
boolean isEmpty(Row row, Column column) {
// Composite key requires all fields to be filled. If one is null, all should be null.
return row.getString(column.getReferences().get(0).getName()) == null;
// Composite key requires all fields to be filled. Using refLink from a non-required field
// could cause a part of the composite key to be defined.
// Therefore, if a composite key is partly defined, assume it is not defined.
return column.getReferences().stream().anyMatch(i -> row.getString(i.getName()) == null);
}
},
REFBACK(CoreDatatype.XSD.ANYURI) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class RDFTest {
static Schema tableInherExtTest;
static Schema fileTest;
static Schema refBackTest;
static Schema refLinkTest;

final Set<Namespace> DEFAULT_NAMESPACES =
new HashSet<>() {
Expand Down Expand Up @@ -317,6 +318,25 @@ public static void setup() {

refBackTest.getTable("tableRefBack").insert(row("id", "a"));
refBackTest.getTable("tableRef").insert(row("id", "1", "link", "a"));

// refLink test
refLinkTest = database.dropCreateSchema("refLinkTest");

refLinkTest.create(
table("table1", column("id").setType(ColumnType.STRING).setPkey()),
table(
"table2",
column("id1").setPkey().setType(ColumnType.REF).setRefTable("table1"),
column("id2").setType(ColumnType.STRING).setPkey()),
table(
"table3",
column("p1").setPkey().setType(ColumnType.REF).setRefTable("table1"),
column("p2").setPkey().setType(ColumnType.REF).setRefTable("table2").setRefLink("p1"),
column("ref").setType(ColumnType.REF).setRefTable("table2").setRefLink("p1")));

refLinkTest.getTable("table1").insert(row("id", "t1First"));
refLinkTest.getTable("table2").insert(row("id1", "t1First", "id2", "t2First"));
refLinkTest.getTable("table3").insert(row("p1", "t1First", "p2", "t2First"));
}

private static String getApi(Schema schema) {
Expand All @@ -334,6 +354,7 @@ public static void tearDown() {
database.dropSchema(tableInherTest.getName());
database.dropSchema(fileTest.getName());
database.dropSchema(refBackTest.getName());
database.dropSchema(refLinkTest.getName());
}

@Test
Expand Down Expand Up @@ -1260,6 +1281,13 @@ void refBackInRdf() throws IOException {
assertEquals(Set.of(Values.iri(getApi(refBackTest) + "TableRef?id=1")), refBacks);
}

@Test
void testRefLinkWorks() throws IOException {
var handler = new InMemoryRDFHandler() {};
assertDoesNotThrow(() -> getAndParseRDF(Selection.of(refLinkTest), handler));

}

/**
* Helper test method to compare namespaces of 2 schemas.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,9 @@ public String getRefLink() {
return refLink;
}

public void setRefLink(String refLink) {
public Column setRefLink(String refLink) {
this.refLink = refLink;
return this;
}

public Column getRefLinkColumn() {
Expand Down

0 comments on commit 0fb3ef1

Please sign in to comment.