Compare commits

..

593 Commits

Author SHA1 Message Date
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
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
Juan Ignacio Sánchez Lara
2687f0c73a Merge pull request #494 from CartoDB/development
TomTom release
2018-05-07 13:10:20 +02:00
Mario de Frutos
6b117e26b1 Remove unused Mapzen test 2018-05-07 12:22:39 +02:00
Juan Ignacio Sánchez Lara
9c428dbf31 Fix quote at NEWS 2018-05-07 11:17:43 +02:00
Juan Ignacio Sánchez Lara
20a610d1d8 Merge pull request #466 from CartoDB/Added_TomTom_services
[Leapfrog] Adding TomTom services
2018-05-07 11:11:27 +02:00
Juan Ignacio Sánchez Lara
4b599ecf78 NEWS 2018-05-07 11:08:51 +02:00
Juan Ignacio Sánchez Lara
3a240bf6ad params at routing metrics 2018-04-27 12:43:29 +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
Juan Ignacio Sánchez Lara
7577936c33 Fixes isolines quota check 2018-04-11 15:24:17 +02:00
Juan Ignacio Sánchez Lara
193513bfea params at metrics 2018-04-11 14:28:15 +02:00
Juan Ignacio Sánchez Lara
c3c28dfd5e Simpler quota check matching 2018-04-11 12:14:11 +02:00
Juan Ignacio Sánchez Lara
e5d2182da3 Removed geocoder_api user creation from version upgrade script 2018-04-11 11:50:30 +02:00
Juan Ignacio Sánchez Lara
33f23e0902 Minor instead of patch for TomTom support at Python lib 2018-04-10 11:36:34 +02:00
Juan Ignacio Sánchez Lara
94aeceb894 Fixes encoding 2018-04-10 09:32:23 +02:00
Juan Ignacio Sánchez Lara
e21d3e2e70 TomTom Python lib version 2018-04-09 16:29:00 +02:00
Juan Ignacio Sánchez Lara
adde2d3a46 0.31.0 release scripts 2018-04-09 14:41:44 +02:00
Juan Ignacio Sánchez Lara
6143c04c82 Remove server extension versioned files of outdated version changes 2018-04-09 13:11:50 +02:00
Juan Ignacio Sánchez Lara
3b121c8793 Merge branch 'master' into Added_TomTom_services 2018-04-09 13:07:04 +02:00
Mario de Frutos
e70aefba1d Merge pull request #491 from CartoDB/development
Release 0.30.5 for server and 0.17.6 for python library
2018-03-28 10:38:06 +02:00
Mario de Frutos
423fe42007 Merge pull request #488 from CartoDB/cc211-Isolines_should_always_return_multipolygon
Cc211 isolines should always return multipolygon
2018-03-28 10:35:43 +02:00
Mario de Frutos
5e141e3a10 Update NEWS.md 2018-03-28 10:34:45 +02:00
Mario de Frutos
50aa537a7a Bump python library version 2018-03-27 16:36:04 +02:00
Mario de Frutos
e25e2c26a0 Remove the PARALLEL modifiers from the version SQL artifact 2018-03-27 16:36:04 +02:00
Juan Ignacio Sánchez Lara
8025f657b8 Upgrade version scripts 2018-03-27 16:36:04 +02:00
Juan Ignacio Sánchez Lara
2a47000f32 coordinates_to_polygon should always return multipolygon to avoid inconsistencies 2018-03-27 16:36:04 +02:00
Mario de Frutos
53e9ad4d2e Merge pull request #490 from CartoDB/development
Release python library 0.17.5
2018-03-27 16:23:28 +02:00
Mario de Frutos
ea5818f08f Update NEWS.md 2018-03-27 16:20:29 +02:00
Mario de Frutos
2f8edbe5ce Merge pull request #476 from CartoDB/Avoid_reaching_provider_for_empty_geocodings
Avoid reaching provider for empty geocodings
2018-03-27 16:12:33 +02:00
Antonio
552a7d4886 Fixing Mapbox geocoding validity checks 2018-03-16 16:55:08 +01:00
Antonio
a34da0adb5 Fixed CR suggestions 2018-03-16 16:37:17 +01:00
Antonio
ab5ef64e83 Fixed CR suggestions 2018-03-16 16:35:28 +01:00
Antonio
f0cef02dfc Fixed CR suggestions 2018-03-16 16:33:45 +01:00
Antonio
e78063ae75 Fixed geocoding validity 2018-03-16 16:01:00 +01:00
Antonio
d66804b93d Fixed test 2018-03-16 14:47:56 +01:00
Antonio
6572891036 Merging changes 2018-03-16 14:30:01 +01:00
Antonio Carlón
59940ea994 Merge pull request #487 from CartoDB/development
Release server 0.30.4
2018-03-16 12:28:52 +01:00
Antonio Carlón
b9da6c9ec5 Merge pull request #486 from CartoDB/485-Add_CollectionExtract_to_MakeValid
Added ST_CollectionExtract
2018-03-16 12:26:06 +01:00
Antonio
ace7683ffe Added suggestion from CR 2018-03-16 12:14:14 +01:00
Antonio
6017b53ea0 Server version 0.30.4 2018-03-16 12:07:20 +01:00
Antonio
e15c6127d3 Added ST_CollectionExtract 2018-03-16 12:01:12 +01:00
Antonio Carlón
4bd8726720 Merge pull request #484 from CartoDB/development
Release server 0.30.3
2018-03-16 11:19:46 +01:00
Antonio
5d20d0bdf5 Updated NEWS.md 2018-03-16 11:16:57 +01:00
Antonio Carlón
db5ead6f98 Merge pull request #483 from CartoDB/1381MakeValidPolygonsForIsoMapboxDistances
Make valid polygons for iso mapbox distances
2018-03-16 11:13:29 +01:00
Ubuntu
44fae489a3 Update scripts 2018-03-15 15:09:21 +00:00
Alex Martín
71c93fe13a Add ST_MakeValid to sql 2018-03-15 15:58:15 +01:00
Antonio Carlón
d9c569881a Merge pull request #481 from CartoDB/development
Release python 0.17.4
2018-03-14 17:49:33 +01:00
Antonio Carlón
244d579f6f Merge pull request #480 from CartoDB/479-Fix_get_service_quota_info
Fixed error when checking quota
2018-03-14 17:41:22 +01:00
Antonio
c90859e58b Fixed error when checking quota 2018-03-14 16:26:00 +01:00
Antonio Carlón
12eecc271d Merge branch 'development' into Avoid_reaching_provider_for_empty_geocodings 2018-03-14 15:12:58 +01:00
Antonio Carlón
f216b6d922 Merge pull request #478 from CartoDB/development
Release python 0.17.3
2018-03-14 14:21:46 +01:00
Antonio Carlón
573a304bd2 Merge pull request #477 from CartoDB/fix_routing_quota
Fix routing quota
2018-03-14 14:18:00 +01:00
Antonio
f5cbc195cc Fixed tests 2018-03-14 13:31:00 +01:00
Mario de Frutos
e324afd77f Update NEWS.md 2018-03-14 11:20:56 +01:00
Mario de Frutos
0196292093 Bump version 2018-03-14 11:20:12 +01:00
Mario de Frutos
f652a52a8d Use routing quota instead of monthly quota 2018-03-14 11:19:48 +01:00
Antonio
1c38b33501 Updated server side scripts 2018-03-14 09:55:07 +01:00
Antonio
59751d7c9c Avoid reaching provider for empty geocodings 2018-03-13 16:01:05 +01:00
Antonio
ffa1080277 isochrones fix 2018-03-13 14:58:40 +01:00
Juan Ignacio Sánchez Lara
b279fafbc5 Merge pull request #474 from CartoDB/development
0.17.2 version of Python library
2018-03-05 16:17:11 +01:00
Juan Ignacio Sánchez Lara
07ed2a4112 Merge pull request #471 from CartoDB/1333-Mapbox_isolines_almost_shoreline
Fix Mapbox isolines near the shoreline
2018-03-05 16:14:45 +01:00
Antonio
da7d43cc08 Added client functions (untested) 2018-03-02 17:38:02 +01:00
Antonio
39800122b2 Merging 2018-03-02 17:25:32 +01:00
Antonio
12ac2c269d Modified expected result for test 2018-03-02 17:17:03 +01:00
Antonio
74c0bb6f26 Created new server version (0.31.0) 2018-03-02 17:09:25 +01:00
Antonio
c9d0f0447f Added server functions (untested) 2018-03-02 16:40:12 +01:00
Antonio
596189185f Added configuration for TomTom services 2018-03-02 16:01:22 +01:00
Antonio
35f743164e Keep deleting points that got None 2018-03-02 10:27:37 +01:00
Antonio
4308b5f351 Remove too far away points (filtering by time) 2018-03-02 10:23:58 +01:00
Antonio
9fb04fdc24 Version bumped 2018-02-28 11:49:23 +01:00
Antonio
a2fd0bf142 Merge branch 'master' into 1333-Mapbox_isolines_almost_shoreline 2018-02-28 11:48:00 +01:00
Antonio Carlón
6534b12606 Merge pull request #473 from CartoDB/development
Version 0.17.1 of the python library
2018-02-28 11:37:52 +01:00
Antonio Carlón
8d9c3a4bf7 Merge pull request #472 from CartoDB/fix_mapzen_routing
Fix mapzen routing bug
2018-02-28 11:35:26 +01:00
Mario de Frutos
ad46de1156 Bump version and update NEWS.md 2018-02-27 18:11:50 +01:00
Mario de Frutos
97f1611d62 Only get mapzen/mapbox values in case the provider of routing is one of these 2018-02-27 18:09:21 +01:00
Antonio
bc4c9fea33 Using Mapbox returned destinations as coordinates for isolines 2018-02-26 12:45:08 +01:00
Antonio
177c19f935 Added TomTom isolines 2018-02-23 15:59:54 +01:00
csubira
ef68ad4dcb Add new docs folder structure 2018-02-22 17:25:12 +01:00
Antonio Carlón
e110ab4cc3 Merge pull request #469 from CartoDB/development
Release 0.17.0
2018-02-22 12:46:34 +01:00
Antonio Carlón
e646000f24 Merge pull request #468 from CartoDB/remove_legacy_mapzen
Remove legacy mapzen
2018-02-22 12:41:48 +01:00
Mario de Frutos
05e2cc981e Change min log level for tests to WARNING 2018-02-22 11:20:16 +01:00
Mario de Frutos
cbc19b869c Fix CR suggestions 2018-02-22 11:14:33 +01:00
Mario de Frutos
199788748b Updated NEWS.md 2018-02-21 19:14:56 +01:00
Mario de Frutos
e3f23adfdd Bump to version 0.17.0 2018-02-21 19:14:47 +01:00
Mario de Frutos
39dabffb85 Now is not mandatory to have mapzen configuration becuase its deprecated as provider 2018-02-21 19:14:29 +01:00
Mario de Frutos
03e1d1ca61 Change default provider to mapbox instead of mapzen 2018-02-21 19:13:59 +01:00
Antonio
90d8d207eb Added geocoding and routing services 2018-02-16 17:43:22 +01:00
Mario de Frutos
c14fb057d3 Update README.md 2018-02-14 11:03:51 +01:00
Mario de Frutos
9e247685b8 Merge pull request #465 from CartoDB/457-Fix_Mapbox_Python_tests
457 fix mapbox python tests
2018-02-14 10:21:29 +01:00
Juan Ignacio Sánchez Lara
1fdb4d3b3a Pythonic refactor, importing single method 2018-02-13 18:24:21 +01:00
Juan Ignacio Sánchez Lara
029541f298 api_key -> mapbox_api_key rename refactor 2018-02-13 16:16:13 +01:00
Juan Ignacio Sánchez Lara
45d9edbba6 Mapbox test API key is supplied now through a MAPBOX_API_KEY environment variable 2018-02-13 15:58:10 +01:00
Mario de Frutos
39c54f3e0c Merge pull request #464 from CartoDB/development
Release 0.16.7
2018-02-13 13:26:44 +01:00
Mario de Frutos
54e40645fa Update NEWS.md 2018-02-13 11:51:06 +01:00
Mario de Frutos
a86b8e86f9 Merge pull request #462 from CartoDB/Fixing_mapbox_request_errors
Fixed Mapbox requests and responses
2018-02-13 11:46:45 +01:00
Antonio
8674dabeb2 Version bumped 2018-02-13 08:38:54 +01:00
Antonio
080a386b8f Fixed mapbox requests and responses 2018-02-12 18:02:37 +01:00
Antonio Carlón
972aba6cfb Merge pull request #459 from CartoDB/development
Mapbox permanent geocoder. Documentation
2018-02-12 12:54:40 +01:00
Antonio Carlón
9b43e8a92e Merge pull request #456 from CartoDB/455-Use_Mapbox_permanent_geocoder
Use Mapbox permanent geocoder
2018-02-12 12:45:09 +01:00
Antonio
4e311aef47 Updated NEWS.md 2018-02-12 12:40:56 +01:00
Antonio
b65d003742 Using Mapbox permanent geocoder by default 2018-02-09 09:07:31 +01:00
Iñigo Medina
b171951bc7 Merge pull request #421 from CartoDB/docs-1266-replace-content
updating content as per docs issue 1266, ready for review but do not …
2018-02-06 12:32:30 +01:00
Mario de Frutos
462773a138 Merge pull request #453 from CartoDB/development
Release python library version 0.16.5
2018-02-05 09:39:47 +01:00
Mario de Frutos
fad2f25183 Updated NEWS.md 2018-02-05 09:35:40 +01:00
Mario de Frutos
2f54ef7e4e Merge pull request #452 from CartoDB/fix_misplaced_coordinate_polyline
Multiple fixes
2018-02-05 09:30:24 +01:00
Mario de Frutos
ab4d77edf2 Merge pull request #377 from CartoDB/logger_conf_wrong_square_brackets
Removed wrong square brackets
2018-02-02 18:16:36 +01:00
Mario de Frutos
0b12f26f47 Add info about square brackets in server configuration of the README 2018-02-02 18:15:40 +01:00
Mario de Frutos
a116aba660 Merge pull request #379 from CartoDB/missing_grant_usage
Missing GRANT USAGE
2018-02-02 18:11:47 +01:00
Mario de Frutos
29d5a332b6 Change to reflect the current used user for the DS
Check this issue https://github.com/CartoDB/dataservices-api/issues/380
which talks about the renaming for a more proper name
2018-02-02 18:10:02 +01:00
Juan Ignacio Sánchez Lara
b2825f46a4 Missing GRANT USAGE 2018-02-02 18:08:01 +01:00
Mario de Frutos
a791d02dcc 422 errors from mapbox return empty response 2018-02-02 14:11:22 +01:00
Mario de Frutos
e2612645c3 Bump to version 0.16.5 2018-02-02 13:18:47 +01:00
Mario de Frutos
c5fed2cc80 Check for empty coordinates when we transform to polygon 2018-02-02 13:18:32 +01:00
Mario de Frutos
a1f339376e By default the polyline comes with 6 decimals so we avoid to use 5 by default 2018-02-02 13:17:56 +01:00
Mario de Frutos
019df2b4e0 Merge pull request #451 from CartoDB/development
Hotfix circular dependencies exceptions
2018-02-02 12:38:23 +01:00
Mario de Frutos
9e67beab3d Merge pull request #450 from CartoDB/move_exceptions_to_avoid_circular_dependencies
Move exceptions to a proper place
2018-02-02 12:37:14 +01:00
Mario de Frutos
5c7d1e9ac1 Solve some dependencies bugs 2018-02-02 12:29:48 +01:00
Mario de Frutos
6e54507b5a Move exceptions to a proper place 2018-02-02 12:06:43 +01:00
Mario de Frutos
14925ea448 Add missing imports for google gecode street 2018-02-02 11:18:56 +01:00
Mario de Frutos
26e0a5e00f Merge pull request #448 from CartoDB/development
Release server 0.30.2 and python library 0.16.4
2018-02-02 10:37:16 +01:00
Mario de Frutos
a99e0cb513 Updated NEWS.md 2018-02-02 10:32:24 +01:00
Mario de Frutos
1e4fef5868 Merge pull request #447 from CartoDB/dont_send_quota_exceptions_rollbar
Avoid treating quota exception as bug exception
2018-02-02 10:29:04 +01:00
Mario de Frutos
3973483af2 Move limits check inside the try 2018-02-01 19:03:32 +01:00
Mario de Frutos
88edad9414 Release artifacts for version 0.30.2 2018-02-01 18:46:24 +01:00
Mario de Frutos
88ad551e4a Bump python version to 0.16.4 2018-02-01 18:40:21 +01:00
Mario de Frutos
94eaf84f91 Treat quota exception as a failure 2018-02-01 18:27:32 +01:00
Mario de Frutos
0df0b0d49c Avoid treating quota exception as bug exception 2018-02-01 18:21:15 +01:00
Mario de Frutos
b260c29b8c Merge pull request #445 from CartoDB/development
Updated routing documentation
2018-02-01 12:10:20 +01:00
Mario de Frutos
da8aa5a8c0 Merge pull request #444 from CartoDB/fix_routing_documentation
Change routing docs with the Mapbox addition as provider
2018-02-01 12:05:27 +01:00
Mario de Frutos
423534068a Change routing docs with the Mapbox addition as provider 2018-02-01 11:55:22 +01:00
Mario de Frutos
6f508b550d Merge pull request #441 from CartoDB/development
Release python library 0.16.3
2018-01-31 17:06:00 +01:00
Mario de Frutos
1462f87d97 Merge pull request #440 from CartoDB/439_filter_empty_requests_mapbox_geocoder
Improve empty requests treatment in geocoders
2018-01-31 16:31:11 +01:00
Mario de Frutos
6ae8aa45fd CR changes 2018-01-31 16:13:20 +01:00
Mario de Frutos
02cb4862f9 Update NEWS.md 2018-01-31 13:18:09 +01:00
Mario de Frutos
07f00cc0ae Added tests for the client/channel part of google 2018-01-31 13:17:36 +01:00
Mario de Frutos
544e0fa763 Going green with non empty request strings 2018-01-31 12:25:35 +01:00
Mario de Frutos
2bbd6bac91 Going red with non empty request string 2018-01-31 12:25:18 +01:00
Mario de Frutos
2f8dbbb5dc Dont raise exception when empty params passed to HERE geocoder 2018-01-31 12:16:13 +01:00
Mario de Frutos
3484cce88b Update NEWS.md 2018-01-31 12:13:02 +01:00
Mario de Frutos
56c90cc541 Bump version to 0.16.3 2018-01-31 12:12:52 +01:00
Mario de Frutos
3583cc6f47 Going green with empty requests that leads to 404 responses 2018-01-31 12:11:25 +01:00
Mario de Frutos
850dc09a4f Going green with empty responses 2018-01-31 12:11:25 +01:00
Mario de Frutos
876bae6b56 Going red with bad request parameters 2018-01-31 12:11:25 +01:00
Mario de Frutos
8f30359cc7 Added rate limits topic to the README 2018-01-30 15:02:40 +01:00
Mario de Frutos
7be27969fa Merge pull request #438 from CartoDB/development
Release python version 0.16.2
2018-01-30 09:58:49 +01:00
Mario de Frutos
502039796f Merge pull request #437 from CartoDB/436-Fixing_valid_types
Fixed valid Mapbox types
2018-01-30 09:42:50 +01:00
Antonio
e0b1632fa8 Fixed tests 2018-01-30 09:13:43 +01:00
Antonio
51bf6c2a43 Fixed valid Mapbox types 2018-01-29 18:39:11 +01:00
Mario de Frutos
5f9185ee6b Merge pull request #435 from CartoDB/development
Release 0.30.1 server side
2018-01-29 17:43:51 +01:00
Mario de Frutos
08e21e3999 Updated NEWS.md 2018-01-29 17:42:30 +01:00
Mario de Frutos
212cbda9a0 Merge pull request #434 from CartoDB/433-Fixing_encoding_issues
Fixing encoding issues
2018-01-29 17:40:12 +01:00
Antonio
05718ce58c Fixed KeyError Exception 2018-01-29 17:32:44 +01:00
Antonio
fed444ff6c Version bumped 2018-01-29 17:18:18 +01:00
Antonio
d1c8f8ced0 Fixing encoding issues 2018-01-29 17:09:17 +01:00
Mario de Frutos
96d2bf6218 Update NEWS.md 2018-01-18 17:27:34 +01:00
Mario de Frutos
b4dc616590 Merge pull request #432 from CartoDB/development
Release python library 0.16.1
2018-01-18 17:24:23 +01:00
Mario de Frutos
4f907053f5 Merge pull request #431 from CartoDB/430-Fixed_encoding_problems_with_mapbox_geocoding
Fixed encoding problem with Mapbox geocoding
2018-01-18 17:21:20 +01:00
Antonio
1a2785dff4 Version bumped 2018-01-18 15:21:06 +01:00
Antonio
d442fab9da Fixed encoding problem with Mapbox geocoding 2018-01-18 11:55:25 +01:00
Antonio
236837ebb6 Release January 17th 2018 2018-01-17 16:19:57 +01:00
Antonio Carlón
6edad7b810 Merge pull request #429 from CartoDB/development
Release server 0.30.0 , client 0.23.0 and python library 0.16.0
2018-01-17 16:05:00 +01:00
Mario de Frutos
7d8cc4ae87 Fix bug that checks only for name of the custom type and not uses the
namespace
2018-01-16 18:28:54 +01:00
Mario de Frutos
41916eed18 Merge pull request #428 from CartoDB/427-Fixed_country_codes_for_Mapbox
Added iso3166 import
2018-01-16 17:31:20 +01:00
Antonio
9921f0f394 Added iso3166 import 2018-01-16 17:25:12 +01:00
Mario de Frutos
72b99a1729 Merge pull request #426 from CartoDB/425-Fixed_country_code_problem
Fixed country code problem
2018-01-16 16:44:12 +01:00
Antonio
6c53846e33 Fixed country code problem. Added test 2018-01-16 16:36:24 +01:00
Mario de Frutos
5781f78c7f Revert "Removed suspect import"
This reverts commit 9c1ec1ddde.
2018-01-16 11:04:29 +01:00
Mario de Frutos
8127314965 Merge pull request #424 from CartoDB/423-Fix_staging_error
Removed suspect import
2018-01-16 10:18:13 +01:00
Antonio
9c1ec1ddde Removed suspect import 2018-01-16 10:02:41 +01:00
Antonio
d1d8713f05 Generated sql files 2018-01-15 11:22:34 +01:00
Antonio
0ed477d264 Generated sql files 2018-01-15 11:18:04 +01:00
Antonio Carlón
42abfd962c Merge pull request #420 from CartoDB/Clients_for_Mapbox_services
Python implementation of clients for Mapbox services
2018-01-15 11:08:57 +01:00
Antonio
61e8273a47 Removed unneccessary drop functions 2018-01-15 11:07:50 +01:00
Antonio
6339623ad9 Added ServiceManager for Mapbox services 2018-01-12 12:24:17 +01:00
elenatorro
ae32f91c7c Fix Logger config 2018-01-12 09:53:58 +01:00
Antonio
a02a634e76 Added metrics for DO (related to #419 and removed for easy merging) 2018-01-11 11:13:37 +01:00
Antonio
7dc87ad38e Rotating API keys for Mapbox 2018-01-11 10:18:01 +01:00
Mario de Frutos
af0125197d Merge pull request #422 from CartoDB/development
Release python 0.15.7
2018-01-10 16:36:47 +01:00
Antonio Carlón
b10f48166d Merge branch 'development' into Clients_for_Mapbox_services 2018-01-10 12:50:20 +01:00
Mario de Frutos
051453898e Merge pull request #419 from CartoDB/260-Tracking_OBS_usage
Logging GetMeta and GetData parameters
2018-01-10 12:49:13 +01:00
Mario de Frutos
6047300259 Move the new params parameter to the end to avoid breaking backward compatibility 2018-01-10 12:41:08 +01:00
Antonio
b282c7db5b Fixed tests 2018-01-10 12:33:10 +01:00
Mario de Frutos
84749a2631 Revert SQL changes just leave the python ones 2018-01-10 12:31:49 +01:00
Antonio
c0cc5fe6a7 Logging GetMeta and GetData parameters 2018-01-10 12:31:49 +01:00
Antonio
7d99ede28d Error fixed 2018-01-10 11:55:02 +01:00
Antonio
cd5dba920e Using user's configured geocoder for namedplaces via street point 2018-01-10 10:34:18 +01:00
Antonio
6d978deb16 Using user's configured geocoder for namedplaces via street point 2018-01-10 10:16:59 +01:00
Antonio
d3e01b4d53 Reverted default providers to mapzen to allow dark deployment 2018-01-09 17:15:03 +01:00
Antonio
dd6ad0119c Added CR suggestions 2018-01-09 16:21:55 +01:00
Antonio
3bbb3c6bcc Autogenerated sql file 2018-01-04 18:02:49 +01:00
Antonio
fa3f2fbc3a Modified SQL files 2018-01-04 17:58:46 +01:00
Antonio
dc5dbe8c0a Fixing tests 2018-01-04 16:01:32 +01:00
Antonio
e7c0628751 Solving errors and refactor 2018-01-04 15:00:52 +01:00
csobier
7775d2373d updating content as per docs issue 1266, ready for review but do not merge until given notice 2018-01-04 08:29:02 -05:00
Antonio
51d97228dc Added CR suggestions 2018-01-04 12:30:58 +01:00
Antonio
cc34a8b19b Added Mapbox configuration to README.md 2018-01-03 14:19:49 +01:00
Antonio
801c5a3cee Solved data conversion issues 2018-01-03 14:14:25 +01:00
Antonio
941af522ae Bumped Python library version 2018-01-03 09:47:55 +01:00
Antonio
bb86f080fc Added limits/quotas and tests for Mapbox services 2018-01-02 16:21:57 +01:00
Antonio
15340fedad Added cdb_dataservices_client functions 2017-12-29 15:28:29 +01:00
Antonio
c46174210d Added cdb_dataservices_server functions 2017-12-29 14:07:51 +01:00
Antonio
af07def7fc Added parameters for PLPython functions 2017-12-28 11:36:02 +01:00
Antonio
bc9dbdbb72 Removed routing client from isolines 2017-12-27 16:31:29 +01:00
Antonio
dabd596271 Added QPS decorator 2017-12-27 14:55:50 +01:00
Antonio
8c0af7d51d Pure Python implementation of clients for Mapbox services 2017-12-27 13:43:14 +01:00
Mario de Frutos
b16f7e6ed5 Merge pull request #416 from CartoDB/Added_sudo_to_pip_install
Added sudo to pip install
2017-12-12 12:46:00 +01:00
Rafa de la Torre
1ea5400e40 Merge pull request #418 from CartoDB/417-fix-client-upgrade
Fix for client upgrade #417
2017-12-01 17:15:15 +01:00
Rafa de la Torre
c7bae90e93 Update NEWS.md 2017-12-01 17:03:05 +01:00
Rafa de la Torre
604e802807 Add DROP FUNCTION's to the upgrade script #417 2017-12-01 17:00:49 +01:00
Rafa de la Torre
27c17ddc8b Re-generated extension file #417 2017-12-01 16:56:45 +01:00
Rafa de la Torre
feff20ac5a Use params_with_type to avoid DEFAULT #417 2017-12-01 16:40:39 +01:00
Rafa de la Torre
4c996733ce Fix for client upgrade #417 2017-12-01 16:31:57 +01:00
Rafa de la Torre
046b8f71f9 Revert "Fix bad renaming of function parameter"
This reverts commit 63786caaa6.
2017-12-01 13:35:45 +01:00
Antonio
9b8045f2ed Added sudo to pip install requirements.txt 2017-12-01 13:27:11 +01:00
Rafa de la Torre
63786caaa6 Fix bad renaming of function parameter
This fixes the following error when trying to upgrade:

```
cannot change name of input parameter "organization_name"
```

The problem was introduced ages ago. I fixed it by running a script:

```bash
BAD_REGEXP='CREATE OR REPLACE FUNCTION cdb_dataservices_client\._cdb_geocode_admin0_polygon (username text, orgname text, country_name text)'
REPLACEMENT='CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin0_polygon (username text, organization_name text, country_name text)'
git grep -l "$BAD_REGEXP" | xargs sed -i "s/$BAD_REGEXP/$REPLACEMENT/g"
```
2017-12-01 12:52:17 +01:00
Rafa de la Torre
9d9262c0e7 Update NEWS.md 2017-12-01 11:18:22 +01:00
Rafa de la Torre
580f6d9867 Make the install target depend on deploy
The deploy target strips the PARALLEL tag when needed. This is done for
versions not supporting it.
2017-12-01 10:47:30 +01:00
Rafa de la Torre
48942cbb03 Fix typo in PARALLEL stripping 2017-12-01 10:25:10 +01:00
Rafa de la Torre
e4a2e13f69 Merge pull request #413 from CartoDB/server-0.29.0
Server 0.29.0
2017-11-30 13:11:43 +01:00
Rafa de la Torre
048aebedd9 Remove permissions stuff from downgrade script 2017-11-30 13:08:54 +01:00
Rafa de la Torre
1bcfa30938 Remove type creation from downgrade script 2017-11-30 13:08:26 +01:00
Rafa de la Torre
24098a6d2c Remove duplicated header 2017-11-30 13:07:31 +01:00
Rafa de la Torre
645818838b Append old script to downgrade stub 2017-11-30 13:06:57 +01:00
Rafa de la Torre
a2929e88cc Remove permissions stuff from upgrade script 2017-11-30 13:04:34 +01:00
Rafa de la Torre
7e7432b4ec Remove type creation from upgrade script 2017-11-30 13:04:09 +01:00
Rafa de la Torre
82db791706 Delete duplicate header from upgrade script 2017-11-30 13:02:28 +01:00
Rafa de la Torre
d21aa07673 Apend contents of extension to upgrade stub 2017-11-30 13:01:32 +01:00
Rafa de la Torre
dec7842240 Stub new server v0.29.0 2017-11-30 13:00:23 +01:00
Rafa de la Torre
0cb359a9bc Add some instructions to make release target 2017-11-30 12:59:11 +01:00
Rafa de la Torre
5bdf10936e Merge pull request #412 from CartoDB/client-0.22.0
Client 0.22.0
2017-11-30 12:49:57 +01:00
Rafa de la Torre
bf424a8f1e Remove permissions stuff from downgrade script 2017-11-30 12:43:28 +01:00
Rafa de la Torre
ccf27eaa5c Remove type creation from downgrade script 2017-11-30 12:42:51 +01:00
Rafa de la Torre
d2980aa30c Remove duplicate header from downgrade script 2017-11-30 12:41:49 +01:00
Rafa de la Torre
bffd6e8200 Append contents of old version to downgrade script
I just did this:

```
cat old_versions/cdb_dataservices_client--0.21.0.sql >> cdb_dataservices_client--0.22.0--0.21.0.sql
```
2017-11-30 12:40:57 +01:00
Rafa de la Torre
89792b2d0c Remove permissions stuff from client upgrade 2017-11-30 12:38:18 +01:00
Rafa de la Torre
8446c9c388 Remove type creation from client upgrade 2017-11-30 12:37:33 +01:00
Rafa de la Torre
29693ddc81 Remove duplicated header from upgrade 2017-11-30 12:36:44 +01:00
Rafa de la Torre
2213900831 Copy content of new version into upgrade script
I just ran the following:

```
cat cdb_dataservices_client--0.22.0.sql >> cdb_dataservices_client--0.21.0--0.22.0.sql
```
2017-11-30 12:35:25 +01:00
Rafa de la Torre
f645766235 Stub new client version 0.22.0 2017-11-30 12:31:36 +01:00
Rafa de la Torre
657e4064ef Add some instructions to the make release target 2017-11-30 12:27:07 +01:00
Rafa de la Torre
b5c0e135f9 Revert "PG release: Include all files in git upon release"
This reverts commit b44778c586.
2017-11-30 12:19:11 +01:00
Raúl Marín
f4d57007c2 Merge pull request #411 from Algunenano/parallel_deploy
PG release: Strip PARALLEL on deploy instead of release
2017-11-28 17:59:31 +01:00
Raul Marin
b44778c586 PG release: Include all files in git upon release 2017-11-28 16:27:45 +01:00
Raul Marin
723a3d02ff PG release: Strip PARALLEL on deploy instead of release 2017-11-28 15:44:30 +01:00
Raúl Marín
6180b00525 Merge pull request #408 from Algunenano/parallel
Client: Add PARALLEL and VOLATILE categories
2017-11-27 13:56:01 +01:00
Raul Marin
5086ee908d Update CONTRIBUTING with information about SQL function labels 2017-11-24 16:44:47 +01:00
Mario de Frutos
f751530dd2 Merge pull request #410 from CartoDB/development
Release 0.15.6 of the python library
2017-11-17 11:24:49 +01:00
Mario de Frutos
d42fb3cf8e Updated NEWS.md 2017-11-17 11:20:06 +01:00
Mario de Frutos
4f5117611f Merge pull request #409 from CartoDB/s1060-google_geocoding_returns_null
Support for multiple parameters at client (such as channel)
2017-11-17 11:17:45 +01:00
Raul Marin
ff71a406ae Server: Categorize functions
Redis/Service functions declared as STATIC to avoid unneded calls
but it's really questionable if they trully are
2017-11-14 16:48:48 +01:00
Raul Marin
98206a3296 Server: Mark all plproxy functions as VOLATILE PARALLEL UNSAFE 2017-11-14 16:48:48 +01:00
Raul Marin
a69da0084b Server: Add PARALLEL support 2017-11-14 16:48:48 +01:00
Raul Marin
80fc32e1ea Categorize renderer template functions 2017-11-14 16:45:36 +01:00
Raul Marin
b8527514b7 Client: Add PARALLEL and VOLATILE categories
I'm not 100% sure what's appropiate for plproxy functions so, for now,
I've set them up as VOLATILE and PARALLEL UNSAFE
2017-11-14 16:45:36 +01:00
Juan Ignacio Sánchez Lara
da8e5f6e36 Extract parsing and return fix 2017-11-14 13:15:11 +01:00
Juan Ignacio Sánchez Lara
f540a3d6b3 Bump version 2017-11-13 19:09:52 +01:00
Juan Ignacio Sánchez Lara
e26bf2a803 Proper parsing of client and channel parameters 2017-11-13 19:09:17 +01:00
Juan Ignacio Sánchez Lara
43dd9f6ada Better regexp and wrong input handling 2017-11-08 17:33:00 +01:00
Juan Ignacio Sánchez Lara
2cf4072b21 Support for multiple parameters at client (such as channel) 2017-11-08 11:07:35 +01:00
274 changed files with 143038 additions and 978 deletions

2
.gitignore vendored
View File

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

View File

@@ -5,6 +5,23 @@ The issue tracker is at [github.com/CartoDB/dataservices-api](https://github.com
We love pull requests from everyone, see [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/#contributing).
## PostgreSQL
When adding or modifying PostgreSQL functions make sure that the
[VOLATILITY](https://www.postgresql.org/docs/current/static/xfunc-volatility.html) and [PARALLEL](https://www.postgresql.org/docs/9.6/static/parallel-safety.html) categories are updated accordingly.
Please mark public [client functions](client/sql) or [templates](client/renderer/templates)
as STABLE even if the internals are VOLATILE to allow the planner to cache
results inside a query. For example, in this query we need `cdb_geocode_admin1_polygon`
to be STABLE so it gets called only once (instead of once per row):
```sql
SELECT * japank WHERE NOT (the_geom && cdb_geocode_admin1_polygon('Madrid', 'Spain'));
```
As PARALLEL labels need to be stripped for incompatible PostgreSQL versions,
please use _PARALLEL SAFE/RESTRICTED/UNSAFE_ in uppercase so it's handled
automatically.
## Submitting Contributions

195
NEWS.md
View File

@@ -1,3 +1,198 @@
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.
* Support for TomTom routing, geocoding and isolines.
March 28th, 2018
================
* Version `0.30.5` of server side and `0.17.6` of the python library
* All the returned polygons are now always MULTIPOLYGON #488
March 27th, 2018
================
* Version `0.17.5` of python library
* Avoid reaching provider for empty geocodings (but still incrementing empty service use) #476
March 16th, 2018
================
* Version `0.30.3` of server side
* Fix problem with invalid Mapbox isolines #483
* Version `0.30.4` of server side
* Added ST_CollectionExtract to ST_MakeValid for Mapbox isolines to avoid non-polygonal geometries #486
March 14th, 2018
================
* Version `0.17.4` of the python library
* Fix bug with previous version when checking quotas #480
* Version `0.17.3` of the python library
* Fix bug with Mapbox routing not using the proper quota value #477
February 22th, 2018
==================
* Version `0.17.2` of the python library
* Fix bug with Mapbox isolines not stopping at the seacoast #471
February 27th, 2018
==================
* Version `0.17.1` of the python library
* Fix bug when the mapzen credentials are not in the db config and we keep getting them
February 22th, 2018
==================
* Version `0.17.0` of the python library
* Change default provider to Mapbox
* Remove the obligatory nature of the Mapzen configuration due to its deprecation as provider
February 13th, 2018
==================
* Version `0.16.7` of the python library
* Pick the first result when Mapbox geocoder returns multiple results #462
* Normalize input for Mapbox geocoder #462
February 12th, 2018
==================
* Version `0.16.6` of the python library
* Using Mapbox permanent geocoder #455
February 5th, 2018
==================
* Version `0.16.5` of the python library
* Fix displaced routing shape #443
* Check for empty coordinates object before converting it to polygon
* 422 errors that come from Mapbox now returns an empty result because is a bad input from the user data
February 2th, 2018
==================
* Version `0.16.4` of the python library
* Create a QuotaExceededException instead of using a generic one
* Version `0.30.2` of server side
* Return empty value when the quota is exceeded and don't send the exception to external loggers
to avoid noise
January 31th, 2018
==================
* Version `0.16.3` of the python library
* Fix for Mapbox geocoder to handle empty requests and empty responses
* Remove raising an exception when non parameters are passed to the HERE geocoder
* Fix for HERE geocoder with non empty requests
* Added more coverage to the google geocoder credentials parse logic
January 29th, 2018
==================
* Version `0.30.1` of server side
* Fix for Mapbox geocoding function due to the iso3166 library doesn't support UTF-8 names for the countries
* Version `0.16.2` of the python library
* Fix for Mapbox cycling profile
January 18th, 2018
==================
* Version `0.16.1` of the python library
* Fixed encoding problem with Mapbox geocoding (using the Mapbox Python library)
January 17th, 2018
==================
* Version `0.16.0` of the python library
* Added Mapbox provider for routing, geocoding and isolines
* Version `0.30.0` of the server extension
* Added Mapbox provider for routing, geocoding and isolines
* Fixed a bug that makes impossible to install server side if the client is already installed due a namespace problem
* Version `0.23.0` of the client
* Added Mapbox provider for routing, geocoding and isolines
December 1st, 2017
==================
* Version `0.29.0` of the server extension
* Functions qualified with PARALLEL and volatility
* Version `0.22.0` of the client
* Functions qualified with PARALLEL and volatility
* Fixed an issue with upgrades from older versions. See #417
November 17th, 2017
=================
* Version `0.15.6` of the python library
* Added support for channels for google geocoder #409
* Improved the way we manage the client_id #409
October 18th, 2017
=================
* Version `0.21.0` of the client extension

View File

@@ -38,14 +38,14 @@ Steps to deploy a new Data Services API version :
```
# in dataservices-api repo root path:
cd server/lib/python/cartodb_services && pip install -r requirements.txt && sudo pip install . --upgrade
cd server/lib/python/cartodb_services && sudo pip install -r requirements.txt && sudo pip install . --upgrade
```
- Create a database to hold all the server part and a user for it
```sql
CREATE DATABASE dataservices_db ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
CREATE USER dataservices_user;
CREATE USER geocoder_api;
```
- Install needed extensions in `dataservices_db` database
@@ -90,19 +90,23 @@ Steps to deploy a new Data Services API version :
```
psql -U postgres -d dataservices_db -f src/pg/test/fixtures/load_fixtures.sql
```
- Give permission to execute and select to the `dataservices_user` user:
- 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 dataservices_user; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_observatory TO dataservices_user; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT SELECT ON ALL TABLES IN SCHEMA observatory TO dataservices_user; COMMIT" -e
psql -U postgres -d dataservices_db -c "BEGIN;GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA observatory TO dataservices_user; 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()`.
**All the configuration inside brackets [] is optional**
#### Redis configuration
If sentinel is used:
@@ -158,6 +162,33 @@ SELECT CDB_Conf_SetConf(
);
```
#### Mapbox configuration
```sql
SELECT CDB_Conf_SetConf(
'mapbox_conf',
'{"routing": {"api_keys": ["your_api_key"], "monthly_quota": 999999}, "geocoder": {"api_keys": ["your_api_key"], "monthly_quota": 999999}, "matrix": {"api_keys": ["your_api_key"], "monthly_quota": 1500000}}'
);
```
#### TomTom configuration
```sql
SELECT CDB_Conf_SetConf(
'tomtom_conf',
'{"routing": {"api_keys": ["your_api_key"], "monthly_quota": 999999}, "geocoder": {"api_keys": ["your_api_key"], "monthly_quota": 999999}, "isolines": {"api_keys": ["your_api_key"], "monthly_quota": 1500000}}'
);
```
#### Geocod.io configuration
```sql
SELECT CDB_Conf_SetConf(
'geocodio_conf',
'{"geocoder": {"api_keys": ["your_api_key"], "monthly_quota": 999999}}'
);
```
#### Data Observatory
```sql
@@ -172,10 +203,12 @@ SELECT CDB_Conf_SetConf(
```sql
SELECT CDB_Conf_SetConf(
'logger_conf',
'{"geocoder_log_path": "/tmp/geocodings.log", [ "min_log_level": "[debug|info|warning|error]", "rollbar_api_key": "SERVER_SIDE_API_KEY", "log_file_path": "LOG_FILE_PATH"]}'
'{"geocoder_log_path": "/tmp/geocodings.log", "min_log_level": "LOG_LEVEL", "rollbar_api_key": "SERVER_SIDE_API_KEY", "log_file_path": "LOG_FILE_PATH"}'
);
```
Where `LOG_LEVEL` can be `debug`, `info`, `warning` or `error`.
#### Environment
The execution environment (development/staging/production) affects rollbar messages and other details.
@@ -284,4 +317,7 @@ ALTER ROLE "<USER_ROLE>" SET search_path="$user", public, cartodb, cdb_dataservi
#### Option 2 (from builder)
See [the **Configuring Dataservices** documentation](http://cartodb.readthedocs.io/en/latest/operations/configure_data_services.html)
See [the **Configuring Dataservices** documentation](http://cartodb.readthedocs.io/en/latest/operations/configure_data_services.html)
### Rate limits
See [docs](https://github.com/CartoDB/dataservices-api/blob/master/doc/rate_limits.md)

View File

@@ -8,6 +8,11 @@ SED = sed
ERB = erb
REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g'
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
AWK = awk
# Parallel support macros
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))
# OLD_VERSIONS = $(wildcard old_versions/*.sql)
# DATA = $(NEW_EXTENSION_ARTIFACT) \
@@ -50,6 +55,13 @@ 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)
@@ -64,9 +76,30 @@ release: $(EXTENSION).control $(SOURCES_DATA)
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
@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
# Only meant for development time, do not use once a version is released
.PHONY: devclean
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)
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; \
done
endif
# Install the current release into the PostgreSQL extensions directory
deploy: release_remove_parallel_deploy
$(INSTALL_DATA) $(EXTENSION).control '$(DESTDIR)$(datadir)/extension/'
$(INSTALL_DATA) old_versions/*.sql *.sql '$(DESTDIR)$(datadir)/extension/'
install: deploy

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.32.0"
},
"works_with": {
}
}
}

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;

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;

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.21.0'
default_version = '0.28.0'
requires = 'plproxy, cartodb'
superuser = true
schema = 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

@@ -0,0 +1,200 @@
--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.23.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_mapbox_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
RETURNS Geometry AS $$
DECLARE
ret Geometry;
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;
SELECT cdb_dataservices_client._cdb_mapbox_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret; RETURN ret;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_mapbox_isochrone (source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_mapbox_isochrone(username, orgname, source, mode, range, options);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_mapbox_isodistance (source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_mapbox_isodistance(username, orgname, source, mode, range, options);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapbox_geocode_street_point_exception_safe (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
RETURNS Geometry AS $$
DECLARE
ret Geometry;
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
SELECT cdb_dataservices_client._cdb_mapbox_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;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapbox_isochrone_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_mapbox_isochrone(username, orgname, source, mode, range, options);
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;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapbox_isodistance_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_mapbox_isodistance(username, orgname, source, mode, range, options);
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;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapbox_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_mapbox_geocode_street_point (username, orgname, searchtext, city, state_province, country);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapbox_isochrone (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT * FROM cdb_dataservices_server.cdb_mapbox_isochrone (username, orgname, source, mode, range, options);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_mapbox_isodistance (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT * FROM cdb_dataservices_server.cdb_mapbox_isodistance (username, orgname, source, mode, range, options);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_mapbox_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_mapbox_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text ) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_mapbox_isochrone(source geometry(Geometry, 4326), mode text, range integer[], options text[]) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_mapbox_isochrone_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[] ) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_mapbox_isodistance(source geometry(Geometry, 4326), mode text, range integer[], options text[]) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_mapbox_isodistance_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[] ) TO publicuser;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
--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.22.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_mapbox_geocode_street_point (searchtext text, city text, state_province text, country text);
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_mapbox_isochrone (source geometry(Geometry, 4326), mode text, range integer[], options text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_mapbox_isodistance (source geometry(Geometry, 4326), mode text, range integer[], options text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapbox_geocode_street_point_exception_safe (searchtext text, city text, state_province text, country text);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapbox_isochrone_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapbox_isodistance_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapbox_geocode_street_point (username text, orgname text, searchtext text, city text, state_province text, country text);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapbox_isochrone (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapbox_isodistance (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[]);

View File

@@ -0,0 +1,202 @@
--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.24.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_tomtom_geocode_street_point (searchtext text ,city text DEFAULT NULL ,state_province text DEFAULT NULL ,country text DEFAULT NULL)
RETURNS Geometry AS $$
DECLARE
ret Geometry;
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;
SELECT cdb_dataservices_client._cdb_tomtom_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret; RETURN ret;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_tomtom_isochrone (source geometry(Geometry, 4326) ,mode text ,range integer[] ,options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_tomtom_isochrone(username, orgname, source, mode, range, options);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_tomtom_isodistance (source geometry(Geometry, 4326) ,mode text ,range integer[] ,options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_tomtom_isodistance(username, orgname, source, mode, range, options);
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_tomtom_geocode_street_point_exception_safe (searchtext text ,city text DEFAULT NULL ,state_province text DEFAULT NULL ,country text DEFAULT NULL)
RETURNS Geometry AS $$
DECLARE
ret Geometry;
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
SELECT cdb_dataservices_client._cdb_tomtom_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;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_tomtom_isochrone_exception_safe (source geometry(Geometry, 4326) ,mode text ,range integer[] ,options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_tomtom_isochrone(username, orgname, source, mode, range, options);
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;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_tomtom_isodistance_exception_safe (source geometry(Geometry, 4326) ,mode text ,range integer[] ,options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline 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_tomtom_isodistance(username, orgname, source, mode, range, options);
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_tomtom_geocode_street_point (username text, orgname text, searchtext text, city text, state_province text, country text);
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_tomtom_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_tomtom_geocode_street_point (username, orgname, searchtext, city, state_province, country);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_isochrone (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[]);
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_tomtom_isochrone (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT * FROM cdb_dataservices_server.cdb_tomtom_isochrone (username, orgname, source, mode, range, options);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_isodistance (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[]);
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_tomtom_isodistance (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
RETURNS SETOF cdb_dataservices_client.isoline AS $$
CONNECT cdb_dataservices_client._server_conn_str();
SELECT * FROM cdb_dataservices_server.cdb_tomtom_isodistance (username, orgname, source, mode, range, options);
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_tomtom_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_tomtom_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text ) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_tomtom_isochrone(source geometry(Geometry, 4326), mode text, range integer[], options text[]) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_tomtom_isochrone_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[] ) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_tomtom_isodistance(source geometry(Geometry, 4326), mode text, range integer[], options text[]) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_dataservices_client._cdb_tomtom_isodistance_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[] ) TO publicuser;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
--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.23.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_tomtom_geocode_street_point (text, text, text, text);
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_tomtom_isochrone (geometry(Geometry, 4326), text, integer[], text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_tomtom_isodistance (geometry(Geometry, 4326), text, integer[], text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_geocode_street_point_exception_safe (text, text, text, text);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_isochrone_exception_safe (geometry(Geometry, 4326), text, integer[], text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_isodistance_exception_safe (geometry(Geometry, 4326), text, integer[], text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_geocode_street_point (username text, orgname text, searchtext text, city text, state_province text, country text);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_isochrone (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[]);
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_tomtom_isodistance (username text, orgname text, source geometry(Geometry, 4326), mode text, range integer[], options text[]);

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;

File diff suppressed because it is too large Load Diff

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

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,43 @@
- { 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'}
- { name: state_province, type: text, default: 'NULL'}
- { name: country, type: text, default: 'NULL'}
- name: cdb_mapbox_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'}
- { name: state_province, type: text, default: 'NULL'}
- { name: country, type: text, default: 'NULL'}
- name: cdb_tomtom_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'}
- { 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'}
@@ -87,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'}
@@ -98,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[]' }
@@ -108,8 +199,37 @@
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[]' }
- name: cdb_mapbox_isochrone
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: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
- name: cdb_tomtom_isochrone
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: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -118,8 +238,37 @@
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[]' }
- name: cdb_mapbox_isodistance
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: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
- name: cdb_tomtom_isodistance
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: "public.geometry(Geometry, 4326)" }
- { name: mode, type: text }
- { name: range, type: "integer[]" }
- { name: options, type: "text[]", default: 'ARRAY[]::text[]' }
@@ -128,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[]' }
@@ -137,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'"}
@@ -147,56 +302,80 @@
- 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
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.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
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: geometry_level, type: text, default: 'NULL' }
- name: obs_getdemographicsnapshot
return_type: SETOF JSON
multi_row: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.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
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: geometry_level, type: text, default: 'NULL' }
- name: obs_getboundary
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getboundaryid
return_type: text
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- name: obs_getboundarybyid
return_type: Geometry
return_type: public.Geometry
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geometry_id, type: text }
- { name: boundary_id, type: text }
@@ -206,11 +385,14 @@
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- { name: overlap_type, type: text, default: 'NULL'}
@@ -219,11 +401,14 @@
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: radius, type: numeric }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
@@ -233,11 +418,14 @@
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
- { name: overlap_type, type: text, default: 'NULL'}
@@ -246,11 +434,14 @@
return_type: TABLE(the_geom geometry, geom_refs text)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: the_geom, type: geometry }
- { name: geom_refs, type: text }
params:
- { name: geom, type: "geometry(Geometry, 4326)" }
- { name: geom, type: "public.geometry(Geometry, 4326)" }
- { name: radius, type: numeric }
- { name: boundary_id, type: text }
- { name: time_span, type: text, default: 'NULL'}
@@ -258,8 +449,11 @@
- name: obs_getmeasure
return_type: numeric
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: Geometry }
- { name: geom, type: public.Geometry }
- { name: measure_id, type: text }
- { name: normalize, type: text, default: 'NULL'}
- { name: boundary_id, type: text, default: 'NULL' }
@@ -267,6 +461,9 @@
- name: obs_getmeasurebyid
return_type: numeric
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom_ref, type: text }
- { name: measure_id, type: text }
@@ -277,6 +474,9 @@
return_type: TABLE(id int, data json)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: id, type: integer }
- { name: data, type: json }
@@ -289,6 +489,9 @@
return_type: TABLE(id text, data json)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: id, type: text }
- { name: data, type: json }
@@ -298,8 +501,11 @@
- name: obs_getmeta
return_type: json
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom_ref, type: "Geometry(Geometry, 4326)" }
- { name: geom_ref, type: "public.Geometry(Geometry, 4326)" }
- { name: params, type: json }
- { name: max_timespan_rank, type: integer, default: 'NULL' }
- { name: max_score_rank, type: integer, default: 'NULL' }
@@ -309,24 +515,33 @@
return_type: TABLE(valid boolean, errors text[])
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom_extent, type: "Geometry(Geometry, 4326)" }
- { name: geom_extent, type: "public.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
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: Geometry }
- { name: geom, type: public.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
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: Geometry }
- { name: geom, type: public.Geometry }
- { name: name, type: text }
- { name: normalize, type: text, default: 'NULL'}
- { name: boundary_id, type: text, default: 'NULL' }
@@ -334,16 +549,22 @@
- name: obs_getuscensuscategory
return_type: text
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: Geometry }
- { name: geom, type: public.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
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: geom, type: Geometry }
- { name: geom, type: public.Geometry }
- { name: normalize, type: text, default: 'NULL'}
- { name: boundary_id, type: text, default: 'NULL' }
- { name: time_span, type: text, default: 'NULL'}
@@ -352,6 +573,9 @@
return_type: TABLE(id text, description text, name text, aggregate text, source text)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
table_fields:
- { name: id, type: text }
- { name: description, type: text }
@@ -366,17 +590,23 @@
return_type: TABLE(boundary_id text, description text, time_span text, tablename text)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
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: geom, type: public.Geometry }
- { name: timespan, type: text, default: 'NULL'}
- name: obs_dumpversion
return_type: text
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- {}
@@ -384,8 +614,11 @@
return_type: SETOF cdb_dataservices_client.obs_meta_numerator
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: bounds, type: "public.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' }
@@ -395,8 +628,11 @@
return_type: SETOF cdb_dataservices_client.obs_meta_numerator
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: bounds, type: "public.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[]' }
@@ -410,8 +646,11 @@
return_type: SETOF cdb_dataservices_client.obs_meta_denominator
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: bounds, type: "public.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' }
@@ -421,8 +660,11 @@
return_type: SETOF cdb_dataservices_client.obs_meta_geometry
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: bounds, type: "public.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' }
@@ -433,8 +675,11 @@
return_type: SETOF cdb_dataservices_client.obs_meta_timespan
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
- { name: bounds, type: "public.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' }
@@ -444,6 +689,9 @@
return_type: TABLE(name text, subsection json)
multi_row: true
multi_field: true
requires_permission: true
permission_name: observatory
permission_error: Data Observatory permission denied
params:
- { name: aggregate_type, type: text, default: 'NULL' }
@@ -454,6 +702,13 @@
params:
- {}
- name: cdb_service_quota_info_batch
return_type: SETOF service_quota_info_batch
multi_row: true
multi_field: true
params:
- {}
- name: cdb_enough_quota
return_type: BOOLEAN
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;
$$ 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;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE
SET search_path = pg_temp;

View File

@@ -1,3 +1,4 @@
DROP FUNCTION IF EXISTS <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (<%= params_with_type(true).join(', ') %>);
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (<%= params_with_type_and_default(_with_user_org=true).join(', ') %>)
RETURNS <%= return_type %> AS $$
CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str();
@@ -6,4 +7,4 @@ RETURNS <%= return_type %> AS $$
<% else %>
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= params(_with_user_org=true).join(', ') %>);
<% end %>
$$ LANGUAGE plproxy;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;

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

@@ -13,4 +13,4 @@ BEGIN
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
RETURN db_connection_str;
END;
$$ LANGUAGE 'plpgsql';
$$ LANGUAGE 'plpgsql' STABLE PARALLEL SAFE;

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;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL SAFE
SET search_path = pg_temp;

View File

@@ -4,6 +4,12 @@ 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,
@@ -35,3 +41,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

@@ -18,7 +18,7 @@ BEGIN
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);
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument';
@@ -41,7 +41,9 @@ BEGIN
RETURN result;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE
SET search_path = pg_temp;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure(
table_name text,
@@ -62,7 +64,7 @@ BEGIN
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);
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text, p json);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
RAISE EXCEPTION 'Username is a mandatory argument';
@@ -89,7 +91,9 @@ BEGIN
RETURN result;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE
SET search_path = pg_temp;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PrepareTableOBS_GetMeasure(
@@ -124,7 +128,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PrepareTableOBS_GetMeas
# Create a new table with the required columns
plpy.execute('CREATE TABLE "{schema}".{table_name} ( '
'cartodb_id int, the_geom geometry, {columns_with_types} '
'cartodb_id int, the_geom public.geometry, {columns_with_types} '
');'
.format(schema=user_schema, table_name=output_table_name, columns_with_types=columns_with_types)
)
@@ -134,7 +138,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PrepareTableOBS_GetMeas
)
return True
$$ LANGUAGE plpythonu;
$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PopulateTableOBS_GetMeasure(
username text,
@@ -200,7 +204,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PopulateTableOBS_GetMea
'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, '
'LEFT JOIN cdb_dataservices_client._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(
@@ -227,7 +231,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PopulateTableOBS_GetMea
fdw_server=plpy.quote_literal(server_name)))
return True
$$ LANGUAGE plpythonu;
$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_ConnectUserTable(
username text,
@@ -239,7 +243,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_ConnectUserTable(
)RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_ConnectUserTable;
$$ LANGUAGE plproxy;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_GetReturnMetadata(
username text,
@@ -249,7 +253,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_GetReturnMetadata(
) RETURNS cdb_dataservices_client.ds_return_metadata AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_GetReturnMetadata;
$$ LANGUAGE plproxy;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_FetchJoinFdwTableData(
username text,
@@ -261,7 +265,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_FetchJoinFdwTableData(
) RETURNS SETOF record AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_FetchJoinFdwTableData;
$$ LANGUAGE plproxy;
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_DisconnectUserTable(
username text,
@@ -272,4 +276,4 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_DisconnectUserTable(
) RETURNS boolean AS $$
CONNECT cdb_dataservices_client._server_conn_str();
TARGET cdb_dataservices_server._DST_DisconnectUserTable;
$$ LANGUAGE plproxy;
$$ 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

@@ -51,4 +51,4 @@ BEGIN
RETURN TRUE;
END;
$$ LANGUAGE 'plpgsql';
$$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;

View File

@@ -1,3 +1,7 @@
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,3 +1,5 @@
-- Only show warning or error messages in the tests output
SET client_min_messages TO WARNING;
-- Install dependencies
CREATE EXTENSION postgis;
CREATE EXTENSION plpythonu;

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)

View File

@@ -202,7 +202,114 @@ BEGIN
RETURN QUERY SELECT true AS valid, ARRAY[]::TEXT[] AS errors;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT obs_get_demographic_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013'::text, '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_get_segment_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_getdemographicsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013', '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_getsegmentsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundary(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundaryid(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundarybyid('36047'::text, 'us.census.tiger.county'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundariesbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundariesbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500, 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getpointsbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getpointsbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500::numeric, 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.acs.B01001001'::text);
ERROR: Data Observatory permission denied
SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text);
ERROR: Data Observatory permission denied
SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text);
ERROR: Data Observatory permission denied
SELECT obs_getuscensusmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'male population'::text);
ERROR: Data Observatory permission denied
SELECT obs_getuscensuscategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'Spielman-Singleton Segments: 10 Clusters'::text);
ERROR: Data Observatory permission denied
SELECT obs_getpopulation(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
ERROR: Data Observatory permission denied
SELECT obs_search('total_pop'::text);
ERROR: Data Observatory permission denied
SELECT obs_getavailableboundaries(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
ERROR: Data Observatory permission denied
SELECT obs_getmeta(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]', 1, 1, 1000);
ERROR: Data Observatory permission denied
SELECT obs_getdata(ARRAY['36047'], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001", "geom_id": "us.census.tiger.county"}]', 1, 1, 1000));
ERROR: Data Observatory permission denied
SELECT obs_getdata(ARRAY[(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 1)::geomval], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]'));
ERROR: Data Observatory permission denied
SELECT obs_metadatavalidation(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 'ST_Polygon', '[{"numer_id": "us.census.acs.B01003001"}]', 1000);
ERROR: Data Observatory permission denied
-- Grant other permissions but DO
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT obs_get_demographic_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013'::text, '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_get_segment_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_getdemographicsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013', '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_getsegmentsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundary(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundaryid(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundarybyid('36047'::text, 'us.census.tiger.county'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundariesbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getboundariesbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500, 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getpointsbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getpointsbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500::numeric, 'us.census.tiger.census_tract'::text);
ERROR: Data Observatory permission denied
SELECT obs_getmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.acs.B01001001'::text);
ERROR: Data Observatory permission denied
SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text);
ERROR: Data Observatory permission denied
SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text);
ERROR: Data Observatory permission denied
SELECT obs_getuscensusmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'male population'::text);
ERROR: Data Observatory permission denied
SELECT obs_getuscensuscategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'Spielman-Singleton Segments: 10 Clusters'::text);
ERROR: Data Observatory permission denied
SELECT obs_getpopulation(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
ERROR: Data Observatory permission denied
SELECT obs_search('total_pop'::text);
ERROR: Data Observatory permission denied
SELECT obs_getavailableboundaries(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
ERROR: Data Observatory permission denied
SELECT obs_getmeta(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]', 1, 1, 1000);
ERROR: Data Observatory permission denied
SELECT obs_getdata(ARRAY['36047'], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001", "geom_id": "us.census.tiger.county"}]', 1, 1, 1000));
ERROR: Data Observatory permission denied
SELECT obs_getdata(ARRAY[(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 1)::geomval], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]'));
ERROR: Data Observatory permission denied
SELECT obs_metadatavalidation(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 'ST_Polygon', '[{"numer_id": "us.census.acs.B01003001"}]', 1000);
ERROR: Data Observatory permission denied
-- Grant DO permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["observatory"]}');
cdb_conf_setconf
------------------
(1 row)
SELECT obs_get_demographic_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013'::text, '"us.census.tiger".block_group'::text);
NOTICE: cdb_dataservices_client._obs_get_demographic_snapshot(5): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.obs_get_demographic_snapshot invoked with params (test_user, <NULL>, 0101000020E6100000548B8862F27B52C0DDD1FF722D5A4440, 2009 - 2013, "us.census.tiger".block_group)
obs_get_demographic_snapshot
@@ -366,3 +473,9 @@ NOTICE: cdb_dataservices_client._obs_metadatavalidation(6): [contrib_regression
(t,{})
(1 row)
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

View File

@@ -27,6 +27,12 @@ BEGIN
RETURN true;
END;
$$ LANGUAGE 'plpgsql';
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": [""]}');
cdb_conf_setconf
------------------
(1 row)
-- 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');
@@ -63,3 +69,9 @@ SELECT * FROM my_table_dst;
-- Clean tables
DROP TABLE my_table_dst;
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
cdb_conf_removeconf
---------------------
(1 row)

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,3 +1,5 @@
-- Only show warning or error messages in the tests output
SET client_min_messages TO WARNING;
-- Install dependencies
CREATE EXTENSION postgis;
CREATE EXTENSION plpythonu;

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');

View File

@@ -227,7 +227,9 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
-- -- Exercise the public and the proxied function
-- No permissions granted
SELECT obs_get_demographic_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013'::text, '"us.census.tiger".block_group'::text);
SELECT obs_get_segment_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
SELECT obs_getdemographicsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013', '"us.census.tiger".block_group'::text);
@@ -252,3 +254,56 @@ SELECT obs_getdata(ARRAY['36047'], obs_getmeta(st_setsrid(st_point(-73.9, 40.7),
SELECT obs_getdata(ARRAY[(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 1)::geomval], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]'));
SELECT obs_metadatavalidation(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 'ST_Polygon', '[{"numer_id": "us.census.acs.B01003001"}]', 1000);
-- Grant other permissions but DO
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
SELECT obs_get_demographic_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013'::text, '"us.census.tiger".block_group'::text);
SELECT obs_get_segment_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
SELECT obs_getdemographicsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013', '"us.census.tiger".block_group'::text);
SELECT obs_getsegmentsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
SELECT obs_getboundary(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getboundaryid(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getboundarybyid('36047'::text, 'us.census.tiger.county'::text);
SELECT obs_getboundariesbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getboundariesbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500, 'us.census.tiger.census_tract'::text);
SELECT obs_getpointsbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getpointsbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500::numeric, 'us.census.tiger.census_tract'::text);
SELECT obs_getmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.acs.B01001001'::text);
SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text);
SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text);
SELECT obs_getuscensusmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'male population'::text);
SELECT obs_getuscensuscategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'Spielman-Singleton Segments: 10 Clusters'::text);
SELECT obs_getpopulation(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
SELECT obs_search('total_pop'::text);
SELECT obs_getavailableboundaries(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
SELECT obs_getmeta(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]', 1, 1, 1000);
SELECT obs_getdata(ARRAY['36047'], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001", "geom_id": "us.census.tiger.county"}]', 1, 1, 1000));
SELECT obs_getdata(ARRAY[(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 1)::geomval], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]'));
SELECT obs_metadatavalidation(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 'ST_Polygon', '[{"numer_id": "us.census.acs.B01003001"}]', 1000);
-- Grant DO permissions
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["observatory"]}');
SELECT obs_get_demographic_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013'::text, '"us.census.tiger".block_group'::text);
SELECT obs_get_segment_snapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
SELECT obs_getdemographicsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '2009 - 2013', '"us.census.tiger".block_group'::text);
SELECT obs_getsegmentsnapshot(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), '"us.census.tiger".block_group'::text);
SELECT obs_getboundary(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getboundaryid(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getboundarybyid('36047'::text, 'us.census.tiger.county'::text);
SELECT obs_getboundariesbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getboundariesbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500, 'us.census.tiger.census_tract'::text);
SELECT obs_getpointsbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text);
SELECT obs_getpointsbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500::numeric, 'us.census.tiger.census_tract'::text);
SELECT obs_getmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.acs.B01001001'::text);
SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text);
SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text);
SELECT obs_getuscensusmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'male population'::text);
SELECT obs_getuscensuscategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'Spielman-Singleton Segments: 10 Clusters'::text);
SELECT obs_getpopulation(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
SELECT obs_search('total_pop'::text);
SELECT obs_getavailableboundaries(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326));
SELECT obs_getmeta(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]', 1, 1, 1000);
SELECT obs_getdata(ARRAY['36047'], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001", "geom_id": "us.census.tiger.county"}]', 1, 1, 1000));
SELECT obs_getdata(ARRAY[(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 1)::geomval], obs_getmeta(st_setsrid(st_point(-73.9, 40.7), 4326), '[{"numer_id": "us.census.acs.B01003001"}]'));
SELECT obs_metadatavalidation(ST_SetSRID(ST_Point(-73.9, 40.7), 4326), 'ST_Polygon', '[{"numer_id": "us.census.acs.B01003001"}]', 1000);
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

View File

@@ -34,6 +34,8 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": [""]}');
-- 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');
@@ -53,4 +55,6 @@ SELECT cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure('user_table', 'm
SELECT * FROM my_table_dst;
-- Clean tables
DROP TABLE my_table_dst;
DROP TABLE my_table_dst;
SELECT CDB_Conf_RemoveConf('api_keys_postgres');

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,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/).
_The Data Services API is collaborating with [Mapzen](https://mapzen.com/), and several other geospatial service providers, in order to supply the best location data services from within our CARTO Engine._
_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,10 +1,10 @@
# 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.
Here is an example of how to geocode a single country:
The following example displays how to geocode a single country:
```bash
https://{username}.carto.com/api/v2/sql?q=SELECT cdb_geocode_admin0_polygon('USA')&api_key={api_key}
@@ -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 [HERE geocoding services](https://developer.here.com/rest-apis/documentation/geocoder/topics/quick-start.html). Additional service providers will be implemented in the future.
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.
@@ -10,12 +10,14 @@ You can use the isoline functions to retrieve, for example, isochrone lines from
https://{username}.carto.com/api/v2/sql?q=INSERT INTO {table} (the_geom) SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300, 600, 900]::integer[])&api_key={api_key}
```
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 [HERE](https://developer.here.com/coverage-info) maps.
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,20 +1,20 @@
# Demographic Functions
### 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.
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]({{site.dataservicesapi_docs}}/reference/#geocoding-functions) documentation.
_**Note:** The Demographic Snapshot functions are only available for the United States._
## OBS_GetDemographicSnapshot( point geometry )
#### 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
##### 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
##### 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.
@@ -37,14 +37,14 @@ obs_getdemographicsnapshot: {
**For details, see the [Glossary of Demographic Measures](#glossary-of-demographic-measures).**
### Examples
##### 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 Geographic Snapshot of a Demographic
__Get the Demographic Snapshot at Camp David__
@@ -60,7 +60,7 @@ https://{username}.carto.com/api/v2/sql?q=SELECT * FROM
OBS_GetDemographicSnapshot(CDB_LatLng(40.80, -73.960))
```
## Glossary of Demographic Measures
#### Glossary of Demographic Measures
This list contains the demographic measures and response names for results from the ```OBS_GetDemographicSnapshot``` function.

View File

@@ -1,12 +1,12 @@
# 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
--- | --- | --- | ---
@@ -14,72 +14,71 @@ Name | Type | Description | Accepted values
`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`
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
`units` | `text` | Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`
`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
--- | --- | ---
`duration` | `integer` | Duration in seconds of the calculated route.
`length` | `real` | Length in the defined unit in the `units` field. `kilometers` by default .
`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`
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
`units` | `text` | Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`
`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
--- | --- | ---
`duration` | `integer` | Duration in seconds of the calculated route.
`length` | `real` | Length in the defined unit in the `units` field. `kilometers` by default .
`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.
*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`.
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

@@ -1,18 +1,18 @@
# Segmentation Functions
## 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.
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]({{site.dataservicesapi_docs}}/reference/#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 )
### OBS_GetSegmentSnapshot( Point Geometry )
### Arguments
#### 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
#### 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.
@@ -155,14 +155,14 @@ The possible segments are:
</table>
### Examples
#### 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 Geographic Snapshot of a Segmentation
__Get the Segmentation Snapshot around the MGM Grand__

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,10 @@ 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/)
* `'observatory'` Data Observatory services ([demographic]({{site.dataservicesapi_docs}}/reference/#demographic_functions/) and [segmentation]({{site.dataservicesapi_docs}}/reference/#segmentation_functions/) functions)
**Notes**
@@ -48,7 +48,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,9 +59,9 @@ Result:
```sql
service | monthly_quota | used_quota | soft_limit | provider
----------------+---------------+------------+------------+------------------
isolines | 100 | 0 | f | mapzen
hires_geocoder | 100 | 0 | f | mapzen
routing | 50 | 0 | f | mapzen
isolines | 100 | 0 | f | tomtom
hires_geocoder | 100 | 0 | f | tomtom
routing | 50 | 0 | f | tomtom
observatory | 0 | 0 | f | data observatory
(4 rows)
@@ -69,7 +69,7 @@ Result:
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.
## 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 +79,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:
@@ -100,7 +100,7 @@ Suppose you want to geocode a whole table. In order to check that you have enoug
SELECT COUNT(*) FROM {tablename} WHERE {street_name_column} IS NOT NULL;
```
Result: here's a sample result of 10000 records:
Result: A sample result of 10000 records:
```sql
count

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.

0
server/__init__.py Normal file
View File

View File

@@ -7,6 +7,11 @@ SED = sed
ERB = erb
REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g'
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
AWK = awk
# Parallel support macros
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))
REGRESS = $(notdir $(basename $(sort $(wildcard test/sql/*test.sql))))
TEST_DIR = test/
@@ -31,6 +36,13 @@ 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)
@@ -40,11 +52,37 @@ release: $(EXTENSION).control $(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
@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
# Only meant for development time, do not use once a version is released
.PHONY: devclean
devclean:
rm -f $(NEW_EXTENSION_ARTIFACT)
# If needed remove PARALLEL tags from the release files
release_remove_parallel_deploy:
ifeq ($(PG_PARALLEL), 0)
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; \
done
endif
# Install the current release into the PostgreSQL extensions directory
deploy: release_remove_parallel_deploy
$(INSTALL_DATA) $(EXTENSION).control '$(DESTDIR)$(datadir)/extension/'
$(INSTALL_DATA) old_versions/*.sql *.sql '$(DESTDIR)$(datadir)/extension/'
install: deploy
reinstall: install
psql -U postgres -d dataservices_db -c "drop extension if exists cdb_dataservices_server; create extension cdb_dataservices_server;"

View File

@@ -0,0 +1,14 @@
{
"name": "dataservices-api-server-extension",
"current_version": {
"requires": {
"postgresql": "^10.0.0",
"postgis": "^2.4.0.0",
"carto_postgresql_ext": "^0.23.0"
},
"works_with": {
"dataservices-api-server-python-lib": "^0.19.1",
"observatory-server-extension": "^1.9.0"
}
}
}

View File

@@ -0,0 +1,197 @@
--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_server UPDATE TO '0.36.0'" to load this file. \quit
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_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 $$
from cartodb_services.metrics import metrics
from cartodb_services.tools import Logger,LoggerConfig
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
logger_config = GD["logger_config"]
logger = Logger(logger_config)
params = {'username': username, 'orgname': orgname, 'searchtext': searchtext, 'city': city, 'state_province': state_province, 'country': country}
with metrics('cdb_geocode_street_point', user_geocoder_config, logger, params):
if user_geocoder_config.heremaps_geocoder:
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.google_geocoder:
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.mapzen_geocoder:
mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.mapbox_geocoder:
mapbox_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapbox_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(mapbox_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.tomtom_geocoder:
tomtom_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_tomtom_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(tomtom_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.geocodio_geocoder:
geocodio_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocodio_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(geocodio_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
else:
raise Exception('Requested geocoder is not available')
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION cdb_dataservices_server.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 $$
# The configuration is retrieved but no checks are performed on it
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
geocodio_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocodio_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(geocodio_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION cdb_dataservices_server._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 $$
from iso3166 import countries
from cartodb_services.tools import ServiceManager, QuotaExceededException
from cartodb_services.geocodio import GeocodioGeocoder
from cartodb_services.tools.country import country_to_iso3
from cartodb_services.refactor.service.geocodio_geocoder_config import GeocodioGeocoderConfigBuilder
import cartodb_services
cartodb_services.init(plpy, GD)
service_manager = ServiceManager('geocoder', GeocodioGeocoderConfigBuilder, username, orgname, GD)
try:
service_manager.assert_within_limits()
geocoder = GeocodioGeocoder(service_manager.config.geocodio_api_key, service_manager.logger, service_manager.config.service_params)
country_iso3166 = None
if country:
country_iso3 = country_to_iso3(country)
if country_iso3:
country_iso3166 = countries.get(country_iso3).alpha2.lower()
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
state_province=state_province,
country=country_iso3166)
if coordinates:
service_manager.quota_service.increment_success_service_use()
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
return point['st_setsrid']
else:
service_manager.quota_service.increment_empty_service_use()
return None
except QuotaExceededException as qe:
service_manager.quota_service.increment_failed_service_use()
return None
except BaseException as e:
import sys
service_manager.quota_service.increment_failed_service_use()
service_manager.logger.error('Error trying to geocode street point using Geocodio', sys.exc_info(), data={"username": username, "orgname": orgname})
raise Exception('Error trying to geocode street point using Geocodio')
finally:
service_manager.quota_service.increment_total_service_use()
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
from cartodb_services.metrics import metrics
from cartodb_services.tools import Logger
import json
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
logger_config = GD["logger_config"]
logger = Logger(logger_config)
params = {'username': username, 'orgname': orgname, 'searches': json.loads(searches)}
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
if user_geocoder_config.google_geocoder:
provider_function = "_cdb_bulk_google_geocode_street_point";
elif user_geocoder_config.heremaps_geocoder:
provider_function = "_cdb_bulk_heremaps_geocode_street_point";
elif user_geocoder_config.tomtom_geocoder:
provider_function = "_cdb_bulk_tomtom_geocode_street_point";
elif user_geocoder_config.mapbox_geocoder:
provider_function = "_cdb_bulk_mapbox_geocode_street_point";
elif user_geocoder_config.geocodio_geocoder:
provider_function = "_cdb_bulk_geocodio_geocode_street_point";
else:
raise Exception('Requested geocoder is not available')
plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.{}($1, $2, $3); ".format(provider_function), ["text", "text", "jsonb"])
return plpy.execute(plan, [username, orgname, searches])
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocodio_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
from cartodb_services import run_street_point_geocoder
from cartodb_services.tools import ServiceManager
from cartodb_services.refactor.service.geocodio_geocoder_config import GeocodioGeocoderConfigBuilder
from cartodb_services.geocodio import GeocodioBulkGeocoder
from cartodb_services.tools import Logger
import cartodb_services
cartodb_services.init(plpy, GD)
logger_config = GD["logger_config"]
logger = Logger(logger_config)
service_manager = ServiceManager('geocoder', GeocodioGeocoderConfigBuilder, username, orgname, GD)
geocoder = GeocodioBulkGeocoder(service_manager.config.geocodio_api_key, service_manager.logger, service_manager.config.service_params)
return run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, orgname, searches)
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
RETURNS Geometry AS $$
from cartodb_services.metrics import QuotaService
from cartodb_services.metrics import InternalGeocoderConfig
from cartodb_services.metrics import metrics
from cartodb_services.tools import Logger,LoggerConfig
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
plpy.execute("SELECT cdb_dataservices_server._get_internal_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
user_geocoder_config = GD["user_internal_geocoder_config_{0}".format(username)]
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
logger_config = GD["logger_config"]
logger = Logger(logger_config)
quota_service = QuotaService(user_geocoder_config, redis_conn)
params = {'username': username, 'orgname': orgname, 'country_name': country_name}
with metrics('cdb_geocode_admin0_polygon', user_geocoder_config, logger, params):
try:
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"])
rv = plpy.execute(plan, [country_name], 1)
result = rv[0]["mypolygon"]
if result:
quota_service.increment_success_service_use()
return result
else:
quota_service.increment_empty_service_use()
return None
except BaseException as e:
import sys
quota_service.increment_failed_service_use()
logger.error('Error trying to geocode admin0 polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
raise Exception('Error trying to geocode admin0 polygon')
finally:
quota_service.increment_total_service_use()
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;

View File

@@ -0,0 +1,79 @@
--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_server UPDATE TO '0.35.1'" to load this file. \quit
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_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 $$
from cartodb_services.metrics import metrics
from cartodb_services.tools import Logger,LoggerConfig
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
logger_config = GD["logger_config"]
logger = Logger(logger_config)
params = {'username': username, 'orgname': orgname, 'searchtext': searchtext, 'city': city, 'state_province': state_province, 'country': country}
with metrics('cdb_geocode_street_point', user_geocoder_config, logger, params):
if user_geocoder_config.heremaps_geocoder:
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.google_geocoder:
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.mapzen_geocoder:
mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.mapbox_geocoder:
mapbox_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapbox_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(mapbox_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
elif user_geocoder_config.tomtom_geocoder:
tomtom_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_tomtom_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(tomtom_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
else:
raise Exception('Requested geocoder is not available')
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_geocodio_geocode_street_point;
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_geocodio_geocode_street_point;
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
from cartodb_services.metrics import metrics
from cartodb_services.tools import Logger
import json
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
logger_config = GD["logger_config"]
logger = Logger(logger_config)
params = {'username': username, 'orgname': orgname, 'searches': json.loads(searches)}
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
if user_geocoder_config.google_geocoder:
provider_function = "_cdb_bulk_google_geocode_street_point";
elif user_geocoder_config.heremaps_geocoder:
provider_function = "_cdb_bulk_heremaps_geocode_street_point";
elif user_geocoder_config.tomtom_geocoder:
provider_function = "_cdb_bulk_tomtom_geocode_street_point";
elif user_geocoder_config.mapbox_geocoder:
provider_function = "_cdb_bulk_mapbox_geocode_street_point";
else:
raise Exception('Requested geocoder is not available')
plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.{}($1, $2, $3); ".format(provider_function), ["text", "text", "jsonb"])
return plpy.execute(plan, [username, orgname, searches])
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_bulk_geocodio_geocode_street_point;

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