作家
登录

Hive、MapReduce、Spark分布式生成唯一数值型ID

作者: 来源: 2017-04-12 10:21:27 阅读 我要评论

  •         } 
  •          
  •         initID = getInitId(context.getJobConf().get("mapred.task.id"),increment); 
  •         if(initID == 0l) { 
  •             throw new IllegalArgumentException("mapred.task.id"); 
  •         } 
  •          
  •         System.out.println("initID : " + initID + "  increment : " + increment); 
  •     } 
  •      
  •     @Override 
  •     public ObjectInspector initialize(ObjectInspector[] arguments) 
  •             throws UDFArgumentException { 
  •         return PrimitiveObjectInspectorFactory.writableLongObjectInspector; 
  •     } 
  •   
  •     @Override 
  •     public Object evaluate(DeferredObject[] arguments) throws HiveException { 
  •         result.set(getValue()); 
  •         increment(increment); 
  •         return result; 
  •     } 
  •      
  •     @Override 
  •     public String getDisplayString(String[] children) { 
  •         return "RowSeq-func()"
  •     } 
  •      
  •     private synchronized void increment(int incr) { 
  •         initID += incr; 
  •     } 
  •      
  •     private synchronized long getValue() { 
  •         return initID; 
  •     } 
  •      
  •     //attempt_1478926768563_0537_m_000004_0 // return 0+1 
  •     private long getInitId (String taskAttemptIDstr,int numTasks) 
  •             throws IllegalArgumentException { 
  •         try { 
  •             String[] parts = taskAttemptIDstr.split(Character

      推荐阅读

      软件开发人员的编程障碍,你知道多少?

    没有人知足Java开辟人员这种已经“竭尽全力”改变世界的速度,每小我都欲望代码像消防水管里的水一样可以或许源源赓续地流出来,但没有人愿意供给给开辟人员更好地完成工作的前>>>详细阅读


    本文标题:Hive、MapReduce、Spark分布式生成唯一数值型ID

    地址:http://www.17bianji.com/lsqh/34744.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)