You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2018/11/07 16:28:15 UTC
[3/9] hbase git commit: HBASE-21443 [hbase-connectors] Purge hbase-*
modules from core now they've been moved to hbase-connectors
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseBulkPutExample.scala
----------------------------------------------------------------------
diff --git a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseBulkPutExample.scala b/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseBulkPutExample.scala
deleted file mode 100644
index 9f5885f..0000000
--- a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseBulkPutExample.scala
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.hbase.spark.example.rdd
-
-import org.apache.hadoop.hbase.client.Put
-import org.apache.hadoop.hbase.spark.HBaseContext
-import org.apache.hadoop.hbase.spark.HBaseRDDFunctions._
-import org.apache.hadoop.hbase.util.Bytes
-import org.apache.hadoop.hbase.HBaseConfiguration
-import org.apache.hadoop.hbase.TableName
-import org.apache.spark.SparkConf
-import org.apache.spark.SparkContext
-import org.apache.yetus.audience.InterfaceAudience
-
-/**
- * This is a simple example of putting records in HBase
- * with the bulkPut function.
- */
-@InterfaceAudience.Private
-object HBaseBulkPutExample {
- def main(args: Array[String]) {
- if (args.length < 2) {
- println("HBaseBulkPutExample {tableName} {columnFamily} are missing an arguments")
- return
- }
-
- val tableName = args(0)
- val columnFamily = args(1)
-
- val sparkConf = new SparkConf().setAppName("HBaseBulkPutExample " +
- tableName + " " + columnFamily)
- val sc = new SparkContext(sparkConf)
-
- try {
- //[(Array[Byte], Array[(Array[Byte], Array[Byte], Array[Byte])])]
- val rdd = sc.parallelize(Array(
- (Bytes.toBytes("1"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("1")))),
- (Bytes.toBytes("2"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("2")))),
- (Bytes.toBytes("3"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("3")))),
- (Bytes.toBytes("4"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("4")))),
- (Bytes.toBytes("5"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("5"))))
- ))
-
- val conf = HBaseConfiguration.create()
-
- val hbaseContext = new HBaseContext(sc, conf)
-
- rdd.hbaseBulkPut(hbaseContext, TableName.valueOf(tableName),
- (putRecord) => {
- val put = new Put(putRecord._1)
- putRecord._2.foreach((putValue) => put.addColumn(putValue._1, putValue._2,
- putValue._3))
- put
- })
-
- } finally {
- sc.stop()
- }
- }
- }
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseForeachPartitionExample.scala
----------------------------------------------------------------------
diff --git a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseForeachPartitionExample.scala b/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseForeachPartitionExample.scala
deleted file mode 100644
index be257ee..0000000
--- a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseForeachPartitionExample.scala
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.hbase.spark.example.rdd
-
-import org.apache.hadoop.hbase.HBaseConfiguration
-import org.apache.hadoop.hbase.TableName
-import org.apache.hadoop.hbase.client.Put
-import org.apache.hadoop.hbase.spark.HBaseContext
-import org.apache.hadoop.hbase.spark.HBaseRDDFunctions._
-import org.apache.hadoop.hbase.util.Bytes
-import org.apache.spark.SparkConf
-import org.apache.spark.SparkContext
-import org.apache.yetus.audience.InterfaceAudience
-
-/**
- * This is a simple example of using the foreachPartition
- * method with a HBase connection
- */
-@InterfaceAudience.Private
-object HBaseForeachPartitionExample {
- def main(args: Array[String]) {
- if (args.length < 2) {
- println("HBaseForeachPartitionExample {tableName} {columnFamily} are missing an arguments")
- return
- }
-
- val tableName = args(0)
- val columnFamily = args(1)
-
- val sparkConf = new SparkConf().setAppName("HBaseForeachPartitionExample " +
- tableName + " " + columnFamily)
- val sc = new SparkContext(sparkConf)
-
- try {
- //[(Array[Byte], Array[(Array[Byte], Array[Byte], Array[Byte])])]
- val rdd = sc.parallelize(Array(
- (Bytes.toBytes("1"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("1")))),
- (Bytes.toBytes("2"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("2")))),
- (Bytes.toBytes("3"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("3")))),
- (Bytes.toBytes("4"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("4")))),
- (Bytes.toBytes("5"),
- Array((Bytes.toBytes(columnFamily), Bytes.toBytes("1"), Bytes.toBytes("5"))))
- ))
-
- val conf = HBaseConfiguration.create()
-
- val hbaseContext = new HBaseContext(sc, conf)
-
-
- rdd.hbaseForeachPartition(hbaseContext,
- (it, connection) => {
- val m = connection.getBufferedMutator(TableName.valueOf(tableName))
-
- it.foreach(r => {
- val put = new Put(r._1)
- r._2.foreach((putValue) =>
- put.addColumn(putValue._1, putValue._2, putValue._3))
- m.mutate(put)
- })
- m.flush()
- m.close()
- })
-
- } finally {
- sc.stop()
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseMapPartitionExample.scala
----------------------------------------------------------------------
diff --git a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseMapPartitionExample.scala b/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseMapPartitionExample.scala
deleted file mode 100644
index 0793524..0000000
--- a/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/example/rdd/HBaseMapPartitionExample.scala
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.hbase.spark.example.rdd
-
-import org.apache.hadoop.hbase.client.Get
-import org.apache.hadoop.hbase.spark.HBaseContext
-import org.apache.hadoop.hbase.spark.HBaseRDDFunctions._
-import org.apache.hadoop.hbase.util.Bytes
-import org.apache.hadoop.hbase.HBaseConfiguration
-import org.apache.hadoop.hbase.TableName
-import org.apache.spark.SparkConf
-import org.apache.spark.SparkContext
-import org.apache.yetus.audience.InterfaceAudience
-
-/**
- * This is a simple example of using the mapPartitions
- * method with a HBase connection
- */
-@InterfaceAudience.Private
-object HBaseMapPartitionExample {
- def main(args: Array[String]) {
- if (args.length < 1) {
- println("HBaseMapPartitionExample {tableName} is missing an argument")
- return
- }
-
- val tableName = args(0)
-
- val sparkConf = new SparkConf().setAppName("HBaseMapPartitionExample " + tableName)
- val sc = new SparkContext(sparkConf)
-
- try {
-
- //[(Array[Byte])]
- val rdd = sc.parallelize(Array(
- Bytes.toBytes("1"),
- Bytes.toBytes("2"),
- Bytes.toBytes("3"),
- Bytes.toBytes("4"),
- Bytes.toBytes("5"),
- Bytes.toBytes("6"),
- Bytes.toBytes("7")))
-
- val conf = HBaseConfiguration.create()
-
- val hbaseContext = new HBaseContext(sc, conf)
-
- val getRdd = rdd.hbaseMapPartitions[String](hbaseContext, (it, connection) => {
- val table = connection.getTable(TableName.valueOf(tableName))
- it.map{r =>
- //batching would be faster. This is just an example
- val result = table.get(new Get(r))
-
- val it = result.listCells().iterator()
- val b = new StringBuilder
-
- b.append(Bytes.toString(result.getRow) + ":")
-
- while (it.hasNext) {
- val cell = it.next()
- val q = Bytes.toString(cell.getQualifierArray)
- if (q.equals("counter")) {
- b.append("(" + q + "," + Bytes.toLong(cell.getValueArray) + ")")
- } else {
- b.append("(" + q + "," + Bytes.toString(cell.getValueArray) + ")")
- }
- }
- b.toString()
- }
- })
-
- getRdd.collect().foreach(v => println(v))
-
- } finally {
- sc.stop()
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java
----------------------------------------------------------------------
diff --git a/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java b/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java
deleted file mode 100644
index 723b09a..0000000
--- a/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java
+++ /dev/null
@@ -1,538 +0,0 @@
-/**
- * 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.hbase.spark;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.Admin;
-import org.apache.hadoop.hbase.client.Connection;
-import org.apache.hadoop.hbase.client.ConnectionFactory;
-import org.apache.hadoop.hbase.client.Delete;
-import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.client.Table;
-import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.spark.example.hbasecontext.JavaHBaseBulkDeleteExample;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.apache.hadoop.hbase.testclassification.MiscTests;
-import org.apache.hadoop.hbase.tool.LoadIncrementalHFiles;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.spark.api.java.JavaRDD;
-import org.apache.spark.api.java.JavaSparkContext;
-import org.apache.spark.api.java.function.Function;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import scala.Tuple2;
-
-import org.apache.hbase.thirdparty.com.google.common.io.Files;
-
-@Category({MiscTests.class, MediumTests.class})
-public class TestJavaHBaseContext implements Serializable {
-
- @ClassRule
- public static final HBaseClassTestRule TIMEOUT =
- HBaseClassTestRule.forClass(TestJavaHBaseContext.class);
-
- private transient JavaSparkContext jsc;
- HBaseTestingUtility htu;
- protected static final Logger LOG = LoggerFactory.getLogger(TestJavaHBaseContext.class);
-
-
-
- byte[] tableName = Bytes.toBytes("t1");
- byte[] columnFamily = Bytes.toBytes("c");
- byte[] columnFamily1 = Bytes.toBytes("d");
- String columnFamilyStr = Bytes.toString(columnFamily);
- String columnFamilyStr1 = Bytes.toString(columnFamily1);
-
-
- @Before
- public void setUp() {
- jsc = new JavaSparkContext("local", "JavaHBaseContextSuite");
-
- File tempDir = Files.createTempDir();
- tempDir.deleteOnExit();
-
- htu = new HBaseTestingUtility();
- try {
- LOG.info("cleaning up test dir");
-
- htu.cleanupTestDir();
-
- LOG.info("starting minicluster");
-
- htu.startMiniZKCluster();
- htu.startMiniHBaseCluster();
-
- LOG.info(" - minicluster started");
-
- try {
- htu.deleteTable(TableName.valueOf(tableName));
- } catch (Exception e) {
- LOG.info(" - no table " + Bytes.toString(tableName) + " found");
- }
-
- LOG.info(" - creating table " + Bytes.toString(tableName));
- htu.createTable(TableName.valueOf(tableName),
- new byte[][]{columnFamily, columnFamily1});
- LOG.info(" - created table");
- } catch (Exception e1) {
- throw new RuntimeException(e1);
- }
- }
-
- @After
- public void tearDown() {
- try {
- htu.deleteTable(TableName.valueOf(tableName));
- LOG.info("shuting down minicluster");
- htu.shutdownMiniHBaseCluster();
- htu.shutdownMiniZKCluster();
- LOG.info(" - minicluster shut down");
- htu.cleanupTestDir();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- jsc.stop();
- jsc = null;
- }
-
- @Test
- public void testBulkPut() throws IOException {
-
- List<String> list = new ArrayList<>(5);
- list.add("1," + columnFamilyStr + ",a,1");
- list.add("2," + columnFamilyStr + ",a,2");
- list.add("3," + columnFamilyStr + ",a,3");
- list.add("4," + columnFamilyStr + ",a,4");
- list.add("5," + columnFamilyStr + ",a,5");
-
- JavaRDD<String> rdd = jsc.parallelize(list);
-
- Configuration conf = htu.getConfiguration();
-
- JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
-
- Connection conn = ConnectionFactory.createConnection(conf);
- Table table = conn.getTable(TableName.valueOf(tableName));
-
- try {
- List<Delete> deletes = new ArrayList<>(5);
- for (int i = 1; i < 6; i++) {
- deletes.add(new Delete(Bytes.toBytes(Integer.toString(i))));
- }
- table.delete(deletes);
- } finally {
- table.close();
- }
-
- hbaseContext.bulkPut(rdd,
- TableName.valueOf(tableName),
- new PutFunction());
-
- table = conn.getTable(TableName.valueOf(tableName));
-
- try {
- Result result1 = table.get(new Get(Bytes.toBytes("1")));
- Assert.assertNotNull("Row 1 should had been deleted", result1.getRow());
-
- Result result2 = table.get(new Get(Bytes.toBytes("2")));
- Assert.assertNotNull("Row 2 should had been deleted", result2.getRow());
-
- Result result3 = table.get(new Get(Bytes.toBytes("3")));
- Assert.assertNotNull("Row 3 should had been deleted", result3.getRow());
-
- Result result4 = table.get(new Get(Bytes.toBytes("4")));
- Assert.assertNotNull("Row 4 should had been deleted", result4.getRow());
-
- Result result5 = table.get(new Get(Bytes.toBytes("5")));
- Assert.assertNotNull("Row 5 should had been deleted", result5.getRow());
- } finally {
- table.close();
- conn.close();
- }
- }
-
- public static class PutFunction implements Function<String, Put> {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Put call(String v) throws Exception {
- String[] cells = v.split(",");
- Put put = new Put(Bytes.toBytes(cells[0]));
-
- put.addColumn(Bytes.toBytes(cells[1]), Bytes.toBytes(cells[2]),
- Bytes.toBytes(cells[3]));
- return put;
- }
- }
-
- @Test
- public void testBulkDelete() throws IOException {
- List<byte[]> list = new ArrayList<>(3);
- list.add(Bytes.toBytes("1"));
- list.add(Bytes.toBytes("2"));
- list.add(Bytes.toBytes("3"));
-
- JavaRDD<byte[]> rdd = jsc.parallelize(list);
-
- Configuration conf = htu.getConfiguration();
-
- populateTableWithMockData(conf, TableName.valueOf(tableName));
-
- JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
-
- hbaseContext.bulkDelete(rdd, TableName.valueOf(tableName),
- new JavaHBaseBulkDeleteExample.DeleteFunction(), 2);
-
-
-
- try (
- Connection conn = ConnectionFactory.createConnection(conf);
- Table table = conn.getTable(TableName.valueOf(tableName))
- ){
- Result result1 = table.get(new Get(Bytes.toBytes("1")));
- Assert.assertNull("Row 1 should had been deleted", result1.getRow());
-
- Result result2 = table.get(new Get(Bytes.toBytes("2")));
- Assert.assertNull("Row 2 should had been deleted", result2.getRow());
-
- Result result3 = table.get(new Get(Bytes.toBytes("3")));
- Assert.assertNull("Row 3 should had been deleted", result3.getRow());
-
- Result result4 = table.get(new Get(Bytes.toBytes("4")));
- Assert.assertNotNull("Row 4 should had been deleted", result4.getRow());
-
- Result result5 = table.get(new Get(Bytes.toBytes("5")));
- Assert.assertNotNull("Row 5 should had been deleted", result5.getRow());
- }
- }
-
- @Test
- public void testDistributedScan() throws IOException {
- Configuration conf = htu.getConfiguration();
-
- populateTableWithMockData(conf, TableName.valueOf(tableName));
-
- JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
-
- Scan scan = new Scan();
- scan.setCaching(100);
-
- JavaRDD<String> javaRdd =
- hbaseContext.hbaseRDD(TableName.valueOf(tableName), scan)
- .map(new ScanConvertFunction());
-
- List<String> results = javaRdd.collect();
-
- Assert.assertEquals(results.size(), 5);
- }
-
- private static class ScanConvertFunction implements
- Function<Tuple2<ImmutableBytesWritable, Result>, String> {
- @Override
- public String call(Tuple2<ImmutableBytesWritable, Result> v1) throws Exception {
- return Bytes.toString(v1._1().copyBytes());
- }
- }
-
- @Test
- public void testBulkGet() throws IOException {
- List<byte[]> list = new ArrayList<>(5);
- list.add(Bytes.toBytes("1"));
- list.add(Bytes.toBytes("2"));
- list.add(Bytes.toBytes("3"));
- list.add(Bytes.toBytes("4"));
- list.add(Bytes.toBytes("5"));
-
- JavaRDD<byte[]> rdd = jsc.parallelize(list);
-
- Configuration conf = htu.getConfiguration();
-
- populateTableWithMockData(conf, TableName.valueOf(tableName));
-
- JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
-
- final JavaRDD<String> stringJavaRDD =
- hbaseContext.bulkGet(TableName.valueOf(tableName), 2, rdd,
- new GetFunction(),
- new ResultFunction());
-
- Assert.assertEquals(stringJavaRDD.count(), 5);
- }
-
- @Test
- public void testBulkLoad() throws Exception {
-
- Path output = htu.getDataTestDir("testBulkLoad");
- // Add cell as String: "row,falmily,qualifier,value"
- List<String> list= new ArrayList<String>();
- // row1
- list.add("1," + columnFamilyStr + ",b,1");
- // row3
- list.add("3," + columnFamilyStr + ",a,2");
- list.add("3," + columnFamilyStr + ",b,1");
- list.add("3," + columnFamilyStr1 + ",a,1");
- //row2
- list.add("2," + columnFamilyStr + ",a,3");
- list.add("2," + columnFamilyStr + ",b,3");
-
- JavaRDD<String> rdd = jsc.parallelize(list);
-
- Configuration conf = htu.getConfiguration();
- JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
-
-
-
- hbaseContext.bulkLoad(rdd, TableName.valueOf(tableName), new BulkLoadFunction(),
- output.toUri().getPath(), new HashMap<byte[], FamilyHFileWriteOptions>(), false,
- HConstants.DEFAULT_MAX_FILE_SIZE);
-
- try (Connection conn = ConnectionFactory.createConnection(conf);
- Admin admin = conn.getAdmin()) {
- Table table = conn.getTable(TableName.valueOf(tableName));
- // Do bulk load
- LoadIncrementalHFiles load = new LoadIncrementalHFiles(conf);
- load.doBulkLoad(output, admin, table, conn.getRegionLocator(TableName.valueOf(tableName)));
-
-
-
- // Check row1
- List<Cell> cell1 = table.get(new Get(Bytes.toBytes("1"))).listCells();
- Assert.assertEquals(cell1.size(), 1);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell1.get(0))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell1.get(0))), "b");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell1.get(0))), "1");
-
- // Check row3
- List<Cell> cell3 = table.get(new Get(Bytes.toBytes("3"))).listCells();
- Assert.assertEquals(cell3.size(), 3);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell3.get(0))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell3.get(0))), "a");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell3.get(0))), "2");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell3.get(1))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell3.get(1))), "b");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell3.get(1))), "1");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell3.get(2))), columnFamilyStr1);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell3.get(2))), "a");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell3.get(2))), "1");
-
- // Check row2
- List<Cell> cell2 = table.get(new Get(Bytes.toBytes("2"))).listCells();
- Assert.assertEquals(cell2.size(), 2);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell2.get(0))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell2.get(0))), "a");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell2.get(0))), "3");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell2.get(1))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell2.get(1))), "b");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell2.get(1))), "3");
- }
- }
-
- @Test
- public void testBulkLoadThinRows() throws Exception {
- Path output = htu.getDataTestDir("testBulkLoadThinRows");
- // because of the limitation of scala bulkLoadThinRows API
- // we need to provide data as <row, all cells in that row>
- List<List<String>> list= new ArrayList<List<String>>();
- // row1
- List<String> list1 = new ArrayList<String>();
- list1.add("1," + columnFamilyStr + ",b,1");
- list.add(list1);
- // row3
- List<String> list3 = new ArrayList<String>();
- list3.add("3," + columnFamilyStr + ",a,2");
- list3.add("3," + columnFamilyStr + ",b,1");
- list3.add("3," + columnFamilyStr1 + ",a,1");
- list.add(list3);
- //row2
- List<String> list2 = new ArrayList<String>();
- list2.add("2," + columnFamilyStr + ",a,3");
- list2.add("2," + columnFamilyStr + ",b,3");
- list.add(list2);
-
- JavaRDD<List<String>> rdd = jsc.parallelize(list);
-
- Configuration conf = htu.getConfiguration();
- JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
-
- hbaseContext.bulkLoadThinRows(rdd, TableName.valueOf(tableName), new BulkLoadThinRowsFunction(),
- output.toString(), new HashMap<byte[], FamilyHFileWriteOptions>(), false,
- HConstants.DEFAULT_MAX_FILE_SIZE);
-
-
- try (Connection conn = ConnectionFactory.createConnection(conf);
- Admin admin = conn.getAdmin()) {
- Table table = conn.getTable(TableName.valueOf(tableName));
- // Do bulk load
- LoadIncrementalHFiles load = new LoadIncrementalHFiles(conf);
- load.doBulkLoad(output, admin, table, conn.getRegionLocator(TableName.valueOf(tableName)));
-
- // Check row1
- List<Cell> cell1 = table.get(new Get(Bytes.toBytes("1"))).listCells();
- Assert.assertEquals(cell1.size(), 1);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell1.get(0))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell1.get(0))), "b");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell1.get(0))), "1");
-
- // Check row3
- List<Cell> cell3 = table.get(new Get(Bytes.toBytes("3"))).listCells();
- Assert.assertEquals(cell3.size(), 3);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell3.get(0))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell3.get(0))), "a");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell3.get(0))), "2");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell3.get(1))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell3.get(1))), "b");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell3.get(1))), "1");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell3.get(2))), columnFamilyStr1);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell3.get(2))), "a");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell3.get(2))), "1");
-
- // Check row2
- List<Cell> cell2 = table.get(new Get(Bytes.toBytes("2"))).listCells();
- Assert.assertEquals(cell2.size(), 2);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell2.get(0))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell2.get(0))), "a");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell2.get(0))), "3");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(cell2.get(1))), columnFamilyStr);
- Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(cell2.get(1))), "b");
- Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(cell2.get(1))), "3");
- }
-
- }
- public static class BulkLoadFunction
- implements Function<String, Pair<KeyFamilyQualifier, byte[]>> {
- @Override public Pair<KeyFamilyQualifier, byte[]> call(String v1) throws Exception {
- if (v1 == null) {
- return null;
- }
-
- String[] strs = v1.split(",");
- if(strs.length != 4) {
- return null;
- }
-
- KeyFamilyQualifier kfq = new KeyFamilyQualifier(Bytes.toBytes(strs[0]),
- Bytes.toBytes(strs[1]), Bytes.toBytes(strs[2]));
- return new Pair(kfq, Bytes.toBytes(strs[3]));
- }
- }
-
- public static class BulkLoadThinRowsFunction
- implements Function<List<String>, Pair<ByteArrayWrapper, FamiliesQualifiersValues>> {
- @Override public Pair<ByteArrayWrapper, FamiliesQualifiersValues> call(List<String> list) {
- if (list == null) {
- return null;
- }
-
- ByteArrayWrapper rowKey = null;
- FamiliesQualifiersValues fqv = new FamiliesQualifiersValues();
- for (String cell : list) {
- String[] strs = cell.split(",");
- if (rowKey == null) {
- rowKey = new ByteArrayWrapper(Bytes.toBytes(strs[0]));
- }
- fqv.add(Bytes.toBytes(strs[1]), Bytes.toBytes(strs[2]), Bytes.toBytes(strs[3]));
- }
- return new Pair(rowKey, fqv);
- }
- }
-
- public static class GetFunction implements Function<byte[], Get> {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Get call(byte[] v) throws Exception {
- return new Get(v);
- }
- }
-
- public static class ResultFunction implements Function<Result, String> {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String call(Result result) throws Exception {
- Iterator<Cell> it = result.listCells().iterator();
- StringBuilder b = new StringBuilder();
-
- b.append(Bytes.toString(result.getRow())).append(":");
-
- while (it.hasNext()) {
- Cell cell = it.next();
- String q = Bytes.toString(CellUtil.cloneQualifier(cell));
- if ("counter".equals(q)) {
- b.append("(")
- .append(q)
- .append(",")
- .append(Bytes.toLong(CellUtil.cloneValue(cell)))
- .append(")");
- } else {
- b.append("(")
- .append(q)
- .append(",")
- .append(Bytes.toString(CellUtil.cloneValue(cell)))
- .append(")");
- }
- }
- return b.toString();
- }
- }
-
- private void populateTableWithMockData(Configuration conf, TableName tableName)
- throws IOException {
- try (
- Connection conn = ConnectionFactory.createConnection(conf);
- Table table = conn.getTable(tableName)) {
-
- List<Put> puts = new ArrayList<>(5);
-
- for (int i = 1; i < 6; i++) {
- Put put = new Put(Bytes.toBytes(Integer.toString(i)));
- put.addColumn(columnFamily, columnFamily, columnFamily);
- puts.add(put);
- }
- table.put(puts);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/test/resources/hbase-site.xml
----------------------------------------------------------------------
diff --git a/hbase-spark/src/test/resources/hbase-site.xml b/hbase-spark/src/test/resources/hbase-site.xml
deleted file mode 100644
index b3fb0d9..0000000
--- a/hbase-spark/src/test/resources/hbase-site.xml
+++ /dev/null
@@ -1,157 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
-<!--
-/**
- *
- * 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.
- */
--->
-<configuration>
- <property>
- <name>hbase.regionserver.msginterval</name>
- <value>1000</value>
- <description>Interval between messages from the RegionServer to HMaster
- in milliseconds. Default is 15. Set this value low if you want unit
- tests to be responsive.
- </description>
- </property>
- <property>
- <name>hbase.defaults.for.version.skip</name>
- <value>true</value>
- </property>
- <property>
- <name>hbase.server.thread.wakefrequency</name>
- <value>1000</value>
- <description>Time to sleep in between searches for work (in milliseconds).
- Used as sleep interval by service threads such as hbase:meta scanner and log roller.
- </description>
- </property>
- <property>
- <name>hbase.master.event.waiting.time</name>
- <value>50</value>
- <description>Time to sleep between checks to see if a table event took place.
- </description>
- </property>
- <property>
- <name>hbase.regionserver.handler.count</name>
- <value>5</value>
- </property>
- <property>
- <name>hbase.regionserver.metahandler.count</name>
- <value>5</value>
- </property>
- <property>
- <name>hbase.ipc.server.read.threadpool.size</name>
- <value>3</value>
- </property>
- <property>
- <name>hbase.master.info.port</name>
- <value>-1</value>
- <description>The port for the hbase master web UI
- Set to -1 if you do not want the info server to run.
- </description>
- </property>
- <property>
- <name>hbase.master.port</name>
- <value>0</value>
- <description>Always have masters and regionservers come up on port '0' so we don't clash over
- default ports.
- </description>
- </property>
- <property>
- <name>hbase.regionserver.port</name>
- <value>0</value>
- <description>Always have masters and regionservers come up on port '0' so we don't clash over
- default ports.
- </description>
- </property>
- <property>
- <name>hbase.ipc.client.fallback-to-simple-auth-allowed</name>
- <value>true</value>
- </property>
-
- <property>
- <name>hbase.regionserver.info.port</name>
- <value>-1</value>
- <description>The port for the hbase regionserver web UI
- Set to -1 if you do not want the info server to run.
- </description>
- </property>
- <property>
- <name>hbase.regionserver.info.port.auto</name>
- <value>true</value>
- <description>Info server auto port bind. Enables automatic port
- search if hbase.regionserver.info.port is already in use.
- Enabled for testing to run multiple tests on one machine.
- </description>
- </property>
- <property>
- <name>hbase.regionserver.safemode</name>
- <value>false</value>
- <description>
- Turn on/off safe mode in region server. Always on for production, always off
- for tests.
- </description>
- </property>
- <property>
- <name>hbase.hregion.max.filesize</name>
- <value>67108864</value>
- <description>
- Maximum desired file size for an HRegion. If filesize exceeds
- value + (value / 2), the HRegion is split in two. Default: 256M.
-
- Keep the maximum filesize small so we split more often in tests.
- </description>
- </property>
- <property>
- <name>hadoop.log.dir</name>
- <value>${user.dir}/../logs</value>
- </property>
- <property>
- <name>hbase.zookeeper.property.clientPort</name>
- <value>21818</value>
- <description>Property from ZooKeeper's config zoo.cfg.
- The port at which the clients will connect.
- </description>
- </property>
- <property>
- <name>hbase.defaults.for.version.skip</name>
- <value>true</value>
- <description>
- Set to true to skip the 'hbase.defaults.for.version'.
- Setting this to true can be useful in contexts other than
- the other side of a maven generation; i.e. running in an
- ide. You'll want to set this boolean to true to avoid
- seeing the RuntimeException complaint: "hbase-default.xml file
- seems to be for and old version of HBase (@@@VERSION@@@), this
- version is X.X.X-SNAPSHOT"
- </description>
- </property>
- <property>
- <name>hbase.table.sanity.checks</name>
- <value>false</value>
- <description>Skip sanity checks in tests
- </description>
- </property>
- <property>
- <name>hbase.procedure.fail.on.corruption</name>
- <value>true</value>
- <description>
- Enable replay sanity checks on procedure tests.
- </description>
- </property>
-</configuration>
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/hbase-spark/src/test/resources/log4j.properties b/hbase-spark/src/test/resources/log4j.properties
deleted file mode 100644
index cd3b8e9..0000000
--- a/hbase-spark/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,76 +0,0 @@
-# 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.
-
-# Define some default values that can be overridden by system properties
-hbase.root.logger=INFO,FA
-hbase.log.dir=.
-hbase.log.file=hbase.log
-
-# Define the root logger to the system property "hbase.root.logger".
-log4j.rootLogger=${hbase.root.logger}
-
-# Logging Threshold
-log4j.threshold=ALL
-
-#
-# Daily Rolling File Appender
-#
-log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file}
-
-# Rollver at midnight
-log4j.appender.DRFA.DatePattern=.yyyy-MM-dd
-
-# 30-day backup
-#log4j.appender.DRFA.MaxBackupIndex=30
-log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout
-# Debugging Pattern format
-log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n
-
-
-#
-# console
-# Add "console" to rootlogger above if you want to use this
-#
-log4j.appender.console=org.apache.log4j.ConsoleAppender
-log4j.appender.console.target=System.err
-log4j.appender.console.layout=org.apache.log4j.PatternLayout
-log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n
-
-#File Appender
-log4j.appender.FA=org.apache.log4j.FileAppender
-log4j.appender.FA.append=false
-log4j.appender.FA.file=target/log-output.txt
-log4j.appender.FA.layout=org.apache.log4j.PatternLayout
-log4j.appender.FA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n
-log4j.appender.FA.Threshold = INFO
-
-# Custom Logging levels
-
-#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG
-
-log4j.logger.org.apache.hadoop=WARN
-log4j.logger.org.apache.zookeeper=ERROR
-log4j.logger.org.apache.hadoop.hbase=DEBUG
-
-#These settings are workarounds against spurious logs from the minicluster.
-#See HBASE-4709
-log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN
-log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN
-log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN
-log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN
-# Enable this to get detailed connection error/retry logging.
-# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE
http://git-wip-us.apache.org/repos/asf/hbase/blob/0ffeb54a/hbase-spark/src/test/scala/org/apache/hadoop/hbase/spark/BulkLoadSuite.scala
----------------------------------------------------------------------
diff --git a/hbase-spark/src/test/scala/org/apache/hadoop/hbase/spark/BulkLoadSuite.scala b/hbase-spark/src/test/scala/org/apache/hadoop/hbase/spark/BulkLoadSuite.scala
deleted file mode 100644
index dc328f3..0000000
--- a/hbase-spark/src/test/scala/org/apache/hadoop/hbase/spark/BulkLoadSuite.scala
+++ /dev/null
@@ -1,956 +0,0 @@
-/*
- * 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.hbase.spark
-
-import org.apache.hadoop.fs.{FileSystem, Path}
-import org.apache.hadoop.hbase.client.{Get, ConnectionFactory}
-import org.apache.hadoop.hbase.io.hfile.{CacheConfig, HFile}
-import org.apache.hadoop.hbase.tool.LoadIncrementalHFiles
-import org.apache.hadoop.hbase.{HConstants, CellUtil, HBaseTestingUtility, TableName}
-import org.apache.hadoop.hbase.util.Bytes
-import org.apache.hadoop.hbase.spark.HBaseRDDFunctions._
-import org.apache.spark.SparkContext
-import org.junit.rules.TemporaryFolder
-import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, FunSuite}
-
-class BulkLoadSuite extends FunSuite with
-BeforeAndAfterEach with BeforeAndAfterAll with Logging {
- @transient var sc: SparkContext = null
- var TEST_UTIL = new HBaseTestingUtility
-
- val tableName = "t1"
- val columnFamily1 = "f1"
- val columnFamily2 = "f2"
- val testFolder = new TemporaryFolder()
-
-
- override def beforeAll() {
- TEST_UTIL.startMiniCluster()
- logInfo(" - minicluster started")
-
- try {
- TEST_UTIL.deleteTable(TableName.valueOf(tableName))
- } catch {
- case e: Exception =>
- logInfo(" - no table " + tableName + " found")
- }
-
- logInfo(" - created table")
-
- val envMap = Map[String,String](("Xmx", "512m"))
-
- sc = new SparkContext("local", "test", null, Nil, envMap)
- }
-
- override def afterAll() {
- logInfo("shuting down minicluster")
- TEST_UTIL.shutdownMiniCluster()
- logInfo(" - minicluster shut down")
- TEST_UTIL.cleanupTestDir()
- sc.stop()
- }
-
- test("Wide Row Bulk Load: Test multi family and multi column tests " +
- "with all default HFile Configs.") {
- val config = TEST_UTIL.getConfiguration
-
- logInfo(" - creating table " + tableName)
- TEST_UTIL.createTable(TableName.valueOf(tableName),
- Array(Bytes.toBytes(columnFamily1), Bytes.toBytes(columnFamily2)))
-
- //There are a number of tests in here.
- // 1. Row keys are not in order
- // 2. Qualifiers are not in order
- // 3. Column Families are not in order
- // 4. There are tests for records in one column family and some in two column families
- // 5. There are records will a single qualifier and some with two
- val rdd = sc.parallelize(Array(
- (Bytes.toBytes("1"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo1"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo2.a"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("a"), Bytes.toBytes("foo2.b"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo2.c"))),
- (Bytes.toBytes("5"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo3"))),
- (Bytes.toBytes("4"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo.1"))),
- (Bytes.toBytes("4"),
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo.2"))),
- (Bytes.toBytes("2"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("bar.1"))),
- (Bytes.toBytes("2"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("bar.2")))))
-
-
-
- val hbaseContext = new HBaseContext(sc, config)
-
- testFolder.create()
- val stagingFolder = testFolder.newFolder()
-
- hbaseContext.bulkLoad[(Array[Byte], (Array[Byte], Array[Byte], Array[Byte]))](rdd,
- TableName.valueOf(tableName),
- t => {
- val rowKey = t._1
- val family:Array[Byte] = t._2._1
- val qualifier = t._2._2
- val value:Array[Byte] = t._2._3
-
- val keyFamilyQualifier= new KeyFamilyQualifier(rowKey, family, qualifier)
-
- Seq((keyFamilyQualifier, value)).iterator
- },
- stagingFolder.getPath)
-
- val fs = FileSystem.get(config)
- assert(fs.listStatus(new Path(stagingFolder.getPath)).length == 2)
-
- val conn = ConnectionFactory.createConnection(config)
-
- val load = new LoadIncrementalHFiles(config)
- val table = conn.getTable(TableName.valueOf(tableName))
- try {
- load.doBulkLoad(new Path(stagingFolder.getPath), conn.getAdmin, table,
- conn.getRegionLocator(TableName.valueOf(tableName)))
-
- val cells5 = table.get(new Get(Bytes.toBytes("5"))).listCells()
- assert(cells5.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells5.get(0))).equals("foo3"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells5.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells5.get(0))).equals("a"))
-
- val cells4 = table.get(new Get(Bytes.toBytes("4"))).listCells()
- assert(cells4.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(0))).equals("foo.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(1))).equals("foo.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(1))).equals("b"))
-
- val cells3 = table.get(new Get(Bytes.toBytes("3"))).listCells()
- assert(cells3.size == 3)
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(0))).equals("foo2.c"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(1))).equals("foo2.b"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(1))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(2))).equals("foo2.a"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(2))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(2))).equals("b"))
-
-
- val cells2 = table.get(new Get(Bytes.toBytes("2"))).listCells()
- assert(cells2.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(0))).equals("bar.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(1))).equals("bar.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(1))).equals("b"))
-
- val cells1 = table.get(new Get(Bytes.toBytes("1"))).listCells()
- assert(cells1.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells1.get(0))).equals("foo1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells1.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells1.get(0))).equals("a"))
-
- } finally {
- table.close()
- val admin = ConnectionFactory.createConnection(config).getAdmin
- try {
- admin.disableTable(TableName.valueOf(tableName))
- admin.deleteTable(TableName.valueOf(tableName))
- } finally {
- admin.close()
- }
- fs.delete(new Path(stagingFolder.getPath), true)
-
- testFolder.delete()
-
- }
- }
-
- test("Wide Row Bulk Load: Test HBase client: Test Roll Over and " +
- "using an implicit call to bulk load") {
- val config = TEST_UTIL.getConfiguration
-
- logInfo(" - creating table " + tableName)
- TEST_UTIL.createTable(TableName.valueOf(tableName),
- Array(Bytes.toBytes(columnFamily1), Bytes.toBytes(columnFamily2)))
-
- //There are a number of tests in here.
- // 1. Row keys are not in order
- // 2. Qualifiers are not in order
- // 3. Column Families are not in order
- // 4. There are tests for records in one column family and some in two column families
- // 5. There are records will a single qualifier and some with two
- val rdd = sc.parallelize(Array(
- (Bytes.toBytes("1"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo1"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("foo2.b"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo2.a"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("c"), Bytes.toBytes("foo2.c"))),
- (Bytes.toBytes("5"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo3"))),
- (Bytes.toBytes("4"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo.1"))),
- (Bytes.toBytes("4"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("foo.2"))),
- (Bytes.toBytes("2"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("bar.1"))),
- (Bytes.toBytes("2"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("bar.2")))))
-
- val hbaseContext = new HBaseContext(sc, config)
-
- testFolder.create()
- val stagingFolder = testFolder.newFolder()
-
- rdd.hbaseBulkLoad(hbaseContext,
- TableName.valueOf(tableName),
- t => {
- val rowKey = t._1
- val family:Array[Byte] = t._2._1
- val qualifier = t._2._2
- val value = t._2._3
-
- val keyFamilyQualifier= new KeyFamilyQualifier(rowKey, family, qualifier)
-
- Seq((keyFamilyQualifier, value)).iterator
- },
- stagingFolder.getPath,
- new java.util.HashMap[Array[Byte], FamilyHFileWriteOptions],
- compactionExclude = false,
- 20)
-
- val fs = FileSystem.get(config)
- assert(fs.listStatus(new Path(stagingFolder.getPath)).length == 1)
-
- assert(fs.listStatus(new Path(stagingFolder.getPath+ "/f1")).length == 5)
-
- val conn = ConnectionFactory.createConnection(config)
-
- val load = new LoadIncrementalHFiles(config)
- val table = conn.getTable(TableName.valueOf(tableName))
- try {
- load.doBulkLoad(new Path(stagingFolder.getPath),
- conn.getAdmin, table, conn.getRegionLocator(TableName.valueOf(tableName)))
-
- val cells5 = table.get(new Get(Bytes.toBytes("5"))).listCells()
- assert(cells5.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells5.get(0))).equals("foo3"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells5.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells5.get(0))).equals("a"))
-
- val cells4 = table.get(new Get(Bytes.toBytes("4"))).listCells()
- assert(cells4.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(0))).equals("foo.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(1))).equals("foo.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(1))).equals("b"))
-
- val cells3 = table.get(new Get(Bytes.toBytes("3"))).listCells()
- assert(cells3.size == 3)
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(0))).equals("foo2.a"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(1))).equals("foo2.b"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(1))).equals("b"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(2))).equals("foo2.c"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(2))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(2))).equals("c"))
-
- val cells2 = table.get(new Get(Bytes.toBytes("2"))).listCells()
- assert(cells2.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(0))).equals("bar.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(1))).equals("bar.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(1))).equals("b"))
-
- val cells1 = table.get(new Get(Bytes.toBytes("1"))).listCells()
- assert(cells1.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells1.get(0))).equals("foo1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells1.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells1.get(0))).equals("a"))
-
- } finally {
- table.close()
- val admin = ConnectionFactory.createConnection(config).getAdmin
- try {
- admin.disableTable(TableName.valueOf(tableName))
- admin.deleteTable(TableName.valueOf(tableName))
- } finally {
- admin.close()
- }
- fs.delete(new Path(stagingFolder.getPath), true)
-
- testFolder.delete()
- }
- }
-
- test("Wide Row Bulk Load: Test multi family and multi column tests" +
- " with one column family with custom configs plus multi region") {
- val config = TEST_UTIL.getConfiguration
-
- val splitKeys:Array[Array[Byte]] = new Array[Array[Byte]](2)
- splitKeys(0) = Bytes.toBytes("2")
- splitKeys(1) = Bytes.toBytes("4")
-
- logInfo(" - creating table " + tableName)
- TEST_UTIL.createTable(TableName.valueOf(tableName),
- Array(Bytes.toBytes(columnFamily1), Bytes.toBytes(columnFamily2)),
- splitKeys)
-
- //There are a number of tests in here.
- // 1. Row keys are not in order
- // 2. Qualifiers are not in order
- // 3. Column Families are not in order
- // 4. There are tests for records in one column family and some in two column families
- // 5. There are records will a single qualifier and some with two
- val rdd = sc.parallelize(Array(
- (Bytes.toBytes("1"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo1"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo2.a"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("a"), Bytes.toBytes("foo2.b"))),
- (Bytes.toBytes("3"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo2.c"))),
- (Bytes.toBytes("5"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo3"))),
- (Bytes.toBytes("4"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo.1"))),
- (Bytes.toBytes("4"),
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo.2"))),
- (Bytes.toBytes("2"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("bar.1"))),
- (Bytes.toBytes("2"),
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("bar.2")))))
-
- val hbaseContext = new HBaseContext(sc, config)
-
- testFolder.create()
- val stagingFolder = testFolder.newFolder()
-
- val familyHBaseWriterOptions = new java.util.HashMap[Array[Byte], FamilyHFileWriteOptions]
-
- val f1Options = new FamilyHFileWriteOptions("GZ", "ROW", 128,
- "PREFIX")
-
- familyHBaseWriterOptions.put(Bytes.toBytes(columnFamily1), f1Options)
-
- hbaseContext.bulkLoad[(Array[Byte], (Array[Byte], Array[Byte], Array[Byte]))](rdd,
- TableName.valueOf(tableName),
- t => {
- val rowKey = t._1
- val family:Array[Byte] = t._2._1
- val qualifier = t._2._2
- val value = t._2._3
-
- val keyFamilyQualifier= new KeyFamilyQualifier(rowKey, family, qualifier)
-
- Seq((keyFamilyQualifier, value)).iterator
- },
- stagingFolder.getPath,
- familyHBaseWriterOptions,
- compactionExclude = false,
- HConstants.DEFAULT_MAX_FILE_SIZE)
-
- val fs = FileSystem.get(config)
- assert(fs.listStatus(new Path(stagingFolder.getPath)).length == 2)
-
- val f1FileList = fs.listStatus(new Path(stagingFolder.getPath +"/f1"))
- for ( i <- 0 until f1FileList.length) {
- val reader = HFile.createReader(fs, f1FileList(i).getPath,
- new CacheConfig(config), true, config)
- assert(reader.getCompressionAlgorithm.getName.equals("gz"))
- assert(reader.getDataBlockEncoding.name().equals("PREFIX"))
- }
-
- assert( 3 == f1FileList.length)
-
- val f2FileList = fs.listStatus(new Path(stagingFolder.getPath +"/f2"))
- for ( i <- 0 until f2FileList.length) {
- val reader = HFile.createReader(fs, f2FileList(i).getPath,
- new CacheConfig(config), true, config)
- assert(reader.getCompressionAlgorithm.getName.equals("none"))
- assert(reader.getDataBlockEncoding.name().equals("NONE"))
- }
-
- assert( 2 == f2FileList.length)
-
-
- val conn = ConnectionFactory.createConnection(config)
-
- val load = new LoadIncrementalHFiles(config)
- val table = conn.getTable(TableName.valueOf(tableName))
- try {
- load.doBulkLoad(new Path(stagingFolder.getPath),
- conn.getAdmin, table, conn.getRegionLocator(TableName.valueOf(tableName)))
-
- val cells5 = table.get(new Get(Bytes.toBytes("5"))).listCells()
- assert(cells5.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells5.get(0))).equals("foo3"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells5.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells5.get(0))).equals("a"))
-
- val cells4 = table.get(new Get(Bytes.toBytes("4"))).listCells()
- assert(cells4.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(0))).equals("foo.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(1))).equals("foo.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(1))).equals("b"))
-
- val cells3 = table.get(new Get(Bytes.toBytes("3"))).listCells()
- assert(cells3.size == 3)
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(0))).equals("foo2.c"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(1))).equals("foo2.b"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(1))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(2))).equals("foo2.a"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(2))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(2))).equals("b"))
-
-
- val cells2 = table.get(new Get(Bytes.toBytes("2"))).listCells()
- assert(cells2.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(0))).equals("bar.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(1))).equals("bar.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(1))).equals("b"))
-
- val cells1 = table.get(new Get(Bytes.toBytes("1"))).listCells()
- assert(cells1.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells1.get(0))).equals("foo1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells1.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells1.get(0))).equals("a"))
-
- } finally {
- table.close()
- val admin = ConnectionFactory.createConnection(config).getAdmin
- try {
- admin.disableTable(TableName.valueOf(tableName))
- admin.deleteTable(TableName.valueOf(tableName))
- } finally {
- admin.close()
- }
- fs.delete(new Path(stagingFolder.getPath), true)
-
- testFolder.delete()
-
- }
- }
-
- test("Test partitioner") {
-
- var splitKeys:Array[Array[Byte]] = new Array[Array[Byte]](3)
- splitKeys(0) = Bytes.toBytes("")
- splitKeys(1) = Bytes.toBytes("3")
- splitKeys(2) = Bytes.toBytes("7")
-
- var partitioner = new BulkLoadPartitioner(splitKeys)
-
- assert(0 == partitioner.getPartition(Bytes.toBytes("")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("1")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("2")))
- assert(1 == partitioner.getPartition(Bytes.toBytes("3")))
- assert(1 == partitioner.getPartition(Bytes.toBytes("4")))
- assert(1 == partitioner.getPartition(Bytes.toBytes("6")))
- assert(2 == partitioner.getPartition(Bytes.toBytes("7")))
- assert(2 == partitioner.getPartition(Bytes.toBytes("8")))
-
-
- splitKeys = new Array[Array[Byte]](1)
- splitKeys(0) = Bytes.toBytes("")
-
- partitioner = new BulkLoadPartitioner(splitKeys)
-
- assert(0 == partitioner.getPartition(Bytes.toBytes("")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("1")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("2")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("3")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("4")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("6")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("7")))
-
- splitKeys = new Array[Array[Byte]](7)
- splitKeys(0) = Bytes.toBytes("")
- splitKeys(1) = Bytes.toBytes("02")
- splitKeys(2) = Bytes.toBytes("04")
- splitKeys(3) = Bytes.toBytes("06")
- splitKeys(4) = Bytes.toBytes("08")
- splitKeys(5) = Bytes.toBytes("10")
- splitKeys(6) = Bytes.toBytes("12")
-
- partitioner = new BulkLoadPartitioner(splitKeys)
-
- assert(0 == partitioner.getPartition(Bytes.toBytes("")))
- assert(0 == partitioner.getPartition(Bytes.toBytes("01")))
- assert(1 == partitioner.getPartition(Bytes.toBytes("02")))
- assert(1 == partitioner.getPartition(Bytes.toBytes("03")))
- assert(2 == partitioner.getPartition(Bytes.toBytes("04")))
- assert(2 == partitioner.getPartition(Bytes.toBytes("05")))
- assert(3 == partitioner.getPartition(Bytes.toBytes("06")))
- assert(3 == partitioner.getPartition(Bytes.toBytes("07")))
- assert(4 == partitioner.getPartition(Bytes.toBytes("08")))
- assert(4 == partitioner.getPartition(Bytes.toBytes("09")))
- assert(5 == partitioner.getPartition(Bytes.toBytes("10")))
- assert(5 == partitioner.getPartition(Bytes.toBytes("11")))
- assert(6 == partitioner.getPartition(Bytes.toBytes("12")))
- assert(6 == partitioner.getPartition(Bytes.toBytes("13")))
- }
-
- test("Thin Row Bulk Load: Test multi family and multi column tests " +
- "with all default HFile Configs") {
- val config = TEST_UTIL.getConfiguration
-
- logInfo(" - creating table " + tableName)
- TEST_UTIL.createTable(TableName.valueOf(tableName),
- Array(Bytes.toBytes(columnFamily1), Bytes.toBytes(columnFamily2)))
-
- //There are a number of tests in here.
- // 1. Row keys are not in order
- // 2. Qualifiers are not in order
- // 3. Column Families are not in order
- // 4. There are tests for records in one column family and some in two column families
- // 5. There are records will a single qualifier and some with two
- val rdd = sc.parallelize(Array(
- ("1",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo1"))),
- ("3",
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo2.a"))),
- ("3",
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("a"), Bytes.toBytes("foo2.b"))),
- ("3",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo2.c"))),
- ("5",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo3"))),
- ("4",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo.1"))),
- ("4",
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo.2"))),
- ("2",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("bar.1"))),
- ("2",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("bar.2"))))).
- groupByKey()
-
- val hbaseContext = new HBaseContext(sc, config)
-
- testFolder.create()
- val stagingFolder = testFolder.newFolder()
-
- hbaseContext.bulkLoadThinRows[(String, Iterable[(Array[Byte], Array[Byte], Array[Byte])])](rdd,
- TableName.valueOf(tableName),
- t => {
- val rowKey = Bytes.toBytes(t._1)
-
- val familyQualifiersValues = new FamiliesQualifiersValues
- t._2.foreach(f => {
- val family:Array[Byte] = f._1
- val qualifier = f._2
- val value:Array[Byte] = f._3
-
- familyQualifiersValues +=(family, qualifier, value)
- })
- (new ByteArrayWrapper(rowKey), familyQualifiersValues)
- },
- stagingFolder.getPath)
-
- val fs = FileSystem.get(config)
- assert(fs.listStatus(new Path(stagingFolder.getPath)).length == 2)
-
- val conn = ConnectionFactory.createConnection(config)
-
- val load = new LoadIncrementalHFiles(config)
- val table = conn.getTable(TableName.valueOf(tableName))
- try {
- load.doBulkLoad(new Path(stagingFolder.getPath), conn.getAdmin, table,
- conn.getRegionLocator(TableName.valueOf(tableName)))
-
- val cells5 = table.get(new Get(Bytes.toBytes("5"))).listCells()
- assert(cells5.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells5.get(0))).equals("foo3"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells5.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells5.get(0))).equals("a"))
-
- val cells4 = table.get(new Get(Bytes.toBytes("4"))).listCells()
- assert(cells4.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(0))).equals("foo.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(1))).equals("foo.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(1))).equals("b"))
-
- val cells3 = table.get(new Get(Bytes.toBytes("3"))).listCells()
- assert(cells3.size == 3)
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(0))).equals("foo2.c"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(1))).equals("foo2.b"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(1))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(2))).equals("foo2.a"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(2))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(2))).equals("b"))
-
-
- val cells2 = table.get(new Get(Bytes.toBytes("2"))).listCells()
- assert(cells2.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(0))).equals("bar.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(1))).equals("bar.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(1))).equals("b"))
-
- val cells1 = table.get(new Get(Bytes.toBytes("1"))).listCells()
- assert(cells1.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells1.get(0))).equals("foo1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells1.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells1.get(0))).equals("a"))
-
- } finally {
- table.close()
- val admin = ConnectionFactory.createConnection(config).getAdmin
- try {
- admin.disableTable(TableName.valueOf(tableName))
- admin.deleteTable(TableName.valueOf(tableName))
- } finally {
- admin.close()
- }
- fs.delete(new Path(stagingFolder.getPath), true)
-
- testFolder.delete()
-
- }
- }
-
- test("Thin Row Bulk Load: Test HBase client: Test Roll Over and " +
- "using an implicit call to bulk load") {
- val config = TEST_UTIL.getConfiguration
-
- logInfo(" - creating table " + tableName)
- TEST_UTIL.createTable(TableName.valueOf(tableName),
- Array(Bytes.toBytes(columnFamily1), Bytes.toBytes(columnFamily2)))
-
- //There are a number of tests in here.
- // 1. Row keys are not in order
- // 2. Qualifiers are not in order
- // 3. Column Families are not in order
- // 4. There are tests for records in one column family and some in two column families
- // 5. There are records will a single qualifier and some with two
- val rdd = sc.parallelize(Array(
- ("1",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo1"))),
- ("3",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("foo2.b"))),
- ("3",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo2.a"))),
- ("3",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("c"), Bytes.toBytes("foo2.c"))),
- ("5",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo3"))),
- ("4",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo.1"))),
- ("4",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("foo.2"))),
- ("2",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("bar.1"))),
- ("2",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("bar.2"))))).
- groupByKey()
-
- val hbaseContext = new HBaseContext(sc, config)
-
- testFolder.create()
- val stagingFolder = testFolder.newFolder()
-
- rdd.hbaseBulkLoadThinRows(hbaseContext,
- TableName.valueOf(tableName),
- t => {
- val rowKey = t._1
-
- val familyQualifiersValues = new FamiliesQualifiersValues
- t._2.foreach(f => {
- val family:Array[Byte] = f._1
- val qualifier = f._2
- val value:Array[Byte] = f._3
-
- familyQualifiersValues +=(family, qualifier, value)
- })
- (new ByteArrayWrapper(Bytes.toBytes(rowKey)), familyQualifiersValues)
- },
- stagingFolder.getPath,
- new java.util.HashMap[Array[Byte], FamilyHFileWriteOptions],
- compactionExclude = false,
- 20)
-
- val fs = FileSystem.get(config)
- assert(fs.listStatus(new Path(stagingFolder.getPath)).length == 1)
-
- assert(fs.listStatus(new Path(stagingFolder.getPath+ "/f1")).length == 5)
-
- val conn = ConnectionFactory.createConnection(config)
-
- val load = new LoadIncrementalHFiles(config)
- val table = conn.getTable(TableName.valueOf(tableName))
- try {
- load.doBulkLoad(new Path(stagingFolder.getPath),
- conn.getAdmin, table, conn.getRegionLocator(TableName.valueOf(tableName)))
-
- val cells5 = table.get(new Get(Bytes.toBytes("5"))).listCells()
- assert(cells5.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells5.get(0))).equals("foo3"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells5.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells5.get(0))).equals("a"))
-
- val cells4 = table.get(new Get(Bytes.toBytes("4"))).listCells()
- assert(cells4.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(0))).equals("foo.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(1))).equals("foo.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(1))).equals("b"))
-
- val cells3 = table.get(new Get(Bytes.toBytes("3"))).listCells()
- assert(cells3.size == 3)
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(0))).equals("foo2.a"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(1))).equals("foo2.b"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(1))).equals("b"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(2))).equals("foo2.c"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(2))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(2))).equals("c"))
-
- val cells2 = table.get(new Get(Bytes.toBytes("2"))).listCells()
- assert(cells2.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(0))).equals("bar.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(1))).equals("bar.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(1))).equals("b"))
-
- val cells1 = table.get(new Get(Bytes.toBytes("1"))).listCells()
- assert(cells1.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells1.get(0))).equals("foo1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells1.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells1.get(0))).equals("a"))
-
- } finally {
- table.close()
- val admin = ConnectionFactory.createConnection(config).getAdmin
- try {
- admin.disableTable(TableName.valueOf(tableName))
- admin.deleteTable(TableName.valueOf(tableName))
- } finally {
- admin.close()
- }
- fs.delete(new Path(stagingFolder.getPath), true)
-
- testFolder.delete()
- }
- }
-
- test("Thin Row Bulk Load: Test multi family and multi column tests" +
- " with one column family with custom configs plus multi region") {
- val config = TEST_UTIL.getConfiguration
-
- val splitKeys:Array[Array[Byte]] = new Array[Array[Byte]](2)
- splitKeys(0) = Bytes.toBytes("2")
- splitKeys(1) = Bytes.toBytes("4")
-
- logInfo(" - creating table " + tableName)
- TEST_UTIL.createTable(TableName.valueOf(tableName),
- Array(Bytes.toBytes(columnFamily1), Bytes.toBytes(columnFamily2)),
- splitKeys)
-
- //There are a number of tests in here.
- // 1. Row keys are not in order
- // 2. Qualifiers are not in order
- // 3. Column Families are not in order
- // 4. There are tests for records in one column family and some in two column families
- // 5. There are records will a single qualifier and some with two
- val rdd = sc.parallelize(Array(
- ("1",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo1"))),
- ("3",
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo2.a"))),
- ("3",
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("a"), Bytes.toBytes("foo2.b"))),
- ("3",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo2.c"))),
- ("5",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo3"))),
- ("4",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("foo.1"))),
- ("4",
- (Bytes.toBytes(columnFamily2), Bytes.toBytes("b"), Bytes.toBytes("foo.2"))),
- ("2",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("a"), Bytes.toBytes("bar.1"))),
- ("2",
- (Bytes.toBytes(columnFamily1), Bytes.toBytes("b"), Bytes.toBytes("bar.2"))))).
- groupByKey()
-
- val hbaseContext = new HBaseContext(sc, config)
-
- testFolder.create()
- val stagingFolder = testFolder.newFolder()
-
- val familyHBaseWriterOptions = new java.util.HashMap[Array[Byte], FamilyHFileWriteOptions]
-
- val f1Options = new FamilyHFileWriteOptions("GZ", "ROW", 128,
- "PREFIX")
-
- familyHBaseWriterOptions.put(Bytes.toBytes(columnFamily1), f1Options)
-
- hbaseContext.bulkLoadThinRows[(String, Iterable[(Array[Byte], Array[Byte], Array[Byte])])](rdd,
- TableName.valueOf(tableName),
- t => {
- val rowKey = t._1
-
- val familyQualifiersValues = new FamiliesQualifiersValues
- t._2.foreach(f => {
- val family:Array[Byte] = f._1
- val qualifier = f._2
- val value:Array[Byte] = f._3
-
- familyQualifiersValues +=(family, qualifier, value)
- })
- (new ByteArrayWrapper(Bytes.toBytes(rowKey)), familyQualifiersValues)
- },
- stagingFolder.getPath,
- familyHBaseWriterOptions,
- compactionExclude = false,
- HConstants.DEFAULT_MAX_FILE_SIZE)
-
- val fs = FileSystem.get(config)
- assert(fs.listStatus(new Path(stagingFolder.getPath)).length == 2)
-
- val f1FileList = fs.listStatus(new Path(stagingFolder.getPath +"/f1"))
- for ( i <- 0 until f1FileList.length) {
- val reader = HFile.createReader(fs, f1FileList(i).getPath,
- new CacheConfig(config), true, config)
- assert(reader.getCompressionAlgorithm.getName.equals("gz"))
- assert(reader.getDataBlockEncoding.name().equals("PREFIX"))
- }
-
- assert( 3 == f1FileList.length)
-
- val f2FileList = fs.listStatus(new Path(stagingFolder.getPath +"/f2"))
- for ( i <- 0 until f2FileList.length) {
- val reader = HFile.createReader(fs, f2FileList(i).getPath,
- new CacheConfig(config), true, config)
- assert(reader.getCompressionAlgorithm.getName.equals("none"))
- assert(reader.getDataBlockEncoding.name().equals("NONE"))
- }
-
- assert( 2 == f2FileList.length)
-
-
- val conn = ConnectionFactory.createConnection(config)
-
- val load = new LoadIncrementalHFiles(config)
- val table = conn.getTable(TableName.valueOf(tableName))
- try {
- load.doBulkLoad(new Path(stagingFolder.getPath),
- conn.getAdmin, table, conn.getRegionLocator(TableName.valueOf(tableName)))
-
- val cells5 = table.get(new Get(Bytes.toBytes("5"))).listCells()
- assert(cells5.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells5.get(0))).equals("foo3"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells5.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells5.get(0))).equals("a"))
-
- val cells4 = table.get(new Get(Bytes.toBytes("4"))).listCells()
- assert(cells4.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(0))).equals("foo.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells4.get(1))).equals("foo.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells4.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells4.get(1))).equals("b"))
-
- val cells3 = table.get(new Get(Bytes.toBytes("3"))).listCells()
- assert(cells3.size == 3)
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(0))).equals("foo2.c"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(1))).equals("foo2.b"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(1))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(1))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells3.get(2))).equals("foo2.a"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells3.get(2))).equals("f2"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells3.get(2))).equals("b"))
-
-
- val cells2 = table.get(new Get(Bytes.toBytes("2"))).listCells()
- assert(cells2.size == 2)
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(0))).equals("bar.1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(0))).equals("a"))
- assert(Bytes.toString(CellUtil.cloneValue(cells2.get(1))).equals("bar.2"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells2.get(1))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells2.get(1))).equals("b"))
-
- val cells1 = table.get(new Get(Bytes.toBytes("1"))).listCells()
- assert(cells1.size == 1)
- assert(Bytes.toString(CellUtil.cloneValue(cells1.get(0))).equals("foo1"))
- assert(Bytes.toString(CellUtil.cloneFamily(cells1.get(0))).equals("f1"))
- assert(Bytes.toString(CellUtil.cloneQualifier(cells1.get(0))).equals("a"))
-
- } finally {
- table.close()
- val admin = ConnectionFactory.createConnection(config).getAdmin
- try {
- admin.disableTable(TableName.valueOf(tableName))
- admin.deleteTable(TableName.valueOf(tableName))
- } finally {
- admin.close()
- }
- fs.delete(new Path(stagingFolder.getPath), true)
-
- testFolder.delete()
-
- }
- }
-}