hive output json string

At present, there is no convenient function that can be used directly, and only concat can be used to manually splicing.

Note that the null field value is converted to empty, use the nvl function

  1. If the hql statement is written in the script.q file as follows:

    select concat('{"data_dt":"',a.data_dt,
    '","user":"',NVL(a.`user`, ''),
    '","click":"',NVL(a.click, ''),
    '"}') as value
    from table a;
  2. If you use the hive -e parameter directly, you need to escape the double quotes

    select concat('{\"data_dt\":\"',a.data_dt,
    '\",\"user\":\"',NVL(a.`user`, ''),
    '\",\"click\":\"',NVL(a.click, ''),
    '\"}') as value
    from table a;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324893608&siteId=291194637