Skip to content

Commit ab34304

Browse files
authored
Task/hp index hole investigation (#49)
* re #2702: Renaming the field index hole to a index field gap * Ensure date range in from beginning of day to end of day for index field holes * Use java.time library instead of Calendar. Added test cases for index field hole * For old style index markers, marking the previous day as as the boundary because we can assume the current day is only partially indexed
1 parent 1d7b27e commit ab34304

File tree

5 files changed

+331
-116
lines changed

5 files changed

+331
-116
lines changed

src/main/java/datawave/query/model/FieldIndexHole.java renamed to src/main/java/datawave/query/model/IndexFieldHole.java

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datawave.query.model;
22

3+
import java.time.Instant;
4+
import java.time.temporal.ChronoUnit;
35
import java.util.Collection;
46
import java.util.Comparator;
57
import java.util.Date;
@@ -16,21 +18,52 @@
1618
* This class represents a set of calculated field index holes for a given fieldName and datatype. A field index hole is effectively a date where a frequency
1719
* row was seen, but an index and/or reversed indexed row was not.
1820
*/
19-
public class FieldIndexHole {
21+
public class IndexFieldHole {
2022

2123
private final String fieldName;
2224
private final String datatype;
2325
private final SortedSet<Pair<Date,Date>> dateRanges;
26+
private static long DAY_MILLIS = 1000L * 60 * 60 * 24;
2427

25-
public FieldIndexHole(String fieldName, String dataType, Collection<Pair<Date,Date>> holes) {
28+
public IndexFieldHole(String fieldName, String dataType, Collection<Pair<Date,Date>> holes) {
2629
this.fieldName = fieldName;
2730
this.datatype = dataType;
28-
// Ensure the date range set is immutable.
31+
// Ensure the date range set is immutable, and starts at the beginning of the start date, and ends at the end of the end date
2932
ImmutableSortedSet.Builder<Pair<Date,Date>> builder = new ImmutableSortedSet.Builder<>(Comparator.naturalOrder());
30-
holes.forEach(p -> builder.add(new ImmutablePair<>(p.getLeft(), p.getRight())));
33+
holes.forEach(p -> builder.add(new ImmutablePair<>(floor(p.getLeft()), ceil(p.getRight()))));
3134
dateRanges = builder.build();
3235
}
3336

37+
/**
38+
* return the date instant at 00:00:00
39+
*
40+
* @param d
41+
* @return instant of d with time reset to 00:00:00
42+
*/
43+
private static Instant floorInstant(Date d) {
44+
return Instant.ofEpochMilli(d.getTime()).truncatedTo(ChronoUnit.DAYS);
45+
}
46+
47+
/**
48+
* return the date at 00:00:00
49+
*
50+
* @param d
51+
* @return d with time reset to 00:00:00
52+
*/
53+
private static Date floor(Date d) {
54+
return Date.from(floorInstant(d));
55+
}
56+
57+
/**
58+
* return the date at 23:59:59
59+
*
60+
* @param d
61+
* @return d with time reset to 23:59:59
62+
*/
63+
private static Date ceil(Date d) {
64+
return Date.from(floorInstant(d).plusMillis(DAY_MILLIS - 1));
65+
}
66+
3467
/**
3568
* Return the field name.
3669
*
@@ -50,7 +83,7 @@ public String getDatatype() {
5083
}
5184

5285
/**
53-
* Returns the set of date ranges that span over field index holes for the fieldName and datatype of this {@link FieldIndexHole}. Each date range represents
86+
* Returns the set of date ranges that span over field index holes for the fieldName and datatype of this {@link IndexFieldHole}. Each date range represents
5487
* a span of consecutive days for which a frequency row exist, but an index row does not. All date ranges are start(inclusive)-end(inclusive).
5588
*
5689
* @return the date ranges
@@ -67,7 +100,7 @@ public boolean equals(Object o) {
67100
if (o == null || getClass() != o.getClass()) {
68101
return false;
69102
}
70-
FieldIndexHole indexHole = (FieldIndexHole) o;
103+
IndexFieldHole indexHole = (IndexFieldHole) o;
71104
return Objects.equals(fieldName, indexHole.fieldName) && Objects.equals(datatype, indexHole.datatype)
72105
&& Objects.equals(dateRanges, indexHole.dateRanges);
73106
}
@@ -79,7 +112,7 @@ public int hashCode() {
79112

80113
@Override
81114
public String toString() {
82-
return new StringJoiner(", ", FieldIndexHole.class.getSimpleName() + "[", "]").add("fieldName='" + fieldName + "'").add("dataType='" + datatype + "'")
115+
return new StringJoiner(", ", IndexFieldHole.class.getSimpleName() + "[", "]").add("fieldName='" + fieldName + "'").add("dataType='" + datatype + "'")
83116
.add("dateRanges=" + dateRanges).toString();
84117
}
85118
}

0 commit comments

Comments
 (0)