Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SQL filters while downloading a dataset #165

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Apr-dd-2020: version 1.11.0
- Add sql_query and add_geom parameters to DO client download methods.

Apr-06-2020: version 1.10.1
- Add geom_column parameter to DO client upload methods.

Expand Down
29 changes: 24 additions & 5 deletions carto/do_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def upload_dataframe(self, dataframe, name, params=None):

return status

def download(self, name_id, limit=None, order_by=None):
def download(self, name_id, limit=None, order_by=None, sql_query=None, add_geom=None, is_geography=None):
params = {
'api_key': self.api_key
}
Expand All @@ -92,6 +92,15 @@ def download(self, name_id, limit=None, order_by=None):
if order_by is not None:
params['order_by'] = order_by

if sql_query is not None:
params['sql_query'] = sql_query

if add_geom is not None:
params['add_geom'] = add_geom

if is_geography is not None:
params['is_geography'] = is_geography

relative_path = '{}/{}'.format(DATASETS_BASE_PATH, name_id)

try:
Expand All @@ -109,8 +118,13 @@ def download(self, name_id, limit=None, order_by=None):

return response

def download_stream(self, name_id, limit=None, order_by=None):
return ResponseStream(self.download(name_id, limit=limit, order_by=order_by))
def download_stream(self, name_id, limit=None, order_by=None, sql_query=None, add_geom=None, is_geography=None):
return ResponseStream(self.download(name_id,
limit=limit,
order_by=order_by,
sql_query=sql_query,
add_geom=add_geom,
is_geography=is_geography))

def create(self, payload):
params = {'api_key': self.api_key}
Expand Down Expand Up @@ -304,8 +318,13 @@ def create(self):
payload['ttl_seconds'] = self._ttl_seconds
self._client.create(payload)

def download_stream(self, limit=None, order_by=None):
return self._client.download_stream(name_id=self._name, limit=limit, order_by=order_by)
def download_stream(self, limit=None, order_by=None, sql_query=None, add_geom=None, is_geography=None):
return self._client.download_stream(name_id=self._name,
limit=limit,
order_by=order_by,
sql_query=sql_query,
add_geom=add_geom,
is_geography=is_geography)

def upload(self, dataframe, geom_column=None):
return self._client.upload(dataframe, self._name, params={'geom_column': geom_column})
Expand Down
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
# built documents.
#
# The short X.Y version.
version = u'1.10.1'
version = u'1.11.0'
# The full version, including alpha/beta/rc tags.
release = u'1.10.1'
release = u'1.11.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
author="Daniel Carrión",
author_email="daniel@carto.com",
description="SDK around CARTO's APIs",
version="1.10.1",
version="1.11.0",
url="https://github.com/CartoDB/carto-python",
install_requires=required,
packages=["carto"])