In vector GPKG with DateTime field Geoserver sees it as a String field
Description
Environment
Running Platform Independent Binary on Debian 64bits using OpenJDK
Attachments
Activity
Jody Garnett March 3, 2020 at 12:58 AM(edited)
Closing this one out:
David and Richard added mappings, and found aggregate functions were not respecting mapping - in part by turning off aggregate functions
Andrea addressed the performance implications - by adding some logic to visitor results so they could determine if a conversion was needed

Richard Duivenvoorde February 21, 2020 at 10:10 AM
See also https://github.com/geotools/geotools/pull/2811
I just added a geopackage ‘model.gpkg’ with several tables and views in it.
To test I would use ‘view3’ (>34000 polygons and a datetime column).
But to test how it ‘detoriates’ the generation of the capabilities it is also a good one because it contains 3 views and tables.

Richard Duivenvoorde January 27, 2020 at 11:59 AM
Adding 2 example datasets for reference.
cloud.gpkg is a dataset with table named ‘grid’ holding polygons, a table named ‘data’ holding a ‘Value' and a ‘Time’ and a ‘Cell’-id which is the polygon id from ‘grid’. There there is the view ‘view’ which joins them together (as in adds the polygons).This cloud.gpkg is not yet adapted to have a DATETIME column in it’s data
effective.gpkg is a dataset in which I created copies of the ‘data’ table by redefining type and filling it with a copy of the data but changing the epoch to a valid iso-datetime string.
For example view3 should work because then time is an isostring.
view4 still has epoch integers.
Note that both dataset are kept rather small. Normal grids have at least 40000 records (but can be a multitude).
@Jukka Rahkonen you are right. But for example QGIS is able to ‘load’ the view from attached cloud.gpkg. Then loaded with the timemanager plugin you can filter on Time (in hours).
Same for view3 from effective.gpkg
By some hardcoding hacking into the gpkg dialect I’m at least able to registre a layer in a way that datetime is recognized as as a time column. But then geoserver is still not able to read the strings/epochs as datetime…
Have to find out where the mapping back is arranged

Jukka Rahkonen January 24, 2020 at 5:53 PM
Spatial views in geopackage are still little bit unclear, see https://github.com/opengeospatial/geopackage/issues/446 and other related tickets. Does Geoserver/Geotools have logic for finding the spatial index from the main table if it is usable, which means that geometry in the view is selected simple as “select geometry from main_table”?

Jukka Rahkonen January 24, 2020 at 3:22 PM
For views, as far as I know, using PRAGMA is the only direct way. Alternatively the client could try to follow the route by finding the CREATE VIEW AS… from sqlite_master.
Even PRAGMA can’t handle thiscreate view viewtest4 as
select CAST(dt as text) dt
from datetimetest;
We try to create a WMS-T (timebased wms) with GeoPackages (Vector) as datastores (actual data are model runs).
But whatever I try, Geoserver never recognizes the DateTime column in the Geopackage as a DateTime column. So when publishing it as a (WMS) layer I'm not able to add a Time-based Dimension to it. Making it impossible to create a WMS-T from it.
To make this reproducible, I created a minimal gpkg in QGIS, setting the datatype of the 'dt' column as DateTime.
Both QGIS and SqliteBrowser show the type as DateTime (see screendump sqlitebrowser.png).
But registring this as datetimetest.gpkg as store and registring it as a layer, you will see geoserver.png showing you dt is a String.
In the real data, the gpkg consists of 2 tables (one with a polygon-grid, and one with time-value data 50 records per grid-cell) and one view which joins these together to a view of 3000000 records).