title: read/write bucketed tables in Spark
body: <p>I have a number of tables (with 100 million-ish rows) that are stored as external Hive tables using Parquet format. The Spark job needs to join several of them together, using a single column, with almost no filtering. The join column has unique values about 2/3X fewer than the number of rows. </p>
  
  <p>I can see that there are shuffles happening by the join key; and I have been trying to utilize bucketing/partitioning to improve join performance. My thought is that if Spark can be made aware that each of these tables has been bucketed using the same column, it can load the dataframes and join them without shuffling. I have tried using Hive bucketing, but the shuffles don't go away. (From Spark's documentation it looks like Hive bucketing is not supported as of Spark 2.3.0 at least, which I found out later.) Can I use Spark's bucketing feature to do this? If yes, would I have to disable Hive support and just read the files directly? Or could I rewrite the tables once using Spark's bucketing scheme and still be able to read them as Hive tables?</p>
  
  <p>EDIT: For writing out the Hive bucketed tables I was using something like:</p>
  
  <pre><code>customerDF
  .write
  .option("path", "/some/path")
  .mode("overwrite")
  .format("parquet")
  .bucketBy(200, "customer_key")
  .sortBy("customer_key")
  .saveAsTable("table_name")
  </code></pre>
  
  <p>The writing part seems to work. However, reading from two tables written that way and joining them didn't work as I expected. That is, Spark was repartitioning both tables again into 200 partitions. </p>
  
  <p>I don't have code for doing Spark bucketing right now but will update if I figure it out.</p>