title: How to pass the parameter to User-Defined Function?
body: <p>I have a user-defined function:</p>
  
  <pre><code>calc = udf(calculate, FloatType())
  
  param1 = "A"
  
  result = df.withColumn('col1', calc(col('type'), col('pos'))).groupBy('pk').sum('events')
  
  def calculate(type, pos):
     if param1=="A":
         a, b = [ 0.05, -0.06 ]
     else:
         a, b = [ 0.15, -0.16 ]
     return a * math.pow(type, b) * max(pos, 1)
  </code></pre>
  
  <p>I need to pass a parameter <code>param1</code> to this <code>udf</code>. How can I do it?</p>