查看Hive中表的所有信息(结构、字段、存放路径、属性)

目录

1. 查询创建表信息(show create table)

2. 查询表的字段信息(desc)

3. 查看表的详细属性信息(desc formatted)

4.  查看表的详细信息(describe extended)

5. 查看表的partitions信息(show partitions )


1. 查询创建表信息(show create table)

里面有delemited信息

hive> show create table alpha_sales_staff_info;
OK
CREATE TABLE `alpha_sales_staff_info`(
  `staff` string COMMENT '客服pin',
  `mall_id` string COMMENT '服务商ID',
  `brand_name` string COMMENT '品牌名称',
  `category` string COMMENT '品类名称',
  `level` string COMMENT '客服评级',
  `group` string COMMENT 'AB test组别')
PARTITIONED BY (
  `dt` string)
ROW FORMAT DELIMITED
  FIELDS TERMINATED BY ' '
  LINES TERMINATED BY '\n'
STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://ns7/user/mart_ai/app.db/alpha_sales_staff_info'
TBLPROPERTIES (
  'mart_name'='mart_ai',
  'transient_lastDdlTime'='1542188102')
Time taken: 0.149 seconds, Fetched: 21 row(s)


2. 查询表的字段信息(desc)

hive> desc alpha_sales_staff_info;
OK
staff                   string                  客服pin
mall_id                 string                  服务商ID
brand_name              string                  品牌名称
category                string                  品类名称
level                   string                  客服评级
group                   string                  AB test组别
dt                      string
 
# Partition Information
# col_name                data_type               comment
 
dt                      string
Time taken: 0.053 seconds, Fetched: 12 row(s)


3. 查看表的详细属性信息(desc formatted)


hive> desc formatted alpha_sales_staff_info;

# col_name                data_type               comment
 
staff                   string                  客服pin
mall_id                 string                  服务商ID
brand_name              string                  品牌名称
category                string                  品类名称
level                   string                  客服评级
group                   string                  AB test组别
 
# Partition Information
# col_name                data_type               comment
 
dt                      string
 
# Detailed Table Information
Database:               app
Owner:                  mart_ai
CreateTime:             Wed Nov 14 17:35:02 CST 2018
LastAccessTime:         UNKNOWN
Retention:              0
Location:               hdfs://ns7/user/mart_ai/app.db/alpha_sales_staff_info
Table Type:             MANAGED_TABLE
Table Parameters:
    mart_name               mart_ai
    transient_lastDdlTime    1542188102
 
# Storage Information
SerDe Library:          org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat:            org.apache.hadoop.mapred.TextInputFormat
OutputFormat:           org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed:             No
Num Buckets:            -1
Bucket Columns:         []
Sort Columns:           []
Storage Desc Params:
    field.delim
    line.delim              \n
    serialization.format
Time taken: 0.082 seconds, Fetched: 38 row(s)


4.  查看表的详细信息(describe extended)

hive> describe extended alpha_sales_staff_info;
OK
staff                   string                  客服pin
mall_id                 string                  服务商ID
brand_name              string                  品牌名称
category                string                  品类名称
level                   string                  客服评级
group                   string                  AB test组别
dt                      string
 
# Partition Information
# col_name                data_type               comment
 
dt                      string
 
Detailed Table Information    
Table(tableName:alpha_sales_staff_info, dbName:app, owner:mart_ai, createTime:1542188102, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:staff, type:string, comment:客服pin), FieldSchema(name:mall_id, type:string, comment:服务商ID), FieldSchema(name:brand_name, type:string, comment:品牌名称), FieldSchema(name:category, type:string, comment:品类名称), FieldSchema(name:level, type:string, comment:客服评级), FieldSchema(name:group, type:string, comment:AB test组别), FieldSchema(name:dt, type:string, comment:null)], location:hdfs://ns7/user/mart_ai/app.db/alpha_sales_staff_info, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format= , field.delim= , line.delim=
}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{}), storedAsSubDirectories:false), partitionKeys:[FieldSchema(name:dt, type:string, comment:null)], parameters:{mart_name=mart_ai, transient_lastDdlTime=1542188102}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE)
Time taken: 0.078 seconds, Fetched: 15 row(s)


5. 查看表的partitions信息(show partitions )

#a.表不是partition表

hive> show partitions dpc_test;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Table dpc_test is not a partitioned table


#b. 表有partition

hive> show partitions alpha_sales_staff_info;
OK
dt=v1
dt=v2
dt=v3
Time taken: 0.075 seconds, Fetched: 3 row(s)


 

### 回答1: Hive是基于Hadoop的数据仓库工具,用于处理大规模数据。Hive存放的数据是以表的形式组织的,并且默认情况下是没有索引的。没有索引意味着在查询数据时,Hive需要对整个数据集进行暴力查询,这会导致查询效率低下。 在Hive中建立分区可以提高查询效率。分区将数据按照一定的规则划分为更小的子集,例如按照时间、地区等维度进行划分。这样,当进行查询时,Hive只需要扫描相关分区的数据,而不必对整个数据集进行全局扫描。这大大减少了查询的时间和资源消耗,提高了查询效率。 如果没有建立分区直接查询,Hive需要对整个数据集进行扫描。由于Hive通常处理的是大规模数据,全局扫描会导致查询花费大量的时间和计算资源,效率非常低。此外,在没有索引的情况下,Hive无法直接定位到所需数据,需要进行全表遍历,导致查询延迟增加。 因此,在使用Hive进行数据查询时,建议根据数据的特点和查询需求,合理地建立分区。通过划分分区,可以充分利用Hive的并行计算能力,提高查询效率,减少查询时间和资源消耗。 ### 回答2: Hive是一种建立在Hadoop之上的数据仓库工具,用于处理大规模数据集。它的设计目标是支持数据的批量处理和分析,而不是实时查询和交互式应用。因此,在Hive存放的数据一般都是以文件的形式存储在分布式文件系统中,比如HDFS。 由于Hive存放的数据是以文件的形式存储,并且没有索引,所以在没有建立分区的情况下直接进行查询时,Hive只能进行全表扫描来获取需要的数据。这种方式被称为暴力查询,因为它需要检查每一行数据以满足查询条件,而没有任何优化方法。 暴力查询的效率非常低下,特别是当数据规模非常大时。由于需要遍历整个数据集,查询耗费的时间会非常长,甚至超出可接受的范围。因此,在使用Hive进行查询时,建立合适的分区是非常重要的。 通过建立分区,可以将数据按照特定的字段进行划分,将相同属性的数据放在同一个分区中。这样,在查询时只需要扫描部分分区,而不是整个数据集,大大提高了查询效率。类似于在关系型数据库中创建索引,分区相当于在Hive中的数据中引入了一种逻辑上的索引。 综上所述,由于Hive存放的数据没有索引,如果没有建立分区直接进行查询,Hive只能进行暴力查询,效率低下。因此,合理建立分区是提高Hive查询效率的重要手段。 ### 回答3: Hive是一种基于Hadoop的数据仓库工具,它将数据存储在Hadoop分布式文件系统(HDFS)中。Hive提供了类似于SQL的查询语言,允许用户对存储在HDFS中的大规模结构化数据进行查询和分析。 Hive中的数据存放方式通常是以表的形式组织,表是由一系列行和列组成的数据集合。然而,由于在HDFS中存储的数据没有索引,如果没有建立分区来对数据进行组织,Hive执行查询时就会进行暴力查询。 暴力查询是指对整个数据集进行全表扫描,无论查询条件是否与数据的特定子集匹配。由于没有索引来加速查询过程,暴力查询的效率往往比较低下,尤其是对于大规模的数据集。 建立分区是一种将数据按照指定的列进行拆分和组织的方法。通过在表中建立分区,可以将数据按照不同的分区键值进行划分,并为每个分区分配独立的存储路径。这样,在执行查询时,Hive只需扫描与查询条件匹配的特定分区,而不是整个数据集,从而大大提高了查询效率。 建立分区除了可以提高查询效率外,还能够提供更好的数据管理和组织能力。通过合理的分区设计,可以将数据按照时间、地区、类别等进行拆分,使得数据的查询和分析更加灵活和高效。 因此,为了提高Hive查询的效率,建议在存储大规模数据时,根据具体情况建立合适的分区来组织数据。这样可以避免暴力查询,提高查询效率,同时也可以提供更好的数据管理和组织能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值