O que o argumento 'startTime' da função pyspark.sql.functions.window faz e window.start?
O exemplo é o seguinte:
df=spark.createDataFrame([
(1,"2017-05-15 23:12:26",2.5),
(1,"2017-05-09 15:26:58",3.5),
(1,"2017-05-18 15:26:58",3.6),
(2,"2017-05-15 15:24:25",4.8),
(3,"2017-05-25 15:14:12",4.6)],["index","time","val"]).orderBy("index","time")
df.collect()
+-----+-------------------+---+
|index| time|val|
+-----+-------------------+---+
| 1|2017-05-09 15:26:58|3.5|
| 1|2017-05-15 23:12:26|2.5|
| 1|2017-05-18 15:26:58|3.6|
| 2|2017-05-15 15:24:25|4.8|
| 3|2017-05-25 15:14:12|4.6|
+-----+-------------------+---+
para a função "pyspark.sql.functions"
window(timeColumn, windowDuration, slideDuration=None, startTime=None)
timeColumn:The time column must be of TimestampType.
windowDuration: Durations are provided as strings, e.g. '1 second', '1 day 12 hours', '2 minutes'. Valid
interval strings are 'week', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond'.
slideDuration: If the 'slideDuration' is not provided, the windows will be tumbling windows.
startTime: the startTime is the offset with respect to 1970-01-01 00:00:00 UTC with which to start window intervals. For example, in order to have hourly tumbling windows that start 15 minutes past the hour, e.g. 12:15-13:15, 13:15-14:15... provide `startTime` as `15 minutes`.
Desejo contar os parâmetros "val" nessa função a cada 5 dias e defino o parâmetro "slideDuration" como um valor de string com "5 day"
timeColumn="time",windowDuration="5 day",slideDuration="5 day"
os códigos da seguinte forma:
df2=df.groupBy("index",F.window("time",windowDuration="5 day",slideDuration="5 day")).agg(F.sum("val").alias("sum_val"))
Quando obtenho o valor do parâmetro "window.start", o horário não começa com o tempo mínimo indicado na coluna "time" ou o tempo definido anteriormente, mas o outro momento, de onde não.
Os resultados foram os seguintes:
+-----+---------------------+---------------------+-------+
|index|start |end |sum_val|
+-----+---------------------+---------------------+-------+
|1 |2017-05-09 08:00:00.0|2017-05-14 08:00:00.0|3.5 |
|1 |2017-05-14 08:00:00.0|2017-05-19 08:00:00.0|6.1 |
|2 |2017-05-14 08:00:00.0|2017-05-19 08:00:00.0|4.8 |
|3 |2017-05-24 08:00:00.0|2017-05-29 08:00:00.0|4.6 |
+-----+---------------------+---------------------+-------+
Quando defino um valor para o parâmetro "startTime" com '0 segundo' (os códigos são os seguintes):
df2=df.groupBy("index",F.window("time",windowDuration="5 day",slideDuration="5 day",startTime="0 second")).agg(F.sum("val").alias("sum_val"))
+-----+---------------------+---------------------+-------+
|index|start |end |sum_val|
+-----+---------------------+---------------------+-------+
|1 |2017-05-09 08:00:00.0|2017-05-14 08:00:00.0|3.5 |
|1 |2017-05-14 08:00:00.0|2017-05-19 08:00:00.0|6.1 |
|2 |2017-05-14 08:00:00.0|2017-05-19 08:00:00.0|4.8 |
|3 |2017-05-24 08:00:00.0|2017-05-29 08:00:00.0|4.6 |
+-----+---------------------+---------------------+-------+
Os resultados revelaram que ainda não começou com o tempo mínimo na coluna "tempo"
Então, como devo fazer essa função começar com o tempo mínimo na coluna "time" ou com o tempo definido na primeira vez, como "2017-05-09 15:25:30", sou muito grato por você me descobrir fora desta questão
A introdução oficial do 'startTime' da seguinte forma
The startTime is the offset with respect to 1970-01-01 00:00:00 UTC with which to start window intervals.
For example, in order to have hourly tumbling windows that start 15 minutes past the hour, e.g. 12:15-13:15, 13:15-14:15...
provide `startTime` as `15 minutes`.
As referências são as seguintes1O que o argumento 'startTime' da função 'pyspark.sql.functions.window' faz?