Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withConf "escape hatch" methods to reader and writer builders. #22

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ case class HBaseReaderBuilder [R: ClassTag] private[hbase] (
private[hbase] val columns: Iterable[String] = Seq.empty,
private[hbase] val startRow: Option[String] = None,
private[hbase] val stopRow: Option[String] = None,
private[hbase] val salting: Iterable[String] = Seq.empty
private[hbase] val salting: Iterable[String] = Seq.empty,
private[hbase] val conf: Map[String, String] = Map.empty
)
(implicit mapper: FieldReader[R], saltingProvider: SaltingProviderFactory[String]) extends Serializable {

Expand Down Expand Up @@ -57,6 +58,10 @@ case class HBaseReaderBuilder [R: ClassTag] private[hbase] (
this.copy(salting = salting)
}

def withConf(entry: (String, String)) = this.copy(conf = conf + entry)

def withConf(entries: Map[String, String]) = this.copy(conf = conf ++ entries)

}


Expand All @@ -80,7 +85,7 @@ trait HBaseReaderBuilderConversions extends Serializable {
}

def toSimpleHBaseRDD[R: ClassTag](builder: HBaseReaderBuilder[R], saltingLength: Int = 0)(implicit mapper: FieldReader[R], saltingProvider: SaltingProviderFactory[String]): HBaseSimpleRDD[R] = {
val hbaseConfig = HBaseSparkConf.fromSparkConf(builder.sc.getConf).createHadoopBaseConfig()
val hbaseConfig = HBaseSparkConf.fromSparkConf(builder.sc.getConf).createHadoopBaseConfig(builder.conf)

hbaseConfig.set(TableInputFormat.INPUT_TABLE, builder.table)

Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/it/nerdammer/spark/hbase/HBaseSparkConf.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package it.nerdammer.spark.hbase

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.spark.SparkConf

case class HBaseSparkConf (
hbaseHost: String = HBaseSparkConf.DefaultHBaseHost,
hbaseRootDir: String = HBaseSparkConf.DefaultHBaseRootDir) extends Serializable {

def createHadoopBaseConfig() = {
def createHadoopBaseConfig() : Configuration = createHadoopBaseConfig(Map())

def createHadoopBaseConfig(extraConf: Map[String, String]) : Configuration = {
val conf = HBaseConfiguration.create
conf.setBoolean("hbase.cluster.distributed", true)
conf.setInt("hbase.client.scanner.caching", 10000)
conf.set("hbase.rootdir", hbaseRootDir)
conf.set("hbase.zookeeper.quorum", hbaseHost)

for ((key, value) <- extraConf) {
conf.set(key, value)
}
conf
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/scala/it/nerdammer/spark/hbase/HBaseWriterBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.mapreduce.Job
import org.apache.spark.SparkContext._
import org.apache.spark.rdd.RDD

import scala.reflect.ClassTag
Expand All @@ -16,7 +15,8 @@ case class HBaseWriterBuilder[R: ClassTag] private[hbase] (
private[hbase] val table: String,
private[hbase] val columnFamily: Option[String] = None,
private[hbase] val columns: Iterable[String] = Seq.empty,
private[hbase] val salting: Iterable[String] = Seq.empty
private[hbase] val salting: Iterable[String] = Seq.empty,
private[hbase] val conf: Map[String, String] = Map.empty
)(implicit mapper: FieldWriter[R], saltingProvider: SaltingProviderFactory[String])
extends Serializable {

Expand All @@ -41,6 +41,14 @@ case class HBaseWriterBuilder[R: ClassTag] private[hbase] (
this.copy(salting = salting)
}

def withConf(entry: (String, String)) = {
this.copy(conf = conf + entry)
}

def withConf(entries: Map[String, String]) = {
this.copy(conf = conf ++ entries)
}

}

class HBaseWriterBuildable[R: ClassTag](rdd: RDD[R])(implicit mapper: FieldWriter[R], sal: SaltingProviderFactory[String]) extends Serializable {
Expand All @@ -53,7 +61,7 @@ class HBaseWriter[R: ClassTag](builder: HBaseWriterBuilder[R])(implicit mapper:

def save(): Unit = {

val conf = HBaseSparkConf.fromSparkConf(builder.rdd.sparkContext.getConf).createHadoopBaseConfig()
val conf = HBaseSparkConf.fromSparkConf(builder.rdd.sparkContext.getConf).createHadoopBaseConfig(builder.conf)
conf.set(TableOutputFormat.OUTPUT_TABLE, builder.table)

val job = Job.getInstance(conf)
Expand Down