title: Spark SQL saveAsTable returns empty result
body: <p>I am using the following code for creating / inserting data into a Hive table in Spark SQL:</p>
  
  <pre><code>val sc = SparkSession
    .builder()
    .appName("App")
    .master("local[2]")
    .config("spark.sql.warehouse.dir", "file:///tmp/spark-warehouse")
    .enableHiveSupport()
    .getOrCreate()
  
  // actual code
  
  result.createOrReplaceTempView("result")
  result.write.format("parquet").partitionBy("year", "month").mode(SaveMode.Append).saveAsTable("tablename")
  </code></pre>
  
  <p>Which runs without errors. A <code>result.show(10)</code> confirms this. The input files are csv on the local FS.</p>
  
  <p>It creates parquet files under <code>./spark-warehouse/tablename/</code> and also creates the table in hive, using a correct create table statement.</p>
  
  <pre><code>git:(master) ✗ tree
  .
  └── tablename
      ├── _SUCCESS
      └── year=2017
          └── month=01
              ├── part-r-00013-abaea338-8ed3-4961-8598-cb2623a78ce1.snappy.parquet
              ├── part-r-00013-f42ce8ac-a42c-46c5-b188-598a23699ce8.snappy.parquet
              ├── part-r-00018-abaea338-8ed3-4961-8598-cb2623a78ce1.snappy.parquet
              └── part-r-00018-f42ce8ac-a42c-46c5-b188-598a23699ce8.snappy.parquet
  </code></pre>
  
  <p>hive:</p>
  
  <pre><code>hive&gt; show create table tablename;
  OK
  CREATE TABLE `tablename`(
    `col` array&lt;string&gt; COMMENT 'from deserializer')
  ROW FORMAT SERDE
    'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
  WITH SERDEPROPERTIES (
    'path'='file:/Users/IdeaProjects/project/spark-warehouse/tablename')
  STORED AS INPUTFORMAT
    'org.apache.hadoop.mapred.SequenceFileInputFormat'
  OUTPUTFORMAT
    'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat'
  LOCATION
    'file:/tmp/spark-warehouse/tablename'
  TBLPROPERTIES (
    'EXTERNAL'='FALSE',
    'spark.sql.sources.provider'='parquet',
    'spark.sql.sources.schema.numPartCols'='2',
    'spark.sql.sources.schema.numParts'='1',
    'spark.sql.sources.schema.part.0'='{ 
    // fields
    }',
    'spark.sql.sources.schema.partCol.0'='year',
    'spark.sql.sources.schema.partCol.1'='month',
    'transient_lastDdlTime'='1488157476')
  </code></pre>
  
  <p>However, the table is empty:</p>
  
  <pre><code>hive&gt; select count(*) from tablename;
  ...
  OK
  0
  Time taken: 1.89 seconds, Fetched: 1 row(s)
  </code></pre>
  
  <p>Software used: Spark 2.1.0 with spark-sql and spark-hive_2.10, Hive 2.10 and a mysql metastore, Hadoop 2.70, macOS 10.12.3</p>