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 022D5200D3F for ; Sat, 14 Oct 2017 16:42:48 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 00CE4160BEA; Sat, 14 Oct 2017 14:42:48 +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 14483160BE9 for ; Sat, 14 Oct 2017 16:42:46 +0200 (CEST) Received: (qmail 82714 invoked by uid 500); 14 Oct 2017 14:42:43 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 81718 invoked by uid 99); 14 Oct 2017 14:42:42 -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; Sat, 14 Oct 2017 14:42:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9C5D4DFF0A; Sat, 14 Oct 2017 14:42:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gates@apache.org To: commits@hive.apache.org Date: Sat, 14 Oct 2017 14:42:44 -0000 Message-Id: <63848914421a4f63a0b927339ddab76e@git.apache.org> In-Reply-To: <969fe65ed34e4540b38d4ec622de8484@git.apache.org> References: <969fe65ed34e4540b38d4ec622de8484@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/27] hive git commit: HIVE-17733 Move RawStore to standalone metastore. This closes #258 github PR. (Alan Gates, reviewed by Sergey Shelukhin, Vihang Karajgaonkar, and Zoltan Haindrich) archived-at: Sat, 14 Oct 2017 14:42:48 -0000 http://git-wip-us.apache.org/repos/asf/hive/blob/133d3c47/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/ByteArrayWrapper.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/ByteArrayWrapper.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/ByteArrayWrapper.java new file mode 100644 index 0000000..2e92a4f --- /dev/null +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/ByteArrayWrapper.java @@ -0,0 +1,45 @@ +/* + * 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.hive.metastore.cache; + +import java.util.Arrays; + +/** + * byte array with comparator + */ +public class ByteArrayWrapper { + byte[] wrapped; + + ByteArrayWrapper(byte[] b) { + wrapped = b; + } + + @Override + public boolean equals(Object other) { + if (other instanceof ByteArrayWrapper) { + return Arrays.equals(((ByteArrayWrapper)other).wrapped, wrapped); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Arrays.hashCode(wrapped); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hive/blob/133d3c47/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java ---------------------------------------------------------------------- diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java new file mode 100644 index 0000000..ab6b90f --- /dev/null +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java @@ -0,0 +1,143 @@ +/* + * 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.hive.metastore.cache; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.SkewedInfo; +import org.apache.hadoop.hive.metastore.api.StorageDescriptor; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.cache.CachedStore.PartitionWrapper; +import org.apache.hadoop.hive.metastore.cache.CachedStore.TableWrapper; +import org.apache.hadoop.hive.metastore.utils.StringUtils; + +public class CacheUtils { + private static final String delimit = "\u0001"; + + public static String buildKey(String dbName, String tableName) { + return dbName + delimit + tableName; + } + + public static String buildKeyWithDelimit(String dbName, String tableName) { + return buildKey(dbName, tableName) + delimit; + } + + public static String buildKey(String dbName, String tableName, List partVals) { + String key = buildKey(dbName, tableName); + if (partVals == null || partVals.size() == 0) { + return key; + } + for (int i = 0; i < partVals.size(); i++) { + key += partVals.get(i); + if (i != partVals.size() - 1) { + key += delimit; + } + } + return key; + } + + public static String buildKeyWithDelimit(String dbName, String tableName, List partVals) { + return buildKey(dbName, tableName, partVals) + delimit; + } + + public static String buildKey(String dbName, String tableName, List partVals, String colName) { + String key = buildKey(dbName, tableName, partVals); + return key + delimit + colName; + } + + public static String buildKey(String dbName, String tableName, String colName) { + String key = buildKey(dbName, tableName); + return key + delimit + colName; + } + + public static String[] splitTableColStats(String key) { + return key.split(delimit); + } + + public static Object[] splitPartitionColStats(String key) { + Object[] result = new Object[4]; + String[] comps = key.split(delimit); + result[0] = comps[0]; + result[1] = comps[1]; + List vals = new ArrayList<>(); + for (int i=2;i()); + } + if (sdCopy.getSortCols()==null) { + sdCopy.setSortCols(new ArrayList<>()); + } + if (sdCopy.getSkewedInfo()==null) { + sdCopy.setSkewedInfo(new SkewedInfo(new ArrayList<>(), + new ArrayList<>(), new HashMap<>())); + } + sdCopy.setLocation(wrapper.getLocation()); + sdCopy.setParameters(wrapper.getParameters()); + t.setSd(sdCopy); + } + return t; + } + + static Partition assemble(PartitionWrapper wrapper, SharedCache sharedCache) { + Partition p = wrapper.getPartition().deepCopy(); + if (wrapper.getSdHash()!=null) { + StorageDescriptor sdCopy = sharedCache.getSdFromCache(wrapper.getSdHash()).deepCopy(); + if (sdCopy.getBucketCols()==null) { + sdCopy.setBucketCols(new ArrayList<>()); + } + if (sdCopy.getSortCols()==null) { + sdCopy.setSortCols(new ArrayList<>()); + } + if (sdCopy.getSkewedInfo()==null) { + sdCopy.setSkewedInfo(new SkewedInfo(new ArrayList<>(), + new ArrayList<>(), new HashMap<>())); + } + sdCopy.setLocation(wrapper.getLocation()); + sdCopy.setParameters(wrapper.getParameters()); + p.setSd(sdCopy); + } + return p; + } + + public static boolean matches(String name, String pattern) { + String[] subpatterns = pattern.trim().split("\\|"); + for (String subpattern : subpatterns) { + subpattern = "(?i)" + subpattern.replaceAll("\\?", ".{1}").replaceAll("\\*", ".*") + .replaceAll("\\^", "\\\\^").replaceAll("\\$", "\\\\$"); + if (Pattern.matches(subpattern, StringUtils.normalizeIdentifier(name))) { + return true; + } + } + return false; + } +}