tencent cloud

Elastic MapReduce

  • Release Notes and Announcements
  • Product Introduction
  • Purchase Guide
    • EMR on CVM Billing Instructions
    • EMR on TKE Billing Instructions
    • EMR Serverless HBase Billing Instructions
    • EMR Serverless TCBase Billing Overview
  • Getting Started
  • EMR on CVM Operation Guide
    • Planning Cluster
    • Administrative rights
    • Configuring Cluster
    • Managing Cluster
    • Managing Service
    • Monitoring and Alarms
    • TCInsight
  • EMR on TKE Operation Guide
  • EMR Serverless HBase Operation Guide
  • EMR Serverless TCBase Operation Guide
  • EMR Development Guide
    • Hadoop Development Guide
    • Spark Development Guide
    • Hbase Development Guide
    • Phoenix on Hbase Development Guide
    • Hive Development Guide
    • Presto Development Guide
    • Sqoop Development Guide
    • Hue Development Guide
    • Oozie Development Guide
    • Flume Development Guide
    • Kerberos Development Guide
    • Knox Development Guide
    • Alluxio Development Guide
    • Kylin Development Guide
    • Livy Development Guide
    • Kyuubi Development Guide
    • Zeppelin Development Guide
    • Hudi Development Guide
    • Superset Development Guide
    • Impala Development Guide
    • Druid Development Guide
    • TensorFlow Development Guide
    • Kudu Development Guide
    • Ranger Development Guide
    • Kafka Development Guide
    • StarRocks Development Guide
    • Flink Development Guide
    • JupyterLab Development Guide
    • MLflow Development Guide
  • Practical Tutorial
    • Practice of EMR on CVM Ops
    • Data Migration
    • Practical Tutorial on Custom Scaling
  • API Documentation
    • History
    • Introduction
    • API Category
    • Making API Requests
    • Cluster Resource Management APIs
    • Cluster Services APIs
    • User Management APIs
    • Information Query APIs
    • Scaling APIs
    • Configuration APIs
    • Other APIs
    • Cluster Lifecycle APIs
    • Serverless HBase APIs
    • YARN Resource Scheduling APIs
    • Data Types
    • Error Codes
  • FAQs
    • EMR on CVM
  • Service Level Agreement
  • Contact Us

Creating Databases and Tables in COS/CHDFS with Hive

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-10-30 11:43:59
This document introduces how to create databases and tables in Hive on COS and CHDFS.

Development Preparation

Make sure you have activated Tencent Cloud and created an EMR cluster. When creating an EMR cluster, you need to select the Hive component in the software configuration interface.
The example includes content that requires access to Tencent COS. You can see Creating a Bucket to create a bucket in COS and enable COS authorization on the Instance Information page of the EMR console.
The example includes content that requires access to Tencent Cloud CHDFS. You can see Mounting CHDFS to create a mount point and mount it to the EMR cluster.

Using Hive to Create Databases and Tables in COS

Note:
EMR has integrated Hadoop-COS by default. After enabling COS authorization in the EMR console, you may use a temporary key tied to the Tencent Cloud EMR instance’s role to access COS, which is more secure compared to using a fixed key.
For other configuration methods, see COS-Hadoop Tools.

Method I: Creating the Entire Database on COS

Log in to the EMR cluster’s Master node, switch to the Hadoop user, and execute the following command to enter the Hive command line:
hive
Execute the following command to create a database named hivewithcos in your COS bucket.
hive> create database hivewithcos location 'cosn://${bucketname}/${path}';
Note:
${bucketname} is the name of the COS bucket you created, and ${path} is the storage path.
View the execution result, and you will see the hivewithcos database created on COS.
hive> show databases;
OK
default
hivewithcos
Time taken: 0.094 seconds, Fetched: 2 row(s)
Create a data table named record (the method to load data into the table is the same as on HDFS):
hive> use hivewithcos;
hive> create table record(id int, name string) row format delimited fields terminated by ',' stored as textfile;
View the table:
hive> show tables;
OK
record
Time taken: 0.063 seconds, Fetched: 1 row(s)

Method II: Placing a Specific Table in COS

Create a database in Hive:
hive> create database test;
hive> use test;
Execute the following statement to create a table named record in the specified path of the COS bucket (the method to load data into the table is the same as on HDFS):
hive> create table record(id int, name string) row format delimited fields terminated by ',' stored as textfile location 'cosn://$bucketname/$path';
View the table:
hive> show tables;
OK
record
Time taken: 0.063 seconds, Fetched: 1 row(s)

Using Hive to Create Databases and Tables on CHDFS

Method I: Creating the Entire Database on CHDFS

Log in to the EMR cluster’s Master node, switch to the Hadoop user, and execute the following command to enter the Hive command line:
hive
Execute the following command to create a database named hivewithofs in your CHDFS directory:
hive> create database hivewithofs location 'ofs://${mountpoint}/${path}';
Note:
${mountpoint} is the CHDFS mount address you created, and ${path} is the directory path.
View the execution result, and you will see the hivewithofs database created on CHDFS.
hive> show databases;
OK
default
hivewithofs
Time taken: 0.094 seconds, Fetched: 2 row(s)
Create a data table named record (the method to load data into the table is the same as on HDFS).
hive> use hivewithofs;
hive> create table record(id int, name string) row format delimited fields terminated by ',' stored as textfile;
View the table:
hive> show tables;
OK
record
Time taken: 0.063 seconds, Fetched: 1 row(s)

Method II: Placing a Specific Table in CHDFS

Create a database test2 in Hive:
hive> create database test2;
hive> use test2;
Execute the following statement to create a table named record in CHDFS:
hive> create table record(id int, name string) row format delimited fields terminated by ',' stored as textfile location 'cosn://$mountpoint/$path';
View the table:
hive> show tables;
OK
record
Time taken: 0.063 seconds, Fetched: 1 row(s)

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan