maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.
https://martin.maplibre.org
Apache License 2.0
2.27k stars 213 forks source link

Error on get bounds when one table has only one Point #299

Open HackJack-101 opened 2 years ago

HackJack-101 commented 2 years ago

Context

I use martin on a database and one of the tables has only one row which is a Point. image

Martin: Docker image | urbica/martin:latest and urbica/martin:main Postgres+Postgis: Docker image | kartoza/postgis:13-3.1

Errors

When /index.json is requested, Martin returns an error 500 "Mailbox has closed". When any /schema.table.json is requested, Martin returns an error 500 "There is no such table sources"

Logs

martin_1  | [2022-01-11T16:46:43Z INFO  actix_web::middleware::logger] 172.18.0.1:64284 "GET /index.json HTTP/1.1" 200 3169 "-" "PostmanRuntime/7.28.4" 0.442517
martin_1  | [2022-01-11T16:51:57Z INFO  martin::server] Scanning database for table sources
martin_1  | [2022-01-11T16:51:57Z DEBUG tokio_postgres::simple_query] executing simple query: SELECT 1;
martin_1  | [2022-01-11T16:51:57Z DEBUG tokio_postgres::prepare] preparing query s9: WITH columns AS (
martin_1  |       SELECT
martin_1  |         ns.nspname AS table_schema,
martin_1  |         class.relname AS table_name,
martin_1  |         attr.attname AS column_name,
martin_1  |         trim(leading '_' from tp.typname) AS type_name
martin_1  |       FROM pg_attribute attr
martin_1  |         JOIN pg_catalog.pg_class AS class ON class.oid = attr.attrelid
martin_1  |         JOIN pg_catalog.pg_namespace AS ns ON ns.oid = class.relnamespace
martin_1  |         JOIN pg_catalog.pg_type AS tp ON tp.oid = attr.atttypid
martin_1  |       WHERE NOT attr.attisdropped AND attr.attnum > 0)
martin_1  |     SELECT
martin_1  |       f_table_schema, f_table_name, f_geometry_column, srid, type,
martin_1  |         COALESCE(
martin_1  |           jsonb_object_agg(columns.column_name, columns.type_name) FILTER (WHERE columns.column_name IS NOT NULL),
martin_1  |           '{}'::jsonb
martin_1  |         ) as properties
martin_1  |     FROM geometry_columns
martin_1  |     LEFT JOIN columns ON
martin_1  |       geometry_columns.f_table_schema = columns.table_schema AND
martin_1  |       geometry_columns.f_table_name = columns.table_name AND
martin_1  |       geometry_columns.f_geometry_column != columns.column_name
martin_1  |     GROUP BY f_table_schema, f_table_name, f_geometry_column, srid, type;
martin_1  | [2022-01-11T16:51:57Z DEBUG tokio_postgres::query] executing statement s9 with parameters: []
martin_1  | [2022-01-11T16:51:58Z INFO  martin::table_source] Found "demo.cable" table source with "geom" column (MULTILINESTRING, SRID=3857)
martin_1  | [2022-01-11T16:51:58Z DEBUG tokio_postgres::prepare] preparing query s10: SELECT
martin_1  |       ST_Transform (ST_SetSRID (ST_Extent (geom), 3857), 4326) AS bounds
martin_1  |     FROM
martin_1  |       demo.cable
martin_1  |     
martin_1  | [2022-01-11T16:51:58Z DEBUG tokio_postgres::query] executing statement s10 with parameters: []
martin_1  | [2022-01-11T16:51:58Z INFO  martin::table_source] Found "demo.t_formulaire_1" table source with "geom" column (POINT, SRID=3857)
martin_1  | [2022-01-11T16:51:58Z DEBUG tokio_postgres::prepare] preparing query s11: SELECT
martin_1  |       ST_Transform (ST_SetSRID (ST_Extent (geom), 3857), 4326) AS bounds
martin_1  |     FROM
martin_1  |       demo.t_formulaire_1
martin_1  |     
martin_1  | [2022-01-11T16:51:58Z DEBUG tokio_postgres::query] executing statement s11 with parameters: []
martin_1  | [2022-01-11T16:51:58Z INFO  martin::table_source] Found "demo.t_formulaire_2" table source with "geom" column (POINT, SRID=3857)
martin_1  | [2022-01-11T16:51:58Z DEBUG tokio_postgres::prepare] preparing query s12: SELECT
martin_1  |       ST_Transform (ST_SetSRID (ST_Extent (geom), 3857), 4326) AS bounds
martin_1  |     FROM
martin_1  |       demo.t_formulaire_2
martin_1  |     
martin_1  | [2022-01-11T16:51:58Z DEBUG tokio_postgres::query] executing statement s12 with parameters: []
martin_1  | thread '<unnamed>' panicked at 'error retrieving column bounds: error deserializing column 0: cannot convert geometry to PolygonT', /home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-postgres-0.7.3/src/row.rs:151:25
martin_1  | note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
martin_1  | [2022-01-11T16:51:58Z ERROR martin::server] Mailbox has closed
martin_1  | [2022-01-11T16:51:58Z INFO  actix_web::middleware::logger] 172.18.0.1:64292 "GET /index.json HTTP/1.1" 500 18 "-" "PostmanRuntime/7.28.4" 0.327784

Precisions

The SQL request SELECT ST_Transform (ST_SetSRID (ST_Extent (geom), 3857), 4326) AS bounds FROM demo.t_formulaire_2 returns a Point

If I add another entry in the table, there is no more error.

Thanks in advance

dechristopher commented 2 years ago

Nice fix! Now if only we could get a new release...

nyurik commented 8 months ago

See also #1206