title: How to use constant value in UDF of Spark SQL(DataFrame)
body: <p>I have a dataframe which includes <code>timestamp</code>. To aggregate by time(minute, hour, or day), I have tried as:</p>
  
  <pre><code>val toSegment = udf((timestamp: String) =&gt; {
    val asLong = timestamp.toLong
    asLong - asLong % 3600000 // period = 1 hour
  })
  
  val df: DataFrame // the dataframe
  df.groupBy(toSegment($"timestamp")).count()
  </code></pre>
  
  <p>This works fine. </p>
  
  <p><strong>My question is how to generalize the UDF <code>toSegment</code> as</strong></p>
  
  <pre><code>val toSegmentGeneralized = udf((timestamp: String, period: Int) =&gt; {
    val asLong = timestamp.toLong
    asLong - asLong % period
  })
  </code></pre>
  
  <p>I have tried as follows but it doesn't work</p>
  
  <pre><code>df.groupBy(toSegment($"timestamp", $"3600000")).count()
  </code></pre>
  
  <p>It seems to find the column named <code>3600000</code>.</p>
  
  <p>Possible solution is <strong>to use constant column</strong> but I couldn't find it.</p>