citusdata / citusdata/citus

Postgis aggregate `ST_AsGeoBuf` may fail on Citus if second parameter is used

Open
#4,999 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

Citus supports many of the Postgis aggs., but `ST_AsGeoBuf` seems to be failing.

```SQL
CREATE TABLE t1 (id bigserial, geom geometry(Polygon, 3857), catetitle varchar(32));
SELECT create_distributed_table('t1', 'id');
INSERT INTO t1 (catetitle, geom) SELECT i::text, 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))' FROM generate_series(0,1000)i;

SELECT(
catetitle,
count(geom),
public.ST_AsGeoBuf(
feature,
'geom'
)
)
FROM
(
SELECT
catetitle,
id,
geom
FROM t1
)feature group by catetitle;
ERROR: encode_keys: no geometry column found
Time: 220.492 ms

```

The workaound is to avoid the second parameter of `ST_AsGeoBuf` if possible:
```

SELECT(
catetitle,
count(geom),
public.ST_AsGeoBuf(
feature )
)
FROM
(
SELECT
catetitle,
id,
geom
FROM t1
)feature group by catetitle;
```

Initial observation:

The second parameter of ST_AsGeoBuf is the name of geom type that should be fetched from the first parameter. If it is not given, it uses the first geom type found in the first parameter: https://postgis.net/docs/doxygen/3.1/d2/d3b/geobuf_8c_ad01c55e7ba9997532bb58f481911d51f.html
It seems like Postgis explicitly expects the name of the name of the attribute in ROW(), whereas Citus fails to pass the names.
char *tkey = TupleDescAttr(tupdesc, i)->attname.data

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.