zoukankan      html  css  js  c++  java
  • hive建表语句对加载数据的影响

    hive建表语句对加载数据还有影响?你是不是在开玩笑吧?
    客官不可以走!!看我测试数据。

    一:Hive一般建表语句

     HIve外表建表语句:

    create external table if not exists externaltable_test
    (
            aa string,
            bb string
    ) partitioned by (date string)
    row format delimited
    fields terminated by '|'
    location '/hive/table/externaltable_test/';

    hive内表建表语句

    create table if not exists innertable_test
    (
            aa string,
            bb string
    ) partitioned by (date string)
    row format delimited
    fields terminated by '|'
    location '/hive/table/innertable_test/';

    二:hive加载数据的速度

        数据约为500M,数据由一份拷贝而来

    普通load加载数据

        load data inpath '/hive/table/table_test/table_test/date=20190921' into table externaltable_test partition(date=20190921);         5.288

        load data inpath '/hive/table/table_test/table_test/date=20190923' into table innertable_test partition(date=20190923);              5.454

       看到这可能有人要喷我了,内表需要剪切数据,外表只是更改元数据

       外表和内表加载数据的速度怎么可能一样

       但是事实就是如此!!

    三:外表load慢揭秘

    1.location的作用

                        location的使用是规定了外表数据的存放路径,但是再加载数据的时候还是会将数据剪切到location中

          内表和外表的不同只是在删表的时候会不会删除数据 

    2.结论

                        如果外表有location制定的话,在加载数据的时候还是会将数据剪切到location中,导致数据加载过慢。

    3.修bug再测试

                        将外表的建表语句改为

         create external table if not exists externaltable_test
         (
                 aa string,
                 bb string
         ) partitioned by (date string)
         row format delimited 
         fields terminated by '|';

         再测试加载数据:

         load data inpath '/hive/table/table_test/table_test/date=20190921' into table externaltable_test partition(date=20190921);         0.683

         所以,建外表的时候还是不指定location,自觉的将数据拷贝到规定的location中比较好~~~

    四:内表的load速度提升方法

        ALTER TABLE innertable_test ADD PARTITION(date=20190922) LOCATION '/hive/table/table_test/table_test/date=20190922';         0.684

        这种只是对表加了一个外表类似的链接,删表的时候数据不删除需自己管理。这种方式无论外表内表都使用。

        这种方式让表内表不是内表外表不是外表了。但是个人感觉对外表使用更好一点。

        ALTER TABLE externaltable_test  ADD PARTITION(ddate=20190920) LOCATION '/hive/table/table_test/dt=20190920';            6.829

        这是对有location的外表加载数据的测试,几乎和load的方式一样了,但是数据并没有剪切过去。具体原因还在探索。

    五:快速插数据

        改方方适用于数据已经按照hive的方式存好了,或者表location变化了需要load数据

        //更改分区

         alter table aa set location ‘path’

        //多层分区需要加上

        set hive.msck.path.validation=ignore;

        MSCK REPAIR TABLE tablename

  • 相关阅读:
    C语言学生管理系统(原版本)(自编)
    【JavaScript】解构赋值
    【JavaScript】箭头函数
    【JavaScript】typeof 和 instanceof
    【JavaScript】Proxy 实例方法(二)
    【JavaScript】Proxy 实例方法(一)
    【JavaScript】Reflect 静态方法(二)
    【JavaScript】Reflect 静态方法(一)
    【JavaScript】async function
    开发系统关键字(例子)
  • 原文地址:https://www.cnblogs.com/wuxiaolong4/p/11665948.html
Copyright © 2011-2022 走看看