Hive读取表数据时跳过文件行首和行尾

    xiaoxiao2022-07-13  157

    有时候用hive读取外表数据时,比如csv这种类型的,需要跳过行首或者行尾一些和数据无关的或者自动生成的多余信息,这里可以用tblproperties属性设置来实现,建表的时候设置如下:

    create external table order_products_prior( order_id string, product_id string, add_to_cart_order string, reordered string) row format delimited fields terminated by ',' lines terminated by '\n' tblproperties ("skip.header.line.count"="1");

    可以看到上述sql中设置tblproperties的2个属性

    “skip.heaer.line.count” 跳过文件行首多少行

    “skip.footer.line.count”跳过文件行尾多少行

    注意,这个属性的功能是hive0.13以后的都可以支持

    建表后,表的tblproperties属性无法被删除,只能被修改,可以通过修改属性值使hive读取表数据不跳行:

    ALTER TABLE order_products_prior SET TBLPROPERTIES( "skip.header.line.count"="0");
    最新回复(0)