• 【Hive】Hive CLI初探


    $HIVE_HOME/bin/hive是一个Shell工具,可以用来以交互式或批量模式运行HIve查询,本篇对其进行学习。

    一 Hive环境
    hive> select version();
    OK
    2.3.3 r8a511e3f79b43d4be41cd231cf5c99e43b248383
    Time taken: 11.166 seconds, Fetched: 1 row(s)
    二 HIve CLI介绍

    1 CLI选项

    1)查看帮助信息
    [hadoop@strong ~]$ hive -H
    usage: hive
     -d,--define <key=value>          Variable substitution to apply to Hive
                                      commands. e.g. -d A=B or --define A=B
        --database <databasename>     Specify the database to use
     -e <quoted-query-string>         SQL from command line
     -f <filename>                    SQL from files
     -H,--help                        Print help information
        --hiveconf <property=value>   Use value for given property
        --hivevar <key=value>         Variable substitution to apply to Hive
                                      commands. e.g. --hivevar A=B
     -i <filename>                    Initialization SQL file
     -S,--silent                      Silent mode in interactive shell
     -v,--verbose                     Verbose mode (echo executed SQL to the console)
    2)-d选项

    该选项定义一个变量,以键值对形式进行定义,可直接在Hive命令行引用。
    [hadoop@strong ~]$ hive -d tab=emp;
    hive> select *from ${tab} limit 3;
    OK
    1	Alen
    2	Jane
    3	Tom
    Time taken: 5.031 seconds, Fetched: 3 row(s)
    注:以${}方式对变量进行引用。

    3)--database选项

    该选项表明要连接的数据库名称。
    [hadoop@strong ~]$ hive --database hive
    hive> select current_database() as db;
    OK
    hive
    Time taken: 1.494 seconds, Fetched: 1 row(s)
    4)-e选项

    该选项表示在命令行执行一个SQL语句。
    [hadoop@strong ~]$ hive -e "select *from hive.emp limit 3"
    OK
    1	Alen
    2	Jane
    3	Tom
    Time taken: 14.263 seconds, Fetched: 3 row(s)
    5)-f选项

    该选项表示要执行一个文件。
    [hadoop@strong ~]$ cat test.hql 
    use hive;
    select *from emp limit 3;
    [hadoop@strong ~]$ hive -f test.hql 
    OK
    Time taken: 11.383 seconds
    OK
    1	Alen
    2	Jane
    3	Tom
    Time taken: 4.126 seconds, Fetched: 3 row(s)
    6)-S选项

    该选项表示以静默方式执行。
    [hadoop@strong ~]$ hive -S -e 'select *from hive.emp limit 3'
    1	Alen
    2	Jane
    3	Tom
    7)-V选项

    该选项用于打印输出信息。

    8)-H选项

    该选项用于显示帮助信息。

    9)--hiveconf选项

    该选项用于定义属性信息。
    [hadoop@strong ~]$ hive --hiveconf mapreduce.job.reduces=10
    hive> set mapreduce.job.reduces;
    mapreduce.job.reduces=10
    10)--hivevar选项

    和变量-d作用相同。

    2 Hive批量模式命令

    当$HIVE_HOME/bin/hive运行时带有-e或-f参数时,它以批量形式执行SQL命令,示例如上面的-e和-f选项讲解。

    3 HIve交互式Shell命令

    当$HIVE_HOME/bin/hive运行时不带有-e或-f参数时,它进入交互式模式。每个命令务必以;结束,否则命令不会执行。

    1)quit/exit

    这两个命令用于在交互式模式退出Hive Shell。
    hive> exit;
    [hadoop@strong ~]$ 
    2)set

    该命令用于以键值对方式设置配置变量,或打印变量。
    hive> set mapreduce.job.reduces=10;
    hive> set mapreduce.job.reduces;
    mapreduce.job.reduces=10
    3)reset

    该命令用于重置配置变量为默认值。
    hive> reset;
    hive> set mapreduce.job.reduces;
    mapreduce.job.reduces=-1
    4)!

    该命令用于在Hive Shell中使用Shell命令。
    hive> ! pwd;
    /home/hadoop
    5)source

    该命令用于在CLI执行脚本文件。
    hive> source test.hql;
    OK
    Time taken: 0.619 seconds
    OK
    1	Alen
    2	Jane
    3	Tom
    Time taken: 3.994 seconds, Fetched: 3 row(s)
    6)dfs

    该命令用于在Hive Shell执行dfs命令。
    hive> dfs -ls /user/hive;
    Found 2 items
    drwxrwxrwx   - hadoop supergroup          0 2018-06-19 16:37 /user/hive/tmp
    drwxrwxrwx   - hadoop supergroup          0 2018-06-20 17:30 /user/hive/warehouse
    3 Hive资源相关命令

    用法:
    ADD { FILE[S] | JAR[S] | ARCHIVE[S] } <filepath1> [<filepath2>]* LIST { FILE[S] | JAR[S] | ARCHIVE[S] } [<filepath1> <filepath2> ..] DELETE { FILE[S] | JAR[S] | ARCHIVE[S] } [<filepath1> <filepath2> ..]





  • 相关阅读:
    Fortify Audit Workbench Cookie Security: Cookie not Sent Over SSL
    Fortify Audit Workbench 笔记 Access Control: Database
    MATLAB中的polyfit函数的使用方法
    编写python代码时出现SyntaxError: invalid character in identifier的解决方法
    Windows10安装MinGW-W64出现Cannot download repository.txt的一种解决方法
    使用IDM下载B站视频出现声音跟视频分离的一种解决方法
    简洁桌面(使用Windows自带的桌面整理功能)
    MATLAB标记图像中特殊的点
    解决python使用pip安装下载库出现错误:ERROR:Cannot unpack file xxxx情况
    解决python使用pip下载安装库速度慢问题
  • 原文地址:https://www.cnblogs.com/alen-liu-sz/p/12975628.html
Copyright © 2020-2023  润新知