Return-Path: Delivered-To: apmail-hadoop-hbase-commits-archive@minotaur.apache.org Received: (qmail 34900 invoked from network); 20 May 2009 17:47:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 May 2009 17:47:43 -0000 Received: (qmail 98069 invoked by uid 500); 20 May 2009 17:47:52 -0000 Delivered-To: apmail-hadoop-hbase-commits-archive@hadoop.apache.org Received: (qmail 98034 invoked by uid 500); 20 May 2009 17:47:52 -0000 Mailing-List: contact hbase-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hbase-dev@hadoop.apache.org Delivered-To: mailing list hbase-commits@hadoop.apache.org Received: (qmail 97958 invoked by uid 99); 20 May 2009 17:47:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 May 2009 17:47:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 May 2009 17:47:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7A7EF238889C; Wed, 20 May 2009 17:47:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r776786 - /hadoop/hbase/branches/0.19/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexMaintenanceUtils.java Date: Wed, 20 May 2009 17:47:29 -0000 To: hbase-commits@hadoop.apache.org From: stack@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090520174729.7A7EF238889C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: stack Date: Wed May 20 17:47:29 2009 New Revision: 776786 URL: http://svn.apache.org/viewvc?rev=776786&view=rev Log: HBASE-1420 add abliity to add and remove table) indexes on existing... Added: hadoop/hbase/branches/0.19/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexMaintenanceUtils.java Added: hadoop/hbase/branches/0.19/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexMaintenanceUtils.java URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.19/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexMaintenanceUtils.java?rev=776786&view=auto ============================================================================== --- hadoop/hbase/branches/0.19/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexMaintenanceUtils.java (added) +++ hadoop/hbase/branches/0.19/src/java/org/apache/hadoop/hbase/regionserver/tableindexed/IndexMaintenanceUtils.java Wed May 20 17:47:29 2009 @@ -0,0 +1,73 @@ +/** + * Copyright 2008 The Apache Software Foundation 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.hadoop.hbase.regionserver.tableindexed; + +import java.util.SortedMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.client.tableindexed.IndexSpecification; +import org.apache.hadoop.hbase.client.tableindexed.IndexedTable; +import org.apache.hadoop.hbase.io.BatchUpdate; +import org.apache.hadoop.hbase.util.Bytes; + +/** + * Singleton class for index maintence logic. + */ +public class IndexMaintenanceUtils { + + private static final Log LOG = LogFactory.getLog(IndexMaintenanceUtils.class); + + public static BatchUpdate createIndexUpdate(final IndexSpecification indexSpec, final byte[] row, + final SortedMap columnValues) { + byte[] indexRow = indexSpec.getKeyGenerator().createIndexKey(row, columnValues); + BatchUpdate update = new BatchUpdate(indexRow); + + update.put(IndexedTable.INDEX_BASE_ROW_COLUMN, row); + + for (byte[] col : indexSpec.getIndexedColumns()) { + byte[] val = columnValues.get(col); + if (val == null) { + throw new RuntimeException("Unexpected missing column value. [" + Bytes.toString(col) + "]"); + } + update.put(col, val); + } + + for (byte[] col : indexSpec.getAdditionalColumns()) { + byte[] val = columnValues.get(col); + if (val != null) { + update.put(col, val); + } + } + + return update; + } + + /** + * Ask if this update does apply to the index. + * + * @param indexSpec + * @param b + * @return true if possibly apply. + */ + public static boolean doesApplyToIndex(final IndexSpecification indexSpec, + final SortedMap columnValues) { + + for (byte[] neededCol : indexSpec.getIndexedColumns()) { + if (!columnValues.containsKey(neededCol)) { + LOG.debug("Index [" + indexSpec.getIndexId() + "] can't be updated because [" + + Bytes.toString(neededCol) + "] is missing"); + return false; + } + } + return true; + } +}