Return-Path: Delivered-To: apmail-incubator-cassandra-commits-archive@minotaur.apache.org Received: (qmail 54461 invoked from network); 5 Mar 2010 20:21:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Mar 2010 20:21:15 -0000 Received: (qmail 54353 invoked by uid 500); 5 Mar 2010 20:21:01 -0000 Delivered-To: apmail-incubator-cassandra-commits-archive@incubator.apache.org Received: (qmail 54341 invoked by uid 500); 5 Mar 2010 20:21:01 -0000 Mailing-List: contact cassandra-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-dev@incubator.apache.org Delivered-To: mailing list cassandra-commits@incubator.apache.org Received: (qmail 54333 invoked by uid 99); 5 Mar 2010 20:21:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Mar 2010 20:21:01 +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; Fri, 05 Mar 2010 20:21:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BDBE123888D1; Fri, 5 Mar 2010 20:20:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r919587 - /incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java Date: Fri, 05 Mar 2010 20:20:39 -0000 To: cassandra-commits@incubator.apache.org From: jbellis@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100305202039.BDBE123888D1@eris.apache.org> Author: jbellis Date: Fri Mar 5 20:20:39 2010 New Revision: 919587 URL: http://svn.apache.org/viewvc?rev=919587&view=rev Log: add ConfigHelper class Added: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java (with props) Added: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java?rev=919587&view=auto ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java (added) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java Fri Mar 5 20:20:39 2010 @@ -0,0 +1,110 @@ +package org.apache.cassandra.hadoop; + +import org.apache.cassandra.thrift.InvalidRequestException; +import org.apache.cassandra.thrift.SlicePredicate; +import org.apache.cassandra.thrift.ThriftValidation; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.mapreduce.Job; +import org.apache.thrift.TDeserializer; +import org.apache.thrift.TException; +import org.apache.thrift.TSerializer; +import org.apache.thrift.protocol.TJSONProtocol; + +public class ConfigHelper +{ + private static final String KEYSPACE_CONFIG = "cassandra.input.keyspace"; + private static final String COLUMNFAMILY_CONFIG = "cassandra.input.columnfamily"; + private static final String PREDICATE_CONFIG = "cassandra.input.predicate"; + private static final String INPUT_SPLIT_SIZE_CONFIG = "cassandra.input.split.size"; + + public static void setColumnFamily(Configuration conf, String keyspace, String columnFamily) + { + if (keyspace == null) + { + throw new UnsupportedOperationException("keyspace may not be null"); + } + if (columnFamily == null) + { + throw new UnsupportedOperationException("columnfamily may not be null"); + } + try + { + ThriftValidation.validateColumnFamily(keyspace, columnFamily); + } + catch (InvalidRequestException e) + { + throw new RuntimeException(e); + } + conf.set(KEYSPACE_CONFIG, keyspace); + conf.set(COLUMNFAMILY_CONFIG, columnFamily); + } + + /** + * Set the size of the input split. + * This affects the number of maps created, if the number is too small + * the overhead of each map will take up the bulk of the job time. + * + * @param conf Job configuration you are about to run. + * @param splitsize Size of the input split + */ + public static void setInputSplitSize(Configuration conf, int splitsize) + { + conf.setInt(INPUT_SPLIT_SIZE_CONFIG, splitsize); + } + + public static int getInputSplitSize(Configuration conf) + { + return conf.getInt(INPUT_SPLIT_SIZE_CONFIG, 4096); + } + + public static void setSlicePredicate(Configuration conf, SlicePredicate predicate) + { + conf.set(PREDICATE_CONFIG, predicateToString(predicate)); + } + + public static SlicePredicate getSlicePredicate(Configuration conf) + { + return predicateFromString(conf.get(PREDICATE_CONFIG)); + } + + private static String predicateToString(SlicePredicate predicate) + { + assert predicate != null; + // this is so awful it's kind of cool! + TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); + try + { + return serializer.toString(predicate, "UTF-8"); + } + catch (TException e) + { + throw new RuntimeException(e); + } + } + + private static SlicePredicate predicateFromString(String st) + { + assert st != null; + TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory()); + SlicePredicate predicate = new SlicePredicate(); + try + { + deserializer.deserialize(predicate, st, "UTF-8"); + } + catch (TException e) + { + throw new RuntimeException(e); + } + return predicate; + } + + public static String getKeyspace(Configuration conf) + { + return conf.get(KEYSPACE_CONFIG); + } + + public static String getColumnFamily(Configuration conf) + { + return conf.get(COLUMNFAMILY_CONFIG); + } +} Propchange: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ConfigHelper.java ------------------------------------------------------------------------------ svn:eol-style = native