【问题标题】:Export hql output to csv in beeline在直线中将 hql 输出导出到 csv
【发布时间】:2020-07-22 05:14:56
【问题描述】:

我正在尝试使用以下命令将我的 hql 输出导出到直线中的 csv:

beeline -u "jdbc:hive2://****/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2"?tez.queue.name=devices-jobs  --outputformat=csv2 -e "use schema_name; select * from table_name where open_time_new>= '2020-07-13' and open_time_new < '2020-07-22'" > filename.csv

问题是表中的某些列值包含逗号,这会将同一列的数据推送到下一个列值。 例如:

| abcd  | as per data,outage fault,xxxx. 
| xyz  |as per the source,ghfg,hjhjg.

以上数据将保存为 4 列而不是 2 列。 需要帮助!

【问题讨论】:

    标签: bash csv hive hiveql beeline


    【解决方案1】:

    试试the approach with local directory:

    insert overwrite local directory '/tmp/local_csv_report'
    row format delimited fields terminated by "," escaped by '\\'
    select * 
      from table_name 
     where open_time_new >= '2020-07-13' 
       and open_time_new < '2020-07-22'
    

    这将在您的本地 /tmp/local_csv_report 目录下创建几个 csv 文件,因此之后使用简单的 cat 会将结果合并到一个文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-05
      • 2015-01-17
      • 2022-01-21
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      相关资源
      最近更新 更多