Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5EB96200C3E for ; Tue, 7 Mar 2017 01:50:14 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5DAC2160B89; Tue, 7 Mar 2017 00:50:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8AB7B160B84 for ; Tue, 7 Mar 2017 01:50:13 +0100 (CET) Received: (qmail 76145 invoked by uid 500); 7 Mar 2017 00:50:12 -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 75182 invoked by uid 99); 7 Mar 2017 00:50:11 -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; Tue, 07 Mar 2017 00:50:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5D54EED4A1; Tue, 7 Mar 2017 00:50:11 +0000 (UTC) From: joshelser To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request #224: ACCUMULO-4500 ACCUMULO-96 Added summarization Content-Type: text/plain Message-Id: <20170307005011.5D54EED4A1@git1-us-west.apache.org> Date: Tue, 7 Mar 2017 00:50:11 +0000 (UTC) archived-at: Tue, 07 Mar 2017 00:50:14 -0000 Github user joshelser commented on a diff in the pull request: https://github.com/apache/accumulo/pull/224#discussion_r104511336 --- Diff: core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataScanner.java --- @@ -0,0 +1,228 @@ +/* + * 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.metadata.schema; + +import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.IsolatedScanner; +import org.apache.accumulo.core.client.Scanner; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.impl.ClientContext; +import org.apache.accumulo.core.data.impl.KeyExtent; +import org.apache.accumulo.core.metadata.MetadataTable; +import org.apache.accumulo.core.metadata.RootTable; +import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily; +import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily; +import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily; +import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily; +import org.apache.accumulo.core.metadata.schema.TabletMetadata.FetchedColumns; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.util.ColumnFQ; +import org.apache.hadoop.io.Text; + +import com.google.common.base.Preconditions; + +public class MetadataScanner { + + public static interface SourceOptions { + TableOptions from(Scanner scanner); + + TableOptions from(ClientContext ctx); + } + + public static interface TableOptions { + ColumnOptions overRootTable(); + + ColumnOptions overMetadataTable(); + + ColumnOptions overTableId(String tableId); + + ColumnOptions overTableId(String tableId, Text startRow, Text endRow); + } + + public static interface ColumnOptions { + public ColumnOptions fetchFiles(); + + public ColumnOptions fetchLocation(); + + public ColumnOptions fetchPrev(); + + public ColumnOptions fetchLast(); + + public Iterable build() throws TableNotFoundException, AccumuloException, AccumuloSecurityException; + } + + private static class Builder implements SourceOptions, TableOptions, ColumnOptions { + + private List families = new ArrayList<>(); + private List qualifiers = new ArrayList<>(); + private Scanner scanner; + private ClientContext ctx; + private String table; + private String userTableId; + private EnumSet fetchedCols = EnumSet.noneOf(FetchedColumns.class); + private Text startRow; + private Text endRow; + + @Override + public ColumnOptions fetchFiles() { + fetchedCols.add(FetchedColumns.FILES); + families.add(DataFileColumnFamily.NAME); + return this; + } + + @Override + public ColumnOptions fetchLocation() { + fetchedCols.add(FetchedColumns.LOCATION); + families.add(CurrentLocationColumnFamily.NAME); + families.add(FutureLocationColumnFamily.NAME); + return this; + } + + @Override + public ColumnOptions fetchPrev() { + fetchedCols.add(FetchedColumns.PREV_ROW); + qualifiers.add(PREV_ROW_COLUMN); + return this; + } + + @Override + public ColumnOptions fetchLast() { + fetchedCols.add(FetchedColumns.LAST); + families.add(LastLocationColumnFamily.NAME); + return this; + } + + @Override + public Iterable build() throws TableNotFoundException, AccumuloException, AccumuloSecurityException { + if (ctx != null) { + scanner = new IsolatedScanner(ctx.getConnector().createScanner(table, Authorizations.EMPTY)); + } else if (!(scanner instanceof IsolatedScanner)) { + scanner = new IsolatedScanner(scanner); + } + + if (userTableId != null) { + scanner.setRange(new KeyExtent(userTableId, null, startRow).toMetadataRange()); + } + + for (Text fam : families) { + scanner.fetchColumnFamily(fam); + } + + for (ColumnFQ col : qualifiers) { + col.fetch(scanner); + } + + if (families.size() == 0 && qualifiers.size() == 0) { + fetchedCols = EnumSet.allOf(FetchedColumns.class); + } + + Iterable tmi = TabletMetadata.convert(scanner, fetchedCols); + + if (endRow != null) { + // create an iterable that will stop at the tablet which contains the endRow + return new Iterable() { + @Override + public Iterator iterator() { + Iterator iter = tmi.iterator(); + return new Iterator() { --- End diff -- Maybe lift this `Iterator` into it's own class for test-ability. I think the inline `Iterable` wrapper is fine. @ --- 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. ---