diff options
author | Ellen Spertus <ellen.spertus@gmail.com> | 2018-06-03 16:31:59 -0700 |
---|---|---|
committer | Ellen Spertus <ellen.spertus@gmail.com> | 2018-06-03 16:31:59 -0700 |
commit | 5da6d85175992fae019e1d4d1ebeb4accfec1820 (patch) | |
tree | 0aa2ab2d74e23fdfce365b36b21c75338624582f /scalding/src/main | |
parent | 59c2827bcd682a6c78714438ef8d7aaca2ccf13b (diff) | |
download | sandcrawler-5da6d85175992fae019e1d4d1ebeb4accfec1820.tar.gz sandcrawler-5da6d85175992fae019e1d4d1ebeb4accfec1820.zip |
Added HBaseBuilder.parseColSpecs and tests, which pass.
Diffstat (limited to 'scalding/src/main')
-rw-r--r-- | scalding/src/main/scala/sandcrawler/HBaseBuilder.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/scalding/src/main/scala/sandcrawler/HBaseBuilder.scala b/scalding/src/main/scala/sandcrawler/HBaseBuilder.scala new file mode 100644 index 0000000..c55aef6 --- /dev/null +++ b/scalding/src/main/scala/sandcrawler/HBaseBuilder.scala @@ -0,0 +1,49 @@ +package sandcrawler + +import cascading.tuple.Fields +import parallelai.spyglass.hbase.HBaseConstants.SourceMode +import parallelai.spyglass.hbase.HBaseSource +import scala._ + +object HBaseBuilder { + // map from column families to column names + val schema = Map("f" -> List("c"), + "file" -> List("size", "mime", "cdx"), + "grobid0" -> List("status_code", "quality", "status", "tei_xml", "tei_json", "metadata"), + "match0" -> List("status", "doi", "info")) + // map from colFamily:colName -> colFamily + // Code from https://stackoverflow.com/a/50595189/6310511 + val inverseSchema = for ((k, vs) <- schema; v <- vs) yield (k + ":" + v, k) + + @throws(classOf[IllegalArgumentException]) + def parseColSpec(colSpecs: List[String]) : (List[String], List[Fields]) = { + // Verify that all column specifiers are legal. + for (colSpec <- colSpecs) { + if (!(inverseSchema contains colSpec)) { + throw new IllegalArgumentException("No such column: " + colSpec) + } + val pair = colSpec split(":") + if (colSpec.split(":").length != 2) { + throw new IllegalArgumentException("Bad column specifier " + colSpec + + " (specifiers should be family:name)") + } + } + + // Produce and return a tuple containing: + // 1. A list of column families. + // 2. A corresponding list of Fields, each containing column names. + val groupMap: Map[String, List[String]] = colSpecs.groupBy(c => (c split ":")(0)) + val families = groupMap.keys.toList + val groupedColNames : List[List[String]] = families map {fam => { + val cols = {groupMap(fam).map(v => v.split(":")(1))} + cols}} + (families, groupedColNames.map({fields => new Fields(fields : _*)})) + } + + /* + def build(table: String, server: String, colSpec: List[String], sourceMode: SourceMode, keyList: List[String]) { + val (families: List[String], fields: List[Fields]) = parseColSpec(colSpec) + new HBaseSource(table, server, new Fields("key"), families, fields, sourceMode = sourceMode, keyList = keyList) + } + */ +} |