【问题标题】:Hadoop/Hive - Split a single row into multiple rows and store to a new tableHadoop/Hive - 将单行拆分为多行并存储到新表中
【发布时间】:2021-02-18 08:49:37
【问题描述】:

目前,我用这个主题解决了我最初的问题:Hadoop/Hive - 将单行拆分为多行并存储到新表中。

有没有人知道如何用分组的 subs 创建一个新表?

ID  Subs
1   deep-learning, machine-learning, python
2   java, c++, python, javascript

使用下面的代码,我得到了我正在寻找的回报,但无法弄清楚如何将输出保存到新表中

use demoDB 
Select id_main , topic_tag from demoTable
lateral view explode (split(topic_tag , ',')) topic_tag as topic

谢谢 妮可

【问题讨论】:

    标签: sql hadoop hive sql-insert create-table


    【解决方案1】:

    在 Hive 中,您可以使用 create ... as select ...:

    create table newtable as
    select id_main, topic_tag 
    from demoTable
    lateral view explode (split(topic_tag , ',')) topic_tag as topic
    

    这将创建一个新表并从查询的结果集中启动其内容。如果新表已经存在,请改用insert ... select

    insert into newtable (id_main, topic_tag)
    select id_main, topic_tag 
    from demoTable
    lateral view explode (split(topic_tag , ',')) topic_tag as topic
    

    【讨论】:

    • 非常感谢您的快速回答和解释!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    相关资源
    最近更新 更多