Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-29240

PySpark 2.4 about sql function 'element_at' param 'extraction'

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.4.0
    • Fix Version/s: 2.4.5, 3.0.0
    • Component/s: PySpark
    • Labels:
      None

      Description

      I was trying to translate Scala into python with PySpark 2.4.0 .Codes below aims to extract col 'list' value using col 'num' as index.

       

      x = spark.createDataFrame([((1,2,3),1),((4,5,6),2),((7,8,9),3)],['list','num'])
      x.show()

       

      list num
      [1,2,3] 1
      [4,5,6] 2
      [7,8,9] 3

      I suppose to use new func 'element_at' in 2.4.0 .But it gives an error:

      x.withColumn('aa',F.element_at('list',x.num.cast('int')))
      

      TypeError: Column is not iterable

       

      Finally ,I have to use udf to solve this problem.

      But in Scala ,it is ok when the second param 'extraction' in func 'element_at' is a col name with int type: 

      //Scala
      val y = x.withColumn("aa",element_at('list,'num.cast("int")))
      y.show()
      list num  aa
      [1,2,3] 1  1
      [4,5,6] 
      [7,8,9] 

       I hope it could be fixed in latest version.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hyukjin.kwon Hyukjin Kwon
                Reporter:
                ChuboChaser Simon Reon
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 336h
                  336h
                  Remaining:
                  Remaining Estimate - 336h
                  336h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified