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

Stats return all zeroes when there is a change in arrays #10

Open
christian-roggia opened this issue Jul 16, 2020 · 8 comments
Open

Stats return all zeroes when there is a change in arrays #10

christian-roggia opened this issue Jul 16, 2020 · 8 comments

Comments

@christian-roggia
Copy link

The following test code does throws an error as the diff fails to pick up the changes from file A to file B:

import (
	"context"
	"encoding/json"
	"io/ioutil"
	"testing"

	"github.com/qri-io/deepdiff"
	"github.com/stretchr/testify/assert"
)

func TestJsonDiff(t *testing.T) {
	assert := assert.New(t)

	dd := deepdiff.New()

	data00a, err := ioutil.ReadFile("./testdata/regression-00-a.json")
	assert.Nil(err)

	data00b, err := ioutil.ReadFile("./testdata/regression-00-b.json")
	assert.Nil(err)

	var a, b interface{}

	assert.Nil(json.Unmarshal(data00a, &a))
	assert.Nil(json.Unmarshal(data00b, &b))

	stats, err := dd.Stat(context.TODO(), a, b)
	assert.Nil(err)

	assert.False(stats.Deletes == 0 && stats.Inserts == 0 && stats.Updates == 0)
}

testdata/regression-00-a.json:

{
    "X": [
        {
            "A": "A"
        },
        {
            "B": "B"
        }
    ],
    "Y": [
        {
            "C": "C"
        }
    ]
}

testdata/regression-00-b.json:

{
    "X": [
        {
            "A": "A"
        }
    ],
    "Z": [
        {
            "B": "B"
        },
        {
            "C": "C"
        }
    ]
}
@christian-roggia
Copy link
Author

Please note that Z has been added, X has been updated, and Y has been deleted.

@christian-roggia christian-roggia changed the title Stats return all zeroes when there is Stats return all zeroes when there is a change in arrays Jul 16, 2020
@christian-roggia
Copy link
Author

/ping @b5
This is a critical issue in our systems and we will be forced to move away from deepdiff if we cannot solve it

@dustmop
Copy link
Contributor

dustmop commented Jul 29, 2020

Hi @christian-roggia, apologies for the delay, we're going to be focusing on fixing this as soon as possible and hope to have it figured out by the end of the week.

@christian-roggia
Copy link
Author

Any update on this issue?

@dustmop
Copy link
Contributor

dustmop commented Sep 22, 2020

@christian-roggia Sorry for dropping off. After looking into this, there's some problems in deepdiff where some results are returned non-deterministically, and some where clearly wrong results are returned for maps (like your example). There's also a general lack of understanding around the codebase. We're going to need to rewrite the core algorithm in order to fix both of these problems, so it's going to take some more time. However, it is something we want to fix soon, since it's causing user-facing bugs in https://github.com/qri-io/qri. Perhaps there'll be better news in a few more weeks, but I understand if you need to switch to a different library.

@christian-roggia
Copy link
Author

@dustmop thank you very much for sharing the current status quo of this library. We will momentarily switch to another one until the refactor is complete.

@malikbenkirane
Copy link

malikbenkirane commented Oct 31, 2020

@christian-roggia would you mind sharing the alternative library you've elected for you project. I'm looking for a similar alternative. I would enjoy to hear news from you too @dustmop

Also looking forward to help you with this rewrite once I'm able find a little more time with my side projects.

@christian-roggia
Copy link
Author

@malikbenkirane we switched back to https://github.com/yudai/gojsondiff as in general we are performing relatively small diffs.

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

3 participants