Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong column name in Column.getReferences() when dealing with composite REFBACK #4564

Open
1 task done
svandenhoek opened this issue Dec 16, 2024 · 2 comments · May be fixed by #4569
Open
1 task done

Wrong column name in Column.getReferences() when dealing with composite REFBACK #4564

svandenhoek opened this issue Dec 16, 2024 · 2 comments · May be fixed by #4569
Labels
bug Something isn't working

Comments

@svandenhoek
Copy link
Contributor

Have you checked if this issue already exists?

  • yes

Molgenis EMX2 version

Software version: v11.40.0-SNAPSHOT. Database version: 23.

Description

When I try to retrieve the reference column names for a composite refback, the given column names do not match the actually retrieved column names through Query.retrieveRows(). In contrary to REF_ARRAY, a refback uses a different separator for composite keys (. vs -).

Reproduction steps

This test should not fail:

@Test
  void wrongColName() {
    Database database = TestDatabaseFactory.getTestDatabase();
    Schema schema = database.dropCreateSchema("testCompositeRefbackColname");
    schema.create(
        table(
            "table1",
            column("id1", ColumnType.STRING).setPkey(),
            column("id2", ColumnType.STRING).setPkey(),
            column("ref", ColumnType.REF).setRefTable("table2")),
        table("table2", column("id", ColumnType.STRING).setPkey()));
    schema
        .getTable("table2")
        .getMetadata()
        .add(column("refback", ColumnType.REFBACK).setRefTable("table1").setRefBack("ref"));
    schema.getTable("table2").insert(row("id", "x"));
    schema
        .getTable("table1")
        .insert(row("id1", "a", "id2", "aa", "ref", "x"), row("id1", "b", "id2", "bb", "ref", "x"));

    Set<String> expectedColNames = new HashSet<>();
    expectedColNames.add("id");
    schema
        .getTable("table2")
        .getMetadata()
        .getColumn("refback")
        .getReferences()
        .forEach(r -> expectedColNames.add(r.getName()));

    Set<String> actualColNames =
        schema
            .getTable("table2")
            .query()
            .select(s("id"), s("refback", s("id1"), s("id2")))
            .retrieveRows()
            .get(0)
            .getColumnNames();

    Assertions.assertEquals(expectedColNames, actualColNames);
  }

Currently it returns:

org.opentest4j.AssertionFailedError: 
Expected :[id, refback.id2, refback.id1]
Actual   :[id, refback-id1, refback-id2]

Expected behaviour

While it is debatable whether getReferences() is incorrect or the given column names by Query, fact is that they do not match while expected would be that getReferences().getNames() should allow for retrieving the columns belonging to a composite foreign key.

System configuration

No response

@svandenhoek svandenhoek added the bug Something isn't working label Dec 16, 2024
@svandenhoek
Copy link
Contributor Author

A fix is needed for properly merging #4566 without implementing some temporary work-around.

@svandenhoek
Copy link
Contributor Author

Actual issue might be more complicated, see: #4569 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant