CartoDB / cartoframes

CARTO Python package for data scientists
BSD 3-Clause "New" or "Revised" License
251 stars 63 forks source link

Bug/ch155055/emily mo inconsistent to carto error #1734

Closed Mmoncadaisla closed 3 years ago

Mmoncadaisla commented 3 years ago

Context

In this small PR from Support we aim to avoid hitting the Batch API 16 kb payload limit when using the _truncate_and_drop_add_columns function, which is called from to_carto (through copy_from) with if_exists='replace' collision strategy if the table structure changes used and the table has a considerable amount of columns.

Further context can be found here: https://app.clubhouse.io/cartoteam/story/155055/emily-mo-inconsistent-to-carto-error

Proposed solution

  1. Create a temporary PostgreSQL user defined function through a standard SQL API call with the required changes
  2. Apply this function in the transaction (after the TRUNCATE operation and before the cartodbfication process)
  3. Drop the temporary function

Example output with the current logic

CartoException: ['Your payload is too large: 18745 bytes. Max size allowed is 16384 bytes (16kb). Are you trying to import data?. Please, check out import api http://docs.cartodb.com/cartodb-platform/import-api/']

Example output with the changes implemented

Success! Data uploaded to table "test_to_carto_truncate_drop_add_" correctly
'test_to_carto_truncate_drop_add_'

We have also verified that the temporary function is dropped as expected.

PR changes

Relevant

Minor

shortcut-integration[bot] commented 3 years ago

This pull request has been linked to Clubhouse Story #155055: [emily-mo] Inconsistent to_carto error.

Mmoncadaisla commented 3 years ago

Performed different Q&A tests on both an enterprise and a free plan accounts and it seems to be working as expected. Thank you a lot for the great CR @Jesus89 @jgoizueta ❤️