shell—如何检查配置单元中是否存在任何特定分区

of1yzvn4  于 2021-05-29  发布在  Hadoop
关注(0)|答案(3)|浏览(426)

如何检查配置单元中是否存在任何特定分区:
我的配置单元表中有如下分区:
国家=印度/州=mh国家=美国/州=纽约
我想检查country=“something”和state=“something”是否存在于配置单元中或使用shell脚本。请帮助

ubof19bj

ubof19bj1#

描述mytable分区(…)
显示像mytable分区一样扩展的表(…)
使用从shell执行 hive -e '...' ####演示

  1. create table mytable (i int)
  2. partitioned by (year int,month tinyint,day tinyint)
  3. ;
  4. insert into mytable partition(year,month,day) values (1,2017,3,29)
  5. ;
  6. hive> desc mytable partition (year=2017,month=3,day=29);
  7. OK
  8. i int
  9. year int
  10. month tinyint
  11. day tinyint
  12. # Partition Information
  13. # col_name data_type comment
  14. year int
  15. month tinyint
  16. day tinyint
  17. hive> desc mytable partition (year=2017,month=4,day=1);
  18. FAILED: SemanticException [Error 10006]: Partition not found {year=2017, month=4, day=1}
  19. hive> show table extended like mytable partition (year=2017,month=3,day=29);
  20. OK
  21. tableName:mytable
  22. owner:cloudera
  23. location:hdfs://quickstart.cloudera:8020/user/hive/warehouse/mytable/year=2017/month=3/day=29
  24. inputformat:org.apache.hadoop.mapred.TextInputFormat
  25. outputformat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
  26. columns:struct columns { i32 i}
  27. partitioned:true
  28. partitionColumns:struct partition_columns { i32 year, byte month, byte day}
  29. totalNumberFiles:1
  30. totalFileSize:2
  31. maxFileSize:2
  32. minFileSize:2
  33. lastAccessTime:1490770378864
  34. lastUpdateTime:1490770379748
  35. hive> show table extended like mytable partition (year=2017,month=4,day=1);
  36. FAILED: SemanticException [Error 10006]: Partition not found {year=2017, month=4, day=1}
展开查看全部
yb3bgrhw

yb3bgrhw2#

  1. res=`hive -e "use {db}; show partitions {table} partition(country='india',state='MH')"`
  2. if [ ! -z "$res" ]; then
  3. do sth if the partition exists
  4. fi

您可以为其他分区进行复制。

lc8prwob

lc8prwob3#

  1. hive -e "use <db>; show partitions <table>;" egrep --color '<countryName>|<stateName>'

前任: hive -e "use db; show partitions table;" egrep --color 'India|MH' 这将为您提供所有匹配分区,其结果与india或mh或两者都匹配

相关问题