Navigation Menu

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

MergeDataTables does not correctly merge if table2 has more data than table1 #15294

Merged
merged 7 commits into from Dec 24, 2019

Conversation

diosmosis
Copy link
Member

... & fix build.

When fixing tests I noticed a bug exposed by the new VisitFrequency metrics. MergeDataTables will only iterate over the first table when merging tables, which means if there are tables that exist in table2 only, they won't get added.

@diosmosis diosmosis added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review labels Dec 20, 2019
@diosmosis diosmosis added this to the 3.13.1 milestone Dec 20, 2019
@@ -52,4 +52,23 @@ public function mergeDataTables($table1, $table2)
}
}

private function makeNewDataTable(DataTable\DataTableInterface $subTable2)
{
if ($subTable2 instanceof DataTable\Map) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diosmosis wondering if we would need to create a clone and keep any filters? Not sure though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could. Might be an issue if filters hold references to the old table or to some other object that isn't relevant anymore (ie, like ones that calculate percent over a total or specific column value in another table or something like that). Actually, it's probably better to require this class be used before filters are run, since if metrics are formatted they won't be able to be added properly...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't hold a reference to the table but possibly to some other parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some filters do hold references to other tables, eg, CalculateEvolutionFilter. It is conceivable that they could hold onto a lot of data.

Ideally it would be great to deprecate queued filters and instead move that logic to a method in the Report class, like, formatApiResponse(), similar to configureView() or whatever it's called.

$subTables1 = $table1->getDataTables();
foreach ($table2->getDataTables() as $index => $subTable2) {
if (!array_key_exists($index, $subTables1)) {
$subTable1 = $this->makeNewDataTable($subTable2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diosmosis reading the previous comment in #5168 (comment) I wonder if this could cause any issues with potentially wrong data when archiving overlaps another day basically? Not sure I fully understand #5168 . I suppose if it was a problem, it would need to be handled somewhere else maybe and not in this class as when merging you expect both tables to be merged as it is implemented in this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So:

  • archive starts on one day sending request for 'today'
  • new day begins, archive finishes, 'today' value changes

then some bug happens? I'm not sure I understand either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe @mattab knows?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you said, "if it was a problem, it would need to be handled somewhere else maybe and not in this class as when merging you expect both tables to be merged as it is implemented in this PR" -> so sounds good to proceed with this proper fix and we can see if the problem in #5168 starts appearing again

@mattab
Copy link
Member

mattab commented Dec 23, 2019

Would it be possible adding some unit tests or so?

@diosmosis
Copy link
Member Author

👍 can add unit tests

@diosmosis diosmosis merged commit dedaf6b into 3.x-dev Dec 24, 2019
@diosmosis diosmosis deleted the fix-build branch December 24, 2019 13:15
@mattab
Copy link
Member

mattab commented Dec 29, 2019

@diosmosis looks like you forgot to add the unit tests in 1c83ed2 ?

diosmosis added a commit that referenced this pull request Dec 29, 2019
diosmosis added a commit that referenced this pull request Dec 29, 2019
@diosmosis
Copy link
Member Author

@mattab added in #15323

jonasgrilleres pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 22, 2020
… table1 (matomo-org#15294)

* update submodules to fix build

* Handle DataTable Maps in VisitFrequency API and in DataTable merger, make sure to correctly copy child datatables.

* fix some tests

* Copy metadata over.

* Updated expected test results.

* Adding unit tests.
jonasgrilleres pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 22, 2020
jbuget pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 26, 2020
… table1 (matomo-org#15294)

* update submodules to fix build

* Handle DataTable Maps in VisitFrequency API and in DataTable merger, make sure to correctly copy child datatables.

* fix some tests

* Copy metadata over.

* Updated expected test results.

* Adding unit tests.
jbuget pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants