From 653b485c580540fa00a920b04b7b73c6df80f5c1 Mon Sep 17 00:00:00 2001 From: Joseph Alphonso Date: Mon, 16 Dec 2024 15:07:05 -0500 Subject: [PATCH] Optimize FieldAgeOffFilter (#2668) Authored-by: Joe Alphonso Closes #2667 --- pom.xml | 2 +- .../filter/ageoff/FieldAgeOffFilter.java | 33 ++++++++----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index bfdf749bb46..cf17f340616 100644 --- a/pom.xml +++ b/pom.xml @@ -126,7 +126,7 @@ 5.2.2.RELEASE ${version.spring} 2.9.6 - 3.2.5 + 3.5.2 0.17.0 3.1.1.Final 3.1.1.Final diff --git a/warehouse/age-off/src/main/java/datawave/iterators/filter/ageoff/FieldAgeOffFilter.java b/warehouse/age-off/src/main/java/datawave/iterators/filter/ageoff/FieldAgeOffFilter.java index d0875f2176b..53d230868e8 100644 --- a/warehouse/age-off/src/main/java/datawave/iterators/filter/ageoff/FieldAgeOffFilter.java +++ b/warehouse/age-off/src/main/java/datawave/iterators/filter/ageoff/FieldAgeOffFilter.java @@ -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; @@ -104,9 +104,9 @@ protected enum FieldExclusionType { protected Set 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. * *

* 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 @@ -116,17 +116,12 @@ 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(); @@ -134,9 +129,7 @@ public boolean accept(AgeOffPeriod period, Key k, Value v) { 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(); @@ -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; } /** @@ -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<>();