是否可以对两个表中的形状进行空间连接?

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

我希望能够运行这样的查询:

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

但我得到:

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

示例架构:

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

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

尝试 wkt string 的原因是 documentation's use of WKT literals。此外,由于我们的实际实现是可变数量的几何体,我们可能会加入这些几何体,并且 geo_shape 不能存在于一个对象中,我们希望 WKT 可以与一个连接一起工作。

更新 1(根据 )尝试 geo_shape 使用此模式加入 geo_shape:

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

上面的查询产生了不同的错误:

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

而且,虽然错误并不理想,但我不希望它能正常工作,因为 docs state:

Note

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

更新 2 使用 geo_shape 加入 geo_shape,match 不起作用,但 within 起作用,但是,being "exact" queries,性能使其几乎无法使用,至少在我们的 2.4B 行中是这样。

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

您在 Table 中的变量 A geom 的类型为 geo_shape,而 B 的 wkt 类型为 string

将它们更改为匹配类型,它应该可以解决您的 java.lang.IllegalArgumentException

如果您正在使用 match 谓词,Crate 利用 geo_shape 生成的 Lucene 索引来获得非常快但不是 "exact" 结果(正如您已经注意到的)。然而,Lucene 不可能对两个关系(连接)进行地理空间匹配,这就是 Crate 无法做到的原因。文档也在这里解释:
https://crate.io/docs/reference/en/latest/sql/joins.html#join-conditions