Skip to content

Instantly share code, notes, and snippets.

@ottomata
Created December 20, 2018 17:38
Show Gist options
  • Save ottomata/9abaf0cefcdd9af9bcaba36c8ec3968d to your computer and use it in GitHub Desktop.
Save ottomata/9abaf0cefcdd9af9bcaba36c8ec3968d to your computer and use it in GitHub Desktop.
import scala.collection.JavaConversions._
import org.apache.hadoop.hive.metastore.HiveConf
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient
import org.apache.spark.sql.SparkSession
def getHivePartitionColumnNames(tableName: String): Seq[String] = {
val spark: SparkSession = SparkSession.builder().enableHiveSupport().getOrCreate()
val hiveConf = new HiveConf(spark.sparkContext.hadoopConfiguration, classOf[HiveConf])
val metastoreClient = new HiveMetaStoreClient(hiveConf)
val Array(db, table) = tableName.split('.')
metastoreClient.getTable(db, table).getPartitionKeys.map(_.getName).toSeq
}
scala> getHivePartitionColumnNames("event.navigationtiming")
res33: Seq[String] = ArrayBuffer(year, month, day, hour)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment