accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From keith-turner <...@git.apache.org>
Subject [GitHub] accumulo pull request: Implementation of SeekingFilter, CfCqSliceF...
Date Fri, 14 Aug 2015 11:23:39 GMT
Github user keith-turner commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/42#discussion_r37068064
  
    --- Diff: core/src/main/java/org/apache/accumulo/core/iterators/user/SeekingFilter.java
---
    @@ -0,0 +1,206 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.accumulo.core.iterators.user;
    +
    +import org.apache.accumulo.core.data.ByteSequence;
    +import org.apache.accumulo.core.data.Key;
    +import org.apache.accumulo.core.data.PartialKey;
    +import org.apache.accumulo.core.data.Range;
    +import org.apache.accumulo.core.data.Value;
    +import org.apache.accumulo.core.iterators.IteratorEnvironment;
    +import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
    +import org.apache.accumulo.core.iterators.WrappingIterator;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.IOException;
    +import java.util.Collection;
    +import java.util.Map;
    +
    +/**
    + * Base class for filters that can skip over key-value pairs which do not match their
filter predicate. In addition to returning true/false to accept or reject
    + * a kv pair, subclasses can return an extra field which indicates how far the source
iterator should be advanced.
    + *
    + * Note that the behaviour of the negate option is different from the Filter class. If
a KV pair fails the subclass' filter predicate and negate is true, then
    + * the KV pair will pass the filter. However if the subclass advances the source past
a bunch of KV pairs, all those pairs will be implicitly rejected and
    + * negate will have no effect.
    + *
    + * @see org.apache.accumulo.core.iterators.Filter
    + */
    +public abstract class SeekingFilter extends WrappingIterator {
    +  private static final Logger log = LoggerFactory.getLogger(SeekingFilter.class);
    +
    +  protected static final String NEGATE = "negate";
    +
    +  public enum AdvanceResult {
    +    NEXT, NEXT_CQ, NEXT_CF, NEXT_ROW, USE_HINT
    +  }
    +
    +  public static class FilterResult {
    +    final boolean accept;
    +    final AdvanceResult advance;
    +
    +    public FilterResult(boolean accept, AdvanceResult advance) {
    --- End diff --
    
    Could pass the hint back via the FilterResult.  Thinking that sometimes the hint may have
been calculated in `filter()`.   I was also trying to think of a way that object allocation
could be avoided since there is a small number of possible FilterResult instances when using
the enum+boolean option.  One possibility I thought of is static factory methods to avoid
creating objects.   
    
    ```java
     public static class FilterResult {
        final boolean accept;
        final AdvanceResult advance;
        final Key hint;
    
        private FilterResult(boolean accept, AdvanceResult advance) {
          this.accept = accept;
          this.advance = advance;
        }
        private FilterResult(boolean accept, Key hint) {
          this.accept = accept;
          this.hint = hint;
        }
        
       public static FilterResult of(boolean accept, Key hint){
         return new FilterResult(accept, hint);
       }
    
       private static final  FilterResult ROW_FALSE_FR = new FilterResult(false, AdvanceResult.NEXT_ROW);
    
       public static FilterResult of(boolean accept, AdvanceResult advanceResult){
              if(accept){
                  //return constants ...
              }else{
                 switch (advanceResult){
                     case NEXT_ROW:
                       return ROW_FALSE_FR;
                     //handle other cases
                 }
              }
       }
    
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message