You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Alex <si...@gmail.com> on 2017/02/03 14:49:25 UTC
Is DoubleWritable and DoubleObjectInspector doing the same thing in
Hive UDF?
Hi,
can You guys tell me if below peice of two codes are returning the same
thing?
(((DoubleObjectInspector) ins2).get(obj)); and (DoubleWritable)obj).get(); from
below two codes
code 1)
public Object get(Object name) {
int pos = getPos((String)name);
if(pos<0) return null;
String f = "string";
Object obj= list.get(pos);
if(obj==null) return null;
ObjectInspector ins = ((StructField)colnames.get(
pos)).getFieldObjectInspector();
if(ins!=null) f = ins.getTypeName();
switch (f) {
case "double" : return ((DoubleWritable)obj).get();
case "bigint" : return ((LongWritable)obj).get();
case "string" : return ((Text)obj).toString();
default : return obj;
}
}
Code 2)
public Object get(Object name) {
int pos = getPos((String) name);
if (pos < 0)
return null;
String f = "string";
String f1 = "string";
Object obj = list.get(pos);
if (obj == null)
return null;
ObjectInspector ins = ((StructField) colnames.get(pos)).
getFieldObjectInspector();
if (ins != null)
f = ins.getTypeName();
PrimitiveObjectInspector ins2 = (PrimitiveObjectInspector)
ins;
f1 = ins2.getPrimitiveCategory().name();
switch (ins2.getPrimitiveCategory()) {
case DOUBLE:
return (((DoubleObjectInspector) ins2).get(obj));
case LONG:
return (((LongObjectInspector) ins2).get(obj));
case STRING:
return (((StringObjectInspector)
ins2).getPrimitiveJavaObject(obj)).toString();
default: return obj;
}
}
Re: Is DoubleWritable and DoubleObjectInspector doing the same thing
in Hive UDF?
Posted by Alex <si...@gmail.com>.
Hiiii,
Please Reply?
On Fri, Feb 3, 2017 at 8:19 PM, Alex <si...@gmail.com> wrote:
> Hi,
>
> can You guys tell me if below peice of two codes are returning the same
> thing?
>
> (((DoubleObjectInspector) ins2).get(obj)); and (DoubleWritable)obj).get()
> ; from below two codes
>
>
> code 1)
>
> public Object get(Object name) {
> int pos = getPos((String)name);
> if(pos<0) return null;
> String f = "string";
> Object obj= list.get(pos);
> if(obj==null) return null;
> ObjectInspector ins = ((StructField)colnames.get(pos
> )).getFieldObjectInspector();
> if(ins!=null) f = ins.getTypeName();
> switch (f) {
> case "double" : return ((DoubleWritable)obj).get();
> case "bigint" : return ((LongWritable)obj).get();
> case "string" : return ((Text)obj).toString();
> default : return obj;
> }
> }
>
>
> Code 2)
>
> public Object get(Object name) {
>
> int pos = getPos((String) name);
>
> if (pos < 0)
>
> return null;
>
> String f = "string";
>
> String f1 = "string";
>
> Object obj = list.get(pos);
>
>
>
> if (obj == null)
>
> return null;
>
> ObjectInspector ins = ((StructField)
> colnames.get(pos)).getFieldObjectInspector();
>
> if (ins != null)
>
> f = ins.getTypeName();
>
>
>
>
>
> PrimitiveObjectInspector ins2 =
> (PrimitiveObjectInspector) ins;
>
> f1 = ins2.getPrimitiveCategory().name();
>
>
>
>
>
> switch (ins2.getPrimitiveCategory()) {
>
> case DOUBLE:
>
>
>
> return (((DoubleObjectInspector) ins2).get(obj));
>
>
>
> case LONG:
>
>
>
> return (((LongObjectInspector) ins2).get(obj));
>
>
>
> case STRING:
>
> return (((StringObjectInspector)
> ins2).getPrimitiveJavaObject(obj)).toString();
>
>
>
> default: return obj;
>
> }
>
> }
>