From c434cacd109e52d0d274192c7011b4865de46607 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Thu, 14 Apr 2016 14:52:23 -0400 Subject: [PATCH] adding null cases --- .../expected/40_observatory_utility_test.out | 107 ++++++++++-------- .../test/sql/40_observatory_utility_test.sql | 30 ++++- 2 files changed, 91 insertions(+), 46 deletions(-) diff --git a/src/pg/test/expected/40_observatory_utility_test.out b/src/pg/test/expected/40_observatory_utility_test.out index 9799c7f..9ee815d 100644 --- a/src/pg/test/expected/40_observatory_utility_test.out +++ b/src/pg/test/expected/40_observatory_utility_test.out @@ -1,51 +1,46 @@ SELECT set_config( 'search_path', - current_setting('search_path') || ',cdb_observatory', + current_setting('search_path') || ',cdb_observatory,observatory', false -) WHERE current_setting('search_path') !~ '(^|,)cdb_observatory(,|$)'; - set_config ------------------------------------------- - "$user", public, cartodb,cdb_observatory +) WHERE current_setting('search_path') !~ '(^|,)(cdb_observatory|observatory)(,|$)'; + set_config +------------------------------------------------------ + "$user", public, cartodb,cdb_observatory,observatory (1 row) --- OBS_GeomTable --- get table with known geometry_id --- should give back a table like obs_{hex hash} -SELECT - cdb_observatory.OBS_GeomTable( - CDB_LatLng(40.7128,-74.0059), - '"us.census.tiger".census_tract' - ); +\i test/sql/load_fixtures.sql +SET client_min_messages TO WARNING; +\set ECHO none +Loading obs_table.sql fixture file... +Done. +Loading obs_column.sql fixture file... +Done. +Loading obs_column_table.sql fixture file... +Done. +Loading obs_column_to_column.sql fixture file... +Done. +Loading obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1.sql fixture file... +Done. +Loading obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb.sql fixture file... +Done. +Loading obs_ab038198aaab3f3cb055758638ee4de28ad70146.sql fixture file... +Done. +Loading obs_a92e1111ad3177676471d66bb8036e6d057f271b.sql fixture file... +Done. +Loading obs_11ee8b82c877c073438bc935a91d3dfccef875d1.sql fixture file... +Done. +Loading obs_d34555209878e8c4b37cf0b2b3d072ff129ec470.sql fixture file... +Done. obs_geomtable ---------------------------------------------- obs_a92e1111ad3177676471d66bb8036e6d057f271b (1 row) --- get null for unknown geometry_id --- should give back null -SELECT - cdb_observatory.OBS_GeomTable( - CDB_LatLng(40.7128,-74.0059), - '"us.census.tiger".nonexistant_id' - ); obs_geomtable --------------- (1 row) --- OBS_GetColumnData --- should give back: --- colname | tablename | aggregate --- -----------|-----------------|----------- --- geoid | obs_{hex table} | null --- total_pop | obs_{hex table} | sum -SELECT - (unnest(cdb_observatory.OBS_GetColumnData( - '"us.census.tiger".census_tract', - Array['"us.census.tiger".census_tract_geoid', '"us.census.acs".B01001001'], - '2009 - 2013' - ))).* -ORDER BY 1 ASC; colname | tablename | aggregate -----------+----------------------------------------------+----------- geoid | obs_11ee8b82c877c073438bc935a91d3dfccef875d1 | @@ -55,25 +50,47 @@ ORDER BY 1 ASC; total_pop | obs_ab038198aaab3f3cb055758638ee4de28ad70146 | sum (5 rows) --- OBS_LookupCensusHuman --- should give back: {"\"us.census.acs\".B19083001"} -SELECT - cdb_observatory.OBS_LookupCensusHuman( - Array['gini_index'] - ); + colname | tablename | aggregate +---------+-----------+----------- +(0 rows) + obs_lookupcensushuman --------------------------------- {"\"us.census.acs\".B19083001"} (1 row) --- OBS_BuildSnapshotQuery --- Should give back: SELECT vals[1] As total_pop, vals[2] As male_pop, vals[3] As female_pop, vals[4] As median_age -SELECT - cdb_observatory.OBS_BuildSnapshotQuery( - Array['total_pop','male_pop','female_pop','median_age'] - ); + obs_lookupcensushuman +----------------------- + +(1 row) + obs_buildsnapshotquery ------------------------------------------------------------------------------------------------- SELECT vals[1] As total_pop, vals[2] As male_pop, vals[3] As female_pop, vals[4] As median_age (1 row) + obs_buildsnapshotquery +------------------------------------ + SELECT vals[1] As mandarin_orange +(1 row) + +Dropping obs_table.sql fixture table... +Done. +Dropping obs_column.sql fixture table... +Done. +Dropping obs_column_table.sql fixture table... +Done. +Dropping obs_column_to_column.sql fixture table... +Done. +Dropping obs_85328201013baa14e8e8a4a57a01e6f6fbc5f9b1 fixture table... +Done. +Dropping obs_3e7cc9cfd403b912c57b42d5f9195af9ce2f3cdb fixture table... +Done. +Dropping obs_ab038198aaab3f3cb055758638ee4de28ad70146 fixture table... +Done. +Dropping obs_a92e1111ad3177676471d66bb8036e6d057f271b fixture table... +Done. +Dropping obs_11ee8b82c877c073438bc935a91d3dfccef875d1 fixture table... +Done. +Dropping obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 fixture table... +Done. diff --git a/src/pg/test/sql/40_observatory_utility_test.sql b/src/pg/test/sql/40_observatory_utility_test.sql index e0d49ce..88ad8ba 100644 --- a/src/pg/test/sql/40_observatory_utility_test.sql +++ b/src/pg/test/sql/40_observatory_utility_test.sql @@ -21,9 +21,16 @@ SELECT SELECT cdb_observatory.OBS_GeomTable( CDB_LatLng(40.7128,-74.0059), - '"us.census.tiger".nonexistant_id' + '"us.census.tiger".nonexistant_id' -- not in catalog ); +-- future test: give back nulls when geometry doesn't intersect +-- SELECT +-- cdb_observatory.OBS_GeomTable( +-- CDB_LatLng(0,0), -- should give back null since it's in the ocean? +-- '"us.census.tiger".census_tract' +-- ); + -- OBS_GetColumnData -- should give back: -- colname | tablename | aggregate @@ -38,6 +45,15 @@ SELECT ))).* ORDER BY 1 ASC; +-- should be null-valued +SELECT + (unnest(cdb_observatory.OBS_GetColumnData( + '"us.census.tiger".census_tract', + Array['"us.census.tiger".baloney'], -- entry not in catalog + '2009 - 2013' + ))).* +ORDER BY 1 ASC; + -- OBS_LookupCensusHuman -- should give back: {"\"us.census.acs\".B19083001"} SELECT @@ -45,6 +61,12 @@ SELECT Array['gini_index'] ); +-- should be empty array +SELECT + cdb_observatory.OBS_LookupCensusHuman( + Array['cookies'] + ); + -- OBS_BuildSnapshotQuery -- Should give back: SELECT vals[1] As total_pop, vals[2] As male_pop, vals[3] As female_pop, vals[4] As median_age SELECT @@ -52,4 +74,10 @@ SELECT Array['total_pop','male_pop','female_pop','median_age'] ); +-- should give back: SELECT vals[1] As mandarin_orange +SELECT + cdb_observatory.OBS_BuildSnapshotQuery( + Array['mandarin_orange'] + ); + \i test/sql/drop_fixtures.sql