博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使用Spark SQL 的JDBC server
阅读量:7038 次
发布时间:2019-06-28

本文共 2609 字,大约阅读时间需要 8 分钟。

hot3.png

简介

        Spark SQL  provides JDBC connectivity, which is useful for connecting business intelligence (BI) tools to a Spark cluster and for sharing a cluster across multipleusers. The JDBC server runs as a standalone Spark driver program that can be shared by multiple clients. Any client can cache tables in memory, query them, and so on and the cluster resources and cached data will be shared among all of them.

    Spark SQL’s JDBC server corresponds to the HiveServer2 in Hive.  It is also known as the “Thrift server” since it uses the Thrift communication protocol. Note that the JDBC server requires Spark be built with Hive support

运行环境

集群环境:CDH5.3.0

具体JAR版本如下:

spark版本:1.2.0-cdh5.3.0

hive版本:0.13.1-cdh5.3.0

hadoop版本:2.5.0-cdh5.3.0

启动 JDBC server

cd /etc/spark/confln -s /etc/hive/conf/hive-site.xml hive-site.xmlcd /opt/cloudera/parcels/CDH/lib/spark/chmod- -R 777 logs/cd /opt/cloudera/parcels/CDH/lib/spark/sbin./start-thriftserver.sh  --master yarn --hiveconf hive.server2.thrift.port=10008

 Connecting to the JDBC server with Beeline

cd /opt/cloudera/parcels/CDH/lib/spark/binbeeline -u jdbc:hive2://hadoop04:10000[root@hadoop04 bin]# beeline -u jdbc:hive2://hadoop04:10000scan complete in 2msConnecting to jdbc:hive2://hadoop04:10000Connected to: Spark SQL (version 1.2.0)Driver: Hive JDBC (version 0.13.1-cdh5.3.0)Transaction isolation: TRANSACTION_REPEATABLE_READBeeline version 0.13.1-cdh5.3.0 by Apache Hive0: jdbc:hive2://hadoop04:10000>

Working with Beeline

Within the Beeline client, you can use standard HiveQL commands to create, list, and query tables. You can find the full details of HiveQL in the  Hive Language Manual,but here, we show a few common operations.

CREATE TABLE IF NOT EXISTS mytable (key INT, value STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';create table mytable(name string,addr string,status string) row format delimited fields terminated by '#'#加载本地文件load data local inpath '/external/tmp/data.txt' into table mytable#加载hdfs文件load data inpath 'hdfs://ju51nn/external/tmp/data.txt' into table mytable;describe mytable;explain select * from mytable where name = '张三'select * from mytable where name = '张三'   cache table mytable select count(*) total,count(distinct addr) num1,count(distinct status) num2 from mytable where addr='gz';  uncache table mytable

使用数据示例

张三#广州#学生李四#贵州#教师王五#武汉#讲师赵六#成都#学生lisa#广州#学生lily#gz#studene

Standalone Spark SQL Shell

Spark SQL also supports a simple shell you can use as a single process: spark-sql

它主要用于本地的开发环境,在共享集群环境中,请使用JDBC SERVER

cd /opt/cloudera/parcels/CDH/lib/spark/bin./spark-sql

转载于:https://my.oschina.net/cloudcoder/blog/467713

你可能感兴趣的文章
【windows8开发】序
查看>>
NAT方式,宿主机无法ping通虚拟机
查看>>
RabbitMQ配置
查看>>
bzoj3654 图样图森破
查看>>
四则运算一
查看>>
用Javascript获取页面元素的位置
查看>>
electron 学习笔记
查看>>
vs 开发 qt 遇到 无法找到 Visual Studio 2010 的生成工具(平台工具集 =“v100”) 解决方案...
查看>>
Oracle死锁处理实例
查看>>
[转]Android Studio创建Xposed模块项目时BridgeApi的正确添加方式
查看>>
【hive】——Hive sql语法详解
查看>>
python 全栈开发,Day50(Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏)...
查看>>
一篇网络流的好blog
查看>>
Python基础之继承与派生
查看>>
filter、map、every函数的使用
查看>>
黑马程序员——iOS学习——UITableView表视图单元样式
查看>>
Bash基础——减号-
查看>>
Android适配文件dimen自动生成代码
查看>>
走马观花--快餐学python笔记
查看>>
jquery轻量级富文本编辑器Trumbowyg
查看>>