Issue 1:
When I open the Samples tab in data table, it show "No results" even though the row counter shows that there are rows available to display and inspection of the request in the console shows that data was fetched.

I think the bug might have been introduced in PR #16299 - it uses columns from chart query to display data tables Results and Samples, even though Samples might (and usually does) have different columns than Results. It will actually show only those columns from Samples query that are present in current chart query.

How to reproduce the bug

Open a chart, for example 'Games per Genre over time'

Go to Samples tab

It shows only "Genre" column, even though there are many more available.

Expected results

All columns of Samples query should be displayed in data table

Actual results

Only columns that are present in both Samples query and current chart query are displayed in Samples data table.

Screenshots

Environment

Latest master (e32acd)

Checklist

Make sure to follow these steps before submitting your issue - thank you!

I have checked the superset logs for python stacktraces and included it here as text if there are any.

I have reproduced the issue with at least the latest released version of superset.

I have checked the issue tracker for the same issue and I haven't found one similar.

CC @junlincc @AAfghahi

Issue 2:
SQL Lab goes to a "500 - Internal Server Error" if you try to export a .csv file from a query that has two columns with the same name if those columns correspond to character typed.

This issue is not suggesting that SQL Lab needs to support the ability to return two fields with the same name, but rather that SQL queries that return some results in the SQL Lab GUI should also return those same results in the .CSV export.

Superset version

0.18.4

Expected results

when you Run Query in SQL Lab and results are successfully returned, those same results should be downloadable by clicking the .CSV button in SQL lab

Actual results

clicking the .CSV button in SQL lab takes you to a 500-error page when the results have certain properties

Steps to reproduce

go to SQL Lab

enter the query:

SELECT 'a' AS a, 'a' AS a ;

click "run query". this runs properly and returns a table that looks like:

a a__1
a a

click the button that says .CSV to export a csv

get the error message included below.

Note that in step (2) if you use the query SELECT 1 AS a, 1 AS a the .csv export works properly, so maybe the error has something to do with the column type being a string rather than numeric.

Output from web browser

Sorry, something went wrong

500 - Internal Server Error

Stacktrace

Traceback (most recent call last):
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/indexes/base.py", line 2134, in get_loc
return self._engine.get_loc(key)
File "pandas/index.pyx", line 132, in pandas.index.IndexEngine.get_loc (pandas/index.c:4433)
File "pandas/index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas/index.c:4279)
File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13742)
File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)
KeyError: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/venv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/venv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/venv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/ubuntu/venv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/venv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ubuntu/venv/lib/python3.5/site-packages/superset/utils.py", line 572, in wraps
return f(self, *args, **kwargs)
File "/home/ubuntu/venv/lib/python3.5/site-packages/superset/models/core.py", line 756, in wrapper
value = f(*args, **kwargs)
File "/home/ubuntu/venv/lib/python3.5/site-packages/superset/views/core.py", line 2075, in csv
df = query.database.get_df(sql, query.schema)
File "/home/ubuntu/venv/lib/python3.5/site-packages/superset/models/core.py", line 589, in get_df
if v.type == numpy.object_ and needs_conversion(df[k]):
File "/home/ubuntu/venv/lib/python3.5/site-packages/superset/models/core.py", line 584, in needs_conversion
if isinstance(df_series[0], (list, dict)):
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/core/frame.py", line 2059, in __getitem__
return self._getitem_column(key)
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/core/frame.py", line 2071, in _getitem_column
result = result[key]
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/core/frame.py", line 2059, in __getitem__
return self._getitem_column(key)
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/core/frame.py", line 2066, in _getitem_column
return self._get_item_cache(key)
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/core/generic.py", line 1386, in _get_item_cache
values = self._data.get(item)
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/core/internals.py", line 3543, in get
loc = self.items.get_loc(item)
File "/home/ubuntu/venv/lib/python3.5/site-packages/pandas/indexes/base.py", line 2136, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/index.pyx", line 132, in pandas.index.IndexEngine.get_loc (pandas/index.c:4433)
File "pandas/index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas/index.c:4279)
File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13742)
File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)
KeyError: 0