Skip to content

Commit

Permalink
Insert/upsert fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarans committed Nov 8, 2016
1 parent 07b2091 commit c21ef4a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hdx/data/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ def create_datastore(self, schema: List[dict] = None, primary_key: Optional[str]
chunksize = 10000
offset = 0
if primary_key is None:
datastore_function = 'datastore_insert'
method = 'insert'
else:
datastore_function = 'datastore_upsert'
method = 'upsert'
logger.debug('Uploading data from %s to datastore' % url)
while offset < len(rows):
rowset = rows[offset:offset + chunksize]
data = {'resource_id': self.data['id'], 'force': True, 'method': 'upsert', 'records': rowset}
self._write_to_hdx(datastore_function, data, 'id')
data = {'resource_id': self.data['id'], 'force': True, 'method': method, 'records': rowset}
self._write_to_hdx('datastore_upsert', data, 'id')
offset += chunksize
logger.debug('Uploading: %s' % offset)
except Exception as e:
Expand Down

0 comments on commit c21ef4a

Please sign in to comment.