python判断hive是不是分区表

Python017

python判断hive是不是分区表,第1张

show create table 表名

如果是这个表有分区的话,可以看到显示的内容里有partition,partition里面跟的就是分区列名

python执行该命令即可

这个要用到python的一个模块,wmi, 可以参考这篇帖子:

python wmi

#Show disk partitions

import wmi

c = wmi.WMI ()

for physical_disk in c.Win32_DiskDrive ():

for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):

for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):

print physical_disk.Caption, partition.Caption, logical_disk.Caption

#Show the percentage free space for each fixed disk

import wmi

c = wmi.WMI ()

for disk in c.Win32_LogicalDisk (DriveType=3):

print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))

更多信息可参考《Linux就该这么学》