Hive Table Type Mapping to JDBC Table Type
- Create external table
For hive, if you want to create an external table, please use the following HQL:
CREATE EXTERNAL TABLE marvin_ext_table1(id INT, name STRING, age INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION ‘/user/marvin/externaTable1′;
Hive will create a table named marvin_ext_table1 which points to an existing file(data) externaTable1 in the HDFS path /user/marvin/. The contents of file named externaTable1 are as follows:
001,Marvin,27
090,Jack,22
111,Lucy,32
- JDBC for Hive to Get Tables
The following is a map to JDBC table types from Hive table types:
Hive Table Type JDBC Table Type
MANAGED_TABLE -> 'TABLE'
VIRTUAL_VIEW -> 'VIEW'
EXTERNAL_TABLE -> 'EXTERNAL TABLE'
For hive there are some table types in the enum of TableType as follows:
public enum TableType {
MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW, INDEX_TABLE
}
If you want to get the JDBC types of hive, you could invoke the method in HiveDatabaseMetaData:
/**
* Translate hive table types into jdbc table types.
* @param hivetabletype
* @return
*/
public static String toJdbcTableType(String hivetabletype) {
if (hivetabletype==null) {
return null;
} else if (hivetabletype.equals(TableType.MANAGED_TABLE.toString())) {
return "TABLE";
} else if (hivetabletype.equals(TableType.VIRTUAL_VIEW.toString())) {
return "VIEW";
} else if (hivetabletype.equals(TableType.EXTERNAL_TABLE.toString())) {
return "EXTERNAL TABLE";
} else {
return hivetabletype;
}
}