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/01 05:38:17 UTC

Re: does both below code do the same thing? I had to refactor code to fit in spark-sql

Guys!!!!!!!!! Please Reply

On Tue, Jan 31, 2017 at 12:31 PM, Alex <si...@gmail.com> wrote:

> public Object get(Object name) {
>                 int pos = getPos((String) name);
>                 if (pos < 0)
>                         return null;
>                 String f = "string";
>                 Object obj = list.get(pos);
>                 Object result = null;
>                 if (obj == null)
>                         return null;
>                 ObjectInspector ins = ((StructField) colnames.get(pos)).
> getFieldObjectInspector();
>                 if (ins != null)
>                         f = ins.getTypeName();
>
>                         PrimitiveObjectInspector ins2 =
> (PrimitiveObjectInspector) ins;
>                         switch (ins2.getPrimitiveCategory()) {
>                         case DOUBLE:
>
>                                 Double res = (Double)(((DoubleObjectInspector)
> ins2).get(obj));
>                                 result = (double) res;
>                                 return result;
>
>
>                         case LONG:
>
>                                 Long res1 = (Long)(((LongObjectInspector)
> ins2).get(obj));
>                                 result = (long) res1;
>                                 return result;
>
>
>                         case STRING:
>                                 result = (((StringObjectInspector)
> ins2).getPrimitiveJavaObject(obj)).toString();
>                                 return result;
>
>                         default:
>                                 result = obj;
>                                 return result;
>                         }
>
>                 }
>
>
>
>
> Code 2 )
>
>
> 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;
>  }
> }
>
>
> But getting different results in hive and spark
>