<Zhuuu_ZZ>HIVE(十)查缺补漏

本文详细介绍了Hive的各种高级操作,包括交互命令、配置显示数据库和表信息、高阶建表语句、类型转换、数据库管理、表的操作、数据导入导出以及查询和调优技巧。此外,还探讨了窗口函数的使用,强调了Hive查询的灵活性和性能优化的重要性。

Hive常用交互命令

  • “-e”不进入hive的交互窗口执行sql语句
bin/hive -e "select id from student;"
  • “-f”执行脚本中sql语句
 -- 在/opt/module/datas目录下创建hivef.sql文件
  touch hivef.sql
 --文件中写入正确的sql语句
    select *from student;
--执行文件中的sql语句
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/datas/hivef.sql
--执行文件中的sql语句并将结果写入文件中
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/datas/hivef.sql  > /opt/module/datas/hive_result.txt

hive配置显示数据库名和表字段

在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>

高阶建表语句

  • CTAS(复制表结构和数据):
create table1 as select * from2;
  • CTAS(复制表结构):
create table1 
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <!-- 指定Hive数据要访问的地址 --> <property> <name>hive.metastore.uris</name> <value>thrift://master:9083</value> <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> </property> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> </property> <property> <name>hive.exec.local.scratchdir</name> <value>/usr/local/src/hive</value> </property> <property> <name>hive.exec.scratchdir</name> <value>/tmp/hive</value> </property> <property> <name>hive.downloaded.resources.dir</name> <value>/usr/local/src/hive</value> </property> <property> <name>hive.querylog.location</name> <value>/usr/local/src/hive</value> </property> <property> <name>hive.server2.logging.operation.log.location</name> <value>/usr/local/src/hive</value> </property> <property> <name>hive.server2.thrift.bind.host</name> <value>master</value> </property> <property> <name>hive.metastore.enent.db.notification.api.auth</name> <value>false</value> </property> <property> <name>hive.cli.print.header</name> <value>true</value> </property> <property> <name>hive.cli.encoding</name> <value>UTF-8</value> <description>Character-set encoding for various CLI output data such as console output, logs, reports.</description> </property> <property> <name>hive.charset</name> <value>utf8</value> <description>The character set encoding to use for data read/write operations.</description> </property> </configuration>
最新发布
07-16
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值