Skip to content

Commit

Permalink
Processing: Guard registerExportFunctions
Browse files Browse the repository at this point in the history
This ran with empty data which crashed

```
db  | 2024-11-18 16:24:38.343 GMT [2564197] ERROR:  syntax error at or near "," at character 439
db  | 2024-11-18 16:24:38.343 GMT [2564197] STATEMENT:  CREATE FUNCTION public."atlas_export_flatgeobuf_poiclassification"(region Geometry(Polygon))
db  | 	           RETURNS BYTEA
db  | 	           LANGUAGE plpgsql
db  | 	           AS $$
db  | 	           DECLARE
db  | 	            fgb BYTEA;
db  | 	           BEGIN
db  | 	            SELECT ST_AsFlatGeobuf(q, false, 'geom') INTO fgb FROM (
db  | 	              SELECT st_transform(geom, 4326) AS geom,
db  | 	                id,
db  | 	                osm_id,
db  | 	                osm_type::text,
db  | 	                ,
db  |
db  | 	              FROM "poiClassification"
db  | 	              WHERE geom && ST_Transform(region, 3857) AND minzoom > -1
db  | 	            ) q;
db  | 	            RETURN fgb;
db  | 	           END;
db  | 	           $$;
db  | 2024-11-19 09:15:43.994 GMT [2649964] ERROR:  syntax error at or near "," at character 439
```
  • Loading branch information
tordans committed Dec 16, 2024
1 parent ae2cb91 commit 64e5371
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/src/registerSQLFunctions/registerExportFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export async function registerExportFunctions(tables: typeof exportApiIdentifier
const tagKeys = tagKeyQuery.map(({ key }) => `tags->>'${key}' as "${key}"`).join(',')
const metaKeys = metaKeyQuery.map(({ key }) => `meta->>'${key}' as "${key}"`).join(',')

if (!tagKeys || !metaKeys) {
console.error(
'Failed to `registerExportFunctions` because required tagKeys and metaKeys are empty',
{ functionName, tagKeyQuery, metaKeyQuery },
)
}

return geoDataClient.$transaction([
geoDataClient.$executeRawUnsafe(`
DROP FUNCTION IF EXISTS public."${functionName}"(region Geometry(Polygon));
Expand Down

0 comments on commit 64e5371

Please sign in to comment.