title: Column name cannot be resolved in SparkSQL join
body: <p>I'm not sure why this is happening. In PySpark, I read in two dataframes and print out their column names and they are as expected, but then when do a SQL join I get an error that cannot resolve column name given the inputs. I have simplified the merge just to get it to work, but I will need to add in more join conditions which is why I'm using SQL (will be adding in: "and b.mnvr_bgn &lt; a.idx_trip_id and b.mnvr_end > a.idx_trip_data"). It appears that the column 'device_id' is being renamed to '_col7' in the df <strong>mnvr_temp_idx_prev_temp</strong></p>
  
  <pre><code>mnvr_temp_idx_prev = mnvr_3.select('device_id', 'mnvr_bgn', 'mnvr_end')
  print mnvr_temp_idx_prev.columns
  ['device_id', 'mnvr_bgn', 'mnvr_end']
  
  raw_data_filtered = raw_data.select('device_id', 'trip_id', 'idx').groupby('device_id', 'trip_id').agg(F.max('idx').alias('idx_trip_end'))
  print raw_data_filtered.columns
  ['device_id', 'trip_id', 'idx_trip_end']
  
  raw_data_filtered.registerTempTable('raw_data_filtered_temp')
  mnvr_temp_idx_prev.registerTempTable('mnvr_temp_idx_prev_temp') 
  test = sqlContext.sql('SELECT a.device_id, a.idx_trip_end, b.mnvr_bgn, b.mnvr_end \
                            FROM raw_data_filtered_temp as a  \
                               INNER JOIN mnvr_temp_idx_prev_temp as b \
                                  ON a.device_id = b.device_id')
  </code></pre>
  
  <p>Traceback (most recent call last): AnalysisException: u"cannot resolve 'b.device_id' given input columns: [_col7, trip_id, device_id, mnvr_end, mnvr_bgn, idx_trip_end]; line 1 pos 237"</p>
  
  <p>Any help is appreciated!</p>