You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQL date parser should gracefully handle invalid dates #146
Bug description
We ran into this issue over at #144. The date SQL functions to parse dates was throwing an error for invalid dates and causing tiles to not generate.
Repro Steps
The data is now fixed on production, but on staging you should be able to run a query like:
SELECT osm_id from osm_admin_areas where tags->'end_date' = '1917-04-31';
Add some "Invalid date" messaging so we can see that in SQL console
EITHER return a null value (so tiles don't break) or even better salvage as much of the date as we can -- yyyy-mm if the day portion is invalid or just yyyy if the month and day are wrong, and null if all three are somehow invalid (though years if integer can be presumed correct I think).
This would be relevant to isodatetodecimaldate for invalid dates such as:
# SELECT isodatetodecimaldate('1917-04-31');
ERROR: Not a valid date 1917, 4, 31
CONTEXT: PL/pgSQL function isodatetodecimaldate(character varying) line 18 at RAISE
@gregallensworth is the process how these dates get processed documented somewhere? Which script runs first, the SQL or the Python script? Where would approximate dates be handled (e.g. "1950s" or "1950..1960") if we were to implement this?
Activity
danrademacher commentedon Sep 1, 2020
I think this should be a change to paddate over to https://github.com/OpenHistoricalMap/paddate-python
We should have a two-step solution here:
yyyy-mmif the day portion is invalid or justyyyyif the month and day are wrong, andnullif all three are somehow invalid (though years if integer can be presumed correct I think).gregallensworth commentedon Sep 3, 2020
Correction: Dan's link is to a Python libary. SQL functions for PostgreSQL are at https://github.com/OpenHistoricalMap/DateFunctions-plpgsql/blob/master/datefunctions.sql
This would be relevant to
isodatetodecimaldatefor invalid dates such as:hroest commentedon Sep 3, 2020
@gregallensworth is the process how these dates get processed documented somewhere? Which script runs first, the SQL or the Python script? Where would approximate dates be handled (e.g. "1950s" or "1950..1960") if we were to implement this?
OpenHistoricalMap/issues#146 isodatetodecimaldate() optional param to…
gregallensworth commentedon Sep 3, 2020
I have enhanced
isodatetodecimaldate(varchar)now accepts an optional second parameter. See OpenHistoricalMap/DateFunctions-plpgsql#1The optional parameter
trytofixinvaliddefines the handling for invalid dates such as 1917-28-31 or 2020-13-31NULL(default) = an invalid date will raise an exceptionFALSE= an invalid date will return NULLTRUE= try hard to return a number; return the 1st of the month if the month is valid, or the year if even the month is invalidTherefore, you now have a choice of how to handle invalid dates:
FALSE= return nullTRUE= return whatever we candanrademacher commentedon Sep 3, 2020
Great! So I think to get this into production, @geohacker or others at DevSeed would need to both implement the updated function on the tilerservers and add the
trytofixinvalidparam to every instance ofisodatetodecimaldate()in this file, https://github.com/developmentseed/osm-seed/blob/ohm/tiler-server/config/config.toml@hroest I'll file a separate issue on handling uncertain dates and can say more over there. Stand by.
geohacker commentedon Feb 3, 2021
This is now deployed on production, so let's close. Thanks so much @gregallensworth and @danrademacher for your work here.