Created
March 4, 2013 19:06
-
-
Save jnatkins/5084569 to your computer and use it in GitHub Desktop.
A loader for generating a small set of sample data for a Kiji and HBase table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kiji.examples.importers; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.apache.hadoop.conf.Configured; | |
import org.apache.hadoop.hbase.HBaseConfiguration; | |
import org.apache.hadoop.hbase.client.HTable; | |
import org.apache.hadoop.hbase.client.Put; | |
import org.apache.hadoop.hbase.util.Bytes; | |
import org.apache.hadoop.util.Tool; | |
import org.apache.hadoop.util.ToolRunner; | |
import org.kiji.schema.Kiji; | |
import org.kiji.schema.KijiTable; | |
import org.kiji.schema.KijiTableWriter; | |
import org.kiji.schema.KijiURI; | |
/** | |
* A small data loader for loading an identical dataset into an | |
* HBase and Kiji table. | |
* | |
* See the context of this class on the Kiji blog: | |
* http://www.kiji.org/use-disk-space-efficiently-with-kiji-schema | |
*/ | |
public class KijiAndHBaseTestLoader extends Configured implements Tool { | |
@Override | |
public int run(String[] args) throws Exception { | |
setConf(HBaseConfiguration.addHbaseResources(getConf())); | |
/* Open the HBase table */ | |
HTable htable = new HTable(getConf(), "hbase_test"); | |
KijiURI uri = KijiURI.parse("kiji://.env/default"); | |
Kiji kiji = Kiji.Factory.open(uri); | |
/* Open the Kiji table */ | |
KijiTable table = kiji.openTable("kiji_test"); | |
KijiTableWriter writer = table.openTableWriter(); | |
List<Put> puts = new ArrayList<Put>(); | |
for (int i = 1; i <= 5000; i++) { | |
Put put = new Put(Bytes.toBytes("key" + i)); | |
put.add( | |
Bytes.toBytes("really_long_column_family_names_are_ok_with_kiji"), | |
Bytes.toBytes("even_longer_column_qualifiers_are_no_problem_with_kiji_schema"), | |
Bytes.toBytes("1234")); | |
puts.add(put); | |
writer.put(table.getEntityId("key" + i), | |
"really_long_column_family_names_are_ok_with_kiji", | |
"even_longer_column_qualifiers_are_no_problem_with_kiji_schema", | |
"1234"); | |
} | |
htable.put(puts); | |
return 0; | |
} | |
public static void main(String args[]) throws Exception { | |
System.exit(ToolRunner.run(new KijiAndHBaseTestLoader(), args)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment