Skip to content

Commit

Permalink
Optimize FieldAgeOffFilter (#2668)
Browse files Browse the repository at this point in the history
Authored-by: Joe Alphonso <jfalpho@uwe.nsa.gov>  
Closes #2667
  • Loading branch information
jalphonso authored Dec 16, 2024
1 parent a8561e4 commit 653b485
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<version.spring>5.2.2.RELEASE</version.spring>
<version.springframework>${version.spring}</version.springframework>
<version.stream>2.9.6</version.stream>
<version.surefire.plugin>3.2.5</version.surefire.plugin>
<version.surefire.plugin>3.5.2</version.surefire.plugin>
<version.thrift>0.17.0</version.thrift>
<version.weld>3.1.1.Final</version.weld>
<version.weld-se>3.1.1.Final</version.weld-se>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected enum FieldExclusionType {
private static final Logger log = Logger.getLogger(FieldAgeOffFilter.class);

/**
* Determine whether or not the rules are applied
* Determine whether the rules are applied
*/
protected boolean ruleApplied = false;

Expand All @@ -104,9 +104,9 @@ protected enum FieldExclusionType {
protected Set<FieldExclusionType> fieldExcludeOptions = null;

/**
* Required by the {@code FilterRule} interface. This method returns a {@code boolean} value indicating whether or not to allow the {@code (Key, Value)}
* pair through the rule. A value of {@code true} indicates that he pair should be passed onward through the {@code Iterator} stack, and {@code false}
* indicates that the {@code (Key, Value)} pair should not be passed on.
* Required by the {@code FilterRule} interface. This method returns a {@code boolean} value indicating whether to allow the {@code (Key, Value)} pair
* through the rule. A value of {@code true} indicates that he pair should be passed onward through the {@code Iterator} stack, and {@code false} indicates
* that the {@code (Key, Value)} pair should not be passed on.
*
* <p>
* If the value provided in the parameter {@code k} does not match the REGEX pattern specified in this filter's configuration options, then a value of
Expand All @@ -116,27 +116,20 @@ protected enum FieldExclusionType {
* {@code Key} object containing the row, column family, and column qualifier.
* @param v
* {@code Value} object containing the value corresponding to the {@code Key: k}
* @return {@code boolean} value indicating whether or not to allow the {@code Key, Value} through the {@code Filter}.
* @return {@code boolean} value indicating whether to allow the {@code Key, Value} through the {@code Filter}.
*/
@Override
public boolean accept(AgeOffPeriod period, Key k, Value v) {

ruleApplied = false;
// if accepted by ColumnVisibilityOrFilter logic, pass the K/V up the iterator stack
// otherwise evaluate based on field
if (cvOrFilter.hasToken(k, v, this.cvOrFilter.getPatternBytes()) == false) {
return true;
}

// get the column qualifier, so that we can use it throughout
final byte[] cq = k.getColumnQualifierData().getBackingArray();

ByteSequence field = null;
FieldExclusionType candidateExclusionType = null;

/**
* Supports the shard and index table. There should not be a failure, however if either one is used on the incorrect table
*/
// Supports the shard and index table. There should not be a failure, however if either one is used on the incorrect table
if (isIndextable) {
field = k.getColumnFamilyData();

Expand Down Expand Up @@ -206,13 +199,15 @@ public boolean accept(AgeOffPeriod period, Key k, Value v) {
return true;
}

Long dataTypeCutoff = (fieldTimes.containsKey(field)) ? fieldTimes.get(field) : null;
if (dataTypeCutoff != null) {
ruleApplied = true;
return CompositeTimestamp.getAgeOffDate(k.getTimestamp()) > dataTypeCutoff;
Long dataTypeCutoff = fieldTimes.get(field);

// evaluating field first then the ColumnVisibilityOrFilter based on performance test results
if (dataTypeCutoff == null || !cvOrFilter.hasToken(k, v, this.cvOrFilter.getPatternBytes())) {
return true;
}

return true;
ruleApplied = true;
return CompositeTimestamp.getAgeOffDate(k.getTimestamp()) > dataTypeCutoff;
}

/**
Expand Down Expand Up @@ -275,7 +270,7 @@ protected void init(FilterOptions options, final long startScan, IteratorEnviron
isIndextable = Boolean.parseBoolean(iterEnv.getConfig().get("table.custom." + AgeOffConfigParams.IS_INDEX_TABLE));
}
} else { // legacy
isIndextable = Boolean.valueOf(options.getOption(AgeOffConfigParams.IS_INDEX_TABLE));
isIndextable = Boolean.parseBoolean(options.getOption(AgeOffConfigParams.IS_INDEX_TABLE));
}

fieldExcludeOptions = new HashSet<>();
Expand Down

0 comments on commit 653b485

Please sign in to comment.