【问题标题】:How to load a file to HIVE with columns name mentioned in the file?如何使用文件中提到的列名将文件加载到 HIVE?
【发布时间】:2018-09-27 14:56:42
【问题描述】:

我有一个已加载到新创建的配置单元表中的文本文件。当我得到文件时,它也有列名。所以,我从文件中删除了列名,只加载了数据。但是,前两行我得到“null”,然后数据开始。该表有 39 列。我很确定 null 值用于列名。

下面是选择查询的输出

NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULLNULL     NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
600002158100    2000-02-15      2018-09-24 07:06:26     63      1       0       0       0       0       0       1       0       0       0       0       0   00       0       0       0       0               "S"     0       NULL    "Y"     "N"     "N"     0       7       "xyz"  "MEDIUM"        "abc" "pqr"  "Sam"   1       "chris"        1999-07-31

1)So, do I had to load the files including the column names with it? 
2) I still believe that the file that needs to be loaded need not have column names in it, just the data. please correct me if I am wrong.

请告诉我我的错误。

使用 tblproperties 后的新输出

abc      xyz        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    pqr       name  NULL     NULL    age    NULL    NULL    city    country       date     year     month

即当我触发“select * from tbl limi4”时,我得到标题名称,然后是数据。请指教

【问题讨论】:

    标签: hive


    【解决方案1】:

    您可以在创建能够(或稍后更改)时设置 tablproperties 以跳过标题。

    tblproperties ("skip.header.line.count"="1")
    

    这里的count 显示有多少第一行代表标题。

    【讨论】:

    • 所以,在我的例子中,我将使用“1”,因为标题在第一行,对吧?
    • @learner 如果只有第一行代表标题,那么是 1。但是,如果您设置此选项,则不再需要从文件中删除标题。
    • 当我使用 tblproperties 时。我得到了我在原始帖子中更新的输出
    • 数据类型好像不匹配,能不能把数据类型改成字符串再运行一下。
    • 不,我无法更改数据类型,因为还有浮点数和整数数据。但是,作为一种解决方法,我从文件中删除了标题,并使用了 tblproperties,这似乎是有效的。下面的链接也可能对整个情况有更多的了解。 stackoverflow.com/questions/40573474/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多