<p dir="auto">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.<br>
I think the bug might have been introduced in PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="973055254" data-permission-text="Title is private" data-url="https://github.com/apache/superset/issues/16299" data-hovercard-type="pull_request" data-hovercard-url="/apache/superset/pull/16299/hovercard" href="https://github.com/apache/superset/pull/16299">#16299</a> - 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.</p>
<h4 dir="auto">How to reproduce the bug</h4>
<ol dir="auto">
<li>Open a chart, for example 'Games per Genre over time'</li>
<li>Go to Samples tab</li>
<li>It shows only "Genre" column, even though there are many more available.</li>
</ol>
<h3 dir="auto">Expected results</h3>
<p dir="auto">All columns of Samples query should be displayed in data table</p>
<h3 dir="auto">Actual results</h3>
<p dir="auto">Only columns that are present in both Samples query and current chart query are displayed in Samples data table.</p>
<h4 dir="auto">Screenshots</h4>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/15073128/138292711-bb8abda2-909b-4ce1-9378-a13d3d7b469e.png"><img src="https://user-images.githubusercontent.com/15073128/138292711-bb8abda2-909b-4ce1-9378-a13d3d7b469e.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Environment</h3>
<p dir="auto">Latest master (e32acd)</p>
<h3 dir="auto">Checklist</h3>
<p dir="auto">Make sure to follow these steps before submitting your issue - thank you!</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the superset logs for python stacktraces and included it here as text if there are any.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have reproduced the issue with at least the latest released version of superset.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the issue tracker for the same issue and I haven't found one similar.</li>
</ul>
<p dir="auto">CC <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/junlincc/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/junlincc">@junlincc</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/AAfghahi/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/AAfghahi">@AAfghahi</a></p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<h3 dir="auto">Superset version</h3>
<p dir="auto">0.18.4</p>
<h3 dir="auto">Expected results</h3>
<p dir="auto">when you <code class="notranslate">Run Query</code> in SQL Lab and results are successfully returned, those same results should be downloadable by clicking the <code class="notranslate">.CSV</code> button in SQL lab</p>
<h3 dir="auto">Actual results</h3>
<p dir="auto">clicking the <code class="notranslate">.CSV</code> button in SQL lab takes you to a 500-error page when the results have certain properties</p>
<h3 dir="auto">Steps to reproduce</h3>
<ol dir="auto">
<li>go to SQL Lab</li>
<li>enter the query:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SELECT 'a' AS a, 'a' AS a ;"><pre class="notranslate"><code class="notranslate">SELECT 'a' AS a, 'a' AS a ;
</code></pre></div>
<ol start="3" dir="auto">
<li>click "run query". this runs properly and returns a table that looks like:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a   a__1
a   a"><pre class="notranslate"><code class="notranslate">a   a__1
a   a
</code></pre></div>
<ol start="4" dir="auto">
<li>click the button that says <code class="notranslate">.CSV</code> to export a csv</li>
<li>get the error message included below.</li>
</ol>
<p dir="auto">Note that in step (2) if you use the query <code class="notranslate">SELECT 1 AS a, 1 AS a</code> the .csv export works properly, so maybe the error has something to do with the column type being a string rather than numeric.</p>
<h3 dir="auto">Output from web browser</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Sorry, something went wrong

500 - Internal Server Error

Stacktrace

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

      "><pre class="notranslate"><code class="notranslate">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

      
</code></pre></div>