Skip to content

TimeAndDims does not implement equals/hashcode#2692

Closed
navis wants to merge 1 commit intoapache:masterfrom
navis:missing-equals-timeanddims
Closed

TimeAndDims does not implement equals/hashcode#2692
navis wants to merge 1 commit intoapache:masterfrom
navis:missing-equals-timeanddims

Conversation

@navis
Copy link
Copy Markdown
Contributor

@navis navis commented Mar 21, 2016

Testing #2670, I've found #2571 expects TimeAndDims to be comparable(equals/hashcode) but it's not. It'll make invalid results apparently but it's missing proper test cases.

@navis navis added the Bug label Mar 21, 2016
@fjy
Copy link
Copy Markdown
Contributor

fjy commented Mar 21, 2016

👍

@gianm gianm added this to the 0.9.1 milestone Mar 23, 2016
@gianm
Copy link
Copy Markdown
Contributor

gianm commented Mar 23, 2016

added to 0.9.1 milestone so this fix goes in along with #2571. @navis could you please address the merge conflicts?

NB: I have not actually read this yet!

@navis navis force-pushed the missing-equals-timeanddims branch from 8140683 to f7bf058 Compare March 23, 2016 23:42
@navis
Copy link
Copy Markdown
Contributor Author

navis commented Mar 23, 2016

rebased. It's for adding eq/hash for TimeAndDims. others are just refactorings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does this need to "extend" IncrementalIndices , it seems that only contains a bunch of "static" stuff that needs to be referenced by IncrementalIndex.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems odd to me too, it would make more sense to me if things were called statically like IncrementalIndices.STRING_TRANSFORMER

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

@fjy
Copy link
Copy Markdown
Contributor

fjy commented Mar 29, 2016

@navis any chance of addressing these comments?

@jon-wei
Copy link
Copy Markdown
Contributor

jon-wei commented Mar 30, 2016

I am also in favor of removing the inheritance between IncrementalIndex and IncrementalIndices.

👍 aside from that

@navis navis force-pushed the missing-equals-timeanddims branch from f7bf058 to bf2c93d Compare March 30, 2016 05:38
@navis
Copy link
Copy Markdown
Contributor Author

navis commented Mar 30, 2016

@fjy done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two TimeAndDims might have dims of different length so I think this could cause an out of bounds array access on that.dims[i]. This also doesn't check types at all but the Comparator for sorted facts does check types.

The equals impl could do return dimsComparator.compare(this, that) == 0 although this does some needless name lookups.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the type comparison in TimeAndDimsComp is actually unnecessary (the dims will have the same types up to numComparisons since the same dimension ordering is maintained), I shouldn't have added that in.

I guess the current equals/hashcode() in this PR doesn't trigger an exception since it's being used only by "no sort" IncrementalIndex during GroupBy merging where the dimension count will be the same across rows?

I think it'd be fine to reuse TimeAndDimsComp as @gianm suggested or to add a similar dims length check to equals(), if you feel like avoiding the name lookups.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added length check

@jon-wei
Copy link
Copy Markdown
Contributor

jon-wei commented Mar 30, 2016

Let me delay my previous 👍 until the comment re: comparator/equals() is addressed

@navis navis force-pushed the missing-equals-timeanddims branch from bf2c93d to d8f7228 Compare March 31, 2016 00:58

if (timestamp != that.timestamp) {
return false;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this consider two TimeAndDims equal if their dims have different length, but the longer one is all nulls? That could happen if a dimension was added later on, but not all rows actually have that dimension. Those two rows should roll up together (I think IndexMerger actually will do this but maybe it'd be nice to do it here too).

I believe currently, the behavior you have here is equivalent to what TimeAndDimsComp does. So if we want to change that here then we should probably change it in the TimeAndDimsComp too.

@gianm
Copy link
Copy Markdown
Contributor

gianm commented Apr 1, 2016

@navis could you please move the refactoring to a different PR if it is not necessary for the bug fix?

@gianm
Copy link
Copy Markdown
Contributor

gianm commented Apr 21, 2016

@navis could you please adjust this PR to fix merge conflicts & just include the bug fix?

gianm added a commit to gianm/druid that referenced this pull request Apr 21, 2016
Adapted from apache#2692, thanks @navis for original implementation.
fjy pushed a commit that referenced this pull request Apr 22, 2016
Adapted from #2692, thanks @navis for original implementation.
@navis navis closed this Apr 24, 2016
@navis navis deleted the missing-equals-timeanddims branch April 24, 2016 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants