superset icon indicating copy to clipboard operation
superset copied to clipboard

How to programmatically import a CSV file as a table?

Open klazaj opened this issue 6 years ago • 8 comments

I am running the last version of Superset via Docker.

If I want to import a CSV file to Superset, I go through this route: Open Superset -> Sources -> Upload a CSV

I want to write a script that uploads a CSV file to superset. Is it possible to perform this task programmatically?

klazaj avatar Dec 09 '19 15:12 klazaj

Issue-Label Bot is automatically applying the label #question to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Dec 09 '19 15:12 issue-label-bot[bot]

Might as well write a script that uploads data directly to your database (?)

mistercrunch avatar Dec 10 '19 06:12 mistercrunch

I had to write a script to write my tables into the database.

DavidJHassan avatar Dec 11 '19 04:12 DavidJHassan

@mistercrunch If I do that then I'd have to stop the Superset Server every time I upload the data to the postgreSQL database. I was wondering whether there was another way

klazaj avatar Dec 11 '19 12:12 klazaj

@klazaj, why do you need to stop superset?

dpgaspar avatar Dec 11 '19 16:12 dpgaspar

@davidhassan did you also run superset with docker? was your database the superset postgres?

klazaj avatar Dec 12 '19 11:12 klazaj

@dpgaspar I thought I had to stop it because it was using the same postgres port, but apparently I don't need to

klazaj avatar Dec 12 '19 11:12 klazaj

What I resorted to doing:

  1. copy file from local to live container: docker cp file.csv container:/file.csv
  2. enter live container: docker exec -it container_id bash
  3. login postgres database from within the container: psql -U superset -d superset
  4. create table in db and copy new table:
create table new (field type ...);
\copy new from 'file.csv' with delimiter as ',' csv header;

If someone knows a better way please comment below!

klazaj avatar Dec 13 '19 18:12 klazaj