0

I would like to use a window function in Scala.

I have a CSV file which is the following one :

id;date;value1
1;63111600000;100
1;63111700000;200
1;63154800000;300

When I try to apply a window function over this data frame, sometimes it works and sometimes it fails:

val df = loadCSVFile() 
val tw = Window.orderBy(date).partitionBy(id).rangeBetween(-5356800000,0) 
df.withColumn(value1___min_2_month, min(df.col("value1")).over(tw))
+---+-----------+--------------------+
| id|       date|value1___min_2_month|
+---+-----------+--------------------+
|  1|63111600000|                 100|
|  1|63111700000|                 100|
|  1|63154800000|                 100|
+---+-----------+--------------------+

So it works ! But when I try with a bigger number (which contains row of the previous exemple) I have the following result

val tw = 

Window.orderBy(date).partitionBy(id).rangeBetween(-8035200000,0) \n
df.withColumn(value1___min_3_month, min(df.col("value1")).over(tw)) 
+---+-----------+--------------------+
| id|       date|value1___min_3_month|
+---+-----------+--------------------+
|  1|63111600000|                null|
|  1|63111700000|                null|
|  1|63154800000|                null|
+---+-----------+--------------------+

1 Answers1

2

Suffix your number with L:

scala> -10000000000
<console>:1: error: integer number too large
-10000000000
 ^

scala> -10000000000L
res0: Long = -10000000000
pedrofurla
  • 12,763
  • 1
  • 38
  • 49