Return-Path: X-Original-To: apmail-accumulo-dev-archive@www.apache.org Delivered-To: apmail-accumulo-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 50237182C6 for ; Fri, 14 Aug 2015 18:43:51 +0000 (UTC) Received: (qmail 13848 invoked by uid 500); 14 Aug 2015 18:43:51 -0000 Delivered-To: apmail-accumulo-dev-archive@accumulo.apache.org Received: (qmail 13808 invoked by uid 500); 14 Aug 2015 18:43:51 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 13792 invoked by uid 99); 14 Aug 2015 18:43:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Aug 2015 18:43:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CA36FE08E0; Fri, 14 Aug 2015 18:43:50 +0000 (UTC) From: keith-turner To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request: Implementation of SeekingFilter, CfCqSliceF... Content-Type: text/plain Message-Id: <20150814184350.CA36FE08E0@git1-us-west.apache.org> Date: Fri, 14 Aug 2015 18:43:50 +0000 (UTC) Github user keith-turner commented on a diff in the pull request: https://github.com/apache/accumulo/pull/42#discussion_r37106676 --- Diff: core/src/main/java/org/apache/accumulo/core/iterators/user/CfCqSliceSeekingFilter.java --- @@ -0,0 +1,132 @@ +/* + * 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.Key; +import org.apache.accumulo.core.data.PartialKey; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.OptionDescriber; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; + +import java.io.IOException; +import java.util.Map; + +/** + * Filters key/value pairs for a range of column families and a range of column qualifiers. Only keys which fall in both ranges will be passed by the filter. + * Note that if you have a small, well-defined set of column families it will be much more efficient to configure locality groups to isolate that data instead + * of configuring this iterator to seek over it. + * + * This filter may be more efficient than the CfCqSliceFilter or the ColumnSlice filter for small slices of large rows as it will seek to the next potential + * match once it determines that it has iterated past the end of a slice. + * + * @see org.apache.accumulo.core.iterators.user.CfCqSliceOpts for a description of this iterator's options. + */ +public class CfCqSliceSeekingFilter extends SeekingFilter implements OptionDescriber { + + private static final FilterResult SKIP_TO_HINT = new FilterResult(false, AdvanceResult.USE_HINT); + private static final FilterResult SKIP_TO_NEXT = new FilterResult(false, AdvanceResult.NEXT); + private static final FilterResult SKIP_TO_NEXT_ROW = new FilterResult(false, AdvanceResult.NEXT_ROW); + private static final FilterResult SKIP_TO_NEXT_CF = new FilterResult(false, AdvanceResult.NEXT_CF); + private static final FilterResult INCLUDE_AND_NEXT = new FilterResult(true, AdvanceResult.NEXT); + private static final FilterResult INCLUDE_AND_NEXT_CF = new FilterResult(true, AdvanceResult.NEXT_CF); + + private CfCqSliceOpts cso; + + @Override + public void init(SortedKeyValueIterator source, Map options, IteratorEnvironment env) throws IOException { + super.init(source, options, env); + cso = new CfCqSliceOpts(options); + } + + @Override + public FilterResult filter(Key k, Value v) { + if (cso.minCf.getLength() > 0) { + int minCfCmp = k.compareColumnFamily(cso.minCf); + if (minCfCmp < 0) { + return SKIP_TO_HINT; // hint will be the min CF in this row. + } + if (minCfCmp == 0 && !cso.minInclusive) { + return SKIP_TO_NEXT; + } + } + if (cso.maxCf.getLength() > 0) { + int maxCfCmp = k.compareColumnFamily(cso.maxCf); + if (maxCfCmp > 0 || (maxCfCmp == 0 && !cso.maxInclusive)) { + return SKIP_TO_NEXT_ROW; + } + } + // at this point we're in the correct CF range, now check the CQ. + if (cso.minCq.getLength() > 0) { + int minCqCmp = k.compareColumnQualifier(cso.minCq); + if (minCqCmp < 0) { + return SKIP_TO_HINT; // hint will be the min CQ in this CF in this row. + } + if (minCqCmp == 0 && !cso.minInclusive) { + return SKIP_TO_NEXT; + } + } + if (cso.maxCq.getLength() > 0) { + int maxCqCmp = k.compareColumnQualifier(cso.maxCq); + if (maxCqCmp > 0 || (maxCqCmp == 0 && !cso.maxInclusive)) { + return SKIP_TO_NEXT_CF; + } + if (maxCqCmp == 0) { + // special-case here: we know we're at the last CQ in the slice, so skip to the next CF in the row. + return INCLUDE_AND_NEXT_CF; + } + } + // at this point we're in the CQ slice. + return INCLUDE_AND_NEXT; + } + + @Override + public Key getNextKeyHint(Key k, Value v) { + if (cso.minCf.getLength() > 0) { + int minCfCmp = k.compareColumnFamily(cso.minCf); + if (minCfCmp < 0) { + Key hint = new Key(k.getRow(), cso.minCf); + return cso.minInclusive ? hint : hint.followingKey(PartialKey.ROW_COLFAM); + } + } + if (cso.minCq.getLength() > 0) { + int minCqCmp = k.compareColumnQualifier(cso.minCq); + if (minCqCmp < 0) { + Key hint = new Key(k.getRow(), k.getColumnFamily(), cso.minCq); + return cso.minInclusive ? hint : hint.followingKey(PartialKey.ROW_COLFAM_COLQUAL); + } + } + return null; --- End diff -- This case is not covered in unit test --- 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. ---