zoukankan      html  css  js  c++  java
  • hive使用小技巧如何往Hive SQL中传入参数

    很多SQL需要重复执行,可能是每天执行一次,而需要修改的只是SQL中的日期字段,这种情况下可以使用 参数代入
    使用的方式
    1. hive -d key1=value1 -d key2=value -d key3=value3 ...
    复制代码

    例子-1:

    1. hive -d shell_date_1='20120425' -d shell_date_2='20120426'
    2. hive> set shell_date_1;
    3. shell_date_1=20120425
    4. hive> set shell_date_2;
    5. shell_date_2=20120426
    6. hive> explain select * from dual where user_id = ${shell_date_1};
    复制代码

    这里面的 shell_date_1 会替换为 20120425
    例子-2:
    1. hive -d shell_date_1='20120425' -d shell_date_2='20120426' \ 
    2.        -e "explain select * from dual where user_id = ${shell_date_1}"
    复制代码

    例子-3:
    1. vim hive.sql
    复制代码

    内容为:

    1. explain select * from dual where user_id = ${shell_date_1}
    2. hive -d shell_date_1='20120425' -f hive.sql
    复制代码

  • 相关阅读:
    数据流图和数据流程图的定义与组成元素
    敏捷开发3种角色
    WBS
    开发流程
    结对编程
    笔记
    登录注册界面维护2----注册界面进行Toast提示
    登录注册界面修改错误
    听说
    “学习链接篇”
  • 原文地址:https://www.cnblogs.com/java20130722/p/3206939.html
Copyright © 2011-2022 走看看