Author: apresta
Date: Wed Oct 10 01:15:53 2012
New Revision: 1396443
URL: http://svn.apache.org/viewvc?rev=1396443&view=rev
Log:
Adding missing files from GIRAPH-361
Added:
giraph/trunk/giraph-formats-contrib/src/main/java/org/apache/giraph/io/hcatalog/HiveUtils.java
giraph/trunk/giraph-formats-contrib/src/test/java/org/apache/giraph/io/hcatalog/
giraph/trunk/giraph-formats-contrib/src/test/java/org/apache/giraph/io/hcatalog/TestHiveUtils.java
Added:
giraph/trunk/giraph-formats-contrib/src/main/java/org/apache/giraph/io/hcatalog/HiveUtils.java
URL:
http://svn.apache.org/viewvc/giraph/trunk/giraph-formats-contrib/src/main/java/org/apache/giraph/io/hcatalog/HiveUtils.java?rev=1396443&view=auto
==============================================================================
---
giraph/trunk/giraph-formats-contrib/src/main/java/org/apache/giraph/io/hcatalog/HiveUtils.java
(added)
+++
giraph/trunk/giraph-formats-contrib/src/main/java/org/apache/giraph/io/hcatalog/HiveUtils.java
Wed Oct 10 01:15:53 2012
@@ -0,0 +1,64 @@
+/*
+ * 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.giraph.io.hcatalog;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utilities and helpers for working with Hive tables.
+ */
+public class HiveUtils {
+ // TODO use Hive util class if this is already provided by it
+
+ /**
+ * Private constructor for helper class.
+ */
+ private HiveUtils() {
+ // Do nothing.
+ }
+
+ /**
+ * @param outputTablePartitionString table partition string
+ * @return Map
+ */
+ public static Map<String, String> parsePartitionValues(
+ String outputTablePartitionString) {
+ if (outputTablePartitionString == null) {
+ return null;
+ }
+ Splitter commaSplitter = Splitter.on(',').omitEmptyStrings().trimResults();
+ Splitter equalSplitter = Splitter.on('=').omitEmptyStrings().trimResults();
+ Map<String, String> partitionValues = Maps.newHashMap();
+ for (String keyValStr : commaSplitter.split(outputTablePartitionString)) {
+ List<String> keyVal = Lists.newArrayList(equalSplitter.split(keyValStr));
+ if (keyVal.size() != 2) {
+ throw new IllegalArgumentException(
+ "Unrecognized partition value format: " +
+ outputTablePartitionString);
+ }
+ partitionValues.put(keyVal.get(0), keyVal.get(1));
+ }
+ return partitionValues;
+ }
+}
Added:
giraph/trunk/giraph-formats-contrib/src/test/java/org/apache/giraph/io/hcatalog/TestHiveUtils.java
URL:
http://svn.apache.org/viewvc/giraph/trunk/giraph-formats-contrib/src/test/java/org/apache/giraph/io/hcatalog/TestHiveUtils.java?rev=1396443&view=auto
==============================================================================
---
giraph/trunk/giraph-formats-contrib/src/test/java/org/apache/giraph/io/hcatalog/TestHiveUtils.java
(added)
+++
giraph/trunk/giraph-formats-contrib/src/test/java/org/apache/giraph/io/hcatalog/TestHiveUtils.java
Wed Oct 10 01:15:53 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.giraph.io.hcatalog;
+
+import java.util.Map;
+
+import static junit.framework.Assert.assertEquals;
+
+public class TestHiveUtils {
+ public void testParsePartition() {
+ String partitionStr = "feature1=2012-10-09, feature2=a1+b2,
feature3=ff-gg";
+ Map<String, String> partition =
HiveUtils.parsePartitionValues(partitionStr);
+ assertEquals(3, partition.size());
+ assertEquals("2012-10-09", partition.get("feature1"));
+ assertEquals("a1+b2", partition.get("feature2"));
+ assertEquals("ff-gg", partition.get("feature3"));
+ }
+}