From d5e47e39ab76ca77765466e4b9858526d4ae3e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Tue, 26 Jun 2018 13:59:44 +0200 Subject: [PATCH] Revert bulk geocoding column parameters order and test_city_column_geocoding --- client/cdb_dataservices_client--0.25.0.sql | 2 +- client/sql/21_bulk_geocoding_functions.sql | 2 +- test/integration/test_street_functions.py | 27 ++++++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/client/cdb_dataservices_client--0.25.0.sql b/client/cdb_dataservices_client--0.25.0.sql index f1346e9..6900c64 100644 --- a/client/cdb_dataservices_client--0.25.0.sql +++ b/client/cdb_dataservices_client--0.25.0.sql @@ -1987,7 +1987,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_DisconnectUserTable( TARGET cdb_dataservices_server._DST_DisconnectUserTable; $$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text, - country_column text, state_column text, city_column text, street_column text, batch_size integer DEFAULT 100) + street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT 100) RETURNS SETOF cdb_dataservices_client.geocoding AS $$ DECLARE query_row_count integer; diff --git a/client/sql/21_bulk_geocoding_functions.sql b/client/sql/21_bulk_geocoding_functions.sql index a733245..b3ff689 100644 --- a/client/sql/21_bulk_geocoding_functions.sql +++ b/client/sql/21_bulk_geocoding_functions.sql @@ -1,5 +1,5 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text, - country_column text, state_column text, city_column text, street_column text, batch_size integer DEFAULT 100) + street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT 100) RETURNS SETOF cdb_dataservices_client.geocoding AS $$ DECLARE query_row_count integer; diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index 180cc70..3694468 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -51,7 +51,7 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp): "select 2 as cartodb_id, ''Spain'' as country, " \ "''Castilla y León'' as state, ''Valladolid'' as city, " \ "''Paseo Zorrilla'' as street' " \ - ", 'country', 'state', 'city', 'street')" + ", 'street', 'city', 'state', 'country')" response = self._run_authenticated(query) assert_equal(response['total_rows'], 2) @@ -66,7 +66,7 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp): "'select * from jsonb_to_recordset(''[" \ "{\"cartodb_id\": 1, \"address\": \"1901 amphitheatre parkway, mountain view, ca, us\"}" \ "]''::jsonb) as (cartodb_id integer, address text)', " \ - "'''''', '''''', '''''', 'address')" + "'address', '''''', '''''', '''''')" response = self._run_authenticated(query) assert_equal(response['total_rows'], 1) @@ -80,7 +80,7 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp): "'select * from jsonb_to_recordset(''[" \ "{\"cartodb_id\": 1, \"address\": \"1901 amphitheatre parkway, mountain view, ca, us\"}" \ "]''::jsonb) as (cartodb_id integer, address text)', " \ - "null, null, null, 'address')" + "'address')" response = self._run_authenticated(query) assert_equal(response['total_rows'], 1) @@ -96,9 +96,8 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp): "{\"cartodb_id\": 2, \"address\": \"1901 amphitheatre parkway, mountain view, ca, us\"}," \ "{\"cartodb_id\": 3, \"address\": \"1902 amphitheatre parkway, mountain view, ca, us\"}" \ "]''::jsonb) as (cartodb_id integer, address text)', " \ - "null, null, null, 'address', 2)" + "'address', null, null, null, 2)" response = self._run_authenticated(query) - # from nose.tools import set_trace; set_trace() assert_equal(response['total_rows'], 3) @@ -108,6 +107,24 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp): self._assert_x_y(row_by_cartodb_id[3], -122.0876674, 37.4235729) + def test_city_column_geocoding(self): + query = "select *, st_x(the_geom), st_y(the_geom) " \ + "FROM cdb_dataservices_client.cdb_bulk_geocode_street_point( " \ + "'select * from jsonb_to_recordset(''[" \ + "{\"cartodb_id\": 1, \"city\": \"Valladolid\"}," \ + "{\"cartodb_id\": 2, \"city\": \"Madrid\"}" \ + "]''::jsonb) as (cartodb_id integer, city text)', " \ + "'city')" + response = self._run_authenticated(query) + # from nose.tools import set_trace; set_trace() + + assert_equal(response['total_rows'], 2) + + row_by_cartodb_id = self._row_by_cartodb_id(response) + self._assert_x_y(row_by_cartodb_id[1], -4.7245321, 41.652251) + self._assert_x_y(row_by_cartodb_id[2], -3.7037902, 40.4167754) + + def _run_authenticated(self, query): authenticated_query = "{}&api_key={}".format(query, self.env_variables[