spark thriftserver简称sts是sparksql的apache hive hiveServer2的端口,用户可以通过它来执行sql查询
这个是个单独的服务
启动:
通过spark的bin目录下的start-thriftserver.sh来启动,stop-thriftserver.sh来关闭
启动的参数:
--hiveconf
下面我们去查询一下hive仓库中表的数据试一下
代码:
def selectData =Try {
lazy val conn = DriverManager.getConnection("jdbc:hive2://huawei1:10001/gk?" +
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()
}
}