• Hive大白话(●三●)


    目录

    🧡EXPLAIN

    🧡Fetch抓取

    🧡本地模式


    💟这里是CS大白话专场,让枯燥的学习变得有趣!

    💟没有对象不要怕,我们new一个出来,每天对ta说不尽情话!

    💟好记性不如烂键盘,自己总结不如收藏别人!

    💌Hive优化是非常关键的,将分多篇进行总结~

    🧡EXPLAIN

    💌Hive提供了EXPLAIN命令来展示一个查询的执行计划,可以提前预计查询需要的时间,语法如下,括号里为可选参数:

    EXPLAIN [EXTENDED|CBO|AST|DEPENDENCY|AUTHORIZATION|LOCKS|VECTORIZATION|ANALYZE] query
    

     🍠我们用explain展示一下上节用到的查询语句:

    1. Explain
    2. STAGE DEPENDENCIES: //各Stage之间的依赖性
    3. Stage-1 is a root stage //Stage-1为根stage
    4. Stage-0 depends on stages: Stage-1 //Stage-0依赖Stage-1
    5. STAGE PLANS: //各Stage的执行计划
    6. Stage: Stage-1 //先执行Stage-1
    7. Map Reduce
    8. Map Operator Tree: //Map阶段的执行计划树
    9. TableScan //表扫描,加载表
    10. alias: business //表名称
    11. Statistics: Num rows: 1 Data size: 2970 Basic stats: COMPLETE Column stats: NONE //表统计信息(数据条数、数据大小等)
    12. Reduce Output Operator
    13. key expressions: name (type: string) //分组的字段
    14. sort order: + //值为 + 正序排序,值为 - 倒序排序,值为空不排序
    15. Map-reduce partition columns: name (type: string) //partition by name
    16. Statistics: Num rows: 1 Data size: 2970 Basic stats: COMPLETE Column stats: NONE
    17. value expressions: id (type: string), cost (type: int) //查询的字段名称及类型
    18. Execution mode: vectorized
    19. Reduce Operator Tree: //Reduce阶段的执行计划树
    20. Select Operator
    21. expressions: VALUE._col0 (type: string), KEY.reducesinkkey0 (type: string), VALUE._col2 (type: int) //需要的字段名称及字段类型
    22. outputColumnNames: _col0, _col1, _col3 //map阶段输出的字段
    23. Statistics: Num rows: 1 Data size: 2970 Basic stats: COMPLETE Column stats: NONE
    24. PTF Operator
    25. Function definitions:
    26. Input definition
    27. input alias: ptf_0
    28. output shape: _col0: string, _col1: string, _col3: int
    29. type: WINDOWING
    30. Windowing table definition
    31. input alias: ptf_1
    32. name: windowingtablefunction
    33. order by: _col1 ASC NULLS FIRST
    34. partition by: _col1
    35. raw input shape:
    36. window functions:
    37. window function definition
    38. alias: sum_window_0
    39. arguments: _col3
    40. name: sum
    41. window function: GenericUDAFSumLong
    42. window frame: ROWS PRECEDING(MAX)~FOLLOWING(MAX)
    43. Statistics: Num rows: 1 Data size: 2970 Basic stats: COMPLETE Column stats: NONE
    44. Select Operator
    45. expressions: _col0 (type: string), _col1 (type: string), sum_window_0 (type: bigint)
    46. outputColumnNames: _col0, _col1, _col2
    47. Statistics: Num rows: 1 Data size: 2970 Basic stats: COMPLETE Column stats: NONE
    48. File Output Operator //文件输出操作
    49. compressed: false //是否压缩
    50. Statistics: Num rows: 1 Data size: 2970 Basic stats: COMPLETE Column stats: NONE
    51. table:
    52. input format: org.apache.hadoop.mapred.SequenceFileInputFormat //输入文件格式化方式
    53. output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat //输出文件格式化方式
    54. serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe //序列化方式
    55. Stage: Stage-0 //再执行Stage-0
    56. Fetch Operator //客户端获取数据操作
    57. limit: -1 //值为 -1 不限制条数
    58. Processor Tree:
    59. ListSink

    💌不同的SQL语句的执行计划是不同的,可以详细参考:http://t.csdn.cn/anONF。本文为带窗口函数的SQL查询。

    🧡Fetch抓取

     💌通过设置hive-default.xml.template文件中hive.fetch.task.conversion属性可以减少MR操作

    none : 只要用到HDFS都要进行MR。

    minimal : 在select *,partition分区,limit查询时不用MR。

    more(默认): 在minimal基础上添加TABLESAMPLE (时间戳)and 虚拟字段(别名)

    🧡本地模式

    💌对于数据量小、文件数少的情况,Hive可以通过本地模式在单台机器上处理所有的任务,减少网络传输,设置如下:

    1. set hive.exec.mode.local.auto=true; //开启本地mr
    2. set hive.exec.mode.local.auto.inputbytes.max=50000000; //设置local mr的最大输入数据量,当输入数据量小于这个值时采用local mr的方式,默认为134217728,即128M
    3. set hive.exec.mode.local.auto.input.files.max=10; //设置local mr的最大输入文件个数,当输入文件个数小于这个值时采用local mr的方式,默认为4
  • 相关阅读:
    张量-规约计算
    一文搞定IDEA中SpringBoot项目环境的热部署
    【Reinforcement Learning】AlphaGo 如何使用的强化学习?
    计算机网络_2.2物理层下面的传输媒体
    轻松整理文件夹,将视频文件全部归类到另一个文件夹!
    AI绘图提示词Stable Diffusion Prompt 笔记
    基于用户行为的交易反欺诈探索
    iOS接入IJKPlayer遇到的问题汇总
    01BFS最短距离的原理和C++实现
    使用自功率谱、互功率谱估计滤波器幅频特性
  • 原文地址:https://blog.csdn.net/qq_41847894/article/details/126674238