Skip to content

Commit

Permalink
Add functions to retrieve field index holes (#29)
Browse files Browse the repository at this point in the history
* Add functionality to retrieve field index holes for index rows and reversed index rows from the metadata table.
  • Loading branch information
lbschanno authored Nov 21, 2023
1 parent b2d9790 commit fcfc55e
Show file tree
Hide file tree
Showing 5 changed files with 906 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/datawave/query/model/FieldIndexHole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package datawave.query.model;

import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.Objects;
import java.util.SortedSet;
import java.util.StringJoiner;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import com.google.common.collect.ImmutableSortedSet;

/**
* 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
* row was seen, but an index and/or reversed indexed row was not.
*/
public class FieldIndexHole {

private final String fieldName;
private final String datatype;
private final SortedSet<Pair<Date,Date>> dateRanges;

public FieldIndexHole(String fieldName, String dataType, Collection<Pair<Date,Date>> holes) {
this.fieldName = fieldName;
this.datatype = dataType;
// Ensure the date range set is immutable.
ImmutableSortedSet.Builder<Pair<Date,Date>> builder = new ImmutableSortedSet.Builder<>(Comparator.naturalOrder());
holes.forEach(p -> builder.add(new ImmutablePair<>(p.getLeft(), p.getRight())));
dateRanges = builder.build();
}

/**
* Return the field name.
*
* @return the field name.
*/
public String getFieldName() {
return fieldName;
}

/**
* Return the datatype.
*
* @return the datatype.
*/
public String getDatatype() {
return datatype;
}

/**
* 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
* 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).
*
* @return the date ranges
*/
public SortedSet<Pair<Date,Date>> getDateRanges() {
return dateRanges;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FieldIndexHole indexHole = (FieldIndexHole) o;
return Objects.equals(fieldName, indexHole.fieldName) && Objects.equals(datatype, indexHole.datatype)
&& Objects.equals(dateRanges, indexHole.dateRanges);
}

@Override
public int hashCode() {
return Objects.hash(fieldName, datatype, dateRanges);
}

@Override
public String toString() {
return new StringJoiner(", ", FieldIndexHole.class.getSimpleName() + "[", "]").add("fieldName='" + fieldName + "'").add("dataType='" + datatype + "'")
.add("dateRanges=" + dateRanges).toString();
}
}
Loading

0 comments on commit fcfc55e

Please sign in to comment.