CartoDB / observatory-extension

BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

Question about OBS_GetMeta and null values #288

Closed rafatower closed 7 years ago

rafatower commented 7 years ago

We're developing the analysis for the new Observatory API for multiple measures and we have one question: is there any functional difference (or otherwise) between omitting a key in the metadata input object and setting it to null?

Apparently there isn't any, but we'd need confirmation.

E.g:

WITH

  -- Example with area normalization. No denom_id, geom_id, numer_timespan
  meta AS (
    SELECT OBS_GetMeta(
      ST_MakeEnvelope(-4.443970,39.967122,-2.696457,40.673868, 4326),
      $$
      [{
        "numer_id": "es.ine.t12_3",
        "normalization": "area"
      }]
      $$
    ) meta
  ),

  my_dummy_table AS (
    -- a point in Getafe
    SELECT 1 cartodb_id, CDB_LatLng(40.307807,-3.732605) the_geom
  )

SELECT id AS cartodb_id, (data->0->>'value')::Numeric AS pop_first_level_studies_area
FROM OBS_GetData((SELECT ARRAY_AGG((the_geom, cartodb_id)::geomval) FROM my_dummy_table),
                 (SELECT meta FROM meta));

vs

WITH

  -- Same as above but with nulls for denom_id, geom_id and numer_timespan
  meta AS (
    SELECT OBS_GetMeta(
      ST_MakeEnvelope(-4.443970,39.967122,-2.696457,40.673868, 4326),
      $$
      [{
        "numer_id": "es.ine.t12_3",
        "denom_id": null,
        "normalization": "area",
        "geom_id": null,
        "numer_timespan": null
      }]
      $$
    ) meta
  ),

  my_dummy_table AS (
    -- a point in Getafe
    SELECT 1 cartodb_id, CDB_LatLng(40.307807,-3.732605) the_geom
  )

SELECT id AS cartodb_id, (data->0->>'value')::Numeric AS pop_first_level_studies_area
FROM OBS_GetData((SELECT ARRAY_AGG((the_geom, cartodb_id)::geomval) FROM my_dummy_table),
                 (SELECT meta FROM meta));

Thanks!

rafatower commented 7 years ago

PS: both queries yield the same result:

 cartodb_id | pop_first_level_studies_area 
------------+------------------------------
          1 |             1429.44802980152
(1 row)
talos commented 7 years ago

@rafatower That is correct -- leaving a key out and passing in NULL are functionally identical.

rafatower commented 7 years ago

thanks a lot!