【问题标题】:No records shown after uploading a dataset as csv file to hive将数据集作为 csv 文件上传到 hive 后不显示任何记录
【发布时间】:2017-07-22 13:06:01
【问题描述】:

我有一个使用以下代码创建的 hadoop 表:

create table XXXX 
(...some data definitions...)
row format delimited
WITH SERDEPROPERTIES ('field.delim' = '^')
(...some other properties...)

然后我移动到HDFS,在数据库下找到相应的表并将csv 文件上传到它上面。我的csv 文件的列遵循create table 语句定义的顺序,分区列放在最后。在我成功上传csv文件后,原来当 我做'select * from mydataset' 查询没有产生任何结果。 当我点进csv文件时,似乎没有错,分隔符'^'和数据字段还在。

  1. 我想知道问题出在哪里,如果我这样做,结果会不会不同 改用 { 以 '^' } 终止的行格式分隔字段?
  2. 我所做的上传csv文件与使用负载相同吗 数据路径语句?我可以改用 load data inpath 语句吗 会比手动上传 csv 文件更快吗?

谢谢。

【问题讨论】:

    标签: hadoop


    【解决方案1】:
    There are Two ways to Upload the data into Hive table
    1) Load Command
    2) Follow the below steps.
        Step 1: Create folder on HDFS (Example: hadoop fs -mkidr /user/Username/orders)
        Step 2: Upload the Files to the above folder(Example: hadoop fs -put csvfiles /user/Username/orders/)
        Step 3: Create the External Hive table using the above folder. After this operation you can query and test the data
                Example:
                  Create External Table ordersfeed(
                    order_id BIGINT,
                    order_name String
                  )
                  ROW FORMAT DELIMITED
                    FIELDS TERMINATED BY ','
                  LOCATION '/user/Username/orders'
                  STORED AS TEXTFILE;
        Step 4: Create Internal Hive table
              Create  Table ordersdata(
                order_id BIGINT,
                order_name String
              )
              STORED AS ORC
        Step 5: Insert the Data from External table to internal table
              Example:
                INSERT INTO TABLE ordersdata
                SELECT * FROM ordersfeed;
    Note:
      1) Both delimiter of CSV file and External table should be same
    

    【讨论】:

      【解决方案2】:

      更新我的问题:

      我发现我的表是一个分区表,仅通过将 csv 文件上传到表文件夹中就无法将数据加载到其中。应该使用静态分区/动态分区插入覆盖表。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-19
        • 2011-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多