heshao2005 发表于 2018-10-23 06:29:26

hive job sql 优化 之CPU占有过高

1 Also you should use class level privatete members to save on object  
incantation and garbage collection.
  

  
2 You also get benefits by matching the args with what you would normally
  
expect from upstream. Hive converts text to string when needed, but if the
  
data normally coming into the method is text you could try and match the
  
argument and see if it is any faster.
  
Exapmle:
  
优化前:
  
>>>> import org.apache.hadoop.hive.ql.exec.UDF;
  
>>>> import java.net.URLDecoder;
  
>>>>
  
>>>> public final class urldecode extends UDF {
  
>>>>
  
>>>>    public String evaluate(final String s) {
  
>>>>      if (s == null) { return null; }
  
>>>>      return getString(s);
  
>>>>    }
  
>>>>
  
>>>>    public static String getString(String s) {
  
>>>>      String a;
  
>>>>      try {
  
>>>>            a = URLDecoder.decode(s);
  
>>>>      } catch ( Exception e) {
  
>>>>            a = "";
  
>>>>      }
  
>>>>      return a;
  
>>>>    }
  
>>>>
  
>>>>    public static void main(String args[]) {
  
>>>>      String t = "%E5%A4%AA%E5%8E%9F-%E4%B8%89%E4%BA%9A";
  
>>>>      System.out.println( getString(t) );
  
>>>>    }
  
>>>> }


页: [1]
查看完整版本: hive job sql 优化 之CPU占有过高