【Spark】 Spark beeline简单使用

操作

Spark Thrift Server 是 Spark 社区基于 HiveServer2 实现的一个 Thrift 服务。旨在无缝兼容
HiveServer2。因为 Spark Thrift Server 的接口和协议都和 HiveServer2 完全一致,因此我们部
署好 Spark Thrift Server 后,可以直接使用 hive 的 beeline 访问 Spark Thrift Server 执行相关
语句。Spark Thrift Server 的目的也只是取代 HiveServer2,因此它依旧可以和 Hive Metastore
进行交互,获取到 hive 的元数据。
如果想连接 Thrift Server,需要通过以下几个步骤:
➢ Spark 要接管 Hive 需要把 hive-site.xml 拷贝到 conf/目录下
➢ 把 Mysql 的驱动 copy 到 jars/目录下
➢ 如果访问不到 hdfs,则需要把 core-site.xml 和 hdfs-site.xml 拷贝到 conf/目录下
➢ 启动 Thrift Server

sbin/start-thriftserver.sh

➢ 使用 beeline 连接 Thrift Server

bin/beeline -u jdbc:hive2://linux1:10000 -n root

说明

使用了Spark Thrift Server之后,我们无需再启动HiveServer2 的服务

可能遇到的问题

如果运行select语句碰到Class com.hadoop.compression.lzo.LzoCodec not found的问题可以参考这里

配置文件

这里附上我的配置文件

hive-site.xml

	<!--显示当前数据库以及查询表的头信息-->
        <property>
          <name>hive.cli.print.header</name>
          <value>true</value>
        </property>

        <property>
          <name>hive.cli.print.current.db</name>
          <value>true</value>
        </property>


        <!--关闭元数据的检查-->
        <property>
          <name>hive.metastore.schema.verification</name>
          <value>false</value>
        </property>


        <!--使用tez作为引擎-->
        <property>
          <name>hive.execution.engine</name>
          <value>tez</value>
        </property>

core-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>

<!-- 指定HDFS中NameNode的地址 -->
<property>
                <name>fs.defaultFS</name>
      <value>hdfs://hadoop102:9000</value>
</property>

<!-- 指定Hadoop运行时产生文件的存储目录 -->
<property>
                <name>hadoop.tmp.dir</name>
                <value>/opt/module/hadoop-2.7.2/data/tmp</value>
</property>


<property>
<name>io.compression.codecs</name>
<value>
org.apache.hadoop.io.compress.GzipCodec,
org.apache.hadoop.io.compress.DefaultCodec,
org.apache.hadoop.io.compress.BZip2Codec,
org.apache.hadoop.io.compress.SnappyCodec,
com.hadoop.compression.lzo.LzoCodec,
com.hadoop.compression.lzo.LzopCodec
</value>
</property>

<property>
    <name>io.compression.codec.lzo.class</name>
    <value>com.hadoop.compression.lzo.LzoCodec</value>
</property>



</configuration>

hdfs-site.xml

<configuration>

	<property>
    	<name>dfs.replication</name>
    	<value>1</value>
	</property>

	<!-- 指定Hadoop辅助名称节点主机配置 -->
	<property>
    	<name>dfs.namenode.secondary.http-address</name>
    	<value>hadoop104:50090</value>
	</property>
	<property>
		<name>dfs.permissions</name>
		<value>false</value>
		</property>
</configuration>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Spark Beeline是一个基于HiveServer2的命令行工具,用于连接和查询Hive数据库。它可以在Spark集群上运行,也可以在本地机器上运行。 使用Spark Beeline,您可以执行SQL查询、创建表、加载数据等操作。以下是使用Spark Beeline简单步骤: 1. 启动Spark Beeline 在终端中输入以下命令启动Spark Beeline: ``` $ spark-shell --master yarn --deploy-mode client ``` 2. 连接到Hive数据库 在Spark Beeline中连接到Hive数据库,您需要指定HiveServer2的主机名和端口号。例如: ``` $ beeline -u jdbc:hive2://localhost:10000 ``` 3. 执行SQL查询 连接成功后,您可以执行SQL查询。例如: ``` beeline> SELECT * FROM mytable; ``` 4. 创建表 使用Spark Beeline,您可以创建新表并指定表的模式。例如: ``` beeline> CREATE TABLE mytable (id INT, name STRING); ``` 5. 加载数据 使用Spark Beeline,您可以将数据加载到表中。例如: ``` beeline> LOAD DATA LOCAL INPATH '/path/to/data' INTO TABLE mytable; ``` 这些是使用Spark Beeline的基本步骤。您可以使用更多的命令和选项来执行更复杂的操作。 ### 回答2: Spark是一种运行在分布式集群上的计算框架,BeelineSpark的一种客户端工具,可用于连接云端的Spark集群、建立解释器、编写SQL等操作。 使用Beeline时,首先需要打开终端或命令行窗口,输入以下命令: beeline -u <spark master url> -n <username> -w <password> 其中,<spark master url>是Spark集群的Master URL地址,<username>和<password>是登陆Spark集群所需要的用户名和密码。此外,还可以添加其他的参数,例如: beeline -u <spark master url> -n <username> -w <password> -d <driver name> -hiveconf <hive configuration> 其中,<driver name>是命令行客户端使用的JDBC驱动程序,而-hiveconf用于设置Hive的配置信息。 使用Beeline时,需要注意以下几点: 1. Beeline只支持JDBC-ODBC桥接器,因此需要安装相应的驱动程序。 2. Beeline可以用于编写SparkSQL命令,但是对于复杂的SQL查询语句,应当使用Hive作为SQL查询语句的运行引擎。 3. Beeline可以集成Spark的Web Console和命令行工具,使得开发人员可以轻松地进行调试和测试。 总的来说,Spark Beeline是一个非常强大的工具,可用于连接Spark集群、运行SQL查询、进行调试和测试,它的功能和灵活性为开发人员提供了非常便利的工作环境,因此被广泛应用于云计算、大数据等领域。 ### 回答3: Spark Beeline是Apache Spark生态系统提供的一个命令行界面工具,它提供了一种简单易用的方式来进行SQL查询和操作。在使用Beeline之前,需要确保Hive和Spark已经成功安装,并且配置了相应的环境变量。 首先需要启动Spark集群,并在一台终端中运行Beeline命令。启动Beeline方式如下: ``` $SPARK_HOME/bin/beeline ``` 其中$SPARK_HOME是Spark的安装路径。 接下来需要连接到Spark集群所在的Hive Metastore。连接需要使用一个JDBC连接字符串,例如以下命令所示: ``` !connect jdbc:hive2://<hive-metastore-hostname>:<hive-metastore-port> <username> <password> ``` 其中,\<hive-metastore-hostname\>和\<hive-metastore-port\>需要指定Hive Metastore运行的主机名和端口号。\<username\>和\<password\>分别是连接到Hive Metastore所使用的用户名和密码。 连接成功之后,可以通过Beeline执行SQL查询。例如,可以使用以下命令查询Hive表(假设有一个名为sample\_table的Hive表): ``` SELECT * FROM sample_table; ``` 可以使用另一些Beeline命令来获取关于Beeline设置和调试信息,例如以下命令: - !set:用于设置Beeline变量 - !alias:用于设置Beeline命令别名 - !quit:用于退出Beeline 使用Beeline可以轻松地在Spark集群中进行SQL查询和操作,同时还提供了丰富的命令行选项和配置设置,使其更加灵活和易于使用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值