在Spark 1.6.2中,可以通过以下方法访问HiveConf对象。
https://spark.apache.org/docs/1.6.2/api/java/org/apache/spark/sql/hive/HiveContext.html#hiveconf()
任何人都可以让我知道Spark2.2.2中SparkSe.2对象中的相同内容吗?
答案 0 :(得分:1)
您可以通过spark.conf.getAll
获取Spark conf然后访问各个属性来访问Hive配置。要获取数据库,表格,函数等,您可以通过spark.catalog
。
val spark = SparkSession().builder()
.appName("MyApp")
.enableHiveSupport()
.getOrCreate()
// Get all configuration properties
val config = spark.conf.getAll
// Get the Hive metastore dir
val hiveDir = config("hive.metastore.warehouse.dir")
// List databases
val dbs = spark.catalog.listDatabases
dbs.show
// List tables
val tables = spark.catalog.listTables
tables.show
答案 1 :(得分:0)
您需要调用方法SparkSession.enableHiveSupport()
,然后使用SparkSession Instance本身。
请参阅spark文档中的此示例。
http://spark.apache.org/docs/latest/sql-programming-guide.html#hive-tables
HiveContext已被弃用。看这里。 https://spark.apache.org/docs/2.0.2/api/java/org/apache/spark/sql/hive/HiveContext.html