zoukankan      html  css  js  c++  java
  • hive命令的执行方式

    1.通过cli直接执行

    2.hive -e "hql"

      如:[root@host ~]# hive -e "use gamedw;show tables"

             [root@host ~]# hive -e 'use gamedw;show tables'

    3.执行文件
    [root@host tmpdata]# cat hive.sql
    select * from gamedw.v_cust

    [root@host ~]# hive -f /root/tmpdata/hive.sql  

    SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

    Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

    OK
    tianyongtao     1       50      shenzhen
    wangwu  1       85      shenzhen
    zhangsan        1       20      shenzhen
    liuqin  0       56      shenzhen
    wangwu  0       47      shenzhen
    liuyang 1       32      shenzhen
    Time taken: 5.386 seconds, Fetched: 6 row(s)

    [root@host ~]# hive -f /root/tmpdata/hive.sql >/root/tmpdata/hivelog.txt   //结果保存到本地

    SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

    Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

    OK

    Time taken: 4.75 seconds, Fetched: 6 row(s)
    [root@host ~]# cat /root/tmpdata/hivelog.txt
    tianyongtao     1       50      shenzhen
    wangwu  1       85      shenzhen
    zhangsan        1       20      shenzhen
    liuqin  0       56      shenzhen
    wangwu  0       47      shenzhen
    liuyang 1       32      shenzhen

    同样

     hive -i  /root/tmpdata/hive.sql  也可以执行hql同时开启cli

    hive  -hivevar 传递参数

    [root@host ~]# cat /root/tmpdata/hivevar.sql
    select * from gamedw.v_cust where sex=${varsex} and age>${varage};

    [root@host ~]# hive -hivevar varsex=0 -hivevar varage=20 -f /root/tmpdata/hivevar.sql

    SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

    SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]

    SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]

    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

    SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

    Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

    OK
    liuqin  0       56      shenzhen
    wangwu  0       47      shenzhen
    Time taken: 5.839 seconds, Fetched: 2 row(s)

    [root@host ~]# hive -e "select * from gamedw.cust">>cust.txt SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

    Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true OK Time taken: 9.204 seconds, Fetched: 19 row(s)

    [root@host ~]# cat cust.txt
    tianyt_touch100 1       50
    wangwu  1       85
    zhangsan        1       20
    liuqin  0       56
    wangwu  0       47
    liuyang 1       32
    hello   0       100
    mahuateng       1       1001
    tianyt_touch100 1       50
    wangwu  1       85
    zhangsan        1       20
    liuqin  0       56
    wangwu  0       47
    xiaomage        NULL    51
    nihao   1       5
    liuyang 1       32
    hello   0       100
    mahuateng       1       1001
    nihao   1       5

  • 相关阅读:
    七 使用list和tuple
    python 操作RabbitMQ
    python 操作Memcached
    python 操作SQLAlchemy
    Scrapy 分布式爬虫
    Django 测试驱动开发
    Flask 页面缓存逻辑,jinja2 过滤器,测试器
    Flask Markup 上下文,request
    Flask 学习 十六 部署
    Flask 学习 十五 性能
  • 原文地址:https://www.cnblogs.com/playforever/p/9173753.html
Copyright © 2011-2022 走看看