Created
December 20, 2018 17:38
-
-
Save ottomata/9abaf0cefcdd9af9bcaba36c8ec3968d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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