配置单元视图查询未使用分区

qnyhuwrf  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(432)

我有Hive表和视图上的表。在使用where子句对分区列执行表查询时,我从explain中看到查询使用的是分区列。但在视图上运行相同的查询时,它从explain plan中显示不使用分区键。请建议
示例代码在这里,视图是在where子句中按国家/地区代码筛选的所有列的表上创建的(select*from where country\ U code='xx')
用于表的查询

  1. SELECT a.unique_id,
  2. a.country_code,
  3. a.rpt_prd,
  4. a.abv_cut_off_scor_flag,
  5. a.acct_und_promo_flag,
  6. .
  7. .
  8. b.arrg_cob_dt,
  9. b.arrg_id
  10. from
  11. a
  12. inner join
  13. b
  14. on a.country_code = b.country_code
  15. and a.product_code = b.product_code
  16. and a.rpt_prd =b.rpt_prd
  17. and a.unique_id =b.unique_id
  18. and a.arrg_id = b.arrg_id
  19. WHERE a.country_code='XX'
  20. AND a.product_code = 'YYYYY'
  21. AND a.rpt_prd ='20171231' ;
  22. a
  23. ======================================
  24. Partition Key for - a
  25. PARTITIONED BY ( |
  26. | `country_code` string, |
  27. | `product_code` string, |
  28. | `rpt_prd` string, |
  29. | `unique_id` string)
  30. b
  31. =======================================
  32. PARTITIONED BY ( |
  33. | `country_code` string, |
  34. | `product_code` string, |
  35. | `rpt_prd` string, |
  36. | `unique_id` string)
  37. Query using Views:
  38. ===================
  39. SELECT a.unique_id,
  40. a.country_code,
  41. a.rpt_prd,
  42. a.abv_cut_off_scor_flag,
  43. a.acct_und_promo_flag,
  44. .
  45. .
  46. b.arrg_cob_dt,
  47. b.arrg_id
  48. from
  49. a
  50. inner join
  51. b
  52. on a.country_code = b.country_code
  53. and a.product_code = b.product_code
  54. and a.rpt_prd =b.rpt_prd
  55. and a.unique_id =b.unique_id
  56. and a.arrg_id = b.arrg_id
  57. WHERE a.country_code='XX'
  58. AND a.product_code = 'YYYYY'
  59. AND a.rpt_prd ='20171231' ;
ffscu2ro

ffscu2ro1#

由于视图使用与实际表相同的基础数据,因此它应该使用分区。也就是说,其他人也有这个问题
一种可能的解决方法是通过创建分区视图语法使视图明确地知道分区,如下所示:

  1. ALTER VIEW view_name ADD PARTITION (partition_col = column_name)

相关问题