spark thriftserver简称sts是sparksql的apache hive hiveServer2的端口,用户可以通过它来执行sql查询
这个是个单独的服务
启动:
通过spark的bin目录下的start-thriftserver.sh来启动,stop-thriftserver.sh来关闭
启动的参数:
--hiveconf
hive.server2.thrift.transport.mode(默认值TCP,可选值为http)
hive.server2.thrift.http.path(服务的端点名称,默认cliservice)
hive.server2.thrift.http.min.work.threads(服务池中的最小工作线程,默认为5)
hive.server2.thrift.http.max.worker.threads (最大,默认为500)
下面我们去查询一下hive仓库中表的数据试一下
代码:
def selectData =Try {
lazy val conn = DriverManager.getConnection("jdbc:hive2://huawei1:10001/gk?" +
"hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice","root","")
val sql ="select * from gk.people where age = ?"
Class.forName("org.apache.hive.jdbc.HiveDriver")
val stmt = conn.prepareStatement(sql)
stmt.setInt(1,30)
val rs = stmt.executeQuery()
while (rs.next()) {
println(rs.getString(1))
}
}
def main(args: Array[String]): Unit = {
selectData match {
case Success(value) =>
case Failure(e) => e.printStackTrace()
}
}
网友评论