Member since
02-19-2017
8
Posts
2
Kudos Received
0
Solutions
12-28-2016
10:58 AM
@Kuldeep Kulkarni : Could you let me know how can I call a Hive scripts file i:e <script_name>.hql into a Ooozie shell action file. Is there a way I can achieve the same.
... View more
12-19-2016
01:22 PM
@Constantin Stanca I have come across a certain blog which implements a scala code to generate the Hierarchal data In hive using UDTF. But I have come acrss this below source code. But not sure How to execute or implement this. class ExpandTree 2 UDTF extends GenericUDTF {
var inputOIs : Array[PrimitiveObjectInspector] = null
val tree : collection.mutable.Map[String,Option[String]] = collection.mutable.Map()
override def initialize(args : Array[ObjectInspector]) : StructObjectInspector = {
inputOIs = args.map{ _ .asInstanceOf[PrimitiveObjectInspector]}
val fieldNames = java.util.Arrays.asList( "id" , "ancestor" , "level" )
val fieldOI = primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector.asInstanceOf[ObjectInspector]
val fieldOIs = java.util.Arrays.asList(fieldOI, fieldOI, fieldOI)
ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
def process(record : Array[Object]) {
val id = inputOIs( 0 ).getPrimitiveJavaObject(record( 0 )).asInstanceOf[String]
val parent = Option(inputOIs( 1 ).getPrimitiveJavaObject(record( 1 )).asInstanceOf[String])
tree + = ( id -> parent )
}
def close {
val expandTree = collection.mutable.Map[String,List[String]]()
def calculateAncestors(id : String) : List[String] =
tree(id) match { case Some(parent) = > id :: getAncestors(parent) ; case None = > List(id) }
def getAncestors(id : String) = expandTree.getOrElseUpdate(id, calculateAncestors(id))
tree.keys.foreach{ id = > getAncestors(id).zipWithIndex.foreach{ case (ancestor,level) = > forward(Array(id, ancestor, level)) } }
}
}
... View more
12-16-2016
10:34 AM
2 Kudos
Labels:
- Labels:
-
Apache Hadoop
-
Apache Hive