package shaman.hive.udf;

import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaStringObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;

@Description(value="_FUNC_ get streamType from streamURL. ", 
        name="shaman_streamtype")
public class UDFStreamType extends GenericUDF {

    private JavaStringObjectInspector stringInspector;
    
    @Override
    public Object evaluate(DeferredObject[] arg0) throws HiveException {
        String streamURL = stringInspector.getPrimitiveJavaObject(arg0[0]);
        
        if (streamURL.contains(".mp4") || streamURL.contains("vod"))
        {
            if (streamURL.contains("live"))
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }
        else
        {
            return 0;
        }
    }

    @Override
    public String getDisplayString(String[] arg0) {
        return "Determine Stream Type";
    }

    @Override
    public ObjectInspector initialize(ObjectInspector[] arg0) throws UDFArgumentException {
        if (arg0.length != 1) {
            throw new UDFArgumentLengthException("__FUNC__ take one arguments, streamURL");
        }
        this.stringInspector = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
        return PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    }
    
}
@@ -932,16 +932,22 @@
 (arg0%5B0%5D
+.get()
 );%0A     
@@ -946,24 +946,60 @@
 );%0A        %0A
+        String streamType = %22Live%22;%0A
         if (
@@ -1073,32 +1073,33 @@
             if (
+!
 streamURL.contai
@@ -1144,167 +1144,78 @@
     
-return 0;%0A            %7D%0A            else%0A            %7B%0A                return 1;%0A            %7D%0A        %7D%0A        else%0A        %7B%0A            return 0;%0A        %7D
+streamType = %22VOD%22;%0A            %7D%0A        %7D%0A        return streamType;
 %0A   
@@ -1545,17 +1545,16 @@
 argument
-s
 , stream
@@ -1679,53 +1679,19 @@
 urn 
-PrimitiveObjectInspectorFactory.javaIntObject
+this.string
 Insp

fix a bug