You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/06/22 00:04:56 UTC
[GitHub] [lucene] gautamworah96 opened a new pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
gautamworah96 opened a new pull request #191:
URL: https://github.com/apache/lucene/pull/191
Additionally, minor method name and variable refactoring in the
TestLongValueFacetCounts class
(The name `valueCount` was a bit misleading because it was actually representing the number of test docs. The name `testRandom` was a bit too generic for a method that only tested single valued fields.)
<!--
_(If you are a project committer then you may remove some/all of the following template.)_
Before creating a pull request, please file an issue in the ASF Jira system for Lucene:
* https://issues.apache.org/jira/projects/LUCENE
You will need to create an account in Jira in order to create an issue.
The title of the PR should reference the Jira issue number in the form:
* LUCENE-####: <short description of problem or changes>
LUCENE must be fully capitalized. A short description helps people scanning pull requests for items they can work on.
Properly referencing the issue in the title ensures that Jira is correctly updated with code review comments and commits. -->
# Description
Ideally, if a document contains duplicate values, they should only be counted once when you ask for the number of times a value has occurred in the index. So if a doc has the value `2` indexed twice, it should only be counted once when you try to count the number of times the value `2` has occurred using `LongValueFacetCounts`
# Solution
Added a `uniqueLongValues` map per doc that keeps track of unique values that were already accounted for.
# Tests
Added a new `testDuplicateLongValues` test that adds duplicate `SortedNumericDocValuesField`s to a doc and then checks the count for those duplicate values. Also, modified the randomized test to calculate the correct count.
# Checklist
Please review the following and check all that apply:
- [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/lucene/HowToContribute) and my code conforms to the standards described there to the best of my ability.
- [x] I have created a Jira issue and added the issue ID to my pull request title.
- [x] I have given Lucene maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
- [x] I have developed this patch against the `main` branch.
- [x] I have run `./gradlew check`.
- [x] I have added tests for my changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659660194
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
lets not use boxed Long type here. just initialize `previousValue` to zero or any other value and change the check to:
```
if (i == 0 || value != previousValue) {
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659451970
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Oooh. This is a tricky one.
When converting primitive arrays into lists, Java converts them into a single object.
So when we convert an array of `long`s to a list, Java converts them to a list with a single object and that object has all the `long` children.
So `long[]` is converted to a list `{C@15db9742}` where that C@15db9742 is an array of longs. When you send this list to a HashSet it will not remove out duplicate values because the values the HashSet sees are objects.
In contrast, on converting an array of `Long`s (of type `Object`) to a list, Java converts all of the children directly to a list like `{Long val1, Long val2 ...}`. When you send these values to a HashSet it will do the right thing and remove out the duplicate values.
In L435 `Long value : new HashSet<>(Arrays.asList(values[i]))` we are trying to do exactly that i.e, remove out duplicate values so that we get the correct expected count (with no double counting for duplicate values).
So using `long` will give us the wrong result because it will double count values as it has not removed duplicate ones. Because we've inadvertently sent the wrong values to the `HashSet`!
Related reference from SO: https://stackoverflow.com/questions/47153183/primitive-type-and-wrapper-type-for-arrays-aslist
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r663272121
##########
File path: lucene/CHANGES.txt
##########
@@ -380,6 +380,9 @@ Bug Fixes
---------------------
* LUCENE-9988: Fix DrillSideways correctness bug introduced in LUCENE-9944 (Greg Miller)
+* LUCENE-9964: Duplicate long values in a document field should only be counted once when using SortedNumericDocValuesFields
Review comment:
Here we go https://github.com/apache/lucene-solr/pull/2521
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660149249
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Sure. The next commit uses `long`s everywhere instead of `Long`s.
Just out of curiosity: why do we prefer a `long` over a `Long`? Saves us boxing/unboxing time?
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Sure.
The next commit uses `long`s everywhere instead of `Long`s. It sorts values manually (because they are randomly generated) and then uses the same logic of comparing with the previous value.
Just out of curiosity: why do we prefer a `long` over a `Long`? Saves us boxing/unboxing time?
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -517,22 +512,15 @@ public void testRandomMultiValued() throws Exception {
facetCounts = new LongValueFacetCounts("field", fc);
expected = new HashMap<>();
- expectedChildCount = 0;
- int totCount = 0;
Review comment:
`totCount` was an extra variable with just a different name and `expectedChildCount` was just tracking the number of unique values. We can get that from the size of the map instead
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
Fixed this in the next commit 6b2019e
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Sure.
The next commit uses `long`s everywhere instead of `Long`s. In the test class, it sorts values manually (because they are randomly generated) and then uses the same logic of comparing with the previous value.
Just out of curiosity: why do we prefer a `long` over a `Long`? Saves us boxing/unboxing time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r662518800
##########
File path: lucene/CHANGES.txt
##########
@@ -380,6 +380,9 @@ Bug Fixes
---------------------
* LUCENE-9988: Fix DrillSideways correctness bug introduced in LUCENE-9944 (Greg Miller)
+* LUCENE-9964: Duplicate long values in a document field should only be counted once when using SortedNumericDocValuesFields
Review comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r656099284
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +164,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Set<Long> uniqueLongValues =
+ new HashSet<>(); // count each repeated long value in a field as the same
Review comment:
Hmm, could we use a native HPPC set instead? Also, it makes me nervous to allocate a new `Set` for every hit. Could we reuse a single `Set`?
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Hmm, why switch to boxed `Long` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r662501756
##########
File path: lucene/CHANGES.txt
##########
@@ -380,6 +380,9 @@ Bug Fixes
---------------------
* LUCENE-9988: Fix DrillSideways correctness bug introduced in LUCENE-9944 (Greg Miller)
+* LUCENE-9964: Duplicate long values in a document field should only be counted once when using SortedNumericDocValuesFields
Review comment:
Yes. I was planning to submit a backport PR once this one gets merged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660224322
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
yes that is mainly it. If the index has tens of millions of documents, let's avoid creating tens of millions of objects for performance reasons (both cpu cycles in faceting and also avoiding pressure on the GC system). It is true in some cases that the c2 compiler can eliminate this when the stars align, but we should just avoid doing inefficient code and not leave it to chance in such tight loops.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659420106
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +164,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Set<Long> uniqueLongValues =
+ new HashSet<>(); // count each repeated long value in a field as the same
Review comment:
Ahh. I did not think of this. Will fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659661769
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
let's please not use boxed types everywhere. I don't think we need sets to deduplicate anyway (similar to the other code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gsmiller commented on pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gsmiller commented on pull request #191:
URL: https://github.com/apache/lucene/pull/191#issuecomment-871606648
@mikemccand I'm curious about your suggestion to squash these duplicates at indexing time. Are we certain there aren't any valid use-cases for indexing duplicate longs into the same field for a single document? If that's the case, should we open an issue to enforce this at indexing time? That would indeed remove the need for this bug-fix. That said, I'm still in favor of fixing this bug now at query/faceting time (thanks for taking this up @gautamworah96!). As long as duplicate long values are allowed, we should make sure our facet counting logic handles them appropriately.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659860846
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
+1, I think that can avoid the need for any boxing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659242352
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +164,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Set<Long> uniqueLongValues =
+ new HashSet<>(); // count each repeated long value in a field as the same
Review comment:
That's a great point @rmuir! Then we don't even need the hash set/map!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r661699546
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -556,23 +544,37 @@ public void testRandomMultiValued() throws Exception {
return cmp;
});
if (random().nextBoolean()) {
- topN = valueCount;
+ topN = docCount;
} else {
- topN = random().nextInt(valueCount);
+ topN = random().nextInt(docCount);
}
actual = facetCounts.getTopChildrenSortByCount(topN);
assertSame(
"id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts,
expectedChildCount,
- totCount,
+ expectedTotalCount,
actual,
topN);
}
r.close();
dir.close();
}
+ private void setExpectedFrequencies(long[] values, Map<Long, Integer> expected) {
Review comment:
+1 on the idea. However in this scenario, we do need to populate an existing map.
The map that was populated by the previous `values[i]` value has to be reused and modified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gsmiller merged pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gsmiller merged pull request #191:
URL: https://github.com/apache/lucene/pull/191
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gsmiller commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gsmiller commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r662494802
##########
File path: lucene/CHANGES.txt
##########
@@ -380,6 +380,9 @@ Bug Fixes
---------------------
* LUCENE-9988: Fix DrillSideways correctness bug introduced in LUCENE-9944 (Greg Miller)
+* LUCENE-9964: Duplicate long values in a document field should only be counted once when using SortedNumericDocValuesFields
Review comment:
I just noticed the CHANGES entry here is under 8.10. Are you planning to backport? (I think you should!) Just confirming you're going to be backporting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gsmiller commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gsmiller commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r661692139
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -556,23 +544,37 @@ public void testRandomMultiValued() throws Exception {
return cmp;
});
if (random().nextBoolean()) {
- topN = valueCount;
+ topN = docCount;
} else {
- topN = random().nextInt(valueCount);
+ topN = random().nextInt(docCount);
}
actual = facetCounts.getTopChildrenSortByCount(topN);
assertSame(
"id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts,
expectedChildCount,
- totCount,
+ expectedTotalCount,
actual,
topN);
}
r.close();
dir.close();
}
+ private void setExpectedFrequencies(long[] values, Map<Long, Integer> expected) {
+ long previousValue = 0;
+ for (int j = 0; j < values.length; j++) {
+ if (j == 0 || previousValue != values[j]) {
+ Integer curCount = expected.get(values[j]);
Review comment:
Consider using getOrDefault here with a default value of `0` to avoid the conditional check/assignment below.
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -556,23 +544,37 @@ public void testRandomMultiValued() throws Exception {
return cmp;
});
if (random().nextBoolean()) {
- topN = valueCount;
+ topN = docCount;
} else {
- topN = random().nextInt(valueCount);
+ topN = random().nextInt(docCount);
}
actual = facetCounts.getTopChildrenSortByCount(topN);
assertSame(
"id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts,
expectedChildCount,
- totCount,
+ expectedTotalCount,
actual,
topN);
}
r.close();
dir.close();
}
+ private void setExpectedFrequencies(long[] values, Map<Long, Integer> expected) {
Review comment:
Consider a more idiomatic approach here by returning the expected map instead of populating one passed in as a side-effect. From what I can tell looking at the calling code, there's no need to populate an existing map. It would be a bit cleaner and easier to read if you create the expected map here and return it.
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -394,7 +394,7 @@ public void testRandomMultiValued() throws Exception {
}
for (int j = 0; j < values[i].length; j++) {
- long value = TestUtil.nextLong(random(), -maxValue, maxValue);
+ Long value = TestUtil.nextLong(random(), -maxValue, maxValue);
Review comment:
Can this also be changed back to a `long`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r657528665
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +164,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Set<Long> uniqueLongValues =
+ new HashSet<>(); // count each repeated long value in a field as the same
Review comment:
We could reuse a single set and then empty it out after each matching doc. I'll revise and use a HPPC set here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660149249
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Sure.
The next commit uses `long`s everywhere instead of `Long`s. In the test class, it sorts values manually (because they are randomly generated) and then uses the same logic of comparing with the previous value.
Just out of curiosity: why do we prefer a `long` over a `Long`? Saves us boxing/unboxing time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660151659
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -517,22 +512,15 @@ public void testRandomMultiValued() throws Exception {
facetCounts = new LongValueFacetCounts("field", fc);
expected = new HashMap<>();
- expectedChildCount = 0;
- int totCount = 0;
Review comment:
`totCount` was an extra variable with just a different name and `expectedChildCount` was just tracking the number of unique values. We can get that from the size of the map instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659861196
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
+1, I think that can avoid the need for any boxing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
mikemccand commented on pull request #191:
URL: https://github.com/apache/lucene/pull/191#issuecomment-873625996
> @mikemccand I'm curious about your suggestion to squash these duplicates at indexing time. Are we certain there aren't any valid use-cases for indexing duplicate longs into the same field for a single document? If that's the case, should we open an issue to enforce this at indexing time? That would indeed remove the need for this bug-fix. That said, I'm still in favor of fixing this bug now at query/faceting time (thanks for taking this up @gautamworah96!). As long as duplicate long values are allowed, we should make sure our facet counting logic handles them appropriately.
Yeah +1 to make this first (query-time) fix, now, and separately to provide a simple option to dedup your doc-values field during indexing.
I agree there may be real use cases for preserving duplicates, so both options would be great.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r658678204
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +164,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Set<Long> uniqueLongValues =
+ new HashSet<>(); // count each repeated long value in a field as the same
Review comment:
the values are sorted though. so isn't it enough to just use a check such as `if (value != previousValue)` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660183460
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
Fixed this in the next commit 6b2019e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660149249
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Sure.
The next commit uses `long`s everywhere instead of `Long`s. It sorts values manually (because they are randomly generated) and then uses the same logic of comparing with the previous value.
Just out of curiosity: why do we prefer a `long` over a `Long`? Saves us boxing/unboxing time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660149249
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
Sure. The next commit uses `long`s everywhere instead of `Long`s.
Just out of curiosity: why do we prefer a `long` over a `Long`? Saves us boxing/unboxing time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r660224322
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -382,19 +383,19 @@ public void testRandomMultiValued() throws Exception {
+ allSingleValued);
}
- long[][] values = new long[valueCount][];
- for (int i = 0; i < valueCount; i++) {
+ Long[][] values = new Long[docCount][];
Review comment:
yes that is mainly it. If the index has tens of millions of documents, let's avoid creating tens of millions of objects for performance reasons (both cpu cycles in faceting and also avoiding pressure on the GC system). It is true in some cases that the c2 compiler can eliminate this when the stars align, but we should just avoid doing inefficient code and not leave it to chance in such tight loops.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gsmiller commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gsmiller commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r661709723
##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
##########
@@ -556,23 +544,37 @@ public void testRandomMultiValued() throws Exception {
return cmp;
});
if (random().nextBoolean()) {
- topN = valueCount;
+ topN = docCount;
} else {
- topN = random().nextInt(valueCount);
+ topN = random().nextInt(docCount);
}
actual = facetCounts.getTopChildrenSortByCount(topN);
assertSame(
"id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts,
expectedChildCount,
- totCount,
+ expectedTotalCount,
actual,
topN);
}
r.close();
dir.close();
}
+ private void setExpectedFrequencies(long[] values, Map<Long, Integer> expected) {
Review comment:
Oh right, of course. My apologies.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] gautamworah96 commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
gautamworah96 commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659420106
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +164,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Set<Long> uniqueLongValues =
+ new HashSet<>(); // count each repeated long value in a field as the same
Review comment:
Ahh. I did not think of this. Will fix.
Edit: The new commit e84005f implements this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on a change in pull request #191: LUCENE-9964: Duplicate long values in a field should only be counted once when using SortedNumericDocValuesFields
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #191:
URL: https://github.com/apache/lucene/pull/191#discussion_r659860846
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
+1, I think that can avoid the need for any boxing.
##########
File path: lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
##########
@@ -162,8 +162,14 @@ private void count(String field, List<MatchingDocs> matchingDocs) throws IOExcep
if (limit > 0) {
totCount++;
}
+ Long previousValue = null;
Review comment:
+1, I think that can avoid the need for any boxing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org