spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex <siri8...@gmail.com>
Subject Re: does both below code do the same thing? I had to refactor code to fit in spark-sql
Date Wed, 01 Feb 2017 05:38:17 GMT
Guys!!!!!!!!! Please Reply

On Tue, Jan 31, 2017 at 12:31 PM, Alex <siri8123@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
>

Mime
View raw message