java - 火花函数 rangeBetween 直到满足条件
问题描述
我有一个这种格式的数据集:
+-----------------------------+------------------------------------+------------+-----------------+
| timestamp |uuid |storyTopic |Type |
+-----------------------------+------------------------------------+------------+-----------------+
|2019-04-15 11:21:03.362 -0400|9e0f3d00-cff7-3b76-89df-0d11c0addc91|TRY1 |Draft |
|2019-04-15 11:21:06.547 -0400|null |TRY1 |Draft |
|2019-04-15 11:21:06.617 -0400|e142e9bc-6587-34e3-9042-959b624f5 |Trial12345 |Original |
|2019-04-15 11:21:08.196 -0400|null |TRY1 |Draft |
|2019-04-15 11:21:22.855 -0400|null |TRY1 |Draft |
|2019-04-15 11:23:36.108 -0400|null |TRY1 |Draft |
|2019-04-15 11:23:36.139 -0400|null |TRY1 |Draft |
|2019-04-15 11:23:50.311 -0400|null |TRY1 |Draft |
|2019-04-15 15:21:08.196 -0400|null |TRY1 |Draft |
|2019-04-15 15:21:12.617 -0400|e142e9bc-6587-34e3-9042-959b624f5 |Trial12345 |Original |
+-----------------------------+------------------------------------+------------+-----------------+
TRY1
如果数据集第一行storyTopic为1.找到timeDifference小于5秒的
行2.uuid不为null
我尝试通过以下方式实现它:
//create time difference column
df.withColumn("diff", functions.unix_timestamp(functions.col("timestamp")));
//create a window function for time-range
WindowSpec w = Window.orderBy("diff").rangeBetween(1L, 5L);
df.withColumn("Type", functions.when(
(functions.rank().over(w)==1)
//checking if uuid is null
.and(functions.first("uuid").over(w).isNotNull()),
functions.first("storyTopic").over(w)).otherwise("storyTopic");
发生的事情是它忽略了uuid.isNotNull()
条件并从第二行获取数据,而不是从满足两个条件的第三行获取数据。
如何确保functions.first()
获取 uuid 不为空的行?
解决方案
推荐阅读
- php - symfony - 如何进行路由
- c# - 在 MouseOver 上重绘按钮图形或单击
- c# - C# 分配列表
.Count 减一到整数不起作用 - spring-boot - 在 Spring Boot WebMvcConfigurer 中允许 CORS 时,请求的资源上不存在“Access-Control-Allow-Origin”标头
- javascript - 使用预签名 URL 上传后,AWS S3 上的文件在文件中有额外信息
- reactjs - 在 formik 组件之外处理 formik 表单
- javascript - 空手道 DSL - 如何从 __arg 读取令牌字符串并在 json 请求中发送此字符串?
- python-3.x - Python 3.7:GridSearchCV 和 RandomizedSearch CV 上的 ValueError - 输入包含 NaN、无穷大或对于 dtype('float32') 来说太大的值。-
- python - 无法使用 Selenium (Python) 检索脚本执行的 html 源
- python - Cython 无法识别 pymalloc Python