表名
|
說明
|
BUCKETING_COLS
|
Hive表CLUSTERED BY字段信息(字段名,字段序號)
|
COLUMNS
|
Hive表字段信息(字段註釋,字段名,字段類型,字段序號)
|
DBS
|
|
NUCLEUS_TABLES
|
元數據表和hive中class類的對應關係
|
PARTITIONS
|
Hive表分區信息(創建時間,具體的分區)
|
PARTITION_KEYS
|
Hive分區表分區鍵(名稱,類型,comment,序號)
|
PARTITION_KEY_VALS
|
Hive表分區名(鍵值,序號)
|
PARTITION_PARAMS
|
|
SDS
|
所有hive表、表分區所對應的hdfs數據目錄和數據格式
|
SD_PARAMS
|
|
SEQUENCE_TABLE
|
Hive對象的下一個可用ID
|
SERDES
|
Hive表序列化反序列化使用的類庫信息
|
SERDE_PARAMS
|
序列化反序列化信息,如行分隔符、列分隔符、NULL的表示字符等
|
SORT_COLS
|
Hive表SORTED BY字段信息(字段名,sort類型,字段序號)
|
TABLE_PARAMS
|
表級屬性,如是否外部表,表註釋等
|
TBLS
|
所有hive表的基本信息
|
這些表的內容在HIVE裏面是有很格式化的顯示,在HIVE裏面輸入describe formatted table_name;展示出來的信息就是表格中所有表(除了NUCLEUS_TABLE, SEQUENCE_TABLE這兩張表)的信息,而且key值基本上和元數據的表字段名稱一致。
HIVE如何定義和操作元數據:
定義:
\src\metastore\src\model\ package.jdo和org.apache.hadoop.hive.metastore.model.*用來定義元數據的數據字典和操作。
以TBLS表爲例:
Mysql中的表結構爲:
- mysql> desc TBLS;
- +--------------------+--------------+------+-----+---------+-------+
- | Field | Type | Null | Key | Default | Extra |
- +--------------------+--------------+------+-----+---------+-------+
- | TBL_ID | bigint(20) | NO | PRI | NULL | |
- | CREATE_TIME | int(11) | NO | | NULL | |
- | DB_ID | bigint(20) | YES | MUL | NULL | |
- | LAST_ACCESS_TIME | int(11) | NO | | NULL | |
- | OWNER | varchar(767) | YES | | NULL | |
- | RETENTION | int(11) | NO | | NULL | |
- | SD_ID | bigint(20) | YES | MUL | NULL | |
- | TBL_NAME | varchar(128) | YES | MUL | NULL | |
- | VIEW_EXPANDED_TEXT | mediumtext | YES | | NULL | |
- | VIEW_ORIGINAL_TEXT | mediumtext | YES | | NULL | |
- | TBL_TYPE | varchar(128) | YES | | NULL | |
- +--------------------+--------------+------+-----+---------+-------+
|
在package.jdo裏的定義爲:
- <<strong><span style="color: #0000ff;">class name="MTable"</span></strong> <strong><span style="color: #ff0000;">table="TBLS"</span></strong> identity-type="datastore" detachable="true">
- <datastore-identity>
- <column name="TBL_ID"/>
- </datastore-identity>
- <index name="UniqueTable" unique="true">
- <column name="TBL_NAME"/>
- <column name="DB_ID"/>
- </index>
- <field name="tableName">
- <column name="TBL_NAME" length="128" jdbc-type="VARCHAR"/>
- </field>
- <field name="database">
- <column name="DB_ID"/>
- </field>
- <field name="sd" dependent="true">
- <column name="SD_ID"/>
- </field>
- <field name="owner">
- <column name="OWNER" length="767" jdbc-type="VARCHAR"/>
- </field>
- <field name="createTime">
- <column name="CREATE_TIME" jdbc-type="integer"/>
- </field>
- <field name="lastAccessTime">
- <column name="LAST_ACCESS_TIME" jdbc-type="integer"/>
- </field>
- <field name="retention">
- <column name="RETENTION" jdbc-type="integer"/>
- </field>
- <field name="viewOriginalText">
- <column name="VIEW_ORIGINAL_TEXT" jdbc-type="LONGVARCHAR"/>
- </field>
- <field name="viewExpandedText">
- <column name="VIEW_EXPANDED_TEXT" jdbc-type="LONGVARCHAR"/>
- </field>
- <field name="tableType">
- <column name="TBL_TYPE" length="128" jdbc-type="VARCHAR"/>
- </field>
- </class>
|
表名爲:TBLS;對應的類爲:org.apache.hadoop.hive.metastore.model. MTable,TBLS的所有操作都在此類中定義。
操作:
org.apache.hadoop.hive.metastore. ObjectStore
定義瞭如何獲取元數據,如何寫入元數據,其實全部是調用javax.jdo中各個類的方法。
以listPartitionNames爲例:
- public List<String> listPartitionNames(String dbName, String tableName,
- short max) throws MetaException {
- List<String> pns = new ArrayList<String>();
- boolean success = false;
- try {
- openTransaction();
- LOG.debug("Executing getPartitionNames");
- dbName = dbName.toLowerCase().trim();
- tableName = tableName.toLowerCase().trim();
- javax.jdo.Query q = pm.newQuery(
- "select partitionName from org.apache.hadoop.hive.metastore.model.MPartition "
- + "where table.database.name == t1 && table.tableName == t2 "
- + "order by partitionName asc");
- q.declareParameters("java.lang.String t1, java.lang.String t2");
- q.setResult("partitionName");
- Collection names = (Collection) q.execute(dbName, tableName);
- pns = new ArrayList<String>();
- for (Iterator i = names.iterator(); i.hasNext();) {
- pns.add((String) i.next());
- }
- success = commitTransaction();
- } finally {
- if (!success) {
- rollbackTransaction();
- }
- }
- return pns;
- }
|
所以,如果要修改HIVE元數據管理的功能,就可以按如下步驟操作:
1. 在\src\metastore\src\model\ package.jdo中定義新的HIVE元數據表的數據字典
2. 在org.apache.hadoop.hive.metastore.model中定義新增表的操作
3. 在org.apache.hadoop.hive.metastore. ObjectStore中新增方法處理如上定義的功能