Compare commits

...

543 Commits

Author SHA1 Message Date
Moisés Calzado
6815399155 Merge pull request #629 from CartoDB/development 2022-09-05 13:27:00 +02:00
Moisés Calzado
94512eea59 Merge pull request #628 from CartoDB/bug/sc-254346/opianalytics-here-isolines-returning-null 2022-09-05 13:24:52 +02:00
Moisés Calzado
6ce052072c Add changes for new server release 2022-09-05 13:23:56 +02:00
Moisés Calzado
27d3df3607 Merge branch 'bug/sc-254346/opianalytics-here-isolines-returning-null' of github.com:CartoDB/dataservices-api into bug/sc-254346/opianalytics-here-isolines-returning-null 2022-09-02 11:42:27 +02:00
Moisés Calzado
86c10f0ca5 Bump version 2022-09-02 11:42:16 +02:00
Alberto Hernández
9ff4e25603 Merge branch 'development' into bug/sc-254346/opianalytics-here-isolines-returning-null 2022-09-01 16:20:27 +02:00
alberhander
063cac1b65 try fix CI 2022-09-01 16:15:30 +02:00
Alberto Hernández
2819382dd0 fixing CI 2022-09-01 15:38:01 +02:00
Alberto Hernández
10a34da232 trying to fix action 2022-09-01 15:31:46 +02:00
Alberto Hernández
8caa735262 fix action 2022-09-01 15:27:28 +02:00
Moisés Calzado
c7ed86072b Fix parameter for new HERE Isolines API 2022-09-01 13:30:08 +02:00
Manuel López Ruiz
a65cfb2fd2 Merge pull request #625 from CartoDB/fix/ch175898/gcp-github-actions
fixed gcloud github actions setup
2022-03-30 18:04:42 +02:00
Manuel López Ruiz
a8e9476dad Merge branch 'development' into fix/ch175898/gcp-github-actions 2022-03-30 18:04:23 +02:00
Manuel López Ruiz
ef289214e7 Merge pull request #626 from CartoDB/chore/sc-219063/Z8YDB2NR
Fix deprecation notice GHAction
2022-03-30 17:52:01 +02:00
Manuel López Ruiz
2117afc336 Merge pull request #627 from CartoDB/chore/sc-219063/0EDAHT1N
Fix deprecation notice GHAction
2022-03-30 17:51:31 +02:00
Manuel López Ruiz
6a93a2e881 Changes applyed to Z8YDB2NR 2022-03-30 17:50:08 +02:00
Manuel López Ruiz
52fb8b0875 Changes applyed to 0EDAHT1N 2022-03-30 17:50:08 +02:00
Manuel López Ruiz
e2c79c5ae0 Merge remote-tracking branch 'origin/master' into chore/sc-219063/Z8YDB2NR 2022-03-30 17:50:08 +02:00
Manuel López Ruiz
1794039c6b Changes applyed to 4STN0GNB 2022-03-30 17:50:07 +02:00
Miguel Angel Moreno
d8b00307cd Revert "UPgrade pip"
This reverts commit 1925bb6082.
2022-03-07 16:53:12 +01:00
Miguel Angel Moreno
1925bb6082 UPgrade pip 2022-03-07 16:49:11 +01:00
Miguel Angel Moreno
5fe4263583 Merge branch 'master' of github.com:CartoDB/dataservices-api into fix/ch175898/gcp-github-actions 2022-03-07 16:33:36 +01:00
Manuel López Ruiz
24b17128fc Delete gcloud from CI [ch-198662] 2021-12-21 10:48:16 +01:00
alvarorm22
de33fec79f fixed gcloud github actions setup 2021-08-27 11:55:53 +02:00
Miguel Moncada Isla
3b9bfb7b67 Merge pull request #624 from CartoDB/development
Add Support for new HERE api keys
2021-05-26 11:26:31 +02:00
Miguel Moncada Isla
d0f28cc002 Merge pull request #623 from CartoDB/feature/ch115970/update_news
Update news for support new here api keys feature
2021-05-26 11:20:26 +02:00
Miguel
6a4ed61dab Update news for support new here api keys feature 2021-05-26 11:13:50 +02:00
Miguel Moncada Isla
7862e70bab Merge pull request #622 from CartoDB/feature/ch115970/support-new-here-api-keys
Feature/ch115970/support new here api keys
2021-05-26 10:36:39 +02:00
Miguel
20bdbbd934 Add CR suggestions 2021-05-25 13:46:39 +02:00
Miguel
d305443c82 Fix editor spaces tabs mix 2021-05-24 14:09:15 +02:00
Miguel
6dd18c40a8 Fix HERE GS7 metadata precision 2021-05-24 14:05:46 +02:00
Mmoncadaisla
46809cd760 Revert parameter positions for serial geocoders 2021-05-18 21:11:31 +02:00
Mmoncadaisla
81d3364e0b Include reference to set apikey and use_apikey params with CDB_SetConf 2021-05-18 18:32:27 +02:00
Mmoncadaisla
a16f00966e Do not set routingmode if transportmode value is equivalent to 'walk' mode for HERE Isolines v8.4 2021-05-18 15:14:37 +02:00
Mmoncadaisla
f32d37f312 Add config parameters apikey and use_apikey for geocoder and isoline services (HERE) 2021-05-17 18:07:36 +02:00
Mmoncadaisla
55b2c63c3e Add release files in extension and update cartodb_services python version 2021-05-17 17:03:30 +02:00
Mmoncadaisla
b037bc139c Update heremaps conf parameter names in SQL function calls (geocoder) 2021-05-17 16:43:27 +02:00
Mmoncadaisla
6762665d0d Update Isolines SQL function for V8.4 HERE API Support 2021-05-17 15:11:25 +02:00
Mmoncadaisla
fb57645595 Update bulk geocoder SQL function for GS7 support (serial) and 6.2 apikey support 2021-05-17 15:11:04 +02:00
Mmoncadaisla
d38c894d1b Update serial geocoder SQL function for GS7 support 2021-05-17 15:09:56 +02:00
Mmoncadaisla
216d64fdc6 Include flexpolyline dependency (HERE Routing API v8) 2021-05-17 13:47:09 +02:00
Mmoncadaisla
e21d850679 Parse tuple point response (v8) and minor fix in HereMapsRoutingIsolineV8 options parameter 2021-05-17 13:25:54 +02:00
Mmoncadaisla
8e6da0b6fa Minor comment removal 2021-05-17 13:23:15 +02:00
Mmoncadaisla
f59919efef Add new imports for apikey parameter support 2021-05-13 09:40:53 +02:00
Mmoncadaisla
4cc819e76c Add service factory module to return appropiate service version 2021-05-13 09:40:07 +02:00
Mmoncadaisla
9240a7ab71 Add HERE API V8 Routing Isolines support (draft) 2021-05-13 09:38:50 +02:00
Mmoncadaisla
fb8ffe8c3c Add adapted bulk geocoder for apikey usage 2021-05-13 09:37:42 +02:00
Mmoncadaisla
4b7a62d094 Add HERE API GS7 geocoder 2021-05-13 09:37:04 +02:00
Jesús Arroyo Torrens
aad5044a1f Merge pull request #621 from CartoDB/development
Update master branch
2021-03-31 16:49:02 +02:00
Jesús Arroyo Torrens
07de81397c Merge pull request #620 from CartoDB/bugfix/server-quota-info
Fix server quota_info function
2021-03-31 16:46:30 +02:00
Jesús Arroyo Torrens
f12e25117e Fix ALTER TYPE for multi-command string 2021-03-31 15:58:30 +02:00
Jesús Arroyo Torrens
d4dc60783e Add missing drop types 2021-03-31 15:34:57 +02:00
Jesús Arroyo Torrens
40683e435a Fix server quota_info function 2021-03-31 15:07:00 +02:00
Jesús Arroyo Torrens
695aafd53c Merge pull request #619 from CartoDB/development
Remove Data Observatory v1
2021-03-31 07:38:18 +02:00
Jesús Arroyo Torrens
8eed8ac132 Merge pull request #618 from CartoDB/chore/ch111328/remove-do-v1-api
🔥 Data Observatory
2021-03-30 18:58:49 +02:00
Jesús Arroyo Torrens
ca24563a80 Fix server script 2021-03-30 17:58:17 +02:00
Jesús Arroyo Torrens
05f7b237eb Bump version numbers 2021-03-09 09:09:56 +01:00
Jesús Arroyo Torrens
df8a5492db Add client version-change scripts 2021-03-09 09:05:36 +01:00
Jesús Arroyo Torrens
da87c645a2 Fix tests 2021-03-05 17:32:50 +01:00
Jesús Arroyo Torrens
4acf5f9eef Create client release 0.30.1 2021-03-05 17:12:34 +01:00
Jesús Arroyo Torrens
aac1efaeac Add version-change scripts 2021-03-05 16:52:29 +01:00
Jesús Arroyo Torrens
855bb736eb Fix geocodio tests 2021-03-05 15:14:19 +01:00
Jesús Arroyo Torrens
f98ee6750d Remake extension 2021-03-05 10:49:03 +01:00
Jesús Arroyo Torrens
edbefad6b0 Remove DO Python code and SQL tests 2021-03-05 10:44:09 +01:00
Jesús Arroyo Torrens
610398f531 Remove DO v1 docs 2021-03-05 09:57:19 +01:00
Jesús Arroyo Torrens
e2bddb5139 Create server release 0.39.4 2021-03-03 16:32:07 +01:00
Jesús Arroyo Torrens
f4d8ebab44 Remove Data Observatory functions 2021-03-03 16:22:38 +01:00
Shylpx
2b98908dbc Merge pull request #617 from CartoDB/feature/ch135234/bain-routing-public-transport-parameter
[ch135234] Remove 'public_transport' mode from routing documentation
2021-03-01 11:47:43 +00:00
cgonzalez
475868dd52 Remove 'public_transport' mode from routing doc 2021-02-17 13:18:39 +00:00
Shylpx
b4b545019b Merge pull request #616 from CartoDB/development
Preparing release (server 0.39.3 python 0.23.5)
2021-02-08 10:49:17 +00:00
Shylpx
cda887e6d4 Merge pull request #614 from CartoDB/bug/ch127801/fix-countryset-for-tomtom-geocoding
[ch127801] Country conversion to ISO code in TomTom bulk geocoding
2021-02-08 09:53:57 +00:00
cgonzalez
66b9563a4b Prepare server extension version 0.39.3 2021-01-27 14:27:46 +00:00
cgonzalez
4278f66372 Refactor country conversion for TomTom geocoders 2021-01-27 10:50:33 +00:00
cgonzalez
f995f2d6ec Bump python version and update 'NEWS.md' 2021-01-26 16:37:31 +00:00
cgonzalez
253e0c9c18 Country conversion to ISO code in TomTom bulk geocoding 2021-01-26 12:09:34 +00:00
Raúl Marín
d3720d6953 Merge pull request #612 from CartoDB/master
Update development from master
2020-11-19 11:20:05 +01:00
Raúl Marín
7d1cbb34b3 Release server 0.39.2 and python 0.23.4 2020-11-19 11:12:11 +01:00
Raúl Marín
251daae4aa Merge pull request #611 from CartoDB/development
Preparing release (server 0.39.2 python 0.23.4)
2020-11-19 11:10:28 +01:00
Raúl Marín
f72dabd0a9 Merge pull request #610 from CartoDB/ch102254
HERE Bulk geocoder: Read all responses
2020-11-19 10:03:42 +01:00
Raúl Marín
91da597bac Update NEWS 2020-11-18 16:28:14 +01:00
Raúl Marín
d175e4294d Here bulk geocoder: Read also errors and no matches 2020-11-18 16:26:07 +01:00
Raúl Marín
b432478b6d Merge pull request #609 from CartoDB/ch119936
Improve error reporting
2020-11-18 12:00:17 +01:00
Raúl Marín
953beedd0a GH actions: Change set-env 2020-11-17 18:05:44 +01:00
Raúl Marín
b1448ce27b Add new releases 2020-11-17 18:05:43 +01:00
Raúl Marín
314e709f3b Server: Better error handling and provide error details 2020-11-17 18:05:43 +01:00
Antonio Carlón
9883226d4a Merge pull request #606 from CartoDB/development
Small changes to doc + HERE isolines analysis-failing
2020-10-22 07:57:11 +02:00
Antonio Carlón
151d8f01e4 Merge pull request #607 from CartoDB/doc-text-update
Text update
2020-10-20 10:10:12 +02:00
antoniocarlon
631d44f44e Forcing botocore 1.18.18 2020-10-20 09:41:12 +02:00
Alberto Acuña
a2c8cbe8cc Fixes typo 2020-10-20 09:17:42 +02:00
Alberto Acuña
538e02fe4a Fixes typo 2020-10-20 09:17:14 +02:00
Alberto Acuña
b6b98f6ef0 Text update 2020-10-19 17:33:54 +02:00
Antonio Carlón
9cc874c142 Merge pull request #605 from CartoDB/feature/ch108211/dov1-deprecation-actions-in-developer-center
Updated documentation
2020-10-19 13:41:43 +02:00
alberto
f5d6b64482 Updated documentation 2020-10-19 13:30:17 +02:00
Juan Ramón
ce27c2da0a Merge pull request #604 from CartoDB/bug/ch103251/kyle-se-here-isolines-analysis-fails-due
bug/ch103251/kyle-se-here-isolines-analysis-fails-due
2020-10-05 15:43:51 +02:00
juanrmn
933bf62bee news.md 2020-10-05 15:32:57 +02:00
juanrmn
792152a968 upgrade/downgrade code 2020-10-05 11:44:40 +02:00
juanrmn
ef4192a2ae allow isolines services for google-geocoding users 2020-10-05 11:10:38 +02:00
Antonio Carlón
eca8d1b428 Merge pull request #603 from CartoDB/development
Change HERE batch URL
2020-09-23 12:06:26 +02:00
Antonio Carlón
e1e85e2391 Merge pull request #602 from CartoDB/antoniocarlon/null/bump_version
Bump Python library version
2020-09-23 11:43:54 +02:00
antoniocarlon
0f8e946461 Bump Python library version 2020-09-23 11:33:47 +02:00
Antonio Carlón
ad8a40129a Merge pull request #600 from CartoDB/bug/ch102254/ibicarto1-issues-when-geocoding-through-cartoframes
Change HERE batch endpoint
2020-09-23 11:24:34 +02:00
antoniocarlon
f2dcd4453c Merge branch 'development' into bug/ch102254/ibicarto1-issues-when-geocoding-through-cartoframes 2020-09-23 11:15:45 +02:00
Antonio Carlón
48c3718235 Merge pull request #601 from CartoDB/antoniocarlon/null/Fix_tests
Fix broken tests
2020-09-23 11:15:13 +02:00
antoniocarlon
2a1d751cf5 Change city for geocoding 2020-09-23 10:57:15 +02:00
antoniocarlon
7f87fc2e25 Define CLOUDSDK_PYTHON environment variable 2020-09-23 10:16:46 +02:00
antoniocarlon
b793c02415 hardcode GCP version 2020-09-23 09:56:28 +02:00
antoniocarlon
95bd089366 hardcode GCP version 2020-09-23 09:46:06 +02:00
antoniocarlon
dbb7248f67 hardcode GCP version 2020-09-23 09:44:04 +02:00
antoniocarlon
d527b10f22 Define CLOUDSDK_PYTHON environment variable 2020-09-23 09:18:30 +02:00
antoniocarlon
37d72b333a Change HERE batch endpoint 2020-09-23 08:18:20 +02:00
Raúl Marín
40146c5eff Merge pull request #597 from CartoDB/development
Client 0.30.0, Server 0.39.0 -> master
2020-04-13 11:29:49 +02:00
Raúl Marín
87d9ceec0a Merge pull request #596 from CartoDB/test_postgis_raster
PG12: Fallback to postgis_raster in Postgis 3.0
2020-04-08 13:42:59 +02:00
Raúl Marín
4dc2104f93 Server: Release 0.39.0 2020-04-07 12:35:21 +02:00
Raúl Marín
89b445b99d Client: Release 0.30.0 2020-04-07 12:27:54 +02:00
Raúl Marín
ef7c158e4b Server: Simplify PG12/Postgis 3 interaction 2020-04-07 12:12:05 +02:00
Raúl Marín
4b6c5a23db Client: Simplify PG12/Postgis 3 interaction 2020-04-07 12:11:46 +02:00
Raúl Marín
d0557049c0 CI: Fix diff printing on regress errors 2020-04-07 12:10:01 +02:00
Raúl Marín
e6d3cdab12 CI: Disable fail-fast 2020-04-07 12:09:47 +02:00
Antonio Carlón
f68f997eb7 Merge pull request #595 from CartoDB/development
Fix origin/destination in isolines
2020-03-27 09:13:29 +01:00
Antonio Carlón
4d231c1db0 Merge pull request #594 from CartoDB/Fix_here_is_destination_param
Fixing is_destination for HERE isolines
2020-03-27 08:11:37 +01:00
antoniocarlon
a1fdaacb4c Fixed spacing 2020-03-18 12:14:16 +01:00
antoniocarlon
09e24e13d3 Fixing is_destination for HERE isolines 2020-03-18 12:09:12 +01:00
Manuel J. Morillo
1a2d8e865c Merge pull request #592 from CartoDB/development
Deploy client `0.29.0` and server `0.38.0` to prod
2020-03-18 10:13:19 +01:00
Manuel J. Morillo
a2790c90d9 Merge pull request #593 from CartoDB/code_review_592
CODE REVIEW for client 0.29.0 and server 0.38.0
2020-03-18 09:40:13 +01:00
manmorjim
083b634ea7 Update NEWS 2020-03-17 11:53:21 +01:00
manmorjim
36f271751b Update dependencies to fix vulnerabilities 2020-03-17 11:51:31 +01:00
manmorjim
2d78caeef2 Migration scripts for server 2020-03-17 11:27:10 +01:00
manmorjim
24df64681d Migration scripts for client 2020-03-17 11:20:47 +01:00
manmorjim
b7c9ff8dac Remove @@plpythonu@@ vars from old_versions 2020-03-17 09:49:54 +01:00
Manuel J. Morillo
f4df0a5f7c Merge pull request #591 from CartoDB/deploy_0.29.0client_0.38.0server
Update NEWS with the release (deploy) date
2020-03-13 10:46:36 +01:00
manmorjim
1daa5b1451 Update NEWS with the release (deploy) date 2020-03-13 10:41:26 +01:00
Manuel J. Morillo
f075a9416b Merge pull request #590 from CartoDB/fix_client_vars_replacement
Fixes client release 0.29.0
2020-03-11 11:01:06 +01:00
Manuel J. Morillo
201ab42665 Keep 0.38.0 version 2020-03-10 17:24:17 +01:00
manmorjim
c793293fae Changes from 'development' 2020-03-10 17:21:54 +01:00
manmorjim
40d1b4eafd Update dependencies 2020-03-10 17:19:46 +01:00
manmorjim
0a902d7f00 Replace @@plpythonu@@ vars 2020-03-10 17:19:19 +01:00
manmorjim
9b95682243 Add @@plpythonu@@ vars into old_versions 2020-03-10 17:18:55 +01:00
Manuel J. Morillo
e77038ce2f Merge pull request #589 from CartoDB/fix_release_0.38
Fix server release 0.38.0
2020-03-10 16:51:11 +01:00
manmorjim
8f720e8165 Update dependencies 2020-03-10 15:45:31 +01:00
manmorjim
da9948cba3 Fix release 0.38.0
Replace `@@plpythonu@@` vars in old_versions
2020-03-10 15:45:04 +01:00
manmorjim
35ff75ea64 Replace @@plpythonu@@ vars in old_versions 2020-03-09 13:02:26 +01:00
Manuel J. Morillo
18459fb906 Merge pull request #588 from CartoDB/fix_release_0.29
Fix release 0.29.0
2020-03-09 11:50:44 +01:00
manmorjim
796ba4a15e Files for the release 0.29.0 2020-03-09 11:15:23 +01:00
manmorjim
63e5379016 restore 0.28.0 files 2020-03-09 11:09:58 +01:00
manmorjim
ee837e0e5f release 0.29.0 2020-03-06 17:57:32 +01:00
manmorjim
c6e5711905 Replace @@plpythonu@@ var in old_versions 2020-03-06 17:57:02 +01:00
Daniel G. Aubert
10a62cc3c5 Merge pull request #587 from CartoDB/development
python-0.23.1 deploy to production
2020-03-06 16:31:56 +01:00
Daniel G. Aubert
021469c825 Merge pull request #586 from CartoDB/release-python-0.23.1
Release python 0.23.1
2020-03-06 11:42:02 +01:00
Daniel García Aubert
84bdd8a828 Update NEWS 2020-03-06 10:49:37 +01:00
Daniel García Aubert
67fa730436 Bump python library to version 0.23.1 2020-03-06 10:43:39 +01:00
Daniel G. Aubert
151c768894 Merge pull request #583 from CartoDB/tomtom_bulk_qps_retry
add qps_retry to tomtom bulk API calls
2020-03-06 10:29:34 +01:00
Daniel García Aubert
3560c07d7f Merge branch 'development' into tomtom_bulk_qps_retry 2020-03-05 10:47:01 +01:00
Manuel J. Morillo
18816f2bfb Merge pull request #584 from CartoDB/pg12_migration
[PG12] Adapt project to PostgreSQL 12 and PostGIS 3
2020-03-05 10:34:35 +01:00
manmorjim
e99d88500a Use authenticated query for geocoding 2020-03-02 15:27:32 +01:00
manmorjim
2664095e21 Update tolerance and fixture values 2020-03-02 15:26:59 +01:00
manmorjim
5bb0e67499 Add method parameter to requests
It allows using POST for large URI to prevent errors `414 Request-URI Too Large`
2020-03-02 15:24:56 +01:00
manmorjim
e3e037563b Deconding the tests output 2020-03-02 15:21:32 +01:00
manmorjim
944bc8c3ff Create the type geomval in the extension schema
Having it as public.geomval means that we would block ourselves from installing `postgis_raster` if this extension is installed.
2020-03-02 09:09:10 +01:00
manmorjim
e97d350e5a Decode redis responses by default
In python3 redis responses are encoded by default.
2020-02-27 17:20:10 +01:00
manmorjim
880f756eae Add the extension schema to the SEARCH_PATH 2020-02-27 16:06:30 +01:00
manmorjim
0164b07b92 Install always python lib in python2 for unit tests 2020-02-27 10:46:06 +01:00
manmorjim
4a880805cc Fix conditional CI 2020-02-27 10:19:13 +01:00
manmorjim
5370ea23c7 Conditional jobs dependint on PG version 2020-02-27 10:14:42 +01:00
Alberto Romeu
f1cd40f7e7 add qps_retry to tomtom bulk API calls 2020-02-26 19:52:56 +01:00
manmorjim
7aefba181c Install packages in python3 using pip3 2020-02-26 18:52:26 +01:00
manmorjim
35f098686c Force non-zero exit if tests failed 2020-02-26 17:39:35 +01:00
manmorjim
8a3f28c45b Rename output test directory 2020-02-26 17:32:59 +01:00
manmorjim
53a0e7abf3 Show errors if tests failed 2020-02-26 17:32:08 +01:00
manmorjim
3c916bdfc9 Adapt dataservices-api server to python3
Related to https://github.com/CartoDB/cartodb-platform/issues/6237
2020-02-26 15:49:15 +01:00
manmorjim
b2a06c6ed6 Create the type geomval if not exist
Related to https://github.com/CartoDB/cartodb-platform/issues/6237
2020-02-26 15:42:10 +01:00
manmorjim
d5b0d86997 Add variable @@plpythonu@@
Related with https://github.com/CartoDB/cartodb-platform/issues/6237
2020-02-26 15:41:04 +01:00
manmorjim
fa2bed0df5 Add details about what the rule does 2020-02-26 15:38:43 +01:00
ibrahim menem
d920d72b0b remove integration tests from github actions (#581) 2020-02-26 13:17:56 +01:00
ibrahim
495f2425bc add integration tests to ci 2020-02-25 15:55:39 +01:00
manmorjim
6a34f5d6cb Release 0.29.0 2020-02-24 16:14:29 +01:00
manmorjim
e08ca8f6bc Creates the type geomval if does not exist
PG12 migration #6237
2020-02-24 16:13:48 +01:00
manmorjim
dd907ac2bc Using @@plpythonu@@ variable
PG12 migration #6237
2020-02-24 16:12:27 +01:00
Antonio Carlón
0268b67d0c Merge pull request #578 from CartoDB/development
Added Mapbox true isolines
2020-02-12 12:56:37 +01:00
antoniocarlon
a90391aeef Updated NEWS.md 2020-02-12 11:32:15 +01:00
Antonio Carlón
426800df63 Merge pull request #572 from CartoDB/Add_Mapbox_true_isochrones
[leapfrog] First implementation of the true Mapbox isochrones
2020-02-12 11:26:15 +01:00
Antonio Carlón
3ca6133a9e Merge pull request #577 from CartoDB/Mapbox_iso_autogenerated_files
Added autogenerated files
2020-02-12 11:21:54 +01:00
antoniocarlon
f39e3551a0 Merge branch 'Add_Mapbox_true_isochrones' into Mapbox_iso_autogenerated_files 2020-02-11 15:51:17 +01:00
antoniocarlon
6b50d004bd Fix error 2020-02-11 15:45:04 +01:00
antoniocarlon
6081613220 Added autogenerated files 2020-02-11 15:29:35 +01:00
antoniocarlon
ef5b82450a Avoid renaming the matrix parameter to isolines 2020-02-11 15:25:12 +01:00
antoniocarlon
ab71acd461 Removed generated files to ease review 2020-02-11 14:08:19 +01:00
antoniocarlon
34e715f460 Deleted old mapbox isolines implementation (server extension) 2020-02-11 10:01:37 +01:00
antoniocarlon
822c574b5c Deleted old mapbox isolines implementation 2020-02-11 10:00:27 +01:00
antoniocarlon
484a05dbd9 Deleted new client version 2020-02-11 09:58:04 +01:00
antoniocarlon
62cbed7f17 Fixed speed 2020-02-10 16:56:17 +01:00
antoniocarlon
02d705465c Removed unneeded message 2020-02-10 15:45:51 +01:00
antoniocarlon
e696fa2d39 Add test to validate time ranges 2020-02-10 13:18:45 +01:00
antoniocarlon
d5efc681e4 Validate time ranges 2020-02-10 13:18:24 +01:00
antoniocarlon
cd366d7589 Extracting correct coordinates 2020-02-10 13:07:21 +01:00
antoniocarlon
80c1433bbd Fix error 2020-02-10 11:51:13 +01:00
antoniocarlon
8f823a5fae Fixed error 2020-02-10 10:27:11 +01:00
antoniocarlon
3eb36f99bb Added mapbox_iso isolines provider to config 2020-02-10 10:13:42 +01:00
antoniocarlon
8c3b10a061 Client extension changes 2020-02-07 16:24:04 +01:00
antoniocarlon
3b5f33503b Server extension changes 2020-02-07 15:52:31 +01:00
antoniocarlon
a171d91204 Merge development 2020-02-07 14:05:41 +01:00
ibrahim menem
efca8e7c9d update github actions workflow to include pg12 (#576)
* update github actions workflow to include pg12

* Pass PG_VERSION env correctly
2020-02-04 18:11:34 +01:00
Rafa de la Torre
b35e67f65a Merge pull request #575 from CartoDB/add-github-actions
add CI tests to github actions
2020-01-30 16:32:45 +01:00
ibrahim
04e81584d1 add CI tests to github actions 2020-01-30 15:50:49 +01:00
jvillarf
9e57df371a Update README.md 2020-01-21 09:00:20 +01:00
Antonio Carlón
b845717077 Merge pull request #574 from CartoDB/development
Add geocodio geocoder
2020-01-20 13:01:28 +01:00
antoniocarlon
9955b3b8ff Updated NEWS.md 2020-01-20 12:56:40 +01:00
Antonio Carlón
89dff1244f Merge pull request #571 from CartoDB/antoniocarlon/568/Add_geocodio_geocoder
Add Geocodio geocoder
2020-01-20 12:53:15 +01:00
antoniocarlon
b495fcfef3 Add geocodio geocoder to tests 2020-01-20 11:20:36 +01:00
antoniocarlon
a2f0ee01a2 Add geocodio geocoder to tests 2020-01-20 11:16:57 +01:00
antoniocarlon
0c23cc4f4f Modification to trigger the CI 2020-01-20 11:07:00 +01:00
antoniocarlon
2a68291da7 First implementation of the true Mapbox isochrones 2020-01-17 17:04:43 +01:00
antoniocarlon
861bef0382 Fixed badly generated client scripts 2020-01-15 17:40:36 +01:00
antoniocarlon
9b9f032d30 Fixed geocoding with components 2020-01-15 14:48:31 +01:00
antoniocarlon
620b02c259 Added geocodio config to the README file 2020-01-14 15:04:47 +01:00
antoniocarlon
9558df2095 Client extension sql files 2020-01-14 13:34:02 +01:00
antoniocarlon
b5d3c5fd8e Server extension sql files 2020-01-14 13:33:33 +01:00
antoniocarlon
42c9d21475 Extensions 2020-01-14 13:27:16 +01:00
antoniocarlon
1e0a8fae06 Added geocodio geocoder to the Python library 2020-01-14 13:25:44 +01:00
antoniocarlon
7a08cdf096 Old versions 2020-01-14 13:23:22 +01:00
jvillarf
509e56468b Merge pull request #565 from CartoDB/development
Updating carto-package for Onpremises 4.0.0
2019-11-13 10:00:01 +01:00
jvillarf
d2be601049 Merge pull request #564 from CartoDB/onpremises_4_0_0_update_carto_package
Updating carto-package
2019-11-12 12:55:39 +01:00
Javier Villar
7335bacc00 Removing server extension dependency temporarily 2019-11-12 12:32:33 +01:00
Javier Villar
f0070e6158 Updating carto-package 2019-11-12 11:52:40 +01:00
Raul Marin
4684eac410 Merge branch 'development' into blessed/master 2019-10-10 13:03:31 +02:00
Raúl Marín
48748b479e Merge pull request #559 from CartoDB/client_0270
Release client extension 0.27.0
2019-10-09 13:54:47 +02:00
Raul Marin
346db43968 Release client extension 0.27.0 2019-10-09 12:57:27 +02:00
Raúl Marín
0bca39c6a8 Merge pull request #558 from CartoDB/sec
Set safe path
2019-10-08 12:32:17 +02:00
Raul Marin
a30ba351cf Qualify extension calls 2019-10-08 11:47:00 +02:00
Raul Marin
33b723fa3d Set safe path 2019-10-08 11:19:09 +02:00
Raúl Marín
80ab38a0c9 Merge pull request #557 from CartoDB/dev_pg11
Fix CI
2019-10-08 11:16:15 +02:00
Raul Marin
5ab5e8ddf9 Fix CI 2019-10-07 18:16:33 +02:00
Raúl Marín
ced23bbe93 Merge pull request #555 from CartoDB/pg11_test
Fix CI
2019-10-07 18:12:00 +02:00
Raul Marin
8b0ec7b6f5 Fix CI 2019-10-07 18:09:37 +02:00
Javier Torres
f1bfc70e6e Merge pull request #553 from CartoDB/531-document-batch-geocoding
TomTom as default LDS provider and reference documentation for cdb_bulk_geocode_street_point
2019-03-25 13:31:12 +01:00
Daniel Carrión
9e6da8908c TomTom as default LDS provider instead of Mapbox 2019-03-22 13:27:46 +01:00
Daniel Carrión
6ef7d2cd6e added reference documentation for cdb_bulk_geocode_street_point 2019-03-22 13:06:38 +01:00
Javier Goizueta
304f9fd0d3 Merge pull request #551 from CartoDB/tomtom-bulk-fix
Fix altered public method of TomTomGeocoder
2019-03-13 13:51:02 +01:00
Javier Goizueta
63dfa51092 Merge pull request #551 from CartoDB/tomtom-bulk-fix
Fix altered public method of TomTomGeocoder
2019-03-13 13:40:02 +01:00
Javier Goizueta
f07ff35b58 Release python-lib 0.21.4 2019-03-13 13:39:07 +01:00
Javier Goizueta
1cbbe29e22 Fix altered public method of TomTomGeocoder
In #456 the public method geocode_meta return value was changed
(to a tuple).
2019-03-13 12:47:37 +01:00
cillas
1ae8eaafd0 Merge pull request #470 from CartoDB/developer-center
New docs folder for developer center
2019-03-07 18:32:17 +01:00
csubira
2a05b86e55 Add CR changes and update older links in dev center docs 2019-03-06 18:15:42 +01:00
Javier Goizueta
dc0b3191f6 Merge pull request #549 from CartoDB/development
Release python-0.21.3
2019-03-05 11:59:21 +01:00
Javier Goizueta
6a57a85e72 Release new python lib version 0.21.3 2019-03-05 11:55:40 +01:00
Javier Goizueta
08a50c14bb Merge pull request #548 from CartoDB/tomtom-qps
Pass the response through the exception object
2019-03-05 11:51:25 +01:00
Javier Goizueta
ec2fe14ed3 Pass http response to ServiceException 2019-03-05 11:33:25 +01:00
Javier Goizueta
305b010225 Pass the response through the exception object 2019-03-05 11:12:58 +01:00
Javier Goizueta
885c7c50fb Merge pull request #547 from CartoDB/development
Release python-0.21.2
2019-03-04 18:48:55 +01:00
Javier Goizueta
a38c5b275d Merge pull request #546 from CartoDB/545-tomtom-qps
Detect alternative TomTom rate limit header
2019-03-04 18:26:43 +01:00
Javier Goizueta
45542b2f28 Release new python lib version 2019-03-04 18:25:25 +01:00
Javier Goizueta
f0a9779a8d Detect alternative TomTom rate limit header
Also flexibilizes detection by making it case-insensitive and allowing for text around the message
Fixes 545
2019-03-04 15:43:22 +01:00
csubira
de1ab5218a Remove empty file 2019-03-01 12:08:41 +01:00
csubira
84f17f946f Update with development branch 2019-03-01 12:06:42 +01:00
csubira
a31b429c7a Remove older content 2019-03-01 11:54:33 +01:00
csubira
f1e4ff6f33 Reorder dev center folder 2019-03-01 11:53:49 +01:00
Javier Goizueta
dd1df8695f Merge pull request #544 from CartoDB/development
Release client extension 0.26.2
2019-02-26 10:18:48 +01:00
Javier Goizueta
8507067901 Release 0.26.2 client extension 2019-02-25 16:48:36 +01:00
Javier Goizueta
00f77cca8a Merge pull request #543 from CartoDB/fix-bulk-geocoding-soft-limit
Fix bulk geocoding soft limit
2019-02-25 16:39:29 +01:00
Javier Goizueta
dfaf0d5245 Prevent use of quota for bogus configurations
This is a stop-gap measure for the hypothetical case of a service configuration that yields NULL quota values.
2019-02-25 16:32:01 +01:00
Rafa de la Torre
f63d73b9d7 Fix the bulk geocoding when soft_limit is enabled
Fix the case where there's not enough quota to geocode a table but the
soft_limit is set to true.

The function `cdb_enough_quota` accounts for the `soft_limit` flag, as
well as for the remaining quota and the rows to be geocoded.
2019-02-19 12:27:29 +01:00
Rafa de la Torre
29e636f115 Test for bulk geocoding w/ soft_limit enabled 2019-02-19 12:24:06 +01:00
Iñigo Medina (aka MacGyver)
2ae1547f3c update references to developer center components 2019-01-31 14:45:30 +01:00
Javier Torres
f082c918f0 Merge pull request #542 from CartoDB/development
Client 0.26.1, Server 0.35.1 -> Fix batch geocoder geometry type
2018-12-31 11:04:45 +01:00
Javier Torres
246ec135db Update NEWS.md 2018-12-31 11:02:26 +01:00
Javier Torres
4f5745988f Merge pull request #540 from CartoDB/538-multipolygon_geocoding_batch
538 multipolygon geocoding batch
2018-12-31 11:01:17 +01:00
Javier Torres
f996cb35db Merge pull request #541 from CartoDB/development
Python 0.21.1: Fix batch geocoder precision
2018-12-26 12:18:29 +01:00
Javier Torres
bbfa03749a Merge pull request #539 from CartoDB/s1891-bulk_geocoder_no_street_address
S1891 bulk geocoder no street address
2018-12-26 12:17:48 +01:00
Javier Torres
ab13f3a803 Also have to upgrade the geocoding function type 2018-12-24 17:55:50 +01:00
Javier Torres
ac991a05ab ALTER TYPE syntax fixes 2018-12-24 17:36:09 +01:00
Javier Torres
0dfd1a9caa Update/downgrade scripts 2018-12-24 17:28:56 +01:00
Javier Torres
370272f6c4 Version bumps 2018-12-24 17:22:32 +01:00
Javier Torres
e2c0a63803 Use Point for geocoding results 2018-12-24 17:19:13 +01:00
Javier Torres
84276b4cd3 Do not crash when matchType is empty 2018-12-24 13:04:54 +01:00
cillas
e9856d92f6 Replace mapbox with tomtom in support quota info docs 2018-12-14 10:03:26 +01:00
Mario de Frutos
b608830bce Merge pull request #537 from CartoDB/development
Release 0.35.0 for server extension
2018-11-30 12:34:38 +01:00
Mario de Frutos
a8140e53c3 Update routing mode type doc 2018-11-30 12:30:40 +01:00
Mario de Frutos
c28ca4861a Update NEWS.md 2018-11-30 12:24:47 +01:00
Mario de Frutos
b269c46724 Merge pull request #536 from CartoDB/add_mode_type_tomtom
Mode type options for routing
2018-11-30 12:17:06 +01:00
Mario de Frutos
6b6fbef586 Remove unused import 2018-11-30 11:31:46 +01:00
Mario de Frutos
eb4638a326 CR fixes 2018-11-30 11:24:12 +01:00
Mario de Frutos
a919b87664 Include test for valid request with route type 2018-11-29 16:22:34 +01:00
Mario de Frutos
98a4ed81c5 Add test for route type verification 2018-11-29 16:16:22 +01:00
Mario de Frutos
0ec1e051be Include options parsing functions 2018-11-29 14:28:54 +01:00
Mario de Frutos
850497ef79 Fix some missing arguments in the functions and add drop for the old ones 2018-11-29 13:02:18 +01:00
Mario de Frutos
8d2d0ececd SQL server extension artifact for version 0.35.0 2018-11-29 12:34:56 +01:00
Mario de Frutos
90fd8587e2 Upgrade and downgrade files 2018-11-29 12:12:19 +01:00
Mario de Frutos
64a0616c97 Added options and units parameters to the routing functions 2018-11-29 12:12:05 +01:00
Mario de Frutos
b1bdf2460e Version 0.35.0 initial files 2018-11-29 12:09:48 +01:00
Mario de Frutos
04bbb32849 Added mode type to Tomtom routing functions 2018-11-29 11:51:59 +01:00
Mario de Frutos
3e6c273b48 Merge pull request #535 from CartoDB/development
Release 0.34.2
2018-11-27 18:04:11 +01:00
Mario de Frutos
522591dd63 Update NEWS.md 2018-11-27 17:51:45 +01:00
Mario de Frutos
75d0959aff Merge pull request #532 from CartoDB/fix_metrics
Fix metrics
2018-11-27 17:49:55 +01:00
Mario de Frutos
b2cdb378fb Regenerate 0.34.2 artifact 2018-11-27 17:43:02 +01:00
Mario de Frutos
100319ed0e Migrate old versions 2018-11-27 17:41:14 +01:00
Mario de Frutos
5e161b55d2 Merge branch 'development' into fix_metrics 2018-11-27 17:39:56 +01:00
Mario de Frutos
7f4b87f513 Rename to release 2018-11-27 17:39:05 +01:00
Mario de Frutos
378458c0ae Merge pull request #534 from CartoDB/development
Release 0.34.1 of the server extension
2018-11-22 15:15:13 +01:00
Mario de Frutos
4ae4080bba Updated NEWS.md 2018-11-22 15:10:11 +01:00
Mario de Frutos
2bb67ba17a Merge pull request #533 from CartoDB/fix_isochrones_metrics
Fix isochrones metrics
2018-11-22 15:07:57 +01:00
Mario de Frutos
1027d554a5 Upgrade script from 0.34.0 to 0.34.1 2018-11-19 18:23:28 +01:00
Mario de Frutos
4e1f081952 Generated 0.34.1 artifact with changes 2018-11-19 18:11:23 +01:00
Mario de Frutos
87bb8bea68 Remove duped metrics for isochrones
We are counting the success/empty inside the iteration of the results
returned by the third party service.

For example, if we ask for 3 isochrones to a provider we count:

- 1 for success or empty
- If success we add 1 more success for each isochrone in the result
- N isolines_generated

but it should be

- 1 for success or empty
- N isolines_generated
2018-11-19 17:59:47 +01:00
Mario de Frutos
dc47f6f71b New version 0.34.1 artifacts 2018-11-19 17:51:26 +01:00
Mario de Frutos
2f6d067b4e Parse JSON parameters to avoid problems
If we pass JSON as string, with scape characters and so on, we are
going to have problems parsing that metrics in ES
2018-11-05 17:06:52 +01:00
Mario de Frutos
089d3e3f27 New version 0.34.1 2018-11-05 16:51:17 +01:00
Mario de Frutos
765b2f0901 Merge pull request #529 from CartoDB/development
Release version 0.20.2 for python library
2018-10-31 14:00:31 +01:00
Mario de Frutos
36c42096e4 Updated NEWS.md 2018-10-31 13:58:29 +01:00
Mario de Frutos
909554b453 Merge pull request #528 from CartoDB/fix_qps_tomtom
Fix qps tomtom
2018-10-31 13:55:40 +01:00
Mario de Frutos
33f40bc945 TOMTOM uses 403 instead of 429 for rate limiting
That has a great problem when we're dealing with legit 403 status for
example deactivated user, forbidden access, etc.

I've added a check for the HTTP header `X-Error-Detail-Header` in order
to distinguish between legit 403 and 429 error messages

Possible values for `X-Error-Detail-Header` in a 403 error:

  o Service Requires SSL : http is used instead of https (secure)

  o Invalid Referer : invalid 'Referer' header value is send
  to https://api.tomtom.com and allowed referer values are
  configured on specific API key

  o Account Over Queries Per Second Limit : rate limit exceeded

  o Account Inactive : incorrect API key/API key no longer valid
2018-10-31 12:59:13 +01:00
Mario de Frutos
17c993f6ef Bump version 2018-10-24 12:00:44 +02:00
Mario de Frutos
6640909780 Add provider for QPS manger in tomtom services 2018-10-24 12:00:08 +02:00
Mario de Frutos
0bcdaeabc5 Include note to explain why some isodistances could not be precise 2018-10-24 11:59:06 +02:00
Mario de Frutos
0e859d8955 Merge pull request #527 from CartoDB/change_isodistance_doc
Include note to explain why some isodistances could not be precise
2018-10-24 11:57:53 +02:00
Mario de Frutos
cd8173c7e0 Include note to explain why some isodistances could not be precise 2018-10-23 16:36:05 +02:00
Mario de Frutos
8f362c923e Merge pull request #524 from CartoDB/development
Release python library 0.20.1
2018-10-03 18:54:25 +02:00
Mario de Frutos
56a2ebb210 Fix qps timeout bug 2018-10-03 18:50:20 +02:00
Mario de Frutos
6c1c06f6be Merge pull request #523 from CartoDB/qps_fix_tomtom
Qps fix tomtom
2018-10-03 17:33:07 +02:00
Mario de Frutos
61a27a9f9d Tomtom QPS fix
Tomtom return 403 status code in the following scenarios:

- Forbidden
- Not authorized
- Account inactive
- Account over queries per second limit
- Account over rate limit
- Rate limit exceeded

So when we reach the QPS limit we receive a 403 instead of 429 so we
have to include the provider in the qps service to differentiate between
providers that returns 429 and special cases like tomtom
2018-10-03 16:35:38 +02:00
Javier Torres
ee6f2ab1c2 Merge pull request #521 from CartoDB/Fix_integration_tests
Fixed tests
2018-09-14 15:06:01 +02:00
antoniocarlon
4aa587d32b Fixing DO integration tests 2018-09-14 12:46:43 +02:00
antoniocarlon
4598d5ed7d Added CR suggestion 2018-09-14 10:14:59 +02:00
antoniocarlon
a57500c966 Fixed tests 2018-09-13 16:01:53 +02:00
Antonio Carlón
247e9040dd Merge pull request #520 from CartoDB/development
Release 0.34.0 server and 0.26.0 client
2018-09-13 10:05:34 +02:00
Antonio Carlón
4f983ec32f Merge pull request #519 from CartoDB/518-Use_non-master_keys
Use non-master keys
2018-09-13 10:02:08 +02:00
antoniocarlon
88e6245014 Updated NEWS.md 2018-09-13 10:00:32 +02:00
antoniocarlon
bafa60303c Added data observatory permission 2018-09-11 15:45:06 +02:00
antoniocarlon
ffa67fe6ca Client changes 2018-09-11 14:50:11 +02:00
antoniocarlon
3990d13572 Server changes 2018-09-11 14:35:02 +02:00
antoniocarlon
5989cb1dff Fixed exception safe functions 2018-09-11 12:17:28 +02:00
antoniocarlon
5307078171 Added CR suggestions 2018-09-11 12:13:06 +02:00
antoniocarlon
ad9619bb00 Removed unused declaration 2018-09-11 12:04:19 +02:00
antoniocarlon
2a6e63b618 Fixed tests 2018-09-11 12:02:24 +02:00
antoniocarlon
c5b6c27045 Fixed JSON return value 2018-09-11 11:19:12 +02:00
antoniocarlon
b6d37c6773 Managing public api key permissions 2018-09-11 11:07:59 +02:00
antoniocarlon
e82fb49028 organization default to null 2018-09-11 10:57:32 +02:00
antoniocarlon
4d3e9f2b32 Getting the username from cdb_conf 2018-09-11 10:14:52 +02:00
antoniocarlon
d5864ccada Using ERRCODE 2018-09-10 17:06:37 +02:00
antoniocarlon
0bdba67342 Using ERRCODE 2018-09-10 16:54:25 +02:00
antoniocarlon
08daa6a6a2 Changed error message 2018-09-10 16:45:31 +02:00
antoniocarlon
f4cb9ba812 Fixe 2018-09-10 14:33:54 +02:00
antoniocarlon
a33dd4315c Fixe 2018-09-10 14:31:08 +02:00
antoniocarlon
49bcf31832 Removed appname parameter 2018-09-10 14:26:53 +02:00
antoniocarlon
3d42281d2a Fixed test 2018-09-10 13:50:52 +02:00
antoniocarlon
696c24e432 Fixed test 2018-09-10 13:47:35 +02:00
antoniocarlon
f5ad0290b4 Fixed functions 2018-09-10 13:43:04 +02:00
antoniocarlon
01f145ab69 Fixed client tests 2018-09-10 13:40:15 +02:00
antoniocarlon
b4123625f7 Fixed server tests 2018-09-10 13:15:19 +02:00
antoniocarlon
4b6b4e92e8 CR suggestions (remove appname) 2018-09-10 12:54:37 +02:00
antoniocarlon
5ea1a4ca6b Added permissions to tests 2018-09-06 16:40:05 +02:00
antoniocarlon
ca717ed123 Fixed permission check 2018-09-06 15:40:41 +02:00
antoniocarlon
8a8970efa8 Fixed tests 2018-09-06 15:18:42 +02:00
antoniocarlon
603d691017 Added metrics 2018-09-06 13:47:50 +02:00
antoniocarlon
04a5a25d06 Fixed m04r tests 2018-09-06 12:55:31 +02:00
antoniocarlon
30e480e545 Fixed m04r tests 2018-09-06 12:46:12 +02:00
antoniocarlon
eca4b42a73 Fixed tests 2018-09-06 12:32:48 +02:00
antoniocarlon
7a7ccbbfcf Added appname parameter to the public server functions 2018-09-06 12:04:11 +02:00
antoniocarlon
56c975fef1 Added appname parameter 2018-09-06 10:55:34 +02:00
antoniocarlon
8fb9524213 Added exceptions to bulk geocoding client 2018-09-06 10:42:56 +02:00
antoniocarlon
393da56964 Updated exception safe private functions 2018-09-06 10:06:33 +02:00
antoniocarlon
17dc3ad1c7 Updated exception safe private functions 2018-09-06 10:01:01 +02:00
antoniocarlon
1eff219883 Changes in _cdb_entity_config 2018-09-05 17:57:16 +02:00
antoniocarlon
a09d18a6ee Fixing template 2018-09-05 17:51:08 +02:00
antoniocarlon
d43c9461b1 Fixing template 2018-09-05 17:36:16 +02:00
antoniocarlon
2a2ae481fb Permissions check and client templates 2018-09-05 17:28:15 +02:00
antoniocarlon
652242a8f8 Permissions check and client templates 2018-09-05 17:02:02 +02:00
Mario de Frutos
9a6f52d63b Merge pull request #517 from CartoDB/development
Release 0.33 server and 0.20 for python library
2018-08-27 12:19:07 +02:00
Mario de Frutos
48d82e025a Merge pull request #516 from CartoDB/remove_obs_snapshot_quota
Remove obs snapshot quota
2018-08-27 11:57:44 +02:00
Mario de Frutos
9398ec0524 Updated NEWS.md 2018-08-27 11:56:15 +02:00
Mario de Frutos
073c527a62 Update NEWS.md 2018-08-21 18:42:16 +02:00
Mario de Frutos
a8e96366a5 Bump for the python library version 2018-08-21 18:40:22 +02:00
Mario de Frutos
6cc3cda6e0 Remove obs_snapshot_config from python library 2018-08-21 18:28:55 +02:00
Mario de Frutos
0e95c5ff90 Now the snapshot functions use the obs_genral config 2018-08-21 18:25:12 +02:00
Mario de Frutos
fba933cc88 Remove obs_snapshot_config 2018-08-21 18:18:10 +02:00
Mario de Frutos
44da876b4c Version 0.33.0 initial commit 2018-08-21 18:15:29 +02:00
Alejandro Guirao Rodríguez
288e3a4077 Merge pull request #515 from CartoDB/development
carto-package.json
2018-08-20 10:35:32 +02:00
Juan Ignacio Sánchez Lara
821fc04d49 Merge pull request #514 from CartoDB/naming-fixes
Component change and versioning using more numbers
2018-08-20 10:17:17 +02:00
Alejandro Guirao Rodríguez
a563abb7ab Update carto-package.json 2018-08-17 10:58:56 +02:00
Alejandro Guirao Rodríguez
9c8647ebd4 Changes in component names and versions 2018-08-17 10:57:52 +02:00
Alejandro Guirao Rodríguez
61aaa0804f Changes in component names and versions 2018-08-17 10:56:07 +02:00
Alejandro Guirao Rodríguez
bd391f4bf4 Component change and versioning using more numbers 2018-08-17 10:54:24 +02:00
Juan Ignacio Sánchez Lara
2f4e3d6e05 Merge pull request #513 from CartoDB/development
Disable Mapbox Matrix API
2018-08-14 10:50:43 +02:00
Juan Ignacio Sánchez Lara
a025034d64 Merge pull request #512 from CartoDB/remove_mapbox_matrix_api_usage
Remove mapbox matrix api usage
2018-08-14 10:49:26 +02:00
Juan Ignacio Sánchez Lara
d9f647504a Disable Mapbox Matrix API usage at tests 2018-08-14 09:39:42 +02:00
Juan Ignacio Sánchez Lara
ed2e87f4ca Fix test fixture 2018-08-14 09:27:59 +02:00
Juan Ignacio Sánchez Lara
f6791d6ec8 Merge pull request #511 from CartoDB/dataservices_dependencies_specification
Dataservices dependencies specification
2018-08-13 17:13:32 +02:00
Juan Ignacio Sánchez Lara
c1c671755c Final carto-package.json format 2018-08-13 16:28:47 +02:00
cillas
1f61419467 Fix typo in filename 2018-08-08 17:49:18 +02:00
Juan Ignacio Sánchez Lara
a32e90ea8a carto-package.json proposal 2018-08-02 12:59:45 +02:00
Juan Ignacio Sánchez Lara
a6bff9b8d2 Merge pull request #509 from CartoDB/development
Version `0.19.1` of the Python library
2018-07-25 11:27:43 +02:00
Juan Ignacio Sánchez Lara
075f602a7f WELL_KNOWN_SHAPE and WELL_KNOWN_LENGTH fixture update 2018-07-25 11:22:31 +02:00
Juan Ignacio Sánchez Lara
e69849fb86 Merge pull request #508 from CartoDB/fix_batch_geocoding_error_accounting
Fix batch geocoding error accounting
2018-07-25 11:04:11 +02:00
Juan Ignacio Sánchez Lara
11ec6075c3 Python library version 0.19.1 2018-07-24 11:59:29 +02:00
Juan Ignacio Sánchez Lara
c6720bf689 Better debug message 2018-07-24 11:57:54 +02:00
Juan Ignacio Sánchez Lara
3524ee1e24 Handle postprocessing error 2018-07-24 11:31:05 +02:00
Juan Ignacio Sánchez Lara
80dcde2db0 Log Mapbox unknown status 2018-07-23 22:00:16 +02:00
Juan Ignacio Sánchez Lara
fa3d7db5f8 Fix Google geocoder error handling 2018-07-23 21:54:37 +02:00
Juan Ignacio Sánchez Lara
d060ab3d41 Empty vs missing count detail 2018-07-23 19:11:23 +02:00
Juan Ignacio Sánchez Lara
3a5360c96c Refactor and fix for actual searches type 2018-07-23 19:10:35 +02:00
Juan Ignacio Sánchez Lara
fc75f1afc8 Google batch geocoder error handling 2018-07-23 18:41:47 +02:00
Juan Ignacio Sánchez Lara
4be3aa88fd Constant extraction refactor 2018-07-23 18:30:33 +02:00
Juan Ignacio Sánchez Lara
8162bff204 Serial geocoding error handling 2018-07-23 18:27:02 +02:00
Juan Ignacio Sánchez Lara
1b31c089ce Global error handling for batched geocoding 2018-07-23 18:16:40 +02:00
Juan Ignacio Sánchez Lara
faf9b7237b Adjustments on street level fixtures 2018-07-23 17:36:06 +02:00
Juan Ignacio Sánchez Lara
5d2303e1de Log a failed one if any 2018-07-23 17:23:08 +02:00
Juan Ignacio Sánchez Lara
07f5be9207 TomTom error handling 2018-07-23 17:17:38 +02:00
Juan Ignacio Sánchez Lara
bcb34d1cea Adjustments on street level fixtures 2018-07-23 15:57:32 +02:00
Juan Ignacio Sánchez Lara
c5d9db61e6 Mapbox error handling 2018-07-23 15:48:32 +02:00
Juan Ignacio Sánchez Lara
1ff512839d Fixes empty results count 2018-07-23 13:01:46 +02:00
Juan Ignacio Sánchez Lara
9a1b1e2832 Error count 2018-07-23 12:18:26 +02:00
Juan Ignacio Sánchez Lara
1cebbe7af0 Missing warning mock and fix for debug 2018-07-23 12:16:48 +02:00
Juan Ignacio Sánchez Lara
2862c80025 Proper empty count on bulk geocoding 2018-07-23 11:53:02 +02:00
Juan Ignacio Sánchez Lara
abbaf83e97 run_street_point_geocoder tests 2018-07-23 11:42:51 +02:00
Juan Ignacio Sánchez Lara
cd5e6510a6 In case of general error, failed service use should be incremented by searches length 2018-07-23 09:30:09 +02:00
Juan Ignacio Sánchez Lara
fd097724f1 In case of general error, total service use should be incremented by searches length 2018-07-19 21:17:09 +02:00
Juan Ignacio Sánchez Lara
96fbf3080a Base run_street_point_geocoder test 2018-07-19 21:08:07 +02:00
Juan Ignacio Sánchez Lara
0d490bbb19 Extract EMPTY_RESPONSE 2018-07-19 20:52:59 +02:00
Juan Ignacio Sánchez Lara
f86558c30b Merge pull request #507 from CartoDB/development
Version `0.25.0` of the client, `0.32.0` of the server, and `0.19.0` of the Python library
2018-07-19 11:36:44 +02:00
Juan Ignacio Sánchez Lara
0bd2fbf80a Merge pull request #499 from CartoDB/geocoder_boost
Geocoder boost
2018-07-19 11:32:23 +02:00
Juan Ignacio Sánchez Lara
887fc15915 NEWS versions update 2018-07-19 11:31:35 +02:00
Juan Ignacio Sánchez Lara
5c09a2eb29 Missing grant 2018-07-19 10:36:49 +02:00
Juan Ignacio Sánchez Lara
b0c1948c14 TL;DR: safer deployment and minor fixes
- Instead of modifying cdb_service_quota_info to return max_batch_size,
a new type (service_quota_info_batch) and a new function
(cdb_service_quota_info_batch) are created. That makes deployment safe.
- Fixes geocoding with forced batch size 1.
- Improves namespacing for count_estimate (->
cdb_dataservices_client.cdb_count_estimate).
- Improves namespacing for jsonb_array_casttext (->
cdb_dataservices_client.cdb_jsonb_array_casttext).
2018-07-18 14:57:40 +02:00
Juan Ignacio Sánchez Lara
0c5e9da028 Upgrade/downgrade scripts for server 0.32.0 and client 0.25.0 2018-07-17 19:48:13 +02:00
Juan Ignacio Sánchez Lara
f534da906c Merge pull request #506 from CartoDB/geocoder_boost_refactor
Geocoder boost refactor
2018-07-17 17:59:30 +02:00
Juan Ignacio Sánchez Lara
5e34faefe5 Quota test 2018-07-17 14:39:56 +02:00
Juan Ignacio Sánchez Lara
5e8dbaf239 Improvements in fixtures accuracy 2018-07-17 13:56:44 +02:00
Juan Ignacio Sánchez Lara
b90d402fa9 Round relevance (plus refactor) 2018-07-17 13:56:01 +02:00
Juan Ignacio Sánchez Lara
d060bd8229 Simplification of batching 2018-07-17 13:24:39 +02:00
Juan Ignacio Sánchez Lara
c104f6f34b Metadata attributes constant extraction 2018-07-17 12:46:16 +02:00
Juan Ignacio Sánchez Lara
e9ed3bca18 Safer comparison 2018-07-17 12:27:42 +02:00
Juan Ignacio Sánchez Lara
e2762a6e03 Removed debug traces 2018-07-17 10:06:43 +02:00
Juan Ignacio Sánchez Lara
8cb9e123b1 Helper function to convert json arrays to PG arrays 2018-07-16 19:55:04 +02:00
Juan Ignacio Sánchez Lara
e82346e7f6 match_types for batched HERE metadata 2018-07-16 12:43:40 +02:00
Juan Ignacio Sánchez Lara
080de34163 match_types for Mapbox metadata 2018-07-16 12:11:40 +02:00
Juan Ignacio Sánchez Lara
0a92ae1445 match_types for TomTom metadata 2018-07-16 12:01:55 +02:00
Juan Ignacio Sánchez Lara
0b635377ef match_types for HERE metadata 2018-07-16 11:59:43 +02:00
Juan Ignacio Sánchez Lara
f2197d4b2a match_types for Google metadata 2018-07-16 11:34:33 +02:00
Juan Ignacio Sánchez Lara
6e78da55b2 Precision metadata for Mapbox 2018-07-11 19:28:16 +02:00
Juan Ignacio Sánchez Lara
4123a4c442 Precision metadata for TomTom 2018-07-11 19:09:02 +02:00
Juan Ignacio Sánchez Lara
dbb4f9204a Precision metadata for HERE 2018-07-11 15:30:51 +02:00
Juan Ignacio Sánchez Lara
67fee1cce8 Precision metadata for Google 2018-07-11 14:06:50 +02:00
Juan Ignacio Sánchez Lara
b779742585 Fix logging on error 2018-07-11 12:51:56 +02:00
Juan Ignacio Sánchez Lara
da78b0bc65 Fix batching with negatives cartodb_id 2018-07-11 12:28:39 +02:00
Juan Ignacio Sánchez Lara
d46d51c3bb Relevance metadata for Google 2018-07-11 11:43:54 +02:00
Juan Ignacio Sánchez Lara
0b2ee85c11 TomTom normalization 2018-07-11 09:30:28 +02:00
Juan Ignacio Sánchez Lara
825e3b7ee8 Relevance metadata for Mapbox 2018-07-11 09:30:08 +02:00
Juan Ignacio Sánchez Lara
2af9204542 Relevance metadata for TomTom 2018-07-10 21:21:42 +02:00
Juan Ignacio Sánchez Lara
34e622b809 Relevance metadata for HERE 2018-07-10 20:30:01 +02:00
Juan Ignacio Sánchez Lara
531ad28158 Send optimal batch size 2018-07-10 19:31:58 +02:00
Juan Ignacio Sánchez Lara
286a75fa8e _bulk_geocode logic extraction 2018-07-10 15:17:14 +02:00
Juan Ignacio Sánchez Lara
a6c5c21131 Serial geocode for Google bulk 2018-07-10 13:45:01 +02:00
Juan Ignacio Sánchez Lara
f6b7c13dde GoogleMapsBulkGeocoder extraction 2018-07-10 13:38:51 +02:00
Juan Ignacio Sánchez Lara
1ffe3658fe Revert "maxresults depends on batch"
This reverts commit bf8b76b5fe.
2018-07-10 12:28:16 +02:00
Juan Ignacio Sánchez Lara
8e430ce1c1 Google geocoder works better concatenating all components 2018-07-10 11:17:21 +02:00
Juan Ignacio Sánchez Lara
8ebd22bc26 Fixes error message check 2018-07-10 11:17:21 +02:00
Juan Ignacio Sánchez Lara
0ff950d01e Merge pull request #505 from CartoDB/geocoder_boost_mapbox
Mapbox bulk geocoding
2018-07-10 11:16:52 +02:00
Juan Ignacio Sánchez Lara
fed8894c33 Merge pull request #504 from CartoDB/geocoder_boost_tomtom
Geocoder boost tomtom
2018-07-10 09:50:44 +02:00
Juan Ignacio Sánchez Lara
cce5f92312 Escape semicolons at Mapbox batch 2018-07-09 18:17:45 +02:00
Juan Ignacio Sánchez Lara
40ace9cfaa Send _serial_geocode for single results 2018-07-09 17:42:08 +02:00
Juan Ignacio Sánchez Lara
f618e4aec3 Mapbox bulk geocoding 2018-07-09 17:35:56 +02:00
Juan Ignacio Sánchez Lara
ae84122c3d countries --> country 2018-07-09 15:35:37 +02:00
Juan Ignacio Sánchez Lara
b8475bac30 TomTom batch geocoding 2018-07-06 20:11:48 +02:00
Juan Ignacio Sánchez Lara
bf8b76b5fe maxresults depends on batch 2018-07-06 20:04:28 +02:00
Juan Ignacio Sánchez Lara
31afc82b56 TomTom bulk geocoding by bypassing to serial 2018-07-06 15:52:45 +02:00
Juan Ignacio Sánchez Lara
5be43e15c0 Fix error message on TomTom error 2018-07-06 15:52:45 +02:00
Juan Ignacio Sánchez Lara
6da70fd8ea Fix encoding of missing fields 2018-07-06 15:52:10 +02:00
Juan Ignacio Sánchez Lara
d00a48f16e Check array length 2018-07-05 17:57:17 +02:00
Juan Ignacio Sánchez Lara
91012ea62d Updated version script 2018-07-05 16:26:28 +02:00
Juan Ignacio Sánchez Lara
23e3de9da5 Add missing permission for cdb_bulk_geocode_street_point 2018-07-05 15:10:05 +02:00
Juan Ignacio Sánchez Lara
6c89ca8d70 Fix exception raising 2018-07-05 12:42:18 +02:00
Juan Ignacio Sánchez Lara
3c07133912 Improve logging of exceptions from sys.exc_info 2018-07-05 08:50:26 +02:00
Juan Ignacio Sánchez Lara
5b46c1527e Revert "Revert expected warnings"
This reverts commit 89e9bf1ed6.
2018-07-05 08:23:33 +02:00
Juan Ignacio Sánchez Lara
89e9bf1ed6 Revert expected warnings 2018-07-04 15:07:54 +02:00
Antonio Carlón
ff6cbd1d5b Merge pull request #503 from CartoDB/geocoder_boost_here
Geocoder boost HERE
2018-07-04 14:26:20 +02:00
Juan Ignacio Sánchez Lara
8968f0e6ec Fix message 2018-07-04 13:36:18 +02:00
Juan Ignacio Sánchez Lara
44744de73d Explicit check for result length 2018-07-04 13:29:37 +02:00
Juan Ignacio Sánchez Lara
754c364d22 Reduce precision on fixture points 2018-07-04 13:24:11 +02:00
Juan Ignacio Sánchez Lara
9856adb7ce Explicit NotImplementedError 2018-07-04 12:33:29 +02:00
Juan Ignacio Sánchez Lara
e416a8a641 HERE batch support 2018-07-02 18:35:36 +02:00
Juan Ignacio Sánchez Lara
fc610313bf Test refactor and Here serial batch 2018-06-29 19:18:53 +02:00
Juan Ignacio Sánchez Lara
18e2349713 Bulk geocoding refactor 2018-06-29 14:59:07 +02:00
Juan Ignacio Sánchez Lara
e884b1d1f4 Fixture fix 2018-06-28 13:11:28 +02:00
Juan Ignacio Sánchez Lara
45b8fc4ecf Quota and batch size checks fixes and tests 2018-06-28 13:06:52 +02:00
Juan Ignacio Sánchez Lara
379257b4b4 Fix quota check 2018-06-27 19:07:19 +02:00
Juan Ignacio Sánchez Lara
8fe9903e7a searchtext -> searches for bulk geocoding 2018-06-27 15:14:11 +02:00
Juan Ignacio Sánchez Lara
d0b04a97b8 Better Google geocoding through concatenation 2018-06-27 13:47:57 +02:00
Juan Ignacio Sánchez Lara
a931086e29 Log now also logs the exception, fixing fixtures 2018-06-27 13:13:08 +02:00
Juan Ignacio Sánchez Lara
8f4249ee24 Merge branch 'development' into geocoder_boost 2018-06-27 11:17:56 +02:00
Mario de Frutos
71b87834b3 Merge pull request #501 from CartoDB/fix_mapbox_routing_fixture
Fix mapbox routing fixture
2018-06-27 11:13:22 +02:00
Juan Ignacio Sánchez Lara
9c90c539f8 Fix Mapbox routing fixture shape 2018-06-27 11:09:32 +02:00
Juan Ignacio Sánchez Lara
ed828c3b89 test_templating_with_two_columns_geocoding 2018-06-27 10:13:59 +02:00
Juan Ignacio Sánchez Lara
675ef72e30 test_templating_geocoding 2018-06-27 08:57:04 +02:00
Juan Ignacio Sánchez Lara
c13d29e4c2 test_free_text_geocoding 2018-06-26 16:52:41 +02:00
Juan Ignacio Sánchez Lara
d5e47e39ab Revert bulk geocoding column parameters order and test_city_column_geocoding 2018-06-26 13:59:44 +02:00
Juan Ignacio Sánchez Lara
c2a207b1cd Batching, better support for null columns, and bulk geocoding integration tests 2018-06-26 13:35:24 +02:00
Juan Ignacio Sánchez Lara
e280444479 Integration tests dependencies 2018-06-26 11:07:38 +02:00
Juan Ignacio Sánchez Lara
9b64d91998 Fixed env variables cleaning 2018-06-26 10:56:14 +02:00
Iñigo Medina (aka MacGyver)
ab7bc424d3 remove references to providers depending on the platform 2018-06-25 12:41:40 +02:00
Juan Ignacio Sánchez Lara
91d93bef79 Random temporary table name 2018-06-22 14:34:42 +02:00
Juan Ignacio Sánchez Lara
bbbf70f3ac Street level columns for country, city and state 2018-06-22 12:19:51 +02:00
Juan Ignacio Sánchez Lara
4d2abc7667 Simpler and more precise quota check 2018-06-22 09:41:29 +02:00
Juan Ignacio Sánchez Lara
58d70e252f checked, bulked cdb_bulk_geocode_street_point 2018-06-21 10:23:39 +02:00
Juan Ignacio Sánchez Lara
e85f43f1d1 cdb_bulk_geocode_street_point skeleton 2018-06-15 09:55:52 +02:00
Juan Ignacio Sánchez Lara
f3f2b213e7 Bump versions 2018-06-11 16:26:57 +02:00
Juan Ignacio Sánchez Lara
34fc6439d2 cdb_bulk_geocode_street_point functions 2018-06-11 16:12:41 +02:00
Juan Ignacio Sánchez Lara
3f08d37ef7 Google bulk_geocoder 2018-06-11 12:56:07 +02:00
Juan Ignacio Sánchez Lara
be446c1bf2 exception logging at _send_to_plpy 2018-06-07 10:29:57 +02:00
Juan Ignacio Sánchez Lara
5251534283 Allow using non-Premium keys for Google Maps client 2018-06-04 18:07:16 +02:00
Iñigo Medina
cb7e9d48f4 Update 02-contribute.md 2018-04-17 14:43:12 +02:00
Iñigo Medina
6cc6ee8162 Update 02-authentication.md 2018-04-13 10:46:53 +02:00
Iñigo Medina
920c5a9fc0 Update 02-authentication.md 2018-04-13 10:45:34 +02:00
Iñigo Medina
c682bec387 Update 05-geocoding-functions.md 2018-04-13 10:44:51 +02:00
Iñigo Medina
ce79038f46 Rename 05-segementation-functions.md to 09-segementation-functions.md 2018-04-13 10:43:04 +02:00
Iñigo Medina
7727fbb1c7 Rename 04-routing-functions.md to 08-routing-functions.md 2018-04-13 10:36:44 +02:00
Iñigo Medina
214b84f606 Rename 03-demographic-functions.md to 07-demographic-functions.md 2018-04-13 10:35:05 +02:00
Iñigo Medina
971695899b Rename 02-isoline-functions.md to 06-isoline-functions.md 2018-04-13 10:34:47 +02:00
Iñigo Medina
1a7d0e5a8f Rename 01-geocoding-functions.md to 05-geocoding-functions.md 2018-04-13 10:33:30 +02:00
Iñigo Medina
e4256c1eb1 Create 04-error-handling.md 2018-04-13 10:33:03 +02:00
Iñigo Medina
6b38d89153 Create 03-versioning.md 2018-04-13 10:32:43 +02:00
Iñigo Medina
341c240907 Create 02-authentication.md 2018-04-13 10:32:07 +02:00
Iñigo Medina
8be34f0132 Create 01-introduction.md 2018-04-13 10:31:37 +02:00
Iñigo Medina
a56e9f63a3 Update 01-geocoding-functions.md 2018-04-13 10:26:29 +02:00
Iñigo Medina
efad90aa62 Delete test 2018-04-13 10:23:05 +02:00
Iñigo Medina
8ceb1e02a5 Add files via upload 2018-04-13 10:22:51 +02:00
Iñigo Medina
8e49d837b0 Create test 2018-04-13 10:22:27 +02:00
Iñigo Medina
eb1e3fc5e5 Update 01-geocoding-functions.md 2018-04-13 10:17:28 +02:00
Iñigo Medina
02071f1cde Update 01-geocoding-functions.md 2018-04-13 10:15:28 +02:00
Iñigo Medina
f368925f8e Delete 06-segmentation-functions.md 2018-04-13 00:50:12 +02:00
Iñigo Medina
f7349e6a92 Delete 05-demographic-functions.md 2018-04-13 00:50:04 +02:00
Iñigo Medina
39af462136 Delete 04-routing-functions.md 2018-04-13 00:49:53 +02:00
Iñigo Medina
073dc3b68b Delete 03-isoline-functions.md 2018-04-13 00:49:44 +02:00
Iñigo Medina
9f9bdd7e64 Delete 02-geocoding-functions.md 2018-04-13 00:49:35 +02:00
Iñigo Medina
292755215c Rename 02-rate-limits.md to 04-rate-limits.md 2018-04-13 00:45:36 +02:00
Iñigo Medina
6d82896eaa Rename 01-quota-information.md to 03-quota-information.md 2018-04-13 00:45:24 +02:00
Iñigo Medina
89ee3ff8fb Create 02-contribute.md 2018-04-13 00:45:12 +02:00
Iñigo Medina
5f2a0bb7dd Create 01-support-options.md 2018-04-13 00:44:22 +02:00
Iñigo Medina
38a2c3d063 Delete 07-quota-information.md 2018-04-13 00:43:30 +02:00
Iñigo Medina
6606d26984 Create 07-quota-information.md 2018-04-13 00:42:17 +02:00
Iñigo Medina
5a3fcec664 Create 06-segmentation-functions.md 2018-04-13 00:41:53 +02:00
Iñigo Medina
af81ba2cf2 Create 05-demographic-functions.md 2018-04-13 00:41:27 +02:00
Iñigo Medina
70232957f8 Create 04-routing-functions.md 2018-04-13 00:40:45 +02:00
Iñigo Medina
8ab24dc611 Create 03-isoline-functions.md 2018-04-13 00:40:07 +02:00
Iñigo Medina
140094cdde Create 02-geocoding-functions.md 2018-04-13 00:39:38 +02:00
csubira
ef68ad4dcb Add new docs folder structure 2018-02-22 17:25:12 +01:00
265 changed files with 130189 additions and 5544 deletions

60
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
name: dataservices-api PR testing
on: push
jobs:
dataservices-api:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pg_version: [10, 12]
env:
PG_VERSION: ${{ matrix.pg_version }}
steps:
- uses: actions/checkout@v1
- name: Set CLOUDSDK_PYTHON path
run: echo "CLOUDSDK_PYTHON=/usr/bin/python" >> $GITHUB_ENV
- name: Setup gcloud authentication
uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.GCS }}
- name: Pull base image
run: docker pull gcr.io/cartodb-on-gcp-ci-testing/cartodb-postgresql-base:${{ matrix.pg_version }}
- name: Checkout ci tools repository
uses: actions/checkout@v2
with:
repository: CartoDB/ci-tools
path: ci-tools
token: ${{ secrets.CARTOFANTE_PAT }}
- name: Copy ci files to root
run: cp ci-tools/repos/${{ github.event.repository.name }}/* .
- name: Start docker-compose services
run: docker-compose -f docker-compose.yaml up -d
- name: Install required python3 libs
run: docker-compose -f docker-compose.yaml exec -T postgres-server bash -c "cd /dataservices-api/server/ && sudo pip3 install -U -r ./lib/python/cartodb_services/requirements.txt && sudo pip3 install -U ./lib/python/cartodb_services"
if: env.PG_VERSION == 12
- name: Install required python libs
run: docker-compose -f docker-compose.yaml exec -T postgres-server bash -c "cd /dataservices-api/server/ && pip install -U -r ./lib/python/cartodb_services/requirements.txt && pip install -U ./lib/python/cartodb_services"
- name: Run python library tests
run: docker-compose -f docker-compose.yaml exec -T postgres-server bash -c "cd /dataservices-api/server/ && MAPBOX_API_KEY=$MAPBOX_API_KEY TOMTOM_API_KEY=$TOMTOM_API_KEY GEOCODIO_API_KEY=$GEOCODIO_API_KEY nosetests lib/python/cartodb_services/test"
env:
MAPBOX_API_KEY: ${{ secrets.MAPBOX_API_KEY }}
TOMTOM_API_KEY: ${{ secrets.TOMTOM_API_KEY }}
GEOCODIO_API_KEY: ${{ secrets.GEOCODIO_API_KEY }}
timeout-minutes: 5
- name: Run server tests
run: docker-compose -f docker-compose.yaml exec -T postgres-server bash -c "cd /dataservices-api/server/extension/ && sudo make clean all install installcheck || (cat /dataservices-api/server/extension/test/regression.diffs && false)"
timeout-minutes: 5
- name: Run client tests
run: docker-compose -f docker-compose.yaml exec -T postgres-server bash -c "sudo createuser publicuser --no-createrole --no-createdb --no-superuser -U postgres && cd /dataservices-api/client/ && sudo make clean all install installcheck || (cat /dataservices-api/client/test/regression.diffs && false)"
timeout-minutes: 5

2
.gitignore vendored
View File

@@ -5,3 +5,5 @@ cartodb_services.egg-info/
build/
dist/
.vscode/
.idea/
venv/

149
NEWS.md
View File

@@ -1,3 +1,152 @@
Sep 5th, 2022
==============
* Version `0.24.2` of the Python library
* Fix error calculating isolines with HERE
May 26th, 2021
==============
* Version `0.40.1` of the server extension
* Version `0.24.1` of the Python library
* Support new HERE API keys
Mar 4th, 2021
=============
* Version `0.31.0` of the client extension
* Version `0.40.0` of the server extension
* Version `0.24.0` of the Python library
* Remove Data Observatory
Jan 26th, 2021
==============
* Version `0.39.3` of the server extension
* Version `0.23.5` of the Python library
* Country name conversion to ISO code for TomTom bulk geocoding.
Nov 19th, 2020
==============
* Version `0.39.2` of the server extension
* Version `0.23.4` of the Python library
* Better messages on remote errors.
* Fix error on unknown status codes.
* Here bulk geocoder: Return also errors and no-matches.
Sep 23th, 2020
==============
* Version `0.39.1` of the server extension
* Allow isolines services for google-geocoding users.
Sep 23th, 2020
==============
* Version `0.23.3` of the Python library
* Change HERE batch geocoding URL
Apr 7th, 2020
=============
* Version `0.30.0` of the client extension
* PG12: Use postgis_raster instead of custom geomval.
* Version `0.39.0` of the server extension
* PG12: Use postgis_raster instead of custom geomval.
Mar 17th, 2020
==============
* Version `0.29.0` of the client extension
* Adapted client to PG12 (https://github.com/CartoDB/cartodb-platform/issues/6237)
* Version `0.38.0` of the server extension
* Adapted server to PG12 (https://github.com/CartoDB/cartodb-platform/issues/6237)
* Update dependencies to fix vulnerabilities
Mar 6th, 2020
==============
* Version `0.23.1` of the Python library
* Added query per second throttle to TomTom bulk API calls
Feb 12th, 2020
==============
* Version `0.23.0` of the Python library
* Added Mapbox true isolines
* Version `0.37.0` of the server extension
* Added Mapbox true isolines
Jan 20th, 2020
==============
* Version `0.22.0` of the Python library
* Added geocodio geocoder
* Version `0.36.0` of the server extension
* Added geocodio geocoder
* Version `0.28.0` of the client extension
* Added geocodio geocoder
Oct 9th, 2019
==============
* Version `0.27.0` of the client extension
* Changes in search_path
Mar 13rd, 2019
==============
* Version `0.21.4` of the python library
* Fix TomTom bulk geocoder bug (#551)
Mar 5th, 2019
==============
* Version `0.21.3` of the python library
* Fixed TomTom Qps respondes part 2 (#546)
Mar 4th, 2019
==============
* Version `0.21.2` of the python library
* Fixed TomTom Qps responses (#546)
Feb 25th, 2019
==============
* Version `0.26.2` of the client extension
* Fixed bulk geocoding soft limit (#543)
Dec 31st, 2018
==============
* Version `0.35.1` of the server extension and `0.26.1` of the client
* Now the bulk geocoder returns `Point` geometries instead of MultiPolygons (#538)
Nov 30th, 2018
==============
* Version `0.35.0` of the server extension
* Now the `mode_type` is working the providers that support it (#536)
Nov 27th, 2018
==============
* Version `0.34.2` of the server extension
* Fixed bulk geocoding log metrics in order to fix problems in ELK due to the JSON not being standard (#530)
Nov 22th, 2018
==============
* Version `0.34.1` of the server extension
* Fixed isochrones metrics that increase `success_rows` field for every isochrone generated (#533)
Oct 31th, 2018
==============
* Version `0.20.2` of the python library
* Added missing provider property to the QPS decorator in other TomTom services
* Now we only retry with the properly header coming from TomTom
Oct 3rd, 2018
==============
* Version `0.20.1` of the python library
* Fix QPS manager to retry with 403 status codes coming from TomTom
Sep 13th, 2018
==============
* Version `0.34.0` of the server, and `0.26.0` of the client.
* Use dataservices with non-master keys
Aug 27th, 2018
==============
* Version `0.33.0` of the server, and `0.20.0` of the Python library.
* Remove the obs_snapshot quota and now the snapshot functions uses obs_general quota
Jul 19th, 2018
==============
* Version `0.25.0` of the client, `0.32.0` of the server, and `0.19.1` of the Python library.
* Support for batch street-level geocoding.
May 7th, 2018
=============
* Version `0.24.0` of the client, `0.31.0` of the server, and `0.18.0` of the python library.

View File

@@ -40,6 +40,7 @@ Steps to deploy a new Data Services API version :
# in dataservices-api repo root path:
cd server/lib/python/cartodb_services && sudo pip install -r requirements.txt && sudo pip install . --upgrade
```
**CLOUD DEPLOY NOTE**: we were not installing automatically `requirements.txt`, so we fixed it in https://github.com/CartoDB/cartodb-platform/pull/6187 . Please, be aware that in some corner cases scenarios, rolling back to a previous version might require to manually force-install some dependency versions that were upgraded previously in this step.
- Create a database to hold all the server part and a user for it
@@ -79,28 +80,6 @@ Steps to deploy a new Data Services API version :
psql -U postgres -d dataservices_db -c "BEGIN;CREATE EXTENSION IF NOT EXISTS cdb_geocoder; COMMIT" -e
```
- [optional] install data observatory extension
- Make the extension available in postgresql to be installed
```
git clone https://github.com/CartoDB/observatory-extension.git
cd observatory
sudo make install
```
- This extension needs data, dumps are not available so we're going to use the test fixtures to make it work. Execute:
```
psql -U postgres -d dataservices_db -f src/pg/test/fixtures/load_fixtures.sql
```
- Give permission to execute and select to the `geocoder_api` user:
```
psql -U postgres -d dataservices_db -c "BEGIN;CREATE EXTENSION IF NOT EXISTS observatory VERSION 'dev'; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA cdb_observatory TO geocoder_api; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_observatory TO geocoder_api; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA cdb_observatory TO geocoder_api; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA observatory TO geocoder_api; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA observatory TO geocoder_api; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT USAGE ON SCHEMA observatory TO geocoder_api; COMMIT" -e
```
### Server configuration
Configuration for the different services must be stored in the server database using `CDB_Conf_SetConf()`.
@@ -153,6 +132,15 @@ SELECT CDB_Conf_SetConf(
);
```
Use HERE apikeys
```sql
SELECT CDB_Conf_SetConf(
'heremaps_conf',
'{"geocoder": {"app_id": "here_geocoder_app_id", "app_code": "here_geocoder_app_code", "apikey": "here_geocoder_apikey", "use_apikey": true, "geocoder_cost_per_hit": "1"}, "isolines" : {"app_id": "here_isolines_app_id", "app_code": "here_geocoder_app_code", "apikey": "here_geocoder_apikey", "use_apikey": true}}'
);
```
#### Mapzen configuration
```sql
@@ -180,12 +168,12 @@ SELECT CDB_Conf_SetConf(
);
```
#### Data Observatory
#### Geocod.io configuration
```sql
SELECT CDB_Conf_SetConf(
'data_observatory_conf',
'{"connection": {"whitelist": [], "production": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api", "staging": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api"}}'
'geocodio_conf',
'{"geocoder": {"api_keys": ["your_api_key"], "monthly_quota": 999999}}'
);
```

1
client/.gitignore vendored
View File

@@ -9,3 +9,4 @@ cdb_geocoder_client--0.0.1.sql
cdb_geocoder_client--0.1.0.sql
cdb_geocoder_client--0.2.0.sql
cdb_geocoder_client--0.3.0.sql
cdb_dataservices_client.control

View File

@@ -1,19 +1,30 @@
# Makefile to generate the extension out of separate sql source files.
# Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed.
EXTENSION = cdb_dataservices_client
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
EXTVERSION = 0.31.0
# The new version to be generated from templates
SED = sed
ERB = erb
REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g'
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
AWK = awk
SED ?= sed
ERB ?= erb
AWK ?= awk
# Parallel support macros
PG_CONFIG = pg_config
PG_CONFIG ?= pg_config
PG_PARALLEL := $(shell $(PG_CONFIG) --version | ($(AWK) '{$$2*=1000; if ($$2 >= 9600) print 1; else print 0;}' 2> /dev/null || echo 0))
# PG12 compatibility
PG_VERSION := $(shell $(PG_CONFIG) --version | $(AWK) '{split($$2,a,"."); print a[1]}')
PG_12_GE := $(shell [ $(PG_VERSION) -ge 12 ] && echo true)
PLPYTHONU := plpythonu
POSTGIS := postgis
ifeq ($(PG_12_GE), true)
PLPYTHONU := plpython3u
POSTGIS := postgis, postgis_raster
endif
REPLACEMENTS = -e 's/@@EXTVERSION@@/$(EXTVERSION)/g' -e 's/@@plpythonu@@/$(PLPYTHONU)/g' -e 's/@@postgis@@/$(POSTGIS)/g'
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
# OLD_VERSIONS = $(wildcard old_versions/*.sql)
# DATA = $(NEW_EXTENSION_ARTIFACT) \
# $(OLD_VERSIONS) \
@@ -25,9 +36,9 @@ DATA = $(NEW_EXTENSION_ARTIFACT) \
$(OLD_VERSIONS)
SOURCES_DATA_DIR = sql/
REGRESS = $(notdir $(basename $(sort $(wildcard test/sql/*test.sql))))
TEST_DIR = test/
REGRESS_EXPEC = $(notdir $(basename $(sort $(wildcard test/expected/*test.out))))
TEST_DIR = test
REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)' --user='postgres'
# DATA is a special variable used by postgres build infrastructure
@@ -43,7 +54,6 @@ TEMPLATE_FILES = $(wildcard $(TEMPLATE_DIR)/*.erb)
GENERATED_SQL_FILES = $(patsubst $(TEMPLATE_DIR)/%.erb, $(SOURCES_DATA_DIR)/%.sql, $(TEMPLATE_FILES))
# postgres build stuff
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
@@ -55,27 +65,20 @@ SOURCES_DATA = $(wildcard $(SOURCES_DATA_DIR)/*.sql) $(GENERATED_SQL_FILES)
$(NEW_EXTENSION_ARTIFACT): $(SOURCES_DATA)
rm -f $@
cat $(SOURCES_DATA_DIR)/*.sql >> $@
ifeq ($(PG_PARALLEL), 0)
# Remove PARALLEL in aggregates and functions
$(eval TMPFILE := $(shell mktemp /tmp/$(basename $0).XXXXXXXX))
$(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' \
-e 's/PARALLEL [A-Z]*/''/g' $@ > $(TMPFILE)
mv $(TMPFILE) $@
endif
.PHONY: all
all: $(DATA)
.PHONY: release
release: $(EXTENSION).control $(SOURCES_DATA)
release: $(SOURCES_DATA)
test -n "$(NEW_VERSION)" # $$NEW_VERSION VARIABLE MISSING. Eg. make release NEW_VERSION=0.x.0
git mv *.sql old_versions
$(SED) $(REPLACEMENTS) $(EXTENSION).control
git add $(EXTENSION).control
cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql
git add $(EXTENSION)--$(NEW_VERSION).sql
$(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql
$(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql
$(SED) -i -e 's/^EXTVERSION =.*/EXTVERSION = $(NEW_VERSION)/g' Makefile
git add Makefile
@echo
@echo "Please review the file $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql and add any code needed to upgrade $(EXTVERSION) to $(NEW_VERSION)"
@echo "Please review the file $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql and add any code needed to downgrade $(NEW_VERSION) to $(EXTVERSION)"
@@ -87,19 +90,29 @@ devclean:
rm -f $(NEW_EXTENSION_ARTIFACT)
rm -f $(GENERATED_SQL_FILES)
# If needed remove PARALLEL tags from the release files
release_remove_parallel_deploy:
ifeq ($(PG_PARALLEL), 0)
# Replace variables (and PARALLEL tags if necessary) and deploy files
.PHONY: replace_variables_and_deploy
replace_variables_and_deploy: $(NEW_EXTENSION_ARTIFACT)
mkdir -p '$(DESTDIR)$(datadir)/extension/'; \
for n in $(wildcard old_versions/*.sql *.sql); do \
$(eval TMPFILE := $(shell mktemp /tmp/XXXXXXXXXX)) \
$(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' -e 's/PARALLEL [A-Z]*/''/g' $$n > $(TMPFILE); \
mv $(TMPFILE) $$n; \
if [ "$(PG_PARALLEL)" -eq "0" ]; then \
$(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' -e 's/PARALLEL [A-Z]*/''/g' $$n > $(TMPFILE); \
mv $(TMPFILE) $$n; \
fi; \
$(SED) $(REPLACEMENTS) $$n > $(TMPFILE); \
mv $(TMPFILE) '$(DESTDIR)$(datadir)/extension/'$$(basename $$n); \
done
endif
.PHONY: $(EXTENSION).control
$(EXTENSION).control:
$(SED) $(REPLACEMENTS) $(EXTENSION).control.in > $(EXTENSION).control
# Install the current release into the PostgreSQL extensions directory
deploy: release_remove_parallel_deploy
.PHONY: deploy
deploy: replace_variables_and_deploy $(EXTENSION).control
$(INSTALL_DATA) $(EXTENSION).control '$(DESTDIR)$(datadir)/extension/'
$(INSTALL_DATA) old_versions/*.sql *.sql '$(DESTDIR)$(datadir)/extension/'
.PHONY: install
install: deploy
@echo "Install overriden"

View File

@@ -37,7 +37,7 @@ psql -U postgres cartodb_dev_user_fe3b850a-01c0-48f9-8a26-a82f09e9b53f_db
and then:
```sql
CREATE EXTENSION cdb_dataservices_client;
CREATE EXTENSION cdb_dataservices_client CASCADE;
```
The extension creation in the user's db requires **superuser** privileges.

12
client/carto-package.json Normal file
View File

@@ -0,0 +1,12 @@
{
"name": "dataservices-api-client-extension",
"current_version": {
"requires": {
"postgresql": "^11.0.0",
"postgis": "^2.5.0.0",
"carto_postgresql_ext": "^0.36.0"
},
"works_with": {
}
}
}

View File

@@ -0,0 +1,187 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.31.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_get_demographic_snapshot(geom public.geometry(Geometry, 4326), time_span text, geometry_level text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_get_demographic_snapshot_exception_safe(geom public.geometry(Geometry, 4326), time_span text, geometry_level text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_get_segment_snapshot(geom public.geometry(Geometry, 4326), geometry_level text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_get_segment_snapshot_exception_safe(geom public.geometry(Geometry, 4326), geometry_level text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getdemographicsnapshot(geom public.geometry(Geometry, 4326), time_span text, geometry_level text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getdemographicsnapshot_exception_safe(geom public.geometry(Geometry, 4326), time_span text, geometry_level text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getsegmentsnapshot(geom public.geometry(Geometry, 4326), geometry_level text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getsegmentsnapshot_exception_safe(geom public.geometry(Geometry, 4326), geometry_level text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getboundary(geom public.geometry(Geometry, 4326), boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getboundary_exception_safe(geom public.geometry(Geometry, 4326), boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getboundaryid(geom public.geometry(Geometry, 4326), boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getboundaryid_exception_safe(geom public.geometry(Geometry, 4326), boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getboundarybyid(geometry_id text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getboundarybyid_exception_safe(geometry_id text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getboundariesbygeometry(geom public.geometry(Geometry, 4326), boundary_id text, time_span text, overlap_type text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getboundariesbygeometry_exception_safe(geom public.geometry(Geometry, 4326), boundary_id text, time_span text, overlap_type text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getboundariesbypointandradius(geom public.geometry(Geometry, 4326), radius numeric, boundary_id text, time_span text, overlap_type text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getboundariesbypointandradius_exception_safe(geom public.geometry(Geometry, 4326), radius numeric, boundary_id text, time_span text, overlap_type text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getpointsbygeometry(geom public.geometry(Geometry, 4326), boundary_id text, time_span text, overlap_type text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getpointsbygeometry_exception_safe(geom public.geometry(Geometry, 4326), boundary_id text, time_span text, overlap_type text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getpointsbypointandradius(geom public.geometry(Geometry, 4326), radius numeric, boundary_id text, time_span text, overlap_type text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getpointsbypointandradius_exception_safe(geom public.geometry(Geometry, 4326), radius numeric, boundary_id text, time_span text, overlap_type text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getmeasure(geom public.Geometry, measure_id text, normalize text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getmeasure_exception_safe(geom public.Geometry, measure_id text, normalize text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getmeasurebyid(geom_ref text, measure_id text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getmeasurebyid_exception_safe(geom_ref text, measure_id text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getdata(geomvals geomval[], params json, merge boolean) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getdata_exception_safe(geomvals geomval[], params json, merge boolean ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getdata(geomrefs text[], params json) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getdata_exception_safe(geomrefs text[], params json ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getmeta(geom_ref public.Geometry(Geometry, 4326), params json, max_timespan_rank integer, max_score_rank integer, target_geoms integer) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getmeta_exception_safe(geom_ref public.Geometry(Geometry, 4326), params json, max_timespan_rank integer, max_score_rank integer, target_geoms integer ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_metadatavalidation(geom_extent public.Geometry(Geometry, 4326), geom_type text, params json, target_geoms integer) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_metadatavalidation_exception_safe(geom_extent public.Geometry(Geometry, 4326), geom_type text, params json, target_geoms integer ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getcategory(geom public.Geometry, category_id text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getcategory_exception_safe(geom public.Geometry, category_id text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getuscensusmeasure(geom public.Geometry, name text, normalize text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getuscensusmeasure_exception_safe(geom public.Geometry, name text, normalize text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getuscensuscategory(geom public.Geometry, name text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getuscensuscategory_exception_safe(geom public.Geometry, name text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getpopulation(geom public.Geometry, normalize text, boundary_id text, time_span text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getpopulation_exception_safe(geom public.Geometry, normalize text, boundary_id text, time_span text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_search(search_term text, relevant_boundary text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_search_exception_safe(search_term text, relevant_boundary text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailableboundaries(geom public.Geometry, timespan text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getavailableboundaries_exception_safe(geom public.Geometry, timespan text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_dumpversion() FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_dumpversion_exception_safe( ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailablenumerators(bounds public.geometry(Geometry, 4326), filter_tags text[], denom_id text, geom_id text, timespan text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getavailablenumerators_exception_safe(bounds public.geometry(Geometry, 4326), filter_tags text[], denom_id text, geom_id text, timespan text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getnumerators(bounds public.geometry(Geometry, 4326), section_tags text[], subsection_tags text[], other_tags text[], ids text[], name text, denom_id text, geom_id text, timespan text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.__obs_getnumerators_exception_safe(bounds public.geometry(Geometry, 4326), section_tags text[], subsection_tags text[], other_tags text[], ids text[], name text, denom_id text, geom_id text, timespan text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailabledenominators(bounds public.geometry(Geometry, 4326), filter_tags text[], numer_id text, geom_id text, timespan text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getavailabledenominators_exception_safe(bounds public.geometry(Geometry, 4326), filter_tags text[], numer_id text, geom_id text, timespan text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailablegeometries(bounds public.geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, timespan text, number_geometries integer) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getavailablegeometries_exception_safe(bounds public.geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, timespan text, number_geometries integer ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailabletimespans(bounds public.geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, geom_id text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_getavailabletimespans_exception_safe(bounds public.geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, geom_id text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client.obs_legacybuildermetadata(aggregate_type text) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._obs_legacybuildermetadata_exception_safe(aggregate_type text ) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure(output_table_name text, params json) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure(table_name text, output_table_name text, params json) FROM publicuser;
REVOKE EXECUTE ON FUNCTION cdb_dataservices_client._OBS_PreCheck(source_query text, params JSON) FROM publicuser;
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_get_demographic_snapshot (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_get_segment_snapshot (geometry(Geometry, 4326), TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getdemographicsnapshot (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getsegmentsnapshot (geometry(Geometry, 4326), TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getboundary (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getboundaryid (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getboundarybyid (TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getboundariesbygeometry (geometry(Geometry, 4326), TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getboundariesbypointandradius (geometry(Geometry, 4326), NUMERIC, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getpointsbygeometry (geometry(Geometry, 4326), TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getpointsbypointandradius (geometry(Geometry, 4326), NUMERIC, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getmeasure (geometry, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getmeasurebyid (TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getdata (geomval[], JSON, BOOLEAN);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getdata (TEXT[], JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getmeta (geometry(Geometry, 4326), JSON, INTEGER, INTEGER, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_metadatavalidation (geometry(Geometry, 4326), TEXT, JSON, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getcategory (geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getuscensusmeasure (geometry, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getuscensuscategory (geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getpopulation (geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_search (TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailableboundaries (geometry, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_dumpversion ();
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailablenumerators (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getnumerators (geometry(Geometry, 4326), TEXT[], TEXT[], TEXT[], TEXT[], TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailabledenominators (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailablegeometries (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailabletimespans (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_legacybuildermetadata (TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure (TEXT, JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure (TEXT, TEXT, JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client.__DST_PrepareTableOBS_GetMeasure (TEXT, TEXT, TEXT, TEXT, TEXT, JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client.__DST_PopulateTableOBS_GetMeasure (TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client._DST_ConnectUserTable (TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._DST_GetReturnMetadata (TEXT, TEXT, TEXT, JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client._DST_FetchJoinFdwTableData (TEXT, TEXT, TEXT, TEXT, TEXT, JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client._DST_DisconnectUserTable (TEXT, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_get_demographic_snapshot_exception_safe (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_get_segment_snapshot_exception_safe (geometry(Geometry, 4326), TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdemographicsnapshot_exception_safe (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getsegmentsnapshot_exception_safe (geometry(Geometry, 4326), TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundary_exception_safe (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundaryid_exception_safe (geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundarybyid_exception_safe (TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundariesbygeometry_exception_safe (geometry(Geometry, 4326), TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundariesbypointandradius_exception_safe (geometry(Geometry, 4326), NUMERIC, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpointsbygeometry_exception_safe (geometry(Geometry, 4326), TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpointsbypointandradius_exception_safe (geometry(Geometry, 4326), NUMERIC, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasure_exception_safe (geometry, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasurebyid_exception_safe (TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdata_exception_safe (geomval[], JSON, BOOLEAN);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdata_exception_safe (TEXT[], JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeta_exception_safe (geometry(Geometry, 4326), JSON, INTEGER, INTEGER, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_metadatavalidation_exception_safe (geometry(Geometry, 4326), TEXT, JSON, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getcategory_exception_safe (geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getuscensusmeasure_exception_safe (geometry, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getuscensuscategory_exception_safe (geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpopulation_exception_safe (geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_search_exception_safe (TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailableboundaries_exception_safe (geometry, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_dumpversion_exception_safe ();
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablenumerators_exception_safe (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.__obs_getnumerators_exception_safe (geometry(Geometry, 4326), TEXT[], TEXT[], TEXT[], TEXT[], TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabledenominators_exception_safe (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablegeometries_exception_safe (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabletimespans_exception_safe (geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_legacybuildermetadata_exception_safe (TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_get_demographic_snapshot (TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_get_segment_snapshot (TEXT, TEXT, geometry(Geometry, 4326), TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdemographicsnapshot (TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getsegmentsnapshot (TEXT, TEXT, geometry(Geometry, 4326), TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundary (TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundaryid (TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundarybyid (TEXT, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundariesbygeometry (TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundariesbypointandradius (TEXT, TEXT, geometry(Geometry, 4326), NUMERIC, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpointsbygeometry (TEXT, TEXT, geometry(Geometry, 4326), TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpointsbypointandradius (TEXT, TEXT, geometry(Geometry, 4326), NUMERIC, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasure (TEXT, TEXT, geometry, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasurebyid (TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdata (TEXT, TEXT, geomval[], JSON, BOOLEAN);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdata (TEXT, TEXT, TEXT[], JSON);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeta (TEXT, TEXT, geometry(Geometry, 4326), JSON, INTEGER, INTEGER, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_metadatavalidation (TEXT, TEXT, geometry(Geometry, 4326), TEXT, JSON, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getcategory (TEXT, TEXT, geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getuscensusmeasure (TEXT, TEXT, geometry, TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getuscensuscategory (TEXT, TEXT, geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpopulation (TEXT, TEXT, geometry, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_search (TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailableboundaries (TEXT, TEXT, geometry, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_dumpversion (TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablenumerators (TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client.__obs_getnumerators (TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT[], TEXT[], TEXT[], TEXT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabledenominators (TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablegeometries (TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT, INTEGER);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabletimespans (TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_legacybuildermetadata (TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS cdb_dataservices_client._OBS_PreCheck (TEXT, JSON);
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_numerator;
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_denominator;
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_geometry;
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_timespan;
DROP TYPE IF EXISTS cdb_dataservices_client.ds_fdw_metadata;
DROP TYPE IF EXISTS cdb_dataservices_client.ds_return_metadata;
DELETE FROM pg_enum
WHERE enumlabel = 'observatory'
AND enumtypid = (
SELECT pg_type.oid
FROM pg_type INNER JOIN pg_namespace ON (pg_type.typnamespace = pg_namespace.oid)
WHERE pg_type.typname = 'service_type' AND pg_namespace.nspname = 'cdb_dataservices_client'
);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
comment = 'CartoDB dataservices client API extension'
default_version = '0.24.0'
requires = 'plproxy, cartodb'
default_version = '@@EXTVERSION@@'
requires = 'plproxy, cartodb, @@plpythonu@@, @@postgis@@'
superuser = true
schema = cdb_dataservices_client

View File

View File

View File

@@ -0,0 +1,276 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '<%= version %>'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
-- Taken from https://wiki.postgresql.org/wiki/Count_estimate
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_count_estimate(query text) RETURNS INTEGER AS
$func$
DECLARE
rec record;
ROWS INTEGER;
BEGIN
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP
ROWS := SUBSTRING(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)');
EXIT WHEN ROWS IS NOT NULL;
END LOOP;
RETURN ROWS;
END
$func$ LANGUAGE plpgsql;
-- Taken from https://stackoverflow.com/a/48013356/351721
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_jsonb_array_casttext(jsonb) RETURNS text[] AS $f$
SELECT array_agg(x) || ARRAY[]::text[] FROM jsonb_array_elements_text($1) t(x);
$f$ LANGUAGE sql IMMUTABLE;--
CREATE TYPE cdb_dataservices_client.geocoding AS (
cartodb_id integer,
the_geom geometry(Multipolygon,4326),
metadata jsonb
);
CREATE TYPE cdb_dataservices_client.service_quota_info_batch AS (
service cdb_dataservices_client.service_type,
monthly_quota NUMERIC,
used_quota NUMERIC,
soft_limit BOOLEAN,
provider TEXT,
max_batch_size NUMERIC
);
--
-- Public dataservices API function
--
-- These are the only ones with permissions to publicuser role
-- and should also be the only ones with SECURITY DEFINER
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point (searches jsonb)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
username text;
orgname text;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
RETURN QUERY SELECT * FROM cdb_dataservices_client.__cdb_bulk_geocode_street_point(username, orgname, searches);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
--
-- Public dataservices API function
--
-- These are the only ones with permissions to publicuser role
-- and should also be the only ones with SECURITY DEFINER
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch ()
RETURNS SETOF service_quota_info_batch AS $$
DECLARE
username text;
orgname text;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
RETURN QUERY SELECT * FROM cdb_dataservices_client._cdb_service_quota_info_batch(username, orgname);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
query_row_count integer;
enough_quota boolean;
remaining_quota integer;
max_batch_size integer;
cartodb_id_batch integer;
batches_n integer;
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
temp_table_name text;
BEGIN
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
INTO remaining_quota, max_batch_size
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
WHERE service = 'hires_geocoder';
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
IF batch_size IS NULL THEN
batch_size := max_batch_size;
ELSIF batch_size > max_batch_size THEN
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
END IF;
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
batch_size := MAX_SAFE_BATCH_SIZE;
END IF;
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
INTO query_row_count, batches_n;
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
query_row_count, query, country_column, state_column, city_column, street_column;
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
IF remaining_quota < query_row_count THEN
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
END IF;
RAISE DEBUG 'batches_n: %', batches_n;
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
'(cartodb_id integer, the_geom geometry(Multipolygon,4326), metadata jsonb)',
temp_table_name);
select
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
coalesce(state_column, ''''''), coalesce(country_column, '''''')
into street_column, city_column, state_column, country_column;
IF batches_n > 0 THEN
FOR cartodb_id_batch in 0..(batches_n - 1)
LOOP
EXECUTE format(
'WITH geocoding_data as (' ||
' SELECT ' ||
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
' floor((row_number() over () - 1)::float/$1) as batch' ||
' FROM (%s) _x' ||
') ' ||
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
'FROM geocoding_data ' ||
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
USING batch_size, cartodb_id_batch;
END LOOP;
END IF;
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
--
-- Exception-safe private DataServices API function
--
CREATE OR REPLACE FUNCTION cdb_dataservices_client.__cdb_bulk_geocode_street_point_exception_safe (searches jsonb)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
username text;
orgname text;
_returned_sqlstate TEXT;
_message_text TEXT;
_pg_exception_context TEXT;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
BEGIN
RETURN QUERY SELECT * FROM cdb_dataservices_client.__cdb_bulk_geocode_street_point(username, orgname, searches);
EXCEPTION
WHEN OTHERS THEN
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
_message_text = MESSAGE_TEXT,
_pg_exception_context = PG_EXCEPTION_CONTEXT;
RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context;
END;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
--
-- Exception-safe private DataServices API function
--
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_service_quota_info_batch_exception_safe ()
RETURNS SETOF service_quota_info_batch AS $$
DECLARE
username text;
orgname text;
_returned_sqlstate TEXT;
_message_text TEXT;
_pg_exception_context TEXT;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
BEGIN
RETURN QUERY SELECT * FROM cdb_dataservices_client._cdb_service_quota_info_batch(username, orgname);
EXCEPTION
WHEN OTHERS THEN
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
_message_text = MESSAGE_TEXT,
_pg_exception_context = PG_EXCEPTION_CONTEXT;
RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context;
END;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
DROP FUNCTION IF EXISTS cdb_dataservices_client.__cdb_bulk_geocode_street_point (username text, orgname text, searches jsonb);
CREATE OR REPLACE FUNCTION cdb_dataservices_client.__cdb_bulk_geocode_street_point (username text, orgname text, searches jsonb)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT * FROM cdb_dataservices_server._cdb_bulk_geocode_street_point (username, orgname, searches);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_service_quota_info_batch (username text, orgname text);
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_service_quota_info_batch (username text, orgname text)
RETURNS SETOF service_quota_info_batch AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT * FROM cdb_dataservices_server.cdb_service_quota_info_batch (username, orgname);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.__cdb_bulk_geocode_street_point_exception_safe(searches jsonb ) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch() TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_service_quota_info_batch_exception_safe( ) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point(query text, street_column text, city_column text, state_column text, country_column text, batch_size integer) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_count_estimate(query text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_jsonb_array_casttext(jsonb) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.__cdb_bulk_geocode_street_point (username text, orgname text, searches jsonb) TO publicuser;

View File

@@ -0,0 +1,29 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '<%= version %>'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_count_estimate(query text);
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_jsonb_array_casttext(jsonb);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_bulk_geocode_street_point (jsonb);
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_service_quota_info_batch();
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_bulk_geocode_street_point (text, text, text, text, text, integer);
DROP FUNCTION IF EXISTS cdb_dataservices_client.__cdb_bulk_geocode_street_point_exception_safe (jsonb);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_service_quota_info_batch_exception_safe ();
DROP FUNCTION IF EXISTS cdb_dataservices_client.__cdb_bulk_geocode_street_point (text, text, jsonb);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_service_quota_info_batch (text, text);
DROP TYPE IF EXISTS cdb_dataservices_client.service_quota_info_batch;
DROP TYPE IF EXISTS cdb_dataservices_client.geocoding;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.1'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
ALTER TYPE cdb_dataservices_client.geocoding ALTER ATTRIBUTE the_geom TYPE geometry(Point,4326);
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
query_row_count integer;
enough_quota boolean;
remaining_quota integer;
max_batch_size integer;
cartodb_id_batch integer;
batches_n integer;
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
temp_table_name text;
username text;
orgname text;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
INTO remaining_quota, max_batch_size
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
WHERE service = 'hires_geocoder';
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
IF batch_size IS NULL THEN
batch_size := max_batch_size;
ELSIF batch_size > max_batch_size THEN
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
END IF;
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
batch_size := MAX_SAFE_BATCH_SIZE;
END IF;
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
INTO query_row_count, batches_n;
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
query_row_count, query, country_column, state_column, city_column, street_column;
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
IF remaining_quota < query_row_count THEN
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
END IF;
RAISE DEBUG 'batches_n: %', batches_n;
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
temp_table_name);
select
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
coalesce(state_column, ''''''), coalesce(country_column, '''''')
into street_column, city_column, state_column, country_column;
IF batches_n > 0 THEN
FOR cartodb_id_batch in 0..(batches_n - 1)
LOOP
EXECUTE format(
'WITH geocoding_data as (' ||
' SELECT ' ||
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
' floor((row_number() over () - 1)::float/$1) as batch' ||
' FROM (%s) _x' ||
') ' ||
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
'FROM geocoding_data ' ||
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
USING batch_size, cartodb_id_batch;
END LOOP;
END IF;
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
ALTER TYPE cdb_dataservices_client.geocoding ALTER ATTRIBUTE the_geom TYPE geometry(MultiPolygon,4326);
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
query_row_count integer;
enough_quota boolean;
remaining_quota integer;
max_batch_size integer;
cartodb_id_batch integer;
batches_n integer;
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
temp_table_name text;
username text;
orgname text;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
INTO remaining_quota, max_batch_size
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
WHERE service = 'hires_geocoder';
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
IF batch_size IS NULL THEN
batch_size := max_batch_size;
ELSIF batch_size > max_batch_size THEN
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
END IF;
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
batch_size := MAX_SAFE_BATCH_SIZE;
END IF;
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
INTO query_row_count, batches_n;
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
query_row_count, query, country_column, state_column, city_column, street_column;
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
IF remaining_quota < query_row_count THEN
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
END IF;
RAISE DEBUG 'batches_n: %', batches_n;
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
'(cartodb_id integer, the_geom geometry(Multipolygon,4326), metadata jsonb)',
temp_table_name);
select
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
coalesce(state_column, ''''''), coalesce(country_column, '''''')
into street_column, city_column, state_column, country_column;
IF batches_n > 0 THEN
FOR cartodb_id_batch in 0..(batches_n - 1)
LOOP
EXECUTE format(
'WITH geocoding_data as (' ||
' SELECT ' ||
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
' floor((row_number() over () - 1)::float/$1) as batch' ||
' FROM (%s) _x' ||
') ' ||
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
'FROM geocoding_data ' ||
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
USING batch_size, cartodb_id_batch;
END LOOP;
END IF;
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;

View File

@@ -0,0 +1,96 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.2'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
query_row_count integer;
enough_quota boolean;
remaining_quota integer;
max_batch_size integer;
cartodb_id_batch integer;
batches_n integer;
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
temp_table_name text;
username text;
orgname text;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
INTO remaining_quota, max_batch_size
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
WHERE service = 'hires_geocoder';
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
IF batch_size IS NULL THEN
batch_size := max_batch_size;
ELSIF batch_size > max_batch_size THEN
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
END IF;
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
batch_size := MAX_SAFE_BATCH_SIZE;
END IF;
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
INTO query_row_count, batches_n;
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
query_row_count, query, country_column, state_column, city_column, street_column;
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
IF enough_quota IS NULL OR NOT enough_quota THEN
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
END IF;
RAISE DEBUG 'batches_n: %', batches_n;
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
temp_table_name);
select
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
coalesce(state_column, ''''''), coalesce(country_column, '''''')
into street_column, city_column, state_column, country_column;
IF batches_n > 0 THEN
FOR cartodb_id_batch in 0..(batches_n - 1)
LOOP
EXECUTE format(
'WITH geocoding_data as (' ||
' SELECT ' ||
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
' floor((row_number() over () - 1)::float/$1) as batch' ||
' FROM (%s) _x' ||
') ' ||
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
'FROM geocoding_data ' ||
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
USING batch_size, cartodb_id_batch;
END LOOP;
END IF;
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,96 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.1'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
query_row_count integer;
enough_quota boolean;
remaining_quota integer;
max_batch_size integer;
cartodb_id_batch integer;
batches_n integer;
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
temp_table_name text;
username text;
orgname text;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
INTO remaining_quota, max_batch_size
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
WHERE service = 'hires_geocoder';
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
IF batch_size IS NULL THEN
batch_size := max_batch_size;
ELSIF batch_size > max_batch_size THEN
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
END IF;
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
batch_size := MAX_SAFE_BATCH_SIZE;
END IF;
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
INTO query_row_count, batches_n;
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
query_row_count, query, country_column, state_column, city_column, street_column;
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
IF remaining_quota < query_row_count THEN
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
END IF;
RAISE DEBUG 'batches_n: %', batches_n;
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
'(cartodb_id integer, the_geom geometry(Point,4326), metadata jsonb)',
temp_table_name);
select
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
coalesce(state_column, ''''''), coalesce(country_column, '''''')
into street_column, city_column, state_column, country_column;
IF batches_n > 0 THEN
FOR cartodb_id_batch in 0..(batches_n - 1)
LOOP
EXECUTE format(
'WITH geocoding_data as (' ||
' SELECT ' ||
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
' floor((row_number() over () - 1)::float/$1) as batch' ||
' FROM (%s) _x' ||
') ' ||
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
'FROM geocoding_data ' ||
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
USING batch_size, cartodb_id_batch;
END LOOP;
END IF;
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;

View File

@@ -0,0 +1,8 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.27.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.26.2'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade

View File

@@ -0,0 +1,83 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.28.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocodio_geocode_street_point_exception_safe (searchtext text ,city text DEFAULT NULL ,state_province text DEFAULT NULL ,country text DEFAULT NULL)
RETURNS public.Geometry AS $$
DECLARE
ret public.Geometry;
username text;
orgname text;
_returned_sqlstate TEXT;
_message_text TEXT;
_pg_exception_context TEXT;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
BEGIN
SELECT cdb_dataservices_client._cdb_geocodio_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret; RETURN ret;
EXCEPTION
WHEN OTHERS THEN
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
_message_text = MESSAGE_TEXT,
_pg_exception_context = PG_EXCEPTION_CONTEXT;
RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context;
RETURN ret;
END;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE
SET search_path = pg_temp;
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocodio_geocode_street_point (username text, orgname text, searchtext text, city text, state_province text, country text);
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocodio_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
RETURNS Geometry AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT cdb_dataservices_server.cdb_geocodio_geocode_street_point (username, orgname, searchtext, city, state_province, country);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_geocodio_geocode_street_point (searchtext text ,city text ,state_province text ,country text);
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocodio_geocode_street_point (searchtext text ,city text DEFAULT NULL ,state_province text DEFAULT NULL ,country text DEFAULT NULL)
RETURNS public.Geometry AS $$
DECLARE
ret public.Geometry;
username text;
orgname text;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT cdb_dataservices_client._cdb_geocodio_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret; RETURN ret;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE
SET search_path = pg_temp;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocodio_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_geocodio_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text ) TO publicuser;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.27.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocodio_geocode_street_point_exception_safe;
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocodio_geocode_street_point;
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_geocodio_geocode_street_point;

View File

@@ -0,0 +1,19 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.29.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
-- PG12_DEPRECATED
-- Create geomval if it doesn't exist (in postgis 3+ it only exists in postgis_raster)
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'geomval') THEN
CREATE TYPE cdb_dataservices_client.geomval AS (
geom geometry,
val double precision
);
END IF;
END$$;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.28.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
-- PG12_DEPRECATED
-- Create geomval if it doesn't exist (in postgis 3+ it only exists in postgis_raster)
DO $$
BEGIN
DROP TYPE IF EXISTS cdb_dataservices_client.geomval RESTRICT;
END$$;

View File

@@ -0,0 +1,14 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.30.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
-- In 0.30.0 we removed cdb_dataservices_client.geomval and rely on postgis_raster if necessary
DO $$
BEGIN
DROP TYPE IF EXISTS cdb_dataservices_client.geomval RESTRICT;
END$$;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.29.0'" to load this file. \quit
-- Make sure we have a sane search path to create/update the extension
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
-- HERE goes your code to upgrade/downgrade
-- Create cdb_dataservices_client.geomval if it doesn't exist (in postgis 3+ it only exists in postgis_raster)
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'geomval') THEN
CREATE TYPE cdb_dataservices_client.geomval AS (
geom geometry,
val double precision
);
END IF;
END$$;

File diff suppressed because it is too large Load Diff

View File

@@ -1,77 +1,126 @@
---
- name: cdb_geocode_admin0_polygon
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: country_name, type: text }
- name: cdb_geocode_admin1_polygon
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: admin1_name, type: text }
- name: cdb_geocode_admin1_polygon
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: admin1_name, type: text }
- { name: country_name, type: text }
- name: cdb_geocode_namedplace_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: city_name, type: text}
- name: cdb_geocode_namedplace_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: city_name, type: text}
- { name: country_name, type: text}
- name: cdb_geocode_namedplace_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: city_name, type: text}
- { name: admin1_name, type: text}
- { name: country_name, type: text}
- name: cdb_geocode_postalcode_polygon
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: postal_code, type: text}
- { name: country_name, type: text}
- name: cdb_geocode_postalcode_polygon
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: postal_code, type: double precision}
- { name: country_name, type: text}
- name: cdb_geocode_postalcode_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: postal_code, type: text}
- { name: country_name, type: text}
- name: cdb_geocode_postalcode_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: postal_code, type: double precision}
- { name: country_name, type: text}
- name: cdb_geocode_ipaddress_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: ip_address, type: text}
- name: cdb_geocode_street_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
- { name: state_province, type: text, default: 'NULL'}
- { name: country, type: text, default: 'NULL'}
- name: _cdb_bulk_geocode_street_point
return_type: SETOF cdb_dataservices_client.geocoding
multi_row: true
multi_field: true
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searches, type: jsonb } # Array of JSON objects with id, address, city, state and country fields
- name: cdb_here_geocode_street_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
@@ -79,7 +128,10 @@
- { name: country, type: text, default: 'NULL'}
- name: cdb_google_geocode_street_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
@@ -87,7 +139,10 @@
- { name: country, type: text, default: 'NULL'}
- name: cdb_mapbox_geocode_street_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
@@ -95,7 +150,21 @@
- { name: country, type: text, default: 'NULL'}
- name: cdb_tomtom_geocode_street_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
- { name: state_province, type: text, default: 'NULL'}
- { name: country, type: text, default: 'NULL'}
- name: cdb_geocodio_geocode_street_point
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
@@ -103,7 +172,10 @@
- { name: country, type: text, default: 'NULL'}
- name: cdb_mapzen_geocode_street_point
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: geocoding
permission_error: Geocoding permission denied
params:
- { name: searchtext, type: text}
- { name: city, type: text, default: 'NULL'}
@@ -114,8 +186,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -124,8 +199,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -134,8 +212,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -144,8 +225,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -154,8 +238,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -164,8 +251,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -174,8 +264,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -184,8 +277,11 @@
return_type: SETOF cdb_dataservices_client.isoline
multi_row: true
multi_field: true
requires_permission: true
permission_name: isolines
permission_error: Isolines permission denied
params:
- { name: source, type: "geometry(Geometry, 4326)" }
- { name: source, type: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -193,9 +289,12 @@
- name: cdb_route_point_to_point
return_type: cdb_dataservices_client.simple_route
multi_field: true
requires_permission: true
permission_name: routing
permission_error: Routing permission denied
params:
- { name: origin, type: "geometry(Point, 4326)" }
- { name: destination, type: "geometry(Point, 4326)" }
- { name: origin, type: "public.geometry(Point, 4326)" }
- { name: destination, type: "public.geometry(Point, 4326)" }
- { name: mode, type: text }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
- { name: units, type: "text", default: "'kilometers'"}
@@ -203,308 +302,24 @@
- name: cdb_route_with_waypoints
return_type: cdb_dataservices_client.simple_route
multi_field: true
requires_permission: true
permission_name: routing
permission_error: Routing permission denied
params:
- { name: waypoints, type: "geometry(Point, 4326)[]" }
- { name: waypoints, type: "public.geometry(Point, 4326)[]" }
- { name: mode, type: text }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
- { name: units, type: "text", default: "'kilometers'"}
- name: obs_get_demographic_snapshot
return_type: json
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: time_span, type: "text", default: "'2009 - 2013'::text" }
- { name: geometry_level, type: text, default: 'NULL' }
- name: obs_get_segment_snapshot
return_type: json
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geometry_level, type: text, default: 'NULL' }
- name: obs_getdemographicsnapshot
return_type: SETOF JSON
multi_row: true
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: time_span, type: "text", default: 'NULL' }
- { name: geometry_level, type: text, default: 'NULL' }
- name: obs_getsegmentsnapshot
return_type: SETOF JSON
multi_row: true
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geometry_level, type: text, default: 'NULL' }
- name: obs_getboundary
return_type: Geometry
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getboundaryid
return_type: text
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getboundarybyid
return_type: Geometry
params:
- { name: geometry_id, type: text }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getboundariesbygeometry
return_type: TABLE(the_geom geometry, geom_refs text)
- name: cdb_service_quota_info
return_type: SETOF service_quota_info
multi_row: true
multi_field: true
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- { name: overlap_type, type: text, default: 'NULL'}
- name: obs_getboundariesbypointandradius
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: radius, type: numeric }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- { name: overlap_type, type: text, default: 'NULL'}
- name: obs_getpointsbygeometry
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- { name: overlap_type, type: text, default: 'NULL'}
- name: obs_getpointsbypointandradius
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: radius, type: numeric }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- { name: overlap_type, type: text, default: 'NULL'}
- name: obs_getmeasure
return_type: numeric
params:
- { name: geom, type: Geometry }
- { name: measure_id, type: text }
- { name: normalize, type: text, default: 'NULL'}
- { name: boundary_id, type: text, default: 'NULL' }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getmeasurebyid
return_type: numeric
params:
- { name: geom_ref, type: text }
- { name: measure_id, type: text }
- { name: boundary_id, type: text}
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getdata
return_type: TABLE(id int, data json)
multi_row: true
multi_field: true
table_fields:
- { name: id, type: integer }
- { name: data, type: json }
params:
- { name: geomvals, type: "geomval[]" }
- { name: params, type: json }
- { name: merge, type: boolean, default: true }
- name: obs_getdata
return_type: TABLE(id text, data json)
multi_row: true
multi_field: true
table_fields:
- { name: id, type: text }
- { name: data, type: json }
params:
- { name: geomrefs, type: "text[]" }
- { name: params, type: json }
- name: obs_getmeta
return_type: json
params:
- { name: geom_ref, type: "Geometry(Geometry, 4326)" }
- { name: params, type: json }
- { name: max_timespan_rank, type: integer, default: 'NULL' }
- { name: max_score_rank, type: integer, default: 'NULL' }
- { name: target_geoms, type: integer, default: 'NULL' }
- name: obs_metadatavalidation
return_type: TABLE(valid boolean, errors text[])
multi_row: true
multi_field: true
params:
- { name: geom_extent, type: "Geometry(Geometry, 4326)" }
- { name: geom_type, type: text }
- { name: params, type: json }
- { name: target_geoms, type: integer, default: 'NULL' }
- name: obs_getcategory
return_type: text
params:
- { name: geom, type: Geometry }
- { name: category_id, type: text }
- { name: boundary_id, type: text, default: 'NULL' }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getuscensusmeasure
return_type: numeric
params:
- { name: geom, type: Geometry }
- { name: name, type: text }
- { name: normalize, type: text, default: 'NULL'}
- { name: boundary_id, type: text, default: 'NULL' }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getuscensuscategory
return_type: text
params:
- { name: geom, type: Geometry }
- { name: name, type: text }
- { name: boundary_id, type: text, default: 'NULL' }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getpopulation
return_type: numeric
params:
- { name: geom, type: Geometry }
- { name: normalize, type: text, default: 'NULL'}
- { name: boundary_id, type: text, default: 'NULL' }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_search
return_type: TABLE(id text, description text, name text, aggregate text, source text)
multi_row: true
multi_field: true
table_fields:
- { name: id, type: text }
- { name: description, type: text }
- { name: name, type: text }
- { name: aggregate, type: text }
- { name: source, type: text }
params:
- { name: search_term, type: text }
- { name: relevant_boundary, type: text, default: 'NULL' }
- name: obs_getavailableboundaries
return_type: TABLE(boundary_id text, description text, time_span text, tablename text)
multi_row: true
multi_field: true
table_fields:
- { name: boundary_id, type: text }
- { name: description, type: text }
- { name: time_span, type: text }
- { name: tablename, type: text }
params:
- { name: geom, type: Geometry }
- { name: timespan, type: text, default: 'NULL'}
- name: obs_dumpversion
return_type: text
params:
- {}
- name: obs_getavailablenumerators
return_type: SETOF cdb_dataservices_client.obs_meta_numerator
multi_row: true
multi_field: true
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: filter_tags, type: "text[]", default: 'NULL' }
- { name: denom_id, type: text, default: 'NULL' }
- { name: geom_id, type: text, default: 'NULL' }
- { name: timespan, type: text, default: 'NULL'}
- name: _obs_getnumerators
return_type: SETOF cdb_dataservices_client.obs_meta_numerator
multi_row: true
multi_field: true
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: section_tags, type: "text[]", default: 'ARRAY[]::TEXT[]' }
- { name: subsection_tags, type: "text[]", default: 'ARRAY[]::TEXT[]' }
- { name: other_tags, type: "text[]", default: 'ARRAY[]::TEXT[]' }
- { name: ids, type: "text[]", default: 'ARRAY[]::TEXT[]' }
- { name: name, type: text, default: 'NULL' }
- { name: denom_id, type: text, default: "''" }
- { name: geom_id, type: text, default: "''" }
- { name: timespan, type: text, default: "''"}
- name: obs_getavailabledenominators
return_type: SETOF cdb_dataservices_client.obs_meta_denominator
multi_row: true
multi_field: true
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: filter_tags, type: "text[]", default: 'NULL' }
- { name: numer_id, type: text, default: 'NULL' }
- { name: geom_id, type: text, default: 'NULL' }
- { name: timespan, type: text, default: 'NULL'}
- name: obs_getavailablegeometries
return_type: SETOF cdb_dataservices_client.obs_meta_geometry
multi_row: true
multi_field: true
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: filter_tags, type: "text[]", default: 'NULL' }
- { name: numer_id, type: text, default: 'NULL' }
- { name: denom_id, type: text, default: 'NULL' }
- { name: timespan, type: text, default: 'NULL'}
- { name: number_geometries, type: integer, default: 'NULL'}
- name: obs_getavailabletimespans
return_type: SETOF cdb_dataservices_client.obs_meta_timespan
multi_row: true
multi_field: true
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: filter_tags, type: "text[]", default: 'NULL' }
- { name: numer_id, type: text, default: 'NULL' }
- { name: denom_id, type: text, default: 'NULL' }
- { name: geom_id, type: text, default: 'NULL'}
- name: obs_legacybuildermetadata
return_type: TABLE(name text, subsection json)
multi_row: true
multi_field: true
params:
- { name: aggregate_type, type: text, default: 'NULL' }
- name: cdb_service_quota_info
return_type: SETOF service_quota_info
- name: cdb_service_quota_info_batch
return_type: SETOF service_quota_info_batch
multi_row: true
multi_field: true
params:

View File

@@ -28,6 +28,18 @@ class SqlTemplateRenderer
@function_signature['return_type']
end
def requires_permission
@function_signature['requires_permission']
end
def permission_name
@function_signature['permission_name']
end
def permission_error
@function_signature['permission_error']
end
def multi_field
@function_signature['multi_field']
end

View File

@@ -9,11 +9,16 @@ RETURNS <%= return_type %> AS $$
DECLARE
<%= return_declaration if not multi_row %>
<%= user_org_declaration %>
<% unless superuser_function? -%>apikey_permissions json;<% end %>
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
<% unless requires_permission %>IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
<% unless superuser_function? -%>SELECT u, o INTO username, orgname FROM <%= DATASERVICES_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text);<% end %>
END IF;<% end %>
<% unless superuser_function? -%>SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
<% if requires_permission %>IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? '<%= permission_name %>' THEN
RAISE EXCEPTION '<%= permission_error %>' USING ERRCODE = '01007';
END IF;<% end %>
<% else %>SELECT u, o INTO username, orgname FROM <%= DATASERVICES_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text, p json);<% end %>
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
@@ -21,4 +26,5 @@ BEGIN
<% return_statement do %><%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= params(_with_user_org=true).join(', ') %>)<% end %>
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE
SET search_path = pg_temp;

View File

@@ -10,11 +10,16 @@ DECLARE
_returned_sqlstate TEXT;
_message_text TEXT;
_pg_exception_context TEXT;
<% unless superuser_function? -%>apikey_permissions json;<% end %>
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
<% unless requires_permission %>IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
<% unless superuser_function? -%>SELECT u, o INTO username, orgname FROM <%= DATASERVICES_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text);<% end %>
END IF;<% end %>
<% unless superuser_function? -%>SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
<% if requires_permission %>IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? '<%= permission_name %>' THEN
RAISE EXCEPTION '<%= permission_error %>';
END IF;<% end %>
<% else %>SELECT u, o INTO username, orgname FROM <%= DATASERVICES_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text, p json);<% end %>
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
@@ -32,4 +37,5 @@ BEGIN
<%= return_statement %>
END;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE
SET search_path = pg_temp;

20
client/sql/05_utils.sql Normal file
View File

@@ -0,0 +1,20 @@
-- Taken from https://wiki.postgresql.org/wiki/Count_estimate
CREATE FUNCTION cdb_dataservices_client.cdb_count_estimate(query text) RETURNS INTEGER AS
$func$
DECLARE
rec record;
ROWS INTEGER;
BEGIN
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP
ROWS := SUBSTRING(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)');
EXIT WHEN ROWS IS NOT NULL;
END LOOP;
RETURN ROWS;
END
$func$ LANGUAGE plpgsql;
-- Taken from https://stackoverflow.com/a/48013356/351721
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_jsonb_array_casttext(jsonb) RETURNS text[] AS $f$
SELECT array_agg(x) || ARRAY[]::text[] FROM jsonb_array_elements_text($1) t(x);
$f$ LANGUAGE sql IMMUTABLE;

View File

@@ -1,6 +1,7 @@
CREATE TYPE cdb_dataservices_client._entity_config AS (
username text,
organization_name text
organization_name text,
apikey_permissions json
);
--
@@ -13,25 +14,23 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
RETURNS record AS $$
DECLARE
result cdb_dataservices_client._entity_config;
apikey_config json;
is_organization boolean;
username text;
organization_name text;
organization_name text DEFAULT NULL;
BEGIN
SELECT cartodb.cdb_conf_getconf('api_keys_'||session_user) INTO apikey_config;
SELECT cartodb.cdb_conf_getconf('user_config')->'is_organization' INTO is_organization;
IF is_organization IS NULL THEN
RAISE EXCEPTION 'User must have user configuration in the config table';
ELSIF is_organization = TRUE THEN
SELECT nspname
FROM pg_namespace s
LEFT JOIN pg_roles r ON s.nspowner = r.oid
WHERE r.rolname = session_user INTO username;
SELECT cartodb.cdb_conf_getconf('user_config')->>'entity_name' INTO organization_name;
ELSE
SELECT cartodb.cdb_conf_getconf('user_config')->>'entity_name' INTO username;
organization_name = NULL;
END IF;
result.username = username;
result.username = apikey_config->>'username';
result.organization_name = organization_name;
result.apikey_permissions = apikey_config->'permissions';
RETURN result;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL SAFE;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL SAFE
SET search_path = pg_temp;

View File

@@ -4,28 +4,23 @@ CREATE TYPE cdb_dataservices_client.isoline AS (
the_geom geometry(Multipolygon,4326)
);
CREATE TYPE cdb_dataservices_client.geocoding AS (
cartodb_id integer,
the_geom geometry(Point,4326),
metadata jsonb
);
CREATE TYPE cdb_dataservices_client.simple_route AS (
shape geometry(LineString,4326),
length real,
duration integer
);
-- For the OBS_Meta functions
CREATE TYPE cdb_dataservices_client.obs_meta_numerator AS (numer_id text, numer_name text, numer_description text, numer_weight text, numer_license text, numer_source text, numer_type text, numer_aggregate text, numer_extra jsonb, numer_tags jsonb, valid_denom boolean, valid_geom boolean, valid_timespan boolean);
CREATE TYPE cdb_dataservices_client.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean);
CREATE TYPE cdb_dataservices_client.obs_meta_geometry AS (geom_id text, geom_name text, geom_description text, geom_weight text, geom_aggregate text, geom_license text, geom_source text, valid_numer boolean, valid_denom boolean, valid_timespan boolean, score numeric, numtiles bigint, notnull_percent numeric, numgeoms numeric, percentfill numeric, estnumgeoms numeric, meanmediansize numeric, geom_type text, geom_extra jsonb, geom_tags jsonb);
CREATE TYPE cdb_dataservices_client.obs_meta_timespan AS (timespan_id text, timespan_name text, timespan_description text, timespan_weight text, timespan_aggregate text, timespan_license text, timespan_source text, valid_numer boolean, valid_denom boolean, valid_geom boolean, timespan_type text, timespan_extra jsonb, timespan_tags jsonb);
-- For quotas and services configuration
CREATE TYPE cdb_dataservices_client.service_type AS ENUM (
'isolines',
'hires_geocoder',
'routing',
'observatory'
'routing'
);
CREATE TYPE cdb_dataservices_client.service_quota_info AS (
@@ -35,3 +30,12 @@ CREATE TYPE cdb_dataservices_client.service_quota_info AS (
soft_limit BOOLEAN,
provider TEXT
);
CREATE TYPE cdb_dataservices_client.service_quota_info_batch AS (
service cdb_dataservices_client.service_type,
monthly_quota NUMERIC,
used_quota NUMERIC,
soft_limit BOOLEAN,
provider TEXT,
max_batch_size NUMERIC
);

View File

@@ -1,275 +0,0 @@
CREATE TYPE cdb_dataservices_client.ds_fdw_metadata as (schemaname text, tabname text, servername text);
CREATE TYPE cdb_dataservices_client.ds_return_metadata as (colnames text[], coltypes text[]);
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure(
output_table_name text,
params json
) RETURNS boolean AS $$
DECLARE
username text;
user_db_role text;
orgname text;
user_schema text;
result boolean;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
SELECT session_user INTO user_db_role;
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument';
END IF;
IF orgname IS NULL OR orgname = '' OR orgname = '""' THEN
user_schema := 'public';
ELSE
user_schema := username;
END IF;
SELECT cdb_dataservices_client.__DST_PrepareTableOBS_GetMeasure(
username,
orgname,
user_db_role,
user_schema,
output_table_name,
params
) INTO result;
RETURN result;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure(
table_name text,
output_table_name text,
params json
) RETURNS boolean AS $$
DECLARE
username text;
user_db_role text;
orgname text;
dbname text;
user_schema text;
result boolean;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
SELECT session_user INTO user_db_role;
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument';
END IF;
IF orgname IS NULL OR orgname = '' OR orgname = '""' THEN
user_schema := 'public';
ELSE
user_schema := username;
END IF;
SELECT current_database() INTO dbname;
SELECT cdb_dataservices_client.__DST_PopulateTableOBS_GetMeasure(
username,
orgname,
user_db_role,
user_schema,
dbname,
table_name,
output_table_name,
params
) INTO result;
RETURN result;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PrepareTableOBS_GetMeasure(
username text,
orgname text,
user_db_role text,
user_schema text,
output_table_name text,
params json
) RETURNS boolean AS $$
function_name = 'OBS_GetMeasure'
# Obtain return types for augmentation procedure
ds_return_metadata = plpy.execute("SELECT colnames, coltypes "
"FROM cdb_dataservices_client._DST_GetReturnMetadata({username}::text, {orgname}::text, {function_name}::text, {params}::json);"
.format(
username=plpy.quote_nullable(username),
orgname=plpy.quote_nullable(orgname),
function_name=plpy.quote_literal(function_name),
params=plpy.quote_literal(params)
)
)
if ds_return_metadata[0]["colnames"]:
colnames_arr = ds_return_metadata[0]["colnames"]
coltypes_arr = ds_return_metadata[0]["coltypes"]
else:
raise Exception('Error retrieving OBS_GetMeasure metadata')
# Prepare column and type strings required in the SQL queries
columns_with_types_arr = [colnames_arr[i] + ' ' + coltypes_arr[i] for i in range(0,len(colnames_arr))]
columns_with_types = ','.join(columns_with_types_arr)
# Create a new table with the required columns
plpy.execute('CREATE TABLE "{schema}".{table_name} ( '
'cartodb_id int, the_geom geometry, {columns_with_types} '
');'
.format(schema=user_schema, table_name=output_table_name, columns_with_types=columns_with_types)
)
plpy.execute('ALTER TABLE "{schema}".{table_name} OWNER TO "{user}";'
.format(schema=user_schema, table_name=output_table_name, user=user_db_role)
)
return True
$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PopulateTableOBS_GetMeasure(
username text,
orgname text,
user_db_role text,
user_schema text,
dbname text,
table_name text,
output_table_name text,
params json
) RETURNS boolean AS $$
function_name = 'OBS_GetMeasure'
# Obtain return types for augmentation procedure
ds_return_metadata = plpy.execute(
"SELECT colnames, coltypes "
"FROM cdb_dataservices_client._DST_GetReturnMetadata({username}::text, {orgname}::text, {function_name}::text, {params}::json);" .format(
username=plpy.quote_nullable(username),
orgname=plpy.quote_nullable(orgname),
function_name=plpy.quote_literal(function_name),
params=plpy.quote_literal(params)))
if ds_return_metadata[0]["colnames"]:
colnames_arr = ds_return_metadata[0]["colnames"]
coltypes_arr = ds_return_metadata[0]["coltypes"]
else:
raise Exception('Error retrieving OBS_GetMeasure metadata')
# Prepare column and type strings required in the SQL queries
columns_with_types_arr = [
colnames_arr[i] +
' ' +
coltypes_arr[i] for i in range(
0,
len(colnames_arr))]
columns_with_types = ','.join(columns_with_types_arr)
aliased_colname_list = ','.join(
['result.' + name for name in colnames_arr])
# Instruct the OBS server side to establish a FDW
# The metadata is obtained as well in order to:
# - (a) be able to write the query to grab the actual data to be executed in the remote server via pl/proxy,
# - (b) be able to tell OBS to free resources when done.
ds_fdw_metadata = plpy.execute(
"SELECT schemaname, tabname, servername "
"FROM cdb_dataservices_client._DST_ConnectUserTable({username}::text, {orgname}::text, {user_db_role}::text, "
"{schema}::text, {dbname}::text, {table_name}::text);" .format(
username=plpy.quote_nullable(username),
orgname=plpy.quote_nullable(orgname),
user_db_role=plpy.quote_literal(user_db_role),
schema=plpy.quote_literal(user_schema),
dbname=plpy.quote_literal(dbname),
table_name=plpy.quote_literal(table_name)))
if ds_fdw_metadata[0]["schemaname"]:
server_schema = ds_fdw_metadata[0]["schemaname"]
server_table_name = ds_fdw_metadata[0]["tabname"]
server_name = ds_fdw_metadata[0]["servername"]
else:
raise Exception('Error connecting dataset via FDW')
# Create a new table with the required columns
plpy.execute(
'INSERT INTO "{schema}".{analysis_table_name} '
'SELECT ut.cartodb_id, ut.the_geom, {colname_list} '
'FROM "{schema}".{table_name} ut '
'LEFT JOIN _DST_FetchJoinFdwTableData({username}::text, {orgname}::text, {server_schema}::text, {server_table_name}::text, '
'{function_name}::text, {params}::json) '
'AS result ({columns_with_types}, cartodb_id int) '
'ON result.cartodb_id = ut.cartodb_id;' .format(
schema=user_schema,
analysis_table_name=output_table_name,
colname_list=aliased_colname_list,
table_name=table_name,
username=plpy.quote_nullable(username),
orgname=plpy.quote_nullable(orgname),
server_schema=plpy.quote_literal(server_schema),
server_table_name=plpy.quote_literal(server_table_name),
function_name=plpy.quote_literal(function_name),
params=plpy.quote_literal(params),
columns_with_types=columns_with_types))
# Wipe user FDW data from the server
wiped = plpy.execute(
"SELECT cdb_dataservices_client._DST_DisconnectUserTable({username}::text, {orgname}::text, {server_schema}::text, "
"{server_table_name}::text, {fdw_server}::text)" .format(
username=plpy.quote_nullable(username),
orgname=plpy.quote_nullable(orgname),
server_schema=plpy.quote_literal(server_schema),
server_table_name=plpy.quote_literal(server_table_name),
fdw_server=plpy.quote_literal(server_name)))
return True
$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_ConnectUserTable(
username text,
orgname text,
user_db_role text,
user_schema text,
dbname text,
table_name text
)RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_ConnectUserTable;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_GetReturnMetadata(
username text,
orgname text,
function_name text,
params json
) RETURNS cdb_dataservices_client.ds_return_metadata AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_GetReturnMetadata;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_FetchJoinFdwTableData(
username text,
orgname text,
table_schema text,
table_name text,
function_name text,
params json
) RETURNS SETOF record AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_FetchJoinFdwTableData;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_DisconnectUserTable(
username text,
orgname text,
table_schema text,
table_name text,
server_name text
) RETURNS boolean AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_DisconnectUserTable;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;

View File

@@ -0,0 +1,90 @@
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point (query text,
street_column text, city_column text default null, state_column text default null, country_column text default null, batch_size integer DEFAULT NULL)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
DECLARE
query_row_count integer;
enough_quota boolean;
remaining_quota integer;
max_batch_size integer;
cartodb_id_batch integer;
batches_n integer;
DEFAULT_BATCH_SIZE CONSTANT numeric := 100;
MAX_SAFE_BATCH_SIZE CONSTANT numeric := 5000;
temp_table_name text;
username text;
orgname text;
apikey_permissions json;
BEGIN
SELECT u, o, p INTO username, orgname, apikey_permissions FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
IF apikey_permissions IS NULL OR NOT apikey_permissions::jsonb ? 'geocoding' THEN
RAISE EXCEPTION 'Geocoding permission denied' USING ERRCODE = '01007';
END IF;
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT csqi.monthly_quota - csqi.used_quota AS remaining_quota, csqi.max_batch_size
INTO remaining_quota, max_batch_size
FROM cdb_dataservices_client.cdb_service_quota_info_batch() csqi
WHERE service = 'hires_geocoder';
RAISE DEBUG 'remaining_quota: %; max_batch_size: %', remaining_quota, max_batch_size;
IF batch_size IS NULL THEN
batch_size := max_batch_size;
ELSIF batch_size > max_batch_size THEN
RAISE EXCEPTION 'batch_size must be lower than %', max_batch_size + 1;
END IF;
IF batch_size > MAX_SAFE_BATCH_SIZE THEN
batch_size := MAX_SAFE_BATCH_SIZE;
END IF;
EXECUTE format('SELECT count(1), ceil(count(1)::float/%s) FROM (%s) _x', batch_size, query)
INTO query_row_count, batches_n;
RAISE DEBUG 'cdb_bulk_geocode_street_point --> query_row_count: %; query: %; country: %; state: %; city: %; street: %',
query_row_count, query, country_column, state_column, city_column, street_column;
SELECT cdb_dataservices_client.cdb_enough_quota('hires_geocoder', query_row_count) INTO enough_quota;
IF enough_quota IS NULL OR NOT enough_quota THEN
RAISE EXCEPTION 'Remaining quota: %. Estimated cost: %', remaining_quota, query_row_count;
END IF;
RAISE DEBUG 'batches_n: %', batches_n;
temp_table_name := 'bulk_geocode_street_' || md5(random()::text);
EXECUTE format('CREATE TEMPORARY TABLE %s ' ||
'(cartodb_id integer, the_geom public.geometry(Point,4326), metadata jsonb)',
temp_table_name);
select
coalesce(street_column, ''''''), coalesce(city_column, ''''''),
coalesce(state_column, ''''''), coalesce(country_column, '''''')
into street_column, city_column, state_column, country_column;
IF batches_n > 0 THEN
FOR cartodb_id_batch in 0..(batches_n - 1)
LOOP
EXECUTE format(
'WITH geocoding_data as (' ||
' SELECT ' ||
' json_build_object(''id'', cartodb_id, ''address'', %s, ''city'', %s, ''state'', %s, ''country'', %s) as data , ' ||
' floor((row_number() over () - 1)::float/$1) as batch' ||
' FROM (%s) _x' ||
') ' ||
'INSERT INTO %s SELECT (cdb_dataservices_client._cdb_bulk_geocode_street_point(jsonb_agg(data))).* ' ||
'FROM geocoding_data ' ||
'WHERE batch = $2', street_column, city_column, state_column, country_column, query, temp_table_name)
USING batch_size, cartodb_id_batch;
END LOOP;
END IF;
RETURN QUERY EXECUTE 'SELECT * FROM ' || quote_ident(temp_table_name);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE
SET search_path = pg_temp;

View File

@@ -1,54 +0,0 @@
CREATE OR REPLACE FUNCTION cdb_dataservices_client._OBS_PreCheck(
source_query text,
parameters json
) RETURNS boolean AS $$
DECLARE
errors text[];
validator_errors text[];
validator_error text;
valid boolean;
geoms record;
BEGIN
errors := (ARRAY[])::TEXT[];
FOR geoms IN EXECUTE format('SELECT ST_GeometryType(the_geom) as geom_type,
bool_and(st_isvalid(the_geom)) as valid,
avg(st_npoints(the_geom)) as avg_vertex,
ST_SetSRID(ST_Extent(the_geom), 4326) as extent,
count(*)::INT as numgeoms
FROM (%s) as _source
GROUP BY ST_GeometryType(the_geom)', source_query)
LOOP
IF geoms.geom_type NOT IN ('ST_Polygon', 'ST_MultiPolygon', 'ST_Point') THEN
errors := array_append(errors, format($data$'Geometry type %s not supported'$data$, geoms.geom_type));
END IF;
IF geoms.valid IS FALSE THEN
errors := array_append(errors, 'There are invalid geometries in the input data, please try to fix them');
END IF;
-- 1000 vertex for a geometry is a limit we have in the obs_getdata function. You can check here
-- https://github.com/CartoDB/observatory-extension/blob/1.6.0/src/pg/sql/41_observatory_augmentation.sql#L813
IF geoms.avg_vertex > 1000 THEN
errors := array_append(errors, 'The average number of vertices per geometry is greater than 1000, please try to simplify them');
END IF;
-- OBS specific part
EXECUTE 'SELECT valid, errors
FROM cdb_dataservices_client.OBS_MetadataValidation($1, $2, $3, $4)'
INTO valid, validator_errors
USING geoms.extent, geoms.geom_type, parameters, geoms.numgeoms;
IF valid is FALSE THEN
FOR validator_error IN EXECUTE 'SELECT unnest($1)' USING validator_errors
LOOP
errors := array_append(errors, validator_error);
END LOOP;
END IF;
END LOOP;
IF CARDINALITY(errors) > 0 THEN
RAISE EXCEPTION '%', errors;
END IF;
RETURN TRUE;
END;
$$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;

View File

@@ -1,3 +1,4 @@
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure(output_table_name text, params json) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure(table_name text, output_table_name text, params json) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._OBS_PreCheck(source_query text, params JSON) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_bulk_geocode_street_point(query text, street_column text, city_column text, state_column text, country_column text, batch_size integer) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_count_estimate(query text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_jsonb_array_casttext(jsonb) TO publicuser;

View File

@@ -1,30 +1,17 @@
-- Only show warning or error messages in the tests output
SET client_min_messages TO WARNING;
-- Install dependencies
CREATE EXTENSION postgis;
CREATE EXTENSION plpythonu;
CREATE EXTENSION cartodb;
CREATE EXTENSION plproxy;
-- Install the extension
CREATE EXTENSION cdb_dataservices_client;
-- Mock the server connection to point to this very test db
SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}');
\set ECHO none
cdb_conf_setconf
------------------
(1 row)
-- Mock the user configuration
SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}');
cdb_conf_setconf
------------------
(1 row)
-- Mock the server schema
CREATE SCHEMA cdb_dataservices_server;
-- Create a test user to check permissions
DROP ROLE IF EXISTS test_regular_user;
CREATE ROLE test_regular_user;
GRANT publicuser TO test_regular_user;
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_dataservices_client;
CREATE SCHEMA
DROP ROLE
CREATE ROLE
GRANT ROLE
ALTER ROLE

View File

@@ -9,7 +9,26 @@ BEGIN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_admin0_polygon('Spain');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_admin0_polygon('Spain');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_admin0_polygon('Spain');
NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (test_user, <NULL>, Spain)
cdb_geocode_admin0_polygon
@@ -17,3 +36,10 @@ NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regres
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -16,7 +16,30 @@ BEGIN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_admin1_polygon('California');
ERROR: Geocoding permission denied
SELECT cdb_geocode_admin1_polygon('California', 'United States');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_admin1_polygon('California');
ERROR: Geocoding permission denied
SELECT cdb_geocode_admin1_polygon('California', 'United States');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_admin1_polygon('California');
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California)
cdb_geocode_admin1_polygon
@@ -31,3 +54,10 @@ NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(4): [contrib_regres
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -0,0 +1,76 @@
\set VERBOSITY terse
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch() RENAME TO cdb_service_quota_info_batch_mocked;
CREATE FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch ()
RETURNS SETOF cdb_dataservices_client.service_quota_info_batch AS $$
SELECT 'hires_geocoder'::cdb_dataservices_client.service_type AS service, 0::NUMERIC AS monthly_quota, 0::NUMERIC AS used_quota, FALSE AS soft_limit, 'google' AS provider, 1::NUMERIC AS max_batch_size;
$$ LANGUAGE SQL;
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota_mocked;
CREATE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
RETURNS BOOLEAN as $$
SELECT FALSE;
$$ LANGUAGE SQL;
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point_mocked;
CREATE FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
BEGIN
RAISE NOTICE 'called with this searches: %', searches;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE SET search_path = pg_temp;
-- No permissions granted
-- Test bulk size not mandatory (it will get the optimal)
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
ERROR: Geocoding permission denied
-- Test quota check by mocking quota 0
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
-- Test bulk size not mandatory (it will get the optimal)
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
ERROR: Geocoding permission denied
-- Test quota check by mocking quota 0
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
-- Test bulk size not mandatory (it will get the optimal)
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
ERROR: Remaining quota: 0. Estimated cost: 1
-- Test quota check by mocking quota 0
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
ERROR: Remaining quota: 0. Estimated cost: 1
-- Check that when cdb_enough_quota returns true (ie. when soft_limit is set to true, even if not enough quota)
-- it is able to proceed with the bulk geocode
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
RETURNS BOOLEAN as $$
SELECT TRUE;
$$ LANGUAGE SQL;
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
NOTICE: called with this searches: [{"id": 1, "city": "", "state": "", "address": "Valladolid, Spain", "country": ""}]
cdb_bulk_geocode_street_point
-------------------------------
(0 rows)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
DROP FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point;
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point_mocked(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point;

View File

@@ -27,9 +27,39 @@ BEGIN
RETURN ret;
END;
$$ LANGUAGE 'plpgsql';
-- Use regular user role
SET ROLE test_regular_user;
-- Exercise the exception safe and the proxied functions
-- No permissions granted
SET ROLE test_regular_user; -- Use regular user role
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
ERROR: Geocoding permission denied
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
ERROR: Isolines permission denied
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
ERROR: Routing permission denied
-- No permissions granted but conf created
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": []}');
cdb_conf_setconf
------------------
(1 row)
SET ROLE test_regular_user; -- Use regular user role
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
ERROR: Geocoding permission denied
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
ERROR: Isolines permission denied
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
ERROR: Routing permission denied
-- Grant geocoding permissions
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding", "routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SET ROLE test_regular_user; -- Use regular user role
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
WARNING: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE ERROR: Not enough quota or any other exception whatsoever.
_cdb_geocode_street_point_exception_safe
@@ -50,3 +80,11 @@ WARNING: cdb_dataservices_client._cdb_route_point_to_point(7): [contrib_regress
| |
(1 row)
-- Remove permissions
SET ROLE postgres;
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -23,7 +23,34 @@ BEGIN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_namedplace_point('Elx');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_namedplace_point('Elx');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_namedplace_point('Elx');
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx)
cdb_geocode_namedplace_point
@@ -45,3 +72,10 @@ NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(5): [contrib_regr
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -16,7 +16,30 @@ BEGIN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (test_user, <NULL>, 03204, Spain)
cdb_geocode_postalcode_polygon
@@ -31,3 +54,10 @@ NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_point(4): [contrib_regr
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -9,7 +9,26 @@ BEGIN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
NOTICE: cdb_dataservices_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (test_user, <NULL>, 8.8.8.8)
cdb_geocode_ipaddress_point
@@ -17,3 +36,10 @@ NOTICE: cdb_dataservices_client._cdb_geocode_ipaddress_point(3): [contrib_regre
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -9,7 +9,62 @@ BEGIN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_street_point('One street, 1');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street, 1');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
ERROR: Geocoding permission denied
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_street_point('One street, 1');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street, 1');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
ERROR: Geocoding permission denied
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_geocode_street_point('One street, 1');
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, 1, <NULL>, <NULL>, <NULL>)
cdb_geocode_street_point
@@ -80,3 +135,10 @@ NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regressi
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -22,7 +22,46 @@ BEGIN
RETURN ret;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied functions
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
ERROR: Routing permission denied
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
ERROR: Routing permission denied
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY[]::text[], 'miles');
ERROR: Routing permission denied
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car');
ERROR: Routing permission denied
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY['mode_type=shortest']::text[]);
ERROR: Routing permission denied
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY[]::text[], 'miles');
ERROR: Routing permission denied
-- Grant other permissions but routing
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
ERROR: Routing permission denied
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
ERROR: Routing permission denied
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY[]::text[], 'miles');
ERROR: Routing permission denied
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car');
ERROR: Routing permission denied
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY['mode_type=shortest']::text[]);
ERROR: Routing permission denied
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY[]::text[], 'miles');
ERROR: Routing permission denied
-- Grant routing permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
NOTICE: cdb_dataservices_client._cdb_route_point_to_point(7): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_route_point_to_point invoked with params (test_user, <NULL>, 0101000000D53E1D8F19F455C0185B087250F24440, 0101000000465F419AB1F255C0D8B628B341EE4440, car, {}, kilometers)
cdb_route_point_to_point
@@ -65,3 +104,10 @@ NOTICE: cdb_dataservices_client._cdb_route_with_waypoints(6): [contrib_regressi
(,2.22,500)
(1 row)
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

File diff suppressed because one or more lines are too long

View File

@@ -1,65 +0,0 @@
-- Add to the search path the schema
SET search_path TO public,cartodb,cdb_dataservices_client;
CREATE TABLE my_table(cartodb_id int);
INSERT INTO my_table (cartodb_id) VALUES (1);
-- Mock the server functions
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text)
RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$
BEGIN
RETURN ('dummy_schema'::text, 'dummy_table'::text, 'dummy_server'::text);
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_GetReturnMetadata(username text, orgname text, function_name text, params json)
RETURNS cdb_dataservices_client.ds_return_metadata AS $$
BEGIN
RETURN (Array['total_pop'], Array['double precision']);
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json)
RETURNS RECORD AS $$
BEGIN
RETURN (23.4::double precision, 1::int);
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text)
RETURNS boolean AS $$
BEGIN
RETURN true;
END;
$$ LANGUAGE 'plpgsql';
-- Create a sample user table
CREATE TABLE user_table (cartodb_id int, the_geom geometry);
INSERT INTO user_table(cartodb_id, the_geom) VALUES (1, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (2, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (3, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
-- Prepare a table with the total_pop column
SELECT cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure('my_table_dst', '{"dummy":"dummy"}'::json);
_dst_preparetableobs_getmeasure
---------------------------------
t
(1 row)
-- The table should now exist and be empty
SELECT * FROM my_table_dst;
cartodb_id | the_geom | total_pop
------------+----------+-----------
(0 rows)
-- Populate the table with measurement data
SELECT cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure('user_table', 'my_table_dst', '{"dummy":"dummy"}'::json);
_dst_populatetableobs_getmeasure
----------------------------------
t
(1 row)
-- The table should now show the results
SELECT * FROM my_table_dst;
cartodb_id | the_geom | total_pop
------------+----------------------------------------------------+-----------
1 | 0101000020E6100000F74FC902E07D52C05FE24CC7654B4440 | 23.4
2 | 0101000020E6100000F74FC902E07D52C05FE24CC7654B4440 |
3 | 0101000020E6100000F74FC902E07D52C05FE24CC7654B4440 |
(3 rows)
-- Clean tables
DROP TABLE my_table_dst;

View File

@@ -3,8 +3,94 @@
SET ROLE test_regular_user;
-- Add to the search path the schema
SET search_path TO public,cartodb,cdb_dataservices_client;
-- Exercise the public function
-- it is public, it shall work
-- Check the regular user has no permissions on private functions
SELECT _cdb_geocode_admin0_polygon('evil_user', 'evil_orgname', 'Hell');
ERROR: permission denied for function _cdb_geocode_admin0_polygon
SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Hell');
ERROR: permission denied for function _cdb_geocode_admin1_polygon
SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Sheol', 'Hell');
ERROR: permission denied for function _cdb_geocode_admin1_polygon
SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol');
ERROR: permission denied for function _cdb_geocode_namedplace_point
SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell');
ERROR: permission denied for function _cdb_geocode_namedplace_point
SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell', 'Ugly world');
ERROR: permission denied for function _cdb_geocode_namedplace_point
SELECT _cdb_geocode_postalcode_polygon('evil_user', 'evil_orgname', '66666', 'Hell');
ERROR: permission denied for function _cdb_geocode_postalcode_polygon
SELECT _cdb_geocode_postalcode_point('evil_user', 'evil_orgname', '66666', 'Hell');
ERROR: permission denied for function _cdb_geocode_postalcode_point
SELECT _cdb_geocode_ipaddress_point('evil_user', 'evil_orgname', '8.8.8.8');
ERROR: permission denied for function _cdb_geocode_ipaddress_point
SELECT _cdb_geocode_street_point('evil_user', 'evil_orgname', 'one street, 1');
ERROR: permission denied for function _cdb_geocode_street_point
SELECT _cdb_route_point_to_point('evil_user', 'evil_orgname', 'POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
ERROR: permission denied for function _cdb_route_point_to_point
-- -- Exercise the public function
-- -- it is public, it shall work
-- No permissions granted
SELECT cdb_geocode_admin0_polygon('Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_admin1_polygon('California');
ERROR: Geocoding permission denied
SELECT cdb_geocode_admin1_polygon('California', 'United States');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('one street, 1');
ERROR: Geocoding permission denied
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
ERROR: Routing permission denied
-- Grant other permissions but geocoding and routing
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SET ROLE test_regular_user; -- Use regular user role
SELECT cdb_geocode_admin0_polygon('Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_admin1_polygon('California');
ERROR: Geocoding permission denied
SELECT cdb_geocode_admin1_polygon('California', 'United States');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
ERROR: Geocoding permission denied
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
ERROR: Geocoding permission denied
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
ERROR: Geocoding permission denied
SELECT cdb_geocode_street_point('one street, 1');
ERROR: Geocoding permission denied
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
ERROR: Routing permission denied
-- Grant geocoding permissions
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding", "routing"]}');
cdb_conf_setconf
------------------
(1 row)
SET ROLE test_regular_user; -- Use regular user role
SELECT cdb_geocode_admin0_polygon('Spain');
NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (test_user, <NULL>, Spain)
cdb_geocode_admin0_polygon
@@ -82,26 +168,11 @@ NOTICE: cdb_dataservices_client._cdb_route_point_to_point(7): [contrib_regressi
(,5.33,100)
(1 row)
-- Check the regular user has no permissions on private functions
SELECT _cdb_geocode_admin0_polygon('evil_user', 'evil_orgname', 'Hell');
ERROR: permission denied for function _cdb_geocode_admin0_polygon
SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Hell');
ERROR: permission denied for function _cdb_geocode_admin1_polygon
SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Sheol', 'Hell');
ERROR: permission denied for function _cdb_geocode_admin1_polygon
SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol');
ERROR: permission denied for function _cdb_geocode_namedplace_point
SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell');
ERROR: permission denied for function _cdb_geocode_namedplace_point
SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell', 'Ugly world');
ERROR: permission denied for function _cdb_geocode_namedplace_point
SELECT _cdb_geocode_postalcode_polygon('evil_user', 'evil_orgname', '66666', 'Hell');
ERROR: permission denied for function _cdb_geocode_postalcode_polygon
SELECT _cdb_geocode_postalcode_point('evil_user', 'evil_orgname', '66666', 'Hell');
ERROR: permission denied for function _cdb_geocode_postalcode_point
SELECT _cdb_geocode_ipaddress_point('evil_user', 'evil_orgname', '8.8.8.8');
ERROR: permission denied for function _cdb_geocode_ipaddress_point
SELECT _cdb_geocode_street_point('evil_user', 'evil_orgname', 'one street, 1');
ERROR: permission denied for function _cdb_geocode_street_point
SELECT _cdb_route_point_to_point('evil_user', 'evil_orgname', 'POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
ERROR: permission denied for function _cdb_route_point_to_point
-- Remove permissions
SET ROLE postgres;
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -1,13 +1,13 @@
-- Only show warning or error messages in the tests output
\set ECHO none
\set QUIET on
SET client_min_messages TO WARNING;
-- Install dependencies
CREATE EXTENSION postgis;
CREATE EXTENSION plpythonu;
CREATE EXTENSION cartodb;
CREATE EXTENSION plproxy;
-- Install the extension
CREATE EXTENSION cdb_dataservices_client;
CREATE EXTENSION cdb_dataservices_client CASCADE;
\unset ECHO
\unset QUIET
-- Mock the server connection to point to this very test db
SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}');

View File

@@ -11,6 +11,18 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
-- -- Exercise the public and the proxied function
-- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_admin0_polygon('Spain');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT cdb_geocode_admin0_polygon('Spain');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
SELECT cdb_geocode_admin0_polygon('Spain');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -19,7 +19,21 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
-- -- Exercise the public and the proxied function
-- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -0,0 +1,60 @@
\set VERBOSITY terse
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch() RENAME TO cdb_service_quota_info_batch_mocked;
CREATE FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch ()
RETURNS SETOF cdb_dataservices_client.service_quota_info_batch AS $$
SELECT 'hires_geocoder'::cdb_dataservices_client.service_type AS service, 0::NUMERIC AS monthly_quota, 0::NUMERIC AS used_quota, FALSE AS soft_limit, 'google' AS provider, 1::NUMERIC AS max_batch_size;
$$ LANGUAGE SQL;
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota_mocked;
CREATE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
RETURNS BOOLEAN as $$
SELECT FALSE;
$$ LANGUAGE SQL;
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point_mocked;
CREATE FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb)
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
BEGIN
RAISE NOTICE 'called with this searches: %', searches;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE SET search_path = pg_temp;
-- No permissions granted
-- Test bulk size not mandatory (it will get the optimal)
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
-- Test quota check by mocking quota 0
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
-- Test bulk size not mandatory (it will get the optimal)
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
-- Test quota check by mocking quota 0
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
-- Test bulk size not mandatory (it will get the optimal)
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
-- Test quota check by mocking quota 0
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
-- Check that when cdb_enough_quota returns true (ie. when soft_limit is set to true, even if not enough quota)
-- it is able to proceed with the bulk geocode
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
RETURNS BOOLEAN as $$
SELECT TRUE;
$$ LANGUAGE SQL;
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
DROP FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point;
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point_mocked(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point;

View File

@@ -32,11 +32,30 @@ END;
$$ LANGUAGE 'plpgsql';
-- Use regular user role
SET ROLE test_regular_user;
-- Exercise the exception safe and the proxied functions
-- No permissions granted
SET ROLE test_regular_user; -- Use regular user role
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
-- No permissions granted but conf created
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": []}');
SET ROLE test_regular_user; -- Use regular user role
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
-- Grant geocoding permissions
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding", "routing", "isolines"]}');
SET ROLE test_regular_user; -- Use regular user role
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
-- Remove permissions
SET ROLE postgres;
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -27,8 +27,24 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -19,6 +19,21 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -12,5 +12,18 @@ END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -12,7 +12,9 @@ END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_geocode_street_point('One street, 1');
SELECT cdb_geocode_street_point('One street', 'city');
SELECT cdb_geocode_street_point('One street', 'city', 'state');
@@ -23,3 +25,32 @@ SELECT cdb_geocode_street_point('One street', 'city');
SELECT cdb_geocode_street_point('One street', 'city', 'state');
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
-- Grant other permissions but geocoding
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT cdb_geocode_street_point('One street, 1');
SELECT cdb_geocode_street_point('One street', 'city');
SELECT cdb_geocode_street_point('One street', 'city', 'state');
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
SELECT cdb_geocode_street_point('One street, 1');
SELECT cdb_geocode_street_point('One street', 'city');
SELECT cdb_geocode_street_point('One street', 'city', 'state');
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
-- Grant geocoding permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
SELECT cdb_geocode_street_point('One street, 1');
SELECT cdb_geocode_street_point('One street', 'city');
SELECT cdb_geocode_street_point('One street', 'city', 'state');
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
SELECT cdb_geocode_street_point('One street, 1');
SELECT cdb_geocode_street_point('One street', 'city');
SELECT cdb_geocode_street_point('One street', 'city', 'state');
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -28,12 +28,33 @@ END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied functions
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY[]::text[], 'miles');
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car');
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY['mode_type=shortest']::text[]);
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY[]::text[], 'miles');
-- Grant other permissions but routing
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding", "isolines"]}');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY[]::text[], 'miles');
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car');
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY['mode_type=shortest']::text[]);
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY[]::text[], 'miles');
-- Grant routing permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing"]}');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car', ARRAY[]::text[], 'miles');
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car');
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY['mode_type=shortest']::text[]);
SELECT cdb_route_with_waypoints(Array['POINT(-87.81406 41.89308)'::geometry,'POINT(-87.80406 41.87308)'::geometry,'POINT(-87.79209 41.86138)'::geometry], 'car', ARRAY[]::text[], 'miles');
-- Remove permissions
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

File diff suppressed because one or more lines are too long

View File

@@ -1,56 +0,0 @@
-- Add to the search path the schema
SET search_path TO public,cartodb,cdb_dataservices_client;
CREATE TABLE my_table(cartodb_id int);
INSERT INTO my_table (cartodb_id) VALUES (1);
-- Mock the server functions
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text)
RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$
BEGIN
RETURN ('dummy_schema'::text, 'dummy_table'::text, 'dummy_server'::text);
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_GetReturnMetadata(username text, orgname text, function_name text, params json)
RETURNS cdb_dataservices_client.ds_return_metadata AS $$
BEGIN
RETURN (Array['total_pop'], Array['double precision']);
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json)
RETURNS RECORD AS $$
BEGIN
RETURN (23.4::double precision, 1::int);
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text)
RETURNS boolean AS $$
BEGIN
RETURN true;
END;
$$ LANGUAGE 'plpgsql';
-- Create a sample user table
CREATE TABLE user_table (cartodb_id int, the_geom geometry);
INSERT INTO user_table(cartodb_id, the_geom) VALUES (1, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (2, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (3, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
-- Prepare a table with the total_pop column
SELECT cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure('my_table_dst', '{"dummy":"dummy"}'::json);
-- The table should now exist and be empty
SELECT * FROM my_table_dst;
-- Populate the table with measurement data
SELECT cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure('user_table', 'my_table_dst', '{"dummy":"dummy"}'::json);
-- The table should now show the results
SELECT * FROM my_table_dst;
-- Clean tables
DROP TABLE my_table_dst;

View File

@@ -5,20 +5,6 @@ SET ROLE test_regular_user;
-- Add to the search path the schema
SET search_path TO public,cartodb,cdb_dataservices_client;
-- Exercise the public function
-- it is public, it shall work
SELECT cdb_geocode_admin0_polygon('Spain');
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
SELECT cdb_geocode_street_point('one street, 1');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
-- Check the regular user has no permissions on private functions
SELECT _cdb_geocode_admin0_polygon('evil_user', 'evil_orgname', 'Hell');
SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Hell');
@@ -31,3 +17,54 @@ SELECT _cdb_geocode_postalcode_point('evil_user', 'evil_orgname', '66666', 'Hell
SELECT _cdb_geocode_ipaddress_point('evil_user', 'evil_orgname', '8.8.8.8');
SELECT _cdb_geocode_street_point('evil_user', 'evil_orgname', 'one street, 1');
SELECT _cdb_route_point_to_point('evil_user', 'evil_orgname', 'POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
-- -- Exercise the public function
-- -- it is public, it shall work
-- No permissions granted
SELECT cdb_geocode_admin0_polygon('Spain');
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
SELECT cdb_geocode_street_point('one street, 1');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
-- Grant other permissions but geocoding and routing
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["isolines"]}');
SET ROLE test_regular_user; -- Use regular user role
SELECT cdb_geocode_admin0_polygon('Spain');
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
SELECT cdb_geocode_street_point('one street, 1');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
-- Grant geocoding permissions
SET ROLE postgres;
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding", "routing"]}');
SET ROLE test_regular_user; -- Use regular user role
SELECT cdb_geocode_admin0_polygon('Spain');
SELECT cdb_geocode_admin1_polygon('California');
SELECT cdb_geocode_admin1_polygon('California', 'United States');
SELECT cdb_geocode_namedplace_point('Elx');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
SELECT cdb_geocode_street_point('one street, 1');
SELECT cdb_route_point_to_point('POINT(-87.81406 41.89308)'::geometry,'POINT(-87.79209 41.86138)'::geometry, 'car');
-- Remove permissions
SET ROLE postgres;
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -1,13 +0,0 @@
# Data Services API
The CARTO Data Services API offers a set of location based services that can be used programatically to empower your geospatial applications.
## Documentation
* [Overview](overview.md)
* [Geocoding Functions](geocoding_functions.md)
* [Isoline Functions](isoline_functions.md)
* [Routing Functions](routing_functions.md)
* [Demographic Functions](demographic_functions.md)
* [Segmentation Functions](segmentation_functions.md)
* [Quota Information](quota_information.md)

View File

@@ -1,155 +0,0 @@
# Demographic Functions
The Demographic Snapshot enables you to collect demographic reports around a point location. For example, you can take the coordinates of a coffee shop and find the average population characteristics, such as total population, educational attainment, housing and income information around that location. You can use raw street addresses by combining the Demographic Snapshot with CARTO's geocoding features. If you need help creating coordinates from addresses, see the [Geocoding Functions](https://carto.com/docs/carto-engine/dataservices-api/geocoding-functions/) documentation.
_**Note:** The Demographic Snapshot functions are only available for the United States._
## OBS_GetDemographicSnapshot( point geometry )
Fields returned include information about income, education, transportation, race, and more. Not all fields will have information for every coordinate queried.
### Arguments
Name | Description | Example Values
--- | --- | ---
point geometry | A point geometry. You can use the helper function, `CDB_LatLng` to quickly generate one from latitude and longitude | `CDB_LatLng(40.760410,-73.964242)`
### Returns
The Demographic Snapshot contains a broad subset of demographic measures in the Data Observatory. Over 80 measurements are returned by a single API request. For each demographic measure, the API returns the following values.
Value | Name | Tablename | Aggregate | Type | Description
----- | ---- | --------- | --------- | ---- |------------
The value of the measure at the point you requested | The name of the measure | The table it was drawn from | Indicated if the measure is a count or median. | postgresql | A description of the measure
For example the "Female Population" measure returns
```json
obs_getdemographicsnapshot: {
"value": 32.5395066379175,
"name": "Female Population",
"tablename": "obs_1a098da56badf5f32e336002b0a81708c40d29cd",
"aggregate": "sum",
"type": "Numeric",
"description": "The number of people within each geography who are female."
}
```
**For details, see the [Glossary of Demographic Measures](#glossary-of-demographic-measures).**
### Examples
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetDemographicSnapshot({{point geometry}})
```
##### Get the Geographic Snapshot of a Demographic
__Get the Demographic Snapshot at Camp David__
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetDemographicSnapshot(CDB_LatLng(39.648333, -77.465))
```
__Get the Demographic Snapshot in the Upper West Side__
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetDemographicSnapshot(CDB_LatLng(40.80, -73.960))
```
## Glossary of Demographic Measures
This list contains the demographic measures and response names for results from the ```OBS_GetDemographicSnapshot``` function.
Measure name | Measure Description | Response Mame | Response Units
--- | --- | --- | ---
Total Population | The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates. | total_pop | Count per sq. km
Male Population | The number of people within each geography who are male. | male_pop | Count per sq. km
Female Population | The number of people within each geography who are female.| female_pop | Count per sq. km
Population not Hispanic | The number of people not identifying as Hispanic or Latino in each geography. | not_hispanic_pop | Count per sq. km
White Population | The number of people identifying as white, non-Hispanic in each geography. | white_pop | Count per sq. km
Black or African American Population| The number of people identifying as black or African American, non-Hispanic in each geography. | black_pop | Count per sq. km
American Indian and Alaska Native Population | The number of people identifying as American Indian or Alaska native in each geography.| amerindian_pop| Count per sq. km
Asian Population | The number of people identifying as Asian, non-Hispanic in each geography.| asian_pop | Count per sq. km
Other Race population | The number of people identifying as another race in each geography. | other_race_pop | Count per sq. km
Two or more races population| The number of people identifying as two or more races in each geography | two_or_more_races_pop | Count per sq. km
Hispanic Population | The number of people identifying as Hispanic or Latino in each geography. | hispanic_pop | Count per sq. km
Not a U.S. Citizen Population | The number of people within each geography who indicated that they are not U.S. citizens. | not_us_citizen_pop | Count per sq. km
Median Age | The median age of all people in a given geographic area.| median_age | Years
Children under 18 Years of Age | The number of people within each geography who are under 18 years of age.| children | Count per sq. km
Population 15 Years and Over | The number of people in a geographic area who are over the age of 15. This is used mostly as a denominator of marital status. | pop_15_and_over | Count per sq. km
Population 3 Years and Over | The total number of people in each geography age 3 years and over. This denominator is mostly used to calculate rates of school enrollment. | population_3_years_over | Count per sq. km
Population 5 Years and Over | The number of people in a geographic area who are over the age of 5. This is primarily used as a denominator of measures of language spoken at home.| pop_5_years_over | Count per sq. km
Workers over the Age of 16 | The number of people in each geography who work. Workers include those employed at private for-profit companies, the self-employed, government workers and non-profit employees. | workers_16_and_over | Count per sq. km
Workers age 16 and over who do not work from home| The number of workers over the age of 16 who do not work from home in a geographic area| commuters_16_over | Count per sq. km
Commuters by Car, Truck, or Van | The number of workers age 16 years and over within a geographic area who primarily traveled to work by car, truck or van. This is the principal mode of travel or type of conveyance, by distance rather than time, that the worker usually used to get from home to work. | commuters_by_car_truck_van | Count per sq. km
Commuters who drove alone | The number of workers age 16 years and over within a geographic area who primarily traveled by car driving alone. This is the principal mode of travel or type of conveyance, by distance rather than time, that the worker usually used to get from home to work. | commuters_drove_alone | Count per sq. km
Commuters by Carpool| The number of workers age 16 years and over within a geographic area who primarily traveled to work by carpool. This is the principal mode of travel or type of conveyance, by distance rather than time, that the worker usually used to get from home to work. | commuters_by_carpool | Count per sq. km
Commuters by Public Transportation | The number of workers age 16 years and over within a geographic area who primarily traveled to work by public transportation. This is the principal mode of travel or type of conveyance, by distance rather than time, that the worker usually used to get from home to work. | commuters_by_public_transportation | Count per sq. km |
Commuters by Bus | The number of workers age 16 years and over within a geographic area who primarily traveled to work by bus. This is the principal mode of travel or type of conveyance, by distance rather than time, that the worker usually used to get from home to work. This is a subset of workers who commuted by public transport. | commuters_by_bus| Count per sq. km
Commuters by Subway or Elevated | The number of workers age 16 years and over within a geographic area who primarily traveled to work by subway or elevated train. This is the principal mode of travel or type of conveyance, by distance rather than time, that the worker usually used to get from home to work. This is a subset of workers who commuted by public transport. | commuters_by_subway_or_elevated | Count per sq. km
Walked to Work | The number of workers age 16 years and over within a geographic area who primarily walked to work. This would mean that of any way of getting to work, they travelled the most distance walking. | walked_to_work | Count per sq. km
Worked at Home | The count within a geographical area of workers over the age of 16 who worked at home. | worked_at_home | Count per sq. km
Number of workers with less than 10 minute commute | The number of workers over the age of 16 who do not work from home and commute in less than 10 minutes in a geographic area. | commute_less_10_mins | Count per sq. km
Number of workers with a commute between 10 and 14 minutes| The number of workers over the age of 16 who do not work from home and commute in between 10 and 14 minutes in a geographic area. | commute_10_14_mins | Count per sq. km
Number of workers with a commute between 15 and 19 minutes | The number of workers over the age of 16 who do not work from home and commute in between 15 and 19 minutes in a geographic area. | commute_15_19_mins | Count per sq. km
Number of workers with a commute between 20 and 24 minutes | The number of workers over the age of 16 who do not work from home and commute in between 20 and 24 minutes in a geographic area. | commute_20_24_mins | Count per sq. km
Number of workers with a commute between 25 and 29 minutes | The number of workers over the age of 16 who do not work from home and commute in between 25 and 29 minutes in a geographic area. | commute_25_29_mins| Count per sq. km
Number of workers with a commute between 30 and 34 minutes | The number of workers over the age of 16 who do not work from home and commute in between 30 and 34 minutes in a geographic area. | commute_30_34_mins | Count per sq. km
Number of workers with a commute between 35 and 44 minutes | The number of workers over the age of 16 who do not work from home and commute in between 35 and 44 minutes in a geographic area. | commute_35_44_mins | Count per sq. km
Number of workers with a commute between 45 and 59 minutes | The number of workers over the age of 16 who do not work from home and commute in between 45 and 59 minutes in a geographic area. | commute_45_59_mins | Count per sq. km
Number of workers with a commute of over 60 minutes | The number of workers over the age of 16 who do not work from home and commute in over 60 minutes in a geographic area.| commute_60_more_mins | Count per sq. km
Aggregate travel time to work | The total number of minutes every worker over the age of 16 who did not work from home spent spent commuting to work in one day in a geographic area. | aggregate_travel_time_to_work | Minutes
Households | A count of the number of households in each geography. A household consists of one or more people who live in the same dwelling and also share at meals or living accommodation, and may consist of a single family or some other grouping of people. | households | Count per sq. km
Never Married | The number of people in a geographic area who have never been married. | pop_never_married | Count per sq. km
Currently married| The number of people in a geographic area who are currently married. | pop_now_married | Count per sq. km
Married but separated | The number of people in a geographic area who are married but separated.| pop_separated | Count per sq. km
Widowed | The number of people in a geographic area who are widowed.| pop_widowed | Count per sq. km
Divorced | The number of people in a geographic area who are divorced. | pop_divorced | Count per sq. km
Students Enrolled in School | The total number of people in each geography currently enrolled at any level of school, from nursery or pre-school to advanced post-graduate education. Only includes those over the age of 3. | in_school | Count per sq. km
Students Enrolled in Grades 1 to 4 | The total number of people in each geography currently enrolled in grades 1 through 4 inclusive. This corresponds roughly to elementary school. | in_grades_1_to_4 | Count per sq. km
Students Enrolled in Grades 5 to 8 | The total number of people in each geography currently enrolled in grades 5 through 8 inclusive. This corresponds roughly to middle school. | in_grades_5_to_8 | Count per sq. km
Students Enrolled in Grades 9 to 12 | The total number of people in each geography currently enrolled in grades 9 through 12 inclusive. This corresponds roughly to high school. | in_grades_9_to_12 | Count per sq. km
Students Enrolled as Undergraduate in College | The number of people in a geographic area who are enrolled in college at the undergraduate level. Enrollment refers to being registered or listed as a student in an educational program leading to a college degree. This may be a public school or college, a private school or college. | in_undergrad_college | Count per sq. km
Population 25 Years and Over | The number of people in a geographic area who are over the age of 25. This is used mostly as a denominator of educational attainment. | pop_25_years_over | Count per sq. km
Population Completed High School | The number of people in a geographic area over the age of 25 who completed high school, and did not complete a more advanced degree. | high_school_diploma| Count per sq. km
Population completed less than one year of college, no degree | The number of people in a geographic area over the age of 25 who attended college for less than one year and no further. | less_one_year_college | Count per sq. km
Population completed more than one year of college, no degree | The number of people in a geographic area over the age of 25 who attended college for more than one year but did not obtain a degree. | one_year_more_college | Count per sq. km
Population Completed Associate's Degree | The number of people in a geographic area over the age of 25 who obtained a associate's degree, and did not complete a more advanced degree.| associates_degree | Count per sq. km
Population Completed Bachelor's Degree| The number of people in a geographic area over the age of 25 who obtained a bachelor's degree, and did not complete a more advanced degree. | bachelors_degree| Count per sq. km
Population Completed Master's Degree | The number of people in a geographic area over the age of 25 who obtained a master's degree, but did not complete a more advanced degree. | masters_degree | Count per sq. km
Speaks only English at Home | The number of people in a geographic area over age 5 who speak only English at home. | speak_only_english_at_home | Count per sq. km
Speaks Spanish at Home | The number of people in a geographic area over age 5 who speak Spanish at home, possibly in addition to other languages. | speak_spanish_at_home | Count per sq. km
Population for Whom Poverty Status Determined | The number of people in each geography who could be identified as either living in poverty or not. This should be used as the denominator when calculating poverty rates, as it excludes people for whom it was not possible to determine poverty. | pop_determined_poverty_status | Count per sq. km
Income In The Past 12 Months Below Poverty Level | The number of people in a geographic area who are part of a family (which could be just them as an individual) determined to be "in poverty" following the [Office of Management and Budget's Directive 14](https://www.census.gov/hhes/povmeas/methodology/ombdir14.html). | poverty | Count per sq. km
Households with income less than $10,000 | The number of households in a geographic area whose annual income was less than $10,000. | income_less_10000 | Count per sq. km
Households with income of $10,000 to $14,999 | The number of households in a geographic area whose annual income was between $10,000 and $14,999. | income_10000_14999 | Count per sq. km
Households with income of $15,000 to $19,999 | The number of households in a geographic area whose annual income was between $15,000 and $19,999. | income_15000_19999 | Count per sq. km
Households with income of $20,000 To $24,999 | The number of households in a geographic area whose annual income was between $20,000 and $24,999. | income_20000_24999 | Count per sq. km
Households with income of $25,000 To $29,999 | The number of households in a geographic area whose annual income was between $20,000 and $24,999. | income_25000_29999 | Count per sq. km
Households with income of $30,000 To $34,999 | The number of households in a geographic area whose annual income was between $30,000 and $34,999. | income_30000_34999 | Count per sq. km
Households with income of $35,000 To $39,999 | The number of households in a geographic area whose annual income was between $35,000 and $39,999. | income_35000_39999 | Count per sq. km
Households with income of $40,000 To $44,999 | The number of households in a geographic area whose annual income was between $40,000 and $44,999. | income_40000_44999| Count per sq. km
Households with income of $45,000 To $49,999 | The number of households in a geographic area whose annual income was between $45,000 and $49,999. | income_45000_49999 | Count per sq. km
Households with income of $50,000 To $59,999 | The number of households in a geographic area whose annual income was between $50,000 and $59,999. | income_50000_59999 | Count per sq. km
Households with income of $60,000 To $74,999 | The number of households in a geographic area whose annual income was between $60,000 and $74,999. | income_60000_74999 | Count per sq. km
Households with income of $75,000 To $99,999 | The number of households in a geographic area whose annual income was between $75,000 and $99,999. | income_75000_99999 | Count per sq. km
Households with income of $100,000 To $124,999 | The number of households in a geographic area whose annual income was between $100,000 and $124,999. | income_100000_124999 | Count per sq. km
Households with income of $125,000 To $149,999 | The number of households in a geographic area whose annual income was between $125,000 and $149,999. | income_125000_149999 | Count per sq. km
Households with income of $150,000 To $199,999 | The number of households in a geographic area whose annual income was between $150,000 and $1999,999. | income_150000_199999 | Count per sq. km
Households with income of $200,000 Or More | The number of households in a geographic area whose annual income was more than $200,000. | income_200000_or_more | Count per sq. km
Median Household Income in the past 12 Months | Within a geographic area, the median income received by every household on a regular basis before payments for personal income taxes, social security, union dues, medicare deductions, etc. It includes income received from wages, salary, commissions, bonuses, and tips; self-employment income from own nonfarm or farm businesses, including proprietorships and partnerships; interest, dividends, net rental income, royalty income, or income from estates and trusts; Social Security or Railroad Retirement income; Supplemental Security Income (SSI); any cash public assistance or welfare payments from the state or local welfare office; retirement, survivor, or disability benefits; and any other sources of income received regularly such as Veterans' (VA) payments, unemployment and/or worker's compensation, child support, and alimony. | median_income | USD
Per Capita Income in the past 12 Months | | income_per_capita | USD
Gini Index | A measurement of the income distribution of a country's residents. | gini_index | None
Housing Units | A count of housing units in each geography. A housing unit is a house, an apartment, a mobile home or trailer, a group of rooms, or a single room occupied as separate living quarters, or if vacant, intended for occupancy as separate living quarters. | housing_units | Count per sq. km
Vacant Housing Units | The count of vacant housing units in a geographic area. A housing unit is vacant if no one is living in it at the time of enumeration, unless its occupants are only temporarily absent. Units temporarily occupied at the time of enumeration entirely by people who have a usual residence elsewhere are also classified as vacant. | vacant_housing_units | Count per sq. km
Vacant Housing Units for Rent | The count of vacant housing units in a geographic area that are for rent. A housing unit is vacant if no one is living in it at the time of enumeration, unless its occupants are only temporarily absent. Units temporarily occupied at the time of enumeration entirely by people who have a usual residence elsewhere are also classified as vacant. | vacant_housing_units_for_rent | Count per sq. km
Vacant Housing Units for Sale| The count of vacant housing units in a geographic area that are for sale. A housing unit is vacant if no one is living in it at the time of enumeration, unless its occupants are only temporarily absent. Units temporarily occupied at the time of enumeration entirely by people who have a usual residence elsewhere are also classified as vacant. | vacant_housing_units_for_sale | Count per sq. km
Owner-occupied Housing Units | The count of owner occupied housing units in a geographic area. | owner_occupied_housing_units | Count per sq. km
Owner-occupied Housing Units valued at $1,000,000 or more. | The count of owner occupied housing units in a geographic area that are valued at $1,000,000 or more. Value is the respondent's estimate of how much the property (house and lot, mobile home and lot, or condominium unit) would sell for if it were for sale. | million_dollar_housing_units | Count per sq. km
Owner-occupied Housing Units with a Mortgage | The count of housing units within a geographic area that are mortagaged. "Mortgage" refers to all forms of debt where the property is pledged as security for repayment of the debt, including deeds of trust, trust deed, contracts to purchase, land contracts, junior mortgages, and home equity loans. | mortgaged_housing_units | Count per sq. km
Median Rent | The median contract rent within a geographic area. The contract rent is the monthly rent agreed to or contracted for, regardless of any furnishings, utilities, fees, meals, or services that may be included. For vacant units, it is the monthly rent asked for the rental unit at the time of interview.| median_rent | USD
Percent of Household Income Spent on Rent | Within a geographic area, the median percentage of household income which was spent on gross rent. Gross rent is the amount of the contract rent plus the estimated average monthly cost of utilities (electricity, gas, water, sewer etc.) and fuels (oil, coal, wood, etc.) if these are paid by the renter. Household income is the sum of the income of all people 15 years and older living in the household. | percent_income_spent_on_rent | Percent

View File

@@ -1,181 +0,0 @@
# Segmentation Functions
The Segmentation Snapshot functions enable you to determine the pre-calculated population segment for a location. Segmentation is a method that divides a populations into subclassifications based on common traits. For example, you can take the a store location and determine what classification of population exists around that location. If you need help creating coordinates from addresses, see the [Geocoding Functions](https://carto.com/docs/carto-engine/dataservices-api/geocoding-functions/) documentation.
_**Note:** The Segmentation Snapshot functions are only available for the United States. Our first release (May 18, 2016) is derived from Census 2010 variables. Our next release will be based on Census 2014 data. For the latest information, see the [Open Segments](https://github.com/CartoDB/open-segments) project repository._
## OBS_GetSegmentSnapshot( Point Geometry )
### Arguments
Name | Description | Example Values
--- | --- | ---
point geometry | A point geometry. You can use the helper function, `CDB_LatLng` to quickly generate one from latitude and longitude | `CDB_LatLng(40.760410,-73.964242)`
### Returns
The segmentation function returns two segment levels for the point you requests, the x10\_segment and x55\_segment. These segmentation levels contain different classifications of population within with each segment. The function also returns the quantile of a number of census variables. For example, if total_poulation is at 90% quantile level then this tract has a higher total population than 90% of the other tracts.
Name | Type | Description
---- | ---- | -----------
x10\_segment | text | The demographic segment location at the 10 segment level, containing populations at high-levels, broken down into 10 broad categories
x55\_segment | text | The demographic segment location at the 55 segment level, containing more granular sub-levels to categorize the population
An example response appears as follows:
```json
obs_getsegmentsnapshot: {
"x10_segment": "Wealthy, urban without Kids",
"x55_segment": "Wealthy city commuters",
"us.census.acs.B01001001_quantile": "0.0180540540540541",
"us.census.acs.B01001002_quantile": "0.0279864864864865",
"us.census.acs.B01001026_quantile": "0.016527027027027",
"us.census.acs.B01002001_quantile": "0.507297297297297",
"us.census.acs.B03002003_quantile": "0.133162162162162",
"us.census.acs.B03002004_quantile": "0.283743243243243",
"us.census.acs.B03002006_quantile": "0.683945945945946",
"us.census.acs.B03002012_quantile": "0.494594594594595",
"us.census.acs.B05001006_quantile": "0.670972972972973",
"us.census.acs.B08006001_quantile": "0.0607567567567568",
"us.census.acs.B08006002_quantile": "0.0684324324324324",
"us.census.acs.B08006008_quantile": "0.565135135135135",
"us.census.acs.B08006009_quantile": "0.638081081081081",
"us.census.acs.B08006011_quantile": "0",
"us.census.acs.B08006015_quantile": "0.900932432432432",
"us.census.acs.B08006017_quantile": "0.186648648648649",
"us.census.acs.B09001001_quantile": "0.0193513513513514",
"us.census.acs.B11001001_quantile": "0.0617972972972973",
"us.census.acs.B14001001_quantile": "0.0179594594594595",
"us.census.acs.B14001002_quantile": "0.0140405405405405",
"us.census.acs.B14001005_quantile": "0",
"us.census.acs.B14001006_quantile": "0",
"us.census.acs.B14001007_quantile": "0",
"us.census.acs.B14001008_quantile": "0.0609054054054054",
"us.census.acs.B15003001_quantile": "0.0314594594594595",
"us.census.acs.B15003017_quantile": "0.0403378378378378",
"us.census.acs.B15003022_quantile": "0.285972972972973",
"us.census.acs.B15003023_quantile": "0.214567567567568",
"us.census.acs.B16001001_quantile": "0.0181621621621622",
"us.census.acs.B16001002_quantile": "0.0463108108108108",
"us.census.acs.B16001003_quantile": "0.540540540540541",
"us.census.acs.B17001001_quantile": "0.0237567567567568",
"us.census.acs.B17001002_quantile": "0.155972972972973",
"us.census.acs.B19013001_quantile": "0.380662162162162",
"us.census.acs.B19083001_quantile": "0.986891891891892",
"us.census.acs.B19301001_quantile": "0.989594594594595",
"us.census.acs.B25001001_quantile": "0.998418918918919",
"us.census.acs.B25002003_quantile": "0.999824324324324",
"us.census.acs.B25004002_quantile": "0.999986486486486",
"us.census.acs.B25004004_quantile": "0.999662162162162",
"us.census.acs.B25058001_quantile": "0.679054054054054",
"us.census.acs.B25071001_quantile": "0.569716216216216",
"us.census.acs.B25075001_quantile": "0.0415",
"us.census.acs.B25075025_quantile": "0.891702702702703"
}
```
The possible segments are:
<table>
<tr><th> X10 segment</th> <th> X55 Segment </th></tr>
<tr><td> Hispanic and kids</td><td></td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #99C945'></div> Middle Class, Educated, Suburban, Mixed Race </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #a3ce57'></div> Low Income on Urban Periphery</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #add468'></div> Suburban, Young and Low-income </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #b7d978'></div> low-income, urban, young, unmarried </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #c1df88'></div> Low education, mainly suburban </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #cbe598'></div> Young, working class and rural </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #d5eba8'></div> Low-Income with gentrification </td></tr>
<tr><td>Low Income and Diverse</td><td></td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #52BCA3'></div> High school education Long Commuters, Black, White Hispanic mix</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #66c5ae'></div> Rural, Bachelors or college degree, Rent owned mix</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #79cdb7'></div> Rural,High School Education, Owns property</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #8bd5c1'></div> Young, City based renters in Sparse neighborhoods, Low poverty </td></tr>
<tr><td>Low income, minority mix</td><td></td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #5D69B1'></div> Predominantly black, high high school attainment, home owners </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #7b83c6'></div> White and minority mix multilingual, mixed income / education. Married </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #9095d2'></div> Hispanic Black mix multilingual, high poverty, renters, uses public transport</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #a3a7df'></div> Predominantly black renters, rent own mix </td></tr>
<tr><td>Middle income, single family homes</td><td></td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #E58606'></div> Lower Middle Income with higher rent burden </td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #f0983b'></div> Black and mixed community with rent burden</td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #f4a24e'></div> Lower Middle Income with affordable housing</td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #f8ab5f'></div> Relatively affordable, satisfied lower middle class</td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #fcb470'></div> Satisfied Lower Middle Income Higher Rent Costs</td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #ffbe81'></div> Suburban/Rural Satisfied, decently educated lower middle class</td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #ffc792'></div> Struggling lower middle class with rent burden</td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #ffd0a3'></div> Older white home owners, less comfortable financially </td></tr>
<tr><td></td> <td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #ffdab4'></div> Older home owners, more financially comfortable, some diversity</td></tr>
<tr><td>Native American</td><td></td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #2F8AC4'></div>Younger, poorer,single parent family Native Americans</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background: #77b8ee'></div>Older, middle income Native Americans once married and Educated </td></tr>
<tr><td>Old Wealthy, White</td><td></td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#24796C'></div> Older, mixed race professionals</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#388d7e'></div> Works from home, Highly Educated, Super Wealthy </td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#4ca191'></div> Retired Grandparents</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#60b5a5'></div> Wealthy and Rural Living</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#73c9b8'></div> Wealthy, Retired Mountains/Coasts</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#87decc'></div> Wealthy Diverse Suburbanites On the Coasts</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#9bf3e1'></div> Retirement Communitties</td></tr>
<tr><td>Low Income African American</td><td></td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#c23a7e'></div>Urban - Inner city</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#d86298'></div>Rural families</td></tr>
<tr><td>Residential institutions, young people</td><td></td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#764e9f'></div>College towns</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#8a64b1'></div>College town with poverty</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#9e7ac3'></div>University campus wider area</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#b491d5'></div>City Outskirt University Campuses</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#c9a8e8'></div>City Center University Campuses</td></tr>
<tr><td>Wealthy Nuclear Families</td><td></td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ed645a'></div>Lower educational attainment, Homeowner, Low rent</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ee7655'></div>Younger, Long Commuter in dense neighborhood</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#f38060'></div>Long commuters White black mix</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#f98a6b'></div>Low rent in built up neighborhoods</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#fe9576'></div>Renters within cities, mixed income areas, White/Hispanic mix, Unmarried</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ff9f82'></div>Older Home owners with high income</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ffa98d'></div>Older home owners and very high income</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ffb399'></div>White Asian Mix Big City Burbs Dwellers</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ffbda5'></div>Bachelors degree Mid income With Mortgages</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ffc8b1'></div>Asian Hispanic Mix, Mid income</td></tr>
<tr><td></td><td><div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ffd2bd'></div>Bachelors degree Higher income Home Owners</td></tr>
<tr><td>Wealthy, urban, and kid-free</td><td></td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#CC61B0'></div>Wealthy city commuters </td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#d975bd'></div>New Developments</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#e488c9'></div>Very wealthy, multiple million dollar homes</td></tr>
<tr><td></td> <td> <div style='float:left;margin-right:10px;width:20px; height:20px; border-radius:20px;background:#ee9ad4'></div>High rise, dense urbanites</td></tr>
</table>
### Examples
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetSegmentSnapshot({{point geometry}})
```
##### Get the Geographic Snapshot of a Segmentation
__Get the Segmentation Snapshot around the MGM Grand__
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetSegmentSnapshot(CDB_LatLng(36.10222, -115.169516))
```
__Get the Segmentation Snapshot at CARTO's NYC HQ__
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetSegmentSnapshot(CDB_LatLng(40.704512, -73.936669))
```

View File

@@ -1,34 +1,34 @@
# Overview
## Overview
By using CARTO libraries and the SQL API, you can apply location data services to your maps with unique data services functions. These functions are integrated with a number of internal and external services, enabling you to programatically customize subsets of data for your visualizations. These features are useful for geospatial analysis and the results can be saved, and stored, for additional location data service operations.
**Note:** Based on your account plan, some of these data services are subject to different [quota limitations](https://carto.com/docs/carto-engine/dataservices-api/quota-information/#quota-information).
**Note:** Based on your account plan, some of these data services are subject to different [quota limitations]({{site.dataservicesapi_docs}}/support/quota-information/).
_In order to supply the best location data services from within our CARTO Engine, the Data Services API collaborates with [Mapbox](https://www.mapbox.com/) and several other geospatial service providers. [Contact us](mailto:sales@carto.com) if you have any specific questions or requirements about the location data service provider being used with your account._
_In order to supply the best location data services from within our CARTO Engine, the Data Services API collaborates with [TomTom](https://www.tomtom.com/) and several other geospatial service providers. [Contact us](mailto:sales@carto.com) if you have any specific questions or requirements about the location data service provider being used with your account._
## Data Services Integration
### Data Services Integration
By using the SQL API to query the Data Services API functions, you can manage specific operations and the corresponding geometries (a `polygon` or a `point`), according to the input information.
The Data Services API also exposes its services directly through CARTO Builder. For example, you can geocode data (from single rows, complete datasets, or simple inputs) and perform trade areas analysis (computing isodistances or isochrones) programatically, through authenticated SQL requests, or by using the ANALYSIS options.
The Data Services API also exposes its services directly through CARTO Builder. For example, you can geocode data (from single rows, complete datasets, or simple inputs) and perform trade areas analysis (computing isodistances or isochrones) programatically, through authenticated SQL requests, or by using the ANALYSIS options.
The geometries provided by this API are projected in the projection [WGS 84 SRID 4326](http://spatialreference.org/ref/epsg/wgs-84/).
**Note:** The Data Services API [geocoding functions](https://carto.com/docs/carto-engine/dataservices-api/geocoding-functions/#geocoding-functions) return different types of geometries (points or polygons) as result of different geocoding processes. The CARTO Engine does not support multi-geometry layers or datasets, therefore you must confirm that you are using consistent geometry types inside a table, to avoid future conflicts in your map visualization.
**Note:** The Data Services API [geocoding functions]({{site.dataservicesapi_docs}}/reference/#geocoding-functions) return different types of geometries (points or polygons) as result of different geocoding processes. The CARTO Engine does not support multi-geometry layers or datasets, therefore you must verify that you are using consistent geometry types inside a table, to avoid future conflicts in your map visualization.
### Best Practices
#### Best Practices
_Be mindful of the following usage notes when using the Data Services functions with the SQL API:_
It is discouraged to use the SELECT operation with the Data Services API functions in your map layers, as these type of queries consume quota when rendering tiles for your live map views. It may also result in sync performance issues, due to executing multiple requests to the API each time your map is viewed. See details about [Quota Consumption](https://carto.com/docs/carto-engine/dataservices-api/quota-information/#quota-consumption).
It is discouraged to use the SELECT operation with the Data Services API functions in your map layers, as these type of queries consume quota when rendering tiles for your live map views. It may also result in sync performance issues, due to executing multiple requests to the API each time your map is viewed. See details about [Quota Consumption]({{site.dataservicesapi_docs}}/support/quota-information/#quota-consumption).
The Data Services API is **recommended** to be used with INSERT or UPDATE operations, for applying location data to your tables. While SELECT (retrieve) is standard for SQL API requests, be mindful of quota consumption and use INSERT (to insert a new record) or UPDATE (to update an existing record), for best practices.
## Authentication
### Authentication
All requests performed to the CARTO Data Services API must be authenticated with the user API Key. For more information about where to find your API Key, and how to authenticate your SQL API requests, view the [SQL API authentication](/carto-engine/sql-api/authentication/) documentation.
All requests performed to the CARTO Data Services API must be authenticated with the user API Key. For more information about where to find your API Key, and how to authenticate your SQL API requests, view the [Auth API]({{site.authapi_docs}}/) documentation.
## Errors
### Errors
Errors are described in the response of the request. An example is as follows:
@@ -40,10 +40,10 @@ Errors are described in the response of the request. An example is as follows:
}
```
Since the Data Services API is used on top of the CARTO SQL API, you can refer to the [Making calls to the SQL API](https://carto.com/docs/carto-engine/sql-api/making-calls/) documentation for help debugging your SQL errors.
Since the Data Services API is used on top of the CARTO SQL API, you can refer to the [Making calls to the SQL API]({{site.sqlapi_docs}}/guides/making-calls/) documentation for help debugging your SQL errors.
If the requested information is not in the CARTO geocoding database, or if CARTO is unable to recognize your input and match it with a result, the geocoding function returns `null` as a result.
## Limits
### Limits
Usage of the Data Services API is subject to the CARTO SQL API limits, stated in our [Terms of Service](https://carto.com/terms/#excessive).

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

View File

@@ -0,0 +1,5 @@
## Introduction
The CARTO Data Services API offers a set of location based services that can be used to programatically customize subsets of data for your visualizations.
The contents described in this document are subject to CARTO's [Terms of Service](https://carto.com/legal/)

View File

@@ -0,0 +1,9 @@
## Authentication
Data Services API, like any other [CARTO platform's component]({{site.fundamental_docs}}/components/), requires using an API Key. From your CARTO dashboard, click _[Your API keys](https://carto.com/login)_ from the avatar drop-down menu to view your uniquely generated API Key for managing data with CARTO Engine.
![Your API Keys](../img/avatar.gif)
Learn more about the [basics of authorization]({{site.fundamental_docs}}/authorization/), or dig into the details of [Auth API]({{site.authapi_docs}}/), if you want to know more about this part of CARTO platform.
The examples in this documentation may include a placeholder for the API Key. Ensure that you modify any placeholder parameters with your own credentials.

View File

@@ -0,0 +1,3 @@
## Versioning
Data Services API uses [Semantic Versioning](http://semver.org/). View our Github repository to find tags for each [release](https://github.com/CartoDB/data-services-api/releases).

View File

@@ -0,0 +1,5 @@
## Error handling
Most of the errors fired by the API are handled by the API itself. It triggers a `CartoError` every time an error happens.
A cartoError is an object containing a single `message` field with a string explaining the error.

View File

@@ -1,8 +1,8 @@
# Geocoding Functions
## Geocoding Functions
The [geocoder](https://carto.com/data/geocoder-api/) functions allow you to match your data with geometries on your map. This geocoding service can be used programatically to geocode datasets via the CARTO SQL API. It is fed from _Open Data_ and it serves geometries for countries, provinces, states, cities, postal codes, IP addresses and street addresses. CARTO provides functions for several different categories of geocoding through the Data Services API.
_**This service is subject to quota limitations and extra fees may apply**. View the [Quota Information](https://carto.com/docs/carto-engine/dataservices-api/quota-information/) section for details and recommendations about to quota consumption._
**Warning:** This service is subject to quota limitations and extra fees may apply. View the [Quota Information]({{site.dataservicesapi_docs}}/support/quota-information/) section for details and recommendations about to quota consumption.
The following example displays how to geocode a single country:
@@ -25,169 +25,168 @@ https://{username}.carto.com/api/v2/sql?q=UPDATE {tablename} SET the_geom = ST_C
The following geocoding functions are available, grouped by categories.
## Country Geocoder
### Country Geocoder
This function geocodes your data into country border geometries. It recognizes the names of the different countries either by different synonyms (such as their English name or their endonym), or by ISO (ISO2 or ISO3) codes.
### cdb_geocode_admin0_polygon(_country_name text_)
#### cdb_geocode_admin0_polygon(_country_name text_)
Geocodes the text name of a country into a country_name geometry, displayed as polygon data.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`country_name` | `text` | Name of the country
#### Returns
##### Returns
Geometry (polygon, EPSG 4326) or null
#### Example
### Example
##### Update the geometry of a table to geocode it
#### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_admin0_polygon({country_column})
```
##### Insert a geocoded row into a table
#### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_admin0_polygon('France')
```
## Level-1 Administrative Regions Geocoder
### Level-1 Administrative Regions Geocoder
This function geocodes your data into polygon geometries for [Level 1](https://en.wikipedia.org/wiki/Table_of_administrative_divisions_by_country), or [NUTS-1](https://en.wikipedia.org/wiki/NUTS_1_statistical_regions_of_England), administrative divisions (or units) of countries. For example, a "state" in the United States, "départements" in France, or an autonomous community in Spain.
### cdb_geocode_admin1_polygon(_admin1_name text_)
#### cdb_geocode_admin1_polygon(_admin1_name text_)
Geocodes the name of the province/state into a Level-1 administrative region, displayed as a polygon geometry.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`admin1_name` | `text` | Name of the province/state
#### Returns
##### Returns
Geometry (polygon, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_admin1_polygon({province_column})
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_admin1_polygon('Alicante')
```
### cdb_geocode_admin1_polygon(_admin1_name text, country_name text_)
#### cdb_geocode_admin1_polygon(_admin1_name text, country_name text_)
Geocodes the name of the province/state for a specified country into a Level-1 administrative region, displayed as a polygon geometry.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`admin1_name` | `text` | Name of the province/state
`country_name` | `text` | Name of the country in which the province/state is located
#### Returns
##### Returns
Geometry (polygon, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_admin1_polygon({province_column}, {country_column})
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_admin1_polygon('Alicante', 'Spain')
```
## City Geocoder
### City Geocoder
This function geocodes your data into point geometries for names of cities. It is recommended to use geocoding functions that require more defined parameters — this returns more accurate results when several cities have the same name. _If there are duplicate results for a city name, the city name with the highest population will be returned._
### cdb_geocode_namedplace_point(_city_name text_)
#### cdb_geocode_namedplace_point(_city_name text_)
Geocodes the text name of a city into a named place geometry, displayed as point data.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`city_name` | `text` | Name of the city
#### Returns
##### Returns
Geometry (point, EPSG 4326) or null
#### Example
##### Example
##### Select
###### Select
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_namedplace_point({city_column})
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('Barcelona')
```
### cdb_geocode_namedplace_point(_city_name text, country_name text_)
#### cdb_geocode_namedplace_point(_city_name text, country_name text_)
Geocodes the text name of a city for a specified country into a named place point geometry.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`city_name` | `text` | Name of the city
`country_name` | `text` | Name of the country in which the city is located
#### Returns
##### Returns
Geometry (point, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_namedplace_point({city_column}, 'Spain')
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('Barcelona', 'Spain')
```
### cdb_geocode_namedplace_point(_city_name text, admin1_name text, country_name text_)
#### cdb_geocode_namedplace_point(_city_name text, admin1_name text, country_name text_)
Geocodes your data into a named place point geometry, containing the text name of a city, for a specified province/state and country. This is recommended for the most accurate geocoding of city data.
#### Arguments
Geocodes your data into a named place point geometry, containing the text name of a city, for a specified province/state and country. This is recommended for the most accurate geocoding of city data.
##### Arguments
Name | Type | Description
--- | --- | ---
@@ -195,132 +194,132 @@ Name | Type | Description
`admin1_name` | `text` | Name of the province/state in which the city is located
`country_name` | `text` | Name of the country in which the city is located
#### Returns
##### Returns
Geometry (point, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_namedplace_point({city_column}, {province_column}, 'USA')
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('New York', 'New York', 'USA')
```
## Postal Code Geocoder
### Postal Code Geocoder
These functions geocode your data into point, or polygon, geometries for postal codes. The postal code geocoder covers the United States, France, Australia and Canada; a request for a different country will return an empty response.
**Note:** For the USA, US Census Zip Code Tabulation Areas (ZCTA) are used to reference geocodes for USPS postal codes service areas. This is not a CARTO restriction, this is a US Government licensing protection of their zip code data source; which is not publicly available. Additionally, zip codes are considered service areas and are not actually geometric areas. As a solution, the US Census provides ZCTA data, which tabulates GIS postal codes for USPS locations by aggregating census blocks. For details about how ZCTAs are created, see [ZIP Code™ Tabulation Areas (ZCTAs™)](https://www.census.gov/geo/reference/zctas.html). If you are geocoding data and your zip codes fail, ensure you are using ZCTAs for the postal code.
### cdb_geocode_postalcode_polygon(_postal_code text, country_name text_)
#### cdb_geocode_postalcode_polygon(_postal_code text, country_name text_)
Geocodes the postal code for a specified country into a **polygon** geometry.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`postal_code` | `text` | Postal code
`country_name` | `text` | Name of the country in which the postal code is located
#### Returns
##### Returns
Geometry (polygon, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_postalcode_polygon({postal_code_column}, 'USA')
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_postalcode_polygon('11211', 'USA')
```
### cdb_geocode_postalcode_point(_code text, country_name text_)
#### cdb_geocode_postalcode_point(_code text, country_name text_)
Geocodes the postal code for a specified country into a **point** geometry.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`postal_code` | `text` | Postal code
`country_name` | `text` | Name of the country in which the postal code is located
#### Returns
##### Returns
Geometry (point, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_postalcode_point({postal_code_column}, 'USA')
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_postalcode_point('11211', 'USA')
```
## IP Addresses Geocoder
### IP Addresses Geocoder
This function geocodes your data into point geometries for IP addresses. This is useful if you are analyzing location based data, based on a set of user's IP addresses.
### cdb_geocode_ipaddress_point(_ip_address text_)
#### cdb_geocode_ipaddress_point(_ip_address text_)
Geocodes a postal code from a specified country into an IP address, displayed as a point geometry.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | ---
`ip_address` | `text` | IPv4 or IPv6 address
#### Returns
##### Returns
Geometry (point, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_ipaddress_point('102.23.34.1')
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_ipaddress_point('102.23.34.1')
```
## Street-Level Geocoder
### Street-Level Geocoder
This function geocodes your data into a point geometry for a street address. CARTO uses several different service providers for street-level geocoding, depending on your platform. If you access CARTO on a Google Cloud Platform, [Google Maps geocoding](https://developers.google.com/maps/documentation/geocoding/intro) is applied. All other platform users are provided with [Mapbox geocoding services](https://www.mapbox.com/). [Contact us](mailto:sales@carto.com) if you have any specific questions or requirements about the location data service provider being used with your account._.
These functions geocode your data into a point geometry for a street address. CARTO platform uses [TomTom geocoding services](https://www.tomtom.com/) by default as the service provider for street-level geocoding. [Contact us](mailto:sales@carto.com) if you have any specific questions or requirements about the location data service provider being used with your account.
**This service is subject to quota limitations, and extra fees may apply**. View the [Quota information](https://carto.com/docs/carto-engine/dataservices-api/quota-information/) for details and recommendations about quota consumption.
**This service is subject to quota limitations, and extra fees may apply**. View the [Quota information]({{site.dataservicesapi_docs}}/support/quota-information/) for details and recommendations about quota consumption.
### cdb_geocode_street_point(_search_text text, [city text], [state text], [country text]_)
#### cdb_geocode_street_point(_search_text text, [city text], [state text], [country text]_)
Geocodes a complete address into a single street geometry, displayed as point data.
#### Arguments
##### Arguments
Name | Type | Description
--- | --- | --- | ---
@@ -329,20 +328,62 @@ Name | Type | Description
`state` | `text` | (Optional) Name of the state.
`country` | `text` | (Optional) Name of the country.
#### Returns
##### Returns
Geometry (point, EPSG 4326) or null
#### Example
##### Example
##### Update the geometry of a table to geocode it
###### Update the geometry of a table to geocode it
```bash
UPDATE {tablename} SET the_geom = cdb_geocode_street_point({street_name_column})
```
##### Insert a geocoded row into a table
###### Insert a geocoded row into a table
```bash
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_street_point('651 Lombard Street', 'San Francisco', 'California', 'United States')
```
#### cdb_bulk_geocode_street_point (_query text, street_column text, [city_column text], [state_column text], [country_column text], [batch_size integer]_)
Geocodes complete street addresses into point data. Similar to `cdb_geocode_street_point`, but using batch services and therefore allowing for several addresses to be geocoded in a single API call.
##### Arguments
Name | Type | Description
--- | --- | --- | ---
`query` | `text` | SQL query that returns the addresses to be geocoded. It must include a `cartodb_id` column and another column to get the free-form addresses from. Optionally, it may include other columns to fine-tune the geocoding, such as a city column, a state column and a country column.
`street_column` | `text` | Name of the free-form address column, must be present in the SQL query.
`city_column` | `text` | (Optional) Name of the city column, if present in the SQL query.
`state_column` | `text` | (Optional) Name of the state column, if present in the SQL query.
`country_column` | `text` | (Optional) Name of the country column, if present in the SQL query.
`batch_size` | `integer` | (Optional) Geocoding queries are sent in batches. Batch size can be configured, from 1 geocoding query per batch to a maximum value, limited by user quota or other limits. If not specified, it defaults to the maximum size available to the user, which is typically the best option, performance-wise.
##### Returns
Geocoding results are returned in an array. Each array element contains:
Name | Type | Description
--- | --- | --- | ---
`cartodb_id` | `integer` | `cartodb_id` from the original query.
`the_geom` | `Geometry (point, EPSG 4326)` | Point that corresponds to the most accurate match found for this particular address, or `null` if no match was found.
`metadata` | `JSON` | Information about the geocoding result, empty if no match was found.
The `metadata` JSON type includes the following attributes when geocoding was successful:
Name | Type | Description
--- | --- | --- | ---
`precision` | `text` | One of `precise` or `interpolated`.
`relevance` | `number` | Relevance factor, from 0 to 1, higher being more relevant.
`match_type` | `text` | Array with one of `point_of_interest`, `country`, `state`, `county`, `locality`, `district`, `street`, `intersection`, `street_number`, `postal_code`. Empty array if match type is unknown.
##### Example
###### Update the geometries of an entire table by geocoding all the rows based on a street address
```bash
WITH geocoding_results AS (SELECT cartodb_id, the_geom FROM cdb_bulk_geocode_street_point('SELECT cartodb_id, {address_column} from {tablename}', '{address_column}')) UPDATE {tablename} tn SET the_geom = geocoding_results.the_geom FROM geocoding_results WHERE tn.cartodb_id = geocoding_results.cartodb_id
```

View File

@@ -1,8 +1,8 @@
# Isoline Functions
## Isoline Functions
[Isolines](https://carto.com/data/isolines/) are contoured lines that display equally calculated levels over a given surface area. This enables you to view polygon dimensions by forward or reverse measurements. Isoline functions are calculated as the intersection of areas from the origin point, measured by distance (isodistance) or time (isochrone). For example, the distance of a road from a sidewalk. Isoline services through CARTO are available by requesting a single function in the Data Services API.
_**This service is subject to quota limitations and extra fees may apply**. View the [Quota Information](https://carto.com/docs/carto-engine/dataservices-api/quota-information/) section for details and recommendations about to quota consumption._
_**This service is subject to quota limitations and extra fees may apply**. View the [Quota Information]({{site.dataservicesapi_docs}}/support/quota-information/) section for details and recommendations about to quota consumption._
You can use the isoline functions to retrieve, for example, isochrone lines from a certain location, specifying the mode and the ranges that will define each of the isolines. The following query calculates isolines for areas that are 5, 10 and 15 minutes (300, 600 and 900 seconds, respectively) away from the location by following a path defined by car routing and inserts them into a table.
@@ -12,10 +12,12 @@ https://{username}.carto.com/api/v2/sql?q=INSERT INTO {table} (the_geom) SELECT
The following functions provide an isoline generator service, based on time or distance. This service uses the isolines service defined for your account. The default service limits the usage of displayed polygons represented on top of [Mapbox](https://www.mapbox.com/) maps.
## cdb_isodistance(_source geometry, mode text, range integer[], [options text[]]_)
### cdb_isodistance(_source geometry, mode text, range integer[], [options text[]]_)
Displays a contoured line on a map, connecting geometries to a defined area, measured by an equal range of distance (in meters).
Note that not all the providers, for example TomTom, provide us a way to define the isoline limit in distance so we need to make some estimations. Due that estimations the produced isolines could not be 100% precise.
#### Arguments
Name | Type | Description | Accepted values
@@ -26,7 +28,7 @@ Name | Type | Description | Accepted values
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional isolines parameters](#optional-isoline-parameters) for details.
#### Returns
##### Returns
Name | Type | Description
--- | --- | ---
@@ -34,9 +36,9 @@ Name | Type | Description
`data_range` | `integer` | The range that belongs to the generated isoline.
`the_geom` | `geometry(MultiPolygon)` | MultiPolygon geometry of the generated isoline in the 4326 projection.
#### Examples
##### Examples
##### Calculate and insert isodistance polygons from a point into another table
###### Calculate and insert isodistance polygons from a point into another table
```bash
INSERT INTO {table} (the_geom) SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300, 600, 900]::integer[])
@@ -48,18 +50,18 @@ or equivalently:
INSERT INTO {table} (the_geom) SELECT (cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300, 600, 900]::integer[])).the_geom
```
##### Calculate and insert the generated isolines from `points_table` table to another table
###### Calculate and insert the generated isolines from `points_table` table to another table
```bash
INSERT INTO {table} (the_geom) SELECT (cdb_isodistance(the_geom, 'walk', string_to_array(distance, ',')::integer[])).the_geom FROM {points_table}
```
## cdb_isochrone(_source geometry, mode text, range integer[], [options text[]]_)
### cdb_isochrone(_source geometry, mode text, range integer[], [options text[]]_)
Displays a contoured line on a map, connecting geometries to a defined area, measured by an equal range of time (in seconds).
#### Arguments
##### Arguments
This function uses the same parameters and information as the `cdb_isodistance` function, with the exception that the range is measured in seconds instead of meters.
@@ -70,9 +72,9 @@ Name | Type | Description | Accepted values
`range` | `integer[]` | Range of the isoline, in seconds. |
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional isolines parameters](#optional-isoline-parameters) for details.
#### Examples
##### Examples
##### Calculate and insert isochrone polygons from a point into another table
###### Calculate and insert isochrone polygons from a point into another table
```bash
INSERT INTO {table} (the_geom) SELECT the_geom FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300, 900, 12000]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[])
@@ -84,13 +86,13 @@ or equivalently:
INSERT INTO {table} (the_geom) SELECT (cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300, 900, 12000]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[])).the_geom
```
##### Calculate and insert the generated isolines from `points_table` table into another table
###### Calculate and insert the generated isolines from `points_table` table into another table
```bash
INSERT INTO {table} (the_geom) SELECT (cdb_isochrone(the_geom, 'walk', string_to_array(time_distance, ',')::integer[])).the_geom FROM {points_table}
```
### Optional isoline parameters
#### Optional isoline parameters
The optional value parameters must be passed using the format: `option=value`.

View File

@@ -1,23 +1,23 @@
# Routing Functions
## Routing Functions
Routing is the navigation from a defined start location to a defined end location. The calculated results are displayed as turn-by-turn directions on your map, based on the transportation mode that you specified. Routing services through CARTO are available by using the available functions in the Data Services API.
## cdb_route_point_to_point(_origin geometry(Point), destination geometry(Point), mode text, [options text[], units text]_)
### cdb_route_point_to_point(_origin geometry(Point), destination geometry(Point), mode text, [options text[], units text]_)
Returns a route from origin to destination.
#### Arguments
##### Arguments
Name | Type | Description | Accepted values
--- | --- | --- | ---
`origin` | `geometry(Point)` | Origin point, in 4326 projection, which defines the start location. |
`destination` | `geometry(Point)` | Destination point, in 4326 projection, which defines the end location. |
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk`, `bicycle` or `public_transport`
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk` or `bicycle`
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
`units` | `text` | (Optional) Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`. This option is not supported by Mapbox provider
#### Returns
##### Returns
Name | Type | Description
--- | --- | ---
@@ -25,34 +25,34 @@ Name | Type | Description
`length` | `real` | Length in the defined unit in the `units` field. `meters` by default .
`the_geom` | `geometry(LineString)` | LineString geometry of the calculated route in the 4326 projection.
#### Examples
##### Examples
##### Insert the values from the calculated route in your table
###### Insert the values from the calculated route in your table
```bash
INSERT INTO <TABLE> (duration, length, the_geom) SELECT duration, length, shape FROM cdb_route_point_to_point('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car')
```
##### Update the geometry field with the calculated route shape
###### Update the geometry field with the calculated route shape
```bash
UPDATE <TABLE> SET the_geom = (SELECT shape FROM cdb_route_point_to_point('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]))
```
## cdb_route_with_waypoints(_waypoints geometry(Point)[], mode text, [options text[], units text]_)
### cdb_route_with_waypoints(_waypoints geometry(Point)[], mode text, [options text[], units text]_)
Returns a route that goes from origin to destination and whose path travels through the defined locations.
#### Arguments
##### Arguments
Name | Type | Description | Accepted values
--- | --- | --- | ---
`waypoints` | `geometry(Point)[]` | Array of ordered points, in 4326 projection, which defines the origin point, one or more locations for the route path to travel through, and the destination. The first element of the array defines the origin and the last element the destination of the route. |
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk`, `bicycle` or `public_transport`
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk` or `bicycle`
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
`units` | `text` | (Optional) Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`. This option is not supported by Mapbox provider
#### Returns
##### Returns
Name | Type | Description
--- | --- | ---
@@ -62,23 +62,23 @@ Name | Type | Description
*Note*: A request to the function _cdb\_route\_with\_waypoints(waypoints geometry(Point)[], mode text, [options text[], units text])_ with only two points in the geometry array are automatically defined as origin and destination. It is equivalent to performing the following request with these two locations as parameters: _cdb\_route\_point\_to\_point(origin geometry(Point), destination geometry(Point), mode text, [options text[], units text])_.
#### Examples
##### Examples
##### Insert the values from the calculated route in your table
###### Insert the values from the calculated route in your table
```bash
INSERT INTO <TABLE> (duration, length, the_geom) SELECT duration, length, shape FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, 'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]::geometry[], 'walk')
```
##### Update the geometry field with the calculated route shape
###### Update the geometry field with the calculated route shape
```bash
UPDATE <TABLE> SET the_geom = (SELECT shape FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, 'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]::geometry[], 'car', ARRAY['mode_type=shortest']::text[]))
```
### Optional routing parameters
#### Optional routing parameters
The optional value parameters must be passed using the format: `option=value`. Not all are available for all the routing providers
Name | Type | Description | Accepted values
--- | --- | --- | ---
`mode_type` | `text` | Type of route calculation | `shortest` (this option only applies to the car transport mode)
`mode_type` | `text` | Type of route calculation | `shortest` or `fastest` (this option only applies to the car transport mode)

View File

@@ -0,0 +1,36 @@
## Support Options
Feeling stuck? There are many ways to find help.
* Ask a question on [GIS StackExchange](https://gis.stackexchange.com/questions/tagged/carto) using the `CARTO` tag.
* [Report an issue](https://github.com/CartoDB/cartodb/issues) in Github.
* Engine Plan customers have additional access to enterprise-level support through CARTO's support representatives.
If you just want to describe an issue or share an idea, just <a class="typeform-share" href="https://cartohq.typeform.com/to/mH6RRl" data-mode="popup" target="_blank"> send your feedback</a>
### Issues on Github
If you think you may have found a bug, or if you have a feature request that you would like to share with the Data Services API team, please [open an issue](https://github.com/CartoDB/cartodb/issues/new).
Before opening an issue, review the [contributing guidelines](https://github.com/CartoDB/cartodb/blob/master/CONTRIBUTING.md).
### Community support on GIS Stack Exchange
GIS Stack Exchange is the most popular community in the geospatial industry. This is a collaboratively-edited question and answer site for geospatial programmers and technicians. It is a fantastic resource for asking technical questions about developing and maintaining your application.
When posting a new question, please consider the following:
* Read the GIS Stack Exchange [help](https://gis.stackexchange.com/help) and [how to ask](https://gis.stackexchange.com/help/how-to-ask) pages for guidelines and tips about posting questions.
* Be very clear about your question in the subject. A clear explanation helps those trying to answer your question, as well as those who may be looking for information in the future.
* Be informative in your post. Details, code snippets, logs, screenshots, etc. help others to understand your problem.
* Use code that demonstrates the problem. It is very hard to debug errors without sample code to reproduce the problem.
### Engine Plan Customers
Engine Plan customers have additional support options beyond general community support. As per your account Terms of Service, you have access to enterprise-level support through CARTO's support representatives available at [enterprise-support@carto.com](mailto:enterprise-support@carto.com)
In order to speed up the resolution of your issue, provide as much information as possible (even if it is a link from community support). This allows our engineers to investigate your problem as soon as possible.
If you are not yet CARTO customer, browse our [plans & pricing](https://carto.com/pricing/) and find the right plan for you.

View File

@@ -0,0 +1,36 @@
## Contribute
CARTO platform is an open-source ecosystem. You can read about the [fundamentals]({{site.fundamental_docs}}/components/) of CARTO architecture and its components.
We are more than happy to receive your contributions to the code and the documentation as well.
## Filling a ticket
If you want to open a new issue in our repository, please follow these instructions:
1. Descriptive title.
2. Write a good description, it always helps.
3. Specify the steps to reproduce the problem.
4. Try to add an example showing the problem.
## Contributing code
Best part of open source, collaborate in Data Services API code!. We like hearing from you, so if you have any bug fixed, or a new feature ready to be merged, those are the steps you should follow:
1. Fork the repository.
2. Create a new branch in your forked repository.
3. Commit your changes. Add new tests if it is necessary.
4. Open a pull request.
5. Any of the maintainers will take a look.
6. If everything works, it will merged and released \o/.
If you want more detailed information, this [GitHub guide](https://guides.github.com/activities/contributing-to-open-source/) is a must.
## Completing documentation
Data Services API documentation is located in ```docs/```. That folder is the content that appears in the [Developer Center](http://carto.com/developers/data-services-api/). Just follow the instructions described in [contributing code](#contributing-code) and after accepting your pull request, we will make it appear online :).
**Tip:** A convenient, easy way of proposing changes in documentation is by using the GitHub editor directly on the web. You can easily create a branch with your changes and make a PR from there.
## Submitting contributions
You will need to sign a Contributor License Agreement (CLA) before making a submission. [Learn more here](https://carto.com/contributions).

View File

@@ -1,8 +1,8 @@
# Quota Information
## Quota Information
**Based on your account plan, some of the Data Services API functions are subject to quota limitations and extra fees may apply.** View our [terms and conditions](https://carto.com/terms/), or [contact us](mailto:sales@carto.com) for details about which functions require service credits to your account.
## Quota Consumption
### Quota Consumption
Quota consumption is calculated based on the number of request made for each function. Be mindful of the following usage recommendations when using the Data Services API functions:
@@ -14,15 +14,15 @@ Quota consumption is calculated based on the number of request made for each fun
* It is advised to store results of these queries into your datasets, and refresh them as needed. This ensure more control of quota credits for your account
## Quota Information Functions
### Quota Information Functions
There are several SQL functions that you can run to obtain quota information about your services.
## cdb_service_quota_info()
### cdb_service_quota_info()
Returns information about per-service quotas (available and used) for the account.
#### Returns
##### Returns
This function returns a set of service quota information records, one per service.
@@ -36,10 +36,9 @@ Name | Type | Description
Service Types:
* `'isolines'` [Isoline/Isochrones (isochrone/isodistance lines) service](https://carto.com/docs/carto-engine/dataservices-api/isoline_functions/)
* `'hires_geocoder'` [Street level geocoding](https://carto.com/docs/carto-engine/dataservices-api/geocoding-functions#street-level-geocoder)
* `'routing'` [Routing functions](https://carto.com/docs/carto-engine/dataservices-api/routing_functions/)
* `'observatory'` Data Observatory services ([demographic](https://carto.com/docs/carto-engine/dataservices-api/demographic_functions/) and [segmentation](https://carto.com/docs/carto-engine/dataservices-api/segmentation_functions/) functions)
* `'isolines'` [Isoline/Isochrones (isochrone/isodistance lines) service]({{site.dataservicesapi_docs}}/reference/#isoline_functions/)
* `'hires_geocoder'` [Street level geocoding]({{site.dataservicesapi_docs}}/reference/#street-level-geocoder)
* `'routing'` [Routing functions]({{site.dataservicesapi_docs}}/reference/#routing_functions/)
**Notes**
@@ -48,7 +47,7 @@ expenses when the regular quota is exceeded.
A zero value of `monthly_quota` indicates that the service has not been activated for the user.
#### Example
##### Example
```sql
SELECT * FROM cdb_service_quota_info();
@@ -59,17 +58,16 @@ Result:
```sql
service | monthly_quota | used_quota | soft_limit | provider
----------------+---------------+------------+------------+------------------
isolines | 100 | 0 | f | mapbox
hires_geocoder | 100 | 0 | f | mapbox
routing | 50 | 0 | f | mapbox
observatory | 0 | 0 | f | data observatory
isolines | 100 | 0 | f | tomtom
hires_geocoder | 100 | 0 | f | tomtom
routing | 50 | 0 | f | tomtom
(4 rows)
```
In this case, notice that the user has no access to the observatory services. All quotas are *hard-limited* (no soft limits), and no quota has been used in the present period.
All quotas are *hard-limited* (no soft limits), and no quota has been used in the present period.
## cdb_enough_quota(service text ,input_size numeric)
### cdb_enough_quota(service text ,input_size numeric)
This function is useful to check if enough quota is available for completing a job.
@@ -79,20 +77,20 @@ This is specifically relevant if a number of service calls are to be performed i
Note that some services consume more than one credit per row/call. For example, isolines (with more than one range/track) consume (N rows x M ranges) credits; indicating that the input size should be N x M.
#### Arguments
##### Arguments
Name | Type | Description
------------ | --------- | -----------
`service` | `text` | Service to check; see the list of valid services above.
`input_size` | `numeric` | Number of service calls required, i.e. size of the input to be processed.
#### Returns
##### Returns
The result is a *boolean* value. A *true* value (`'t'`) indicates that the available quota
for the service is enough for the input size requested. A *false* value (`'f'`) indicates
insufficient quota.
#### Example
##### Example
Suppose you want to geocode a whole table. In order to check that you have enough quota, and avoid a "quota exhausted" exception, first find out how many records you need to geocode:

View File

@@ -1,4 +1,4 @@
# Rate limits
## Rate limits
Services can be rate-limited. (currently only gecoding is limited)
@@ -15,72 +15,72 @@ If a service request exceeds the configured rate limits
(i.e. if more than `limit` calls are performe in a fixed interval of
duration `period` seconds) the call will fail with an "Rate limit exceeded" error.
## Server-side interface
### Server-side interface
There's a server-side SQL interface to query or change the configuration.
### cdb_dataservices_server.cdb_service_get_rate_limit(username, orgname, service)
#### cdb_dataservices_server.cdb_service_get_rate_limit(username, orgname, service)
This function returns the rate limit configuration for a given user and service.
#### Returns
##### Returns
The result is a JSON object with the configuration (`period` and `limit` attributes as explained above).
### cdb_dataservices_server.cdb_service_set_user_rate_limit(username, orgname, service, rate_limit)
#### cdb_dataservices_server.cdb_service_set_user_rate_limit(username, orgname, service, rate_limit)
This function sets the rate limit configuration for the user. This overrides any other configuration.
The configuration is provided as a JSON literal. To remove the user-level configuration `NULL` should be passed as the `rate_limit`.
#### Returns
##### Returns
This functions doesn't return any value.
### cdb_dataservices_server.cdb_service_set_org_rate_limit(username, orgname, service, rate_limit)
#### cdb_dataservices_server.cdb_service_set_org_rate_limit(username, orgname, service, rate_limit)
This function sets the rate limit configuration for the organization.
This overrides server level configuration and is overriden by user configuration if present.
The configuration is provided as a JSON literal. To remove the organization-level configuration `NULL` should be passed as the `rate_limit`.
#### Returns
##### Returns
This functions doesn't return any value.
### cdb_dataservices_server.cdb_service_set_server_rate_limit(username, orgname, service, rate_limit)
#### cdb_dataservices_server.cdb_service_set_server_rate_limit(username, orgname, service, rate_limit)
This function sets the default rate limit configuration for all users accesing the dataservices server. This is overriden by organization of user configuration.
The configuration is provided as a JSON literal. To remove the organization-level configuration `NULL` should be passed as the `rate_limit`.
#### Returns
##### Returns
This functions doesn't return any value.
## Client-side interface
### Client-side interface
For convenience there's also a client-side interface (in the client dataservices-api extension), consisting
of public functions to get the current configuration and privileged functions to change it.
### Public functions
#### Public functions
These functions are accesible to non-privileged roles, and should only be executed
using the role corresponding to a CARTO user, since that will determine the
user and organization to which the rate limits configuration applies.
### cdb_dataservices_client.cdb_service_get_rate_limit(service)
#### cdb_dataservices_client.cdb_service_get_rate_limit(service)
This function returns the rate limit configuration in effect for the specified service
and the user corresponding to the role which makes the calls. The effective configuration
may come from any of the configuration levels (server/organization/user); only the
existing configuration with most precedence is returned.
#### Returns
##### Returns
The result is a JSON object with the configuration (`period` and `limit` attributes as explained above).
#### Example:
##### Example:
```
SELECT cdb_dataservices_client.cdb_service_get_rate_limit('geocoder');
@@ -92,21 +92,21 @@ SELECT cdb_dataservices_client.cdb_service_get_rate_limit('geocoder');
```
### Privileged (superuser) functions
#### Privileged (superuser) functions
Thes functions are not accessible by regular user roles, and the user and organization names must be provided as parameters.
### cdb_dataservices_client.cdb_service_set_user_rate_limit(username, orgname, service, rate_limit)
#### cdb_dataservices_client.cdb_service_set_user_rate_limit(username, orgname, service, rate_limit)
This function sets the rate limit configuration for the user. This overrides any other configuration.
The configuration is provided as a JSON literal. To remove the user-level configuration `NULL` should be passed as the `rate_limit`.
#### Returns
##### Returns
This functions doesn't return any value.
#### Example
##### Example
This will configure the geocoder service rate limit for user `myusername`, a non-organization user.
The limit will be set at 1000 requests per day. Since the user doesn't belong to any organization,
@@ -129,18 +129,18 @@ SELECT cdb_dataservices_client.cdb_service_set_user_rate_limit(
(1 row)
```
### cdb_dataservices_client.cdb_service_set_org_rate_limit(username, orgname, service, rate_limit)
#### cdb_dataservices_client.cdb_service_set_org_rate_limit(username, orgname, service, rate_limit)
This function sets the rate limit configuration for the organization.
This overrides server level configuration and is overriden by user configuration if present.
The configuration is provided as a JSON literal. To remove the organization-level configuration `NULL` should be passed as the `rate_limit`.
#### Returns
##### Returns
This functions doesn't return any value.
#### Example
##### Example
This will configure the geocoder service rate limit for the `myorg` organization.
The limit will be set at 100 requests per hour.
@@ -162,17 +162,17 @@ SELECT cdb_dataservices_client.cdb_service_set_org_rate_limit(
(1 row)
```
### cdb_dataservices_client.cdb_service_set_server_rate_limit(username, orgname, service, rate_limit)
#### cdb_dataservices_client.cdb_service_set_server_rate_limit(username, orgname, service, rate_limit)
This function sets the default rate limit configuration for all users accesing the dataservices server. This is overriden by organization of user configuration.
The configuration is provided as a JSON literal. To remove the organization-level configuration `NULL` should be passed as the `rate_limit`.
#### Returns
##### Returns
This functions doesn't return any value.
#### Example
##### Example
This will configure the default geocoder service rate limit for all users
accesing the data-services server.

View File

@@ -56,11 +56,9 @@ This operation could be done through the rails console:
- Geocoding (street level): `geocoding_quota`, `soft_geocoding_limit`
- Isolines: `here_isolines_quota`, `soft_here_isolines_limit`
- Data observatory snapshot: `obs_snapshot_quota`, `soft_obs_snapshot_limit`
- Data observatory general: `obs_general_quota`, `soft_obs_general_limit`
### How is the quota spent?###
Almost in all the services: geocoding, data observatory snapshot and general the number of spent credits is calculated per request made (either successful or empty request).
Almost in all the services: geocoding and general the number of spent credits is calculated per request made (either successful or empty request).
In the case of the isolines service, the number of credits is calculated based on the number of isolines generated by the request. Ie. If your query generates 3 isolines for the request, you've spent 3 isolines credits.

0
server/__init__.py Normal file
View File

View File

@@ -6,4 +6,6 @@ cdb_geocoder_server--0.1.0.sql
cdb_geocoder_server--0.2.0.sql
cdb_geocoder_server--0.3.0.sql
cdb_geocoder_server--0.4.0.sql
cdb_geocoder_server--0.5.0.sql
cdb_geocoder_server--0.5.0.sql
cdb_dataservices_server.control
./test/sql/366_empty_table_test.sql

View File

@@ -1,20 +1,35 @@
# Makefile to generate the extension out of separate sql source files.
# Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed.
EXTENSION = cdb_dataservices_server
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
EXTVERSION = 0.40.1
# The new version to be generated from templates
SED = sed
ERB = erb
REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g'
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
AWK = awk
SED ?= sed
ERB ?= erb
AWK ?= awk
PG_CONFIG ?= pg_config
# Parallel support macros
PG_CONFIG = pg_config
PG_CONFIG ?= pg_config
PG_PARALLEL := $(shell $(PG_CONFIG) --version | ($(AWK) '{$$2*=1000; if ($$2 >= 9600) print 1; else print 0;}' 2> /dev/null || echo 0))
# PG12 compatibility
PG_VERSION := $(shell $(PG_CONFIG) --version | $(AWK) '{split($$2,a,"."); print a[1]}')
PG_12_GE := $(shell [ $(PG_VERSION) -ge 12 ] && echo true)
PLPYTHONU := plpythonu
POSTGIS := postgis
ifeq ($(PG_12_GE), true)
PLPYTHONU := plpython3u
POSTGIS := postgis, postgis_raster
endif
REPLACEMENTS = -e 's/@@EXTVERSION@@/$(EXTVERSION)/g' -e 's/@@plpythonu@@/$(PLPYTHONU)/g' -e 's/@@postgis@@/$(POSTGIS)/g'
REPLACEMENTS_TEST_REVERSE = -e 's/$(PLPYTHONU)/@@plpythonu@@/g'
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
REGRESS = $(notdir $(basename $(sort $(wildcard test/sql/*test.sql))))
TEST_DIR = test/
REGRESS_EXPEC = $(notdir $(basename $(sort $(wildcard test/expected/*test.out))))
TEST_DIR = test
REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)' --user='postgres'
# DATA is a special variable used by postgres build infrastructure
@@ -29,57 +44,70 @@ SOURCES_DATA_DIR = sql/
SOURCES_DATA = $(wildcard sql/*.sql)
# postgres build stuff
PG_CONFIG = pg_config
# The targets listed under REGRESS_PREP are executed before regress
PYTHON_TESTS = ./test/sql/366_empty_table_test.sql
REGRESS_PREP = $(PYTHON_TESTS)
./test/sql/366_empty_table_test.sql: ./test/sql/366_empty_table_test.sql.template
$(SED) $(REPLACEMENTS) $@.template > $@
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
$(NEW_EXTENSION_ARTIFACT): $(SOURCES_DATA)
rm -f $@
cat $(SOURCES_DATA_DIR)/*.sql >> $@
ifeq ($(PG_PARALLEL), 0)
# Remove PARALLEL in aggregates and functions
$(eval TMPFILE := $(shell mktemp /tmp/$(basename $0).XXXXXXXX))
$(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' \
-e 's/PARALLEL [A-Z]*/''/g' $@ > $(TMPFILE)
mv $(TMPFILE) $@
endif
.PHONY: all
all: $(DATA)
.PHONY: release
release: $(EXTENSION).control $(SOURCES_DATA)
release: $(SOURCES_DATA)
test -n "$(NEW_VERSION)" # $$NEW_VERSION VARIABLE MISSING. Eg. make release NEW_VERSION=0.x.0
git mv *.sql old_versions
$(SED) $(REPLACEMENTS) $(EXTENSION).control
git add $(EXTENSION).control
cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql
$(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql
$(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql
git add $(EXTENSION)--$(NEW_VERSION).sql
$(SED) -i -e 's/^EXTVERSION =.*/EXTVERSION = $(NEW_VERSION)/g' Makefile
git add Makefile
@echo
@echo "Please review the file $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql and add any code needed to upgrade $(EXTVERSION) to $(NEW_VERSION)"
@echo "Please review the file $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql and add any code needed to downgrade $(NEW_VERSION) to $(EXTVERSION)"
@echo "Please review the file $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql.in and add any code needed to upgrade $(EXTVERSION) to $(NEW_VERSION)"
@echo "Please review the file $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql.in and add any code needed to downgrade $(NEW_VERSION) to $(EXTVERSION)"
@echo
# Only meant for development time, do not use once a version is released
.PHONY: devclean
devclean:
rm -f $(NEW_EXTENSION_ARTIFACT)
rm -f $(PYTHON_TESTS)
# If needed remove PARALLEL tags from the release files
release_remove_parallel_deploy:
ifeq ($(PG_PARALLEL), 0)
# Replace variables (and PARALLEL tags if necessary) and deploy files
.PHONY: replace_variables_and_deploy
replace_variables_and_deploy: $(NEW_EXTENSION_ARTIFACT)
mkdir -p '$(DESTDIR)$(datadir)/extension/'; \
for n in $(wildcard old_versions/*.sql *.sql); do \
$(eval TMPFILE := $(shell mktemp /tmp/XXXXXXXXXX)) \
$(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' -e 's/PARALLEL [A-Z]*/''/g' $$n > $(TMPFILE); \
mv $(TMPFILE) $$n; \
if [ "$(PG_PARALLEL)" -eq "0" ]; then \
$(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' -e 's/PARALLEL [A-Z]*/''/g' $$n > $(TMPFILE); \
mv $(TMPFILE) $$n; \
fi; \
$(SED) $(REPLACEMENTS) $$n > $(TMPFILE); \
mv $(TMPFILE) '$(DESTDIR)$(datadir)/extension/'$$(basename $$n); \
done
endif
.PHONY: $(EXTENSION).control
$(EXTENSION).control:
$(SED) $(REPLACEMENTS) $(EXTENSION).control.in > $(EXTENSION).control
# Install the current release into the PostgreSQL extensions directory
deploy: release_remove_parallel_deploy
.PHONY: deploy
deploy: replace_variables_and_deploy $(EXTENSION).control
$(INSTALL_DATA) $(EXTENSION).control '$(DESTDIR)$(datadir)/extension/'
$(INSTALL_DATA) old_versions/*.sql *.sql '$(DESTDIR)$(datadir)/extension/'
.PHONY: install
install: deploy
@echo "Install overriden"

Some files were not shown because too many files have changed in this diff Show More