- Directly query data stored in Hive without the need to manually create tables.
- Use INSERT INTO or asynchronous materialized views (which are supported from v2.5 onwards) to process data stored in Hive and load the data into the database.
- Perform operations on the database to create or drop Hive databases and tables, or sink data from tables to Parquet-formatted (supported from v3.2 onwards) and ORC- or Textfile-formatted (supported from v3.3 onwards) Hive tables by using INSERT INTO.
- Distributed file system (HDFS) or object storage like AWS S3, Microsoft Azure Storage, Google GCS, or other S3-compatible storage system (for example, MinIO)
- Metastore like Hive metastore or AWS Glue Note If you choose AWS S3 as storage, you can use HMS or AWS Glue as metastore. If you choose any other storage system, you can only use HMS as metastore.
Usage notes
-
The database supports queries against Hive tables in Parquet, ORC, Textfile, Avro, RCFile, and SequenceFile file formats:
- Parquet files support the following compression formats: SNAPPY, LZ4, ZSTD, GZIP, and NO_COMPRESSION. From v3.1.5 onwards, Parquet files also support the LZO compression format.
- ORC files support the following compression formats: ZLIB, SNAPPY, LZO, LZ4, ZSTD, and NO_COMPRESSION.
- Textfile files support the LZO compression format from v3.1.5 onwards.
- The data types of Hive that the database does not support are INTERVAL, BINARY, and UNION. Additionally, the database does not support the STRUCT data type for Textfile-formatted Hive tables. The MAP data type for Textfile-formatted Hive tables is supported from v4.2 onwards.
-
From v4.2 onwards, the database parses Textfile-formatted Hive tables in the same way as Hive:
- For tables that use OpenCSVSerde, the database honors the
quoteCharandescapeCharproperties (including their default values"and\), and follows the parsing rules of the opencsv 2.3 library bundled with Hive 0.14 through 4.0. - For tables that use LazySimpleSerDe, the database honors the escape character defined by
ESCAPED BY. - Rows are split at physical line boundaries, and the
\NNULL marker is recognized before unescaping, both matching Hive. - MAP columns are parsed in the Hive text format, that is, entries separated by the collection delimiter, and keys and values separated by the map key delimiter.
- For tables that use OpenCSVSerde, the database honors the
-
The database supports sinking data to Parquet-formatted (supported from v3.2 onwards) and ORC- or Textfile-formatted (supported from v3.3 onwards) Hive tables:
- Parquet and ORC files support the following compression formats: NO_COMPRESSION, SNAPPY, LZ4, ZSTD, and GZIP.
- Textfile files support the NO_COMPRESSION compression format.
compression_codecor the system variableconnector_sink_compression_codecto specify the compression algorithm used for sinking data to Hive tables. When writing to a Hive table, if the table’s properties include a compression codec, the database will preferentially use that algorithm to compress the written data. Otherwise, it will use the compression algorithm set in the system variableconnector_sink_compression_codec.
Integration preparations
Before you create a Hive catalog, make sure your cluster can integrate with the storage system and metastore of your Hive cluster.AWS IAM
If your Hive cluster uses AWS S3 as storage or AWS Glue as metastore, choose your suitable authentication method and make the required preparations to ensure that your cluster can access the related AWS cloud resources. The following authentication methods are recommended:- Instance profile
- Assumed role
- IAM user
HDFS
If you choose HDFS as storage, configure your cluster as follows:-
(Optional) Set the username that is used to access your HDFS cluster and Hive metastore. By default, the database uses the username of the FE and BE or CN processes to access your HDFS cluster and Hive metastore. You can also set the username by adding
export HADOOP_USER_NAME="<user_name>"at the beginning of the fe/conf/hadoop_env.sh file of each FE and at the beginning of the be/conf/hadoop_env.sh file of each BE or the cn/conf/hadoop_env.sh file of each CN. After you set the username in these files, restart each FE and each BE or CN to make the parameter settings take effect. You can set only one username for each cluster. -
When you query Hive data, the FEs and BEs or CNs of your cluster use the HDFS client to access your HDFS cluster. In most cases, you do not need to configure your cluster to achieve that purpose, and the database starts the HDFS client using the default configurations. You need to configure your cluster only in the following situations:
- High availability (HA) is enabled for your HDFS cluster: Add the hdfs-site.xml file of your HDFS cluster to the BE_HOME/conf path of each BE or the $CN_HOME/conf path of each CN.
- View File System (ViewFs) is enabled for your HDFS cluster: Add the core-site.xml file of your HDFS cluster to the BE_HOME/conf path of each BE or the $CN_HOME/conf path of each CN.
Kerberos authentication
If Kerberos authentication is enabled for your HDFS cluster or Hive metastore, configure your cluster as follows:- Run the
kinit -kt keytab_path principalcommand on each FE and each BE or CN to obtain Ticket Granting Ticket (TGT) from Key Distribution Center (KDC). To run this command, you must have the permissions to access your HDFS cluster and Hive metastore. Note that accessing KDC with this command is time-sensitive. Therefore, you need to use cron to run this command periodically. - Add
JAVA_OPTS="-Djava.security.krb5.conf=/etc/krb5.conf"to the BE_HOME/conf/be.conf file of each BE or the $CN_HOME/conf/cn.conf file of each CN. In this example,/etc/krb5.confis the save path of the krb5.conf file. You can modify the path based on your needs.
Create a Hive catalog
Syntax
Parameters
catalog_name
The name of the Hive catalog. The naming conventions are as follows:- The name can contain letters, digits (0-9), and underscores (_). It must start with a letter.
- The name is case-sensitive and cannot exceed 1023 characters in length.
comment
The description of the Hive catalog. This parameter is optional.type
The type of your data source. Set the value tohive.
GeneralParams
A set of general parameters. The following table describes the parameters you can configure inGeneralParams.
MetastoreParams
A set of parameters about how the database integrates with the metastore of your data source.Hive metastore
If you choose Hive metastore as the metastore of your data source, configureMetastoreParams as follows:
/etc/hosts path. Otherwise, the database may fail to access your Hive metastore when you start a query.
The following table describes the parameter you need to configure in MetastoreParams.
AWS Glue
If you choose AWS Glue as the metastore of your data source, which is supported only when you choose AWS S3 as storage, take one of the following actions:-
To choose the instance profile-based authentication method, configure
MetastoreParamsas follows: -
To choose the assumed role-based authentication method, configure
MetastoreParamsas follows: -
To choose the IAM user-based authentication method, configure
MetastoreParamsas follows:
MetastoreParams.
For information about how to choose an authentication method for accessing AWS Glue and how to configure an access control policy in the AWS IAM Console, see Authentication parameters for accessing AWS Glue.
StorageCredentialParams
A set of parameters about how the database integrates with your storage system. This parameter set is optional. If you use HDFS as storage, you do not need to configureStorageCredentialParams.
If you use AWS S3, other S3-compatible storage system, Microsoft Azure Storage, or Google GCS as storage, you must configure StorageCredentialParams.
AWS S3
If you choose AWS S3 as storage for your Hive cluster, take one of the following actions:-
To choose the instance profile-based authentication method, configure
StorageCredentialParamsas follows: -
To choose the assumed role-based authentication method, configure
StorageCredentialParamsas follows: -
To choose the IAM user-based authentication method, configure
StorageCredentialParamsas follows:
StorageCredentialParams.
For information about how to choose an authentication method for accessing AWS S3 and how to configure an access control policy in AWS IAM Console, see Authentication parameters for accessing AWS S3.
S3-compatible storage system
Hive catalogs support S3-compatible storage systems from v2.5 onwards. If you choose an S3-compatible storage system, such as MinIO, as storage for your Hive cluster, configureStorageCredentialParams as follows to ensure a successful integration:
StorageCredentialParams.
Microsoft Azure Storage
Hive catalogs support Microsoft Azure Storage from v3.0 onwards.Azure Blob Storage
If you choose Blob Storage as storage for your Hive cluster, take one of the following actions:-
To choose the Shared Key authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams. -
To choose the SAS Token authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams.
Azure Data Lake Storage Gen2
If you choose Data Lake Storage Gen2 as storage for your Hive cluster, take one of the following actions:-
To choose the Managed Identity authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams. -
To choose the Shared Key authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams. -
To choose the Service Principal authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configurein StorageCredentialParams. -
To choose the Workload Identity authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams.
Azure Data Lake Storage Gen1
If you choose Data Lake Storage Gen1 as storage for your Hive cluster, take one of the following actions:-
To choose the Managed Service Identity authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams. -
To choose the Service Principal authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams.
Google GCS
Hive catalogs support Google GCS from v3.0 onwards. If you choose Google GCS as storage for your Hive cluster, take one of the following actions:-
To choose the VM-based authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams. -
To choose the service account-based authentication method, configure
StorageCredentialParamsas follows:The following table describes the parameters you need to configure inStorageCredentialParams. -
To choose the impersonation-based authentication method, configure
StorageCredentialParamsas follows:-
Make a VM instance impersonate a service account:
The following table describes the parameters you need to configure in
StorageCredentialParams. -
Make a service account (temporarily named as meta service account) impersonate another service account (temporarily named as data service account):
The following table describes the parameters you need to configure in
StorageCredentialParams.
-
Make a VM instance impersonate a service account:
MetadataUpdateParams
A set of parameters about how the database updates the cached metadata of Hive. This parameter set is optional. The database implements the automatic asynchronous update policy by default. In most cases, you can ignoreMetadataUpdateParams and do not need to tune the policy parameters in it, because the default values of these parameters already provide you with an out-of-the-box performance.
However, if the frequency of data updates in Hive is high, you can tune these parameters to further optimize the performance of automatic asynchronous updates.
Note
In most cases, if your Hive data is updated at a granularity of 1 hour or less, the data update frequency is considered high.
Examples
The following examples create a Hive catalog namedhive_catalog_hms or hive_catalog_glue, depending on the type of metastore you use, to query data from your Hive cluster.
HDFS
If you use HDFS as storage, run a command like below:AWS S3
Instance profile-based authentication
-
If you use Hive metastore in your Hive cluster, run a command like below:
-
If you use AWS Glue in your Amazon EMR Hive cluster, run a command like below:
Assumed role-based authentication
-
If you use Hive metastore in your Hive cluster, run a command like below:
-
If you use AWS Glue in your Amazon EMR Hive cluster, run a command like below:
IAM user-based authentication
-
If you use Hive metastore in your Hive cluster, run a command like below:
-
If you use AWS Glue in your Amazon EMR Hive cluster, run a command like below:
S3-compatible storage system
Use MinIO as an example. Run a command like below:Microsoft Azure Storage
Azure Blob Storage
-
If you choose the Shared Key authentication method, run a command like below:
-
If you choose the SAS Token authentication method, run a command like below:
Azure Data Lake Storage Gen1
-
If you choose the Managed Service Identity authentication method, run a command like below:
-
If you choose the Service Principal authentication method, run a command like below:
Azure Data Lake Storage Gen2
-
If you choose the Managed Identity authentication method, run a command like below:
-
If you choose the Shared Key authentication method, run a command like below:
-
If you choose the Service Principal authentication method, run a command like below:
-
If you choose the Workload Identity authentication method, run a command like below:
Google GCS
-
If you choose the VM-based authentication method, run a command like below:
-
If you choose the service account-based authentication method, run a command like below:
-
If you choose the impersonation-based authentication method:
-
If you make a VM instance impersonate a service account, run a command like below:
-
If you make a service account impersonate another service account, run a command like below:
-
If you make a VM instance impersonate a service account, run a command like below:
View Hive catalogs
You can use SHOW CATALOGS to query all catalogs in the current cluster:hive_catalog_glue:
Switch to a Hive Catalog and a database in it
You can use one of the following methods to switch to a Hive catalog and a database in it:-
Use SET CATALOG to specify a Hive catalog in the current session, and then use USE to specify an active database:
-
Directly use USE to switch to a Hive catalog and a database in it:
Drop a Hive catalog
You can use DROP CATALOG to drop an external catalog. The following example drops a Hive catalog namedhive_catalog_glue:
View the schema of a Hive table
You can use one of the following syntaxes to view the schema of a Hive table:-
View schema
-
View schema and location from the CREATE statement
Query a Hive table
-
Use SHOW DATABASES to view the databases in your Hive cluster:
- Switch to a Hive Catalog and a database in it.
-
Use SELECT to query the destination table in the specified database:
Load data from Hive
Suppose you have an OLAP table namedolap_tbl, you can transform and load data like below:
Grant privileges on Hive tables and views
You can use the GRANT statement to grant the privileges on all tables and views within a Hive catalog to a specific role. The command syntax is as follows:hive_role_table, switch to the Hive catalog hive_catalog, and then grant the role hive_role_table the privilege to query all tables and views within the Hive catalog hive_catalog:
Create a Hive database
Similar to the internal catalog of the database, if you have the CREATE DATABASE privilege on a Hive catalog, you can use the CREATE DATABASE statement to create a database in that Hive catalog. This feature is supported from v3.2 onwards. Note You can grant and revoke privileges by using GRANT and REVOKE. Note Switch to a Hive catalog, and then use the following statement to create a Hive database in that catalog:location parameter specifies the file path in which you want to create the database, which can be in either HDFS or cloud storage.
- When you use Hive metastore as the metastore of your Hive cluster, the
locationparameter defaults to<warehouse_location>/<database_name.db>, which is supported by Hive metastore if you do not specify that parameter at database creation. - When you use AWS Glue as the metastore of your Hive cluster, the
locationparameter does not have a default value, and therefore you must specify that parameter at database creation.
prefix varies based on the storage system you use:
Drop a Hive database
Similar to the internal databases of the database, if you have the DROP privilege on a Hive database, you can use the DROP DATABASE statement to drop that Hive database. This feature is supported from v3.2 onwards. You can only drop empty databases. Note You can grant and revoke privileges by using GRANT and REVOKE. When you drop a Hive database, the database’s file path on your HDFS cluster or cloud storage will not be dropped along with the database. Switch to a Hive catalog, and then use the following statement to drop a Hive database in that catalog:Create a Hive table
Similar to the internal databases of the database, if you have the CREATE TABLE privilege on a Hive database, you can use the CREATE TABLE, CREATE TABLE AS SELECT, or CREATE TABLE LIKE statement to create a managed table in that Hive database. This feature is supported since v3.2 in which version the database only supports creating Parquet-formatted Hive tables. From v3.3 onwards, the database also supports creating ORC- and Textfile-formatted Hive tables. Note- You can grant and revoke privileges by using GRANT and REVOKE.
- Hive catalogs support CREATE TABLE LIKE from v3.2.4 onwards.
Syntax
Parameters
column_definition
The syntax ofcolumn_definition is as follows:
NOTICE All non-partition columns must useNULLas the default value. This means that you must specifyDEFAULT "NULL"for each of the non-partition columns in the table creation statement. Additionally, partition columns must be defined following non-partition columns and cannot useNULLas the default value.
partition_desc
The syntax ofpartition_desc is as follows:
NOTICE Partition columns must be defined following non-partition columns. Partition columns support all data types excluding FLOAT, DOUBLE, DECIMAL, and DATETIME and cannot useNULLas the default value. Additionally, the sequence of the partition columns declared inpartition_descmust be consistent with the sequence of the columns defined incolumn_definition.
PROPERTIES
You can specify the table attributes in the"key" = "value" format in properties.
The following table describes a few key properties.
Examples
The following DDLs use the default file format Parquet as an example.-
Create a non-partitioned table named
unpartition_tbl. The table consists of two columns,idandscore, as shown below: -
Create a partitioned table named
partition_tbl_1. The table consists of three columns,action,id, anddt, of whichidanddtare defined as partition columns, as shown below: -
Query an existing table named
partition_tbl_1, and create a partitioned table namedpartition_tbl_2based on the query result ofpartition_tbl_1. Forpartition_tbl_2,idanddtare defined as partition columns, as shown below:
Sink data to a Hive table
Similar to the internal tables of the database, if you have the INSERT privilege on a Hive table (which can be a managed table or an external table), you can use the INSERT statement to sink the data of a table to that Hive table. This feature is supported since v3.2 in which version data can be sunk only to Parquet-formatted Hive tables. From v3.3 onwards, the database also supports sinking data to ORC- and Textfile-formatted Hive tables. Note that sinking data to external tables is disabled by default. To sink data to external tables, you must set the system variableENABLE_WRITE_HIVE_EXTERNAL_TABLE to true.
Note
- You can grant and revoke privileges by using GRANT and REVOKE.
- You can use the table property
compression_codecor the system variableconnector_sink_compression_codecto specify the compression algorithm used for sinking data to Hive tables. The database will prioritize using the compression codec specified in the table property.
Syntax
NOTICE
Partition columns do not allow NULL values. Therefore, you must make sure that no empty values are loaded into the partition columns of the Hive table.
Parameters
Examples
The following DMLs use the default file format Parquet as an example.-
Insert three data rows into the
partition_tbl_1table: -
Insert the result of a SELECT query, which contains simple computations, into the
partition_tbl_1table: -
Insert the result of a SELECT query, which reads data from the
partition_tbl_1table, into the same table: -
Insert the result of a SELECT query into the partitions that meet two conditions,
dt='2023-09-01'andid=1, of thepartition_tbl_2table:Or -
Overwrite all
actioncolumn values in the partitions that meet two conditions,dt='2023-09-01'andid=1, of thepartition_tbl_1table withclose:Or
Truncate a Hive table
You can use the TRUNCATE TABLE statement to quickly delete all data from Hive managed tables. This operation supports:- Truncating all data in non-partitioned tables
- Truncating all partitions in a partitioned table
- Truncating specific partitions in a partitioned table
Syntax
Parameters
table_name: The name of the Hive table that you want to truncate data from. You need to Switch to a Hive catalog and a database in it before you truncate the table in that database.partition_name = partition_value: The name and value of the partition column(s) to identify which partition(s) to truncate.
Examples
Switch to a Hive catalog and a database in it, and then use the following statements to truncate a Hive table in that database.-
Truncate a non-partitioned table:
-
Truncate all partitions of a partitioned table:
-
Truncate a single-partition partitioned table:
-
Truncate specific partitions of a multi-partition partitioned table:
Drop a Hive table
Similar to the internal tables of the database, if you have the DROP privilege on a Hive table, you can use the DROP TABLE statement to drop that Hive table. This feature is supported from v3.1 onwards. Note that currently the database supports dropping only managed tables of Hive. Note You can grant and revoke privileges by using GRANT and REVOKE. When you drop a Hive table, you must specify theFORCE keyword in the DROP TABLE statement. After the operation is complete, the table’s file path is retained, but the table’s data on your HDFS cluster or cloud storage is all dropped along with the table. Exercise caution when you perform this operation to drop a Hive table.
Switch to a Hive catalog and a database in it, and then use the following statement to drop a Hive table in that database.
Manually or automatically update metadata cache
Manual update
By default, the database caches the metadata of Hive and automatically updates the metadata in asynchronous mode to deliver better performance. Additionally, after some schema changes or table updates are made on a Hive table, you can also use REFRESH EXTERNAL TABLE to manually update its metadata, thereby ensuring that the database can obtain up-to-date metadata at its earliest opportunity and generate appropriate execution plans:-
A data file in an existing partition is changed, for example, by running the
INSERT OVERWRITE ... PARTITION ...command. - Schema changes are made on a Hive table.
- An existing Hive table is deleted by using the DROP statement, and a new Hive table with the same name as the deleted Hive table is created.
-
You have specified
"enable_cache_list_names" = "true"inPROPERTIESat the creation of your Hive catalog, and you want to query new partitions that you just created on your Hive cluster. Note From v2.5.5 onwards, the database provides the periodic Hive metadata cache refresh feature. For more information, see the below “Periodically refresh metadata cache” section of this topic. After you enable this feature, the database refreshes your Hive metadata cache every 10 minutes by default. Therefore, manual updates are not needed in most cases. You need to perform a manual update only when you want to query new partitions immediately after the new partitions are created on your Hive cluster.
Periodically refresh metadata cache
From v2.5.5 onwards, the database can periodically refresh the cached metadata of the frequently accessed Hive catalogs to perceive data changes. You can configure the Hive metadata cache refresh through the following FE parameters:
Using the periodic Hive metadata cache refresh feature and the metadata automatic asynchronous update policy together significantly accelerates data access, reduces the read load from external data sources, and improves query performance.
Appendix: Understand metadata automatic asynchronous update
Automatic asynchronous update is the default policy that the database uses to update the metadata in Hive catalogs. By default (namely, when theenable_metastore_cache and enable_remote_file_cache parameters are both set to true), if a query hits a partition of a Hive table, the database automatically caches the metadata of the partition and the metadata of the underlying data files of the partition. The cached metadata is updated by using the lazy update policy.
For example, there is a Hive table named table2, which has four partitions: p1, p2, p3, and p4. A query hits p1, and the database caches the metadata of p1 and the metadata of the underlying data files of p1. Assume that the default time intervals to update and discard the cached metadata are as follows:
- The time interval (specified by the
metastore_cache_refresh_interval_secparameter) to asynchronously update the cached metadata ofp1is 60 seconds. - The time interval (specified by the
remote_file_cache_refresh_interval_secparameter) to asynchronously update the cached metadata of the underlying data files ofp1is 60 seconds. - The time interval (specified by the
metastore_cache_ttl_secparameter) to automatically discard the cached metadata ofp1is 24 hours. - The time interval (specified by the
remote_file_cache_ttl_secparameter) to automatically discard the cached metadata of the underlying data files ofp1is 24 hours.

- If another query hits
p1again and the current time from the last update is less than 60 seconds, the database does not update the cached metadata ofp1or the cached metadata of the underlying data files ofp1. - If another query hits
p1again and the current time from the last update is more than 60 seconds, the database updates the cached metadata ofp1and the cached metadata of the underlying data files ofp1. - If the table has been accessed within 24 hours, the related cache will be refreshed every 10 minutes in the background.
- If
p1has not been accessed within 24 hours from the last update, the database discards the cached metadata ofp1. The metadata will be cached at the next query. - If
p1has not been accessed within 24 hours from the last update, the database discards the cached metadata of the underlying data files ofp1. The metadata will be cached at the next query.