Updated on 2024-11-29 GMT+08:00

Interconnecting Hive with OBS

Before performing the following operations, ensure that you have configured a storage-compute decoupled cluster by referring to Configuring a Storage-Compute Decoupled Cluster (Agency) or Configuring a Storage-Compute Decoupled Cluster (AK/SK).

Setting the Location to an OBS Path When Creating a Table

  1. Log in to the client installation node as the client installation user.
  2. Run the following command to initialize environment variables:

    source Client installation directory/bigdata_env

  3. For a security cluster, run the following command to perform user authentication (the user must have the permission to perform Hive operations). If Kerberos authentication is not enabled for the current cluster, you do not need to run this command.

    kinit User performing Hive operations

  4. Click Save to save the configuration. On the Dashboard page, click More and select Restart Service. Enter the password of the current user, click OK, and select Restart upper-layer services. Click OK to restart Hive.
  5. Log in to the beeline client and set Location to the OBS file system path when creating a table.

    beeline

    For example, run the following command to create the table test in obs://OBS parallel file system name/user/hive/warehouse/Database name/Table name:

    create table test(name string) location "obs://OBS parallel file system name/user/hive/warehouse/Database name/Table name";

    You need to add the component operator to the URL policy in the Ranger policy. Set the URL to the complete path of the object on OBS. Select the Read and Write permissions.

Interconnecting Hive with OBS Through MetaStore

  1. Log in to FusionInsight Manager and choose Cluster > Services > Hive > Configurations > All Configurations.

    Search for hive.metastore.warehouse.dir in the search box and change the parameter value to an OBS path, for example, obs://hivetest/user/hive/warehouse/. hivetest indicates the OBS file system name.
    Figure 1 Configuring hive.metastore.warehouse.dir

  2. Save the change and restart Hive.
  3. (Optional) Install the client by referring to Installing a Client. If the client has been installed in the cluster, go to 4.
  4. Update the client configuration file.

    1. Run the following command to open hivemetastore-site.xml in the Hive configuration file directory on the client:

      vim Client installation directory/Hive/config/hivemetastore-site.xml

    2. Change the value of hive.metastore.warehouse.dir to the corresponding OBS path, for example, obs://hivetest/user/hive/warehouse/, where hivetest is the OBS bucket name.
      Figure 2 Configuring the OBS Path
    3. Change the value of hive.metastore.warehouse.dir in hivemetastore-site.xml to the corresponding OBS path, for example, obs://hivetest/user/hive/warehouse/. The XML file is stored in the HCatalog client configuration file directory.

      vi Client installation directory/Hive/HCatalog/conf/hivemetastore-site.xml

  5. Log in to the beeline client, create a table, and check whether the location is the OBS path.

    beeline

    create table test(name string);

    desc formatted test;

    Location of the table is the OBS path.

    Figure 3 Location of the Hive table

    If the location of the current database points to HDFS, tables created in the database also point to HDFS by default. You do not need to specify the location. To modify the default table creation policy, modify the location of the database to point to OBS. Perform the following steps to modify the parameters:

    1. Run the following command to query the location of the database:

      show create database obs_test;

      Figure 4 Viewing the location of the Hive Table
    2. Run the following command to change the database location:

      alter database obs_test set location 'obs://OBS parallel file system name/user/hive/warehouse/Database name'

      Run the show create database obs_test command to check whether the database location points to OBS.

      Figure 5 Check the location of the modified Hive table.
    3. Run the following command to modify the table location:

      alter table user_info set location 'obs://OBS parallel file system name/user/hive/warehouse/Database name/Table name'

      If the table contains data, migrate the original data file to the new location.