Guest User

Untitled

a guest
Mar 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. mica.select(concat_ws(':',mica.DieX, mica.DieY)).show()
  2.  
  3. or use UDF:
  4.  
  5. func = udf(lambda c1,c2: c1 +":" + c2, StringType())
  6. mica.withColumn("fid", func(col('LotId'),col('WaferId'))).show()
  7.  
  8. Define an UDF
  9. def position_X(s):
  10. if s in ["0","1","2","3","4","5","6","7","8","9"]:
  11. return 'P0'+s
  12. elif s in ["-1","-2","-3","-4","-5","-6","-7","-8","-9"]:
  13. return 'N0'+s[1]
  14. elif s >= "10":
  15. return 'P' + s
  16. else:
  17. return 'N' + s[1:]
  18. spark.udf.register("position_X",position_X)
  19.  
  20. def position_Y(s):
  21. if len(s) == 1:
  22. return '0' + s
  23. else:
  24. return s
  25. spark.udf.register("position_Y",position_Y)
  26.  
  27. from pyspark.sql.functions import *
  28. from pyspark.sql.functions import udf,col
  29. from pyspark.sql.types import *
  30.  
  31. pdf = pdf.select('*',substring("LotId",1,7) ,substring("WaferId",6,2)).drop("LotId","WaferId")
  32. pdf = pdf.withColumnRenamed('substring(LotId, 1, 7)', 'LotId')
  33. pdf = pdf.withColumnRenamed('substring(WaferId, 6, 2)', 'WaferId')
  34. Die_X = udf(position_X, StringType())
  35. pdf = pdf.withColumn("DieX", Die_X(col('DieX')))
  36. Die_Y = udf(position_Y, StringType())
  37. pdf = pdf.withColumn("DieY", Die_Y(col('DieY')))
  38. pdf = pdf.withColumn('Fid',concat_ws(':',pdf.LotId, pdf.WaferId,pdf.DieX,pdf.DieY)).drop("DieX","DieY","LotId","WaferId")
Add Comment
Please, Sign In to add comment