From issues-return-4275-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Tue Jan 29 09:08:44 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7830D18067B for ; Tue, 29 Jan 2019 09:08:43 +0100 (CET) Received: (qmail 93468 invoked by uid 500); 29 Jan 2019 08:08:42 -0000 Mailing-List: contact issues-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list issues@phoenix.apache.org Received: (qmail 93459 invoked by uid 99); 29 Jan 2019 08:08:42 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jan 2019 08:08:42 +0000 From: GitBox To: issues@phoenix.apache.org Subject: [GitHub] ChinmaySKulkarni commented on a change in pull request #428: PHOENIX-374: Enable access to dynamic columns in * or cf.* selection Message-ID: <154874932188.8682.1023155377843906830.gitbox@gitbox.apache.org> Date: Tue, 29 Jan 2019 08:08:41 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ChinmaySKulkarni commented on a change in pull request #428: PHOENIX-374: Enable access to dynamic columns in * or cf.* selection URL: https://github.com/apache/phoenix/pull/428#discussion_r251726132 ########## File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DynamicColumnWildcard.java ########## @@ -0,0 +1,141 @@ +/* + * 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.phoenix.coprocessor; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.client.Mutation; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; +import org.apache.hadoop.hbase.coprocessor.RegionObserver; +import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.phoenix.coprocessor.generated.DynamicColumnMetaDataProtos; +import org.apache.phoenix.coprocessor.generated.PTableProtos; +import org.apache.phoenix.schema.PColumn; +import org.apache.phoenix.schema.PColumnImpl; +import org.apache.phoenix.util.ServerUtil; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.NavigableMap; +import java.util.Optional; + +/** + * Coprocessor for exposing dynamic columns in wildcard queries. This coprocessor will be registered + * to physical HBase tables only i.e. PTableType.TABLE and is driven by the client-side config + * QueryServices.WILDCARD_QUERY_DYNAMIC_COLS_ATTRIB + * See PHOENIX-374 + */ +public class DynamicColumnWildcard implements RegionObserver, RegionCoprocessor { + + private static final Log LOG = LogFactory.getLog(DynamicColumnWildcard.class); + // Scan attribute that is set in case we want to project dynamic columns + public static final String WILDCARD_SCAN_INCLUDES_DYNAMIC_COLUMNS = + "_WildcardScanIncludesDynCols"; + public static final byte[] DYN_COLS_METADATA_CELL_QUALIFIER = Bytes.toBytes("#Dyn_"); + + @Override + public Optional getRegionObserver() { + return Optional.of(this); + } + + @Override + public void preBatchMutate(ObserverContext c, + MiniBatchOperationInProgress miniBatchOp) throws IOException { + try { + preBatchMutateWithExceptions(c, miniBatchOp); + } catch(Throwable t) { + // Wrap all exceptions in an IOException to prevent region server crashes + throw ServerUtil.createIOException("Unable to Put cells corresponding to dynamic" + + "column metadata for " + + c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString(), t); + } + } + + /** + * Iterate over all Put mutations and add metadata for the list of dynamic columns for each + * column family in its own cell under reserved qualifiers. This is used for resolving dynamic + * columns for wildcard queries. See PHOENIX-374 + * @param c the region server environment + * @param miniBatchOp batch of mutations getting applied to region + * @throws IOException If an I/O error occurs when parsing protobuf + */ + private void preBatchMutateWithExceptions(ObserverContext c, + MiniBatchOperationInProgress miniBatchOp) throws IOException { + for (int i = 0; i < miniBatchOp.size(); i++) { + Mutation m = miniBatchOp.getOperation(i); + List putDynColMetaData = new ArrayList<>(1); + boolean isThereAnExtraPut = false; + if (m instanceof Put) { + // There is at max 1 extra Put (for dynamic column shadow cells) per original Put + putDynColMetaData.add(new Put(m.getRow())); + NavigableMap> famCellMap = m.getFamilyCellMap(); + for (byte[] fam : famCellMap.keySet()) { + byte[] serializedDynColsList = m.getAttribute(Bytes.toString(fam)); Review comment: Yes. The Put's attribute key is the column family name and the value is the serialized list of dynamic columns in that column family ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services