[SPARK-2871] [PySpark] add zipWithIndex() and zipWithUniqueId()
[SPARK-2871] [PySpark] add zipWithIndex() and zipWithUniqueId()

RDD.zipWithIndex()

        Zips this RDD with its element indices.

        The ordering is first based on the partition index and then the
        ordering of items within each partition. So the first item in
        the first partition gets index 0, and the last item in the last
        partition receives the largest index.

        This method needs to trigger a spark job when this RDD contains
        more than one partitions.

        >>> sc.parallelize(range(4), 2).zipWithIndex().collect()
        [(0, 0), (1, 1), (2, 2), (3, 3)]

RDD.zipWithUniqueId()

        Zips this RDD with generated unique Long ids.

        Items in the kth partition will get ids k, n+k, 2*n+k, ..., where
        n is the number of partitions. So there may exist gaps, but this
        method won't trigger a spark job, which is different from
        L{zipWithIndex}

        >>> sc.parallelize(range(4), 2).zipWithUniqueId().collect()
        [(0, 0), (2, 1), (1, 2), (3, 3)]

Author: Davies Liu <davies.liu@gmail.com>

Closes #2092 from davies/zipWith and squashes the following commits:

cebe5bf [Davies Liu] improve test cases, reverse the order of index
0d2a128 [Davies Liu] add zipWithIndex() and zipWithUniqueId()

ddna1021/spark,ericvandenbergfb/spark,rezasafi/spark,WindCanDie/spark,loneknightpy/spark,wangyum/spark,saltstar/spark,highfei2011/spark,ajaysaini725/spark,dhruve/spark,sahilTakiar/spark,yanboliang/spark,wzhfy/spark,rezasafi/spark,pronix/spark,mahak/spark,darionyaphet/spark,ibm-research-ireland/sparkoscope,liyichao/spark,jiangxb1987/spark,jlopezmalla/spark,akopich/spark,cin/spark,highfei2011/spark,nchammas/spark,brad-kaiser/spark,huang1900/spark,setjet/spark,pronix/spark,kissmetrics/spark,ahnqirage/spark,ron8hu/spark,apache/spark,witgo/spark,actuaryzhang/spark,ahnqirage/spark,huang1900/spark,apache-spark-on-k8s/spark,bdrillard/spark,sureshthalamati/spark,zhouyejoe/spark,goldmedal/spark,big-pegasus/spark,minixalpha/spark,liyichao/spark,ron8hu/spark,tengpeng/spark,publicRoman/spark,zuotingbing/spark,alunarbeach/spark,poffuomo/spark,someorz/spark,saturday-shi/spark,jrshust/spark,gioenn/xSpark,Aegeaner/spark,pgandhi999/spark,srowen/spark,srowen/spark,HyukjinKwon/spark,SHASHANKB/spark,narahari92/spark,map222/spark,lvdongr/spark,michalsenkyr/spark,cin/spark,ueshin/apache-spark,akopich/spark,highfei2011/spark,UndeadBaneGitHub/spark,JerryLead/spark,rednaxelafx/apache-spark,wangyum/spark,goldmedal/spark,gengliangwang/spark,milliman/spark,ddna1021/spark,debugger87/spark,hhbyyh/spark,ptkool/spark,janewangfb/spark,skonto/spark,sureshthalamati/spark,zzcclp/spark,jiangxb1987/spark,stanzhai/spark,guoxiaolongzte/spark,aokolnychyi/spark,saturday-shi/spark,SHASHANKB/spark,mahak/spark,jrshust/spark,wzhfy/spark,skonto/spark,gengliangwang/spark,szhem/spark,brad-kaiser/spark,kiszk/spark,zero323/spark,xflin/spark,dongjoon-hyun/spark,nchammas/spark,tengpeng/spark,bdrillard/spark,matthewfranglen/spark,ConeyLiu/spark,gioenn/xSpark,kevinyu98/spark,jiangxb1987/spark,milliman/spark,haowu80s/spark,goldmedal/spark,techaddict/spark,mzl9039/spark,Panos-Bletsos/spark-cost-model-optimizer,mdespriee/spark,big-pegasus/spark,map222/spark,gengliangwang/spark,hhbyyh/spark,adrian-ionescu/apache-spark,gioenn/xSpark,darionyaphet/spark,someorz/spark,szhem/spark,tengpeng/spark,dbtsai/spark,saturday-shi/spark,sahilTakiar/spark,xflin/spark,Aegeaner/spark,witgo/spark,janewangfb/spark,ioana-delaney/spark,guoxiaolongzte/spark,goldmedal/spark,pgandhi999/spark,szhem/spark,pgandhi999/spark,akopich/spark,esi-mineset/spark,aosagie/spark,byakuinss/spark,pgandhi999/spark,wangyum/spark,patrick-nicholson/spark,pgandhi999/spark,xflin/spark,highfei2011/spark,jlopezmalla/spark,apache/spark,andrewor14/spark,UndeadBaneGitHub/spark,SHASHANKB/spark,markhamstra/spark,setjet/spark,saltstar/spark,ioana-delaney/spark,LantaoJin/spark,holdenk/spark,mzl9039/spark,lxsmnv/spark,mike0sv/spark,xuanyuanking/spark,sachintyagi22/spark,1haodian/spark,wzhfy/spark,cloud-fan/spark,dhruve/spark,publicRoman/spark,rednaxelafx/apache-spark,zero323/spark,vinodkc/spark,ajaysaini725/spark,wzhfy/spark,chuckchen/spark,bOOm-X/spark,jiangxb1987/spark,wzhfy/spark,patrick-nicholson/spark,esi-mineset/spark,sachintyagi22/spark,sureshthalamati/spark,tengpeng/spark,dbtsai/spark,ajaysaini725/spark,jrshust/spark,nlalevee/spark,skonto/spark,LantaoJin/spark,xflin/spark,haowu80s/spark,JoshRosen/spark,alunarbeach/spark,BryanCutler/spark,BryanCutler/spark,minixalpha/spark,andrewor14/iolap,kimoonkim/spark,icexelloss/spark,HyukjinKwon/spark,akopich/spark,MLnick/spark,sureshthalamati/spark,Aegeaner/spark,kiszk/spark,sachintyagi22/spark,pronix/spark,panfengfeng/spark,ahnqirage/spark,szhem/spark,jkbradley/spark,chuckchen/spark,ajaysaini725/spark,bOOm-X/spark,aray/spark,witgo/spark,goldmedal/spark,adrian-ionescu/apache-spark,shubhamchopra/spark,cin/spark,andrewor14/iolap,saturday-shi/spark,aokolnychyi/spark,skonto/spark,kevinyu98/spark,shuangshuangwang/spark,byakuinss/spark,kissmetrics/spark,joseph-torres/spark,patrick-nicholson/spark,dbtsai/spark,liyichao/spark,cin/spark,tejasapatil/spark,jlopezmalla/spark,MLnick/spark,kimoonkim/spark,saturday-shi/spark,SnappyDataInc/spark,adrian-ionescu/apache-spark,mdespriee/spark,panfengfeng/spark,cloud-fan/spark,SHASHANKB/spark,brad-kaiser/spark,brad-kaiser/spark,ajaysaini725/spark,JoshRosen/spark,ron8hu/spark,eyalfa/spark,1haodian/spark,wangyum/spark,kissmetrics/spark,guoxiaolongzte/spark,UndeadBaneGitHub/spark,guoxiaolongzte/spark,setjet/spark,bdrillard/spark,kiszk/spark,cloud-fan/spark,wzhfy/spark,wangmiao1981/spark,caneGuy/spark,bravo-zhang/spark,nlalevee/spark,srowen/spark,zzcclp/spark,jianran/spark,JerryLead/spark,ddna1021/spark,darionyaphet/spark,stanzhai/spark,ptkool/spark,nlalevee/spark,tejasapatil/spark,bOOm-X/spark,ibm-research-ireland/sparkoscope,aray/spark,apache/spark,ptkool/spark,someorz/spark,xuanyuanking/spark,setjet/spark,xuanyuanking/spark,nilsgrabbert/spark,dbtsai/spark,dhruve/spark,sureshthalamati/spark,pgandhi999/spark,MLnick/spark,maropu/spark,brad-kaiser/spark,mzl9039/spark,huang1900/spark,JoshRosen/spark,Aegeaner/spark,saltstar/spark,witgo/spark,aosagie/spark,markhamstra/spark,BryanCutler/spark,nlalevee/spark,holdenk/spark,actuaryzhang/spark,ConeyLiu/spark,bOOm-X/spark,ahnqirage/spark,Panos-Bletsos/spark-cost-model-optimizer,shuangshuangwang/spark,huang1900/spark,jianran/spark,publicRoman/spark,pgandhi999/spark,rezasafi/spark,LantaoJin/spark,gioenn/xSpark,kimoonkim/spark,icexelloss/spark,michalsenkyr/spark,map222/spark,hvanhovell/spark,MLnick/spark,actuaryzhang/spark,mahak/spark,apache-spark-on-k8s/spark,pronix/spark,hvanhovell/spark,debugger87/spark,zero323/spark,1haodian/spark,rezasafi/spark,icexelloss/spark,michalsenkyr/spark,akopich/spark,ueshin/apache-spark,shubhamchopra/spark,JerryLead/spark,joseph-torres/spark,lvdongr/spark,ahnqirage/spark,dhruve/spark,wangmiao1981/spark,alunarbeach/spark,Panos-Bletsos/spark-cost-model-optimizer,darionyaphet/spark,michalsenkyr/spark,andrewor14/spark,andrewor14/iolap,SnappyDataInc/spark,mahak/spark,apache-spark-on-k8s/spark,rikima/spark,wangmiao1981/spark,rikima/spark,vinodkc/spark,ConeyLiu/spark,actuaryzhang/spark,minixalpha/spark,markhamstra/spark,tejasapatil/spark,setjet/spark,icexelloss/spark,ron8hu/spark,publicRoman/spark,lvdongr/spark,ueshin/apache-spark,narahari92/spark,zuotingbing/spark,mike0sv/spark,hhbyyh/spark,darionyaphet/spark,narahari92/spark,tengpeng/spark,nilsgrabbert/spark,xflin/spark,WindCanDie/spark,taroplus/spark,zhouyejoe/spark,panfengfeng/spark,gioenn/xSpark,aosagie/spark,eyalfa/spark,SnappyDataInc/spark,adrian-ionescu/apache-spark,aokolnychyi/spark,mike0sv/spark,Aegeaner/spark,jrshust/spark,techaddict/spark,janewangfb/spark,mzl9039/spark,rekhajoshm/spark,joseph-torres/spark,1haodian/spark,caneGuy/spark,patrick-nicholson/spark,spark-test/spark,big-pegasus/spark,WindCanDie/spark,xflin/spark,facaiy/spark,milliman/spark,ioana-delaney/spark,akopich/spark,ddna1021/spark,shuangshuangwang/spark,setjet/spark,jkbradley/spark,srowen/spark,JoshRosen/spark,esi-mineset/spark,hvanhovell/spark,sachintyagi22/spark,shaneknapp/spark,patrick-nicholson/spark,shubhamchopra/spark,dongjoon-hyun/spark,ptkool/spark,ibm-research-ireland/sparkoscope,spark-test/spark,chuckchen/spark,ptkool/spark,ibm-research-ireland/sparkoscope,nchammas/spark,1haodian/spark,esi-mineset/spark,xuanyuanking/spark,WindCanDie/spark,jiangxb1987/spark,loneknightpy/spark,rekhajoshm/spark,zzcclp/spark,zzcclp/spark,BryanCutler/spark,highfei2011/spark,caneGuy/spark,hvanhovell/spark,BryanCutler/spark,bdrillard/spark,ioana-delaney/spark,chuckchen/spark,guoxiaolongzte/spark,lvdongr/spark,kissmetrics/spark,aray/spark,bdrillard/spark,HyukjinKwon/spark,wangmiao1981/spark,narahari92/spark,stanzhai/spark,dongjoon-hyun/spark,ueshin/apache-spark,mike0sv/spark,zero323/spark,guoxiaolongzte/spark,ajaysaini725/spark,Aegeaner/spark,lvdongr/spark,pronix/spark,nchammas/spark,panfengfeng/spark,WeichenXu123/spark,WindCanDie/spark,rikima/spark,saltstar/spark,srowen/spark,shaneknapp/spark,mdespriee/spark,aosagie/spark,markhamstra/spark,Panos-Bletsos/spark-cost-model-optimizer,shuangshuangwang/spark,chuckchen/spark,hvanhovell/spark,metamx/spark,spark-test/spark,dongjoon-hyun/spark,huang1900/spark,bravo-zhang/spark,rekhajoshm/spark,joseph-torres/spark,adrian-ionescu/apache-spark,jkbradley/spark,wangyum/spark,loneknightpy/spark,Panos-Bletsos/spark-cost-model-optimizer,nilsgrabbert/spark,gengliangwang/spark,bravo-zhang/spark,nchammas/spark,lxsmnv/spark,shaneknapp/spark,wangyum/spark,kissmetrics/spark,HyukjinKwon/spark,mike0sv/spark,milliman/spark,yanboliang/spark,liutang123/spark,minixalpha/spark,apache-spark-on-k8s/spark,techaddict/spark,panfengfeng/spark,andrewor14/spark,MLnick/spark,maropu/spark,aosagie/spark,xuanyuanking/spark,icexelloss/spark,eyalfa/spark,1haodian/spark,markhamstra/spark,facaiy/spark,map222/spark,cloud-fan/spark,kissmetrics/spark,vinodkc/spark,andrewor14/spark,liutang123/spark,zhouyejoe/spark,ericvandenbergfb/spark,big-pegasus/spark,ddna1021/spark,byakuinss/spark,someorz/spark,byakuinss/spark,shaneknapp/spark,narahari92/spark,WeichenXu123/spark,dbtsai/spark,lxsmnv/spark,nlalevee/spark,eyalfa/spark,ueshin/apache-spark,jrshust/spark,UndeadBaneGitHub/spark,zuotingbing/spark,ericvandenbergfb/spark,hhbyyh/spark,bravo-zhang/spark,taroplus/spark,ibm-research-ireland/sparkoscope,eyalfa/spark,vinodkc/spark,sachintyagi22/spark,michalsenkyr/spark,darionyaphet/spark,narahari92/spark,yanboliang/spark,zuotingbing/spark,hhbyyh/spark,mdespriee/spark,JerryLead/spark,jkbradley/spark,actuaryzhang/spark,highfei2011/spark,zhouyejoe/spark,BryanCutler/spark,caneGuy/spark,janewangfb/spark,witgo/spark,SnappyDataInc/spark,zhouyejoe/spark,pronix/spark,kevinyu98/spark,holdenk/spark,rekhajoshm/spark,lxsmnv/spark,caneGuy/spark,facaiy/spark,xuanyuanking/spark,eyalfa/spark,shaneknapp/spark,ConeyLiu/spark,alunarbeach/spark,kevinyu98/spark,jlopezmalla/spark,alunarbeach/spark,WeichenXu123/spark,WeichenXu123/spark,markhamstra/spark,rikima/spark,skonto/spark,kiszk/spark,metamx/spark,eyalfa/spark,ahnqirage/spark,szhem/spark,gioenn/xSpark,jiangxb1987/spark,liyichao/spark,jkbradley/spark,rekhajoshm/spark,narahari92/spark,vinodkc/spark,poffuomo/spark,bdrillard/spark,MLnick/spark,panfengfeng/spark,BryanCutler/spark,vinodkc/spark,nilsgrabbert/spark,metamx/spark,witgo/spark,mahak/spark,brad-kaiser/spark,liyichao/spark,andrewor14/iolap,apache/spark,shuangshuangwang/spark,metamx/spark,mike0sv/spark,rekhajoshm/spark,janewangfb/spark,SnappyDataInc/spark,hvanhovell/spark,nilsgrabbert/spark,yanboliang/spark,saltstar/spark,saltstar/spark,rikima/spark,metamx/spark,saltstar/spark,map222/spark,gioenn/xSpark,rezasafi/spark,shuangshuangwang/spark,WindCanDie/spark,zhouyejoe/spark,LantaoJin/spark,jkbradley/spark,Aegeaner/spark,JoshRosen/spark,byakuinss/spark,patrick-nicholson/spark,byakuinss/spark,mahak/spark,nchammas/spark,facaiy/spark,chuckchen/spark,mdespriee/spark,ioana-delaney/spark,ron8hu/spark,haowu80s/spark,liutang123/spark,bdrillard/spark,JerryLead/spark,lxsmnv/spark,saturday-shi/spark,ron8hu/spark,rekhajoshm/spark,ptkool/spark,cloud-fan/spark,dongjoon-hyun/spark,milliman/spark,cin/spark,holdenk/spark,sachintyagi22/spark,shubhamchopra/spark,sureshthalamati/spark,ConeyLiu/spark,adrian-ionescu/apache-spark,bravo-zhang/spark,janewangfb/spark,techaddict/spark,cloud-fan/spark,holdenk/spark,poffuomo/spark,andrewor14/spark,jlopezmalla/spark,jkbradley/spark,SHASHANKB/spark,actuaryzhang/spark,UndeadBaneGitHub/spark,aosagie/spark,hhbyyh/spark,Panos-Bletsos/spark-cost-model-optimizer,andrewor14/spark,tejasapatil/spark,lvdongr/spark,kissmetrics/spark,dongjoon-hyun/spark,alunarbeach/spark,loneknightpy/spark,ibm-research-ireland/sparkoscope,esi-mineset/spark,zero323/spark,minixalpha/spark,apache/spark,zero323/spark,rednaxelafx/apache-spark,ericvandenbergfb/spark,gengliangwang/spark,actuaryzhang/spark,adrian-ionescu/apache-spark,joseph-torres/spark,techaddict/spark,WeichenXu123/spark,jiangxb1987/spark,huang1900/spark,sahilTakiar/spark,mzl9039/spark,dhruve/spark,poffuomo/spark,publicRoman/spark,jrshust/spark,SHASHANKB/spark,srowen/spark,aray/spark,ConeyLiu/spark,xuanyuanking/spark,apache-spark-on-k8s/spark,lxsmnv/spark,kimoonkim/spark,dongjoon-hyun/spark,zuotingbing/spark,vinodkc/spark,spark-test/spark,aokolnychyi/spark,caneGuy/spark,aray/spark,maropu/spark,apache/spark,SHASHANKB/spark,big-pegasus/spark,LantaoJin/spark,ajaysaini725/spark,publicRoman/spark,minixalpha/spark,WeichenXu123/spark,spark-test/spark,akopich/spark,taroplus/spark,kimoonkim/spark,someorz/spark,debugger87/spark,UndeadBaneGitHub/spark,haowu80s/spark,taroplus/spark,mahak/spark,janewangfb/spark,witgo/spark,liutang123/spark,patrick-nicholson/spark,esi-mineset/spark,hhbyyh/spark,dhruve/spark,sachintyagi22/spark,jlopezmalla/spark,joseph-torres/spark,guoxiaolongzte/spark,aray/spark,HyukjinKwon/spark,kevinyu98/spark,icexelloss/spark,taroplus/spark,ericvandenbergfb/spark,aokolnychyi/spark,tejasapatil/spark,SnappyDataInc/spark,WeichenXu123/spark,ddna1021/spark,UndeadBaneGitHub/spark,sureshthalamati/spark,cin/spark,michalsenkyr/spark,cin/spark,someorz/spark,debugger87/spark,szhem/spark,andrewor14/spark,saturday-shi/spark,zhouyejoe/spark,apache/spark,kiszk/spark,kiszk/spark,sahilTakiar/spark,jianran/spark,rednaxelafx/apache-spark,zero323/spark,maropu/spark,JerryLead/spark,rikima/spark,lvdongr/spark,michalsenkyr/spark,bOOm-X/spark,andrewor14/iolap,nlalevee/spark,jlopezmalla/spark,joseph-torres/spark,map222/spark,dbtsai/spark,rezasafi/spark,jianran/spark,nchammas/spark,ron8hu/spark,chuckchen/spark,debugger87/spark,aosagie/spark,metamx/spark,tejasapatil/spark,goldmedal/spark,andrewor14/iolap,stanzhai/spark,minixalpha/spark,loneknightpy/spark,caneGuy/spark,rednaxelafx/apache-spark,taroplus/spark,spark-test/spark,aokolnychyi/spark,shuangshuangwang/spark,nlalevee/spark,hvanhovell/spark,poffuomo/spark,aokolnychyi/spark,yanboliang/spark,loneknightpy/spark,liutang123/spark,mike0sv/spark,tejasapatil/spark,wzhfy/spark,haowu80s/spark,szhem/spark,ptkool/spark,liutang123/spark,apache-spark-on-k8s/spark,ueshin/apache-spark,spark-test/spark,tengpeng/spark,facaiy/spark,ericvandenbergfb/spark,mdespriee/spark,wangmiao1981/spark,zzcclp/spark,darionyaphet/spark,kimoonkim/spark,kevinyu98/spark,ioana-delaney/spark,cloud-fan/spark,stanzhai/spark,huang1900/spark,shubhamchopra/spark,milliman/spark,skonto/spark,maropu/spark,HyukjinKwon/spark,JerryLead/spark,rednaxelafx/apache-spark,big-pegasus/spark,JoshRosen/spark,mzl9039/spark,map222/spark,panfengfeng/spark,esi-mineset/spark,mzl9039/spark,zzcclp/spark,ioana-delaney/spark,big-pegasus/spark,wangmiao1981/spark,nilsgrabbert/spark,apache-spark-on-k8s/spark,milliman/spark,bOOm-X/spark,skonto/spark,kimoonkim/spark,aray/spark,wangmiao1981/spark,liutang123/spark,goldmedal/spark,highfei2011/spark,techaddict/spark,rednaxelafx/apache-spark,maropu/spark,bravo-zhang/spark,loneknightpy/spark,yanboliang/spark,ibm-research-ireland/sparkoscope,haowu80s/spark,yanboliang/spark,zzcclp/spark,xflin/spark,poffuomo/spark,rikima/spark,ddna1021/spark,JoshRosen/spark,Panos-Bletsos/spark-cost-model-optimizer,shubhamchopra/spark,bravo-zhang/spark,jrshust/spark,shaneknapp/spark,dhruve/spark,setjet/spark,shaneknapp/spark,1haodian/spark,rezasafi/spark,SnappyDataInc/spark,lxsmnv/spark,WindCanDie/spark,sahilTakiar/spark,nilsgrabbert/spark,kiszk/spark,debugger87/spark,ahnqirage/spark,zuotingbing/spark,debugger87/spark,jianran/spark,srowen/spark,gengliangwang/spark,shubhamchopra/spark,bOOm-X/spark,metamx/spark,brad-kaiser/spark,LantaoJin/spark,poffuomo/spark,tengpeng/spark,stanzhai/spark,andrewor14/iolap,icexelloss/spark,sahilTakiar/spark,byakuinss/spark,ueshin/apache-spark,sahilTakiar/spark,stanzhai/spark,someorz/spark,jianran/spark,taroplus/spark,facaiy/spark,techaddict/spark,liyichao/spark,kevinyu98/spark,jianran/spark,markhamstra/spark,gengliangwang/spark,holdenk/spark,holdenk/spark,liyichao/spark,LantaoJin/spark,publicRoman/spark,zuotingbing/spark,mdespriee/spark,alunarbeach/spark,facaiy/spark,wangyum/spark,dbtsai/spark,maropu/spark,HyukjinKwon/spark,ericvandenbergfb/spark,MLnick/spark,ConeyLiu/spark