来从远程服务器hive2表我用下面的代码试图从远程火花服务器hive2访问表:错误而尝试使用火花
import org.apache.spark.SparkContext, org.apache.spark.SparkConf, org.apache.spark.sql._
import com.typesafe.config._
import java.io._
import org.apache.hadoop.fs._
import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.sql.Row
import org.apache.spark.sql.SparkSession
object stack {
def main(args: Array[String]) {
val warehouseLocation = "/usr/hive/warehouse"
System.setProperty("javax.jdo.option.ConnectionURL","jdbc:mysql://sparkserver:3306/metastore?createDatabaseIfNotExist=true")
System.setProperty("javax.jdo.option.ConnectionUserName","hiveroot")
System.setProperty("javax.jdo.option.ConnectionPassword","hivepassword")
System.setProperty("hive.exec.scratchdir","/tmp/hive/${user.name}")
System.setProperty("spark.sql.warehouse.dir", warehouseLocation)
// System.setProperty("hive.metastore.uris", "thrift://sparkserver:9083")
System.setProperty("javax.jdo.option.ConnectionDriverName","com.mysql.jdbc.Driver")
System.setProperty("hive.metastore.warehouse.dir","/user/hive/warehouse")
val spark = SparkSession.builder().master("local")
.appName("spark remote")
// .config("javax.jdo.option.ConnectionURL","jdbc:mysql://sparkserver:3306/metastore?createDatabaseIfNotExist=true")
.config("javax.jdo.option.ConnectionURL","jdbc:mysql://sparkserver:3306/metastore?createDatabaseIfNotExist=true")
.config("javax.jdo.option.ConnectionUserName","hiveroot")
.config("javax.jdo.option.ConnectionPassword","hivepassword")
.config("hive.exec.scratchdir","/tmp/hive/${user.name}")
.config("spark.sql.warehouse.dir", warehouseLocation)
// .config("hive.metastore.uris", "thrift://sparkserver:9083")
.config("javax.jdo.option.ConnectionDriverName","com.mysql.jdbc.Driver")
.config("hive.querylog.location","/tmp/hivequerylogs/${user.name}")
.config("hive.support.concurrency","false")
.config("hive.server2.enable.doAs","true")
.config("hive.server2.authentication","PAM")
.config("hive.server2.custom.authentication.class","org.apache.hive.service.auth.PamAuthenticationProvider")
.config("hive.server2.authentication.pam.services","sshd,sudo")
.config("hive.stats.dbclass","jdbc:mysql")
.config("hive.stats.jdbcdriver","com.mysql.jdbc.Driver")
.config("hive.session.history.enabled","true")
.config("hive.metastore.schema.verification","false")
.config("hive.optimize.sort.dynamic.partition","false")
.config("hive.optimize.insert.dest.volume","false")
.config("datanucleus.fixedDatastore","true")
.config("hive.metastore.warehouse.dir","/user/hive/warehouse")
.config("datanucleus.autoCreateSchema","false")
.config("datanucleus.schema.autoCreateAll","true")
.config("datanucleus.schema.validateConstraints","true")
.config("datanucleus.schema.validateColumns","true")
.config("datanucleus.schema.validateTables","true")
.config("fs.default.name","hdfs://sparkserver:54310")
.config("dfs.namenode.name.dir","/usr/local/hadoop_tmp/hdfs/namenode")
.config("dfs.datanode.name.dir","/usr/local/hadoop_tmp/hdfs/datanode")
.enableHiveSupport()
.getOrCreate()
import spark.implicits._
import spark.sql
sql("select * from sample.source").collect.foreach(println)
sql("select * from sample.destination").collect.foreach(println)
}
}
连接请求元店被拒绝通过远程配置单元服务器。
错误:无法启动蜂房metastore.service:未找到单位蜂房metastore.service
谢谢!
Raktotpal,我有两个不同的hive安装,一个是在localhost上有hive.metastore。uris as 其工作正常时,即时通讯试图访问从本地主机配置单位,我的火花也运行在本地主机,但现在我试图连接远程机器已安装配置单元和metstore是节俭://sparkserver:9083 –
Vickyster
是啊,我明白了,然后使用hive-site.xml - 在我的答案中提到的所有属性。 ------------程序将能够连接到该配置单元服务器。 Hive-Metastore服务在该远程配置单元服务器中完全没有运行;所以,不需要单独连接到Metastore服务器。 –
但我不想使用Hive-site.xml文件而是我想调用config中的所有属性。我会试着让你知道 – Vickyster