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
    复制代码

  • 相关阅读:
    启动Docker容器
    Docker 删除容器
    11.18数据库认证
    10.17权限认证
    9.16角色认证
    8.13数据库认证
    6.11Realm简介
    5.8认证流程分析
    4.7固定信息认证
    20张图表达程序员的心酸
  • 原文地址:https://www.cnblogs.com/java20130722/p/3206939.html
Copyright © 2011-2022 走看看