【问题标题】:How to pass date into shell script for a sqoop command dynamically?如何动态地将日期传递给 sqoop 命令的 shell 脚本?
【发布时间】:2017-03-22 20:56:13
【问题描述】:

我正在使用以下命令进行 sqoop 导入:

#!/bin/bash
    while IFS=":" read -r server dbname table; do
    sqoop eval --connect jdbc:mysql://$server/$dbname --username root --password cloudera --table mydata --hive-import --hive-table dynpart --check-column id --last-value $(hive -e "select max(id) from dynpart"); --hive-partition-key 'thisday' --hive-partition-value '01-01-2016'
done<tables.txt

我每天都在做分区。 蜂巢表:

create table dynpart(id int, name char(30), city char(30))
  partitioned by(thisday char(10))
  row format delimited
  fields terminated by ','
  stored as textfile
  location '/hive/mytables'
  tblproperties("comment"="partition column: thisday structure is dd-mm-yyyy");

但我不想直接给出分区值,因为我想创建一个 sqoop 作业并每天运行它。在脚本中,如何将日期值动态传递给 sqoop 命令(格式:dd/mm/yyyy)而不是直接提供? 任何帮助表示赞赏。

【问题讨论】:

  • YYYY-MM-DD (!!)
  • 嗯,我得到了所需格式的日期。我在表中有 3 列中的数据。问题是,表中的实际数据为 NULL,如下所示 NULL NULL NULL 30-03-2017

标签: shell hadoop


【解决方案1】:

可以使用shell命令date来获取(ubuntu 14.04):

$ date +%d/%m/%Y
22/03/2017

【讨论】:

  • 我给出了你提到的格式,但我得到的输出为 NULL NULL NULL +%d/%m/%Y
【解决方案2】:

你可以试试下面的代码

#!/bin/bash
DATE=$(date +"%d-%m-%y")
while IFS=":" read -r server dbname table; do
sqoop eval --connect jdbc:mysql://$server/$dbname --username root --password cloudera --table mydata --hive-import --hive-table dynpart --check-column id --last-value $(hive -e "select max(id) from dynpart"); --hive-partition-key 'thisday' --hive-partition-value $DATE
done<tables.txt

希望对您有所帮助

【讨论】:

  • 我正在获取日期,但其他列数据即将到来 NULL 像 NULL NULL NULL 22-03-2017 我的 RDBMS 表有一个像 1 Abcd NewYork 这样的记录
  • 你有那个日期分区的数据吗?....22-03-2017?从上面的查询中,我们提取 01-01-2016 为什么不将 DATE 变量设置为 DATE="01-01-2016"
  • 我试过了,直接给出日期。 #!/bin/bash DATE="22-03-2017" while IFS=":" read -r server dbname tablename;做 sqoop 导入 --connect jdbc:mysql://$server/$dbname --table $tablename --username root --password cloudera --hive-import --hive-table dynpart --hive-partition-key 'thisday ' --hive-partition-value $DATE --target-dir '/user/hive/newimp5' -m 1 done
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 2020-01-03
  • 1970-01-01
  • 2019-07-02
相关资源
最近更新 更多