superset icon indicating copy to clipboard operation
superset copied to clipboard

CTAS executed but resulting table not created

Open trepmag opened this issue 7 years ago • 8 comments

CTAS executed but resulting table not created.

Expected results

Generated table existing in the database.

Actual results

Log portion showing that the related instruction is executed:

superset_1  | 2019-10-09 14:59:13,727:DEBUG:root:Fetching data for query object: {'changedOn': datetime.datetime(2019, 10, 9, 14, 59, 12, 652119), 'changed_on': '2019-10-09T14:59:12.652119', 'dbId': 4, 'db': 'ig3is', 'endDttm': None, 'errorMessage': None, 'executedSql': 'CREATE TABLE public.zzz AS \n-- Note: Unless you save your query, these tabs will NOT persist if you clear your cookies or change browsers.\n\nSELECT id_gas,\n       gas_acro,\n       gas_name,\n       gas_info\nFROM public.gas\nLIMIT 100', 'id': 'iCmKnonTn', 'limit': 100, 'progress': 0, 'rows': None, 'schema': 'public', 'ctas': True, 'serverId': 111, 'sql': '-- Note: Unless you save your query, these tabs will NOT persist if you clear your cookies or change browsers.\n\nSELECT id_gas,\n       gas_acro,\n       gas_name,\n       gas_info\nFROM public.gas\nLIMIT 100', 'sqlEditorId': 'Gxp1oIezo', 'startDttm': Decimal('1570633152373.131000'), 'state': 'running', 'tab': 'test zzz', 'tempTable': 'public.zzz', 'userId': 1, 'user': 'Admin user', 'resultsKey': None, 'trackingUrl': None, 'extra': {'progress': 'Running statement 1 out of 1'}}
superset_1  | 2019-10-09 14:59:13,727:DEBUG:root:[stats_logger] (timing) sqllab.query.time_fetching_results | 3.83984375 
superset_1  | 2019-10-09 14:59:13,727:DEBUG:root:Fetching cursor description
superset_1  | 2019-10-09 14:59:13,734:INFO:root:Database.get_sqla_engine(). Masked URL: postgresql://postgres:XXXXXXXXXX@somehost:5432/ig3is
superset_1  | 2019-10-09 14:59:13,735:INFO:root:Database.get_sqla_engine(). Masked URL: postgresql://postgres:XXXXXXXXXX@somehost:5432/ig3is

image

Screenshots

image

How to reproduce the bug

See above screenshot

Environment

  • superset version: 0.34
  • python version: 3.6.8
  • node.js version: v10.15.3
  • npm version: 6.4.1

Runned using the docker-compose given in the git repository at https://github.com/apache/incubator-superset/tree/0.34.1rc2/contrib/docker

Checklist

Make sure these boxes are checked before submitting your issue - thank you!

  • [x] I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • [x] I have reproduced the issue with at least the latest released version of superset.
  • [x] I have checked the issue tracker for the same issue and I haven't found one similar.

trepmag avatar Oct 09 '19 15:10 trepmag

Issue-Label Bot is automatically applying the label #bug to this issue, with a confidence of 0.85. 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 Oct 09 '19 15:10 issue-label-bot[bot]

Hi @trepmag,

I'm able to reproduce this, investigating...

dpgaspar avatar Oct 09 '19 16:10 dpgaspar

I think you need to commit (remembering a related discussion some time ago). Perhaps we should add an option to autocommit in the datasource settings?

villebro avatar Oct 09 '19 16:10 villebro

May be that, I've checked and the correct query gets to db_engine_specs.execute, and (of course) also makes it to PG.

I've added a COMMIT on the execute and it does work, :+1: @villebro. PG does some complaining around it:

2019-10-09 17:20:52.304 UTC [122] WARNING:  there is no transaction in progress

Yes making it optional per datasource does seem like a good option

dpgaspar avatar Oct 09 '19 17:10 dpgaspar

Very weird warning, considering it clearly has something to commit. Looked around and stumbled across this, related perhaps? https://stackoverflow.com/questions/28593685/why-does-this-postgresql-transaction-give-warning-there-is-no-transaction-in-p

villebro avatar Oct 09 '19 20:10 villebro

You can solve this issue in a simple way; first change your data connection to: postgresql+psycopg2://username:XXXXXXXXXX@database_server_name:5432/database

them in the extra parameters

{
"metadata_params": {},
"engine_params": {"isolation_level":"AUTOCOMMIT"},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": []
}

rc-ontruck avatar Oct 11 '19 10:10 rc-ontruck

oh! excellent thank you @rc-ontruck simple is beautiful. I've tested it and it solves the problem, @trepmag can you confirm?

dpgaspar avatar Oct 11 '19 12:10 dpgaspar

Absolutely, it woks!

Thank you all there for looking into this...

GRIDgeneva avatar Oct 11 '19 13:10 GRIDgeneva