Is it possible to issue a spatial join with shapes from two tables?

不问归期 提交于 2019-12-25 08:16:53

问题


I want to be able to run a query like:

select A.*
  from A
  join B
    on match(A.geom,B.wkt) using within;

But i get:

ERROR:  UnhandledServerException: java.lang.IllegalArgumentException: queryTerm must be a literal

Sample schema:

create table if not exists A (
  id integer,
  geom geo_shape
);

create table if not exists B (
  id integer,
  wkt string index off
);

The reason for trying wkt string is due to the documentation's use of WKT literals. Additionally, since our actual implementation is a variable number of geometries that we might join against and geo_shape can't exist in an object, we were hoping to WKT would work with a join.

Update 1 (per Augmented Jacob's answer) Trying geo_shape join geo_shape with this schema:

create table if not exists B (
  id integer,
  wkt geo_shape
);

And the above query produces a different error:

SQLParseException: Couldn't create executionContexts from NodeOperations
... original-error: Can't handle Symbol io.crate.analyze.symbol.MatchPredicate@6666c921 

And, while the error isn't ideal, I wouldn't expect it to work anyway since the docs state:

Note

One MATCH predicate cannot combine columns of both relations of a join.

Update 2 With geo_shape join geo_shape, match doesn't work but within works, though, being "exact" queries, the performance makes it mostly unusable, at least across our 2.4B rows.

select A.*
  from A
  join B
    on within(B.wkt,A.geom);

回答1:


If you are using the match predicate Crate leverages the generated Lucene index of the geo_shape to get really fast but not "exact" results (as you already noticed). However, a geospatial match on two relations (join) is not possible with Lucene and that is why Crate is not able to do it. The documentation explains it also here:
https://crate.io/docs/reference/en/latest/sql/joins.html#join-conditions




回答2:


Your Variable in Table A geom is of type geo_shape whereas B has wkt of type string.

Change them to matching types and it should solve your java.lang.IllegalArgumentException



来源:https://stackoverflow.com/questions/41286539/is-it-possible-to-issue-a-spatial-join-with-shapes-from-two-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!