Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark 如何计算用户会话的开始和结束时间?_Apache Spark_Apache Spark Sql - Fatal编程技术网

Apache spark 如何计算用户会话的开始和结束时间?

Apache spark 如何计算用户会话的开始和结束时间?,apache-spark,apache-spark-sql,Apache Spark,Apache Spark Sql,是否有推荐的方法执行以下类型的转换: 输入: 输出: userID startTime endTime actions u1 100 135 [edit1, edit2, edit3] u2 143 158 [edit4, edit5] u1 212 241 [edit6, edit7] 按用户ID分组会导致会话信息丢失。与使用窗口函数相同 为清晰起见,请编辑: 在这种情况下,请注意,用

是否有推荐的方法执行以下类型的转换:
输入:

输出:

userID  startTime  endTime  actions
u1      100        135      [edit1, edit2, edit3]
u2      143        158      [edit4, edit5]
u1      212        241      [edit6, edit7]
按用户ID分组会导致会话信息丢失。与使用窗口函数相同

为清晰起见,请编辑:
在这种情况下,请注意,用户u1在结果集中出现2次。用户u2的操作将u1的操作分为两个会话。

使用良好的ol'SQL聚合所有列:

SELECT userID min(timestamp), max(timestamp), collect_list(actions)
FROM df GROUP BY userID
或数据集API:

df.groupBy("userID").agg(
    min("timestamp") as "startTime",
    max("timestamp") as "endTime",
    collect_list("actions") as "actions")

遗憾的是,这将导致以下行:
[(u1 100 241[edit1,edit2,edit3,edit6,edit7]),(u2 143 158[edit4,edit5])]
,并且不会为同一用户维护单独的会话。u1需要有两行代表两个会话。谢谢@jaceklaskowski。另一个问题有帮助。另一个类似的问题回答:
df.groupBy("userID").agg(
    min("timestamp") as "startTime",
    max("timestamp") as "endTime",
    collect_list("actions") as "actions")