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

diff record based on primary key doesn't work #168

Open
KaiWW opened this issue Jun 23, 2021 · 1 comment
Open

diff record based on primary key doesn't work #168

KaiWW opened this issue Jun 23, 2021 · 1 comment

Comments

@KaiWW
Copy link

KaiWW commented Jun 23, 2021

The "age" has been assigned as the primary key, but it's using "key" as the primary key.

before_data = [["key", "id", "name", "age"],
["1001", "1", "Cleo", "4"],
["1010", "2", "Pancakes", "2"]]

after_data = [["key", "id", "name", "age"],
["1001", "1", "Cleo", "5"],
["1009", "3", "Bailey", "1"],
["1012", "234", "John", "10"],
["1010", "32", "Dave", "21"]]

table1 = daff.PythonTableView(before_data)
table2 = daff.PythonTableView(after_data)

compare_object = daff.Coopy.compareTables(table1, table2)

align_tables = compare_object.align()

data_diff = []
table_diff = daff.PythonTableView(data_diff)

flags = daff.CompareFlags()
**flags.addPrimaryKey("age")**

highlighter = daff.TableDiff(align_tables, flags)
highlighter.hilite(table_diff)

sys.stdout.writelines(str(data_diff))

This gives me:
[['@@', 'key', 'id', 'name', 'age'],
['->', '1001', '1', 'Cleo', '4->5'],
['+++', '1009', '3', 'Bailey', '1'],
['+++', '1012', '234', 'John', '10'],
['->', '1010', '2->32', 'Pancakes->Dave', '2->21']]

@paulfitz
Copy link
Owner

Hi @KaiWW, I think the problem is that the initial call to compareTables is being done without the flags available to specify the primary key. Try calling it as compareTables(table1, table2, flags). For example in harness/BasicTest.hx there is a test for primary keys that goes like this:

    public function testNamedID(){
        var table1 = Native.table(data1);
        var table2 = Native.table(data2);
        var flags = new coopy.CompareFlags();
        flags.addPrimaryKey("Capital");
        var alignment = coopy.Coopy.compareTables(table1,table2,flags).align();
        var data_diff = [];
        var table_diff = Native.table(data_diff);
        var highlighter = new coopy.TableDiff(alignment,flags);
        highlighter.hilite(table_diff);
        assertEquals(""+table_diff.getCell(3,6),"Barcelona");
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants