fix read/write mixup
fix read/write mixup

Author: Peter Hoffmann <ph@peter-hoffmann.com>

Closes #6815 from hoffmann/patch-1 and squashes the following commits:

2abb6da [Peter Hoffmann] fix read/write mixup

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