簡體   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