繁体   English   中英

Presto SQL left joining using ST_intersects, ST_crosses 产生意想不到的结果

[英]Presto SQL left joining using ST_intersects, ST_crosses yield unexpected results

抱歉,如果标题没有提供信息。

使用 AWS 雅典娜。

有两张表:

1.交易表

location      time         status    type    ....   deleted_at
  BLOB     2020-09-01
  BLOB     2020-09-02
  BLOB     2020-09-03

2.area_table

 boundary              created_at     deleted_at
  POLYGON((...))       2020-09-01       null
  POLYGON((...))       2020-09-01       null
  POLYGON((...))       2020-09-01     2020-10-01

对于 transaction_table 中的每一行,我想添加适当的边界

    select date(time) as dt
         , count(time) As cnt
      from transaction_table t
 left join area_table a
        on ST_intersects(boundary, ST_Point(ST_X(t.location), ST_Y(t.location)))
     where t.status = 'complete'
       and t.deleted_at is null
       and t.time >= date('2020-09-01')
       and a.deleted_at is null
  group by date(withdraw_time);

问题是当我使用 ST_intersects 或 ST_contains 每天 cnt 从没有左连接的查询中减少时,这对我来说没有意义,因为左连接总是 output 等于或大于离开表的行。

左表、右表都没有 null 值,并且没有增加行数的多重连接(如果是这样,使用左连接查询比没有查询更多行)

现在使用 ST_Crosses 解决了这个问题 -> 使用/不使用左连接输出相同的结果。 但是我不确定为什么上面的查询中行数会减少。

编辑: ST_Crosses 似乎没有连接任何行,因此与没有左连接的查询具有相同的值。 所以我的问题是为什么在使用左连接 ST_intersects 或 ST_contains 时每日 cnt 会减少? Mysql(ST_point -> point) 中的相同查询运行得很好。

来自https://prestodb.io/docs/current/functions/geospatial.htmlhttps://dev.mysql.com/doc/refman/5.7/en/gis-class-point.html

  • Point(lat,lng) 给出零维点 object
  • ST_Point(lat,lng) 是一个几何图形,是二维的。

所以我想使用 ST_intersects(Geom,Geom) 和 ST_intersects(Geom, Point) 的工作方式不同,但这仍然不能解释左连接上减少的每日 cnt。

Athena 基于 Presto 0.172 - 根据他们的发行说明,没有可用的地理空间功能:

Athena 的地理空间功能作为 Presto 插件实现,完整的参考资料可在此处获得: 支持的地理空间功能列表

需要考虑的一件事实际上是 ST_POINT 的ST_POINT的顺序是ST_POINT(longitude, latitude) ,所以经度是第一个参数,纬度是第二个。

您还在 where 条件中引用了左右表,这肯定会导致行数减少。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM